| 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 <shellapi.h> | 8 #include <shellapi.h> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 354 bool force_; | 354 bool force_; |
| 355 | 355 |
| 356 DISALLOW_COPY_AND_ASSIGN(ScopedRedrawLock); | 356 DISALLOW_COPY_AND_ASSIGN(ScopedRedrawLock); |
| 357 }; | 357 }; |
| 358 | 358 |
| 359 //////////////////////////////////////////////////////////////////////////////// | 359 //////////////////////////////////////////////////////////////////////////////// |
| 360 // HWNDMessageHandler, public: | 360 // HWNDMessageHandler, public: |
| 361 | 361 |
| 362 HWNDMessageHandler::HWNDMessageHandler(HWNDMessageHandlerDelegate* delegate) | 362 HWNDMessageHandler::HWNDMessageHandler(HWNDMessageHandlerDelegate* delegate) |
| 363 : delegate_(delegate), | 363 : delegate_(delegate), |
| 364 ALLOW_THIS_IN_INITIALIZER_LIST(fullscreen_handler_(new FullscreenHandler( | 364 ALLOW_THIS_IN_INITIALIZER_LIST( |
| 365 delegate->AsNativeWidgetWin()->GetWidget()))), | 365 fullscreen_handler_(new FullscreenHandler)), |
| 366 ALLOW_THIS_IN_INITIALIZER_LIST(close_widget_factory_(this)), | 366 ALLOW_THIS_IN_INITIALIZER_LIST(close_widget_factory_(this)), |
| 367 remove_standard_frame_(false), | 367 remove_standard_frame_(false), |
| 368 restore_focus_when_enabled_(false), | 368 restore_focus_when_enabled_(false), |
| 369 restored_enabled_(false), | 369 restored_enabled_(false), |
| 370 previous_cursor_(NULL), | 370 previous_cursor_(NULL), |
| 371 active_mouse_tracking_flags_(0), | 371 active_mouse_tracking_flags_(0), |
| 372 is_right_mouse_pressed_on_caption_(false), | 372 is_right_mouse_pressed_on_caption_(false), |
| 373 lock_updates_count_(0), | 373 lock_updates_count_(0), |
| 374 destroyed_(NULL), | 374 destroyed_(NULL), |
| 375 ignore_window_pos_changes_(false), | 375 ignore_window_pos_changes_(false), |
| (...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 917 // If the notification code is > 1 it means it is control specific and we | 917 // If the notification code is > 1 it means it is control specific and we |
| 918 // should ignore it. | 918 // should ignore it. |
| 919 if (notification_code > 1 || delegate_->HandleAppCommand(command)) | 919 if (notification_code > 1 || delegate_->HandleAppCommand(command)) |
| 920 SetMsgHandled(FALSE); | 920 SetMsgHandled(FALSE); |
| 921 } | 921 } |
| 922 | 922 |
| 923 LRESULT HWNDMessageHandler::OnCreate(CREATESTRUCT* create_struct) { | 923 LRESULT HWNDMessageHandler::OnCreate(CREATESTRUCT* create_struct) { |
| 924 use_layered_buffer_ = !!(delegate_->AsNativeWidgetWin()-> | 924 use_layered_buffer_ = !!(delegate_->AsNativeWidgetWin()-> |
| 925 window_ex_style() & WS_EX_LAYERED); | 925 window_ex_style() & WS_EX_LAYERED); |
| 926 | 926 |
| 927 fullscreen_handler_->set_hwnd(hwnd()); |
| 928 |
| 927 // Attempt to detect screen readers by sending an event with our custom id. | 929 // Attempt to detect screen readers by sending an event with our custom id. |
| 928 NotifyWinEvent(EVENT_SYSTEM_ALERT, hwnd(), kCustomObjectID, CHILDID_SELF); | 930 NotifyWinEvent(EVENT_SYSTEM_ALERT, hwnd(), kCustomObjectID, CHILDID_SELF); |
| 929 | 931 |
| 930 // This message initializes the window so that focus border are shown for | 932 // This message initializes the window so that focus border are shown for |
| 931 // windows. | 933 // windows. |
| 932 SendMessage(hwnd(), | 934 SendMessage(hwnd(), |
| 933 WM_CHANGEUISTATE, | 935 WM_CHANGEUISTATE, |
| 934 MAKELPARAM(UIS_CLEAR, UISF_HIDEFOCUS), | 936 MAKELPARAM(UIS_CLEAR, UISF_HIDEFOCUS), |
| 935 0); | 937 0); |
| 936 | 938 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 948 GetSystemMenu(hwnd(), false); | 950 GetSystemMenu(hwnd(), false); |
| 949 | 951 |
| 950 if (base::win::GetVersion() >= base::win::VERSION_WIN7) | 952 if (base::win::GetVersion() >= base::win::VERSION_WIN7) |
| 951 RegisterTouchWindow(hwnd(), 0); | 953 RegisterTouchWindow(hwnd(), 0); |
| 952 | 954 |
| 953 // We need to allow the delegate to size its contents since the window may not | 955 // We need to allow the delegate to size its contents since the window may not |
| 954 // receive a size notification when its initial bounds are specified at window | 956 // receive a size notification when its initial bounds are specified at window |
| 955 // creation time. | 957 // creation time. |
| 956 ClientAreaSizeChanged(); | 958 ClientAreaSizeChanged(); |
| 957 | 959 |
| 960 // We need to add ourselves as a message loop observer so that we can repaint |
| 961 // aggressively if the contents of our window become invalid. Unfortunately |
| 962 // WM_PAINT messages are starved and we get flickery redrawing when resizing |
| 963 // if we do not do this. |
| 964 MessageLoopForUI::current()->AddObserver(this); |
| 965 |
| 958 delegate_->HandleCreate(); | 966 delegate_->HandleCreate(); |
| 959 | 967 |
| 960 // TODO(beng): move more of NWW::OnCreate here. | 968 // TODO(beng): move more of NWW::OnCreate here. |
| 961 return 0; | 969 return 0; |
| 962 } | 970 } |
| 963 | 971 |
| 964 void HWNDMessageHandler::OnDestroy() { | 972 void HWNDMessageHandler::OnDestroy() { |
| 965 delegate_->HandleDestroying(); | 973 delegate_->HandleDestroying(); |
| 966 } | 974 } |
| 967 | 975 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1004 SetMsgHandled(FALSE); | 1012 SetMsgHandled(FALSE); |
| 1005 } | 1013 } |
| 1006 | 1014 |
| 1007 void HWNDMessageHandler::OnGetMinMaxInfo(MINMAXINFO* minmax_info) { | 1015 void HWNDMessageHandler::OnGetMinMaxInfo(MINMAXINFO* minmax_info) { |
| 1008 gfx::Size min_window_size; | 1016 gfx::Size min_window_size; |
| 1009 gfx::Size max_window_size; | 1017 gfx::Size max_window_size; |
| 1010 delegate_->GetMinMaxSize(&min_window_size, &max_window_size); | 1018 delegate_->GetMinMaxSize(&min_window_size, &max_window_size); |
| 1011 | 1019 |
| 1012 // Add the native frame border size to the minimum and maximum size if the | 1020 // Add the native frame border size to the minimum and maximum size if the |
| 1013 // view reports its size as the client size. | 1021 // view reports its size as the client size. |
| 1014 if (delegate_->AsNativeWidgetWin()->WidgetSizeIsClientSize()) { | 1022 if (delegate_->WidgetSizeIsClientSize()) { |
| 1015 CRect client_rect, window_rect; | 1023 CRect client_rect, window_rect; |
| 1016 GetClientRect(hwnd(), &client_rect); | 1024 GetClientRect(hwnd(), &client_rect); |
| 1017 GetWindowRect(hwnd(), &window_rect); | 1025 GetWindowRect(hwnd(), &window_rect); |
| 1018 window_rect -= client_rect; | 1026 window_rect -= client_rect; |
| 1019 min_window_size.Enlarge(window_rect.Width(), window_rect.Height()); | 1027 min_window_size.Enlarge(window_rect.Width(), window_rect.Height()); |
| 1020 if (!max_window_size.IsEmpty()) | 1028 if (!max_window_size.IsEmpty()) |
| 1021 max_window_size.Enlarge(window_rect.Width(), window_rect.Height()); | 1029 max_window_size.Enlarge(window_rect.Width(), window_rect.Height()); |
| 1022 } | 1030 } |
| 1023 minmax_info->ptMinTrackSize.x = min_window_size.width(); | 1031 minmax_info->ptMinTrackSize.x = min_window_size.width(); |
| 1024 minmax_info->ptMinTrackSize.y = min_window_size.height(); | 1032 minmax_info->ptMinTrackSize.y = min_window_size.height(); |
| (...skipping 820 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1845 return ViewsDelegate::views_delegate ? | 1853 return ViewsDelegate::views_delegate ? |
| 1846 ViewsDelegate::views_delegate->GetDefaultWindowIcon() : NULL; | 1854 ViewsDelegate::views_delegate->GetDefaultWindowIcon() : NULL; |
| 1847 } | 1855 } |
| 1848 | 1856 |
| 1849 LRESULT HWNDMessageHandler::OnWndProc(UINT message, | 1857 LRESULT HWNDMessageHandler::OnWndProc(UINT message, |
| 1850 WPARAM w_param, | 1858 WPARAM w_param, |
| 1851 LPARAM l_param) { | 1859 LPARAM l_param) { |
| 1852 HWND window = hwnd(); | 1860 HWND window = hwnd(); |
| 1853 LRESULT result = 0; | 1861 LRESULT result = 0; |
| 1854 | 1862 |
| 1863 if (delegate_->PreHandleMSG(message, w_param, l_param, &result)) |
| 1864 return result; |
| 1865 |
| 1855 // First allow messages sent by child controls to be processed directly by | 1866 // First allow messages sent by child controls to be processed directly by |
| 1856 // their associated views. If such a view is present, it will handle the | 1867 // their associated views. If such a view is present, it will handle the |
| 1857 // message *instead of* this NativeWidgetWin. | 1868 // message *instead of* this NativeWidgetWin. |
| 1858 if (ProcessChildWindowMessage(message, w_param, l_param, &result)) | 1869 if (ProcessChildWindowMessage(message, w_param, l_param, &result)) |
| 1859 return result; | 1870 return result; |
| 1860 | 1871 |
| 1861 // Otherwise we handle everything else. | 1872 // Otherwise we handle everything else. |
| 1862 if (!delegate_->AsNativeWidgetWin()->ProcessWindowMessage( | 1873 if (!delegate_->AsNativeWidgetWin()->ProcessWindowMessage( |
| 1863 window, message, w_param, l_param, result)) { | 1874 window, message, w_param, l_param, result)) { |
| 1864 result = DefWindowProc(window, message, w_param, l_param); | 1875 result = DefWindowProc(window, message, w_param, l_param); |
| 1865 } | 1876 } |
| 1866 if (message == WM_NCDESTROY) | 1877 delegate_->PostHandleMSG(message, w_param, l_param); |
| 1878 if (message == WM_NCDESTROY) { |
| 1879 MessageLoopForUI::current()->RemoveObserver(this); |
| 1867 delegate_->HandleDestroyed(); | 1880 delegate_->HandleDestroyed(); |
| 1881 } |
| 1868 | 1882 |
| 1869 // Only top level widget should store/restore focus. | 1883 // Only top level widget should store/restore focus. |
| 1870 if (message == WM_ACTIVATE && delegate_->CanSaveFocus()) | 1884 if (message == WM_ACTIVATE && delegate_->CanSaveFocus()) |
| 1871 PostProcessActivateMessage(LOWORD(w_param)); | 1885 PostProcessActivateMessage(LOWORD(w_param)); |
| 1872 if (message == WM_ENABLE && restore_focus_when_enabled_) { | 1886 if (message == WM_ENABLE && restore_focus_when_enabled_) { |
| 1873 // This path should be executed only for top level as | 1887 // This path should be executed only for top level as |
| 1874 // restore_focus_when_enabled_ is set in PostProcessActivateMessage. | 1888 // restore_focus_when_enabled_ is set in PostProcessActivateMessage. |
| 1875 DCHECK(delegate_->CanSaveFocus()); | 1889 DCHECK(delegate_->CanSaveFocus()); |
| 1876 restore_focus_when_enabled_ = false; | 1890 restore_focus_when_enabled_ = false; |
| 1877 delegate_->RestoreFocusOnEnable(); | 1891 delegate_->RestoreFocusOnEnable(); |
| 1878 } | 1892 } |
| 1879 return result; | 1893 return result; |
| 1880 } | 1894 } |
| 1881 | 1895 |
| 1896 //////////////////////////////////////////////////////////////////////////////// |
| 1897 // HWNDMessageHandler, MessageLoopForUI::Observer implementation: |
| 1898 |
| 1899 base::EventStatus HWNDMessageHandler::WillProcessEvent( |
| 1900 const base::NativeEvent& event) { |
| 1901 return base::EVENT_CONTINUE; |
| 1902 } |
| 1903 |
| 1904 void HWNDMessageHandler::DidProcessEvent(const base::NativeEvent& event) { |
| 1905 RedrawInvalidRect(); |
| 1906 } |
| 1882 | 1907 |
| 1883 //////////////////////////////////////////////////////////////////////////////// | 1908 //////////////////////////////////////////////////////////////////////////////// |
| 1884 // HWNDMessageHandler, private: | 1909 // HWNDMessageHandler, private: |
| 1885 | 1910 |
| 1886 void HWNDMessageHandler::SetInitialFocus() { | 1911 void HWNDMessageHandler::SetInitialFocus() { |
| 1887 if (!(GetWindowLong(hwnd(), GWL_EXSTYLE) & WS_EX_TRANSPARENT) && | 1912 if (!(GetWindowLong(hwnd(), GWL_EXSTYLE) & WS_EX_TRANSPARENT) && |
| 1888 !(GetWindowLong(hwnd(), GWL_EXSTYLE) & WS_EX_NOACTIVATE)) { | 1913 !(GetWindowLong(hwnd(), GWL_EXSTYLE) & WS_EX_NOACTIVATE)) { |
| 1889 // The window does not get keyboard messages unless we focus it. | 1914 // The window does not get keyboard messages unless we focus it. |
| 1890 SetFocus(hwnd()); | 1915 SetFocus(hwnd()); |
| 1891 } | 1916 } |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1953 tme.dwHoverTime = 0; | 1978 tme.dwHoverTime = 0; |
| 1954 TrackMouseEvent(&tme); | 1979 TrackMouseEvent(&tme); |
| 1955 } else if (mouse_tracking_flags != active_mouse_tracking_flags_) { | 1980 } else if (mouse_tracking_flags != active_mouse_tracking_flags_) { |
| 1956 TrackMouseEvents(active_mouse_tracking_flags_ | TME_CANCEL); | 1981 TrackMouseEvents(active_mouse_tracking_flags_ | TME_CANCEL); |
| 1957 TrackMouseEvents(mouse_tracking_flags); | 1982 TrackMouseEvents(mouse_tracking_flags); |
| 1958 } | 1983 } |
| 1959 } | 1984 } |
| 1960 | 1985 |
| 1961 void HWNDMessageHandler::ClientAreaSizeChanged() { | 1986 void HWNDMessageHandler::ClientAreaSizeChanged() { |
| 1962 RECT r = {0, 0, 0, 0}; | 1987 RECT r = {0, 0, 0, 0}; |
| 1963 if (delegate_->AsNativeWidgetWin()->WidgetSizeIsClientSize()) { | 1988 if (delegate_->WidgetSizeIsClientSize()) { |
| 1964 // TODO(beng): investigate whether this could be done | 1989 // TODO(beng): investigate whether this could be done |
| 1965 // from other branch of if-else. | 1990 // from other branch of if-else. |
| 1966 if (!IsMinimized()) | 1991 if (!IsMinimized()) |
| 1967 GetClientRect(hwnd(), &r); | 1992 GetClientRect(hwnd(), &r); |
| 1968 } else { | 1993 } else { |
| 1969 GetWindowRect(hwnd(), &r); | 1994 GetWindowRect(hwnd(), &r); |
| 1970 } | 1995 } |
| 1971 gfx::Size s(std::max(0, static_cast<int>(r.right - r.left)), | 1996 gfx::Size s(std::max(0, static_cast<int>(r.right - r.left)), |
| 1972 std::max(0, static_cast<int>(r.bottom - r.top))); | 1997 std::max(0, static_cast<int>(r.bottom - r.top))); |
| 1973 delegate_->HandleClientSizeChanged(s); | 1998 delegate_->HandleClientSizeChanged(s); |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2093 RGB(0xFF, 0xFF, 0xFF), &blend, ULW_ALPHA); | 2118 RGB(0xFF, 0xFF, 0xFF), &blend, ULW_ALPHA); |
| 2094 invalid_rect_.SetRect(0, 0, 0, 0); | 2119 invalid_rect_.SetRect(0, 0, 0, 0); |
| 2095 skia::EndPlatformPaint(layered_window_contents_->sk_canvas()); | 2120 skia::EndPlatformPaint(layered_window_contents_->sk_canvas()); |
| 2096 } | 2121 } |
| 2097 | 2122 |
| 2098 void HWNDMessageHandler::SetMsgHandled(BOOL handled) { | 2123 void HWNDMessageHandler::SetMsgHandled(BOOL handled) { |
| 2099 delegate_->AsNativeWidgetWin()->SetMsgHandled(handled); | 2124 delegate_->AsNativeWidgetWin()->SetMsgHandled(handled); |
| 2100 } | 2125 } |
| 2101 | 2126 |
| 2102 } // namespace views | 2127 } // namespace views |
| OLD | NEW |