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 void AddScrollStylesToWindow(HWND window) { | |
303 if (::IsWindow(window)) { | |
304 long current_style = ::GetWindowLong(window, GWL_STYLE); | |
305 ::SetWindowLong(window, GWL_STYLE, | |
306 current_style | WS_VSCROLL | WS_HSCROLL); | |
307 } | |
308 } | |
309 | |
302 } // namespace | 310 } // namespace |
303 | 311 |
304 // A scoping class that prevents a window from being able to redraw in response | 312 // 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. | 313 // to invalidations that may occur within it for the lifetime of the object. |
306 // | 314 // |
307 // Why would we want such a thing? Well, it turns out Windows has some | 315 // 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. | 316 // "unorthodox" behavior when it comes to painting its non-client areas. |
309 // Occasionally, Windows will paint portions of the default non-client area | 317 // 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 | 318 // 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 | 319 // 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), | 391 is_right_mouse_pressed_on_caption_(false), |
384 lock_updates_count_(0), | 392 lock_updates_count_(0), |
385 ignore_window_pos_changes_(false), | 393 ignore_window_pos_changes_(false), |
386 last_monitor_(NULL), | 394 last_monitor_(NULL), |
387 use_layered_buffer_(false), | 395 use_layered_buffer_(false), |
388 layered_alpha_(255), | 396 layered_alpha_(255), |
389 waiting_for_redraw_layered_window_contents_(false), | 397 waiting_for_redraw_layered_window_contents_(false), |
390 is_first_nccalc_(true), | 398 is_first_nccalc_(true), |
391 menu_depth_(0), | 399 menu_depth_(0), |
392 autohide_factory_(this), | 400 autohide_factory_(this), |
393 id_generator_(0) { | 401 id_generator_(0), |
402 scroll_styles_set_(false) { | |
394 } | 403 } |
395 | 404 |
396 HWNDMessageHandler::~HWNDMessageHandler() { | 405 HWNDMessageHandler::~HWNDMessageHandler() { |
397 delegate_ = NULL; | 406 delegate_ = NULL; |
398 // Prevent calls back into this class via WNDPROC now that we've been | 407 // Prevent calls back into this class via WNDPROC now that we've been |
399 // destroyed. | 408 // destroyed. |
400 ClearUserData(); | 409 ClearUserData(); |
401 } | 410 } |
402 | 411 |
403 void HWNDMessageHandler::Init(HWND parent, const gfx::Rect& bounds) { | 412 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) | 1345 #if !defined(USE_AURA) |
1337 // We need to add ourselves as a message loop observer so that we can repaint | 1346 // 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 | 1347 // aggressively if the contents of our window become invalid. Unfortunately |
1339 // WM_PAINT messages are starved and we get flickery redrawing when resizing | 1348 // WM_PAINT messages are starved and we get flickery redrawing when resizing |
1340 // if we do not do this. | 1349 // if we do not do this. |
1341 base::MessageLoopForUI::current()->AddObserver(this); | 1350 base::MessageLoopForUI::current()->AddObserver(this); |
1342 #endif | 1351 #endif |
1343 | 1352 |
1344 delegate_->HandleCreate(); | 1353 delegate_->HandleCreate(); |
1345 | 1354 |
1355 scroll_styles_set_ = !!(create_struct->style & (WS_VSCROLL | WS_HSCROLL)); | |
1346 // TODO(beng): move more of NWW::OnCreate here. | 1356 // TODO(beng): move more of NWW::OnCreate here. |
1347 return 0; | 1357 return 0; |
1348 } | 1358 } |
1349 | 1359 |
1350 void HWNDMessageHandler::OnDestroy() { | 1360 void HWNDMessageHandler::OnDestroy() { |
1351 delegate_->HandleDestroying(); | 1361 delegate_->HandleDestroying(); |
1352 } | 1362 } |
1353 | 1363 |
1354 void HWNDMessageHandler::OnDisplayChange(UINT bits_per_pixel, | 1364 void HWNDMessageHandler::OnDisplayChange(UINT bits_per_pixel, |
1355 const CSize& screen_size) { | 1365 const CSize& screen_size) { |
(...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1958 EndPaint(hwnd(), &ps); | 1968 EndPaint(hwnd(), &ps); |
1959 } | 1969 } |
1960 | 1970 |
1961 LRESULT HWNDMessageHandler::OnReflectedMessage(UINT message, | 1971 LRESULT HWNDMessageHandler::OnReflectedMessage(UINT message, |
1962 WPARAM w_param, | 1972 WPARAM w_param, |
1963 LPARAM l_param) { | 1973 LPARAM l_param) { |
1964 SetMsgHandled(FALSE); | 1974 SetMsgHandled(FALSE); |
1965 return 0; | 1975 return 0; |
1966 } | 1976 } |
1967 | 1977 |
1978 LRESULT HWNDMessageHandler::OnScrollMessage(UINT message, | |
1979 WPARAM w_param, | |
1980 LPARAM l_param) { | |
1981 MSG msg = { hwnd(), message, w_param, l_param, GetMessageTime() }; | |
1982 ui::ScrollEvent event(msg); | |
1983 delegate_->HandleScrollEvent(event); | |
1984 return 0; | |
1985 } | |
1986 | |
1968 LRESULT HWNDMessageHandler::OnSetCursor(UINT message, | 1987 LRESULT HWNDMessageHandler::OnSetCursor(UINT message, |
1969 WPARAM w_param, | 1988 WPARAM w_param, |
1970 LPARAM l_param) { | 1989 LPARAM l_param) { |
1971 // Reimplement the necessary default behavior here. Calling DefWindowProc can | 1990 // Reimplement the necessary default behavior here. Calling DefWindowProc can |
1972 // trigger weird non-client painting for non-glass windows with custom frames. | 1991 // trigger weird non-client painting for non-glass windows with custom frames. |
1973 // Using a ScopedRedrawLock to prevent caption rendering artifacts may allow | 1992 // Using a ScopedRedrawLock to prevent caption rendering artifacts may allow |
1974 // content behind this window to incorrectly paint in front of this window. | 1993 // 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. | 1994 // Invalidating the window to paint over either set of artifacts is not ideal. |
1976 wchar_t* cursor = IDC_ARROW; | 1995 wchar_t* cursor = IDC_ARROW; |
1977 switch (LOWORD(l_param)) { | 1996 switch (LOWORD(l_param)) { |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2035 delegate_->HandleWorkAreaChanged(); | 2054 delegate_->HandleWorkAreaChanged(); |
2036 SetMsgHandled(FALSE); | 2055 SetMsgHandled(FALSE); |
2037 } | 2056 } |
2038 } | 2057 } |
2039 | 2058 |
2040 void HWNDMessageHandler::OnSize(UINT param, const CSize& size) { | 2059 void HWNDMessageHandler::OnSize(UINT param, const CSize& size) { |
2041 RedrawWindow(hwnd(), NULL, NULL, RDW_INVALIDATE | RDW_ALLCHILDREN); | 2060 RedrawWindow(hwnd(), NULL, NULL, RDW_INVALIDATE | RDW_ALLCHILDREN); |
2042 // ResetWindowRegion is going to trigger WM_NCPAINT. By doing it after we've | 2061 // ResetWindowRegion is going to trigger WM_NCPAINT. By doing it after we've |
2043 // invoked OnSize we ensure the RootView has been laid out. | 2062 // invoked OnSize we ensure the RootView has been laid out. |
2044 ResetWindowRegion(false, true); | 2063 ResetWindowRegion(false, true); |
2064 | |
2065 #if defined(USE_AURA) | |
2066 // We add the WS_VSCROLL and WS_HSCROLL styles to top level windows to ensure | |
2067 // that legacy trackpad/trackpoint drivers generate the WM_VSCROLL and | |
2068 // WM_HSCROLL messages and scrolling works. | |
2069 // We want the style to be present on the window. However we don't want | |
2070 // Windows to draw the scrollbars. To achieve this we hide the scroll bars | |
2071 // and readd them to the window style in a posted task which works. | |
2072 if (scroll_styles_set_) { | |
2073 BOOL visible = ::IsWindowVisible(hwnd()); | |
2074 ShowScrollBar(hwnd(), SB_BOTH, FALSE); | |
2075 long current_style = ::GetWindowLong(hwnd(), GWL_STYLE); | |
cpu_(ooo_6.6-7.5)
2014/01/10 21:10:18
current_style not used also visible not used.
ananta
2014/01/11 00:20:29
Done.
| |
2076 base::MessageLoop::current()->PostTask( | |
2077 FROM_HERE, | |
2078 base::Bind(&AddScrollStylesToWindow, hwnd())); | |
2079 #endif | |
2080 } | |
2045 } | 2081 } |
2046 | 2082 |
2047 void HWNDMessageHandler::OnSysCommand(UINT notification_code, | 2083 void HWNDMessageHandler::OnSysCommand(UINT notification_code, |
2048 const CPoint& point) { | 2084 const CPoint& point) { |
2049 if (!delegate_->ShouldHandleSystemCommands()) | 2085 if (!delegate_->ShouldHandleSystemCommands()) |
2050 return; | 2086 return; |
2051 | 2087 |
2052 // Windows uses the 4 lower order bits of |notification_code| for type- | 2088 // Windows uses the 4 lower order bits of |notification_code| for type- |
2053 // specific information so we must exclude this when comparing. | 2089 // specific information so we must exclude this when comparing. |
2054 static const int sc_mask = 0xFFF0; | 2090 static const int sc_mask = 0xFFF0; |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2255 SetMsgHandled(FALSE); | 2291 SetMsgHandled(FALSE); |
2256 } | 2292 } |
2257 | 2293 |
2258 void HWNDMessageHandler::HandleTouchEvents(const TouchEvents& touch_events) { | 2294 void HWNDMessageHandler::HandleTouchEvents(const TouchEvents& touch_events) { |
2259 base::WeakPtr<HWNDMessageHandler> ref(weak_factory_.GetWeakPtr()); | 2295 base::WeakPtr<HWNDMessageHandler> ref(weak_factory_.GetWeakPtr()); |
2260 for (size_t i = 0; i < touch_events.size() && ref; ++i) | 2296 for (size_t i = 0; i < touch_events.size() && ref; ++i) |
2261 delegate_->HandleTouchEvent(touch_events[i]); | 2297 delegate_->HandleTouchEvent(touch_events[i]); |
2262 } | 2298 } |
2263 | 2299 |
2264 } // namespace views | 2300 } // namespace views |
OLD | NEW |