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()) { |
| 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 } |
153 return 0; | 155 return 0; |
| 156 } |
154 | 157 |
155 if (!browser_view()->IsTabStripVisible()) { | 158 if (!browser_view()->IsTabStripVisible()) { |
156 return (UsePackagedAppHeaderStyle()) | 159 return (UsePackagedAppHeaderStyle()) |
157 ? header_painter_->GetHeaderHeight() | 160 ? header_painter_->GetHeaderHeight() |
158 : caption_button_container_->bounds().bottom(); | 161 : caption_button_container_->bounds().bottom(); |
159 } | 162 } |
160 | 163 |
161 const int header_height = restored | 164 const int header_height = restored |
162 ? GetAshLayoutSize( | 165 ? GetAshLayoutSize( |
163 AshLayoutSize::BROWSER_RESTORED_CAPTION_BUTTON).height() | 166 AshLayoutSize::BROWSER_RESTORED_CAPTION_BUTTON).height() |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 | 212 |
210 return hit_test; | 213 return hit_test; |
211 } | 214 } |
212 | 215 |
213 void BrowserNonClientFrameViewAsh::GetWindowMask(const gfx::Size& size, | 216 void BrowserNonClientFrameViewAsh::GetWindowMask(const gfx::Size& size, |
214 gfx::Path* window_mask) { | 217 gfx::Path* window_mask) { |
215 // Aura does not use window masks. | 218 // Aura does not use window masks. |
216 } | 219 } |
217 | 220 |
218 void BrowserNonClientFrameViewAsh::ResetWindowControls() { | 221 void BrowserNonClientFrameViewAsh::ResetWindowControls() { |
219 // Hide the caption buttons in immersive fullscreen when the tab light bar | 222 caption_button_container_->SetVisible(true); |
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(); | 223 caption_button_container_->ResetWindowControls(); |
226 } | 224 } |
227 | 225 |
228 void BrowserNonClientFrameViewAsh::UpdateWindowIcon() { | 226 void BrowserNonClientFrameViewAsh::UpdateWindowIcon() { |
229 if (window_icon_) | 227 if (window_icon_) |
230 window_icon_->SchedulePaint(); | 228 window_icon_->SchedulePaint(); |
231 } | 229 } |
232 | 230 |
233 void BrowserNonClientFrameViewAsh::UpdateWindowTitle() { | 231 void BrowserNonClientFrameViewAsh::UpdateWindowTitle() { |
234 if (!frame()->IsFullscreen()) | 232 if (!frame()->IsFullscreen()) |
235 header_painter_->SchedulePaintForTitle(); | 233 header_painter_->SchedulePaintForTitle(); |
236 } | 234 } |
237 | 235 |
238 void BrowserNonClientFrameViewAsh::SizeConstraintsChanged() { | 236 void BrowserNonClientFrameViewAsh::SizeConstraintsChanged() { |
239 } | 237 } |
240 | 238 |
241 /////////////////////////////////////////////////////////////////////////////// | 239 /////////////////////////////////////////////////////////////////////////////// |
242 // views::View: | 240 // views::View: |
243 | 241 |
244 void BrowserNonClientFrameViewAsh::OnPaint(gfx::Canvas* canvas) { | 242 void BrowserNonClientFrameViewAsh::OnPaint(gfx::Canvas* canvas) { |
245 if (!ShouldPaint()) | 243 if (!ShouldPaint()) |
246 return; | 244 return; |
247 | 245 |
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(); | 246 const bool should_paint_as_active = ShouldPaintAsActive(); |
257 caption_button_container_->SetPaintAsActive(should_paint_as_active); | 247 caption_button_container_->SetPaintAsActive(should_paint_as_active); |
258 | 248 |
259 const ash::HeaderPainter::Mode header_mode = should_paint_as_active ? | 249 const ash::HeaderPainter::Mode header_mode = should_paint_as_active ? |
260 ash::HeaderPainter::MODE_ACTIVE : ash::HeaderPainter::MODE_INACTIVE; | 250 ash::HeaderPainter::MODE_ACTIVE : ash::HeaderPainter::MODE_INACTIVE; |
261 header_painter_->PaintHeader(canvas, header_mode); | 251 header_painter_->PaintHeader(canvas, header_mode); |
262 | 252 |
263 if (browser_view()->IsToolbarVisible() && | 253 if (browser_view()->IsToolbarVisible() && |
264 !browser_view()->toolbar()->GetPreferredSize().IsEmpty() && | 254 !browser_view()->toolbar()->GetPreferredSize().IsEmpty() && |
265 browser_view()->IsTabStripVisible()) { | 255 browser_view()->IsTabStripVisible()) { |
266 PaintToolbarBackground(canvas); | 256 PaintToolbarBackground(canvas); |
267 } | 257 } |
268 } | 258 } |
269 | 259 |
270 void BrowserNonClientFrameViewAsh::Layout() { | 260 void BrowserNonClientFrameViewAsh::Layout() { |
271 // The header must be laid out before computing |painted_height| because the | 261 // 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 | 262 // computation of |painted_height| for app and popup windows depends on the |
273 // position of the window controls. | 263 // position of the window controls. |
274 header_painter_->LayoutHeader(); | 264 header_painter_->LayoutHeader(); |
275 | 265 |
276 int painted_height = GetTopInset(false); | 266 int painted_height = GetTopInset(false); |
277 if (browser_view()->IsTabStripVisible()) { | 267 if (browser_view()->IsTabStripVisible()) |
278 const ImmersiveModeController* const immersive_controller = | 268 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 | 269 |
287 header_painter_->SetHeaderHeightForPainting(painted_height); | 270 header_painter_->SetHeaderHeightForPainting(painted_height); |
288 | 271 |
289 if (profile_indicator_icon()) | 272 if (profile_indicator_icon()) |
290 LayoutProfileIndicatorIcon(); | 273 LayoutProfileIndicatorIcon(); |
291 BrowserNonClientFrameView::Layout(); | 274 BrowserNonClientFrameView::Layout(); |
292 frame()->GetNativeWindow()->SetProperty( | 275 frame()->GetNativeWindow()->SetProperty( |
293 aura::client::kTopViewInset, | 276 aura::client::kTopViewInset, |
294 browser_view()->IsTabStripVisible() ? 0 : GetTopInset(true)); | 277 browser_view()->IsTabStripVisible() ? 0 : GetTopInset(true)); |
295 } | 278 } |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
395 ? (kAvatarIconPadding + GetIncognitoAvatarIcon().width()) | 378 ? (kAvatarIconPadding + GetIncognitoAvatarIcon().width()) |
396 : 0; | 379 : 0; |
397 return avatar_right + kAvatarIconPadding; | 380 return avatar_right + kAvatarIconPadding; |
398 } | 381 } |
399 | 382 |
400 int BrowserNonClientFrameViewAsh::GetTabStripRightInset() const { | 383 int BrowserNonClientFrameViewAsh::GetTabStripRightInset() const { |
401 return kTabstripRightSpacing + | 384 return kTabstripRightSpacing + |
402 caption_button_container_->GetPreferredSize().width(); | 385 caption_button_container_->GetPreferredSize().width(); |
403 } | 386 } |
404 | 387 |
405 bool BrowserNonClientFrameViewAsh::UseImmersiveLightbarHeaderStyle() const { | |
406 if (ash::MaterialDesignController::IsImmersiveModeMaterial()) | |
407 return false; | |
408 | |
409 const ImmersiveModeController* const immersive_controller = | |
410 browser_view()->immersive_mode_controller(); | |
411 return immersive_controller->IsEnabled() && | |
412 !immersive_controller->IsRevealed() && | |
413 browser_view()->IsTabStripVisible(); | |
414 } | |
415 | |
416 bool BrowserNonClientFrameViewAsh::UsePackagedAppHeaderStyle() const { | 388 bool BrowserNonClientFrameViewAsh::UsePackagedAppHeaderStyle() const { |
417 // Use for non tabbed trusted source windows, e.g. Settings, as well as apps. | 389 // Use for non tabbed trusted source windows, e.g. Settings, as well as apps. |
418 const Browser* const browser = browser_view()->browser(); | 390 const Browser* const browser = browser_view()->browser(); |
419 return (!browser->is_type_tabbed() && browser->is_trusted_source()) || | 391 return (!browser->is_type_tabbed() && browser->is_trusted_source()) || |
420 browser->is_app(); | 392 browser->is_app(); |
421 } | 393 } |
422 | 394 |
423 void BrowserNonClientFrameViewAsh::LayoutProfileIndicatorIcon() { | 395 void BrowserNonClientFrameViewAsh::LayoutProfileIndicatorIcon() { |
424 DCHECK(profile_indicator_icon()); | 396 DCHECK(profile_indicator_icon()); |
425 #if !defined(OS_CHROMEOS) | 397 #if !defined(OS_CHROMEOS) |
426 // ChromeOS shows avatar on V1 app. | 398 // ChromeOS shows avatar on V1 app. |
427 DCHECK(browser_view()->IsTabStripVisible()); | 399 DCHECK(browser_view()->IsTabStripVisible()); |
428 #endif | 400 #endif |
429 | 401 |
430 const gfx::ImageSkia incognito_icon = GetIncognitoAvatarIcon(); | 402 const gfx::ImageSkia incognito_icon = GetIncognitoAvatarIcon(); |
431 const int avatar_bottom = GetTopInset(false) + | 403 const int avatar_bottom = GetTopInset(false) + |
432 browser_view()->GetTabStripHeight() - | 404 browser_view()->GetTabStripHeight() - |
433 kAvatarIconPadding; | 405 kAvatarIconPadding; |
434 int avatar_y = avatar_bottom - incognito_icon.height(); | 406 int avatar_y = avatar_bottom - incognito_icon.height(); |
435 | 407 |
436 // Hide the incognito icon in immersive fullscreen when the tab light bar is | 408 const int avatar_height = avatar_bottom - avatar_y; |
437 // visible because the header is too short for the icognito icon to be | |
438 // recognizable. | |
439 const bool avatar_visible = !UseImmersiveLightbarHeaderStyle(); | |
440 const int avatar_height = avatar_visible ? (avatar_bottom - avatar_y) : 0; | |
441 profile_indicator_icon()->SetBounds(kAvatarIconPadding, avatar_y, | 409 profile_indicator_icon()->SetBounds(kAvatarIconPadding, avatar_y, |
442 incognito_icon.width(), avatar_height); | 410 incognito_icon.width(), avatar_height); |
443 profile_indicator_icon()->SetVisible(avatar_visible); | 411 profile_indicator_icon()->SetVisible(true); |
444 } | 412 } |
445 | 413 |
446 bool BrowserNonClientFrameViewAsh::ShouldPaint() const { | 414 bool BrowserNonClientFrameViewAsh::ShouldPaint() const { |
447 if (!frame()->IsFullscreen()) | 415 if (!frame()->IsFullscreen()) |
448 return true; | 416 return true; |
449 | 417 |
450 // We need to paint when in immersive fullscreen and either: | 418 // We need to paint when the top-of-window views are revealed in immersive |
451 // - The top-of-window views are revealed. | 419 // fullscreen. |
452 // - The lightbar style tabstrip is visible. | |
453 ImmersiveModeController* immersive_mode_controller = | 420 ImmersiveModeController* immersive_mode_controller = |
454 browser_view()->immersive_mode_controller(); | 421 browser_view()->immersive_mode_controller(); |
455 return immersive_mode_controller->IsEnabled() && | 422 return immersive_mode_controller->IsEnabled() && |
456 (immersive_mode_controller->IsRevealed() || | 423 immersive_mode_controller->IsRevealed(); |
457 UseImmersiveLightbarHeaderStyle()); | |
458 } | 424 } |
459 | 425 |
460 void BrowserNonClientFrameViewAsh::PaintToolbarBackground(gfx::Canvas* canvas) { | 426 void BrowserNonClientFrameViewAsh::PaintToolbarBackground(gfx::Canvas* canvas) { |
461 gfx::Rect toolbar_bounds(browser_view()->GetToolbarBounds()); | 427 gfx::Rect toolbar_bounds(browser_view()->GetToolbarBounds()); |
462 if (toolbar_bounds.IsEmpty()) | 428 if (toolbar_bounds.IsEmpty()) |
463 return; | 429 return; |
464 gfx::Point toolbar_origin(toolbar_bounds.origin()); | 430 gfx::Point toolbar_origin(toolbar_bounds.origin()); |
465 View::ConvertPointToTarget(browser_view(), this, &toolbar_origin); | 431 View::ConvertPointToTarget(browser_view(), this, &toolbar_origin); |
466 toolbar_bounds.set_origin(toolbar_origin); | 432 toolbar_bounds.set_origin(toolbar_origin); |
467 const ui::ThemeProvider* tp = GetThemeProvider(); | 433 const ui::ThemeProvider* tp = GetThemeProvider(); |
(...skipping 20 matching lines...) Expand all Loading... |
488 toolbar_bounds.width(), 0); | 454 toolbar_bounds.width(), 0); |
489 BrowserView::Paint1pxHorizontalLine(canvas, GetToolbarTopSeparatorColor(), | 455 BrowserView::Paint1pxHorizontalLine(canvas, GetToolbarTopSeparatorColor(), |
490 separator_rect, true); | 456 separator_rect, true); |
491 | 457 |
492 // Toolbar/content separator. | 458 // Toolbar/content separator. |
493 toolbar_bounds.Inset(kClientEdgeThickness, 0); | 459 toolbar_bounds.Inset(kClientEdgeThickness, 0); |
494 BrowserView::Paint1pxHorizontalLine( | 460 BrowserView::Paint1pxHorizontalLine( |
495 canvas, tp->GetColor(ThemeProperties::COLOR_TOOLBAR_BOTTOM_SEPARATOR), | 461 canvas, tp->GetColor(ThemeProperties::COLOR_TOOLBAR_BOTTOM_SEPARATOR), |
496 toolbar_bounds, true); | 462 toolbar_bounds, true); |
497 } | 463 } |
OLD | NEW |