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