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

Side by Side Diff: Source/core/accessibility/AccessibilityInlineTextBox.cpp

Issue 23983002: Expose InlineTextBoxes in the accessibility tree. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Remove platform differences from inline-text-textarea output Created 7 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 /*
2 * Copyright (C) 2013, Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
14 * its contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 #include "config.h"
30 #include "core/accessibility/AccessibilityInlineTextBox.h"
31
32 #include "core/accessibility/AXObjectCache.h"
33 #include "core/dom/Range.h"
34 #include "core/editing/TextIterator.h"
35 #include "core/platform/LayoutUnit.h"
36 #include "core/platform/text/TextBreakIterator.h"
37 #include "core/rendering/InlineTextBox.h"
38
39 using namespace std;
40
41 namespace WebCore {
42
43 using namespace HTMLNames;
44
45 AccessibilityInlineTextBox::AccessibilityInlineTextBox(InlineTextBox* inlineText Box)
46 : m_inlineTextBox(inlineTextBox)
47 {
48 }
49
50 AccessibilityInlineTextBox::~AccessibilityInlineTextBox()
51 {
52 }
53
54 PassRefPtr<AccessibilityInlineTextBox> AccessibilityInlineTextBox::create(Inline TextBox* inlineTextBox)
55 {
56 return adoptRef(new AccessibilityInlineTextBox(inlineTextBox));
57 }
58
59 void AccessibilityInlineTextBox::init()
60 {
61 RenderObject* renderer = m_inlineTextBox->renderer();
62 AccessibilityObject* parent = renderer->document().axObjectCache()->getOrCre ate(renderer);
63 }
64
65 void AccessibilityInlineTextBox::detach()
66 {
67 m_inlineTextBox = 0;
68 AccessibilityObject::detach();
69 }
70
71 LayoutRect AccessibilityInlineTextBox::elementRect() const
72 {
73 if (!m_inlineTextBox)
74 return LayoutRect();
75
76 AccessibilityObject* parent = parentObject();
77 if (!parent)
78 return LayoutRect();
79
80 LayoutRect rect(m_inlineTextBox->topLeft(), m_inlineTextBox->size());
81 rect.moveBy(parent->elementRect().location());
82 return rect;
83 }
84
85 bool AccessibilityInlineTextBox::computeAccessibilityIsIgnored() const
86 {
87 if (AccessibilityObject* parent = parentObject())
88 return parent->accessibilityIsIgnored();
89
90 return false;
91 }
92
93 void AccessibilityInlineTextBox::textCharacterOffsets(Vector<int>& offsets) cons t
94 {
95 if (!m_inlineTextBox)
96 return;
97
98 int len = m_inlineTextBox->len();
99 float* widths = new float[len];
100 m_inlineTextBox->characterWidths(widths);
101 offsets.resize(len);
102
103 float widthSoFar = 0;
104 for (int i = 0; i < len; i++) {
105 widthSoFar += widths[i];
106 offsets[i] = LayoutUnit::fromFloatRound(widthSoFar);
107 }
108 delete[] widths;
109 }
110
111 void AccessibilityInlineTextBox::wordBoundaries(Vector<int>& starts, Vector<int> & ends) const
112 {
113 if (!m_inlineTextBox)
114 return;
115
116 RenderText* renderText = toRenderText(m_inlineTextBox->renderer());
117 ASSERT(renderText);
118
119 unsigned start = m_inlineTextBox->start();
120 unsigned len = m_inlineTextBox->len();
121 TextBreakIterator* iterator = wordBreakIterator(renderText->text(), start, l en);
122 int pos = textBreakFirst(iterator);
123 while (pos >= 0 && pos < len) {
124 pos = textBreakNext(iterator);
aboxhall 2013/09/06 17:19:21 Out of curiosity, how does this deal with spaces?
dmazzoni 2013/09/06 20:25:27 That's what it seems to do, yes. It's a bit confus
125 if (isWordTextBreak(iterator)) {
126 starts.append(textBreakPrevious(iterator));
127 ends.append(textBreakNext(iterator));
128 }
129 }
130 }
131
132 String AccessibilityInlineTextBox::stringValue() const
133 {
134 if (!m_inlineTextBox)
135 return String();
136
137 RenderText* renderText = toRenderText(m_inlineTextBox->renderer());
138 ASSERT(renderText);
139
140 unsigned start = m_inlineTextBox->start();
141 unsigned len = m_inlineTextBox->len();
142 if (Node* node = renderText->node()) {
aboxhall 2013/09/06 17:19:21 Why is this a special case?
dmazzoni 2013/09/06 20:25:27 This is the common case. What we want is the "plai
143 RefPtr<Range> range = Range::create(node->document());
144 range->setStart(node, start, IGNORE_EXCEPTION);
145 range->setEnd(node, start + len, IGNORE_EXCEPTION);
146 return plainText(range.get(), textIteratorBehaviorForTextRange());
147 }
148
149 return renderText->text().substring(start, len);
dmazzoni 2013/09/06 20:25:27 This is the uncommon case. We only reach this for
150 }
151
152 AccessibilityObject* AccessibilityInlineTextBox::parentObject() const
153 {
154 if (!m_inlineTextBox)
155 return 0;
156
157 RenderObject* renderer = m_inlineTextBox->renderer();
158 return renderer->document().axObjectCache()->getOrCreate(renderer);
159 }
160
161 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698