Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(72)

Side by Side Diff: chrome/browser/chromeos/ui/accessibility_focus_ring.cc

Issue 557393003: Introduce AccessibilityFocusRing. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@accessibility_private_histograms
Patch Set: Address last feedback Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/chromeos/ui/accessibility_focus_ring.h"
6
7 namespace chromeos {
8
9 // static
10 AccessibilityFocusRing AccessibilityFocusRing::CreateWithRect(
11 const gfx::Rect& bounds, int margin) {
12 gfx::Rect top(bounds.x(), bounds.y(),
13 bounds.width(), bounds.height() / 4);
14 gfx::Rect body(bounds.x(), top.bottom(),
15 bounds.width(), bounds.height() / 2);
16 gfx::Rect bottom(bounds.x(), body.bottom(),
17 bounds.width(), bounds.bottom() - body.bottom());
18 return CreateWithParagraphShape(top, body, bottom, margin);
19 }
20
21 // static
22 AccessibilityFocusRing AccessibilityFocusRing::CreateWithParagraphShape(
23 const gfx::Rect& orig_top_line,
24 const gfx::Rect& orig_body,
25 const gfx::Rect& orig_bottom_line,
26 int margin) {
27 gfx::Rect top = orig_top_line;
28 gfx::Rect middle = orig_body;
29 gfx::Rect bottom = orig_bottom_line;
30
31 if (top.x() <= middle.x() + 2 * margin) {
32 top.set_width(top.width() + top.x() - middle.x());
33 top.set_x(middle.x());
34 }
35 if (top.right() >= middle.right() - 2 * margin) {
36 top.set_width(middle.right() - top.x());
37 }
38
39 if (bottom.x() <= middle.x() + 2 * margin) {
40 bottom.set_width(bottom.width() + bottom.x() - middle.x());
41 bottom.set_x(middle.x());
42 }
43 if (bottom.right() >= middle.right() - 2 * margin) {
44 bottom.set_width(middle.right() - bottom.x());
45 }
46
47 AccessibilityFocusRing ring;
48 ring.points[0] = gfx::Point(top.x(), top.bottom() - margin);
49 ring.points[1] = gfx::Point(top.x(), top.y() + margin);
50 ring.points[2] = gfx::Point(top.x(), top.y());
51 ring.points[3] = gfx::Point(top.x() + margin, top.y());
52 ring.points[4] = gfx::Point(top.right() - margin, top.y());
53 ring.points[5] = gfx::Point(top.right(), top.y());
54 ring.points[6] = gfx::Point(top.right(), top.y() + margin);
55 ring.points[7] = gfx::Point(top.right(), top.bottom() - margin);
56 ring.points[8] = gfx::Point(top.right(), top.bottom());
57 if (top.right() < middle.right()) {
58 ring.points[9] = gfx::Point(top.right() + margin, middle.y());
59 ring.points[10] = gfx::Point(middle.right() - margin, middle.y());
60 } else {
61 ring.points[9] = gfx::Point(top.right(), middle.y());
62 ring.points[10] = gfx::Point(middle.right(), middle.y());
63 }
64 ring.points[11] = gfx::Point(middle.right(), middle.y());
65 ring.points[12] = gfx::Point(middle.right(), middle.y() + margin);
66 ring.points[13] = gfx::Point(middle.right(), middle.bottom() - margin);
67 ring.points[14] = gfx::Point(middle.right(), middle.bottom());
68 if (bottom.right() < middle.right()) {
69 ring.points[15] = gfx::Point(middle.right() - margin, bottom.y());
70 ring.points[16] = gfx::Point(bottom.right() + margin, bottom.y());
71 } else {
72 ring.points[15] = gfx::Point(middle.right(), bottom.y());
73 ring.points[16] = gfx::Point(bottom.right(), bottom.y());
74 }
75 ring.points[17] = gfx::Point(bottom.right(), bottom.y());
76 ring.points[18] = gfx::Point(bottom.right(), bottom.y() + margin);
77 ring.points[19] = gfx::Point(bottom.right(), bottom.bottom() - margin);
78 ring.points[20] = gfx::Point(bottom.right(), bottom.bottom());
79 ring.points[21] = gfx::Point(bottom.right() - margin, bottom.bottom());
80 ring.points[22] = gfx::Point(bottom.x() + margin, bottom.bottom());
81 ring.points[23] = gfx::Point(bottom.x(), bottom.bottom());
82 ring.points[24] = gfx::Point(bottom.x(), bottom.bottom() - margin);
83 ring.points[25] = gfx::Point(bottom.x(), bottom.y() + margin);
84 ring.points[26] = gfx::Point(bottom.x(), bottom.y());
85 if (bottom.x() > middle.x()) {
86 ring.points[27] = gfx::Point(bottom.x() - margin, bottom.y());
87 ring.points[28] = gfx::Point(middle.x() + margin, middle.bottom());
88 } else {
89 ring.points[27] = gfx::Point(bottom.x(), bottom.y());
90 ring.points[28] = gfx::Point(middle.x(), middle.bottom());
91 }
92 ring.points[29] = gfx::Point(middle.x(), middle.bottom());
93 ring.points[30] = gfx::Point(middle.x(), middle.bottom() - margin);
94 ring.points[31] = gfx::Point(middle.x(), middle.y() + margin);
95 ring.points[32] = gfx::Point(middle.x(), middle.y());
96 if (top.x() > middle.x()) {
97 ring.points[33] = gfx::Point(middle.x() + margin, middle.y());
98 ring.points[34] = gfx::Point(top.x() - margin, top.bottom());
99 } else {
100 ring.points[33] = gfx::Point(middle.x(), middle.y());
101 ring.points[34] = gfx::Point(top.x(), top.bottom());
102 }
103 ring.points[35] = gfx::Point(top.x(), top.bottom());
104
105 return ring;
106 }
107
108 gfx::Rect AccessibilityFocusRing::GetBounds() const {
109 gfx::Point top_left = points[0];
110 gfx::Point bottom_right = points[0];
111 for (size_t i = 1; i < 36; i++) {
112 top_left.SetToMin(points[i]);
113 bottom_right.SetToMax(points[i]);
114 }
115 return gfx::Rect(top_left, gfx::Size(bottom_right.x() - top_left.x(),
116 bottom_right.y() - top_left.y()));
117 }
118
119 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698