1bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)/* 2bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) * Copyright (C) 2013 Google Inc. All rights reserved. 3bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) * 4bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) * Redistribution and use in source and binary forms, with or without 5bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) * modification, are permitted provided that the following conditions are 6bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) * met: 7bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) * 8bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) * * Redistributions of source code must retain the above copyright 9bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) * notice, this list of conditions and the following disclaimer. 10bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) * * Redistributions in binary form must reproduce the above 11bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) * copyright notice, this list of conditions and the following disclaimer 12bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) * in the documentation and/or other materials provided with the 13bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) * distribution. 14bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) * * Neither the name of Google Inc. nor the names of its 15bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) * contributors may be used to endorse or promote products derived from 16bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) * this software without specific prior written permission. 17bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) * 18bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) */ 30bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) 31bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)#ifndef AbstractInlineTextBox_h 32bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)#define AbstractInlineTextBox_h 33bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) 34bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)#include "core/dom/Range.h" 35bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)#include "core/rendering/InlineTextBox.h" 36bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)#include "core/rendering/RenderText.h" 37bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)#include "wtf/HashMap.h" 38bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)#include "wtf/RefPtr.h" 39bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) 40c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)namespace blink { 41bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) 42bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)class InlineTextBox; 43bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) 44bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)// High-level abstraction of InlineTextBox to allow the accessibility module to 45bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)// get information about InlineTextBoxes without tight coupling. 46bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)class AbstractInlineTextBox : public RefCounted<AbstractInlineTextBox> { 47bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)private: 48bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) AbstractInlineTextBox(RenderText* renderText, InlineTextBox* inlineTextBox) 49bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) : m_renderText(renderText) 50bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) , m_inlineTextBox(inlineTextBox) 51bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) { 52bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) } 53bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) 54bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) static PassRefPtr<AbstractInlineTextBox> getOrCreate(RenderText*, InlineTextBox*); 55bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) static void willDestroy(InlineTextBox*); 56bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) 57bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) friend class RenderText; 58bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) friend class InlineTextBox; 59bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) 60bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)public: 61bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) struct WordBoundaries { 62bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) WordBoundaries(int startIndex, int endIndex) : startIndex(startIndex), endIndex(endIndex) { } 63bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) int startIndex; 64bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) int endIndex; 65bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) }; 66bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) 67bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) enum Direction { 68bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) LeftToRight, 69bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) RightToLeft, 70bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) TopToBottom, 71bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) BottomToTop 72bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) }; 73bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) 74bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) RenderText* renderText() const { return m_renderText; } 75bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) 76bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) PassRefPtr<AbstractInlineTextBox> nextInlineTextBox() const; 77bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) LayoutRect bounds() const; 78bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) unsigned start() const; 79bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) unsigned len() const; 80bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) Direction direction() const; 81bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) void characterWidths(Vector<float>&) const; 82bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) void wordBoundaries(Vector<WordBoundaries>&) const; 83bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) String text() const; 84bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) 85bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)private: 86bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) void detach(); 87bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) 88bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) // Weak ptrs; these are nulled when InlineTextBox::destroy() calls AbstractInlineTextBox::willDestroy. 89bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) RenderText* m_renderText; 90bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) InlineTextBox* m_inlineTextBox; 91bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) 92bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) typedef HashMap<InlineTextBox*, RefPtr<AbstractInlineTextBox> > InlineToAbstractInlineTextBoxHashMap; 93bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) static InlineToAbstractInlineTextBoxHashMap* gAbstractInlineTextBoxMap; 94bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)}; 95bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) 96c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)} // namespace blink 97bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) 98bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)#endif // AbstractInlineTextBox_h 99