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 int component = frame()->client_view()->NonClientHitTest(point);
74 // BrowserView::NonClientHitTest will return HTNOWHERE for points that hit
75 // the native title bar. On Mac, we need to explicitly return HTCAPTION for
77 if (component == HTNOWHERE && bounds().Contains(point))
83 void BrowserNonClientFrameViewMac::GetWindowMask(const gfx::Size& size,
84 gfx::Path* window_mask) {
87 void BrowserNonClientFrameViewMac::ResetWindowControls() {
90 void BrowserNonClientFrameViewMac::UpdateWindowIcon() {
93 void BrowserNonClientFrameViewMac::UpdateWindowTitle() {
96 void BrowserNonClientFrameViewMac::SizeConstraintsChanged() {
99 ///////////////////////////////////////////////////////////////////////////////
100 // BrowserNonClientFrameViewMac, views::View implementation:
102 gfx::Size BrowserNonClientFrameViewMac::GetMinimumSize() const {
103 return browser_view()->GetMinimumSize();
106 ///////////////////////////////////////////////////////////////////////////////
107 // BrowserNonClientFrameViewMac, protected:
110 void BrowserNonClientFrameViewMac::OnPaint(gfx::Canvas* canvas) {
111 if (!browser_view()->IsBrowserTypeNormal())
114 canvas->DrawColor(GetFrameColor());
116 if (!GetThemeProvider()->UsingSystemTheme())
117 PaintThemedFrame(canvas);
119 if (browser_view()->IsToolbarVisible())
120 PaintToolbarBackground(canvas);
123 // BrowserNonClientFrameView:
124 void BrowserNonClientFrameViewMac::UpdateNewAvatarButtonImpl() {
128 ///////////////////////////////////////////////////////////////////////////////
129 // BrowserNonClientFrameViewMac, private:
131 void BrowserNonClientFrameViewMac::PaintThemedFrame(gfx::Canvas* canvas) {
132 gfx::ImageSkia* image = GetFrameImage();
134 canvas->TileImageInt(*image, 0, 0, width(), image->height());
136 gfx::ImageSkia* overlay = GetFrameOverlayImage();
138 canvas->TileImageInt(*overlay, 0, 0, width(), overlay->height());
141 void BrowserNonClientFrameViewMac::PaintToolbarBackground(gfx::Canvas* canvas) {
142 gfx::Rect bounds(browser_view()->GetToolbarBounds());
143 if (bounds.IsEmpty())
146 ui::ThemeProvider* tp = GetThemeProvider();
147 gfx::ImageSkia* border = tp->GetImageSkiaNamed(IDR_TOOLBAR_SHADE_TOP);
148 const int top_inset =
149 BrowserViewLayout::kToolbarTabStripVerticalOverlap - border->height();
151 const int x = bounds.x();
152 const int y = bounds.y() + top_inset;
153 const int w = bounds.width();
154 const int h = bounds.height() - top_inset;
156 // The tabstrip border image height is 2*scale pixels, but only the bottom 2
157 // pixels contain the actual border (the rest is transparent). We can't draw
158 // the toolbar image below this transparent upper area when scale > 1.
159 const int fill_y = y + canvas->image_scale() - 1;
160 const int fill_height = bounds.bottom() - fill_y;
162 // Draw the toolbar fill.
163 canvas->TileImageInt(*tp->GetImageSkiaNamed(IDR_THEME_TOOLBAR),
164 x + GetThemeBackgroundXInset(), fill_y - GetTopInset(),
165 x, fill_y, w, fill_height);
167 // Draw the tabstrip/toolbar separator.
168 canvas->TileImageInt(*border, 0, 0, x, y, w, border->height());
170 // Draw the content/toolbar separator.
172 gfx::Rect(x, y + h - kClientEdgeThickness, w, kClientEdgeThickness),
173 ThemeProperties::GetDefaultColor(
174 ThemeProperties::COLOR_TOOLBAR_SEPARATOR));