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

Side by Side Diff: chrome/browser/ui/views/chrome_views_delegate.cc

Issue 2542533002: Don't check autohide taskbar for WS_EX_TOPMOST when we are querying the autohide state. (Closed)
Patch Set: Added comments Created 4 years 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
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 "chrome/browser/ui/views/chrome_views_delegate.h" 5 #include "chrome/browser/ui/views/chrome_views_delegate.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 PrefService* GetPrefsForWindow(const views::Widget* window) { 92 PrefService* GetPrefsForWindow(const views::Widget* window) {
93 Profile* profile = GetProfileForWindow(window); 93 Profile* profile = GetProfileForWindow(window);
94 if (!profile) { 94 if (!profile) {
95 // Use local state for windows that have no explicit profile. 95 // Use local state for windows that have no explicit profile.
96 return g_browser_process->local_state(); 96 return g_browser_process->local_state();
97 } 97 }
98 return profile->GetPrefs(); 98 return profile->GetPrefs();
99 } 99 }
100 100
101 #if defined(OS_WIN) 101 #if defined(OS_WIN)
102 bool MonitorHasTopmostAutohideTaskbarForEdge(UINT edge, HMONITOR monitor) { 102 bool MonitorHasAutohideTaskbarForEdge(UINT edge, HMONITOR monitor) {
103 APPBARDATA taskbar_data = { sizeof(APPBARDATA), NULL, 0, edge }; 103 APPBARDATA taskbar_data = { sizeof(APPBARDATA), NULL, 0, edge };
104 taskbar_data.hWnd = ::GetForegroundWindow(); 104 taskbar_data.hWnd = ::GetForegroundWindow();
105 105
106 // TODO(robliao): Remove ScopedTracker below once crbug.com/462368 is fixed. 106 // TODO(robliao): Remove ScopedTracker below once crbug.com/462368 is fixed.
107 tracked_objects::ScopedTracker tracking_profile( 107 tracked_objects::ScopedTracker tracking_profile(
108 FROM_HERE_WITH_EXPLICIT_FUNCTION( 108 FROM_HERE_WITH_EXPLICIT_FUNCTION(
109 "462368 MonitorHasTopmostAutohideTaskbarForEdge")); 109 "462368 MonitorHasAutohideTaskbarForEdge"));
110 110
111 // MSDN documents an ABM_GETAUTOHIDEBAREX, which supposedly takes a monitor 111 // MSDN documents an ABM_GETAUTOHIDEBAREX, which supposedly takes a monitor
112 // rect and returns autohide bars on that monitor. This sounds like a good 112 // rect and returns autohide bars on that monitor. This sounds like a good
113 // idea for multi-monitor systems. Unfortunately, it appears to not work at 113 // idea for multi-monitor systems. Unfortunately, it appears to not work at
114 // least some of the time (erroneously returning NULL) and there's almost no 114 // least some of the time (erroneously returning NULL) and there's almost no
115 // online documentation or other sample code using it that suggests ways to 115 // online documentation or other sample code using it that suggests ways to
116 // address this problem. We do the following:- 116 // address this problem. We do the following:-
117 // 1. Use the ABM_GETAUTOHIDEBAR message. If it works, i.e. returns a valid 117 // 1. Use the ABM_GETAUTOHIDEBAR message. If it works, i.e. returns a valid
118 // window we are done. 118 // window we are done.
119 // 2. If the ABM_GETAUTOHIDEBAR message does not work we query the auto hide 119 // 2. If the ABM_GETAUTOHIDEBAR message does not work we query the auto hide
(...skipping 12 matching lines...) Expand all
132 132
133 taskbar_data.hWnd = ::FindWindow(L"Shell_TrayWnd", NULL); 133 taskbar_data.hWnd = ::FindWindow(L"Shell_TrayWnd", NULL);
134 if (!::IsWindow(taskbar_data.hWnd)) 134 if (!::IsWindow(taskbar_data.hWnd))
135 return false; 135 return false;
136 136
137 SHAppBarMessage(ABM_GETTASKBARPOS, &taskbar_data); 137 SHAppBarMessage(ABM_GETTASKBARPOS, &taskbar_data);
138 if (taskbar_data.uEdge == edge) 138 if (taskbar_data.uEdge == edge)
139 taskbar = taskbar_data.hWnd; 139 taskbar = taskbar_data.hWnd;
140 } 140 }
141 141
142 if (::IsWindow(taskbar) && 142 if (::IsWindow(taskbar)) {
143 (GetWindowLong(taskbar, GWL_EXSTYLE) & WS_EX_TOPMOST)) {
144 if (MonitorFromWindow(taskbar, MONITOR_DEFAULTTONEAREST) == monitor) 143 if (MonitorFromWindow(taskbar, MONITOR_DEFAULTTONEAREST) == monitor)
145 return true; 144 return true;
146 // In some cases like when the autohide taskbar is on the left of the 145 // In some cases like when the autohide taskbar is on the left of the
147 // secondary monitor, the MonitorFromWindow call above fails to return the 146 // secondary monitor, the MonitorFromWindow call above fails to return the
148 // correct monitor the taskbar is on. We fallback to MonitorFromPoint for 147 // correct monitor the taskbar is on. We fallback to MonitorFromPoint for
149 // the cursor position in that case, which seems to work well. 148 // the cursor position in that case, which seems to work well.
150 POINT cursor_pos = {0}; 149 POINT cursor_pos = {0};
151 GetCursorPos(&cursor_pos); 150 GetCursorPos(&cursor_pos);
152 if (MonitorFromPoint(cursor_pos, MONITOR_DEFAULTTONEAREST) == monitor) 151 if (MonitorFromPoint(cursor_pos, MONITOR_DEFAULTTONEAREST) == monitor)
153 return true; 152 return true;
154 } 153 }
155 return false; 154 return false;
156 } 155 }
157 156
158 int GetAppbarAutohideEdgesOnWorkerThread(HMONITOR monitor) { 157 int GetAppbarAutohideEdgesOnWorkerThread(HMONITOR monitor) {
159 DCHECK(monitor); 158 DCHECK(monitor);
160 159
161 int edges = 0; 160 int edges = 0;
162 if (MonitorHasTopmostAutohideTaskbarForEdge(ABE_LEFT, monitor)) 161 if (MonitorHasAutohideTaskbarForEdge(ABE_LEFT, monitor))
163 edges |= views::ViewsDelegate::EDGE_LEFT; 162 edges |= views::ViewsDelegate::EDGE_LEFT;
164 if (MonitorHasTopmostAutohideTaskbarForEdge(ABE_TOP, monitor)) 163 if (MonitorHasAutohideTaskbarForEdge(ABE_TOP, monitor))
165 edges |= views::ViewsDelegate::EDGE_TOP; 164 edges |= views::ViewsDelegate::EDGE_TOP;
166 if (MonitorHasTopmostAutohideTaskbarForEdge(ABE_RIGHT, monitor)) 165 if (MonitorHasAutohideTaskbarForEdge(ABE_RIGHT, monitor))
167 edges |= views::ViewsDelegate::EDGE_RIGHT; 166 edges |= views::ViewsDelegate::EDGE_RIGHT;
168 if (MonitorHasTopmostAutohideTaskbarForEdge(ABE_BOTTOM, monitor)) 167 if (MonitorHasAutohideTaskbarForEdge(ABE_BOTTOM, monitor))
169 edges |= views::ViewsDelegate::EDGE_BOTTOM; 168 edges |= views::ViewsDelegate::EDGE_BOTTOM;
170 return edges; 169 return edges;
171 } 170 }
172 #endif 171 #endif
173 172
174 #if defined(USE_ASH) 173 #if defined(USE_ASH)
175 void ProcessAcceleratorNow(const ui::Accelerator& accelerator) { 174 void ProcessAcceleratorNow(const ui::Accelerator& accelerator) {
176 // TODO(afakhry): See if we need here to send the accelerator to the 175 // TODO(afakhry): See if we need here to send the accelerator to the
177 // FocusManager of the active window in a follow-up CL. 176 // FocusManager of the active window in a follow-up CL.
178 ash::WmShell::Get()->accelerator_controller()->Process(accelerator); 177 ash::WmShell::Get()->accelerator_controller()->Process(accelerator);
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 459
461 ui::ContextFactory* ChromeViewsDelegate::GetContextFactory() { 460 ui::ContextFactory* ChromeViewsDelegate::GetContextFactory() {
462 return content::GetContextFactory(); 461 return content::GetContextFactory();
463 } 462 }
464 463
465 std::string ChromeViewsDelegate::GetApplicationName() { 464 std::string ChromeViewsDelegate::GetApplicationName() {
466 return version_info::GetProductName(); 465 return version_info::GetProductName();
467 } 466 }
468 467
469 #if defined(OS_WIN) 468 #if defined(OS_WIN)
469 // We use the SHAppBarMessage API to get the taskbar autohide state. This API
Peter Kasting 2016/12/02 01:56:41 Perhaps this comment should be moved up to where w
ananta 2016/12/02 06:09:14 Done.
470 // spins a modal loop which could cause callers to be reentered. This may not
471 // be desirable and to avoid that we retrieve the taskbar state in a worker
472 // thread. This fixes the reentrancy problems but introduces subtle timing
473 // issues like the one below:
474 // 1. A maximized chrome window is fullscreened.
475 // 2. It is switched back to maximized.
476 // 3. In the process the window gets a WM_NCCACLSIZE message which calls us to
477 // get the autohide state.
478 // 4. The worker thread is invoked and the main thread is suspended. The worker
Peter Kasting 2016/12/02 01:56:41 Is the main thread always suspended, or is it just
ananta 2016/12/02 06:09:14 The latter.
479 // thread calls the API to get the autohide state. The code also checked
480 // whether the taskbar was a topmost window. That fails in this case because
481 // the main window on the main thread is still in the process of switching
482 // away from fullscreen.
483 // 5. The main thread resumes and does not leave space for the taskbar and
484 // hence it does not popup up when hovered on.
485 //
486 // To fix point 4 above we removed the check for the WS_EX_TOPMOST style as
487 // that is the default on Windows 7+. Additionally we also want to ensure
488 // that we query the taskbar state at the point when a window switches fully
489 // away from fullscreen. The best time appears to be when we receive the
490 // ABN_FULLSCREENAPP notification from the shell. Please refer to the
491 // HWNDMessageHandler::OnAppBarMessage() for the code.
470 int ChromeViewsDelegate::GetAppbarAutohideEdges(HMONITOR monitor, 492 int ChromeViewsDelegate::GetAppbarAutohideEdges(HMONITOR monitor,
471 const base::Closure& callback) { 493 const base::Closure& callback) {
472 // Initialize the map with EDGE_BOTTOM. This is important, as if we return an 494 // Initialize the map with EDGE_BOTTOM. This is important, as if we return an
473 // initial value of 0 (no auto-hide edges) then we'll go fullscreen and 495 // initial value of 0 (no auto-hide edges) then we'll go fullscreen and
474 // windows will automatically remove WS_EX_TOPMOST from the appbar resulting 496 // windows will automatically remove WS_EX_TOPMOST from the appbar resulting
475 // in us thinking there is no auto-hide edges. By returning at least one edge 497 // in us thinking there is no auto-hide edges. By returning at least one edge
476 // we don't initially go fullscreen until we figure out the real auto-hide 498 // we don't initially go fullscreen until we figure out the real auto-hide
477 // edges. 499 // edges.
478 if (!appbar_autohide_edge_map_.count(monitor)) 500 if (!appbar_autohide_edge_map_.count(monitor))
479 appbar_autohide_edge_map_[monitor] = EDGE_BOTTOM; 501 appbar_autohide_edge_map_[monitor] = EDGE_BOTTOM;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
523 return ViewsDelegate::GetDialogRelatedButtonHorizontalSpacing(); 545 return ViewsDelegate::GetDialogRelatedButtonHorizontalSpacing();
524 } 546 }
525 547
526 #if !defined(USE_ASH) 548 #if !defined(USE_ASH)
527 views::Widget::InitParams::WindowOpacity 549 views::Widget::InitParams::WindowOpacity
528 ChromeViewsDelegate::GetOpacityForInitParams( 550 ChromeViewsDelegate::GetOpacityForInitParams(
529 const views::Widget::InitParams& params) { 551 const views::Widget::InitParams& params) {
530 return views::Widget::InitParams::OPAQUE_WINDOW; 552 return views::Widget::InitParams::OPAQUE_WINDOW;
531 } 553 }
532 #endif 554 #endif
OLDNEW
« no previous file with comments | « no previous file | ui/views/win/hwnd_message_handler.h » ('j') | ui/views/win/hwnd_message_handler.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698