OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/views/win/hwnd_message_handler.h" | 5 #include "ui/views/win/hwnd_message_handler.h" |
6 | 6 |
7 #include <dwmapi.h> | 7 #include <dwmapi.h> |
8 #include <oleacc.h> | 8 #include <oleacc.h> |
9 #include <shellapi.h> | 9 #include <shellapi.h> |
10 #include <tchar.h> | 10 #include <tchar.h> |
11 | 11 |
12 #include <utility> | 12 #include <utility> |
13 | 13 |
14 #include "base/bind.h" | 14 #include "base/bind.h" |
15 #include "base/bind_helpers.h" | 15 #include "base/bind_helpers.h" |
16 #include "base/debug/alias.h" | 16 #include "base/debug/alias.h" |
17 #include "base/location.h" | 17 #include "base/location.h" |
18 #include "base/macros.h" | 18 #include "base/macros.h" |
19 #include "base/single_thread_task_runner.h" | 19 #include "base/single_thread_task_runner.h" |
20 #include "base/threading/thread_task_runner_handle.h" | 20 #include "base/threading/thread_task_runner_handle.h" |
21 #include "base/time/time.h" | |
22 #include "base/trace_event/trace_event.h" | 21 #include "base/trace_event/trace_event.h" |
23 #include "base/win/scoped_gdi_object.h" | 22 #include "base/win/scoped_gdi_object.h" |
24 #include "base/win/windows_version.h" | 23 #include "base/win/windows_version.h" |
25 #include "ui/base/view_prop.h" | 24 #include "ui/base/view_prop.h" |
26 #include "ui/base/win/internal_constants.h" | 25 #include "ui/base/win/internal_constants.h" |
27 #include "ui/base/win/lock_state.h" | 26 #include "ui/base/win/lock_state.h" |
28 #include "ui/base/win/mouse_wheel_util.h" | 27 #include "ui/base/win/mouse_wheel_util.h" |
29 #include "ui/base/win/shell.h" | 28 #include "ui/base/win/shell.h" |
30 #include "ui/base/win/touch_input.h" | 29 #include "ui/base/win/touch_input.h" |
31 #include "ui/display/win/dpi.h" | 30 #include "ui/display/win/dpi.h" |
32 #include "ui/display/win/screen_win.h" | 31 #include "ui/display/win/screen_win.h" |
33 #include "ui/events/event.h" | 32 #include "ui/events/event.h" |
33 #include "ui/events/event_constants.h" | |
34 #include "ui/events/event_utils.h" | 34 #include "ui/events/event_utils.h" |
35 #include "ui/events/keycodes/keyboard_code_conversion_win.h" | 35 #include "ui/events/keycodes/keyboard_code_conversion_win.h" |
36 #include "ui/events/win/system_event_state_lookup.h" | 36 #include "ui/events/win/system_event_state_lookup.h" |
37 #include "ui/gfx/canvas.h" | 37 #include "ui/gfx/canvas.h" |
38 #include "ui/gfx/geometry/insets.h" | 38 #include "ui/gfx/geometry/insets.h" |
39 #include "ui/gfx/icon_util.h" | 39 #include "ui/gfx/icon_util.h" |
40 #include "ui/gfx/path.h" | 40 #include "ui/gfx/path.h" |
41 #include "ui/gfx/path_win.h" | 41 #include "ui/gfx/path_win.h" |
42 #include "ui/gfx/win/direct_manipulation.h" | 42 #include "ui/gfx/win/direct_manipulation.h" |
43 #include "ui/gfx/win/hwnd_util.h" | 43 #include "ui/gfx/win/hwnd_util.h" |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
340 menu_depth_(0), | 340 menu_depth_(0), |
341 id_generator_(0), | 341 id_generator_(0), |
342 in_size_loop_(false), | 342 in_size_loop_(false), |
343 touch_down_contexts_(0), | 343 touch_down_contexts_(0), |
344 last_mouse_hwheel_time_(0), | 344 last_mouse_hwheel_time_(0), |
345 dwm_transition_desired_(false), | 345 dwm_transition_desired_(false), |
346 sent_window_size_changing_(false), | 346 sent_window_size_changing_(false), |
347 left_button_down_on_caption_(false), | 347 left_button_down_on_caption_(false), |
348 background_fullscreen_hack_(false), | 348 background_fullscreen_hack_(false), |
349 autohide_factory_(this), | 349 autohide_factory_(this), |
350 weak_factory_(this) {} | 350 weak_factory_(this) { |
351 // EnableMouseInPointer(true); | |
352 } | |
351 | 353 |
352 HWNDMessageHandler::~HWNDMessageHandler() { | 354 HWNDMessageHandler::~HWNDMessageHandler() { |
353 delegate_ = NULL; | 355 delegate_ = NULL; |
354 // Prevent calls back into this class via WNDPROC now that we've been | 356 // Prevent calls back into this class via WNDPROC now that we've been |
355 // destroyed. | 357 // destroyed. |
356 ClearUserData(); | 358 ClearUserData(); |
357 } | 359 } |
358 | 360 |
359 void HWNDMessageHandler::Init(HWND parent, const gfx::Rect& bounds) { | 361 void HWNDMessageHandler::Init(HWND parent, const gfx::Rect& bounds) { |
360 TRACE_EVENT0("views", "HWNDMessageHandler::Init"); | 362 TRACE_EVENT0("views", "HWNDMessageHandler::Init"); |
(...skipping 606 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
967 LRESULT HWNDMessageHandler::HandleTouchMessage(unsigned int message, | 969 LRESULT HWNDMessageHandler::HandleTouchMessage(unsigned int message, |
968 WPARAM w_param, | 970 WPARAM w_param, |
969 LPARAM l_param, | 971 LPARAM l_param, |
970 bool* handled) { | 972 bool* handled) { |
971 base::WeakPtr<HWNDMessageHandler> ref(weak_factory_.GetWeakPtr()); | 973 base::WeakPtr<HWNDMessageHandler> ref(weak_factory_.GetWeakPtr()); |
972 LRESULT ret = OnTouchEvent(message, w_param, l_param); | 974 LRESULT ret = OnTouchEvent(message, w_param, l_param); |
973 *handled = IsMsgHandled(); | 975 *handled = IsMsgHandled(); |
974 return ret; | 976 return ret; |
975 } | 977 } |
976 | 978 |
979 LRESULT HWNDMessageHandler::HandlePointerMessage(unsigned int message, | |
980 WPARAM w_param, | |
981 LPARAM l_param, | |
982 bool* handled) { | |
983 base::WeakPtr<HWNDMessageHandler> ref(weak_factory_.GetWeakPtr()); | |
984 LRESULT ret = OnPointerEvent(message, w_param, l_param); | |
985 *handled = IsMsgHandled(); | |
986 return ret; | |
987 } | |
988 | |
977 LRESULT HWNDMessageHandler::HandleScrollMessage(unsigned int message, | 989 LRESULT HWNDMessageHandler::HandleScrollMessage(unsigned int message, |
978 WPARAM w_param, | 990 WPARAM w_param, |
979 LPARAM l_param, | 991 LPARAM l_param, |
980 bool* handled) { | 992 bool* handled) { |
981 base::WeakPtr<HWNDMessageHandler> ref(weak_factory_.GetWeakPtr()); | 993 base::WeakPtr<HWNDMessageHandler> ref(weak_factory_.GetWeakPtr()); |
982 LRESULT ret = OnScrollMessage(message, w_param, l_param); | 994 LRESULT ret = OnScrollMessage(message, w_param, l_param); |
983 *handled = IsMsgHandled(); | 995 *handled = IsMsgHandled(); |
984 return ret; | 996 return ret; |
985 } | 997 } |
986 | 998 |
(...skipping 648 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1635 POINTER_INPUT_TYPE pointer_type; | 1647 POINTER_INPUT_TYPE pointer_type; |
1636 static GetPointerTypeFn get_pointer_type = reinterpret_cast<GetPointerTypeFn>( | 1648 static GetPointerTypeFn get_pointer_type = reinterpret_cast<GetPointerTypeFn>( |
1637 GetProcAddress(GetModuleHandleA("user32.dll"), "GetPointerType")); | 1649 GetProcAddress(GetModuleHandleA("user32.dll"), "GetPointerType")); |
1638 if (get_pointer_type && get_pointer_type(pointer_id, &pointer_type) && | 1650 if (get_pointer_type && get_pointer_type(pointer_id, &pointer_type) && |
1639 pointer_type == PT_TOUCHPAD) | 1651 pointer_type == PT_TOUCHPAD) |
1640 return PA_NOACTIVATE; | 1652 return PA_NOACTIVATE; |
1641 SetMsgHandled(FALSE); | 1653 SetMsgHandled(FALSE); |
1642 return -1; | 1654 return -1; |
1643 } | 1655 } |
1644 | 1656 |
1657 LRESULT HWNDMessageHandler::OnPointerEvent(UINT message, | |
1658 WPARAM w_param, | |
1659 LPARAM l_param) { | |
1660 UINT32 pointer_id = GET_POINTERID_WPARAM(w_param); | |
1661 POINTER_INFO pointer_info; | |
1662 if (GetPointerInfo(pointer_id, &pointer_info)) { | |
1663 POINTER_INPUT_TYPE pointer_type; | |
1664 if (GetPointerType(pointer_id, &pointer_type)) { | |
1665 if (pointer_type != PT_PEN) | |
1666 return 0; | |
1667 | |
1668 POINTER_PEN_INFO pointer_pen_info; | |
1669 if (GetPointerPenInfo(pointer_id, &pointer_pen_info)) { | |
1670 float pressure = (float)pointer_pen_info.pressure / 1024; | |
1671 float rotation = pointer_pen_info.rotation; | |
1672 int tiltX = pointer_pen_info.tiltX; | |
1673 int tiltY = pointer_pen_info.tiltY; | |
1674 POINT client_point = pointer_info.ptPixelLocation; | |
1675 ScreenToClient(hwnd(), &client_point); | |
1676 gfx::Point point(client_point.x, client_point.y); | |
1677 ui::EventType event_type = ui::ET_MOUSE_MOVED; | |
1678 int flag = 0; | |
1679 switch (message) { | |
1680 case WM_POINTERDOWN: | |
1681 event_type = ui::ET_MOUSE_PRESSED; | |
1682 flag = ui::EF_LEFT_MOUSE_BUTTON; | |
1683 break; | |
1684 case WM_POINTERUP: | |
1685 event_type = ui::ET_MOUSE_RELEASED; | |
1686 flag = ui::EF_LEFT_MOUSE_BUTTON; | |
1687 break; | |
1688 case WM_POINTERUPDATE: | |
1689 event_type = ui::ET_MOUSE_MOVED; | |
1690 break; | |
1691 case WM_POINTERLEAVE: | |
1692 event_type = ui::ET_MOUSE_EXITED; | |
1693 break; | |
1694 default: | |
1695 break; | |
1696 } | |
1697 ui::MouseEvent event(event_type, point, point, base::TimeTicks::Now(), | |
1698 0, 0); | |
1699 event.set_flags(flag); | |
1700 ui::PointerDetails pointer_details( | |
dtapuska
2017/01/23 14:15:37
We need to make another change to aura to add rot
| |
1701 ui::EventPointerType::POINTER_TYPE_PEN, 0.0f, 0.0f, pressure, tiltX, | |
1702 tiltY); | |
1703 event.set_pointer_details(pointer_details); | |
1704 | |
1705 // There are cases where the code handling the message destroys the | |
1706 // window, | |
1707 // so use the weak ptr to check if destruction occured or not. | |
1708 base::WeakPtr<HWNDMessageHandler> ref(weak_factory_.GetWeakPtr()); | |
1709 bool handled = delegate_->HandleMouseEvent(event); | |
1710 | |
1711 if (ref.get()) | |
1712 SetMsgHandled(handled); | |
dtapuska
2017/01/23 14:15:37
I wonder if you need to always return SetMsgHandle
| |
1713 } | |
1714 } | |
1715 } | |
1716 return 0; | |
1717 } | |
1718 | |
1645 void HWNDMessageHandler::OnMove(const gfx::Point& point) { | 1719 void HWNDMessageHandler::OnMove(const gfx::Point& point) { |
1646 delegate_->HandleMove(); | 1720 delegate_->HandleMove(); |
1647 SetMsgHandled(FALSE); | 1721 SetMsgHandled(FALSE); |
1648 } | 1722 } |
1649 | 1723 |
1650 void HWNDMessageHandler::OnMoving(UINT param, const RECT* new_bounds) { | 1724 void HWNDMessageHandler::OnMoving(UINT param, const RECT* new_bounds) { |
1651 delegate_->HandleMove(); | 1725 delegate_->HandleMove(); |
1652 } | 1726 } |
1653 | 1727 |
1654 LRESULT HWNDMessageHandler::OnNCActivate(UINT message, | 1728 LRESULT HWNDMessageHandler::OnNCActivate(UINT message, |
(...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2161 if (!ref.get()) | 2235 if (!ref.get()) |
2162 return; | 2236 return; |
2163 in_size_loop_ = false; | 2237 in_size_loop_ = false; |
2164 } | 2238 } |
2165 } | 2239 } |
2166 | 2240 |
2167 void HWNDMessageHandler::OnThemeChanged() { | 2241 void HWNDMessageHandler::OnThemeChanged() { |
2168 ui::NativeThemeWin::CloseHandles(); | 2242 ui::NativeThemeWin::CloseHandles(); |
2169 } | 2243 } |
2170 | 2244 |
2171 void HWNDMessageHandler::OnTimeChange() { | |
2172 // Call NowFromSystemTime() to force base::Time to re-initialize the clock | |
2173 // from system time. Otherwise base::Time::Now() might continue to reflect the | |
2174 // old system clock for some amount of time. See https://crbug.com/672906#c5 | |
2175 base::Time::NowFromSystemTime(); | |
2176 } | |
2177 | |
2178 LRESULT HWNDMessageHandler::OnTouchEvent(UINT message, | 2245 LRESULT HWNDMessageHandler::OnTouchEvent(UINT message, |
2179 WPARAM w_param, | 2246 WPARAM w_param, |
2180 LPARAM l_param) { | 2247 LPARAM l_param) { |
2181 // Handle touch events only on Aura for now. | 2248 // Handle touch events only on Aura for now. |
2182 int num_points = LOWORD(w_param); | 2249 int num_points = LOWORD(w_param); |
2183 std::unique_ptr<TOUCHINPUT[]> input(new TOUCHINPUT[num_points]); | 2250 std::unique_ptr<TOUCHINPUT[]> input(new TOUCHINPUT[num_points]); |
2184 if (ui::GetTouchInputInfoWrapper(reinterpret_cast<HTOUCHINPUT>(l_param), | 2251 if (ui::GetTouchInputInfoWrapper(reinterpret_cast<HTOUCHINPUT>(l_param), |
2185 num_points, input.get(), | 2252 num_points, input.get(), |
2186 sizeof(TOUCHINPUT))) { | 2253 sizeof(TOUCHINPUT))) { |
2187 // input[i].dwTime doesn't necessarily relate to the system time at all, | 2254 // input[i].dwTime doesn't necessarily relate to the system time at all, |
(...skipping 593 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2781 MONITORINFO monitor_info = {sizeof(monitor_info)}; | 2848 MONITORINFO monitor_info = {sizeof(monitor_info)}; |
2782 GetMonitorInfo(MonitorFromWindow(hwnd(), MONITOR_DEFAULTTOPRIMARY), | 2849 GetMonitorInfo(MonitorFromWindow(hwnd(), MONITOR_DEFAULTTOPRIMARY), |
2783 &monitor_info); | 2850 &monitor_info); |
2784 gfx::Rect shrunk_rect(monitor_info.rcMonitor); | 2851 gfx::Rect shrunk_rect(monitor_info.rcMonitor); |
2785 shrunk_rect.set_height(shrunk_rect.height() - 1); | 2852 shrunk_rect.set_height(shrunk_rect.height() - 1); |
2786 background_fullscreen_hack_ = true; | 2853 background_fullscreen_hack_ = true; |
2787 SetBoundsInternal(shrunk_rect, false); | 2854 SetBoundsInternal(shrunk_rect, false); |
2788 } | 2855 } |
2789 | 2856 |
2790 } // namespace views | 2857 } // namespace views |
OLD | NEW |