| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/chromeos/ui/accessibility_focus_ring.h" | 5 #include "chrome/browser/chromeos/ui/accessibility_focus_ring.h" |
| 6 | 6 |
| 7 #include "base/logging.h" |
| 8 |
| 7 namespace chromeos { | 9 namespace chromeos { |
| 8 | 10 |
| 9 // static | 11 // static |
| 10 AccessibilityFocusRing AccessibilityFocusRing::CreateWithRect( | 12 AccessibilityFocusRing AccessibilityFocusRing::CreateWithRect( |
| 11 const gfx::Rect& bounds, int margin) { | 13 const gfx::Rect& bounds, int margin) { |
| 14 // Compute the height of the top and bottom cap. |
| 15 int cap_height = std::min(bounds.height() / 2, margin * 2); |
| 16 |
| 12 gfx::Rect top(bounds.x(), bounds.y(), | 17 gfx::Rect top(bounds.x(), bounds.y(), |
| 13 bounds.width(), bounds.height() / 4); | 18 bounds.width(), cap_height); |
| 19 gfx::Rect bottom(bounds.x(), bounds.bottom() - cap_height, |
| 20 bounds.width(), cap_height); |
| 14 gfx::Rect body(bounds.x(), top.bottom(), | 21 gfx::Rect body(bounds.x(), top.bottom(), |
| 15 bounds.width(), bounds.height() / 2); | 22 bounds.width(), bottom.y() - top.bottom()); |
| 16 gfx::Rect bottom(bounds.x(), body.bottom(), | 23 |
| 17 bounds.width(), bounds.bottom() - body.bottom()); | |
| 18 return CreateWithParagraphShape(top, body, bottom, margin); | 24 return CreateWithParagraphShape(top, body, bottom, margin); |
| 19 } | 25 } |
| 20 | 26 |
| 21 // static | 27 // static |
| 28 AccessibilityFocusRing AccessibilityFocusRing::Interpolate( |
| 29 const AccessibilityFocusRing& r1, |
| 30 const AccessibilityFocusRing& r2, |
| 31 double fraction) { |
| 32 AccessibilityFocusRing dst; |
| 33 for (int i = 0; i < 36; ++i) { |
| 34 dst.points[i] = gfx::Point( |
| 35 r1.points[i].x() * (1 - fraction) + r2.points[i].x() * fraction, |
| 36 r1.points[i].y() * (1 - fraction) + r2.points[i].y() * fraction); |
| 37 } |
| 38 return dst; |
| 39 } |
| 40 |
| 41 // static |
| 22 AccessibilityFocusRing AccessibilityFocusRing::CreateWithParagraphShape( | 42 AccessibilityFocusRing AccessibilityFocusRing::CreateWithParagraphShape( |
| 23 const gfx::Rect& orig_top_line, | 43 const gfx::Rect& orig_top_line, |
| 24 const gfx::Rect& orig_body, | 44 const gfx::Rect& orig_body, |
| 25 const gfx::Rect& orig_bottom_line, | 45 const gfx::Rect& orig_bottom_line, |
| 26 int margin) { | 46 int margin) { |
| 27 gfx::Rect top = orig_top_line; | 47 gfx::Rect top = orig_top_line; |
| 28 gfx::Rect middle = orig_body; | 48 gfx::Rect middle = orig_body; |
| 29 gfx::Rect bottom = orig_bottom_line; | 49 gfx::Rect bottom = orig_bottom_line; |
| 30 | 50 |
| 51 int min_height = std::min(top.height(), bottom.height()); |
| 52 margin = std::min(margin, min_height / 2); |
| 53 |
| 31 if (top.x() <= middle.x() + 2 * margin) { | 54 if (top.x() <= middle.x() + 2 * margin) { |
| 32 top.set_width(top.width() + top.x() - middle.x()); | 55 top.set_width(top.width() + top.x() - middle.x()); |
| 33 top.set_x(middle.x()); | 56 top.set_x(middle.x()); |
| 34 } | 57 } |
| 35 if (top.right() >= middle.right() - 2 * margin) { | 58 if (top.right() >= middle.right() - 2 * margin) { |
| 36 top.set_width(middle.right() - top.x()); | 59 top.set_width(middle.right() - top.x()); |
| 37 } | 60 } |
| 38 | 61 |
| 39 if (bottom.x() <= middle.x() + 2 * margin) { | 62 if (bottom.x() <= middle.x() + 2 * margin) { |
| 40 bottom.set_width(bottom.width() + bottom.x() - middle.x()); | 63 bottom.set_width(bottom.width() + bottom.x() - middle.x()); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 ring.points[34] = gfx::Point(top.x(), top.bottom()); | 124 ring.points[34] = gfx::Point(top.x(), top.bottom()); |
| 102 } | 125 } |
| 103 ring.points[35] = gfx::Point(top.x(), top.bottom()); | 126 ring.points[35] = gfx::Point(top.x(), top.bottom()); |
| 104 | 127 |
| 105 return ring; | 128 return ring; |
| 106 } | 129 } |
| 107 | 130 |
| 108 gfx::Rect AccessibilityFocusRing::GetBounds() const { | 131 gfx::Rect AccessibilityFocusRing::GetBounds() const { |
| 109 gfx::Point top_left = points[0]; | 132 gfx::Point top_left = points[0]; |
| 110 gfx::Point bottom_right = points[0]; | 133 gfx::Point bottom_right = points[0]; |
| 111 for (size_t i = 1; i < 36; i++) { | 134 for (size_t i = 1; i < 36; ++i) { |
| 112 top_left.SetToMin(points[i]); | 135 top_left.SetToMin(points[i]); |
| 113 bottom_right.SetToMax(points[i]); | 136 bottom_right.SetToMax(points[i]); |
| 114 } | 137 } |
| 115 return gfx::Rect(top_left, gfx::Size(bottom_right.x() - top_left.x(), | 138 return gfx::Rect(top_left, gfx::Size(bottom_right.x() - top_left.x(), |
| 116 bottom_right.y() - top_left.y())); | 139 bottom_right.y() - top_left.y())); |
| 117 } | 140 } |
| 118 | 141 |
| 119 } // namespace chromeos | 142 } // namespace chromeos |
| OLD | NEW |