Chromium Code Reviews| Index: ui/native_theme/native_theme_base.cc |
| diff --git a/ui/native_theme/native_theme_base.cc b/ui/native_theme/native_theme_base.cc |
| index 548b4a5cf695869c665d8eee425948b31e0d60af..f0c115cd8bf522166a97bd663fded9ba91841b22 100644 |
| --- a/ui/native_theme/native_theme_base.cc |
| +++ b/ui/native_theme/native_theme_base.cc |
| @@ -368,12 +368,8 @@ void NativeThemeBase::PaintArrow(SkCanvas* gc, |
| SkPath NativeThemeBase::PathForArrow(const gfx::Rect& rect, |
| Part direction) const { |
| - gfx::Rect bounding_rect(rect); |
| - const int padding_width = ceil(rect.width() / 4.f); |
| - const int padding_height = ceil(rect.height() / 4.f); |
| - bounding_rect.Inset(padding_width, padding_height); |
| - const gfx::Point center = bounding_rect.CenterPoint(); |
| - |
| + gfx::RectF bounding_rect = BoundingRectForArrow(rect); |
| + const gfx::PointF center = bounding_rect.CenterPoint(); |
| SkPath path; |
| SkMatrix transform; |
| transform.setIdentity(); |
| @@ -385,7 +381,6 @@ SkPath NativeThemeBase::PathForArrow(const gfx::Rect& rect, |
| path.close(); |
| path.offset(0, -arrow_altitude / 2 + 1); |
| if (direction == kScrollbarDownArrow) { |
| - path.offset(0, -1); |
|
Peter Kasting
2016/06/10 01:03:23
What were these offsets for?
Bret
2016/06/11 00:11:43
Before this change the bounding box was an integer
|
| transform.setScale(1, -1, center.x(), center.y()); |
| } |
| } else { |
| @@ -396,7 +391,6 @@ SkPath NativeThemeBase::PathForArrow(const gfx::Rect& rect, |
| path.close(); |
| path.offset(arrow_altitude / 2, 0); |
| if (direction == kScrollbarLeftArrow) { |
| - path.offset(-1, 0); |
| transform.setScale(-1, 1, center.x(), center.y()); |
| } |
| } |
| @@ -405,6 +399,39 @@ SkPath NativeThemeBase::PathForArrow(const gfx::Rect& rect, |
| return path; |
| } |
| +gfx::RectF NativeThemeBase::BoundingRectForArrow(const gfx::Rect& rect) const { |
|
Peter Kasting
2016/06/10 01:03:23
It seems like this whole function just does someth
Bret
2016/06/11 00:11:43
I managed to synthesize your suggestion with what
|
| + gfx::RectF bounding_rect(rect); |
| + int padding_width = ceil(rect.width() / 4.f); |
| + int padding_height = ceil(rect.height() / 4.f); |
| + bounding_rect.Inset(padding_width, padding_height); |
| + |
| + // Ensure bounding_rect is a square. |
| + if (bounding_rect.width() > bounding_rect.height()) { |
| + float square_adjust = |
| + (bounding_rect.width() - bounding_rect.height()) / 2.f; |
| + bounding_rect.Inset(0, -square_adjust); |
| + if (bounding_rect.height() > rect.height()) { |
| + float clamp_adjust = (bounding_rect.height() - rect.height()) / 2.f; |
| + bounding_rect.Inset(clamp_adjust, clamp_adjust); |
| + } |
| + } else if (bounding_rect.height() > bounding_rect.width()) { |
| + float square_adjust = |
| + (bounding_rect.height() - bounding_rect.width()) / 2.f; |
| + bounding_rect.Inset(-square_adjust, 0); |
| + if (bounding_rect.width() > rect.width()) { |
| + float clamp_adjust = (bounding_rect.width() - rect.width()) / 2.f; |
| + bounding_rect.Inset(clamp_adjust, clamp_adjust); |
| + } |
| + } |
| + |
| + // Snap bounding_rect to whole pixels. |
| + bounding_rect.set_x(ceil(bounding_rect.x())); |
| + bounding_rect.set_y(ceil(bounding_rect.y())); |
| + // Width and height are always aligned to whole pixels. |
| + |
| + return bounding_rect; |
| +} |
| + |
| void NativeThemeBase::PaintScrollbarTrack(SkCanvas* canvas, |
| Part part, |
| State state, |