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

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: 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(), 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.
15 bounds.width(), bounds.height() / 2);
16 int bottom_height =
17 bounds.height() - (bounds.height() / 4) - (bounds.height() / 2);
18 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.
19 bounds.width(), bottom_height);
20 return CreateWithParagraphShape(top, body, bottom, margin);
21 }
22
23 // static
24 AccessibilityFocusRing AccessibilityFocusRing::CreateWithParagraphShape(
25 const gfx::Rect& orig_top_line,
26 const gfx::Rect& orig_body,
27 const gfx::Rect& orig_bottom_line,
28 int margin) {
29 gfx::Rect top = orig_top_line;
30 gfx::Rect middle = orig_body;
31 gfx::Rect bottom = orig_bottom_line;
32
33 if (top.x() <= middle.x() + 2 * margin) {
34 top.set_width(top.width() + top.x() - middle.x());
35 top.set_x(middle.x());
36 }
37 if (top.right() >= middle.right() - 2 * margin) {
38 top.set_width(middle.right() - top.x());
39 }
40
41 if (bottom.x() <= middle.x() + 2 * margin) {
42 bottom.set_width(bottom.width() + bottom.x() - middle.x());
43 bottom.set_x(middle.x());
44 }
45 if (bottom.right() >= middle.right() - 2 * margin) {
46 bottom.set_width(middle.right() - bottom.x());
47 }
48
49 AccessibilityFocusRing ring;
50 ring.points[0] = gfx::Point(top.x(), top.bottom() - margin);
51 ring.points[1] = gfx::Point(top.x(), top.y() + margin);
52 ring.points[2] = gfx::Point(top.x(), top.y());
53 ring.points[3] = gfx::Point(top.x() + margin, top.y());
54 ring.points[4] = gfx::Point(top.right() - margin, top.y());
55 ring.points[5] = gfx::Point(top.right(), top.y());
56 ring.points[6] = gfx::Point(top.right(), top.y() + margin);
57 ring.points[7] = gfx::Point(top.right(), top.bottom() - margin);
58 ring.points[8] = gfx::Point(top.right(), top.bottom());
59 if (top.right() < middle.right()) {
60 ring.points[9] = gfx::Point(top.right() + margin, middle.y());
61 ring.points[10] = gfx::Point(middle.right() - margin, middle.y());
62 } else {
63 ring.points[9] = gfx::Point(top.right(), middle.y());
64 ring.points[10] = gfx::Point(middle.right(), middle.y());
65 }
66 ring.points[11] = gfx::Point(middle.right(), middle.y());
67 ring.points[12] = gfx::Point(middle.right(), middle.y() + margin);
68 ring.points[13] = gfx::Point(middle.right(), middle.bottom() - margin);
69 ring.points[14] = gfx::Point(middle.right(), middle.bottom());
70 if (bottom.right() < middle.right()) {
71 ring.points[15] = gfx::Point(middle.right() - margin, bottom.y());
72 ring.points[16] = gfx::Point(bottom.right() + margin, bottom.y());
73 } else {
74 ring.points[15] = gfx::Point(middle.right(), bottom.y());
75 ring.points[16] = gfx::Point(bottom.right(), bottom.y());
76 }
77 ring.points[17] = gfx::Point(bottom.right(), bottom.y());
78 ring.points[18] = gfx::Point(bottom.right(), bottom.y() + margin);
79 ring.points[19] = gfx::Point(bottom.right(), bottom.bottom() - margin);
80 ring.points[20] = gfx::Point(bottom.right(), bottom.bottom());
81 ring.points[21] = gfx::Point(bottom.right() - margin, bottom.bottom());
82 ring.points[22] = gfx::Point(bottom.x() + margin, bottom.bottom());
83 ring.points[23] = gfx::Point(bottom.x(), bottom.bottom());
84 ring.points[24] = gfx::Point(bottom.x(), bottom.bottom() - margin);
85 ring.points[25] = gfx::Point(bottom.x(), bottom.y() + margin);
86 ring.points[26] = gfx::Point(bottom.x(), bottom.y());
87 if (bottom.x() > middle.x()) {
88 ring.points[27] = gfx::Point(bottom.x() - margin, bottom.y());
89 ring.points[28] = gfx::Point(middle.x() + margin, middle.bottom());
90 } else {
91 ring.points[27] = gfx::Point(bottom.x(), bottom.y());
92 ring.points[28] = gfx::Point(middle.x(), middle.bottom());
93 }
94 ring.points[29] = gfx::Point(middle.x(), middle.bottom());
95 ring.points[30] = gfx::Point(middle.x(), middle.bottom() - margin);
96 ring.points[31] = gfx::Point(middle.x(), middle.y() + margin);
97 ring.points[32] = gfx::Point(middle.x(), middle.y());
98 if (top.x() > middle.x()) {
99 ring.points[33] = gfx::Point(middle.x() + margin, middle.y());
100 ring.points[34] = gfx::Point(top.x() - margin, top.bottom());
101 } else {
102 ring.points[33] = gfx::Point(middle.x(), middle.y());
103 ring.points[34] = gfx::Point(top.x(), top.bottom());
104 }
105 ring.points[35] = gfx::Point(top.x(), top.bottom());
106
107 return ring;
108 }
109
110 gfx::Rect AccessibilityFocusRing::GetBounds() const {
111 gfx::Point top_left = points[0];
112 gfx::Point bottom_right = points[0];
113 for (size_t i = 1; i < 36; i++) {
114 top_left.SetToMin(points[i]);
115 bottom_right.SetToMax(points[i]);
116 }
117 return gfx::Rect(top_left, gfx::Size(bottom_right.x() - top_left.x(),
118 bottom_right.y() - top_left.y()));
119 }
120
121 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698