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

Side by Side Diff: ui/views/win/hwnd_message_handler.cc

Issue 146833020: Remove some uses of ATL in UI code (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 10 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/win/hwnd_message_handler.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/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 <oleacc.h>
8 #include <shellapi.h> 9 #include <shellapi.h>
9 #include <wtsapi32.h> 10 #include <wtsapi32.h>
10 #pragma comment(lib, "wtsapi32.lib") 11 #pragma comment(lib, "wtsapi32.lib")
11 12
12 #include "base/bind.h" 13 #include "base/bind.h"
13 #include "base/debug/trace_event.h" 14 #include "base/debug/trace_event.h"
14 #include "base/win/win_util.h" 15 #include "base/win/win_util.h"
15 #include "base/win/windows_version.h" 16 #include "base/win/windows_version.h"
16 #include "ui/base/touch/touch_enabled.h" 17 #include "ui/base/touch/touch_enabled.h"
17 #include "ui/base/win/lock_state.h" 18 #include "ui/base/win/lock_state.h"
(...skipping 1133 matching lines...) Expand 10 before | Expand all | Expand 10 after
1151 if (force) 1152 if (force)
1152 SetWindowRgn(hwnd(), NULL, redraw); 1153 SetWindowRgn(hwnd(), NULL, redraw);
1153 return; 1154 return;
1154 } 1155 }
1155 1156
1156 // Changing the window region is going to force a paint. Only change the 1157 // Changing the window region is going to force a paint. Only change the
1157 // window region if the region really differs. 1158 // window region if the region really differs.
1158 HRGN current_rgn = CreateRectRgn(0, 0, 0, 0); 1159 HRGN current_rgn = CreateRectRgn(0, 0, 0, 0);
1159 int current_rgn_result = GetWindowRgn(hwnd(), current_rgn); 1160 int current_rgn_result = GetWindowRgn(hwnd(), current_rgn);
1160 1161
1161 CRect window_rect; 1162 RECT window_rect;
1162 GetWindowRect(hwnd(), &window_rect); 1163 GetWindowRect(hwnd(), &window_rect);
1163 HRGN new_region; 1164 HRGN new_region;
1164 if (custom_window_region_) { 1165 if (custom_window_region_) {
1165 new_region = ::CreateRectRgn(0, 0, 0, 0); 1166 new_region = ::CreateRectRgn(0, 0, 0, 0);
1166 ::CombineRgn(new_region, custom_window_region_.Get(), NULL, RGN_COPY); 1167 ::CombineRgn(new_region, custom_window_region_.Get(), NULL, RGN_COPY);
1167 } else if (IsMaximized()) { 1168 } else if (IsMaximized()) {
1168 HMONITOR monitor = MonitorFromWindow(hwnd(), MONITOR_DEFAULTTONEAREST); 1169 HMONITOR monitor = MonitorFromWindow(hwnd(), MONITOR_DEFAULTTONEAREST);
1169 MONITORINFO mi; 1170 MONITORINFO mi;
1170 mi.cbSize = sizeof mi; 1171 mi.cbSize = sizeof mi;
1171 GetMonitorInfo(monitor, &mi); 1172 GetMonitorInfo(monitor, &mi);
1172 CRect work_rect = mi.rcWork; 1173 RECT work_rect = mi.rcWork;
1173 work_rect.OffsetRect(-window_rect.left, -window_rect.top); 1174 OffsetRect(&work_rect, -window_rect.left, -window_rect.top);
1174 new_region = CreateRectRgnIndirect(&work_rect); 1175 new_region = CreateRectRgnIndirect(&work_rect);
1175 } else { 1176 } else {
1176 gfx::Path window_mask; 1177 gfx::Path window_mask;
1177 delegate_->GetWindowMask( 1178 delegate_->GetWindowMask(gfx::Size(window_rect.right - window_rect.left,
1178 gfx::Size(window_rect.Width(), window_rect.Height()), &window_mask); 1179 window_rect.bottom - window_rect.top),
1180 &window_mask);
1179 new_region = gfx::CreateHRGNFromSkPath(window_mask); 1181 new_region = gfx::CreateHRGNFromSkPath(window_mask);
1180 } 1182 }
1181 1183
1182 if (current_rgn_result == ERROR || !EqualRgn(current_rgn, new_region)) { 1184 if (current_rgn_result == ERROR || !EqualRgn(current_rgn, new_region)) {
1183 // SetWindowRgn takes ownership of the HRGN created by CreateNativeRegion. 1185 // SetWindowRgn takes ownership of the HRGN created by CreateNativeRegion.
1184 SetWindowRgn(hwnd(), new_region, redraw); 1186 SetWindowRgn(hwnd(), new_region, redraw);
1185 } else { 1187 } else {
1186 DeleteObject(new_region); 1188 DeleteObject(new_region);
1187 } 1189 }
1188 1190
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
1405 // TODO(beng): move more of NWW::OnCreate here. 1407 // TODO(beng): move more of NWW::OnCreate here.
1406 return 0; 1408 return 0;
1407 } 1409 }
1408 1410
1409 void HWNDMessageHandler::OnDestroy() { 1411 void HWNDMessageHandler::OnDestroy() {
1410 WTSUnRegisterSessionNotification(hwnd()); 1412 WTSUnRegisterSessionNotification(hwnd());
1411 delegate_->HandleDestroying(); 1413 delegate_->HandleDestroying();
1412 } 1414 }
1413 1415
1414 void HWNDMessageHandler::OnDisplayChange(UINT bits_per_pixel, 1416 void HWNDMessageHandler::OnDisplayChange(UINT bits_per_pixel,
1415 const CSize& screen_size) { 1417 const gfx::Size& screen_size) {
1416 delegate_->HandleDisplayChange(); 1418 delegate_->HandleDisplayChange();
1417 } 1419 }
1418 1420
1419 LRESULT HWNDMessageHandler::OnDwmCompositionChanged(UINT msg, 1421 LRESULT HWNDMessageHandler::OnDwmCompositionChanged(UINT msg,
1420 WPARAM w_param, 1422 WPARAM w_param,
1421 LPARAM l_param) { 1423 LPARAM l_param) {
1422 if (!delegate_->IsWidgetWindow()) { 1424 if (!delegate_->IsWidgetWindow()) {
1423 SetMsgHandled(FALSE); 1425 SetMsgHandled(FALSE);
1424 return 0; 1426 return 0;
1425 } 1427 }
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1469 } 1471 }
1470 1472
1471 void HWNDMessageHandler::OnGetMinMaxInfo(MINMAXINFO* minmax_info) { 1473 void HWNDMessageHandler::OnGetMinMaxInfo(MINMAXINFO* minmax_info) {
1472 gfx::Size min_window_size; 1474 gfx::Size min_window_size;
1473 gfx::Size max_window_size; 1475 gfx::Size max_window_size;
1474 delegate_->GetMinMaxSize(&min_window_size, &max_window_size); 1476 delegate_->GetMinMaxSize(&min_window_size, &max_window_size);
1475 1477
1476 // Add the native frame border size to the minimum and maximum size if the 1478 // Add the native frame border size to the minimum and maximum size if the
1477 // view reports its size as the client size. 1479 // view reports its size as the client size.
1478 if (delegate_->WidgetSizeIsClientSize()) { 1480 if (delegate_->WidgetSizeIsClientSize()) {
1479 CRect client_rect, window_rect; 1481 RECT client_rect, window_rect;
1480 GetClientRect(hwnd(), &client_rect); 1482 GetClientRect(hwnd(), &client_rect);
1481 GetWindowRect(hwnd(), &window_rect); 1483 GetWindowRect(hwnd(), &window_rect);
1482 window_rect -= client_rect; 1484 CR_DEFLATE_RECT(&window_rect, &client_rect);
1483 min_window_size.Enlarge(window_rect.Width(), window_rect.Height()); 1485 min_window_size.Enlarge(window_rect.right - window_rect.left,
1484 if (!max_window_size.IsEmpty()) 1486 window_rect.bottom - window_rect.top);
1485 max_window_size.Enlarge(window_rect.Width(), window_rect.Height()); 1487 if (!max_window_size.IsEmpty()) {
1488 max_window_size.Enlarge(window_rect.right - window_rect.left,
1489 window_rect.bottom - window_rect.top);
1490 }
1486 } 1491 }
1487 minmax_info->ptMinTrackSize.x = min_window_size.width(); 1492 minmax_info->ptMinTrackSize.x = min_window_size.width();
1488 minmax_info->ptMinTrackSize.y = min_window_size.height(); 1493 minmax_info->ptMinTrackSize.y = min_window_size.height();
1489 if (max_window_size.width() || max_window_size.height()) { 1494 if (max_window_size.width() || max_window_size.height()) {
1490 if (!max_window_size.width()) 1495 if (!max_window_size.width())
1491 max_window_size.set_width(GetSystemMetrics(SM_CXMAXTRACK)); 1496 max_window_size.set_width(GetSystemMetrics(SM_CXMAXTRACK));
1492 if (!max_window_size.height()) 1497 if (!max_window_size.height())
1493 max_window_size.set_height(GetSystemMetrics(SM_CYMAXTRACK)); 1498 max_window_size.set_height(GetSystemMetrics(SM_CYMAXTRACK));
1494 minmax_info->ptMaxTrackSize.x = max_window_size.width(); 1499 minmax_info->ptMaxTrackSize.x = max_window_size.width();
1495 minmax_info->ptMaxTrackSize.y = max_window_size.height(); 1500 minmax_info->ptMaxTrackSize.y = max_window_size.height();
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
1608 // We handle touch events on Windows Aura. Windows generates synthesized 1613 // We handle touch events on Windows Aura. Windows generates synthesized
1609 // mouse messages in response to touch which we should ignore. However touch 1614 // mouse messages in response to touch which we should ignore. However touch
1610 // messages are only received for the client area. We need to ignore the 1615 // messages are only received for the client area. We need to ignore the
1611 // synthesized mouse messages for all points in the client area and places 1616 // synthesized mouse messages for all points in the client area and places
1612 // which return HTNOWHERE. 1617 // which return HTNOWHERE.
1613 if (ui::IsMouseEventFromTouch(message)) { 1618 if (ui::IsMouseEventFromTouch(message)) {
1614 LPARAM l_param_ht = l_param; 1619 LPARAM l_param_ht = l_param;
1615 // For mouse events (except wheel events), location is in window coordinates 1620 // For mouse events (except wheel events), location is in window coordinates
1616 // and should be converted to screen coordinates for WM_NCHITTEST. 1621 // and should be converted to screen coordinates for WM_NCHITTEST.
1617 if (message != WM_MOUSEWHEEL && message != WM_MOUSEHWHEEL) { 1622 if (message != WM_MOUSEWHEEL && message != WM_MOUSEHWHEEL) {
1618 CPoint screen_point(l_param_ht); 1623 POINT screen_point = CR_POINT_INITIALIZER_FROM_LPARAM(l_param_ht);
1619 MapWindowPoints(hwnd(), HWND_DESKTOP, &screen_point, 1); 1624 MapWindowPoints(hwnd(), HWND_DESKTOP, &screen_point, 1);
1620 l_param_ht = MAKELPARAM(screen_point.x, screen_point.y); 1625 l_param_ht = MAKELPARAM(screen_point.x, screen_point.y);
1621 } 1626 }
1622 LRESULT hittest = SendMessage(hwnd(), WM_NCHITTEST, 0, l_param_ht); 1627 LRESULT hittest = SendMessage(hwnd(), WM_NCHITTEST, 0, l_param_ht);
1623 if (hittest == HTCLIENT || hittest == HTNOWHERE) 1628 if (hittest == HTCLIENT || hittest == HTNOWHERE)
1624 return 0; 1629 return 0;
1625 } 1630 }
1626 #endif 1631 #endif
1627 if (message == WM_RBUTTONUP && is_right_mouse_pressed_on_caption_) { 1632 if (message == WM_RBUTTONUP && is_right_mouse_pressed_on_caption_) {
1628 is_right_mouse_pressed_on_caption_ = false; 1633 is_right_mouse_pressed_on_caption_ = false;
1629 ReleaseCapture(); 1634 ReleaseCapture();
1630 // |point| is in window coordinates, but WM_NCHITTEST and TrackPopupMenu() 1635 // |point| is in window coordinates, but WM_NCHITTEST and TrackPopupMenu()
1631 // expect screen coordinates. 1636 // expect screen coordinates.
1632 CPoint screen_point(l_param); 1637 POINT screen_point = CR_POINT_INITIALIZER_FROM_LPARAM(l_param);
1633 MapWindowPoints(hwnd(), HWND_DESKTOP, &screen_point, 1); 1638 MapWindowPoints(hwnd(), HWND_DESKTOP, &screen_point, 1);
1634 w_param = SendMessage(hwnd(), WM_NCHITTEST, 0, 1639 w_param = SendMessage(hwnd(), WM_NCHITTEST, 0,
1635 MAKELPARAM(screen_point.x, screen_point.y)); 1640 MAKELPARAM(screen_point.x, screen_point.y));
1636 if (w_param == HTCAPTION || w_param == HTSYSMENU) { 1641 if (w_param == HTCAPTION || w_param == HTSYSMENU) {
1637 gfx::ShowSystemMenuAtPoint(hwnd(), gfx::Point(screen_point)); 1642 gfx::ShowSystemMenuAtPoint(hwnd(), gfx::Point(screen_point));
1638 return 0; 1643 return 0;
1639 } 1644 }
1640 } else if (message == WM_NCLBUTTONDOWN && delegate_->IsUsingCustomFrame()) { 1645 } else if (message == WM_NCLBUTTONDOWN && delegate_->IsUsingCustomFrame()) {
1641 switch (w_param) { 1646 switch (w_param) {
1642 case HTCLOSE: 1647 case HTCLOSE:
(...skipping 19 matching lines...) Expand all
1662 } else if (message == WM_NCRBUTTONDOWN && 1667 } else if (message == WM_NCRBUTTONDOWN &&
1663 (w_param == HTCAPTION || w_param == HTSYSMENU)) { 1668 (w_param == HTCAPTION || w_param == HTSYSMENU)) {
1664 is_right_mouse_pressed_on_caption_ = true; 1669 is_right_mouse_pressed_on_caption_ = true;
1665 // We SetCapture() to ensure we only show the menu when the button 1670 // We SetCapture() to ensure we only show the menu when the button
1666 // down and up are both on the caption. Note: this causes the button up to 1671 // down and up are both on the caption. Note: this causes the button up to
1667 // be WM_RBUTTONUP instead of WM_NCRBUTTONUP. 1672 // be WM_RBUTTONUP instead of WM_NCRBUTTONUP.
1668 SetCapture(); 1673 SetCapture();
1669 } 1674 }
1670 1675
1671 MSG msg = { hwnd(), message, w_param, l_param, GetMessageTime(), 1676 MSG msg = { hwnd(), message, w_param, l_param, GetMessageTime(),
1672 { GET_X_LPARAM(l_param), GET_Y_LPARAM(l_param) } }; 1677 { CR_GET_X_LPARAM(l_param), CR_GET_Y_LPARAM(l_param) } };
1673 ui::MouseEvent event(msg); 1678 ui::MouseEvent event(msg);
1674 if (!touch_ids_.empty() || ui::IsMouseEventFromTouch(message)) 1679 if (!touch_ids_.empty() || ui::IsMouseEventFromTouch(message))
1675 event.set_flags(event.flags() | ui::EF_FROM_TOUCH); 1680 event.set_flags(event.flags() | ui::EF_FROM_TOUCH);
1676 1681
1677 if (!(event.flags() & ui::EF_IS_NON_CLIENT)) 1682 if (!(event.flags() & ui::EF_IS_NON_CLIENT))
1678 delegate_->HandleTooltipMouseMove(message, w_param, l_param); 1683 delegate_->HandleTooltipMouseMove(message, w_param, l_param);
1679 1684
1680 if (event.type() == ui::ET_MOUSE_MOVED && !HasCapture()) { 1685 if (event.type() == ui::ET_MOUSE_MOVED && !HasCapture()) {
1681 // Windows only fires WM_MOUSELEAVE events if the application begins 1686 // Windows only fires WM_MOUSELEAVE events if the application begins
1682 // "tracking" mouse events for a given HWND during WM_MOUSEMOVE events. 1687 // "tracking" mouse events for a given HWND during WM_MOUSEMOVE events.
(...skipping 25 matching lines...) Expand all
1708 // side-effects (ex/ stifling non-client mouse releases). 1713 // side-effects (ex/ stifling non-client mouse releases).
1709 DefWindowProcWithRedrawLock(message, w_param, l_param); 1714 DefWindowProcWithRedrawLock(message, w_param, l_param);
1710 handled = true; 1715 handled = true;
1711 } 1716 }
1712 1717
1713 if (ref.get()) 1718 if (ref.get())
1714 SetMsgHandled(handled); 1719 SetMsgHandled(handled);
1715 return 0; 1720 return 0;
1716 } 1721 }
1717 1722
1718 void HWNDMessageHandler::OnMove(const CPoint& point) { 1723 void HWNDMessageHandler::OnMove(const gfx::Point& point) {
1719 delegate_->HandleMove(); 1724 delegate_->HandleMove();
1720 SetMsgHandled(FALSE); 1725 SetMsgHandled(FALSE);
1721 } 1726 }
1722 1727
1723 void HWNDMessageHandler::OnMoving(UINT param, const RECT* new_bounds) { 1728 void HWNDMessageHandler::OnMoving(UINT param, const RECT* new_bounds) {
1724 delegate_->HandleMove(); 1729 delegate_->HandleMove();
1725 } 1730 }
1726 1731
1727 LRESULT HWNDMessageHandler::OnNCActivate(UINT message, 1732 LRESULT HWNDMessageHandler::OnNCActivate(UINT message,
1728 WPARAM w_param, 1733 WPARAM w_param,
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
1869 // pixels in the (now wrong) location, and thus makes actions like resizing a 1874 // pixels in the (now wrong) location, and thus makes actions like resizing a
1870 // window from the left edge look slightly less broken. 1875 // window from the left edge look slightly less broken.
1871 // We special case when left or top insets are 0, since these conditions 1876 // We special case when left or top insets are 0, since these conditions
1872 // actually require another repaint to correct the layout after glass gets 1877 // actually require another repaint to correct the layout after glass gets
1873 // turned on and off. 1878 // turned on and off.
1874 if (insets.left() == 0 || insets.top() == 0) 1879 if (insets.left() == 0 || insets.top() == 0)
1875 return 0; 1880 return 0;
1876 return mode ? WVR_REDRAW : 0; 1881 return mode ? WVR_REDRAW : 0;
1877 } 1882 }
1878 1883
1879 LRESULT HWNDMessageHandler::OnNCHitTest(const CPoint& point) { 1884 LRESULT HWNDMessageHandler::OnNCHitTest(const gfx::Point& point) {
1880 if (!delegate_->IsWidgetWindow()) { 1885 if (!delegate_->IsWidgetWindow()) {
1881 SetMsgHandled(FALSE); 1886 SetMsgHandled(FALSE);
1882 return 0; 1887 return 0;
1883 } 1888 }
1884 1889
1885 // If the DWM is rendering the window controls, we need to give the DWM's 1890 // If the DWM is rendering the window controls, we need to give the DWM's
1886 // default window procedure first chance to handle hit testing. 1891 // default window procedure first chance to handle hit testing.
1887 if (!remove_standard_frame_ && !delegate_->IsUsingCustomFrame()) { 1892 if (!remove_standard_frame_ && !delegate_->IsUsingCustomFrame()) {
1888 LRESULT result; 1893 LRESULT result;
1889 if (DwmDefWindowProc(hwnd(), WM_NCHITTEST, 0, 1894 if (DwmDefWindowProc(hwnd(), WM_NCHITTEST, 0,
1890 MAKELPARAM(point.x, point.y), &result)) { 1895 MAKELPARAM(point.x(), point.y()), &result)) {
1891 return result; 1896 return result;
1892 } 1897 }
1893 } 1898 }
1894 1899
1895 // First, give the NonClientView a chance to test the point to see if it 1900 // First, give the NonClientView a chance to test the point to see if it
1896 // provides any of the non-client area. 1901 // provides any of the non-client area.
1897 POINT temp = point; 1902 POINT temp = { point.x(), point.y() };
1898 MapWindowPoints(HWND_DESKTOP, hwnd(), &temp, 1); 1903 MapWindowPoints(HWND_DESKTOP, hwnd(), &temp, 1);
1899 int component = delegate_->GetNonClientComponent(gfx::Point(temp)); 1904 int component = delegate_->GetNonClientComponent(gfx::Point(temp));
1900 if (component != HTNOWHERE) 1905 if (component != HTNOWHERE)
1901 return component; 1906 return component;
1902 1907
1903 // Otherwise, we let Windows do all the native frame non-client handling for 1908 // Otherwise, we let Windows do all the native frame non-client handling for
1904 // us. 1909 // us.
1905 #if defined(USE_AURA) 1910 #if defined(USE_AURA)
1906 LRESULT hit_test_code = DefWindowProc(hwnd(), WM_NCHITTEST, 0, 1911 LRESULT hit_test_code = DefWindowProc(hwnd(), WM_NCHITTEST, 0,
1907 MAKELPARAM(point.x, point.y)); 1912 MAKELPARAM(point.x(), point.y()));
1908 if (needs_scroll_styles_) { 1913 if (needs_scroll_styles_) {
1909 switch (hit_test_code) { 1914 switch (hit_test_code) {
1910 // If we faked the WS_VSCROLL and WS_HSCROLL styles for this window, then 1915 // If we faked the WS_VSCROLL and WS_HSCROLL styles for this window, then
1911 // Windows returns the HTVSCROLL or HTHSCROLL hit test codes if we hover 1916 // Windows returns the HTVSCROLL or HTHSCROLL hit test codes if we hover
1912 // or click on the non client portions of the window where the OS 1917 // or click on the non client portions of the window where the OS
1913 // scrollbars would be drawn. These hittest codes are returned even when 1918 // scrollbars would be drawn. These hittest codes are returned even when
1914 // the scrollbars are hidden, which is the case in Aura. We fake the 1919 // the scrollbars are hidden, which is the case in Aura. We fake the
1915 // hittest code as HTCLIENT in this case to ensure that we receive client 1920 // hittest code as HTCLIENT in this case to ensure that we receive client
1916 // mouse messages as opposed to non client mouse messages. 1921 // mouse messages as opposed to non client mouse messages.
1917 case HTVSCROLL: 1922 case HTVSCROLL:
(...skipping 12 matching lines...) Expand all
1930 int border_height = ::GetSystemMetrics(SM_CYSIZEFRAME); 1935 int border_height = ::GetSystemMetrics(SM_CYSIZEFRAME);
1931 int scroll_width = ::GetSystemMetrics(SM_CXVSCROLL); 1936 int scroll_width = ::GetSystemMetrics(SM_CXVSCROLL);
1932 int scroll_height = ::GetSystemMetrics(SM_CYVSCROLL); 1937 int scroll_height = ::GetSystemMetrics(SM_CYVSCROLL);
1933 RECT window_rect; 1938 RECT window_rect;
1934 ::GetWindowRect(hwnd(), &window_rect); 1939 ::GetWindowRect(hwnd(), &window_rect);
1935 window_rect.bottom -= border_height; 1940 window_rect.bottom -= border_height;
1936 window_rect.right -= border_width; 1941 window_rect.right -= border_width;
1937 window_rect.left = window_rect.right - scroll_width; 1942 window_rect.left = window_rect.right - scroll_width;
1938 window_rect.top = window_rect.bottom - scroll_height; 1943 window_rect.top = window_rect.bottom - scroll_height;
1939 POINT pt; 1944 POINT pt;
1940 pt.x = point.x; 1945 pt.x = point.x();
1941 pt.y = point.y; 1946 pt.y = point.y();
1942 if (::PtInRect(&window_rect, pt)) 1947 if (::PtInRect(&window_rect, pt))
1943 hit_test_code = HTCLIENT; 1948 hit_test_code = HTCLIENT;
1944 break; 1949 break;
1945 } 1950 }
1946 1951
1947 default: 1952 default:
1948 break; 1953 break;
1949 } 1954 }
1950 } 1955 }
1951 return hit_test_code; 1956 return hit_test_code;
1952 #else 1957 #else
1953 SetMsgHandled(FALSE); 1958 SetMsgHandled(FALSE);
1954 #endif 1959 #endif
1955 } 1960 }
1956 1961
1957 void HWNDMessageHandler::OnNCPaint(HRGN rgn) { 1962 void HWNDMessageHandler::OnNCPaint(HRGN rgn) {
1958 // We only do non-client painting if we're not using the native frame. 1963 // We only do non-client painting if we're not using the native frame.
1959 // It's required to avoid some native painting artifacts from appearing when 1964 // It's required to avoid some native painting artifacts from appearing when
1960 // the window is resized. 1965 // the window is resized.
1961 if (!delegate_->IsWidgetWindow() || !delegate_->IsUsingCustomFrame()) { 1966 if (!delegate_->IsWidgetWindow() || !delegate_->IsUsingCustomFrame()) {
1962 SetMsgHandled(FALSE); 1967 SetMsgHandled(FALSE);
1963 return; 1968 return;
1964 } 1969 }
1965 1970
1966 // We have an NC region and need to paint it. We expand the NC region to 1971 // We have an NC region and need to paint it. We expand the NC region to
1967 // include the dirty region of the root view. This is done to minimize 1972 // include the dirty region of the root view. This is done to minimize
1968 // paints. 1973 // paints.
1969 CRect window_rect; 1974 RECT window_rect;
1970 GetWindowRect(hwnd(), &window_rect); 1975 GetWindowRect(hwnd(), &window_rect);
1971 1976
1972 gfx::Size root_view_size = delegate_->GetRootViewSize(); 1977 gfx::Size root_view_size = delegate_->GetRootViewSize();
1973 if (gfx::Size(window_rect.Width(), window_rect.Height()) != root_view_size) { 1978 if (gfx::Size(window_rect.right - window_rect.left,
1979 window_rect.bottom - window_rect.top) != root_view_size) {
1974 // If the size of the window differs from the size of the root view it 1980 // If the size of the window differs from the size of the root view it
1975 // means we're being asked to paint before we've gotten a WM_SIZE. This can 1981 // means we're being asked to paint before we've gotten a WM_SIZE. This can
1976 // happen when the user is interactively resizing the window. To avoid 1982 // happen when the user is interactively resizing the window. To avoid
1977 // mass flickering we don't do anything here. Once we get the WM_SIZE we'll 1983 // mass flickering we don't do anything here. Once we get the WM_SIZE we'll
1978 // reset the region of the window which triggers another WM_NCPAINT and 1984 // reset the region of the window which triggers another WM_NCPAINT and
1979 // all is well. 1985 // all is well.
1980 return; 1986 return;
1981 } 1987 }
1982 1988
1983 CRect dirty_region; 1989 RECT dirty_region;
1984 // A value of 1 indicates paint all. 1990 // A value of 1 indicates paint all.
1985 if (!rgn || rgn == reinterpret_cast<HRGN>(1)) { 1991 if (!rgn || rgn == reinterpret_cast<HRGN>(1)) {
1986 dirty_region = CRect(0, 0, window_rect.Width(), window_rect.Height()); 1992 dirty_region.left = 0;
1993 dirty_region.top = 0;
1994 dirty_region.right = window_rect.right - window_rect.left;
1995 dirty_region.bottom = window_rect.bottom - window_rect.top;
1987 } else { 1996 } else {
1988 RECT rgn_bounding_box; 1997 RECT rgn_bounding_box;
1989 GetRgnBox(rgn, &rgn_bounding_box); 1998 GetRgnBox(rgn, &rgn_bounding_box);
1990 if (!IntersectRect(&dirty_region, &rgn_bounding_box, &window_rect)) 1999 if (!IntersectRect(&dirty_region, &rgn_bounding_box, &window_rect))
1991 return; // Dirty region doesn't intersect window bounds, bale. 2000 return; // Dirty region doesn't intersect window bounds, bale.
1992 2001
1993 // rgn_bounding_box is in screen coordinates. Map it to window coordinates. 2002 // rgn_bounding_box is in screen coordinates. Map it to window coordinates.
1994 OffsetRect(&dirty_region, -window_rect.left, -window_rect.top); 2003 OffsetRect(&dirty_region, -window_rect.left, -window_rect.top);
1995 } 2004 }
1996 2005
1997 // In theory GetDCEx should do what we want, but I couldn't get it to work. 2006 // In theory GetDCEx should do what we want, but I couldn't get it to work.
1998 // In particular the docs mentiond DCX_CLIPCHILDREN, but as far as I can tell 2007 // In particular the docs mentiond DCX_CLIPCHILDREN, but as far as I can tell
1999 // it doesn't work at all. So, instead we get the DC for the window then 2008 // it doesn't work at all. So, instead we get the DC for the window then
2000 // manually clip out the children. 2009 // manually clip out the children.
2001 HDC dc = GetWindowDC(hwnd()); 2010 HDC dc = GetWindowDC(hwnd());
2002 ClipState clip_state; 2011 ClipState clip_state;
2003 clip_state.x = window_rect.left; 2012 clip_state.x = window_rect.left;
2004 clip_state.y = window_rect.top; 2013 clip_state.y = window_rect.top;
2005 clip_state.parent = hwnd(); 2014 clip_state.parent = hwnd();
2006 clip_state.dc = dc; 2015 clip_state.dc = dc;
2007 EnumChildWindows(hwnd(), &ClipDCToChild, 2016 EnumChildWindows(hwnd(), &ClipDCToChild,
2008 reinterpret_cast<LPARAM>(&clip_state)); 2017 reinterpret_cast<LPARAM>(&clip_state));
2009 2018
2010 gfx::Rect old_paint_region = invalid_rect_; 2019 gfx::Rect old_paint_region = invalid_rect_;
2011 if (!old_paint_region.IsEmpty()) { 2020 if (!old_paint_region.IsEmpty()) {
2012 // The root view has a region that needs to be painted. Include it in the 2021 // The root view has a region that needs to be painted. Include it in the
2013 // region we're going to paint. 2022 // region we're going to paint.
2014 2023
2015 CRect old_paint_region_crect = old_paint_region.ToRECT(); 2024 RECT old_paint_region_crect = old_paint_region.ToRECT();
2016 CRect tmp = dirty_region; 2025 RECT tmp = dirty_region;
2017 UnionRect(&dirty_region, &tmp, &old_paint_region_crect); 2026 UnionRect(&dirty_region, &tmp, &old_paint_region_crect);
2018 } 2027 }
2019 2028
2020 SchedulePaintInRect(gfx::Rect(dirty_region)); 2029 SchedulePaintInRect(gfx::Rect(dirty_region));
2021 2030
2022 // gfx::CanvasSkiaPaint's destructor does the actual painting. As such, wrap 2031 // gfx::CanvasSkiaPaint's destructor does the actual painting. As such, wrap
2023 // the following in a block to force paint to occur so that we can release 2032 // the following in a block to force paint to occur so that we can release
2024 // the dc. 2033 // the dc.
2025 if (!delegate_->HandlePaintAccelerated(gfx::Rect(dirty_region))) { 2034 if (!delegate_->HandlePaintAccelerated(gfx::Rect(dirty_region))) {
2026 gfx::CanvasSkiaPaint canvas(dc, true, dirty_region.left, 2035 gfx::CanvasSkiaPaint canvas(dc,
2027 dirty_region.top, dirty_region.Width(), 2036 true,
2028 dirty_region.Height()); 2037 dirty_region.left,
2038 dirty_region.top,
2039 dirty_region.right - dirty_region.left,
2040 dirty_region.bottom - dirty_region.top);
2029 delegate_->HandlePaint(&canvas); 2041 delegate_->HandlePaint(&canvas);
2030 } 2042 }
2031 2043
2032 ReleaseDC(hwnd(), dc); 2044 ReleaseDC(hwnd(), dc);
2033 // When using a custom frame, we want to avoid calling DefWindowProc() since 2045 // When using a custom frame, we want to avoid calling DefWindowProc() since
2034 // that may render artifacts. 2046 // that may render artifacts.
2035 SetMsgHandled(delegate_->IsUsingCustomFrame()); 2047 SetMsgHandled(delegate_->IsUsingCustomFrame());
2036 } 2048 }
2037 2049
2038 LRESULT HWNDMessageHandler::OnNCUAHDrawCaption(UINT message, 2050 LRESULT HWNDMessageHandler::OnNCUAHDrawCaption(UINT message,
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
2174 ::SetWindowPos(hwnd(), 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | 2186 ::SetWindowPos(hwnd(), 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE |
2175 SWP_NOZORDER | SWP_NOREDRAW | SWP_NOACTIVATE | SWP_NOOWNERZORDER); 2187 SWP_NOZORDER | SWP_NOREDRAW | SWP_NOACTIVATE | SWP_NOOWNERZORDER);
2176 SetMsgHandled(TRUE); 2188 SetMsgHandled(TRUE);
2177 } else { 2189 } else {
2178 if (flags == SPI_SETWORKAREA) 2190 if (flags == SPI_SETWORKAREA)
2179 delegate_->HandleWorkAreaChanged(); 2191 delegate_->HandleWorkAreaChanged();
2180 SetMsgHandled(FALSE); 2192 SetMsgHandled(FALSE);
2181 } 2193 }
2182 } 2194 }
2183 2195
2184 void HWNDMessageHandler::OnSize(UINT param, const CSize& size) { 2196 void HWNDMessageHandler::OnSize(UINT param, const gfx::Size& size) {
2185 RedrawWindow(hwnd(), NULL, NULL, RDW_INVALIDATE | RDW_ALLCHILDREN); 2197 RedrawWindow(hwnd(), NULL, NULL, RDW_INVALIDATE | RDW_ALLCHILDREN);
2186 // ResetWindowRegion is going to trigger WM_NCPAINT. By doing it after we've 2198 // ResetWindowRegion is going to trigger WM_NCPAINT. By doing it after we've
2187 // invoked OnSize we ensure the RootView has been laid out. 2199 // invoked OnSize we ensure the RootView has been laid out.
2188 ResetWindowRegion(false, true); 2200 ResetWindowRegion(false, true);
2189 2201
2190 #if defined(USE_AURA) 2202 #if defined(USE_AURA)
2191 // We add the WS_VSCROLL and WS_HSCROLL styles to top level windows to ensure 2203 // We add the WS_VSCROLL and WS_HSCROLL styles to top level windows to ensure
2192 // that legacy trackpad/trackpoint drivers generate the WM_VSCROLL and 2204 // that legacy trackpad/trackpoint drivers generate the WM_VSCROLL and
2193 // WM_HSCROLL messages and scrolling works. 2205 // WM_HSCROLL messages and scrolling works.
2194 // We want the scroll styles to be present on the window. However we don't 2206 // We want the scroll styles to be present on the window. However we don't
2195 // want Windows to draw the scrollbars. To achieve this we hide the scroll 2207 // want Windows to draw the scrollbars. To achieve this we hide the scroll
2196 // bars and readd them to the window style in a posted task to ensure that we 2208 // bars and readd them to the window style in a posted task to ensure that we
2197 // don't get nested WM_SIZE messages. 2209 // don't get nested WM_SIZE messages.
2198 if (needs_scroll_styles_ && !in_size_loop_) { 2210 if (needs_scroll_styles_ && !in_size_loop_) {
2199 ShowScrollBar(hwnd(), SB_BOTH, FALSE); 2211 ShowScrollBar(hwnd(), SB_BOTH, FALSE);
2200 base::MessageLoop::current()->PostTask( 2212 base::MessageLoop::current()->PostTask(
2201 FROM_HERE, base::Bind(&AddScrollStylesToWindow, hwnd())); 2213 FROM_HERE, base::Bind(&AddScrollStylesToWindow, hwnd()));
2202 } 2214 }
2203 #endif 2215 #endif
2204 } 2216 }
2205 2217
2206 void HWNDMessageHandler::OnSysCommand(UINT notification_code, 2218 void HWNDMessageHandler::OnSysCommand(UINT notification_code,
2207 const CPoint& point) { 2219 const gfx::Point& point) {
2208 if (!delegate_->ShouldHandleSystemCommands()) 2220 if (!delegate_->ShouldHandleSystemCommands())
2209 return; 2221 return;
2210 2222
2211 // Windows uses the 4 lower order bits of |notification_code| for type- 2223 // Windows uses the 4 lower order bits of |notification_code| for type-
2212 // specific information so we must exclude this when comparing. 2224 // specific information so we must exclude this when comparing.
2213 static const int sc_mask = 0xFFF0; 2225 static const int sc_mask = 0xFFF0;
2214 // Ignore size/move/maximize in fullscreen mode. 2226 // Ignore size/move/maximize in fullscreen mode.
2215 if (fullscreen_handler_->fullscreen() && 2227 if (fullscreen_handler_->fullscreen() &&
2216 (((notification_code & sc_mask) == SC_SIZE) || 2228 (((notification_code & sc_mask) == SC_SIZE) ||
2217 ((notification_code & sc_mask) == SC_MOVE) || 2229 ((notification_code & sc_mask) == SC_MOVE) ||
(...skipping 10 matching lines...) Expand all
2228 // Circumvent ScopedRedrawLocks and force visibility before entering a 2240 // Circumvent ScopedRedrawLocks and force visibility before entering a
2229 // resize or move modal loop to get continuous sizing/moving feedback. 2241 // resize or move modal loop to get continuous sizing/moving feedback.
2230 SetWindowLong(hwnd(), GWL_STYLE, 2242 SetWindowLong(hwnd(), GWL_STYLE,
2231 GetWindowLong(hwnd(), GWL_STYLE) | WS_VISIBLE); 2243 GetWindowLong(hwnd(), GWL_STYLE) | WS_VISIBLE);
2232 } 2244 }
2233 } 2245 }
2234 } 2246 }
2235 2247
2236 // Handle SC_KEYMENU, which means that the user has pressed the ALT 2248 // Handle SC_KEYMENU, which means that the user has pressed the ALT
2237 // key and released it, so we should focus the menu bar. 2249 // key and released it, so we should focus the menu bar.
2238 if ((notification_code & sc_mask) == SC_KEYMENU && point.x == 0) { 2250 if ((notification_code & sc_mask) == SC_KEYMENU && point.x() == 0) {
2239 int modifiers = ui::EF_NONE; 2251 int modifiers = ui::EF_NONE;
2240 if (base::win::IsShiftPressed()) 2252 if (base::win::IsShiftPressed())
2241 modifiers |= ui::EF_SHIFT_DOWN; 2253 modifiers |= ui::EF_SHIFT_DOWN;
2242 if (base::win::IsCtrlPressed()) 2254 if (base::win::IsCtrlPressed())
2243 modifiers |= ui::EF_CONTROL_DOWN; 2255 modifiers |= ui::EF_CONTROL_DOWN;
2244 // Retrieve the status of shift and control keys to prevent consuming 2256 // Retrieve the status of shift and control keys to prevent consuming
2245 // shift+alt keys, which are used by Windows to change input languages. 2257 // shift+alt keys, which are used by Windows to change input languages.
2246 ui::Accelerator accelerator(ui::KeyboardCodeForWindowsKeyCode(VK_MENU), 2258 ui::Accelerator accelerator(ui::KeyboardCodeForWindowsKeyCode(VK_MENU),
2247 modifiers); 2259 modifiers);
2248 delegate_->HandleAccelerator(accelerator); 2260 delegate_->HandleAccelerator(accelerator);
2249 return; 2261 return;
2250 } 2262 }
2251 2263
2252 // If the delegate can't handle it, the system implementation will be called. 2264 // If the delegate can't handle it, the system implementation will be called.
2253 if (!delegate_->HandleCommand(notification_code)) { 2265 if (!delegate_->HandleCommand(notification_code)) {
2254 // If the window is being resized by dragging the borders of the window 2266 // If the window is being resized by dragging the borders of the window
2255 // with the mouse/touch/keyboard, we flag as being in a size loop. 2267 // with the mouse/touch/keyboard, we flag as being in a size loop.
2256 if ((notification_code & sc_mask) == SC_SIZE) 2268 if ((notification_code & sc_mask) == SC_SIZE)
2257 in_size_loop_ = true; 2269 in_size_loop_ = true;
2258 DefWindowProc(hwnd(), WM_SYSCOMMAND, notification_code, 2270 DefWindowProc(hwnd(), WM_SYSCOMMAND, notification_code,
2259 MAKELPARAM(point.x, point.y)); 2271 MAKELPARAM(point.x(), point.y()));
2260 in_size_loop_ = false; 2272 in_size_loop_ = false;
2261 } 2273 }
2262 } 2274 }
2263 2275
2264 void HWNDMessageHandler::OnThemeChanged() { 2276 void HWNDMessageHandler::OnThemeChanged() {
2265 ui::NativeThemeWin::instance()->CloseHandles(); 2277 ui::NativeThemeWin::instance()->CloseHandles();
2266 } 2278 }
2267 2279
2268 LRESULT HWNDMessageHandler::OnTouchEvent(UINT message, 2280 LRESULT HWNDMessageHandler::OnTouchEvent(UINT message,
2269 WPARAM w_param, 2281 WPARAM w_param,
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
2330 // If somebody's trying to toggle our visibility, change the nonclient area, 2342 // If somebody's trying to toggle our visibility, change the nonclient area,
2331 // change our Z-order, or activate us, we should probably let it go through. 2343 // change our Z-order, or activate us, we should probably let it go through.
2332 if (!(window_pos->flags & ((IsVisible() ? SWP_HIDEWINDOW : SWP_SHOWWINDOW) | 2344 if (!(window_pos->flags & ((IsVisible() ? SWP_HIDEWINDOW : SWP_SHOWWINDOW) |
2333 SWP_FRAMECHANGED)) && 2345 SWP_FRAMECHANGED)) &&
2334 (window_pos->flags & (SWP_NOZORDER | SWP_NOACTIVATE))) { 2346 (window_pos->flags & (SWP_NOZORDER | SWP_NOACTIVATE))) {
2335 // Just sizing/moving the window; ignore. 2347 // Just sizing/moving the window; ignore.
2336 window_pos->flags |= SWP_NOSIZE | SWP_NOMOVE | SWP_NOREDRAW; 2348 window_pos->flags |= SWP_NOSIZE | SWP_NOMOVE | SWP_NOREDRAW;
2337 window_pos->flags &= ~(SWP_SHOWWINDOW | SWP_HIDEWINDOW); 2349 window_pos->flags &= ~(SWP_SHOWWINDOW | SWP_HIDEWINDOW);
2338 } 2350 }
2339 } else if (!GetParent(hwnd())) { 2351 } else if (!GetParent(hwnd())) {
2340 CRect window_rect; 2352 RECT window_rect;
2341 HMONITOR monitor; 2353 HMONITOR monitor;
2342 gfx::Rect monitor_rect, work_area; 2354 gfx::Rect monitor_rect, work_area;
2343 if (GetWindowRect(hwnd(), &window_rect) && 2355 if (GetWindowRect(hwnd(), &window_rect) &&
2344 GetMonitorAndRects(window_rect, &monitor, &monitor_rect, &work_area)) { 2356 GetMonitorAndRects(window_rect, &monitor, &monitor_rect, &work_area)) {
2345 bool work_area_changed = (monitor_rect == last_monitor_rect_) && 2357 bool work_area_changed = (monitor_rect == last_monitor_rect_) &&
2346 (work_area != last_work_area_); 2358 (work_area != last_work_area_);
2347 if (monitor && (monitor == last_monitor_) && 2359 if (monitor && (monitor == last_monitor_) &&
2348 ((fullscreen_handler_->fullscreen() && 2360 ((fullscreen_handler_->fullscreen() &&
2349 !fullscreen_handler_->metro_snap()) || 2361 !fullscreen_handler_->metro_snap()) ||
2350 work_area_changed)) { 2362 work_area_changed)) {
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
2421 SetMsgHandled(FALSE); 2433 SetMsgHandled(FALSE);
2422 } 2434 }
2423 2435
2424 void HWNDMessageHandler::HandleTouchEvents(const TouchEvents& touch_events) { 2436 void HWNDMessageHandler::HandleTouchEvents(const TouchEvents& touch_events) {
2425 base::WeakPtr<HWNDMessageHandler> ref(weak_factory_.GetWeakPtr()); 2437 base::WeakPtr<HWNDMessageHandler> ref(weak_factory_.GetWeakPtr());
2426 for (size_t i = 0; i < touch_events.size() && ref; ++i) 2438 for (size_t i = 0; i < touch_events.size() && ref; ++i)
2427 delegate_->HandleTouchEvent(touch_events[i]); 2439 delegate_->HandleTouchEvent(touch_events[i]);
2428 } 2440 }
2429 2441
2430 } // namespace views 2442 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/win/hwnd_message_handler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698