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

Side by Side Diff: ui/base/native_theme/native_theme_aura.cc

Issue 10447053: Converts remainder of ui and chrome/browser/ui/views/frame to use ImageSkia (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 6 months 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 | Annotate | Revision Log
« no previous file with comments | « ui/base/native_theme/native_theme_android.cc ('k') | ui/base/native_theme/native_theme_base.h » ('j') | 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 "ui/base/native_theme/native_theme_aura.h" 5 #include "ui/base/native_theme/native_theme_aura.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "grit/ui_resources_standard.h" 8 #include "grit/ui_resources_standard.h"
9 #include "ui/base/layout.h" 9 #include "ui/base/layout.h"
10 #include "ui/base/resource/resource_bundle.h" 10 #include "ui/base/resource/resource_bundle.h"
11 #include "ui/gfx/image/image_skia.h"
11 #include "ui/gfx/rect.h" 12 #include "ui/gfx/rect.h"
12 #include "ui/gfx/size.h" 13 #include "ui/gfx/size.h"
13 #include "ui/gfx/skbitmap_operations.h" 14 #include "ui/gfx/skbitmap_operations.h"
14 15
15 namespace { 16 namespace {
16 17
17 const SkColor kMenuBackgroundColor = SK_ColorWHITE; 18 const SkColor kMenuBackgroundColor = SK_ColorWHITE;
18 19
19 // Theme colors returned by GetSystemColor(). 20 // Theme colors returned by GetSystemColor().
20 const SkColor kInvalidColorIdColor = SkColorSetRGB(255, 0, 128); 21 const SkColor kInvalidColorIdColor = SkColorSetRGB(255, 0, 128);
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 152 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
152 if (part == kScrollbarVerticalTrack) { 153 if (part == kScrollbarVerticalTrack) {
153 int center_offset = 0; 154 int center_offset = 0;
154 int center_height = rect.height(); 155 int center_height = rect.height();
155 156
156 if (rect.y() == extra_params.track_y) { 157 if (rect.y() == extra_params.track_y) {
157 // TODO(derat): Honor |state| instead of only using the highlighted images 158 // TODO(derat): Honor |state| instead of only using the highlighted images
158 // after updating WebKit so we can draw the entire track in one go instead 159 // after updating WebKit so we can draw the entire track in one go instead
159 // of as two separate pieces: otherwise, only the portion of the scrollbar 160 // of as two separate pieces: otherwise, only the portion of the scrollbar
160 // that the mouse is over gets the highlighted state. 161 // that the mouse is over gets the highlighted state.
161 SkBitmap* top = rb.GetBitmapNamed(IDR_SCROLL_BASE_VERTICAL_TOP_H); 162 gfx::ImageSkia* top = rb.GetImageSkiaNamed(
163 IDR_SCROLL_BASE_VERTICAL_TOP_H);
162 DrawTiledImage(canvas, *top, 164 DrawTiledImage(canvas, *top,
163 0, 0, 1.0, 1.0, 165 0, 0, 1.0, 1.0,
164 rect.x(), rect.y(), top->width(), top->height()); 166 rect.x(), rect.y(), top->width(), top->height());
165 center_offset += top->height(); 167 center_offset += top->height();
166 center_height -= top->height(); 168 center_height -= top->height();
167 } 169 }
168 170
169 if (rect.y() + rect.height() == 171 if (rect.y() + rect.height() ==
170 extra_params.track_y + extra_params.track_height) { 172 extra_params.track_y + extra_params.track_height) {
171 SkBitmap* bottom = rb.GetBitmapNamed(IDR_SCROLL_BASE_VERTICAL_BOTTOM_H); 173 gfx::ImageSkia* bottom = rb.GetImageSkiaNamed(
174 IDR_SCROLL_BASE_VERTICAL_BOTTOM_H);
172 DrawTiledImage(canvas, *bottom, 175 DrawTiledImage(canvas, *bottom,
173 0, 0, 1.0, 1.0, 176 0, 0, 1.0, 1.0,
174 rect.x(), rect.y() + rect.height() - bottom->height(), 177 rect.x(), rect.y() + rect.height() - bottom->height(),
175 bottom->width(), bottom->height()); 178 bottom->width(), bottom->height());
176 center_height -= bottom->height(); 179 center_height -= bottom->height();
177 } 180 }
178 181
179 if (center_height > 0) { 182 if (center_height > 0) {
180 SkBitmap* center = rb.GetBitmapNamed(IDR_SCROLL_BASE_VERTICAL_CENTER_H); 183 gfx::ImageSkia* center = rb.GetImageSkiaNamed(
184 IDR_SCROLL_BASE_VERTICAL_CENTER_H);
181 DrawTiledImage(canvas, *center, 185 DrawTiledImage(canvas, *center,
182 0, 0, 1.0, 1.0, 186 0, 0, 1.0, 1.0,
183 rect.x(), rect.y() + center_offset, 187 rect.x(), rect.y() + center_offset,
184 center->width(), center_height); 188 center->width(), center_height);
185 } 189 }
186 } else { 190 } else {
187 int center_offset = 0; 191 int center_offset = 0;
188 int center_width = rect.width(); 192 int center_width = rect.width();
189 193
190 if (rect.x() == extra_params.track_x) { 194 if (rect.x() == extra_params.track_x) {
191 SkBitmap* left = rb.GetBitmapNamed(IDR_SCROLL_BASE_HORIZONTAL_LEFT_H); 195 gfx::ImageSkia* left = rb.GetImageSkiaNamed(
196 IDR_SCROLL_BASE_HORIZONTAL_LEFT_H);
192 DrawTiledImage(canvas, *left, 197 DrawTiledImage(canvas, *left,
193 0, 0, 1.0, 1.0, 198 0, 0, 1.0, 1.0,
194 rect.x(), rect.y(), left->width(), left->height()); 199 rect.x(), rect.y(), left->width(), left->height());
195 center_offset += left->width(); 200 center_offset += left->width();
196 center_width -= left->width(); 201 center_width -= left->width();
197 } 202 }
198 203
199 if (rect.x() + rect.width() == 204 if (rect.x() + rect.width() ==
200 extra_params.track_x + extra_params.track_width) { 205 extra_params.track_x + extra_params.track_width) {
201 SkBitmap* right = rb.GetBitmapNamed(IDR_SCROLL_BASE_HORIZONTAL_RIGHT_H); 206 gfx::ImageSkia* right = rb.GetImageSkiaNamed(
207 IDR_SCROLL_BASE_HORIZONTAL_RIGHT_H);
202 DrawTiledImage(canvas, *right, 208 DrawTiledImage(canvas, *right,
203 0, 0, 1.0, 1.0, 209 0, 0, 1.0, 1.0,
204 rect.x() + rect.width() - right->width(), rect.y(), 210 rect.x() + rect.width() - right->width(), rect.y(),
205 right->width(), right->height()); 211 right->width(), right->height());
206 center_width -= right->width(); 212 center_width -= right->width();
207 } 213 }
208 214
209 if (center_width > 0) { 215 if (center_width > 0) {
210 SkBitmap* center = rb.GetBitmapNamed(IDR_SCROLL_BASE_HORIZONTAL_CENTER_H); 216 gfx::ImageSkia* center = rb.GetImageSkiaNamed(
217 IDR_SCROLL_BASE_HORIZONTAL_CENTER_H);
211 DrawTiledImage(canvas, *center, 218 DrawTiledImage(canvas, *center,
212 0, 0, 1.0, 1.0, 219 0, 0, 1.0, 1.0,
213 rect.x() + center_offset, rect.y(), 220 rect.x() + center_offset, rect.y(),
214 center_width, center->height()); 221 center_width, center->height());
215 } 222 }
216 } 223 }
217 } 224 }
218 225
219 void NativeThemeAura::PaintArrowButton(SkCanvas* canvas, 226 void NativeThemeAura::PaintArrowButton(SkCanvas* canvas,
220 const gfx::Rect& rect, 227 const gfx::Rect& rect,
221 Part part, 228 Part part,
222 State state) const { 229 State state) const {
223 DCHECK(rect.IsEmpty()); 230 DCHECK(rect.IsEmpty());
224 } 231 }
225 232
226 void NativeThemeAura::PaintScrollbarThumb(SkCanvas* canvas, 233 void NativeThemeAura::PaintScrollbarThumb(SkCanvas* canvas,
227 Part part, 234 Part part,
228 State state, 235 State state,
229 const gfx::Rect& rect) const { 236 const gfx::Rect& rect) const {
230 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 237 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
231 if (part == kScrollbarVerticalThumb) { 238 if (part == kScrollbarVerticalThumb) {
232 int top_resource_id = 239 int top_resource_id =
233 state == kHovered ? IDR_SCROLL_THUMB_VERTICAL_TOP_H : 240 state == kHovered ? IDR_SCROLL_THUMB_VERTICAL_TOP_H :
234 state == kPressed ? IDR_SCROLL_THUMB_VERTICAL_TOP_P : 241 state == kPressed ? IDR_SCROLL_THUMB_VERTICAL_TOP_P :
235 IDR_SCROLL_THUMB_VERTICAL_TOP; 242 IDR_SCROLL_THUMB_VERTICAL_TOP;
236 SkBitmap* top = rb.GetBitmapNamed(top_resource_id); 243 gfx::ImageSkia* top = rb.GetImageSkiaNamed(top_resource_id);
237 DrawTiledImage(canvas, *top, 244 DrawTiledImage(canvas, *top,
238 0, 0, 1.0, 1.0, 245 0, 0, 1.0, 1.0,
239 rect.x(), rect.y(), top->width(), top->height()); 246 rect.x(), rect.y(), top->width(), top->height());
240 247
241 int bottom_resource_id = 248 int bottom_resource_id =
242 state == kHovered ? IDR_SCROLL_THUMB_VERTICAL_BOTTOM_H : 249 state == kHovered ? IDR_SCROLL_THUMB_VERTICAL_BOTTOM_H :
243 state == kPressed ? IDR_SCROLL_THUMB_VERTICAL_BOTTOM_P : 250 state == kPressed ? IDR_SCROLL_THUMB_VERTICAL_BOTTOM_P :
244 IDR_SCROLL_THUMB_VERTICAL_BOTTOM; 251 IDR_SCROLL_THUMB_VERTICAL_BOTTOM;
245 SkBitmap* bottom = rb.GetBitmapNamed(bottom_resource_id); 252 gfx::ImageSkia* bottom = rb.GetImageSkiaNamed(bottom_resource_id);
246 DrawTiledImage(canvas, *bottom, 253 DrawTiledImage(canvas, *bottom,
247 0, 0, 1.0, 1.0, 254 0, 0, 1.0, 1.0,
248 rect.x(), rect.y() + rect.height() - bottom->height(), 255 rect.x(), rect.y() + rect.height() - bottom->height(),
249 bottom->width(), bottom->height()); 256 bottom->width(), bottom->height());
250 257
251 if (rect.height() > top->height() + bottom->height()) { 258 if (rect.height() > top->height() + bottom->height()) {
252 int center_resource_id = 259 int center_resource_id =
253 state == kHovered ? IDR_SCROLL_THUMB_VERTICAL_CENTER_H : 260 state == kHovered ? IDR_SCROLL_THUMB_VERTICAL_CENTER_H :
254 state == kPressed ? IDR_SCROLL_THUMB_VERTICAL_CENTER_P : 261 state == kPressed ? IDR_SCROLL_THUMB_VERTICAL_CENTER_P :
255 IDR_SCROLL_THUMB_VERTICAL_CENTER; 262 IDR_SCROLL_THUMB_VERTICAL_CENTER;
256 SkBitmap* center = rb.GetBitmapNamed(center_resource_id); 263 gfx::ImageSkia* center = rb.GetImageSkiaNamed(center_resource_id);
257 DrawTiledImage(canvas, *center, 264 DrawTiledImage(canvas, *center,
258 0, 0, 1.0, 1.0, 265 0, 0, 1.0, 1.0,
259 rect.x(), rect.y() + top->height(), 266 rect.x(), rect.y() + top->height(),
260 center->width(), 267 center->width(),
261 rect.height() - top->height() - bottom->height()); 268 rect.height() - top->height() - bottom->height());
262 } 269 }
263 } else { 270 } else {
264 int left_resource_id = 271 int left_resource_id =
265 state == kHovered ? IDR_SCROLL_THUMB_HORIZONTAL_LEFT_H : 272 state == kHovered ? IDR_SCROLL_THUMB_HORIZONTAL_LEFT_H :
266 state == kPressed ? IDR_SCROLL_THUMB_HORIZONTAL_LEFT_P : 273 state == kPressed ? IDR_SCROLL_THUMB_HORIZONTAL_LEFT_P :
267 IDR_SCROLL_THUMB_HORIZONTAL_LEFT; 274 IDR_SCROLL_THUMB_HORIZONTAL_LEFT;
268 SkBitmap* left = rb.GetBitmapNamed(left_resource_id); 275 gfx::ImageSkia* left = rb.GetImageSkiaNamed(left_resource_id);
269 DrawTiledImage(canvas, *left, 276 DrawTiledImage(canvas, *left,
270 0, 0, 1.0, 1.0, 277 0, 0, 1.0, 1.0,
271 rect.x(), rect.y(), left->width(), left->height()); 278 rect.x(), rect.y(), left->width(), left->height());
272 279
273 int right_resource_id = 280 int right_resource_id =
274 state == kHovered ? IDR_SCROLL_THUMB_HORIZONTAL_RIGHT_H : 281 state == kHovered ? IDR_SCROLL_THUMB_HORIZONTAL_RIGHT_H :
275 state == kPressed ? IDR_SCROLL_THUMB_HORIZONTAL_RIGHT_P : 282 state == kPressed ? IDR_SCROLL_THUMB_HORIZONTAL_RIGHT_P :
276 IDR_SCROLL_THUMB_HORIZONTAL_RIGHT; 283 IDR_SCROLL_THUMB_HORIZONTAL_RIGHT;
277 SkBitmap* right = rb.GetBitmapNamed(right_resource_id); 284 gfx::ImageSkia* right = rb.GetImageSkiaNamed(right_resource_id);
278 DrawTiledImage(canvas, *right, 285 DrawTiledImage(canvas, *right,
279 0, 0, 1.0, 1.0, 286 0, 0, 1.0, 1.0,
280 rect.x() + rect.width() - right->width(), rect.y(), 287 rect.x() + rect.width() - right->width(), rect.y(),
281 right->width(), right->height()); 288 right->width(), right->height());
282 289
283 if (rect.width() > left->width() + right->width()) { 290 if (rect.width() > left->width() + right->width()) {
284 int center_resource_id = 291 int center_resource_id =
285 state == kHovered ? IDR_SCROLL_THUMB_HORIZONTAL_CENTER_H : 292 state == kHovered ? IDR_SCROLL_THUMB_HORIZONTAL_CENTER_H :
286 state == kPressed ? IDR_SCROLL_THUMB_HORIZONTAL_CENTER_P : 293 state == kPressed ? IDR_SCROLL_THUMB_HORIZONTAL_CENTER_P :
287 IDR_SCROLL_THUMB_HORIZONTAL_CENTER; 294 IDR_SCROLL_THUMB_HORIZONTAL_CENTER;
288 SkBitmap* center = rb.GetBitmapNamed(center_resource_id); 295 gfx::ImageSkia* center = rb.GetImageSkiaNamed(center_resource_id);
289 DrawTiledImage(canvas, *center, 296 DrawTiledImage(canvas, *center,
290 0, 0, 1.0, 1.0, 297 0, 0, 1.0, 1.0,
291 rect.x() + left->width(), rect.y(), 298 rect.x() + left->width(), rect.y(),
292 rect.width() - left->width() - right->width(), 299 rect.width() - left->width() - right->width(),
293 center->height()); 300 center->height());
294 } 301 }
295 } 302 }
296 } 303 }
297 304
298 } // namespace ui 305 } // namespace ui
OLDNEW
« no previous file with comments | « ui/base/native_theme/native_theme_android.cc ('k') | ui/base/native_theme/native_theme_base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698