OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/views/frame/browser_non_client_frame_view_ash.h" | 5 #include "chrome/browser/ui/views/frame/browser_non_client_frame_view_ash.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "ash/frame/caption_buttons/frame_caption_button.h" | 9 #include "ash/frame/caption_buttons/frame_caption_button.h" |
10 #include "ash/frame/caption_buttons/frame_caption_button_container_view.h" | 10 #include "ash/frame/caption_buttons/frame_caption_button_container_view.h" |
11 #include "ash/frame/default_header_painter.h" | 11 #include "ash/frame/default_header_painter.h" |
12 #include "ash/frame/frame_border_hit_test_controller.h" | 12 #include "ash/frame/frame_border_hit_test_controller.h" |
13 #include "ash/frame/header_painter_util.h" | 13 #include "ash/frame/header_painter_util.h" |
14 #include "ash/shell.h" | 14 #include "ash/shell.h" |
15 #include "chrome/app/chrome_command_ids.h" | 15 #include "chrome/app/chrome_command_ids.h" |
16 #include "chrome/browser/extensions/extension_util.h" | 16 #include "chrome/browser/extensions/extension_util.h" |
17 #include "chrome/browser/themes/theme_properties.h" | 17 #include "chrome/browser/themes/theme_properties.h" |
18 #include "chrome/browser/ui/browser.h" | 18 #include "chrome/browser/ui/browser.h" |
19 #include "chrome/browser/ui/browser_commands.h" | 19 #include "chrome/browser/ui/browser_commands.h" |
20 #include "chrome/browser/ui/views/frame/browser_frame.h" | 20 #include "chrome/browser/ui/views/frame/browser_frame.h" |
21 #include "chrome/browser/ui/views/frame/browser_header_painter_ash.h" | 21 #include "chrome/browser/ui/views/frame/browser_header_painter_ash.h" |
22 #include "chrome/browser/ui/views/frame/browser_view.h" | 22 #include "chrome/browser/ui/views/frame/browser_view.h" |
23 #include "chrome/browser/ui/views/frame/immersive_mode_controller.h" | 23 #include "chrome/browser/ui/views/frame/immersive_mode_controller.h" |
24 #include "chrome/browser/ui/views/profiles/avatar_menu_button.h" | 24 #include "chrome/browser/ui/views/profiles/avatar_menu_button.h" |
25 #include "chrome/browser/ui/views/tab_icon_view.h" | 25 #include "chrome/browser/ui/views/tab_icon_view.h" |
26 #include "chrome/browser/ui/views/tabs/tab_strip.h" | 26 #include "chrome/browser/ui/views/tabs/tab_strip.h" |
| 27 #include "components/signin/core/common/profile_management_switches.h" |
27 #include "content/public/browser/web_contents.h" | 28 #include "content/public/browser/web_contents.h" |
28 #include "grit/ash_resources.h" | 29 #include "grit/ash_resources.h" |
29 #include "grit/theme_resources.h" | 30 #include "grit/theme_resources.h" |
30 #include "ui/accessibility/ax_view_state.h" | 31 #include "ui/accessibility/ax_view_state.h" |
31 #include "ui/aura/client/aura_constants.h" | 32 #include "ui/aura/client/aura_constants.h" |
32 #include "ui/aura/window.h" | 33 #include "ui/aura/window.h" |
33 #include "ui/base/hit_test.h" | 34 #include "ui/base/hit_test.h" |
34 #include "ui/base/layout.h" | 35 #include "ui/base/layout.h" |
35 #include "ui/base/resource/resource_bundle.h" | 36 #include "ui/base/resource/resource_bundle.h" |
36 #include "ui/base/theme_provider.h" | 37 #include "ui/base/theme_provider.h" |
(...skipping 12 matching lines...) Expand all Loading... |
49 | 50 |
50 namespace { | 51 namespace { |
51 | 52 |
52 // The avatar ends 2 px above the bottom of the tabstrip (which, given the | 53 // The avatar ends 2 px above the bottom of the tabstrip (which, given the |
53 // way the tabstrip draws its bottom edge, will appear like a 1 px gap to the | 54 // way the tabstrip draws its bottom edge, will appear like a 1 px gap to the |
54 // user). | 55 // user). |
55 const int kAvatarBottomSpacing = 2; | 56 const int kAvatarBottomSpacing = 2; |
56 // There are 2 px on each side of the avatar (between the frame border and | 57 // There are 2 px on each side of the avatar (between the frame border and |
57 // it on the left, and between it and the tabstrip on the right). | 58 // it on the left, and between it and the tabstrip on the right). |
58 const int kAvatarSideSpacing = 2; | 59 const int kAvatarSideSpacing = 2; |
| 60 // Space between the new avatar button and the minimize button. |
| 61 const int kNewAvatarButtonOffset = 5; |
59 // Space between left edge of window and tabstrip. | 62 // Space between left edge of window and tabstrip. |
60 const int kTabstripLeftSpacing = 0; | 63 const int kTabstripLeftSpacing = 0; |
61 // Space between right edge of tabstrip and maximize button. | 64 // Space between right edge of tabstrip and maximize button. |
62 const int kTabstripRightSpacing = 10; | 65 const int kTabstripRightSpacing = 10; |
63 // Height of the shadow of the content area, at the top of the toolbar. | 66 // Height of the shadow of the content area, at the top of the toolbar. |
64 const int kContentShadowHeight = 1; | 67 const int kContentShadowHeight = 1; |
65 // Space between top of window and top of tabstrip for tall headers, such as | 68 // Space between top of window and top of tabstrip for tall headers, such as |
66 // for restored windows, apps, etc. | 69 // for restored windows, apps, etc. |
67 const int kTabstripTopSpacingTall = 7; | 70 const int kTabstripTopSpacingTall = 7; |
68 // Space between top of window and top of tabstrip for short headers, such as | 71 // Space between top of window and top of tabstrip for short headers, such as |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 AddChildView(caption_button_container_); | 122 AddChildView(caption_button_container_); |
120 | 123 |
121 // Initializing the TabIconView is expensive, so only do it if we need to. | 124 // Initializing the TabIconView is expensive, so only do it if we need to. |
122 if (browser_view()->ShouldShowWindowIcon()) { | 125 if (browser_view()->ShouldShowWindowIcon()) { |
123 window_icon_ = new TabIconView(this, NULL); | 126 window_icon_ = new TabIconView(this, NULL); |
124 window_icon_->set_is_light(true); | 127 window_icon_->set_is_light(true); |
125 AddChildView(window_icon_); | 128 AddChildView(window_icon_); |
126 window_icon_->Update(); | 129 window_icon_->Update(); |
127 } | 130 } |
128 | 131 |
129 // Create incognito icon if necessary. | 132 if (browser_view()->IsRegularOrGuestSession() && |
130 UpdateAvatarInfo(); | 133 switches::IsNewAvatarMenu()) { |
| 134 UpdateNewStyleAvatarInfo(this, NewAvatarButton::NATIVE_BUTTON); |
| 135 } else { |
| 136 UpdateAvatarInfo(); |
| 137 } |
131 | 138 |
132 // HeaderPainter handles layout. | 139 // HeaderPainter handles layout. |
133 if (UsePackagedAppHeaderStyle()) { | 140 if (UsePackagedAppHeaderStyle()) { |
134 ash::DefaultHeaderPainter* header_painter = new ash::DefaultHeaderPainter; | 141 ash::DefaultHeaderPainter* header_painter = new ash::DefaultHeaderPainter; |
135 header_painter_.reset(header_painter); | 142 header_painter_.reset(header_painter); |
136 header_painter->Init(frame(), this, caption_button_container_); | 143 header_painter->Init(frame(), this, caption_button_container_); |
137 if (window_icon_) { | 144 if (window_icon_) { |
138 header_painter->UpdateLeftHeaderView(window_icon_); | 145 header_painter->UpdateLeftHeaderView(window_icon_); |
139 } | 146 } |
140 } else if (UseWebAppHeaderStyle()) { | 147 } else if (UseWebAppHeaderStyle()) { |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 | 238 |
232 gfx::Rect BrowserNonClientFrameViewAsh::GetWindowBoundsForClientBounds( | 239 gfx::Rect BrowserNonClientFrameViewAsh::GetWindowBoundsForClientBounds( |
233 const gfx::Rect& client_bounds) const { | 240 const gfx::Rect& client_bounds) const { |
234 return client_bounds; | 241 return client_bounds; |
235 } | 242 } |
236 | 243 |
237 int BrowserNonClientFrameViewAsh::NonClientHitTest(const gfx::Point& point) { | 244 int BrowserNonClientFrameViewAsh::NonClientHitTest(const gfx::Point& point) { |
238 int hit_test = ash::FrameBorderHitTestController::NonClientHitTest(this, | 245 int hit_test = ash::FrameBorderHitTestController::NonClientHitTest(this, |
239 caption_button_container_, point); | 246 caption_button_container_, point); |
240 | 247 |
241 // See if the point is actually within the avatar menu button.d | 248 // See if the point is actually within either of the avatar menu buttons. |
242 if (hit_test == HTCAPTION && avatar_button() && | 249 if (hit_test == HTCAPTION && avatar_button() && |
243 ConvertedHitTest(this, avatar_button(), point)) { | 250 ConvertedHitTest(this, avatar_button(), point)) { |
244 return HTCLIENT; | 251 return HTCLIENT; |
245 } | 252 } |
246 | 253 |
| 254 if (hit_test == HTCAPTION && new_avatar_button() && |
| 255 ConvertedHitTest(this, new_avatar_button(), point)) { |
| 256 return HTCLIENT; |
| 257 } |
| 258 |
247 // See if the point is actually within the web app back button. | 259 // See if the point is actually within the web app back button. |
248 if (hit_test == HTCAPTION && web_app_back_button_ && | 260 if (hit_test == HTCAPTION && web_app_back_button_ && |
249 ConvertedHitTest(this, web_app_back_button_, point)) { | 261 ConvertedHitTest(this, web_app_back_button_, point)) { |
250 return HTCLIENT; | 262 return HTCLIENT; |
251 } | 263 } |
252 | 264 |
253 #if defined(ENABLE_MANAGED_USERS) | 265 #if defined(ENABLE_MANAGED_USERS) |
254 // ...or within the avatar label, if it's a supervised user. | 266 // ...or within the avatar label, if it's a supervised user. |
255 if (hit_test == HTCAPTION && supervised_user_avatar_label() && | 267 if (hit_test == HTCAPTION && supervised_user_avatar_label() && |
256 ConvertedHitTest(this, supervised_user_avatar_label(), point)) { | 268 ConvertedHitTest(this, supervised_user_avatar_label(), point)) { |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 painted_height = GetTopInset() + | 354 painted_height = GetTopInset() + |
343 browser_view()->tabstrip()->GetPreferredSize().height(); | 355 browser_view()->tabstrip()->GetPreferredSize().height(); |
344 } else if (browser_view()->IsToolbarVisible()) { | 356 } else if (browser_view()->IsToolbarVisible()) { |
345 // Paint the header so that it overlaps with the top few pixels of the | 357 // Paint the header so that it overlaps with the top few pixels of the |
346 // toolbar because the top few pixels of the toolbar are not opaque. | 358 // toolbar because the top few pixels of the toolbar are not opaque. |
347 painted_height = GetTopInset() + kFrameShadowThickness * 2; | 359 painted_height = GetTopInset() + kFrameShadowThickness * 2; |
348 } else { | 360 } else { |
349 painted_height = GetTopInset(); | 361 painted_height = GetTopInset(); |
350 } | 362 } |
351 header_painter_->SetHeaderHeightForPainting(painted_height); | 363 header_painter_->SetHeaderHeightForPainting(painted_height); |
| 364 |
352 if (avatar_button()) { | 365 if (avatar_button()) { |
353 LayoutAvatar(); | 366 LayoutAvatar(); |
354 header_painter_->UpdateLeftViewXInset(avatar_button()->bounds().right()); | 367 header_painter_->UpdateLeftViewXInset(avatar_button()->bounds().right()); |
355 } else { | 368 } else { |
| 369 if (new_avatar_button()) |
| 370 LayoutNewStyleAvatar(); |
356 header_painter_->UpdateLeftViewXInset( | 371 header_painter_->UpdateLeftViewXInset( |
357 ash::HeaderPainterUtil::GetDefaultLeftViewXInset()); | 372 ash::HeaderPainterUtil::GetDefaultLeftViewXInset()); |
358 } | 373 } |
359 BrowserNonClientFrameView::Layout(); | 374 BrowserNonClientFrameView::Layout(); |
360 } | 375 } |
361 | 376 |
362 const char* BrowserNonClientFrameViewAsh::GetClassName() const { | 377 const char* BrowserNonClientFrameViewAsh::GetClassName() const { |
363 return kViewClassName; | 378 return kViewClassName; |
364 } | 379 } |
365 | 380 |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
436 bool enabled) { | 451 bool enabled) { |
437 DCHECK_EQ(IDC_BACK, id); | 452 DCHECK_EQ(IDC_BACK, id); |
438 UpdateBackButtonState(enabled); | 453 UpdateBackButtonState(enabled); |
439 } | 454 } |
440 | 455 |
441 /////////////////////////////////////////////////////////////////////////////// | 456 /////////////////////////////////////////////////////////////////////////////// |
442 // views::ButtonListener: | 457 // views::ButtonListener: |
443 | 458 |
444 void BrowserNonClientFrameViewAsh::ButtonPressed(views::Button* sender, | 459 void BrowserNonClientFrameViewAsh::ButtonPressed(views::Button* sender, |
445 const ui::Event& event) { | 460 const ui::Event& event) { |
446 DCHECK_EQ(sender, web_app_back_button_); | 461 if (sender == web_app_back_button_) |
447 chrome::ExecuteCommand(browser_view()->browser(), IDC_BACK); | 462 chrome::ExecuteCommand(browser_view()->browser(), IDC_BACK); |
| 463 else if (sender == new_avatar_button()) |
| 464 chrome::ExecuteCommand(browser_view()->browser(), IDC_SHOW_AVATAR_MENU); |
| 465 else |
| 466 NOTREACHED(); |
448 } | 467 } |
449 | 468 |
450 /////////////////////////////////////////////////////////////////////////////// | 469 /////////////////////////////////////////////////////////////////////////////// |
451 // BrowserNonClientFrameViewAsh, private: | 470 // BrowserNonClientFrameViewAsh, private: |
452 | 471 |
453 // views::NonClientFrameView: | 472 // views::NonClientFrameView: |
454 bool BrowserNonClientFrameViewAsh::DoesIntersectRect( | 473 bool BrowserNonClientFrameViewAsh::DoesIntersectRect( |
455 const views::View* target, | 474 const views::View* target, |
456 const gfx::Rect& rect) const { | 475 const gfx::Rect& rect) const { |
457 CHECK_EQ(target, this); | 476 CHECK_EQ(target, this); |
(...skipping 22 matching lines...) Expand all Loading... |
480 return rect.y() < GetTopInset(); | 499 return rect.y() < GetTopInset(); |
481 } | 500 } |
482 | 501 |
483 int BrowserNonClientFrameViewAsh::GetTabStripLeftInset() const { | 502 int BrowserNonClientFrameViewAsh::GetTabStripLeftInset() const { |
484 return avatar_button() ? kAvatarSideSpacing + | 503 return avatar_button() ? kAvatarSideSpacing + |
485 browser_view()->GetOTRAvatarIcon().width() + kAvatarSideSpacing : | 504 browser_view()->GetOTRAvatarIcon().width() + kAvatarSideSpacing : |
486 kTabstripLeftSpacing; | 505 kTabstripLeftSpacing; |
487 } | 506 } |
488 | 507 |
489 int BrowserNonClientFrameViewAsh::GetTabStripRightInset() const { | 508 int BrowserNonClientFrameViewAsh::GetTabStripRightInset() const { |
490 return caption_button_container_->GetPreferredSize().width() + | 509 int tabstrip_width = kTabstripRightSpacing + |
491 kTabstripRightSpacing; | 510 caption_button_container_->GetPreferredSize().width(); |
| 511 |
| 512 return new_avatar_button() ? kNewAvatarButtonOffset + |
| 513 new_avatar_button()->GetPreferredSize().width() + tabstrip_width : |
| 514 tabstrip_width; |
492 } | 515 } |
493 | 516 |
494 bool BrowserNonClientFrameViewAsh::UseImmersiveLightbarHeaderStyle() const { | 517 bool BrowserNonClientFrameViewAsh::UseImmersiveLightbarHeaderStyle() const { |
495 ImmersiveModeController* immersive_controller = | 518 ImmersiveModeController* immersive_controller = |
496 browser_view()->immersive_mode_controller(); | 519 browser_view()->immersive_mode_controller(); |
497 return immersive_controller->IsEnabled() && | 520 return immersive_controller->IsEnabled() && |
498 !immersive_controller->IsRevealed() && | 521 !immersive_controller->IsRevealed() && |
499 browser_view()->IsTabStripVisible(); | 522 browser_view()->IsTabStripVisible(); |
500 } | 523 } |
501 | 524 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
535 int avatar_height = avatar_visible ? avatar_bottom - avatar_y : 0; | 558 int avatar_height = avatar_visible ? avatar_bottom - avatar_y : 0; |
536 | 559 |
537 gfx::Rect avatar_bounds(kAvatarSideSpacing, | 560 gfx::Rect avatar_bounds(kAvatarSideSpacing, |
538 avatar_y, | 561 avatar_y, |
539 incognito_icon.width(), | 562 incognito_icon.width(), |
540 avatar_height); | 563 avatar_height); |
541 avatar_button()->SetBoundsRect(avatar_bounds); | 564 avatar_button()->SetBoundsRect(avatar_bounds); |
542 avatar_button()->SetVisible(avatar_visible); | 565 avatar_button()->SetVisible(avatar_visible); |
543 } | 566 } |
544 | 567 |
| 568 void BrowserNonClientFrameViewAsh::LayoutNewStyleAvatar() { |
| 569 DCHECK(switches::IsNewAvatarMenu()); |
| 570 if (!new_avatar_button()) |
| 571 return; |
| 572 |
| 573 gfx::Size button_size = new_avatar_button()->GetPreferredSize(); |
| 574 int button_x = width() - |
| 575 caption_button_container_->GetPreferredSize().width() - |
| 576 kNewAvatarButtonOffset - button_size.width(); |
| 577 |
| 578 new_avatar_button()->SetBounds( |
| 579 button_x, |
| 580 0, |
| 581 button_size.width(), |
| 582 caption_button_container_->GetPreferredSize().height()); |
| 583 } |
| 584 |
545 bool BrowserNonClientFrameViewAsh::ShouldPaint() const { | 585 bool BrowserNonClientFrameViewAsh::ShouldPaint() const { |
546 if (!frame()->IsFullscreen()) | 586 if (!frame()->IsFullscreen()) |
547 return true; | 587 return true; |
548 | 588 |
549 // We need to paint when in immersive fullscreen and either: | 589 // We need to paint when in immersive fullscreen and either: |
550 // - The top-of-window views are revealed. | 590 // - The top-of-window views are revealed. |
551 // - The lightbar style tabstrip is visible. | 591 // - The lightbar style tabstrip is visible. |
552 ImmersiveModeController* immersive_mode_controller = | 592 ImmersiveModeController* immersive_mode_controller = |
553 browser_view()->immersive_mode_controller(); | 593 browser_view()->immersive_mode_controller(); |
554 return immersive_mode_controller->IsEnabled() && | 594 return immersive_mode_controller->IsEnabled() && |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
643 canvas->FillRect(gfx::Rect(0, caption_button_container_->bounds().bottom(), | 683 canvas->FillRect(gfx::Rect(0, caption_button_container_->bounds().bottom(), |
644 width(), kClientEdgeThickness), | 684 width(), kClientEdgeThickness), |
645 ThemeProperties::GetDefaultColor( | 685 ThemeProperties::GetDefaultColor( |
646 ThemeProperties::COLOR_TOOLBAR_SEPARATOR)); | 686 ThemeProperties::COLOR_TOOLBAR_SEPARATOR)); |
647 } | 687 } |
648 | 688 |
649 void BrowserNonClientFrameViewAsh::UpdateBackButtonState(bool enabled) { | 689 void BrowserNonClientFrameViewAsh::UpdateBackButtonState(bool enabled) { |
650 web_app_back_button_->SetState(enabled ? views::Button::STATE_NORMAL | 690 web_app_back_button_->SetState(enabled ? views::Button::STATE_NORMAL |
651 : views::Button::STATE_DISABLED); | 691 : views::Button::STATE_DISABLED); |
652 } | 692 } |
OLD | NEW |