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); | |
304 if (!(style & WS_CHILD)) | |
305 return true; | |
306 | |
307 HWND parent = GetParent(window); | |
308 return !parent || (parent == GetDesktopWindow()); | |
309 } | |
310 | |
311 void AddScrollStylesToWindow(HWND window) { | |
312 if (::IsWindow(window)) { | |
313 DCHECK(IsTopLevelWindow(window)); | |
314 long current_style = ::GetWindowLong(window, GWL_STYLE); | |
315 ::SetWindowLong(window, GWL_STYLE, | |
316 current_style | WS_VSCROLL | WS_HSCROLL); | |
317 } | |
318 } | |
319 | |
302 } // namespace | 320 } // namespace |
303 | 321 |
304 // A scoping class that prevents a window from being able to redraw in response | 322 // 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. | 323 // to invalidations that may occur within it for the lifetime of the object. |
306 // | 324 // |
307 // Why would we want such a thing? Well, it turns out Windows has some | 325 // 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. | 326 // "unorthodox" behavior when it comes to painting its non-client areas. |
309 // Occasionally, Windows will paint portions of the default non-client area | 327 // 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 | 328 // 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 | 329 // WM_NCPAINT/WM_PAINT, with some investigation it turns out that this |
(...skipping 1024 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1336 #if !defined(USE_AURA) | 1354 #if !defined(USE_AURA) |
1337 // We need to add ourselves as a message loop observer so that we can repaint | 1355 // 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 | 1356 // aggressively if the contents of our window become invalid. Unfortunately |
1339 // WM_PAINT messages are starved and we get flickery redrawing when resizing | 1357 // WM_PAINT messages are starved and we get flickery redrawing when resizing |
1340 // if we do not do this. | 1358 // if we do not do this. |
1341 base::MessageLoopForUI::current()->AddObserver(this); | 1359 base::MessageLoopForUI::current()->AddObserver(this); |
1342 #endif | 1360 #endif |
1343 | 1361 |
1344 delegate_->HandleCreate(); | 1362 delegate_->HandleCreate(); |
1345 | 1363 |
1364 #if defined(USE_AURA) | |
sky
2014/01/10 16:43:21
Can this be moved to CalculateWindowStylesFromInit
ananta
2014/01/10 18:59:21
Done.
| |
1365 // Certain trackpad drivers on Windows have bugs where in they don't generate | |
1366 // WM_MOUSEWHEEL messages for the trackpoint and trackpad scrolling gestures | |
1367 // unless there is an entry for Chrome with the class name of the Window. | |
1368 // These drivers check if the window under the trackpoint has the WS_VSCROLL/ | |
1369 // WS_HSCROLL style and if yes they generate the legacy WM_VSCROLL/WM_HSCROLL | |
1370 // messages. We want the style to be present on the window. However we don't | |
1371 // want Windows to draw the scrollbars. To achieve this we hide the scroll | |
1372 // bars and readd them to the window style in a posted task which works. | |
1373 if (IsTopLevelWindow(hwnd())) { | |
1374 long current_style = ::GetWindowLong(hwnd(), GWL_STYLE); | |
1375 ::SetWindowLong(hwnd(), GWL_STYLE, | |
1376 current_style | WS_VSCROLL | WS_HSCROLL); | |
1377 } | |
1378 #endif | |
1346 // TODO(beng): move more of NWW::OnCreate here. | 1379 // TODO(beng): move more of NWW::OnCreate here. |
1347 return 0; | 1380 return 0; |
1348 } | 1381 } |
1349 | 1382 |
1350 void HWNDMessageHandler::OnDestroy() { | 1383 void HWNDMessageHandler::OnDestroy() { |
1351 delegate_->HandleDestroying(); | 1384 delegate_->HandleDestroying(); |
1352 } | 1385 } |
1353 | 1386 |
1354 void HWNDMessageHandler::OnDisplayChange(UINT bits_per_pixel, | 1387 void HWNDMessageHandler::OnDisplayChange(UINT bits_per_pixel, |
1355 const CSize& screen_size) { | 1388 const CSize& screen_size) { |
(...skipping 679 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2035 delegate_->HandleWorkAreaChanged(); | 2068 delegate_->HandleWorkAreaChanged(); |
2036 SetMsgHandled(FALSE); | 2069 SetMsgHandled(FALSE); |
2037 } | 2070 } |
2038 } | 2071 } |
2039 | 2072 |
2040 void HWNDMessageHandler::OnSize(UINT param, const CSize& size) { | 2073 void HWNDMessageHandler::OnSize(UINT param, const CSize& size) { |
2041 RedrawWindow(hwnd(), NULL, NULL, RDW_INVALIDATE | RDW_ALLCHILDREN); | 2074 RedrawWindow(hwnd(), NULL, NULL, RDW_INVALIDATE | RDW_ALLCHILDREN); |
2042 // ResetWindowRegion is going to trigger WM_NCPAINT. By doing it after we've | 2075 // ResetWindowRegion is going to trigger WM_NCPAINT. By doing it after we've |
2043 // invoked OnSize we ensure the RootView has been laid out. | 2076 // invoked OnSize we ensure the RootView has been laid out. |
2044 ResetWindowRegion(false, true); | 2077 ResetWindowRegion(false, true); |
2078 | |
2079 #if defined(USE_AURA) | |
2080 // As documented in the HWNDMessageHandler::OnCreate function, we add the | |
2081 // WS_VSCROLL and WS_HSCROLL styles to the window to ensure that legacy track | |
2082 // pad/trackpoint drivers generate the WM_VSCROLL and WM_HSCROLL messages. | |
2083 // We want the style to be present on the window. However we don't want | |
2084 // Windows to draw the scrollbars. To achieve this we hide the scroll bars | |
sky
2014/01/10 16:43:21
Could we instead set the scrollbar sizes to 0?
ananta
2014/01/10 18:59:21
Tricky to do that. The non AURA code did this in t
| |
2085 // and readd them to the window style in a posted task which works. | |
2086 if (IsTopLevelWindow(hwnd())) { | |
2087 BOOL visible = ::IsWindowVisible(hwnd()); | |
2088 ShowScrollBar(hwnd(), SB_BOTH, FALSE); | |
2089 long current_style = ::GetWindowLong(hwnd(), GWL_STYLE); | |
2090 base::MessageLoop::current()->PostTask( | |
2091 FROM_HERE, | |
2092 base::Bind(&AddScrollStylesToWindow, hwnd())); | |
2093 #endif | |
2094 } | |
2045 } | 2095 } |
2046 | 2096 |
2047 void HWNDMessageHandler::OnSysCommand(UINT notification_code, | 2097 void HWNDMessageHandler::OnSysCommand(UINT notification_code, |
2048 const CPoint& point) { | 2098 const CPoint& point) { |
2049 if (!delegate_->ShouldHandleSystemCommands()) | 2099 if (!delegate_->ShouldHandleSystemCommands()) |
2050 return; | 2100 return; |
2051 | 2101 |
2052 // Windows uses the 4 lower order bits of |notification_code| for type- | 2102 // Windows uses the 4 lower order bits of |notification_code| for type- |
2053 // specific information so we must exclude this when comparing. | 2103 // specific information so we must exclude this when comparing. |
2054 static const int sc_mask = 0xFFF0; | 2104 static const int sc_mask = 0xFFF0; |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2248 MARGINS m = {10, 10, 10, 10}; | 2298 MARGINS m = {10, 10, 10, 10}; |
2249 DwmExtendFrameIntoClientArea(hwnd(), &m); | 2299 DwmExtendFrameIntoClientArea(hwnd(), &m); |
2250 } | 2300 } |
2251 if (window_pos->flags & SWP_SHOWWINDOW) | 2301 if (window_pos->flags & SWP_SHOWWINDOW) |
2252 delegate_->HandleVisibilityChanged(true); | 2302 delegate_->HandleVisibilityChanged(true); |
2253 else if (window_pos->flags & SWP_HIDEWINDOW) | 2303 else if (window_pos->flags & SWP_HIDEWINDOW) |
2254 delegate_->HandleVisibilityChanged(false); | 2304 delegate_->HandleVisibilityChanged(false); |
2255 SetMsgHandled(FALSE); | 2305 SetMsgHandled(FALSE); |
2256 } | 2306 } |
2257 | 2307 |
2308 LRESULT HWNDMessageHandler::OnScrollMessage(UINT message, | |
2309 WPARAM w_param, | |
2310 LPARAM l_param) { | |
2311 MSG msg = { hwnd(), message, w_param, l_param, GetMessageTime() }; | |
2312 ui::ScrollEvent event(msg); | |
2313 delegate_->HandleScrollEvent(event); | |
2314 return 0; | |
2315 } | |
2316 | |
2258 void HWNDMessageHandler::HandleTouchEvents(const TouchEvents& touch_events) { | 2317 void HWNDMessageHandler::HandleTouchEvents(const TouchEvents& touch_events) { |
2259 base::WeakPtr<HWNDMessageHandler> ref(weak_factory_.GetWeakPtr()); | 2318 base::WeakPtr<HWNDMessageHandler> ref(weak_factory_.GetWeakPtr()); |
2260 for (size_t i = 0; i < touch_events.size() && ref; ++i) | 2319 for (size_t i = 0; i < touch_events.size() && ref; ++i) |
2261 delegate_->HandleTouchEvent(touch_events[i]); | 2320 delegate_->HandleTouchEvent(touch_events[i]); |
2262 } | 2321 } |
2263 | 2322 |
2264 } // namespace views | 2323 } // namespace views |
OLD | NEW |