Chromium Code Reviews| 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 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 361 SkPaint paint; | 361 SkPaint paint; |
| 362 paint.setColor(color); | 362 paint.setColor(color); |
| 363 | 363 |
| 364 SkPath path = PathForArrow(rect, direction); | 364 SkPath path = PathForArrow(rect, direction); |
| 365 | 365 |
| 366 gc->drawPath(path, paint); | 366 gc->drawPath(path, paint); |
| 367 } | 367 } |
| 368 | 368 |
| 369 SkPath NativeThemeBase::PathForArrow(const gfx::Rect& rect, | 369 SkPath NativeThemeBase::PathForArrow(const gfx::Rect& rect, |
| 370 Part direction) const { | 370 Part direction) const { |
| 371 gfx::Rect bounding_rect(rect); | 371 gfx::RectF bounding_rect = BoundingRectForArrow(rect); |
| 372 const int padding_width = ceil(rect.width() / 4.f); | 372 const gfx::PointF center = bounding_rect.CenterPoint(); |
| 373 const int padding_height = ceil(rect.height() / 4.f); | |
| 374 bounding_rect.Inset(padding_width, padding_height); | |
| 375 const gfx::Point center = bounding_rect.CenterPoint(); | |
| 376 | |
| 377 SkPath path; | 373 SkPath path; |
| 378 SkMatrix transform; | 374 SkMatrix transform; |
| 379 transform.setIdentity(); | 375 transform.setIdentity(); |
| 380 if (direction == kScrollbarUpArrow || direction == kScrollbarDownArrow) { | 376 if (direction == kScrollbarUpArrow || direction == kScrollbarDownArrow) { |
| 381 int arrow_altitude = bounding_rect.height() / 2 + 1; | 377 int arrow_altitude = bounding_rect.height() / 2 + 1; |
| 382 path.moveTo(bounding_rect.x(), bounding_rect.bottom()); | 378 path.moveTo(bounding_rect.x(), bounding_rect.bottom()); |
| 383 path.rLineTo(bounding_rect.width(), 0); | 379 path.rLineTo(bounding_rect.width(), 0); |
| 384 path.rLineTo(-bounding_rect.width() / 2.0f, -arrow_altitude); | 380 path.rLineTo(-bounding_rect.width() / 2.0f, -arrow_altitude); |
| 385 path.close(); | 381 path.close(); |
| 386 path.offset(0, -arrow_altitude / 2 + 1); | 382 path.offset(0, -arrow_altitude / 2 + 1); |
| 387 if (direction == kScrollbarDownArrow) { | 383 if (direction == kScrollbarDownArrow) { |
| 388 path.offset(0, -1); | |
| 389 transform.setScale(1, -1, center.x(), center.y()); | 384 transform.setScale(1, -1, center.x(), center.y()); |
| 390 } | 385 } |
| 391 } else { | 386 } else { |
| 392 int arrow_altitude = bounding_rect.width() / 2 + 1; | 387 int arrow_altitude = bounding_rect.width() / 2 + 1; |
| 393 path.moveTo(bounding_rect.x(), bounding_rect.y()); | 388 path.moveTo(bounding_rect.x(), bounding_rect.y()); |
| 394 path.rLineTo(0, bounding_rect.height()); | 389 path.rLineTo(0, bounding_rect.height()); |
| 395 path.rLineTo(arrow_altitude, -bounding_rect.height() / 2.0f); | 390 path.rLineTo(arrow_altitude, -bounding_rect.height() / 2.0f); |
| 396 path.close(); | 391 path.close(); |
| 397 path.offset(arrow_altitude / 2, 0); | 392 path.offset(arrow_altitude / 2, 0); |
| 398 if (direction == kScrollbarLeftArrow) { | 393 if (direction == kScrollbarLeftArrow) { |
| 399 path.offset(-1, 0); | |
| 400 transform.setScale(-1, 1, center.x(), center.y()); | 394 transform.setScale(-1, 1, center.x(), center.y()); |
| 401 } | 395 } |
| 402 } | 396 } |
| 403 path.transform(transform); | 397 path.transform(transform); |
| 404 | 398 |
| 405 return path; | 399 return path; |
| 406 } | 400 } |
| 407 | 401 |
| 402 gfx::RectF NativeThemeBase::BoundingRectForArrow(const gfx::Rect& rect) const { | |
| 403 const std::pair<int, int> rect_sides = | |
| 404 std::minmax(rect.width(), rect.height()); | |
| 405 const int side_length_inset = 2 * std::ceil(rect_sides.second / 4.f); | |
| 406 const int side_length = | |
| 407 std::min(rect_sides.first, rect_sides.second - side_length_inset); | |
| 408 gfx::RectF bounding_rect(rect.x() + (rect.width() - side_length) / 2.f, | |
| 409 rect.y() + (rect.height() - side_length) / 2.f, | |
| 410 side_length, side_length); | |
| 411 | |
| 412 // Snap bounding_rect to whole pixels. | |
| 413 bounding_rect.set_x(ceil(bounding_rect.x())); | |
| 414 bounding_rect.set_y(ceil(bounding_rect.y())); | |
|
Peter Kasting
2016/06/11 02:19:27
After thinking about this for a while, I think the
Bret
2016/06/13 18:02:51
Ok, I like this suggestion.
| |
| 415 // Width and height are always aligned to whole pixels. | |
| 416 | |
| 417 return bounding_rect; | |
| 418 } | |
| 419 | |
| 408 void NativeThemeBase::PaintScrollbarTrack(SkCanvas* canvas, | 420 void NativeThemeBase::PaintScrollbarTrack(SkCanvas* canvas, |
| 409 Part part, | 421 Part part, |
| 410 State state, | 422 State state, |
| 411 const ScrollbarTrackExtraParams& extra_params, | 423 const ScrollbarTrackExtraParams& extra_params, |
| 412 const gfx::Rect& rect) const { | 424 const gfx::Rect& rect) const { |
| 413 SkPaint paint; | 425 SkPaint paint; |
| 414 SkIRect skrect; | 426 SkIRect skrect; |
| 415 | 427 |
| 416 skrect.set(rect.x(), rect.y(), rect.right(), rect.bottom()); | 428 skrect.set(rect.x(), rect.y(), rect.right(), rect.bottom()); |
| 417 SkScalar track_hsv[3]; | 429 SkScalar track_hsv[3]; |
| (...skipping 590 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1008 SkScalar min_diff = Clamp((hsv1[1] + hsv2[1]) * 1.2f, 0.28f, 0.5f); | 1020 SkScalar min_diff = Clamp((hsv1[1] + hsv2[1]) * 1.2f, 0.28f, 0.5f); |
| 1009 SkScalar diff = Clamp(fabs(hsv1[2] - hsv2[2]) / 2, min_diff, 0.5f); | 1021 SkScalar diff = Clamp(fabs(hsv1[2] - hsv2[2]) / 2, min_diff, 0.5f); |
| 1010 | 1022 |
| 1011 if (hsv1[2] + hsv2[2] > 1.0) | 1023 if (hsv1[2] + hsv2[2] > 1.0) |
| 1012 diff = -diff; | 1024 diff = -diff; |
| 1013 | 1025 |
| 1014 return SaturateAndBrighten(hsv2, -0.2f, diff); | 1026 return SaturateAndBrighten(hsv2, -0.2f, diff); |
| 1015 } | 1027 } |
| 1016 | 1028 |
| 1017 } // namespace ui | 1029 } // namespace ui |
| OLD | NEW |