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 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
447 | 447 |
448 void HWNDMessageHandler::CloseNow() { | 448 void HWNDMessageHandler::CloseNow() { |
449 // We may already have been destroyed if the selection resulted in a tab | 449 // We may already have been destroyed if the selection resulted in a tab |
450 // switch which will have reactivated the browser window and closed us, so | 450 // switch which will have reactivated the browser window and closed us, so |
451 // we need to check to see if we're still a window before trying to destroy | 451 // we need to check to see if we're still a window before trying to destroy |
452 // ourself. | 452 // ourself. |
453 if (IsWindow(hwnd())) | 453 if (IsWindow(hwnd())) |
454 DestroyWindow(hwnd()); | 454 DestroyWindow(hwnd()); |
455 } | 455 } |
456 | 456 |
| 457 void ConvertToScreen(RECT* rect) { |
| 458 #if defined(ENABLE_HIDPI) |
| 459 static float os_scale = ui::GetDPIScale(); |
| 460 rect->left *= os_scale; |
| 461 rect->right *= os_scale; |
| 462 rect->top *= os_scale; |
| 463 rect->bottom *= os_scale; |
| 464 #endif |
| 465 } |
| 466 |
| 467 void ConvertToScreen(POINT* point) { |
| 468 #if defined(ENABLE_HIDPI) |
| 469 static float os_scale = ui::GetDPIScale(); |
| 470 point->x *= os_scale; |
| 471 point->y *= os_scale; |
| 472 #endif |
| 473 } |
| 474 |
457 gfx::Rect HWNDMessageHandler::GetWindowBoundsInScreen() const { | 475 gfx::Rect HWNDMessageHandler::GetWindowBoundsInScreen() const { |
458 RECT r; | 476 RECT r; |
459 GetWindowRect(hwnd(), &r); | 477 GetWindowRect(hwnd(), &r); |
| 478 ConvertToScreen(&r); |
460 return gfx::Rect(r); | 479 return gfx::Rect(r); |
461 } | 480 } |
462 | 481 |
463 gfx::Rect HWNDMessageHandler::GetClientAreaBoundsInScreen() const { | 482 gfx::Rect HWNDMessageHandler::GetClientAreaBoundsInScreen() const { |
464 RECT r; | 483 RECT r; |
465 GetClientRect(hwnd(), &r); | 484 GetClientRect(hwnd(), &r); |
466 POINT point = { r.left, r.top }; | 485 POINT point = { r.left, r.top }; |
467 ClientToScreen(hwnd(), &point); | 486 ClientToScreen(hwnd(), &point); |
| 487 ConvertToScreen(&r); // Scales right/left |
| 488 ConvertToScreen(&point); // Scale x/y |
468 return gfx::Rect(point.x, point.y, r.right - r.left, r.bottom - r.top); | 489 return gfx::Rect(point.x, point.y, r.right - r.left, r.bottom - r.top); |
469 } | 490 } |
470 | 491 |
471 gfx::Rect HWNDMessageHandler::GetRestoredBounds() const { | 492 gfx::Rect HWNDMessageHandler::GetRestoredBounds() const { |
472 // If we're in fullscreen mode, we've changed the normal bounds to the monitor | 493 // If we're in fullscreen mode, we've changed the normal bounds to the monitor |
473 // rect, so return the saved bounds instead. | 494 // rect, so return the saved bounds instead. |
474 if (fullscreen_handler_->fullscreen()) | 495 if (fullscreen_handler_->fullscreen()) |
475 return fullscreen_handler_->GetRestoreBounds(); | 496 return fullscreen_handler_->GetRestoreBounds(); |
476 | 497 |
477 gfx::Rect bounds; | 498 gfx::Rect bounds; |
(...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1034 tme.dwFlags = mouse_tracking_flags; | 1055 tme.dwFlags = mouse_tracking_flags; |
1035 tme.hwndTrack = hwnd(); | 1056 tme.hwndTrack = hwnd(); |
1036 tme.dwHoverTime = 0; | 1057 tme.dwHoverTime = 0; |
1037 TrackMouseEvent(&tme); | 1058 TrackMouseEvent(&tme); |
1038 } else if (mouse_tracking_flags != active_mouse_tracking_flags_) { | 1059 } else if (mouse_tracking_flags != active_mouse_tracking_flags_) { |
1039 TrackMouseEvents(active_mouse_tracking_flags_ | TME_CANCEL); | 1060 TrackMouseEvents(active_mouse_tracking_flags_ | TME_CANCEL); |
1040 TrackMouseEvents(mouse_tracking_flags); | 1061 TrackMouseEvents(mouse_tracking_flags); |
1041 } | 1062 } |
1042 } | 1063 } |
1043 | 1064 |
| 1065 ui::ScaleFactor GetScaleFactor() { |
| 1066 #if defined(ENABLE_HIDPI) |
| 1067 float scale = ui::GetDPIScale(); |
| 1068 if (scale > 1.6) |
| 1069 return ui::SCALE_FACTOR_180P; |
| 1070 else if (scale > 1.2) |
| 1071 return ui::SCALE_FACTOR_140P; |
| 1072 #endif |
| 1073 return ui::SCALE_FACTOR_100P; |
| 1074 } |
| 1075 |
1044 void HWNDMessageHandler::ClientAreaSizeChanged() { | 1076 void HWNDMessageHandler::ClientAreaSizeChanged() { |
1045 RECT r = {0, 0, 0, 0}; | 1077 RECT r = {0, 0, 0, 0}; |
1046 if (delegate_->WidgetSizeIsClientSize()) { | 1078 if (delegate_->WidgetSizeIsClientSize()) { |
1047 // TODO(beng): investigate whether this could be done | 1079 // TODO(beng): investigate whether this could be done |
1048 // from other branch of if-else. | 1080 // from other branch of if-else. |
1049 if (!IsMinimized()) | 1081 if (!IsMinimized()) |
1050 GetClientRect(hwnd(), &r); | 1082 GetClientRect(hwnd(), &r); |
1051 } else { | 1083 } else { |
1052 GetWindowRect(hwnd(), &r); | 1084 GetWindowRect(hwnd(), &r); |
1053 } | 1085 } |
1054 gfx::Size s(std::max(0, static_cast<int>(r.right - r.left)), | 1086 gfx::Size s(std::max(0, static_cast<int>(r.right - r.left)), |
1055 std::max(0, static_cast<int>(r.bottom - r.top))); | 1087 std::max(0, static_cast<int>(r.bottom - r.top))); |
1056 delegate_->HandleClientSizeChanged(s); | 1088 delegate_->HandleClientSizeChanged(s); |
1057 if (use_layered_buffer_) { | 1089 if (use_layered_buffer_) { |
1058 layered_window_contents_.reset( | 1090 layered_window_contents_.reset( |
1059 new gfx::Canvas(s, ui::SCALE_FACTOR_100P, false)); | 1091 new gfx::Canvas(s, GetScaleFactor(), false)); |
1060 } | 1092 } |
1061 } | 1093 } |
1062 | 1094 |
1063 gfx::Insets HWNDMessageHandler::GetClientAreaInsets() const { | 1095 gfx::Insets HWNDMessageHandler::GetClientAreaInsets() const { |
1064 gfx::Insets insets; | 1096 gfx::Insets insets; |
1065 if (delegate_->GetClientAreaInsets(&insets)) | 1097 if (delegate_->GetClientAreaInsets(&insets)) |
1066 return insets; | 1098 return insets; |
1067 DCHECK(insets.empty()); | 1099 DCHECK(insets.empty()); |
1068 | 1100 |
1069 // Returning an empty Insets object causes the default handling in | 1101 // Returning an empty Insets object causes the default handling in |
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1458 // TODO(beng): resolve this with the GetWindowLong() check on the subsequent | 1490 // TODO(beng): resolve this with the GetWindowLong() check on the subsequent |
1459 // line. | 1491 // line. |
1460 if (delegate_->IsWidgetWindow()) | 1492 if (delegate_->IsWidgetWindow()) |
1461 return delegate_->CanActivate() ? MA_ACTIVATE : MA_NOACTIVATEANDEAT; | 1493 return delegate_->CanActivate() ? MA_ACTIVATE : MA_NOACTIVATEANDEAT; |
1462 if (GetWindowLong(hwnd(), GWL_EXSTYLE) & WS_EX_NOACTIVATE) | 1494 if (GetWindowLong(hwnd(), GWL_EXSTYLE) & WS_EX_NOACTIVATE) |
1463 return MA_NOACTIVATE; | 1495 return MA_NOACTIVATE; |
1464 SetMsgHandled(FALSE); | 1496 SetMsgHandled(FALSE); |
1465 return MA_ACTIVATE; | 1497 return MA_ACTIVATE; |
1466 } | 1498 } |
1467 | 1499 |
| 1500 void ScaleScreenPoint(CPoint* point) { |
| 1501 static float dpi_scale = ui::GetDPIScale(); |
| 1502 point->SetPoint( point->x * dpi_scale, point->y * dpi_scale); |
| 1503 } |
| 1504 |
| 1505 void ScaleScreenPoint(POINT* point) { |
| 1506 static float dpi_scale = ui::GetDPIScale(); |
| 1507 point->x *= dpi_scale; |
| 1508 point->y *= dpi_scale; |
| 1509 } |
| 1510 |
1468 LRESULT HWNDMessageHandler::OnMouseRange(UINT message, | 1511 LRESULT HWNDMessageHandler::OnMouseRange(UINT message, |
1469 WPARAM w_param, | 1512 WPARAM w_param, |
1470 LPARAM l_param) { | 1513 LPARAM l_param) { |
1471 #if defined(USE_AURA) | 1514 #if defined(USE_AURA) |
1472 // We handle touch events on Windows Aura. Ignore synthesized mouse messages | 1515 // We handle touch events on Windows Aura. Ignore synthesized mouse messages |
1473 // from Windows. | 1516 // from Windows. |
1474 if (!touch_ids_.empty() || ui::IsMouseEventFromTouch(message)) | 1517 if (!touch_ids_.empty() || ui::IsMouseEventFromTouch(message)) |
1475 return 0; | 1518 return 0; |
1476 #endif | 1519 #endif |
1477 if (message == WM_RBUTTONUP && is_right_mouse_pressed_on_caption_) { | 1520 if (message == WM_RBUTTONUP && is_right_mouse_pressed_on_caption_) { |
1478 is_right_mouse_pressed_on_caption_ = false; | 1521 is_right_mouse_pressed_on_caption_ = false; |
1479 ReleaseCapture(); | 1522 ReleaseCapture(); |
1480 // |point| is in window coordinates, but WM_NCHITTEST and TrackPopupMenu() | 1523 // |point| is in window coordinates, but WM_NCHITTEST and TrackPopupMenu() |
1481 // expect screen coordinates. | 1524 // expect screen coordinates. |
1482 CPoint screen_point(l_param); | 1525 CPoint screen_point(l_param); |
| 1526 ScaleScreenPoint(&screen_point); |
1483 MapWindowPoints(hwnd(), HWND_DESKTOP, &screen_point, 1); | 1527 MapWindowPoints(hwnd(), HWND_DESKTOP, &screen_point, 1); |
1484 w_param = SendMessage(hwnd(), WM_NCHITTEST, 0, | 1528 w_param = SendMessage(hwnd(), WM_NCHITTEST, 0, |
1485 MAKELPARAM(screen_point.x, screen_point.y)); | 1529 MAKELPARAM(screen_point.x, screen_point.y)); |
1486 if (w_param == HTCAPTION || w_param == HTSYSMENU) { | 1530 if (w_param == HTCAPTION || w_param == HTSYSMENU) { |
1487 ui::ShowSystemMenu(hwnd(), screen_point.x, screen_point.y); | 1531 ui::ShowSystemMenu(hwnd(), screen_point.x, screen_point.y); |
1488 return 0; | 1532 return 0; |
1489 } | 1533 } |
1490 } else if (message == WM_NCLBUTTONDOWN && delegate_->IsUsingCustomFrame()) { | 1534 } else if (message == WM_NCLBUTTONDOWN && delegate_->IsUsingCustomFrame()) { |
1491 switch (w_param) { | 1535 switch (w_param) { |
1492 case HTCLOSE: | 1536 case HTCLOSE: |
(...skipping 20 matching lines...) Expand all Loading... |
1513 (w_param == HTCAPTION || w_param == HTSYSMENU)) { | 1557 (w_param == HTCAPTION || w_param == HTSYSMENU)) { |
1514 is_right_mouse_pressed_on_caption_ = true; | 1558 is_right_mouse_pressed_on_caption_ = true; |
1515 // We SetCapture() to ensure we only show the menu when the button | 1559 // We SetCapture() to ensure we only show the menu when the button |
1516 // down and up are both on the caption. Note: this causes the button up to | 1560 // down and up are both on the caption. Note: this causes the button up to |
1517 // be WM_RBUTTONUP instead of WM_NCRBUTTONUP. | 1561 // be WM_RBUTTONUP instead of WM_NCRBUTTONUP. |
1518 SetCapture(); | 1562 SetCapture(); |
1519 } | 1563 } |
1520 | 1564 |
1521 MSG msg = { hwnd(), message, w_param, l_param, GetMessageTime(), | 1565 MSG msg = { hwnd(), message, w_param, l_param, GetMessageTime(), |
1522 { GET_X_LPARAM(l_param), GET_Y_LPARAM(l_param) } }; | 1566 { GET_X_LPARAM(l_param), GET_Y_LPARAM(l_param) } }; |
| 1567 //ScaleScreenPoint(&msg.pt); |
1523 ui::MouseEvent event(msg); | 1568 ui::MouseEvent event(msg); |
1524 if (!touch_ids_.empty() || ui::IsMouseEventFromTouch(message)) | 1569 if (!touch_ids_.empty() || ui::IsMouseEventFromTouch(message)) |
1525 event.set_flags(event.flags() | ui::EF_FROM_TOUCH); | 1570 event.set_flags(event.flags() | ui::EF_FROM_TOUCH); |
1526 | 1571 |
1527 if (!(event.flags() & ui::EF_IS_NON_CLIENT)) | 1572 if (!(event.flags() & ui::EF_IS_NON_CLIENT)) |
1528 delegate_->HandleTooltipMouseMove(message, w_param, l_param); | 1573 delegate_->HandleTooltipMouseMove(message, w_param, l_param); |
1529 | 1574 |
1530 if (event.type() == ui::ET_MOUSE_MOVED && !HasCapture()) { | 1575 if (event.type() == ui::ET_MOUSE_MOVED && !HasCapture()) { |
1531 // Windows only fires WM_MOUSELEAVE events if the application begins | 1576 // Windows only fires WM_MOUSELEAVE events if the application begins |
1532 // "tracking" mouse events for a given HWND during WM_MOUSEMOVE events. | 1577 // "tracking" mouse events for a given HWND during WM_MOUSEMOVE events. |
(...skipping 585 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2118 DwmExtendFrameIntoClientArea(hwnd(), &m); | 2163 DwmExtendFrameIntoClientArea(hwnd(), &m); |
2119 } | 2164 } |
2120 if (window_pos->flags & SWP_SHOWWINDOW) | 2165 if (window_pos->flags & SWP_SHOWWINDOW) |
2121 delegate_->HandleVisibilityChanged(true); | 2166 delegate_->HandleVisibilityChanged(true); |
2122 else if (window_pos->flags & SWP_HIDEWINDOW) | 2167 else if (window_pos->flags & SWP_HIDEWINDOW) |
2123 delegate_->HandleVisibilityChanged(false); | 2168 delegate_->HandleVisibilityChanged(false); |
2124 SetMsgHandled(FALSE); | 2169 SetMsgHandled(FALSE); |
2125 } | 2170 } |
2126 | 2171 |
2127 } // namespace views | 2172 } // namespace views |
OLD | NEW |