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 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 DCHECK(!tab_strip_); | 128 DCHECK(!tab_strip_); |
129 tab_strip_ = browser_view()->tabstrip(); | 129 tab_strip_ = browser_view()->tabstrip(); |
130 tab_strip_->AddObserver(this); | 130 tab_strip_->AddObserver(this); |
131 } | 131 } |
132 | 132 |
133 gfx::Rect BrowserNonClientFrameViewMus::GetBoundsForTabStrip( | 133 gfx::Rect BrowserNonClientFrameViewMus::GetBoundsForTabStrip( |
134 views::View* tabstrip) const { | 134 views::View* tabstrip) const { |
135 if (!tabstrip) | 135 if (!tabstrip) |
136 return gfx::Rect(); | 136 return gfx::Rect(); |
137 | 137 |
138 // When the tab strip is painted in the immersive fullscreen light bar style, | |
139 // the caption buttons and the avatar button are not visible. However, their | |
140 // bounds are still used to compute the tab strip bounds so that the tabs have | |
141 // the same horizontal position when the tab strip is painted in the immersive | |
142 // light bar style as when the top-of-window views are revealed. | |
143 int left_inset = GetTabStripLeftInset(); | 138 int left_inset = GetTabStripLeftInset(); |
144 int right_inset = GetTabStripRightInset(); | 139 int right_inset = GetTabStripRightInset(); |
145 return gfx::Rect(left_inset, GetTopInset(false), | 140 return gfx::Rect(left_inset, GetTopInset(false), |
146 std::max(0, width() - left_inset - right_inset), | 141 std::max(0, width() - left_inset - right_inset), |
147 tabstrip->GetPreferredSize().height()); | 142 tabstrip->GetPreferredSize().height()); |
148 } | 143 } |
149 | 144 |
150 int BrowserNonClientFrameViewMus::GetTopInset(bool restored) const { | 145 int BrowserNonClientFrameViewMus::GetTopInset(bool restored) const { |
151 if (!ShouldPaint() || UseImmersiveLightbarHeaderStyle()) | 146 if (!ShouldPaint()) { |
| 147 // When immersive fullscreen unrevealed, tabstrip is offscreen with normal |
| 148 // tapstrip bounds, the top inset should reach this topmost edge. |
| 149 const ImmersiveModeController* const immersive_controller = |
| 150 browser_view()->immersive_mode_controller(); |
| 151 if (immersive_controller->IsEnabled() && |
| 152 !immersive_controller->IsRevealed()) { |
| 153 return (-1) * browser_view()->GetTabStripHeight(); |
| 154 } |
152 return 0; | 155 return 0; |
| 156 } |
153 | 157 |
154 if (browser_view()->IsTabStripVisible()) { | 158 if (browser_view()->IsTabStripVisible()) { |
155 return ((frame()->IsMaximized() || frame()->IsFullscreen()) && !restored) | 159 return ((frame()->IsMaximized() || frame()->IsFullscreen()) && !restored) |
156 ? kTabstripTopSpacingShort | 160 ? kTabstripTopSpacingShort |
157 : kTabstripTopSpacingTall; | 161 : kTabstripTopSpacingTall; |
158 } | 162 } |
159 | 163 |
160 int caption_buttons_bottom = frame_values().normal_insets.top(); | 164 int caption_buttons_bottom = frame_values().normal_insets.top(); |
161 | 165 |
162 // The toolbar partially overlaps the caption buttons. | 166 // The toolbar partially overlaps the caption buttons. |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 | 293 |
290 void BrowserNonClientFrameViewMus::SizeConstraintsChanged() {} | 294 void BrowserNonClientFrameViewMus::SizeConstraintsChanged() {} |
291 | 295 |
292 /////////////////////////////////////////////////////////////////////////////// | 296 /////////////////////////////////////////////////////////////////////////////// |
293 // views::View: | 297 // views::View: |
294 | 298 |
295 void BrowserNonClientFrameViewMus::OnPaint(gfx::Canvas* canvas) { | 299 void BrowserNonClientFrameViewMus::OnPaint(gfx::Canvas* canvas) { |
296 if (!ShouldPaint()) | 300 if (!ShouldPaint()) |
297 return; | 301 return; |
298 | 302 |
299 // TODO(sky): get immersive mode working. | |
300 | |
301 if (UseImmersiveLightbarHeaderStyle()) { | |
302 PaintImmersiveLightbarStyleHeader(canvas); | |
303 return; | |
304 } | |
305 | |
306 if (browser_view()->IsToolbarVisible()) | 303 if (browser_view()->IsToolbarVisible()) |
307 PaintToolbarBackground(canvas); | 304 PaintToolbarBackground(canvas); |
308 else if (!UsePackagedAppHeaderStyle()) | 305 else if (!UsePackagedAppHeaderStyle()) |
309 PaintContentEdge(canvas); | 306 PaintContentEdge(canvas); |
310 } | 307 } |
311 | 308 |
312 void BrowserNonClientFrameViewMus::Layout() { | 309 void BrowserNonClientFrameViewMus::Layout() { |
313 if (profile_indicator_icon()) | 310 if (profile_indicator_icon()) |
314 LayoutIncognitoButton(); | 311 LayoutIncognitoButton(); |
315 | 312 |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
409 #if defined(FRAME_AVATAR_BUTTON) | 406 #if defined(FRAME_AVATAR_BUTTON) |
410 if (profile_switcher_.view()) { | 407 if (profile_switcher_.view()) { |
411 right_inset += kAvatarButtonOffset + | 408 right_inset += kAvatarButtonOffset + |
412 profile_switcher_.view()->GetPreferredSize().width(); | 409 profile_switcher_.view()->GetPreferredSize().width(); |
413 } | 410 } |
414 #endif | 411 #endif |
415 | 412 |
416 return right_inset; | 413 return right_inset; |
417 } | 414 } |
418 | 415 |
419 bool BrowserNonClientFrameViewMus::UseImmersiveLightbarHeaderStyle() const { | |
420 ImmersiveModeController* immersive_controller = | |
421 browser_view()->immersive_mode_controller(); | |
422 return immersive_controller->IsEnabled() && | |
423 !immersive_controller->IsRevealed() && | |
424 browser_view()->IsTabStripVisible(); | |
425 } | |
426 | |
427 bool BrowserNonClientFrameViewMus::UsePackagedAppHeaderStyle() const { | 416 bool BrowserNonClientFrameViewMus::UsePackagedAppHeaderStyle() const { |
428 // Use for non tabbed trusted source windows, e.g. Settings, as well as apps. | 417 // Use for non tabbed trusted source windows, e.g. Settings, as well as apps. |
429 const Browser* const browser = browser_view()->browser(); | 418 const Browser* const browser = browser_view()->browser(); |
430 return (!browser->is_type_tabbed() && browser->is_trusted_source()) || | 419 return (!browser->is_type_tabbed() && browser->is_trusted_source()) || |
431 browser->is_app(); | 420 browser->is_app(); |
432 } | 421 } |
433 | 422 |
434 void BrowserNonClientFrameViewMus::LayoutIncognitoButton() { | 423 void BrowserNonClientFrameViewMus::LayoutIncognitoButton() { |
435 DCHECK(profile_indicator_icon()); | 424 DCHECK(profile_indicator_icon()); |
436 #if !defined(OS_CHROMEOS) | 425 #if !defined(OS_CHROMEOS) |
437 // ChromeOS shows avatar on V1 app. | 426 // ChromeOS shows avatar on V1 app. |
438 DCHECK(browser_view()->IsTabStripVisible()); | 427 DCHECK(browser_view()->IsTabStripVisible()); |
439 #endif | 428 #endif |
440 gfx::ImageSkia incognito_icon = GetIncognitoAvatarIcon(); | 429 gfx::ImageSkia incognito_icon = GetIncognitoAvatarIcon(); |
441 int avatar_bottom = GetTopInset(false) + browser_view()->GetTabStripHeight() - | 430 int avatar_bottom = GetTopInset(false) + browser_view()->GetTabStripHeight() - |
442 kAvatarIconPadding; | 431 kAvatarIconPadding; |
443 int avatar_y = avatar_bottom - incognito_icon.height(); | 432 int avatar_y = avatar_bottom - incognito_icon.height(); |
444 | 433 int avatar_height = incognito_icon.height(); |
445 // Hide the incognito icon in immersive fullscreen when the tab light bar is | |
446 // visible because the header is too short for the icognito icon to be | |
447 // recognizable. | |
448 bool avatar_visible = !UseImmersiveLightbarHeaderStyle(); | |
449 int avatar_height = avatar_visible ? incognito_icon.height() : 0; | |
450 | 434 |
451 gfx::Rect avatar_bounds(kAvatarIconPadding, avatar_y, incognito_icon.width(), | 435 gfx::Rect avatar_bounds(kAvatarIconPadding, avatar_y, incognito_icon.width(), |
452 avatar_height); | 436 avatar_height); |
453 profile_indicator_icon()->SetBoundsRect(avatar_bounds); | 437 profile_indicator_icon()->SetBoundsRect(avatar_bounds); |
454 profile_indicator_icon()->SetVisible(avatar_visible); | 438 profile_indicator_icon()->SetVisible(true); |
455 } | 439 } |
456 | 440 |
457 void BrowserNonClientFrameViewMus::LayoutProfileSwitcher() { | 441 void BrowserNonClientFrameViewMus::LayoutProfileSwitcher() { |
458 #if defined(FRAME_AVATAR_BUTTON) | 442 #if defined(FRAME_AVATAR_BUTTON) |
459 gfx::Size button_size = profile_switcher_.view()->GetPreferredSize(); | 443 gfx::Size button_size = profile_switcher_.view()->GetPreferredSize(); |
460 int button_x = width() - GetTabStripRightInset() + kAvatarButtonOffset; | 444 int button_x = width() - GetTabStripRightInset() + kAvatarButtonOffset; |
461 profile_switcher_.view()->SetBounds(button_x, 0, button_size.width(), | 445 profile_switcher_.view()->SetBounds(button_x, 0, button_size.width(), |
462 button_size.height()); | 446 button_size.height()); |
463 #endif | 447 #endif |
464 } | 448 } |
465 | 449 |
466 bool BrowserNonClientFrameViewMus::ShouldPaint() const { | 450 bool BrowserNonClientFrameViewMus::ShouldPaint() const { |
467 if (!frame()->IsFullscreen()) | 451 if (!frame()->IsFullscreen()) |
468 return true; | 452 return true; |
469 | 453 |
470 // We need to paint when in immersive fullscreen and either: | 454 // We need to paint when the top-of-window views are revealed in immersive |
471 // - The top-of-window views are revealed. | 455 // fullscreen. |
472 // - The lightbar style tabstrip is visible. | |
473 ImmersiveModeController* immersive_mode_controller = | 456 ImmersiveModeController* immersive_mode_controller = |
474 browser_view()->immersive_mode_controller(); | 457 browser_view()->immersive_mode_controller(); |
475 return immersive_mode_controller->IsEnabled() && | 458 return immersive_mode_controller->IsEnabled() && |
476 (immersive_mode_controller->IsRevealed() || | 459 immersive_mode_controller->IsRevealed(); |
477 UseImmersiveLightbarHeaderStyle()); | |
478 } | 460 } |
479 | 461 |
480 void BrowserNonClientFrameViewMus::PaintImmersiveLightbarStyleHeader( | |
481 gfx::Canvas* canvas) {} | |
482 | |
483 void BrowserNonClientFrameViewMus::PaintToolbarBackground(gfx::Canvas* canvas) { | 462 void BrowserNonClientFrameViewMus::PaintToolbarBackground(gfx::Canvas* canvas) { |
484 gfx::Rect toolbar_bounds(browser_view()->GetToolbarBounds()); | 463 gfx::Rect toolbar_bounds(browser_view()->GetToolbarBounds()); |
485 if (toolbar_bounds.IsEmpty()) | 464 if (toolbar_bounds.IsEmpty()) |
486 return; | 465 return; |
487 gfx::Point toolbar_origin(toolbar_bounds.origin()); | 466 gfx::Point toolbar_origin(toolbar_bounds.origin()); |
488 View::ConvertPointToTarget(browser_view(), this, &toolbar_origin); | 467 View::ConvertPointToTarget(browser_view(), this, &toolbar_origin); |
489 toolbar_bounds.set_origin(toolbar_origin); | 468 toolbar_bounds.set_origin(toolbar_origin); |
490 const ui::ThemeProvider* tp = GetThemeProvider(); | 469 const ui::ThemeProvider* tp = GetThemeProvider(); |
491 | 470 |
492 // Background. | 471 // Background. |
(...skipping 28 matching lines...) Expand all Loading... |
521 } | 500 } |
522 | 501 |
523 void BrowserNonClientFrameViewMus::PaintContentEdge(gfx::Canvas* canvas) { | 502 void BrowserNonClientFrameViewMus::PaintContentEdge(gfx::Canvas* canvas) { |
524 DCHECK(!UsePackagedAppHeaderStyle()); | 503 DCHECK(!UsePackagedAppHeaderStyle()); |
525 const int bottom = frame_values().normal_insets.bottom(); | 504 const int bottom = frame_values().normal_insets.bottom(); |
526 canvas->FillRect( | 505 canvas->FillRect( |
527 gfx::Rect(0, bottom, width(), kClientEdgeThickness), | 506 gfx::Rect(0, bottom, width(), kClientEdgeThickness), |
528 GetThemeProvider()->GetColor( | 507 GetThemeProvider()->GetColor( |
529 ThemeProperties::COLOR_TOOLBAR_BOTTOM_SEPARATOR)); | 508 ThemeProperties::COLOR_TOOLBAR_BOTTOM_SEPARATOR)); |
530 } | 509 } |
OLD | NEW |