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/app/chrome_command_ids.h" | |
10 #include "chrome/browser/extensions/extension_util.h" | |
11 #include "chrome/browser/profiles/profiles_state.h" | 9 #include "chrome/browser/profiles/profiles_state.h" |
12 #include "chrome/browser/themes/theme_properties.h" | 10 #include "chrome/browser/themes/theme_properties.h" |
13 #include "chrome/browser/ui/browser.h" | 11 #include "chrome/browser/ui/browser.h" |
14 #include "chrome/browser/ui/browser_commands.h" | |
15 #include "chrome/browser/ui/layout_constants.h" | 12 #include "chrome/browser/ui/layout_constants.h" |
16 #include "chrome/browser/ui/views/frame/browser_frame.h" | 13 #include "chrome/browser/ui/views/frame/browser_frame.h" |
17 #include "chrome/browser/ui/views/frame/browser_frame_mus.h" | 14 #include "chrome/browser/ui/views/frame/browser_frame_mus.h" |
18 #include "chrome/browser/ui/views/frame/browser_header_painter_ash.h" | 15 #include "chrome/browser/ui/views/frame/browser_header_painter_ash.h" |
19 #include "chrome/browser/ui/views/frame/browser_view.h" | 16 #include "chrome/browser/ui/views/frame/browser_view.h" |
20 #include "chrome/browser/ui/views/frame/immersive_mode_controller.h" | 17 #include "chrome/browser/ui/views/frame/immersive_mode_controller.h" |
21 #include "chrome/browser/ui/views/frame/web_app_left_header_view_ash.h" | 18 #include "chrome/browser/ui/views/frame/web_app_left_header_view_ash.h" |
22 #include "chrome/browser/ui/views/profiles/profile_indicator_icon.h" | 19 #include "chrome/browser/ui/views/profiles/profile_indicator_icon.h" |
23 #include "chrome/browser/ui/views/tab_icon_view.h" | 20 #include "chrome/browser/ui/views/tab_icon_view.h" |
24 #include "chrome/browser/ui/views/tabs/tab_strip.h" | 21 #include "chrome/browser/ui/views/tabs/tab_strip.h" |
25 #include "chrome/browser/web_applications/web_app.h" | 22 #include "chrome/browser/web_applications/web_app.h" |
26 #include "chrome/grit/theme_resources.h" | 23 #include "chrome/grit/theme_resources.h" |
27 #include "components/signin/core/common/profile_management_switches.h" | |
28 #include "content/public/browser/web_contents.h" | 24 #include "content/public/browser/web_contents.h" |
29 #include "extensions/browser/extension_registry.h" | |
30 #include "services/ui/public/cpp/window.h" | 25 #include "services/ui/public/cpp/window.h" |
31 #include "ui/accessibility/ax_view_state.h" | 26 #include "ui/accessibility/ax_view_state.h" |
32 #include "ui/aura/client/aura_constants.h" | 27 #include "ui/aura/client/aura_constants.h" |
33 #include "ui/aura/window.h" | 28 #include "ui/aura/window.h" |
34 #include "ui/base/hit_test.h" | 29 #include "ui/base/hit_test.h" |
35 #include "ui/base/layout.h" | 30 #include "ui/base/layout.h" |
36 #include "ui/base/material_design/material_design_controller.h" | |
37 #include "ui/base/resource/resource_bundle.h" | |
38 #include "ui/base/theme_provider.h" | 31 #include "ui/base/theme_provider.h" |
39 #include "ui/compositor/layer_animator.h" | 32 #include "ui/compositor/layer_animator.h" |
40 #include "ui/gfx/canvas.h" | 33 #include "ui/gfx/canvas.h" |
41 #include "ui/gfx/geometry/rect_conversions.h" | 34 #include "ui/gfx/geometry/rect_conversions.h" |
42 #include "ui/gfx/image/image_skia.h" | 35 #include "ui/gfx/image/image_skia.h" |
43 #include "ui/gfx/scoped_canvas.h" | 36 #include "ui/gfx/scoped_canvas.h" |
44 #include "ui/views/controls/label.h" | 37 #include "ui/views/controls/label.h" |
45 #include "ui/views/layout/layout_constants.h" | 38 #include "ui/views/layout/layout_constants.h" |
46 #include "ui/views/mus/window_manager_frame_values.h" | 39 #include "ui/views/mus/window_manager_frame_values.h" |
47 #include "ui/views/widget/widget.h" | 40 #include "ui/views/widget/widget.h" |
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
427 DCHECK(profile_indicator_icon()); | 420 DCHECK(profile_indicator_icon()); |
428 #if !defined(OS_CHROMEOS) | 421 #if !defined(OS_CHROMEOS) |
429 // ChromeOS shows avatar on V1 app. | 422 // ChromeOS shows avatar on V1 app. |
430 DCHECK(browser_view()->IsTabStripVisible()); | 423 DCHECK(browser_view()->IsTabStripVisible()); |
431 #endif | 424 #endif |
432 gfx::ImageSkia incognito_icon = GetIncognitoAvatarIcon(); | 425 gfx::ImageSkia incognito_icon = GetIncognitoAvatarIcon(); |
433 gfx::Insets avatar_insets = GetLayoutInsets(AVATAR_ICON); | 426 gfx::Insets avatar_insets = GetLayoutInsets(AVATAR_ICON); |
434 int avatar_bottom = GetTopInset(false) + browser_view()->GetTabStripHeight() - | 427 int avatar_bottom = GetTopInset(false) + browser_view()->GetTabStripHeight() - |
435 avatar_insets.bottom(); | 428 avatar_insets.bottom(); |
436 int avatar_y = avatar_bottom - incognito_icon.height(); | 429 int avatar_y = avatar_bottom - incognito_icon.height(); |
437 if (!ui::MaterialDesignController::IsModeMaterial() && | |
438 browser_view()->IsTabStripVisible() && | |
439 (frame()->IsMaximized() || frame()->IsFullscreen())) { | |
440 avatar_y = GetTopInset(false) + kContentShadowHeight; | |
441 } | |
442 | 430 |
443 // Hide the incognito icon in immersive fullscreen when the tab light bar is | 431 // Hide the incognito icon in immersive fullscreen when the tab light bar is |
444 // visible because the header is too short for the icognito icon to be | 432 // visible because the header is too short for the icognito icon to be |
445 // recognizable. | 433 // recognizable. |
446 bool avatar_visible = !UseImmersiveLightbarHeaderStyle(); | 434 bool avatar_visible = !UseImmersiveLightbarHeaderStyle(); |
447 int avatar_height = avatar_visible ? avatar_bottom - avatar_y : 0; | 435 int avatar_height = avatar_visible ? incognito_icon.height() : 0; |
448 | 436 |
449 gfx::Rect avatar_bounds(avatar_insets.left(), avatar_y, | 437 gfx::Rect avatar_bounds(avatar_insets.left(), avatar_y, |
450 incognito_icon.width(), avatar_height); | 438 incognito_icon.width(), avatar_height); |
451 profile_indicator_icon()->SetBoundsRect(avatar_bounds); | 439 profile_indicator_icon()->SetBoundsRect(avatar_bounds); |
452 profile_indicator_icon()->SetVisible(avatar_visible); | 440 profile_indicator_icon()->SetVisible(avatar_visible); |
453 } | 441 } |
454 | 442 |
455 void BrowserNonClientFrameViewMus::LayoutProfileSwitcher() { | 443 void BrowserNonClientFrameViewMus::LayoutProfileSwitcher() { |
456 #if defined(FRAME_AVATAR_BUTTON) | 444 #if defined(FRAME_AVATAR_BUTTON) |
457 gfx::Size button_size = profile_switcher_.view()->GetPreferredSize(); | 445 gfx::Size button_size = profile_switcher_.view()->GetPreferredSize(); |
(...skipping 20 matching lines...) Expand all Loading... |
478 void BrowserNonClientFrameViewMus::PaintImmersiveLightbarStyleHeader( | 466 void BrowserNonClientFrameViewMus::PaintImmersiveLightbarStyleHeader( |
479 gfx::Canvas* canvas) {} | 467 gfx::Canvas* canvas) {} |
480 | 468 |
481 void BrowserNonClientFrameViewMus::PaintToolbarBackground(gfx::Canvas* canvas) { | 469 void BrowserNonClientFrameViewMus::PaintToolbarBackground(gfx::Canvas* canvas) { |
482 gfx::Rect toolbar_bounds(browser_view()->GetToolbarBounds()); | 470 gfx::Rect toolbar_bounds(browser_view()->GetToolbarBounds()); |
483 if (toolbar_bounds.IsEmpty()) | 471 if (toolbar_bounds.IsEmpty()) |
484 return; | 472 return; |
485 gfx::Point toolbar_origin(toolbar_bounds.origin()); | 473 gfx::Point toolbar_origin(toolbar_bounds.origin()); |
486 View::ConvertPointToTarget(browser_view(), this, &toolbar_origin); | 474 View::ConvertPointToTarget(browser_view(), this, &toolbar_origin); |
487 toolbar_bounds.set_origin(toolbar_origin); | 475 toolbar_bounds.set_origin(toolbar_origin); |
488 | |
489 int x = toolbar_bounds.x(); | |
490 int w = toolbar_bounds.width(); | |
491 int y = toolbar_bounds.y(); | |
492 const ui::ThemeProvider* tp = GetThemeProvider(); | 476 const ui::ThemeProvider* tp = GetThemeProvider(); |
493 | 477 |
494 if (ui::MaterialDesignController::IsModeMaterial()) { | 478 // Background. |
495 if (tp->HasCustomImage(IDR_THEME_TOOLBAR)) { | 479 if (tp->HasCustomImage(IDR_THEME_TOOLBAR)) { |
496 // Paint the main toolbar image. Since this image is also used to draw | 480 const int bg_y = GetTopInset(false) + GetLayoutInsets(TAB).top(); |
497 // the tab background, we must use the tab strip offset to compute the | 481 const int x = toolbar_bounds.x(); |
498 // image source y position. If you have to debug this code use an image | 482 const int y = toolbar_bounds.y(); |
499 // editor to paint a diagonal line through the toolbar image and ensure it | 483 canvas->TileImageInt(*tp->GetImageSkiaNamed(IDR_THEME_TOOLBAR), |
500 // lines up across the tab and toolbar. | 484 x + GetThemeBackgroundXInset(), y - bg_y, x, y, |
501 gfx::ImageSkia* theme_toolbar = tp->GetImageSkiaNamed(IDR_THEME_TOOLBAR); | 485 toolbar_bounds.width(), toolbar_bounds.height()); |
502 canvas->TileImageInt(*theme_toolbar, x + GetThemeBackgroundXInset(), | 486 } else { |
503 y - GetTopInset(false), x, y, w, | 487 canvas->FillRect(toolbar_bounds, |
504 theme_toolbar->height()); | 488 tp->GetColor(ThemeProperties::COLOR_TOOLBAR)); |
505 } else { | 489 } |
506 canvas->FillRect(toolbar_bounds, | |
507 tp->GetColor(ThemeProperties::COLOR_TOOLBAR)); | |
508 } | |
509 | 490 |
510 // Draw the separator line atop the toolbar, on the left and right of the | 491 // Top stroke. |
511 // tabstrip. | 492 gfx::ScopedCanvas scoped_canvas(canvas); |
512 // TODO(tdanderson): Draw the separator line for non-tabbed windows. | 493 gfx::Rect tabstrip_bounds(GetBoundsForTabStrip(browser_view()->tabstrip())); |
513 if (browser_view()->IsTabStripVisible()) { | 494 tabstrip_bounds.set_x(GetMirroredXForRect(tabstrip_bounds)); |
514 gfx::Rect separator_rect(x, y, w, 0); | 495 canvas->ClipRect(tabstrip_bounds, SkRegion::kDifference_Op); |
515 gfx::ScopedCanvas scoped_canvas(canvas); | 496 const gfx::Rect separator_rect(toolbar_bounds.x(), tabstrip_bounds.bottom(), |
516 gfx::Rect tabstrip_bounds( | 497 toolbar_bounds.width(), 0); |
517 GetBoundsForTabStrip(browser_view()->tabstrip())); | 498 BrowserView::Paint1pxHorizontalLine(canvas, GetToolbarTopSeparatorColor(), |
518 tabstrip_bounds.set_x(GetMirroredXForRect(tabstrip_bounds)); | 499 separator_rect, true); |
519 canvas->ClipRect(tabstrip_bounds, SkRegion::kDifference_Op); | |
520 separator_rect.set_y(tabstrip_bounds.bottom()); | |
521 BrowserView::Paint1pxHorizontalLine(canvas, GetToolbarTopSeparatorColor(), | |
522 separator_rect, true); | |
523 } | |
524 | 500 |
525 // Draw the content/toolbar separator. | 501 // Toolbar/content separator. |
526 toolbar_bounds.Inset(kClientEdgeThickness, 0); | 502 toolbar_bounds.Inset(kClientEdgeThickness, 0); |
527 BrowserView::Paint1pxHorizontalLine( | 503 BrowserView::Paint1pxHorizontalLine( |
528 canvas, tp->GetColor(ThemeProperties::COLOR_TOOLBAR_BOTTOM_SEPARATOR), | 504 canvas, tp->GetColor(ThemeProperties::COLOR_TOOLBAR_BOTTOM_SEPARATOR), |
529 toolbar_bounds, true); | 505 toolbar_bounds, |
530 } else { | 506 true); |
531 // NOTE: this ifdef can't be OS_CHROMEOS as we want to see how it looks on | |
532 // windows as well. | |
533 #if defined(USE_ASH) | |
534 int h = toolbar_bounds.height(); | |
535 // Gross hack: We split the toolbar images into two pieces, since sometimes | |
536 // (popup mode) the toolbar isn't tall enough to show the whole image. The | |
537 // split happens between the top shadow section and the bottom gradient | |
538 // section so that we never break the gradient. | |
539 // NOTE(pkotwicz): If the computation for |bottom_y| is changed, Layout() | |
540 // must be changed as well. | |
541 int split_point = kFrameShadowThickness * 2; | |
542 int bottom_y = y + split_point; | |
543 int bottom_edge_height = h - split_point; | |
544 | |
545 canvas->FillRect(gfx::Rect(x, bottom_y, w, bottom_edge_height), | |
546 tp->GetColor(ThemeProperties::COLOR_TOOLBAR)); | |
547 | |
548 // Paint the main toolbar image. Since this image is also used to draw the | |
549 // tab background, we must use the tab strip offset to compute the image | |
550 // source y position. If you have to debug this code use an image editor | |
551 // to paint a diagonal line through the toolbar image and ensure it lines up | |
552 // across the tab and toolbar. | |
553 gfx::ImageSkia* theme_toolbar = tp->GetImageSkiaNamed(IDR_THEME_TOOLBAR); | |
554 canvas->TileImageInt(*theme_toolbar, x + GetThemeBackgroundXInset(), | |
555 bottom_y - GetTopInset(false), x, bottom_y, w, | |
556 theme_toolbar->height()); | |
557 | |
558 // The pre-material design content area line has a shadow that extends a | |
559 // couple of pixels above the toolbar bounds. | |
560 const int kContentShadowHeight = 2; | |
561 gfx::ImageSkia* toolbar_top = tp->GetImageSkiaNamed(IDR_TOOLBAR_SHADE_TOP); | |
562 canvas->TileImageInt(*toolbar_top, 0, 0, x, y - kContentShadowHeight, w, | |
563 split_point + kContentShadowHeight + 1); | |
564 | |
565 // Draw the "lightening" shade line around the edges of the toolbar. | |
566 gfx::ImageSkia* toolbar_left = | |
567 tp->GetImageSkiaNamed(IDR_TOOLBAR_SHADE_LEFT); | |
568 canvas->TileImageInt(*toolbar_left, 0, 0, x + kClientEdgeThickness, | |
569 y + kClientEdgeThickness + kContentShadowHeight, | |
570 toolbar_left->width(), theme_toolbar->height()); | |
571 gfx::ImageSkia* toolbar_right = | |
572 tp->GetImageSkiaNamed(IDR_TOOLBAR_SHADE_RIGHT); | |
573 canvas->TileImageInt(*toolbar_right, 0, 0, | |
574 w - toolbar_right->width() - 2 * kClientEdgeThickness, | |
575 y + kClientEdgeThickness + kContentShadowHeight, | |
576 toolbar_right->width(), theme_toolbar->height()); | |
577 | |
578 // Draw the content/toolbar separator. | |
579 canvas->FillRect( | |
580 gfx::Rect(x + kClientEdgeThickness, | |
581 toolbar_bounds.bottom() - kClientEdgeThickness, | |
582 w - (2 * kClientEdgeThickness), kClientEdgeThickness), | |
583 tp->GetColor(ThemeProperties::COLOR_TOOLBAR_BOTTOM_SEPARATOR)); | |
584 #else | |
585 // This is the case for running on non-chromeos. Decide how we want this to | |
586 // look. | |
587 #endif | |
588 } | |
589 } | 507 } |
590 | 508 |
591 void BrowserNonClientFrameViewMus::PaintContentEdge(gfx::Canvas* canvas) { | 509 void BrowserNonClientFrameViewMus::PaintContentEdge(gfx::Canvas* canvas) { |
592 DCHECK(!UsePackagedAppHeaderStyle() && !UseWebAppHeaderStyle()); | 510 DCHECK(!UsePackagedAppHeaderStyle() && !UseWebAppHeaderStyle()); |
593 const int bottom = frame_values().normal_insets.bottom(); | 511 const int bottom = frame_values().normal_insets.bottom(); |
594 canvas->FillRect( | 512 canvas->FillRect( |
595 gfx::Rect(0, bottom, width(), kClientEdgeThickness), | 513 gfx::Rect(0, bottom, width(), kClientEdgeThickness), |
596 GetThemeProvider()->GetColor( | 514 GetThemeProvider()->GetColor( |
597 ThemeProperties::COLOR_TOOLBAR_BOTTOM_SEPARATOR)); | 515 ThemeProperties::COLOR_TOOLBAR_BOTTOM_SEPARATOR)); |
598 } | 516 } |
OLD | NEW |