| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_mus.h" | 5 #include "chrome/browser/ui/views/frame/browser_non_client_frame_view_mus.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "chrome/browser/profiles/profiles_state.h" | 9 #include "chrome/browser/profiles/profiles_state.h" |
| 10 #include "chrome/browser/themes/theme_properties.h" | 10 #include "chrome/browser/themes/theme_properties.h" |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 DCHECK(!tab_strip_); | 127 DCHECK(!tab_strip_); |
| 128 tab_strip_ = browser_view()->tabstrip(); | 128 tab_strip_ = browser_view()->tabstrip(); |
| 129 tab_strip_->AddObserver(this); | 129 tab_strip_->AddObserver(this); |
| 130 } | 130 } |
| 131 | 131 |
| 132 gfx::Rect BrowserNonClientFrameViewMus::GetBoundsForTabStrip( | 132 gfx::Rect BrowserNonClientFrameViewMus::GetBoundsForTabStrip( |
| 133 views::View* tabstrip) const { | 133 views::View* tabstrip) const { |
| 134 if (!tabstrip) | 134 if (!tabstrip) |
| 135 return gfx::Rect(); | 135 return gfx::Rect(); |
| 136 | 136 |
| 137 // When the tab strip is painted in the immersive fullscreen light bar style, | |
| 138 // the caption buttons and the avatar button are not visible. However, their | |
| 139 // bounds are still used to compute the tab strip bounds so that the tabs have | |
| 140 // the same horizontal position when the tab strip is painted in the immersive | |
| 141 // light bar style as when the top-of-window views are revealed. | |
| 142 int left_inset = GetTabStripLeftInset(); | 137 int left_inset = GetTabStripLeftInset(); |
| 143 int right_inset = GetTabStripRightInset(); | 138 int right_inset = GetTabStripRightInset(); |
| 144 return gfx::Rect(left_inset, GetTopInset(false), | 139 return gfx::Rect(left_inset, GetTopInset(false), |
| 145 std::max(0, width() - left_inset - right_inset), | 140 std::max(0, width() - left_inset - right_inset), |
| 146 tabstrip->GetPreferredSize().height()); | 141 tabstrip->GetPreferredSize().height()); |
| 147 } | 142 } |
| 148 | 143 |
| 149 int BrowserNonClientFrameViewMus::GetTopInset(bool restored) const { | 144 int BrowserNonClientFrameViewMus::GetTopInset(bool restored) const { |
| 150 if (!ShouldPaint() || UseImmersiveLightbarHeaderStyle()) | 145 if (!ShouldPaint()) { |
| 146 // When immersive fullscreen unrevealed, tabstrip is offscreen with normal |
| 147 // tapstrip bounds, the top inset should reach this topmost edge. |
| 148 const ImmersiveModeController* const immersive_controller = |
| 149 browser_view()->immersive_mode_controller(); |
| 150 if (immersive_controller->IsEnabled() && |
| 151 !immersive_controller->IsRevealed()) { |
| 152 return (-1) * browser_view()->GetTabStripHeight(); |
| 153 } |
| 151 return 0; | 154 return 0; |
| 155 } |
| 152 | 156 |
| 153 if (browser_view()->IsTabStripVisible()) { | 157 if (browser_view()->IsTabStripVisible()) { |
| 154 return ((frame()->IsMaximized() || frame()->IsFullscreen()) && !restored) | 158 return ((frame()->IsMaximized() || frame()->IsFullscreen()) && !restored) |
| 155 ? kTabstripTopSpacingShort | 159 ? kTabstripTopSpacingShort |
| 156 : kTabstripTopSpacingTall; | 160 : kTabstripTopSpacingTall; |
| 157 } | 161 } |
| 158 | 162 |
| 159 int caption_buttons_bottom = frame_values().normal_insets.top(); | 163 int caption_buttons_bottom = frame_values().normal_insets.top(); |
| 160 | 164 |
| 161 // The toolbar partially overlaps the caption buttons. | 165 // The toolbar partially overlaps the caption buttons. |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 | 246 |
| 243 void BrowserNonClientFrameViewMus::SizeConstraintsChanged() {} | 247 void BrowserNonClientFrameViewMus::SizeConstraintsChanged() {} |
| 244 | 248 |
| 245 /////////////////////////////////////////////////////////////////////////////// | 249 /////////////////////////////////////////////////////////////////////////////// |
| 246 // views::View: | 250 // views::View: |
| 247 | 251 |
| 248 void BrowserNonClientFrameViewMus::OnPaint(gfx::Canvas* canvas) { | 252 void BrowserNonClientFrameViewMus::OnPaint(gfx::Canvas* canvas) { |
| 249 if (!ShouldPaint()) | 253 if (!ShouldPaint()) |
| 250 return; | 254 return; |
| 251 | 255 |
| 252 // TODO(sky): get immersive mode working. | |
| 253 | |
| 254 if (UseImmersiveLightbarHeaderStyle()) { | |
| 255 PaintImmersiveLightbarStyleHeader(canvas); | |
| 256 return; | |
| 257 } | |
| 258 | |
| 259 if (browser_view()->IsToolbarVisible()) | 256 if (browser_view()->IsToolbarVisible()) |
| 260 PaintToolbarBackground(canvas); | 257 PaintToolbarBackground(canvas); |
| 261 else if (!UsePackagedAppHeaderStyle()) | 258 else if (!UsePackagedAppHeaderStyle()) |
| 262 PaintContentEdge(canvas); | 259 PaintContentEdge(canvas); |
| 263 } | 260 } |
| 264 | 261 |
| 265 void BrowserNonClientFrameViewMus::Layout() { | 262 void BrowserNonClientFrameViewMus::Layout() { |
| 266 if (profile_indicator_icon()) | 263 if (profile_indicator_icon()) |
| 267 LayoutIncognitoButton(); | 264 LayoutIncognitoButton(); |
| 268 | 265 |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 377 #if defined(FRAME_AVATAR_BUTTON) | 374 #if defined(FRAME_AVATAR_BUTTON) |
| 378 if (profile_switcher_.view()) { | 375 if (profile_switcher_.view()) { |
| 379 right_inset += kAvatarButtonOffset + | 376 right_inset += kAvatarButtonOffset + |
| 380 profile_switcher_.view()->GetPreferredSize().width(); | 377 profile_switcher_.view()->GetPreferredSize().width(); |
| 381 } | 378 } |
| 382 #endif | 379 #endif |
| 383 | 380 |
| 384 return right_inset; | 381 return right_inset; |
| 385 } | 382 } |
| 386 | 383 |
| 387 bool BrowserNonClientFrameViewMus::UseImmersiveLightbarHeaderStyle() const { | |
| 388 ImmersiveModeController* immersive_controller = | |
| 389 browser_view()->immersive_mode_controller(); | |
| 390 return immersive_controller->IsEnabled() && | |
| 391 !immersive_controller->IsRevealed() && | |
| 392 browser_view()->IsTabStripVisible(); | |
| 393 } | |
| 394 | |
| 395 bool BrowserNonClientFrameViewMus::UsePackagedAppHeaderStyle() const { | 384 bool BrowserNonClientFrameViewMus::UsePackagedAppHeaderStyle() const { |
| 396 // Use for non tabbed trusted source windows, e.g. Settings, as well as apps. | 385 // Use for non tabbed trusted source windows, e.g. Settings, as well as apps. |
| 397 const Browser* const browser = browser_view()->browser(); | 386 const Browser* const browser = browser_view()->browser(); |
| 398 return (!browser->is_type_tabbed() && browser->is_trusted_source()) || | 387 return (!browser->is_type_tabbed() && browser->is_trusted_source()) || |
| 399 browser->is_app(); | 388 browser->is_app(); |
| 400 } | 389 } |
| 401 | 390 |
| 402 void BrowserNonClientFrameViewMus::LayoutIncognitoButton() { | 391 void BrowserNonClientFrameViewMus::LayoutIncognitoButton() { |
| 403 DCHECK(profile_indicator_icon()); | 392 DCHECK(profile_indicator_icon()); |
| 404 #if !defined(OS_CHROMEOS) | 393 #if !defined(OS_CHROMEOS) |
| 405 // ChromeOS shows avatar on V1 app. | 394 // ChromeOS shows avatar on V1 app. |
| 406 DCHECK(browser_view()->IsTabStripVisible()); | 395 DCHECK(browser_view()->IsTabStripVisible()); |
| 407 #endif | 396 #endif |
| 408 gfx::ImageSkia incognito_icon = GetIncognitoAvatarIcon(); | 397 gfx::ImageSkia incognito_icon = GetIncognitoAvatarIcon(); |
| 409 int avatar_bottom = GetTopInset(false) + browser_view()->GetTabStripHeight() - | 398 int avatar_bottom = GetTopInset(false) + browser_view()->GetTabStripHeight() - |
| 410 kAvatarIconPadding; | 399 kAvatarIconPadding; |
| 411 int avatar_y = avatar_bottom - incognito_icon.height(); | 400 int avatar_y = avatar_bottom - incognito_icon.height(); |
| 412 | 401 int avatar_height = incognito_icon.height(); |
| 413 // Hide the incognito icon in immersive fullscreen when the tab light bar is | |
| 414 // visible because the header is too short for the icognito icon to be | |
| 415 // recognizable. | |
| 416 bool avatar_visible = !UseImmersiveLightbarHeaderStyle(); | |
| 417 int avatar_height = avatar_visible ? incognito_icon.height() : 0; | |
| 418 | 402 |
| 419 gfx::Rect avatar_bounds(kAvatarIconPadding, avatar_y, incognito_icon.width(), | 403 gfx::Rect avatar_bounds(kAvatarIconPadding, avatar_y, incognito_icon.width(), |
| 420 avatar_height); | 404 avatar_height); |
| 421 profile_indicator_icon()->SetBoundsRect(avatar_bounds); | 405 profile_indicator_icon()->SetBoundsRect(avatar_bounds); |
| 422 profile_indicator_icon()->SetVisible(avatar_visible); | 406 profile_indicator_icon()->SetVisible(true); |
| 423 } | 407 } |
| 424 | 408 |
| 425 void BrowserNonClientFrameViewMus::LayoutProfileSwitcher() { | 409 void BrowserNonClientFrameViewMus::LayoutProfileSwitcher() { |
| 426 #if defined(FRAME_AVATAR_BUTTON) | 410 #if defined(FRAME_AVATAR_BUTTON) |
| 427 gfx::Size button_size = profile_switcher_.view()->GetPreferredSize(); | 411 gfx::Size button_size = profile_switcher_.view()->GetPreferredSize(); |
| 428 int button_x = width() - GetTabStripRightInset() + kAvatarButtonOffset; | 412 int button_x = width() - GetTabStripRightInset() + kAvatarButtonOffset; |
| 429 profile_switcher_.view()->SetBounds(button_x, 0, button_size.width(), | 413 profile_switcher_.view()->SetBounds(button_x, 0, button_size.width(), |
| 430 button_size.height()); | 414 button_size.height()); |
| 431 #endif | 415 #endif |
| 432 } | 416 } |
| 433 | 417 |
| 434 bool BrowserNonClientFrameViewMus::ShouldPaint() const { | 418 bool BrowserNonClientFrameViewMus::ShouldPaint() const { |
| 435 if (!frame()->IsFullscreen()) | 419 if (!frame()->IsFullscreen()) |
| 436 return true; | 420 return true; |
| 437 | 421 |
| 438 // We need to paint when in immersive fullscreen and either: | 422 // We need to paint when the top-of-window views are revealed in immersive |
| 439 // - The top-of-window views are revealed. | 423 // fullscreen. |
| 440 // - The lightbar style tabstrip is visible. | |
| 441 ImmersiveModeController* immersive_mode_controller = | 424 ImmersiveModeController* immersive_mode_controller = |
| 442 browser_view()->immersive_mode_controller(); | 425 browser_view()->immersive_mode_controller(); |
| 443 return immersive_mode_controller->IsEnabled() && | 426 return immersive_mode_controller->IsEnabled() && |
| 444 (immersive_mode_controller->IsRevealed() || | 427 immersive_mode_controller->IsRevealed(); |
| 445 UseImmersiveLightbarHeaderStyle()); | |
| 446 } | 428 } |
| 447 | 429 |
| 448 void BrowserNonClientFrameViewMus::PaintImmersiveLightbarStyleHeader( | |
| 449 gfx::Canvas* canvas) {} | |
| 450 | |
| 451 void BrowserNonClientFrameViewMus::PaintToolbarBackground(gfx::Canvas* canvas) { | 430 void BrowserNonClientFrameViewMus::PaintToolbarBackground(gfx::Canvas* canvas) { |
| 452 gfx::Rect toolbar_bounds(browser_view()->GetToolbarBounds()); | 431 gfx::Rect toolbar_bounds(browser_view()->GetToolbarBounds()); |
| 453 if (toolbar_bounds.IsEmpty()) | 432 if (toolbar_bounds.IsEmpty()) |
| 454 return; | 433 return; |
| 455 gfx::Point toolbar_origin(toolbar_bounds.origin()); | 434 gfx::Point toolbar_origin(toolbar_bounds.origin()); |
| 456 View::ConvertPointToTarget(browser_view(), this, &toolbar_origin); | 435 View::ConvertPointToTarget(browser_view(), this, &toolbar_origin); |
| 457 toolbar_bounds.set_origin(toolbar_origin); | 436 toolbar_bounds.set_origin(toolbar_origin); |
| 458 const ui::ThemeProvider* tp = GetThemeProvider(); | 437 const ui::ThemeProvider* tp = GetThemeProvider(); |
| 459 | 438 |
| 460 // Background. | 439 // Background. |
| (...skipping 28 matching lines...) Expand all Loading... |
| 489 } | 468 } |
| 490 | 469 |
| 491 void BrowserNonClientFrameViewMus::PaintContentEdge(gfx::Canvas* canvas) { | 470 void BrowserNonClientFrameViewMus::PaintContentEdge(gfx::Canvas* canvas) { |
| 492 DCHECK(!UsePackagedAppHeaderStyle()); | 471 DCHECK(!UsePackagedAppHeaderStyle()); |
| 493 const int bottom = frame_values().normal_insets.bottom(); | 472 const int bottom = frame_values().normal_insets.bottom(); |
| 494 canvas->FillRect( | 473 canvas->FillRect( |
| 495 gfx::Rect(0, bottom, width(), kClientEdgeThickness), | 474 gfx::Rect(0, bottom, width(), kClientEdgeThickness), |
| 496 GetThemeProvider()->GetColor( | 475 GetThemeProvider()->GetColor( |
| 497 ThemeProperties::COLOR_TOOLBAR_BOTTOM_SEPARATOR)); | 476 ThemeProperties::COLOR_TOOLBAR_BOTTOM_SEPARATOR)); |
| 498 } | 477 } |
| OLD | NEW |