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

Side by Side Diff: ui/native_theme/native_theme_base.cc

Issue 143953007: Changes look for scrollbars on windows (2) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix Created 6 years, 11 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/native_theme/native_theme_base.h ('k') | ui/native_theme/native_theme_win.cc » ('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/native_theme/native_theme_base.h" 5 #include "ui/native_theme/native_theme_base.h"
6 6
7 #include <limits> 7 #include <limits>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 } 240 }
241 241
242 NativeThemeBase::NativeThemeBase() 242 NativeThemeBase::NativeThemeBase()
243 : scrollbar_width_(kDefaultScrollbarWidth), 243 : scrollbar_width_(kDefaultScrollbarWidth),
244 scrollbar_button_length_(kDefaultScrollbarButtonLength) { 244 scrollbar_button_length_(kDefaultScrollbarButtonLength) {
245 } 245 }
246 246
247 NativeThemeBase::~NativeThemeBase() { 247 NativeThemeBase::~NativeThemeBase() {
248 } 248 }
249 249
250 // static
251 scoped_ptr<gfx::Canvas> NativeThemeBase::CreateCanvas(SkCanvas* sk_canvas) {
252 // TODO(pkotwicz): Do something better and don't infer device
253 // scale factor from canvas scale.
254 SkMatrix m = sk_canvas->getTotalMatrix();
255 float device_scale = static_cast<float>(SkScalarAbs(m.getScaleX()));
256 return scoped_ptr<gfx::Canvas>(
257 gfx::Canvas::CreateCanvasWithoutScaling(sk_canvas, device_scale));
258 }
259
250 void NativeThemeBase::PaintArrowButton( 260 void NativeThemeBase::PaintArrowButton(
251 SkCanvas* canvas, 261 SkCanvas* canvas,
252 const gfx::Rect& rect, Part direction, State state) const { 262 const gfx::Rect& rect, Part direction, State state) const {
253 int widthMiddle, lengthMiddle;
254 SkPaint paint; 263 SkPaint paint;
255 if (direction == kScrollbarUpArrow || direction == kScrollbarDownArrow) {
256 widthMiddle = rect.width() / 2 + 1;
257 lengthMiddle = rect.height() / 2 + 1;
258 } else {
259 lengthMiddle = rect.width() / 2 + 1;
260 widthMiddle = rect.height() / 2 + 1;
261 }
262 264
263 // Calculate button color. 265 // Calculate button color.
264 SkScalar trackHSV[3]; 266 SkScalar trackHSV[3];
265 SkColorToHSV(track_color_, trackHSV); 267 SkColorToHSV(track_color_, trackHSV);
266 SkColor buttonColor = SaturateAndBrighten(trackHSV, 0, 0.2f); 268 SkColor buttonColor = SaturateAndBrighten(trackHSV, 0, 0.2f);
267 SkColor backgroundColor = buttonColor; 269 SkColor backgroundColor = buttonColor;
268 if (state == kPressed) { 270 if (state == kPressed) {
269 SkScalar buttonHSV[3]; 271 SkScalar buttonHSV[3];
270 SkColorToHSV(buttonColor, buttonHSV); 272 SkColorToHSV(buttonColor, buttonHSV);
271 buttonColor = SaturateAndBrighten(buttonHSV, 0, -0.1f); 273 buttonColor = SaturateAndBrighten(buttonHSV, 0, -0.1f);
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 paint.setColor(buttonColor); 328 paint.setColor(buttonColor);
327 canvas->drawPath(outline, paint); 329 canvas->drawPath(outline, paint);
328 330
329 paint.setAntiAlias(true); 331 paint.setAntiAlias(true);
330 paint.setStyle(SkPaint::kStroke_Style); 332 paint.setStyle(SkPaint::kStroke_Style);
331 SkScalar thumbHSV[3]; 333 SkScalar thumbHSV[3];
332 SkColorToHSV(thumb_inactive_color_, thumbHSV); 334 SkColorToHSV(thumb_inactive_color_, thumbHSV);
333 paint.setColor(OutlineColor(trackHSV, thumbHSV)); 335 paint.setColor(OutlineColor(trackHSV, thumbHSV));
334 canvas->drawPath(outline, paint); 336 canvas->drawPath(outline, paint);
335 337
336 // If the button is disabled or read-only, the arrow is drawn with the 338 PaintArrow(canvas, rect, direction, GetArrowColor(state));
337 // outline color. 339 }
338 if (state != kDisabled)
339 paint.setColor(SK_ColorBLACK);
340 340
341 void NativeThemeBase::PaintArrow(SkCanvas* gc,
342 const gfx::Rect& rect,
343 Part direction,
344 SkColor color) const {
345 int width_middle, length_middle;
346 if (direction == kScrollbarUpArrow || direction == kScrollbarDownArrow) {
347 width_middle = rect.width() / 2 + 1;
348 length_middle = rect.height() / 2 + 1;
349 } else {
350 length_middle = rect.width() / 2 + 1;
351 width_middle = rect.height() / 2 + 1;
352 }
353
354 SkPaint paint;
355 paint.setColor(color);
341 paint.setAntiAlias(false); 356 paint.setAntiAlias(false);
342 paint.setStyle(SkPaint::kFill_Style); 357 paint.setStyle(SkPaint::kFill_Style);
343 358
344 SkPath path; 359 SkPath path;
345 // The constants in this block of code are hand-tailored to produce good 360 // The constants in this block of code are hand-tailored to produce good
346 // looking arrows without anti-aliasing. 361 // looking arrows without anti-aliasing.
347 switch (direction) { 362 switch (direction) {
348 case kScrollbarUpArrow: 363 case kScrollbarUpArrow:
349 path.moveTo(rect.x() + widthMiddle - 4, rect.y() + lengthMiddle + 2); 364 path.moveTo(rect.x() + width_middle - 4, rect.y() + length_middle + 2);
350 path.rLineTo(7, 0); 365 path.rLineTo(7, 0);
351 path.rLineTo(-4, -4); 366 path.rLineTo(-4, -4);
352 break; 367 break;
353 case kScrollbarDownArrow: 368 case kScrollbarDownArrow:
354 path.moveTo(rect.x() + widthMiddle - 4, rect.y() + lengthMiddle - 3); 369 path.moveTo(rect.x() + width_middle - 4, rect.y() + length_middle - 3);
355 path.rLineTo(7, 0); 370 path.rLineTo(7, 0);
356 path.rLineTo(-4, 4); 371 path.rLineTo(-4, 4);
357 break; 372 break;
358 case kScrollbarRightArrow: 373 case kScrollbarRightArrow:
359 path.moveTo(rect.x() + lengthMiddle - 3, rect.y() + widthMiddle - 4); 374 path.moveTo(rect.x() + length_middle - 3, rect.y() + width_middle - 4);
360 path.rLineTo(0, 7); 375 path.rLineTo(0, 7);
361 path.rLineTo(4, -4); 376 path.rLineTo(4, -4);
362 break; 377 break;
363 case kScrollbarLeftArrow: 378 case kScrollbarLeftArrow:
364 path.moveTo(rect.x() + lengthMiddle + 1, rect.y() + widthMiddle - 5); 379 path.moveTo(rect.x() + length_middle + 1, rect.y() + width_middle - 5);
365 path.rLineTo(0, 9); 380 path.rLineTo(0, 9);
366 path.rLineTo(-4, -4); 381 path.rLineTo(-4, -4);
367 break; 382 break;
368 default: 383 default:
369 break; 384 break;
370 } 385 }
371 path.close(); 386 path.close();
372 387
373 canvas->drawPath(path, paint); 388 gc->drawPath(path, paint);
374 } 389 }
375 390
376 void NativeThemeBase::PaintScrollbarTrack(SkCanvas* canvas, 391 void NativeThemeBase::PaintScrollbarTrack(SkCanvas* canvas,
377 Part part, 392 Part part,
378 State state, 393 State state,
379 const ScrollbarTrackExtraParams& extra_params, 394 const ScrollbarTrackExtraParams& extra_params,
380 const gfx::Rect& rect) const { 395 const gfx::Rect& rect) const {
381 SkPaint paint; 396 SkPaint paint;
382 SkIRect skrect; 397 SkIRect skrect;
383 398
(...skipping 608 matching lines...) Expand 10 before | Expand all | Expand 10 after
992 SkRect clip; 1007 SkRect clip;
993 return canvas->getClipBounds(&clip) && 1008 return canvas->getClipBounds(&clip) &&
994 clip.intersect(SkIntToScalar(x), SkIntToScalar(y), SkIntToScalar(x + w), 1009 clip.intersect(SkIntToScalar(x), SkIntToScalar(y), SkIntToScalar(x + w),
995 SkIntToScalar(y + h)); 1010 SkIntToScalar(y + h));
996 } 1011 }
997 1012
998 void NativeThemeBase::DrawImageInt( 1013 void NativeThemeBase::DrawImageInt(
999 SkCanvas* sk_canvas, const gfx::ImageSkia& image, 1014 SkCanvas* sk_canvas, const gfx::ImageSkia& image,
1000 int src_x, int src_y, int src_w, int src_h, 1015 int src_x, int src_y, int src_w, int src_h,
1001 int dest_x, int dest_y, int dest_w, int dest_h) const { 1016 int dest_x, int dest_y, int dest_w, int dest_h) const {
1002 // TODO(pkotwicz): Do something better and don't infer device 1017 scoped_ptr<gfx::Canvas> canvas(CreateCanvas(sk_canvas));
1003 // scale factor from canvas scale.
1004 SkMatrix m = sk_canvas->getTotalMatrix();
1005 float device_scale = static_cast<float>(SkScalarAbs(m.getScaleX()));
1006 scoped_ptr<gfx::Canvas> canvas(gfx::Canvas::CreateCanvasWithoutScaling(
1007 sk_canvas, device_scale));
1008 canvas->DrawImageInt(image, src_x, src_y, src_w, src_h, 1018 canvas->DrawImageInt(image, src_x, src_y, src_w, src_h,
1009 dest_x, dest_y, dest_w, dest_h, true); 1019 dest_x, dest_y, dest_w, dest_h, true);
1010 } 1020 }
1011 1021
1012 void NativeThemeBase::DrawTiledImage(SkCanvas* sk_canvas, 1022 void NativeThemeBase::DrawTiledImage(SkCanvas* sk_canvas,
1013 const gfx::ImageSkia& image, 1023 const gfx::ImageSkia& image,
1014 int src_x, int src_y, float tile_scale_x, float tile_scale_y, 1024 int src_x, int src_y, float tile_scale_x, float tile_scale_y,
1015 int dest_x, int dest_y, int w, int h) const { 1025 int dest_x, int dest_y, int w, int h) const {
1016 // TODO(pkotwicz): Do something better and don't infer device 1026 scoped_ptr<gfx::Canvas> canvas(CreateCanvas(sk_canvas));
1017 // scale factor from canvas scale.
1018 SkMatrix m = sk_canvas->getTotalMatrix();
1019 float device_scale = static_cast<float>(SkScalarAbs(m.getScaleX()));
1020 scoped_ptr<gfx::Canvas> canvas(gfx::Canvas::CreateCanvasWithoutScaling(
1021 sk_canvas, device_scale));
1022 canvas->TileImageInt(image, src_x, src_y, tile_scale_x, 1027 canvas->TileImageInt(image, src_x, src_y, tile_scale_x,
1023 tile_scale_y, dest_x, dest_y, w, h); 1028 tile_scale_y, dest_x, dest_y, w, h);
1024 } 1029 }
1025 1030
1026 SkColor NativeThemeBase::SaturateAndBrighten(SkScalar* hsv, 1031 SkColor NativeThemeBase::SaturateAndBrighten(SkScalar* hsv,
1027 SkScalar saturate_amount, 1032 SkScalar saturate_amount,
1028 SkScalar brighten_amount) const { 1033 SkScalar brighten_amount) const {
1029 SkScalar color[3]; 1034 SkScalar color[3];
1030 color[0] = hsv[0]; 1035 color[0] = hsv[0];
1031 color[1] = Clamp(hsv[1] + saturate_amount, 0.0, 1.0); 1036 color[1] = Clamp(hsv[1] + saturate_amount, 0.0, 1.0);
1032 color[2] = Clamp(hsv[2] + brighten_amount, 0.0, 1.0); 1037 color[2] = Clamp(hsv[2] + brighten_amount, 0.0, 1.0);
1033 return SkHSVToColor(color); 1038 return SkHSVToColor(color);
1034 } 1039 }
1035 1040
1041 SkColor NativeThemeBase::GetArrowColor(State state) const {
1042 if (state != kDisabled)
1043 return SK_ColorBLACK;
1044
1045 SkScalar track_hsv[3];
1046 SkColorToHSV(track_color_, track_hsv);
1047 SkScalar thumb_hsv[3];
1048 SkColorToHSV(thumb_inactive_color_, thumb_hsv);
1049 return OutlineColor(track_hsv, thumb_hsv);
1050 }
1051
1036 void NativeThemeBase::DrawVertLine(SkCanvas* canvas, 1052 void NativeThemeBase::DrawVertLine(SkCanvas* canvas,
1037 int x, 1053 int x,
1038 int y1, 1054 int y1,
1039 int y2, 1055 int y2,
1040 const SkPaint& paint) const { 1056 const SkPaint& paint) const {
1041 SkIRect skrect; 1057 SkIRect skrect;
1042 skrect.set(x, y1, x + 1, y2 + 1); 1058 skrect.set(x, y1, x + 1, y2 + 1);
1043 canvas->drawIRect(skrect, paint); 1059 canvas->drawIRect(skrect, paint);
1044 } 1060 }
1045 1061
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
1101 SkScalar min_diff = Clamp((hsv1[1] + hsv2[1]) * 1.2f, 0.28f, 0.5f); 1117 SkScalar min_diff = Clamp((hsv1[1] + hsv2[1]) * 1.2f, 0.28f, 0.5f);
1102 SkScalar diff = Clamp(fabs(hsv1[2] - hsv2[2]) / 2, min_diff, 0.5f); 1118 SkScalar diff = Clamp(fabs(hsv1[2] - hsv2[2]) / 2, min_diff, 0.5f);
1103 1119
1104 if (hsv1[2] + hsv2[2] > 1.0) 1120 if (hsv1[2] + hsv2[2] > 1.0)
1105 diff = -diff; 1121 diff = -diff;
1106 1122
1107 return SaturateAndBrighten(hsv2, -0.2f, diff); 1123 return SaturateAndBrighten(hsv2, -0.2f, diff);
1108 } 1124 }
1109 1125
1110 } // namespace ui 1126 } // namespace ui
OLDNEW
« no previous file with comments | « ui/native_theme/native_theme_base.h ('k') | ui/native_theme/native_theme_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698