OLD | NEW |
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 Loading... |
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 Loading... |
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 // AvatarMenuButton takes ownership of |menu_model|. |
| 205 avatar_button_.reset(new AvatarMenuButton(std::wstring(), menu_model)); |
| 206 AddChildView(avatar_button_.get()); |
| 207 |
| 208 if (browser_view_->IsOffTheRecord()) { |
| 209 avatar_button_->SetIcon(browser_view_->GetOTRAvatarIcon()); |
| 210 } else { |
| 211 // TODO(sail) Get the avatar icon assigned to this profile. |
| 212 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 213 avatar_button_->SetIcon(*rb.GetBitmapNamed(IDR_PROFILE_AVATAR_1)); |
| 214 // TODO(sail) Also need to call SetHoverIcon() and SetPushedIcon(). |
| 215 } |
| 216 } |
| 217 |
| 218 // If multi-profile is enabled set up login notifications. |
204 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess(); | 219 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess(); |
205 if (browser_command_line.HasSwitch(switches::kMultiProfiles) && | 220 if (browser_command_line.HasSwitch(switches::kMultiProfiles) && |
206 !browser_view_->ShouldShowOffTheRecordAvatar()) { | 221 !browser_view->IsOffTheRecord()) { |
207 RegisterLoginNotifications(); | 222 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 } | 223 } |
216 } | 224 } |
217 | 225 |
218 OpaqueBrowserFrameView::~OpaqueBrowserFrameView() { | 226 OpaqueBrowserFrameView::~OpaqueBrowserFrameView() { |
219 } | 227 } |
220 | 228 |
221 /////////////////////////////////////////////////////////////////////////////// | 229 /////////////////////////////////////////////////////////////////////////////// |
222 // OpaqueBrowserFrameView, protected: | 230 // OpaqueBrowserFrameView, protected: |
223 | 231 |
224 int OpaqueBrowserFrameView::GetReservedHeight() const { | 232 int OpaqueBrowserFrameView::GetReservedHeight() const { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 if (!tabstrip) | 270 if (!tabstrip) |
263 return gfx::Rect(); | 271 return gfx::Rect(); |
264 | 272 |
265 if (browser_view_->UseVerticalTabs()) { | 273 if (browser_view_->UseVerticalTabs()) { |
266 gfx::Size ps = tabstrip->GetPreferredSize(); | 274 gfx::Size ps = tabstrip->GetPreferredSize(); |
267 return gfx::Rect(NonClientBorderThickness(), | 275 return gfx::Rect(NonClientBorderThickness(), |
268 NonClientTopBorderHeight(false, false), ps.width(), | 276 NonClientTopBorderHeight(false, false), ps.width(), |
269 browser_view_->height()); | 277 browser_view_->height()); |
270 } | 278 } |
271 | 279 |
272 int tabstrip_x = browser_view_->ShouldShowOffTheRecordAvatar() ? | 280 int tabstrip_x = browser_view_->ShouldShowAvatar() ? |
273 (otr_avatar_bounds_.right() + kOTRSideSpacing) : | 281 (avatar_bounds_.right() + kAvatarSideSpacing) : |
274 NonClientBorderThickness() + kTabStripIndent; | 282 NonClientBorderThickness() + kTabStripIndent; |
275 | 283 |
276 int maximized_spacing = | 284 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 - | 285 int tabstrip_width = minimize_button_->x() - tabstrip_x - |
282 (frame_->IsMaximized() ? | 286 (frame_->IsMaximized() ? |
283 maximized_spacing : kNewTabCaptionRestoredSpacing); | 287 maximized_spacing : kNewTabCaptionRestoredSpacing); |
284 return gfx::Rect(tabstrip_x, GetHorizontalTabStripVerticalOffset(false), | 288 return gfx::Rect(tabstrip_x, GetHorizontalTabStripVerticalOffset(false), |
285 std::max(0, tabstrip_width), tabstrip->GetPreferredSize().height()); | 289 std::max(0, tabstrip_width), tabstrip->GetPreferredSize().height()); |
286 } | 290 } |
287 | 291 |
288 int OpaqueBrowserFrameView::GetHorizontalTabStripVerticalOffset( | 292 int OpaqueBrowserFrameView::GetHorizontalTabStripVerticalOffset( |
289 bool restored) const { | 293 bool restored) const { |
290 return NonClientTopBorderHeight(restored, true) + ((!restored && | 294 return NonClientTopBorderHeight(restored, true) + ((!restored && |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 return gfx::Rect(std::max(0, client_bounds.x() - border_thickness), | 337 return gfx::Rect(std::max(0, client_bounds.x() - border_thickness), |
334 std::max(0, client_bounds.y() - top_height), | 338 std::max(0, client_bounds.y() - top_height), |
335 client_bounds.width() + (2 * border_thickness), | 339 client_bounds.width() + (2 * border_thickness), |
336 client_bounds.height() + top_height + border_thickness); | 340 client_bounds.height() + top_height + border_thickness); |
337 } | 341 } |
338 | 342 |
339 int OpaqueBrowserFrameView::NonClientHitTest(const gfx::Point& point) { | 343 int OpaqueBrowserFrameView::NonClientHitTest(const gfx::Point& point) { |
340 if (!bounds().Contains(point)) | 344 if (!bounds().Contains(point)) |
341 return HTNOWHERE; | 345 return HTNOWHERE; |
342 | 346 |
343 int frame_component = | 347 // See if the point is within the avatar menu button. |
344 frame_->client_view()->NonClientHitTest(point); | 348 if (avatar_button_.get() && |
| 349 avatar_button_->GetMirroredBounds().Contains(point)) |
| 350 return HTCLIENT; |
| 351 |
| 352 int frame_component = frame_->client_view()->NonClientHitTest(point); |
345 | 353 |
346 // See if we're in the sysmenu region. We still have to check the tabstrip | 354 // 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. | 355 // first so that clicks in a tab don't get treated as sysmenu clicks. |
348 gfx::Rect sysmenu_rect(IconBounds()); | 356 gfx::Rect sysmenu_rect(IconBounds()); |
349 // In maximized mode we extend the rect to the screen corner to take advantage | 357 // In maximized mode we extend the rect to the screen corner to take advantage |
350 // of Fitts' Law. | 358 // of Fitts' Law. |
351 if (frame_->IsMaximized()) | 359 if (frame_->IsMaximized()) |
352 sysmenu_rect.SetRect(0, 0, sysmenu_rect.right(), sysmenu_rect.bottom()); | 360 sysmenu_rect.SetRect(0, 0, sysmenu_rect.right(), sysmenu_rect.bottom()); |
353 sysmenu_rect.set_x(GetMirroredXForRect(sysmenu_rect)); | 361 sysmenu_rect.set_x(GetMirroredXForRect(sysmenu_rect)); |
354 if (sysmenu_rect.Contains(point)) | 362 if (sysmenu_rect.Contains(point)) |
355 return (frame_component == HTCLIENT) ? HTCLIENT : HTSYSMENU; | 363 return (frame_component == HTCLIENT) ? HTCLIENT : HTSYSMENU; |
356 | 364 |
357 if (frame_component != HTNOWHERE) | 365 if (frame_component != HTNOWHERE) |
358 return frame_component; | 366 return frame_component; |
359 | 367 |
360 // Then see if the point is within any of the window controls. | 368 // Then see if the point is within any of the window controls. |
361 if (close_button_->IsVisible() && | 369 if (close_button_->IsVisible() && |
362 close_button_->GetMirroredBounds().Contains(point)) | 370 close_button_->GetMirroredBounds().Contains(point)) |
363 return HTCLOSE; | 371 return HTCLOSE; |
364 if (restore_button_->IsVisible() && | 372 if (restore_button_->IsVisible() && |
365 restore_button_->GetMirroredBounds().Contains(point)) | 373 restore_button_->GetMirroredBounds().Contains(point)) |
366 return HTMAXBUTTON; | 374 return HTMAXBUTTON; |
367 if (maximize_button_->IsVisible() && | 375 if (maximize_button_->IsVisible() && |
368 maximize_button_->GetMirroredBounds().Contains(point)) | 376 maximize_button_->GetMirroredBounds().Contains(point)) |
369 return HTMAXBUTTON; | 377 return HTMAXBUTTON; |
370 if (minimize_button_->IsVisible() && | 378 if (minimize_button_->IsVisible() && |
371 minimize_button_->GetMirroredBounds().Contains(point)) | 379 minimize_button_->GetMirroredBounds().Contains(point)) |
372 return HTMINBUTTON; | 380 return HTMINBUTTON; |
373 | 381 |
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(); | 382 views::WindowDelegate* delegate = frame_->window_delegate(); |
380 if (!delegate) { | 383 if (!delegate) { |
381 LOG(WARNING) << "delegate is NULL, returning safe default."; | 384 LOG(WARNING) << "delegate is NULL, returning safe default."; |
382 return HTCAPTION; | 385 return HTCAPTION; |
383 } | 386 } |
384 int window_component = GetHTComponentForFrame(point, TopResizeHeight(), | 387 int window_component = GetHTComponentForFrame(point, TopResizeHeight(), |
385 NonClientBorderThickness(), kResizeAreaCornerSize, kResizeAreaCornerSize, | 388 NonClientBorderThickness(), kResizeAreaCornerSize, kResizeAreaCornerSize, |
386 delegate->CanResize()); | 389 delegate->CanResize()); |
387 // Fall back to the caption if no other component matches. | 390 // Fall back to the caption if no other component matches. |
388 return (window_component == HTNOWHERE) ? HTCAPTION : window_component; | 391 return (window_component == HTNOWHERE) ? HTCAPTION : window_component; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
421 return; // Nothing is visible, so don't bother to paint. | 424 return; // Nothing is visible, so don't bother to paint. |
422 | 425 |
423 if (frame_->IsMaximized()) | 426 if (frame_->IsMaximized()) |
424 PaintMaximizedFrameBorder(canvas); | 427 PaintMaximizedFrameBorder(canvas); |
425 else | 428 else |
426 PaintRestoredFrameBorder(canvas); | 429 PaintRestoredFrameBorder(canvas); |
427 PaintTitleBar(canvas); | 430 PaintTitleBar(canvas); |
428 if (browser_view_->IsToolbarVisible() || | 431 if (browser_view_->IsToolbarVisible() || |
429 browser_view_->UseCompactNavigationBar()) | 432 browser_view_->UseCompactNavigationBar()) |
430 PaintToolbarBackground(canvas); | 433 PaintToolbarBackground(canvas); |
431 if (browser_view_->ShouldShowOffTheRecordAvatar()) | |
432 PaintOTRAvatar(canvas); | |
433 if (!frame_->IsMaximized()) | 434 if (!frame_->IsMaximized()) |
434 PaintRestoredClientEdge(canvas); | 435 PaintRestoredClientEdge(canvas); |
435 } | 436 } |
436 | 437 |
437 void OpaqueBrowserFrameView::Layout() { | 438 void OpaqueBrowserFrameView::Layout() { |
438 LayoutWindowControls(); | 439 LayoutWindowControls(); |
439 LayoutTitleBar(); | 440 LayoutTitleBar(); |
440 LayoutOTRAvatar(); | 441 LayoutAvatar(); |
441 LayoutProfileTag(); | |
442 client_view_bounds_ = CalculateClientAreaBounds(width(), height()); | 442 client_view_bounds_ = CalculateClientAreaBounds(width(), height()); |
443 } | 443 } |
444 | 444 |
445 bool OpaqueBrowserFrameView::HitTest(const gfx::Point& l) const { | 445 bool OpaqueBrowserFrameView::HitTest(const gfx::Point& l) const { |
446 // If the point is outside the bounds of the client area, claim it. | 446 // If the point is outside the bounds of the client area, claim it. |
447 bool in_nonclient = NonClientFrameView::HitTest(l); | 447 bool in_nonclient = NonClientFrameView::HitTest(l); |
448 if (in_nonclient) | 448 if (in_nonclient) |
449 return in_nonclient; | 449 return in_nonclient; |
450 | 450 |
451 // Otherwise claim it only if it's in a non-tab portion of the tabstrip. | 451 // 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 Loading... |
517 | 517 |
518 /////////////////////////////////////////////////////////////////////////////// | 518 /////////////////////////////////////////////////////////////////////////////// |
519 // OpaqueBrowserFrameView, protected: | 519 // OpaqueBrowserFrameView, protected: |
520 | 520 |
521 void OpaqueBrowserFrameView::Observe(NotificationType type, | 521 void OpaqueBrowserFrameView::Observe(NotificationType type, |
522 const NotificationSource& source, | 522 const NotificationSource& source, |
523 const NotificationDetails& details) { | 523 const NotificationDetails& details) { |
524 DCHECK_EQ(NotificationType::PREF_CHANGED, type.value); | 524 DCHECK_EQ(NotificationType::PREF_CHANGED, type.value); |
525 std::string* name = Details<std::string>(details).ptr(); | 525 std::string* name = Details<std::string>(details).ptr(); |
526 if (prefs::kGoogleServicesUsername == *name) | 526 if (prefs::kGoogleServicesUsername == *name) |
527 LayoutProfileTag(); | 527 LayoutAvatar(); |
528 } | 528 } |
529 | 529 |
530 /////////////////////////////////////////////////////////////////////////////// | 530 /////////////////////////////////////////////////////////////////////////////// |
531 // OpaqueBrowserFrameView, private: | 531 // OpaqueBrowserFrameView, private: |
532 | 532 |
533 int OpaqueBrowserFrameView::FrameBorderThickness(bool restored) const { | 533 int OpaqueBrowserFrameView::FrameBorderThickness(bool restored) const { |
534 return (!restored && (frame_->IsMaximized() || frame_->IsFullscreen())) ? | 534 return (!restored && (frame_->IsMaximized() || frame_->IsFullscreen())) ? |
535 0 : kFrameBorderThickness; | 535 0 : kFrameBorderThickness; |
536 } | 536 } |
537 | 537 |
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
918 toolbar_right->height() - bottom_edge_height, toolbar_right->width(), | 918 toolbar_right->height() - bottom_edge_height, toolbar_right->width(), |
919 bottom_edge_height, right_x, bottom_y, toolbar_right->width(), | 919 bottom_edge_height, right_x, bottom_y, toolbar_right->width(), |
920 bottom_edge_height, false); | 920 bottom_edge_height, false); |
921 | 921 |
922 // Draw the content/toolbar separator. | 922 // Draw the content/toolbar separator. |
923 canvas->FillRectInt(ResourceBundle::toolbar_separator_color, | 923 canvas->FillRectInt(ResourceBundle::toolbar_separator_color, |
924 x + kClientEdgeThickness, toolbar_bounds.bottom() - kClientEdgeThickness, | 924 x + kClientEdgeThickness, toolbar_bounds.bottom() - kClientEdgeThickness, |
925 w - (2 * kClientEdgeThickness), kClientEdgeThickness); | 925 w - (2 * kClientEdgeThickness), kClientEdgeThickness); |
926 } | 926 } |
927 | 927 |
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) { | 928 void OpaqueBrowserFrameView::PaintRestoredClientEdge(gfx::Canvas* canvas) { |
950 ui::ThemeProvider* tp = GetThemeProvider(); | 929 ui::ThemeProvider* tp = GetThemeProvider(); |
951 int client_area_top = frame_->client_view()->y(); | 930 int client_area_top = frame_->client_view()->y(); |
952 int image_top = client_area_top; | 931 int image_top = client_area_top; |
953 | 932 |
954 gfx::Rect client_area_bounds = CalculateClientAreaBounds(width(), height()); | 933 gfx::Rect client_area_bounds = CalculateClientAreaBounds(width(), height()); |
955 SkColor toolbar_color = tp->GetColor(ThemeService::COLOR_TOOLBAR); | 934 SkColor toolbar_color = tp->GetColor(ThemeService::COLOR_TOOLBAR); |
956 | 935 |
957 if (browser_view_->IsToolbarVisible() || | 936 if (browser_view_->IsToolbarVisible() || |
958 browser_view_->UseCompactNavigationBar()) { | 937 browser_view_->UseCompactNavigationBar()) { |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1127 // vertical midline rather than below. This compensates for how the icon is | 1106 // vertical midline rather than below. This compensates for how the icon is |
1128 // already biased downwards (see IconBounds()) and helps prevent descenders | 1107 // already biased downwards (see IconBounds()) and helps prevent descenders |
1129 // on the title from overlapping the 3D edge at the bottom of the titlebar. | 1108 // on the title from overlapping the 3D edge at the bottom of the titlebar. |
1130 title_bounds_.SetRect(title_x, | 1109 title_bounds_.SetRect(title_x, |
1131 icon_bounds.y() + ((icon_bounds.height() - title_height - 1) / 2), | 1110 icon_bounds.y() + ((icon_bounds.height() - title_height - 1) / 2), |
1132 std::max(0, minimize_button_->x() - kTitleLogoSpacing - title_x), | 1111 std::max(0, minimize_button_->x() - kTitleLogoSpacing - title_x), |
1133 title_height); | 1112 title_height); |
1134 } | 1113 } |
1135 } | 1114 } |
1136 | 1115 |
1137 void OpaqueBrowserFrameView::LayoutOTRAvatar() { | 1116 void OpaqueBrowserFrameView::LayoutAvatar() { |
1138 SkBitmap otr_avatar_icon = browser_view_->GetOTRAvatarIcon(); | 1117 // Even though the avatar is used for both incognito and profiles we always |
1139 int otr_bottom, otr_restored_y; | 1118 // use the incognito icon to layout the avatar button. |
| 1119 SkBitmap incognito_icon = browser_view_->GetOTRAvatarIcon(); |
| 1120 |
| 1121 int avatar_bottom, avatar_restored_y; |
1140 if (browser_view_->UseVerticalTabs()) { | 1122 if (browser_view_->UseVerticalTabs()) { |
1141 otr_bottom = NonClientTopBorderHeight(false, false) - kOTRBottomSpacing; | 1123 avatar_bottom = NonClientTopBorderHeight(false, false) - |
1142 otr_restored_y = kFrameShadowThickness; | 1124 kAvatarBottomSpacing; |
| 1125 avatar_restored_y = kFrameShadowThickness; |
1143 } else { | 1126 } else { |
1144 otr_bottom = GetHorizontalTabStripVerticalOffset(false) + | 1127 avatar_bottom = GetHorizontalTabStripVerticalOffset(false) + |
1145 browser_view_->GetTabStripHeight() - kOTRBottomSpacing; | 1128 browser_view_->GetTabStripHeight() - kAvatarBottomSpacing; |
1146 otr_restored_y = otr_bottom - otr_avatar_icon.height(); | 1129 avatar_restored_y = avatar_bottom - incognito_icon.height(); |
1147 } | 1130 } |
1148 int otr_y = frame_->IsMaximized() ? | 1131 int avatar_y = frame_->IsMaximized() ? |
1149 (NonClientTopBorderHeight(false, true) + kTabstripTopShadowThickness) : | 1132 (NonClientTopBorderHeight(false, true) + kTabstripTopShadowThickness) : |
1150 otr_restored_y; | 1133 avatar_restored_y; |
1151 otr_avatar_bounds_.SetRect(NonClientBorderThickness() + kOTRSideSpacing, | 1134 avatar_bounds_.SetRect(NonClientBorderThickness() + kAvatarSideSpacing, |
1152 otr_y, otr_avatar_icon.width(), | 1135 avatar_y, incognito_icon.width(), |
1153 browser_view_->ShouldShowOffTheRecordAvatar() ? (otr_bottom - otr_y) : 0); | 1136 browser_view_->ShouldShowAvatar() ? (avatar_bottom - avatar_y) : 0); |
1154 } | |
1155 | 1137 |
1156 void OpaqueBrowserFrameView::LayoutProfileTag() { | 1138 if (avatar_button_.get()) |
1157 if (!show_profile_button()) | 1139 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 } | 1140 } |
1199 | 1141 |
1200 gfx::Rect OpaqueBrowserFrameView::CalculateClientAreaBounds(int width, | 1142 gfx::Rect OpaqueBrowserFrameView::CalculateClientAreaBounds(int width, |
1201 int height) const { | 1143 int height) const { |
1202 int top_height = NonClientTopBorderHeight(false, false); | 1144 int top_height = NonClientTopBorderHeight(false, false); |
1203 int border_thickness = NonClientBorderThickness(); | 1145 int border_thickness = NonClientBorderThickness(); |
1204 return gfx::Rect(border_thickness, top_height, | 1146 return gfx::Rect(border_thickness, top_height, |
1205 std::max(0, width - (2 * border_thickness)), | 1147 std::max(0, width - (2 * border_thickness)), |
1206 std::max(0, height - GetReservedHeight() - | 1148 std::max(0, height - GetReservedHeight() - |
1207 top_height - border_thickness)); | 1149 top_height - border_thickness)); |
1208 } | 1150 } |
1209 | 1151 |
1210 void OpaqueBrowserFrameView::RegisterLoginNotifications() { | 1152 void OpaqueBrowserFrameView::RegisterLoginNotifications() { |
1211 PrefService* pref_service = browser_view_->browser()->profile()->GetPrefs(); | 1153 PrefService* pref_service = browser_view_->browser()->profile()->GetPrefs(); |
1212 DCHECK(pref_service); | 1154 DCHECK(pref_service); |
1213 username_pref_.Init(prefs::kGoogleServicesUsername, pref_service, this); | 1155 username_pref_.Init(prefs::kGoogleServicesUsername, pref_service, this); |
1214 } | 1156 } |
OLD | NEW |