1 // Copyright (c) 2012 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/detachable_toolbar_view.h"
7 #include "chrome/browser/themes/theme_properties.h"
8 #include "grit/theme_resources.h"
9 #include "third_party/skia/include/core/SkShader.h"
10 #include "ui/base/resource/resource_bundle.h"
11 #include "ui/base/theme_provider.h"
12 #include "ui/gfx/canvas.h"
13 #include "ui/gfx/image/image_skia.h"
14 #include "ui/gfx/skia_util.h"
15 #include "ui/views/window/non_client_view.h"
17 // How round the 'new tab' style bookmarks bar is.
18 static const int kNewtabBarRoundness
= 5;
20 const SkColor
DetachableToolbarView::kEdgeDividerColor
=
21 SkColorSetRGB(222, 234, 248);
22 const SkColor
DetachableToolbarView::kMiddleDividerColor
=
23 SkColorSetRGB(194, 205, 212);
26 void DetachableToolbarView::PaintBackgroundAttachedMode(
28 ui::ThemeProvider
* theme_provider
,
29 const gfx::Rect
& bounds
,
30 const gfx::Point
& background_origin
,
31 chrome::HostDesktopType host_desktop_type
) {
32 canvas
->FillRect(bounds
,
33 theme_provider
->GetColor(ThemeProperties::COLOR_TOOLBAR
));
34 canvas
->TileImageInt(*theme_provider
->GetImageSkiaNamed(IDR_THEME_TOOLBAR
),
35 background_origin
.x(), background_origin
.y(), bounds
.x(),
36 bounds
.y(), bounds
.width(), bounds
.height());
38 if (host_desktop_type
== chrome::HOST_DESKTOP_TYPE_ASH
) {
39 // Ash provides additional lightening at the edges of the toolbar.
40 gfx::ImageSkia
* toolbar_left
=
41 theme_provider
->GetImageSkiaNamed(IDR_TOOLBAR_SHADE_LEFT
);
42 canvas
->TileImageInt(*toolbar_left
,
43 bounds
.x(), bounds
.y(),
44 toolbar_left
->width(), bounds
.height());
45 gfx::ImageSkia
* toolbar_right
=
46 theme_provider
->GetImageSkiaNamed(IDR_TOOLBAR_SHADE_RIGHT
);
47 canvas
->TileImageInt(*toolbar_right
,
48 bounds
.right() - toolbar_right
->width(), bounds
.y(),
49 toolbar_right
->width(), bounds
.height());
55 void DetachableToolbarView::CalculateContentArea(
56 double animation_state
, double horizontal_padding
,
57 double vertical_padding
, SkRect
* rect
,
58 double* roundness
, views::View
* view
) {
59 // The 0.5 is to correct for Skia's "draw on pixel boundaries"ness.
60 rect
->set(SkDoubleToScalar(horizontal_padding
- 0.5),
61 SkDoubleToScalar(vertical_padding
- 0.5),
62 SkDoubleToScalar(view
->width() - horizontal_padding
- 0.5),
63 SkDoubleToScalar(view
->height() - vertical_padding
- 0.5));
65 *roundness
= static_cast<double>(kNewtabBarRoundness
) * animation_state
;
69 void DetachableToolbarView::PaintHorizontalBorder(
71 DetachableToolbarView
* view
,
74 int thickness
= views::NonClientFrameView::kClientEdgeThickness
;
75 int y
= at_top
? 0 : (view
->height() - thickness
);
76 canvas
->FillRect(gfx::Rect(0, y
, view
->width(), thickness
), color
);
80 void DetachableToolbarView::PaintContentAreaBackground(
82 ui::ThemeProvider
* theme_provider
,
86 paint
.setAntiAlias(true);
87 paint
.setColor(theme_provider
->GetColor(ThemeProperties::COLOR_TOOLBAR
));
89 canvas
->sk_canvas()->drawRoundRect(
90 rect
, SkDoubleToScalar(roundness
), SkDoubleToScalar(roundness
), paint
);
94 void DetachableToolbarView::PaintContentAreaBorder(
95 gfx::Canvas
* canvas
, ui::ThemeProvider
* theme_provider
,
96 const SkRect
& rect
, double roundness
) {
98 border_paint
.setColor(
99 theme_provider
->GetColor(ThemeProperties::COLOR_NTP_HEADER
));
100 border_paint
.setStyle(SkPaint::kStroke_Style
);
101 border_paint
.setAlpha(96);
102 border_paint
.setAntiAlias(true);
104 canvas
->sk_canvas()->drawRoundRect(
105 rect
, SkDoubleToScalar(roundness
), SkDoubleToScalar(roundness
),
110 void DetachableToolbarView::PaintVerticalDivider(gfx::Canvas
* canvas
,
113 int vertical_padding
,
115 SkColor middle_color
,
116 SkColor bottom_color
) {
117 // Draw the upper half of the divider.
119 skia::RefPtr
<SkShader
> shader
= gfx::CreateGradientShader(
120 vertical_padding
+ 1, height
/ 2, top_color
, middle_color
);
121 paint
.setShader(shader
.get());
122 SkRect rc
= { SkIntToScalar(x
),
123 SkIntToScalar(vertical_padding
+ 1),
124 SkIntToScalar(x
+ 1),
125 SkIntToScalar(height
/ 2) };
126 canvas
->sk_canvas()->drawRect(rc
, paint
);
128 // Draw the lower half of the divider.
130 shader
= gfx::CreateGradientShader(
131 height
/ 2, height
- vertical_padding
, middle_color
, bottom_color
);
132 paint_down
.setShader(shader
.get());
133 SkRect rc_down
= { SkIntToScalar(x
),
134 SkIntToScalar(height
/ 2),
135 SkIntToScalar(x
+ 1),
136 SkIntToScalar(height
- vertical_padding
) };
137 canvas
->sk_canvas()->drawRect(rc_down
, paint_down
);