Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / chromeos / ui / accessibility_focus_ring.h
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 #ifndef CHROME_BROWSER_CHROMEOS_UI_ACCESSIBILITY_FOCUS_RING_H_
6 #define CHROME_BROWSER_CHROMEOS_UI_ACCESSIBILITY_FOCUS_RING_H_
7
8 #include "ui/gfx/point.h"
9 #include "ui/gfx/rect.h"
10
11 namespace chromeos {
12
13 // An AccessibilityFocusRing is a special type of shape designed to
14 // outline the focused object on the screen for users with visual
15 // impairments. It's specifically designed to outline text ranges that
16 // span multiple lines (we'll call this a "paragraph" shape from here on,
17 // but it works for any text range), so it can outline a shape defined by a
18 // few words from the first line, the complete contents of more lines,
19 // followed by a few words from the last line. See the figure below.
20 // When highlighting any other object, it outlines a rectangular shape.
21 //
22 // The outline is outset from the object it's highlighting by a few pixels;
23 // this margin distance also determines its border radius for rounded
24 // corners.
25 //
26 // An AccessibilityFocusRing can be initialized with either a rectangle
27 // defining the bounds of an object, or a paragraph-shape with three
28 // rectangles defining a top line, a body, and a bottom line, which are
29 // assumed to be adjacent to one another.
30 //
31 // Initializing an AccessibilityFocusRing computes the following 36 points
32 // that completely define the shape's outline. This shape can be traced
33 // using Skia or any other drawing utility just by drawing alternating
34 // straight lines and quadratic curves (e.g. a line from 0 to 1, a curve
35 // from 1 to 3 with 2 as a control point, then a line from 3 to 4, and so on.
36 //
37 // The same path should be used even if the focus ring was initialized with
38 // a rectangle and not a paragraph shape - this makes it possible to
39 // smoothly animate between one object and the next simply by interpolating
40 // points.
41 //
42 // Noncontiguous shapes should be handled by drawing multiple focus rings.
43 //
44 // The 36 points are defined as follows:
45 //
46 //          2 3------------------------------4 5
47 //           /                                |
48 //          1                                  6
49 //          |      First line of paragraph     |
50 //          0                                  7
51 //         /                                    |
52 // 32 33-34 35                                 8 9---------------10 11
53 //   /                                                             |
54 // 31      Middle line of paragraph..........................       12
55 // |                                                                |
56 // |                                                                |
57 // |       Middle line of paragraph..........................       |
58 // |                                                                |
59 // |                                                                |
60 // 30      Middle line of paragraph..........................       13
61 //   |                                                             |
62 // 29 28---------27 26                             17 16---------15 14
63 //                 |                                 |
64 //                  25                             18
65 //                  |    Last line of paragraph    |
66 //                  24                             19
67 //                    |                           |
68 //                  23 22-----------------------21 20
69
70 struct AccessibilityFocusRing {
71   // Construct an AccessibilityFocusRing that outlines a rectangular object.
72   static AccessibilityFocusRing CreateWithRect(
73       const gfx::Rect& bounds, int margin);
74
75   // Returns a ring where 0.0 returns r1, 1.0 returns r2, and any number
76   // in-between interpolates linearly between them.
77   static AccessibilityFocusRing Interpolate(
78       const AccessibilityFocusRing& r1,
79       const AccessibilityFocusRing& r2,
80       double fraction);
81
82   // Construct an AccessibilityFocusRing that outlines a paragraph-shaped
83   // object.
84   static AccessibilityFocusRing CreateWithParagraphShape(
85       const gfx::Rect& top_line,
86       const gfx::Rect& body,
87       const gfx::Rect& bottom_line,
88       int margin);
89
90   gfx::Rect GetBounds() const;
91
92   gfx::Point points[36];
93 };
94
95 }  // namespace chromeos
96
97 #endif  // CHROME_BROWSER_CHROMEOS_UI_ACCESSIBILITY_FOCUS_RING_H_