| 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> |
| (...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 }; | 313 }; |
| 314 | 314 |
| 315 // static HWNDMessageHandler member initialization. | 315 // static HWNDMessageHandler member initialization. |
| 316 base::LazyInstance<HWNDMessageHandler::FullscreenWindowMonitorMap>:: | 316 base::LazyInstance<HWNDMessageHandler::FullscreenWindowMonitorMap>:: |
| 317 DestructorAtExit HWNDMessageHandler::fullscreen_monitor_map_ = | 317 DestructorAtExit HWNDMessageHandler::fullscreen_monitor_map_ = |
| 318 LAZY_INSTANCE_INITIALIZER; | 318 LAZY_INSTANCE_INITIALIZER; |
| 319 | 319 |
| 320 //////////////////////////////////////////////////////////////////////////////// | 320 //////////////////////////////////////////////////////////////////////////////// |
| 321 // HWNDMessageHandler, public: | 321 // HWNDMessageHandler, public: |
| 322 | 322 |
| 323 long HWNDMessageHandler::last_touch_message_time_ = 0; | |
| 324 | |
| 325 HWNDMessageHandler::HWNDMessageHandler(HWNDMessageHandlerDelegate* delegate) | 323 HWNDMessageHandler::HWNDMessageHandler(HWNDMessageHandlerDelegate* delegate) |
| 326 : msg_handled_(FALSE), | 324 : msg_handled_(FALSE), |
| 327 delegate_(delegate), | 325 delegate_(delegate), |
| 328 fullscreen_handler_(new FullscreenHandler), | 326 fullscreen_handler_(new FullscreenHandler), |
| 329 waiting_for_close_now_(false), | 327 waiting_for_close_now_(false), |
| 330 use_system_default_icon_(false), | 328 use_system_default_icon_(false), |
| 331 restored_enabled_(false), | 329 restored_enabled_(false), |
| 332 current_cursor_(NULL), | 330 current_cursor_(NULL), |
| 333 previous_cursor_(NULL), | 331 previous_cursor_(NULL), |
| 334 dpi_(0), | 332 dpi_(0), |
| (...skipping 1994 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2329 // ignore touch events in the non-client area. | 2327 // ignore touch events in the non-client area. |
| 2330 LPARAM l_param_ht = MAKELPARAM(point.x, point.y); | 2328 LPARAM l_param_ht = MAKELPARAM(point.x, point.y); |
| 2331 LRESULT hittest = SendMessage(hwnd(), WM_NCHITTEST, 0, l_param_ht); | 2329 LRESULT hittest = SendMessage(hwnd(), WM_NCHITTEST, 0, l_param_ht); |
| 2332 | 2330 |
| 2333 if (hittest != HTCLIENT) | 2331 if (hittest != HTCLIENT) |
| 2334 return 0; | 2332 return 0; |
| 2335 } | 2333 } |
| 2336 | 2334 |
| 2337 ScreenToClient(hwnd(), &point); | 2335 ScreenToClient(hwnd(), &point); |
| 2338 | 2336 |
| 2339 last_touch_message_time_ = ::GetMessageTime(); | |
| 2340 | |
| 2341 gfx::Point touch_point(point.x, point.y); | 2337 gfx::Point touch_point(point.x, point.y); |
| 2342 unsigned int touch_id = id_generator_.GetGeneratedID(input[i].dwID); | 2338 unsigned int touch_id = id_generator_.GetGeneratedID(input[i].dwID); |
| 2343 | 2339 |
| 2344 if (input[i].dwFlags & TOUCHEVENTF_DOWN) { | 2340 if (input[i].dwFlags & TOUCHEVENTF_DOWN) { |
| 2345 touch_ids_.insert(input[i].dwID); | 2341 touch_ids_.insert(input[i].dwID); |
| 2346 GenerateTouchEvent(ui::ET_TOUCH_PRESSED, touch_point, touch_id, | 2342 GenerateTouchEvent(ui::ET_TOUCH_PRESSED, touch_point, touch_id, |
| 2347 event_time, &touch_events); | 2343 event_time, &touch_events); |
| 2348 touch_down_contexts_++; | 2344 touch_down_contexts_++; |
| 2349 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 2345 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 2350 FROM_HERE, base::Bind(&HWNDMessageHandler::ResetTouchDownContext, | 2346 FROM_HERE, base::Bind(&HWNDMessageHandler::ResetTouchDownContext, |
| (...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2647 // down and up are both on the caption. Note: this causes the button up to | 2643 // down and up are both on the caption. Note: this causes the button up to |
| 2648 // be WM_RBUTTONUP instead of WM_NCRBUTTONUP. | 2644 // be WM_RBUTTONUP instead of WM_NCRBUTTONUP. |
| 2649 SetCapture(); | 2645 SetCapture(); |
| 2650 } | 2646 } |
| 2651 | 2647 |
| 2652 long message_time = GetMessageTime(); | 2648 long message_time = GetMessageTime(); |
| 2653 MSG msg = { hwnd(), message, w_param, l_param, | 2649 MSG msg = { hwnd(), message, w_param, l_param, |
| 2654 static_cast<DWORD>(message_time), | 2650 static_cast<DWORD>(message_time), |
| 2655 { CR_GET_X_LPARAM(l_param), CR_GET_Y_LPARAM(l_param) } }; | 2651 { CR_GET_X_LPARAM(l_param), CR_GET_Y_LPARAM(l_param) } }; |
| 2656 ui::MouseEvent event(msg); | 2652 ui::MouseEvent event(msg); |
| 2657 if (IsSynthesizedMouseMessage(message, message_time, l_param)) | 2653 if (ui::IsMouseEventFromTouch(message)) |
| 2658 event.set_flags(event.flags() | ui::EF_FROM_TOUCH); | 2654 event.set_flags(event.flags() | ui::EF_FROM_TOUCH); |
| 2655 if (ui::IsWindowsCursorHidden()) |
| 2656 event.set_flags(event.flags() | ui::EF_CURSOR_HIDDEN); |
| 2659 | 2657 |
| 2660 if (event.type() == ui::ET_MOUSE_MOVED && !HasCapture() && track_mouse) { | 2658 if (event.type() == ui::ET_MOUSE_MOVED && !HasCapture() && track_mouse) { |
| 2661 // Windows only fires WM_MOUSELEAVE events if the application begins | 2659 // Windows only fires WM_MOUSELEAVE events if the application begins |
| 2662 // "tracking" mouse events for a given HWND during WM_MOUSEMOVE events. | 2660 // "tracking" mouse events for a given HWND during WM_MOUSEMOVE events. |
| 2663 // We need to call |TrackMouseEvents| to listen for WM_MOUSELEAVE. | 2661 // We need to call |TrackMouseEvents| to listen for WM_MOUSELEAVE. |
| 2664 TrackMouseEvents((message == WM_NCMOUSEMOVE) ? | 2662 TrackMouseEvents((message == WM_NCMOUSEMOVE) ? |
| 2665 TME_NONCLIENT | TME_LEAVE : TME_LEAVE); | 2663 TME_NONCLIENT | TME_LEAVE : TME_LEAVE); |
| 2666 } else if (event.type() == ui::ET_MOUSE_EXITED) { | 2664 } else if (event.type() == ui::ET_MOUSE_EXITED) { |
| 2667 // Reset our tracking flags so future mouse movement over this | 2665 // Reset our tracking flags so future mouse movement over this |
| 2668 // NativeWidget results in a new tracking session. Fall through for | 2666 // NativeWidget results in a new tracking session. Fall through for |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2703 // Please refer to the HandleMouseInputForCaption() function for more | 2701 // Please refer to the HandleMouseInputForCaption() function for more |
| 2704 // information. | 2702 // information. |
| 2705 if (!handled) | 2703 if (!handled) |
| 2706 handled = HandleMouseInputForCaption(message, w_param, l_param); | 2704 handled = HandleMouseInputForCaption(message, w_param, l_param); |
| 2707 | 2705 |
| 2708 if (ref.get()) | 2706 if (ref.get()) |
| 2709 SetMsgHandled(handled); | 2707 SetMsgHandled(handled); |
| 2710 return 0; | 2708 return 0; |
| 2711 } | 2709 } |
| 2712 | 2710 |
| 2713 bool HWNDMessageHandler::IsSynthesizedMouseMessage(unsigned int message, | |
| 2714 int message_time, | |
| 2715 LPARAM l_param) { | |
| 2716 if (ui::IsMouseEventFromTouch(message)) | |
| 2717 return true; | |
| 2718 // Ignore mouse messages which occur at the same location as the current | |
| 2719 // cursor position and within a time difference of 500 ms from the last | |
| 2720 // touch message. | |
| 2721 if (last_touch_message_time_ && message_time >= last_touch_message_time_ && | |
| 2722 ((message_time - last_touch_message_time_) <= | |
| 2723 kSynthesizedMouseTouchMessagesTimeDifference)) { | |
| 2724 POINT mouse_location = CR_POINT_INITIALIZER_FROM_LPARAM(l_param); | |
| 2725 ::ClientToScreen(hwnd(), &mouse_location); | |
| 2726 POINT cursor_pos = {0}; | |
| 2727 ::GetCursorPos(&cursor_pos); | |
| 2728 if (memcmp(&cursor_pos, &mouse_location, sizeof(POINT))) | |
| 2729 return false; | |
| 2730 return true; | |
| 2731 } | |
| 2732 return false; | |
| 2733 } | |
| 2734 | |
| 2735 void HWNDMessageHandler::PerformDwmTransition() { | 2711 void HWNDMessageHandler::PerformDwmTransition() { |
| 2736 dwm_transition_desired_ = false; | 2712 dwm_transition_desired_ = false; |
| 2737 | 2713 |
| 2738 UpdateDwmNcRenderingPolicy(); | 2714 UpdateDwmNcRenderingPolicy(); |
| 2739 // Don't redraw the window here, because we need to hide and show the window | 2715 // Don't redraw the window here, because we need to hide and show the window |
| 2740 // which will also trigger a redraw. | 2716 // which will also trigger a redraw. |
| 2741 ResetWindowRegion(true, false); | 2717 ResetWindowRegion(true, false); |
| 2742 // The non-client view needs to update too. | 2718 // The non-client view needs to update too. |
| 2743 delegate_->HandleFrameChanged(); | 2719 delegate_->HandleFrameChanged(); |
| 2744 | 2720 |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2913 MONITORINFO monitor_info = {sizeof(monitor_info)}; | 2889 MONITORINFO monitor_info = {sizeof(monitor_info)}; |
| 2914 GetMonitorInfo(MonitorFromWindow(hwnd(), MONITOR_DEFAULTTOPRIMARY), | 2890 GetMonitorInfo(MonitorFromWindow(hwnd(), MONITOR_DEFAULTTOPRIMARY), |
| 2915 &monitor_info); | 2891 &monitor_info); |
| 2916 gfx::Rect shrunk_rect(monitor_info.rcMonitor); | 2892 gfx::Rect shrunk_rect(monitor_info.rcMonitor); |
| 2917 shrunk_rect.set_height(shrunk_rect.height() - 1); | 2893 shrunk_rect.set_height(shrunk_rect.height() - 1); |
| 2918 background_fullscreen_hack_ = true; | 2894 background_fullscreen_hack_ = true; |
| 2919 SetBoundsInternal(shrunk_rect, false); | 2895 SetBoundsInternal(shrunk_rect, false); |
| 2920 } | 2896 } |
| 2921 | 2897 |
| 2922 } // namespace views | 2898 } // namespace views |
| OLD | NEW |