OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 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. |
| 4 |
| 5 #include "chrome/browser/ui/views/frame/browser_frame_view_mac.h" |
| 6 |
| 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/tabs/tab_strip.h" |
| 11 #include "grit/theme_resources.h" |
| 12 #include "ui/base/theme_provider.h" |
| 13 #include "ui/gfx/canvas.h" |
| 14 #include "ui/views/widget/widget_delegate.h" |
| 15 |
| 16 namespace { |
| 17 |
| 18 // The content left/right images have a shadow built into them. |
| 19 const int kContentEdgeShadowThickness = 2; |
| 20 |
| 21 } // namespace |
| 22 |
| 23 /////////////////////////////////////////////////////////////////////////////// |
| 24 // BrowserFrameViewMac, public: |
| 25 |
| 26 BrowserFrameViewMac::BrowserFrameViewMac(BrowserFrame* frame, |
| 27 BrowserView* browser_view) |
| 28 : BrowserNonClientFrameView(frame, browser_view) { |
| 29 } |
| 30 |
| 31 BrowserFrameViewMac::~BrowserFrameViewMac() { |
| 32 } |
| 33 |
| 34 /////////////////////////////////////////////////////////////////////////////// |
| 35 // BrowserFrameViewMac, BrowserNonClientFrameView implementation: |
| 36 |
| 37 gfx::Rect BrowserFrameViewMac::GetBoundsForTabStrip( |
| 38 views::View* tabstrip) const { |
| 39 return gfx::Rect(0, 0, width(), tabstrip->GetPreferredSize().height()); |
| 40 } |
| 41 |
| 42 int BrowserFrameViewMac::GetTopInset() const { |
| 43 return 0; |
| 44 } |
| 45 |
| 46 int BrowserFrameViewMac::GetThemeBackgroundXInset() const { |
| 47 return 0; |
| 48 } |
| 49 |
| 50 void BrowserFrameViewMac::UpdateThrobber(bool running) { |
| 51 } |
| 52 |
| 53 gfx::Size BrowserFrameViewMac::GetMinimumSize() const { |
| 54 return frame()->client_view()->GetMinimumSize(); |
| 55 } |
| 56 |
| 57 //////////////////////////////////////////////////////////////////////////////// |
| 58 // BrowserFrameViewMac, NonClientFrameView overrides: |
| 59 |
| 60 gfx::Rect BrowserFrameViewMac::GetBoundsForClientView() const { |
| 61 // return bounds(); |
| 62 // TODO(andresantoso): Tab strip and toolbar won't draw without this -1? |
| 63 return gfx::Rect(0, 0, width()-1, height()); |
| 64 } |
| 65 |
| 66 gfx::Rect BrowserFrameViewMac::GetWindowBoundsForClientBounds( |
| 67 const gfx::Rect& client_bounds) const { |
| 68 return client_bounds; |
| 69 } |
| 70 |
| 71 int BrowserFrameViewMac::NonClientHitTest(const gfx::Point& point) { |
| 72 return frame()->client_view()->NonClientHitTest(point); |
| 73 } |
| 74 |
| 75 void BrowserFrameViewMac::GetWindowMask(const gfx::Size& size, |
| 76 gfx::Path* window_mask) { |
| 77 // Nothing to do. |
| 78 } |
| 79 |
| 80 void BrowserFrameViewMac::ResetWindowControls() { |
| 81 // Nothing to do. |
| 82 } |
| 83 |
| 84 void BrowserFrameViewMac::UpdateWindowIcon() { |
| 85 // Nothing to do. |
| 86 } |
| 87 |
| 88 void BrowserFrameViewMac::UpdateWindowTitle() { |
| 89 // Nothing to do. |
| 90 } |
| 91 |
| 92 void BrowserFrameViewMac::SizeConstraintsChanged() { |
| 93 // Nothing to do. |
| 94 } |
| 95 |
| 96 //////////////////////////////////////////////////////////////////////////////// |
| 97 // BrowserFrameViewMac, views::View overrides: |
| 98 |
| 99 void BrowserFrameViewMac::PaintToolbarBackground(gfx::Canvas* canvas) { |
| 100 gfx::Rect toolbar_bounds(browser_view()->GetToolbarBounds()); |
| 101 if (toolbar_bounds.IsEmpty()) |
| 102 return; |
| 103 gfx::Point toolbar_origin(toolbar_bounds.origin()); |
| 104 ConvertPointToTarget(browser_view(), this, &toolbar_origin); |
| 105 toolbar_bounds.set_origin(toolbar_origin); |
| 106 |
| 107 int x = toolbar_bounds.x(); |
| 108 int w = toolbar_bounds.width(); |
| 109 int y = toolbar_bounds.y(); |
| 110 int h = toolbar_bounds.height(); |
| 111 |
| 112 // Gross hack: We split the toolbar images into two pieces, since sometimes |
| 113 // (popup mode) the toolbar isn't tall enough to show the whole image. The |
| 114 // split happens between the top shadow section and the bottom gradient |
| 115 // section so that we never break the gradient. |
| 116 int split_point = kFrameShadowThickness * 2; |
| 117 int bottom_y = y + split_point; |
| 118 ui::ThemeProvider* tp = GetThemeProvider(); |
| 119 gfx::ImageSkia* toolbar_left = tp->GetImageSkiaNamed( |
| 120 IDR_CONTENT_TOP_LEFT_CORNER); |
| 121 int bottom_edge_height = std::min(toolbar_left->height(), h) - split_point; |
| 122 |
| 123 // Split our canvas out so we can mask out the corners of the toolbar |
| 124 // without masking out the frame. |
| 125 canvas->SaveLayerAlpha( |
| 126 255, gfx::Rect(x - kClientEdgeThickness, y, w + kClientEdgeThickness * 3, |
| 127 h)); |
| 128 |
| 129 // Paint the bottom rect. |
| 130 canvas->FillRect(gfx::Rect(x, bottom_y, w, bottom_edge_height), |
| 131 tp->GetColor(ThemeProperties::COLOR_TOOLBAR)); |
| 132 |
| 133 // Tile the toolbar image starting at the frame edge on the left and where the |
| 134 // horizontal tabstrip is (or would be) on the top. |
| 135 gfx::ImageSkia* theme_toolbar = tp->GetImageSkiaNamed(IDR_THEME_TOOLBAR); |
| 136 canvas->TileImageInt(*theme_toolbar, |
| 137 x + GetThemeBackgroundXInset(), |
| 138 bottom_y - GetTopInset(), |
| 139 x, bottom_y, w, theme_toolbar->height()); |
| 140 |
| 141 // Draw rounded corners for the tab. |
| 142 gfx::ImageSkia* toolbar_left_mask = |
| 143 tp->GetImageSkiaNamed(IDR_CONTENT_TOP_LEFT_CORNER_MASK); |
| 144 gfx::ImageSkia* toolbar_right_mask = |
| 145 tp->GetImageSkiaNamed(IDR_CONTENT_TOP_RIGHT_CORNER_MASK); |
| 146 |
| 147 // We mask out the corners by using the DestinationIn transfer mode, |
| 148 // which keeps the RGB pixels from the destination and the alpha from |
| 149 // the source. |
| 150 SkPaint paint; |
| 151 paint.setXfermodeMode(SkXfermode::kDstIn_Mode); |
| 152 |
| 153 // Mask the left edge. |
| 154 int left_x = x - kContentEdgeShadowThickness; |
| 155 canvas->DrawImageInt(*toolbar_left_mask, 0, 0, toolbar_left_mask->width(), |
| 156 split_point, left_x, y, toolbar_left_mask->width(), |
| 157 split_point, false, paint); |
| 158 canvas->DrawImageInt(*toolbar_left_mask, 0, |
| 159 toolbar_left_mask->height() - bottom_edge_height, |
| 160 toolbar_left_mask->width(), bottom_edge_height, left_x, bottom_y, |
| 161 toolbar_left_mask->width(), bottom_edge_height, false, paint); |
| 162 |
| 163 // Mask the right edge. |
| 164 int right_x = |
| 165 x + w - toolbar_right_mask->width() + kContentEdgeShadowThickness; |
| 166 canvas->DrawImageInt(*toolbar_right_mask, 0, 0, toolbar_right_mask->width(), |
| 167 split_point, right_x, y, toolbar_right_mask->width(), |
| 168 split_point, false, paint); |
| 169 canvas->DrawImageInt(*toolbar_right_mask, 0, |
| 170 toolbar_right_mask->height() - bottom_edge_height, |
| 171 toolbar_right_mask->width(), bottom_edge_height, right_x, bottom_y, |
| 172 toolbar_right_mask->width(), bottom_edge_height, false, paint); |
| 173 canvas->Restore(); |
| 174 |
| 175 canvas->DrawImageInt(*toolbar_left, 0, 0, toolbar_left->width(), split_point, |
| 176 left_x, y, toolbar_left->width(), split_point, false); |
| 177 canvas->DrawImageInt(*toolbar_left, 0, |
| 178 toolbar_left->height() - bottom_edge_height, toolbar_left->width(), |
| 179 bottom_edge_height, left_x, bottom_y, toolbar_left->width(), |
| 180 bottom_edge_height, false); |
| 181 |
| 182 gfx::ImageSkia* toolbar_center = |
| 183 tp->GetImageSkiaNamed(IDR_CONTENT_TOP_CENTER); |
| 184 canvas->TileImageInt(*toolbar_center, 0, 0, left_x + toolbar_left->width(), |
| 185 y, right_x - (left_x + toolbar_left->width()), |
| 186 split_point); |
| 187 |
| 188 gfx::ImageSkia* toolbar_right = tp->GetImageSkiaNamed( |
| 189 IDR_CONTENT_TOP_RIGHT_CORNER); |
| 190 canvas->DrawImageInt(*toolbar_right, 0, 0, toolbar_right->width(), |
| 191 split_point, right_x, y, toolbar_right->width(), split_point, false); |
| 192 canvas->DrawImageInt(*toolbar_right, 0, |
| 193 toolbar_right->height() - bottom_edge_height, toolbar_right->width(), |
| 194 bottom_edge_height, right_x, bottom_y, toolbar_right->width(), |
| 195 bottom_edge_height, false); |
| 196 |
| 197 // Draw the content/toolbar separator. |
| 198 canvas->FillRect( |
| 199 gfx::Rect(x + kClientEdgeThickness, |
| 200 toolbar_bounds.bottom() - kClientEdgeThickness, |
| 201 w - (2 * kClientEdgeThickness), |
| 202 kClientEdgeThickness), |
| 203 ThemeProperties::GetDefaultColor( |
| 204 ThemeProperties::COLOR_TOOLBAR_SEPARATOR)); |
| 205 } |
| 206 |
| 207 void BrowserFrameViewMac::OnPaint(gfx::Canvas* canvas) { |
| 208 // canvas->DrawColor(GetThemeProvider()->GetColor(ThemeProperties::COLOR_FRAME
)); |
| 209 gfx::ImageSkia* image = GetThemeProvider()->GetImageSkiaNamed(IDR_THEME_FRAME)
; |
| 210 canvas->TileImageInt(*image, 0, 0, width(), image->height()); |
| 211 |
| 212 PaintToolbarBackground(canvas); |
| 213 } |
OLD | NEW |