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() || IsImmersiveFullscreenUnrevealed()) |
152 return 0; | 147 return 0; |
153 | 148 |
154 if (browser_view()->IsTabStripVisible()) { | 149 if (browser_view()->IsTabStripVisible()) { |
155 return ((frame()->IsMaximized() || frame()->IsFullscreen()) && !restored) | 150 return ((frame()->IsMaximized() || frame()->IsFullscreen()) && !restored) |
156 ? kTabstripTopSpacingShort | 151 ? kTabstripTopSpacingShort |
157 : kTabstripTopSpacingTall; | 152 : kTabstripTopSpacingTall; |
158 } | 153 } |
159 | 154 |
160 int caption_buttons_bottom = frame_values().normal_insets.top(); | 155 int caption_buttons_bottom = frame_values().normal_insets.top(); |
161 | 156 |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 | 284 |
290 void BrowserNonClientFrameViewMus::SizeConstraintsChanged() {} | 285 void BrowserNonClientFrameViewMus::SizeConstraintsChanged() {} |
291 | 286 |
292 /////////////////////////////////////////////////////////////////////////////// | 287 /////////////////////////////////////////////////////////////////////////////// |
293 // views::View: | 288 // views::View: |
294 | 289 |
295 void BrowserNonClientFrameViewMus::OnPaint(gfx::Canvas* canvas) { | 290 void BrowserNonClientFrameViewMus::OnPaint(gfx::Canvas* canvas) { |
296 if (!ShouldPaint()) | 291 if (!ShouldPaint()) |
297 return; | 292 return; |
298 | 293 |
299 // TODO(sky): get immersive mode working. | |
300 | |
301 if (UseImmersiveLightbarHeaderStyle()) { | |
302 PaintImmersiveLightbarStyleHeader(canvas); | |
303 return; | |
304 } | |
305 | |
306 if (browser_view()->IsToolbarVisible()) | 294 if (browser_view()->IsToolbarVisible()) |
307 PaintToolbarBackground(canvas); | 295 PaintToolbarBackground(canvas); |
308 else if (!UsePackagedAppHeaderStyle()) | 296 else if (!UsePackagedAppHeaderStyle()) |
309 PaintContentEdge(canvas); | 297 PaintContentEdge(canvas); |
310 } | 298 } |
311 | 299 |
312 void BrowserNonClientFrameViewMus::Layout() { | 300 void BrowserNonClientFrameViewMus::Layout() { |
313 if (profile_indicator_icon()) | 301 if (profile_indicator_icon()) |
314 LayoutIncognitoButton(); | 302 LayoutIncognitoButton(); |
315 | 303 |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
409 #if defined(FRAME_AVATAR_BUTTON) | 397 #if defined(FRAME_AVATAR_BUTTON) |
410 if (profile_switcher_.view()) { | 398 if (profile_switcher_.view()) { |
411 right_inset += kAvatarButtonOffset + | 399 right_inset += kAvatarButtonOffset + |
412 profile_switcher_.view()->GetPreferredSize().width(); | 400 profile_switcher_.view()->GetPreferredSize().width(); |
413 } | 401 } |
414 #endif | 402 #endif |
415 | 403 |
416 return right_inset; | 404 return right_inset; |
417 } | 405 } |
418 | 406 |
419 bool BrowserNonClientFrameViewMus::UseImmersiveLightbarHeaderStyle() const { | 407 bool BrowserNonClientFrameViewMus::IsImmersiveFullscreenUnrevealed() const { |
420 ImmersiveModeController* immersive_controller = | 408 ImmersiveModeController* immersive_controller = |
421 browser_view()->immersive_mode_controller(); | 409 browser_view()->immersive_mode_controller(); |
422 return immersive_controller->IsEnabled() && | 410 return immersive_controller->IsEnabled() && |
423 !immersive_controller->IsRevealed() && | 411 !immersive_controller->IsRevealed(); |
424 browser_view()->IsTabStripVisible(); | |
425 } | 412 } |
426 | 413 |
427 bool BrowserNonClientFrameViewMus::UsePackagedAppHeaderStyle() const { | 414 bool BrowserNonClientFrameViewMus::UsePackagedAppHeaderStyle() const { |
428 // Use for non tabbed trusted source windows, e.g. Settings, as well as apps. | 415 // Use for non tabbed trusted source windows, e.g. Settings, as well as apps. |
429 const Browser* const browser = browser_view()->browser(); | 416 const Browser* const browser = browser_view()->browser(); |
430 return (!browser->is_type_tabbed() && browser->is_trusted_source()) || | 417 return (!browser->is_type_tabbed() && browser->is_trusted_source()) || |
431 browser->is_app(); | 418 browser->is_app(); |
432 } | 419 } |
433 | 420 |
434 void BrowserNonClientFrameViewMus::LayoutIncognitoButton() { | 421 void BrowserNonClientFrameViewMus::LayoutIncognitoButton() { |
435 DCHECK(profile_indicator_icon()); | 422 DCHECK(profile_indicator_icon()); |
436 #if !defined(OS_CHROMEOS) | 423 #if !defined(OS_CHROMEOS) |
437 // ChromeOS shows avatar on V1 app. | 424 // ChromeOS shows avatar on V1 app. |
438 DCHECK(browser_view()->IsTabStripVisible()); | 425 DCHECK(browser_view()->IsTabStripVisible()); |
439 #endif | 426 #endif |
440 gfx::ImageSkia incognito_icon = GetIncognitoAvatarIcon(); | 427 gfx::ImageSkia incognito_icon = GetIncognitoAvatarIcon(); |
441 int avatar_bottom = GetTopInset(false) + browser_view()->GetTabStripHeight() - | 428 int avatar_bottom = GetTopInset(false) + browser_view()->GetTabStripHeight() - |
442 kAvatarIconPadding; | 429 kAvatarIconPadding; |
443 int avatar_y = avatar_bottom - incognito_icon.height(); | 430 int avatar_y = avatar_bottom - incognito_icon.height(); |
444 | 431 |
445 // Hide the incognito icon in immersive fullscreen when the tab light bar is | 432 // Hide the incognito icon in immersive fullscreen unrevealed state because |
446 // visible because the header is too short for the icognito icon to be | 433 // the header height is zero for displaying the icon. |
447 // recognizable. | 434 bool avatar_visible = !IsImmersiveFullscreenUnrevealed(); |
448 bool avatar_visible = !UseImmersiveLightbarHeaderStyle(); | |
449 int avatar_height = avatar_visible ? incognito_icon.height() : 0; | 435 int avatar_height = avatar_visible ? incognito_icon.height() : 0; |
450 | 436 |
451 gfx::Rect avatar_bounds(kAvatarIconPadding, avatar_y, incognito_icon.width(), | 437 gfx::Rect avatar_bounds(kAvatarIconPadding, avatar_y, incognito_icon.width(), |
452 avatar_height); | 438 avatar_height); |
453 profile_indicator_icon()->SetBoundsRect(avatar_bounds); | 439 profile_indicator_icon()->SetBoundsRect(avatar_bounds); |
454 profile_indicator_icon()->SetVisible(avatar_visible); | 440 profile_indicator_icon()->SetVisible(avatar_visible); |
455 } | 441 } |
456 | 442 |
457 void BrowserNonClientFrameViewMus::LayoutProfileSwitcher() { | 443 void BrowserNonClientFrameViewMus::LayoutProfileSwitcher() { |
458 #if defined(FRAME_AVATAR_BUTTON) | 444 #if defined(FRAME_AVATAR_BUTTON) |
459 gfx::Size button_size = profile_switcher_.view()->GetPreferredSize(); | 445 gfx::Size button_size = profile_switcher_.view()->GetPreferredSize(); |
460 int button_x = width() - GetTabStripRightInset() + kAvatarButtonOffset; | 446 int button_x = width() - GetTabStripRightInset() + kAvatarButtonOffset; |
461 profile_switcher_.view()->SetBounds(button_x, 0, button_size.width(), | 447 profile_switcher_.view()->SetBounds(button_x, 0, button_size.width(), |
462 button_size.height()); | 448 button_size.height()); |
463 #endif | 449 #endif |
464 } | 450 } |
465 | 451 |
466 bool BrowserNonClientFrameViewMus::ShouldPaint() const { | 452 bool BrowserNonClientFrameViewMus::ShouldPaint() const { |
467 if (!frame()->IsFullscreen()) | 453 if (!frame()->IsFullscreen()) |
468 return true; | 454 return true; |
469 | 455 |
470 // We need to paint when in immersive fullscreen and either: | 456 // We need to paint when the top-of-window views are revealed in immersive |
471 // - The top-of-window views are revealed. | 457 // fullscreen. |
472 // - The lightbar style tabstrip is visible. | |
473 ImmersiveModeController* immersive_mode_controller = | 458 ImmersiveModeController* immersive_mode_controller = |
474 browser_view()->immersive_mode_controller(); | 459 browser_view()->immersive_mode_controller(); |
475 return immersive_mode_controller->IsEnabled() && | 460 return immersive_mode_controller->IsEnabled() && |
476 (immersive_mode_controller->IsRevealed() || | 461 immersive_mode_controller->IsRevealed(); |
477 UseImmersiveLightbarHeaderStyle()); | |
478 } | 462 } |
479 | 463 |
480 void BrowserNonClientFrameViewMus::PaintImmersiveLightbarStyleHeader( | |
481 gfx::Canvas* canvas) {} | |
482 | |
483 void BrowserNonClientFrameViewMus::PaintToolbarBackground(gfx::Canvas* canvas) { | 464 void BrowserNonClientFrameViewMus::PaintToolbarBackground(gfx::Canvas* canvas) { |
484 gfx::Rect toolbar_bounds(browser_view()->GetToolbarBounds()); | 465 gfx::Rect toolbar_bounds(browser_view()->GetToolbarBounds()); |
485 if (toolbar_bounds.IsEmpty()) | 466 if (toolbar_bounds.IsEmpty()) |
486 return; | 467 return; |
487 gfx::Point toolbar_origin(toolbar_bounds.origin()); | 468 gfx::Point toolbar_origin(toolbar_bounds.origin()); |
488 View::ConvertPointToTarget(browser_view(), this, &toolbar_origin); | 469 View::ConvertPointToTarget(browser_view(), this, &toolbar_origin); |
489 toolbar_bounds.set_origin(toolbar_origin); | 470 toolbar_bounds.set_origin(toolbar_origin); |
490 const ui::ThemeProvider* tp = GetThemeProvider(); | 471 const ui::ThemeProvider* tp = GetThemeProvider(); |
491 | 472 |
492 // Background. | 473 // Background. |
(...skipping 28 matching lines...) Expand all Loading... |
521 } | 502 } |
522 | 503 |
523 void BrowserNonClientFrameViewMus::PaintContentEdge(gfx::Canvas* canvas) { | 504 void BrowserNonClientFrameViewMus::PaintContentEdge(gfx::Canvas* canvas) { |
524 DCHECK(!UsePackagedAppHeaderStyle()); | 505 DCHECK(!UsePackagedAppHeaderStyle()); |
525 const int bottom = frame_values().normal_insets.bottom(); | 506 const int bottom = frame_values().normal_insets.bottom(); |
526 canvas->FillRect( | 507 canvas->FillRect( |
527 gfx::Rect(0, bottom, width(), kClientEdgeThickness), | 508 gfx::Rect(0, bottom, width(), kClientEdgeThickness), |
528 GetThemeProvider()->GetColor( | 509 GetThemeProvider()->GetColor( |
529 ThemeProperties::COLOR_TOOLBAR_BOTTOM_SEPARATOR)); | 510 ThemeProperties::COLOR_TOOLBAR_BOTTOM_SEPARATOR)); |
530 } | 511 } |
OLD | NEW |