| 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 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 379 layered_alpha_(255), | 379 layered_alpha_(255), |
| 380 ALLOW_THIS_IN_INITIALIZER_LIST(paint_layered_window_factory_(this)), | 380 ALLOW_THIS_IN_INITIALIZER_LIST(paint_layered_window_factory_(this)), |
| 381 can_update_layered_window_(true) { | 381 can_update_layered_window_(true) { |
| 382 } | 382 } |
| 383 | 383 |
| 384 HWNDMessageHandler::~HWNDMessageHandler() { | 384 HWNDMessageHandler::~HWNDMessageHandler() { |
| 385 if (destroyed_ != NULL) | 385 if (destroyed_ != NULL) |
| 386 *destroyed_ = true; | 386 *destroyed_ = true; |
| 387 } | 387 } |
| 388 | 388 |
| 389 void HWNDMessageHandler::Init(const gfx::Rect& bounds) { | 389 void HWNDMessageHandler::Init(HWND parent, const gfx::Rect& bounds) { |
| 390 GetMonitorAndRects(bounds.ToRECT(), &last_monitor_, &last_monitor_rect_, | 390 GetMonitorAndRects(bounds.ToRECT(), &last_monitor_, &last_monitor_rect_, |
| 391 &last_work_area_); | 391 &last_work_area_); |
| 392 |
| 393 // Create the window. |
| 394 WindowImpl::Init(parent, bounds); |
| 392 } | 395 } |
| 393 | 396 |
| 394 void HWNDMessageHandler::InitModalType(ui::ModalType modal_type) { | 397 void HWNDMessageHandler::InitModalType(ui::ModalType modal_type) { |
| 395 if (modal_type == ui::MODAL_TYPE_NONE) | 398 if (modal_type == ui::MODAL_TYPE_NONE) |
| 396 return; | 399 return; |
| 397 // We implement modality by crawling up the hierarchy of windows starting | 400 // 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 | 401 // at the owner, disabling all of them so that they don't receive input |
| 399 // messages. | 402 // messages. |
| 400 HWND start = ::GetWindow(hwnd(), GW_OWNER); | 403 HWND start = ::GetWindow(hwnd(), GW_OWNER); |
| 401 while (start) { | 404 while (start) { |
| (...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 914 void HWNDMessageHandler::OnCommand(UINT notification_code, | 917 void HWNDMessageHandler::OnCommand(UINT notification_code, |
| 915 int command, | 918 int command, |
| 916 HWND window) { | 919 HWND window) { |
| 917 // If the notification code is > 1 it means it is control specific and we | 920 // If the notification code is > 1 it means it is control specific and we |
| 918 // should ignore it. | 921 // should ignore it. |
| 919 if (notification_code > 1 || delegate_->HandleAppCommand(command)) | 922 if (notification_code > 1 || delegate_->HandleAppCommand(command)) |
| 920 SetMsgHandled(FALSE); | 923 SetMsgHandled(FALSE); |
| 921 } | 924 } |
| 922 | 925 |
| 923 LRESULT HWNDMessageHandler::OnCreate(CREATESTRUCT* create_struct) { | 926 LRESULT HWNDMessageHandler::OnCreate(CREATESTRUCT* create_struct) { |
| 924 use_layered_buffer_ = !!(delegate_->AsNativeWidgetWin()-> | 927 use_layered_buffer_ = !!(window_ex_style() & WS_EX_LAYERED); |
| 925 window_ex_style() & WS_EX_LAYERED); | |
| 926 | 928 |
| 927 fullscreen_handler_->set_hwnd(hwnd()); | 929 fullscreen_handler_->set_hwnd(hwnd()); |
| 928 | 930 |
| 929 // Attempt to detect screen readers by sending an event with our custom id. | 931 // Attempt to detect screen readers by sending an event with our custom id. |
| 930 NotifyWinEvent(EVENT_SYSTEM_ALERT, hwnd(), kCustomObjectID, CHILDID_SELF); | 932 NotifyWinEvent(EVENT_SYSTEM_ALERT, hwnd(), kCustomObjectID, CHILDID_SELF); |
| 931 | 933 |
| 932 // This message initializes the window so that focus border are shown for | 934 // This message initializes the window so that focus border are shown for |
| 933 // windows. | 935 // windows. |
| 934 SendMessage(hwnd(), | 936 SendMessage(hwnd(), |
| 935 WM_CHANGEUISTATE, | 937 WM_CHANGEUISTATE, |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1100 ScopedRedrawLock lock(this); | 1102 ScopedRedrawLock lock(this); |
| 1101 EnableMenuItemByCommand(menu, SC_RESTORE, is_minimized || is_maximized); | 1103 EnableMenuItemByCommand(menu, SC_RESTORE, is_minimized || is_maximized); |
| 1102 EnableMenuItemByCommand(menu, SC_MOVE, is_restored); | 1104 EnableMenuItemByCommand(menu, SC_MOVE, is_restored); |
| 1103 EnableMenuItemByCommand(menu, SC_SIZE, delegate_->CanResize() && is_restored); | 1105 EnableMenuItemByCommand(menu, SC_SIZE, delegate_->CanResize() && is_restored); |
| 1104 EnableMenuItemByCommand(menu, SC_MAXIMIZE, delegate_->CanMaximize() && | 1106 EnableMenuItemByCommand(menu, SC_MAXIMIZE, delegate_->CanMaximize() && |
| 1105 !is_fullscreen && !is_maximized); | 1107 !is_fullscreen && !is_maximized); |
| 1106 EnableMenuItemByCommand(menu, SC_MINIMIZE, delegate_->CanMaximize() && | 1108 EnableMenuItemByCommand(menu, SC_MINIMIZE, delegate_->CanMaximize() && |
| 1107 !is_minimized); | 1109 !is_minimized); |
| 1108 } | 1110 } |
| 1109 | 1111 |
| 1110 void HWNDMessageHandler::OnInitMenuPopup() { | 1112 void HWNDMessageHandler::OnInitMenuPopup(HMENU menu, |
| 1113 UINT position, |
| 1114 BOOL is_system_menu) { |
| 1111 SetMsgHandled(FALSE); | 1115 SetMsgHandled(FALSE); |
| 1112 } | 1116 } |
| 1113 | 1117 |
| 1114 void HWNDMessageHandler::OnInputLangChange(DWORD character_set, | 1118 void HWNDMessageHandler::OnInputLangChange(DWORD character_set, |
| 1115 HKL input_language_id) { | 1119 HKL input_language_id) { |
| 1116 InputMethod* input_method = delegate_->GetInputMethod(); | 1120 InputMethod* input_method = delegate_->GetInputMethod(); |
| 1117 if (input_method && !input_method->IsMock()) { | 1121 if (input_method && !input_method->IsMock()) { |
| 1118 static_cast<InputMethodWin*>(input_method)->OnInputLangChange( | 1122 static_cast<InputMethodWin*>(input_method)->OnInputLangChange( |
| 1119 character_set, input_language_id); | 1123 character_set, input_language_id); |
| 1120 } | 1124 } |
| (...skipping 703 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1824 if (current_rgn_result == ERROR || !EqualRgn(current_rgn, new_region)) { | 1828 if (current_rgn_result == ERROR || !EqualRgn(current_rgn, new_region)) { |
| 1825 // SetWindowRgn takes ownership of the HRGN created by CreateNativeRegion. | 1829 // SetWindowRgn takes ownership of the HRGN created by CreateNativeRegion. |
| 1826 SetWindowRgn(hwnd(), new_region, TRUE); | 1830 SetWindowRgn(hwnd(), new_region, TRUE); |
| 1827 } else { | 1831 } else { |
| 1828 DeleteObject(new_region); | 1832 DeleteObject(new_region); |
| 1829 } | 1833 } |
| 1830 | 1834 |
| 1831 DeleteObject(current_rgn); | 1835 DeleteObject(current_rgn); |
| 1832 } | 1836 } |
| 1833 | 1837 |
| 1834 HWND HWNDMessageHandler::hwnd() { | |
| 1835 return delegate_->AsNativeWidgetWin()->hwnd(); | |
| 1836 } | |
| 1837 | |
| 1838 HWND HWNDMessageHandler::hwnd() const { | |
| 1839 return delegate_->AsNativeWidgetWin()->hwnd(); | |
| 1840 } | |
| 1841 | |
| 1842 //////////////////////////////////////////////////////////////////////////////// | 1838 //////////////////////////////////////////////////////////////////////////////// |
| 1843 // HWNDMessageHandler, InputMethodDelegate implementation: | 1839 // HWNDMessageHandler, InputMethodDelegate implementation: |
| 1844 | 1840 |
| 1845 void HWNDMessageHandler::DispatchKeyEventPostIME(const ui::KeyEvent& key) { | 1841 void HWNDMessageHandler::DispatchKeyEventPostIME(const ui::KeyEvent& key) { |
| 1846 SetMsgHandled(delegate_->HandleKeyEvent(key)); | 1842 SetMsgHandled(delegate_->HandleKeyEvent(key)); |
| 1847 } | 1843 } |
| 1848 | 1844 |
| 1849 //////////////////////////////////////////////////////////////////////////////// | 1845 //////////////////////////////////////////////////////////////////////////////// |
| 1850 // HWNDMessageHandler, ui::WindowImpl overrides: | 1846 // HWNDMessageHandler, ui::WindowImpl overrides: |
| 1851 | 1847 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1863 if (delegate_->PreHandleMSG(message, w_param, l_param, &result)) | 1859 if (delegate_->PreHandleMSG(message, w_param, l_param, &result)) |
| 1864 return result; | 1860 return result; |
| 1865 | 1861 |
| 1866 // First allow messages sent by child controls to be processed directly by | 1862 // First allow messages sent by child controls to be processed directly by |
| 1867 // their associated views. If such a view is present, it will handle the | 1863 // their associated views. If such a view is present, it will handle the |
| 1868 // message *instead of* this NativeWidgetWin. | 1864 // message *instead of* this NativeWidgetWin. |
| 1869 if (ProcessChildWindowMessage(message, w_param, l_param, &result)) | 1865 if (ProcessChildWindowMessage(message, w_param, l_param, &result)) |
| 1870 return result; | 1866 return result; |
| 1871 | 1867 |
| 1872 // Otherwise we handle everything else. | 1868 // Otherwise we handle everything else. |
| 1873 if (!delegate_->AsNativeWidgetWin()->ProcessWindowMessage( | 1869 if (!ProcessWindowMessage(window, message, w_param, l_param, result)) |
| 1874 window, message, w_param, l_param, result)) { | |
| 1875 result = DefWindowProc(window, message, w_param, l_param); | 1870 result = DefWindowProc(window, message, w_param, l_param); |
| 1876 } | |
| 1877 delegate_->PostHandleMSG(message, w_param, l_param); | 1871 delegate_->PostHandleMSG(message, w_param, l_param); |
| 1878 if (message == WM_NCDESTROY) { | 1872 if (message == WM_NCDESTROY) { |
| 1879 MessageLoopForUI::current()->RemoveObserver(this); | 1873 MessageLoopForUI::current()->RemoveObserver(this); |
| 1880 delegate_->HandleDestroyed(); | 1874 delegate_->HandleDestroyed(); |
| 1881 } | 1875 } |
| 1882 | 1876 |
| 1883 // Only top level widget should store/restore focus. | 1877 // Only top level widget should store/restore focus. |
| 1884 if (message == WM_ACTIVATE && delegate_->CanSaveFocus()) | 1878 if (message == WM_ACTIVATE && delegate_->CanSaveFocus()) |
| 1885 PostProcessActivateMessage(LOWORD(w_param)); | 1879 PostProcessActivateMessage(LOWORD(w_param)); |
| 1886 if (message == WM_ENABLE && restore_focus_when_enabled_) { | 1880 if (message == WM_ENABLE && restore_focus_when_enabled_) { |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2113 POINT position = {wr.left, wr.top}; | 2107 POINT position = {wr.left, wr.top}; |
| 2114 HDC dib_dc = skia::BeginPlatformPaint(layered_window_contents_->sk_canvas()); | 2108 HDC dib_dc = skia::BeginPlatformPaint(layered_window_contents_->sk_canvas()); |
| 2115 POINT zero = {0, 0}; | 2109 POINT zero = {0, 0}; |
| 2116 BLENDFUNCTION blend = {AC_SRC_OVER, 0, layered_alpha_, AC_SRC_ALPHA}; | 2110 BLENDFUNCTION blend = {AC_SRC_OVER, 0, layered_alpha_, AC_SRC_ALPHA}; |
| 2117 UpdateLayeredWindow(hwnd(), NULL, &position, &size, dib_dc, &zero, | 2111 UpdateLayeredWindow(hwnd(), NULL, &position, &size, dib_dc, &zero, |
| 2118 RGB(0xFF, 0xFF, 0xFF), &blend, ULW_ALPHA); | 2112 RGB(0xFF, 0xFF, 0xFF), &blend, ULW_ALPHA); |
| 2119 invalid_rect_.SetRect(0, 0, 0, 0); | 2113 invalid_rect_.SetRect(0, 0, 0, 0); |
| 2120 skia::EndPlatformPaint(layered_window_contents_->sk_canvas()); | 2114 skia::EndPlatformPaint(layered_window_contents_->sk_canvas()); |
| 2121 } | 2115 } |
| 2122 | 2116 |
| 2123 void HWNDMessageHandler::SetMsgHandled(BOOL handled) { | |
| 2124 delegate_->AsNativeWidgetWin()->SetMsgHandled(handled); | |
| 2125 } | |
| 2126 | |
| 2127 } // namespace views | 2117 } // namespace views |
| OLD | NEW |