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

Side by Side Diff: chrome/browser/ui/views/frame/glass_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: Change profile menu button to avatar button 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/glass_browser_frame_view.h" 5 #include "chrome/browser/ui/views/frame/glass_browser_frame_view.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "chrome/app/chrome_command_ids.h" 9 #include "chrome/app/chrome_command_ids.h"
10 #include "chrome/app/chrome_dll_resource.h" 10 #include "chrome/app/chrome_dll_resource.h"
11 #include "chrome/browser/prefs/pref_service.h" 11 #include "chrome/browser/prefs/pref_service.h"
12 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/themes/theme_service.h" 13 #include "chrome/browser/themes/theme_service.h"
14 #include "chrome/browser/ui/profile_menu_model.h"
15 #include "chrome/browser/ui/views/avatar_menu_button.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/side_tab_strip.h" 17 #include "chrome/browser/ui/views/tabs/side_tab_strip.h"
18 #include "chrome/browser/ui/views/tabs/tab.h" 18 #include "chrome/browser/ui/views/tabs/tab.h"
19 #include "chrome/browser/ui/views/tabs/tab_strip.h" 19 #include "chrome/browser/ui/views/tabs/tab_strip.h"
20 #include "chrome/common/chrome_switches.h" 20 #include "chrome/common/chrome_switches.h"
21 #include "chrome/common/pref_names.h" 21 #include "chrome/common/pref_names.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/generated_resources.h" 24 #include "grit/generated_resources.h"
25 #include "grit/theme_resources.h" 25 #include "grit/theme_resources.h"
26 #include "grit/theme_resources_standard.h" 26 #include "grit/theme_resources_standard.h"
(...skipping 12 matching lines...) Expand all
39 // There are 3 px of client edge drawn inside the outer frame borders. 39 // There are 3 px of client edge drawn inside the outer frame borders.
40 const int kNonClientBorderThickness = 3; 40 const int kNonClientBorderThickness = 3;
41 // Vertical tabs have 4 px border. 41 // Vertical tabs have 4 px border.
42 const int kNonClientVerticalTabStripBorderThickness = 4; 42 const int kNonClientVerticalTabStripBorderThickness = 4;
43 // Besides the frame border, there's another 11 px of empty space atop the 43 // Besides the frame border, there's another 11 px of empty space atop the
44 // window in restored mode, to use to drag the window around. 44 // window in restored mode, to use to drag the window around.
45 const int kNonClientRestoredExtraThickness = 11; 45 const int kNonClientRestoredExtraThickness = 11;
46 // In the window corners, the resize areas don't actually expand bigger, but the 46 // In the window corners, the resize areas don't actually expand bigger, but the
47 // 16 px at the end of the top and bottom edges triggers diagonal resizing. 47 // 16 px at the end of the top and bottom edges triggers diagonal resizing.
48 const int kResizeAreaCornerSize = 16; 48 const int kResizeAreaCornerSize = 16;
49 // The OTR avatar ends 2 px above the bottom of the tabstrip (which, given the 49 // The avatar ends 2 px above the bottom of the tabstrip (which, given the
50 // way the tabstrip draws its bottom edge, will appear like a 1 px gap to the 50 // way the tabstrip draws its bottom edge, will appear like a 1 px gap to the
51 // user). 51 // user).
52 const int kOTRBottomSpacing = 2; 52 const int kAvatarBottomSpacing = 2;
53 // There are 2 px on each side of the OTR avatar (between the frame border and 53 // There are 2 px on each side of the avatar (between the frame border and
54 // it on the left, and between it and the tabstrip on the right). 54 // it on the left, and between it and the tabstrip on the right).
55 const int kOTRSideSpacing = 2; 55 const int kAvatarSideSpacing = 2;
56 // The content left/right images have a shadow built into them. 56 // The content left/right images have a shadow built into them.
57 const int kContentEdgeShadowThickness = 2; 57 const int kContentEdgeShadowThickness = 2;
58 // The top 1 px of the tabstrip is shadow; in maximized mode we push this off 58 // The top 1 px of the tabstrip is shadow; in maximized mode we push this off
59 // the top of the screen so the tabs appear flush against the screen edge. 59 // the top of the screen so the tabs appear flush against the screen edge.
60 const int kTabstripTopShadowThickness = 1; 60 const int kTabstripTopShadowThickness = 1;
61 // In restored mode, the New Tab button isn't at the same height as the caption 61 // In restored mode, the New Tab button isn't at the same height as the caption
62 // buttons, but the space will look cluttered if it actually slides under them, 62 // buttons, but the space will look cluttered if it actually slides under them,
63 // so we stop it when the gap between the two is down to 5 px. 63 // so we stop it when the gap between the two is down to 5 px.
64 const int kNewTabCaptionRestoredSpacing = 5; 64 const int kNewTabCaptionRestoredSpacing = 5;
65 // In maximized mode, where the New Tab button and the caption buttons are at 65 // In maximized mode, where the New Tab button and the caption buttons are at
66 // similar vertical coordinates, we need to reserve a larger, 16 px gap to avoid 66 // similar vertical coordinates, we need to reserve a larger, 16 px gap to avoid
67 // looking too cluttered. 67 // looking too cluttered.
68 const int kNewTabCaptionMaximizedSpacing = 16; 68 const int kNewTabCaptionMaximizedSpacing = 16;
69 // Y position for profile button inside the frame.
70 const int kProfileButtonYPosition = 2;
71 // Y position for profile tag inside the frame.
72 const int kProfileTagYPosition = 1;
73 // Offset y position of profile button and tag by this amount when maximized.
74 const int kProfileElementMaximizedYOffset = 6;
75 } 69 }
76 70
77 /////////////////////////////////////////////////////////////////////////////// 71 ///////////////////////////////////////////////////////////////////////////////
78 // GlassBrowserFrameView, public: 72 // GlassBrowserFrameView, public:
79 73
80 GlassBrowserFrameView::GlassBrowserFrameView(BrowserFrame* frame, 74 GlassBrowserFrameView::GlassBrowserFrameView(BrowserFrame* frame,
81 BrowserView* browser_view) 75 BrowserView* browser_view)
82 : BrowserNonClientFrameView(), 76 : BrowserNonClientFrameView(),
83 frame_(frame), 77 frame_(frame),
84 browser_view_(browser_view), 78 browser_view_(browser_view),
85 throbber_running_(false), 79 throbber_running_(false),
86 throbber_frame_(0) { 80 throbber_frame_(0) {
87 if (browser_view_->ShouldShowWindowIcon()) 81 if (browser_view_->ShouldShowWindowIcon())
88 InitThrobberIcons(); 82 InitThrobberIcons();
89 // If multi-profile is enabled set up profile button and login notifications. 83
84 if (browser_view_->ShouldShowAvatar()) {
85 ui::MenuModel* menu_model = browser_view_->IsOffTheRecord() ?
86 NULL : new ProfileMenuModel;
87 // AvatarMenuButton takes ownership of |menu_model|.
88 avatar_button_.reset(new AvatarMenuButton(std::wstring(), menu_model));
89 AddChildView(avatar_button_.get());
90
91 if (browser_view_->IsOffTheRecord()) {
92 avatar_button_->SetIcon(browser_view_->GetOTRAvatarIcon());
93 } else {
94 // TODO(sail) Get the avatar icon assigned to this profile.
95 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
96 avatar_button_->SetIcon(*rb.GetBitmapNamed(IDR_PROFILE_AVATAR_1));
97 // TODO(sail) Also need to call SetHoverIcon() and SetPushedIcon().
98 }
99 }
100
101 // If multi-profile is enabled set up login notifications.
90 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess(); 102 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
91 if (browser_command_line.HasSwitch(switches::kMultiProfiles) && 103 if (browser_command_line.HasSwitch(switches::kMultiProfiles) &&
92 !browser_view->ShouldShowOffTheRecordAvatar()) { 104 !browser_view->IsOffTheRecord()) {
93 RegisterLoginNotifications(); 105 RegisterLoginNotifications();
94 profile_button_.reset(new ProfileMenuButton(std::wstring(),
95 browser_view_->browser()->profile()));
96 profile_button_->SetVisible(false);
97 profile_tag_.reset(new ProfileTagView(frame_, profile_button_.get()));
98 profile_tag_->SetVisible(false);
99 AddChildView(profile_tag_.get());
100 AddChildView(profile_button_.get());
101 } 106 }
102 } 107 }
103 108
104 GlassBrowserFrameView::~GlassBrowserFrameView() { 109 GlassBrowserFrameView::~GlassBrowserFrameView() {
105 } 110 }
106 111
107 /////////////////////////////////////////////////////////////////////////////// 112 ///////////////////////////////////////////////////////////////////////////////
108 // GlassBrowserFrameView, BrowserNonClientFrameView implementation: 113 // GlassBrowserFrameView, BrowserNonClientFrameView implementation:
109 114
110 gfx::Rect GlassBrowserFrameView::GetBoundsForTabStrip( 115 gfx::Rect GlassBrowserFrameView::GetBoundsForTabStrip(
111 views::View* tabstrip) const { 116 views::View* tabstrip) const {
112 if (browser_view_->UseVerticalTabs()) { 117 if (browser_view_->UseVerticalTabs()) {
113 gfx::Size ps = tabstrip->GetPreferredSize(); 118 gfx::Size ps = tabstrip->GetPreferredSize();
114 return gfx::Rect(NonClientBorderThickness(), 119 return gfx::Rect(NonClientBorderThickness(),
115 NonClientTopBorderHeight(false, false), ps.width(), 120 NonClientTopBorderHeight(false, false), ps.width(),
116 browser_view_->height()); 121 browser_view_->height());
117 } 122 }
118 int minimize_button_offset = 123 int minimize_button_offset =
119 std::min(frame_->GetMinimizeButtonOffset(), width()); 124 std::min(frame_->GetMinimizeButtonOffset(), width());
120 int tabstrip_x = browser_view_->ShouldShowOffTheRecordAvatar() ? 125 int tabstrip_x = browser_view_->ShouldShowAvatar() ?
121 (otr_avatar_bounds_.right() + kOTRSideSpacing) : 126 (avatar_bounds_.right() + kAvatarSideSpacing) :
122 NonClientBorderThickness(); 127 NonClientBorderThickness();
123 // In RTL languages, we have moved an avatar icon left by the size of window 128 // In RTL languages, we have moved an avatar icon left by the size of window
124 // controls to prevent it from being rendered over them. So, we use its x 129 // controls to prevent it from being rendered over them. So, we use its x
125 // position to move this tab strip left when maximized. Also, we can render 130 // position to move this tab strip left when maximized. Also, we can render
126 // a tab strip until the left end of this window without considering the size 131 // a tab strip until the left end of this window without considering the size
127 // of window controls in RTL languages. 132 // of window controls in RTL languages.
128 if (base::i18n::IsRTL()) { 133 if (base::i18n::IsRTL()) {
129 if (!browser_view_->ShouldShowOffTheRecordAvatar() && frame_->IsMaximized()) 134 if (!browser_view_->ShouldShowAvatar() && frame_->IsMaximized())
130 tabstrip_x += otr_avatar_bounds_.x(); 135 tabstrip_x += avatar_bounds_.x();
131 minimize_button_offset = width(); 136 minimize_button_offset = width();
132 } 137 }
133 int maximized_spacing = 138 int maximized_spacing = kNewTabCaptionMaximizedSpacing;
134 kNewTabCaptionMaximizedSpacing +
135 (show_profile_button() && profile_button_->IsVisible() ?
136 profile_button_->GetPreferredSize().width() +
137 ProfileMenuButton::kProfileTagHorizontalSpacing : 0);
138 int tabstrip_width = minimize_button_offset - tabstrip_x - 139 int tabstrip_width = minimize_button_offset - tabstrip_x -
139 (frame_->IsMaximized() ? 140 (frame_->IsMaximized() ?
140 maximized_spacing : kNewTabCaptionRestoredSpacing); 141 maximized_spacing : kNewTabCaptionRestoredSpacing);
141 return gfx::Rect(tabstrip_x, GetHorizontalTabStripVerticalOffset(false), 142 return gfx::Rect(tabstrip_x, GetHorizontalTabStripVerticalOffset(false),
142 std::max(0, tabstrip_width), 143 std::max(0, tabstrip_width),
143 tabstrip->GetPreferredSize().height()); 144 tabstrip->GetPreferredSize().height());
144 } 145 }
145 146
146 int GlassBrowserFrameView::GetHorizontalTabStripVerticalOffset( 147 int GlassBrowserFrameView::GetHorizontalTabStripVerticalOffset(
147 bool restored) const { 148 bool restored) const {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 } 191 }
191 192
192 int GlassBrowserFrameView::NonClientHitTest(const gfx::Point& point) { 193 int GlassBrowserFrameView::NonClientHitTest(const gfx::Point& point) {
193 // If the browser isn't in normal mode, we haven't customized the frame, so 194 // If the browser isn't in normal mode, we haven't customized the frame, so
194 // Windows can figure this out. If the point isn't within our bounds, then 195 // Windows can figure this out. If the point isn't within our bounds, then
195 // it's in the native portion of the frame, so again Windows can figure it 196 // it's in the native portion of the frame, so again Windows can figure it
196 // out. 197 // out.
197 if (!browser_view_->IsBrowserTypeNormal() || !bounds().Contains(point)) 198 if (!browser_view_->IsBrowserTypeNormal() || !bounds().Contains(point))
198 return HTNOWHERE; 199 return HTNOWHERE;
199 200
201 // See if the point is within the avatar menu button.
202 if (avatar_button_.get() &&
203 avatar_button_->GetMirroredBounds().Contains(point))
204 return HTCLIENT;
205
200 int frame_component = frame_->client_view()->NonClientHitTest(point); 206 int frame_component = frame_->client_view()->NonClientHitTest(point);
201 207
202 // See if we're in the sysmenu region. We still have to check the tabstrip 208 // See if we're in the sysmenu region. We still have to check the tabstrip
203 // first so that clicks in a tab don't get treated as sysmenu clicks. 209 // first so that clicks in a tab don't get treated as sysmenu clicks.
204 int nonclient_border_thickness = NonClientBorderThickness(); 210 int nonclient_border_thickness = NonClientBorderThickness();
205 if (gfx::Rect(nonclient_border_thickness, GetSystemMetrics(SM_CXSIZEFRAME), 211 if (gfx::Rect(nonclient_border_thickness, GetSystemMetrics(SM_CXSIZEFRAME),
206 GetSystemMetrics(SM_CXSMICON), 212 GetSystemMetrics(SM_CXSMICON),
207 GetSystemMetrics(SM_CYSMICON)).Contains(point)) 213 GetSystemMetrics(SM_CYSMICON)).Contains(point))
208 return (frame_component == HTCLIENT) ? HTCLIENT : HTSYSMENU; 214 return (frame_component == HTCLIENT) ? HTCLIENT : HTSYSMENU;
209 215
210 if (frame_component != HTNOWHERE) 216 if (frame_component != HTNOWHERE)
211 return frame_component; 217 return frame_component;
212 218
213 // See if the point is within the profile menu button.
214 if (show_profile_button() && profile_button_->IsVisible() &&
215 profile_button_->GetMirroredBounds().Contains(point))
216 return HTCLIENT;
217
218 int frame_border_thickness = FrameBorderThickness(); 219 int frame_border_thickness = FrameBorderThickness();
219 int window_component = GetHTComponentForFrame(point, frame_border_thickness, 220 int window_component = GetHTComponentForFrame(point, frame_border_thickness,
220 nonclient_border_thickness, frame_border_thickness, 221 nonclient_border_thickness, frame_border_thickness,
221 kResizeAreaCornerSize - frame_border_thickness, 222 kResizeAreaCornerSize - frame_border_thickness,
222 frame_->window_delegate()->CanResize()); 223 frame_->window_delegate()->CanResize());
223 // Fall back to the caption if no other component matches. 224 // Fall back to the caption if no other component matches.
224 return (window_component == HTNOWHERE) ? HTCAPTION : window_component; 225 return (window_component == HTNOWHERE) ? HTCAPTION : window_component;
225 } 226 }
226 227
227 /////////////////////////////////////////////////////////////////////////////// 228 ///////////////////////////////////////////////////////////////////////////////
228 // GlassBrowserFrameView, views::View overrides: 229 // GlassBrowserFrameView, views::View overrides:
229 230
230 void GlassBrowserFrameView::OnPaint(gfx::Canvas* canvas) { 231 void GlassBrowserFrameView::OnPaint(gfx::Canvas* canvas) {
231 if (!browser_view_->IsTabStripVisible()) 232 if (!browser_view_->IsTabStripVisible())
232 return; // Nothing is visible, so don't bother to paint. 233 return; // Nothing is visible, so don't bother to paint.
233 234
234 PaintToolbarBackground(canvas); 235 PaintToolbarBackground(canvas);
235 if (browser_view_->ShouldShowOffTheRecordAvatar())
236 PaintOTRAvatar(canvas);
237 if (!frame_->IsMaximized()) 236 if (!frame_->IsMaximized())
238 PaintRestoredClientEdge(canvas); 237 PaintRestoredClientEdge(canvas);
239 } 238 }
240 239
241 void GlassBrowserFrameView::Layout() { 240 void GlassBrowserFrameView::Layout() {
242 LayoutOTRAvatar(); 241 LayoutAvatar();
243 LayoutClientView(); 242 LayoutClientView();
244 LayoutProfileTag();
245 } 243 }
246 244
247 bool GlassBrowserFrameView::HitTest(const gfx::Point& l) const { 245 bool GlassBrowserFrameView::HitTest(const gfx::Point& l) const {
248 // The ProfileMenuButton intrudes into the client area when the window is 246 return (avatar_button_.get() &&
249 // maximized. 247 avatar_button_->GetMirroredBounds().Contains(l)) ||
250 return (frame_->IsMaximized() && show_profile_button() &&
251 profile_button_->IsVisible() &&
252 profile_button_->GetMirroredBounds().Contains(l)) ||
253 !frame_->client_view()->bounds().Contains(l); 248 !frame_->client_view()->bounds().Contains(l);
254 } 249 }
255 250
256 /////////////////////////////////////////////////////////////////////////////// 251 ///////////////////////////////////////////////////////////////////////////////
257 // GlassBrowserFrameView, private: 252 // GlassBrowserFrameView, private:
258 253
259 int GlassBrowserFrameView::FrameBorderThickness() const { 254 int GlassBrowserFrameView::FrameBorderThickness() const {
260 return (frame_->IsMaximized() || frame_->IsFullscreen()) ? 255 return (frame_->IsMaximized() || frame_->IsFullscreen()) ?
261 0 : GetSystemMetrics(SM_CXSIZEFRAME); 256 0 : GetSystemMetrics(SM_CXSIZEFRAME);
262 } 257 }
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 canvas->DrawBitmapInt(*tp->GetBitmapNamed(IDR_CONTENT_TOP_RIGHT_CORNER), 370 canvas->DrawBitmapInt(*tp->GetBitmapNamed(IDR_CONTENT_TOP_RIGHT_CORNER),
376 right_x, y); 371 right_x, y);
377 } 372 }
378 373
379 // Draw the content/toolbar separator. 374 // Draw the content/toolbar separator.
380 canvas->FillRectInt(ResourceBundle::toolbar_separator_color, 375 canvas->FillRectInt(ResourceBundle::toolbar_separator_color,
381 x + kClientEdgeThickness, toolbar_bounds.bottom() - kClientEdgeThickness, 376 x + kClientEdgeThickness, toolbar_bounds.bottom() - kClientEdgeThickness,
382 w - (2 * kClientEdgeThickness), kClientEdgeThickness); 377 w - (2 * kClientEdgeThickness), kClientEdgeThickness);
383 } 378 }
384 379
385 void GlassBrowserFrameView::PaintOTRAvatar(gfx::Canvas* canvas) {
386 // In RTL mode, the avatar icon should be looking the opposite direction.
387 canvas->Save();
388 if (base::i18n::IsRTL()) {
389 canvas->TranslateInt(width(), 0);
390 canvas->ScaleInt(-1, 1);
391 }
392
393 SkBitmap otr_avatar_icon = browser_view_->GetOTRAvatarIcon();
394 int w = otr_avatar_bounds_.width();
395 int h = otr_avatar_bounds_.height();
396 canvas->DrawBitmapInt(otr_avatar_icon, 0,
397 // Bias the rounding to select a region that's lower rather than higher,
398 // as the shadows at the image top mean the apparent center is below the
399 // real center.
400 ((otr_avatar_icon.height() - otr_avatar_bounds_.height()) + 1) / 2, w, h,
401 otr_avatar_bounds_.x(), otr_avatar_bounds_.y(), w, h, false);
402
403 canvas->Restore();
404 }
405
406 void GlassBrowserFrameView::PaintRestoredClientEdge(gfx::Canvas* canvas) { 380 void GlassBrowserFrameView::PaintRestoredClientEdge(gfx::Canvas* canvas) {
407 ui::ThemeProvider* tp = GetThemeProvider(); 381 ui::ThemeProvider* tp = GetThemeProvider();
408 gfx::Rect client_area_bounds = CalculateClientAreaBounds(width(), height()); 382 gfx::Rect client_area_bounds = CalculateClientAreaBounds(width(), height());
409 383
410 // The client edges start below the toolbar upper corner images regardless 384 // The client edges start below the toolbar upper corner images regardless
411 // of how tall the toolbar itself is. 385 // of how tall the toolbar itself is.
412 int client_area_top = browser_view_->UseVerticalTabs() ? 386 int client_area_top = browser_view_->UseVerticalTabs() ?
413 client_area_bounds.y() : 387 client_area_bounds.y() :
414 (frame_->client_view()->y() + 388 (frame_->client_view()->y() +
415 browser_view_->GetToolbarBounds().y() + 389 browser_view_->GetToolbarBounds().y() +
(...skipping 30 matching lines...) Expand all
446 client_area_bounds.x() - kClientEdgeThickness, client_area_top, 420 client_area_bounds.x() - kClientEdgeThickness, client_area_top,
447 kClientEdgeThickness, 421 kClientEdgeThickness,
448 client_area_bottom + kClientEdgeThickness - client_area_top); 422 client_area_bottom + kClientEdgeThickness - client_area_top);
449 canvas->FillRectInt(toolbar_color, client_area_bounds.x(), client_area_bottom, 423 canvas->FillRectInt(toolbar_color, client_area_bounds.x(), client_area_bottom,
450 client_area_bounds.width(), kClientEdgeThickness); 424 client_area_bounds.width(), kClientEdgeThickness);
451 canvas->FillRectInt(toolbar_color, client_area_bounds.right(), 425 canvas->FillRectInt(toolbar_color, client_area_bounds.right(),
452 client_area_top, kClientEdgeThickness, 426 client_area_top, kClientEdgeThickness,
453 client_area_bottom + kClientEdgeThickness - client_area_top); 427 client_area_bottom + kClientEdgeThickness - client_area_top);
454 } 428 }
455 429
456 void GlassBrowserFrameView::LayoutOTRAvatar() { 430 void GlassBrowserFrameView::LayoutAvatar() {
457 int otr_x = NonClientBorderThickness() + kOTRSideSpacing; 431 int avatar_x = NonClientBorderThickness() + kAvatarSideSpacing;
458 // Move this avatar icon by the size of window controls to prevent it from 432 // Move this avatar icon by the size of window controls to prevent it from
459 // being rendered over them in RTL languages. This code also needs to adjust 433 // being rendered over them in RTL languages. This code also needs to adjust
460 // the width of a tab strip to avoid decreasing this size twice. (See the 434 // the width of a tab strip to avoid decreasing this size twice. (See the
461 // comment in GetBoundsForTabStrip().) 435 // comment in GetBoundsForTabStrip().)
462 if (base::i18n::IsRTL()) 436 if (base::i18n::IsRTL())
463 otr_x += width() - frame_->GetMinimizeButtonOffset(); 437 avatar_x += width() - frame_->GetMinimizeButtonOffset();
464 438
465 SkBitmap otr_avatar_icon = browser_view_->GetOTRAvatarIcon(); 439 gfx::Size preferred_size = AvatarMenuButton::GetPreferredAvatarSize();
466 int otr_bottom, otr_restored_y; 440
441 int avatar_bottom, avatar_restored_y;
467 if (browser_view_->UseVerticalTabs()) { 442 if (browser_view_->UseVerticalTabs()) {
468 otr_bottom = NonClientTopBorderHeight(false, false) - kOTRBottomSpacing; 443 avatar_bottom = NonClientTopBorderHeight(false, false) -
469 otr_restored_y = kFrameShadowThickness; 444 kAvatarBottomSpacing;
445 avatar_restored_y = kFrameShadowThickness;
470 } else { 446 } else {
471 otr_bottom = GetHorizontalTabStripVerticalOffset(false) + 447 avatar_bottom = GetHorizontalTabStripVerticalOffset(false) +
472 browser_view_->GetTabStripHeight() - kOTRBottomSpacing; 448 browser_view_->GetTabStripHeight() - kAvatarBottomSpacing;
473 otr_restored_y = otr_bottom - otr_avatar_icon.height(); 449 avatar_restored_y = avatar_bottom - preferred_size.height();
474 } 450 }
475 int otr_y = frame_->IsMaximized() ? 451 int avatar_y = frame_->IsMaximized() ?
476 (NonClientTopBorderHeight(false, true) + kTabstripTopShadowThickness) : 452 (NonClientTopBorderHeight(false, true) + kTabstripTopShadowThickness) :
477 otr_restored_y; 453 avatar_restored_y;
478 otr_avatar_bounds_.SetRect(otr_x, otr_y, otr_avatar_icon.width(), 454 avatar_bounds_.SetRect(avatar_x, avatar_y, preferred_size.width(),
479 browser_view_->ShouldShowOffTheRecordAvatar() ? (otr_bottom - otr_y) : 0); 455 browser_view_->ShouldShowAvatar() ? (avatar_bottom - avatar_y) : 0);
456
457 if (avatar_button_.get())
458 avatar_button_->SetBoundsRect(avatar_bounds_);
480 } 459 }
481 460
482 void GlassBrowserFrameView::LayoutClientView() { 461 void GlassBrowserFrameView::LayoutClientView() {
483 client_view_bounds_ = CalculateClientAreaBounds(width(), height()); 462 client_view_bounds_ = CalculateClientAreaBounds(width(), height());
484 } 463 }
485 464
486 void GlassBrowserFrameView::LayoutProfileTag() {
487 if (!show_profile_button())
488 return;
489
490 string16 profile_name = UTF8ToUTF16(browser_view_->browser()->profile()->
491 GetPrefs()->GetString(prefs::kGoogleServicesUsername));
492 if (!profile_name.empty()) {
493 profile_button_->SetText(profile_name);
494 profile_button_->SetTextShadowColors(
495 ProfileMenuButton::kDefaultActiveTextShadow,
496 ProfileMenuButton::kDefaultInactiveTextShadow);
497 } else {
498 profile_button_->SetText(l10n_util::GetStringUTF16(
499 IDS_PROFILES_NOT_SIGNED_IN_MENU));
500 profile_button_->SetTextShadowColors(
501 ProfileMenuButton::kDarkTextShadow,
502 ProfileMenuButton::kDefaultInactiveTextShadow);
503 }
504
505 profile_button_->ClearMaxTextSize();
506 profile_button_->SetVisible(true);
507 int x_tag =
508 // The x position of minimize button in the frame
509 frame_->GetMinimizeButtonOffset() -
510 // - the space between the minimize button and the profile button
511 ProfileMenuButton::kProfileTagHorizontalSpacing -
512 // - the width of the profile button
513 profile_button_->GetPreferredSize().width();
514 int y_maximized_offset = frame_->IsMaximized() ?
515 kProfileElementMaximizedYOffset : 0;
516 profile_button_->SetBounds(
517 x_tag,
518 kProfileButtonYPosition + y_maximized_offset,
519 profile_button_->GetPreferredSize().width(),
520 profile_button_->GetPreferredSize().height());
521
522 profile_tag_->SetVisible(true);
523 profile_tag_->set_is_signed_in(!profile_name.empty());
524 profile_tag_->SetBounds(
525 x_tag,
526 kProfileTagYPosition + y_maximized_offset,
527 profile_button_->GetPreferredSize().width(),
528 ProfileTagView::kProfileTagHeight);
529 }
530
531 gfx::Rect GlassBrowserFrameView::CalculateClientAreaBounds(int width, 465 gfx::Rect GlassBrowserFrameView::CalculateClientAreaBounds(int width,
532 int height) const { 466 int height) const {
533 if (!browser_view_->IsTabStripVisible()) 467 if (!browser_view_->IsTabStripVisible())
534 return gfx::Rect(0, 0, this->width(), this->height()); 468 return gfx::Rect(0, 0, this->width(), this->height());
535 469
536 int top_height = NonClientTopBorderHeight(false, false); 470 int top_height = NonClientTopBorderHeight(false, false);
537 int border_thickness = NonClientBorderThickness(); 471 int border_thickness = NonClientBorderThickness();
538 return gfx::Rect(border_thickness, top_height, 472 return gfx::Rect(border_thickness, top_height,
539 std::max(0, width - (2 * border_thickness)), 473 std::max(0, width - (2 * border_thickness)),
540 std::max(0, height - top_height - border_thickness)); 474 std::max(0, height - top_height - border_thickness));
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
585 static_cast<WPARAM>(ICON_SMALL), 519 static_cast<WPARAM>(ICON_SMALL),
586 reinterpret_cast<LPARAM>(throbber_icons_[throbber_frame_])); 520 reinterpret_cast<LPARAM>(throbber_icons_[throbber_frame_]));
587 } 521 }
588 522
589 void GlassBrowserFrameView::Observe(NotificationType type, 523 void GlassBrowserFrameView::Observe(NotificationType type,
590 const NotificationSource& source, 524 const NotificationSource& source,
591 const NotificationDetails& details) { 525 const NotificationDetails& details) {
592 DCHECK_EQ(NotificationType::PREF_CHANGED, type.value); 526 DCHECK_EQ(NotificationType::PREF_CHANGED, type.value);
593 std::string* name = Details<std::string>(details).ptr(); 527 std::string* name = Details<std::string>(details).ptr();
594 if (prefs::kGoogleServicesUsername == *name) 528 if (prefs::kGoogleServicesUsername == *name)
595 LayoutProfileTag(); 529 LayoutAvatar();
596 } 530 }
597 531
598 void GlassBrowserFrameView::RegisterLoginNotifications() { 532 void GlassBrowserFrameView::RegisterLoginNotifications() {
599 PrefService* pref_service = browser_view_->browser()->profile()->GetPrefs(); 533 PrefService* pref_service = browser_view_->browser()->profile()->GetPrefs();
600 DCHECK(pref_service); 534 DCHECK(pref_service);
601 username_pref_.Init(prefs::kGoogleServicesUsername, pref_service, this); 535 username_pref_.Init(prefs::kGoogleServicesUsername, pref_service, this);
602 } 536 }
603 537
604 // static 538 // static
605 void GlassBrowserFrameView::InitThrobberIcons() { 539 void GlassBrowserFrameView::InitThrobberIcons() {
606 static bool initialized = false; 540 static bool initialized = false;
607 if (!initialized) { 541 if (!initialized) {
608 ResourceBundle &rb = ResourceBundle::GetSharedInstance(); 542 ResourceBundle &rb = ResourceBundle::GetSharedInstance();
609 for (int i = 0; i < kThrobberIconCount; ++i) { 543 for (int i = 0; i < kThrobberIconCount; ++i) {
610 throbber_icons_[i] = rb.LoadThemeIcon(IDI_THROBBER_01 + i); 544 throbber_icons_[i] = rb.LoadThemeIcon(IDI_THROBBER_01 + i);
611 DCHECK(throbber_icons_[i]); 545 DCHECK(throbber_icons_[i]);
612 } 546 }
613 initialized = true; 547 initialized = true;
614 } 548 }
615 } 549 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/frame/glass_browser_frame_view.h ('k') | chrome/browser/ui/views/frame/opaque_browser_frame_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698