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

Side by Side Diff: chrome/browser/views/frame/browser_frame_win.cc

Issue 304007: Make sure the RootView is sized to the correct bounds when the opaque frame i... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 2 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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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/views/frame/browser_frame_win.h" 5 #include "chrome/browser/views/frame/browser_frame_win.h"
6 6
7 #include <dwmapi.h> 7 #include <dwmapi.h>
8 #include <shellapi.h> 8 #include <shellapi.h>
9 9
10 #include <set> 10 #include <set>
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 // (e.g. no custom theme is active), or when we're a popup or app window. We 112 // (e.g. no custom theme is active), or when we're a popup or app window. We
113 // don't theme popup or app windows, so regardless of whether or not a theme 113 // don't theme popup or app windows, so regardless of whether or not a theme
114 // is active for normal browser windows, we don't want to use the custom frame 114 // is active for normal browser windows, we don't want to use the custom frame
115 // for popups/apps. 115 // for popups/apps.
116 return GetThemeProvider()->ShouldUseNativeFrame() || 116 return GetThemeProvider()->ShouldUseNativeFrame() ||
117 (!browser_view_->IsBrowserTypeNormal() && 117 (!browser_view_->IsBrowserTypeNormal() &&
118 win_util::ShouldUseVistaFrame()); 118 win_util::ShouldUseVistaFrame());
119 } 119 }
120 120
121 /////////////////////////////////////////////////////////////////////////////// 121 ///////////////////////////////////////////////////////////////////////////////
122 // BrowserFrame, views::WidgetWin overrides: 122 // BrowserFrame, views::WindowWin overrides:
123
124 gfx::Insets BrowserFrameWin::GetClientAreaInsets() const {
125 if (!GetNonClientView()->UseNativeFrame())
126 return WindowWin::GetClientAreaInsets();
127
128 int border_thickness = GetSystemMetrics(SM_CXSIZEFRAME);
129 // We draw our own client edge over part of the default frame.
130 if (!IsMaximized())
131 border_thickness -= kClientEdgeThickness;
132 return gfx::Insets(0, border_thickness, border_thickness, border_thickness);
133 }
123 134
124 bool BrowserFrameWin::GetAccelerator(int cmd_id, 135 bool BrowserFrameWin::GetAccelerator(int cmd_id,
125 views::Accelerator* accelerator) { 136 views::Accelerator* accelerator) {
126 return browser_view_->GetAccelerator(cmd_id, accelerator); 137 return browser_view_->GetAccelerator(cmd_id, accelerator);
127 } 138 }
128 139
129 void BrowserFrameWin::OnEndSession(BOOL ending, UINT logoff) { 140 void BrowserFrameWin::OnEndSession(BOOL ending, UINT logoff) {
130 BrowserList::WindowsSessionEnding(); 141 BrowserList::WindowsSessionEnding();
131 } 142 }
132 143
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 } 185 }
175 186
176 LRESULT BrowserFrameWin::OnNCActivate(BOOL active) { 187 LRESULT BrowserFrameWin::OnNCActivate(BOOL active) {
177 if (browser_view_->ActivateAppModalDialog()) 188 if (browser_view_->ActivateAppModalDialog())
178 return TRUE; 189 return TRUE;
179 190
180 browser_view_->ActivationChanged(!!active); 191 browser_view_->ActivationChanged(!!active);
181 return WindowWin::OnNCActivate(active); 192 return WindowWin::OnNCActivate(active);
182 } 193 }
183 194
184 LRESULT BrowserFrameWin::OnNCCalcSize(BOOL mode, LPARAM l_param) {
185 // This class' client rect calculations are specific to the tabbed browser
186 // window. When the glass frame is active, the client area is reported to be
187 // a rectangle that touches the top of the window and is inset from the left,
188 // right and bottom edges. The client rect touches the top because the
189 // tabstrip is painted over the caption at a custom offset.
190 // When the glass frame is not active, the client area is reported to be the
191 // entire window rect, except for the cases noted below.
192 // For non-tabbed browser windows, we use the default handling from the
193 // views system.
194 if (!browser_view_->IsBrowserTypeNormal())
195 return WindowWin::OnNCCalcSize(mode, l_param);
196
197 RECT* client_rect = mode ?
198 &reinterpret_cast<NCCALCSIZE_PARAMS*>(l_param)->rgrc[0] :
199 reinterpret_cast<RECT*>(l_param);
200 int border_thickness = 0;
201 if (browser_view_->IsMaximized()) {
202 // Make the maximized mode client rect fit the screen exactly, by
203 // subtracting the border Windows automatically adds for maximized mode.
204 border_thickness = GetSystemMetrics(SM_CXSIZEFRAME);
205 // Find all auto-hide taskbars along the screen edges and adjust in by the
206 // thickness of the auto-hide taskbar on each such edge, so the window isn't
207 // treated as a "fullscreen app", which would cause the taskbars to
208 // disappear.
209 HMONITOR monitor = MonitorFromWindow(GetNativeView(),
210 MONITOR_DEFAULTTONULL);
211 if (win_util::EdgeHasTopmostAutoHideTaskbar(ABE_LEFT, monitor))
212 client_rect->left += win_util::kAutoHideTaskbarThicknessPx;
213 if (win_util::EdgeHasTopmostAutoHideTaskbar(ABE_RIGHT, monitor))
214 client_rect->right -= win_util::kAutoHideTaskbarThicknessPx;
215 if (win_util::EdgeHasTopmostAutoHideTaskbar(ABE_BOTTOM, monitor)) {
216 client_rect->bottom -= win_util::kAutoHideTaskbarThicknessPx;
217 } else if (win_util::EdgeHasTopmostAutoHideTaskbar(ABE_TOP, monitor)) {
218 // Tricky bit. Due to a bug in DwmDefWindowProc()'s handling of
219 // WM_NCHITTEST, having any nonclient area atop the window causes the
220 // caption buttons to draw onscreen but not respond to mouse hover/clicks.
221 // So for a taskbar at the screen top, we can't push the client_rect->top
222 // down; instead, we move the bottom up by one pixel, which is the
223 // smallest change we can make and still get a client area less than the
224 // screen size. This is visibly ugly, but there seems to be no better
225 // solution.
226 --client_rect->bottom;
227 }
228 } else if (!browser_view_->IsFullscreen()) {
229 if (GetNonClientView()->UseNativeFrame()) {
230 // We draw our own client edge over part of the default frame.
231 border_thickness =
232 GetSystemMetrics(SM_CXSIZEFRAME) - kClientEdgeThickness;
233 } else {
234 // This is weird, but highly essential. If we don't offset the bottom edge
235 // of the client rect, the window client area and window area will match,
236 // and when returning to glass rendering mode from non-glass, the client
237 // area will not paint black as transparent. This is because (and I don't
238 // know why) the client area goes from matching the window rect to being
239 // something else. If the client area is not the window rect in both
240 // modes, the blackness doesn't occur. Because of this, we need to tell
241 // the RootView to lay out to fit the window rect, rather than the client
242 // rect when using the opaque frame. See SizeRootViewToWindowRect.
243 --client_rect->bottom;
244 }
245 }
246 client_rect->left += border_thickness;
247 client_rect->right -= border_thickness;
248 client_rect->bottom -= border_thickness;
249
250 // We'd like to return WVR_REDRAW in some cases here, but because we almost
251 // always have nonclient area (except in fullscreen mode, where it doesn't
252 // matter), we can't. See comments in window.cc:OnNCCalcSize() for more info.
253 return 0;
254 }
255
256 LRESULT BrowserFrameWin::OnNCHitTest(const CPoint& pt) { 195 LRESULT BrowserFrameWin::OnNCHitTest(const CPoint& pt) {
257 // Only do DWM hit-testing when we are using the native frame. 196 // Only do DWM hit-testing when we are using the native frame.
258 if (GetNonClientView()->UseNativeFrame()) { 197 if (GetNonClientView()->UseNativeFrame()) {
259 LRESULT result; 198 LRESULT result;
260 if (DwmDefWindowProc(GetNativeView(), WM_NCHITTEST, 0, 199 if (DwmDefWindowProc(GetNativeView(), WM_NCHITTEST, 0,
261 MAKELPARAM(pt.x, pt.y), &result)) { 200 MAKELPARAM(pt.x, pt.y), &result)) {
262 return result; 201 return result;
263 } 202 }
264 } 203 }
265 return WindowWin::OnNCHitTest(pt); 204 return WindowWin::OnNCHitTest(pt);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 } 252 }
314 253
315 ThemeProvider* BrowserFrameWin::GetThemeProvider() const { 254 ThemeProvider* BrowserFrameWin::GetThemeProvider() const {
316 return profile_->GetThemeProvider(); 255 return profile_->GetThemeProvider();
317 } 256 }
318 257
319 ThemeProvider* BrowserFrameWin::GetDefaultThemeProvider() const { 258 ThemeProvider* BrowserFrameWin::GetDefaultThemeProvider() const {
320 return profile_->GetThemeProvider(); 259 return profile_->GetThemeProvider();
321 } 260 }
322 261
323 bool BrowserFrameWin::SizeRootViewToWindowRect() const {
324 return !GetNonClientView()->UseNativeFrame();
325 }
326
327 /////////////////////////////////////////////////////////////////////////////// 262 ///////////////////////////////////////////////////////////////////////////////
328 // BrowserFrame, views::CustomFrameWindow overrides: 263 // BrowserFrame, views::CustomFrameWindow overrides:
329 264
330 int BrowserFrameWin::GetShowState() const { 265 int BrowserFrameWin::GetShowState() const {
331 return browser_view_->GetShowState(); 266 return browser_view_->GetShowState();
332 } 267 }
333 268
334 views::NonClientFrameView* BrowserFrameWin::CreateFrameViewForWindow() { 269 views::NonClientFrameView* BrowserFrameWin::CreateFrameViewForWindow() {
335 if (AlwaysUseNativeFrame()) 270 if (AlwaysUseNativeFrame())
336 browser_frame_view_ = new GlassBrowserFrameView(this, browser_view_); 271 browser_frame_view_ = new GlassBrowserFrameView(this, browser_view_);
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 // more "transparent" look. 328 // more "transparent" look.
394 ::SetWindowLong(frame_hwnd, GWL_STYLE, 329 ::SetWindowLong(frame_hwnd, GWL_STYLE,
395 saved_window_style_ & ~WS_CAPTION); 330 saved_window_style_ & ~WS_CAPTION);
396 SetLayeredWindowAttributes(frame_hwnd, RGB(0xFF, 0xFF, 0xFF), 331 SetLayeredWindowAttributes(frame_hwnd, RGB(0xFF, 0xFF, 0xFF),
397 kTabDragWindowAlpha, LWA_ALPHA); 332 kTabDragWindowAlpha, LWA_ALPHA);
398 } else { 333 } else {
399 ::SetWindowLong(frame_hwnd, GWL_STYLE, saved_window_style_); 334 ::SetWindowLong(frame_hwnd, GWL_STYLE, saved_window_style_);
400 ::SetWindowLong(frame_hwnd, GWL_EXSTYLE, saved_window_ex_style_); 335 ::SetWindowLong(frame_hwnd, GWL_EXSTYLE, saved_window_ex_style_);
401 } 336 }
402 } 337 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698