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) { | |
sky
2014/01/10 19:18:42
Is this still needed? Can't you key off the styles
ananta
2014/01/10 20:05:36
Removed. Added a member flag
| |
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 1646 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1958 EndPaint(hwnd(), &ps); | 1976 EndPaint(hwnd(), &ps); |
1959 } | 1977 } |
1960 | 1978 |
1961 LRESULT HWNDMessageHandler::OnReflectedMessage(UINT message, | 1979 LRESULT HWNDMessageHandler::OnReflectedMessage(UINT message, |
1962 WPARAM w_param, | 1980 WPARAM w_param, |
1963 LPARAM l_param) { | 1981 LPARAM l_param) { |
1964 SetMsgHandled(FALSE); | 1982 SetMsgHandled(FALSE); |
1965 return 0; | 1983 return 0; |
1966 } | 1984 } |
1967 | 1985 |
1986 LRESULT HWNDMessageHandler::OnScrollMessage(UINT message, | |
1987 WPARAM w_param, | |
1988 LPARAM l_param) { | |
1989 MSG msg = { hwnd(), message, w_param, l_param, GetMessageTime() }; | |
1990 ui::ScrollEvent event(msg); | |
1991 delegate_->HandleScrollEvent(event); | |
1992 return 0; | |
1993 } | |
1994 | |
1968 LRESULT HWNDMessageHandler::OnSetCursor(UINT message, | 1995 LRESULT HWNDMessageHandler::OnSetCursor(UINT message, |
1969 WPARAM w_param, | 1996 WPARAM w_param, |
1970 LPARAM l_param) { | 1997 LPARAM l_param) { |
1971 // Reimplement the necessary default behavior here. Calling DefWindowProc can | 1998 // Reimplement the necessary default behavior here. Calling DefWindowProc can |
1972 // trigger weird non-client painting for non-glass windows with custom frames. | 1999 // trigger weird non-client painting for non-glass windows with custom frames. |
1973 // Using a ScopedRedrawLock to prevent caption rendering artifacts may allow | 2000 // Using a ScopedRedrawLock to prevent caption rendering artifacts may allow |
1974 // content behind this window to incorrectly paint in front of this window. | 2001 // 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. | 2002 // Invalidating the window to paint over either set of artifacts is not ideal. |
1976 wchar_t* cursor = IDC_ARROW; | 2003 wchar_t* cursor = IDC_ARROW; |
1977 switch (LOWORD(l_param)) { | 2004 switch (LOWORD(l_param)) { |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2035 delegate_->HandleWorkAreaChanged(); | 2062 delegate_->HandleWorkAreaChanged(); |
2036 SetMsgHandled(FALSE); | 2063 SetMsgHandled(FALSE); |
2037 } | 2064 } |
2038 } | 2065 } |
2039 | 2066 |
2040 void HWNDMessageHandler::OnSize(UINT param, const CSize& size) { | 2067 void HWNDMessageHandler::OnSize(UINT param, const CSize& size) { |
2041 RedrawWindow(hwnd(), NULL, NULL, RDW_INVALIDATE | RDW_ALLCHILDREN); | 2068 RedrawWindow(hwnd(), NULL, NULL, RDW_INVALIDATE | RDW_ALLCHILDREN); |
2042 // ResetWindowRegion is going to trigger WM_NCPAINT. By doing it after we've | 2069 // ResetWindowRegion is going to trigger WM_NCPAINT. By doing it after we've |
2043 // invoked OnSize we ensure the RootView has been laid out. | 2070 // invoked OnSize we ensure the RootView has been laid out. |
2044 ResetWindowRegion(false, true); | 2071 ResetWindowRegion(false, true); |
2072 | |
2073 #if defined(USE_AURA) | |
2074 // We add the WS_VSCROLL and WS_HSCROLL styles to top level windows to ensure | |
2075 // that legacy trackpad/trackpoint drivers generate the WM_VSCROLL and | |
2076 // WM_HSCROLL messages and scrolling works. | |
2077 // We want the style to be present on the window. However we don't want | |
2078 // Windows to draw the scrollbars. To achieve this we hide the scroll bars | |
2079 // and readd them to the window style in a posted task which works. | |
2080 if (IsTopLevelWindow(hwnd())) { | |
2081 BOOL visible = ::IsWindowVisible(hwnd()); | |
2082 ShowScrollBar(hwnd(), SB_BOTH, FALSE); | |
2083 long current_style = ::GetWindowLong(hwnd(), GWL_STYLE); | |
2084 base::MessageLoop::current()->PostTask( | |
2085 FROM_HERE, | |
2086 base::Bind(&AddScrollStylesToWindow, hwnd())); | |
2087 #endif | |
2088 } | |
2045 } | 2089 } |
2046 | 2090 |
2047 void HWNDMessageHandler::OnSysCommand(UINT notification_code, | 2091 void HWNDMessageHandler::OnSysCommand(UINT notification_code, |
2048 const CPoint& point) { | 2092 const CPoint& point) { |
2049 if (!delegate_->ShouldHandleSystemCommands()) | 2093 if (!delegate_->ShouldHandleSystemCommands()) |
2050 return; | 2094 return; |
2051 | 2095 |
2052 // Windows uses the 4 lower order bits of |notification_code| for type- | 2096 // Windows uses the 4 lower order bits of |notification_code| for type- |
2053 // specific information so we must exclude this when comparing. | 2097 // specific information so we must exclude this when comparing. |
2054 static const int sc_mask = 0xFFF0; | 2098 static const int sc_mask = 0xFFF0; |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2255 SetMsgHandled(FALSE); | 2299 SetMsgHandled(FALSE); |
2256 } | 2300 } |
2257 | 2301 |
2258 void HWNDMessageHandler::HandleTouchEvents(const TouchEvents& touch_events) { | 2302 void HWNDMessageHandler::HandleTouchEvents(const TouchEvents& touch_events) { |
2259 base::WeakPtr<HWNDMessageHandler> ref(weak_factory_.GetWeakPtr()); | 2303 base::WeakPtr<HWNDMessageHandler> ref(weak_factory_.GetWeakPtr()); |
2260 for (size_t i = 0; i < touch_events.size() && ref; ++i) | 2304 for (size_t i = 0; i < touch_events.size() && ref; ++i) |
2261 delegate_->HandleTouchEvent(touch_events[i]); | 2305 delegate_->HandleTouchEvent(touch_events[i]); |
2262 } | 2306 } |
2263 | 2307 |
2264 } // namespace views | 2308 } // namespace views |
OLD | NEW |