Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(450)

Side by Side Diff: ui/views/win/hwnd_message_handler.cc

Issue 137403008: Don't set the scroll styles (WS_VSCROLL and WS_HSCROLL) for WS_POPUP windows. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 } 308 }
309 309
310 void AddScrollStylesToWindow(HWND window) { 310 void AddScrollStylesToWindow(HWND window) {
311 if (::IsWindow(window)) { 311 if (::IsWindow(window)) {
312 long current_style = ::GetWindowLong(window, GWL_STYLE); 312 long current_style = ::GetWindowLong(window, GWL_STYLE);
313 ::SetWindowLong(window, GWL_STYLE, 313 ::SetWindowLong(window, GWL_STYLE,
314 current_style | WS_VSCROLL | WS_HSCROLL); 314 current_style | WS_VSCROLL | WS_HSCROLL);
315 } 315 }
316 } 316 }
317 317
318 void HideWindowsScrollBar(HWND window) {
319 ShowScrollBar(window, SB_BOTH, FALSE);
320 // Hiding the scrollbar also removes the WS_VSCROLL and WS_HSCROLL styles.
321 // We need to add the styles back to ensure that some trackpoint drivers
322 // which rely on them for scrolling work. However as this function can get
323 // called in the context of WM_SIZE we don't want to do this synchronously
324 // as that may trigger a WM_SIZE in some cases.
325 base::MessageLoop::current()->PostTask(
326 FROM_HERE,
327 base::Bind(&AddScrollStylesToWindow, window));
328 }
329
318 } // namespace 330 } // namespace
319 331
320 // A scoping class that prevents a window from being able to redraw in response 332 // A scoping class that prevents a window from being able to redraw in response
321 // to invalidations that may occur within it for the lifetime of the object. 333 // to invalidations that may occur within it for the lifetime of the object.
322 // 334 //
323 // Why would we want such a thing? Well, it turns out Windows has some 335 // Why would we want such a thing? Well, it turns out Windows has some
324 // "unorthodox" behavior when it comes to painting its non-client areas. 336 // "unorthodox" behavior when it comes to painting its non-client areas.
325 // Occasionally, Windows will paint portions of the default non-client area 337 // Occasionally, Windows will paint portions of the default non-client area
326 // right over the top of the custom frame. This is not simply fixed by handling 338 // right over the top of the custom frame. This is not simply fixed by handling
327 // WM_NCPAINT/WM_PAINT, with some investigation it turns out that this 339 // WM_NCPAINT/WM_PAINT, with some investigation it turns out that this
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 lock_updates_count_(0), 412 lock_updates_count_(0),
401 ignore_window_pos_changes_(false), 413 ignore_window_pos_changes_(false),
402 last_monitor_(NULL), 414 last_monitor_(NULL),
403 use_layered_buffer_(false), 415 use_layered_buffer_(false),
404 layered_alpha_(255), 416 layered_alpha_(255),
405 waiting_for_redraw_layered_window_contents_(false), 417 waiting_for_redraw_layered_window_contents_(false),
406 is_first_nccalc_(true), 418 is_first_nccalc_(true),
407 menu_depth_(0), 419 menu_depth_(0),
408 autohide_factory_(this), 420 autohide_factory_(this),
409 id_generator_(0), 421 id_generator_(0),
410 scroll_styles_set_(false) { 422 needs_scroll_styles_(false),
423 size_move_loop_(false) {
411 } 424 }
412 425
413 HWNDMessageHandler::~HWNDMessageHandler() { 426 HWNDMessageHandler::~HWNDMessageHandler() {
414 delegate_ = NULL; 427 delegate_ = NULL;
415 // Prevent calls back into this class via WNDPROC now that we've been 428 // Prevent calls back into this class via WNDPROC now that we've been
416 // destroyed. 429 // destroyed.
417 ClearUserData(); 430 ClearUserData();
418 } 431 }
419 432
420 void HWNDMessageHandler::Init(HWND parent, const gfx::Rect& bounds) { 433 void HWNDMessageHandler::Init(HWND parent, const gfx::Rect& bounds) {
421 TRACE_EVENT0("views", "HWNDMessageHandler::Init"); 434 TRACE_EVENT0("views", "HWNDMessageHandler::Init");
422 GetMonitorAndRects(bounds.ToRECT(), &last_monitor_, &last_monitor_rect_, 435 GetMonitorAndRects(bounds.ToRECT(), &last_monitor_, &last_monitor_rect_,
423 &last_work_area_); 436 &last_work_area_);
424 437
425 // Create the window. 438 // Create the window.
426 WindowImpl::Init(parent, bounds); 439 WindowImpl::Init(parent, bounds);
440
441 #if defined(USE_AURA)
442 // Certain trackpad drivers on Windows have bugs where in they don't generate
443 // WM_MOUSEWHEEL messages for the trackpoint and trackpad scrolling gestures
444 // unless there is an entry for Chrome with the class name of the Window.
445 // These drivers check if the window under the trackpoint has the WS_VSCROLL/
446 // WS_HSCROLL style and if yes they generate the legacy WM_VSCROLL/WM_HSCROLL
447 // messages. We add these styles to ensure that trackpad/trackpoint scrolling
448 // work.
449 // TODO(ananta)
450 // Look into moving the WS_VSCROLL and WS_HSCROLL style setting logic to the
451 // CalculateWindowStylesFromInitParams function. Doing it there seems to
452 // cause some interactive tests to fail. Investigation needed.
453 if (IsTopLevelWindow(hwnd())) {
454 long current_style = ::GetWindowLong(hwnd(), GWL_STYLE);
455 if (!(current_style & WS_POPUP)) {
456 AddScrollStylesToWindow(hwnd());
457 needs_scroll_styles_ = true;
458 }
459 }
460 #endif
427 } 461 }
428 462
429 void HWNDMessageHandler::InitModalType(ui::ModalType modal_type) { 463 void HWNDMessageHandler::InitModalType(ui::ModalType modal_type) {
430 if (modal_type == ui::MODAL_TYPE_NONE) 464 if (modal_type == ui::MODAL_TYPE_NONE)
431 return; 465 return;
432 // We implement modality by crawling up the hierarchy of windows starting 466 // We implement modality by crawling up the hierarchy of windows starting
433 // at the owner, disabling all of them so that they don't receive input 467 // at the owner, disabling all of them so that they don't receive input
434 // messages. 468 // messages.
435 HWND start = ::GetWindow(hwnd(), GW_OWNER); 469 HWND start = ::GetWindow(hwnd(), GW_OWNER);
436 while (start) { 470 while (start) {
(...skipping 922 matching lines...) Expand 10 before | Expand all | Expand 10 after
1359 #if !defined(USE_AURA) 1393 #if !defined(USE_AURA)
1360 // We need to add ourselves as a message loop observer so that we can repaint 1394 // We need to add ourselves as a message loop observer so that we can repaint
1361 // aggressively if the contents of our window become invalid. Unfortunately 1395 // aggressively if the contents of our window become invalid. Unfortunately
1362 // WM_PAINT messages are starved and we get flickery redrawing when resizing 1396 // WM_PAINT messages are starved and we get flickery redrawing when resizing
1363 // if we do not do this. 1397 // if we do not do this.
1364 base::MessageLoopForUI::current()->AddObserver(this); 1398 base::MessageLoopForUI::current()->AddObserver(this);
1365 #endif 1399 #endif
1366 1400
1367 delegate_->HandleCreate(); 1401 delegate_->HandleCreate();
1368 1402
1369 #if defined(USE_AURA)
1370 // Certain trackpad drivers on Windows have bugs where in they don't generate
1371 // WM_MOUSEWHEEL messages for the trackpoint and trackpad scrolling gestures
1372 // unless there is an entry for Chrome with the class name of the Window.
1373 // These drivers check if the window under the trackpoint has the WS_VSCROLL/
1374 // WS_HSCROLL style and if yes they generate the legacy WM_VSCROLL/WM_HSCROLL
1375 // messages. We add these styles to ensure that trackpad/trackpoint scrolling
1376 // work.
1377 // TODO(ananta)
1378 // Look into moving the WS_VSCROLL and WS_HSCROLL style setting logic to the
1379 // CalculateWindowStylesFromInitParams function. Doing it there seems to
1380 // cause some interactive tests to fail. Investigation needed.
1381 if (IsTopLevelWindow(hwnd())) {
1382 long current_style = ::GetWindowLong(hwnd(), GWL_STYLE);
1383 ::SetWindowLong(hwnd(), GWL_STYLE,
1384 current_style | WS_VSCROLL | WS_HSCROLL);
1385 scroll_styles_set_ = true;
1386 }
1387 #endif
1388 // TODO(beng): move more of NWW::OnCreate here. 1403 // TODO(beng): move more of NWW::OnCreate here.
1389 return 0; 1404 return 0;
1390 } 1405 }
1391 1406
1392 void HWNDMessageHandler::OnDestroy() { 1407 void HWNDMessageHandler::OnDestroy() {
1393 delegate_->HandleDestroying(); 1408 delegate_->HandleDestroying();
1394 } 1409 }
1395 1410
1396 void HWNDMessageHandler::OnDisplayChange(UINT bits_per_pixel, 1411 void HWNDMessageHandler::OnDisplayChange(UINT bits_per_pixel,
1397 const CSize& screen_size) { 1412 const CSize& screen_size) {
(...skipping 11 matching lines...) Expand all
1409 FrameTypeChanged(); 1424 FrameTypeChanged();
1410 return 0; 1425 return 0;
1411 } 1426 }
1412 1427
1413 void HWNDMessageHandler::OnEnterMenuLoop(BOOL from_track_popup_menu) { 1428 void HWNDMessageHandler::OnEnterMenuLoop(BOOL from_track_popup_menu) {
1414 if (menu_depth_++ == 0) 1429 if (menu_depth_++ == 0)
1415 delegate_->HandleMenuLoop(true); 1430 delegate_->HandleMenuLoop(true);
1416 } 1431 }
1417 1432
1418 void HWNDMessageHandler::OnEnterSizeMove() { 1433 void HWNDMessageHandler::OnEnterSizeMove() {
1434 size_move_loop_ = true;
1419 delegate_->HandleBeginWMSizeMove(); 1435 delegate_->HandleBeginWMSizeMove();
1420 SetMsgHandled(FALSE); 1436 SetMsgHandled(FALSE);
1421 } 1437 }
1422 1438
1423 LRESULT HWNDMessageHandler::OnEraseBkgnd(HDC dc) { 1439 LRESULT HWNDMessageHandler::OnEraseBkgnd(HDC dc) {
1424 // Needed to prevent resize flicker. 1440 // Needed to prevent resize flicker.
1425 return 1; 1441 return 1;
1426 } 1442 }
1427 1443
1428 void HWNDMessageHandler::OnExitMenuLoop(BOOL is_shortcut_menu) { 1444 void HWNDMessageHandler::OnExitMenuLoop(BOOL is_shortcut_menu) {
1429 if (--menu_depth_ == 0) 1445 if (--menu_depth_ == 0)
1430 delegate_->HandleMenuLoop(false); 1446 delegate_->HandleMenuLoop(false);
1431 DCHECK_GE(0, menu_depth_); 1447 DCHECK_GE(0, menu_depth_);
1432 } 1448 }
1433 1449
1434 void HWNDMessageHandler::OnExitSizeMove() { 1450 void HWNDMessageHandler::OnExitSizeMove() {
1435 delegate_->HandleEndWMSizeMove(); 1451 delegate_->HandleEndWMSizeMove();
1436 SetMsgHandled(FALSE); 1452 SetMsgHandled(FALSE);
1453 size_move_loop_ = false;
1454 // Please refer to the notes in the OnSize function for information about
1455 // the scrolling hack.
1456 if (needs_scroll_styles_)
1457 HideWindowsScrollBar(hwnd());
1437 } 1458 }
1438 1459
1439 void HWNDMessageHandler::OnGetMinMaxInfo(MINMAXINFO* minmax_info) { 1460 void HWNDMessageHandler::OnGetMinMaxInfo(MINMAXINFO* minmax_info) {
1440 gfx::Size min_window_size; 1461 gfx::Size min_window_size;
1441 gfx::Size max_window_size; 1462 gfx::Size max_window_size;
1442 delegate_->GetMinMaxSize(&min_window_size, &max_window_size); 1463 delegate_->GetMinMaxSize(&min_window_size, &max_window_size);
1443 1464
1444 // Add the native frame border size to the minimum and maximum size if the 1465 // Add the native frame border size to the minimum and maximum size if the
1445 // view reports its size as the client size. 1466 // view reports its size as the client size.
1446 if (delegate_->WidgetSizeIsClientSize()) { 1467 if (delegate_->WidgetSizeIsClientSize()) {
(...skipping 647 matching lines...) Expand 10 before | Expand all | Expand 10 after
2094 // invoked OnSize we ensure the RootView has been laid out. 2115 // invoked OnSize we ensure the RootView has been laid out.
2095 ResetWindowRegion(false, true); 2116 ResetWindowRegion(false, true);
2096 2117
2097 #if defined(USE_AURA) 2118 #if defined(USE_AURA)
2098 // We add the WS_VSCROLL and WS_HSCROLL styles to top level windows to ensure 2119 // We add the WS_VSCROLL and WS_HSCROLL styles to top level windows to ensure
2099 // that legacy trackpad/trackpoint drivers generate the WM_VSCROLL and 2120 // that legacy trackpad/trackpoint drivers generate the WM_VSCROLL and
2100 // WM_HSCROLL messages and scrolling works. 2121 // WM_HSCROLL messages and scrolling works.
2101 // We want the style to be present on the window. However we don't want 2122 // We want the style to be present on the window. However we don't want
2102 // Windows to draw the scrollbars. To achieve this we hide the scroll bars 2123 // Windows to draw the scrollbars. To achieve this we hide the scroll bars
2103 // and readd them to the window style in a posted task which works. 2124 // and readd them to the window style in a posted task which works.
2104 if (scroll_styles_set_) { 2125 // If we are in the context of a size loop operation, we do this when the
2105 ShowScrollBar(hwnd(), SB_BOTH, FALSE); 2126 // sizing operation completes.
2106 base::MessageLoop::current()->PostTask( 2127 if (needs_scroll_styles_ && !size_move_loop_)
2107 FROM_HERE, 2128 HideWindowsScrollBar(hwnd());
2108 base::Bind(&AddScrollStylesToWindow, hwnd()));
2109 #endif 2129 #endif
2110 }
2111 } 2130 }
2112 2131
2113 void HWNDMessageHandler::OnSysCommand(UINT notification_code, 2132 void HWNDMessageHandler::OnSysCommand(UINT notification_code,
2114 const CPoint& point) { 2133 const CPoint& point) {
2115 if (!delegate_->ShouldHandleSystemCommands()) 2134 if (!delegate_->ShouldHandleSystemCommands())
2116 return; 2135 return;
2117 2136
2118 // Windows uses the 4 lower order bits of |notification_code| for type- 2137 // Windows uses the 4 lower order bits of |notification_code| for type-
2119 // specific information so we must exclude this when comparing. 2138 // specific information so we must exclude this when comparing.
2120 static const int sc_mask = 0xFFF0; 2139 static const int sc_mask = 0xFFF0;
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
2321 SetMsgHandled(FALSE); 2340 SetMsgHandled(FALSE);
2322 } 2341 }
2323 2342
2324 void HWNDMessageHandler::HandleTouchEvents(const TouchEvents& touch_events) { 2343 void HWNDMessageHandler::HandleTouchEvents(const TouchEvents& touch_events) {
2325 base::WeakPtr<HWNDMessageHandler> ref(weak_factory_.GetWeakPtr()); 2344 base::WeakPtr<HWNDMessageHandler> ref(weak_factory_.GetWeakPtr());
2326 for (size_t i = 0; i < touch_events.size() && ref; ++i) 2345 for (size_t i = 0; i < touch_events.size() && ref; ++i)
2327 delegate_->HandleTouchEvent(touch_events[i]); 2346 delegate_->HandleTouchEvent(touch_events[i]);
2328 } 2347 }
2329 2348
2330 } // namespace views 2349 } // namespace views
OLDNEW
« ui/views/win/hwnd_message_handler.h ('K') | « ui/views/win/hwnd_message_handler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698