summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui/views/frame/browser_non_client_frame_view_mac.mm
blob: a556d22c35d43c272ea33ae174af891aaac2f4b1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/ui/views/frame/browser_non_client_frame_view_mac.h"

#include "chrome/browser/themes/theme_properties.h"
#include "chrome/browser/ui/layout_constants.h"
#include "chrome/browser/ui/views/frame/browser_frame.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/browser/ui/views/frame/browser_view_layout.h"
#include "grit/theme_resources.h"
#include "ui/base/hit_test.h"
#include "ui/base/theme_provider.h"
#include "ui/gfx/canvas.h"

namespace {

// How far to inset the tabstrip from the sides of the window.
const int kTabstripTopInset = 8;
const int kTabstripLeftInset = 70;  // Make room for window control buttons.
const int kTabstripRightInset = 0;

}  // namespace

///////////////////////////////////////////////////////////////////////////////
// BrowserNonClientFrameViewMac, public:

BrowserNonClientFrameViewMac::BrowserNonClientFrameViewMac(
    BrowserFrame* frame, BrowserView* browser_view)
    : BrowserNonClientFrameView(frame, browser_view) {
}

BrowserNonClientFrameViewMac::~BrowserNonClientFrameViewMac() {
}

///////////////////////////////////////////////////////////////////////////////
// BrowserNonClientFrameViewMac, BrowserNonClientFrameView implementation:

gfx::Rect BrowserNonClientFrameViewMac::GetBoundsForTabStrip(
    views::View* tabstrip) const {
  DCHECK(tabstrip);
  gfx::Rect bounds = gfx::Rect(0, kTabstripTopInset,
                               width(), tabstrip->GetPreferredSize().height());
  bounds.Inset(kTabstripLeftInset, 0, kTabstripRightInset, 0);
  return bounds;
}

int BrowserNonClientFrameViewMac::GetTopInset(bool restored) const {
  return browser_view()->IsTabStripVisible() ? kTabstripTopInset : 0;
}

int BrowserNonClientFrameViewMac::GetThemeBackgroundXInset() const {
  return 0;
}

void BrowserNonClientFrameViewMac::UpdateThrobber(bool running) {
}

///////////////////////////////////////////////////////////////////////////////
// BrowserNonClientFrameViewMac, views::NonClientFrameView implementation:

gfx::Rect BrowserNonClientFrameViewMac::GetBoundsForClientView() const {
  return bounds();
}

gfx::Rect BrowserNonClientFrameViewMac::GetWindowBoundsForClientBounds(
    const gfx::Rect& client_bounds) const {
  return client_bounds;
}

int BrowserNonClientFrameViewMac::NonClientHitTest(const gfx::Point& point) {
  int component = frame()->client_view()->NonClientHitTest(point);

  // BrowserView::NonClientHitTest will return HTNOWHERE for points that hit
  // the native title bar. On Mac, we need to explicitly return HTCAPTION for
  // those points.
  if (component == HTNOWHERE && bounds().Contains(point))
    return HTCAPTION;

  return component;
}

void BrowserNonClientFrameViewMac::GetWindowMask(const gfx::Size& size,
                                                 gfx::Path* window_mask) {
}

void BrowserNonClientFrameViewMac::ResetWindowControls() {
}

void BrowserNonClientFrameViewMac::UpdateWindowIcon() {
}

void BrowserNonClientFrameViewMac::UpdateWindowTitle() {
}

void BrowserNonClientFrameViewMac::SizeConstraintsChanged() {
}

///////////////////////////////////////////////////////////////////////////////
// BrowserNonClientFrameViewMac, views::View implementation:

gfx::Size BrowserNonClientFrameViewMac::GetMinimumSize() const {
  return browser_view()->GetMinimumSize();
}

///////////////////////////////////////////////////////////////////////////////
// BrowserNonClientFrameViewMac, protected:

// views::View:
void BrowserNonClientFrameViewMac::OnPaint(gfx::Canvas* canvas) {
  if (!browser_view()->IsBrowserTypeNormal())
    return;

  canvas->DrawColor(GetFrameColor());

  if (!GetThemeProvider()->UsingSystemTheme())
    PaintThemedFrame(canvas);

  if (browser_view()->IsToolbarVisible())
    PaintToolbarBackground(canvas);
}

// BrowserNonClientFrameView:
void BrowserNonClientFrameViewMac::UpdateAvatar() {
  NOTIMPLEMENTED();
}

///////////////////////////////////////////////////////////////////////////////
// BrowserNonClientFrameViewMac, private:

void BrowserNonClientFrameViewMac::PaintThemedFrame(gfx::Canvas* canvas) {
  gfx::ImageSkia image = GetFrameImage();
  canvas->TileImageInt(image, 0, 0, width(), image.height());
  gfx::ImageSkia overlay = GetFrameOverlayImage();
  canvas->TileImageInt(overlay, 0, 0, width(), overlay.height());
}

void BrowserNonClientFrameViewMac::PaintToolbarBackground(gfx::Canvas* canvas) {
  gfx::Rect bounds(browser_view()->GetToolbarBounds());
  if (bounds.IsEmpty())
    return;

  const ui::ThemeProvider* tp = GetThemeProvider();
  gfx::ImageSkia* border = tp->GetImageSkiaNamed(IDR_TOOLBAR_SHADE_TOP);
  const int top_inset =
      GetLayoutConstant(TABSTRIP_TOOLBAR_OVERLAP) - border->height();

  const int x = bounds.x();
  const int y = bounds.y() + top_inset;
  const int w = bounds.width();
  const int h = bounds.height() - top_inset;

  // The tabstrip border image height is 2*scale pixels, but only the bottom 2
  // pixels contain the actual border (the rest is transparent). We can't draw
  // the toolbar image below this transparent upper area when scale > 1.
  const int fill_y = y + canvas->image_scale() - 1;
  const int fill_height = bounds.bottom() - fill_y;

  // Draw the toolbar fill.
  canvas->TileImageInt(*tp->GetImageSkiaNamed(IDR_THEME_TOOLBAR),
                       x + GetThemeBackgroundXInset(),
                       fill_y - GetTopInset(false), x, fill_y, w, fill_height);

  // Draw the tabstrip/toolbar separator.
  canvas->TileImageInt(*border, 0, 0, x, y, w, border->height());

  // Draw the content/toolbar separator.
  canvas->FillRect(
      gfx::Rect(x, y + h - kClientEdgeThickness, w, kClientEdgeThickness),
      ThemeProperties::GetDefaultColor(
          ThemeProperties::COLOR_TOOLBAR_BOTTOM_SEPARATOR,
          browser_view()->IsOffTheRecord()));
}