OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/opaque_browser_frame_view.h" | 5 #include "chrome/browser/ui/views/frame/opaque_browser_frame_view.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
(...skipping 21 matching lines...) Expand all Loading... | |
32 #include "ui/base/hit_test.h" | 32 #include "ui/base/hit_test.h" |
33 #include "ui/base/l10n/l10n_util.h" | 33 #include "ui/base/l10n/l10n_util.h" |
34 #include "ui/base/resource/material_design/material_design_controller.h" | 34 #include "ui/base/resource/material_design/material_design_controller.h" |
35 #include "ui/base/theme_provider.h" | 35 #include "ui/base/theme_provider.h" |
36 #include "ui/gfx/canvas.h" | 36 #include "ui/gfx/canvas.h" |
37 #include "ui/gfx/font_list.h" | 37 #include "ui/gfx/font_list.h" |
38 #include "ui/gfx/geometry/rect_conversions.h" | 38 #include "ui/gfx/geometry/rect_conversions.h" |
39 #include "ui/gfx/image/image.h" | 39 #include "ui/gfx/image/image.h" |
40 #include "ui/gfx/image/image_skia.h" | 40 #include "ui/gfx/image/image_skia.h" |
41 #include "ui/gfx/path.h" | 41 #include "ui/gfx/path.h" |
42 #include "ui/gfx/scoped_canvas.h" | |
42 #include "ui/resources/grit/ui_resources.h" | 43 #include "ui/resources/grit/ui_resources.h" |
43 #include "ui/views/controls/button/image_button.h" | 44 #include "ui/views/controls/button/image_button.h" |
44 #include "ui/views/controls/image_view.h" | 45 #include "ui/views/controls/image_view.h" |
45 #include "ui/views/controls/label.h" | 46 #include "ui/views/controls/label.h" |
46 #include "ui/views/layout/layout_constants.h" | 47 #include "ui/views/layout/layout_constants.h" |
47 #include "ui/views/resources/grit/views_resources.h" | 48 #include "ui/views/resources/grit/views_resources.h" |
48 #include "ui/views/views_delegate.h" | 49 #include "ui/views/views_delegate.h" |
49 #include "ui/views/widget/root_view.h" | 50 #include "ui/views/widget/root_view.h" |
50 #include "ui/views/window/frame_background.h" | 51 #include "ui/views/window/frame_background.h" |
51 #include "ui/views/window/window_shape.h" | 52 #include "ui/views/window/window_shape.h" |
(...skipping 590 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
642 tp->GetColor(ThemeProperties::COLOR_TOOLBAR_SEPARATOR); | 643 tp->GetColor(ThemeProperties::COLOR_TOOLBAR_SEPARATOR); |
643 | 644 |
644 if (browser_view()->IsTabStripVisible()) { | 645 if (browser_view()->IsTabStripVisible()) { |
645 gfx::ImageSkia* bg = tp->GetImageSkiaNamed(IDR_THEME_TOOLBAR); | 646 gfx::ImageSkia* bg = tp->GetImageSkiaNamed(IDR_THEME_TOOLBAR); |
646 int x = toolbar_bounds.x(); | 647 int x = toolbar_bounds.x(); |
647 const int y = toolbar_bounds.y(); | 648 const int y = toolbar_bounds.y(); |
648 const int bg_y = | 649 const int bg_y = |
649 GetTopInset(false) + Tab::GetYInsetForActiveTabBackground(); | 650 GetTopInset(false) + Tab::GetYInsetForActiveTabBackground(); |
650 const int w = toolbar_bounds.width(); | 651 const int w = toolbar_bounds.width(); |
651 | 652 |
652 // Background. We need to create a separate layer so we can mask off the | 653 if (md) { |
653 // corners before compositing onto the frame. | 654 // Background. The top stroke is drawn above the toolbar bounds, so |
654 canvas->sk_canvas()->saveLayer( | 655 // unlike in the non-Material Design code below, we don't need to exclude |
655 gfx::RectToSkRect(gfx::Rect(x - kContentEdgeShadowThickness, y, | 656 // any region from having the background image drawn over it. |
656 w + kContentEdgeShadowThickness * 2, h)), | 657 if (tp->HasCustomImage(IDR_THEME_TOOLBAR)) { |
657 nullptr); | 658 canvas->TileImageInt(*bg, x + GetThemeBackgroundXInset(), y - bg_y, x, |
659 y, w, h); | |
660 } else { | |
661 canvas->FillRect(toolbar_bounds, | |
662 tp->GetColor(ThemeProperties::COLOR_TOOLBAR)); | |
663 } | |
658 | 664 |
659 // The top stroke is drawn using the IDR_CONTENT_TOP_XXX images, which | 665 // Material Design has no corners to mask out. |
660 // overlay the toolbar. The top 2 px of these images is the actual top | 666 |
661 // stroke + shadow, and is partly transparent, so the toolbar background | 667 // Top stroke. For Material Design, the toolbar has no side strokes. |
662 // shouldn't be drawn over it. | 668 gfx::Rect separator_rect(x, y, w, 0); |
663 const int split_point = std::min(kContentEdgeShadowThickness, h); | 669 gfx::ScopedCanvas scoped_canvas(canvas); |
664 if (h > split_point) { | 670 gfx::Rect tabstrip_bounds( |
665 const int split_y = y + split_point; | 671 GetBoundsForTabStrip(browser_view()->tabstrip())); |
666 canvas->TileImageInt(*bg, x + GetThemeBackgroundXInset(), split_y - bg_y, | 672 tabstrip_bounds.set_x(GetMirroredXForRect(tabstrip_bounds)); |
667 x, split_y, w, h - split_point); | 673 canvas->sk_canvas()->clipRect(gfx::RectToSkRect(tabstrip_bounds), |
674 SkRegion::kDifference_Op); | |
675 separator_rect.set_y(tabstrip_bounds.bottom()); | |
676 BrowserView::Paint1pxHorizontalLine( | |
677 canvas, SkColorSetA(SK_ColorBLACK, 0x40), separator_rect, true); | |
678 } else { | |
Peter Kasting
2015/12/09 01:20:30
This arm is copied verbatim from before, just inde
| |
679 // Background. We need to create a separate layer so we can mask off the | |
680 // corners before compositing onto the frame. | |
681 canvas->sk_canvas()->saveLayer( | |
682 gfx::RectToSkRect(gfx::Rect(x - kContentEdgeShadowThickness, y, | |
683 w + kContentEdgeShadowThickness * 2, h)), | |
684 nullptr); | |
685 | |
686 // The top stroke is drawn using the IDR_CONTENT_TOP_XXX images, which | |
687 // overlay the toolbar. The top 2 px of these images is the actual top | |
688 // stroke + shadow, and is partly transparent, so the toolbar background | |
689 // shouldn't be drawn over it. | |
690 const int split_point = std::min(kContentEdgeShadowThickness, h); | |
691 if (h > split_point) { | |
692 const int split_y = y + split_point; | |
693 canvas->TileImageInt(*bg, x + GetThemeBackgroundXInset(), | |
694 split_y - bg_y, x, split_y, w, h - split_point); | |
695 } | |
696 | |
697 // Mask out the corners. | |
698 gfx::ImageSkia* left = tp->GetImageSkiaNamed(IDR_CONTENT_TOP_LEFT_CORNER); | |
699 const int img_w = left->width(); | |
700 x -= kContentEdgeShadowThickness; | |
701 SkPaint paint; | |
702 paint.setXfermodeMode(SkXfermode::kDstIn_Mode); | |
703 canvas->DrawImageInt( | |
704 *tp->GetImageSkiaNamed(IDR_CONTENT_TOP_LEFT_CORNER_MASK), 0, 0, img_w, | |
705 h, x, y, img_w, h, false, paint); | |
706 const int right_x = | |
707 toolbar_bounds.right() + kContentEdgeShadowThickness - img_w; | |
708 canvas->DrawImageInt( | |
709 *tp->GetImageSkiaNamed(IDR_CONTENT_TOP_RIGHT_CORNER_MASK), 0, 0, | |
710 img_w, h, right_x, y, img_w, h, false, paint); | |
711 canvas->Restore(); | |
712 | |
713 // Corner and side strokes. | |
714 canvas->DrawImageInt(*left, 0, 0, img_w, h, x, y, img_w, h, false); | |
715 canvas->DrawImageInt(*tp->GetImageSkiaNamed(IDR_CONTENT_TOP_RIGHT_CORNER), | |
716 0, 0, img_w, h, right_x, y, img_w, h, false); | |
717 | |
718 // Top stroke. | |
719 x += img_w; | |
720 canvas->TileImageInt(*tp->GetImageSkiaNamed(IDR_CONTENT_TOP_CENTER), x, y, | |
721 right_x - x, split_point); | |
668 } | 722 } |
669 | |
670 // Mask out the corners. | |
671 gfx::ImageSkia* left = tp->GetImageSkiaNamed(IDR_CONTENT_TOP_LEFT_CORNER); | |
672 const int img_w = left->width(); | |
673 x -= kContentEdgeShadowThickness; | |
674 SkPaint paint; | |
675 paint.setXfermodeMode(SkXfermode::kDstIn_Mode); | |
676 canvas->DrawImageInt( | |
677 *tp->GetImageSkiaNamed(IDR_CONTENT_TOP_LEFT_CORNER_MASK), 0, 0, img_w, | |
678 h, x, y, img_w, h, false, paint); | |
679 const int right_x = | |
680 toolbar_bounds.right() + kContentEdgeShadowThickness - img_w; | |
681 canvas->DrawImageInt( | |
682 *tp->GetImageSkiaNamed(IDR_CONTENT_TOP_RIGHT_CORNER_MASK), 0, 0, img_w, | |
683 h, right_x, y, img_w, h, false, paint); | |
684 canvas->Restore(); | |
685 | |
686 // Corner and side strokes. | |
687 canvas->DrawImageInt(*left, 0, 0, img_w, h, x, y, img_w, h, false); | |
688 canvas->DrawImageInt(*tp->GetImageSkiaNamed(IDR_CONTENT_TOP_RIGHT_CORNER), | |
689 0, 0, img_w, h, right_x, y, img_w, h, false); | |
690 | |
691 // Top stroke. | |
692 x += img_w; | |
693 canvas->TileImageInt(*tp->GetImageSkiaNamed(IDR_CONTENT_TOP_CENTER), x, y, | |
694 right_x - x, split_point); | |
695 } | 723 } |
696 | 724 |
697 // Toolbar/content separator. | 725 // Toolbar/content separator. |
698 toolbar_bounds.Inset(kClientEdgeThickness, h - kClientEdgeThickness, | 726 toolbar_bounds.Inset(kClientEdgeThickness, h - kClientEdgeThickness, |
699 kClientEdgeThickness, 0); | 727 kClientEdgeThickness, 0); |
700 if (md) { | 728 if (md) { |
701 BrowserView::Paint1pxHorizontalLine(canvas, separator_color, | 729 BrowserView::Paint1pxHorizontalLine(canvas, separator_color, |
702 toolbar_bounds, true); | 730 toolbar_bounds, true); |
703 } else { | 731 } else { |
704 canvas->FillRect(toolbar_bounds, separator_color); | 732 canvas->FillRect(toolbar_bounds, separator_color); |
705 } | 733 } |
706 } | 734 } |
707 | 735 |
708 void OpaqueBrowserFrameView::PaintClientEdge(gfx::Canvas* canvas) { | 736 void OpaqueBrowserFrameView::PaintClientEdge(gfx::Canvas* canvas) { |
709 gfx::Rect client_bounds = | 737 gfx::Rect client_bounds = |
710 layout_->CalculateClientAreaBounds(width(), height()); | 738 layout_->CalculateClientAreaBounds(width(), height()); |
711 const int x = client_bounds.x(); | 739 const int x = client_bounds.x(); |
712 int y = client_bounds.y(); | 740 int y = client_bounds.y(); |
713 const int w = client_bounds.width(); | 741 const int w = client_bounds.width(); |
714 const int right = client_bounds.right(); | 742 const int right = client_bounds.right(); |
715 const bool normal_mode = browser_view()->IsTabStripVisible(); | 743 const bool normal_mode = browser_view()->IsTabStripVisible(); |
744 const bool md = ui::MaterialDesignController::IsModeMaterial(); | |
716 const ui::ThemeProvider* tp = GetThemeProvider(); | 745 const ui::ThemeProvider* tp = GetThemeProvider(); |
717 const SkColor toolbar_color = normal_mode ? | 746 const SkColor toolbar_color = normal_mode ? |
718 tp->GetColor(ThemeProperties::COLOR_TOOLBAR) : | 747 tp->GetColor(ThemeProperties::COLOR_TOOLBAR) : |
719 ThemeProperties::GetDefaultColor(ThemeProperties::COLOR_TOOLBAR); | 748 ThemeProperties::GetDefaultColor(ThemeProperties::COLOR_TOOLBAR); |
720 | 749 |
721 const gfx::Rect toolbar_bounds(browser_view()->GetToolbarBounds()); | 750 const gfx::Rect toolbar_bounds(browser_view()->GetToolbarBounds()); |
722 int img_y_offset = 0; | 751 int img_y_offset = 0; |
723 if (normal_mode) { | 752 if (normal_mode) { |
724 // The client edge images start below the toolbar. | 753 // Pre-Material Design, the client edge images start below the toolbar. In |
754 // MD the client edge images start at the top of the toolbar. | |
725 y += toolbar_bounds.bottom(); | 755 y += toolbar_bounds.bottom(); |
756 if (md) | |
757 img_y_offset = -toolbar_bounds.height(); | |
726 } else { | 758 } else { |
727 // The toolbar isn't going to draw a top edge for us, so draw one ourselves. | 759 // The toolbar isn't going to draw a top edge for us, so draw one ourselves. |
728 if (IsToolbarVisible()) { | 760 if (IsToolbarVisible()) { |
729 y += toolbar_bounds.y() + kContentEdgeShadowThickness + | 761 y += toolbar_bounds.y() + kContentEdgeShadowThickness + |
730 kClientEdgeThickness; | 762 kClientEdgeThickness; |
731 } | 763 } |
732 client_bounds.set_y(y); | 764 client_bounds.set_y(y); |
733 client_bounds.Inset(-kClientEdgeThickness, -kClientEdgeThickness, | 765 client_bounds.Inset(-kClientEdgeThickness, -kClientEdgeThickness, |
734 -kClientEdgeThickness, client_bounds.height()); | 766 -kClientEdgeThickness, client_bounds.height()); |
767 if (md) { | |
768 img_y_offset = -kClientEdgeThickness; | |
735 | 769 |
736 // Edge. | 770 // Edge. |
737 canvas->FillRect(client_bounds, toolbar_color); | 771 BrowserView::Paint1pxHorizontalLine(canvas, toolbar_color, client_bounds, |
772 false); | |
738 | 773 |
739 // Shadow. | 774 // Shadow. |
740 gfx::ImageSkia* top_left = tp->GetImageSkiaNamed(IDR_APP_TOP_LEFT); | 775 client_bounds.Offset(0, img_y_offset); |
741 const int img_w = top_left->width(); | 776 BrowserView::Paint1pxHorizontalLine( |
742 const int height = top_left->height(); | 777 canvas, SkColorSetA(SK_ColorBLACK, 0x40), client_bounds, true); |
743 const int top_y = y - height; | 778 } else { |
Peter Kasting
2015/12/09 01:20:30
Same here.
| |
744 canvas->DrawImageInt(*top_left, 0, 0, img_w, height, x - img_w, top_y, | 779 // Edge. |
745 img_w, height, false); | 780 canvas->FillRect(client_bounds, toolbar_color); |
746 canvas->TileImageInt(*tp->GetImageSkiaNamed(IDR_APP_TOP_CENTER), 0, 0, x, | 781 |
747 top_y, w, height); | 782 // Shadow. |
748 canvas->DrawImageInt(*tp->GetImageSkiaNamed(IDR_APP_TOP_RIGHT), 0, 0, img_w, | 783 gfx::ImageSkia* top_left = tp->GetImageSkiaNamed(IDR_APP_TOP_LEFT); |
749 height, right, top_y, img_w, height, false); | 784 const int img_w = top_left->width(); |
785 const int height = top_left->height(); | |
786 const int top_y = y - height; | |
787 canvas->DrawImageInt(*top_left, 0, 0, img_w, height, x - img_w, top_y, | |
788 img_w, height, false); | |
789 canvas->TileImageInt(*tp->GetImageSkiaNamed(IDR_APP_TOP_CENTER), 0, 0, x, | |
790 top_y, w, height); | |
791 canvas->DrawImageInt(*tp->GetImageSkiaNamed(IDR_APP_TOP_RIGHT), 0, 0, | |
792 img_w, height, right, top_y, img_w, height, false); | |
793 } | |
750 } | 794 } |
751 | 795 |
752 // In maximized mode, the only edge to draw is the top one, so we're done. | 796 // In maximized mode, the only edge to draw is the top one, so we're done. |
753 if (layout_->IsTitleBarCondensed()) | 797 if (layout_->IsTitleBarCondensed()) |
754 return; | 798 return; |
755 | 799 |
756 const int img_y = y + img_y_offset; | 800 const int img_y = y + img_y_offset; |
757 const int bottom = std::max(y, height() - NonClientBorderThickness()); | 801 const int bottom = std::max(y, height() - NonClientBorderThickness()); |
758 int height = bottom - img_y; | 802 int height = bottom - img_y; |
759 | 803 |
(...skipping 16 matching lines...) Expand all Loading... | |
776 // images because the images are meant to alpha-blend atop the frame whereas | 820 // images because the images are meant to alpha-blend atop the frame whereas |
777 // these rects are meant to be fully opaque, without anything overlaid. | 821 // these rects are meant to be fully opaque, without anything overlaid. |
778 gfx::Rect side(x - kClientEdgeThickness, y, kClientEdgeThickness, | 822 gfx::Rect side(x - kClientEdgeThickness, y, kClientEdgeThickness, |
779 bottom + kClientEdgeThickness - y); | 823 bottom + kClientEdgeThickness - y); |
780 canvas->FillRect(side, toolbar_color); | 824 canvas->FillRect(side, toolbar_color); |
781 canvas->FillRect(gfx::Rect(x, bottom, w, kClientEdgeThickness), | 825 canvas->FillRect(gfx::Rect(x, bottom, w, kClientEdgeThickness), |
782 toolbar_color); | 826 toolbar_color); |
783 side.set_x(right); | 827 side.set_x(right); |
784 canvas->FillRect(side, toolbar_color); | 828 canvas->FillRect(side, toolbar_color); |
785 } | 829 } |
OLD | NEW |