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

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
« no previous file with comments | « ui/views/win/hwnd_message_handler.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 389 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 lock_updates_count_(0), 400 lock_updates_count_(0),
401 ignore_window_pos_changes_(false), 401 ignore_window_pos_changes_(false),
402 last_monitor_(NULL), 402 last_monitor_(NULL),
403 use_layered_buffer_(false), 403 use_layered_buffer_(false),
404 layered_alpha_(255), 404 layered_alpha_(255),
405 waiting_for_redraw_layered_window_contents_(false), 405 waiting_for_redraw_layered_window_contents_(false),
406 is_first_nccalc_(true), 406 is_first_nccalc_(true),
407 menu_depth_(0), 407 menu_depth_(0),
408 autohide_factory_(this), 408 autohide_factory_(this),
409 id_generator_(0), 409 id_generator_(0),
410 scroll_styles_set_(false) { 410 needs_scroll_styles_(false),
411 in_size_move_loop_(false) {
411 } 412 }
412 413
413 HWNDMessageHandler::~HWNDMessageHandler() { 414 HWNDMessageHandler::~HWNDMessageHandler() {
414 delegate_ = NULL; 415 delegate_ = NULL;
415 // Prevent calls back into this class via WNDPROC now that we've been 416 // Prevent calls back into this class via WNDPROC now that we've been
416 // destroyed. 417 // destroyed.
417 ClearUserData(); 418 ClearUserData();
418 } 419 }
419 420
420 void HWNDMessageHandler::Init(HWND parent, const gfx::Rect& bounds) { 421 void HWNDMessageHandler::Init(HWND parent, const gfx::Rect& bounds) {
421 TRACE_EVENT0("views", "HWNDMessageHandler::Init"); 422 TRACE_EVENT0("views", "HWNDMessageHandler::Init");
422 GetMonitorAndRects(bounds.ToRECT(), &last_monitor_, &last_monitor_rect_, 423 GetMonitorAndRects(bounds.ToRECT(), &last_monitor_, &last_monitor_rect_,
423 &last_work_area_); 424 &last_work_area_);
424 425
425 // Create the window. 426 // Create the window.
426 WindowImpl::Init(parent, bounds); 427 WindowImpl::Init(parent, bounds);
428
429 #if defined(USE_AURA)
430 // Certain trackpad drivers on Windows have bugs where in they don't generate
431 // WM_MOUSEWHEEL messages for the trackpoint and trackpad scrolling gestures
432 // unless there is an entry for Chrome with the class name of the Window.
433 // These drivers check if the window under the trackpoint has the WS_VSCROLL/
434 // WS_HSCROLL style and if yes they generate the legacy WM_VSCROLL/WM_HSCROLL
435 // messages. We add these styles to ensure that trackpad/trackpoint scrolling
436 // work.
437 // TODO(ananta)
438 // Look into moving the WS_VSCROLL and WS_HSCROLL style setting logic to the
439 // CalculateWindowStylesFromInitParams function. Doing it there seems to
440 // cause some interactive tests to fail. Investigation needed.
441 if (IsTopLevelWindow(hwnd())) {
442 long current_style = ::GetWindowLong(hwnd(), GWL_STYLE);
443 if (!(current_style & WS_POPUP)) {
444 AddScrollStylesToWindow(hwnd());
445 needs_scroll_styles_ = true;
446 }
447 }
448 #endif
427 } 449 }
428 450
429 void HWNDMessageHandler::InitModalType(ui::ModalType modal_type) { 451 void HWNDMessageHandler::InitModalType(ui::ModalType modal_type) {
430 if (modal_type == ui::MODAL_TYPE_NONE) 452 if (modal_type == ui::MODAL_TYPE_NONE)
431 return; 453 return;
432 // We implement modality by crawling up the hierarchy of windows starting 454 // 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 455 // at the owner, disabling all of them so that they don't receive input
434 // messages. 456 // messages.
435 HWND start = ::GetWindow(hwnd(), GW_OWNER); 457 HWND start = ::GetWindow(hwnd(), GW_OWNER);
436 while (start) { 458 while (start) {
(...skipping 922 matching lines...) Expand 10 before | Expand all | Expand 10 after
1359 #if !defined(USE_AURA) 1381 #if !defined(USE_AURA)
1360 // We need to add ourselves as a message loop observer so that we can repaint 1382 // 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 1383 // aggressively if the contents of our window become invalid. Unfortunately
1362 // WM_PAINT messages are starved and we get flickery redrawing when resizing 1384 // WM_PAINT messages are starved and we get flickery redrawing when resizing
1363 // if we do not do this. 1385 // if we do not do this.
1364 base::MessageLoopForUI::current()->AddObserver(this); 1386 base::MessageLoopForUI::current()->AddObserver(this);
1365 #endif 1387 #endif
1366 1388
1367 delegate_->HandleCreate(); 1389 delegate_->HandleCreate();
1368 1390
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. 1391 // TODO(beng): move more of NWW::OnCreate here.
1389 return 0; 1392 return 0;
1390 } 1393 }
1391 1394
1392 void HWNDMessageHandler::OnDestroy() { 1395 void HWNDMessageHandler::OnDestroy() {
1393 delegate_->HandleDestroying(); 1396 delegate_->HandleDestroying();
1394 } 1397 }
1395 1398
1396 void HWNDMessageHandler::OnDisplayChange(UINT bits_per_pixel, 1399 void HWNDMessageHandler::OnDisplayChange(UINT bits_per_pixel,
1397 const CSize& screen_size) { 1400 const CSize& screen_size) {
(...skipping 11 matching lines...) Expand all
1409 FrameTypeChanged(); 1412 FrameTypeChanged();
1410 return 0; 1413 return 0;
1411 } 1414 }
1412 1415
1413 void HWNDMessageHandler::OnEnterMenuLoop(BOOL from_track_popup_menu) { 1416 void HWNDMessageHandler::OnEnterMenuLoop(BOOL from_track_popup_menu) {
1414 if (menu_depth_++ == 0) 1417 if (menu_depth_++ == 0)
1415 delegate_->HandleMenuLoop(true); 1418 delegate_->HandleMenuLoop(true);
1416 } 1419 }
1417 1420
1418 void HWNDMessageHandler::OnEnterSizeMove() { 1421 void HWNDMessageHandler::OnEnterSizeMove() {
1422 in_size_move_loop_ = true;
1423
1424 // Please refer to the comments in the OnSize function about the scrollbar
1425 // hack.
1426 // Hide the Windows scrollbar if the scroll styles are present to ensure
1427 // that a paint flicker does not occur while sizing.
1428 if (needs_scroll_styles_)
1429 ShowScrollBar(hwnd(), SB_BOTH, FALSE);
1430
1419 delegate_->HandleBeginWMSizeMove(); 1431 delegate_->HandleBeginWMSizeMove();
1420 SetMsgHandled(FALSE); 1432 SetMsgHandled(FALSE);
1421 } 1433 }
1422 1434
1423 LRESULT HWNDMessageHandler::OnEraseBkgnd(HDC dc) { 1435 LRESULT HWNDMessageHandler::OnEraseBkgnd(HDC dc) {
1424 // Needed to prevent resize flicker. 1436 // Needed to prevent resize flicker.
1425 return 1; 1437 return 1;
1426 } 1438 }
1427 1439
1428 void HWNDMessageHandler::OnExitMenuLoop(BOOL is_shortcut_menu) { 1440 void HWNDMessageHandler::OnExitMenuLoop(BOOL is_shortcut_menu) {
1429 if (--menu_depth_ == 0) 1441 if (--menu_depth_ == 0)
1430 delegate_->HandleMenuLoop(false); 1442 delegate_->HandleMenuLoop(false);
1431 DCHECK_GE(0, menu_depth_); 1443 DCHECK_GE(0, menu_depth_);
1432 } 1444 }
1433 1445
1434 void HWNDMessageHandler::OnExitSizeMove() { 1446 void HWNDMessageHandler::OnExitSizeMove() {
1435 delegate_->HandleEndWMSizeMove(); 1447 delegate_->HandleEndWMSizeMove();
1436 SetMsgHandled(FALSE); 1448 SetMsgHandled(FALSE);
1449 in_size_move_loop_ = false;
1450 // Please refer to the notes in the OnSize function for information about
1451 // the scrolling hack.
1452 // We hide the Windows scrollbar in the OnEnterSizeMove function. We need
1453 // to add the scroll styles back to ensure that scrolling works in legacy
1454 // trackpoint drivers.
1455 if (needs_scroll_styles_)
1456 AddScrollStylesToWindow(hwnd());
1437 } 1457 }
1438 1458
1439 void HWNDMessageHandler::OnGetMinMaxInfo(MINMAXINFO* minmax_info) { 1459 void HWNDMessageHandler::OnGetMinMaxInfo(MINMAXINFO* minmax_info) {
1440 gfx::Size min_window_size; 1460 gfx::Size min_window_size;
1441 gfx::Size max_window_size; 1461 gfx::Size max_window_size;
1442 delegate_->GetMinMaxSize(&min_window_size, &max_window_size); 1462 delegate_->GetMinMaxSize(&min_window_size, &max_window_size);
1443 1463
1444 // Add the native frame border size to the minimum and maximum size if the 1464 // Add the native frame border size to the minimum and maximum size if the
1445 // view reports its size as the client size. 1465 // view reports its size as the client size.
1446 if (delegate_->WidgetSizeIsClientSize()) { 1466 if (delegate_->WidgetSizeIsClientSize()) {
(...skipping 644 matching lines...) Expand 10 before | Expand all | Expand 10 after
2091 void HWNDMessageHandler::OnSize(UINT param, const CSize& size) { 2111 void HWNDMessageHandler::OnSize(UINT param, const CSize& size) {
2092 RedrawWindow(hwnd(), NULL, NULL, RDW_INVALIDATE | RDW_ALLCHILDREN); 2112 RedrawWindow(hwnd(), NULL, NULL, RDW_INVALIDATE | RDW_ALLCHILDREN);
2093 // ResetWindowRegion is going to trigger WM_NCPAINT. By doing it after we've 2113 // ResetWindowRegion is going to trigger WM_NCPAINT. By doing it after we've
2094 // invoked OnSize we ensure the RootView has been laid out. 2114 // invoked OnSize we ensure the RootView has been laid out.
2095 ResetWindowRegion(false, true); 2115 ResetWindowRegion(false, true);
2096 2116
2097 #if defined(USE_AURA) 2117 #if defined(USE_AURA)
2098 // We add the WS_VSCROLL and WS_HSCROLL styles to top level windows to ensure 2118 // 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 2119 // that legacy trackpad/trackpoint drivers generate the WM_VSCROLL and
2100 // WM_HSCROLL messages and scrolling works. 2120 // WM_HSCROLL messages and scrolling works.
2101 // We want the style to be present on the window. However we don't want 2121 // We want the scroll styles to be present on the window. However we don't
2102 // Windows to draw the scrollbars. To achieve this we hide the scroll bars 2122 // want Windows to draw the scrollbars. To achieve this we hide the scroll
2103 // and readd them to the window style in a posted task which works. 2123 // bars and readd them to the window style in a posted task to ensure that we
2104 if (scroll_styles_set_) { 2124 // don't get nested WM_SIZE messages.
2105 ShowScrollBar(hwnd(), SB_BOTH, FALSE); 2125 if (needs_scroll_styles_ && !in_size_move_loop_)
2106 base::MessageLoop::current()->PostTask( 2126 base::MessageLoop::current()->PostTask(
2107 FROM_HERE, 2127 FROM_HERE, base::Bind(&AddScrollStylesToWindow, hwnd()));
2108 base::Bind(&AddScrollStylesToWindow, hwnd()));
2109 #endif 2128 #endif
2110 }
2111 } 2129 }
2112 2130
2113 void HWNDMessageHandler::OnSysCommand(UINT notification_code, 2131 void HWNDMessageHandler::OnSysCommand(UINT notification_code,
2114 const CPoint& point) { 2132 const CPoint& point) {
2115 if (!delegate_->ShouldHandleSystemCommands()) 2133 if (!delegate_->ShouldHandleSystemCommands())
2116 return; 2134 return;
2117 2135
2118 // Windows uses the 4 lower order bits of |notification_code| for type- 2136 // Windows uses the 4 lower order bits of |notification_code| for type-
2119 // specific information so we must exclude this when comparing. 2137 // specific information so we must exclude this when comparing.
2120 static const int sc_mask = 0xFFF0; 2138 static const int sc_mask = 0xFFF0;
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
2321 SetMsgHandled(FALSE); 2339 SetMsgHandled(FALSE);
2322 } 2340 }
2323 2341
2324 void HWNDMessageHandler::HandleTouchEvents(const TouchEvents& touch_events) { 2342 void HWNDMessageHandler::HandleTouchEvents(const TouchEvents& touch_events) {
2325 base::WeakPtr<HWNDMessageHandler> ref(weak_factory_.GetWeakPtr()); 2343 base::WeakPtr<HWNDMessageHandler> ref(weak_factory_.GetWeakPtr());
2326 for (size_t i = 0; i < touch_events.size() && ref; ++i) 2344 for (size_t i = 0; i < touch_events.size() && ref; ++i)
2327 delegate_->HandleTouchEvent(touch_events[i]); 2345 delegate_->HandleTouchEvent(touch_events[i]);
2328 } 2346 }
2329 2347
2330 } // namespace views 2348 } // namespace views
OLDNEW
« no previous file with comments | « 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