Chromium Code Reviews| 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 // How far the new avatar button is from the left of the minimize button. | |
|
msw
2014/10/21 19:54:37
nit: the comment should match the surrounding patt
noms (inactive)
2014/10/21 20:55:18
Done.
| |
| 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::ShowAvatarMenu(browser_view()->browser()); | |
|
msw
2014/10/21 19:54:38
nit: use IDC_SHOW_AVATAR_MENU to match the abstrac
noms (inactive)
2014/10/21 20:55:18
Done.
| |
| 465 else | |
| 466 NOTREACHED(); | |
| 467 | |
|
msw
2014/10/21 19:54:37
nit: remove blank line
noms (inactive)
2014/10/21 20:55:17
Done.
| |
| 448 } | 468 } |
| 449 | 469 |
| 450 /////////////////////////////////////////////////////////////////////////////// | 470 /////////////////////////////////////////////////////////////////////////////// |
| 451 // BrowserNonClientFrameViewAsh, private: | 471 // BrowserNonClientFrameViewAsh, private: |
| 452 | 472 |
| 453 // views::NonClientFrameView: | 473 // views::NonClientFrameView: |
| 454 bool BrowserNonClientFrameViewAsh::DoesIntersectRect( | 474 bool BrowserNonClientFrameViewAsh::DoesIntersectRect( |
| 455 const views::View* target, | 475 const views::View* target, |
| 456 const gfx::Rect& rect) const { | 476 const gfx::Rect& rect) const { |
| 457 CHECK_EQ(target, this); | 477 CHECK_EQ(target, this); |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 480 return rect.y() < GetTopInset(); | 500 return rect.y() < GetTopInset(); |
| 481 } | 501 } |
| 482 | 502 |
| 483 int BrowserNonClientFrameViewAsh::GetTabStripLeftInset() const { | 503 int BrowserNonClientFrameViewAsh::GetTabStripLeftInset() const { |
| 484 return avatar_button() ? kAvatarSideSpacing + | 504 return avatar_button() ? kAvatarSideSpacing + |
| 485 browser_view()->GetOTRAvatarIcon().width() + kAvatarSideSpacing : | 505 browser_view()->GetOTRAvatarIcon().width() + kAvatarSideSpacing : |
| 486 kTabstripLeftSpacing; | 506 kTabstripLeftSpacing; |
| 487 } | 507 } |
| 488 | 508 |
| 489 int BrowserNonClientFrameViewAsh::GetTabStripRightInset() const { | 509 int BrowserNonClientFrameViewAsh::GetTabStripRightInset() const { |
| 490 return caption_button_container_->GetPreferredSize().width() + | 510 int tabstrip_width = kTabstripRightSpacing + |
| 491 kTabstripRightSpacing; | 511 caption_button_container_->GetPreferredSize().width(); |
| 512 | |
| 513 return new_avatar_button() ? kNewAvatarButtonOffset + | |
| 514 new_avatar_button()->GetPreferredSize().width() + tabstrip_width : | |
| 515 tabstrip_width; | |
| 492 } | 516 } |
| 493 | 517 |
| 494 bool BrowserNonClientFrameViewAsh::UseImmersiveLightbarHeaderStyle() const { | 518 bool BrowserNonClientFrameViewAsh::UseImmersiveLightbarHeaderStyle() const { |
| 495 ImmersiveModeController* immersive_controller = | 519 ImmersiveModeController* immersive_controller = |
| 496 browser_view()->immersive_mode_controller(); | 520 browser_view()->immersive_mode_controller(); |
| 497 return immersive_controller->IsEnabled() && | 521 return immersive_controller->IsEnabled() && |
| 498 !immersive_controller->IsRevealed() && | 522 !immersive_controller->IsRevealed() && |
| 499 browser_view()->IsTabStripVisible(); | 523 browser_view()->IsTabStripVisible(); |
| 500 } | 524 } |
| 501 | 525 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 535 int avatar_height = avatar_visible ? avatar_bottom - avatar_y : 0; | 559 int avatar_height = avatar_visible ? avatar_bottom - avatar_y : 0; |
| 536 | 560 |
| 537 gfx::Rect avatar_bounds(kAvatarSideSpacing, | 561 gfx::Rect avatar_bounds(kAvatarSideSpacing, |
| 538 avatar_y, | 562 avatar_y, |
| 539 incognito_icon.width(), | 563 incognito_icon.width(), |
| 540 avatar_height); | 564 avatar_height); |
| 541 avatar_button()->SetBoundsRect(avatar_bounds); | 565 avatar_button()->SetBoundsRect(avatar_bounds); |
| 542 avatar_button()->SetVisible(avatar_visible); | 566 avatar_button()->SetVisible(avatar_visible); |
| 543 } | 567 } |
| 544 | 568 |
| 569 void BrowserNonClientFrameViewAsh::LayoutNewStyleAvatar() { | |
| 570 DCHECK(switches::IsNewAvatarMenu()); | |
| 571 if (!new_avatar_button()) | |
| 572 return; | |
| 573 | |
| 574 gfx::Size button_size = new_avatar_button()->GetPreferredSize(); | |
| 575 int button_x = width() - | |
| 576 caption_button_container_->GetPreferredSize().width() - | |
| 577 kNewAvatarButtonOffset - button_size.width(); | |
| 578 | |
| 579 new_avatar_button()->SetBounds( | |
| 580 button_x, | |
| 581 0, | |
| 582 button_size.width(), | |
| 583 caption_button_container_->GetPreferredSize().height()); | |
|
msw
2014/10/21 19:54:37
nit: do you want the preferred height or the actua
noms (inactive)
2014/10/21 20:55:17
The rest of the file uses preferred height, so I k
msw
2014/10/21 21:00:40
Acknowledged.
| |
| 584 } | |
| 585 | |
| 545 bool BrowserNonClientFrameViewAsh::ShouldPaint() const { | 586 bool BrowserNonClientFrameViewAsh::ShouldPaint() const { |
| 546 if (!frame()->IsFullscreen()) | 587 if (!frame()->IsFullscreen()) |
| 547 return true; | 588 return true; |
| 548 | 589 |
| 549 // We need to paint when in immersive fullscreen and either: | 590 // We need to paint when in immersive fullscreen and either: |
| 550 // - The top-of-window views are revealed. | 591 // - The top-of-window views are revealed. |
| 551 // - The lightbar style tabstrip is visible. | 592 // - The lightbar style tabstrip is visible. |
| 552 ImmersiveModeController* immersive_mode_controller = | 593 ImmersiveModeController* immersive_mode_controller = |
| 553 browser_view()->immersive_mode_controller(); | 594 browser_view()->immersive_mode_controller(); |
| 554 return immersive_mode_controller->IsEnabled() && | 595 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(), | 684 canvas->FillRect(gfx::Rect(0, caption_button_container_->bounds().bottom(), |
| 644 width(), kClientEdgeThickness), | 685 width(), kClientEdgeThickness), |
| 645 ThemeProperties::GetDefaultColor( | 686 ThemeProperties::GetDefaultColor( |
| 646 ThemeProperties::COLOR_TOOLBAR_SEPARATOR)); | 687 ThemeProperties::COLOR_TOOLBAR_SEPARATOR)); |
| 647 } | 688 } |
| 648 | 689 |
| 649 void BrowserNonClientFrameViewAsh::UpdateBackButtonState(bool enabled) { | 690 void BrowserNonClientFrameViewAsh::UpdateBackButtonState(bool enabled) { |
| 650 web_app_back_button_->SetState(enabled ? views::Button::STATE_NORMAL | 691 web_app_back_button_->SetState(enabled ? views::Button::STATE_NORMAL |
| 651 : views::Button::STATE_DISABLED); | 692 : views::Button::STATE_DISABLED); |
| 652 } | 693 } |
| OLD | NEW |