OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2003, 2004, 2005, 2006, 2007 Apple Inc. All rights reserved. | 2 * Copyright (C) 2003, 2004, 2005, 2006, 2007 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * This library is free software; you can redistribute it and/or | 4 * This library is free software; you can redistribute it and/or |
5 * modify it under the terms of the GNU Library General Public | 5 * modify it under the terms of the GNU Library General Public |
6 * License as published by the Free Software Foundation; either | 6 * License as published by the Free Software Foundation; either |
7 * version 2 of the License, or (at your option) any later version. | 7 * version 2 of the License, or (at your option) any later version. |
8 * | 8 * |
9 * This library is distributed in the hope that it will be useful, | 9 * This library is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 } | 75 } |
76 | 76 |
77 #ifndef NDEBUG | 77 #ifndef NDEBUG |
78 const char* InlineBox::boxName() const | 78 const char* InlineBox::boxName() const |
79 { | 79 { |
80 return "InlineBox"; | 80 return "InlineBox"; |
81 } | 81 } |
82 | 82 |
83 void InlineBox::showTreeForThis() const | 83 void InlineBox::showTreeForThis() const |
84 { | 84 { |
85 if (m_renderer) | 85 renderer().showTreeForThis(); |
86 m_renderer->showTreeForThis(); | |
87 } | 86 } |
88 | 87 |
89 void InlineBox::showLineTreeForThis() const | 88 void InlineBox::showLineTreeForThis() const |
90 { | 89 { |
91 if (m_renderer) | 90 renderer().containingBlock()->showLineTreeAndMark(this, "*"); |
92 m_renderer->containingBlock()->showLineTreeAndMark(this, "*"); | |
93 } | 91 } |
94 | 92 |
95 void InlineBox::showLineTreeAndMark(const InlineBox* markedBox1, const char* mar
kedLabel1, const InlineBox* markedBox2, const char* markedLabel2, const RenderOb
ject* obj, int depth) const | 93 void InlineBox::showLineTreeAndMark(const InlineBox* markedBox1, const char* mar
kedLabel1, const InlineBox* markedBox2, const char* markedLabel2, const RenderOb
ject* obj, int depth) const |
96 { | 94 { |
97 int printedCharacters = 0; | 95 int printedCharacters = 0; |
98 if (this == markedBox1) | 96 if (this == markedBox1) |
99 printedCharacters += fprintf(stderr, "%s", markedLabel1); | 97 printedCharacters += fprintf(stderr, "%s", markedLabel1); |
100 if (this == markedBox2) | 98 if (this == markedBox2) |
101 printedCharacters += fprintf(stderr, "%s", markedLabel2); | 99 printedCharacters += fprintf(stderr, "%s", markedLabel2); |
102 if (renderer() == obj) | 100 if (&renderer() == obj) |
103 printedCharacters += fprintf(stderr, "*"); | 101 printedCharacters += fprintf(stderr, "*"); |
104 for (; printedCharacters < depth * 2; printedCharacters++) | 102 for (; printedCharacters < depth * 2; printedCharacters++) |
105 fputc(' ', stderr); | 103 fputc(' ', stderr); |
106 | 104 |
107 showBox(printedCharacters); | 105 showBox(printedCharacters); |
108 } | 106 } |
109 | 107 |
110 void InlineBox::showBox(int printedCharacters) const | 108 void InlineBox::showBox(int printedCharacters) const |
111 { | 109 { |
112 printedCharacters += fprintf(stderr, "%s\t%p", boxName(), this); | 110 printedCharacters += fprintf(stderr, "%s\t%p", boxName(), this); |
113 for (; printedCharacters < showTreeCharacterOffset; printedCharacters++) | 111 for (; printedCharacters < showTreeCharacterOffset; printedCharacters++) |
114 fputc(' ', stderr); | 112 fputc(' ', stderr); |
115 fprintf(stderr, "\t%s %p\n", renderer() ? renderer()->renderName() : "No Ren
derer", renderer()); | 113 fprintf(stderr, "\t%s %p\n", renderer().renderName(), &renderer()); |
116 } | 114 } |
117 #endif | 115 #endif |
118 | 116 |
119 float InlineBox::logicalHeight() const | 117 float InlineBox::logicalHeight() const |
120 { | 118 { |
121 if (hasVirtualLogicalHeight()) | 119 if (hasVirtualLogicalHeight()) |
122 return virtualLogicalHeight(); | 120 return virtualLogicalHeight(); |
123 | 121 |
124 if (renderer()->isText()) | 122 if (renderer().isText()) |
125 return m_bitfields.isText() ? renderer()->style(isFirstLineStyle())->fon
tMetrics().height() : 0; | 123 return m_bitfields.isText() ? renderer().style(isFirstLineStyle())->font
Metrics().height() : 0; |
126 if (renderer()->isBox() && parent()) | 124 if (renderer().isBox() && parent()) |
127 return isHorizontal() ? toRenderBox(m_renderer)->height() : toRenderBox(
m_renderer)->width(); | 125 return isHorizontal() ? toRenderBox(renderer()).height() : toRenderBox(r
enderer()).width(); |
128 | 126 |
129 ASSERT(isInlineFlowBox()); | 127 ASSERT(isInlineFlowBox()); |
130 RenderBoxModelObject* flowObject = boxModelObject(); | 128 RenderBoxModelObject* flowObject = boxModelObject(); |
131 const FontMetrics& fontMetrics = renderer()->style(isFirstLineStyle())->font
Metrics(); | 129 const FontMetrics& fontMetrics = renderer().style(isFirstLineStyle())->fontM
etrics(); |
132 float result = fontMetrics.height(); | 130 float result = fontMetrics.height(); |
133 if (parent()) | 131 if (parent()) |
134 result += flowObject->borderAndPaddingLogicalHeight(); | 132 result += flowObject->borderAndPaddingLogicalHeight(); |
135 return result; | 133 return result; |
136 } | 134 } |
137 | 135 |
138 int InlineBox::baselinePosition(FontBaseline baselineType) const | 136 int InlineBox::baselinePosition(FontBaseline baselineType) const |
139 { | 137 { |
140 return boxModelObject()->baselinePosition(baselineType, m_bitfields.firstLin
e(), isHorizontal() ? HorizontalLine : VerticalLine, PositionOnContainingLine); | 138 return boxModelObject()->baselinePosition(baselineType, m_bitfields.firstLin
e(), isHorizontal() ? HorizontalLine : VerticalLine, PositionOnContainingLine); |
141 } | 139 } |
142 | 140 |
143 LayoutUnit InlineBox::lineHeight() const | 141 LayoutUnit InlineBox::lineHeight() const |
144 { | 142 { |
145 return boxModelObject()->lineHeight(m_bitfields.firstLine(), isHorizontal()
? HorizontalLine : VerticalLine, PositionOnContainingLine); | 143 return boxModelObject()->lineHeight(m_bitfields.firstLine(), isHorizontal()
? HorizontalLine : VerticalLine, PositionOnContainingLine); |
146 } | 144 } |
147 | 145 |
148 int InlineBox::caretMinOffset() const | 146 int InlineBox::caretMinOffset() const |
149 { | 147 { |
150 return m_renderer->caretMinOffset(); | 148 return renderer().caretMinOffset(); |
151 } | 149 } |
152 | 150 |
153 int InlineBox::caretMaxOffset() const | 151 int InlineBox::caretMaxOffset() const |
154 { | 152 { |
155 return m_renderer->caretMaxOffset(); | 153 return renderer().caretMaxOffset(); |
156 } | 154 } |
157 | 155 |
158 void InlineBox::dirtyLineBoxes() | 156 void InlineBox::dirtyLineBoxes() |
159 { | 157 { |
160 markDirty(); | 158 markDirty(); |
161 for (InlineFlowBox* curr = parent(); curr && !curr->isDirty(); curr = curr->
parent()) | 159 for (InlineFlowBox* curr = parent(); curr && !curr->isDirty(); curr = curr->
parent()) |
162 curr->markDirty(); | 160 curr->markDirty(); |
163 } | 161 } |
164 | 162 |
165 void InlineBox::deleteLine() | 163 void InlineBox::deleteLine() |
166 { | 164 { |
167 if (!m_bitfields.extracted() && m_renderer->isBox()) | 165 if (!m_bitfields.extracted() && renderer().isBox()) |
168 toRenderBox(m_renderer)->setInlineBoxWrapper(0); | 166 toRenderBox(renderer()).setInlineBoxWrapper(0); |
169 destroy(); | 167 destroy(); |
170 } | 168 } |
171 | 169 |
172 void InlineBox::extractLine() | 170 void InlineBox::extractLine() |
173 { | 171 { |
174 m_bitfields.setExtracted(true); | 172 m_bitfields.setExtracted(true); |
175 if (m_renderer->isBox()) | 173 if (renderer().isBox()) |
176 toRenderBox(m_renderer)->setInlineBoxWrapper(0); | 174 toRenderBox(renderer()).setInlineBoxWrapper(0); |
177 } | 175 } |
178 | 176 |
179 void InlineBox::attachLine() | 177 void InlineBox::attachLine() |
180 { | 178 { |
181 m_bitfields.setExtracted(false); | 179 m_bitfields.setExtracted(false); |
182 if (m_renderer->isBox()) | 180 if (renderer().isBox()) |
183 toRenderBox(m_renderer)->setInlineBoxWrapper(this); | 181 toRenderBox(renderer()).setInlineBoxWrapper(this); |
184 } | 182 } |
185 | 183 |
186 void InlineBox::adjustPosition(float dx, float dy) | 184 void InlineBox::adjustPosition(float dx, float dy) |
187 { | 185 { |
188 m_topLeft.move(dx, dy); | 186 m_topLeft.move(dx, dy); |
189 | 187 |
190 if (m_renderer->isReplaced()) | 188 if (renderer().isReplaced()) |
191 toRenderBox(m_renderer)->move(dx, dy); | 189 toRenderBox(renderer()).move(dx, dy); |
192 } | 190 } |
193 | 191 |
194 void InlineBox::paint(PaintInfo& paintInfo, const LayoutPoint& paintOffset, Layo
utUnit /* lineTop */, LayoutUnit /*lineBottom*/) | 192 void InlineBox::paint(PaintInfo& paintInfo, const LayoutPoint& paintOffset, Layo
utUnit /* lineTop */, LayoutUnit /*lineBottom*/) |
195 { | 193 { |
196 if (!paintInfo.shouldPaintWithinRoot(renderer()) || (paintInfo.phase != Pain
tPhaseForeground && paintInfo.phase != PaintPhaseSelection)) | 194 if (!paintInfo.shouldPaintWithinRoot(&renderer()) || (paintInfo.phase != Pai
ntPhaseForeground && paintInfo.phase != PaintPhaseSelection)) |
197 return; | 195 return; |
198 | 196 |
199 LayoutPoint childPoint = paintOffset; | 197 LayoutPoint childPoint = paintOffset; |
200 if (parent()->renderer()->style()->isFlippedBlocksWritingMode()) // Faster t
han calling containingBlock(). | 198 if (parent()->renderer().style()->isFlippedBlocksWritingMode()) // Faster th
an calling containingBlock(). |
201 childPoint = renderer()->containingBlock()->flipForWritingModeForChild(t
oRenderBox(renderer()), childPoint); | 199 childPoint = renderer().containingBlock()->flipForWritingModeForChild(&t
oRenderBox(renderer()), childPoint); |
202 | 200 |
203 RenderBlock::paintAsInlineBlock(renderer(), paintInfo, childPoint); | 201 RenderBlock::paintAsInlineBlock(&renderer(), paintInfo, childPoint); |
204 } | 202 } |
205 | 203 |
206 bool InlineBox::nodeAtPoint(const HitTestRequest& request, HitTestResult& result
, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffs
et, LayoutUnit /* lineTop */, LayoutUnit /*lineBottom*/) | 204 bool InlineBox::nodeAtPoint(const HitTestRequest& request, HitTestResult& result
, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffs
et, LayoutUnit /* lineTop */, LayoutUnit /*lineBottom*/) |
207 { | 205 { |
208 // Hit test all phases of replaced elements atomically, as though the replac
ed element established its | 206 // Hit test all phases of replaced elements atomically, as though the replac
ed element established its |
209 // own stacking context. (See Appendix E.2, section 6.4 on inline block/tab
le elements in the CSS2.1 | 207 // own stacking context. (See Appendix E.2, section 6.4 on inline block/tab
le elements in the CSS2.1 |
210 // specification.) | 208 // specification.) |
211 LayoutPoint childPoint = accumulatedOffset; | 209 LayoutPoint childPoint = accumulatedOffset; |
212 if (parent()->renderer()->style()->isFlippedBlocksWritingMode()) // Faster t
han calling containingBlock(). | 210 if (parent()->renderer().style()->isFlippedBlocksWritingMode()) // Faster th
an calling containingBlock(). |
213 childPoint = renderer()->containingBlock()->flipForWritingModeForChild(t
oRenderBox(renderer()), childPoint); | 211 childPoint = renderer().containingBlock()->flipForWritingModeForChild(&t
oRenderBox(renderer()), childPoint); |
214 | 212 |
215 return renderer()->hitTest(request, result, locationInContainer, childPoint)
; | 213 return renderer().hitTest(request, result, locationInContainer, childPoint); |
216 } | 214 } |
217 | 215 |
218 const RootInlineBox* InlineBox::root() const | 216 const RootInlineBox* InlineBox::root() const |
219 { | 217 { |
220 if (m_parent) | 218 if (m_parent) |
221 return m_parent->root(); | 219 return m_parent->root(); |
222 ASSERT(isRootInlineBox()); | 220 ASSERT(isRootInlineBox()); |
223 return static_cast<const RootInlineBox*>(this); | 221 return static_cast<const RootInlineBox*>(this); |
224 } | 222 } |
225 | 223 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 InlineBox* InlineBox::prevLeafChildIgnoringLineBreak() const | 275 InlineBox* InlineBox::prevLeafChildIgnoringLineBreak() const |
278 { | 276 { |
279 InlineBox* leaf = prevLeafChild(); | 277 InlineBox* leaf = prevLeafChild(); |
280 if (leaf && leaf->isLineBreak()) | 278 if (leaf && leaf->isLineBreak()) |
281 return 0; | 279 return 0; |
282 return leaf; | 280 return leaf; |
283 } | 281 } |
284 | 282 |
285 RenderObject::SelectionState InlineBox::selectionState() | 283 RenderObject::SelectionState InlineBox::selectionState() |
286 { | 284 { |
287 return renderer()->selectionState(); | 285 return renderer().selectionState(); |
288 } | 286 } |
289 | 287 |
290 bool InlineBox::canAccommodateEllipsis(bool ltr, int blockEdge, int ellipsisWidt
h) const | 288 bool InlineBox::canAccommodateEllipsis(bool ltr, int blockEdge, int ellipsisWidt
h) const |
291 { | 289 { |
292 // Non-replaced elements can always accommodate an ellipsis. | 290 // Non-replaced elements can always accommodate an ellipsis. |
293 if (!m_renderer || !m_renderer->isReplaced()) | 291 if (!renderer().isReplaced()) |
294 return true; | 292 return true; |
295 | 293 |
296 IntRect boxRect(left(), 0, m_logicalWidth, 10); | 294 IntRect boxRect(left(), 0, m_logicalWidth, 10); |
297 IntRect ellipsisRect(ltr ? blockEdge - ellipsisWidth : blockEdge, 0, ellipsi
sWidth, 10); | 295 IntRect ellipsisRect(ltr ? blockEdge - ellipsisWidth : blockEdge, 0, ellipsi
sWidth, 10); |
298 return !(boxRect.intersects(ellipsisRect)); | 296 return !(boxRect.intersects(ellipsisRect)); |
299 } | 297 } |
300 | 298 |
301 float InlineBox::placeEllipsisBox(bool, float, float, float, float& truncatedWid
th, bool&) | 299 float InlineBox::placeEllipsisBox(bool, float, float, float, float& truncatedWid
th, bool&) |
302 { | 300 { |
303 // Use -1 to mean "we didn't set the position." | 301 // Use -1 to mean "we didn't set the position." |
304 truncatedWidth += logicalWidth(); | 302 truncatedWidth += logicalWidth(); |
305 return -1; | 303 return -1; |
306 } | 304 } |
307 | 305 |
308 void InlineBox::clearKnownToHaveNoOverflow() | 306 void InlineBox::clearKnownToHaveNoOverflow() |
309 { | 307 { |
310 m_bitfields.setKnownToHaveNoOverflow(false); | 308 m_bitfields.setKnownToHaveNoOverflow(false); |
311 if (parent() && parent()->knownToHaveNoOverflow()) | 309 if (parent() && parent()->knownToHaveNoOverflow()) |
312 parent()->clearKnownToHaveNoOverflow(); | 310 parent()->clearKnownToHaveNoOverflow(); |
313 } | 311 } |
314 | 312 |
315 FloatPoint InlineBox::locationIncludingFlipping() | 313 FloatPoint InlineBox::locationIncludingFlipping() |
316 { | 314 { |
317 if (!renderer()->style()->isFlippedBlocksWritingMode()) | 315 if (!renderer().style()->isFlippedBlocksWritingMode()) |
318 return FloatPoint(x(), y()); | 316 return FloatPoint(x(), y()); |
319 RenderBlockFlow* block = root()->block(); | 317 RenderBlockFlow& block = root()->block(); |
320 if (block->style()->isHorizontalWritingMode()) | 318 if (block.style()->isHorizontalWritingMode()) |
321 return FloatPoint(x(), block->height() - height() - y()); | 319 return FloatPoint(x(), block.height() - height() - y()); |
322 else | 320 |
323 return FloatPoint(block->width() - width() - x(), y()); | 321 return FloatPoint(block.width() - width() - x(), y()); |
324 } | 322 } |
325 | 323 |
326 void InlineBox::flipForWritingMode(FloatRect& rect) | 324 void InlineBox::flipForWritingMode(FloatRect& rect) |
327 { | 325 { |
328 if (!renderer()->style()->isFlippedBlocksWritingMode()) | 326 if (!renderer().style()->isFlippedBlocksWritingMode()) |
329 return; | 327 return; |
330 root()->block()->flipForWritingMode(rect); | 328 root()->block().flipForWritingMode(rect); |
331 } | 329 } |
332 | 330 |
333 FloatPoint InlineBox::flipForWritingMode(const FloatPoint& point) | 331 FloatPoint InlineBox::flipForWritingMode(const FloatPoint& point) |
334 { | 332 { |
335 if (!renderer()->style()->isFlippedBlocksWritingMode()) | 333 if (!renderer().style()->isFlippedBlocksWritingMode()) |
336 return point; | 334 return point; |
337 return root()->block()->flipForWritingMode(point); | 335 return root()->block().flipForWritingMode(point); |
338 } | 336 } |
339 | 337 |
340 void InlineBox::flipForWritingMode(LayoutRect& rect) | 338 void InlineBox::flipForWritingMode(LayoutRect& rect) |
341 { | 339 { |
342 if (!renderer()->style()->isFlippedBlocksWritingMode()) | 340 if (!renderer().style()->isFlippedBlocksWritingMode()) |
343 return; | 341 return; |
344 root()->block()->flipForWritingMode(rect); | 342 root()->block().flipForWritingMode(rect); |
345 } | 343 } |
346 | 344 |
347 LayoutPoint InlineBox::flipForWritingMode(const LayoutPoint& point) | 345 LayoutPoint InlineBox::flipForWritingMode(const LayoutPoint& point) |
348 { | 346 { |
349 if (!renderer()->style()->isFlippedBlocksWritingMode()) | 347 if (!renderer().style()->isFlippedBlocksWritingMode()) |
350 return point; | 348 return point; |
351 return root()->block()->flipForWritingMode(point); | 349 return root()->block().flipForWritingMode(point); |
352 } | 350 } |
353 | 351 |
354 } // namespace WebCore | 352 } // namespace WebCore |
355 | 353 |
356 #ifndef NDEBUG | 354 #ifndef NDEBUG |
357 | 355 |
358 void showTree(const WebCore::InlineBox* b) | 356 void showTree(const WebCore::InlineBox* b) |
359 { | 357 { |
360 if (b) | 358 if (b) |
361 b->showTreeForThis(); | 359 b->showTreeForThis(); |
362 } | 360 } |
363 | 361 |
364 void showLineTree(const WebCore::InlineBox* b) | 362 void showLineTree(const WebCore::InlineBox* b) |
365 { | 363 { |
366 if (b) | 364 if (b) |
367 b->showLineTreeForThis(); | 365 b->showLineTreeForThis(); |
368 } | 366 } |
369 | 367 |
370 #endif | 368 #endif |
OLD | NEW |