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/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> |
11 | 11 |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/string_util.h" | 13 #include "base/string_util.h" |
| 14 #include "base/system_monitor/system_monitor.h" |
14 #include "base/win/scoped_gdi_object.h" | 15 #include "base/win/scoped_gdi_object.h" |
15 #include "base/win/win_util.h" | 16 #include "base/win/win_util.h" |
16 #include "base/win/windows_version.h" | 17 #include "base/win/windows_version.h" |
17 #include "ui/base/dragdrop/drag_drop_types.h" | 18 #include "ui/base/dragdrop/drag_drop_types.h" |
18 #include "ui/base/dragdrop/drag_source.h" | 19 #include "ui/base/dragdrop/drag_source.h" |
19 #include "ui/base/dragdrop/os_exchange_data.h" | 20 #include "ui/base/dragdrop/os_exchange_data.h" |
20 #include "ui/base/dragdrop/os_exchange_data_provider_win.h" | 21 #include "ui/base/dragdrop/os_exchange_data_provider_win.h" |
21 #include "ui/base/event.h" | 22 #include "ui/base/event.h" |
22 #include "ui/base/keycodes/keyboard_code_conversion_win.h" | 23 #include "ui/base/keycodes/keyboard_code_conversion_win.h" |
23 #include "ui/base/l10n/l10n_util_win.h" | 24 #include "ui/base/l10n/l10n_util_win.h" |
| 25 #include "ui/base/native_theme/native_theme_win.h" |
24 #include "ui/base/theme_provider.h" | 26 #include "ui/base/theme_provider.h" |
25 #include "ui/base/view_prop.h" | 27 #include "ui/base/view_prop.h" |
26 #include "ui/base/win/hwnd_util.h" | 28 #include "ui/base/win/hwnd_util.h" |
27 #include "ui/base/win/mouse_wheel_util.h" | 29 #include "ui/base/win/mouse_wheel_util.h" |
28 #include "ui/gfx/canvas.h" | 30 #include "ui/gfx/canvas.h" |
29 #include "ui/gfx/canvas_paint.h" | 31 #include "ui/gfx/canvas_paint.h" |
30 #include "ui/gfx/canvas_skia_paint.h" | 32 #include "ui/gfx/canvas_skia_paint.h" |
31 #include "ui/gfx/icon_util.h" | 33 #include "ui/gfx/icon_util.h" |
32 #include "ui/gfx/path.h" | 34 #include "ui/gfx/path.h" |
33 #include "ui/gfx/screen.h" | 35 #include "ui/gfx/screen.h" |
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
537 WindowImpl::Init(params.GetParent(), params.bounds); | 539 WindowImpl::Init(params.GetParent(), params.bounds); |
538 } | 540 } |
539 | 541 |
540 NonClientFrameView* NativeWidgetWin::CreateNonClientFrameView() { | 542 NonClientFrameView* NativeWidgetWin::CreateNonClientFrameView() { |
541 return GetWidget()->ShouldUseNativeFrame() ? | 543 return GetWidget()->ShouldUseNativeFrame() ? |
542 new NativeFrameView(GetWidget()) : NULL; | 544 new NativeFrameView(GetWidget()) : NULL; |
543 } | 545 } |
544 | 546 |
545 void NativeWidgetWin::UpdateFrameAfterFrameChange() { | 547 void NativeWidgetWin::UpdateFrameAfterFrameChange() { |
546 // We've either gained or lost a custom window region, so reset it now. | 548 // We've either gained or lost a custom window region, so reset it now. |
547 message_handler_->ResetWindowRegion(true); | 549 ResetWindowRegion(true); |
548 } | 550 } |
549 | 551 |
550 bool NativeWidgetWin::ShouldUseNativeFrame() const { | 552 bool NativeWidgetWin::ShouldUseNativeFrame() const { |
551 return IsAeroGlassEnabled(); | 553 return IsAeroGlassEnabled(); |
552 } | 554 } |
553 | 555 |
554 void NativeWidgetWin::FrameTypeChanged() { | 556 void NativeWidgetWin::FrameTypeChanged() { |
555 // Called when the frame type could possibly be changing (theme change or | 557 // Called when the frame type could possibly be changing (theme change or |
556 // DWM composition change). | 558 // DWM composition change). |
557 if (base::win::GetVersion() >= base::win::VERSION_VISTA) { | 559 if (base::win::GetVersion() >= base::win::VERSION_VISTA) { |
(...skipping 891 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1449 | 1451 |
1450 void NativeWidgetWin::OnHScroll(int scroll_type, | 1452 void NativeWidgetWin::OnHScroll(int scroll_type, |
1451 short position, | 1453 short position, |
1452 HWND scrollbar) { | 1454 HWND scrollbar) { |
1453 SetMsgHandled(FALSE); | 1455 SetMsgHandled(FALSE); |
1454 } | 1456 } |
1455 | 1457 |
1456 LRESULT NativeWidgetWin::OnImeMessages(UINT message, | 1458 LRESULT NativeWidgetWin::OnImeMessages(UINT message, |
1457 WPARAM w_param, | 1459 WPARAM w_param, |
1458 LPARAM l_param) { | 1460 LPARAM l_param) { |
1459 return message_handler_->OnImeMessages(message, w_param, l_param); | 1461 InputMethod* input_method = GetWidget()->GetInputMethodDirect(); |
| 1462 if (!input_method || input_method->IsMock()) { |
| 1463 SetMsgHandled(FALSE); |
| 1464 return 0; |
| 1465 } |
| 1466 |
| 1467 InputMethodWin* ime_win = static_cast<InputMethodWin*>(input_method); |
| 1468 BOOL handled = FALSE; |
| 1469 LRESULT result = ime_win->OnImeMessages(message, w_param, l_param, &handled); |
| 1470 |
| 1471 SetMsgHandled(handled); |
| 1472 return result; |
1460 } | 1473 } |
1461 | 1474 |
1462 void NativeWidgetWin::OnInitMenu(HMENU menu) { | 1475 void NativeWidgetWin::OnInitMenu(HMENU menu) { |
| 1476 bool is_fullscreen = IsFullscreen(); |
| 1477 bool is_minimized = IsMinimized(); |
| 1478 bool is_maximized = IsMaximized(); |
| 1479 bool is_restored = !is_fullscreen && !is_minimized && !is_maximized; |
| 1480 |
1463 ScopedRedrawLock lock(this); | 1481 ScopedRedrawLock lock(this); |
1464 message_handler_->OnInitMenu(menu); | 1482 EnableMenuItem(menu, SC_RESTORE, is_minimized || is_maximized); |
| 1483 EnableMenuItem(menu, SC_MOVE, is_restored); |
| 1484 EnableMenuItem(menu, SC_SIZE, |
| 1485 GetWidget()->widget_delegate()->CanResize() && is_restored); |
| 1486 EnableMenuItem(menu, SC_MAXIMIZE, |
| 1487 GetWidget()->widget_delegate()->CanMaximize() && |
| 1488 !is_fullscreen && !is_maximized); |
| 1489 EnableMenuItem(menu, SC_MINIMIZE, |
| 1490 GetWidget()->widget_delegate()->CanMaximize() && |
| 1491 !is_minimized); |
1465 } | 1492 } |
1466 | 1493 |
1467 void NativeWidgetWin::OnInitMenuPopup(HMENU menu, | 1494 void NativeWidgetWin::OnInitMenuPopup(HMENU menu, |
1468 UINT position, | 1495 UINT position, |
1469 BOOL is_system_menu) { | 1496 BOOL is_system_menu) { |
1470 message_handler_->OnInitMenu(menu); | 1497 SetMsgHandled(FALSE); |
1471 } | 1498 } |
1472 | 1499 |
1473 void NativeWidgetWin::OnInputLangChange(DWORD character_set, | 1500 void NativeWidgetWin::OnInputLangChange(DWORD character_set, |
1474 HKL input_language_id) { | 1501 HKL input_language_id) { |
1475 message_handler_->OnInputLangChange(character_set, input_language_id); | 1502 InputMethod* input_method = GetWidget()->GetInputMethodDirect(); |
| 1503 |
| 1504 if (input_method && !input_method->IsMock()) { |
| 1505 static_cast<InputMethodWin*>(input_method)->OnInputLangChange( |
| 1506 character_set, input_language_id); |
| 1507 } |
1476 } | 1508 } |
1477 | 1509 |
1478 LRESULT NativeWidgetWin::OnKeyEvent(UINT message, | 1510 LRESULT NativeWidgetWin::OnKeyEvent(UINT message, |
1479 WPARAM w_param, | 1511 WPARAM w_param, |
1480 LPARAM l_param) { | 1512 LPARAM l_param) { |
1481 return message_handler_->OnKeyEvent(message, w_param, l_param); | 1513 MSG msg = { hwnd(), message, w_param, l_param }; |
| 1514 ui::KeyEvent key(msg, message == WM_CHAR); |
| 1515 InputMethod* input_method = GetWidget()->GetInputMethodDirect(); |
| 1516 if (input_method) |
| 1517 input_method->DispatchKeyEvent(key); |
| 1518 else |
| 1519 DispatchKeyEventPostIME(key); |
| 1520 return 0; |
1482 } | 1521 } |
1483 | 1522 |
1484 void NativeWidgetWin::OnKillFocus(HWND focused_window) { | 1523 void NativeWidgetWin::OnKillFocus(HWND focused_window) { |
1485 message_handler_->OnKillFocus(focused_window); | 1524 delegate_->OnNativeBlur(focused_window); |
| 1525 InputMethod* input_method = GetWidget()->GetInputMethodDirect(); |
| 1526 if (input_method) |
| 1527 input_method->OnBlur(); |
| 1528 SetMsgHandled(FALSE); |
1486 } | 1529 } |
1487 | 1530 |
1488 LRESULT NativeWidgetWin::OnMouseActivate(UINT message, | 1531 LRESULT NativeWidgetWin::OnMouseActivate(UINT message, |
1489 WPARAM w_param, | 1532 WPARAM w_param, |
1490 LPARAM l_param) { | 1533 LPARAM l_param) { |
1491 return message_handler_->OnMouseActivate(message, w_param, l_param); | 1534 // TODO(beng): resolve this with the GetWindowLong() check on the subsequent |
| 1535 // line. |
| 1536 if (GetWidget()->non_client_view()) |
| 1537 return delegate_->CanActivate() ? MA_ACTIVATE : MA_NOACTIVATEANDEAT; |
| 1538 if (GetWindowLong(GWL_EXSTYLE) & WS_EX_NOACTIVATE) |
| 1539 return MA_NOACTIVATE; |
| 1540 SetMsgHandled(FALSE); |
| 1541 return MA_ACTIVATE; |
1492 } | 1542 } |
1493 | 1543 |
1494 LRESULT NativeWidgetWin::OnMouseRange(UINT message, | 1544 LRESULT NativeWidgetWin::OnMouseRange(UINT message, |
1495 WPARAM w_param, | 1545 WPARAM w_param, |
1496 LPARAM l_param) { | 1546 LPARAM l_param) { |
1497 if (message == WM_RBUTTONUP && is_right_mouse_pressed_on_caption_) { | 1547 if (message == WM_RBUTTONUP && is_right_mouse_pressed_on_caption_) { |
1498 is_right_mouse_pressed_on_caption_ = false; | 1548 is_right_mouse_pressed_on_caption_ = false; |
1499 ReleaseCapture(); | 1549 ReleaseCapture(); |
1500 // |point| is in window coordinates, but WM_NCHITTEST and TrackPopupMenu() | 1550 // |point| is in window coordinates, but WM_NCHITTEST and TrackPopupMenu() |
1501 // expect screen coordinates. | 1551 // expect screen coordinates. |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1576 // side-effects (ex/ stifling non-client mouse releases). | 1626 // side-effects (ex/ stifling non-client mouse releases). |
1577 DefWindowProcWithRedrawLock(message, w_param, l_param); | 1627 DefWindowProcWithRedrawLock(message, w_param, l_param); |
1578 handled = true; | 1628 handled = true; |
1579 } | 1629 } |
1580 | 1630 |
1581 SetMsgHandled(handled); | 1631 SetMsgHandled(handled); |
1582 return 0; | 1632 return 0; |
1583 } | 1633 } |
1584 | 1634 |
1585 void NativeWidgetWin::OnMove(const CPoint& point) { | 1635 void NativeWidgetWin::OnMove(const CPoint& point) { |
1586 message_handler_->OnMove(point); | 1636 delegate_->OnNativeWidgetMove(); |
| 1637 SetMsgHandled(FALSE); |
1587 } | 1638 } |
1588 | 1639 |
1589 void NativeWidgetWin::OnMoving(UINT param, const LPRECT new_bounds) { | 1640 void NativeWidgetWin::OnMoving(UINT param, const LPRECT new_bounds) { |
1590 message_handler_->OnMoving(param, new_bounds); | 1641 delegate_->OnNativeWidgetMove(); |
1591 } | 1642 } |
1592 | 1643 |
1593 LRESULT NativeWidgetWin::OnNCActivate(BOOL active) { | 1644 LRESULT NativeWidgetWin::OnNCActivate(BOOL active) { |
1594 if (delegate_->CanActivate()) | 1645 if (delegate_->CanActivate()) |
1595 delegate_->OnNativeWidgetActivationChanged(!!active); | 1646 delegate_->OnNativeWidgetActivationChanged(!!active); |
1596 | 1647 |
1597 if (!GetWidget()->non_client_view()) { | 1648 if (!GetWidget()->non_client_view()) { |
1598 SetMsgHandled(FALSE); | 1649 SetMsgHandled(FALSE); |
1599 return 0; | 1650 return 0; |
1600 } | 1651 } |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1715 // window from the left edge look slightly less broken. | 1766 // window from the left edge look slightly less broken. |
1716 // We special case when left or top insets are 0, since these conditions | 1767 // We special case when left or top insets are 0, since these conditions |
1717 // actually require another repaint to correct the layout after glass gets | 1768 // actually require another repaint to correct the layout after glass gets |
1718 // turned on and off. | 1769 // turned on and off. |
1719 if (insets.left() == 0 || insets.top() == 0) | 1770 if (insets.left() == 0 || insets.top() == 0) |
1720 return 0; | 1771 return 0; |
1721 return mode ? WVR_REDRAW : 0; | 1772 return mode ? WVR_REDRAW : 0; |
1722 } | 1773 } |
1723 | 1774 |
1724 LRESULT NativeWidgetWin::OnNCHitTest(const CPoint& point) { | 1775 LRESULT NativeWidgetWin::OnNCHitTest(const CPoint& point) { |
1725 return message_handler_->OnNCHitTest(point); | 1776 if (!GetWidget()->non_client_view()) { |
| 1777 SetMsgHandled(FALSE); |
| 1778 return 0; |
| 1779 } |
| 1780 |
| 1781 // If the DWM is rendering the window controls, we need to give the DWM's |
| 1782 // default window procedure first chance to handle hit testing. |
| 1783 if (!message_handler_->remove_standard_frame() && |
| 1784 GetWidget()->ShouldUseNativeFrame()) { |
| 1785 LRESULT result; |
| 1786 if (DwmDefWindowProc(GetNativeView(), WM_NCHITTEST, 0, |
| 1787 MAKELPARAM(point.x, point.y), &result)) { |
| 1788 return result; |
| 1789 } |
| 1790 } |
| 1791 |
| 1792 // First, give the NonClientView a chance to test the point to see if it |
| 1793 // provides any of the non-client area. |
| 1794 POINT temp = point; |
| 1795 MapWindowPoints(HWND_DESKTOP, GetNativeView(), &temp, 1); |
| 1796 int component = delegate_->GetNonClientComponent(gfx::Point(temp)); |
| 1797 if (component != HTNOWHERE) |
| 1798 return component; |
| 1799 |
| 1800 // Otherwise, we let Windows do all the native frame non-client handling for |
| 1801 // us. |
| 1802 SetMsgHandled(FALSE); |
| 1803 return 0; |
1726 } | 1804 } |
1727 | 1805 |
1728 void NativeWidgetWin::OnNCPaint(HRGN rgn) { | 1806 void NativeWidgetWin::OnNCPaint(HRGN rgn) { |
1729 // We only do non-client painting if we're not using the native frame. | 1807 // We only do non-client painting if we're not using the native frame. |
1730 // It's required to avoid some native painting artifacts from appearing when | 1808 // It's required to avoid some native painting artifacts from appearing when |
1731 // the window is resized. | 1809 // the window is resized. |
1732 if (!GetWidget()->non_client_view() || GetWidget()->ShouldUseNativeFrame()) { | 1810 if (!GetWidget()->non_client_view() || GetWidget()->ShouldUseNativeFrame()) { |
1733 SetMsgHandled(FALSE); | 1811 SetMsgHandled(FALSE); |
1734 return; | 1812 return; |
1735 } | 1813 } |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1803 | 1881 |
1804 ReleaseDC(GetNativeView(), dc); | 1882 ReleaseDC(GetNativeView(), dc); |
1805 // When using a custom frame, we want to avoid calling DefWindowProc() since | 1883 // When using a custom frame, we want to avoid calling DefWindowProc() since |
1806 // that may render artifacts. | 1884 // that may render artifacts. |
1807 SetMsgHandled(!GetWidget()->ShouldUseNativeFrame()); | 1885 SetMsgHandled(!GetWidget()->ShouldUseNativeFrame()); |
1808 } | 1886 } |
1809 | 1887 |
1810 LRESULT NativeWidgetWin::OnNCUAHDrawCaption(UINT msg, | 1888 LRESULT NativeWidgetWin::OnNCUAHDrawCaption(UINT msg, |
1811 WPARAM w_param, | 1889 WPARAM w_param, |
1812 LPARAM l_param) { | 1890 LPARAM l_param) { |
1813 return message_handler_->OnNCUAHDrawCaption(msg, w_param, l_param); | 1891 // See comment in widget_win.h at the definition of WM_NCUAHDRAWCAPTION for |
| 1892 // an explanation about why we need to handle this message. |
| 1893 SetMsgHandled(!GetWidget()->ShouldUseNativeFrame()); |
| 1894 return 0; |
1814 } | 1895 } |
1815 | 1896 |
1816 LRESULT NativeWidgetWin::OnNCUAHDrawFrame(UINT msg, | 1897 LRESULT NativeWidgetWin::OnNCUAHDrawFrame(UINT msg, |
1817 WPARAM w_param, | 1898 WPARAM w_param, |
1818 LPARAM l_param) { | 1899 LPARAM l_param) { |
1819 return message_handler_->OnNCUAHDrawFrame(msg, w_param, l_param); | 1900 // See comment in widget_win.h at the definition of WM_NCUAHDRAWCAPTION for |
| 1901 // an explanation about why we need to handle this message. |
| 1902 SetMsgHandled(!GetWidget()->ShouldUseNativeFrame()); |
| 1903 return 0; |
1820 } | 1904 } |
1821 | 1905 |
1822 LRESULT NativeWidgetWin::OnNotify(int w_param, NMHDR* l_param) { | 1906 LRESULT NativeWidgetWin::OnNotify(int w_param, NMHDR* l_param) { |
1823 // We can be sent this message before the tooltip manager is created, if a | 1907 // We can be sent this message before the tooltip manager is created, if a |
1824 // subclass overrides OnCreate and creates some kind of Windows control there | 1908 // subclass overrides OnCreate and creates some kind of Windows control there |
1825 // that sends WM_NOTIFY messages. | 1909 // that sends WM_NOTIFY messages. |
1826 if (tooltip_manager_.get()) { | 1910 if (tooltip_manager_.get()) { |
1827 bool handled; | 1911 bool handled; |
1828 LRESULT result = tooltip_manager_->OnNotify(w_param, l_param, &handled); | 1912 LRESULT result = tooltip_manager_->OnNotify(w_param, l_param, &handled); |
1829 SetMsgHandled(handled); | 1913 SetMsgHandled(handled); |
(...skipping 17 matching lines...) Expand all Loading... |
1847 delegate_->OnNativeWidgetPaint(canvas->AsCanvas()); | 1931 delegate_->OnNativeWidgetPaint(canvas->AsCanvas()); |
1848 } | 1932 } |
1849 } else { | 1933 } else { |
1850 // TODO(msw): Find a better solution for this crbug.com/93530 workaround. | 1934 // TODO(msw): Find a better solution for this crbug.com/93530 workaround. |
1851 // Some scenarios otherwise fail to validate minimized app/popup windows. | 1935 // Some scenarios otherwise fail to validate minimized app/popup windows. |
1852 ValidateRect(hwnd(), NULL); | 1936 ValidateRect(hwnd(), NULL); |
1853 } | 1937 } |
1854 } | 1938 } |
1855 | 1939 |
1856 LRESULT NativeWidgetWin::OnPowerBroadcast(DWORD power_event, DWORD data) { | 1940 LRESULT NativeWidgetWin::OnPowerBroadcast(DWORD power_event, DWORD data) { |
1857 return message_handler_->OnPowerBroadcast(power_event, data); | 1941 base::SystemMonitor* monitor = base::SystemMonitor::Get(); |
| 1942 if (monitor) |
| 1943 monitor->ProcessWmPowerBroadcastMessage(power_event); |
| 1944 SetMsgHandled(FALSE); |
| 1945 return 0; |
1858 } | 1946 } |
1859 | 1947 |
1860 LRESULT NativeWidgetWin::OnReflectedMessage(UINT msg, | 1948 LRESULT NativeWidgetWin::OnReflectedMessage(UINT msg, |
1861 WPARAM w_param, | 1949 WPARAM w_param, |
1862 LPARAM l_param) { | 1950 LPARAM l_param) { |
1863 return message_handler_->OnReflectedMessage(msg, w_param, l_param); | 1951 SetMsgHandled(FALSE); |
| 1952 return 0; |
1864 } | 1953 } |
1865 | 1954 |
1866 LRESULT NativeWidgetWin::OnSetCursor(UINT message, | 1955 LRESULT NativeWidgetWin::OnSetCursor(UINT message, |
1867 WPARAM w_param, | 1956 WPARAM w_param, |
1868 LPARAM l_param) { | 1957 LPARAM l_param) { |
1869 return message_handler_->OnSetCursor(message, w_param, l_param); | 1958 // Using ScopedRedrawLock here frequently allows content behind this window to |
| 1959 // paint in front of this window, causing glaring rendering artifacts. |
| 1960 // If omitting ScopedRedrawLock here triggers caption rendering artifacts via |
| 1961 // DefWindowProc message handling, we'll need to find a better solution. |
| 1962 SetMsgHandled(FALSE); |
| 1963 return 0; |
1870 } | 1964 } |
1871 | 1965 |
1872 void NativeWidgetWin::OnSetFocus(HWND old_focused_window) { | 1966 void NativeWidgetWin::OnSetFocus(HWND old_focused_window) { |
1873 message_handler_->OnSetFocus(old_focused_window); | 1967 delegate_->OnNativeFocus(old_focused_window); |
| 1968 InputMethod* input_method = GetWidget()->GetInputMethodDirect(); |
| 1969 if (input_method) |
| 1970 input_method->OnFocus(); |
| 1971 SetMsgHandled(FALSE); |
1874 } | 1972 } |
1875 | 1973 |
1876 LRESULT NativeWidgetWin::OnSetIcon(UINT size_type, HICON new_icon) { | 1974 LRESULT NativeWidgetWin::OnSetIcon(UINT size_type, HICON new_icon) { |
1877 return message_handler_->OnSetIcon(size_type, new_icon); | 1975 // Use a ScopedRedrawLock to avoid weird non-client painting. |
| 1976 return DefWindowProcWithRedrawLock(WM_SETICON, size_type, |
| 1977 reinterpret_cast<LPARAM>(new_icon)); |
1878 } | 1978 } |
1879 | 1979 |
1880 LRESULT NativeWidgetWin::OnSetText(const wchar_t* text) { | 1980 LRESULT NativeWidgetWin::OnSetText(const wchar_t* text) { |
1881 return message_handler_->OnSetText(text); | 1981 // Use a ScopedRedrawLock to avoid weird non-client painting. |
| 1982 return DefWindowProcWithRedrawLock(WM_SETTEXT, NULL, |
| 1983 reinterpret_cast<LPARAM>(text)); |
1882 } | 1984 } |
1883 | 1985 |
1884 void NativeWidgetWin::OnSettingChange(UINT flags, const wchar_t* section) { | 1986 void NativeWidgetWin::OnSettingChange(UINT flags, const wchar_t* section) { |
1885 if (!GetParent() && (flags == SPI_SETWORKAREA) && | 1987 if (!GetParent() && (flags == SPI_SETWORKAREA) && |
1886 !GetWidget()->widget_delegate()->WillProcessWorkAreaChange()) { | 1988 !GetWidget()->widget_delegate()->WillProcessWorkAreaChange()) { |
1887 // Fire a dummy SetWindowPos() call, so we'll trip the code in | 1989 // Fire a dummy SetWindowPos() call, so we'll trip the code in |
1888 // OnWindowPosChanging() below that notices work area changes. | 1990 // OnWindowPosChanging() below that notices work area changes. |
1889 ::SetWindowPos(GetNativeView(), 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | | 1991 ::SetWindowPos(GetNativeView(), 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | |
1890 SWP_NOZORDER | SWP_NOREDRAW | SWP_NOACTIVATE | SWP_NOOWNERZORDER); | 1992 SWP_NOZORDER | SWP_NOREDRAW | SWP_NOACTIVATE | SWP_NOOWNERZORDER); |
1891 SetMsgHandled(TRUE); | 1993 SetMsgHandled(TRUE); |
1892 } else { | 1994 } else { |
1893 // TODO(beng): move to Widget. | 1995 // TODO(beng): move to Widget. |
1894 if (flags == SPI_SETWORKAREA) | 1996 if (flags == SPI_SETWORKAREA) |
1895 GetWidget()->widget_delegate()->OnWorkAreaChanged(); | 1997 GetWidget()->widget_delegate()->OnWorkAreaChanged(); |
1896 SetMsgHandled(FALSE); | 1998 SetMsgHandled(FALSE); |
1897 } | 1999 } |
1898 } | 2000 } |
1899 | 2001 |
1900 void NativeWidgetWin::OnSize(UINT param, const CSize& size) { | 2002 void NativeWidgetWin::OnSize(UINT param, const CSize& size) { |
1901 message_handler_->OnSize(param, size); | 2003 RedrawWindow(GetNativeView(), NULL, NULL, RDW_INVALIDATE | RDW_ALLCHILDREN); |
| 2004 // ResetWindowRegion is going to trigger WM_NCPAINT. By doing it after we've |
| 2005 // invoked OnSize we ensure the RootView has been laid out. |
| 2006 ResetWindowRegion(false); |
1902 } | 2007 } |
1903 | 2008 |
1904 void NativeWidgetWin::OnSysCommand(UINT notification_code, CPoint click) { | 2009 void NativeWidgetWin::OnSysCommand(UINT notification_code, CPoint click) { |
1905 if (!GetWidget()->non_client_view()) | 2010 if (!GetWidget()->non_client_view()) |
1906 return; | 2011 return; |
1907 | 2012 |
1908 // Windows uses the 4 lower order bits of |notification_code| for type- | 2013 // Windows uses the 4 lower order bits of |notification_code| for type- |
1909 // specific information so we must exclude this when comparing. | 2014 // specific information so we must exclude this when comparing. |
1910 static const int sc_mask = 0xFFF0; | 2015 static const int sc_mask = 0xFFF0; |
1911 // Ignore size/move/maximize in fullscreen mode. | 2016 // Ignore size/move/maximize in fullscreen mode. |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1946 } | 2051 } |
1947 | 2052 |
1948 // If the delegate can't handle it, the system implementation will be called. | 2053 // If the delegate can't handle it, the system implementation will be called. |
1949 if (!delegate_->ExecuteCommand(notification_code)) { | 2054 if (!delegate_->ExecuteCommand(notification_code)) { |
1950 DefWindowProc(GetNativeView(), WM_SYSCOMMAND, notification_code, | 2055 DefWindowProc(GetNativeView(), WM_SYSCOMMAND, notification_code, |
1951 MAKELPARAM(click.x, click.y)); | 2056 MAKELPARAM(click.x, click.y)); |
1952 } | 2057 } |
1953 } | 2058 } |
1954 | 2059 |
1955 void NativeWidgetWin::OnThemeChanged() { | 2060 void NativeWidgetWin::OnThemeChanged() { |
1956 message_handler_->OnThemeChanged(); | 2061 // Notify NativeThemeWin. |
| 2062 ui::NativeThemeWin::instance()->CloseHandles(); |
1957 } | 2063 } |
1958 | 2064 |
1959 LRESULT NativeWidgetWin::OnTouchEvent(UINT message, | 2065 LRESULT NativeWidgetWin::OnTouchEvent(UINT message, |
1960 WPARAM w_param, | 2066 WPARAM w_param, |
1961 LPARAM l_param) { | 2067 LPARAM l_param) { |
1962 int num_points = LOWORD(w_param); | 2068 int num_points = LOWORD(w_param); |
1963 scoped_array<TOUCHINPUT> input(new TOUCHINPUT[num_points]); | 2069 scoped_array<TOUCHINPUT> input(new TOUCHINPUT[num_points]); |
1964 if (GetTouchInputInfo(reinterpret_cast<HTOUCHINPUT>(l_param), | 2070 if (GetTouchInputInfo(reinterpret_cast<HTOUCHINPUT>(l_param), |
1965 num_points, input.get(), sizeof(TOUCHINPUT))) { | 2071 num_points, input.get(), sizeof(TOUCHINPUT))) { |
1966 for (int i = 0; i < num_points; ++i) { | 2072 for (int i = 0; i < num_points; ++i) { |
1967 if (input[i].dwFlags & TOUCHEVENTF_DOWN) | 2073 if (input[i].dwFlags & TOUCHEVENTF_DOWN) |
1968 touch_ids_.insert(input[i].dwID); | 2074 touch_ids_.insert(input[i].dwID); |
1969 if (input[i].dwFlags & TOUCHEVENTF_UP) | 2075 if (input[i].dwFlags & TOUCHEVENTF_UP) |
1970 touch_ids_.erase(input[i].dwID); | 2076 touch_ids_.erase(input[i].dwID); |
1971 } | 2077 } |
1972 } | 2078 } |
1973 CloseTouchInputHandle(reinterpret_cast<HTOUCHINPUT>(l_param)); | 2079 CloseTouchInputHandle(reinterpret_cast<HTOUCHINPUT>(l_param)); |
1974 SetMsgHandled(FALSE); | 2080 SetMsgHandled(FALSE); |
1975 return 0; | 2081 return 0; |
1976 } | 2082 } |
1977 | 2083 |
1978 void NativeWidgetWin::OnVScroll(int scroll_type, | 2084 void NativeWidgetWin::OnVScroll(int scroll_type, |
1979 short position, | 2085 short position, |
1980 HWND scrollbar) { | 2086 HWND scrollbar) { |
1981 message_handler_->OnVScroll(scroll_type, position, scrollbar); | 2087 SetMsgHandled(FALSE); |
1982 } | 2088 } |
1983 | 2089 |
1984 void NativeWidgetWin::OnWindowPosChanging(WINDOWPOS* window_pos) { | 2090 void NativeWidgetWin::OnWindowPosChanging(WINDOWPOS* window_pos) { |
1985 if (ignore_window_pos_changes_) { | 2091 if (ignore_window_pos_changes_) { |
1986 // If somebody's trying to toggle our visibility, change the nonclient area, | 2092 // If somebody's trying to toggle our visibility, change the nonclient area, |
1987 // change our Z-order, or activate us, we should probably let it go through. | 2093 // change our Z-order, or activate us, we should probably let it go through. |
1988 if (!(window_pos->flags & ((IsVisible() ? SWP_HIDEWINDOW : SWP_SHOWWINDOW) | | 2094 if (!(window_pos->flags & ((IsVisible() ? SWP_HIDEWINDOW : SWP_SHOWWINDOW) | |
1989 SWP_FRAMECHANGED)) && | 2095 SWP_FRAMECHANGED)) && |
1990 (window_pos->flags & (SWP_NOZORDER | SWP_NOACTIVATE))) { | 2096 (window_pos->flags & (SWP_NOZORDER | SWP_NOACTIVATE))) { |
1991 // Just sizing/moving the window; ignore. | 2097 // Just sizing/moving the window; ignore. |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2177 // NativeWidgetWin, HWNDMessageHandlerDelegate implementation: | 2283 // NativeWidgetWin, HWNDMessageHandlerDelegate implementation: |
2178 | 2284 |
2179 bool NativeWidgetWin::IsWidgetWindow() const { | 2285 bool NativeWidgetWin::IsWidgetWindow() const { |
2180 return !!GetWidget()->non_client_view(); | 2286 return !!GetWidget()->non_client_view(); |
2181 } | 2287 } |
2182 | 2288 |
2183 bool NativeWidgetWin::IsUsingCustomFrame() const { | 2289 bool NativeWidgetWin::IsUsingCustomFrame() const { |
2184 return GetWidget()->ShouldUseNativeFrame(); | 2290 return GetWidget()->ShouldUseNativeFrame(); |
2185 } | 2291 } |
2186 | 2292 |
2187 bool NativeWidgetWin::CanResize() const { | |
2188 return GetWidget()->widget_delegate()->CanResize(); | |
2189 } | |
2190 | |
2191 bool NativeWidgetWin::CanMaximize() const { | |
2192 return GetWidget()->widget_delegate()->CanMaximize(); | |
2193 } | |
2194 | |
2195 bool NativeWidgetWin::CanActivate() const { | |
2196 return delegate_->CanActivate(); | |
2197 } | |
2198 | |
2199 int NativeWidgetWin::GetNonClientComponent(const gfx::Point& point) const { | |
2200 return delegate_->GetNonClientComponent(point); | |
2201 } | |
2202 | |
2203 void NativeWidgetWin::GetWindowMask(const gfx::Size& size, gfx::Path* path) { | |
2204 GetWidget()->non_client_view()->GetWindowMask(size, path); | |
2205 } | |
2206 | |
2207 InputMethod* NativeWidgetWin::GetInputMethod() { | |
2208 return GetWidget()->GetInputMethodDirect(); | |
2209 } | |
2210 | |
2211 void NativeWidgetWin::HandleAppDeactivated() { | 2293 void NativeWidgetWin::HandleAppDeactivated() { |
2212 // Another application was activated, we should reset any state that | 2294 // Another application was activated, we should reset any state that |
2213 // disables inactive rendering now. | 2295 // disables inactive rendering now. |
2214 delegate_->EnableInactiveRendering(); | 2296 delegate_->EnableInactiveRendering(); |
2215 } | 2297 } |
2216 | 2298 |
2217 bool NativeWidgetWin::HandleAppCommand(short command) { | 2299 bool NativeWidgetWin::HandleAppCommand(short command) { |
2218 // We treat APPCOMMAND ids as an extension of our command namespace, and just | 2300 // We treat APPCOMMAND ids as an extension of our command namespace, and just |
2219 // let the delegate figure out what to do... | 2301 // let the delegate figure out what to do... |
2220 return GetWidget()->widget_delegate() && | 2302 return GetWidget()->widget_delegate() && |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2256 } | 2338 } |
2257 | 2339 |
2258 void NativeWidgetWin::HandleBeginWMSizeMove() { | 2340 void NativeWidgetWin::HandleBeginWMSizeMove() { |
2259 delegate_->OnNativeWidgetBeginUserBoundsChange(); | 2341 delegate_->OnNativeWidgetBeginUserBoundsChange(); |
2260 } | 2342 } |
2261 | 2343 |
2262 void NativeWidgetWin::HandleEndWMSizeMove() { | 2344 void NativeWidgetWin::HandleEndWMSizeMove() { |
2263 delegate_->OnNativeWidgetEndUserBoundsChange(); | 2345 delegate_->OnNativeWidgetEndUserBoundsChange(); |
2264 } | 2346 } |
2265 | 2347 |
2266 void NativeWidgetWin::HandleMove() { | |
2267 delegate_->OnNativeWidgetMove(); | |
2268 } | |
2269 | |
2270 void NativeWidgetWin::HandleNativeFocus(HWND last_focused_window) { | |
2271 delegate_->OnNativeFocus(last_focused_window); | |
2272 } | |
2273 | |
2274 void NativeWidgetWin::HandleNativeBlur(HWND focused_window) { | |
2275 delegate_->OnNativeBlur(focused_window); | |
2276 } | |
2277 | |
2278 NativeWidgetWin* NativeWidgetWin::AsNativeWidgetWin() { | 2348 NativeWidgetWin* NativeWidgetWin::AsNativeWidgetWin() { |
2279 return this; | 2349 return this; |
2280 } | 2350 } |
2281 | 2351 |
2282 //////////////////////////////////////////////////////////////////////////////// | 2352 //////////////////////////////////////////////////////////////////////////////// |
2283 // NativeWidgetWin, private: | 2353 // NativeWidgetWin, private: |
2284 | 2354 |
2285 // static | 2355 // static |
2286 void NativeWidgetWin::PostProcessActivateMessage(NativeWidgetWin* widget, | 2356 void NativeWidgetWin::PostProcessActivateMessage(NativeWidgetWin* widget, |
2287 int activation_state) { | 2357 int activation_state) { |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2482 if (use_layered_buffer_) | 2552 if (use_layered_buffer_) |
2483 layered_window_contents_.reset( | 2553 layered_window_contents_.reset( |
2484 new gfx::Canvas(s, ui::SCALE_FACTOR_100P, false)); | 2554 new gfx::Canvas(s, ui::SCALE_FACTOR_100P, false)); |
2485 } | 2555 } |
2486 | 2556 |
2487 void NativeWidgetWin::UpdateDWMFrame() { | 2557 void NativeWidgetWin::UpdateDWMFrame() { |
2488 MARGINS m = {10, 10, 10, 10}; | 2558 MARGINS m = {10, 10, 10, 10}; |
2489 DwmExtendFrameIntoClientArea(GetNativeView(), &m); | 2559 DwmExtendFrameIntoClientArea(GetNativeView(), &m); |
2490 } | 2560 } |
2491 | 2561 |
| 2562 void NativeWidgetWin::ResetWindowRegion(bool force) { |
| 2563 // A native frame uses the native window region, and we don't want to mess |
| 2564 // with it. |
| 2565 if (GetWidget()->ShouldUseNativeFrame() || !GetWidget()->non_client_view()) { |
| 2566 if (force) |
| 2567 SetWindowRgn(NULL, TRUE); |
| 2568 return; |
| 2569 } |
| 2570 |
| 2571 // Changing the window region is going to force a paint. Only change the |
| 2572 // window region if the region really differs. |
| 2573 HRGN current_rgn = CreateRectRgn(0, 0, 0, 0); |
| 2574 int current_rgn_result = GetWindowRgn(GetNativeView(), current_rgn); |
| 2575 |
| 2576 CRect window_rect; |
| 2577 GetWindowRect(&window_rect); |
| 2578 HRGN new_region; |
| 2579 if (IsMaximized()) { |
| 2580 HMONITOR monitor = |
| 2581 MonitorFromWindow(GetNativeView(), MONITOR_DEFAULTTONEAREST); |
| 2582 MONITORINFO mi; |
| 2583 mi.cbSize = sizeof mi; |
| 2584 GetMonitorInfo(monitor, &mi); |
| 2585 CRect work_rect = mi.rcWork; |
| 2586 work_rect.OffsetRect(-window_rect.left, -window_rect.top); |
| 2587 new_region = CreateRectRgnIndirect(&work_rect); |
| 2588 } else { |
| 2589 gfx::Path window_mask; |
| 2590 GetWidget()->non_client_view()->GetWindowMask( |
| 2591 gfx::Size(window_rect.Width(), window_rect.Height()), &window_mask); |
| 2592 new_region = window_mask.CreateNativeRegion(); |
| 2593 } |
| 2594 |
| 2595 if (current_rgn_result == ERROR || !EqualRgn(current_rgn, new_region)) { |
| 2596 // SetWindowRgn takes ownership of the HRGN created by CreateNativeRegion. |
| 2597 SetWindowRgn(new_region, TRUE); |
| 2598 } else { |
| 2599 DeleteObject(new_region); |
| 2600 } |
| 2601 |
| 2602 DeleteObject(current_rgn); |
| 2603 } |
| 2604 |
2492 LRESULT NativeWidgetWin::DefWindowProcWithRedrawLock(UINT message, | 2605 LRESULT NativeWidgetWin::DefWindowProcWithRedrawLock(UINT message, |
2493 WPARAM w_param, | 2606 WPARAM w_param, |
2494 LPARAM l_param) { | 2607 LPARAM l_param) { |
2495 ScopedRedrawLock lock(this); | 2608 ScopedRedrawLock lock(this); |
2496 // The Widget and HWND can be destroyed in the call to DefWindowProc, so use | 2609 // The Widget and HWND can be destroyed in the call to DefWindowProc, so use |
2497 // the |destroyed_| flag to avoid unlocking (and crashing) after destruction. | 2610 // the |destroyed_| flag to avoid unlocking (and crashing) after destruction. |
2498 bool destroyed = false; | 2611 bool destroyed = false; |
2499 destroyed_ = &destroyed; | 2612 destroyed_ = &destroyed; |
2500 LRESULT result = DefWindowProc(GetNativeView(), message, w_param, l_param); | 2613 LRESULT result = DefWindowProc(GetNativeView(), message, w_param, l_param); |
2501 if (destroyed) | 2614 if (destroyed) |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2694 // static | 2807 // static |
2695 bool NativeWidgetPrivate::IsTouchDown() { | 2808 bool NativeWidgetPrivate::IsTouchDown() { |
2696 // This currently isn't necessary because we're not generating touch events on | 2809 // This currently isn't necessary because we're not generating touch events on |
2697 // windows. When we do, this will need to be updated. | 2810 // windows. When we do, this will need to be updated. |
2698 return false; | 2811 return false; |
2699 } | 2812 } |
2700 | 2813 |
2701 } // namespace internal | 2814 } // namespace internal |
2702 | 2815 |
2703 } // namespace views | 2816 } // namespace views |
OLD | NEW |