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 "config.h" 28 #include "PlatformMouseEvent.h" 29 30 #include <wtf/Assertions.h> 31 #include <windows.h> 32 #include <windowsx.h> 33 34 namespace WebCore { 35 36 #define HIGH_BIT_MASK_SHORT 0x8000 37 38 static IntPoint positionForEvent(HWND hWnd, LPARAM lParam) 39 { 40 POINT point = {GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)}; 41 return point; 42 } 43 44 static IntPoint globalPositionForEvent(HWND hWnd, LPARAM lParam) 45 { 46 POINT point = {GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)}; 47 ClientToScreen(hWnd, &point); 48 return point; 49 } 50 51 static MouseEventType messageToEventType(UINT message) 52 { 53 switch (message) { 54 case WM_LBUTTONDBLCLK: 55 case WM_RBUTTONDBLCLK: 56 case WM_MBUTTONDBLCLK: 57 //MSDN docs say double click is sent on mouse down 58 case WM_LBUTTONDOWN: 59 case WM_RBUTTONDOWN: 60 case WM_MBUTTONDOWN: 61 return MouseEventPressed; 62 63 case WM_LBUTTONUP: 64 case WM_RBUTTONUP: 65 case WM_MBUTTONUP: 66 return MouseEventReleased; 67 68 #if !OS(WINCE) 69 case WM_MOUSELEAVE: 70 #endif 71 case WM_MOUSEMOVE: 72 return MouseEventMoved; 73 74 default: 75 ASSERT_NOT_REACHED(); 76 //Move is relatively harmless 77 return MouseEventMoved; 78 } 79 } 80 PlatformMouseEvent::PlatformMouseEvent(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam, bool activatedWebView) 81 : m_position(positionForEvent(hWnd, lParam)) 82 , m_globalPosition(globalPositionForEvent(hWnd, lParam)) 83 , m_clickCount(0) 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_activatedWebView(activatedWebView) 89 , m_eventType(messageToEventType(message)) 90 , m_modifierFlags(wParam) 91 { 92 m_timestamp = ::GetTickCount()*0.001; // GetTickCount returns milliseconds 93 94 switch (message) { 95 case WM_LBUTTONDOWN: 96 case WM_LBUTTONUP: 97 case WM_LBUTTONDBLCLK: 98 m_button = LeftButton; 99 break; 100 case WM_RBUTTONDOWN: 101 case WM_RBUTTONUP: 102 case WM_RBUTTONDBLCLK: 103 m_button = RightButton; 104 break; 105 case WM_MBUTTONDOWN: 106 case WM_MBUTTONUP: 107 case WM_MBUTTONDBLCLK: 108 m_button = MiddleButton; 109 break; 110 case WM_MOUSEMOVE: 111 #if !OS(WINCE) 112 case WM_MOUSELEAVE: 113 #endif 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; 120 else 121 m_button = NoButton; 122 break; 123 default: 124 ASSERT_NOT_REACHED(); 125 } 126 } 127 128 } // namespace WebCore 129