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/editing/TextIterator.h" |
| 35 #include "core/platform/text/TextBreakIterator.h" |
| 36 #include "core/rendering/RenderText.h" |
| 37 #include "platform/LayoutUnit.h" |
| 38 |
| 39 using namespace std; |
| 40 |
| 41 namespace WebCore { |
| 42 |
| 43 using namespace HTMLNames; |
| 44 |
| 45 AccessibilityInlineTextBox::AccessibilityInlineTextBox(RenderText* renderText, R
enderText::AbstractInlineTextBox* inlineTextBox) |
| 46 : m_renderText(renderText), m_inlineTextBox(inlineTextBox) |
| 47 { |
| 48 } |
| 49 |
| 50 AccessibilityInlineTextBox::~AccessibilityInlineTextBox() |
| 51 { |
| 52 } |
| 53 |
| 54 PassRefPtr<AccessibilityInlineTextBox> AccessibilityInlineTextBox::create(Render
Text* renderText, RenderText::AbstractInlineTextBox* inlineTextBox) |
| 55 { |
| 56 return adoptRef(new AccessibilityInlineTextBox(renderText, inlineTextBox)); |
| 57 } |
| 58 |
| 59 void AccessibilityInlineTextBox::init() |
| 60 { |
| 61 } |
| 62 |
| 63 void AccessibilityInlineTextBox::detach() |
| 64 { |
| 65 m_renderText = 0; |
| 66 m_inlineTextBox = 0; |
| 67 AccessibilityObject::detach(); |
| 68 } |
| 69 |
| 70 LayoutRect AccessibilityInlineTextBox::elementRect() const |
| 71 { |
| 72 if (!m_renderText || !m_inlineTextBox) |
| 73 return LayoutRect(); |
| 74 |
| 75 return m_renderText->inlineTextBoxBounds(m_inlineTextBox); |
| 76 } |
| 77 |
| 78 bool AccessibilityInlineTextBox::computeAccessibilityIsIgnored() const |
| 79 { |
| 80 if (AccessibilityObject* parent = parentObject()) |
| 81 return parent->accessibilityIsIgnored(); |
| 82 |
| 83 return false; |
| 84 } |
| 85 |
| 86 void AccessibilityInlineTextBox::textCharacterOffsets(Vector<int>& offsets) cons
t |
| 87 { |
| 88 if (!m_renderText || !m_inlineTextBox) |
| 89 return; |
| 90 |
| 91 unsigned len = m_renderText->inlineTextBoxLen(m_inlineTextBox); |
| 92 Vector<float> widths; |
| 93 m_renderText->inlineTextBoxCharacterWidths(m_inlineTextBox, widths); |
| 94 ASSERT(widths.size() == len); |
| 95 offsets.resize(len); |
| 96 |
| 97 float widthSoFar = 0; |
| 98 for (unsigned i = 0; i < len; i++) { |
| 99 widthSoFar += widths[i]; |
| 100 offsets[i] = LayoutUnit::fromFloatRound(widthSoFar); |
| 101 } |
| 102 } |
| 103 |
| 104 void AccessibilityInlineTextBox::wordBoundaries(Vector<PlainTextRange>& words) c
onst |
| 105 { |
| 106 if (!m_renderText || !m_inlineTextBox) |
| 107 return; |
| 108 |
| 109 Vector<RenderText::WordBoundaries> wordBoundaries; |
| 110 m_renderText->inlineTextBoxWordBoundaries(m_inlineTextBox, wordBoundaries); |
| 111 words.resize(wordBoundaries.size()); |
| 112 for (unsigned i = 0; i < wordBoundaries.size(); i++) |
| 113 words[i] = PlainTextRange(wordBoundaries[i].startIndex, wordBoundaries[i
].endIndex - wordBoundaries[i].startIndex); |
| 114 } |
| 115 |
| 116 String AccessibilityInlineTextBox::stringValue() const |
| 117 { |
| 118 if (!m_renderText || !m_inlineTextBox) |
| 119 return String(); |
| 120 |
| 121 return m_renderText->inlineTextBoxText(m_inlineTextBox); |
| 122 } |
| 123 |
| 124 AccessibilityObject* AccessibilityInlineTextBox::parentObject() const |
| 125 { |
| 126 return m_renderText->document().axObjectCache()->getOrCreate(m_renderText); |
| 127 } |
| 128 |
| 129 AccessibilityTextDirection AccessibilityInlineTextBox::textDirection() const |
| 130 { |
| 131 if (!m_renderText || !m_inlineTextBox) |
| 132 return AccessibilityTextDirectionLR; |
| 133 |
| 134 switch (m_renderText->inlineTextBoxDirection(m_inlineTextBox)) { |
| 135 case RenderText::AbstractInlineTextBoxDirectionLR: |
| 136 return AccessibilityTextDirectionLR; |
| 137 case RenderText::AbstractInlineTextBoxDirectionRL: |
| 138 return AccessibilityTextDirectionRL; |
| 139 case RenderText::AbstractInlineTextBoxDirectionTB: |
| 140 return AccessibilityTextDirectionTB; |
| 141 case RenderText::AbstractInlineTextBoxDirectionBT: |
| 142 return AccessibilityTextDirectionBT; |
| 143 } |
| 144 |
| 145 return AccessibilityTextDirectionLR; |
| 146 } |
| 147 |
| 148 } // namespace WebCore |
OLD | NEW |