OLD | NEW |
| (Empty) |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "ui/views/event_utils.h" | |
6 | |
7 #include <windowsx.h> | |
8 | |
9 #include "base/logging.h" | |
10 #include "ui/events/event.h" | |
11 #include "ui/events/event_constants.h" | |
12 #include "ui/gfx/point.h" | |
13 | |
14 namespace views { | |
15 | |
16 bool RepostLocatedEventWin(HWND window, | |
17 const ui::LocatedEvent& event) { | |
18 if (!window) | |
19 return false; | |
20 | |
21 // Determine whether the click was in the client area or not. | |
22 // NOTE: WM_NCHITTEST coordinates are relative to the screen. | |
23 const gfx::Point screen_loc = event.location(); | |
24 LRESULT nc_hit_result = SendMessage(window, WM_NCHITTEST, 0, | |
25 MAKELPARAM(screen_loc.x(), | |
26 screen_loc.y())); | |
27 const bool in_client_area = nc_hit_result == HTCLIENT; | |
28 | |
29 // TODO(sky): this isn't right. The event to generate should correspond with | |
30 // the event we just got. MouseEvent only tells us what is down, which may | |
31 // differ. Need to add ability to get changed button from MouseEvent. | |
32 int event_type; | |
33 int flags = event.flags(); | |
34 if (flags & ui::EF_LEFT_MOUSE_BUTTON) { | |
35 event_type = in_client_area ? WM_LBUTTONDOWN : WM_NCLBUTTONDOWN; | |
36 } else if (flags & ui::EF_MIDDLE_MOUSE_BUTTON) { | |
37 event_type = in_client_area ? WM_MBUTTONDOWN : WM_NCMBUTTONDOWN; | |
38 } else if (flags & ui::EF_RIGHT_MOUSE_BUTTON) { | |
39 event_type = in_client_area ? WM_RBUTTONDOWN : WM_NCRBUTTONDOWN; | |
40 } else { | |
41 NOTREACHED(); | |
42 return false; | |
43 } | |
44 | |
45 int window_x = screen_loc.x(); | |
46 int window_y = screen_loc.y(); | |
47 if (in_client_area) { | |
48 POINT pt = {window_x, window_y}; | |
49 ScreenToClient(window, &pt); | |
50 window_x = pt.x; | |
51 window_y = pt.y; | |
52 } | |
53 | |
54 WPARAM target = in_client_area ? event.native_event().wParam : nc_hit_result; | |
55 PostMessage(window, event_type, target, MAKELPARAM(window_x, window_y)); | |
56 return true; | |
57 } | |
58 | |
59 } // namespace views | |
OLD | NEW |