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
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/views/frame/browser_non_client_frame_view_mac.h"
7 #include "chrome/browser/themes/theme_properties.h"
8 #include "chrome/browser/ui/views/frame/browser_frame.h"
9 #include "chrome/browser/ui/views/frame/browser_view.h"
10 #include "chrome/browser/ui/views/frame/browser_view_layout.h"
11 #include "grit/theme_resources.h"
12 #include "ui/base/hit_test.h"
13 #include "ui/base/theme_provider.h"
14 #include "ui/gfx/canvas.h"
18 // How far to inset the tabstrip from the sides of the window.
19 const int kTabstripTopInset = 8;
20 const int kTabstripLeftInset = 70; // Make room for window control buttons.
21 const int kTabstripRightInset = 0;
25 ///////////////////////////////////////////////////////////////////////////////
26 // BrowserNonClientFrameViewMac, public:
28 BrowserNonClientFrameViewMac::BrowserNonClientFrameViewMac(
29 BrowserFrame* frame, BrowserView* browser_view)
30 : BrowserNonClientFrameView(frame, browser_view) {
33 BrowserNonClientFrameViewMac::~BrowserNonClientFrameViewMac() {
36 ///////////////////////////////////////////////////////////////////////////////
37 // BrowserNonClientFrameViewMac, BrowserNonClientFrameView implementation:
39 gfx::Rect BrowserNonClientFrameViewMac::GetBoundsForTabStrip(
40 views::View* tabstrip) const {
42 gfx::Rect bounds = gfx::Rect(0, kTabstripTopInset,
43 width(), tabstrip->GetPreferredSize().height());
44 bounds.Inset(kTabstripLeftInset, 0, kTabstripRightInset, 0);
48 int BrowserNonClientFrameViewMac::GetTopInset() const {
49 return browser_view()->IsTabStripVisible() ? kTabstripTopInset : 0;
52 int BrowserNonClientFrameViewMac::GetThemeBackgroundXInset() const {
56 void BrowserNonClientFrameViewMac::UpdateThrobber(bool running) {
59 ///////////////////////////////////////////////////////////////////////////////
60 // BrowserNonClientFrameViewMac, views::NonClientFrameView implementation:
62 gfx::Rect BrowserNonClientFrameViewMac::GetBoundsForClientView() const {
66 gfx::Rect BrowserNonClientFrameViewMac::GetWindowBoundsForClientBounds(
67 const gfx::Rect& client_bounds) const {
71 int BrowserNonClientFrameViewMac::NonClientHitTest(const gfx::Point& point) {
72 return frame()->client_view()->NonClientHitTest(point);
75 void BrowserNonClientFrameViewMac::GetWindowMask(const gfx::Size& size,
76 gfx::Path* window_mask) {
79 void BrowserNonClientFrameViewMac::ResetWindowControls() {
82 void BrowserNonClientFrameViewMac::UpdateWindowIcon() {
85 void BrowserNonClientFrameViewMac::UpdateWindowTitle() {
88 void BrowserNonClientFrameViewMac::SizeConstraintsChanged() {
91 ///////////////////////////////////////////////////////////////////////////////
92 // BrowserNonClientFrameViewMac, views::View implementation:
94 gfx::Size BrowserNonClientFrameViewMac::GetMinimumSize() const {
95 return browser_view()->GetMinimumSize();
98 ///////////////////////////////////////////////////////////////////////////////
99 // BrowserNonClientFrameViewMac, protected:
102 void BrowserNonClientFrameViewMac::OnPaint(gfx::Canvas* canvas) {
103 if (!browser_view()->IsBrowserTypeNormal())
106 canvas->DrawColor(GetFrameColor());
108 if (!GetThemeProvider()->UsingSystemTheme())
109 PaintThemedFrame(canvas);
111 if (browser_view()->IsToolbarVisible())
112 PaintToolbarBackground(canvas);
115 // BrowserNonClientFrameView:
116 void BrowserNonClientFrameViewMac::UpdateNewAvatarButtonImpl() {
120 ///////////////////////////////////////////////////////////////////////////////
121 // BrowserNonClientFrameViewMac, private:
123 void BrowserNonClientFrameViewMac::PaintThemedFrame(gfx::Canvas* canvas) {
124 gfx::ImageSkia* image = GetFrameImage();
126 canvas->TileImageInt(*image, 0, 0, width(), image->height());
128 gfx::ImageSkia* overlay = GetFrameOverlayImage();
130 canvas->TileImageInt(*overlay, 0, 0, width(), overlay->height());
133 void BrowserNonClientFrameViewMac::PaintToolbarBackground(gfx::Canvas* canvas) {
134 gfx::Rect bounds(browser_view()->GetToolbarBounds());
135 if (bounds.IsEmpty())
138 ui::ThemeProvider* tp = GetThemeProvider();
139 gfx::ImageSkia* border = tp->GetImageSkiaNamed(IDR_TOOLBAR_SHADE_TOP);
140 const int top_inset =
141 BrowserViewLayout::kToolbarTabStripVerticalOverlap - border->height();
143 const int x = bounds.x();
144 const int y = bounds.y() + top_inset;
145 const int w = bounds.width();
146 const int h = bounds.height() - top_inset;
148 // The tabstrip border image height is 2*scale pixels, but only the bottom 2
149 // pixels contain the actual border (the rest is transparent). We can't draw
150 // the toolbar image below this transparent upper area when scale > 1.
151 const int fill_y = y + canvas->image_scale() - 1;
152 const int fill_height = bounds.bottom() - fill_y;
154 // Draw the toolbar fill.
155 canvas->TileImageInt(*tp->GetImageSkiaNamed(IDR_THEME_TOOLBAR),
156 x + GetThemeBackgroundXInset(), fill_y - GetTopInset(),
157 x, fill_y, w, fill_height);
159 // Draw the tabstrip/toolbar separator.
160 canvas->TileImageInt(*border, 0, 0, x, y, w, border->height());
162 // Draw the content/toolbar separator.
164 gfx::Rect(x, y + h - kClientEdgeThickness, w, kClientEdgeThickness),
165 ThemeProperties::GetDefaultColor(
166 ThemeProperties::COLOR_TOOLBAR_SEPARATOR));