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

Side by Side Diff: chrome/browser/ui/views/frame/glass_browser_frame_view.cc

Issue 1869163003: Refactored GlassBrowserFrameView and BrowserDesktopTreeHostWin. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: opaque edits Created 4 years, 8 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
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/frame/glass_browser_frame_view.h" 5 #include "chrome/browser/ui/views/frame/glass_browser_frame_view.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "base/win/windows_version.h" 10 #include "base/win/windows_version.h"
(...skipping 24 matching lines...) Expand all
35 #include "ui/views/controls/label.h" 35 #include "ui/views/controls/label.h"
36 #include "ui/views/layout/layout_constants.h" 36 #include "ui/views/layout/layout_constants.h"
37 #include "ui/views/resources/grit/views_resources.h" 37 #include "ui/views/resources/grit/views_resources.h"
38 #include "ui/views/win/hwnd_util.h" 38 #include "ui/views/win/hwnd_util.h"
39 #include "ui/views/window/client_view.h" 39 #include "ui/views/window/client_view.h"
40 40
41 HICON GlassBrowserFrameView::throbber_icons_[ 41 HICON GlassBrowserFrameView::throbber_icons_[
42 GlassBrowserFrameView::kThrobberIconCount]; 42 GlassBrowserFrameView::kThrobberIconCount];
43 43
44 namespace { 44 namespace {
45 // Size of client edge drawn inside the outer frame borders. 45 // Thickness of the border in the client area that separates it from the
46 const int kNonClientBorderThicknessPreWin10 = 3; 46 // non-client area. Not to be confused with kClientEdgeThickness, which is the
47 const int kNonClientBorderThicknessWin10 = 1; 47 // thickness of the border between the web content and our frame border.
Peter Kasting 2016/04/15 00:20:52 Is the 1 DP "client edge thickness" at least _incl
Bret 2016/04/15 23:07:08 It does. Comment edited.
48 const int kClientBorderThicknessPreWin10 = 3;
49 const int kClientBorderThicknessWin10 = 1;
48 // Besides the frame border, there's empty space atop the window in restored 50 // Besides the frame border, there's empty space atop the window in restored
49 // mode, to use to drag the window around. 51 // mode, to use to drag the window around.
50 const int kNonClientRestoredExtraThickness = 11; 52 const int kNonClientRestoredExtraThickness = 11;
51 // In the window corners, the resize areas don't actually expand bigger, but the 53 // In the window corners the resize area is not actually bigger, but the 16
52 // 16 px at the end of the top and bottom edges triggers diagonal resizing. 54 // pixels at the end of the top edges trigger diagonal resizing.
Peter Kasting 2016/04/15 00:20:52 Why did you remove "and bottom"? We still say "ed
Bret 2016/04/15 23:07:08 Oops, I actually thought it wasn't used at the bot
53 const int kResizeCornerWidth = 16; 55 const int kResizeCornerWidth = 16;
54 // How far the new avatar button is from the left of the minimize button. 56 // How far the profile switcher button is from the left of the minimize button.
55 const int kNewAvatarButtonOffset = 5; 57 const int kProfileSwitcherButtonOffset = 5;
56 // The content edge images have a shadow built into them. 58 // The content edge images have a shadow built into them.
57 const int kContentEdgeShadowThickness = 2; 59 const int kContentEdgeShadowThickness = 2;
58 // In restored mode, the New Tab button isn't at the same height as the caption 60 // In restored mode, the New Tab button isn't at the same height as the caption
59 // buttons, but the space will look cluttered if it actually slides under them, 61 // buttons, but the space will look cluttered if it actually slides under them,
60 // so we stop it when the gap between the two is down to 5 px. 62 // so we stop it when the gap between the two is down to 5 px.
61 const int kNewTabCaptionRestoredSpacing = 5; 63 const int kNewTabCaptionRestoredSpacing = 5;
62 // In maximized mode, where the New Tab button and the caption buttons are at 64 // In maximized mode, where the New Tab button and the caption buttons are at
63 // similar vertical coordinates, we need to reserve a larger, 16 px gap to avoid 65 // similar vertical coordinates, we need to reserve a larger, 16 px gap to avoid
64 // looking too cluttered. 66 // looking too cluttered.
65 const int kNewTabCaptionMaximizedSpacing = 16; 67 const int kNewTabCaptionMaximizedSpacing = 16;
68 // Height of the profile switcher button. Same as the height of the Windows 7/8
69 // caption buttons but doesn't change for 10 where the caption buttons are much
70 // bigger.
71 const int kProfileSwitcherButtonHeightRestored = 20;
72 const int kProfileSwitcherButtonHeightMaximized = 19;
66 73
67 // Converts the |image| to a Windows icon and returns the corresponding HICON 74 // Converts the |image| to a Windows icon and returns the corresponding HICON
68 // handle. |image| is resized to desired |width| and |height| if needed. 75 // handle. |image| is resized to desired |width| and |height| if needed.
69 base::win::ScopedHICON CreateHICONFromSkBitmapSizedTo( 76 base::win::ScopedHICON CreateHICONFromSkBitmapSizedTo(
70 const gfx::ImageSkia& image, 77 const gfx::ImageSkia& image,
71 int width, 78 int width,
72 int height) { 79 int height) {
73 return IconUtil::CreateHICONFromSkBitmap( 80 return IconUtil::CreateHICONFromSkBitmap(
74 width == image.width() && height == image.height() 81 width == image.width() && height == image.height()
75 ? *image.bitmap() 82 ? *image.bitmap()
(...skipping 19 matching lines...) Expand all
95 102
96 GlassBrowserFrameView::~GlassBrowserFrameView() { 103 GlassBrowserFrameView::~GlassBrowserFrameView() {
97 } 104 }
98 105
99 /////////////////////////////////////////////////////////////////////////////// 106 ///////////////////////////////////////////////////////////////////////////////
100 // GlassBrowserFrameView, BrowserNonClientFrameView implementation: 107 // GlassBrowserFrameView, BrowserNonClientFrameView implementation:
101 108
102 gfx::Rect GlassBrowserFrameView::GetBoundsForTabStrip( 109 gfx::Rect GlassBrowserFrameView::GetBoundsForTabStrip(
103 views::View* tabstrip) const { 110 views::View* tabstrip) const {
104 // In maximized RTL windows, don't let the tabstrip overlap the caption area, 111 // In maximized RTL windows, don't let the tabstrip overlap the caption area,
105 // or the alpha-blending it does will make things like the new avatar button 112 // or the alpha-blending it does will make things like the profile switcher
106 // look glitchy. 113 // button look glitchy.
107 const int offset = 114 const int offset = (ui::MaterialDesignController::IsModeMaterial() ||
108 (ui::MaterialDesignController::IsModeMaterial() || !base::i18n::IsRTL() || 115 !CaptionButtonsOnLeadingEdge() || !frame()->IsMaximized())
109 !frame()->IsMaximized()) ? 116 ? GetLayoutInsets(AVATAR_ICON).right()
110 GetLayoutInsets(AVATAR_ICON).right() : 0; 117 : 0;
111 const int x = incognito_bounds_.right() + offset; 118 const int x = incognito_bounds_.right() + offset;
112 int end_x = width() - NonClientBorderThickness(false); 119 int end_x = width() - ClientBorderThickness(false);
113 if (!base::i18n::IsRTL()) { 120 if (!CaptionButtonsOnLeadingEdge()) {
114 end_x = std::min(frame()->GetMinimizeButtonOffset(), end_x) - 121 end_x = std::min(frame()->GetMinimizeButtonOffset(), end_x) -
115 (frame()->IsMaximized() ? 122 (frame()->IsMaximized() ?
116 kNewTabCaptionMaximizedSpacing : kNewTabCaptionRestoredSpacing); 123 kNewTabCaptionMaximizedSpacing : kNewTabCaptionRestoredSpacing);
117 124
118 // The new avatar button is optionally displayed to the left of the 125 // The profile switcher button is optionally displayed to the left of the
119 // minimize button. 126 // minimize button.
120 if (profile_switcher_.view()) { 127 if (profile_switcher_.view()) {
121 const int old_end_x = end_x; 128 const int old_end_x = end_x;
122 end_x -= profile_switcher_.view()->width() + kNewAvatarButtonOffset; 129 end_x -= profile_switcher_.view()->width() + kProfileSwitcherButtonOffset;
123 130
124 // In non-maximized mode, allow the new tab button to slide completely 131 // In non-maximized mode, allow the new tab button to slide completely
125 // under the avatar button. 132 // under the profile switcher button.
126 if (!frame()->IsMaximized()) { 133 if (!frame()->IsMaximized()) {
127 end_x = std::min(end_x + GetLayoutSize(NEW_TAB_BUTTON).width() + 134 end_x = std::min(end_x + GetLayoutSize(NEW_TAB_BUTTON).width() +
128 kNewTabCaptionRestoredSpacing, 135 kNewTabCaptionRestoredSpacing,
129 old_end_x); 136 old_end_x);
130 } 137 }
131 } 138 }
132 } 139 }
133 return gfx::Rect(x, NonClientTopBorderHeight(false), std::max(0, end_x - x), 140 return gfx::Rect(x, NonClientTopHeight(false), std::max(0, end_x - x),
134 tabstrip->GetPreferredSize().height()); 141 tabstrip->GetPreferredSize().height());
135 } 142 }
136 143
137 int GlassBrowserFrameView::GetTopInset(bool restored) const { 144 int GlassBrowserFrameView::GetTopInset(bool restored) const {
138 return GetClientAreaInsets(restored).top(); 145 return GetClientAreaInsets(restored).top();
139 } 146 }
140 147
141 int GlassBrowserFrameView::GetThemeBackgroundXInset() const { 148 int GlassBrowserFrameView::GetThemeBackgroundXInset() const {
142 return 0; 149 return 0;
143 } 150 }
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 } 216 }
210 217
211 int GlassBrowserFrameView::NonClientHitTest(const gfx::Point& point) { 218 int GlassBrowserFrameView::NonClientHitTest(const gfx::Point& point) {
212 // If the browser isn't in normal mode, we haven't customized the frame, so 219 // If the browser isn't in normal mode, we haven't customized the frame, so
213 // Windows can figure this out. If the point isn't within our bounds, then 220 // Windows can figure this out. If the point isn't within our bounds, then
214 // it's in the native portion of the frame, so again Windows can figure it 221 // it's in the native portion of the frame, so again Windows can figure it
215 // out. 222 // out.
216 if (!browser_view()->IsBrowserTypeNormal() || !bounds().Contains(point)) 223 if (!browser_view()->IsBrowserTypeNormal() || !bounds().Contains(point))
217 return HTNOWHERE; 224 return HTNOWHERE;
218 225
219 // See if the point is within the incognito icon or the new avatar menu. 226 // See if the point is within the incognito icon or the profile switcher menu.
220 if ((avatar_button() && 227 if ((avatar_button() &&
221 avatar_button()->GetMirroredBounds().Contains(point)) || 228 avatar_button()->GetMirroredBounds().Contains(point)) ||
222 (profile_switcher_.view() && 229 (profile_switcher_.view() &&
223 profile_switcher_.view()->GetMirroredBounds().Contains(point))) 230 profile_switcher_.view()->GetMirroredBounds().Contains(point)))
224 return HTCLIENT; 231 return HTCLIENT;
225 232
226 int frame_component = frame()->client_view()->NonClientHitTest(point); 233 int frame_component = frame()->client_view()->NonClientHitTest(point);
227 234
228 // See if we're in the sysmenu region. We still have to check the tabstrip 235 // See if we're in the sysmenu region. We still have to check the tabstrip
229 // first so that clicks in a tab don't get treated as sysmenu clicks. 236 // first so that clicks in a tab don't get treated as sysmenu clicks.
230 int nonclient_border_thickness = NonClientBorderThickness(false); 237 int client_border_thickness = ClientBorderThickness(false);
231 if (gfx::Rect(nonclient_border_thickness, 238 if (gfx::Rect(client_border_thickness,
232 gfx::win::GetSystemMetricsInDIP(SM_CYSIZEFRAME), 239 gfx::win::GetSystemMetricsInDIP(SM_CYSIZEFRAME),
233 gfx::win::GetSystemMetricsInDIP(SM_CXSMICON), 240 gfx::win::GetSystemMetricsInDIP(SM_CXSMICON),
234 gfx::win::GetSystemMetricsInDIP(SM_CYSMICON)).Contains(point)) 241 gfx::win::GetSystemMetricsInDIP(SM_CYSMICON))
242 .Contains(point))
235 return (frame_component == HTCLIENT) ? HTCLIENT : HTSYSMENU; 243 return (frame_component == HTCLIENT) ? HTCLIENT : HTSYSMENU;
236 244
237 if (frame_component != HTNOWHERE) 245 if (frame_component != HTNOWHERE)
238 return frame_component; 246 return frame_component;
239 247
240 int frame_top_border_height = FrameTopBorderHeight(false); 248 int top_border_thickness = NonClientTopBorderThickness(false);
241 // We want the resize corner behavior to apply to the kResizeCornerWidth 249 // We want the resize corner behavior to apply to the kResizeCornerWidth
242 // pixels at each end of the top and bottom edges. Because |point|'s x 250 // pixels at each end of the top and bottom edges. Because |point|'s x
243 // coordinate is based on the DWM-inset portion of the window (so, it's 0 at 251 // coordinate is based on the DWM-inset portion of the window (so, it's 0 at
244 // the first pixel inside the left DWM margin), we need to subtract the DWM 252 // the first pixel inside the left DWM margin), we need to subtract the DWM
245 // margin thickness, which we calculate as the total frame border thickness 253 // margin thickness, which we calculate as the total frame border thickness
246 // minus the nonclient border thickness. 254 // minus the nonclient border thickness.
247 const int dwm_margin = FrameBorderThickness() - nonclient_border_thickness; 255 const int dwm_margin = NonClientBorderThickness() - client_border_thickness;
248 int window_component = GetHTComponentForFrame(point, frame_top_border_height, 256 int window_component = GetHTComponentForFrame(
249 nonclient_border_thickness, frame_top_border_height, 257 point, top_border_thickness, client_border_thickness,
250 kResizeCornerWidth - dwm_margin, frame()->widget_delegate()->CanResize()); 258 top_border_thickness, kResizeCornerWidth - dwm_margin,
259 frame()->widget_delegate()->CanResize());
251 // Fall back to the caption if no other component matches. 260 // Fall back to the caption if no other component matches.
252 return (window_component == HTNOWHERE) ? HTCAPTION : window_component; 261 return (window_component == HTNOWHERE) ? HTCAPTION : window_component;
253 } 262 }
254 263
255 /////////////////////////////////////////////////////////////////////////////// 264 ///////////////////////////////////////////////////////////////////////////////
256 // GlassBrowserFrameView, views::View overrides: 265 // GlassBrowserFrameView, views::View overrides:
257 266
258 void GlassBrowserFrameView::OnPaint(gfx::Canvas* canvas) { 267 void GlassBrowserFrameView::OnPaint(gfx::Canvas* canvas) {
259 if (!browser_view()->IsTabStripVisible()) 268 if (!browser_view()->IsTabStripVisible())
260 return; 269 return;
261 if (IsToolbarVisible()) 270 if (IsToolbarVisible())
262 PaintToolbarBackground(canvas); 271 PaintToolbarBackground(canvas);
263 if (!frame()->IsMaximized()) 272 if (!frame()->IsMaximized())
264 PaintClientEdge(canvas); 273 PaintClientEdge(canvas);
265 } 274 }
266 275
267 void GlassBrowserFrameView::Layout() { 276 void GlassBrowserFrameView::Layout() {
268 if (browser_view()->IsRegularOrGuestSession()) 277 if (browser_view()->IsRegularOrGuestSession())
269 LayoutNewStyleAvatar(); 278 LayoutProfileSwitcher();
270 LayoutIncognitoIcon(); 279 LayoutIncognitoIcon();
271 LayoutClientView(); 280 LayoutClientView();
272 } 281 }
273 282
274 /////////////////////////////////////////////////////////////////////////////// 283 ///////////////////////////////////////////////////////////////////////////////
275 // GlassBrowserFrameView, protected: 284 // GlassBrowserFrameView, protected:
276 285
277 // BrowserNonClientFrameView: 286 // BrowserNonClientFrameView:
278 void GlassBrowserFrameView::UpdateAvatar() { 287 void GlassBrowserFrameView::UpdateAvatar() {
279 if (browser_view()->IsRegularOrGuestSession()) 288 if (browser_view()->IsRegularOrGuestSession())
280 profile_switcher_.Update(AvatarButtonStyle::NATIVE); 289 profile_switcher_.Update(AvatarButtonStyle::NATIVE);
281 else 290 else
282 UpdateOldAvatarButton(); 291 UpdateOldAvatarButton();
283 } 292 }
284 293
285 /////////////////////////////////////////////////////////////////////////////// 294 ///////////////////////////////////////////////////////////////////////////////
286 // GlassBrowserFrameView, private: 295 // GlassBrowserFrameView, private:
287 296
288 // views::NonClientFrameView: 297 // views::NonClientFrameView:
289 bool GlassBrowserFrameView::DoesIntersectRect(const views::View* target, 298 bool GlassBrowserFrameView::DoesIntersectRect(const views::View* target,
290 const gfx::Rect& rect) const { 299 const gfx::Rect& rect) const {
291 CHECK_EQ(target, this); 300 CHECK_EQ(target, this);
292 bool hit_incognito_icon = avatar_button() && 301 bool hit_incognito_icon = avatar_button() &&
293 avatar_button()->GetMirroredBounds().Intersects(rect); 302 avatar_button()->GetMirroredBounds().Intersects(rect);
294 bool hit_new_avatar_button = 303 bool hit_profile_switcher_button =
295 profile_switcher_.view() && 304 profile_switcher_.view() &&
296 profile_switcher_.view()->GetMirroredBounds().Intersects(rect); 305 profile_switcher_.view()->GetMirroredBounds().Intersects(rect);
297 return hit_incognito_icon || hit_new_avatar_button || 306 return hit_incognito_icon || hit_profile_switcher_button ||
298 !frame()->client_view()->bounds().Intersects(rect); 307 !frame()->client_view()->bounds().Intersects(rect);
299 } 308 }
300 309
301 int GlassBrowserFrameView::FrameBorderThickness() const { 310 int GlassBrowserFrameView::ClientBorderThickness(bool restored) const {
311 if ((frame()->IsMaximized() || frame()->IsFullscreen()) && !restored)
312 return 0;
313
314 return (base::win::GetVersion() < base::win::VERSION_WIN10)
315 ? kClientBorderThicknessPreWin10
316 : kClientBorderThicknessWin10;
317 }
318
319 int GlassBrowserFrameView::NonClientBorderThickness() const {
302 return (frame()->IsMaximized() || frame()->IsFullscreen()) ? 320 return (frame()->IsMaximized() || frame()->IsFullscreen()) ?
303 0 : gfx::win::GetSystemMetricsInDIP(SM_CXSIZEFRAME); 321 0 : gfx::win::GetSystemMetricsInDIP(SM_CXSIZEFRAME);
304 } 322 }
305 323
306 int GlassBrowserFrameView::FrameTopBorderHeight(bool restored) const { 324 int GlassBrowserFrameView::NonClientTopBorderThickness(bool restored) const {
307 // We'd like to use FrameBorderThickness() here, but the maximized Aero glass 325 // Distinct from NonClientBorderThickness() because Windows gives maximized
308 // frame has a 0 frame border around most edges and a CYSIZEFRAME-thick border 326 // windows an offscreen CYSIZEFRAME-thick region around the edges. The
309 // at the top (see AeroGlassFrame::OnGetMinMaxInfo()). 327 // left/right/bottom edges don't worry about this because we cancel them out
328 // in BrowserDesktopWindowTreeHostWin::GetClientAreaInsets() so the offscreen
329 // area is non-client as far as Windows is concerned. However because we want
330 // to push away the top part of the glass's gradient in Win7 we set the top
331 // client inset to 0. Thus we must compensate here to avoid having UI elements
332 // drift off the top of the screen.
310 return (frame()->IsFullscreen() && !restored) ? 333 return (frame()->IsFullscreen() && !restored) ?
311 0 : gfx::win::GetSystemMetricsInDIP(SM_CYSIZEFRAME); 334 0 : gfx::win::GetSystemMetricsInDIP(SM_CYSIZEFRAME);
312 } 335 }
313 336
314 int GlassBrowserFrameView::NonClientBorderThickness(bool restored) const { 337 int GlassBrowserFrameView::NonClientTopHeight(bool restored) const {
315 if ((frame()->IsMaximized() || frame()->IsFullscreen()) && !restored)
316 return 0;
317
318 return (base::win::GetVersion() < base::win::VERSION_WIN10)
319 ? kNonClientBorderThicknessPreWin10
320 : kNonClientBorderThicknessWin10;
321 }
322
323 int GlassBrowserFrameView::NonClientTopBorderHeight(bool restored) const {
324 if (frame()->IsFullscreen() && !restored) 338 if (frame()->IsFullscreen() && !restored)
325 return 0; 339 return 0;
326 340
327 const int top = FrameTopBorderHeight(restored); 341 const int top = NonClientTopBorderThickness(restored);
328 // The tab top inset is equal to the height of any shadow region above the 342 // The tab top inset is equal to the height of any shadow region above the
329 // tabs, plus a 1 px top stroke. In maximized mode, we want to push the 343 // tabs, plus a 1 px top stroke. In maximized mode, we want to push the
330 // shadow region off the top of the screen but leave the top stroke. 344 // shadow region off the top of the screen but leave the top stroke.
331 // Annoyingly, the pre-MD layout uses different heights for the hit-test 345 // Annoyingly, the pre-MD layout uses different heights for the hit-test
332 // exclusion region (which we want here, since we're trying to size the border 346 // exclusion region (which we want here, since we're trying to size the border
333 // so that the region above the tab's hit-test zone matches) versus the shadow 347 // so that the region above the tab's hit-test zone matches) versus the shadow
334 // thickness. 348 // thickness.
335 const int exclusion = GetLayoutConstant(TAB_TOP_EXCLUSION_HEIGHT); 349 const int exclusion = GetLayoutConstant(TAB_TOP_EXCLUSION_HEIGHT);
336 return (frame()->IsMaximized() && !restored) ? 350 return (frame()->IsMaximized() && !restored) ?
337 (top - GetLayoutInsets(TAB).top() + 1) : 351 (top - GetLayoutInsets(TAB).top() + 1) :
338 (top + kNonClientRestoredExtraThickness - exclusion); 352 (top + kNonClientRestoredExtraThickness - exclusion);
339 } 353 }
340 354
355 int GlassBrowserFrameView::CaptionButtonY() const {
356 // Windows draws its caption buttons at the top of the screen for maximized
357 // windows, and 1 px from the top of the window when restored.
358 return frame()->IsMaximized() ? NonClientTopBorderThickness(false) : 1;
359 }
360
341 bool GlassBrowserFrameView::IsToolbarVisible() const { 361 bool GlassBrowserFrameView::IsToolbarVisible() const {
342 return browser_view()->IsToolbarVisible() && 362 return browser_view()->IsToolbarVisible() &&
343 !browser_view()->toolbar()->GetPreferredSize().IsEmpty(); 363 !browser_view()->toolbar()->GetPreferredSize().IsEmpty();
344 } 364 }
345 365
366 bool GlassBrowserFrameView::CaptionButtonsOnLeadingEdge() const {
367 // Windows always draws the buttons on the right, even in RTL mode.
Peter Kasting 2016/04/15 00:20:51 Nit: Maybe add more detail, e.g.: http://crbug.co
Bret 2016/04/15 23:07:08 Okay I like your comment but since this situation
368 return base::i18n::IsRTL();
369 }
370
346 void GlassBrowserFrameView::PaintToolbarBackground(gfx::Canvas* canvas) const { 371 void GlassBrowserFrameView::PaintToolbarBackground(gfx::Canvas* canvas) const {
347 gfx::Rect toolbar_bounds(browser_view()->GetToolbarBounds()); 372 gfx::Rect toolbar_bounds(browser_view()->GetToolbarBounds());
348 if (toolbar_bounds.IsEmpty()) 373 if (toolbar_bounds.IsEmpty())
349 return; 374 return;
350 gfx::Point toolbar_origin(toolbar_bounds.origin()); 375 gfx::Point toolbar_origin(toolbar_bounds.origin());
351 ConvertPointToTarget(browser_view(), this, &toolbar_origin); 376 ConvertPointToTarget(browser_view(), this, &toolbar_origin);
352 toolbar_bounds.set_origin(toolbar_origin); 377 toolbar_bounds.set_origin(toolbar_origin);
353 378
354 const ui::ThemeProvider* tp = GetThemeProvider(); 379 const ui::ThemeProvider* tp = GetThemeProvider();
355 const gfx::ImageSkia* const bg = tp->GetImageSkiaNamed(IDR_THEME_TOOLBAR); 380 const gfx::ImageSkia* const bg = tp->GetImageSkiaNamed(IDR_THEME_TOOLBAR);
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 // Pre-Material Design, the client edge images start below the toolbar. In MD 467 // Pre-Material Design, the client edge images start below the toolbar. In MD
443 // the client edge images start at the top of the toolbar. 468 // the client edge images start at the top of the toolbar.
444 gfx::Rect client_bounds = CalculateClientAreaBounds(); 469 gfx::Rect client_bounds = CalculateClientAreaBounds();
445 const int x = client_bounds.x(); 470 const int x = client_bounds.x();
446 const bool md = ui::MaterialDesignController::IsModeMaterial(); 471 const bool md = ui::MaterialDesignController::IsModeMaterial();
447 const gfx::Rect toolbar_bounds(browser_view()->GetToolbarBounds()); 472 const gfx::Rect toolbar_bounds(browser_view()->GetToolbarBounds());
448 const int y = 473 const int y =
449 client_bounds.y() + (md ? toolbar_bounds.y() : toolbar_bounds.bottom()); 474 client_bounds.y() + (md ? toolbar_bounds.y() : toolbar_bounds.bottom());
450 const int w = client_bounds.width(); 475 const int w = client_bounds.width();
451 const int right = client_bounds.right(); 476 const int right = client_bounds.right();
452 const int bottom = std::max(y, height() - NonClientBorderThickness(false)); 477 const int bottom = std::max(y, height() - ClientBorderThickness(false));
453 const int height = bottom - y; 478 const int height = bottom - y;
454 479
455 // Draw the client edge images. For non-MD, we fill the toolbar color 480 // Draw the client edge images. For non-MD, we fill the toolbar color
456 // underneath these images so they will lighten/darken it appropriately to 481 // underneath these images so they will lighten/darken it appropriately to
457 // create a "3D shaded" effect. For MD, where we want a flatter appearance, 482 // create a "3D shaded" effect. For MD, where we want a flatter appearance,
458 // we do the filling afterwards so the user sees the unmodified toolbar color. 483 // we do the filling afterwards so the user sees the unmodified toolbar color.
459 const ui::ThemeProvider* tp = GetThemeProvider(); 484 const ui::ThemeProvider* tp = GetThemeProvider();
460 const SkColor toolbar_color = tp->GetColor(ThemeProperties::COLOR_TOOLBAR); 485 const SkColor toolbar_color = tp->GetColor(ThemeProperties::COLOR_TOOLBAR);
461 if (!md) 486 if (!md)
462 FillClientEdgeRects(x, y, right, bottom, toolbar_color, canvas); 487 FillClientEdgeRects(x, y, right, bottom, toolbar_color, canvas);
(...skipping 22 matching lines...) Expand all
485 gfx::Canvas* canvas) const { 510 gfx::Canvas* canvas) const {
486 gfx::Rect side(x - kClientEdgeThickness, y, kClientEdgeThickness, 511 gfx::Rect side(x - kClientEdgeThickness, y, kClientEdgeThickness,
487 bottom + kClientEdgeThickness - y); 512 bottom + kClientEdgeThickness - y);
488 canvas->FillRect(side, color); 513 canvas->FillRect(side, color);
489 canvas->FillRect(gfx::Rect(x, bottom, right - x, kClientEdgeThickness), 514 canvas->FillRect(gfx::Rect(x, bottom, right - x, kClientEdgeThickness),
490 color); 515 color);
491 side.set_x(right); 516 side.set_x(right);
492 canvas->FillRect(side, color); 517 canvas->FillRect(side, color);
493 } 518 }
494 519
495 void GlassBrowserFrameView::LayoutNewStyleAvatar() { 520 void GlassBrowserFrameView::LayoutProfileSwitcher() {
496 DCHECK(browser_view()->IsRegularOrGuestSession()); 521 DCHECK(browser_view()->IsRegularOrGuestSession());
497 if (!profile_switcher_.view()) 522 if (!profile_switcher_.view())
498 return; 523 return;
499 524
500 gfx::Size label_size = profile_switcher_.view()->GetPreferredSize(); 525 gfx::Size label_size = profile_switcher_.view()->GetPreferredSize();
501 526
502 int button_x = frame()->GetMinimizeButtonOffset() - 527 int button_x = frame()->GetMinimizeButtonOffset() -
503 kNewAvatarButtonOffset - label_size.width(); 528 kProfileSwitcherButtonOffset - label_size.width();
504 if (base::i18n::IsRTL()) 529 if (CaptionButtonsOnLeadingEdge())
505 button_x = width() - frame()->GetMinimizeButtonOffset() + 530 button_x = width() - frame()->GetMinimizeButtonOffset() +
506 kNewAvatarButtonOffset; 531 kProfileSwitcherButtonOffset;
507 532
508 // The caption button position and size is confusing. In maximized mode, the 533 const int button_y = CaptionButtonY();
509 // caption buttons are SM_CYMENUSIZE pixels high and are placed 534 const int button_h = frame()->IsMaximized()
510 // FrameTopBorderHeight() pixels from the top of the window; all those top 535 ? kProfileSwitcherButtonHeightMaximized
511 // border pixels are offscreen, so this result in caption buttons flush with 536 : kProfileSwitcherButtonHeightRestored;
512 // the top of the screen. In restored mode, the caption buttons are first 537 profile_switcher_.view()->SetBounds(button_x, button_y, label_size.width(),
513 // placed just below a 2 px border at the top of the window (which is the 538 button_h);
514 // first two pixels' worth of FrameTopBorderHeight()), then extended upwards
515 // one extra pixel to overlap part of this border.
516 //
517 // To match both of these, we size the button as if it's always the extra one
518 // pixel in height, then we place it at the correct position in restored mode,
519 // or one pixel above the top of the screen in maximized mode.
520 int button_y = frame()->IsMaximized() ? (FrameTopBorderHeight(false) - 1) : 1;
521 profile_switcher_.view()->SetBounds(
522 button_x, button_y, label_size.width(),
523 gfx::win::GetSystemMetricsInDIP(SM_CYMENUSIZE) + 1);
524 } 539 }
525 540
526 void GlassBrowserFrameView::LayoutIncognitoIcon() { 541 void GlassBrowserFrameView::LayoutIncognitoIcon() {
527 const bool md = ui::MaterialDesignController::IsModeMaterial(); 542 const bool md = ui::MaterialDesignController::IsModeMaterial();
528 const gfx::Insets insets(GetLayoutInsets(AVATAR_ICON)); 543 const gfx::Insets insets(GetLayoutInsets(AVATAR_ICON));
529 const gfx::Size size(GetOTRAvatarIcon().size()); 544 const gfx::Size size(GetOTRAvatarIcon().size());
530 int x = NonClientBorderThickness(false); 545 int x = ClientBorderThickness(false);
531 // In RTL, the icon needs to start after the caption buttons. 546 // In RTL, the icon needs to start after the caption buttons.
532 if (base::i18n::IsRTL()) { 547 if (CaptionButtonsOnLeadingEdge()) {
533 x = width() - frame()->GetMinimizeButtonOffset() + 548 x = width() - frame()->GetMinimizeButtonOffset() +
534 (profile_switcher_.view() 549 (profile_switcher_.view() ? (profile_switcher_.view()->width() +
535 ? (profile_switcher_.view()->width() + kNewAvatarButtonOffset) 550 kProfileSwitcherButtonOffset)
536 : 0); 551 : 0);
537 } else if (!md && !avatar_button() && IsToolbarVisible() && 552 } else if (!md && !avatar_button() && IsToolbarVisible() &&
538 (base::win::GetVersion() < base::win::VERSION_WIN10)) { 553 (base::win::GetVersion() < base::win::VERSION_WIN10)) {
539 // In non-MD before Win 10, the toolbar has a rounded corner that we don't 554 // In non-MD before Win 10, the toolbar has a rounded corner that we don't
540 // want the tabstrip to overlap. 555 // want the tabstrip to overlap.
541 x += browser_view()->GetToolbarBounds().x() - kContentEdgeShadowThickness + 556 x += browser_view()->GetToolbarBounds().x() - kContentEdgeShadowThickness +
542 GetThemeProvider()->GetImageSkiaNamed( 557 GetThemeProvider()->GetImageSkiaNamed(
543 IDR_CONTENT_TOP_LEFT_CORNER)->width(); 558 IDR_CONTENT_TOP_LEFT_CORNER)->width();
544 } 559 }
545 const int bottom = GetTopInset(false) + browser_view()->GetTabStripHeight() - 560 const int bottom = GetTopInset(false) + browser_view()->GetTabStripHeight() -
546 insets.bottom(); 561 insets.bottom();
547 const int y = (md || !frame()->IsMaximized()) ? 562 const int y = (md || !frame()->IsMaximized())
548 (bottom - size.height()) : FrameTopBorderHeight(false); 563 ? (bottom - size.height())
564 : NonClientTopBorderThickness(false);
549 incognito_bounds_.SetRect(x + (avatar_button() ? insets.left() : 0), y, 565 incognito_bounds_.SetRect(x + (avatar_button() ? insets.left() : 0), y,
550 avatar_button() ? size.width() : 0, bottom - y); 566 avatar_button() ? size.width() : 0, bottom - y);
551 if (avatar_button()) 567 if (avatar_button())
552 avatar_button()->SetBoundsRect(incognito_bounds_); 568 avatar_button()->SetBoundsRect(incognito_bounds_);
553 } 569 }
554 570
555 void GlassBrowserFrameView::LayoutClientView() { 571 void GlassBrowserFrameView::LayoutClientView() {
556 client_view_bounds_ = CalculateClientAreaBounds(); 572 client_view_bounds_ = CalculateClientAreaBounds();
557 } 573 }
558 574
559 gfx::Insets GlassBrowserFrameView::GetClientAreaInsets(bool restored) const { 575 gfx::Insets GlassBrowserFrameView::GetClientAreaInsets(bool restored) const {
560 if (!browser_view()->IsTabStripVisible()) 576 if (!browser_view()->IsTabStripVisible())
561 return gfx::Insets(); 577 return gfx::Insets();
562 578
563 const int top_height = NonClientTopBorderHeight(restored); 579 const int top_height = NonClientTopHeight(restored);
564 const int border_thickness = NonClientBorderThickness(restored); 580 const int border_thickness = ClientBorderThickness(restored);
565 return gfx::Insets(top_height, 581 return gfx::Insets(top_height,
566 border_thickness, 582 border_thickness,
567 border_thickness, 583 border_thickness,
568 border_thickness); 584 border_thickness);
569 } 585 }
570 586
571 gfx::Rect GlassBrowserFrameView::CalculateClientAreaBounds() const { 587 gfx::Rect GlassBrowserFrameView::CalculateClientAreaBounds() const {
572 gfx::Rect bounds(GetLocalBounds()); 588 gfx::Rect bounds(GetLocalBounds());
573 bounds.Inset(GetClientAreaInsets(false)); 589 bounds.Inset(GetClientAreaInsets(false));
574 return bounds; 590 return bounds;
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
648 static bool initialized = false; 664 static bool initialized = false;
649 if (!initialized) { 665 if (!initialized) {
650 for (int i = 0; i < kThrobberIconCount; ++i) { 666 for (int i = 0; i < kThrobberIconCount; ++i) {
651 throbber_icons_[i] = 667 throbber_icons_[i] =
652 ui::LoadThemeIconFromResourcesDataDLL(IDI_THROBBER_01 + i); 668 ui::LoadThemeIconFromResourcesDataDLL(IDI_THROBBER_01 + i);
653 DCHECK(throbber_icons_[i]); 669 DCHECK(throbber_icons_[i]);
654 } 670 }
655 initialized = true; 671 initialized = true;
656 } 672 }
657 } 673 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698