OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "views/widget/widget_win.h" | 5 #include "views/widget/widget_win.h" |
6 | 6 |
7 #include <dwmapi.h> | 7 #include <dwmapi.h> |
8 | 8 |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "base/win/windows_version.h" | 10 #include "base/win/windows_version.h" |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
132 | 132 |
133 WidgetWin::WidgetWin() | 133 WidgetWin::WidgetWin() |
134 : ALLOW_THIS_IN_INITIALIZER_LIST(delegate_(this)), | 134 : ALLOW_THIS_IN_INITIALIZER_LIST(delegate_(this)), |
135 close_widget_factory_(this), | 135 close_widget_factory_(this), |
136 active_mouse_tracking_flags_(0), | 136 active_mouse_tracking_flags_(0), |
137 use_layered_buffer_(false), | 137 use_layered_buffer_(false), |
138 layered_alpha_(255), | 138 layered_alpha_(255), |
139 ALLOW_THIS_IN_INITIALIZER_LIST(paint_layered_window_factory_(this)), | 139 ALLOW_THIS_IN_INITIALIZER_LIST(paint_layered_window_factory_(this)), |
140 delete_on_destroy_(true), | 140 delete_on_destroy_(true), |
141 can_update_layered_window_(true), | 141 can_update_layered_window_(true), |
142 last_mouse_event_was_move_(false), | |
143 is_mouse_down_(false), | |
144 is_window_(false), | 142 is_window_(false), |
145 restore_focus_when_enabled_(false), | 143 restore_focus_when_enabled_(false), |
146 accessibility_view_events_index_(-1), | 144 accessibility_view_events_index_(-1), |
147 accessibility_view_events_(kMaxAccessibilityViewEvents), | 145 accessibility_view_events_(kMaxAccessibilityViewEvents), |
148 previous_cursor_(NULL) { | 146 previous_cursor_(NULL) { |
149 set_native_widget(this); | 147 set_native_widget(this); |
150 } | 148 } |
151 | 149 |
152 WidgetWin::~WidgetWin() { | 150 WidgetWin::~WidgetWin() { |
153 DestroyRootView(); | 151 DestroyRootView(); |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
315 } | 313 } |
316 | 314 |
317 TooltipManager* WidgetWin::GetTooltipManager() const { | 315 TooltipManager* WidgetWin::GetTooltipManager() const { |
318 return tooltip_manager_.get(); | 316 return tooltip_manager_.get(); |
319 } | 317 } |
320 | 318 |
321 bool WidgetWin::IsScreenReaderActive() const { | 319 bool WidgetWin::IsScreenReaderActive() const { |
322 return screen_reader_active_; | 320 return screen_reader_active_; |
323 } | 321 } |
324 | 322 |
325 void WidgetWin::SetNativeCapture() { | 323 void WidgetWin::SetMouseCapture() { |
326 DCHECK(!HasNativeCapture()); | 324 DCHECK(!HasMouseCapture()); |
327 SetCapture(hwnd()); | 325 SetCapture(hwnd()); |
328 } | 326 } |
329 | 327 |
330 void WidgetWin::ReleaseNativeCapture() { | 328 void WidgetWin::ReleaseMouseCapture() { |
331 ReleaseCapture(); | 329 ReleaseCapture(); |
332 } | 330 } |
333 | 331 |
334 bool WidgetWin::HasNativeCapture() const { | 332 bool WidgetWin::HasMouseCapture() const { |
335 return GetCapture() == hwnd(); | 333 return GetCapture() == hwnd(); |
336 } | 334 } |
337 | 335 |
336 bool WidgetWin::ShouldReleaseCaptureOnMouseReleased() const { | |
337 return true; | |
338 } | |
339 | |
338 gfx::Rect WidgetWin::GetWindowScreenBounds() const { | 340 gfx::Rect WidgetWin::GetWindowScreenBounds() const { |
339 RECT r; | 341 RECT r; |
340 GetWindowRect(&r); | 342 GetWindowRect(&r); |
341 return gfx::Rect(r); | 343 return gfx::Rect(r); |
342 } | 344 } |
343 | 345 |
344 gfx::Rect WidgetWin::GetClientAreaScreenBounds() const { | 346 gfx::Rect WidgetWin::GetClientAreaScreenBounds() const { |
345 RECT r; | 347 RECT r; |
346 GetClientRect(&r); | 348 GetClientRect(&r); |
347 POINT point = { r.left, r.top }; | 349 POINT point = { r.left, r.top }; |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
559 LRESULT WidgetWin::OnAppCommand(HWND window, short app_command, WORD device, | 561 LRESULT WidgetWin::OnAppCommand(HWND window, short app_command, WORD device, |
560 int keystate) { | 562 int keystate) { |
561 SetMsgHandled(FALSE); | 563 SetMsgHandled(FALSE); |
562 return 0; | 564 return 0; |
563 } | 565 } |
564 | 566 |
565 void WidgetWin::OnCancelMode() { | 567 void WidgetWin::OnCancelMode() { |
566 } | 568 } |
567 | 569 |
568 void WidgetWin::OnCaptureChanged(HWND hwnd) { | 570 void WidgetWin::OnCaptureChanged(HWND hwnd) { |
569 if (is_mouse_down_) | 571 ProcessMouseCaptureLost(); |
570 GetRootView()->OnMouseCaptureLost(); | |
571 is_mouse_down_ = false; | |
572 } | 572 } |
573 | 573 |
574 void WidgetWin::OnClose() { | 574 void WidgetWin::OnClose() { |
575 Close(); | 575 Close(); |
576 } | 576 } |
577 | 577 |
578 void WidgetWin::OnCommand(UINT notification_code, int command_id, HWND window) { | 578 void WidgetWin::OnCommand(UINT notification_code, int command_id, HWND window) { |
579 SetMsgHandled(FALSE); | 579 SetMsgHandled(FALSE); |
580 } | 580 } |
581 | 581 |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
743 LRESULT WidgetWin::OnMouseActivate(UINT message, | 743 LRESULT WidgetWin::OnMouseActivate(UINT message, |
744 WPARAM w_param, | 744 WPARAM w_param, |
745 LPARAM l_param) { | 745 LPARAM l_param) { |
746 if (GetWindowLong(GWL_EXSTYLE) & WS_EX_NOACTIVATE) | 746 if (GetWindowLong(GWL_EXSTYLE) & WS_EX_NOACTIVATE) |
747 return MA_NOACTIVATE; | 747 return MA_NOACTIVATE; |
748 SetMsgHandled(FALSE); | 748 SetMsgHandled(FALSE); |
749 return MA_ACTIVATE; | 749 return MA_ACTIVATE; |
750 } | 750 } |
751 | 751 |
752 LRESULT WidgetWin::OnMouseLeave(UINT message, WPARAM w_param, LPARAM l_param) { | 752 LRESULT WidgetWin::OnMouseLeave(UINT message, WPARAM w_param, LPARAM l_param) { |
753 tooltip_manager_->OnMouseLeave(); | 753 if (message != WM_NCMOUSELEAVE) |
754 ProcessMouseExited(message, w_param, l_param); | 754 tooltip_manager_->OnMouseLeave(); |
755 | |
756 MSG msg; | |
757 MakeMSG(&msg, message, w_param, l_param, 0, GET_X_LPARAM(l_param), | |
758 GET_Y_LPARAM(l_param)); | |
759 last_mouse_event_was_move_ = false; | |
760 GetRootView()->OnMouseExited(MouseEvent(msg)); | |
761 // Reset our tracking flag so that future mouse movement over this WidgetWin | |
762 // results in a new tracking session. | |
763 active_mouse_tracking_flags_ = 0; | |
755 return 0; | 764 return 0; |
756 } | 765 } |
757 | 766 |
758 LRESULT WidgetWin::OnMouseMove(UINT message, WPARAM w_param, LPARAM l_param) { | 767 LRESULT WidgetWin::OnMouseMove(UINT message, WPARAM w_param, LPARAM l_param) { |
759 ProcessMouseMoved(message, w_param, l_param); | 768 if (message == WM_NCMOUSEMOVE) |
769 tooltip_manager_->OnMouse(message, w_param, l_param); | |
770 | |
771 // Windows only fires WM_MOUSELEAVE events if the application begins | |
772 // "tracking" mouse events for a given HWND during WM_MOUSEMOVE events. | |
773 // We need to call |TrackMouseEvents| to listen for WM_MOUSELEAVE. | |
774 if (!HasMouseCapture()) | |
775 TrackMouseEvents((message == WM_NCMOUSEMOVE) ? | |
776 TME_NONCLIENT | TME_LEAVE : TME_LEAVE); | |
777 MSG msg; | |
778 MakeMSG(&msg, message, w_param, l_param, 0, GET_X_LPARAM(l_param), | |
779 GET_Y_LPARAM(l_param)); | |
780 ProcessMouseMoved(MouseEvent(msg)); | |
760 return 0; | 781 return 0; |
761 } | 782 } |
762 | 783 |
763 LRESULT WidgetWin::OnMouseRange(UINT message, WPARAM w_param, LPARAM l_param) { | 784 LRESULT WidgetWin::OnMouseRange(UINT message, WPARAM w_param, LPARAM l_param) { |
764 tooltip_manager_->OnMouse(message, w_param, l_param); | 785 MSG msg; |
786 MakeMSG(&msg, message, w_param, l_param, 0, GET_X_LPARAM(l_param), | |
787 GET_Y_LPARAM(l_param)); | |
788 MouseEvent event(msg); | |
765 | 789 |
766 switch (message) { | 790 if (!(event.flags() & ui::EF_IS_NON_CLIENT)) |
767 case WM_LBUTTONDBLCLK: | 791 tooltip_manager_->OnMouse(message, w_param, l_param); |
768 case WM_LBUTTONDOWN: | 792 |
769 case WM_MBUTTONDBLCLK: | 793 switch (event.type()) { |
770 case WM_MBUTTONDOWN: | 794 case ui::ET_MOUSE_PRESSED: |
771 case WM_RBUTTONDBLCLK: | 795 SetMsgHandled(ProcessMousePressed(event)); |
772 case WM_RBUTTONDOWN: | |
773 SetMsgHandled(ProcessMousePressed(message, w_param, l_param)); | |
774 break; | 796 break; |
775 case WM_LBUTTONUP: | 797 case ui::ET_MOUSE_RELEASED: |
776 case WM_MBUTTONUP: | 798 SetMsgHandled((event.flags() & ui::EF_IS_NON_CLIENT) ? FALSE : |
777 case WM_RBUTTONUP: | 799 ProcessMouseReleased(event)); |
Ben Goodger (Google)
2011/03/30 23:22:55
This is fine for now. I want you to eventually con
msw
2011/03/31 14:01:18
Done; I did some of this work now.
| |
778 SetMsgHandled(ProcessMouseReleased(message, w_param, l_param)); | |
779 break; | 800 break; |
780 default: | 801 default: |
781 SetMsgHandled(FALSE); | 802 SetMsgHandled(FALSE); |
782 } | 803 } |
783 | 804 |
784 return 0; | 805 return 0; |
785 } | 806 } |
786 | 807 |
787 LRESULT WidgetWin::OnMouseWheel(UINT message, WPARAM w_param, LPARAM l_param) { | 808 LRESULT WidgetWin::OnMouseWheel(UINT message, WPARAM w_param, LPARAM l_param) { |
788 // Reroute the mouse-wheel to the window under the mouse pointer if | 809 // Reroute the mouse-wheel to the window under the mouse pointer if |
(...skipping 28 matching lines...) Expand all Loading... | |
817 LRESULT WidgetWin::OnNCCalcSize(BOOL w_param, LPARAM l_param) { | 838 LRESULT WidgetWin::OnNCCalcSize(BOOL w_param, LPARAM l_param) { |
818 SetMsgHandled(FALSE); | 839 SetMsgHandled(FALSE); |
819 return 0; | 840 return 0; |
820 } | 841 } |
821 | 842 |
822 LRESULT WidgetWin::OnNCHitTest(const CPoint& pt) { | 843 LRESULT WidgetWin::OnNCHitTest(const CPoint& pt) { |
823 SetMsgHandled(FALSE); | 844 SetMsgHandled(FALSE); |
824 return 0; | 845 return 0; |
825 } | 846 } |
826 | 847 |
827 LRESULT WidgetWin::OnNCMouseLeave(UINT message, | |
828 WPARAM w_param, | |
829 LPARAM l_param) { | |
830 ProcessMouseExited(message, w_param, l_param); | |
831 return 0; | |
832 } | |
833 | |
834 LRESULT WidgetWin::OnNCMouseMove(UINT message, WPARAM w_param, LPARAM l_param) { | |
835 tooltip_manager_->OnMouse(message, w_param, l_param); | |
836 ProcessMouseMoved(message, w_param, l_param); | |
837 | |
838 // We need to process this message to stop Windows from drawing the window | |
839 // controls as the mouse moves over the title bar area when the window is | |
840 // maximized. | |
841 return 0; | |
842 } | |
843 | |
844 LRESULT WidgetWin::OnNCMouseRange(UINT message, | |
845 WPARAM w_param, | |
846 LPARAM l_param) { | |
847 switch (message) { | |
848 case WM_NCLBUTTONDBLCLK: | |
849 case WM_NCLBUTTONDOWN: | |
850 case WM_NCMBUTTONDBLCLK: | |
851 case WM_NCMBUTTONDOWN: | |
852 case WM_NCRBUTTONDBLCLK: | |
853 case WM_NCRBUTTONDOWN: | |
854 SetMsgHandled(ProcessMousePressed(message, w_param, l_param)); | |
855 break; | |
856 case WM_NCLBUTTONUP: | |
857 case WM_NCMBUTTONUP: | |
858 case WM_NCRBUTTONUP: | |
859 default: | |
860 SetMsgHandled(FALSE); | |
861 } | |
862 | |
863 return 0; | |
864 } | |
865 | |
866 void WidgetWin::OnNCPaint(HRGN rgn) { | 848 void WidgetWin::OnNCPaint(HRGN rgn) { |
867 SetMsgHandled(FALSE); | 849 SetMsgHandled(FALSE); |
868 } | 850 } |
869 | 851 |
870 LRESULT WidgetWin::OnNCUAHDrawCaption(UINT msg, | 852 LRESULT WidgetWin::OnNCUAHDrawCaption(UINT msg, |
871 WPARAM w_param, | 853 WPARAM w_param, |
872 LPARAM l_param) { | 854 LPARAM l_param) { |
873 SetMsgHandled(FALSE); | 855 SetMsgHandled(FALSE); |
874 return 0; | 856 return 0; |
875 } | 857 } |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
986 tme.dwFlags = mouse_tracking_flags; | 968 tme.dwFlags = mouse_tracking_flags; |
987 tme.hwndTrack = hwnd(); | 969 tme.hwndTrack = hwnd(); |
988 tme.dwHoverTime = 0; | 970 tme.dwHoverTime = 0; |
989 TrackMouseEvent(&tme); | 971 TrackMouseEvent(&tme); |
990 } else if (mouse_tracking_flags != active_mouse_tracking_flags_) { | 972 } else if (mouse_tracking_flags != active_mouse_tracking_flags_) { |
991 TrackMouseEvents(active_mouse_tracking_flags_ | TME_CANCEL); | 973 TrackMouseEvents(active_mouse_tracking_flags_ | TME_CANCEL); |
992 TrackMouseEvents(mouse_tracking_flags); | 974 TrackMouseEvents(mouse_tracking_flags); |
993 } | 975 } |
994 } | 976 } |
995 | 977 |
996 bool WidgetWin::ProcessMousePressed(UINT message, | |
997 WPARAM w_param, | |
998 LPARAM l_param) { | |
999 last_mouse_event_was_move_ = false; | |
1000 | |
1001 MSG msg; | |
1002 MakeMSG(&msg, message, w_param, l_param, 0, GET_X_LPARAM(l_param), | |
1003 GET_Y_LPARAM(l_param)); | |
1004 if (GetRootView()->OnMousePressed(MouseEvent(msg))) { | |
1005 is_mouse_down_ = true; | |
1006 if (!HasNativeCapture()) | |
1007 SetNativeCapture(); | |
1008 return true; | |
1009 } | |
1010 return false; | |
1011 } | |
1012 | |
1013 bool WidgetWin::ProcessMouseReleased(UINT message, | |
1014 WPARAM w_param, | |
1015 LPARAM l_param) { | |
1016 last_mouse_event_was_move_ = false; | |
1017 is_mouse_down_ = false; | |
1018 | |
1019 // Release the capture first, that way we don't get confused if | |
1020 // OnMouseReleased blocks. | |
1021 if (HasNativeCapture() && ReleaseCaptureOnMouseReleased()) | |
1022 ReleaseNativeCapture(); | |
1023 | |
1024 MSG msg; | |
1025 MakeMSG(&msg, message, w_param, l_param, 0, GET_X_LPARAM(l_param), | |
1026 GET_Y_LPARAM(l_param)); | |
1027 GetRootView()->OnMouseReleased(MouseEvent(msg)); | |
1028 return true; | |
1029 } | |
1030 | |
1031 bool WidgetWin::ProcessMouseMoved(UINT message, | |
1032 WPARAM w_param, | |
1033 LPARAM l_param) { | |
1034 // Windows only fires WM_MOUSELEAVE events if the application begins | |
1035 // "tracking" mouse events for a given HWND during WM_MOUSEMOVE events. | |
1036 // We need to call |TrackMouseEvents| to listen for WM_MOUSELEAVE. | |
1037 if (!HasNativeCapture()) | |
1038 TrackMouseEvents((message == WM_NCMOUSEMOVE) ? | |
1039 TME_NONCLIENT | TME_LEAVE : TME_LEAVE); | |
1040 MSG msg; | |
1041 MakeMSG(&msg, message, w_param, l_param, 0, GET_X_LPARAM(l_param), | |
1042 GET_Y_LPARAM(l_param)); | |
1043 if (HasNativeCapture() && is_mouse_down_) | |
1044 GetRootView()->OnMouseDragged(MouseEvent(msg)); | |
1045 else if (!last_mouse_event_was_move_ || | |
1046 (last_mouse_move_x_ != GET_X_LPARAM(l_param) || | |
1047 last_mouse_move_y_ != GET_Y_LPARAM(l_param))) { | |
1048 last_mouse_move_x_ = GET_X_LPARAM(l_param); | |
1049 last_mouse_move_y_ = GET_Y_LPARAM(l_param); | |
1050 last_mouse_event_was_move_ = true; | |
1051 GetRootView()->OnMouseMoved(MouseEvent(msg)); | |
1052 } | |
1053 return true; | |
1054 } | |
1055 | |
1056 void WidgetWin::ProcessMouseExited(UINT message, | |
1057 WPARAM w_param, | |
1058 LPARAM l_param) { | |
1059 last_mouse_event_was_move_ = false; | |
1060 MSG msg; | |
1061 MakeMSG(&msg, message, w_param, l_param, 0, GET_X_LPARAM(l_param), | |
1062 GET_Y_LPARAM(l_param)); | |
1063 GetRootView()->OnMouseExited(MouseEvent(msg)); | |
1064 // Reset our tracking flag so that future mouse movement over this WidgetWin | |
1065 // results in a new tracking session. | |
1066 active_mouse_tracking_flags_ = 0; | |
1067 } | |
1068 | |
1069 void WidgetWin::OnScreenReaderDetected() { | 978 void WidgetWin::OnScreenReaderDetected() { |
1070 screen_reader_active_ = true; | 979 screen_reader_active_ = true; |
1071 } | 980 } |
1072 | 981 |
1073 bool WidgetWin::ReleaseCaptureOnMouseReleased() { | |
1074 return true; | |
1075 } | |
1076 | |
1077 //////////////////////////////////////////////////////////////////////////////// | 982 //////////////////////////////////////////////////////////////////////////////// |
1078 // WidgetWin, private: | 983 // WidgetWin, private: |
1079 | 984 |
1080 // static | 985 // static |
1081 Window* WidgetWin::GetWindowImpl(HWND hwnd) { | 986 Window* WidgetWin::GetWindowImpl(HWND hwnd) { |
1082 // NOTE: we can't use GetAncestor here as constrained windows are a Window, | 987 // NOTE: we can't use GetAncestor here as constrained windows are a Window, |
1083 // but not a top level window. | 988 // but not a top level window. |
1084 HWND parent = hwnd; | 989 HWND parent = hwnd; |
1085 while (parent) { | 990 while (parent) { |
1086 WidgetWin* widget = | 991 WidgetWin* widget = |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1263 return; | 1168 return; |
1264 | 1169 |
1265 NativeWidget* native_widget = GetNativeWidgetForNativeView(native_view); | 1170 NativeWidget* native_widget = GetNativeWidgetForNativeView(native_view); |
1266 if (native_widget) | 1171 if (native_widget) |
1267 children->insert(native_widget); | 1172 children->insert(native_widget); |
1268 EnumChildWindows(native_view, EnumerateChildWindowsForNativeWidgets, | 1173 EnumChildWindows(native_view, EnumerateChildWindowsForNativeWidgets, |
1269 reinterpret_cast<LPARAM>(children)); | 1174 reinterpret_cast<LPARAM>(children)); |
1270 } | 1175 } |
1271 | 1176 |
1272 } // namespace views | 1177 } // namespace views |
OLD | NEW |