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 are | |
6 * met: | |
7 * | |
8 * * Redistributions of source code must retain the above copyright | |
9 * notice, this list of conditions and the following disclaimer. | |
10 * * Redistributions in binary form must reproduce the above | |
11 * copyright notice, this list of conditions and the following disclaimer | |
12 * in the documentation and/or other materials provided with the | |
13 * distribution. | |
14 * * Neither the name of Google Inc. nor the names of its | |
15 * contributors may be used to endorse or promote products derived from | |
16 * this software without specific prior written permission. | |
17 * | |
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
29 */ | |
30 | |
31 #include "config.h" | |
32 #include "core/rendering/AbstractInlineTextBox.h" | |
33 | |
34 #include "core/editing/TextIterator.h" | |
35 #include "core/rendering/InlineTextBox.h" | |
36 #include "platform/text/TextBreakIterator.h" | |
37 | |
38 namespace WebCore { | |
39 | |
40 HashMap<InlineTextBox*, RefPtr<AbstractInlineTextBox> >* AbstractInlineTextBox:: gAbstractInlineTextBoxMap = 0; | |
aboxhall
2013/10/17 22:27:55
What's the g for, out of curiosity?
dmazzoni
2013/10/19 06:48:07
Global.
That seems to be the standard Blink style
| |
41 | |
42 PassRefPtr<AbstractInlineTextBox> AbstractInlineTextBox::getOrCreate(RenderText* renderText, InlineTextBox* inlineTextBox) | |
aboxhall
2013/10/17 22:27:55
Do we comment static methods with // static ?
dmazzoni
2013/10/19 06:48:07
I don't think so, I haven't seen it in Blink code.
| |
43 { | |
44 if (!inlineTextBox) | |
45 return 0; | |
46 | |
47 if (!gAbstractInlineTextBoxMap) | |
48 gAbstractInlineTextBoxMap = new HashMap<InlineTextBox*, RefPtr<AbstractI nlineTextBox> >(); | |
49 | |
50 HashMap<InlineTextBox*, RefPtr<AbstractInlineTextBox> >::const_iterator it = gAbstractInlineTextBoxMap->find(inlineTextBox); | |
aboxhall
2013/10/17 22:27:55
Would it make sense to typedef this iterator type
dmazzoni
2013/10/19 06:48:07
Sure, that helps readability a bit. Done.
| |
51 if (it != gAbstractInlineTextBoxMap->end()) | |
52 return it->value; | |
53 | |
54 RefPtr<AbstractInlineTextBox> obj = adoptRef(new AbstractInlineTextBox(rende rText, inlineTextBox)); | |
55 gAbstractInlineTextBoxMap->set(inlineTextBox, obj); | |
56 return obj; | |
57 } | |
58 | |
59 void AbstractInlineTextBox::willDestroy(InlineTextBox* inlineTextBox) | |
60 { | |
61 if (!gAbstractInlineTextBoxMap) | |
62 return; | |
63 | |
64 HashMap<InlineTextBox*, RefPtr<AbstractInlineTextBox> >::const_iterator it = gAbstractInlineTextBoxMap->find(inlineTextBox); | |
65 if (it != gAbstractInlineTextBoxMap->end()) { | |
66 it->value->detach(); | |
67 gAbstractInlineTextBoxMap->remove(inlineTextBox); | |
68 } | |
69 } | |
70 | |
71 void AbstractInlineTextBox::detach() | |
72 { | |
73 m_renderText = 0; | |
74 m_inlineTextBox = 0; | |
75 } | |
76 | |
77 PassRefPtr<AbstractInlineTextBox> AbstractInlineTextBox::nextInlineTextBox() con st | |
78 { | |
79 if (!m_inlineTextBox) | |
80 return 0; | |
81 | |
82 return getOrCreate(m_renderText, m_inlineTextBox->nextTextBox()); | |
83 } | |
84 | |
85 LayoutRect AbstractInlineTextBox::bounds() const | |
86 { | |
87 if (!m_inlineTextBox || !m_renderText) | |
88 return LayoutRect(); | |
89 | |
90 FloatRect boundaries = m_inlineTextBox->calculateBoundaries(); | |
91 return m_renderText->localToAbsoluteQuad(boundaries).enclosingBoundingBox(); | |
92 } | |
93 | |
94 unsigned AbstractInlineTextBox::start() const | |
95 { | |
96 if (!m_inlineTextBox) | |
97 return 0; | |
98 | |
99 return m_inlineTextBox->start(); | |
100 } | |
101 | |
102 unsigned AbstractInlineTextBox::len() const | |
103 { | |
104 if (!m_inlineTextBox) | |
105 return 0; | |
106 | |
107 return m_inlineTextBox->len(); | |
108 } | |
109 | |
110 AbstractInlineTextBox::Direction AbstractInlineTextBox::direction() const | |
111 { | |
112 if (!m_inlineTextBox || !m_renderText) | |
113 return LeftToRight; | |
114 | |
115 if (m_renderText->style()->isHorizontalWritingMode()) | |
116 return (m_inlineTextBox->direction() == RTL ? RightToLeft : LeftToRight) ; | |
117 return (m_inlineTextBox->direction() == RTL ? BottomToTop : TopToBottom); | |
118 } | |
119 | |
120 void AbstractInlineTextBox::characterWidths(Vector<float>& widths) const | |
121 { | |
122 if (!m_inlineTextBox) | |
123 return; | |
124 | |
125 m_inlineTextBox->characterWidths(widths); | |
126 } | |
127 | |
128 void AbstractInlineTextBox::wordBoundaries(Vector<WordBoundaries>& words) const | |
129 { | |
130 if (!m_inlineTextBox) | |
131 return; | |
132 | |
133 String text = this->text(); | |
134 int len = text.length(); | |
135 TextBreakIterator* iterator = wordBreakIterator(text, 0, len); | |
136 int pos = iterator->first(); | |
137 while (pos >= 0 && pos < len) { | |
138 int next = iterator->next(); | |
139 if (isWordTextBreak(iterator)) | |
140 words.append(WordBoundaries(pos, next)); | |
141 pos = next; | |
142 } | |
143 } | |
144 | |
145 String AbstractInlineTextBox::text() const | |
146 { | |
147 if (!m_inlineTextBox || !m_renderText) | |
148 return String(); | |
149 | |
150 unsigned start = m_inlineTextBox->start(); | |
151 unsigned len = m_inlineTextBox->len(); | |
152 if (Node* node = m_renderText->node()) { | |
153 RefPtr<Range> range = Range::create(node->document()); | |
154 range->setStart(node, start, IGNORE_EXCEPTION); | |
155 range->setEnd(node, start + len, IGNORE_EXCEPTION); | |
156 return plainText(range.get(), TextIteratorIgnoresStyleVisibility); | |
157 } | |
158 | |
159 return text().substring(start, len); | |
aboxhall
2013/10/17 22:27:55
What are these two cases (node and !node) for? Doe
dmazzoni
2013/10/19 06:48:07
It's for generated text, like list item numbers or
| |
160 } | |
161 | |
162 } // namespace WebCore | |
OLD | NEW |