Index: chrome/browser/chromeos/ui/accessibility_focus_ring.cc |
diff --git a/chrome/browser/chromeos/ui/accessibility_focus_ring.cc b/chrome/browser/chromeos/ui/accessibility_focus_ring.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..9e1a5520fb6ae21da666ccbca3b6367a2ac95c2f |
--- /dev/null |
+++ b/chrome/browser/chromeos/ui/accessibility_focus_ring.cc |
@@ -0,0 +1,121 @@ |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/browser/chromeos/ui/accessibility_focus_ring.h" |
+ |
+namespace chromeos { |
+ |
+// static |
+AccessibilityFocusRing AccessibilityFocusRing::CreateWithRect( |
+ const gfx::Rect& bounds, int margin) { |
+ gfx::Rect top(bounds.x(), bounds.y(), |
+ bounds.width(), bounds.height() / 4); |
+ gfx::Rect body(bounds.x(), bounds.y() + bounds.height() / 4, |
xiyuan
2014/09/11 03:33:10
nit: bounds.y() + bounds.height() / 4 -> top.botto
dmazzoni
2014/09/11 21:44:38
Done.
|
+ bounds.width(), bounds.height() / 2); |
+ int bottom_height = |
+ bounds.height() - (bounds.height() / 4) - (bounds.height() / 2); |
+ gfx::Rect bottom(bounds.x(), bounds.y() + bounds.height() - bottom_height, |
xiyuan
2014/09/11 03:33:09
nit: bounds.y() + bounds.height() - bottom_height
dmazzoni
2014/09/11 21:44:38
Done.
|
+ bounds.width(), bottom_height); |
+ return CreateWithParagraphShape(top, body, bottom, margin); |
+} |
+ |
+// static |
+AccessibilityFocusRing AccessibilityFocusRing::CreateWithParagraphShape( |
+ const gfx::Rect& orig_top_line, |
+ const gfx::Rect& orig_body, |
+ const gfx::Rect& orig_bottom_line, |
+ int margin) { |
+ gfx::Rect top = orig_top_line; |
+ gfx::Rect middle = orig_body; |
+ gfx::Rect bottom = orig_bottom_line; |
+ |
+ if (top.x() <= middle.x() + 2 * margin) { |
+ top.set_width(top.width() + top.x() - middle.x()); |
+ top.set_x(middle.x()); |
+ } |
+ if (top.right() >= middle.right() - 2 * margin) { |
+ top.set_width(middle.right() - top.x()); |
+ } |
+ |
+ if (bottom.x() <= middle.x() + 2 * margin) { |
+ bottom.set_width(bottom.width() + bottom.x() - middle.x()); |
+ bottom.set_x(middle.x()); |
+ } |
+ if (bottom.right() >= middle.right() - 2 * margin) { |
+ bottom.set_width(middle.right() - bottom.x()); |
+ } |
+ |
+ AccessibilityFocusRing ring; |
+ ring.points[0] = gfx::Point(top.x(), top.bottom() - margin); |
+ ring.points[1] = gfx::Point(top.x(), top.y() + margin); |
+ ring.points[2] = gfx::Point(top.x(), top.y()); |
+ ring.points[3] = gfx::Point(top.x() + margin, top.y()); |
+ ring.points[4] = gfx::Point(top.right() - margin, top.y()); |
+ ring.points[5] = gfx::Point(top.right(), top.y()); |
+ ring.points[6] = gfx::Point(top.right(), top.y() + margin); |
+ ring.points[7] = gfx::Point(top.right(), top.bottom() - margin); |
+ ring.points[8] = gfx::Point(top.right(), top.bottom()); |
+ if (top.right() < middle.right()) { |
+ ring.points[9] = gfx::Point(top.right() + margin, middle.y()); |
+ ring.points[10] = gfx::Point(middle.right() - margin, middle.y()); |
+ } else { |
+ ring.points[9] = gfx::Point(top.right(), middle.y()); |
+ ring.points[10] = gfx::Point(middle.right(), middle.y()); |
+ } |
+ ring.points[11] = gfx::Point(middle.right(), middle.y()); |
+ ring.points[12] = gfx::Point(middle.right(), middle.y() + margin); |
+ ring.points[13] = gfx::Point(middle.right(), middle.bottom() - margin); |
+ ring.points[14] = gfx::Point(middle.right(), middle.bottom()); |
+ if (bottom.right() < middle.right()) { |
+ ring.points[15] = gfx::Point(middle.right() - margin, bottom.y()); |
+ ring.points[16] = gfx::Point(bottom.right() + margin, bottom.y()); |
+ } else { |
+ ring.points[15] = gfx::Point(middle.right(), bottom.y()); |
+ ring.points[16] = gfx::Point(bottom.right(), bottom.y()); |
+ } |
+ ring.points[17] = gfx::Point(bottom.right(), bottom.y()); |
+ ring.points[18] = gfx::Point(bottom.right(), bottom.y() + margin); |
+ ring.points[19] = gfx::Point(bottom.right(), bottom.bottom() - margin); |
+ ring.points[20] = gfx::Point(bottom.right(), bottom.bottom()); |
+ ring.points[21] = gfx::Point(bottom.right() - margin, bottom.bottom()); |
+ ring.points[22] = gfx::Point(bottom.x() + margin, bottom.bottom()); |
+ ring.points[23] = gfx::Point(bottom.x(), bottom.bottom()); |
+ ring.points[24] = gfx::Point(bottom.x(), bottom.bottom() - margin); |
+ ring.points[25] = gfx::Point(bottom.x(), bottom.y() + margin); |
+ ring.points[26] = gfx::Point(bottom.x(), bottom.y()); |
+ if (bottom.x() > middle.x()) { |
+ ring.points[27] = gfx::Point(bottom.x() - margin, bottom.y()); |
+ ring.points[28] = gfx::Point(middle.x() + margin, middle.bottom()); |
+ } else { |
+ ring.points[27] = gfx::Point(bottom.x(), bottom.y()); |
+ ring.points[28] = gfx::Point(middle.x(), middle.bottom()); |
+ } |
+ ring.points[29] = gfx::Point(middle.x(), middle.bottom()); |
+ ring.points[30] = gfx::Point(middle.x(), middle.bottom() - margin); |
+ ring.points[31] = gfx::Point(middle.x(), middle.y() + margin); |
+ ring.points[32] = gfx::Point(middle.x(), middle.y()); |
+ if (top.x() > middle.x()) { |
+ ring.points[33] = gfx::Point(middle.x() + margin, middle.y()); |
+ ring.points[34] = gfx::Point(top.x() - margin, top.bottom()); |
+ } else { |
+ ring.points[33] = gfx::Point(middle.x(), middle.y()); |
+ ring.points[34] = gfx::Point(top.x(), top.bottom()); |
+ } |
+ ring.points[35] = gfx::Point(top.x(), top.bottom()); |
+ |
+ return ring; |
+} |
+ |
+gfx::Rect AccessibilityFocusRing::GetBounds() const { |
+ gfx::Point top_left = points[0]; |
+ gfx::Point bottom_right = points[0]; |
+ for (size_t i = 1; i < 36; i++) { |
+ top_left.SetToMin(points[i]); |
+ bottom_right.SetToMax(points[i]); |
+ } |
+ return gfx::Rect(top_left, gfx::Size(bottom_right.x() - top_left.x(), |
+ bottom_right.y() - top_left.y())); |
+} |
+ |
+} // namespace chromeos |