Home | History | Annotate | Download | only in Shared
      1 /*
      2  * Copyright (C) 2010 Apple Inc. All rights reserved.
      3  *
      4  * Redistribution and use in source and binary forms, with or without
      5  * modification, are permitted provided that the following conditions
      6  * are met:
      7  * 1. Redistributions of source code must retain the above copyright
      8  *    notice, this list of conditions and the following disclaimer.
      9  * 2. Redistributions in binary form must reproduce the above copyright
     10  *    notice, this list of conditions and the following disclaimer in the
     11  *    documentation and/or other materials provided with the distribution.
     12  *
     13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
     14  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
     15  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
     17  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     19  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     21  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     22  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
     23  * THE POSSIBILITY OF SUCH DAMAGE.
     24  */
     25 
     26 #include "config.h"
     27 #include "WebEvent.h"
     28 
     29 #include "Arguments.h"
     30 #include "WebCoreArgumentCoders.h"
     31 
     32 using namespace WebCore;
     33 
     34 namespace WebKit {
     35 
     36 WebMouseEvent::WebMouseEvent()
     37     : WebEvent()
     38     , m_button(static_cast<uint32_t>(NoButton))
     39     , m_deltaX(0)
     40     , m_deltaY(0)
     41     , m_deltaZ(0)
     42     , m_clickCount(0)
     43 #if PLATFORM(WIN)
     44     , m_didActivateWebView(false)
     45 #endif
     46 {
     47 }
     48 
     49 WebMouseEvent::WebMouseEvent(Type type, Button button, const IntPoint& position, const IntPoint& globalPosition, float deltaX, float deltaY, float deltaZ, int clickCount, Modifiers modifiers, double timestamp)
     50     : WebEvent(type, modifiers, timestamp)
     51     , m_button(button)
     52     , m_position(position)
     53     , m_globalPosition(globalPosition)
     54     , m_deltaX(deltaX)
     55     , m_deltaY(deltaY)
     56     , m_deltaZ(deltaZ)
     57     , m_clickCount(clickCount)
     58 #if PLATFORM(WIN)
     59     , m_didActivateWebView(false)
     60 #endif
     61 {
     62     ASSERT(isMouseEventType(type));
     63 }
     64 
     65 #if PLATFORM(WIN)
     66 WebMouseEvent::WebMouseEvent(Type type, Button button, const IntPoint& position, const IntPoint& globalPosition, float deltaX, float deltaY, float deltaZ, int clickCount, Modifiers modifiers, double timestamp, bool didActivateWebView)
     67     : WebEvent(type, modifiers, timestamp)
     68     , m_button(button)
     69     , m_position(position)
     70     , m_globalPosition(globalPosition)
     71     , m_deltaX(deltaX)
     72     , m_deltaY(deltaY)
     73     , m_deltaZ(deltaZ)
     74     , m_clickCount(clickCount)
     75     , m_didActivateWebView(didActivateWebView)
     76 {
     77     ASSERT(isMouseEventType(type));
     78 }
     79 #endif
     80 
     81 void WebMouseEvent::encode(CoreIPC::ArgumentEncoder* encoder) const
     82 {
     83     WebEvent::encode(encoder);
     84 
     85 #if PLATFORM(WIN)
     86     // Include m_didActivateWebView on Windows.
     87     encoder->encode(CoreIPC::In(m_button, m_position, m_globalPosition, m_deltaX, m_deltaY, m_deltaZ, m_clickCount, m_didActivateWebView));
     88 #else
     89     encoder->encode(CoreIPC::In(m_button, m_position, m_globalPosition, m_deltaX, m_deltaY, m_deltaZ, m_clickCount));
     90 #endif
     91 }
     92 
     93 bool WebMouseEvent::decode(CoreIPC::ArgumentDecoder* decoder, WebMouseEvent& t)
     94 {
     95     if (!WebEvent::decode(decoder, t))
     96         return false;
     97 
     98 #if PLATFORM(WIN)
     99     // Include m_didActivateWebView on Windows.
    100     return decoder->decode(CoreIPC::Out(t.m_button, t.m_position, t.m_globalPosition, t.m_deltaX, t.m_deltaY, t.m_deltaZ, t.m_clickCount, t.m_didActivateWebView));
    101 #else
    102     return decoder->decode(CoreIPC::Out(t.m_button, t.m_position, t.m_globalPosition, t.m_deltaX, t.m_deltaY, t.m_deltaZ, t.m_clickCount));
    103 #endif
    104 }
    105 
    106 bool WebMouseEvent::isMouseEventType(Type type)
    107 {
    108     return type == MouseDown || type == MouseUp || type == MouseMove;
    109 }
    110 
    111 } // namespace WebKit
    112