1 /*
2 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
3 * Copyright (C) 2007-2008 Torch Mobile Inc.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
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.
13 *
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.
25 */
26
27 #include "PlatformMouseEvent.h"
28
29 #include <wtf/Assertions.h>
30 #include <windows.h>
31 #include <windowsx.h>
32
33 namespace WebCore {
34
35 #define HIGH_BIT_MASK_SHORT 0x8000
36
positionForEvent(HWND hWnd,LPARAM lParam)37 static IntPoint positionForEvent(HWND hWnd, LPARAM lParam)
38 {
39 POINT point = {GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)};
40 return point;
41 }
42
globalPositionForEvent(HWND hWnd,LPARAM lParam)43 static IntPoint globalPositionForEvent(HWND hWnd, LPARAM lParam)
44 {
45 POINT point = {GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)};
46 ClientToScreen(hWnd, &point);
47 return point;
48 }
49
messageToEventType(UINT message)50 static MouseEventType messageToEventType(UINT message)
51 {
52 switch (message) {
53 case WM_LBUTTONDBLCLK:
54 case WM_RBUTTONDBLCLK:
55 case WM_MBUTTONDBLCLK:
56 //MSDN docs say double click is sent on mouse down
57 case WM_LBUTTONDOWN:
58 case WM_RBUTTONDOWN:
59 case WM_MBUTTONDOWN:
60 return MouseEventPressed;
61
62 case WM_LBUTTONUP:
63 case WM_RBUTTONUP:
64 case WM_MBUTTONUP:
65 return MouseEventReleased;
66
67 #if !PLATFORM(WINCE)
68 case WM_MOUSELEAVE:
69 #endif
70 case WM_MOUSEMOVE:
71 return MouseEventMoved;
72
73 default:
74 ASSERT_NOT_REACHED();
75 //Move is relatively harmless
76 return MouseEventMoved;
77 }
78 }
PlatformMouseEvent(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam,bool activatedWebView)79 PlatformMouseEvent::PlatformMouseEvent(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam, bool activatedWebView)
80 : m_position(positionForEvent(hWnd, lParam))
81 , m_globalPosition(globalPositionForEvent(hWnd, lParam))
82 , m_clickCount(0)
83 , m_shiftKey(wParam & MK_SHIFT)
84 , m_ctrlKey(wParam & MK_CONTROL)
85 , m_altKey(GetKeyState(VK_MENU) & HIGH_BIT_MASK_SHORT)
86 , m_metaKey(m_altKey) // FIXME: We'll have to test other browsers
87 , m_activatedWebView(activatedWebView)
88 , m_eventType(messageToEventType(message))
89 , m_modifierFlags(wParam)
90 {
91 m_timestamp = ::GetTickCount()*0.001; // GetTickCount returns milliseconds
92
93 switch (message) {
94 case WM_LBUTTONDOWN:
95 case WM_LBUTTONUP:
96 case WM_LBUTTONDBLCLK:
97 m_button = LeftButton;
98 break;
99 case WM_RBUTTONDOWN:
100 case WM_RBUTTONUP:
101 case WM_RBUTTONDBLCLK:
102 m_button = RightButton;
103 break;
104 case WM_MBUTTONDOWN:
105 case WM_MBUTTONUP:
106 case WM_MBUTTONDBLCLK:
107 m_button = MiddleButton;
108 break;
109 case WM_MOUSEMOVE:
110 #if !PLATFORM(WINCE)
111 case WM_MOUSELEAVE:
112 #endif
113 if (wParam & MK_LBUTTON)
114 m_button = LeftButton;
115 else if (wParam & MK_MBUTTON)
116 m_button = MiddleButton;
117 else if (wParam & MK_RBUTTON)
118 m_button = RightButton;
119 else
120 m_button = NoButton;
121 break;
122 default:
123 ASSERT_NOT_REACHED();
124 }
125 }
126
127 } // namespace WebCore
128