Chromium Code Reviews| 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 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 339 is_first_nccalc_(true), | 339 is_first_nccalc_(true), |
| 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 is_pointer_in_range_(false), | |
| 349 autohide_factory_(this), | 350 autohide_factory_(this), |
| 350 weak_factory_(this) {} | 351 weak_factory_(this) {} |
| 351 | 352 |
| 352 HWNDMessageHandler::~HWNDMessageHandler() { | 353 HWNDMessageHandler::~HWNDMessageHandler() { |
| 353 delegate_ = NULL; | 354 delegate_ = NULL; |
| 354 // Prevent calls back into this class via WNDPROC now that we've been | 355 // Prevent calls back into this class via WNDPROC now that we've been |
| 355 // destroyed. | 356 // destroyed. |
| 356 ClearUserData(); | 357 ClearUserData(); |
| 357 } | 358 } |
| 358 | 359 |
| (...skipping 576 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 935 if (message == WM_ACTIVATE && IsTopLevelWindow(window)) | 936 if (message == WM_ACTIVATE && IsTopLevelWindow(window)) |
| 936 PostProcessActivateMessage(LOWORD(w_param), !!HIWORD(w_param), | 937 PostProcessActivateMessage(LOWORD(w_param), !!HIWORD(w_param), |
| 937 reinterpret_cast<HWND>(l_param)); | 938 reinterpret_cast<HWND>(l_param)); |
| 938 return result; | 939 return result; |
| 939 } | 940 } |
| 940 | 941 |
| 941 LRESULT HWNDMessageHandler::HandleMouseMessage(unsigned int message, | 942 LRESULT HWNDMessageHandler::HandleMouseMessage(unsigned int message, |
| 942 WPARAM w_param, | 943 WPARAM w_param, |
| 943 LPARAM l_param, | 944 LPARAM l_param, |
| 944 bool* handled) { | 945 bool* handled) { |
| 946 if (is_pointer_in_range_) | |
|
ananta
2017/03/09 00:37:33
Does not appear to be set anywhere.
lanwei
2017/03/09 21:05:05
It is not useful now, I deleted it.
| |
| 947 return 0; | |
| 948 | |
| 945 // Don't track forwarded mouse messages. We expect the caller to track the | 949 // Don't track forwarded mouse messages. We expect the caller to track the |
| 946 // mouse. | 950 // mouse. |
| 947 base::WeakPtr<HWNDMessageHandler> ref(weak_factory_.GetWeakPtr()); | 951 base::WeakPtr<HWNDMessageHandler> ref(weak_factory_.GetWeakPtr()); |
| 948 LRESULT ret = HandleMouseEventInternal(message, w_param, l_param, false); | 952 LRESULT ret = HandleMouseEventInternal(message, w_param, l_param, false); |
| 949 *handled = IsMsgHandled(); | 953 *handled = IsMsgHandled(); |
| 950 return ret; | 954 return ret; |
| 951 } | 955 } |
| 952 | 956 |
| 953 LRESULT HWNDMessageHandler::HandleKeyboardMessage(unsigned int message, | 957 LRESULT HWNDMessageHandler::HandleKeyboardMessage(unsigned int message, |
| 954 WPARAM w_param, | 958 WPARAM w_param, |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 967 LRESULT HWNDMessageHandler::HandleTouchMessage(unsigned int message, | 971 LRESULT HWNDMessageHandler::HandleTouchMessage(unsigned int message, |
| 968 WPARAM w_param, | 972 WPARAM w_param, |
| 969 LPARAM l_param, | 973 LPARAM l_param, |
| 970 bool* handled) { | 974 bool* handled) { |
| 971 base::WeakPtr<HWNDMessageHandler> ref(weak_factory_.GetWeakPtr()); | 975 base::WeakPtr<HWNDMessageHandler> ref(weak_factory_.GetWeakPtr()); |
| 972 LRESULT ret = OnTouchEvent(message, w_param, l_param); | 976 LRESULT ret = OnTouchEvent(message, w_param, l_param); |
| 973 *handled = IsMsgHandled(); | 977 *handled = IsMsgHandled(); |
| 974 return ret; | 978 return ret; |
| 975 } | 979 } |
| 976 | 980 |
| 981 LRESULT HWNDMessageHandler::HandlePointerMessage(unsigned int message, | |
| 982 WPARAM w_param, | |
| 983 LPARAM l_param, | |
| 984 bool* handled) { | |
| 985 base::WeakPtr<HWNDMessageHandler> ref(weak_factory_.GetWeakPtr()); | |
| 986 LRESULT ret = OnPointerEvent(message, w_param, l_param); | |
| 987 *handled = IsMsgHandled(); | |
| 988 return ret; | |
| 989 } | |
| 990 | |
| 977 LRESULT HWNDMessageHandler::HandleScrollMessage(unsigned int message, | 991 LRESULT HWNDMessageHandler::HandleScrollMessage(unsigned int message, |
| 978 WPARAM w_param, | 992 WPARAM w_param, |
| 979 LPARAM l_param, | 993 LPARAM l_param, |
| 980 bool* handled) { | 994 bool* handled) { |
| 981 base::WeakPtr<HWNDMessageHandler> ref(weak_factory_.GetWeakPtr()); | 995 base::WeakPtr<HWNDMessageHandler> ref(weak_factory_.GetWeakPtr()); |
| 982 LRESULT ret = OnScrollMessage(message, w_param, l_param); | 996 LRESULT ret = OnScrollMessage(message, w_param, l_param); |
| 983 *handled = IsMsgHandled(); | 997 *handled = IsMsgHandled(); |
| 984 return ret; | 998 return ret; |
| 985 } | 999 } |
| 986 | 1000 |
| (...skipping 648 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1635 POINTER_INPUT_TYPE pointer_type; | 1649 POINTER_INPUT_TYPE pointer_type; |
| 1636 static GetPointerTypeFn get_pointer_type = reinterpret_cast<GetPointerTypeFn>( | 1650 static GetPointerTypeFn get_pointer_type = reinterpret_cast<GetPointerTypeFn>( |
| 1637 GetProcAddress(GetModuleHandleA("user32.dll"), "GetPointerType")); | 1651 GetProcAddress(GetModuleHandleA("user32.dll"), "GetPointerType")); |
| 1638 if (get_pointer_type && get_pointer_type(pointer_id, &pointer_type) && | 1652 if (get_pointer_type && get_pointer_type(pointer_id, &pointer_type) && |
| 1639 pointer_type == PT_TOUCHPAD) | 1653 pointer_type == PT_TOUCHPAD) |
| 1640 return PA_NOACTIVATE; | 1654 return PA_NOACTIVATE; |
| 1641 SetMsgHandled(FALSE); | 1655 SetMsgHandled(FALSE); |
| 1642 return -1; | 1656 return -1; |
| 1643 } | 1657 } |
| 1644 | 1658 |
| 1659 LRESULT HWNDMessageHandler::OnPointerEvent(UINT message, | |
| 1660 WPARAM w_param, | |
| 1661 LPARAM l_param) { | |
| 1662 UINT32 pointer_id = GET_POINTERID_WPARAM(w_param); | |
| 1663 using GetPointerTypeFn = BOOL(WINAPI*)(UINT32, POINTER_INPUT_TYPE*); | |
| 1664 | |
| 1665 POINTER_INPUT_TYPE pointer_type; | |
| 1666 static GetPointerTypeFn get_pointer_type = reinterpret_cast<GetPointerTypeFn>( | |
| 1667 GetProcAddress(GetModuleHandleA("user32.dll"), "GetPointerType")); | |
| 1668 if (get_pointer_type && get_pointer_type(pointer_id, &pointer_type)) { | |
|
ananta
2017/03/09 00:37:33
If we are getting a WM_POINTER*** message then we
lanwei
2017/03/09 21:05:05
You are right, but the other places calling the Ge
| |
| 1669 if (pointer_type != PT_PEN) { | |
| 1670 SetMsgHandled(FALSE); | |
| 1671 return 0; | |
| 1672 } | |
| 1673 | |
| 1674 using GetPointerPenInfoFn = BOOL(WINAPI*)(UINT32, POINTER_PEN_INFO*); | |
| 1675 using GetPointerInfoFn = BOOL(WINAPI*)(UINT32, POINTER_INFO*); | |
| 1676 | |
| 1677 POINTER_INFO pointer_info; | |
| 1678 static GetPointerInfoFn get_pointer_info = | |
| 1679 reinterpret_cast<GetPointerInfoFn>( | |
| 1680 GetProcAddress(GetModuleHandleA("user32.dll"), "GetPointerInfo")); | |
| 1681 | |
| 1682 POINTER_PEN_INFO pointer_pen_info; | |
| 1683 static GetPointerPenInfoFn get_pointer_pen_info = | |
| 1684 reinterpret_cast<GetPointerPenInfoFn>(GetProcAddress( | |
| 1685 GetModuleHandleA("user32.dll"), "GetPointerPenInfo")); | |
| 1686 if (get_pointer_pen_info && | |
| 1687 GetPointerPenInfo(pointer_id, &pointer_pen_info)) { | |
| 1688 float pressure = (float)pointer_pen_info.pressure / 1024; | |
| 1689 float rotation = pointer_pen_info.rotation; | |
| 1690 int tiltX = pointer_pen_info.tiltX; | |
| 1691 int tiltY = pointer_pen_info.tiltY; | |
| 1692 gfx::Point point; | |
| 1693 if (get_pointer_info && get_pointer_info(pointer_id, &pointer_info)) { | |
| 1694 POINT client_point = pointer_info.ptPixelLocation; | |
| 1695 ScreenToClient(hwnd(), &client_point); | |
| 1696 point = gfx::Point(client_point.x, client_point.y); | |
| 1697 } | |
| 1698 ui::EventType event_type = ui::ET_MOUSE_MOVED; | |
|
ananta
2017/03/09 00:37:33
Please add some comments here. The code below is c
lanwei
2017/03/09 21:05:05
Yes. Touch and mouse work as before, and we are re
| |
| 1699 int flag = 0; | |
| 1700 switch (message) { | |
| 1701 case WM_POINTERDOWN: | |
| 1702 event_type = ui::ET_MOUSE_PRESSED; | |
| 1703 flag = ui::EF_LEFT_MOUSE_BUTTON; | |
| 1704 break; | |
| 1705 case WM_POINTERUP: | |
| 1706 event_type = ui::ET_MOUSE_RELEASED; | |
| 1707 flag = ui::EF_LEFT_MOUSE_BUTTON; | |
| 1708 break; | |
| 1709 case WM_POINTERUPDATE: | |
| 1710 event_type = ui::ET_MOUSE_MOVED; | |
| 1711 break; | |
| 1712 case WM_POINTERLEAVE: | |
| 1713 event_type = ui::ET_MOUSE_EXITED; | |
| 1714 break; | |
| 1715 default: | |
| 1716 break; | |
| 1717 } | |
| 1718 ui::MouseEvent event(event_type, point, point, base::TimeTicks::Now(), 0, | |
| 1719 0); | |
| 1720 event.set_flags(flag); | |
| 1721 ui::PointerDetails pointer_details(ui::EventPointerType::POINTER_TYPE_PEN, | |
| 1722 0.0f, 0.0f, pressure, tiltX, tiltY, | |
| 1723 0.0f, rotation, pointer_id); | |
| 1724 event.set_pointer_details(pointer_details); | |
| 1725 | |
| 1726 // There are cases where the code handling the message destroys the | |
| 1727 // window, so use the weak ptr to check if destruction occured or not. | |
| 1728 base::WeakPtr<HWNDMessageHandler> ref(weak_factory_.GetWeakPtr()); | |
| 1729 bool handled = delegate_->HandleMouseEvent(event); | |
| 1730 | |
| 1731 if (ref.get()) | |
| 1732 SetMsgHandled(handled); | |
| 1733 } | |
| 1734 } | |
| 1735 return 0; | |
| 1736 } | |
| 1737 | |
| 1645 void HWNDMessageHandler::OnMove(const gfx::Point& point) { | 1738 void HWNDMessageHandler::OnMove(const gfx::Point& point) { |
| 1646 delegate_->HandleMove(); | 1739 delegate_->HandleMove(); |
| 1647 SetMsgHandled(FALSE); | 1740 SetMsgHandled(FALSE); |
| 1648 } | 1741 } |
| 1649 | 1742 |
| 1650 void HWNDMessageHandler::OnMoving(UINT param, const RECT* new_bounds) { | 1743 void HWNDMessageHandler::OnMoving(UINT param, const RECT* new_bounds) { |
| 1651 delegate_->HandleMove(); | 1744 delegate_->HandleMove(); |
| 1652 } | 1745 } |
| 1653 | 1746 |
| 1654 LRESULT HWNDMessageHandler::OnNCActivate(UINT message, | 1747 LRESULT HWNDMessageHandler::OnNCActivate(UINT message, |
| (...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2161 if (!ref.get()) | 2254 if (!ref.get()) |
| 2162 return; | 2255 return; |
| 2163 in_size_loop_ = false; | 2256 in_size_loop_ = false; |
| 2164 } | 2257 } |
| 2165 } | 2258 } |
| 2166 | 2259 |
| 2167 void HWNDMessageHandler::OnThemeChanged() { | 2260 void HWNDMessageHandler::OnThemeChanged() { |
| 2168 ui::NativeThemeWin::CloseHandles(); | 2261 ui::NativeThemeWin::CloseHandles(); |
| 2169 } | 2262 } |
| 2170 | 2263 |
| 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, | 2264 LRESULT HWNDMessageHandler::OnTouchEvent(UINT message, |
| 2179 WPARAM w_param, | 2265 WPARAM w_param, |
| 2180 LPARAM l_param) { | 2266 LPARAM l_param) { |
| 2181 // Handle touch events only on Aura for now. | 2267 // Handle touch events only on Aura for now. |
| 2182 int num_points = LOWORD(w_param); | 2268 int num_points = LOWORD(w_param); |
| 2183 std::unique_ptr<TOUCHINPUT[]> input(new TOUCHINPUT[num_points]); | 2269 std::unique_ptr<TOUCHINPUT[]> input(new TOUCHINPUT[num_points]); |
| 2184 if (ui::GetTouchInputInfoWrapper(reinterpret_cast<HTOUCHINPUT>(l_param), | 2270 if (ui::GetTouchInputInfoWrapper(reinterpret_cast<HTOUCHINPUT>(l_param), |
| 2185 num_points, input.get(), | 2271 num_points, input.get(), |
| 2186 sizeof(TOUCHINPUT))) { | 2272 sizeof(TOUCHINPUT))) { |
| 2187 // input[i].dwTime doesn't necessarily relate to the system time at all, | 2273 // 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)}; | 2867 MONITORINFO monitor_info = {sizeof(monitor_info)}; |
| 2782 GetMonitorInfo(MonitorFromWindow(hwnd(), MONITOR_DEFAULTTOPRIMARY), | 2868 GetMonitorInfo(MonitorFromWindow(hwnd(), MONITOR_DEFAULTTOPRIMARY), |
| 2783 &monitor_info); | 2869 &monitor_info); |
| 2784 gfx::Rect shrunk_rect(monitor_info.rcMonitor); | 2870 gfx::Rect shrunk_rect(monitor_info.rcMonitor); |
| 2785 shrunk_rect.set_height(shrunk_rect.height() - 1); | 2871 shrunk_rect.set_height(shrunk_rect.height() - 1); |
| 2786 background_fullscreen_hack_ = true; | 2872 background_fullscreen_hack_ = true; |
| 2787 SetBoundsInternal(shrunk_rect, false); | 2873 SetBoundsInternal(shrunk_rect, false); |
| 2788 } | 2874 } |
| 2789 | 2875 |
| 2790 } // namespace views | 2876 } // namespace views |
| OLD | NEW |