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

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

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