- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / views / detachable_toolbar_view.cc
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.
4
5 #include "chrome/browser/ui/views/detachable_toolbar_view.h"
6
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"
16
17 // How round the 'new tab' style bookmarks bar is.
18 static const int kNewtabBarRoundness = 5;
19
20 const SkColor DetachableToolbarView::kEdgeDividerColor =
21     SkColorSetRGB(222, 234, 248);
22 const SkColor DetachableToolbarView::kMiddleDividerColor =
23     SkColorSetRGB(194, 205, 212);
24
25 // static
26 void DetachableToolbarView::PaintBackgroundAttachedMode(
27     gfx::Canvas* canvas,
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());
37 #if defined(USE_ASH)
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());
50   }
51 #endif
52 }
53
54 // static
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));
64
65   *roundness = static_cast<double>(kNewtabBarRoundness) * animation_state;
66 }
67
68 // static
69 void DetachableToolbarView::PaintHorizontalBorder(
70     gfx::Canvas* canvas,
71     DetachableToolbarView* view,
72     bool at_top,
73     SkColor color) {
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);
77 }
78
79 // static
80 void DetachableToolbarView::PaintContentAreaBackground(
81     gfx::Canvas* canvas,
82     ui::ThemeProvider* theme_provider,
83     const SkRect& rect,
84     double roundness) {
85   SkPaint paint;
86   paint.setAntiAlias(true);
87   paint.setColor(theme_provider->GetColor(ThemeProperties::COLOR_TOOLBAR));
88
89   canvas->sk_canvas()->drawRoundRect(
90       rect, SkDoubleToScalar(roundness), SkDoubleToScalar(roundness), paint);
91 }
92
93 // static
94 void DetachableToolbarView::PaintContentAreaBorder(
95     gfx::Canvas* canvas, ui::ThemeProvider* theme_provider,
96     const SkRect& rect, double roundness) {
97   SkPaint border_paint;
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);
103
104   canvas->sk_canvas()->drawRoundRect(
105       rect, SkDoubleToScalar(roundness), SkDoubleToScalar(roundness),
106       border_paint);
107 }
108
109 // static
110 void DetachableToolbarView::PaintVerticalDivider(gfx::Canvas* canvas,
111                                                  int x,
112                                                  int height,
113                                                  int vertical_padding,
114                                                  SkColor top_color,
115                                                  SkColor middle_color,
116                                                  SkColor bottom_color) {
117   // Draw the upper half of the divider.
118   SkPaint paint;
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);
127
128   // Draw the lower half of the divider.
129   SkPaint paint_down;
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);
138 }