Chromium Code Reviews| 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 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 292 } | 292 } |
| 293 | 293 |
| 294 return false; | 294 return false; |
| 295 } | 295 } |
| 296 | 296 |
| 297 #endif | 297 #endif |
| 298 | 298 |
| 299 // The thickness of an auto-hide taskbar in pixels. | 299 // The thickness of an auto-hide taskbar in pixels. |
| 300 const int kAutoHideTaskbarThicknessPx = 2; | 300 const int kAutoHideTaskbarThicknessPx = 2; |
| 301 | 301 |
| 302 bool IsTopLevelWindow(HWND window) { | |
| 303 long style = GetWindowLong(window, GWL_STYLE); | |
|
cpu_(ooo_6.6-7.5)
2014/01/11 01:34:30
use :: For Windows calls here and in 306, 307
ananta
2014/01/11 01:36:21
Done.
| |
| 304 if (!(style & WS_CHILD)) | |
| 305 return true; | |
| 306 HWND parent = GetParent(window); | |
| 307 return !parent || (parent == GetDesktopWindow()); | |
| 308 } | |
| 309 | |
| 310 void AddScrollStylesToWindow(HWND window) { | |
| 311 if (::IsWindow(window)) { | |
| 312 long current_style = ::GetWindowLong(window, GWL_STYLE); | |
| 313 ::SetWindowLong(window, GWL_STYLE, | |
| 314 current_style | WS_VSCROLL | WS_HSCROLL); | |
| 315 } | |
| 316 } | |
| 317 | |
| 302 } // namespace | 318 } // namespace |
| 303 | 319 |
| 304 // A scoping class that prevents a window from being able to redraw in response | 320 // A scoping class that prevents a window from being able to redraw in response |
| 305 // to invalidations that may occur within it for the lifetime of the object. | 321 // to invalidations that may occur within it for the lifetime of the object. |
| 306 // | 322 // |
| 307 // Why would we want such a thing? Well, it turns out Windows has some | 323 // Why would we want such a thing? Well, it turns out Windows has some |
| 308 // "unorthodox" behavior when it comes to painting its non-client areas. | 324 // "unorthodox" behavior when it comes to painting its non-client areas. |
| 309 // Occasionally, Windows will paint portions of the default non-client area | 325 // Occasionally, Windows will paint portions of the default non-client area |
| 310 // right over the top of the custom frame. This is not simply fixed by handling | 326 // right over the top of the custom frame. This is not simply fixed by handling |
| 311 // WM_NCPAINT/WM_PAINT, with some investigation it turns out that this | 327 // WM_NCPAINT/WM_PAINT, with some investigation it turns out that this |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 383 is_right_mouse_pressed_on_caption_(false), | 399 is_right_mouse_pressed_on_caption_(false), |
| 384 lock_updates_count_(0), | 400 lock_updates_count_(0), |
| 385 ignore_window_pos_changes_(false), | 401 ignore_window_pos_changes_(false), |
| 386 last_monitor_(NULL), | 402 last_monitor_(NULL), |
| 387 use_layered_buffer_(false), | 403 use_layered_buffer_(false), |
| 388 layered_alpha_(255), | 404 layered_alpha_(255), |
| 389 waiting_for_redraw_layered_window_contents_(false), | 405 waiting_for_redraw_layered_window_contents_(false), |
| 390 is_first_nccalc_(true), | 406 is_first_nccalc_(true), |
| 391 menu_depth_(0), | 407 menu_depth_(0), |
| 392 autohide_factory_(this), | 408 autohide_factory_(this), |
| 393 id_generator_(0) { | 409 id_generator_(0), |
| 410 scroll_styles_set_(false) { | |
| 394 } | 411 } |
| 395 | 412 |
| 396 HWNDMessageHandler::~HWNDMessageHandler() { | 413 HWNDMessageHandler::~HWNDMessageHandler() { |
| 397 delegate_ = NULL; | 414 delegate_ = NULL; |
| 398 // Prevent calls back into this class via WNDPROC now that we've been | 415 // Prevent calls back into this class via WNDPROC now that we've been |
| 399 // destroyed. | 416 // destroyed. |
| 400 ClearUserData(); | 417 ClearUserData(); |
| 401 } | 418 } |
| 402 | 419 |
| 403 void HWNDMessageHandler::Init(HWND parent, const gfx::Rect& bounds) { | 420 void HWNDMessageHandler::Init(HWND parent, const gfx::Rect& bounds) { |
| (...skipping 932 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1336 #if !defined(USE_AURA) | 1353 #if !defined(USE_AURA) |
| 1337 // We need to add ourselves as a message loop observer so that we can repaint | 1354 // We need to add ourselves as a message loop observer so that we can repaint |
| 1338 // aggressively if the contents of our window become invalid. Unfortunately | 1355 // aggressively if the contents of our window become invalid. Unfortunately |
| 1339 // WM_PAINT messages are starved and we get flickery redrawing when resizing | 1356 // WM_PAINT messages are starved and we get flickery redrawing when resizing |
| 1340 // if we do not do this. | 1357 // if we do not do this. |
| 1341 base::MessageLoopForUI::current()->AddObserver(this); | 1358 base::MessageLoopForUI::current()->AddObserver(this); |
| 1342 #endif | 1359 #endif |
| 1343 | 1360 |
| 1344 delegate_->HandleCreate(); | 1361 delegate_->HandleCreate(); |
| 1345 | 1362 |
| 1363 #if defined(USE_AURA) | |
| 1364 // Certain trackpad drivers on Windows have bugs where in they don't generate | |
| 1365 // WM_MOUSEWHEEL messages for the trackpoint and trackpad scrolling gestures | |
| 1366 // unless there is an entry for Chrome with the class name of the Window. | |
| 1367 // These drivers check if the window under the trackpoint has the WS_VSCROLL/ | |
| 1368 // WS_HSCROLL style and if yes they generate the legacy WM_VSCROLL/WM_HSCROLL | |
| 1369 // messages. We add these styles to ensure that trackpad/trackpoint scrolling | |
| 1370 // work. | |
| 1371 // TODO(ananta) | |
| 1372 // Look into moving the WS_VSCROLL and WS_HSCROLL style setting logic to the | |
| 1373 // CalculateWindowStylesFromInitParams function. Doing it there seems to | |
| 1374 // cause some interactive tests to fail. Investigation needed. | |
| 1375 if (IsTopLevelWindow(hwnd())) { | |
| 1376 long current_style = ::GetWindowLong(hwnd(), GWL_STYLE); | |
| 1377 ::SetWindowLong(hwnd(), GWL_STYLE, | |
| 1378 current_style | WS_VSCROLL | WS_HSCROLL); | |
| 1379 scroll_styles_set_ = true; | |
| 1380 } | |
| 1381 #endif | |
| 1346 // TODO(beng): move more of NWW::OnCreate here. | 1382 // TODO(beng): move more of NWW::OnCreate here. |
| 1347 return 0; | 1383 return 0; |
| 1348 } | 1384 } |
| 1349 | 1385 |
| 1350 void HWNDMessageHandler::OnDestroy() { | 1386 void HWNDMessageHandler::OnDestroy() { |
| 1351 delegate_->HandleDestroying(); | 1387 delegate_->HandleDestroying(); |
| 1352 } | 1388 } |
| 1353 | 1389 |
| 1354 void HWNDMessageHandler::OnDisplayChange(UINT bits_per_pixel, | 1390 void HWNDMessageHandler::OnDisplayChange(UINT bits_per_pixel, |
| 1355 const CSize& screen_size) { | 1391 const CSize& screen_size) { |
| (...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1958 EndPaint(hwnd(), &ps); | 1994 EndPaint(hwnd(), &ps); |
| 1959 } | 1995 } |
| 1960 | 1996 |
| 1961 LRESULT HWNDMessageHandler::OnReflectedMessage(UINT message, | 1997 LRESULT HWNDMessageHandler::OnReflectedMessage(UINT message, |
| 1962 WPARAM w_param, | 1998 WPARAM w_param, |
| 1963 LPARAM l_param) { | 1999 LPARAM l_param) { |
| 1964 SetMsgHandled(FALSE); | 2000 SetMsgHandled(FALSE); |
| 1965 return 0; | 2001 return 0; |
| 1966 } | 2002 } |
| 1967 | 2003 |
| 2004 LRESULT HWNDMessageHandler::OnScrollMessage(UINT message, | |
| 2005 WPARAM w_param, | |
| 2006 LPARAM l_param) { | |
| 2007 MSG msg = { hwnd(), message, w_param, l_param, GetMessageTime() }; | |
| 2008 ui::ScrollEvent event(msg); | |
| 2009 delegate_->HandleScrollEvent(event); | |
| 2010 return 0; | |
| 2011 } | |
| 2012 | |
| 1968 LRESULT HWNDMessageHandler::OnSetCursor(UINT message, | 2013 LRESULT HWNDMessageHandler::OnSetCursor(UINT message, |
| 1969 WPARAM w_param, | 2014 WPARAM w_param, |
| 1970 LPARAM l_param) { | 2015 LPARAM l_param) { |
| 1971 // Reimplement the necessary default behavior here. Calling DefWindowProc can | 2016 // Reimplement the necessary default behavior here. Calling DefWindowProc can |
| 1972 // trigger weird non-client painting for non-glass windows with custom frames. | 2017 // trigger weird non-client painting for non-glass windows with custom frames. |
| 1973 // Using a ScopedRedrawLock to prevent caption rendering artifacts may allow | 2018 // Using a ScopedRedrawLock to prevent caption rendering artifacts may allow |
| 1974 // content behind this window to incorrectly paint in front of this window. | 2019 // content behind this window to incorrectly paint in front of this window. |
| 1975 // Invalidating the window to paint over either set of artifacts is not ideal. | 2020 // Invalidating the window to paint over either set of artifacts is not ideal. |
| 1976 wchar_t* cursor = IDC_ARROW; | 2021 wchar_t* cursor = IDC_ARROW; |
| 1977 switch (LOWORD(l_param)) { | 2022 switch (LOWORD(l_param)) { |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2035 delegate_->HandleWorkAreaChanged(); | 2080 delegate_->HandleWorkAreaChanged(); |
| 2036 SetMsgHandled(FALSE); | 2081 SetMsgHandled(FALSE); |
| 2037 } | 2082 } |
| 2038 } | 2083 } |
| 2039 | 2084 |
| 2040 void HWNDMessageHandler::OnSize(UINT param, const CSize& size) { | 2085 void HWNDMessageHandler::OnSize(UINT param, const CSize& size) { |
| 2041 RedrawWindow(hwnd(), NULL, NULL, RDW_INVALIDATE | RDW_ALLCHILDREN); | 2086 RedrawWindow(hwnd(), NULL, NULL, RDW_INVALIDATE | RDW_ALLCHILDREN); |
| 2042 // ResetWindowRegion is going to trigger WM_NCPAINT. By doing it after we've | 2087 // ResetWindowRegion is going to trigger WM_NCPAINT. By doing it after we've |
| 2043 // invoked OnSize we ensure the RootView has been laid out. | 2088 // invoked OnSize we ensure the RootView has been laid out. |
| 2044 ResetWindowRegion(false, true); | 2089 ResetWindowRegion(false, true); |
| 2090 | |
| 2091 #if defined(USE_AURA) | |
| 2092 // We add the WS_VSCROLL and WS_HSCROLL styles to top level windows to ensure | |
| 2093 // that legacy trackpad/trackpoint drivers generate the WM_VSCROLL and | |
| 2094 // WM_HSCROLL messages and scrolling works. | |
| 2095 // We want the style to be present on the window. However we don't want | |
| 2096 // Windows to draw the scrollbars. To achieve this we hide the scroll bars | |
| 2097 // and readd them to the window style in a posted task which works. | |
| 2098 if (scroll_styles_set_) { | |
| 2099 ShowScrollBar(hwnd(), SB_BOTH, FALSE); | |
| 2100 base::MessageLoop::current()->PostTask( | |
| 2101 FROM_HERE, | |
| 2102 base::Bind(&AddScrollStylesToWindow, hwnd())); | |
| 2103 #endif | |
| 2104 } | |
| 2045 } | 2105 } |
| 2046 | 2106 |
| 2047 void HWNDMessageHandler::OnSysCommand(UINT notification_code, | 2107 void HWNDMessageHandler::OnSysCommand(UINT notification_code, |
| 2048 const CPoint& point) { | 2108 const CPoint& point) { |
| 2049 if (!delegate_->ShouldHandleSystemCommands()) | 2109 if (!delegate_->ShouldHandleSystemCommands()) |
| 2050 return; | 2110 return; |
| 2051 | 2111 |
| 2052 // Windows uses the 4 lower order bits of |notification_code| for type- | 2112 // Windows uses the 4 lower order bits of |notification_code| for type- |
| 2053 // specific information so we must exclude this when comparing. | 2113 // specific information so we must exclude this when comparing. |
| 2054 static const int sc_mask = 0xFFF0; | 2114 static const int sc_mask = 0xFFF0; |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2255 SetMsgHandled(FALSE); | 2315 SetMsgHandled(FALSE); |
| 2256 } | 2316 } |
| 2257 | 2317 |
| 2258 void HWNDMessageHandler::HandleTouchEvents(const TouchEvents& touch_events) { | 2318 void HWNDMessageHandler::HandleTouchEvents(const TouchEvents& touch_events) { |
| 2259 base::WeakPtr<HWNDMessageHandler> ref(weak_factory_.GetWeakPtr()); | 2319 base::WeakPtr<HWNDMessageHandler> ref(weak_factory_.GetWeakPtr()); |
| 2260 for (size_t i = 0; i < touch_events.size() && ref; ++i) | 2320 for (size_t i = 0; i < touch_events.size() && ref; ++i) |
| 2261 delegate_->HandleTouchEvent(touch_events[i]); | 2321 delegate_->HandleTouchEvent(touch_events[i]); |
| 2262 } | 2322 } |
| 2263 | 2323 |
| 2264 } // namespace views | 2324 } // namespace views |
| OLD | NEW |