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

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

Issue 602813003: Animate the accessibility focus ring and fix some minor visual issues. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@focus_ring_in_chromevox
Patch Set: Correct upstream branch 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
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++) {
xiyuan 2014/09/24 19:40:35 nit: ++i
dmazzoni 2014/09/24 21:40:56 Done.
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());
41 bottom.set_x(middle.x()); 64 bottom.set_x(middle.x());
42 } 65 }
43 if (bottom.right() >= middle.right() - 2 * margin) { 66 if (bottom.right() >= middle.right() - 2 * margin) {
44 bottom.set_width(middle.right() - bottom.x()); 67 bottom.set_width(middle.right() - bottom.x());
45 } 68 }
46 69
70 LogRect("Top2", top);
71 LogRect("Body2", middle);
72 LogRect("Bottom2", bottom);
xiyuan 2014/09/24 19:40:35 Where is LogRect defined?
dmazzoni 2014/09/24 21:40:56 Sorry, left that in while debugging. Gone.
73
47 AccessibilityFocusRing ring; 74 AccessibilityFocusRing ring;
48 ring.points[0] = gfx::Point(top.x(), top.bottom() - margin); 75 ring.points[0] = gfx::Point(top.x(), top.bottom() - margin);
49 ring.points[1] = gfx::Point(top.x(), top.y() + margin); 76 ring.points[1] = gfx::Point(top.x(), top.y() + margin);
50 ring.points[2] = gfx::Point(top.x(), top.y()); 77 ring.points[2] = gfx::Point(top.x(), top.y());
51 ring.points[3] = gfx::Point(top.x() + margin, top.y()); 78 ring.points[3] = gfx::Point(top.x() + margin, top.y());
52 ring.points[4] = gfx::Point(top.right() - margin, top.y()); 79 ring.points[4] = gfx::Point(top.right() - margin, top.y());
53 ring.points[5] = gfx::Point(top.right(), top.y()); 80 ring.points[5] = gfx::Point(top.right(), top.y());
54 ring.points[6] = gfx::Point(top.right(), top.y() + margin); 81 ring.points[6] = gfx::Point(top.right(), top.y() + margin);
55 ring.points[7] = gfx::Point(top.right(), top.bottom() - margin); 82 ring.points[7] = gfx::Point(top.right(), top.bottom() - margin);
56 ring.points[8] = gfx::Point(top.right(), top.bottom()); 83 ring.points[8] = gfx::Point(top.right(), top.bottom());
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 ring.points[34] = gfx::Point(top.x(), top.bottom()); 128 ring.points[34] = gfx::Point(top.x(), top.bottom());
102 } 129 }
103 ring.points[35] = gfx::Point(top.x(), top.bottom()); 130 ring.points[35] = gfx::Point(top.x(), top.bottom());
104 131
105 return ring; 132 return ring;
106 } 133 }
107 134
108 gfx::Rect AccessibilityFocusRing::GetBounds() const { 135 gfx::Rect AccessibilityFocusRing::GetBounds() const {
109 gfx::Point top_left = points[0]; 136 gfx::Point top_left = points[0];
110 gfx::Point bottom_right = points[0]; 137 gfx::Point bottom_right = points[0];
111 for (size_t i = 1; i < 36; i++) { 138 for (size_t i = 1; i < 36; i++) {
xiyuan 2014/09/24 19:40:35 nit: ++i
dmazzoni 2014/09/24 21:40:56 Done.
112 top_left.SetToMin(points[i]); 139 top_left.SetToMin(points[i]);
113 bottom_right.SetToMax(points[i]); 140 bottom_right.SetToMax(points[i]);
114 } 141 }
115 return gfx::Rect(top_left, gfx::Size(bottom_right.x() - top_left.x(), 142 return gfx::Rect(top_left, gfx::Size(bottom_right.x() - top_left.x(),
116 bottom_right.y() - top_left.y())); 143 bottom_right.y() - top_left.y()));
117 } 144 }
118 145
119 } // namespace chromeos 146 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698