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

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: Address review 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
« no previous file with comments | « no previous file | 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 "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 // There is a potential race condition here:
143 (GetWindowLong(taskbar, GWL_EXSTYLE) & WS_EX_TOPMOST)) { 143 // 1. A maximized chrome window is fullscreened.
144 // 2. It is switched back to maximized.
145 // 3. In the process the window gets a WM_NCCACLSIZE message which calls us to
146 // get the autohide state.
147 // 4. The worker thread is invoked. It calls the API to get the autohide
148 // state. On Windows versions earlier than Windows 7, taskbars could
149 // easily be always on top or not.
150 // This meant that we only want to look for taskbars which have the topmost
151 // bit set. However this causes problems in cases where the window on the
152 // main thread is still in the process of switching away from fullscreen.
153 // In this case the taskbar might not yet have the topmost bit set.
154 // 5. The main thread resumes and does not leave space for the taskbar and
155 // hence it does not pop when hovered.
156 //
157 // To address point 4 above, it is best to not check for the WS_EX_TOPMOST
158 // window style on the taskbar, as starting from Windows 7, the topmost
159 // style is always set. We don't support XP and Vista anymore.
160 if (::IsWindow(taskbar)) {
144 if (MonitorFromWindow(taskbar, MONITOR_DEFAULTTONEAREST) == monitor) 161 if (MonitorFromWindow(taskbar, MONITOR_DEFAULTTONEAREST) == monitor)
145 return true; 162 return true;
146 // In some cases like when the autohide taskbar is on the left of the 163 // 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 164 // secondary monitor, the MonitorFromWindow call above fails to return the
148 // correct monitor the taskbar is on. We fallback to MonitorFromPoint for 165 // correct monitor the taskbar is on. We fallback to MonitorFromPoint for
149 // the cursor position in that case, which seems to work well. 166 // the cursor position in that case, which seems to work well.
150 POINT cursor_pos = {0}; 167 POINT cursor_pos = {0};
151 GetCursorPos(&cursor_pos); 168 GetCursorPos(&cursor_pos);
152 if (MonitorFromPoint(cursor_pos, MONITOR_DEFAULTTONEAREST) == monitor) 169 if (MonitorFromPoint(cursor_pos, MONITOR_DEFAULTTONEAREST) == monitor)
153 return true; 170 return true;
154 } 171 }
155 return false; 172 return false;
156 } 173 }
157 174
158 int GetAppbarAutohideEdgesOnWorkerThread(HMONITOR monitor) { 175 int GetAppbarAutohideEdgesOnWorkerThread(HMONITOR monitor) {
159 DCHECK(monitor); 176 DCHECK(monitor);
160 177
161 int edges = 0; 178 int edges = 0;
162 if (MonitorHasTopmostAutohideTaskbarForEdge(ABE_LEFT, monitor)) 179 if (MonitorHasAutohideTaskbarForEdge(ABE_LEFT, monitor))
163 edges |= views::ViewsDelegate::EDGE_LEFT; 180 edges |= views::ViewsDelegate::EDGE_LEFT;
164 if (MonitorHasTopmostAutohideTaskbarForEdge(ABE_TOP, monitor)) 181 if (MonitorHasAutohideTaskbarForEdge(ABE_TOP, monitor))
165 edges |= views::ViewsDelegate::EDGE_TOP; 182 edges |= views::ViewsDelegate::EDGE_TOP;
166 if (MonitorHasTopmostAutohideTaskbarForEdge(ABE_RIGHT, monitor)) 183 if (MonitorHasAutohideTaskbarForEdge(ABE_RIGHT, monitor))
167 edges |= views::ViewsDelegate::EDGE_RIGHT; 184 edges |= views::ViewsDelegate::EDGE_RIGHT;
168 if (MonitorHasTopmostAutohideTaskbarForEdge(ABE_BOTTOM, monitor)) 185 if (MonitorHasAutohideTaskbarForEdge(ABE_BOTTOM, monitor))
169 edges |= views::ViewsDelegate::EDGE_BOTTOM; 186 edges |= views::ViewsDelegate::EDGE_BOTTOM;
170 return edges; 187 return edges;
171 } 188 }
172 #endif 189 #endif
173 190
174 #if defined(USE_ASH) 191 #if defined(USE_ASH)
175 void ProcessAcceleratorNow(const ui::Accelerator& accelerator) { 192 void ProcessAcceleratorNow(const ui::Accelerator& accelerator) {
176 // TODO(afakhry): See if we need here to send the accelerator to the 193 // TODO(afakhry): See if we need here to send the accelerator to the
177 // FocusManager of the active window in a follow-up CL. 194 // FocusManager of the active window in a follow-up CL.
178 ash::WmShell::Get()->accelerator_controller()->Process(accelerator); 195 ash::WmShell::Get()->accelerator_controller()->Process(accelerator);
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 int ChromeViewsDelegate::GetAppbarAutohideEdges(HMONITOR monitor, 487 int ChromeViewsDelegate::GetAppbarAutohideEdges(HMONITOR monitor,
471 const base::Closure& callback) { 488 const base::Closure& callback) {
472 // Initialize the map with EDGE_BOTTOM. This is important, as if we return an 489 // 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 490 // 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 491 // 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 492 // 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 493 // we don't initially go fullscreen until we figure out the real auto-hide
477 // edges. 494 // edges.
478 if (!appbar_autohide_edge_map_.count(monitor)) 495 if (!appbar_autohide_edge_map_.count(monitor))
479 appbar_autohide_edge_map_[monitor] = EDGE_BOTTOM; 496 appbar_autohide_edge_map_[monitor] = EDGE_BOTTOM;
497
498 // We use the SHAppBarMessage API to get the taskbar autohide state. This API
499 // spins a modal loop which could cause callers to be reentered. To avoid
500 // that we retrieve the taskbar state in a worker thread.
480 if (monitor && !in_autohide_edges_callback_) { 501 if (monitor && !in_autohide_edges_callback_) {
481 base::PostTaskAndReplyWithResult( 502 base::PostTaskAndReplyWithResult(
482 content::BrowserThread::GetBlockingPool(), 503 content::BrowserThread::GetBlockingPool(),
483 FROM_HERE, 504 FROM_HERE,
484 base::Bind(&GetAppbarAutohideEdgesOnWorkerThread, 505 base::Bind(&GetAppbarAutohideEdgesOnWorkerThread,
485 monitor), 506 monitor),
486 base::Bind(&ChromeViewsDelegate::OnGotAppbarAutohideEdges, 507 base::Bind(&ChromeViewsDelegate::OnGotAppbarAutohideEdges,
487 weak_factory_.GetWeakPtr(), 508 weak_factory_.GetWeakPtr(),
488 callback, 509 callback,
489 monitor, 510 monitor,
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
523 return ViewsDelegate::GetDialogRelatedButtonHorizontalSpacing(); 544 return ViewsDelegate::GetDialogRelatedButtonHorizontalSpacing();
524 } 545 }
525 546
526 #if !defined(USE_ASH) 547 #if !defined(USE_ASH)
527 views::Widget::InitParams::WindowOpacity 548 views::Widget::InitParams::WindowOpacity
528 ChromeViewsDelegate::GetOpacityForInitParams( 549 ChromeViewsDelegate::GetOpacityForInitParams(
529 const views::Widget::InitParams& params) { 550 const views::Widget::InitParams& params) {
530 return views::Widget::InitParams::OPAQUE_WINDOW; 551 return views::Widget::InitParams::OPAQUE_WINDOW;
531 } 552 }
532 #endif 553 #endif
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698