~ubuntu-branches/ubuntu/raring/qtwebkit-source/raring-proposed

« back to all changes in this revision

Viewing changes to Source/WebCore/platform/win/PlatformMouseEventWin.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2013-02-18 14:24:18 UTC
  • Revision ID: package-import@ubuntu.com-20130218142418-eon0jmjg3nj438uy
Tags: upstream-2.3
ImportĀ upstreamĀ versionĀ 2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 PlatformEvent::Type 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 PlatformEvent::MousePressed;
 
62
 
 
63
        case WM_LBUTTONUP:
 
64
        case WM_RBUTTONUP:
 
65
        case WM_MBUTTONUP:
 
66
            return PlatformEvent::MouseReleased;
 
67
 
 
68
#if !OS(WINCE)
 
69
        case WM_MOUSELEAVE:
 
70
#endif
 
71
        case WM_MOUSEMOVE:
 
72
            return PlatformEvent::MouseMoved;
 
73
 
 
74
        default:
 
75
            ASSERT_NOT_REACHED();
 
76
            //Move is relatively harmless
 
77
            return PlatformEvent::MouseMoved;
 
78
    }
 
79
}
 
80
 
 
81
PlatformMouseEvent::PlatformMouseEvent(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam, bool didActivateWebView)
 
82
    : PlatformEvent(messageToEventType(message), wParam & MK_SHIFT, wParam & MK_CONTROL, GetKeyState(VK_MENU) & HIGH_BIT_MASK_SHORT, GetKeyState(VK_MENU) & HIGH_BIT_MASK_SHORT, ::GetTickCount() * 0.001)
 
83
    , m_position(positionForEvent(hWnd, lParam))
 
84
    , m_globalPosition(globalPositionForEvent(hWnd, lParam))
 
85
    , m_clickCount(0)
 
86
    , m_didActivateWebView(didActivateWebView)
 
87
    , m_modifierFlags(wParam)
 
88
{
 
89
    switch (message) {
 
90
        case WM_LBUTTONDOWN:
 
91
        case WM_LBUTTONUP:
 
92
        case WM_LBUTTONDBLCLK:
 
93
            m_button = LeftButton;
 
94
            break;
 
95
        case WM_RBUTTONDOWN:
 
96
        case WM_RBUTTONUP:
 
97
        case WM_RBUTTONDBLCLK:
 
98
            m_button = RightButton;
 
99
            break;
 
100
        case WM_MBUTTONDOWN:
 
101
        case WM_MBUTTONUP:
 
102
        case WM_MBUTTONDBLCLK:
 
103
            m_button = MiddleButton;
 
104
            break;
 
105
        case WM_MOUSEMOVE:
 
106
#if !OS(WINCE)
 
107
        case WM_MOUSELEAVE:
 
108
#endif
 
109
            if (wParam & MK_LBUTTON)
 
110
                m_button = LeftButton;
 
111
            else if (wParam & MK_MBUTTON)
 
112
                m_button = MiddleButton;
 
113
            else if (wParam & MK_RBUTTON)
 
114
                m_button = RightButton;
 
115
            else
 
116
                m_button = NoButton;
 
117
            break;
 
118
        default:
 
119
            ASSERT_NOT_REACHED();
 
120
    }
 
121
}
 
122
 
 
123
} // namespace WebCore