Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(93)

Side by Side Diff: ui/views/widget/native_widget_win.cc

Issue 10831394: Move more message handlers from NativeWidgetWin to HWNDMessageHandler. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/views/widget/native_widget_win.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/widget/native_widget_win.h" 5 #include "ui/views/widget/native_widget_win.h"
6 6
7 #include <dwmapi.h> 7 #include <dwmapi.h>
8 #include <shellapi.h> 8 #include <shellapi.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 1443 matching lines...) Expand 10 before | Expand all | Expand 10 after
1454 SetMsgHandled(FALSE); 1454 SetMsgHandled(FALSE);
1455 } 1455 }
1456 1456
1457 LRESULT NativeWidgetWin::OnImeMessages(UINT message, 1457 LRESULT NativeWidgetWin::OnImeMessages(UINT message,
1458 WPARAM w_param, 1458 WPARAM w_param,
1459 LPARAM l_param) { 1459 LPARAM l_param) {
1460 return message_handler_->OnImeMessages(message, w_param, l_param); 1460 return message_handler_->OnImeMessages(message, w_param, l_param);
1461 } 1461 }
1462 1462
1463 void NativeWidgetWin::OnInitMenu(HMENU menu) { 1463 void NativeWidgetWin::OnInitMenu(HMENU menu) {
1464 bool is_fullscreen = IsFullscreen(); 1464 message_handler_->OnInitMenu(menu);
1465 bool is_minimized = IsMinimized();
1466 bool is_maximized = IsMaximized();
1467 bool is_restored = !is_fullscreen && !is_minimized && !is_maximized;
1468
1469 ScopedRedrawLock lock(this);
1470 EnableMenuItem(menu, SC_RESTORE, is_minimized || is_maximized);
1471 EnableMenuItem(menu, SC_MOVE, is_restored);
1472 EnableMenuItem(menu, SC_SIZE,
1473 GetWidget()->widget_delegate()->CanResize() && is_restored);
1474 EnableMenuItem(menu, SC_MAXIMIZE,
1475 GetWidget()->widget_delegate()->CanMaximize() &&
1476 !is_fullscreen && !is_maximized);
1477 EnableMenuItem(menu, SC_MINIMIZE,
1478 GetWidget()->widget_delegate()->CanMaximize() &&
1479 !is_minimized);
1480 } 1465 }
1481 1466
1482 void NativeWidgetWin::OnInitMenuPopup(HMENU menu, 1467 void NativeWidgetWin::OnInitMenuPopup(HMENU menu,
1483 UINT position, 1468 UINT position,
1484 BOOL is_system_menu) { 1469 BOOL is_system_menu) {
1485 SetMsgHandled(FALSE); 1470 message_handler_->OnInitMenu(menu);
1486 } 1471 }
1487 1472
1488 void NativeWidgetWin::OnInputLangChange(DWORD character_set, 1473 void NativeWidgetWin::OnInputLangChange(DWORD character_set,
1489 HKL input_language_id) { 1474 HKL input_language_id) {
1490 message_handler_->OnInputLangChange(character_set, input_language_id); 1475 message_handler_->OnInputLangChange(character_set, input_language_id);
1491 } 1476 }
1492 1477
1493 LRESULT NativeWidgetWin::OnKeyEvent(UINT message, 1478 LRESULT NativeWidgetWin::OnKeyEvent(UINT message,
1494 WPARAM w_param, 1479 WPARAM w_param,
1495 LPARAM l_param) { 1480 LPARAM l_param) {
1496 MSG msg = { hwnd(), message, w_param, l_param }; 1481 return message_handler_->OnKeyEvent(message, w_param, l_param);
1497 ui::KeyEvent key(msg, message == WM_CHAR);
1498 InputMethod* input_method = GetWidget()->GetInputMethodDirect();
1499 if (input_method)
1500 input_method->DispatchKeyEvent(key);
1501 else
1502 DispatchKeyEventPostIME(key);
1503 return 0;
1504 } 1482 }
1505 1483
1506 void NativeWidgetWin::OnKillFocus(HWND focused_window) { 1484 void NativeWidgetWin::OnKillFocus(HWND focused_window) {
1507 delegate_->OnNativeBlur(focused_window); 1485 message_handler_->OnKillFocus(focused_window);
1508 InputMethod* input_method = GetWidget()->GetInputMethodDirect();
1509 if (input_method)
1510 input_method->OnBlur();
1511 SetMsgHandled(FALSE);
1512 } 1486 }
1513 1487
1514 LRESULT NativeWidgetWin::OnMouseActivate(UINT message, 1488 LRESULT NativeWidgetWin::OnMouseActivate(UINT message,
1515 WPARAM w_param, 1489 WPARAM w_param,
1516 LPARAM l_param) { 1490 LPARAM l_param) {
1517 // TODO(beng): resolve this with the GetWindowLong() check on the subsequent 1491 // TODO(beng): resolve this with the GetWindowLong() check on the subsequent
1518 // line. 1492 // line.
1519 if (GetWidget()->non_client_view()) 1493 if (GetWidget()->non_client_view())
1520 return delegate_->CanActivate() ? MA_ACTIVATE : MA_NOACTIVATEANDEAT; 1494 return delegate_->CanActivate() ? MA_ACTIVATE : MA_NOACTIVATEANDEAT;
1521 if (GetWindowLong(GWL_EXSTYLE) & WS_EX_NOACTIVATE) 1495 if (GetWindowLong(GWL_EXSTYLE) & WS_EX_NOACTIVATE)
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
1748 // window from the left edge look slightly less broken. 1722 // window from the left edge look slightly less broken.
1749 // We special case when left or top insets are 0, since these conditions 1723 // We special case when left or top insets are 0, since these conditions
1750 // actually require another repaint to correct the layout after glass gets 1724 // actually require another repaint to correct the layout after glass gets
1751 // turned on and off. 1725 // turned on and off.
1752 if (insets.left() == 0 || insets.top() == 0) 1726 if (insets.left() == 0 || insets.top() == 0)
1753 return 0; 1727 return 0;
1754 return mode ? WVR_REDRAW : 0; 1728 return mode ? WVR_REDRAW : 0;
1755 } 1729 }
1756 1730
1757 LRESULT NativeWidgetWin::OnNCHitTest(const CPoint& point) { 1731 LRESULT NativeWidgetWin::OnNCHitTest(const CPoint& point) {
1758 if (!GetWidget()->non_client_view()) { 1732 return message_handler_->OnNCHitTest(point);
1759 SetMsgHandled(FALSE);
1760 return 0;
1761 }
1762
1763 // If the DWM is rendering the window controls, we need to give the DWM's
1764 // default window procedure first chance to handle hit testing.
1765 if (!message_handler_->remove_standard_frame() &&
1766 GetWidget()->ShouldUseNativeFrame()) {
1767 LRESULT result;
1768 if (DwmDefWindowProc(GetNativeView(), WM_NCHITTEST, 0,
1769 MAKELPARAM(point.x, point.y), &result)) {
1770 return result;
1771 }
1772 }
1773
1774 // First, give the NonClientView a chance to test the point to see if it
1775 // provides any of the non-client area.
1776 POINT temp = point;
1777 MapWindowPoints(HWND_DESKTOP, GetNativeView(), &temp, 1);
1778 int component = delegate_->GetNonClientComponent(gfx::Point(temp));
1779 if (component != HTNOWHERE)
1780 return component;
1781
1782 // Otherwise, we let Windows do all the native frame non-client handling for
1783 // us.
1784 SetMsgHandled(FALSE);
1785 return 0;
1786 } 1733 }
1787 1734
1788 void NativeWidgetWin::OnNCPaint(HRGN rgn) { 1735 void NativeWidgetWin::OnNCPaint(HRGN rgn) {
1789 // We only do non-client painting if we're not using the native frame. 1736 // We only do non-client painting if we're not using the native frame.
1790 // It's required to avoid some native painting artifacts from appearing when 1737 // It's required to avoid some native painting artifacts from appearing when
1791 // the window is resized. 1738 // the window is resized.
1792 if (!GetWidget()->non_client_view() || GetWidget()->ShouldUseNativeFrame()) { 1739 if (!GetWidget()->non_client_view() || GetWidget()->ShouldUseNativeFrame()) {
1793 SetMsgHandled(FALSE); 1740 SetMsgHandled(FALSE);
1794 return; 1741 return;
1795 } 1742 }
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
1920 LRESULT NativeWidgetWin::OnReflectedMessage(UINT msg, 1867 LRESULT NativeWidgetWin::OnReflectedMessage(UINT msg,
1921 WPARAM w_param, 1868 WPARAM w_param,
1922 LPARAM l_param) { 1869 LPARAM l_param) {
1923 SetMsgHandled(FALSE); 1870 SetMsgHandled(FALSE);
1924 return 0; 1871 return 0;
1925 } 1872 }
1926 1873
1927 LRESULT NativeWidgetWin::OnSetCursor(UINT message, 1874 LRESULT NativeWidgetWin::OnSetCursor(UINT message,
1928 WPARAM w_param, 1875 WPARAM w_param,
1929 LPARAM l_param) { 1876 LPARAM l_param) {
1930 // Using ScopedRedrawLock here frequently allows content behind this window to 1877 return message_handler_->OnSetCursor(message, w_param, l_param);
1931 // paint in front of this window, causing glaring rendering artifacts.
1932 // If omitting ScopedRedrawLock here triggers caption rendering artifacts via
1933 // DefWindowProc message handling, we'll need to find a better solution.
1934 SetMsgHandled(FALSE);
1935 return 0;
1936 } 1878 }
1937 1879
1938 void NativeWidgetWin::OnSetFocus(HWND old_focused_window) { 1880 void NativeWidgetWin::OnSetFocus(HWND old_focused_window) {
1939 delegate_->OnNativeFocus(old_focused_window); 1881 message_handler_->OnSetFocus(old_focused_window);
1940 InputMethod* input_method = GetWidget()->GetInputMethodDirect();
1941 if (input_method)
1942 input_method->OnFocus();
1943 SetMsgHandled(FALSE);
1944 } 1882 }
1945 1883
1946 LRESULT NativeWidgetWin::OnSetIcon(UINT size_type, HICON new_icon) { 1884 LRESULT NativeWidgetWin::OnSetIcon(UINT size_type, HICON new_icon) {
1947 // Use a ScopedRedrawLock to avoid weird non-client painting. 1885 return message_handler_->OnSetIcon(size_type, new_icon);
1948 return DefWindowProcWithRedrawLock(WM_SETICON, size_type,
1949 reinterpret_cast<LPARAM>(new_icon));
1950 } 1886 }
1951 1887
1952 LRESULT NativeWidgetWin::OnSetText(const wchar_t* text) { 1888 LRESULT NativeWidgetWin::OnSetText(const wchar_t* text) {
1953 // Use a ScopedRedrawLock to avoid weird non-client painting. 1889 return message_handler_->OnSetText(text);
1954 return DefWindowProcWithRedrawLock(WM_SETTEXT, NULL,
1955 reinterpret_cast<LPARAM>(text));
1956 } 1890 }
1957 1891
1958 void NativeWidgetWin::OnSettingChange(UINT flags, const wchar_t* section) { 1892 void NativeWidgetWin::OnSettingChange(UINT flags, const wchar_t* section) {
1959 if (!GetParent() && (flags == SPI_SETWORKAREA) && 1893 if (!GetParent() && (flags == SPI_SETWORKAREA) &&
1960 !GetWidget()->widget_delegate()->WillProcessWorkAreaChange()) { 1894 !GetWidget()->widget_delegate()->WillProcessWorkAreaChange()) {
1961 // Fire a dummy SetWindowPos() call, so we'll trip the code in 1895 // Fire a dummy SetWindowPos() call, so we'll trip the code in
1962 // OnWindowPosChanging() below that notices work area changes. 1896 // OnWindowPosChanging() below that notices work area changes.
1963 ::SetWindowPos(GetNativeView(), 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | 1897 ::SetWindowPos(GetNativeView(), 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE |
1964 SWP_NOZORDER | SWP_NOREDRAW | SWP_NOACTIVATE | SWP_NOOWNERZORDER); 1898 SWP_NOZORDER | SWP_NOREDRAW | SWP_NOACTIVATE | SWP_NOOWNERZORDER);
1965 SetMsgHandled(TRUE); 1899 SetMsgHandled(TRUE);
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
2254 // NativeWidgetWin, HWNDMessageHandlerDelegate implementation: 2188 // NativeWidgetWin, HWNDMessageHandlerDelegate implementation:
2255 2189
2256 bool NativeWidgetWin::IsWidgetWindow() const { 2190 bool NativeWidgetWin::IsWidgetWindow() const {
2257 return !!GetWidget()->non_client_view(); 2191 return !!GetWidget()->non_client_view();
2258 } 2192 }
2259 2193
2260 bool NativeWidgetWin::IsUsingCustomFrame() const { 2194 bool NativeWidgetWin::IsUsingCustomFrame() const {
2261 return GetWidget()->ShouldUseNativeFrame(); 2195 return GetWidget()->ShouldUseNativeFrame();
2262 } 2196 }
2263 2197
2198 bool NativeWidgetWin::CanResize() const {
2199 return GetWidget()->widget_delegate()->CanResize();
2200 }
2201
2202 bool NativeWidgetWin::CanMaximize() const {
2203 return GetWidget()->widget_delegate()->CanMaximize();
2204 }
2205
2206 bool NativeWidgetWin::CanActivate() const {
2207 return delegate_->CanActivate();
2208 }
2209
2210 int NativeWidgetWin::GetNonClientComponent(const gfx::Point& point) const {
2211 return delegate_->GetNonClientComponent(point);
2212 }
2213
2214 void NativeWidgetWin::GetWindowMask(const gfx::Size& size, gfx::Path* path) {
2215 GetWidget()->non_client_view()->GetWindowMask(size, path);
2216 }
2217
2264 InputMethod* NativeWidgetWin::GetInputMethod() { 2218 InputMethod* NativeWidgetWin::GetInputMethod() {
2265 return GetWidget()->GetInputMethodDirect(); 2219 return GetWidget()->GetInputMethodDirect();
2266 } 2220 }
2267 2221
2268 void NativeWidgetWin::HandleAppDeactivated() { 2222 void NativeWidgetWin::HandleAppDeactivated() {
2269 // Another application was activated, we should reset any state that 2223 // Another application was activated, we should reset any state that
2270 // disables inactive rendering now. 2224 // disables inactive rendering now.
2271 delegate_->EnableInactiveRendering(); 2225 delegate_->EnableInactiveRendering();
2272 } 2226 }
2273 2227
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
2317 } 2271 }
2318 2272
2319 void NativeWidgetWin::HandleEndWMSizeMove() { 2273 void NativeWidgetWin::HandleEndWMSizeMove() {
2320 delegate_->OnNativeWidgetEndUserBoundsChange(); 2274 delegate_->OnNativeWidgetEndUserBoundsChange();
2321 } 2275 }
2322 2276
2323 void NativeWidgetWin::HandleMove() { 2277 void NativeWidgetWin::HandleMove() {
2324 delegate_->OnNativeWidgetMove(); 2278 delegate_->OnNativeWidgetMove();
2325 } 2279 }
2326 2280
2281 void NativeWidgetWin::HandleNativeFocus(HWND last_focused_window) {
2282 delegate_->OnNativeFocus(last_focused_window);
2283 }
2284
2285 void NativeWidgetWin::HandleNativeBlur(HWND focused_window) {
2286 delegate_->OnNativeBlur(focused_window);
2287 }
2288
2327 NativeWidgetWin* NativeWidgetWin::AsNativeWidgetWin() { 2289 NativeWidgetWin* NativeWidgetWin::AsNativeWidgetWin() {
2328 return this; 2290 return this;
2329 } 2291 }
2330 2292
2331 //////////////////////////////////////////////////////////////////////////////// 2293 ////////////////////////////////////////////////////////////////////////////////
2332 // NativeWidgetWin, private: 2294 // NativeWidgetWin, private:
2333 2295
2334 // static 2296 // static
2335 void NativeWidgetWin::PostProcessActivateMessage(NativeWidgetWin* widget, 2297 void NativeWidgetWin::PostProcessActivateMessage(NativeWidgetWin* widget,
2336 int activation_state) { 2298 int activation_state) {
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after
2786 // static 2748 // static
2787 bool NativeWidgetPrivate::IsTouchDown() { 2749 bool NativeWidgetPrivate::IsTouchDown() {
2788 // This currently isn't necessary because we're not generating touch events on 2750 // This currently isn't necessary because we're not generating touch events on
2789 // windows. When we do, this will need to be updated. 2751 // windows. When we do, this will need to be updated.
2790 return false; 2752 return false;
2791 } 2753 }
2792 2754
2793 } // namespace internal 2755 } // namespace internal
2794 2756
2795 } // namespace views 2757 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/widget/native_widget_win.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698