| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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/ash_layout_constants.h" | 9 #include "ash/ash_layout_constants.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 "build/build_config.h" | 15 #include "build/build_config.h" |
| 16 #include "chrome/app/chrome_command_ids.h" | 16 #include "chrome/app/chrome_command_ids.h" |
| 17 #include "chrome/browser/extensions/extension_util.h" | 17 #include "chrome/browser/extensions/extension_util.h" |
| 18 #include "chrome/browser/profiles/profiles_state.h" | 18 #include "chrome/browser/profiles/profiles_state.h" |
| 19 #include "chrome/browser/themes/theme_properties.h" | 19 #include "chrome/browser/themes/theme_properties.h" |
| 20 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h" |
| 20 #include "chrome/browser/ui/browser.h" | 21 #include "chrome/browser/ui/browser.h" |
| 21 #include "chrome/browser/ui/browser_commands.h" | 22 #include "chrome/browser/ui/browser_commands.h" |
| 22 #include "chrome/browser/ui/layout_constants.h" | 23 #include "chrome/browser/ui/layout_constants.h" |
| 23 #include "chrome/browser/ui/views/frame/browser_frame.h" | 24 #include "chrome/browser/ui/views/frame/browser_frame.h" |
| 24 #include "chrome/browser/ui/views/frame/browser_header_painter_ash.h" | 25 #include "chrome/browser/ui/views/frame/browser_header_painter_ash.h" |
| 25 #include "chrome/browser/ui/views/frame/browser_view.h" | 26 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 26 #include "chrome/browser/ui/views/frame/immersive_mode_controller.h" | 27 #include "chrome/browser/ui/views/frame/immersive_mode_controller.h" |
| 27 #include "chrome/browser/ui/views/frame/web_app_left_header_view_ash.h" | 28 #include "chrome/browser/ui/views/frame/web_app_left_header_view_ash.h" |
| 28 #include "chrome/browser/ui/views/profiles/avatar_menu_button.h" | 29 #include "chrome/browser/ui/views/profiles/profile_indicator_icon.h" |
| 29 #include "chrome/browser/ui/views/tab_icon_view.h" | 30 #include "chrome/browser/ui/views/tab_icon_view.h" |
| 30 #include "chrome/browser/ui/views/tabs/tab_strip.h" | 31 #include "chrome/browser/ui/views/tabs/tab_strip.h" |
| 31 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" | 32 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" |
| 32 #include "chrome/browser/web_applications/web_app.h" | 33 #include "chrome/browser/web_applications/web_app.h" |
| 33 #include "components/signin/core/common/profile_management_switches.h" | 34 #include "components/signin/core/common/profile_management_switches.h" |
| 34 #include "content/public/browser/web_contents.h" | 35 #include "content/public/browser/web_contents.h" |
| 35 #include "extensions/browser/extension_registry.h" | 36 #include "extensions/browser/extension_registry.h" |
| 36 #include "grit/theme_resources.h" | 37 #include "grit/theme_resources.h" |
| 37 #include "ui/accessibility/ax_view_state.h" | 38 #include "ui/accessibility/ax_view_state.h" |
| 38 #include "ui/aura/client/aura_constants.h" | 39 #include "ui/aura/client/aura_constants.h" |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 // computation of |painted_height| for app and popup windows depends on the | 299 // computation of |painted_height| for app and popup windows depends on the |
| 299 // position of the window controls. | 300 // position of the window controls. |
| 300 header_painter_->LayoutHeader(); | 301 header_painter_->LayoutHeader(); |
| 301 | 302 |
| 302 int painted_height = GetTopInset(false); | 303 int painted_height = GetTopInset(false); |
| 303 if (browser_view()->IsTabStripVisible()) | 304 if (browser_view()->IsTabStripVisible()) |
| 304 painted_height += browser_view()->tabstrip()->GetPreferredSize().height(); | 305 painted_height += browser_view()->tabstrip()->GetPreferredSize().height(); |
| 305 | 306 |
| 306 header_painter_->SetHeaderHeightForPainting(painted_height); | 307 header_painter_->SetHeaderHeightForPainting(painted_height); |
| 307 | 308 |
| 308 if (avatar_button()) | 309 if (profile_indicator_icon()) |
| 309 LayoutAvatar(); | 310 LayoutProfileIndicatorIcon(); |
| 310 BrowserNonClientFrameView::Layout(); | 311 BrowserNonClientFrameView::Layout(); |
| 311 } | 312 } |
| 312 | 313 |
| 313 const char* BrowserNonClientFrameViewAsh::GetClassName() const { | 314 const char* BrowserNonClientFrameViewAsh::GetClassName() const { |
| 314 return "BrowserNonClientFrameViewAsh"; | 315 return "BrowserNonClientFrameViewAsh"; |
| 315 } | 316 } |
| 316 | 317 |
| 317 void BrowserNonClientFrameViewAsh::GetAccessibleState(ui::AXViewState* state) { | 318 void BrowserNonClientFrameViewAsh::GetAccessibleState(ui::AXViewState* state) { |
| 318 state->role = ui::AX_ROLE_TITLE_BAR; | 319 state->role = ui::AX_ROLE_TITLE_BAR; |
| 319 } | 320 } |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 | 374 |
| 374 gfx::ImageSkia BrowserNonClientFrameViewAsh::GetFaviconForTabIconView() { | 375 gfx::ImageSkia BrowserNonClientFrameViewAsh::GetFaviconForTabIconView() { |
| 375 views::WidgetDelegate* delegate = frame()->widget_delegate(); | 376 views::WidgetDelegate* delegate = frame()->widget_delegate(); |
| 376 return delegate ? delegate->GetWindowIcon() : gfx::ImageSkia(); | 377 return delegate ? delegate->GetWindowIcon() : gfx::ImageSkia(); |
| 377 } | 378 } |
| 378 | 379 |
| 379 /////////////////////////////////////////////////////////////////////////////// | 380 /////////////////////////////////////////////////////////////////////////////// |
| 380 // BrowserNonClientFrameViewAsh, protected: | 381 // BrowserNonClientFrameViewAsh, protected: |
| 381 | 382 |
| 382 // BrowserNonClientFrameView: | 383 // BrowserNonClientFrameView: |
| 383 void BrowserNonClientFrameViewAsh::UpdateAvatar() { | 384 void BrowserNonClientFrameViewAsh::UpdateProfileIcons() { |
| 384 UpdateOldAvatarButton(); | 385 Browser* browser = browser_view()->browser(); |
| 386 if ((browser->is_type_tabbed() || browser->is_app()) && |
| 387 chrome::MultiUserWindowManager::ShouldShowAvatar( |
| 388 browser_view()->GetNativeWindow())) { |
| 389 UpdateProfileIndicatorIcon(); |
| 390 } |
| 385 } | 391 } |
| 386 | 392 |
| 387 /////////////////////////////////////////////////////////////////////////////// | 393 /////////////////////////////////////////////////////////////////////////////// |
| 388 // BrowserNonClientFrameViewAsh, private: | 394 // BrowserNonClientFrameViewAsh, private: |
| 389 | 395 |
| 390 // views::NonClientFrameView: | 396 // views::NonClientFrameView: |
| 391 bool BrowserNonClientFrameViewAsh::DoesIntersectRect( | 397 bool BrowserNonClientFrameViewAsh::DoesIntersectRect( |
| 392 const views::View* target, | 398 const views::View* target, |
| 393 const gfx::Rect& rect) const { | 399 const gfx::Rect& rect) const { |
| 394 CHECK_EQ(this, target); | 400 CHECK_EQ(this, target); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 410 View::ConvertRectToTarget(this, tabstrip, &rect_in_tabstrip_coords_f); | 416 View::ConvertRectToTarget(this, tabstrip, &rect_in_tabstrip_coords_f); |
| 411 const gfx::Rect rect_in_tabstrip_coords( | 417 const gfx::Rect rect_in_tabstrip_coords( |
| 412 gfx::ToEnclosingRect(rect_in_tabstrip_coords_f)); | 418 gfx::ToEnclosingRect(rect_in_tabstrip_coords_f)); |
| 413 return (rect_in_tabstrip_coords.y() <= tabstrip->height()) && | 419 return (rect_in_tabstrip_coords.y() <= tabstrip->height()) && |
| 414 (!tabstrip->HitTestRect(rect_in_tabstrip_coords) || | 420 (!tabstrip->HitTestRect(rect_in_tabstrip_coords) || |
| 415 tabstrip->IsRectInWindowCaption(rect_in_tabstrip_coords)); | 421 tabstrip->IsRectInWindowCaption(rect_in_tabstrip_coords)); |
| 416 } | 422 } |
| 417 | 423 |
| 418 int BrowserNonClientFrameViewAsh::GetTabStripLeftInset() const { | 424 int BrowserNonClientFrameViewAsh::GetTabStripLeftInset() const { |
| 419 const gfx::Insets insets(GetLayoutInsets(AVATAR_ICON)); | 425 const gfx::Insets insets(GetLayoutInsets(AVATAR_ICON)); |
| 420 const int avatar_right = | 426 const int avatar_right = profile_indicator_icon() |
| 421 avatar_button() ? (insets.left() + GetOTRAvatarIcon().width()) : 0; | 427 ? (insets.left() + GetOTRAvatarIcon().width()) |
| 428 : 0; |
| 422 return avatar_right + insets.right(); | 429 return avatar_right + insets.right(); |
| 423 } | 430 } |
| 424 | 431 |
| 425 int BrowserNonClientFrameViewAsh::GetTabStripRightInset() const { | 432 int BrowserNonClientFrameViewAsh::GetTabStripRightInset() const { |
| 426 return kTabstripRightSpacing + | 433 return kTabstripRightSpacing + |
| 427 caption_button_container_->GetPreferredSize().width(); | 434 caption_button_container_->GetPreferredSize().width(); |
| 428 } | 435 } |
| 429 | 436 |
| 430 bool BrowserNonClientFrameViewAsh::UseImmersiveLightbarHeaderStyle() const { | 437 bool BrowserNonClientFrameViewAsh::UseImmersiveLightbarHeaderStyle() const { |
| 431 const ImmersiveModeController* const immersive_controller = | 438 const ImmersiveModeController* const immersive_controller = |
| 432 browser_view()->immersive_mode_controller(); | 439 browser_view()->immersive_mode_controller(); |
| 433 return immersive_controller->IsEnabled() && | 440 return immersive_controller->IsEnabled() && |
| 434 !immersive_controller->IsRevealed() && | 441 !immersive_controller->IsRevealed() && |
| 435 browser_view()->IsTabStripVisible(); | 442 browser_view()->IsTabStripVisible(); |
| 436 } | 443 } |
| 437 | 444 |
| 438 bool BrowserNonClientFrameViewAsh::UsePackagedAppHeaderStyle() const { | 445 bool BrowserNonClientFrameViewAsh::UsePackagedAppHeaderStyle() const { |
| 439 // Use for non tabbed trusted source windows, e.g. Settings, as well as apps | 446 // Use for non tabbed trusted source windows, e.g. Settings, as well as apps |
| 440 // that aren't using the newer WebApp style. | 447 // that aren't using the newer WebApp style. |
| 441 const Browser* const browser = browser_view()->browser(); | 448 const Browser* const browser = browser_view()->browser(); |
| 442 return (!browser->is_type_tabbed() && browser->is_trusted_source()) || | 449 return (!browser->is_type_tabbed() && browser->is_trusted_source()) || |
| 443 (browser->is_app() && !UseWebAppHeaderStyle()); | 450 (browser->is_app() && !UseWebAppHeaderStyle()); |
| 444 } | 451 } |
| 445 | 452 |
| 446 bool BrowserNonClientFrameViewAsh::UseWebAppHeaderStyle() const { | 453 bool BrowserNonClientFrameViewAsh::UseWebAppHeaderStyle() const { |
| 447 return browser_view()->browser()->SupportsWindowFeature( | 454 return browser_view()->browser()->SupportsWindowFeature( |
| 448 Browser::FEATURE_WEBAPPFRAME); | 455 Browser::FEATURE_WEBAPPFRAME); |
| 449 } | 456 } |
| 450 | 457 |
| 451 void BrowserNonClientFrameViewAsh::LayoutAvatar() { | 458 void BrowserNonClientFrameViewAsh::LayoutProfileIndicatorIcon() { |
| 452 DCHECK(avatar_button()); | 459 DCHECK(profile_indicator_icon()); |
| 453 #if !defined(OS_CHROMEOS) | 460 #if !defined(OS_CHROMEOS) |
| 454 // ChromeOS shows avatar on V1 app. | 461 // ChromeOS shows avatar on V1 app. |
| 455 DCHECK(browser_view()->IsTabStripVisible()); | 462 DCHECK(browser_view()->IsTabStripVisible()); |
| 456 #endif | 463 #endif |
| 457 | 464 |
| 458 const gfx::ImageSkia incognito_icon = GetOTRAvatarIcon(); | 465 const gfx::ImageSkia incognito_icon = GetOTRAvatarIcon(); |
| 459 const gfx::Insets avatar_insets = GetLayoutInsets(AVATAR_ICON); | 466 const gfx::Insets avatar_insets = GetLayoutInsets(AVATAR_ICON); |
| 460 const int avatar_bottom = GetTopInset(false) + | 467 const int avatar_bottom = GetTopInset(false) + |
| 461 browser_view()->GetTabStripHeight() - avatar_insets.bottom(); | 468 browser_view()->GetTabStripHeight() - avatar_insets.bottom(); |
| 462 int avatar_y = avatar_bottom - incognito_icon.height(); | 469 int avatar_y = avatar_bottom - incognito_icon.height(); |
| 463 if (!ui::MaterialDesignController::IsModeMaterial() && | 470 if (!ui::MaterialDesignController::IsModeMaterial() && |
| 464 browser_view()->IsTabStripVisible() && | 471 browser_view()->IsTabStripVisible() && |
| 465 (frame()->IsMaximized() || frame()->IsFullscreen())) { | 472 (frame()->IsMaximized() || frame()->IsFullscreen())) { |
| 466 avatar_y = GetTopInset(false) + kContentShadowHeight; | 473 avatar_y = GetTopInset(false) + kContentShadowHeight; |
| 467 } | 474 } |
| 468 | 475 |
| 469 // Hide the incognito icon in immersive fullscreen when the tab light bar is | 476 // Hide the incognito icon in immersive fullscreen when the tab light bar is |
| 470 // visible because the header is too short for the icognito icon to be | 477 // visible because the header is too short for the icognito icon to be |
| 471 // recognizable. | 478 // recognizable. |
| 472 const bool avatar_visible = !UseImmersiveLightbarHeaderStyle(); | 479 const bool avatar_visible = !UseImmersiveLightbarHeaderStyle(); |
| 473 const int avatar_height = avatar_visible ? (avatar_bottom - avatar_y) : 0; | 480 const int avatar_height = avatar_visible ? (avatar_bottom - avatar_y) : 0; |
| 474 avatar_button()->SetBounds(avatar_insets.left(), avatar_y, | 481 profile_indicator_icon()->SetBounds(avatar_insets.left(), avatar_y, |
| 475 incognito_icon.width(), avatar_height); | 482 incognito_icon.width(), avatar_height); |
| 476 avatar_button()->SetVisible(avatar_visible); | 483 profile_indicator_icon()->SetVisible(avatar_visible); |
| 477 } | 484 } |
| 478 | 485 |
| 479 bool BrowserNonClientFrameViewAsh::ShouldPaint() const { | 486 bool BrowserNonClientFrameViewAsh::ShouldPaint() const { |
| 480 if (!frame()->IsFullscreen()) | 487 if (!frame()->IsFullscreen()) |
| 481 return true; | 488 return true; |
| 482 | 489 |
| 483 // We need to paint when in immersive fullscreen and either: | 490 // We need to paint when in immersive fullscreen and either: |
| 484 // - The top-of-window views are revealed. | 491 // - The top-of-window views are revealed. |
| 485 // - The lightbar style tabstrip is visible. | 492 // - The lightbar style tabstrip is visible. |
| 486 ImmersiveModeController* immersive_mode_controller = | 493 ImmersiveModeController* immersive_mode_controller = |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 562 // TODO(pkasting): The "2 *" part of this makes no sense to me. | 569 // TODO(pkasting): The "2 *" part of this makes no sense to me. |
| 563 canvas->TileImageInt(*right, 0, 0, w - (2 * kClientEdgeThickness) - img_w, | 570 canvas->TileImageInt(*right, 0, 0, w - (2 * kClientEdgeThickness) - img_w, |
| 564 img_y, img_w, img_h); | 571 img_y, img_w, img_h); |
| 565 | 572 |
| 566 // Toolbar/content separator. | 573 // Toolbar/content separator. |
| 567 toolbar_bounds.Inset(kClientEdgeThickness, h - kClientEdgeThickness, | 574 toolbar_bounds.Inset(kClientEdgeThickness, h - kClientEdgeThickness, |
| 568 kClientEdgeThickness, 0); | 575 kClientEdgeThickness, 0); |
| 569 canvas->FillRect(toolbar_bounds, separator_color); | 576 canvas->FillRect(toolbar_bounds, separator_color); |
| 570 } | 577 } |
| 571 } | 578 } |
| OLD | NEW |