 Chromium Code Reviews
 Chromium Code Reviews Issue 2690443002:
  cros-md: Remove the non-MD immersive mode code paths  (Closed)
    
  
    Issue 2690443002:
  cros-md: Remove the non-MD immersive mode code paths  (Closed) 
  | 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/common/ash_layout_constants.h" | 9 #include "ash/common/ash_layout_constants.h" | 
| 10 #include "ash/common/frame/caption_buttons/frame_caption_button_container_view.h " | 10 #include "ash/common/frame/caption_buttons/frame_caption_button_container_view.h " | 
| 11 #include "ash/common/frame/default_header_painter.h" | 11 #include "ash/common/frame/default_header_painter.h" | 
| 12 #include "ash/common/frame/frame_border_hit_test.h" | 12 #include "ash/common/frame/frame_border_hit_test.h" | 
| 13 #include "ash/common/frame/header_painter_util.h" | 13 #include "ash/common/frame/header_painter_util.h" | 
| 14 #include "ash/common/material_design/material_design_controller.h" | |
| 15 #include "ash/common/wm_lookup.h" | 14 #include "ash/common/wm_lookup.h" | 
| 16 #include "ash/common/wm_shell.h" | 15 #include "ash/common/wm_shell.h" | 
| 17 #include "ash/common/wm_window.h" | 16 #include "ash/common/wm_window.h" | 
| 18 #include "base/feature_list.h" | 17 #include "base/feature_list.h" | 
| 19 #include "build/build_config.h" | 18 #include "build/build_config.h" | 
| 20 #include "chrome/browser/profiles/profiles_state.h" | 19 #include "chrome/browser/profiles/profiles_state.h" | 
| 21 #include "chrome/browser/themes/theme_properties.h" | 20 #include "chrome/browser/themes/theme_properties.h" | 
| 22 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h" | 21 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h" | 
| 23 #include "chrome/browser/ui/browser.h" | 22 #include "chrome/browser/ui/browser.h" | 
| 24 #include "chrome/browser/ui/layout_constants.h" | 23 #include "chrome/browser/ui/layout_constants.h" | 
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 130 } | 129 } | 
| 131 | 130 | 
| 132 /////////////////////////////////////////////////////////////////////////////// | 131 /////////////////////////////////////////////////////////////////////////////// | 
| 133 // BrowserNonClientFrameView: | 132 // BrowserNonClientFrameView: | 
| 134 | 133 | 
| 135 gfx::Rect BrowserNonClientFrameViewAsh::GetBoundsForTabStrip( | 134 gfx::Rect BrowserNonClientFrameViewAsh::GetBoundsForTabStrip( | 
| 136 views::View* tabstrip) const { | 135 views::View* tabstrip) const { | 
| 137 if (!tabstrip) | 136 if (!tabstrip) | 
| 138 return gfx::Rect(); | 137 return gfx::Rect(); | 
| 139 | 138 | 
| 140 // When the tab strip is painted in the immersive fullscreen light bar style, | |
| 141 // the caption buttons and the avatar button are not visible. However, their | |
| 142 // bounds are still used to compute the tab strip bounds so that the tabs have | |
| 143 // the same horizontal position when the tab strip is painted in the immersive | |
| 144 // light bar style as when the top-of-window views are revealed. | |
| 145 const int left_inset = GetTabStripLeftInset(); | 139 const int left_inset = GetTabStripLeftInset(); | 
| 146 return gfx::Rect(left_inset, GetTopInset(false), | 140 return gfx::Rect(left_inset, GetTopInset(false), | 
| 147 std::max(0, width() - left_inset - GetTabStripRightInset()), | 141 std::max(0, width() - left_inset - GetTabStripRightInset()), | 
| 148 tabstrip->GetPreferredSize().height()); | 142 tabstrip->GetPreferredSize().height()); | 
| 149 } | 143 } | 
| 150 | 144 | 
| 151 int BrowserNonClientFrameViewAsh::GetTopInset(bool restored) const { | 145 int BrowserNonClientFrameViewAsh::GetTopInset(bool restored) const { | 
| 152 if (!ShouldPaint() || UseImmersiveLightbarHeaderStyle()) | 146 if (!ShouldPaint()) | 
| 153 return 0; | 147 return 0; | 
| 154 | 148 | 
| 155 if (!browser_view()->IsTabStripVisible()) { | 149 if (!browser_view()->IsTabStripVisible()) { | 
| 156 return (UsePackagedAppHeaderStyle()) | 150 return (UsePackagedAppHeaderStyle()) | 
| 157 ? header_painter_->GetHeaderHeight() | 151 ? header_painter_->GetHeaderHeight() | 
| 158 : caption_button_container_->bounds().bottom(); | 152 : caption_button_container_->bounds().bottom(); | 
| 159 } | 153 } | 
| 160 | 154 | 
| 161 const int header_height = restored | 155 const int header_height = restored | 
| 162 ? GetAshLayoutSize( | 156 ? GetAshLayoutSize( | 
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 209 | 203 | 
| 210 return hit_test; | 204 return hit_test; | 
| 211 } | 205 } | 
| 212 | 206 | 
| 213 void BrowserNonClientFrameViewAsh::GetWindowMask(const gfx::Size& size, | 207 void BrowserNonClientFrameViewAsh::GetWindowMask(const gfx::Size& size, | 
| 214 gfx::Path* window_mask) { | 208 gfx::Path* window_mask) { | 
| 215 // Aura does not use window masks. | 209 // Aura does not use window masks. | 
| 216 } | 210 } | 
| 217 | 211 | 
| 218 void BrowserNonClientFrameViewAsh::ResetWindowControls() { | 212 void BrowserNonClientFrameViewAsh::ResetWindowControls() { | 
| 219 // Hide the caption buttons in immersive fullscreen when the tab light bar | 213 caption_button_container_->SetVisible(!IsImmersiveFullscreenUnrevealed()); | 
| 
sky
2017/02/14 22:40:57
Is this still needed? If so, why? Prior to your ch
 
Qiang(Joe) Xu
2017/02/15 05:57:02
hmm.. sorry about this, we should not need this.
 | |
| 220 // is visible because it's confusing when the user hovers or clicks in the | |
| 221 // top-right of the screen and hits one. | |
| 222 // TODO(yiyix): Update |caption_button_container_|'s visibility calculation | |
| 223 // when Chrome OS MD is enabled by default. | |
| 224 caption_button_container_->SetVisible(!UseImmersiveLightbarHeaderStyle()); | |
| 225 caption_button_container_->ResetWindowControls(); | 214 caption_button_container_->ResetWindowControls(); | 
| 226 } | 215 } | 
| 227 | 216 | 
| 228 void BrowserNonClientFrameViewAsh::UpdateWindowIcon() { | 217 void BrowserNonClientFrameViewAsh::UpdateWindowIcon() { | 
| 229 if (window_icon_) | 218 if (window_icon_) | 
| 230 window_icon_->SchedulePaint(); | 219 window_icon_->SchedulePaint(); | 
| 231 } | 220 } | 
| 232 | 221 | 
| 233 void BrowserNonClientFrameViewAsh::UpdateWindowTitle() { | 222 void BrowserNonClientFrameViewAsh::UpdateWindowTitle() { | 
| 234 if (!frame()->IsFullscreen()) | 223 if (!frame()->IsFullscreen()) | 
| 235 header_painter_->SchedulePaintForTitle(); | 224 header_painter_->SchedulePaintForTitle(); | 
| 236 } | 225 } | 
| 237 | 226 | 
| 238 void BrowserNonClientFrameViewAsh::SizeConstraintsChanged() { | 227 void BrowserNonClientFrameViewAsh::SizeConstraintsChanged() { | 
| 239 } | 228 } | 
| 240 | 229 | 
| 241 /////////////////////////////////////////////////////////////////////////////// | 230 /////////////////////////////////////////////////////////////////////////////// | 
| 242 // views::View: | 231 // views::View: | 
| 243 | 232 | 
| 244 void BrowserNonClientFrameViewAsh::OnPaint(gfx::Canvas* canvas) { | 233 void BrowserNonClientFrameViewAsh::OnPaint(gfx::Canvas* canvas) { | 
| 245 if (!ShouldPaint()) | 234 if (!ShouldPaint()) | 
| 246 return; | 235 return; | 
| 247 | 236 | 
| 248 if (UseImmersiveLightbarHeaderStyle()) { | |
| 249 // The light bar header is not themed because theming it does not look good. | |
| 250 canvas->FillRect( | |
| 251 gfx::Rect(width(), header_painter_->GetHeaderHeightForPainting()), | |
| 252 SK_ColorBLACK); | |
| 253 return; | |
| 254 } | |
| 255 | |
| 256 const bool should_paint_as_active = ShouldPaintAsActive(); | 237 const bool should_paint_as_active = ShouldPaintAsActive(); | 
| 257 caption_button_container_->SetPaintAsActive(should_paint_as_active); | 238 caption_button_container_->SetPaintAsActive(should_paint_as_active); | 
| 258 | 239 | 
| 259 const ash::HeaderPainter::Mode header_mode = should_paint_as_active ? | 240 const ash::HeaderPainter::Mode header_mode = should_paint_as_active ? | 
| 260 ash::HeaderPainter::MODE_ACTIVE : ash::HeaderPainter::MODE_INACTIVE; | 241 ash::HeaderPainter::MODE_ACTIVE : ash::HeaderPainter::MODE_INACTIVE; | 
| 261 header_painter_->PaintHeader(canvas, header_mode); | 242 header_painter_->PaintHeader(canvas, header_mode); | 
| 262 | 243 | 
| 263 if (browser_view()->IsToolbarVisible() && | 244 if (browser_view()->IsToolbarVisible() && | 
| 264 !browser_view()->toolbar()->GetPreferredSize().IsEmpty() && | 245 !browser_view()->toolbar()->GetPreferredSize().IsEmpty() && | 
| 265 browser_view()->IsTabStripVisible()) { | 246 browser_view()->IsTabStripVisible()) { | 
| 266 PaintToolbarBackground(canvas); | 247 PaintToolbarBackground(canvas); | 
| 267 } | 248 } | 
| 268 } | 249 } | 
| 269 | 250 | 
| 270 void BrowserNonClientFrameViewAsh::Layout() { | 251 void BrowserNonClientFrameViewAsh::Layout() { | 
| 271 // The header must be laid out before computing |painted_height| because the | 252 // The header must be laid out before computing |painted_height| because the | 
| 272 // computation of |painted_height| for app and popup windows depends on the | 253 // computation of |painted_height| for app and popup windows depends on the | 
| 273 // position of the window controls. | 254 // position of the window controls. | 
| 274 header_painter_->LayoutHeader(); | 255 header_painter_->LayoutHeader(); | 
| 275 | 256 | 
| 276 int painted_height = GetTopInset(false); | 257 int painted_height = GetTopInset(false); | 
| 277 if (browser_view()->IsTabStripVisible()) { | 258 if (browser_view()->IsTabStripVisible()) | 
| 278 const ImmersiveModeController* const immersive_controller = | 259 painted_height += browser_view()->tabstrip()->GetPreferredSize().height(); | 
| 279 browser_view()->immersive_mode_controller(); | |
| 280 if (!immersive_controller->IsEnabled() || | |
| 281 immersive_controller->IsRevealed() || | |
| 282 !ash::MaterialDesignController::IsImmersiveModeMaterial()) { | |
| 283 painted_height += browser_view()->tabstrip()->GetPreferredSize().height(); | |
| 284 } | |
| 285 } | |
| 286 | 260 | 
| 287 header_painter_->SetHeaderHeightForPainting(painted_height); | 261 header_painter_->SetHeaderHeightForPainting(painted_height); | 
| 288 | 262 | 
| 289 if (profile_indicator_icon()) | 263 if (profile_indicator_icon()) | 
| 290 LayoutProfileIndicatorIcon(); | 264 LayoutProfileIndicatorIcon(); | 
| 291 BrowserNonClientFrameView::Layout(); | 265 BrowserNonClientFrameView::Layout(); | 
| 292 frame()->GetNativeWindow()->SetProperty( | 266 frame()->GetNativeWindow()->SetProperty( | 
| 293 aura::client::kTopViewInset, | 267 aura::client::kTopViewInset, | 
| 294 browser_view()->IsTabStripVisible() ? 0 : GetTopInset(true)); | 268 browser_view()->IsTabStripVisible() ? 0 : GetTopInset(true)); | 
| 295 } | 269 } | 
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 395 ? (kAvatarIconPadding + GetIncognitoAvatarIcon().width()) | 369 ? (kAvatarIconPadding + GetIncognitoAvatarIcon().width()) | 
| 396 : 0; | 370 : 0; | 
| 397 return avatar_right + kAvatarIconPadding; | 371 return avatar_right + kAvatarIconPadding; | 
| 398 } | 372 } | 
| 399 | 373 | 
| 400 int BrowserNonClientFrameViewAsh::GetTabStripRightInset() const { | 374 int BrowserNonClientFrameViewAsh::GetTabStripRightInset() const { | 
| 401 return kTabstripRightSpacing + | 375 return kTabstripRightSpacing + | 
| 402 caption_button_container_->GetPreferredSize().width(); | 376 caption_button_container_->GetPreferredSize().width(); | 
| 403 } | 377 } | 
| 404 | 378 | 
| 405 bool BrowserNonClientFrameViewAsh::UseImmersiveLightbarHeaderStyle() const { | 379 bool BrowserNonClientFrameViewAsh::IsImmersiveFullscreenUnrevealed() const { | 
| 406 if (ash::MaterialDesignController::IsImmersiveModeMaterial()) | |
| 407 return false; | |
| 408 | |
| 409 const ImmersiveModeController* const immersive_controller = | 380 const ImmersiveModeController* const immersive_controller = | 
| 410 browser_view()->immersive_mode_controller(); | 381 browser_view()->immersive_mode_controller(); | 
| 411 return immersive_controller->IsEnabled() && | 382 return immersive_controller->IsEnabled() && | 
| 412 !immersive_controller->IsRevealed() && | 383 !immersive_controller->IsRevealed(); | 
| 413 browser_view()->IsTabStripVisible(); | |
| 414 } | 384 } | 
| 415 | 385 | 
| 416 bool BrowserNonClientFrameViewAsh::UsePackagedAppHeaderStyle() const { | 386 bool BrowserNonClientFrameViewAsh::UsePackagedAppHeaderStyle() const { | 
| 417 // Use for non tabbed trusted source windows, e.g. Settings, as well as apps. | 387 // Use for non tabbed trusted source windows, e.g. Settings, as well as apps. | 
| 418 const Browser* const browser = browser_view()->browser(); | 388 const Browser* const browser = browser_view()->browser(); | 
| 419 return (!browser->is_type_tabbed() && browser->is_trusted_source()) || | 389 return (!browser->is_type_tabbed() && browser->is_trusted_source()) || | 
| 420 browser->is_app(); | 390 browser->is_app(); | 
| 421 } | 391 } | 
| 422 | 392 | 
| 423 void BrowserNonClientFrameViewAsh::LayoutProfileIndicatorIcon() { | 393 void BrowserNonClientFrameViewAsh::LayoutProfileIndicatorIcon() { | 
| 424 DCHECK(profile_indicator_icon()); | 394 DCHECK(profile_indicator_icon()); | 
| 425 #if !defined(OS_CHROMEOS) | 395 #if !defined(OS_CHROMEOS) | 
| 426 // ChromeOS shows avatar on V1 app. | 396 // ChromeOS shows avatar on V1 app. | 
| 427 DCHECK(browser_view()->IsTabStripVisible()); | 397 DCHECK(browser_view()->IsTabStripVisible()); | 
| 428 #endif | 398 #endif | 
| 429 | 399 | 
| 430 const gfx::ImageSkia incognito_icon = GetIncognitoAvatarIcon(); | 400 const gfx::ImageSkia incognito_icon = GetIncognitoAvatarIcon(); | 
| 431 const int avatar_bottom = GetTopInset(false) + | 401 const int avatar_bottom = GetTopInset(false) + | 
| 432 browser_view()->GetTabStripHeight() - | 402 browser_view()->GetTabStripHeight() - | 
| 433 kAvatarIconPadding; | 403 kAvatarIconPadding; | 
| 434 int avatar_y = avatar_bottom - incognito_icon.height(); | 404 int avatar_y = avatar_bottom - incognito_icon.height(); | 
| 435 | 405 | 
| 436 // Hide the incognito icon in immersive fullscreen when the tab light bar is | 406 // Hide the incognito icon in immersive fullscreen unrevealed state because | 
| 437 // visible because the header is too short for the icognito icon to be | 407 // the header height is zero for displaying the icon. | 
| 438 // recognizable. | 408 const bool avatar_visible = !IsImmersiveFullscreenUnrevealed(); | 
| 439 const bool avatar_visible = !UseImmersiveLightbarHeaderStyle(); | |
| 440 const int avatar_height = avatar_visible ? (avatar_bottom - avatar_y) : 0; | 409 const int avatar_height = avatar_visible ? (avatar_bottom - avatar_y) : 0; | 
| 441 profile_indicator_icon()->SetBounds(kAvatarIconPadding, avatar_y, | 410 profile_indicator_icon()->SetBounds(kAvatarIconPadding, avatar_y, | 
| 442 incognito_icon.width(), avatar_height); | 411 incognito_icon.width(), avatar_height); | 
| 443 profile_indicator_icon()->SetVisible(avatar_visible); | 412 profile_indicator_icon()->SetVisible(avatar_visible); | 
| 444 } | 413 } | 
| 445 | 414 | 
| 446 bool BrowserNonClientFrameViewAsh::ShouldPaint() const { | 415 bool BrowserNonClientFrameViewAsh::ShouldPaint() const { | 
| 447 if (!frame()->IsFullscreen()) | 416 if (!frame()->IsFullscreen()) | 
| 448 return true; | 417 return true; | 
| 449 | 418 | 
| 450 // We need to paint when in immersive fullscreen and either: | 419 // We need to paint when the top-of-window views are revealed in immersive | 
| 451 // - The top-of-window views are revealed. | 420 // fullscreen. | 
| 452 // - The lightbar style tabstrip is visible. | |
| 453 ImmersiveModeController* immersive_mode_controller = | 421 ImmersiveModeController* immersive_mode_controller = | 
| 454 browser_view()->immersive_mode_controller(); | 422 browser_view()->immersive_mode_controller(); | 
| 455 return immersive_mode_controller->IsEnabled() && | 423 return immersive_mode_controller->IsEnabled() && | 
| 456 (immersive_mode_controller->IsRevealed() || | 424 immersive_mode_controller->IsRevealed(); | 
| 457 UseImmersiveLightbarHeaderStyle()); | |
| 458 } | 425 } | 
| 459 | 426 | 
| 460 void BrowserNonClientFrameViewAsh::PaintToolbarBackground(gfx::Canvas* canvas) { | 427 void BrowserNonClientFrameViewAsh::PaintToolbarBackground(gfx::Canvas* canvas) { | 
| 461 gfx::Rect toolbar_bounds(browser_view()->GetToolbarBounds()); | 428 gfx::Rect toolbar_bounds(browser_view()->GetToolbarBounds()); | 
| 462 if (toolbar_bounds.IsEmpty()) | 429 if (toolbar_bounds.IsEmpty()) | 
| 463 return; | 430 return; | 
| 464 gfx::Point toolbar_origin(toolbar_bounds.origin()); | 431 gfx::Point toolbar_origin(toolbar_bounds.origin()); | 
| 465 View::ConvertPointToTarget(browser_view(), this, &toolbar_origin); | 432 View::ConvertPointToTarget(browser_view(), this, &toolbar_origin); | 
| 466 toolbar_bounds.set_origin(toolbar_origin); | 433 toolbar_bounds.set_origin(toolbar_origin); | 
| 467 const ui::ThemeProvider* tp = GetThemeProvider(); | 434 const ui::ThemeProvider* tp = GetThemeProvider(); | 
| (...skipping 20 matching lines...) Expand all Loading... | |
| 488 toolbar_bounds.width(), 0); | 455 toolbar_bounds.width(), 0); | 
| 489 BrowserView::Paint1pxHorizontalLine(canvas, GetToolbarTopSeparatorColor(), | 456 BrowserView::Paint1pxHorizontalLine(canvas, GetToolbarTopSeparatorColor(), | 
| 490 separator_rect, true); | 457 separator_rect, true); | 
| 491 | 458 | 
| 492 // Toolbar/content separator. | 459 // Toolbar/content separator. | 
| 493 toolbar_bounds.Inset(kClientEdgeThickness, 0); | 460 toolbar_bounds.Inset(kClientEdgeThickness, 0); | 
| 494 BrowserView::Paint1pxHorizontalLine( | 461 BrowserView::Paint1pxHorizontalLine( | 
| 495 canvas, tp->GetColor(ThemeProperties::COLOR_TOOLBAR_BOTTOM_SEPARATOR), | 462 canvas, tp->GetColor(ThemeProperties::COLOR_TOOLBAR_BOTTOM_SEPARATOR), | 
| 496 toolbar_bounds, true); | 463 toolbar_bounds, true); | 
| 497 } | 464 } | 
| OLD | NEW |