| 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 10 matching lines...) Expand all Loading... |
| 21 #include "ui/gfx/canvas_skia_paint.h" | 21 #include "ui/gfx/canvas_skia_paint.h" |
| 22 #include "ui/gfx/icon_util.h" | 22 #include "ui/gfx/icon_util.h" |
| 23 #include "ui/gfx/insets.h" | 23 #include "ui/gfx/insets.h" |
| 24 #include "ui/gfx/path.h" | 24 #include "ui/gfx/path.h" |
| 25 #include "ui/gfx/screen.h" | 25 #include "ui/gfx/screen.h" |
| 26 #include "ui/views/accessibility/native_view_accessibility_win.h" | 26 #include "ui/views/accessibility/native_view_accessibility_win.h" |
| 27 #include "ui/views/ime/input_method_win.h" | 27 #include "ui/views/ime/input_method_win.h" |
| 28 #include "ui/views/views_delegate.h" | 28 #include "ui/views/views_delegate.h" |
| 29 #include "ui/views/widget/child_window_message_processor.h" | 29 #include "ui/views/widget/child_window_message_processor.h" |
| 30 #include "ui/views/widget/monitor_win.h" | 30 #include "ui/views/widget/monitor_win.h" |
| 31 #include "ui/views/widget/native_widget_win.h" | |
| 32 #include "ui/views/widget/widget_hwnd_utils.h" | 31 #include "ui/views/widget/widget_hwnd_utils.h" |
| 33 #include "ui/views/win/fullscreen_handler.h" | 32 #include "ui/views/win/fullscreen_handler.h" |
| 34 #include "ui/views/win/hwnd_message_handler_delegate.h" | 33 #include "ui/views/win/hwnd_message_handler_delegate.h" |
| 35 #include "ui/views/win/scoped_fullscreen_visibility.h" | 34 #include "ui/views/win/scoped_fullscreen_visibility.h" |
| 36 | 35 |
| 37 #if !defined(USE_AURA) | 36 #if !defined(USE_AURA) |
| 38 #include "base/command_line.h" | 37 #include "base/command_line.h" |
| 39 #include "ui/base/ui_base_switches.h" | 38 #include "ui/base/ui_base_switches.h" |
| 40 #endif | 39 #endif |
| 41 | 40 |
| (...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 354 bool force_; | 353 bool force_; |
| 355 | 354 |
| 356 DISALLOW_COPY_AND_ASSIGN(ScopedRedrawLock); | 355 DISALLOW_COPY_AND_ASSIGN(ScopedRedrawLock); |
| 357 }; | 356 }; |
| 358 | 357 |
| 359 //////////////////////////////////////////////////////////////////////////////// | 358 //////////////////////////////////////////////////////////////////////////////// |
| 360 // HWNDMessageHandler, public: | 359 // HWNDMessageHandler, public: |
| 361 | 360 |
| 362 HWNDMessageHandler::HWNDMessageHandler(HWNDMessageHandlerDelegate* delegate) | 361 HWNDMessageHandler::HWNDMessageHandler(HWNDMessageHandlerDelegate* delegate) |
| 363 : delegate_(delegate), | 362 : delegate_(delegate), |
| 364 ALLOW_THIS_IN_INITIALIZER_LIST(fullscreen_handler_(new FullscreenHandler( | 363 ALLOW_THIS_IN_INITIALIZER_LIST( |
| 365 delegate->AsNativeWidgetWin()->GetWidget()))), | 364 fullscreen_handler_(new FullscreenHandler)), |
| 366 ALLOW_THIS_IN_INITIALIZER_LIST(close_widget_factory_(this)), | 365 ALLOW_THIS_IN_INITIALIZER_LIST(close_widget_factory_(this)), |
| 367 remove_standard_frame_(false), | 366 remove_standard_frame_(false), |
| 368 restore_focus_when_enabled_(false), | 367 restore_focus_when_enabled_(false), |
| 369 restored_enabled_(false), | 368 restored_enabled_(false), |
| 370 previous_cursor_(NULL), | 369 previous_cursor_(NULL), |
| 371 active_mouse_tracking_flags_(0), | 370 active_mouse_tracking_flags_(0), |
| 372 is_right_mouse_pressed_on_caption_(false), | 371 is_right_mouse_pressed_on_caption_(false), |
| 373 lock_updates_count_(0), | 372 lock_updates_count_(0), |
| 374 destroyed_(NULL), | 373 destroyed_(NULL), |
| 375 ignore_window_pos_changes_(false), | 374 ignore_window_pos_changes_(false), |
| 376 ALLOW_THIS_IN_INITIALIZER_LIST(ignore_pos_changes_factory_(this)), | 375 ALLOW_THIS_IN_INITIALIZER_LIST(ignore_pos_changes_factory_(this)), |
| 377 last_monitor_(NULL), | 376 last_monitor_(NULL), |
| 378 use_layered_buffer_(false), | 377 use_layered_buffer_(false), |
| 379 layered_alpha_(255), | 378 layered_alpha_(255), |
| 380 ALLOW_THIS_IN_INITIALIZER_LIST(paint_layered_window_factory_(this)), | 379 ALLOW_THIS_IN_INITIALIZER_LIST(paint_layered_window_factory_(this)), |
| 381 can_update_layered_window_(true) { | 380 can_update_layered_window_(true) { |
| 382 } | 381 } |
| 383 | 382 |
| 384 HWNDMessageHandler::~HWNDMessageHandler() { | 383 HWNDMessageHandler::~HWNDMessageHandler() { |
| 385 if (destroyed_ != NULL) | 384 if (destroyed_ != NULL) |
| 386 *destroyed_ = true; | 385 *destroyed_ = true; |
| 387 } | 386 } |
| 388 | 387 |
| 389 void HWNDMessageHandler::Init(const gfx::Rect& bounds) { | 388 void HWNDMessageHandler::Init(HWND parent, const gfx::Rect& bounds) { |
| 390 GetMonitorAndRects(bounds.ToRECT(), &last_monitor_, &last_monitor_rect_, | 389 GetMonitorAndRects(bounds.ToRECT(), &last_monitor_, &last_monitor_rect_, |
| 391 &last_work_area_); | 390 &last_work_area_); |
| 391 // Create the window. |
| 392 WindowImpl::Init(parent, bounds); |
| 393 fullscreen_handler_->set_hwnd(hwnd()); |
| 394 |
| 395 // We need to add ourselves as a message loop observer so that we can repaint |
| 396 // aggressively if the contents of our window become invalid. Unfortunately |
| 397 // WM_PAINT messages are starved and we get flickery redrawing when resizing |
| 398 // if we do not do this. |
| 399 MessageLoopForUI::current()->AddObserver(this); |
| 392 } | 400 } |
| 393 | 401 |
| 394 void HWNDMessageHandler::InitModalType(ui::ModalType modal_type) { | 402 void HWNDMessageHandler::InitModalType(ui::ModalType modal_type) { |
| 395 if (modal_type == ui::MODAL_TYPE_NONE) | 403 if (modal_type == ui::MODAL_TYPE_NONE) |
| 396 return; | 404 return; |
| 397 // We implement modality by crawling up the hierarchy of windows starting | 405 // We implement modality by crawling up the hierarchy of windows starting |
| 398 // at the owner, disabling all of them so that they don't receive input | 406 // at the owner, disabling all of them so that they don't receive input |
| 399 // messages. | 407 // messages. |
| 400 HWND start = ::GetWindow(hwnd(), GW_OWNER); | 408 HWND start = ::GetWindow(hwnd(), GW_OWNER); |
| 401 while (start) { | 409 while (start) { |
| (...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 914 void HWNDMessageHandler::OnCommand(UINT notification_code, | 922 void HWNDMessageHandler::OnCommand(UINT notification_code, |
| 915 int command, | 923 int command, |
| 916 HWND window) { | 924 HWND window) { |
| 917 // If the notification code is > 1 it means it is control specific and we | 925 // If the notification code is > 1 it means it is control specific and we |
| 918 // should ignore it. | 926 // should ignore it. |
| 919 if (notification_code > 1 || delegate_->HandleAppCommand(command)) | 927 if (notification_code > 1 || delegate_->HandleAppCommand(command)) |
| 920 SetMsgHandled(FALSE); | 928 SetMsgHandled(FALSE); |
| 921 } | 929 } |
| 922 | 930 |
| 923 LRESULT HWNDMessageHandler::OnCreate(CREATESTRUCT* create_struct) { | 931 LRESULT HWNDMessageHandler::OnCreate(CREATESTRUCT* create_struct) { |
| 924 use_layered_buffer_ = !!(delegate_->AsNativeWidgetWin()-> | 932 use_layered_buffer_ = !!(window_ex_style() & WS_EX_LAYERED); |
| 925 window_ex_style() & WS_EX_LAYERED); | |
| 926 | 933 |
| 927 // Attempt to detect screen readers by sending an event with our custom id. | 934 // Attempt to detect screen readers by sending an event with our custom id. |
| 928 NotifyWinEvent(EVENT_SYSTEM_ALERT, hwnd(), kCustomObjectID, CHILDID_SELF); | 935 NotifyWinEvent(EVENT_SYSTEM_ALERT, hwnd(), kCustomObjectID, CHILDID_SELF); |
| 929 | 936 |
| 930 // This message initializes the window so that focus border are shown for | 937 // This message initializes the window so that focus border are shown for |
| 931 // windows. | 938 // windows. |
| 932 SendMessage(hwnd(), | 939 SendMessage(hwnd(), |
| 933 WM_CHANGEUISTATE, | 940 WM_CHANGEUISTATE, |
| 934 MAKELPARAM(UIS_CLEAR, UISF_HIDEFOCUS), | 941 MAKELPARAM(UIS_CLEAR, UISF_HIDEFOCUS), |
| 935 0); | 942 0); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 975 LPARAM l_param) { | 982 LPARAM l_param) { |
| 976 if (!delegate_->IsWidgetWindow()) { | 983 if (!delegate_->IsWidgetWindow()) { |
| 977 SetMsgHandled(FALSE); | 984 SetMsgHandled(FALSE); |
| 978 return 0; | 985 return 0; |
| 979 } | 986 } |
| 980 delegate_->HandleGlassModeChange(); | 987 delegate_->HandleGlassModeChange(); |
| 981 return 0; | 988 return 0; |
| 982 } | 989 } |
| 983 | 990 |
| 984 void HWNDMessageHandler::OnEndSession(BOOL ending, UINT logoff) { | 991 void HWNDMessageHandler::OnEndSession(BOOL ending, UINT logoff) { |
| 992 delegate_->HandleEndSession(); |
| 985 SetMsgHandled(FALSE); | 993 SetMsgHandled(FALSE); |
| 986 } | 994 } |
| 987 | 995 |
| 988 void HWNDMessageHandler::OnEnterSizeMove() { | 996 void HWNDMessageHandler::OnEnterSizeMove() { |
| 989 delegate_->HandleBeginWMSizeMove(); | 997 delegate_->HandleBeginWMSizeMove(); |
| 990 SetMsgHandled(FALSE); | 998 SetMsgHandled(FALSE); |
| 991 } | 999 } |
| 992 | 1000 |
| 993 LRESULT HWNDMessageHandler::OnEraseBkgnd(HDC dc) { | 1001 LRESULT HWNDMessageHandler::OnEraseBkgnd(HDC dc) { |
| 994 // Needed to prevent resize flicker. | 1002 // Needed to prevent resize flicker. |
| 995 return 1; | 1003 return 1; |
| 996 } | 1004 } |
| 997 | 1005 |
| 998 void HWNDMessageHandler::OnExitMenuLoop(BOOL is_track_popup_menu) { | 1006 void HWNDMessageHandler::OnExitMenuLoop(BOOL is_track_popup_menu) { |
| 999 SetMsgHandled(FALSE); | 1007 SetMsgHandled(FALSE); |
| 1000 } | 1008 } |
| 1001 | 1009 |
| 1002 void HWNDMessageHandler::OnExitSizeMove() { | 1010 void HWNDMessageHandler::OnExitSizeMove() { |
| 1003 delegate_->HandleEndWMSizeMove(); | 1011 delegate_->HandleEndWMSizeMove(); |
| 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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1092 ScopedRedrawLock lock(this); | 1100 ScopedRedrawLock lock(this); |
| 1093 EnableMenuItemByCommand(menu, SC_RESTORE, is_minimized || is_maximized); | 1101 EnableMenuItemByCommand(menu, SC_RESTORE, is_minimized || is_maximized); |
| 1094 EnableMenuItemByCommand(menu, SC_MOVE, is_restored); | 1102 EnableMenuItemByCommand(menu, SC_MOVE, is_restored); |
| 1095 EnableMenuItemByCommand(menu, SC_SIZE, delegate_->CanResize() && is_restored); | 1103 EnableMenuItemByCommand(menu, SC_SIZE, delegate_->CanResize() && is_restored); |
| 1096 EnableMenuItemByCommand(menu, SC_MAXIMIZE, delegate_->CanMaximize() && | 1104 EnableMenuItemByCommand(menu, SC_MAXIMIZE, delegate_->CanMaximize() && |
| 1097 !is_fullscreen && !is_maximized); | 1105 !is_fullscreen && !is_maximized); |
| 1098 EnableMenuItemByCommand(menu, SC_MINIMIZE, delegate_->CanMaximize() && | 1106 EnableMenuItemByCommand(menu, SC_MINIMIZE, delegate_->CanMaximize() && |
| 1099 !is_minimized); | 1107 !is_minimized); |
| 1100 } | 1108 } |
| 1101 | 1109 |
| 1102 void HWNDMessageHandler::OnInitMenuPopup() { | 1110 void HWNDMessageHandler::OnInitMenuPopup(HMENU menu, |
| 1111 UINT position, |
| 1112 BOOL is_system_menu) { |
| 1113 delegate_->HandleInitMenuPopup(); |
| 1103 SetMsgHandled(FALSE); | 1114 SetMsgHandled(FALSE); |
| 1104 } | 1115 } |
| 1105 | 1116 |
| 1106 void HWNDMessageHandler::OnInputLangChange(DWORD character_set, | 1117 void HWNDMessageHandler::OnInputLangChange(DWORD character_set, |
| 1107 HKL input_language_id) { | 1118 HKL input_language_id) { |
| 1108 InputMethod* input_method = delegate_->GetInputMethod(); | 1119 InputMethod* input_method = delegate_->GetInputMethod(); |
| 1109 if (input_method && !input_method->IsMock()) { | 1120 if (input_method && !input_method->IsMock()) { |
| 1110 static_cast<InputMethodWin*>(input_method)->OnInputLangChange( | 1121 static_cast<InputMethodWin*>(input_method)->OnInputLangChange( |
| 1111 character_set, input_language_id); | 1122 character_set, input_language_id); |
| 1112 } | 1123 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1130 | 1141 |
| 1131 InputMethod* input_method = delegate_->GetInputMethod(); | 1142 InputMethod* input_method = delegate_->GetInputMethod(); |
| 1132 if (input_method) | 1143 if (input_method) |
| 1133 input_method->OnBlur(); | 1144 input_method->OnBlur(); |
| 1134 SetMsgHandled(FALSE); | 1145 SetMsgHandled(FALSE); |
| 1135 } | 1146 } |
| 1136 | 1147 |
| 1137 LRESULT HWNDMessageHandler::OnMouseActivate(UINT message, | 1148 LRESULT HWNDMessageHandler::OnMouseActivate(UINT message, |
| 1138 WPARAM w_param, | 1149 WPARAM w_param, |
| 1139 LPARAM l_param) { | 1150 LPARAM l_param) { |
| 1151 delegate_->HandleMouseActivate(LOWORD(l_param)); |
| 1140 // TODO(beng): resolve this with the GetWindowLong() check on the subsequent | 1152 // TODO(beng): resolve this with the GetWindowLong() check on the subsequent |
| 1141 // line. | 1153 // line. |
| 1142 if (delegate_->IsWidgetWindow()) | 1154 if (delegate_->IsWidgetWindow()) |
| 1143 return delegate_->CanActivate() ? MA_ACTIVATE : MA_NOACTIVATEANDEAT; | 1155 return delegate_->CanActivate() ? MA_ACTIVATE : MA_NOACTIVATEANDEAT; |
| 1144 if (GetWindowLong(hwnd(), GWL_EXSTYLE) & WS_EX_NOACTIVATE) | 1156 if (GetWindowLong(hwnd(), GWL_EXSTYLE) & WS_EX_NOACTIVATE) |
| 1145 return MA_NOACTIVATE; | 1157 return MA_NOACTIVATE; |
| 1146 SetMsgHandled(FALSE); | 1158 SetMsgHandled(FALSE); |
| 1147 return MA_ACTIVATE; | 1159 return MA_ACTIVATE; |
| 1148 } | 1160 } |
| 1149 | 1161 |
| (...skipping 610 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1760 reinterpret_cast<LPARAM>(window_pos)); | 1772 reinterpret_cast<LPARAM>(window_pos)); |
| 1761 window_pos->cy = old_cy; | 1773 window_pos->cy = old_cy; |
| 1762 SetMsgHandled(TRUE); | 1774 SetMsgHandled(TRUE); |
| 1763 return; | 1775 return; |
| 1764 } | 1776 } |
| 1765 | 1777 |
| 1766 SetMsgHandled(FALSE); | 1778 SetMsgHandled(FALSE); |
| 1767 } | 1779 } |
| 1768 | 1780 |
| 1769 void HWNDMessageHandler::OnWindowPosChanged(WINDOWPOS* window_pos) { | 1781 void HWNDMessageHandler::OnWindowPosChanged(WINDOWPOS* window_pos) { |
| 1782 |
| 1770 if (DidClientAreaSizeChange(window_pos)) | 1783 if (DidClientAreaSizeChange(window_pos)) |
| 1771 ClientAreaSizeChanged(); | 1784 ClientAreaSizeChanged(); |
| 1772 if (remove_standard_frame_ && window_pos->flags & SWP_FRAMECHANGED && | 1785 if (window_pos->flags & SWP_FRAMECHANGED) { |
| 1773 ui::win::IsAeroGlassEnabled()) { | 1786 delegate_->HandleFrameChanged(); |
| 1774 MARGINS m = {10, 10, 10, 10}; | 1787 if (remove_standard_frame_ && ui::win::IsAeroGlassEnabled()) { |
| 1775 DwmExtendFrameIntoClientArea(hwnd(), &m); | 1788 delegate_->HandleFrameChanged(); |
| 1789 MARGINS m = {10, 10, 10, 10}; |
| 1790 DwmExtendFrameIntoClientArea(hwnd(), &m); |
| 1791 } |
| 1776 } | 1792 } |
| 1777 if (window_pos->flags & SWP_SHOWWINDOW) | 1793 if (window_pos->flags & SWP_SHOWWINDOW) |
| 1778 delegate_->HandleVisibilityChanged(true); | 1794 delegate_->HandleVisibilityChanged(true); |
| 1779 else if (window_pos->flags & SWP_HIDEWINDOW) | 1795 else if (window_pos->flags & SWP_HIDEWINDOW) |
| 1780 delegate_->HandleVisibilityChanged(false); | 1796 delegate_->HandleVisibilityChanged(false); |
| 1781 SetMsgHandled(FALSE); | 1797 SetMsgHandled(FALSE); |
| 1782 } | 1798 } |
| 1783 | 1799 |
| 1784 void HWNDMessageHandler::ResetWindowRegion(bool force) { | 1800 void HWNDMessageHandler::ResetWindowRegion(bool force) { |
| 1785 // A native frame uses the native window region, and we don't want to mess | 1801 // A native frame uses the native window region, and we don't want to mess |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1816 if (current_rgn_result == ERROR || !EqualRgn(current_rgn, new_region)) { | 1832 if (current_rgn_result == ERROR || !EqualRgn(current_rgn, new_region)) { |
| 1817 // SetWindowRgn takes ownership of the HRGN created by CreateNativeRegion. | 1833 // SetWindowRgn takes ownership of the HRGN created by CreateNativeRegion. |
| 1818 SetWindowRgn(hwnd(), new_region, TRUE); | 1834 SetWindowRgn(hwnd(), new_region, TRUE); |
| 1819 } else { | 1835 } else { |
| 1820 DeleteObject(new_region); | 1836 DeleteObject(new_region); |
| 1821 } | 1837 } |
| 1822 | 1838 |
| 1823 DeleteObject(current_rgn); | 1839 DeleteObject(current_rgn); |
| 1824 } | 1840 } |
| 1825 | 1841 |
| 1826 HWND HWNDMessageHandler::hwnd() { | |
| 1827 return delegate_->AsNativeWidgetWin()->hwnd(); | |
| 1828 } | |
| 1829 | |
| 1830 HWND HWNDMessageHandler::hwnd() const { | |
| 1831 return delegate_->AsNativeWidgetWin()->hwnd(); | |
| 1832 } | |
| 1833 | |
| 1834 //////////////////////////////////////////////////////////////////////////////// | 1842 //////////////////////////////////////////////////////////////////////////////// |
| 1835 // HWNDMessageHandler, InputMethodDelegate implementation: | 1843 // HWNDMessageHandler, InputMethodDelegate implementation: |
| 1836 | 1844 |
| 1837 void HWNDMessageHandler::DispatchKeyEventPostIME(const ui::KeyEvent& key) { | 1845 void HWNDMessageHandler::DispatchKeyEventPostIME(const ui::KeyEvent& key) { |
| 1838 SetMsgHandled(delegate_->HandleKeyEvent(key)); | 1846 SetMsgHandled(delegate_->HandleKeyEvent(key)); |
| 1839 } | 1847 } |
| 1840 | 1848 |
| 1841 //////////////////////////////////////////////////////////////////////////////// | 1849 //////////////////////////////////////////////////////////////////////////////// |
| 1842 // HWNDMessageHandler, ui::WindowImpl overrides: | 1850 // HWNDMessageHandler, ui::WindowImpl overrides: |
| 1843 | 1851 |
| 1844 HICON HWNDMessageHandler::GetDefaultWindowIcon() const { | 1852 HICON HWNDMessageHandler::GetDefaultWindowIcon() const { |
| 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_->HandleMSG(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 (!ProcessWindowMessage(window, message, w_param, l_param, result)) |
| 1863 window, message, w_param, l_param, result)) { | |
| 1864 result = DefWindowProc(window, message, w_param, l_param); | 1874 result = DefWindowProc(window, message, w_param, l_param); |
| 1875 if (message == WM_NCDESTROY) { |
| 1876 MessageLoopForUI::current()->RemoveObserver(this); |
| 1877 delegate_->HandleDestroyed(); |
| 1865 } | 1878 } |
| 1866 if (message == WM_NCDESTROY) | |
| 1867 delegate_->HandleDestroyed(); | |
| 1868 | 1879 |
| 1869 // Only top level widget should store/restore focus. | 1880 // Only top level widget should store/restore focus. |
| 1870 if (message == WM_ACTIVATE && delegate_->CanSaveFocus()) | 1881 if (message == WM_ACTIVATE && delegate_->CanSaveFocus()) |
| 1871 PostProcessActivateMessage(LOWORD(w_param)); | 1882 PostProcessActivateMessage(LOWORD(w_param)); |
| 1872 if (message == WM_ENABLE && restore_focus_when_enabled_) { | 1883 if (message == WM_ENABLE && restore_focus_when_enabled_) { |
| 1873 // This path should be executed only for top level as | 1884 // This path should be executed only for top level as |
| 1874 // restore_focus_when_enabled_ is set in PostProcessActivateMessage. | 1885 // restore_focus_when_enabled_ is set in PostProcessActivateMessage. |
| 1875 DCHECK(delegate_->CanSaveFocus()); | 1886 DCHECK(delegate_->CanSaveFocus()); |
| 1876 restore_focus_when_enabled_ = false; | 1887 restore_focus_when_enabled_ = false; |
| 1877 delegate_->RestoreFocusOnEnable(); | 1888 delegate_->RestoreFocusOnEnable(); |
| 1878 } | 1889 } |
| 1879 return result; | 1890 return result; |
| 1880 } | 1891 } |
| 1881 | 1892 |
| 1893 //////////////////////////////////////////////////////////////////////////////// |
| 1894 // HWNDMessageHandler, MessageLoop::Observer implementation: |
| 1895 |
| 1896 base::EventStatus HWNDMessageHandler::WillProcessEvent( |
| 1897 const base::NativeEvent& event) { |
| 1898 return base::EVENT_CONTINUE; |
| 1899 } |
| 1900 |
| 1901 void HWNDMessageHandler::DidProcessEvent(const base::NativeEvent& event) { |
| 1902 RedrawInvalidRect(); |
| 1903 } |
| 1882 | 1904 |
| 1883 //////////////////////////////////////////////////////////////////////////////// | 1905 //////////////////////////////////////////////////////////////////////////////// |
| 1884 // HWNDMessageHandler, private: | 1906 // HWNDMessageHandler, private: |
| 1885 | 1907 |
| 1886 void HWNDMessageHandler::SetInitialFocus() { | 1908 void HWNDMessageHandler::SetInitialFocus() { |
| 1887 if (!(GetWindowLong(hwnd(), GWL_EXSTYLE) & WS_EX_TRANSPARENT) && | 1909 if (!(GetWindowLong(hwnd(), GWL_EXSTYLE) & WS_EX_TRANSPARENT) && |
| 1888 !(GetWindowLong(hwnd(), GWL_EXSTYLE) & WS_EX_NOACTIVATE)) { | 1910 !(GetWindowLong(hwnd(), GWL_EXSTYLE) & WS_EX_NOACTIVATE)) { |
| 1889 // The window does not get keyboard messages unless we focus it. | 1911 // The window does not get keyboard messages unless we focus it. |
| 1890 SetFocus(hwnd()); | 1912 SetFocus(hwnd()); |
| 1891 } | 1913 } |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1953 tme.dwHoverTime = 0; | 1975 tme.dwHoverTime = 0; |
| 1954 TrackMouseEvent(&tme); | 1976 TrackMouseEvent(&tme); |
| 1955 } else if (mouse_tracking_flags != active_mouse_tracking_flags_) { | 1977 } else if (mouse_tracking_flags != active_mouse_tracking_flags_) { |
| 1956 TrackMouseEvents(active_mouse_tracking_flags_ | TME_CANCEL); | 1978 TrackMouseEvents(active_mouse_tracking_flags_ | TME_CANCEL); |
| 1957 TrackMouseEvents(mouse_tracking_flags); | 1979 TrackMouseEvents(mouse_tracking_flags); |
| 1958 } | 1980 } |
| 1959 } | 1981 } |
| 1960 | 1982 |
| 1961 void HWNDMessageHandler::ClientAreaSizeChanged() { | 1983 void HWNDMessageHandler::ClientAreaSizeChanged() { |
| 1962 RECT r = {0, 0, 0, 0}; | 1984 RECT r = {0, 0, 0, 0}; |
| 1963 if (delegate_->AsNativeWidgetWin()->WidgetSizeIsClientSize()) { | 1985 if (delegate_->WidgetSizeIsClientSize()) { |
| 1964 // TODO(beng): investigate whether this could be done | 1986 // TODO(beng): investigate whether this could be done |
| 1965 // from other branch of if-else. | 1987 // from other branch of if-else. |
| 1966 if (!IsMinimized()) | 1988 if (!IsMinimized()) |
| 1967 GetClientRect(hwnd(), &r); | 1989 GetClientRect(hwnd(), &r); |
| 1968 } else { | 1990 } else { |
| 1969 GetWindowRect(hwnd(), &r); | 1991 GetWindowRect(hwnd(), &r); |
| 1970 } | 1992 } |
| 1971 gfx::Size s(std::max(0, static_cast<int>(r.right - r.left)), | 1993 gfx::Size s(std::max(0, static_cast<int>(r.right - r.left)), |
| 1972 std::max(0, static_cast<int>(r.bottom - r.top))); | 1994 std::max(0, static_cast<int>(r.bottom - r.top))); |
| 1973 delegate_->HandleClientSizeChanged(s); | 1995 delegate_->HandleClientSizeChanged(s); |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2088 POINT position = {wr.left, wr.top}; | 2110 POINT position = {wr.left, wr.top}; |
| 2089 HDC dib_dc = skia::BeginPlatformPaint(layered_window_contents_->sk_canvas()); | 2111 HDC dib_dc = skia::BeginPlatformPaint(layered_window_contents_->sk_canvas()); |
| 2090 POINT zero = {0, 0}; | 2112 POINT zero = {0, 0}; |
| 2091 BLENDFUNCTION blend = {AC_SRC_OVER, 0, layered_alpha_, AC_SRC_ALPHA}; | 2113 BLENDFUNCTION blend = {AC_SRC_OVER, 0, layered_alpha_, AC_SRC_ALPHA}; |
| 2092 UpdateLayeredWindow(hwnd(), NULL, &position, &size, dib_dc, &zero, | 2114 UpdateLayeredWindow(hwnd(), NULL, &position, &size, dib_dc, &zero, |
| 2093 RGB(0xFF, 0xFF, 0xFF), &blend, ULW_ALPHA); | 2115 RGB(0xFF, 0xFF, 0xFF), &blend, ULW_ALPHA); |
| 2094 invalid_rect_.SetRect(0, 0, 0, 0); | 2116 invalid_rect_.SetRect(0, 0, 0, 0); |
| 2095 skia::EndPlatformPaint(layered_window_contents_->sk_canvas()); | 2117 skia::EndPlatformPaint(layered_window_contents_->sk_canvas()); |
| 2096 } | 2118 } |
| 2097 | 2119 |
| 2098 void HWNDMessageHandler::SetMsgHandled(BOOL handled) { | |
| 2099 delegate_->AsNativeWidgetWin()->SetMsgHandled(handled); | |
| 2100 } | |
| 2101 | |
| 2102 } // namespace views | 2120 } // namespace views |
| OLD | NEW |