2 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
3 * Copyright (C) 2007-2008 Torch Mobile Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 #include "PlatformMouseEvent.h"
30 #include <wtf/Assertions.h>
36 #define HIGH_BIT_MASK_SHORT 0x8000
38 static IntPoint positionForEvent(HWND hWnd, LPARAM lParam)
40 POINT point = {GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)};
44 static IntPoint globalPositionForEvent(HWND hWnd, LPARAM lParam)
46 POINT point = {GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)};
47 ClientToScreen(hWnd, &point);
51 static MouseEventType messageToEventType(UINT message)
54 case WM_LBUTTONDBLCLK:
55 case WM_RBUTTONDBLCLK:
56 case WM_MBUTTONDBLCLK:
57 //MSDN docs say double click is sent on mouse down
61 return MouseEventPressed;
66 return MouseEventReleased;
72 return MouseEventMoved;
76 //Move is relatively harmless
77 return MouseEventMoved;
80 PlatformMouseEvent::PlatformMouseEvent(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam, bool didActivateWebView)
81 : m_position(positionForEvent(hWnd, lParam))
82 , m_globalPosition(globalPositionForEvent(hWnd, lParam))
84 , m_shiftKey(wParam & MK_SHIFT)
85 , m_ctrlKey(wParam & MK_CONTROL)
86 , m_altKey(GetKeyState(VK_MENU) & HIGH_BIT_MASK_SHORT)
87 , m_metaKey(m_altKey) // FIXME: We'll have to test other browsers
88 , m_didActivateWebView(didActivateWebView)
89 , m_eventType(messageToEventType(message))
90 , m_modifierFlags(wParam)
92 m_timestamp = ::GetTickCount()*0.001; // GetTickCount returns milliseconds
97 case WM_LBUTTONDBLCLK:
98 m_button = LeftButton;
102 case WM_RBUTTONDBLCLK:
103 m_button = RightButton;
107 case WM_MBUTTONDBLCLK:
108 m_button = MiddleButton;
114 if (wParam & MK_LBUTTON)
115 m_button = LeftButton;
116 else if (wParam & MK_MBUTTON)
117 m_button = MiddleButton;
118 else if (wParam & MK_RBUTTON)
119 m_button = RightButton;
124 ASSERT_NOT_REACHED();
128 } // namespace WebCore