OLD | NEW |
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 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 paint.setColor(OutlineColor(trackHSV, thumbHSV)); | 351 paint.setColor(OutlineColor(trackHSV, thumbHSV)); |
352 canvas->drawPath(outline, paint); | 352 canvas->drawPath(outline, paint); |
353 | 353 |
354 PaintArrow(canvas, rect, direction, GetArrowColor(state)); | 354 PaintArrow(canvas, rect, direction, GetArrowColor(state)); |
355 } | 355 } |
356 | 356 |
357 void NativeThemeBase::PaintArrow(SkCanvas* gc, | 357 void NativeThemeBase::PaintArrow(SkCanvas* gc, |
358 const gfx::Rect& rect, | 358 const gfx::Rect& rect, |
359 Part direction, | 359 Part direction, |
360 SkColor color) const { | 360 SkColor color) const { |
361 int width_middle, length_middle; | |
362 if (direction == kScrollbarUpArrow || direction == kScrollbarDownArrow) { | |
363 width_middle = rect.width() / 2 + 1; | |
364 length_middle = rect.height() / 2 + 1; | |
365 } else { | |
366 length_middle = rect.width() / 2 + 1; | |
367 width_middle = rect.height() / 2 + 1; | |
368 } | |
369 | |
370 SkPaint paint; | 361 SkPaint paint; |
371 paint.setColor(color); | 362 paint.setColor(color); |
372 paint.setAntiAlias(false); | 363 paint.setAntiAlias(false); |
373 paint.setStyle(SkPaint::kFill_Style); | |
374 | 364 |
375 SkPath path; | 365 SkPath path = PathForArrow(rect, direction); |
376 // The constants in this block of code are hand-tailored to produce good | |
377 // looking arrows without anti-aliasing. | |
378 switch (direction) { | |
379 case kScrollbarUpArrow: | |
380 path.moveTo(rect.x() + width_middle - 4, rect.y() + length_middle + 2); | |
381 path.rLineTo(7, 0); | |
382 path.rLineTo(-4, -4); | |
383 break; | |
384 case kScrollbarDownArrow: | |
385 path.moveTo(rect.x() + width_middle - 4, rect.y() + length_middle - 3); | |
386 path.rLineTo(7, 0); | |
387 path.rLineTo(-4, 4); | |
388 break; | |
389 case kScrollbarRightArrow: | |
390 path.moveTo(rect.x() + length_middle - 3, rect.y() + width_middle - 4); | |
391 path.rLineTo(0, 7); | |
392 path.rLineTo(4, -4); | |
393 break; | |
394 case kScrollbarLeftArrow: | |
395 path.moveTo(rect.x() + length_middle + 1, rect.y() + width_middle - 5); | |
396 path.rLineTo(0, 9); | |
397 path.rLineTo(-4, -4); | |
398 break; | |
399 default: | |
400 break; | |
401 } | |
402 path.close(); | |
403 | 366 |
404 gc->drawPath(path, paint); | 367 gc->drawPath(path, paint); |
405 } | 368 } |
406 | 369 |
| 370 SkPath NativeThemeBase::PathForArrow(const gfx::Rect& rect, |
| 371 Part direction) const { |
| 372 gfx::Rect bounding_rect(rect); |
| 373 const int padding_width = ceil(rect.width() / 4.f); |
| 374 const int padding_height = ceil(rect.height() / 4.f); |
| 375 bounding_rect.Inset(padding_width, padding_height); |
| 376 const gfx::Point center = bounding_rect.CenterPoint(); |
| 377 |
| 378 SkPath path; |
| 379 SkMatrix transform; |
| 380 transform.setIdentity(); |
| 381 if (direction == kScrollbarUpArrow || direction == kScrollbarDownArrow) { |
| 382 int arrow_altitude = bounding_rect.height() / 2 + 1; |
| 383 path.moveTo(bounding_rect.x(), bounding_rect.y() + bounding_rect.height()); |
| 384 path.rLineTo(bounding_rect.width(), 0); |
| 385 path.rLineTo(-bounding_rect.width() / 2.0f, -arrow_altitude); |
| 386 path.close(); |
| 387 path.offset(0, -arrow_altitude / 2 + 1); |
| 388 if (direction == kScrollbarDownArrow) { |
| 389 path.offset(0, -1); |
| 390 transform.setScale(1, -1, center.x(), center.y()); |
| 391 } |
| 392 } else { |
| 393 int arrow_altitude = bounding_rect.width() / 2 + 1; |
| 394 path.moveTo(bounding_rect.x(), bounding_rect.y()); |
| 395 path.rLineTo(0, bounding_rect.height()); |
| 396 path.rLineTo(arrow_altitude, -bounding_rect.height() / 2.0f); |
| 397 path.close(); |
| 398 path.offset(arrow_altitude / 2, 0); |
| 399 if (direction == kScrollbarLeftArrow) { |
| 400 path.offset(-1, 0); |
| 401 transform.setScale(-1, 1, center.x(), center.y()); |
| 402 } |
| 403 } |
| 404 path.transform(transform); |
| 405 |
| 406 return path; |
| 407 } |
| 408 |
407 void NativeThemeBase::PaintScrollbarTrack(SkCanvas* canvas, | 409 void NativeThemeBase::PaintScrollbarTrack(SkCanvas* canvas, |
408 Part part, | 410 Part part, |
409 State state, | 411 State state, |
410 const ScrollbarTrackExtraParams& extra_params, | 412 const ScrollbarTrackExtraParams& extra_params, |
411 const gfx::Rect& rect) const { | 413 const gfx::Rect& rect) const { |
412 SkPaint paint; | 414 SkPaint paint; |
413 SkIRect skrect; | 415 SkIRect skrect; |
414 | 416 |
415 skrect.set(rect.x(), rect.y(), rect.right(), rect.bottom()); | 417 skrect.set(rect.x(), rect.y(), rect.right(), rect.bottom()); |
416 SkScalar track_hsv[3]; | 418 SkScalar track_hsv[3]; |
(...skipping 608 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1025 SkScalar min_diff = Clamp((hsv1[1] + hsv2[1]) * 1.2f, 0.28f, 0.5f); | 1027 SkScalar min_diff = Clamp((hsv1[1] + hsv2[1]) * 1.2f, 0.28f, 0.5f); |
1026 SkScalar diff = Clamp(fabs(hsv1[2] - hsv2[2]) / 2, min_diff, 0.5f); | 1028 SkScalar diff = Clamp(fabs(hsv1[2] - hsv2[2]) / 2, min_diff, 0.5f); |
1027 | 1029 |
1028 if (hsv1[2] + hsv2[2] > 1.0) | 1030 if (hsv1[2] + hsv2[2] > 1.0) |
1029 diff = -diff; | 1031 diff = -diff; |
1030 | 1032 |
1031 return SaturateAndBrighten(hsv2, -0.2f, diff); | 1033 return SaturateAndBrighten(hsv2, -0.2f, diff); |
1032 } | 1034 } |
1033 | 1035 |
1034 } // namespace ui | 1036 } // namespace ui |
OLD | NEW |