Chromium Code Reviews| OLD | NEW |
|---|---|
| (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/rendering/RenderText.h" | |
| 35 #include "platform/LayoutUnit.h" | |
| 36 | |
| 37 using namespace std; | |
| 38 | |
| 39 namespace WebCore { | |
| 40 | |
| 41 using namespace HTMLNames; | |
| 42 | |
| 43 AccessibilityInlineTextBox::AccessibilityInlineTextBox(PassRefPtr<AbstractInline TextBox> inlineTextBox) | |
| 44 : m_inlineTextBox(inlineTextBox) | |
| 45 { | |
| 46 RenderText* renderText = m_inlineTextBox->renderText(); | |
| 47 m_axObjectCache = renderText->document().axObjectCache(); | |
|
eseidel
2013/10/17 18:43:26
Interesting that all of these objects each hold a
dmazzoni
2013/10/17 20:39:20
That isn't normally needed. Normally we find it fr
| |
| 48 } | |
| 49 | |
| 50 AccessibilityInlineTextBox::~AccessibilityInlineTextBox() | |
| 51 { | |
| 52 if (m_axObjectCache && m_inlineTextBox.get()) | |
|
eseidel
2013/10/17 18:43:26
You should be able to just write && m_inlineTextBo
dmazzoni
2013/10/17 20:39:20
Done.
| |
| 53 m_axObjectCache->remove(m_inlineTextBox.get()); | |
| 54 } | |
| 55 | |
| 56 PassRefPtr<AccessibilityInlineTextBox> AccessibilityInlineTextBox::create(PassRe fPtr<AbstractInlineTextBox> inlineTextBox) | |
| 57 { | |
| 58 return adoptRef(new AccessibilityInlineTextBox(inlineTextBox)); | |
| 59 } | |
| 60 | |
| 61 void AccessibilityInlineTextBox::init() | |
| 62 { | |
| 63 } | |
| 64 | |
| 65 void AccessibilityInlineTextBox::detach() | |
| 66 { | |
| 67 m_inlineTextBox = 0; | |
| 68 m_axObjectCache = 0; | |
| 69 AccessibilityObject::detach(); | |
| 70 } | |
| 71 | |
| 72 LayoutRect AccessibilityInlineTextBox::elementRect() const | |
| 73 { | |
| 74 if (!m_inlineTextBox) | |
| 75 return LayoutRect(); | |
| 76 | |
| 77 return m_inlineTextBox->bounds(); | |
| 78 } | |
| 79 | |
| 80 bool AccessibilityInlineTextBox::computeAccessibilityIsIgnored() const | |
| 81 { | |
| 82 if (AccessibilityObject* parent = parentObject()) | |
| 83 return parent->accessibilityIsIgnored(); | |
| 84 | |
| 85 return false; | |
| 86 } | |
| 87 | |
| 88 void AccessibilityInlineTextBox::textCharacterOffsets(Vector<int>& offsets) cons t | |
| 89 { | |
| 90 if (!m_inlineTextBox) | |
| 91 return; | |
| 92 | |
| 93 unsigned len = m_inlineTextBox->len(); | |
| 94 Vector<float> widths; | |
| 95 m_inlineTextBox->characterWidths(widths); | |
| 96 ASSERT(widths.size() == len); | |
| 97 offsets.resize(len); | |
| 98 | |
| 99 float widthSoFar = 0; | |
| 100 for (unsigned i = 0; i < len; i++) { | |
| 101 widthSoFar += widths[i]; | |
| 102 offsets[i] = LayoutUnit::fromFloatRound(widthSoFar); | |
| 103 } | |
| 104 } | |
| 105 | |
| 106 void AccessibilityInlineTextBox::wordBoundaries(Vector<PlainTextRange>& words) c onst | |
| 107 { | |
| 108 if (!m_inlineTextBox) | |
| 109 return; | |
| 110 | |
| 111 Vector<AbstractInlineTextBox::WordBoundaries> wordBoundaries; | |
| 112 m_inlineTextBox->wordBoundaries(wordBoundaries); | |
| 113 words.resize(wordBoundaries.size()); | |
| 114 for (unsigned i = 0; i < wordBoundaries.size(); i++) | |
| 115 words[i] = PlainTextRange(wordBoundaries[i].startIndex, wordBoundaries[i ].endIndex - wordBoundaries[i].startIndex); | |
| 116 } | |
| 117 | |
| 118 String AccessibilityInlineTextBox::stringValue() const | |
| 119 { | |
| 120 if (!m_inlineTextBox) | |
| 121 return String(); | |
| 122 | |
| 123 return m_inlineTextBox->text(); | |
| 124 } | |
| 125 | |
| 126 AccessibilityObject* AccessibilityInlineTextBox::parentObject() const | |
| 127 { | |
| 128 if (!m_inlineTextBox || !m_axObjectCache) | |
| 129 return 0; | |
| 130 | |
| 131 RenderText* renderText = m_inlineTextBox->renderText(); | |
| 132 return m_axObjectCache->getOrCreate(renderText); | |
| 133 } | |
| 134 | |
| 135 AccessibilityTextDirection AccessibilityInlineTextBox::textDirection() const | |
| 136 { | |
| 137 if (!m_inlineTextBox) | |
| 138 return AccessibilityTextDirectionLR; | |
| 139 | |
| 140 switch (m_inlineTextBox->direction()) { | |
| 141 case AbstractInlineTextBoxDirectionLR: | |
| 142 return AccessibilityTextDirectionLR; | |
| 143 case AbstractInlineTextBoxDirectionRL: | |
| 144 return AccessibilityTextDirectionRL; | |
| 145 case AbstractInlineTextBoxDirectionTB: | |
| 146 return AccessibilityTextDirectionTB; | |
| 147 case AbstractInlineTextBoxDirectionBT: | |
| 148 return AccessibilityTextDirectionBT; | |
| 149 } | |
| 150 | |
| 151 return AccessibilityTextDirectionLR; | |
| 152 } | |
| 153 | |
| 154 } // namespace WebCore | |
| OLD | NEW |