testOobeLocalization implementation
[chromium-blink-merge.git] / ui / native_theme / native_theme_aura.cc
blobc4e87243585611730299cb561611489e2b24055e
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 "ui/native_theme/native_theme_aura.h"
7 #include "base/logging.h"
8 #include "grit/ui_resources.h"
9 #include "ui/base/layout.h"
10 #include "ui/base/resource/resource_bundle.h"
11 #include "ui/gfx/image/image_skia.h"
12 #include "ui/gfx/path.h"
13 #include "ui/gfx/rect.h"
14 #include "ui/gfx/size.h"
15 #include "ui/gfx/skbitmap_operations.h"
16 #include "ui/native_theme/common_theme.h"
18 namespace ui {
20 // static
21 NativeTheme* NativeTheme::instance() {
22 return NativeThemeAura::instance();
25 // static
26 NativeThemeAura* NativeThemeAura::instance() {
27 CR_DEFINE_STATIC_LOCAL(NativeThemeAura, s_native_theme, ());
28 return &s_native_theme;
31 NativeThemeAura::NativeThemeAura() {
32 // We don't draw scrollbar buttons.
33 set_scrollbar_button_length(0);
36 NativeThemeAura::~NativeThemeAura() {
39 void NativeThemeAura::PaintMenuPopupBackground(
40 SkCanvas* canvas,
41 const gfx::Size& size,
42 const MenuBackgroundExtraParams& menu_background) const {
43 SkColor color = GetSystemColor(NativeTheme::kColorId_MenuBackgroundColor);
44 if (menu_background.corner_radius > 0) {
45 SkPaint paint;
46 paint.setStyle(SkPaint::kFill_Style);
47 paint.setFlags(SkPaint::kAntiAlias_Flag);
48 paint.setColor(color);
50 gfx::Path path;
51 SkRect rect = SkRect::MakeWH(SkIntToScalar(size.width()),
52 SkIntToScalar(size.height()));
53 SkScalar radius = SkIntToScalar(menu_background.corner_radius);
54 SkScalar radii[8] = {radius, radius, radius, radius,
55 radius, radius, radius, radius};
56 path.addRoundRect(rect, radii);
58 canvas->drawPath(path, paint);
59 } else {
60 canvas->drawColor(color, SkXfermode::kSrc_Mode);
64 void NativeThemeAura::PaintMenuItemBackground(
65 SkCanvas* canvas,
66 State state,
67 const gfx::Rect& rect,
68 const MenuListExtraParams& menu_list) const {
69 CommonThemePaintMenuItemBackground(canvas, state, rect);
72 void NativeThemeAura::PaintScrollbarTrack(
73 SkCanvas* canvas,
74 Part part,
75 State state,
76 const ScrollbarTrackExtraParams& extra_params,
77 const gfx::Rect& rect) const {
78 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
79 if (part == kScrollbarVerticalTrack) {
80 int center_offset = 0;
81 int center_height = rect.height();
83 if (rect.y() == extra_params.track_y) {
84 // TODO(derat): Honor |state| instead of only using the highlighted images
85 // after updating WebKit so we can draw the entire track in one go instead
86 // of as two separate pieces: otherwise, only the portion of the scrollbar
87 // that the mouse is over gets the highlighted state.
88 gfx::ImageSkia* top = rb.GetImageSkiaNamed(
89 IDR_SCROLL_BASE_VERTICAL_TOP_H);
90 DrawTiledImage(canvas, *top,
91 0, 0, 1.0, 1.0,
92 rect.x(), rect.y(), top->width(), top->height());
93 center_offset += top->height();
94 center_height -= top->height();
97 if (rect.y() + rect.height() ==
98 extra_params.track_y + extra_params.track_height) {
99 gfx::ImageSkia* bottom = rb.GetImageSkiaNamed(
100 IDR_SCROLL_BASE_VERTICAL_BOTTOM_H);
101 DrawTiledImage(canvas, *bottom,
102 0, 0, 1.0, 1.0,
103 rect.x(), rect.y() + rect.height() - bottom->height(),
104 bottom->width(), bottom->height());
105 center_height -= bottom->height();
108 if (center_height > 0) {
109 gfx::ImageSkia* center = rb.GetImageSkiaNamed(
110 IDR_SCROLL_BASE_VERTICAL_CENTER_H);
111 DrawTiledImage(canvas, *center,
112 0, 0, 1.0, 1.0,
113 rect.x(), rect.y() + center_offset,
114 center->width(), center_height);
116 } else {
117 int center_offset = 0;
118 int center_width = rect.width();
120 if (rect.x() == extra_params.track_x) {
121 gfx::ImageSkia* left = rb.GetImageSkiaNamed(
122 IDR_SCROLL_BASE_HORIZONTAL_LEFT_H);
123 DrawTiledImage(canvas, *left,
124 0, 0, 1.0, 1.0,
125 rect.x(), rect.y(), left->width(), left->height());
126 center_offset += left->width();
127 center_width -= left->width();
130 if (rect.x() + rect.width() ==
131 extra_params.track_x + extra_params.track_width) {
132 gfx::ImageSkia* right = rb.GetImageSkiaNamed(
133 IDR_SCROLL_BASE_HORIZONTAL_RIGHT_H);
134 DrawTiledImage(canvas, *right,
135 0, 0, 1.0, 1.0,
136 rect.x() + rect.width() - right->width(), rect.y(),
137 right->width(), right->height());
138 center_width -= right->width();
141 if (center_width > 0) {
142 gfx::ImageSkia* center = rb.GetImageSkiaNamed(
143 IDR_SCROLL_BASE_HORIZONTAL_CENTER_H);
144 DrawTiledImage(canvas, *center,
145 0, 0, 1.0, 1.0,
146 rect.x() + center_offset, rect.y(),
147 center_width, center->height());
152 void NativeThemeAura::PaintScrollbarThumb(SkCanvas* canvas,
153 Part part,
154 State state,
155 const gfx::Rect& rect) const {
156 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
157 if (part == kScrollbarVerticalThumb) {
158 int top_resource_id =
159 state == kHovered ? IDR_SCROLL_THUMB_VERTICAL_TOP_H :
160 state == kPressed ? IDR_SCROLL_THUMB_VERTICAL_TOP_P :
161 IDR_SCROLL_THUMB_VERTICAL_TOP;
162 gfx::ImageSkia* top = rb.GetImageSkiaNamed(top_resource_id);
163 DrawTiledImage(canvas, *top,
164 0, 0, 1.0, 1.0,
165 rect.x(), rect.y(), top->width(), top->height());
167 int bottom_resource_id =
168 state == kHovered ? IDR_SCROLL_THUMB_VERTICAL_BOTTOM_H :
169 state == kPressed ? IDR_SCROLL_THUMB_VERTICAL_BOTTOM_P :
170 IDR_SCROLL_THUMB_VERTICAL_BOTTOM;
171 gfx::ImageSkia* bottom = rb.GetImageSkiaNamed(bottom_resource_id);
172 DrawTiledImage(canvas, *bottom,
173 0, 0, 1.0, 1.0,
174 rect.x(), rect.y() + rect.height() - bottom->height(),
175 bottom->width(), bottom->height());
177 if (rect.height() > top->height() + bottom->height()) {
178 int center_resource_id =
179 state == kHovered ? IDR_SCROLL_THUMB_VERTICAL_CENTER_H :
180 state == kPressed ? IDR_SCROLL_THUMB_VERTICAL_CENTER_P :
181 IDR_SCROLL_THUMB_VERTICAL_CENTER;
182 gfx::ImageSkia* center = rb.GetImageSkiaNamed(center_resource_id);
183 DrawTiledImage(canvas, *center,
184 0, 0, 1.0, 1.0,
185 rect.x(), rect.y() + top->height(),
186 center->width(),
187 rect.height() - top->height() - bottom->height());
189 } else {
190 int left_resource_id =
191 state == kHovered ? IDR_SCROLL_THUMB_HORIZONTAL_LEFT_H :
192 state == kPressed ? IDR_SCROLL_THUMB_HORIZONTAL_LEFT_P :
193 IDR_SCROLL_THUMB_HORIZONTAL_LEFT;
194 gfx::ImageSkia* left = rb.GetImageSkiaNamed(left_resource_id);
195 DrawTiledImage(canvas, *left,
196 0, 0, 1.0, 1.0,
197 rect.x(), rect.y(), left->width(), left->height());
199 int right_resource_id =
200 state == kHovered ? IDR_SCROLL_THUMB_HORIZONTAL_RIGHT_H :
201 state == kPressed ? IDR_SCROLL_THUMB_HORIZONTAL_RIGHT_P :
202 IDR_SCROLL_THUMB_HORIZONTAL_RIGHT;
203 gfx::ImageSkia* right = rb.GetImageSkiaNamed(right_resource_id);
204 DrawTiledImage(canvas, *right,
205 0, 0, 1.0, 1.0,
206 rect.x() + rect.width() - right->width(), rect.y(),
207 right->width(), right->height());
209 if (rect.width() > left->width() + right->width()) {
210 int center_resource_id =
211 state == kHovered ? IDR_SCROLL_THUMB_HORIZONTAL_CENTER_H :
212 state == kPressed ? IDR_SCROLL_THUMB_HORIZONTAL_CENTER_P :
213 IDR_SCROLL_THUMB_HORIZONTAL_CENTER;
214 gfx::ImageSkia* center = rb.GetImageSkiaNamed(center_resource_id);
215 DrawTiledImage(canvas, *center,
216 0, 0, 1.0, 1.0,
217 rect.x() + left->width(), rect.y(),
218 rect.width() - left->width() - right->width(),
219 center->height());
224 } // namespace ui