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 "chrome/browser/ui/views/layout_constants.h"
12 #include "grit/theme_resources.h"
13 #include "ui/base/hit_test.h"
14 #include "ui/base/theme_provider.h"
15 #include "ui/gfx/canvas.h"
19 // How far to inset the tabstrip from the sides of the window.
20 const int kTabstripTopInset = 8;
21 const int kTabstripLeftInset = 70; // Make room for window control buttons.
22 const int kTabstripRightInset = 0;
26 ///////////////////////////////////////////////////////////////////////////////
27 // BrowserNonClientFrameViewMac, public:
29 BrowserNonClientFrameViewMac::BrowserNonClientFrameViewMac(
30 BrowserFrame* frame, BrowserView* browser_view)
31 : BrowserNonClientFrameView(frame, browser_view) {
34 BrowserNonClientFrameViewMac::~BrowserNonClientFrameViewMac() {
37 ///////////////////////////////////////////////////////////////////////////////
38 // BrowserNonClientFrameViewMac, BrowserNonClientFrameView implementation:
40 gfx::Rect BrowserNonClientFrameViewMac::GetBoundsForTabStrip(
41 views::View* tabstrip) const {
43 gfx::Rect bounds = gfx::Rect(0, kTabstripTopInset,
44 width(), tabstrip->GetPreferredSize().height());
45 bounds.Inset(kTabstripLeftInset, 0, kTabstripRightInset, 0);
49 int BrowserNonClientFrameViewMac::GetTopInset() const {
50 return browser_view()->IsTabStripVisible() ? kTabstripTopInset : 0;
53 int BrowserNonClientFrameViewMac::GetThemeBackgroundXInset() const {
57 void BrowserNonClientFrameViewMac::UpdateThrobber(bool running) {
60 ///////////////////////////////////////////////////////////////////////////////
61 // BrowserNonClientFrameViewMac, views::NonClientFrameView implementation:
63 gfx::Rect BrowserNonClientFrameViewMac::GetBoundsForClientView() const {
67 gfx::Rect BrowserNonClientFrameViewMac::GetWindowBoundsForClientBounds(
68 const gfx::Rect& client_bounds) const {
72 int BrowserNonClientFrameViewMac::NonClientHitTest(const gfx::Point& point) {
73 int component = frame()->client_view()->NonClientHitTest(point);
75 // BrowserView::NonClientHitTest will return HTNOWHERE for points that hit
76 // the native title bar. On Mac, we need to explicitly return HTCAPTION for
78 if (component == HTNOWHERE && bounds().Contains(point))
84 void BrowserNonClientFrameViewMac::GetWindowMask(const gfx::Size& size,
85 gfx::Path* window_mask) {
88 void BrowserNonClientFrameViewMac::ResetWindowControls() {
91 void BrowserNonClientFrameViewMac::UpdateWindowIcon() {
94 void BrowserNonClientFrameViewMac::UpdateWindowTitle() {
97 void BrowserNonClientFrameViewMac::SizeConstraintsChanged() {
100 ///////////////////////////////////////////////////////////////////////////////
101 // BrowserNonClientFrameViewMac, views::View implementation:
103 gfx::Size BrowserNonClientFrameViewMac::GetMinimumSize() const {
104 return browser_view()->GetMinimumSize();
107 ///////////////////////////////////////////////////////////////////////////////
108 // BrowserNonClientFrameViewMac, protected:
111 void BrowserNonClientFrameViewMac::OnPaint(gfx::Canvas* canvas) {
112 if (!browser_view()->IsBrowserTypeNormal())
115 canvas->DrawColor(GetFrameColor());
117 if (!GetThemeProvider()->UsingSystemTheme())
118 PaintThemedFrame(canvas);
120 if (browser_view()->IsToolbarVisible())
121 PaintToolbarBackground(canvas);
124 // BrowserNonClientFrameView:
125 void BrowserNonClientFrameViewMac::UpdateNewAvatarButtonImpl() {
129 ///////////////////////////////////////////////////////////////////////////////
130 // BrowserNonClientFrameViewMac, private:
132 void BrowserNonClientFrameViewMac::PaintThemedFrame(gfx::Canvas* canvas) {
133 gfx::ImageSkia* image = GetFrameImage();
135 canvas->TileImageInt(*image, 0, 0, width(), image->height());
137 gfx::ImageSkia* overlay = GetFrameOverlayImage();
139 canvas->TileImageInt(*overlay, 0, 0, width(), overlay->height());
142 void BrowserNonClientFrameViewMac::PaintToolbarBackground(gfx::Canvas* canvas) {
143 gfx::Rect bounds(browser_view()->GetToolbarBounds());
144 if (bounds.IsEmpty())
147 ui::ThemeProvider* tp = GetThemeProvider();
148 gfx::ImageSkia* border = tp->GetImageSkiaNamed(IDR_TOOLBAR_SHADE_TOP);
149 const int top_inset =
150 GetLayoutConstant(TABSTRIP_TOOLBAR_OVERLAP) - border->height();
152 const int x = bounds.x();
153 const int y = bounds.y() + top_inset;
154 const int w = bounds.width();
155 const int h = bounds.height() - top_inset;
157 // The tabstrip border image height is 2*scale pixels, but only the bottom 2
158 // pixels contain the actual border (the rest is transparent). We can't draw
159 // the toolbar image below this transparent upper area when scale > 1.
160 const int fill_y = y + canvas->image_scale() - 1;
161 const int fill_height = bounds.bottom() - fill_y;
163 // Draw the toolbar fill.
164 canvas->TileImageInt(*tp->GetImageSkiaNamed(IDR_THEME_TOOLBAR),
165 x + GetThemeBackgroundXInset(), fill_y - GetTopInset(),
166 x, fill_y, w, fill_height);
168 // Draw the tabstrip/toolbar separator.
169 canvas->TileImageInt(*border, 0, 0, x, y, w, border->height());
171 // Draw the content/toolbar separator.
173 gfx::Rect(x, y + h - kClientEdgeThickness, w, kClientEdgeThickness),
174 ThemeProperties::GetDefaultColor(
175 ThemeProperties::COLOR_TOOLBAR_SEPARATOR));