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

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

Issue 7003080: Change profile menu button to avatar button (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 6 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/opaque_browser_frame_view.h" 5 #include "chrome/browser/ui/views/frame/opaque_browser_frame_view.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "chrome/browser/prefs/pref_service.h" 10 #include "chrome/browser/prefs/pref_service.h"
11 #include "chrome/browser/profiles/profile.h" 11 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/themes/theme_service.h" 12 #include "chrome/browser/themes/theme_service.h"
13 #include "chrome/browser/ui/profile_menu_model.h"
14 #include "chrome/browser/ui/views/avatar_menu_button.h"
13 #include "chrome/browser/ui/views/frame/browser_frame.h" 15 #include "chrome/browser/ui/views/frame/browser_frame.h"
14 #include "chrome/browser/ui/views/frame/browser_view.h" 16 #include "chrome/browser/ui/views/frame/browser_view.h"
15 #include "chrome/browser/ui/views/profile_menu_button.h"
16 #include "chrome/browser/ui/views/profile_tag_view.h"
17 #include "chrome/browser/ui/views/tabs/tab_strip.h" 17 #include "chrome/browser/ui/views/tabs/tab_strip.h"
18 #include "chrome/browser/ui/views/toolbar_view.h" 18 #include "chrome/browser/ui/views/toolbar_view.h"
19 #include "chrome/common/chrome_switches.h" 19 #include "chrome/common/chrome_switches.h"
20 #include "chrome/common/pref_names.h" 20 #include "chrome/common/pref_names.h"
21 #include "content/browser/tab_contents/tab_contents.h" 21 #include "content/browser/tab_contents/tab_contents.h"
22 #include "content/common/notification_service.h" 22 #include "content/common/notification_service.h"
23 #include "grit/app_resources.h" 23 #include "grit/app_resources.h"
24 #include "grit/chromium_strings.h" 24 #include "grit/chromium_strings.h"
25 #include "grit/generated_resources.h" 25 #include "grit/generated_resources.h"
26 #include "grit/theme_resources.h" 26 #include "grit/theme_resources.h"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 // The titlebar has a 2 px 3D edge along the top and bottom. 67 // The titlebar has a 2 px 3D edge along the top and bottom.
68 const int kTitlebarTopAndBottomEdgeThickness = 2; 68 const int kTitlebarTopAndBottomEdgeThickness = 2;
69 // The icon is inset 2 px from the left frame border. 69 // The icon is inset 2 px from the left frame border.
70 const int kIconLeftSpacing = 2; 70 const int kIconLeftSpacing = 2;
71 // The icon never shrinks below 16 px on a side. 71 // The icon never shrinks below 16 px on a side.
72 const int kIconMinimumSize = 16; 72 const int kIconMinimumSize = 16;
73 // There is a 4 px gap between the icon and the title text. 73 // There is a 4 px gap between the icon and the title text.
74 const int kIconTitleSpacing = 4; 74 const int kIconTitleSpacing = 4;
75 // There is a 5 px gap between the title text and the caption buttons. 75 // There is a 5 px gap between the title text and the caption buttons.
76 const int kTitleLogoSpacing = 5; 76 const int kTitleLogoSpacing = 5;
77 // The OTR avatar ends 2 px above the bottom of the tabstrip (which, given the 77 // The avatar ends 2 px above the bottom of the tabstrip (which, given the
78 // way the tabstrip draws its bottom edge, will appear like a 1 px gap to the 78 // way the tabstrip draws its bottom edge, will appear like a 1 px gap to the
79 // user). 79 // user).
80 const int kOTRBottomSpacing = 2; 80 const int kAvatarBottomSpacing = 2;
81 // There are 2 px on each side of the OTR avatar (between the frame border and 81 // There are 2 px on each side of the avatar (between the frame border and
82 // it on the left, and between it and the tabstrip on the right). 82 // it on the left, and between it and the tabstrip on the right).
83 const int kOTRSideSpacing = 2; 83 const int kAvatarSideSpacing = 2;
84 // The top 1 px of the tabstrip is shadow; in maximized mode we push this off 84 // The top 1 px of the tabstrip is shadow; in maximized mode we push this off
85 // the top of the screen so the tabs appear flush against the screen edge. 85 // the top of the screen so the tabs appear flush against the screen edge.
86 const int kTabstripTopShadowThickness = 1; 86 const int kTabstripTopShadowThickness = 1;
87 // In restored mode, the New Tab button isn't at the same height as the caption 87 // In restored mode, the New Tab button isn't at the same height as the caption
88 // buttons, but the space will look cluttered if it actually slides under them, 88 // buttons, but the space will look cluttered if it actually slides under them,
89 // so we stop it when the gap between the two is down to 5 px. 89 // so we stop it when the gap between the two is down to 5 px.
90 const int kNewTabCaptionRestoredSpacing = 5; 90 const int kNewTabCaptionRestoredSpacing = 5;
91 // In maximized mode, where the New Tab button and the caption buttons are at 91 // In maximized mode, where the New Tab button and the caption buttons are at
92 // similar vertical coordinates, we need to reserve a larger, 16 px gap to avoid 92 // similar vertical coordinates, we need to reserve a larger, 16 px gap to avoid
93 // looking too cluttered. 93 // looking too cluttered.
94 const int kNewTabCaptionMaximizedSpacing = 16; 94 const int kNewTabCaptionMaximizedSpacing = 16;
95 // How far to indent the tabstrip from the left side of the screen when there 95 // How far to indent the tabstrip from the left side of the screen when there
96 // is no OTR icon. 96 // is no avatar icon.
97 const int kTabStripIndent = 1; 97 const int kTabStripIndent = 1;
98 // Inset from the top of the toolbar/tabstrip to the shadow. Used only for 98 // Inset from the top of the toolbar/tabstrip to the shadow. Used only for
99 // vertical tabs. 99 // vertical tabs.
100 const int kVerticalTabBorderInset = 3; 100 const int kVerticalTabBorderInset = 3;
101 // Y position for profile tag inside the frame.
102 const int kProfileTagYPosition = 1;
103 101
104 // Converts |bounds| from |src|'s coordinate system to |dst|, and checks if 102 // Converts |bounds| from |src|'s coordinate system to |dst|, and checks if
105 // |pt| is contained within. 103 // |pt| is contained within.
106 bool ConvertedContainsCheck(gfx::Rect bounds, const views::View* src, 104 bool ConvertedContainsCheck(gfx::Rect bounds, const views::View* src,
107 const views::View* dst, const gfx::Point& pt) { 105 const views::View* dst, const gfx::Point& pt) {
108 DCHECK(src); 106 DCHECK(src);
109 DCHECK(dst); 107 DCHECK(dst);
110 gfx::Point origin(bounds.origin()); 108 gfx::Point origin(bounds.origin());
111 views::View::ConvertPointToView(src, dst, &origin); 109 views::View::ConvertPointToView(src, dst, &origin);
112 bounds.set_origin(origin); 110 bounds.set_origin(origin);
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 AddChildView(close_button_); 191 AddChildView(close_button_);
194 192
195 // Initializing the TabIconView is expensive, so only do it if we need to. 193 // Initializing the TabIconView is expensive, so only do it if we need to.
196 if (browser_view_->ShouldShowWindowIcon()) { 194 if (browser_view_->ShouldShowWindowIcon()) {
197 window_icon_ = new TabIconView(this); 195 window_icon_ = new TabIconView(this);
198 window_icon_->set_is_light(true); 196 window_icon_->set_is_light(true);
199 AddChildView(window_icon_); 197 AddChildView(window_icon_);
200 window_icon_->Update(); 198 window_icon_->Update();
201 } 199 }
202 200
203 // If multi-profile is enabled set up profile button and login notifications. 201 if (browser_view_->ShouldShowAvatar()) {
202 ui::MenuModel* menu_model = browser_view_->IsOffTheRecord() ?
203 NULL : new ProfileMenuModel;
204 avatar_button_.reset(new AvatarMenuButton(std::wstring(), menu_model));
sky 2011/06/09 15:46:46 Document AvatarMenuButton takes ownership of menu_
sail 2011/06/10 00:56:20 Done.
205 AddChildView(avatar_button_.get());
206
207 if (browser_view_->IsOffTheRecord()) {
208 avatar_button_->SetIcon(browser_view_->GetOTRAvatarIcon());
209 } else {
210 // TODO(sail) Get the avatar icon assigned to this profile.
211 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
212 avatar_button_->SetIcon(*rb.GetBitmapNamed(IDR_PROFILE_AVATAR_1));
213 // TODO(sail) Also need to call SetHoverIcon() and SetPushedIcon().
214 }
215 }
216
217 // If multi-profile is enabled set up login notifications.
204 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess(); 218 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
205 if (browser_command_line.HasSwitch(switches::kMultiProfiles) && 219 if (browser_command_line.HasSwitch(switches::kMultiProfiles) &&
206 !browser_view_->ShouldShowOffTheRecordAvatar()) { 220 !browser_view->IsOffTheRecord()) {
207 RegisterLoginNotifications(); 221 RegisterLoginNotifications();
208 profile_button_.reset(new ProfileMenuButton(std::wstring(),
209 browser_view_->browser()->profile()));
210 profile_button_->SetVisible(false);
211 profile_tag_.reset(new ProfileTagView(frame_, profile_button_.get()));
212 profile_tag_->SetVisible(false);
213 AddChildView(profile_tag_.get());
214 AddChildView(profile_button_.get());
215 } 222 }
216 } 223 }
217 224
218 OpaqueBrowserFrameView::~OpaqueBrowserFrameView() { 225 OpaqueBrowserFrameView::~OpaqueBrowserFrameView() {
219 } 226 }
220 227
221 /////////////////////////////////////////////////////////////////////////////// 228 ///////////////////////////////////////////////////////////////////////////////
222 // OpaqueBrowserFrameView, protected: 229 // OpaqueBrowserFrameView, protected:
223 230
224 int OpaqueBrowserFrameView::GetReservedHeight() const { 231 int OpaqueBrowserFrameView::GetReservedHeight() const {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 if (!tabstrip) 269 if (!tabstrip)
263 return gfx::Rect(); 270 return gfx::Rect();
264 271
265 if (browser_view_->UseVerticalTabs()) { 272 if (browser_view_->UseVerticalTabs()) {
266 gfx::Size ps = tabstrip->GetPreferredSize(); 273 gfx::Size ps = tabstrip->GetPreferredSize();
267 return gfx::Rect(NonClientBorderThickness(), 274 return gfx::Rect(NonClientBorderThickness(),
268 NonClientTopBorderHeight(false, false), ps.width(), 275 NonClientTopBorderHeight(false, false), ps.width(),
269 browser_view_->height()); 276 browser_view_->height());
270 } 277 }
271 278
272 int tabstrip_x = browser_view_->ShouldShowOffTheRecordAvatar() ? 279 int tabstrip_x = browser_view_->ShouldShowAvatar() ?
273 (otr_avatar_bounds_.right() + kOTRSideSpacing) : 280 (avatar_bounds_.right() + kAvatarSideSpacing) :
274 NonClientBorderThickness() + kTabStripIndent; 281 NonClientBorderThickness() + kTabStripIndent;
275 282
276 int maximized_spacing = 283 int maximized_spacing = kNewTabCaptionMaximizedSpacing;
277 kNewTabCaptionMaximizedSpacing +
278 (show_profile_button() && profile_button_->IsVisible() ?
279 profile_button_->GetPreferredSize().width() +
280 ProfileMenuButton::kProfileTagHorizontalSpacing : 0);
281 int tabstrip_width = minimize_button_->x() - tabstrip_x - 284 int tabstrip_width = minimize_button_->x() - tabstrip_x -
282 (frame_->IsMaximized() ? 285 (frame_->IsMaximized() ?
283 maximized_spacing : kNewTabCaptionRestoredSpacing); 286 maximized_spacing : kNewTabCaptionRestoredSpacing);
284 return gfx::Rect(tabstrip_x, GetHorizontalTabStripVerticalOffset(false), 287 return gfx::Rect(tabstrip_x, GetHorizontalTabStripVerticalOffset(false),
285 std::max(0, tabstrip_width), tabstrip->GetPreferredSize().height()); 288 std::max(0, tabstrip_width), tabstrip->GetPreferredSize().height());
286 } 289 }
287 290
288 int OpaqueBrowserFrameView::GetHorizontalTabStripVerticalOffset( 291 int OpaqueBrowserFrameView::GetHorizontalTabStripVerticalOffset(
289 bool restored) const { 292 bool restored) const {
290 return NonClientTopBorderHeight(restored, true) + ((!restored && 293 return NonClientTopBorderHeight(restored, true) + ((!restored &&
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 return gfx::Rect(std::max(0, client_bounds.x() - border_thickness), 336 return gfx::Rect(std::max(0, client_bounds.x() - border_thickness),
334 std::max(0, client_bounds.y() - top_height), 337 std::max(0, client_bounds.y() - top_height),
335 client_bounds.width() + (2 * border_thickness), 338 client_bounds.width() + (2 * border_thickness),
336 client_bounds.height() + top_height + border_thickness); 339 client_bounds.height() + top_height + border_thickness);
337 } 340 }
338 341
339 int OpaqueBrowserFrameView::NonClientHitTest(const gfx::Point& point) { 342 int OpaqueBrowserFrameView::NonClientHitTest(const gfx::Point& point) {
340 if (!bounds().Contains(point)) 343 if (!bounds().Contains(point))
341 return HTNOWHERE; 344 return HTNOWHERE;
342 345
343 int frame_component = 346 int frame_component = frame_->client_view()->NonClientHitTest(point);
344 frame_->client_view()->NonClientHitTest(point); 347
348 // See if the point is within the avatar menu button.
349 if (avatar_button_.get() && avatar_button_->IsVisible() &&
sky 2011/06/09 15:46:46 Move above 346
sail 2011/06/10 00:56:20 Done.
350 avatar_button_->GetMirroredBounds().Contains(point))
351 return HTCLIENT;
345 352
346 // See if we're in the sysmenu region. We still have to check the tabstrip 353 // See if we're in the sysmenu region. We still have to check the tabstrip
347 // first so that clicks in a tab don't get treated as sysmenu clicks. 354 // first so that clicks in a tab don't get treated as sysmenu clicks.
348 gfx::Rect sysmenu_rect(IconBounds()); 355 gfx::Rect sysmenu_rect(IconBounds());
349 // In maximized mode we extend the rect to the screen corner to take advantage 356 // In maximized mode we extend the rect to the screen corner to take advantage
350 // of Fitts' Law. 357 // of Fitts' Law.
351 if (frame_->IsMaximized()) 358 if (frame_->IsMaximized())
352 sysmenu_rect.SetRect(0, 0, sysmenu_rect.right(), sysmenu_rect.bottom()); 359 sysmenu_rect.SetRect(0, 0, sysmenu_rect.right(), sysmenu_rect.bottom());
353 sysmenu_rect.set_x(GetMirroredXForRect(sysmenu_rect)); 360 sysmenu_rect.set_x(GetMirroredXForRect(sysmenu_rect));
354 if (sysmenu_rect.Contains(point)) 361 if (sysmenu_rect.Contains(point))
355 return (frame_component == HTCLIENT) ? HTCLIENT : HTSYSMENU; 362 return (frame_component == HTCLIENT) ? HTCLIENT : HTSYSMENU;
356 363
357 if (frame_component != HTNOWHERE) 364 if (frame_component != HTNOWHERE)
358 return frame_component; 365 return frame_component;
359 366
360 // Then see if the point is within any of the window controls. 367 // Then see if the point is within any of the window controls.
361 if (close_button_->IsVisible() && 368 if (close_button_->IsVisible() &&
362 close_button_->GetMirroredBounds().Contains(point)) 369 close_button_->GetMirroredBounds().Contains(point))
363 return HTCLOSE; 370 return HTCLOSE;
364 if (restore_button_->IsVisible() && 371 if (restore_button_->IsVisible() &&
365 restore_button_->GetMirroredBounds().Contains(point)) 372 restore_button_->GetMirroredBounds().Contains(point))
366 return HTMAXBUTTON; 373 return HTMAXBUTTON;
367 if (maximize_button_->IsVisible() && 374 if (maximize_button_->IsVisible() &&
368 maximize_button_->GetMirroredBounds().Contains(point)) 375 maximize_button_->GetMirroredBounds().Contains(point))
369 return HTMAXBUTTON; 376 return HTMAXBUTTON;
370 if (minimize_button_->IsVisible() && 377 if (minimize_button_->IsVisible() &&
371 minimize_button_->GetMirroredBounds().Contains(point)) 378 minimize_button_->GetMirroredBounds().Contains(point))
372 return HTMINBUTTON; 379 return HTMINBUTTON;
373 380
374 // See if the point is within the profile menu button.
375 if (show_profile_button() && profile_button_->IsVisible() &&
376 profile_button_->GetMirroredBounds().Contains(point))
377 return HTCLIENT;
378
379 views::WindowDelegate* delegate = frame_->window_delegate(); 381 views::WindowDelegate* delegate = frame_->window_delegate();
380 if (!delegate) { 382 if (!delegate) {
381 LOG(WARNING) << "delegate is NULL, returning safe default."; 383 LOG(WARNING) << "delegate is NULL, returning safe default.";
382 return HTCAPTION; 384 return HTCAPTION;
383 } 385 }
384 int window_component = GetHTComponentForFrame(point, TopResizeHeight(), 386 int window_component = GetHTComponentForFrame(point, TopResizeHeight(),
385 NonClientBorderThickness(), kResizeAreaCornerSize, kResizeAreaCornerSize, 387 NonClientBorderThickness(), kResizeAreaCornerSize, kResizeAreaCornerSize,
386 delegate->CanResize()); 388 delegate->CanResize());
387 // Fall back to the caption if no other component matches. 389 // Fall back to the caption if no other component matches.
388 return (window_component == HTNOWHERE) ? HTCAPTION : window_component; 390 return (window_component == HTNOWHERE) ? HTCAPTION : window_component;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 return; // Nothing is visible, so don't bother to paint. 423 return; // Nothing is visible, so don't bother to paint.
422 424
423 if (frame_->IsMaximized()) 425 if (frame_->IsMaximized())
424 PaintMaximizedFrameBorder(canvas); 426 PaintMaximizedFrameBorder(canvas);
425 else 427 else
426 PaintRestoredFrameBorder(canvas); 428 PaintRestoredFrameBorder(canvas);
427 PaintTitleBar(canvas); 429 PaintTitleBar(canvas);
428 if (browser_view_->IsToolbarVisible() || 430 if (browser_view_->IsToolbarVisible() ||
429 browser_view_->UseCompactNavigationBar()) 431 browser_view_->UseCompactNavigationBar())
430 PaintToolbarBackground(canvas); 432 PaintToolbarBackground(canvas);
431 if (browser_view_->ShouldShowOffTheRecordAvatar())
432 PaintOTRAvatar(canvas);
433 if (!frame_->IsMaximized()) 433 if (!frame_->IsMaximized())
434 PaintRestoredClientEdge(canvas); 434 PaintRestoredClientEdge(canvas);
435 } 435 }
436 436
437 void OpaqueBrowserFrameView::Layout() { 437 void OpaqueBrowserFrameView::Layout() {
438 LayoutWindowControls(); 438 LayoutWindowControls();
439 LayoutTitleBar(); 439 LayoutTitleBar();
440 LayoutOTRAvatar(); 440 LayoutAvatar();
441 LayoutProfileTag();
442 client_view_bounds_ = CalculateClientAreaBounds(width(), height()); 441 client_view_bounds_ = CalculateClientAreaBounds(width(), height());
443 } 442 }
444 443
445 bool OpaqueBrowserFrameView::HitTest(const gfx::Point& l) const { 444 bool OpaqueBrowserFrameView::HitTest(const gfx::Point& l) const {
446 // If the point is outside the bounds of the client area, claim it. 445 // If the point is outside the bounds of the client area, claim it.
447 bool in_nonclient = NonClientFrameView::HitTest(l); 446 bool in_nonclient = NonClientFrameView::HitTest(l);
448 if (in_nonclient) 447 if (in_nonclient)
449 return in_nonclient; 448 return in_nonclient;
450 449
451 // Otherwise claim it only if it's in a non-tab portion of the tabstrip. 450 // Otherwise claim it only if it's in a non-tab portion of the tabstrip.
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
517 516
518 /////////////////////////////////////////////////////////////////////////////// 517 ///////////////////////////////////////////////////////////////////////////////
519 // OpaqueBrowserFrameView, protected: 518 // OpaqueBrowserFrameView, protected:
520 519
521 void OpaqueBrowserFrameView::Observe(NotificationType type, 520 void OpaqueBrowserFrameView::Observe(NotificationType type,
522 const NotificationSource& source, 521 const NotificationSource& source,
523 const NotificationDetails& details) { 522 const NotificationDetails& details) {
524 DCHECK_EQ(NotificationType::PREF_CHANGED, type.value); 523 DCHECK_EQ(NotificationType::PREF_CHANGED, type.value);
525 std::string* name = Details<std::string>(details).ptr(); 524 std::string* name = Details<std::string>(details).ptr();
526 if (prefs::kGoogleServicesUsername == *name) 525 if (prefs::kGoogleServicesUsername == *name)
527 LayoutProfileTag(); 526 LayoutAvatar();
528 } 527 }
529 528
530 /////////////////////////////////////////////////////////////////////////////// 529 ///////////////////////////////////////////////////////////////////////////////
531 // OpaqueBrowserFrameView, private: 530 // OpaqueBrowserFrameView, private:
532 531
533 int OpaqueBrowserFrameView::FrameBorderThickness(bool restored) const { 532 int OpaqueBrowserFrameView::FrameBorderThickness(bool restored) const {
534 return (!restored && (frame_->IsMaximized() || frame_->IsFullscreen())) ? 533 return (!restored && (frame_->IsMaximized() || frame_->IsFullscreen())) ?
535 0 : kFrameBorderThickness; 534 0 : kFrameBorderThickness;
536 } 535 }
537 536
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after
918 toolbar_right->height() - bottom_edge_height, toolbar_right->width(), 917 toolbar_right->height() - bottom_edge_height, toolbar_right->width(),
919 bottom_edge_height, right_x, bottom_y, toolbar_right->width(), 918 bottom_edge_height, right_x, bottom_y, toolbar_right->width(),
920 bottom_edge_height, false); 919 bottom_edge_height, false);
921 920
922 // Draw the content/toolbar separator. 921 // Draw the content/toolbar separator.
923 canvas->FillRectInt(ResourceBundle::toolbar_separator_color, 922 canvas->FillRectInt(ResourceBundle::toolbar_separator_color,
924 x + kClientEdgeThickness, toolbar_bounds.bottom() - kClientEdgeThickness, 923 x + kClientEdgeThickness, toolbar_bounds.bottom() - kClientEdgeThickness,
925 w - (2 * kClientEdgeThickness), kClientEdgeThickness); 924 w - (2 * kClientEdgeThickness), kClientEdgeThickness);
926 } 925 }
927 926
928 void OpaqueBrowserFrameView::PaintOTRAvatar(gfx::Canvas* canvas) {
929 // In RTL mode, the avatar icon should be looking the opposite direction.
930 canvas->Save();
931 if (base::i18n::IsRTL()) {
932 canvas->TranslateInt(width(), 0);
933 canvas->ScaleInt(-1, 1);
934 }
935
936 SkBitmap otr_avatar_icon = browser_view_->GetOTRAvatarIcon();
937 int w = otr_avatar_bounds_.width();
938 int h = otr_avatar_bounds_.height();
939 canvas->DrawBitmapInt(otr_avatar_icon, 0,
940 // Bias the rounding to select a region that's lower rather than higher,
941 // as the shadows at the image top mean the apparent center is below the
942 // real center.
943 ((otr_avatar_icon.height() - otr_avatar_bounds_.height()) + 1) / 2, w, h,
944 otr_avatar_bounds_.x(), otr_avatar_bounds_.y(), w, h, false);
945
946 canvas->Restore();
947 }
948
949 void OpaqueBrowserFrameView::PaintRestoredClientEdge(gfx::Canvas* canvas) { 927 void OpaqueBrowserFrameView::PaintRestoredClientEdge(gfx::Canvas* canvas) {
950 ui::ThemeProvider* tp = GetThemeProvider(); 928 ui::ThemeProvider* tp = GetThemeProvider();
951 int client_area_top = frame_->client_view()->y(); 929 int client_area_top = frame_->client_view()->y();
952 int image_top = client_area_top; 930 int image_top = client_area_top;
953 931
954 gfx::Rect client_area_bounds = CalculateClientAreaBounds(width(), height()); 932 gfx::Rect client_area_bounds = CalculateClientAreaBounds(width(), height());
955 SkColor toolbar_color = tp->GetColor(ThemeService::COLOR_TOOLBAR); 933 SkColor toolbar_color = tp->GetColor(ThemeService::COLOR_TOOLBAR);
956 934
957 if (browser_view_->IsToolbarVisible() || 935 if (browser_view_->IsToolbarVisible() ||
958 browser_view_->UseCompactNavigationBar()) { 936 browser_view_->UseCompactNavigationBar()) {
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
1127 // vertical midline rather than below. This compensates for how the icon is 1105 // vertical midline rather than below. This compensates for how the icon is
1128 // already biased downwards (see IconBounds()) and helps prevent descenders 1106 // already biased downwards (see IconBounds()) and helps prevent descenders
1129 // on the title from overlapping the 3D edge at the bottom of the titlebar. 1107 // on the title from overlapping the 3D edge at the bottom of the titlebar.
1130 title_bounds_.SetRect(title_x, 1108 title_bounds_.SetRect(title_x,
1131 icon_bounds.y() + ((icon_bounds.height() - title_height - 1) / 2), 1109 icon_bounds.y() + ((icon_bounds.height() - title_height - 1) / 2),
1132 std::max(0, minimize_button_->x() - kTitleLogoSpacing - title_x), 1110 std::max(0, minimize_button_->x() - kTitleLogoSpacing - title_x),
1133 title_height); 1111 title_height);
1134 } 1112 }
1135 } 1113 }
1136 1114
1137 void OpaqueBrowserFrameView::LayoutOTRAvatar() { 1115 void OpaqueBrowserFrameView::LayoutAvatar() {
1138 SkBitmap otr_avatar_icon = browser_view_->GetOTRAvatarIcon(); 1116 // Even though the avatar is used for both incognito and profiles we always
1139 int otr_bottom, otr_restored_y; 1117 // use the incognito icon to layout the avatar button.
1118 SkBitmap incognito_icon = browser_view_->GetOTRAvatarIcon();
1119
1120 int avatar_bottom, avatar_restored_y;
1140 if (browser_view_->UseVerticalTabs()) { 1121 if (browser_view_->UseVerticalTabs()) {
1141 otr_bottom = NonClientTopBorderHeight(false, false) - kOTRBottomSpacing; 1122 avatar_bottom = NonClientTopBorderHeight(false, false) -
1142 otr_restored_y = kFrameShadowThickness; 1123 kAvatarBottomSpacing;
1124 avatar_restored_y = kFrameShadowThickness;
1143 } else { 1125 } else {
1144 otr_bottom = GetHorizontalTabStripVerticalOffset(false) + 1126 avatar_bottom = GetHorizontalTabStripVerticalOffset(false) +
1145 browser_view_->GetTabStripHeight() - kOTRBottomSpacing; 1127 browser_view_->GetTabStripHeight() - kAvatarBottomSpacing;
1146 otr_restored_y = otr_bottom - otr_avatar_icon.height(); 1128 avatar_restored_y = avatar_bottom - incognito_icon.height();
1147 } 1129 }
1148 int otr_y = frame_->IsMaximized() ? 1130 int avatar_y = frame_->IsMaximized() ?
1149 (NonClientTopBorderHeight(false, true) + kTabstripTopShadowThickness) : 1131 (NonClientTopBorderHeight(false, true) + kTabstripTopShadowThickness) :
1150 otr_restored_y; 1132 avatar_restored_y;
1151 otr_avatar_bounds_.SetRect(NonClientBorderThickness() + kOTRSideSpacing, 1133 avatar_bounds_.SetRect(NonClientBorderThickness() + kAvatarSideSpacing,
1152 otr_y, otr_avatar_icon.width(), 1134 avatar_y, incognito_icon.width(),
1153 browser_view_->ShouldShowOffTheRecordAvatar() ? (otr_bottom - otr_y) : 0); 1135 browser_view_->ShouldShowAvatar() ? (avatar_bottom - avatar_y) : 0);
1154 }
1155 1136
1156 void OpaqueBrowserFrameView::LayoutProfileTag() { 1137 if (avatar_button_.get())
1157 if (!show_profile_button()) 1138 avatar_button_->SetBoundsRect(avatar_bounds_);
1158 return;
1159
1160 string16 profile_name = UTF8ToUTF16(browser_view_->browser()->profile()->
1161 GetPrefs()->GetString(prefs::kGoogleServicesUsername));
1162 if (!profile_name.empty()) {
1163 profile_button_->SetText(UTF16ToWideHack(profile_name));
1164 } else {
1165 profile_button_->SetText(UTF16ToWideHack(l10n_util::GetStringUTF16(
1166 IDS_PROFILES_NOT_SIGNED_IN_MENU)));
1167 }
1168 profile_button_->SetTextShadowColors(ProfileMenuButton::kDarkTextShadow,
1169 ProfileMenuButton::kDarkTextShadow);
1170 profile_button_->ClearMaxTextSize();
1171 profile_button_->SetVisible(true);
1172 int x_tag =
1173 // The x position of minimize button in the frame
1174 minimize_button_->x() -
1175 // - the space between the minimize button and the profile button
1176 ProfileMenuButton::kProfileTagHorizontalSpacing -
1177 // - the width of the profile button
1178 profile_button_->GetPreferredSize().width();
1179 // Adjust for different default font sizes on different Windows platforms.
1180 int y_tag = profile_button_->font().GetHeight() < 14 ? 2 : 0;
1181 int maximized = frame_->IsMaximized();
1182 profile_button_->SetBounds(
1183 x_tag,
1184 maximized ? 0 : y_tag,
1185 profile_button_->GetPreferredSize().width(),
1186 profile_button_->GetPreferredSize().height());
1187
1188 if (!profile_name.empty()) {
1189 profile_tag_->SetVisible(true);
1190 profile_tag_->SetBounds(
1191 x_tag,
1192 maximized ? 0 : kProfileTagYPosition,
1193 profile_button_->GetPreferredSize().width(),
1194 ProfileTagView::kProfileTagHeight);
1195 } else {
1196 profile_tag_->SetVisible(false);
1197 }
1198 } 1139 }
1199 1140
1200 gfx::Rect OpaqueBrowserFrameView::CalculateClientAreaBounds(int width, 1141 gfx::Rect OpaqueBrowserFrameView::CalculateClientAreaBounds(int width,
1201 int height) const { 1142 int height) const {
1202 int top_height = NonClientTopBorderHeight(false, false); 1143 int top_height = NonClientTopBorderHeight(false, false);
1203 int border_thickness = NonClientBorderThickness(); 1144 int border_thickness = NonClientBorderThickness();
1204 return gfx::Rect(border_thickness, top_height, 1145 return gfx::Rect(border_thickness, top_height,
1205 std::max(0, width - (2 * border_thickness)), 1146 std::max(0, width - (2 * border_thickness)),
1206 std::max(0, height - GetReservedHeight() - 1147 std::max(0, height - GetReservedHeight() -
1207 top_height - border_thickness)); 1148 top_height - border_thickness));
1208 } 1149 }
1209 1150
1210 void OpaqueBrowserFrameView::RegisterLoginNotifications() { 1151 void OpaqueBrowserFrameView::RegisterLoginNotifications() {
1211 PrefService* pref_service = browser_view_->browser()->profile()->GetPrefs(); 1152 PrefService* pref_service = browser_view_->browser()->profile()->GetPrefs();
1212 DCHECK(pref_service); 1153 DCHECK(pref_service);
1213 username_pref_.Init(prefs::kGoogleServicesUsername, pref_service, this); 1154 username_pref_.Init(prefs::kGoogleServicesUsername, pref_service, this);
1214 } 1155 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698