Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(863)

Side by Side Diff: chrome/browser/ui/views/detachable_toolbar_view.cc

Issue 795353003: views: Cleanup some things in DetachableToolbarView class. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/ui/views/detachable_toolbar_view.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/views/detachable_toolbar_view.h" 5 #include "chrome/browser/ui/views/detachable_toolbar_view.h"
6 6
7 #include "chrome/browser/themes/theme_properties.h" 7 #include "chrome/browser/themes/theme_properties.h"
8 #include "grit/theme_resources.h" 8 #include "grit/theme_resources.h"
9 #include "third_party/skia/include/core/SkShader.h" 9 #include "third_party/skia/include/core/SkShader.h"
10 #include "ui/base/resource/resource_bundle.h" 10 #include "ui/base/resource/resource_bundle.h"
11 #include "ui/base/theme_provider.h" 11 #include "ui/base/theme_provider.h"
12 #include "ui/gfx/canvas.h" 12 #include "ui/gfx/canvas.h"
13 #include "ui/gfx/image/image_skia.h" 13 #include "ui/gfx/image/image_skia.h"
14 #include "ui/gfx/skia_util.h" 14 #include "ui/gfx/skia_util.h"
15 #include "ui/views/window/non_client_view.h" 15 #include "ui/views/window/non_client_view.h"
16 16
17 namespace {
18
19 // How round the 'new tab' style bookmarks bar is.
20 const int kNewTabBarRoundness = 5;
21
22 } // namespace
23
24 const SkColor DetachableToolbarView::kEdgeDividerColor =
25 SkColorSetRGB(222, 234, 248);
26 const SkColor DetachableToolbarView::kMiddleDividerColor =
27 SkColorSetRGB(194, 205, 212);
28
29 // static 17 // static
30 void DetachableToolbarView::PaintBackgroundAttachedMode( 18 void DetachableToolbarView::PaintBackgroundAttachedMode(
31 gfx::Canvas* canvas, 19 gfx::Canvas* canvas,
32 ui::ThemeProvider* theme_provider, 20 ui::ThemeProvider* theme_provider,
33 const gfx::Rect& bounds, 21 const gfx::Rect& bounds,
34 const gfx::Point& background_origin, 22 const gfx::Point& background_origin,
35 chrome::HostDesktopType host_desktop_type) { 23 chrome::HostDesktopType host_desktop_type) {
36 canvas->FillRect(bounds, 24 canvas->FillRect(bounds,
37 theme_provider->GetColor(ThemeProperties::COLOR_TOOLBAR)); 25 theme_provider->GetColor(ThemeProperties::COLOR_TOOLBAR));
38 canvas->TileImageInt(*theme_provider->GetImageSkiaNamed(IDR_THEME_TOOLBAR), 26 canvas->TileImageInt(*theme_provider->GetImageSkiaNamed(IDR_THEME_TOOLBAR),
39 background_origin.x(), background_origin.y(), bounds.x(), 27 background_origin.x(),
40 bounds.y(), bounds.width(), bounds.height()); 28 background_origin.y(),
29 bounds.x(),
30 bounds.y(),
31 bounds.width(),
32 bounds.height());
41 33
42 if (host_desktop_type == chrome::HOST_DESKTOP_TYPE_ASH) { 34 if (host_desktop_type == chrome::HOST_DESKTOP_TYPE_ASH) {
43 // Ash provides additional lightening at the edges of the toolbar. 35 // Ash provides additional lightening at the edges of the toolbar.
44 gfx::ImageSkia* toolbar_left = 36 gfx::ImageSkia* toolbar_left =
45 theme_provider->GetImageSkiaNamed(IDR_TOOLBAR_SHADE_LEFT); 37 theme_provider->GetImageSkiaNamed(IDR_TOOLBAR_SHADE_LEFT);
46 canvas->TileImageInt(*toolbar_left, 38 canvas->TileImageInt(*toolbar_left,
47 bounds.x(), bounds.y(), 39 bounds.x(),
48 toolbar_left->width(), bounds.height()); 40 bounds.y(),
41 toolbar_left->width(),
42 bounds.height());
49 gfx::ImageSkia* toolbar_right = 43 gfx::ImageSkia* toolbar_right =
50 theme_provider->GetImageSkiaNamed(IDR_TOOLBAR_SHADE_RIGHT); 44 theme_provider->GetImageSkiaNamed(IDR_TOOLBAR_SHADE_RIGHT);
51 canvas->TileImageInt(*toolbar_right, 45 canvas->TileImageInt(*toolbar_right,
52 bounds.right() - toolbar_right->width(), bounds.y(), 46 bounds.right() - toolbar_right->width(),
53 toolbar_right->width(), bounds.height()); 47 bounds.y(),
48 toolbar_right->width(),
49 bounds.height());
54 } 50 }
55 } 51 }
56 52
57 // static 53 // static
58 void DetachableToolbarView::CalculateContentArea(double animation_state,
59 double horizontal_padding,
60 double vertical_padding,
61 SkRect* rect,
62 double* roundness,
63 views::View* view) {
64 // The 0.5 is to correct for Skia's "draw on pixel boundaries"ness.
65 rect->set(SkDoubleToScalar(horizontal_padding - 0.5),
66 SkDoubleToScalar(vertical_padding - 0.5),
67 SkDoubleToScalar(view->width() - horizontal_padding - 0.5),
68 SkDoubleToScalar(view->height() - vertical_padding - 0.5));
69
70 *roundness = static_cast<double>(kNewTabBarRoundness) * animation_state;
71 }
72
73 // static
74 void DetachableToolbarView::PaintHorizontalBorder(gfx::Canvas* canvas, 54 void DetachableToolbarView::PaintHorizontalBorder(gfx::Canvas* canvas,
75 DetachableToolbarView* view, 55 DetachableToolbarView* view,
76 bool at_top, 56 bool at_top,
77 SkColor color) { 57 SkColor color) {
78 int thickness = views::NonClientFrameView::kClientEdgeThickness; 58 int thickness = views::NonClientFrameView::kClientEdgeThickness;
79 int y = at_top ? 0 : (view->height() - thickness); 59 int y = at_top ? 0 : (view->height() - thickness);
80 canvas->FillRect(gfx::Rect(0, y, view->width(), thickness), color); 60 canvas->FillRect(gfx::Rect(0, y, view->width(), thickness), color);
81 } 61 }
82 62
83 // static 63 // static
84 void DetachableToolbarView::PaintContentAreaBackground(
85 gfx::Canvas* canvas,
86 ui::ThemeProvider* theme_provider,
87 const SkRect& rect,
88 double roundness) {
89 SkPaint paint;
90 paint.setAntiAlias(true);
91 paint.setColor(theme_provider->GetColor(ThemeProperties::COLOR_TOOLBAR));
92
93 canvas->sk_canvas()->drawRoundRect(
94 rect, SkDoubleToScalar(roundness), SkDoubleToScalar(roundness), paint);
95 }
96
97 // static
98 void DetachableToolbarView::PaintContentAreaBorder(
99 gfx::Canvas* canvas,
100 ui::ThemeProvider* theme_provider,
101 const SkRect& rect,
102 double roundness) {
103 SkPaint border_paint;
104 border_paint.setColor(
105 theme_provider->GetColor(ThemeProperties::COLOR_NTP_HEADER));
106 border_paint.setStyle(SkPaint::kStroke_Style);
107 border_paint.setAlpha(96);
108 border_paint.setAntiAlias(true);
109
110 canvas->sk_canvas()->drawRoundRect(
111 rect, SkDoubleToScalar(roundness), SkDoubleToScalar(roundness),
112 border_paint);
113 }
114
115 // static
116 void DetachableToolbarView::PaintVerticalDivider(gfx::Canvas* canvas, 64 void DetachableToolbarView::PaintVerticalDivider(gfx::Canvas* canvas,
117 int x, 65 int x,
118 int height, 66 int height,
119 int vertical_padding, 67 int vertical_padding,
120 SkColor top_color, 68 SkColor top_color,
121 SkColor middle_color, 69 SkColor middle_color,
122 SkColor bottom_color) { 70 SkColor bottom_color) {
123 // Draw the upper half of the divider. 71 // Draw the upper half of the divider.
124 SkPaint paint; 72 SkPaint paint;
125 skia::RefPtr<SkShader> shader = gfx::CreateGradientShader( 73 skia::RefPtr<SkShader> shader = gfx::CreateGradientShader(
126 vertical_padding + 1, height / 2, top_color, middle_color); 74 vertical_padding + 1, height / 2, top_color, middle_color);
127 paint.setShader(shader.get()); 75 paint.setShader(shader.get());
128 SkRect rc = { SkIntToScalar(x), 76 SkRect rc = { SkIntToScalar(x),
129 SkIntToScalar(vertical_padding + 1), 77 SkIntToScalar(vertical_padding + 1),
130 SkIntToScalar(x + 1), 78 SkIntToScalar(x + 1),
131 SkIntToScalar(height / 2) }; 79 SkIntToScalar(height / 2) };
132 canvas->sk_canvas()->drawRect(rc, paint); 80 canvas->sk_canvas()->drawRect(rc, paint);
133 81
134 // Draw the lower half of the divider. 82 // Draw the lower half of the divider.
135 SkPaint paint_down; 83 SkPaint paint_down;
136 shader = gfx::CreateGradientShader( 84 shader = gfx::CreateGradientShader(
137 height / 2, height - vertical_padding, middle_color, bottom_color); 85 height / 2, height - vertical_padding, middle_color, bottom_color);
138 paint_down.setShader(shader.get()); 86 paint_down.setShader(shader.get());
139 SkRect rc_down = { SkIntToScalar(x), 87 SkRect rc_down = { SkIntToScalar(x),
140 SkIntToScalar(height / 2), 88 SkIntToScalar(height / 2),
141 SkIntToScalar(x + 1), 89 SkIntToScalar(x + 1),
142 SkIntToScalar(height - vertical_padding) }; 90 SkIntToScalar(height - vertical_padding) };
143 canvas->sk_canvas()->drawRect(rc_down, paint_down); 91 canvas->sk_canvas()->drawRect(rc_down, paint_down);
144 } 92 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/detachable_toolbar_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698