author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Mon, 03 May 2010 13:17:34 +0300 | |
changeset 19 | fcece45ef507 |
parent 0 | 1918ee327afb |
child 30 | 5dc02b23752f |
permissions | -rw-r--r-- |
0 | 1 |
/* |
2 |
* Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
|
3 |
* (C) 1999 Antti Koivisto (koivisto@kde.org) |
|
4 |
* (C) 2005 Allan Sandfeld Jensen (kde@carewolf.com) |
|
5 |
* (C) 2005, 2006 Samuel Weinig (sam.weinig@gmail.com) |
|
6 |
* Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. |
|
7 |
* |
|
8 |
* This library is free software; you can redistribute it and/or |
|
9 |
* modify it under the terms of the GNU Library General Public |
|
10 |
* License as published by the Free Software Foundation; either |
|
11 |
* version 2 of the License, or (at your option) any later version. |
|
12 |
* |
|
13 |
* This library is distributed in the hope that it will be useful, |
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
16 |
* Library General Public License for more details. |
|
17 |
* |
|
18 |
* You should have received a copy of the GNU Library General Public License |
|
19 |
* along with this library; see the file COPYING.LIB. If not, write to |
|
20 |
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
|
21 |
* Boston, MA 02110-1301, USA. |
|
22 |
* |
|
23 |
*/ |
|
24 |
||
25 |
#include "config.h" |
|
26 |
#include "RenderBox.h" |
|
27 |
||
28 |
#include "CachedImage.h" |
|
29 |
#include "ChromeClient.h" |
|
30 |
#include "Document.h" |
|
31 |
#include "FrameView.h" |
|
32 |
#include "GraphicsContext.h" |
|
33 |
#include "htmlediting.h" |
|
34 |
#include "HTMLElement.h" |
|
35 |
#include "HTMLNames.h" |
|
36 |
#include "ImageBuffer.h" |
|
37 |
#include "FloatQuad.h" |
|
38 |
#include "Frame.h" |
|
39 |
#include "Page.h" |
|
40 |
#include "RenderArena.h" |
|
41 |
#include "RenderFlexibleBox.h" |
|
42 |
#include "RenderInline.h" |
|
43 |
#include "RenderLayer.h" |
|
44 |
#include "RenderTableCell.h" |
|
45 |
#include "RenderTheme.h" |
|
46 |
#include "RenderView.h" |
|
47 |
#include "TransformState.h" |
|
48 |
#include <algorithm> |
|
49 |
#include <math.h> |
|
50 |
||
51 |
#if ENABLE(WML) |
|
52 |
#include "WMLNames.h" |
|
53 |
#endif |
|
54 |
||
55 |
using namespace std; |
|
56 |
||
57 |
namespace WebCore { |
|
58 |
||
59 |
using namespace HTMLNames; |
|
60 |
||
61 |
// Used by flexible boxes when flexing this element. |
|
62 |
typedef WTF::HashMap<const RenderBox*, int> OverrideSizeMap; |
|
63 |
static OverrideSizeMap* gOverrideSizeMap = 0; |
|
64 |
||
65 |
bool RenderBox::s_hadOverflowClip = false; |
|
66 |
||
67 |
RenderBox::RenderBox(Node* node) |
|
68 |
: RenderBoxModelObject(node) |
|
69 |
, m_marginLeft(0) |
|
70 |
, m_marginRight(0) |
|
71 |
, m_marginTop(0) |
|
72 |
, m_marginBottom(0) |
|
73 |
, m_minPrefWidth(-1) |
|
74 |
, m_maxPrefWidth(-1) |
|
75 |
, m_inlineBoxWrapper(0) |
|
76 |
{ |
|
77 |
setIsBox(); |
|
78 |
} |
|
79 |
||
80 |
RenderBox::~RenderBox() |
|
81 |
{ |
|
82 |
} |
|
83 |
||
84 |
void RenderBox::destroy() |
|
85 |
{ |
|
86 |
// A lot of the code in this function is just pasted into |
|
87 |
// RenderWidget::destroy. If anything in this function changes, |
|
88 |
// be sure to fix RenderWidget::destroy() as well. |
|
89 |
if (hasOverrideSize()) |
|
90 |
gOverrideSizeMap->remove(this); |
|
91 |
||
92 |
if (style() && (style()->height().isPercent() || style()->minHeight().isPercent() || style()->maxHeight().isPercent())) |
|
93 |
RenderBlock::removePercentHeightDescendant(this); |
|
94 |
||
95 |
RenderBoxModelObject::destroy(); |
|
96 |
} |
|
97 |
||
98 |
void RenderBox::removeFloatingOrPositionedChildFromBlockLists() |
|
99 |
{ |
|
100 |
ASSERT(isFloatingOrPositioned()); |
|
101 |
||
102 |
if (documentBeingDestroyed()) |
|
103 |
return; |
|
104 |
||
105 |
if (isFloating()) { |
|
106 |
RenderBlock* outermostBlock = containingBlock(); |
|
107 |
for (RenderBlock* p = outermostBlock; p && !p->isRenderView(); p = p->containingBlock()) { |
|
108 |
if (p->containsFloat(this)) |
|
109 |
outermostBlock = p; |
|
110 |
} |
|
111 |
||
112 |
if (outermostBlock) |
|
113 |
outermostBlock->markAllDescendantsWithFloatsForLayout(this, false); |
|
114 |
} |
|
115 |
||
116 |
if (isPositioned()) { |
|
117 |
RenderObject* p; |
|
118 |
for (p = parent(); p; p = p->parent()) { |
|
119 |
if (p->isRenderBlock()) |
|
120 |
toRenderBlock(p)->removePositionedObject(this); |
|
121 |
} |
|
122 |
} |
|
123 |
} |
|
124 |
||
125 |
void RenderBox::styleWillChange(StyleDifference diff, const RenderStyle* newStyle) |
|
126 |
{ |
|
127 |
s_hadOverflowClip = hasOverflowClip(); |
|
128 |
||
129 |
if (style()) { |
|
130 |
// The background of the root element or the body element could propagate up to |
|
131 |
// the canvas. Just dirty the entire canvas when our style changes substantially. |
|
132 |
if (diff >= StyleDifferenceRepaint && node() && |
|
133 |
(node()->hasTagName(htmlTag) || node()->hasTagName(bodyTag))) |
|
134 |
view()->repaint(); |
|
135 |
||
136 |
// When a layout hint happens and an object's position style changes, we have to do a layout |
|
137 |
// to dirty the render tree using the old position value now. |
|
138 |
if (diff == StyleDifferenceLayout && parent() && style()->position() != newStyle->position()) { |
|
139 |
markContainingBlocksForLayout(); |
|
140 |
if (style()->position() == StaticPosition) |
|
141 |
repaint(); |
|
142 |
else if (newStyle->position() == AbsolutePosition || newStyle->position() == FixedPosition) |
|
143 |
parent()->setChildNeedsLayout(true); |
|
144 |
if (isFloating() && !isPositioned() && (newStyle->position() == AbsolutePosition || newStyle->position() == FixedPosition)) |
|
145 |
removeFloatingOrPositionedChildFromBlockLists(); |
|
146 |
} |
|
147 |
} |
|
19
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
148 |
if (FrameView *frameView = view()->frameView()) { |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
149 |
bool newStyleIsFixed = newStyle && newStyle->position() == FixedPosition; |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
150 |
bool oldStyleIsFixed = style() && style()->position() == FixedPosition; |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
151 |
if (newStyleIsFixed != oldStyleIsFixed) { |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
152 |
if (newStyleIsFixed) |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
153 |
frameView->addFixedObject(); |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
154 |
else |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
155 |
frameView->removeFixedObject(); |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
156 |
} |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
157 |
} |
0 | 158 |
|
159 |
RenderBoxModelObject::styleWillChange(diff, newStyle); |
|
160 |
} |
|
161 |
||
162 |
void RenderBox::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle) |
|
163 |
{ |
|
164 |
RenderBoxModelObject::styleDidChange(diff, oldStyle); |
|
165 |
||
166 |
if (needsLayout() && oldStyle && (oldStyle->height().isPercent() || oldStyle->minHeight().isPercent() || oldStyle->maxHeight().isPercent())) |
|
167 |
RenderBlock::removePercentHeightDescendant(this); |
|
168 |
||
169 |
// If our zoom factor changes and we have a defined scrollLeft/Top, we need to adjust that value into the |
|
170 |
// new zoomed coordinate space. |
|
171 |
if (hasOverflowClip() && oldStyle && style() && oldStyle->effectiveZoom() != style()->effectiveZoom()) { |
|
172 |
int left = scrollLeft(); |
|
173 |
if (left) { |
|
174 |
left = (left / oldStyle->effectiveZoom()) * style()->effectiveZoom(); |
|
175 |
setScrollLeft(left); |
|
176 |
} |
|
177 |
int top = scrollTop(); |
|
178 |
if (top) { |
|
179 |
top = (top / oldStyle->effectiveZoom()) * style()->effectiveZoom(); |
|
180 |
setScrollTop(top); |
|
181 |
} |
|
182 |
} |
|
183 |
||
184 |
// Set the text color if we're the body. |
|
185 |
if (isBody()) |
|
186 |
document()->setTextColor(style()->color()); |
|
187 |
} |
|
188 |
||
189 |
void RenderBox::updateBoxModelInfoFromStyle() |
|
190 |
{ |
|
191 |
RenderBoxModelObject::updateBoxModelInfoFromStyle(); |
|
192 |
||
193 |
bool isRootObject = isRoot(); |
|
194 |
bool isViewObject = isRenderView(); |
|
195 |
||
196 |
// The root and the RenderView always paint their backgrounds/borders. |
|
197 |
if (isRootObject || isViewObject) |
|
198 |
setHasBoxDecorations(true); |
|
199 |
||
200 |
setPositioned(style()->position() == AbsolutePosition || style()->position() == FixedPosition); |
|
201 |
setFloating(!isPositioned() && style()->isFloating()); |
|
202 |
||
203 |
// We also handle <body> and <html>, whose overflow applies to the viewport. |
|
204 |
if (style()->overflowX() != OVISIBLE && !isRootObject && (isRenderBlock() || isTableRow() || isTableSection())) { |
|
205 |
bool boxHasOverflowClip = true; |
|
206 |
if (isBody()) { |
|
207 |
// Overflow on the body can propagate to the viewport under the following conditions. |
|
208 |
// (1) The root element is <html>. |
|
209 |
// (2) We are the primary <body> (can be checked by looking at document.body). |
|
210 |
// (3) The root element has visible overflow. |
|
211 |
if (document()->documentElement()->hasTagName(htmlTag) && |
|
212 |
document()->body() == node() && |
|
213 |
document()->documentElement()->renderer()->style()->overflowX() == OVISIBLE) |
|
214 |
boxHasOverflowClip = false; |
|
215 |
} |
|
216 |
||
217 |
// Check for overflow clip. |
|
218 |
// It's sufficient to just check one direction, since it's illegal to have visible on only one overflow value. |
|
219 |
if (boxHasOverflowClip) { |
|
220 |
if (!s_hadOverflowClip) |
|
221 |
// Erase the overflow |
|
222 |
repaint(); |
|
223 |
setHasOverflowClip(); |
|
224 |
} |
|
225 |
} |
|
226 |
||
227 |
setHasTransform(style()->hasTransformRelatedProperty()); |
|
228 |
setHasReflection(style()->boxReflect()); |
|
229 |
} |
|
230 |
||
231 |
void RenderBox::layout() |
|
232 |
{ |
|
233 |
ASSERT(needsLayout()); |
|
234 |
||
235 |
RenderObject* child = firstChild(); |
|
236 |
if (!child) { |
|
237 |
setNeedsLayout(false); |
|
238 |
return; |
|
239 |
} |
|
240 |
||
241 |
LayoutStateMaintainer statePusher(view(), this, IntSize(x(), y())); |
|
242 |
while (child) { |
|
243 |
child->layoutIfNeeded(); |
|
244 |
ASSERT(!child->needsLayout()); |
|
245 |
child = child->nextSibling(); |
|
246 |
} |
|
247 |
statePusher.pop(); |
|
248 |
setNeedsLayout(false); |
|
249 |
} |
|
250 |
||
251 |
// More IE extensions. clientWidth and clientHeight represent the interior of an object |
|
252 |
// excluding border and scrollbar. |
|
253 |
int RenderBox::clientWidth() const |
|
254 |
{ |
|
255 |
return width() - borderLeft() - borderRight() - verticalScrollbarWidth(); |
|
256 |
} |
|
257 |
||
258 |
int RenderBox::clientHeight() const |
|
259 |
{ |
|
260 |
return height() - borderTop() - borderBottom() - horizontalScrollbarHeight(); |
|
261 |
} |
|
262 |
||
263 |
int RenderBox::scrollWidth() const |
|
264 |
{ |
|
265 |
if (hasOverflowClip()) |
|
266 |
return layer()->scrollWidth(); |
|
267 |
// For objects with visible overflow, this matches IE. |
|
268 |
if (style()->direction() == LTR) |
|
269 |
return max(clientWidth(), rightmostPosition(true, false) - borderLeft()); |
|
270 |
return clientWidth() - min(0, leftmostPosition(true, false) - borderLeft()); |
|
271 |
} |
|
272 |
||
273 |
int RenderBox::scrollHeight() const |
|
274 |
{ |
|
275 |
if (hasOverflowClip()) |
|
276 |
return layer()->scrollHeight(); |
|
277 |
// For objects with visible overflow, this matches IE. |
|
278 |
return max(clientHeight(), lowestPosition(true, false) - borderTop()); |
|
279 |
} |
|
280 |
||
281 |
int RenderBox::scrollLeft() const |
|
282 |
{ |
|
283 |
return hasOverflowClip() ? layer()->scrollXOffset() : 0; |
|
284 |
} |
|
285 |
||
286 |
int RenderBox::scrollTop() const |
|
287 |
{ |
|
288 |
return hasOverflowClip() ? layer()->scrollYOffset() : 0; |
|
289 |
} |
|
290 |
||
291 |
void RenderBox::setScrollLeft(int newLeft) |
|
292 |
{ |
|
293 |
if (hasOverflowClip()) |
|
294 |
layer()->scrollToXOffset(newLeft); |
|
295 |
} |
|
296 |
||
297 |
void RenderBox::setScrollTop(int newTop) |
|
298 |
{ |
|
299 |
if (hasOverflowClip()) |
|
300 |
layer()->scrollToYOffset(newTop); |
|
301 |
} |
|
302 |
||
303 |
void RenderBox::absoluteRects(Vector<IntRect>& rects, int tx, int ty) |
|
304 |
{ |
|
305 |
rects.append(IntRect(tx, ty, width(), height())); |
|
306 |
} |
|
307 |
||
308 |
void RenderBox::absoluteQuads(Vector<FloatQuad>& quads) |
|
309 |
{ |
|
310 |
quads.append(localToAbsoluteQuad(FloatRect(0, 0, width(), height()))); |
|
311 |
} |
|
312 |
||
313 |
IntRect RenderBox::absoluteContentBox() const |
|
314 |
{ |
|
315 |
IntRect rect = contentBoxRect(); |
|
316 |
FloatPoint absPos = localToAbsolute(FloatPoint()); |
|
317 |
rect.move(absPos.x(), absPos.y()); |
|
318 |
return rect; |
|
319 |
} |
|
320 |
||
321 |
FloatQuad RenderBox::absoluteContentQuad() const |
|
322 |
{ |
|
323 |
IntRect rect = contentBoxRect(); |
|
324 |
return localToAbsoluteQuad(FloatRect(rect)); |
|
325 |
} |
|
326 |
||
327 |
IntRect RenderBox::outlineBoundsForRepaint(RenderBoxModelObject* repaintContainer) const |
|
328 |
{ |
|
329 |
IntRect box = borderBoundingBox(); |
|
330 |
adjustRectForOutlineAndShadow(box); |
|
331 |
||
332 |
FloatQuad containerRelativeQuad = localToContainerQuad(FloatRect(box), repaintContainer); |
|
333 |
box = containerRelativeQuad.enclosingBoundingBox(); |
|
334 |
||
335 |
// FIXME: layoutDelta needs to be applied in parts before/after transforms and |
|
336 |
// repaint containers. https://bugs.webkit.org/show_bug.cgi?id=23308 |
|
337 |
box.move(view()->layoutDelta()); |
|
338 |
||
339 |
return box; |
|
340 |
} |
|
341 |
||
342 |
void RenderBox::addFocusRingRects(GraphicsContext* graphicsContext, int tx, int ty) |
|
343 |
{ |
|
344 |
graphicsContext->addFocusRingRect(IntRect(tx, ty, width(), height())); |
|
345 |
} |
|
346 |
||
347 |
||
348 |
IntRect RenderBox::reflectionBox() const |
|
349 |
{ |
|
350 |
IntRect result; |
|
351 |
if (!style()->boxReflect()) |
|
352 |
return result; |
|
353 |
IntRect box = borderBoxRect(); |
|
354 |
result = box; |
|
355 |
switch (style()->boxReflect()->direction()) { |
|
356 |
case ReflectionBelow: |
|
357 |
result.move(0, box.height() + reflectionOffset()); |
|
358 |
break; |
|
359 |
case ReflectionAbove: |
|
360 |
result.move(0, -box.height() - reflectionOffset()); |
|
361 |
break; |
|
362 |
case ReflectionLeft: |
|
363 |
result.move(-box.width() - reflectionOffset(), 0); |
|
364 |
break; |
|
365 |
case ReflectionRight: |
|
366 |
result.move(box.width() + reflectionOffset(), 0); |
|
367 |
break; |
|
368 |
} |
|
369 |
return result; |
|
370 |
} |
|
371 |
||
372 |
int RenderBox::reflectionOffset() const |
|
373 |
{ |
|
374 |
if (!style()->boxReflect()) |
|
375 |
return 0; |
|
376 |
if (style()->boxReflect()->direction() == ReflectionLeft || style()->boxReflect()->direction() == ReflectionRight) |
|
377 |
return style()->boxReflect()->offset().calcValue(borderBoxRect().width()); |
|
378 |
return style()->boxReflect()->offset().calcValue(borderBoxRect().height()); |
|
379 |
} |
|
380 |
||
381 |
IntRect RenderBox::reflectedRect(const IntRect& r) const |
|
382 |
{ |
|
383 |
if (!style()->boxReflect()) |
|
384 |
return IntRect(); |
|
385 |
||
386 |
IntRect box = borderBoxRect(); |
|
387 |
IntRect result = r; |
|
388 |
switch (style()->boxReflect()->direction()) { |
|
389 |
case ReflectionBelow: |
|
390 |
result.setY(box.bottom() + reflectionOffset() + (box.bottom() - r.bottom())); |
|
391 |
break; |
|
392 |
case ReflectionAbove: |
|
393 |
result.setY(box.y() - reflectionOffset() - box.height() + (box.bottom() - r.bottom())); |
|
394 |
break; |
|
395 |
case ReflectionLeft: |
|
396 |
result.setX(box.x() - reflectionOffset() - box.width() + (box.right() - r.right())); |
|
397 |
break; |
|
398 |
case ReflectionRight: |
|
399 |
result.setX(box.right() + reflectionOffset() + (box.right() - r.right())); |
|
400 |
break; |
|
401 |
} |
|
402 |
return result; |
|
403 |
} |
|
404 |
||
405 |
int RenderBox::verticalScrollbarWidth() const |
|
406 |
{ |
|
407 |
return includeVerticalScrollbarSize() ? layer()->verticalScrollbarWidth() : 0; |
|
408 |
} |
|
409 |
||
410 |
int RenderBox::horizontalScrollbarHeight() const |
|
411 |
{ |
|
412 |
return includeHorizontalScrollbarSize() ? layer()->horizontalScrollbarHeight() : 0; |
|
413 |
} |
|
414 |
||
415 |
bool RenderBox::scroll(ScrollDirection direction, ScrollGranularity granularity, float multiplier, Node** stopNode) |
|
416 |
{ |
|
417 |
RenderLayer* l = layer(); |
|
418 |
if (l && l->scroll(direction, granularity, multiplier)) { |
|
419 |
if (stopNode) |
|
420 |
*stopNode = node(); |
|
421 |
return true; |
|
422 |
} |
|
423 |
||
424 |
if (stopNode && *stopNode && *stopNode == node()) |
|
425 |
return true; |
|
426 |
||
427 |
RenderBlock* b = containingBlock(); |
|
428 |
if (b && !b->isRenderView()) |
|
429 |
return b->scroll(direction, granularity, multiplier, stopNode); |
|
430 |
return false; |
|
431 |
} |
|
432 |
||
433 |
bool RenderBox::canBeScrolledAndHasScrollableArea() const |
|
434 |
{ |
|
435 |
return canBeProgramaticallyScrolled(false) && (scrollHeight() != clientHeight() || scrollWidth() != clientWidth()); |
|
436 |
} |
|
437 |
||
438 |
bool RenderBox::canBeProgramaticallyScrolled(bool) const |
|
439 |
{ |
|
440 |
return (hasOverflowClip() && (scrollsOverflow() || (node() && node()->isContentEditable()))) || (node() && node()->isDocumentNode()); |
|
441 |
} |
|
442 |
||
443 |
void RenderBox::autoscroll() |
|
444 |
{ |
|
445 |
if (layer()) |
|
446 |
layer()->autoscroll(); |
|
447 |
} |
|
448 |
||
449 |
void RenderBox::panScroll(const IntPoint& source) |
|
450 |
{ |
|
451 |
if (layer()) |
|
452 |
layer()->panScrollFromPoint(source); |
|
453 |
} |
|
454 |
||
455 |
int RenderBox::minPrefWidth() const |
|
456 |
{ |
|
457 |
if (prefWidthsDirty()) |
|
458 |
const_cast<RenderBox*>(this)->calcPrefWidths(); |
|
459 |
||
460 |
return m_minPrefWidth; |
|
461 |
} |
|
462 |
||
463 |
int RenderBox::maxPrefWidth() const |
|
464 |
{ |
|
465 |
if (prefWidthsDirty()) |
|
466 |
const_cast<RenderBox*>(this)->calcPrefWidths(); |
|
467 |
||
468 |
return m_maxPrefWidth; |
|
469 |
} |
|
470 |
||
471 |
int RenderBox::overrideSize() const |
|
472 |
{ |
|
473 |
if (!hasOverrideSize()) |
|
474 |
return -1; |
|
475 |
return gOverrideSizeMap->get(this); |
|
476 |
} |
|
477 |
||
478 |
void RenderBox::setOverrideSize(int s) |
|
479 |
{ |
|
480 |
if (s == -1) { |
|
481 |
if (hasOverrideSize()) { |
|
482 |
setHasOverrideSize(false); |
|
483 |
gOverrideSizeMap->remove(this); |
|
484 |
} |
|
485 |
} else { |
|
486 |
if (!gOverrideSizeMap) |
|
487 |
gOverrideSizeMap = new OverrideSizeMap(); |
|
488 |
setHasOverrideSize(true); |
|
489 |
gOverrideSizeMap->set(this, s); |
|
490 |
} |
|
491 |
} |
|
492 |
||
493 |
int RenderBox::overrideWidth() const |
|
494 |
{ |
|
495 |
return hasOverrideSize() ? overrideSize() : width(); |
|
496 |
} |
|
497 |
||
498 |
int RenderBox::overrideHeight() const |
|
499 |
{ |
|
500 |
return hasOverrideSize() ? overrideSize() : height(); |
|
501 |
} |
|
502 |
||
503 |
int RenderBox::calcBorderBoxWidth(int width) const |
|
504 |
{ |
|
505 |
int bordersPlusPadding = borderLeft() + borderRight() + paddingLeft() + paddingRight(); |
|
506 |
if (style()->boxSizing() == CONTENT_BOX) |
|
507 |
return width + bordersPlusPadding; |
|
508 |
return max(width, bordersPlusPadding); |
|
509 |
} |
|
510 |
||
511 |
int RenderBox::calcBorderBoxHeight(int height) const |
|
512 |
{ |
|
513 |
int bordersPlusPadding = borderTop() + borderBottom() + paddingTop() + paddingBottom(); |
|
514 |
if (style()->boxSizing() == CONTENT_BOX) |
|
515 |
return height + bordersPlusPadding; |
|
516 |
return max(height, bordersPlusPadding); |
|
517 |
} |
|
518 |
||
519 |
int RenderBox::calcContentBoxWidth(int width) const |
|
520 |
{ |
|
521 |
if (style()->boxSizing() == BORDER_BOX) |
|
522 |
width -= (borderLeft() + borderRight() + paddingLeft() + paddingRight()); |
|
523 |
return max(0, width); |
|
524 |
} |
|
525 |
||
526 |
int RenderBox::calcContentBoxHeight(int height) const |
|
527 |
{ |
|
528 |
if (style()->boxSizing() == BORDER_BOX) |
|
529 |
height -= (borderTop() + borderBottom() + paddingTop() + paddingBottom()); |
|
530 |
return max(0, height); |
|
531 |
} |
|
532 |
||
533 |
// Hit Testing |
|
534 |
bool RenderBox::nodeAtPoint(const HitTestRequest& request, HitTestResult& result, int xPos, int yPos, int tx, int ty, HitTestAction action) |
|
535 |
{ |
|
536 |
tx += x(); |
|
537 |
ty += y(); |
|
538 |
||
539 |
// Check kids first. |
|
540 |
for (RenderObject* child = lastChild(); child; child = child->previousSibling()) { |
|
541 |
if (!child->hasLayer() && child->nodeAtPoint(request, result, xPos, yPos, tx, ty, action)) { |
|
542 |
updateHitTestResult(result, IntPoint(xPos - tx, yPos - ty)); |
|
543 |
return true; |
|
544 |
} |
|
545 |
} |
|
546 |
||
547 |
// Check our bounds next. For this purpose always assume that we can only be hit in the |
|
548 |
// foreground phase (which is true for replaced elements like images). |
|
549 |
if (visibleToHitTesting() && action == HitTestForeground && IntRect(tx, ty, width(), height()).contains(xPos, yPos)) { |
|
550 |
updateHitTestResult(result, IntPoint(xPos - tx, yPos - ty)); |
|
551 |
return true; |
|
552 |
} |
|
553 |
||
554 |
return false; |
|
555 |
} |
|
556 |
||
557 |
// --------------------- painting stuff ------------------------------- |
|
558 |
||
559 |
void RenderBox::paint(PaintInfo& paintInfo, int tx, int ty) |
|
560 |
{ |
|
561 |
tx += x(); |
|
562 |
ty += y(); |
|
563 |
||
564 |
// default implementation. Just pass paint through to the children |
|
565 |
PaintInfo childInfo(paintInfo); |
|
566 |
childInfo.paintingRoot = paintingRootForChildren(paintInfo); |
|
567 |
for (RenderObject* child = firstChild(); child; child = child->nextSibling()) |
|
568 |
child->paint(childInfo, tx, ty); |
|
569 |
} |
|
570 |
||
571 |
void RenderBox::paintRootBoxDecorations(PaintInfo& paintInfo, int tx, int ty) |
|
572 |
{ |
|
573 |
const FillLayer* bgLayer = style()->backgroundLayers(); |
|
574 |
Color bgColor = style()->backgroundColor(); |
|
575 |
if (!style()->hasBackground() && node() && node()->hasTagName(HTMLNames::htmlTag)) { |
|
576 |
// Locate the <body> element using the DOM. This is easier than trying |
|
577 |
// to crawl around a render tree with potential :before/:after content and |
|
578 |
// anonymous blocks created by inline <body> tags etc. We can locate the <body> |
|
579 |
// render object very easily via the DOM. |
|
580 |
HTMLElement* body = document()->body(); |
|
581 |
RenderObject* bodyObject = (body && body->hasLocalName(bodyTag)) ? body->renderer() : 0; |
|
582 |
if (bodyObject) { |
|
583 |
bgLayer = bodyObject->style()->backgroundLayers(); |
|
584 |
bgColor = bodyObject->style()->backgroundColor(); |
|
585 |
} |
|
586 |
} |
|
587 |
||
588 |
int w = width(); |
|
589 |
int h = height(); |
|
590 |
||
591 |
int rw; |
|
592 |
int rh; |
|
593 |
if (view()->frameView()) { |
|
594 |
rw = view()->frameView()->contentsWidth(); |
|
595 |
rh = view()->frameView()->contentsHeight(); |
|
596 |
} else { |
|
597 |
rw = view()->width(); |
|
598 |
rh = view()->height(); |
|
599 |
} |
|
600 |
||
601 |
// CSS2 14.2: |
|
602 |
// The background of the box generated by the root element covers the entire canvas including |
|
603 |
// its margins. |
|
604 |
int bx = tx - marginLeft(); |
|
605 |
int by = ty - marginTop(); |
|
606 |
int bw = max(w + marginLeft() + marginRight() + borderLeft() + borderRight(), rw); |
|
607 |
int bh = max(h + marginTop() + marginBottom() + borderTop() + borderBottom(), rh); |
|
608 |
||
609 |
paintFillLayers(paintInfo, bgColor, bgLayer, bx, by, bw, bh); |
|
610 |
||
611 |
if (style()->hasBorder() && style()->display() != INLINE) |
|
612 |
paintBorder(paintInfo.context, tx, ty, w, h, style()); |
|
613 |
} |
|
614 |
||
615 |
void RenderBox::paintBoxDecorations(PaintInfo& paintInfo, int tx, int ty) |
|
616 |
{ |
|
617 |
if (!shouldPaintWithinRoot(paintInfo)) |
|
618 |
return; |
|
619 |
||
620 |
if (isRoot()) { |
|
621 |
paintRootBoxDecorations(paintInfo, tx, ty); |
|
622 |
return; |
|
623 |
} |
|
624 |
||
625 |
int w = width(); |
|
626 |
int h = height(); |
|
627 |
||
628 |
// border-fit can adjust where we paint our border and background. If set, we snugly fit our line box descendants. (The iChat |
|
629 |
// balloon layout is an example of this). |
|
630 |
borderFitAdjust(tx, w); |
|
631 |
||
632 |
// FIXME: Should eventually give the theme control over whether the box shadow should paint, since controls could have |
|
633 |
// custom shadows of their own. |
|
634 |
paintBoxShadow(paintInfo.context, tx, ty, w, h, style(), Normal); |
|
635 |
||
636 |
// If we have a native theme appearance, paint that before painting our background. |
|
637 |
// The theme will tell us whether or not we should also paint the CSS background. |
|
638 |
bool themePainted = style()->hasAppearance() && !theme()->paint(this, paintInfo, IntRect(tx, ty, w, h)); |
|
639 |
if (!themePainted) { |
|
640 |
// The <body> only paints its background if the root element has defined a background |
|
641 |
// independent of the body. Go through the DOM to get to the root element's render object, |
|
642 |
// since the root could be inline and wrapped in an anonymous block. |
|
643 |
if (!isBody() || document()->documentElement()->renderer()->style()->hasBackground()) |
|
644 |
paintFillLayers(paintInfo, style()->backgroundColor(), style()->backgroundLayers(), tx, ty, w, h); |
|
645 |
if (style()->hasAppearance()) |
|
646 |
theme()->paintDecorations(this, paintInfo, IntRect(tx, ty, w, h)); |
|
647 |
} |
|
648 |
paintBoxShadow(paintInfo.context, tx, ty, w, h, style(), Inset); |
|
649 |
||
650 |
// The theme will tell us whether or not we should also paint the CSS border. |
|
651 |
if ((!style()->hasAppearance() || (!themePainted && theme()->paintBorderOnly(this, paintInfo, IntRect(tx, ty, w, h)))) && style()->hasBorder()) |
|
652 |
paintBorder(paintInfo.context, tx, ty, w, h, style()); |
|
653 |
} |
|
654 |
||
655 |
void RenderBox::paintMask(PaintInfo& paintInfo, int tx, int ty) |
|
656 |
{ |
|
657 |
if (!shouldPaintWithinRoot(paintInfo) || style()->visibility() != VISIBLE || paintInfo.phase != PaintPhaseMask) |
|
658 |
return; |
|
659 |
||
660 |
int w = width(); |
|
661 |
int h = height(); |
|
662 |
||
663 |
// border-fit can adjust where we paint our border and background. If set, we snugly fit our line box descendants. (The iChat |
|
664 |
// balloon layout is an example of this). |
|
665 |
borderFitAdjust(tx, w); |
|
666 |
||
667 |
paintMaskImages(paintInfo, tx, ty, w, h); |
|
668 |
} |
|
669 |
||
670 |
void RenderBox::paintMaskImages(const PaintInfo& paintInfo, int tx, int ty, int w, int h) |
|
671 |
{ |
|
672 |
// Figure out if we need to push a transparency layer to render our mask. |
|
673 |
bool pushTransparencyLayer = false; |
|
674 |
bool compositedMask = hasLayer() && layer()->hasCompositedMask(); |
|
675 |
CompositeOperator compositeOp = CompositeSourceOver; |
|
676 |
||
677 |
if (!compositedMask) { |
|
678 |
StyleImage* maskBoxImage = style()->maskBoxImage().image(); |
|
679 |
if (maskBoxImage && style()->maskLayers()->hasImage()) { |
|
680 |
pushTransparencyLayer = true; |
|
681 |
} else { |
|
682 |
// We have to use an extra image buffer to hold the mask. Multiple mask images need |
|
683 |
// to composite together using source-over so that they can then combine into a single unified mask that |
|
684 |
// can be composited with the content using destination-in. SVG images need to be able to set compositing modes |
|
685 |
// as they draw images contained inside their sub-document, so we paint all our images into a separate buffer |
|
686 |
// and composite that buffer as the mask. |
|
687 |
// We have to check that the mask images to be rendered contain at least one image that can be actually used in rendering |
|
688 |
// before pushing the transparency layer. |
|
689 |
for (const FillLayer* fillLayer = style()->maskLayers()->next(); fillLayer; fillLayer = fillLayer->next()) { |
|
690 |
if (fillLayer->hasImage() && fillLayer->image()->canRender(style()->effectiveZoom())) { |
|
691 |
pushTransparencyLayer = true; |
|
692 |
// We found one image that can be used in rendering, exit the loop |
|
693 |
break; |
|
694 |
} |
|
695 |
} |
|
696 |
} |
|
697 |
||
698 |
compositeOp = CompositeDestinationIn; |
|
699 |
if (pushTransparencyLayer) { |
|
700 |
paintInfo.context->setCompositeOperation(CompositeDestinationIn); |
|
701 |
paintInfo.context->beginTransparencyLayer(1.0f); |
|
702 |
compositeOp = CompositeSourceOver; |
|
703 |
} |
|
704 |
} |
|
705 |
||
706 |
paintFillLayers(paintInfo, Color(), style()->maskLayers(), tx, ty, w, h, compositeOp); |
|
707 |
paintNinePieceImage(paintInfo.context, tx, ty, w, h, style(), style()->maskBoxImage(), compositeOp); |
|
708 |
||
709 |
if (pushTransparencyLayer) |
|
710 |
paintInfo.context->endTransparencyLayer(); |
|
711 |
} |
|
712 |
||
713 |
IntRect RenderBox::maskClipRect() |
|
714 |
{ |
|
715 |
IntRect bbox = borderBoxRect(); |
|
716 |
if (style()->maskBoxImage().image()) |
|
717 |
return bbox; |
|
718 |
||
719 |
IntRect result; |
|
720 |
for (const FillLayer* maskLayer = style()->maskLayers(); maskLayer; maskLayer = maskLayer->next()) { |
|
721 |
if (maskLayer->image()) { |
|
722 |
IntRect maskRect; |
|
723 |
IntPoint phase; |
|
724 |
IntSize tileSize; |
|
725 |
calculateBackgroundImageGeometry(maskLayer, bbox.x(), bbox.y(), bbox.width(), bbox.height(), maskRect, phase, tileSize); |
|
726 |
result.unite(maskRect); |
|
727 |
} |
|
728 |
} |
|
729 |
return result; |
|
730 |
} |
|
731 |
||
732 |
void RenderBox::paintFillLayers(const PaintInfo& paintInfo, const Color& c, const FillLayer* fillLayer, int tx, int ty, int width, int height, CompositeOperator op) |
|
733 |
{ |
|
734 |
if (!fillLayer) |
|
735 |
return; |
|
736 |
||
737 |
paintFillLayers(paintInfo, c, fillLayer->next(), tx, ty, width, height, op); |
|
738 |
paintFillLayer(paintInfo, c, fillLayer, tx, ty, width, height, op); |
|
739 |
} |
|
740 |
||
741 |
void RenderBox::paintFillLayer(const PaintInfo& paintInfo, const Color& c, const FillLayer* fillLayer, int tx, int ty, int width, int height, CompositeOperator op) |
|
742 |
{ |
|
743 |
paintFillLayerExtended(paintInfo, c, fillLayer, tx, ty, width, height, 0, op); |
|
744 |
} |
|
745 |
||
746 |
void RenderBox::imageChanged(WrappedImagePtr image, const IntRect*) |
|
747 |
{ |
|
748 |
if (!parent()) |
|
749 |
return; |
|
750 |
||
751 |
if ((style()->borderImage().image() && style()->borderImage().image()->data() == image) || |
|
752 |
(style()->maskBoxImage().image() && style()->maskBoxImage().image()->data() == image)) { |
|
753 |
repaint(); |
|
754 |
return; |
|
755 |
} |
|
756 |
||
757 |
bool didFullRepaint = repaintLayerRectsForImage(image, style()->backgroundLayers(), true); |
|
758 |
if (!didFullRepaint) |
|
759 |
repaintLayerRectsForImage(image, style()->maskLayers(), false); |
|
760 |
} |
|
761 |
||
762 |
bool RenderBox::repaintLayerRectsForImage(WrappedImagePtr image, const FillLayer* layers, bool drawingBackground) |
|
763 |
{ |
|
764 |
IntRect rendererRect; |
|
765 |
RenderBox* layerRenderer = 0; |
|
766 |
||
767 |
for (const FillLayer* curLayer = layers; curLayer; curLayer = curLayer->next()) { |
|
768 |
if (curLayer->image() && image == curLayer->image()->data() && curLayer->image()->canRender(style()->effectiveZoom())) { |
|
769 |
// Now that we know this image is being used, compute the renderer and the rect |
|
770 |
// if we haven't already |
|
771 |
if (!layerRenderer) { |
|
772 |
bool drawingRootBackground = drawingBackground && (isRoot() || (isBody() && !document()->documentElement()->renderer()->style()->hasBackground())); |
|
773 |
if (drawingRootBackground) { |
|
774 |
layerRenderer = view(); |
|
775 |
||
776 |
int rw; |
|
777 |
int rh; |
|
778 |
||
779 |
if (FrameView* frameView = toRenderView(layerRenderer)->frameView()) { |
|
780 |
rw = frameView->contentsWidth(); |
|
781 |
rh = frameView->contentsHeight(); |
|
782 |
} else { |
|
783 |
rw = layerRenderer->width(); |
|
784 |
rh = layerRenderer->height(); |
|
785 |
} |
|
786 |
rendererRect = IntRect(-layerRenderer->marginLeft(), |
|
787 |
-layerRenderer->marginTop(), |
|
788 |
max(layerRenderer->width() + layerRenderer->marginLeft() + layerRenderer->marginRight() + layerRenderer->borderLeft() + layerRenderer->borderRight(), rw), |
|
789 |
max(layerRenderer->height() + layerRenderer->marginTop() + layerRenderer->marginBottom() + layerRenderer->borderTop() + layerRenderer->borderBottom(), rh)); |
|
790 |
} else { |
|
791 |
layerRenderer = this; |
|
792 |
rendererRect = borderBoxRect(); |
|
793 |
} |
|
794 |
} |
|
795 |
||
796 |
IntRect repaintRect; |
|
797 |
IntPoint phase; |
|
798 |
IntSize tileSize; |
|
799 |
layerRenderer->calculateBackgroundImageGeometry(curLayer, rendererRect.x(), rendererRect.y(), rendererRect.width(), rendererRect.height(), repaintRect, phase, tileSize); |
|
800 |
layerRenderer->repaintRectangle(repaintRect); |
|
801 |
if (repaintRect == rendererRect) |
|
802 |
return true; |
|
803 |
} |
|
804 |
} |
|
805 |
return false; |
|
806 |
} |
|
807 |
||
808 |
#if PLATFORM(MAC) |
|
809 |
||
810 |
void RenderBox::paintCustomHighlight(int tx, int ty, const AtomicString& type, bool behindText) |
|
811 |
{ |
|
812 |
Frame* frame = document()->frame(); |
|
813 |
if (!frame) |
|
814 |
return; |
|
815 |
Page* page = frame->page(); |
|
816 |
if (!page) |
|
817 |
return; |
|
818 |
||
819 |
InlineBox* boxWrap = inlineBoxWrapper(); |
|
820 |
RootInlineBox* r = boxWrap ? boxWrap->root() : 0; |
|
821 |
if (r) { |
|
822 |
FloatRect rootRect(tx + r->x(), ty + r->selectionTop(), r->width(), r->selectionHeight()); |
|
823 |
FloatRect imageRect(tx + x(), rootRect.y(), width(), rootRect.height()); |
|
824 |
page->chrome()->client()->paintCustomHighlight(node(), type, imageRect, rootRect, behindText, false); |
|
825 |
} else { |
|
826 |
FloatRect imageRect(tx + x(), ty + y(), width(), height()); |
|
827 |
page->chrome()->client()->paintCustomHighlight(node(), type, imageRect, imageRect, behindText, false); |
|
828 |
} |
|
829 |
} |
|
830 |
||
831 |
#endif |
|
832 |
||
833 |
bool RenderBox::pushContentsClip(PaintInfo& paintInfo, int tx, int ty) |
|
834 |
{ |
|
835 |
if (paintInfo.phase == PaintPhaseBlockBackground || paintInfo.phase == PaintPhaseSelfOutline || paintInfo.phase == PaintPhaseMask) |
|
836 |
return false; |
|
837 |
||
838 |
bool isControlClip = hasControlClip(); |
|
839 |
bool isOverflowClip = hasOverflowClip() && !layer()->isSelfPaintingLayer(); |
|
840 |
||
841 |
if (!isControlClip && !isOverflowClip) |
|
842 |
return false; |
|
843 |
||
844 |
if (paintInfo.phase == PaintPhaseOutline) |
|
845 |
paintInfo.phase = PaintPhaseChildOutlines; |
|
846 |
else if (paintInfo.phase == PaintPhaseChildBlockBackground) { |
|
847 |
paintInfo.phase = PaintPhaseBlockBackground; |
|
848 |
paintObject(paintInfo, tx, ty); |
|
849 |
paintInfo.phase = PaintPhaseChildBlockBackgrounds; |
|
850 |
} |
|
851 |
IntRect clipRect(isControlClip ? controlClipRect(tx, ty) : overflowClipRect(tx, ty)); |
|
852 |
paintInfo.context->save(); |
|
853 |
if (style()->hasBorderRadius()) { |
|
854 |
IntSize topLeft, topRight, bottomLeft, bottomRight; |
|
855 |
IntRect borderRect = IntRect(tx, ty, width(), height()); |
|
856 |
style()->getBorderRadiiForRect(borderRect, topLeft, topRight, bottomLeft, bottomRight); |
|
857 |
||
858 |
paintInfo.context->addRoundedRectClip(borderRect, topLeft, topRight, bottomLeft, bottomRight); |
|
859 |
} |
|
860 |
||
861 |
paintInfo.context->clip(clipRect); |
|
862 |
return true; |
|
863 |
} |
|
864 |
||
865 |
void RenderBox::popContentsClip(PaintInfo& paintInfo, PaintPhase originalPhase, int tx, int ty) |
|
866 |
{ |
|
867 |
ASSERT(hasControlClip() || (hasOverflowClip() && !layer()->isSelfPaintingLayer())); |
|
868 |
||
869 |
paintInfo.context->restore(); |
|
870 |
if (originalPhase == PaintPhaseOutline) { |
|
871 |
paintInfo.phase = PaintPhaseSelfOutline; |
|
872 |
paintObject(paintInfo, tx, ty); |
|
873 |
paintInfo.phase = originalPhase; |
|
874 |
} else if (originalPhase == PaintPhaseChildBlockBackground) |
|
875 |
paintInfo.phase = originalPhase; |
|
876 |
} |
|
877 |
||
878 |
IntRect RenderBox::overflowClipRect(int tx, int ty) |
|
879 |
{ |
|
880 |
// FIXME: When overflow-clip (CSS3) is implemented, we'll obtain the property |
|
881 |
// here. |
|
882 |
||
883 |
int bLeft = borderLeft(); |
|
884 |
int bTop = borderTop(); |
|
885 |
||
886 |
int clipX = tx + bLeft; |
|
887 |
int clipY = ty + bTop; |
|
888 |
int clipWidth = width() - bLeft - borderRight(); |
|
889 |
int clipHeight = height() - bTop - borderBottom(); |
|
890 |
||
891 |
// Subtract out scrollbars if we have them. |
|
892 |
if (layer()) { |
|
893 |
clipWidth -= layer()->verticalScrollbarWidth(); |
|
894 |
clipHeight -= layer()->horizontalScrollbarHeight(); |
|
895 |
} |
|
896 |
||
897 |
return IntRect(clipX, clipY, clipWidth, clipHeight); |
|
898 |
} |
|
899 |
||
900 |
IntRect RenderBox::clipRect(int tx, int ty) |
|
901 |
{ |
|
902 |
int clipX = tx; |
|
903 |
int clipY = ty; |
|
904 |
int clipWidth = width(); |
|
905 |
int clipHeight = height(); |
|
906 |
||
907 |
if (!style()->clipLeft().isAuto()) { |
|
908 |
int c = style()->clipLeft().calcValue(width()); |
|
909 |
clipX += c; |
|
910 |
clipWidth -= c; |
|
911 |
} |
|
912 |
||
913 |
if (!style()->clipRight().isAuto()) |
|
914 |
clipWidth -= width() - style()->clipRight().calcValue(width()); |
|
915 |
||
916 |
if (!style()->clipTop().isAuto()) { |
|
917 |
int c = style()->clipTop().calcValue(height()); |
|
918 |
clipY += c; |
|
919 |
clipHeight -= c; |
|
920 |
} |
|
921 |
||
922 |
if (!style()->clipBottom().isAuto()) |
|
923 |
clipHeight -= height() - style()->clipBottom().calcValue(height()); |
|
924 |
||
925 |
return IntRect(clipX, clipY, clipWidth, clipHeight); |
|
926 |
} |
|
927 |
||
928 |
int RenderBox::containingBlockWidthForContent() const |
|
929 |
{ |
|
930 |
RenderBlock* cb = containingBlock(); |
|
931 |
if (shrinkToAvoidFloats()) |
|
932 |
return cb->lineWidth(y(), false); |
|
933 |
return cb->availableWidth(); |
|
934 |
} |
|
935 |
||
936 |
void RenderBox::mapLocalToContainer(RenderBoxModelObject* repaintContainer, bool fixed, bool useTransforms, TransformState& transformState) const |
|
937 |
{ |
|
938 |
if (repaintContainer == this) |
|
939 |
return; |
|
940 |
||
941 |
if (RenderView* v = view()) { |
|
942 |
if (v->layoutStateEnabled() && !repaintContainer) { |
|
943 |
LayoutState* layoutState = v->layoutState(); |
|
944 |
IntSize offset = layoutState->m_offset; |
|
945 |
offset.expand(x(), y()); |
|
946 |
if (style()->position() == RelativePosition && layer()) |
|
947 |
offset += layer()->relativePositionOffset(); |
|
948 |
transformState.move(offset); |
|
949 |
return; |
|
950 |
} |
|
951 |
} |
|
952 |
||
953 |
if (style()->position() == FixedPosition) |
|
954 |
fixed = true; |
|
955 |
||
956 |
bool containerSkipped; |
|
957 |
RenderObject* o = container(repaintContainer, &containerSkipped); |
|
958 |
if (!o) |
|
959 |
return; |
|
960 |
||
961 |
bool hasTransform = hasLayer() && layer()->transform(); |
|
962 |
if (hasTransform) |
|
963 |
fixed = false; // Elements with transforms act as a containing block for fixed position descendants |
|
964 |
||
965 |
IntSize containerOffset = offsetFromContainer(o); |
|
966 |
||
967 |
bool preserve3D = useTransforms && (o->style()->preserves3D() || style()->preserves3D()); |
|
968 |
if (useTransforms && shouldUseTransformFromContainer(o)) { |
|
969 |
TransformationMatrix t; |
|
970 |
getTransformFromContainer(o, containerOffset, t); |
|
971 |
transformState.applyTransform(t, preserve3D ? TransformState::AccumulateTransform : TransformState::FlattenTransform); |
|
972 |
} else |
|
973 |
transformState.move(containerOffset.width(), containerOffset.height(), preserve3D ? TransformState::AccumulateTransform : TransformState::FlattenTransform); |
|
974 |
||
975 |
if (containerSkipped) { |
|
976 |
// There can't be a transform between repaintContainer and o, because transforms create containers, so it should be safe |
|
977 |
// to just subtract the delta between the repaintContainer and o. |
|
978 |
IntSize containerOffset = repaintContainer->offsetFromAncestorContainer(o); |
|
979 |
transformState.move(-containerOffset.width(), -containerOffset.height(), preserve3D ? TransformState::AccumulateTransform : TransformState::FlattenTransform); |
|
980 |
return; |
|
981 |
} |
|
982 |
||
983 |
o->mapLocalToContainer(repaintContainer, fixed, useTransforms, transformState); |
|
984 |
} |
|
985 |
||
986 |
void RenderBox::mapAbsoluteToLocalPoint(bool fixed, bool useTransforms, TransformState& transformState) const |
|
987 |
{ |
|
988 |
// We don't expect absoluteToLocal() to be called during layout (yet) |
|
989 |
ASSERT(!view() || !view()->layoutStateEnabled()); |
|
990 |
||
991 |
if (style()->position() == FixedPosition) |
|
992 |
fixed = true; |
|
993 |
||
994 |
bool hasTransform = hasLayer() && layer()->transform(); |
|
995 |
if (hasTransform) |
|
996 |
fixed = false; // Elements with transforms act as a containing block for fixed position descendants |
|
997 |
||
998 |
RenderObject* o = container(); |
|
999 |
if (!o) |
|
1000 |
return; |
|
1001 |
||
1002 |
o->mapAbsoluteToLocalPoint(fixed, useTransforms, transformState); |
|
1003 |
||
1004 |
IntSize containerOffset = offsetFromContainer(o); |
|
1005 |
||
1006 |
bool preserve3D = useTransforms && (o->style()->preserves3D() || style()->preserves3D()); |
|
1007 |
if (useTransforms && shouldUseTransformFromContainer(o)) { |
|
1008 |
TransformationMatrix t; |
|
1009 |
getTransformFromContainer(o, containerOffset, t); |
|
1010 |
transformState.applyTransform(t, preserve3D ? TransformState::AccumulateTransform : TransformState::FlattenTransform); |
|
1011 |
} else |
|
1012 |
transformState.move(-containerOffset.width(), -containerOffset.height(), preserve3D ? TransformState::AccumulateTransform : TransformState::FlattenTransform); |
|
1013 |
} |
|
1014 |
||
1015 |
IntSize RenderBox::offsetFromContainer(RenderObject* o) const |
|
1016 |
{ |
|
1017 |
ASSERT(o == container()); |
|
1018 |
||
1019 |
IntSize offset; |
|
1020 |
if (isRelPositioned()) |
|
1021 |
offset += relativePositionOffset(); |
|
1022 |
||
1023 |
if (!isInline() || isReplaced()) { |
|
1024 |
RenderBlock* cb; |
|
1025 |
if (o->isBlockFlow() && style()->position() != AbsolutePosition && style()->position() != FixedPosition |
|
1026 |
&& (cb = toRenderBlock(o))->hasColumns()) { |
|
1027 |
IntRect rect(x(), y(), 1, 1); |
|
1028 |
cb->adjustRectForColumns(rect); |
|
1029 |
offset.expand(rect.x(), rect.y()); |
|
1030 |
} else |
|
1031 |
offset.expand(x(), y()); |
|
1032 |
} |
|
1033 |
||
1034 |
if (o->hasOverflowClip()) |
|
1035 |
offset -= toRenderBox(o)->layer()->scrolledContentOffset(); |
|
1036 |
||
1037 |
if (style()->position() == AbsolutePosition && o->isRelPositioned() && o->isRenderInline()) |
|
1038 |
offset += toRenderInline(o)->relativePositionedInlineOffset(this); |
|
1039 |
||
1040 |
return offset; |
|
1041 |
} |
|
1042 |
||
1043 |
InlineBox* RenderBox::createInlineBox() |
|
1044 |
{ |
|
1045 |
return new (renderArena()) InlineBox(this); |
|
1046 |
} |
|
1047 |
||
1048 |
void RenderBox::dirtyLineBoxes(bool fullLayout) |
|
1049 |
{ |
|
1050 |
if (m_inlineBoxWrapper) { |
|
1051 |
if (fullLayout) { |
|
1052 |
m_inlineBoxWrapper->destroy(renderArena()); |
|
1053 |
m_inlineBoxWrapper = 0; |
|
1054 |
} else |
|
1055 |
m_inlineBoxWrapper->dirtyLineBoxes(); |
|
1056 |
} |
|
1057 |
} |
|
1058 |
||
1059 |
void RenderBox::positionLineBox(InlineBox* box) |
|
1060 |
{ |
|
1061 |
if (isPositioned()) { |
|
1062 |
// Cache the x position only if we were an INLINE type originally. |
|
1063 |
bool wasInline = style()->isOriginalDisplayInlineType(); |
|
1064 |
if (wasInline && style()->hasStaticX()) { |
|
1065 |
// The value is cached in the xPos of the box. We only need this value if |
|
1066 |
// our object was inline originally, since otherwise it would have ended up underneath |
|
1067 |
// the inlines. |
|
1068 |
layer()->setStaticX(box->x()); |
|
1069 |
setChildNeedsLayout(true, false); // Just go ahead and mark the positioned object as needing layout, so it will update its position properly. |
|
1070 |
} else if (!wasInline && style()->hasStaticY()) { |
|
1071 |
// Our object was a block originally, so we make our normal flow position be |
|
1072 |
// just below the line box (as though all the inlines that came before us got |
|
1073 |
// wrapped in an anonymous block, which is what would have happened had we been |
|
1074 |
// in flow). This value was cached in the y() of the box. |
|
1075 |
layer()->setStaticY(box->y()); |
|
1076 |
setChildNeedsLayout(true, false); // Just go ahead and mark the positioned object as needing layout, so it will update its position properly. |
|
1077 |
} |
|
1078 |
||
1079 |
// Nuke the box. |
|
1080 |
box->remove(); |
|
1081 |
box->destroy(renderArena()); |
|
1082 |
} else if (isReplaced()) { |
|
1083 |
setLocation(box->x(), box->y()); |
|
1084 |
m_inlineBoxWrapper = box; |
|
1085 |
} |
|
1086 |
} |
|
1087 |
||
1088 |
void RenderBox::deleteLineBoxWrapper() |
|
1089 |
{ |
|
1090 |
if (m_inlineBoxWrapper) { |
|
1091 |
if (!documentBeingDestroyed()) |
|
1092 |
m_inlineBoxWrapper->remove(); |
|
1093 |
m_inlineBoxWrapper->destroy(renderArena()); |
|
1094 |
m_inlineBoxWrapper = 0; |
|
1095 |
} |
|
1096 |
} |
|
1097 |
||
1098 |
IntRect RenderBox::clippedOverflowRectForRepaint(RenderBoxModelObject* repaintContainer) |
|
1099 |
{ |
|
1100 |
if (style()->visibility() != VISIBLE && !enclosingLayer()->hasVisibleContent()) |
|
1101 |
return IntRect(); |
|
1102 |
||
1103 |
IntRect r = visibleOverflowRect(); |
|
1104 |
||
1105 |
RenderView* v = view(); |
|
1106 |
if (v) { |
|
1107 |
// FIXME: layoutDelta needs to be applied in parts before/after transforms and |
|
1108 |
// repaint containers. https://bugs.webkit.org/show_bug.cgi?id=23308 |
|
1109 |
r.move(v->layoutDelta()); |
|
1110 |
} |
|
1111 |
||
1112 |
if (style()) { |
|
1113 |
if (style()->hasAppearance()) |
|
1114 |
// The theme may wish to inflate the rect used when repainting. |
|
1115 |
theme()->adjustRepaintRect(this, r); |
|
1116 |
||
1117 |
// We have to use maximalOutlineSize() because a child might have an outline |
|
1118 |
// that projects outside of our overflowRect. |
|
1119 |
if (v) { |
|
1120 |
ASSERT(style()->outlineSize() <= v->maximalOutlineSize()); |
|
1121 |
r.inflate(v->maximalOutlineSize()); |
|
1122 |
} |
|
1123 |
} |
|
1124 |
computeRectForRepaint(repaintContainer, r); |
|
1125 |
return r; |
|
1126 |
} |
|
1127 |
||
1128 |
void RenderBox::computeRectForRepaint(RenderBoxModelObject* repaintContainer, IntRect& rect, bool fixed) |
|
1129 |
{ |
|
1130 |
if (RenderView* v = view()) { |
|
1131 |
// LayoutState is only valid for root-relative repainting |
|
1132 |
if (v->layoutStateEnabled() && !repaintContainer) { |
|
1133 |
LayoutState* layoutState = v->layoutState(); |
|
1134 |
||
1135 |
if (layer() && layer()->transform()) |
|
1136 |
rect = layer()->transform()->mapRect(rect); |
|
1137 |
||
1138 |
if (style()->position() == RelativePosition && layer()) |
|
1139 |
rect.move(layer()->relativePositionOffset()); |
|
1140 |
||
1141 |
rect.move(x(), y()); |
|
1142 |
rect.move(layoutState->m_offset); |
|
1143 |
if (layoutState->m_clipped) |
|
1144 |
rect.intersect(layoutState->m_clipRect); |
|
1145 |
return; |
|
1146 |
} |
|
1147 |
} |
|
1148 |
||
1149 |
if (hasReflection()) |
|
1150 |
rect.unite(reflectedRect(rect)); |
|
1151 |
||
1152 |
if (repaintContainer == this) |
|
1153 |
return; |
|
1154 |
||
1155 |
bool containerSkipped; |
|
1156 |
RenderObject* o = container(repaintContainer, &containerSkipped); |
|
1157 |
if (!o) |
|
1158 |
return; |
|
1159 |
||
1160 |
IntPoint topLeft = rect.location(); |
|
1161 |
topLeft.move(x(), y()); |
|
1162 |
||
1163 |
if (style()->position() == FixedPosition) |
|
1164 |
fixed = true; |
|
1165 |
||
1166 |
if (o->isBlockFlow() && style()->position() != AbsolutePosition && style()->position() != FixedPosition) { |
|
1167 |
RenderBlock* cb = toRenderBlock(o); |
|
1168 |
if (cb->hasColumns()) { |
|
1169 |
IntRect repaintRect(topLeft, rect.size()); |
|
1170 |
cb->adjustRectForColumns(repaintRect); |
|
1171 |
topLeft = repaintRect.location(); |
|
1172 |
rect = repaintRect; |
|
1173 |
} |
|
1174 |
} |
|
1175 |
||
1176 |
// We are now in our parent container's coordinate space. Apply our transform to obtain a bounding box |
|
1177 |
// in the parent's coordinate space that encloses us. |
|
1178 |
if (layer() && layer()->transform()) { |
|
1179 |
fixed = false; |
|
1180 |
rect = layer()->transform()->mapRect(rect); |
|
1181 |
// FIXME: this clobbers topLeft adjustment done for multicol above |
|
1182 |
topLeft = rect.location(); |
|
1183 |
topLeft.move(x(), y()); |
|
1184 |
} |
|
1185 |
||
1186 |
if (style()->position() == AbsolutePosition && o->isRelPositioned() && o->isRenderInline()) |
|
1187 |
topLeft += toRenderInline(o)->relativePositionedInlineOffset(this); |
|
1188 |
else if (style()->position() == RelativePosition && layer()) { |
|
1189 |
// Apply the relative position offset when invalidating a rectangle. The layer |
|
1190 |
// is translated, but the render box isn't, so we need to do this to get the |
|
1191 |
// right dirty rect. Since this is called from RenderObject::setStyle, the relative position |
|
1192 |
// flag on the RenderObject has been cleared, so use the one on the style(). |
|
1193 |
topLeft += layer()->relativePositionOffset(); |
|
1194 |
} |
|
1195 |
||
1196 |
// FIXME: We ignore the lightweight clipping rect that controls use, since if |o| is in mid-layout, |
|
1197 |
// its controlClipRect will be wrong. For overflow clip we use the values cached by the layer. |
|
1198 |
if (o->hasOverflowClip()) { |
|
1199 |
RenderBox* containerBox = toRenderBox(o); |
|
1200 |
||
1201 |
// o->height() is inaccurate if we're in the middle of a layout of |o|, so use the |
|
1202 |
// layer's size instead. Even if the layer's size is wrong, the layer itself will repaint |
|
1203 |
// anyway if its size does change. |
|
1204 |
topLeft -= containerBox->layer()->scrolledContentOffset(); // For overflow:auto/scroll/hidden. |
|
1205 |
||
1206 |
IntRect repaintRect(topLeft, rect.size()); |
|
1207 |
IntRect boxRect(0, 0, containerBox->layer()->width(), containerBox->layer()->height()); |
|
1208 |
rect = intersection(repaintRect, boxRect); |
|
1209 |
if (rect.isEmpty()) |
|
1210 |
return; |
|
1211 |
} else |
|
1212 |
rect.setLocation(topLeft); |
|
1213 |
||
1214 |
if (containerSkipped) { |
|
1215 |
// If the repaintContainer is below o, then we need to map the rect into repaintContainer's coordinates. |
|
1216 |
IntSize containerOffset = repaintContainer->offsetFromAncestorContainer(o); |
|
1217 |
rect.move(-containerOffset); |
|
1218 |
return; |
|
1219 |
} |
|
1220 |
||
1221 |
o->computeRectForRepaint(repaintContainer, rect, fixed); |
|
1222 |
} |
|
1223 |
||
1224 |
void RenderBox::repaintDuringLayoutIfMoved(const IntRect& rect) |
|
1225 |
{ |
|
1226 |
int newX = x(); |
|
1227 |
int newY = y(); |
|
1228 |
int newWidth = width(); |
|
1229 |
int newHeight = height(); |
|
1230 |
if (rect.x() != newX || rect.y() != newY) { |
|
1231 |
// The child moved. Invalidate the object's old and new positions. We have to do this |
|
1232 |
// since the object may not have gotten a layout. |
|
1233 |
m_frameRect = rect; |
|
1234 |
repaint(); |
|
1235 |
repaintOverhangingFloats(true); |
|
1236 |
m_frameRect = IntRect(newX, newY, newWidth, newHeight); |
|
1237 |
repaint(); |
|
1238 |
repaintOverhangingFloats(true); |
|
1239 |
} |
|
1240 |
} |
|
1241 |
||
1242 |
void RenderBox::calcWidth() |
|
1243 |
{ |
|
1244 |
if (isPositioned()) { |
|
1245 |
calcAbsoluteHorizontal(); |
|
1246 |
return; |
|
1247 |
} |
|
1248 |
||
1249 |
// If layout is limited to a subtree, the subtree root's width does not change. |
|
1250 |
if (node() && view()->frameView() && view()->frameView()->layoutRoot(true) == this) |
|
1251 |
return; |
|
1252 |
||
1253 |
// The parent box is flexing us, so it has increased or decreased our |
|
1254 |
// width. Use the width from the style context. |
|
1255 |
if (hasOverrideSize() && parent()->style()->boxOrient() == HORIZONTAL |
|
1256 |
&& parent()->isFlexibleBox() && parent()->isFlexingChildren()) { |
|
1257 |
setWidth(overrideSize()); |
|
1258 |
return; |
|
1259 |
} |
|
1260 |
||
1261 |
bool inVerticalBox = parent()->isFlexibleBox() && (parent()->style()->boxOrient() == VERTICAL); |
|
1262 |
bool stretching = (parent()->style()->boxAlign() == BSTRETCH); |
|
1263 |
bool treatAsReplaced = shouldCalculateSizeAsReplaced() && (!inVerticalBox || !stretching); |
|
1264 |
||
1265 |
Length w = (treatAsReplaced) ? Length(calcReplacedWidth(), Fixed) : style()->width(); |
|
1266 |
||
1267 |
RenderBlock* cb = containingBlock(); |
|
1268 |
int containerWidth = max(0, containingBlockWidthForContent()); |
|
1269 |
||
1270 |
Length marginLeft = style()->marginLeft(); |
|
1271 |
Length marginRight = style()->marginRight(); |
|
1272 |
||
1273 |
if (isInline() && !isInlineBlockOrInlineTable()) { |
|
1274 |
// just calculate margins |
|
1275 |
m_marginLeft = marginLeft.calcMinValue(containerWidth); |
|
1276 |
m_marginRight = marginRight.calcMinValue(containerWidth); |
|
1277 |
if (treatAsReplaced) |
|
1278 |
setWidth(max(w.value() + borderLeft() + borderRight() + paddingLeft() + paddingRight(), minPrefWidth())); |
|
1279 |
||
1280 |
return; |
|
1281 |
} |
|
1282 |
||
1283 |
// Width calculations |
|
1284 |
if (treatAsReplaced) |
|
1285 |
setWidth(w.value() + borderLeft() + borderRight() + paddingLeft() + paddingRight()); |
|
1286 |
else { |
|
1287 |
// Calculate Width |
|
1288 |
setWidth(calcWidthUsing(Width, containerWidth)); |
|
1289 |
||
1290 |
// Calculate MaxWidth |
|
1291 |
if (!style()->maxWidth().isUndefined()) { |
|
1292 |
int maxW = calcWidthUsing(MaxWidth, containerWidth); |
|
1293 |
if (width() > maxW) { |
|
1294 |
setWidth(maxW); |
|
1295 |
w = style()->maxWidth(); |
|
1296 |
} |
|
1297 |
} |
|
1298 |
||
1299 |
// Calculate MinWidth |
|
1300 |
int minW = calcWidthUsing(MinWidth, containerWidth); |
|
1301 |
if (width() < minW) { |
|
1302 |
setWidth(minW); |
|
1303 |
w = style()->minWidth(); |
|
1304 |
} |
|
1305 |
} |
|
1306 |
||
1307 |
if (stretchesToMinIntrinsicWidth()) { |
|
1308 |
setWidth(max(width(), minPrefWidth())); |
|
1309 |
w = Length(width(), Fixed); |
|
1310 |
} |
|
1311 |
||
1312 |
// Margin calculations |
|
1313 |
if (w.isAuto()) { |
|
1314 |
m_marginLeft = marginLeft.calcMinValue(containerWidth); |
|
1315 |
m_marginRight = marginRight.calcMinValue(containerWidth); |
|
1316 |
} else { |
|
1317 |
m_marginLeft = 0; |
|
1318 |
m_marginRight = 0; |
|
1319 |
calcHorizontalMargins(marginLeft, marginRight, containerWidth); |
|
1320 |
} |
|
1321 |
||
1322 |
if (containerWidth && containerWidth != (width() + m_marginLeft + m_marginRight) |
|
1323 |
&& !isFloating() && !isInline() && !cb->isFlexibleBox()) { |
|
1324 |
if (cb->style()->direction() == LTR) |
|
1325 |
m_marginRight = containerWidth - width() - m_marginLeft; |
|
1326 |
else |
|
1327 |
m_marginLeft = containerWidth - width() - m_marginRight; |
|
1328 |
} |
|
1329 |
} |
|
1330 |
||
1331 |
int RenderBox::calcWidthUsing(WidthType widthType, int cw) |
|
1332 |
{ |
|
1333 |
int widthResult = width(); |
|
1334 |
Length w; |
|
1335 |
if (widthType == Width) |
|
1336 |
w = style()->width(); |
|
1337 |
else if (widthType == MinWidth) |
|
1338 |
w = style()->minWidth(); |
|
1339 |
else |
|
1340 |
w = style()->maxWidth(); |
|
1341 |
||
1342 |
if (w.isIntrinsicOrAuto()) { |
|
1343 |
int marginLeft = style()->marginLeft().calcMinValue(cw); |
|
1344 |
int marginRight = style()->marginRight().calcMinValue(cw); |
|
1345 |
if (cw) |
|
1346 |
widthResult = cw - marginLeft - marginRight; |
|
1347 |
||
1348 |
if (sizesToIntrinsicWidth(widthType)) { |
|
1349 |
widthResult = max(widthResult, minPrefWidth()); |
|
1350 |
widthResult = min(widthResult, maxPrefWidth()); |
|
1351 |
} |
|
1352 |
} else |
|
1353 |
widthResult = calcBorderBoxWidth(w.calcValue(cw)); |
|
1354 |
||
1355 |
return widthResult; |
|
1356 |
} |
|
1357 |
||
1358 |
bool RenderBox::sizesToIntrinsicWidth(WidthType widthType) const |
|
1359 |
{ |
|
1360 |
// Marquees in WinIE are like a mixture of blocks and inline-blocks. They size as though they're blocks, |
|
1361 |
// but they allow text to sit on the same line as the marquee. |
|
1362 |
if (isFloating() || (isInlineBlockOrInlineTable() && !isHTMLMarquee())) |
|
1363 |
return true; |
|
1364 |
||
1365 |
// This code may look a bit strange. Basically width:intrinsic should clamp the size when testing both |
|
1366 |
// min-width and width. max-width is only clamped if it is also intrinsic. |
|
1367 |
Length width = (widthType == MaxWidth) ? style()->maxWidth() : style()->width(); |
|
1368 |
if (width.type() == Intrinsic) |
|
1369 |
return true; |
|
1370 |
||
1371 |
// Children of a horizontal marquee do not fill the container by default. |
|
1372 |
// FIXME: Need to deal with MAUTO value properly. It could be vertical. |
|
1373 |
if (parent()->style()->overflowX() == OMARQUEE) { |
|
1374 |
EMarqueeDirection dir = parent()->style()->marqueeDirection(); |
|
1375 |
if (dir == MAUTO || dir == MFORWARD || dir == MBACKWARD || dir == MLEFT || dir == MRIGHT) |
|
1376 |
return true; |
|
1377 |
} |
|
1378 |
||
1379 |
// Flexible horizontal boxes lay out children at their intrinsic widths. Also vertical boxes |
|
1380 |
// that don't stretch their kids lay out their children at their intrinsic widths. |
|
1381 |
if (parent()->isFlexibleBox() |
|
1382 |
&& (parent()->style()->boxOrient() == HORIZONTAL || parent()->style()->boxAlign() != BSTRETCH)) |
|
1383 |
return true; |
|
1384 |
||
1385 |
return false; |
|
1386 |
} |
|
1387 |
||
1388 |
void RenderBox::calcHorizontalMargins(const Length& marginLeft, const Length& marginRight, int containerWidth) |
|
1389 |
{ |
|
1390 |
if (isFloating() || isInline()) { |
|
1391 |
// Inline blocks/tables and floats don't have their margins increased. |
|
1392 |
m_marginLeft = marginLeft.calcMinValue(containerWidth); |
|
1393 |
m_marginRight = marginRight.calcMinValue(containerWidth); |
|
1394 |
return; |
|
1395 |
} |
|
1396 |
||
1397 |
if ((marginLeft.isAuto() && marginRight.isAuto() && width() < containerWidth) |
|
1398 |
|| (!marginLeft.isAuto() && !marginRight.isAuto() && containingBlock()->style()->textAlign() == WEBKIT_CENTER)) { |
|
1399 |
m_marginLeft = max(0, (containerWidth - width()) / 2); |
|
1400 |
m_marginRight = containerWidth - width() - m_marginLeft; |
|
1401 |
} else if ((marginRight.isAuto() && width() < containerWidth) |
|
1402 |
|| (!marginLeft.isAuto() && containingBlock()->style()->direction() == RTL && containingBlock()->style()->textAlign() == WEBKIT_LEFT)) { |
|
1403 |
m_marginLeft = marginLeft.calcValue(containerWidth); |
|
1404 |
m_marginRight = containerWidth - width() - m_marginLeft; |
|
1405 |
} else if ((marginLeft.isAuto() && width() < containerWidth) |
|
1406 |
|| (!marginRight.isAuto() && containingBlock()->style()->direction() == LTR && containingBlock()->style()->textAlign() == WEBKIT_RIGHT)) { |
|
1407 |
m_marginRight = marginRight.calcValue(containerWidth); |
|
1408 |
m_marginLeft = containerWidth - width() - m_marginRight; |
|
1409 |
} else { |
|
1410 |
// This makes auto margins 0 if we failed a width() < containerWidth test above (css2.1, 10.3.3). |
|
1411 |
m_marginLeft = marginLeft.calcMinValue(containerWidth); |
|
1412 |
m_marginRight = marginRight.calcMinValue(containerWidth); |
|
1413 |
} |
|
1414 |
} |
|
1415 |
||
1416 |
void RenderBox::calcHeight() |
|
1417 |
{ |
|
1418 |
// Cell height is managed by the table and inline non-replaced elements do not support a height property. |
|
1419 |
if (isTableCell() || (isInline() && !isReplaced())) |
|
1420 |
return; |
|
1421 |
||
1422 |
Length h; |
|
1423 |
if (isPositioned()) |
|
1424 |
calcAbsoluteVertical(); |
|
1425 |
else { |
|
1426 |
calcVerticalMargins(); |
|
1427 |
||
1428 |
// For tables, calculate margins only. |
|
1429 |
if (isTable()) |
|
1430 |
return; |
|
1431 |
||
1432 |
bool inHorizontalBox = parent()->isFlexibleBox() && parent()->style()->boxOrient() == HORIZONTAL; |
|
1433 |
bool stretching = parent()->style()->boxAlign() == BSTRETCH; |
|
1434 |
bool treatAsReplaced = shouldCalculateSizeAsReplaced() && (!inHorizontalBox || !stretching); |
|
1435 |
bool checkMinMaxHeight = false; |
|
1436 |
||
1437 |
// The parent box is flexing us, so it has increased or decreased our height. We have to |
|
1438 |
// grab our cached flexible height. |
|
1439 |
if (hasOverrideSize() && parent()->isFlexibleBox() && parent()->style()->boxOrient() == VERTICAL |
|
1440 |
&& parent()->isFlexingChildren()) |
|
1441 |
h = Length(overrideSize() - borderTop() - borderBottom() - paddingTop() - paddingBottom(), Fixed); |
|
1442 |
else if (treatAsReplaced) |
|
1443 |
h = Length(calcReplacedHeight(), Fixed); |
|
1444 |
else { |
|
1445 |
h = style()->height(); |
|
1446 |
checkMinMaxHeight = true; |
|
1447 |
} |
|
1448 |
||
1449 |
// Block children of horizontal flexible boxes fill the height of the box. |
|
1450 |
if (h.isAuto() && parent()->isFlexibleBox() && parent()->style()->boxOrient() == HORIZONTAL |
|
1451 |
&& parent()->isStretchingChildren()) { |
|
1452 |
h = Length(parentBox()->contentHeight() - marginTop() - marginBottom() - |
|
1453 |
borderTop() - paddingTop() - borderBottom() - paddingBottom(), Fixed); |
|
1454 |
checkMinMaxHeight = false; |
|
1455 |
} |
|
1456 |
||
1457 |
int heightResult; |
|
1458 |
if (checkMinMaxHeight) { |
|
1459 |
heightResult = calcHeightUsing(style()->height()); |
|
1460 |
if (heightResult == -1) |
|
1461 |
heightResult = height(); |
|
1462 |
int minH = calcHeightUsing(style()->minHeight()); // Leave as -1 if unset. |
|
1463 |
int maxH = style()->maxHeight().isUndefined() ? heightResult : calcHeightUsing(style()->maxHeight()); |
|
1464 |
if (maxH == -1) |
|
1465 |
maxH = heightResult; |
|
1466 |
heightResult = min(maxH, heightResult); |
|
1467 |
heightResult = max(minH, heightResult); |
|
1468 |
} else { |
|
1469 |
// The only times we don't check min/max height are when a fixed length has |
|
1470 |
// been given as an override. Just use that. The value has already been adjusted |
|
1471 |
// for box-sizing. |
|
1472 |
heightResult = h.value() + borderTop() + borderBottom() + paddingTop() + paddingBottom(); |
|
1473 |
} |
|
1474 |
||
1475 |
setHeight(heightResult); |
|
1476 |
} |
|
1477 |
||
1478 |
// WinIE quirk: The <html> block always fills the entire canvas in quirks mode. The <body> always fills the |
|
1479 |
// <html> block in quirks mode. Only apply this quirk if the block is normal flow and no height |
|
1480 |
// is specified. When we're printing, we also need this quirk if the body or root has a percentage |
|
1481 |
// height since we don't set a height in RenderView when we're printing. So without this quirk, the |
|
1482 |
// height has nothing to be a percentage of, and it ends up being 0. That is bad. |
|
1483 |
bool printingNeedsBaseHeight = document()->printing() && h.isPercent() |
|
1484 |
&& (isRoot() || isBody() && document()->documentElement()->renderer()->style()->height().isPercent()); |
|
1485 |
if (stretchesToViewHeight() || printingNeedsBaseHeight) { |
|
1486 |
int margins = collapsedMarginTop() + collapsedMarginBottom(); |
|
1487 |
int visHeight = document()->printing() ? view()->frameView()->visibleHeight() : view()->viewHeight(); |
|
1488 |
if (isRoot()) |
|
1489 |
setHeight(max(height(), visHeight - margins)); |
|
1490 |
else { |
|
1491 |
int marginsBordersPadding = margins + parentBox()->marginTop() + parentBox()->marginBottom() |
|
1492 |
+ parentBox()->borderTop() + parentBox()->borderBottom() |
|
1493 |
+ parentBox()->paddingTop() + parentBox()->paddingBottom(); |
|
1494 |
setHeight(max(height(), visHeight - marginsBordersPadding)); |
|
1495 |
} |
|
1496 |
} |
|
1497 |
} |
|
1498 |
||
1499 |
int RenderBox::calcHeightUsing(const Length& h) |
|
1500 |
{ |
|
1501 |
int height = -1; |
|
1502 |
if (!h.isAuto()) { |
|
1503 |
if (h.isFixed()) |
|
1504 |
height = h.value(); |
|
1505 |
else if (h.isPercent()) |
|
1506 |
height = calcPercentageHeight(h); |
|
1507 |
if (height != -1) { |
|
1508 |
height = calcBorderBoxHeight(height); |
|
1509 |
return height; |
|
1510 |
} |
|
1511 |
} |
|
1512 |
return height; |
|
1513 |
} |
|
1514 |
||
1515 |
int RenderBox::calcPercentageHeight(const Length& height) |
|
1516 |
{ |
|
1517 |
int result = -1; |
|
1518 |
bool skippedAutoHeightContainingBlock = false; |
|
1519 |
RenderBlock* cb = containingBlock(); |
|
1520 |
if (style()->htmlHacks()) { |
|
1521 |
// In quirks mode, blocks with auto height are skipped, and we keep looking for an enclosing |
|
1522 |
// block that may have a specified height and then use it. In strict mode, this violates the |
|
1523 |
// specification, which states that percentage heights just revert to auto if the containing |
|
1524 |
// block has an auto height. |
|
1525 |
while (!cb->isRenderView() && !cb->isBody() && !cb->isTableCell() && !cb->isPositioned() && cb->style()->height().isAuto()) { |
|
1526 |
skippedAutoHeightContainingBlock = true; |
|
1527 |
cb = cb->containingBlock(); |
|
1528 |
cb->addPercentHeightDescendant(this); |
|
1529 |
} |
|
1530 |
} |
|
1531 |
||
1532 |
// A positioned element that specified both top/bottom or that specifies height should be treated as though it has a height |
|
1533 |
// explicitly specified that can be used for any percentage computations. |
|
1534 |
bool isPositionedWithSpecifiedHeight = cb->isPositioned() && (!cb->style()->height().isAuto() || (!cb->style()->top().isAuto() && !cb->style()->bottom().isAuto())); |
|
1535 |
||
1536 |
bool includeBorderPadding = isTable(); |
|
1537 |
||
1538 |
// Table cells violate what the CSS spec says to do with heights. Basically we |
|
1539 |
// don't care if the cell specified a height or not. We just always make ourselves |
|
1540 |
// be a percentage of the cell's current content height. |
|
1541 |
if (cb->isTableCell()) { |
|
1542 |
if (!skippedAutoHeightContainingBlock) { |
|
1543 |
result = cb->overrideSize(); |
|
1544 |
if (result == -1) { |
|
1545 |
// Normally we would let the cell size intrinsically, but scrolling overflow has to be |
|
1546 |
// treated differently, since WinIE lets scrolled overflow regions shrink as needed. |
|
1547 |
// While we can't get all cases right, we can at least detect when the cell has a specified |
|
1548 |
// height or when the table has a specified height. In these cases we want to initially have |
|
1549 |
// no size and allow the flexing of the table or the cell to its specified height to cause us |
|
1550 |
// to grow to fill the space. This could end up being wrong in some cases, but it is |
|
1551 |
// preferable to the alternative (sizing intrinsically and making the row end up too big). |
|
1552 |
RenderTableCell* cell = toRenderTableCell(cb); |
|
1553 |
if (scrollsOverflowY() && (!cell->style()->height().isAuto() || !cell->table()->style()->height().isAuto())) |
|
1554 |
return 0; |
|
1555 |
return -1; |
|
1556 |
} |
|
1557 |
includeBorderPadding = true; |
|
1558 |
} |
|
1559 |
} |
|
1560 |
// Otherwise we only use our percentage height if our containing block had a specified |
|
1561 |
// height. |
|
1562 |
else if (cb->style()->height().isFixed()) |
|
1563 |
result = cb->calcContentBoxHeight(cb->style()->height().value()); |
|
1564 |
else if (cb->style()->height().isPercent() && !isPositionedWithSpecifiedHeight) { |
|
1565 |
// We need to recur and compute the percentage height for our containing block. |
|
1566 |
result = cb->calcPercentageHeight(cb->style()->height()); |
|
1567 |
if (result != -1) |
|
1568 |
result = cb->calcContentBoxHeight(result); |
|
1569 |
} else if (cb->isRenderView() || (cb->isBody() && style()->htmlHacks()) || isPositionedWithSpecifiedHeight) { |
|
1570 |
// Don't allow this to affect the block' height() member variable, since this |
|
1571 |
// can get called while the block is still laying out its kids. |
|
1572 |
int oldHeight = cb->height(); |
|
1573 |
cb->calcHeight(); |
|
1574 |
result = cb->contentHeight(); |
|
1575 |
cb->setHeight(oldHeight); |
|
1576 |
} else if (cb->isRoot() && isPositioned()) |
|
1577 |
// Match the positioned objects behavior, which is that positioned objects will fill their viewport |
|
1578 |
// always. Note we could only hit this case by recurring into calcPercentageHeight on a positioned containing block. |
|
1579 |
result = cb->calcContentBoxHeight(cb->availableHeight()); |
|
1580 |
||
1581 |
if (result != -1) { |
|
1582 |
result = height.calcValue(result); |
|
1583 |
if (includeBorderPadding) { |
|
1584 |
// It is necessary to use the border-box to match WinIE's broken |
|
1585 |
// box model. This is essential for sizing inside |
|
1586 |
// table cells using percentage heights. |
|
1587 |
result -= (borderTop() + paddingTop() + borderBottom() + paddingBottom()); |
|
1588 |
result = max(0, result); |
|
1589 |
} |
|
1590 |
} |
|
1591 |
return result; |
|
1592 |
} |
|
1593 |
||
1594 |
int RenderBox::calcReplacedWidth(bool includeMaxWidth) const |
|
1595 |
{ |
|
1596 |
int width = calcReplacedWidthUsing(style()->width()); |
|
1597 |
int minW = calcReplacedWidthUsing(style()->minWidth()); |
|
1598 |
int maxW = !includeMaxWidth || style()->maxWidth().isUndefined() ? width : calcReplacedWidthUsing(style()->maxWidth()); |
|
1599 |
||
1600 |
return max(minW, min(width, maxW)); |
|
1601 |
} |
|
1602 |
||
1603 |
int RenderBox::calcReplacedWidthUsing(Length width) const |
|
1604 |
{ |
|
1605 |
switch (width.type()) { |
|
1606 |
case Fixed: |
|
1607 |
return calcContentBoxWidth(width.value()); |
|
1608 |
case Percent: { |
|
1609 |
const int cw = isPositioned() ? containingBlockWidthForPositioned(toRenderBoxModelObject(container())) : containingBlockWidthForContent(); |
|
1610 |
if (cw > 0) |
|
1611 |
return calcContentBoxWidth(width.calcMinValue(cw)); |
|
1612 |
} |
|
1613 |
// fall through |
|
1614 |
default: |
|
1615 |
return intrinsicSize().width(); |
|
1616 |
} |
|
1617 |
} |
|
1618 |
||
1619 |
int RenderBox::calcReplacedHeight() const |
|
1620 |
{ |
|
1621 |
int height = calcReplacedHeightUsing(style()->height()); |
|
1622 |
int minH = calcReplacedHeightUsing(style()->minHeight()); |
|
1623 |
int maxH = style()->maxHeight().isUndefined() ? height : calcReplacedHeightUsing(style()->maxHeight()); |
|
1624 |
||
1625 |
return max(minH, min(height, maxH)); |
|
1626 |
} |
|
1627 |
||
1628 |
int RenderBox::calcReplacedHeightUsing(Length height) const |
|
1629 |
{ |
|
1630 |
switch (height.type()) { |
|
1631 |
case Fixed: |
|
1632 |
return calcContentBoxHeight(height.value()); |
|
1633 |
case Percent: |
|
1634 |
{ |
|
1635 |
RenderObject* cb = isPositioned() ? container() : containingBlock(); |
|
1636 |
while (cb->isAnonymous()) { |
|
1637 |
cb = cb->containingBlock(); |
|
1638 |
toRenderBlock(cb)->addPercentHeightDescendant(const_cast<RenderBox*>(this)); |
|
1639 |
} |
|
1640 |
||
1641 |
if (cb->isPositioned() && cb->style()->height().isAuto() && !(cb->style()->top().isAuto() || cb->style()->bottom().isAuto())) { |
|
1642 |
ASSERT(cb->isRenderBlock()); |
|
1643 |
RenderBlock* block = toRenderBlock(cb); |
|
1644 |
int oldHeight = block->height(); |
|
1645 |
block->calcHeight(); |
|
1646 |
int newHeight = block->calcContentBoxHeight(block->contentHeight()); |
|
1647 |
block->setHeight(oldHeight); |
|
1648 |
return calcContentBoxHeight(height.calcValue(newHeight)); |
|
1649 |
} |
|
1650 |
||
1651 |
int availableHeight = isPositioned() ? containingBlockHeightForPositioned(toRenderBoxModelObject(cb)) : toRenderBox(cb)->availableHeight(); |
|
1652 |
||
1653 |
// It is necessary to use the border-box to match WinIE's broken |
|
1654 |
// box model. This is essential for sizing inside |
|
1655 |
// table cells using percentage heights. |
|
1656 |
if (cb->isTableCell() && (cb->style()->height().isAuto() || cb->style()->height().isPercent())) { |
|
1657 |
// Don't let table cells squeeze percent-height replaced elements |
|
1658 |
// <http://bugs.webkit.org/show_bug.cgi?id=15359> |
|
1659 |
availableHeight = max(availableHeight, intrinsicSize().height()); |
|
1660 |
return height.calcValue(availableHeight - (borderTop() + borderBottom() |
|
1661 |
+ paddingTop() + paddingBottom())); |
|
1662 |
} |
|
1663 |
||
1664 |
return calcContentBoxHeight(height.calcValue(availableHeight)); |
|
1665 |
} |
|
1666 |
default: |
|
1667 |
return intrinsicSize().height(); |
|
1668 |
} |
|
1669 |
} |
|
1670 |
||
1671 |
int RenderBox::availableHeight() const |
|
1672 |
{ |
|
1673 |
return availableHeightUsing(style()->height()); |
|
1674 |
} |
|
1675 |
||
1676 |
int RenderBox::availableHeightUsing(const Length& h) const |
|
1677 |
{ |
|
1678 |
if (h.isFixed()) |
|
1679 |
return calcContentBoxHeight(h.value()); |
|
1680 |
||
1681 |
if (isRenderView()) |
|
1682 |
return toRenderView(this)->frameView()->visibleHeight(); |
|
1683 |
||
1684 |
// We need to stop here, since we don't want to increase the height of the table |
|
1685 |
// artificially. We're going to rely on this cell getting expanded to some new |
|
1686 |
// height, and then when we lay out again we'll use the calculation below. |
|
1687 |
if (isTableCell() && (h.isAuto() || h.isPercent())) |
|
1688 |
return overrideSize() - (borderLeft() + borderRight() + paddingLeft() + paddingRight()); |
|
1689 |
||
1690 |
if (h.isPercent()) |
|
1691 |
return calcContentBoxHeight(h.calcValue(containingBlock()->availableHeight())); |
|
1692 |
||
1693 |
if (isRenderBlock() && isPositioned() && style()->height().isAuto() && !(style()->top().isAuto() || style()->bottom().isAuto())) { |
|
1694 |
RenderBlock* block = const_cast<RenderBlock*>(toRenderBlock(this)); |
|
1695 |
int oldHeight = block->height(); |
|
1696 |
block->calcHeight(); |
|
1697 |
int newHeight = block->calcContentBoxHeight(block->contentHeight()); |
|
1698 |
block->setHeight(oldHeight); |
|
1699 |
return calcContentBoxHeight(newHeight); |
|
1700 |
} |
|
1701 |
||
1702 |
return containingBlock()->availableHeight(); |
|
1703 |
} |
|
1704 |
||
1705 |
void RenderBox::calcVerticalMargins() |
|
1706 |
{ |
|
1707 |
if (isTableCell()) { |
|
1708 |
m_marginTop = 0; |
|
1709 |
m_marginBottom = 0; |
|
1710 |
return; |
|
1711 |
} |
|
1712 |
||
1713 |
// margins are calculated with respect to the _width_ of |
|
1714 |
// the containing block (8.3) |
|
1715 |
int cw = containingBlock()->contentWidth(); |
|
1716 |
||
1717 |
m_marginTop = style()->marginTop().calcMinValue(cw); |
|
1718 |
m_marginBottom = style()->marginBottom().calcMinValue(cw); |
|
1719 |
} |
|
1720 |
||
1721 |
int RenderBox::containingBlockWidthForPositioned(const RenderBoxModelObject* containingBlock) const |
|
1722 |
{ |
|
1723 |
if (containingBlock->isBox()) { |
|
1724 |
const RenderBox* containingBlockBox = toRenderBox(containingBlock); |
|
1725 |
return containingBlockBox->width() - containingBlockBox->borderLeft() - containingBlockBox->borderRight() - containingBlockBox->verticalScrollbarWidth(); |
|
1726 |
} |
|
1727 |
||
1728 |
ASSERT(containingBlock->isRenderInline() && containingBlock->isRelPositioned()); |
|
1729 |
||
1730 |
const RenderInline* flow = toRenderInline(containingBlock); |
|
1731 |
InlineFlowBox* first = flow->firstLineBox(); |
|
1732 |
InlineFlowBox* last = flow->lastLineBox(); |
|
1733 |
||
1734 |
// If the containing block is empty, return a width of 0. |
|
1735 |
if (!first || !last) |
|
1736 |
return 0; |
|
1737 |
||
1738 |
int fromLeft; |
|
1739 |
int fromRight; |
|
1740 |
if (containingBlock->style()->direction() == LTR) { |
|
1741 |
fromLeft = first->x() + first->borderLeft(); |
|
1742 |
fromRight = last->x() + last->width() - last->borderRight(); |
|
1743 |
} else { |
|
1744 |
fromRight = first->x() + first->width() - first->borderRight(); |
|
1745 |
fromLeft = last->x() + last->borderLeft(); |
|
1746 |
} |
|
1747 |
||
1748 |
return max(0, (fromRight - fromLeft)); |
|
1749 |
} |
|
1750 |
||
1751 |
int RenderBox::containingBlockHeightForPositioned(const RenderBoxModelObject* containingBlock) const |
|
1752 |
{ |
|
1753 |
int heightResult = 0; |
|
1754 |
if (containingBlock->isBox()) |
|
1755 |
heightResult = toRenderBox(containingBlock)->height(); |
|
1756 |
else if (containingBlock->isRenderInline()) { |
|
1757 |
ASSERT(containingBlock->isRelPositioned()); |
|
1758 |
heightResult = toRenderInline(containingBlock)->linesBoundingBox().height(); |
|
1759 |
} |
|
1760 |
return heightResult - containingBlock->borderTop() - containingBlock->borderBottom(); |
|
1761 |
} |
|
1762 |
||
1763 |
void RenderBox::calcAbsoluteHorizontal() |
|
1764 |
{ |
|
1765 |
if (isReplaced()) { |
|
1766 |
calcAbsoluteHorizontalReplaced(); |
|
1767 |
return; |
|
1768 |
} |
|
1769 |
||
1770 |
// QUESTIONS |
|
1771 |
// FIXME 1: Which RenderObject's 'direction' property should used: the |
|
1772 |
// containing block (cb) as the spec seems to imply, the parent (parent()) as |
|
1773 |
// was previously done in calculating the static distances, or ourself, which |
|
1774 |
// was also previously done for deciding what to override when you had |
|
1775 |
// over-constrained margins? Also note that the container block is used |
|
1776 |
// in similar situations in other parts of the RenderBox class (see calcWidth() |
|
1777 |
// and calcHorizontalMargins()). For now we are using the parent for quirks |
|
1778 |
// mode and the containing block for strict mode. |
|
1779 |
||
1780 |
// FIXME 2: Should we still deal with these the cases of 'left' or 'right' having |
|
1781 |
// the type 'static' in determining whether to calculate the static distance? |
|
1782 |
// NOTE: 'static' is not a legal value for 'left' or 'right' as of CSS 2.1. |
|
1783 |
||
1784 |
// FIXME 3: Can perhaps optimize out cases when max-width/min-width are greater |
|
1785 |
// than or less than the computed width(). Be careful of box-sizing and |
|
1786 |
// percentage issues. |
|
1787 |
||
1788 |
// The following is based off of the W3C Working Draft from April 11, 2006 of |
|
1789 |
// CSS 2.1: Section 10.3.7 "Absolutely positioned, non-replaced elements" |
|
1790 |
// <http://www.w3.org/TR/CSS21/visudet.html#abs-non-replaced-width> |
|
1791 |
// (block-style-comments in this function and in calcAbsoluteHorizontalValues() |
|
1792 |
// correspond to text from the spec) |
|
1793 |
||
1794 |
||
1795 |
// We don't use containingBlock(), since we may be positioned by an enclosing |
|
1796 |
// relative positioned inline. |
|
1797 |
const RenderBoxModelObject* containerBlock = toRenderBoxModelObject(container()); |
|
1798 |
||
1799 |
const int containerWidth = containingBlockWidthForPositioned(containerBlock); |
|
1800 |
||
1801 |
// To match WinIE, in quirks mode use the parent's 'direction' property |
|
1802 |
// instead of the the container block's. |
|
1803 |
TextDirection containerDirection = (style()->htmlHacks()) ? parent()->style()->direction() : containerBlock->style()->direction(); |
|
1804 |
||
1805 |
const int bordersPlusPadding = borderLeft() + borderRight() + paddingLeft() + paddingRight(); |
|
1806 |
const Length marginLeft = style()->marginLeft(); |
|
1807 |
const Length marginRight = style()->marginRight(); |
|
1808 |
Length left = style()->left(); |
|
1809 |
Length right = style()->right(); |
|
1810 |
||
1811 |
/*---------------------------------------------------------------------------*\ |
|
1812 |
* For the purposes of this section and the next, the term "static position" |
|
1813 |
* (of an element) refers, roughly, to the position an element would have had |
|
1814 |
* in the normal flow. More precisely: |
|
1815 |
* |
|
1816 |
* * The static position for 'left' is the distance from the left edge of the |
|
1817 |
* containing block to the left margin edge of a hypothetical box that would |
|
1818 |
* have been the first box of the element if its 'position' property had |
|
1819 |
* been 'static' and 'float' had been 'none'. The value is negative if the |
|
1820 |
* hypothetical box is to the left of the containing block. |
|
1821 |
* * The static position for 'right' is the distance from the right edge of the |
|
1822 |
* containing block to the right margin edge of the same hypothetical box as |
|
1823 |
* above. The value is positive if the hypothetical box is to the left of the |
|
1824 |
* containing block's edge. |
|
1825 |
* |
|
1826 |
* But rather than actually calculating the dimensions of that hypothetical box, |
|
1827 |
* user agents are free to make a guess at its probable position. |
|
1828 |
* |
|
1829 |
* For the purposes of calculating the static position, the containing block of |
|
1830 |
* fixed positioned elements is the initial containing block instead of the |
|
1831 |
* viewport, and all scrollable boxes should be assumed to be scrolled to their |
|
1832 |
* origin. |
|
1833 |
\*---------------------------------------------------------------------------*/ |
|
1834 |
||
1835 |
// see FIXME 2 |
|
1836 |
// Calculate the static distance if needed. |
|
1837 |
if (left.isAuto() && right.isAuto()) { |
|
1838 |
if (containerDirection == LTR) { |
|
1839 |
// 'staticX' should already have been set through layout of the parent. |
|
1840 |
int staticPosition = layer()->staticX() - containerBlock->borderLeft(); |
|
1841 |
for (RenderObject* po = parent(); po && po != containerBlock; po = po->parent()) { |
|
1842 |
if (po->isBox()) |
|
1843 |
staticPosition += toRenderBox(po)->x(); |
|
1844 |
} |
|
1845 |
left.setValue(Fixed, staticPosition); |
|
1846 |
} else { |
|
1847 |
RenderObject* po = parent(); |
|
1848 |
// 'staticX' should already have been set through layout of the parent. |
|
1849 |
int staticPosition = layer()->staticX() + containerWidth + containerBlock->borderRight(); |
|
1850 |
if (po->isBox()) |
|
1851 |
staticPosition -= toRenderBox(po)->width(); |
|
1852 |
for (; po && po != containerBlock; po = po->parent()) { |
|
1853 |
if (po->isBox()) |
|
1854 |
staticPosition -= toRenderBox(po)->x(); |
|
1855 |
} |
|
1856 |
right.setValue(Fixed, staticPosition); |
|
1857 |
} |
|
1858 |
} |
|
1859 |
||
1860 |
// Calculate constraint equation values for 'width' case. |
|
1861 |
int widthResult; |
|
1862 |
int xResult; |
|
1863 |
calcAbsoluteHorizontalValues(style()->width(), containerBlock, containerDirection, |
|
1864 |
containerWidth, bordersPlusPadding, |
|
1865 |
left, right, marginLeft, marginRight, |
|
1866 |
widthResult, m_marginLeft, m_marginRight, xResult); |
|
1867 |
setWidth(widthResult); |
|
1868 |
setX(xResult); |
|
1869 |
||
1870 |
// Calculate constraint equation values for 'max-width' case. |
|
1871 |
if (!style()->maxWidth().isUndefined()) { |
|
1872 |
int maxWidth; |
|
1873 |
int maxMarginLeft; |
|
1874 |
int maxMarginRight; |
|
1875 |
int maxXPos; |
|
1876 |
||
1877 |
calcAbsoluteHorizontalValues(style()->maxWidth(), containerBlock, containerDirection, |
|
1878 |
containerWidth, bordersPlusPadding, |
|
1879 |
left, right, marginLeft, marginRight, |
|
1880 |
maxWidth, maxMarginLeft, maxMarginRight, maxXPos); |
|
1881 |
||
1882 |
if (width() > maxWidth) { |
|
1883 |
setWidth(maxWidth); |
|
1884 |
m_marginLeft = maxMarginLeft; |
|
1885 |
m_marginRight = maxMarginRight; |
|
1886 |
m_frameRect.setX(maxXPos); |
|
1887 |
} |
|
1888 |
} |
|
1889 |
||
1890 |
// Calculate constraint equation values for 'min-width' case. |
|
1891 |
if (!style()->minWidth().isZero()) { |
|
1892 |
int minWidth; |
|
1893 |
int minMarginLeft; |
|
1894 |
int minMarginRight; |
|
1895 |
int minXPos; |
|
1896 |
||
1897 |
calcAbsoluteHorizontalValues(style()->minWidth(), containerBlock, containerDirection, |
|
1898 |
containerWidth, bordersPlusPadding, |
|
1899 |
left, right, marginLeft, marginRight, |
|
1900 |
minWidth, minMarginLeft, minMarginRight, minXPos); |
|
1901 |
||
1902 |
if (width() < minWidth) { |
|
1903 |
setWidth(minWidth); |
|
1904 |
m_marginLeft = minMarginLeft; |
|
1905 |
m_marginRight = minMarginRight; |
|
1906 |
m_frameRect.setX(minXPos); |
|
1907 |
} |
|
1908 |
} |
|
1909 |
||
1910 |
if (stretchesToMinIntrinsicWidth() && width() < minPrefWidth() - bordersPlusPadding) { |
|
1911 |
calcAbsoluteHorizontalValues(Length(minPrefWidth() - bordersPlusPadding, Fixed), containerBlock, containerDirection, |
|
1912 |
containerWidth, bordersPlusPadding, |
|
1913 |
left, right, marginLeft, marginRight, |
|
1914 |
widthResult, m_marginLeft, m_marginRight, xResult); |
|
1915 |
setWidth(widthResult); |
|
1916 |
setX(xResult); |
|
1917 |
} |
|
1918 |
||
1919 |
// Put width() into correct form. |
|
1920 |
setWidth(width() + bordersPlusPadding); |
|
1921 |
} |
|
1922 |
||
1923 |
void RenderBox::calcAbsoluteHorizontalValues(Length width, const RenderBoxModelObject* containerBlock, TextDirection containerDirection, |
|
1924 |
const int containerWidth, const int bordersPlusPadding, |
|
1925 |
const Length left, const Length right, const Length marginLeft, const Length marginRight, |
|
1926 |
int& widthValue, int& marginLeftValue, int& marginRightValue, int& xPos) |
|
1927 |
{ |
|
1928 |
// 'left' and 'right' cannot both be 'auto' because one would of been |
|
1929 |
// converted to the static postion already |
|
1930 |
ASSERT(!(left.isAuto() && right.isAuto())); |
|
1931 |
||
1932 |
int leftValue = 0; |
|
1933 |
||
1934 |
bool widthIsAuto = width.isIntrinsicOrAuto(); |
|
1935 |
bool leftIsAuto = left.isAuto(); |
|
1936 |
bool rightIsAuto = right.isAuto(); |
|
1937 |
||
1938 |
if (!leftIsAuto && !widthIsAuto && !rightIsAuto) { |
|
1939 |
/*-----------------------------------------------------------------------*\ |
|
1940 |
* If none of the three is 'auto': If both 'margin-left' and 'margin- |
|
1941 |
* right' are 'auto', solve the equation under the extra constraint that |
|
1942 |
* the two margins get equal values, unless this would make them negative, |
|
1943 |
* in which case when direction of the containing block is 'ltr' ('rtl'), |
|
1944 |
* set 'margin-left' ('margin-right') to zero and solve for 'margin-right' |
|
1945 |
* ('margin-left'). If one of 'margin-left' or 'margin-right' is 'auto', |
|
1946 |
* solve the equation for that value. If the values are over-constrained, |
|
1947 |
* ignore the value for 'left' (in case the 'direction' property of the |
|
1948 |
* containing block is 'rtl') or 'right' (in case 'direction' is 'ltr') |
|
1949 |
* and solve for that value. |
|
1950 |
\*-----------------------------------------------------------------------*/ |
|
1951 |
// NOTE: It is not necessary to solve for 'right' in the over constrained |
|
1952 |
// case because the value is not used for any further calculations. |
|
1953 |
||
1954 |
leftValue = left.calcValue(containerWidth); |
|
1955 |
widthValue = calcContentBoxWidth(width.calcValue(containerWidth)); |
|
1956 |
||
1957 |
const int availableSpace = containerWidth - (leftValue + widthValue + right.calcValue(containerWidth) + bordersPlusPadding); |
|
1958 |
||
1959 |
// Margins are now the only unknown |
|
1960 |
if (marginLeft.isAuto() && marginRight.isAuto()) { |
|
1961 |
// Both margins auto, solve for equality |
|
1962 |
if (availableSpace >= 0) { |
|
1963 |
marginLeftValue = availableSpace / 2; // split the diference |
|
1964 |
marginRightValue = availableSpace - marginLeftValue; // account for odd valued differences |
|
1965 |
} else { |
|
1966 |
// see FIXME 1 |
|
1967 |
if (containerDirection == LTR) { |
|
1968 |
marginLeftValue = 0; |
|
1969 |
marginRightValue = availableSpace; // will be negative |
|
1970 |
} else { |
|
1971 |
marginLeftValue = availableSpace; // will be negative |
|
1972 |
marginRightValue = 0; |
|
1973 |
} |
|
1974 |
} |
|
1975 |
} else if (marginLeft.isAuto()) { |
|
1976 |
// Solve for left margin |
|
1977 |
marginRightValue = marginRight.calcValue(containerWidth); |
|
1978 |
marginLeftValue = availableSpace - marginRightValue; |
|
1979 |
} else if (marginRight.isAuto()) { |
|
1980 |
// Solve for right margin |
|
1981 |
marginLeftValue = marginLeft.calcValue(containerWidth); |
|
1982 |
marginRightValue = availableSpace - marginLeftValue; |
|
1983 |
} else { |
|
1984 |
// Over-constrained, solve for left if direction is RTL |
|
1985 |
marginLeftValue = marginLeft.calcValue(containerWidth); |
|
1986 |
marginRightValue = marginRight.calcValue(containerWidth); |
|
1987 |
||
1988 |
// see FIXME 1 -- used to be "this->style()->direction()" |
|
1989 |
if (containerDirection == RTL) |
|
1990 |
leftValue = (availableSpace + leftValue) - marginLeftValue - marginRightValue; |
|
1991 |
} |
|
1992 |
} else { |
|
1993 |
/*--------------------------------------------------------------------*\ |
|
1994 |
* Otherwise, set 'auto' values for 'margin-left' and 'margin-right' |
|
1995 |
* to 0, and pick the one of the following six rules that applies. |
|
1996 |
* |
|
1997 |
* 1. 'left' and 'width' are 'auto' and 'right' is not 'auto', then the |
|
1998 |
* width is shrink-to-fit. Then solve for 'left' |
|
1999 |
* |
|
2000 |
* OMIT RULE 2 AS IT SHOULD NEVER BE HIT |
|
2001 |
* ------------------------------------------------------------------ |
|
2002 |
* 2. 'left' and 'right' are 'auto' and 'width' is not 'auto', then if |
|
2003 |
* the 'direction' property of the containing block is 'ltr' set |
|
2004 |
* 'left' to the static position, otherwise set 'right' to the |
|
2005 |
* static position. Then solve for 'left' (if 'direction is 'rtl') |
|
2006 |
* or 'right' (if 'direction' is 'ltr'). |
|
2007 |
* ------------------------------------------------------------------ |
|
2008 |
* |
|
2009 |
* 3. 'width' and 'right' are 'auto' and 'left' is not 'auto', then the |
|
2010 |
* width is shrink-to-fit . Then solve for 'right' |
|
2011 |
* 4. 'left' is 'auto', 'width' and 'right' are not 'auto', then solve |
|
2012 |
* for 'left' |
|
2013 |
* 5. 'width' is 'auto', 'left' and 'right' are not 'auto', then solve |
|
2014 |
* for 'width' |
|
2015 |
* 6. 'right' is 'auto', 'left' and 'width' are not 'auto', then solve |
|
2016 |
* for 'right' |
|
2017 |
* |
|
2018 |
* Calculation of the shrink-to-fit width is similar to calculating the |
|
2019 |
* width of a table cell using the automatic table layout algorithm. |
|
2020 |
* Roughly: calculate the preferred width by formatting the content |
|
2021 |
* without breaking lines other than where explicit line breaks occur, |
|
2022 |
* and also calculate the preferred minimum width, e.g., by trying all |
|
2023 |
* possible line breaks. CSS 2.1 does not define the exact algorithm. |
|
2024 |
* Thirdly, calculate the available width: this is found by solving |
|
2025 |
* for 'width' after setting 'left' (in case 1) or 'right' (in case 3) |
|
2026 |
* to 0. |
|
2027 |
* |
|
2028 |
* Then the shrink-to-fit width is: |
|
2029 |
* min(max(preferred minimum width, available width), preferred width). |
|
2030 |
\*--------------------------------------------------------------------*/ |
|
2031 |
// NOTE: For rules 3 and 6 it is not necessary to solve for 'right' |
|
2032 |
// because the value is not used for any further calculations. |
|
2033 |
||
2034 |
// Calculate margins, 'auto' margins are ignored. |
|
2035 |
marginLeftValue = marginLeft.calcMinValue(containerWidth); |
|
2036 |
marginRightValue = marginRight.calcMinValue(containerWidth); |
|
2037 |
||
2038 |
const int availableSpace = containerWidth - (marginLeftValue + marginRightValue + bordersPlusPadding); |
|
2039 |
||
2040 |
// FIXME: Is there a faster way to find the correct case? |
|
2041 |
// Use rule/case that applies. |
|
2042 |
if (leftIsAuto && widthIsAuto && !rightIsAuto) { |
|
2043 |
// RULE 1: (use shrink-to-fit for width, and solve of left) |
|
2044 |
int rightValue = right.calcValue(containerWidth); |
|
2045 |
||
2046 |
// FIXME: would it be better to have shrink-to-fit in one step? |
|
2047 |
int preferredWidth = maxPrefWidth() - bordersPlusPadding; |
|
2048 |
int preferredMinWidth = minPrefWidth() - bordersPlusPadding; |
|
2049 |
int availableWidth = availableSpace - rightValue; |
|
2050 |
widthValue = min(max(preferredMinWidth, availableWidth), preferredWidth); |
|
2051 |
leftValue = availableSpace - (widthValue + rightValue); |
|
2052 |
} else if (!leftIsAuto && widthIsAuto && rightIsAuto) { |
|
2053 |
// RULE 3: (use shrink-to-fit for width, and no need solve of right) |
|
2054 |
leftValue = left.calcValue(containerWidth); |
|
2055 |
||
2056 |
// FIXME: would it be better to have shrink-to-fit in one step? |
|
2057 |
int preferredWidth = maxPrefWidth() - bordersPlusPadding; |
|
2058 |
int preferredMinWidth = minPrefWidth() - bordersPlusPadding; |
|
2059 |
int availableWidth = availableSpace - leftValue; |
|
2060 |
widthValue = min(max(preferredMinWidth, availableWidth), preferredWidth); |
|
2061 |
} else if (leftIsAuto && !width.isAuto() && !rightIsAuto) { |
|
2062 |
// RULE 4: (solve for left) |
|
2063 |
widthValue = calcContentBoxWidth(width.calcValue(containerWidth)); |
|
2064 |
leftValue = availableSpace - (widthValue + right.calcValue(containerWidth)); |
|
2065 |
} else if (!leftIsAuto && widthIsAuto && !rightIsAuto) { |
|
2066 |
// RULE 5: (solve for width) |
|
2067 |
leftValue = left.calcValue(containerWidth); |
|
2068 |
widthValue = availableSpace - (leftValue + right.calcValue(containerWidth)); |
|
2069 |
} else if (!leftIsAuto&& !widthIsAuto && rightIsAuto) { |
|
2070 |
// RULE 6: (no need solve for right) |
|
2071 |
leftValue = left.calcValue(containerWidth); |
|
2072 |
widthValue = calcContentBoxWidth(width.calcValue(containerWidth)); |
|
2073 |
} |
|
2074 |
} |
|
2075 |
||
2076 |
// Use computed values to calculate the horizontal position. |
|
2077 |
||
2078 |
// FIXME: This hack is needed to calculate the xPos for a 'rtl' relatively |
|
2079 |
// positioned, inline because right now, it is using the xPos |
|
2080 |
// of the first line box when really it should use the last line box. When |
|
2081 |
// this is fixed elsewhere, this block should be removed. |
|
2082 |
if (containerBlock->isRenderInline() && containerBlock->style()->direction() == RTL) { |
|
2083 |
const RenderInline* flow = toRenderInline(containerBlock); |
|
2084 |
InlineFlowBox* firstLine = flow->firstLineBox(); |
|
2085 |
InlineFlowBox* lastLine = flow->lastLineBox(); |
|
2086 |
if (firstLine && lastLine && firstLine != lastLine) { |
|
2087 |
xPos = leftValue + marginLeftValue + lastLine->borderLeft() + (lastLine->x() - firstLine->x()); |
|
2088 |
return; |
|
2089 |
} |
|
2090 |
} |
|
2091 |
||
2092 |
xPos = leftValue + marginLeftValue + containerBlock->borderLeft(); |
|
2093 |
} |
|
2094 |
||
2095 |
void RenderBox::calcAbsoluteVertical() |
|
2096 |
{ |
|
2097 |
if (isReplaced()) { |
|
2098 |
calcAbsoluteVerticalReplaced(); |
|
2099 |
return; |
|
2100 |
} |
|
2101 |
||
2102 |
// The following is based off of the W3C Working Draft from April 11, 2006 of |
|
2103 |
// CSS 2.1: Section 10.6.4 "Absolutely positioned, non-replaced elements" |
|
2104 |
// <http://www.w3.org/TR/2005/WD-CSS21-20050613/visudet.html#abs-non-replaced-height> |
|
2105 |
// (block-style-comments in this function and in calcAbsoluteVerticalValues() |
|
2106 |
// correspond to text from the spec) |
|
2107 |
||
2108 |
||
2109 |
// We don't use containingBlock(), since we may be positioned by an enclosing relpositioned inline. |
|
2110 |
const RenderBoxModelObject* containerBlock = toRenderBoxModelObject(container()); |
|
2111 |
||
2112 |
const int containerHeight = containingBlockHeightForPositioned(containerBlock); |
|
2113 |
||
2114 |
const int bordersPlusPadding = borderTop() + borderBottom() + paddingTop() + paddingBottom(); |
|
2115 |
const Length marginTop = style()->marginTop(); |
|
2116 |
const Length marginBottom = style()->marginBottom(); |
|
2117 |
Length top = style()->top(); |
|
2118 |
Length bottom = style()->bottom(); |
|
2119 |
||
2120 |
/*---------------------------------------------------------------------------*\ |
|
2121 |
* For the purposes of this section and the next, the term "static position" |
|
2122 |
* (of an element) refers, roughly, to the position an element would have had |
|
2123 |
* in the normal flow. More precisely, the static position for 'top' is the |
|
2124 |
* distance from the top edge of the containing block to the top margin edge |
|
2125 |
* of a hypothetical box that would have been the first box of the element if |
|
2126 |
* its 'position' property had been 'static' and 'float' had been 'none'. The |
|
2127 |
* value is negative if the hypothetical box is above the containing block. |
|
2128 |
* |
|
2129 |
* But rather than actually calculating the dimensions of that hypothetical |
|
2130 |
* box, user agents are free to make a guess at its probable position. |
|
2131 |
* |
|
2132 |
* For the purposes of calculating the static position, the containing block |
|
2133 |
* of fixed positioned elements is the initial containing block instead of |
|
2134 |
* the viewport. |
|
2135 |
\*---------------------------------------------------------------------------*/ |
|
2136 |
||
2137 |
// see FIXME 2 |
|
2138 |
// Calculate the static distance if needed. |
|
2139 |
if (top.isAuto() && bottom.isAuto()) { |
|
2140 |
// staticY should already have been set through layout of the parent() |
|
2141 |
int staticTop = layer()->staticY() - containerBlock->borderTop(); |
|
2142 |
for (RenderObject* po = parent(); po && po != containerBlock; po = po->parent()) { |
|
2143 |
if (po->isBox() && !po->isTableRow()) |
|
2144 |
staticTop += toRenderBox(po)->y(); |
|
2145 |
} |
|
2146 |
top.setValue(Fixed, staticTop); |
|
2147 |
} |
|
2148 |
||
2149 |
||
2150 |
int h; // Needed to compute overflow. |
|
2151 |
int y; |
|
2152 |
||
2153 |
// Calculate constraint equation values for 'height' case. |
|
2154 |
calcAbsoluteVerticalValues(style()->height(), containerBlock, containerHeight, bordersPlusPadding, |
|
2155 |
top, bottom, marginTop, marginBottom, |
|
2156 |
h, m_marginTop, m_marginBottom, y); |
|
2157 |
setY(y); |
|
2158 |
||
2159 |
// Avoid doing any work in the common case (where the values of min-height and max-height are their defaults). |
|
2160 |
// see FIXME 3 |
|
2161 |
||
2162 |
// Calculate constraint equation values for 'max-height' case. |
|
2163 |
if (!style()->maxHeight().isUndefined()) { |
|
2164 |
int maxHeight; |
|
2165 |
int maxMarginTop; |
|
2166 |
int maxMarginBottom; |
|
2167 |
int maxYPos; |
|
2168 |
||
2169 |
calcAbsoluteVerticalValues(style()->maxHeight(), containerBlock, containerHeight, bordersPlusPadding, |
|
2170 |
top, bottom, marginTop, marginBottom, |
|
2171 |
maxHeight, maxMarginTop, maxMarginBottom, maxYPos); |
|
2172 |
||
2173 |
if (h > maxHeight) { |
|
2174 |
h = maxHeight; |
|
2175 |
m_marginTop = maxMarginTop; |
|
2176 |
m_marginBottom = maxMarginBottom; |
|
2177 |
m_frameRect.setY(maxYPos); |
|
2178 |
} |
|
2179 |
} |
|
2180 |
||
2181 |
// Calculate constraint equation values for 'min-height' case. |
|
2182 |
if (!style()->minHeight().isZero()) { |
|
2183 |
int minHeight; |
|
2184 |
int minMarginTop; |
|
2185 |
int minMarginBottom; |
|
2186 |
int minYPos; |
|
2187 |
||
2188 |
calcAbsoluteVerticalValues(style()->minHeight(), containerBlock, containerHeight, bordersPlusPadding, |
|
2189 |
top, bottom, marginTop, marginBottom, |
|
2190 |
minHeight, minMarginTop, minMarginBottom, minYPos); |
|
2191 |
||
2192 |
if (h < minHeight) { |
|
2193 |
h = minHeight; |
|
2194 |
m_marginTop = minMarginTop; |
|
2195 |
m_marginBottom = minMarginBottom; |
|
2196 |
m_frameRect.setY(minYPos); |
|
2197 |
} |
|
2198 |
} |
|
2199 |
||
2200 |
// Set final height value. |
|
2201 |
setHeight(h + bordersPlusPadding); |
|
2202 |
} |
|
2203 |
||
2204 |
void RenderBox::calcAbsoluteVerticalValues(Length h, const RenderBoxModelObject* containerBlock, |
|
2205 |
const int containerHeight, const int bordersPlusPadding, |
|
2206 |
const Length top, const Length bottom, const Length marginTop, const Length marginBottom, |
|
2207 |
int& heightValue, int& marginTopValue, int& marginBottomValue, int& yPos) |
|
2208 |
{ |
|
2209 |
// 'top' and 'bottom' cannot both be 'auto' because 'top would of been |
|
2210 |
// converted to the static position in calcAbsoluteVertical() |
|
2211 |
ASSERT(!(top.isAuto() && bottom.isAuto())); |
|
2212 |
||
2213 |
int contentHeight = height() - bordersPlusPadding; |
|
2214 |
||
2215 |
int topValue = 0; |
|
2216 |
||
2217 |
bool heightIsAuto = h.isAuto(); |
|
2218 |
bool topIsAuto = top.isAuto(); |
|
2219 |
bool bottomIsAuto = bottom.isAuto(); |
|
2220 |
||
2221 |
// Height is never unsolved for tables. |
|
2222 |
if (isTable()) { |
|
2223 |
h.setValue(Fixed, contentHeight); |
|
2224 |
heightIsAuto = false; |
|
2225 |
} |
|
2226 |
||
2227 |
if (!topIsAuto && !heightIsAuto && !bottomIsAuto) { |
|
2228 |
/*-----------------------------------------------------------------------*\ |
|
2229 |
* If none of the three are 'auto': If both 'margin-top' and 'margin- |
|
2230 |
* bottom' are 'auto', solve the equation under the extra constraint that |
|
2231 |
* the two margins get equal values. If one of 'margin-top' or 'margin- |
|
2232 |
* bottom' is 'auto', solve the equation for that value. If the values |
|
2233 |
* are over-constrained, ignore the value for 'bottom' and solve for that |
|
2234 |
* value. |
|
2235 |
\*-----------------------------------------------------------------------*/ |
|
2236 |
// NOTE: It is not necessary to solve for 'bottom' in the over constrained |
|
2237 |
// case because the value is not used for any further calculations. |
|
2238 |
||
2239 |
heightValue = calcContentBoxHeight(h.calcValue(containerHeight)); |
|
2240 |
topValue = top.calcValue(containerHeight); |
|
2241 |
||
2242 |
const int availableSpace = containerHeight - (topValue + heightValue + bottom.calcValue(containerHeight) + bordersPlusPadding); |
|
2243 |
||
2244 |
// Margins are now the only unknown |
|
2245 |
if (marginTop.isAuto() && marginBottom.isAuto()) { |
|
2246 |
// Both margins auto, solve for equality |
|
2247 |
// NOTE: This may result in negative values. |
|
2248 |
marginTopValue = availableSpace / 2; // split the diference |
|
2249 |
marginBottomValue = availableSpace - marginTopValue; // account for odd valued differences |
|
2250 |
} else if (marginTop.isAuto()) { |
|
2251 |
// Solve for top margin |
|
2252 |
marginBottomValue = marginBottom.calcValue(containerHeight); |
|
2253 |
marginTopValue = availableSpace - marginBottomValue; |
|
2254 |
} else if (marginBottom.isAuto()) { |
|
2255 |
// Solve for bottom margin |
|
2256 |
marginTopValue = marginTop.calcValue(containerHeight); |
|
2257 |
marginBottomValue = availableSpace - marginTopValue; |
|
2258 |
} else { |
|
2259 |
// Over-constrained, (no need solve for bottom) |
|
2260 |
marginTopValue = marginTop.calcValue(containerHeight); |
|
2261 |
marginBottomValue = marginBottom.calcValue(containerHeight); |
|
2262 |
} |
|
2263 |
} else { |
|
2264 |
/*--------------------------------------------------------------------*\ |
|
2265 |
* Otherwise, set 'auto' values for 'margin-top' and 'margin-bottom' |
|
2266 |
* to 0, and pick the one of the following six rules that applies. |
|
2267 |
* |
|
2268 |
* 1. 'top' and 'height' are 'auto' and 'bottom' is not 'auto', then |
|
2269 |
* the height is based on the content, and solve for 'top'. |
|
2270 |
* |
|
2271 |
* OMIT RULE 2 AS IT SHOULD NEVER BE HIT |
|
2272 |
* ------------------------------------------------------------------ |
|
2273 |
* 2. 'top' and 'bottom' are 'auto' and 'height' is not 'auto', then |
|
2274 |
* set 'top' to the static position, and solve for 'bottom'. |
|
2275 |
* ------------------------------------------------------------------ |
|
2276 |
* |
|
2277 |
* 3. 'height' and 'bottom' are 'auto' and 'top' is not 'auto', then |
|
2278 |
* the height is based on the content, and solve for 'bottom'. |
|
2279 |
* 4. 'top' is 'auto', 'height' and 'bottom' are not 'auto', and |
|
2280 |
* solve for 'top'. |
|
2281 |
* 5. 'height' is 'auto', 'top' and 'bottom' are not 'auto', and |
|
2282 |
* solve for 'height'. |
|
2283 |
* 6. 'bottom' is 'auto', 'top' and 'height' are not 'auto', and |
|
2284 |
* solve for 'bottom'. |
|
2285 |
\*--------------------------------------------------------------------*/ |
|
2286 |
// NOTE: For rules 3 and 6 it is not necessary to solve for 'bottom' |
|
2287 |
// because the value is not used for any further calculations. |
|
2288 |
||
2289 |
// Calculate margins, 'auto' margins are ignored. |
|
2290 |
marginTopValue = marginTop.calcMinValue(containerHeight); |
|
2291 |
marginBottomValue = marginBottom.calcMinValue(containerHeight); |
|
2292 |
||
2293 |
const int availableSpace = containerHeight - (marginTopValue + marginBottomValue + bordersPlusPadding); |
|
2294 |
||
2295 |
// Use rule/case that applies. |
|
2296 |
if (topIsAuto && heightIsAuto && !bottomIsAuto) { |
|
2297 |
// RULE 1: (height is content based, solve of top) |
|
2298 |
heightValue = contentHeight; |
|
2299 |
topValue = availableSpace - (heightValue + bottom.calcValue(containerHeight)); |
|
2300 |
} else if (!topIsAuto && heightIsAuto && bottomIsAuto) { |
|
2301 |
// RULE 3: (height is content based, no need solve of bottom) |
|
2302 |
topValue = top.calcValue(containerHeight); |
|
2303 |
heightValue = contentHeight; |
|
2304 |
} else if (topIsAuto && !heightIsAuto && !bottomIsAuto) { |
|
2305 |
// RULE 4: (solve of top) |
|
2306 |
heightValue = calcContentBoxHeight(h.calcValue(containerHeight)); |
|
2307 |
topValue = availableSpace - (heightValue + bottom.calcValue(containerHeight)); |
|
2308 |
} else if (!topIsAuto && heightIsAuto && !bottomIsAuto) { |
|
2309 |
// RULE 5: (solve of height) |
|
2310 |
topValue = top.calcValue(containerHeight); |
|
2311 |
heightValue = max(0, availableSpace - (topValue + bottom.calcValue(containerHeight))); |
|
2312 |
} else if (!topIsAuto && !heightIsAuto && bottomIsAuto) { |
|
2313 |
// RULE 6: (no need solve of bottom) |
|
2314 |
heightValue = calcContentBoxHeight(h.calcValue(containerHeight)); |
|
2315 |
topValue = top.calcValue(containerHeight); |
|
2316 |
} |
|
2317 |
} |
|
2318 |
||
2319 |
// Use computed values to calculate the vertical position. |
|
2320 |
yPos = topValue + marginTopValue + containerBlock->borderTop(); |
|
2321 |
} |
|
2322 |
||
2323 |
void RenderBox::calcAbsoluteHorizontalReplaced() |
|
2324 |
{ |
|
2325 |
// The following is based off of the W3C Working Draft from April 11, 2006 of |
|
2326 |
// CSS 2.1: Section 10.3.8 "Absolutly positioned, replaced elements" |
|
2327 |
// <http://www.w3.org/TR/2005/WD-CSS21-20050613/visudet.html#abs-replaced-width> |
|
2328 |
// (block-style-comments in this function correspond to text from the spec and |
|
2329 |
// the numbers correspond to numbers in spec) |
|
2330 |
||
2331 |
// We don't use containingBlock(), since we may be positioned by an enclosing |
|
2332 |
// relative positioned inline. |
|
2333 |
const RenderBoxModelObject* containerBlock = toRenderBoxModelObject(container()); |
|
2334 |
||
2335 |
const int containerWidth = containingBlockWidthForPositioned(containerBlock); |
|
2336 |
||
2337 |
// To match WinIE, in quirks mode use the parent's 'direction' property |
|
2338 |
// instead of the the container block's. |
|
2339 |
TextDirection containerDirection = (style()->htmlHacks()) ? parent()->style()->direction() : containerBlock->style()->direction(); |
|
2340 |
||
2341 |
// Variables to solve. |
|
2342 |
Length left = style()->left(); |
|
2343 |
Length right = style()->right(); |
|
2344 |
Length marginLeft = style()->marginLeft(); |
|
2345 |
Length marginRight = style()->marginRight(); |
|
2346 |
||
2347 |
||
2348 |
/*-----------------------------------------------------------------------*\ |
|
2349 |
* 1. The used value of 'width' is determined as for inline replaced |
|
2350 |
* elements. |
|
2351 |
\*-----------------------------------------------------------------------*/ |
|
2352 |
// NOTE: This value of width is FINAL in that the min/max width calculations |
|
2353 |
// are dealt with in calcReplacedWidth(). This means that the steps to produce |
|
2354 |
// correct max/min in the non-replaced version, are not necessary. |
|
2355 |
setWidth(calcReplacedWidth() + borderLeft() + borderRight() + paddingLeft() + paddingRight()); |
|
2356 |
const int availableSpace = containerWidth - width(); |
|
2357 |
||
2358 |
/*-----------------------------------------------------------------------*\ |
|
2359 |
* 2. If both 'left' and 'right' have the value 'auto', then if 'direction' |
|
2360 |
* of the containing block is 'ltr', set 'left' to the static position; |
|
2361 |
* else if 'direction' is 'rtl', set 'right' to the static position. |
|
2362 |
\*-----------------------------------------------------------------------*/ |
|
2363 |
// see FIXME 2 |
|
2364 |
if (left.isAuto() && right.isAuto()) { |
|
2365 |
// see FIXME 1 |
|
2366 |
if (containerDirection == LTR) { |
|
2367 |
// 'staticX' should already have been set through layout of the parent. |
|
2368 |
int staticPosition = layer()->staticX() - containerBlock->borderLeft(); |
|
2369 |
for (RenderObject* po = parent(); po && po != containerBlock; po = po->parent()) { |
|
2370 |
if (po->isBox()) |
|
2371 |
staticPosition += toRenderBox(po)->x(); |
|
2372 |
} |
|
2373 |
left.setValue(Fixed, staticPosition); |
|
2374 |
} else { |
|
2375 |
RenderObject* po = parent(); |
|
2376 |
// 'staticX' should already have been set through layout of the parent. |
|
2377 |
int staticPosition = layer()->staticX() + containerWidth + containerBlock->borderRight(); |
|
2378 |
for ( ; po && po != containerBlock; po = po->parent()) { |
|
2379 |
if (po->isBox()) |
|
2380 |
staticPosition += toRenderBox(po)->x(); |
|
2381 |
} |
|
2382 |
right.setValue(Fixed, staticPosition); |
|
2383 |
} |
|
2384 |
} |
|
2385 |
||
2386 |
/*-----------------------------------------------------------------------*\ |
|
2387 |
* 3. If 'left' or 'right' are 'auto', replace any 'auto' on 'margin-left' |
|
2388 |
* or 'margin-right' with '0'. |
|
2389 |
\*-----------------------------------------------------------------------*/ |
|
2390 |
if (left.isAuto() || right.isAuto()) { |
|
2391 |
if (marginLeft.isAuto()) |
|
2392 |
marginLeft.setValue(Fixed, 0); |
|
2393 |
if (marginRight.isAuto()) |
|
2394 |
marginRight.setValue(Fixed, 0); |
|
2395 |
} |
|
2396 |
||
2397 |
/*-----------------------------------------------------------------------*\ |
|
2398 |
* 4. If at this point both 'margin-left' and 'margin-right' are still |
|
2399 |
* 'auto', solve the equation under the extra constraint that the two |
|
2400 |
* margins must get equal values, unless this would make them negative, |
|
2401 |
* in which case when the direction of the containing block is 'ltr' |
|
2402 |
* ('rtl'), set 'margin-left' ('margin-right') to zero and solve for |
|
2403 |
* 'margin-right' ('margin-left'). |
|
2404 |
\*-----------------------------------------------------------------------*/ |
|
2405 |
int leftValue = 0; |
|
2406 |
int rightValue = 0; |
|
2407 |
||
2408 |
if (marginLeft.isAuto() && marginRight.isAuto()) { |
|
2409 |
// 'left' and 'right' cannot be 'auto' due to step 3 |
|
2410 |
ASSERT(!(left.isAuto() && right.isAuto())); |
|
2411 |
||
2412 |
leftValue = left.calcValue(containerWidth); |
|
2413 |
rightValue = right.calcValue(containerWidth); |
|
2414 |
||
2415 |
int difference = availableSpace - (leftValue + rightValue); |
|
2416 |
if (difference > 0) { |
|
2417 |
m_marginLeft = difference / 2; // split the diference |
|
2418 |
m_marginRight = difference - m_marginLeft; // account for odd valued differences |
|
2419 |
} else { |
|
2420 |
// see FIXME 1 |
|
2421 |
if (containerDirection == LTR) { |
|
2422 |
m_marginLeft = 0; |
|
2423 |
m_marginRight = difference; // will be negative |
|
2424 |
} else { |
|
2425 |
m_marginLeft = difference; // will be negative |
|
2426 |
m_marginRight = 0; |
|
2427 |
} |
|
2428 |
} |
|
2429 |
||
2430 |
/*-----------------------------------------------------------------------*\ |
|
2431 |
* 5. If at this point there is an 'auto' left, solve the equation for |
|
2432 |
* that value. |
|
2433 |
\*-----------------------------------------------------------------------*/ |
|
2434 |
} else if (left.isAuto()) { |
|
2435 |
m_marginLeft = marginLeft.calcValue(containerWidth); |
|
2436 |
m_marginRight = marginRight.calcValue(containerWidth); |
|
2437 |
rightValue = right.calcValue(containerWidth); |
|
2438 |
||
2439 |
// Solve for 'left' |
|
2440 |
leftValue = availableSpace - (rightValue + m_marginLeft + m_marginRight); |
|
2441 |
} else if (right.isAuto()) { |
|
2442 |
m_marginLeft = marginLeft.calcValue(containerWidth); |
|
2443 |
m_marginRight = marginRight.calcValue(containerWidth); |
|
2444 |
leftValue = left.calcValue(containerWidth); |
|
2445 |
||
2446 |
// Solve for 'right' |
|
2447 |
rightValue = availableSpace - (leftValue + m_marginLeft + m_marginRight); |
|
2448 |
} else if (marginLeft.isAuto()) { |
|
2449 |
m_marginRight = marginRight.calcValue(containerWidth); |
|
2450 |
leftValue = left.calcValue(containerWidth); |
|
2451 |
rightValue = right.calcValue(containerWidth); |
|
2452 |
||
2453 |
// Solve for 'margin-left' |
|
2454 |
m_marginLeft = availableSpace - (leftValue + rightValue + m_marginRight); |
|
2455 |
} else if (marginRight.isAuto()) { |
|
2456 |
m_marginLeft = marginLeft.calcValue(containerWidth); |
|
2457 |
leftValue = left.calcValue(containerWidth); |
|
2458 |
rightValue = right.calcValue(containerWidth); |
|
2459 |
||
2460 |
// Solve for 'margin-right' |
|
2461 |
m_marginRight = availableSpace - (leftValue + rightValue + m_marginLeft); |
|
2462 |
} else { |
|
2463 |
// Nothing is 'auto', just calculate the values. |
|
2464 |
m_marginLeft = marginLeft.calcValue(containerWidth); |
|
2465 |
m_marginRight = marginRight.calcValue(containerWidth); |
|
2466 |
rightValue = right.calcValue(containerWidth); |
|
2467 |
leftValue = left.calcValue(containerWidth); |
|
2468 |
} |
|
2469 |
||
2470 |
/*-----------------------------------------------------------------------*\ |
|
2471 |
* 6. If at this point the values are over-constrained, ignore the value |
|
2472 |
* for either 'left' (in case the 'direction' property of the |
|
2473 |
* containing block is 'rtl') or 'right' (in case 'direction' is |
|
2474 |
* 'ltr') and solve for that value. |
|
2475 |
\*-----------------------------------------------------------------------*/ |
|
2476 |
// NOTE: It is not necessary to solve for 'right' when the direction is |
|
2477 |
// LTR because the value is not used. |
|
2478 |
int totalWidth = width() + leftValue + rightValue + m_marginLeft + m_marginRight; |
|
2479 |
if (totalWidth > containerWidth && (containerDirection == RTL)) |
|
2480 |
leftValue = containerWidth - (totalWidth - leftValue); |
|
2481 |
||
2482 |
// Use computed values to calculate the horizontal position. |
|
2483 |
||
2484 |
// FIXME: This hack is needed to calculate the xPos for a 'rtl' relatively |
|
2485 |
// positioned, inline containing block because right now, it is using the xPos |
|
2486 |
// of the first line box when really it should use the last line box. When |
|
2487 |
// this is fixed elsewhere, this block should be removed. |
|
2488 |
if (containerBlock->isRenderInline() && containerBlock->style()->direction() == RTL) { |
|
2489 |
const RenderInline* flow = toRenderInline(containerBlock); |
|
2490 |
InlineFlowBox* firstLine = flow->firstLineBox(); |
|
2491 |
InlineFlowBox* lastLine = flow->lastLineBox(); |
|
2492 |
if (firstLine && lastLine && firstLine != lastLine) { |
|
2493 |
m_frameRect.setX(leftValue + m_marginLeft + lastLine->borderLeft() + (lastLine->x() - firstLine->x())); |
|
2494 |
return; |
|
2495 |
} |
|
2496 |
} |
|
2497 |
||
2498 |
m_frameRect.setX(leftValue + m_marginLeft + containerBlock->borderLeft()); |
|
2499 |
} |
|
2500 |
||
2501 |
void RenderBox::calcAbsoluteVerticalReplaced() |
|
2502 |
{ |
|
2503 |
// The following is based off of the W3C Working Draft from April 11, 2006 of |
|
2504 |
// CSS 2.1: Section 10.6.5 "Absolutly positioned, replaced elements" |
|
2505 |
// <http://www.w3.org/TR/2005/WD-CSS21-20050613/visudet.html#abs-replaced-height> |
|
2506 |
// (block-style-comments in this function correspond to text from the spec and |
|
2507 |
// the numbers correspond to numbers in spec) |
|
2508 |
||
2509 |
// We don't use containingBlock(), since we may be positioned by an enclosing relpositioned inline. |
|
2510 |
const RenderBoxModelObject* containerBlock = toRenderBoxModelObject(container()); |
|
2511 |
||
2512 |
const int containerHeight = containingBlockHeightForPositioned(containerBlock); |
|
2513 |
||
2514 |
// Variables to solve. |
|
2515 |
Length top = style()->top(); |
|
2516 |
Length bottom = style()->bottom(); |
|
2517 |
Length marginTop = style()->marginTop(); |
|
2518 |
Length marginBottom = style()->marginBottom(); |
|
2519 |
||
2520 |
||
2521 |
/*-----------------------------------------------------------------------*\ |
|
2522 |
* 1. The used value of 'height' is determined as for inline replaced |
|
2523 |
* elements. |
|
2524 |
\*-----------------------------------------------------------------------*/ |
|
2525 |
// NOTE: This value of height is FINAL in that the min/max height calculations |
|
2526 |
// are dealt with in calcReplacedHeight(). This means that the steps to produce |
|
2527 |
// correct max/min in the non-replaced version, are not necessary. |
|
2528 |
setHeight(calcReplacedHeight() + borderTop() + borderBottom() + paddingTop() + paddingBottom()); |
|
2529 |
const int availableSpace = containerHeight - height(); |
|
2530 |
||
2531 |
/*-----------------------------------------------------------------------*\ |
|
2532 |
* 2. If both 'top' and 'bottom' have the value 'auto', replace 'top' |
|
2533 |
* with the element's static position. |
|
2534 |
\*-----------------------------------------------------------------------*/ |
|
2535 |
// see FIXME 2 |
|
2536 |
if (top.isAuto() && bottom.isAuto()) { |
|
2537 |
// staticY should already have been set through layout of the parent(). |
|
2538 |
int staticTop = layer()->staticY() - containerBlock->borderTop(); |
|
2539 |
for (RenderObject* po = parent(); po && po != containerBlock; po = po->parent()) { |
|
2540 |
if (po->isBox() && !po->isTableRow()) |
|
2541 |
staticTop += toRenderBox(po)->y(); |
|
2542 |
} |
|
2543 |
top.setValue(Fixed, staticTop); |
|
2544 |
} |
|
2545 |
||
2546 |
/*-----------------------------------------------------------------------*\ |
|
2547 |
* 3. If 'bottom' is 'auto', replace any 'auto' on 'margin-top' or |
|
2548 |
* 'margin-bottom' with '0'. |
|
2549 |
\*-----------------------------------------------------------------------*/ |
|
2550 |
// FIXME: The spec. says that this step should only be taken when bottom is |
|
2551 |
// auto, but if only top is auto, this makes step 4 impossible. |
|
2552 |
if (top.isAuto() || bottom.isAuto()) { |
|
2553 |
if (marginTop.isAuto()) |
|
2554 |
marginTop.setValue(Fixed, 0); |
|
2555 |
if (marginBottom.isAuto()) |
|
2556 |
marginBottom.setValue(Fixed, 0); |
|
2557 |
} |
|
2558 |
||
2559 |
/*-----------------------------------------------------------------------*\ |
|
2560 |
* 4. If at this point both 'margin-top' and 'margin-bottom' are still |
|
2561 |
* 'auto', solve the equation under the extra constraint that the two |
|
2562 |
* margins must get equal values. |
|
2563 |
\*-----------------------------------------------------------------------*/ |
|
2564 |
int topValue = 0; |
|
2565 |
int bottomValue = 0; |
|
2566 |
||
2567 |
if (marginTop.isAuto() && marginBottom.isAuto()) { |
|
2568 |
// 'top' and 'bottom' cannot be 'auto' due to step 2 and 3 combinded. |
|
2569 |
ASSERT(!(top.isAuto() || bottom.isAuto())); |
|
2570 |
||
2571 |
topValue = top.calcValue(containerHeight); |
|
2572 |
bottomValue = bottom.calcValue(containerHeight); |
|
2573 |
||
2574 |
int difference = availableSpace - (topValue + bottomValue); |
|
2575 |
// NOTE: This may result in negative values. |
|
2576 |
m_marginTop = difference / 2; // split the difference |
|
2577 |
m_marginBottom = difference - m_marginTop; // account for odd valued differences |
|
2578 |
||
2579 |
/*-----------------------------------------------------------------------*\ |
|
2580 |
* 5. If at this point there is only one 'auto' left, solve the equation |
|
2581 |
* for that value. |
|
2582 |
\*-----------------------------------------------------------------------*/ |
|
2583 |
} else if (top.isAuto()) { |
|
2584 |
m_marginTop = marginTop.calcValue(containerHeight); |
|
2585 |
m_marginBottom = marginBottom.calcValue(containerHeight); |
|
2586 |
bottomValue = bottom.calcValue(containerHeight); |
|
2587 |
||
2588 |
// Solve for 'top' |
|
2589 |
topValue = availableSpace - (bottomValue + m_marginTop + m_marginBottom); |
|
2590 |
} else if (bottom.isAuto()) { |
|
2591 |
m_marginTop = marginTop.calcValue(containerHeight); |
|
2592 |
m_marginBottom = marginBottom.calcValue(containerHeight); |
|
2593 |
topValue = top.calcValue(containerHeight); |
|
2594 |
||
2595 |
// Solve for 'bottom' |
|
2596 |
// NOTE: It is not necessary to solve for 'bottom' because we don't ever |
|
2597 |
// use the value. |
|
2598 |
} else if (marginTop.isAuto()) { |
|
2599 |
m_marginBottom = marginBottom.calcValue(containerHeight); |
|
2600 |
topValue = top.calcValue(containerHeight); |
|
2601 |
bottomValue = bottom.calcValue(containerHeight); |
|
2602 |
||
2603 |
// Solve for 'margin-top' |
|
2604 |
m_marginTop = availableSpace - (topValue + bottomValue + m_marginBottom); |
|
2605 |
} else if (marginBottom.isAuto()) { |
|
2606 |
m_marginTop = marginTop.calcValue(containerHeight); |
|
2607 |
topValue = top.calcValue(containerHeight); |
|
2608 |
bottomValue = bottom.calcValue(containerHeight); |
|
2609 |
||
2610 |
// Solve for 'margin-bottom' |
|
2611 |
m_marginBottom = availableSpace - (topValue + bottomValue + m_marginTop); |
|
2612 |
} else { |
|
2613 |
// Nothing is 'auto', just calculate the values. |
|
2614 |
m_marginTop = marginTop.calcValue(containerHeight); |
|
2615 |
m_marginBottom = marginBottom.calcValue(containerHeight); |
|
2616 |
topValue = top.calcValue(containerHeight); |
|
2617 |
// NOTE: It is not necessary to solve for 'bottom' because we don't ever |
|
2618 |
// use the value. |
|
2619 |
} |
|
2620 |
||
2621 |
/*-----------------------------------------------------------------------*\ |
|
2622 |
* 6. If at this point the values are over-constrained, ignore the value |
|
2623 |
* for 'bottom' and solve for that value. |
|
2624 |
\*-----------------------------------------------------------------------*/ |
|
2625 |
// NOTE: It is not necessary to do this step because we don't end up using |
|
2626 |
// the value of 'bottom' regardless of whether the values are over-constrained |
|
2627 |
// or not. |
|
2628 |
||
2629 |
// Use computed values to calculate the vertical position. |
|
2630 |
m_frameRect.setY(topValue + m_marginTop + containerBlock->borderTop()); |
|
2631 |
} |
|
2632 |
||
2633 |
IntRect RenderBox::localCaretRect(InlineBox* box, int caretOffset, int* extraWidthToEndOfLine) |
|
2634 |
{ |
|
2635 |
// VisiblePositions at offsets inside containers either a) refer to the positions before/after |
|
2636 |
// those containers (tables and select elements) or b) refer to the position inside an empty block. |
|
2637 |
// They never refer to children. |
|
2638 |
// FIXME: Paint the carets inside empty blocks differently than the carets before/after elements. |
|
2639 |
||
2640 |
// FIXME: What about border and padding? |
|
2641 |
IntRect rect(x(), y(), caretWidth, height()); |
|
2642 |
TextDirection direction = box ? box->direction() : style()->direction(); |
|
2643 |
||
2644 |
if ((!caretOffset) ^ (direction == LTR)) |
|
2645 |
rect.move(IntSize(width() - caretWidth, 0)); |
|
2646 |
||
2647 |
if (box) { |
|
2648 |
RootInlineBox* rootBox = box->root(); |
|
2649 |
int top = rootBox->lineTop(); |
|
2650 |
rect.setY(top); |
|
2651 |
rect.setHeight(rootBox->lineBottom() - top); |
|
2652 |
} |
|
2653 |
||
2654 |
// If height of box is smaller than font height, use the latter one, |
|
2655 |
// otherwise the caret might become invisible. |
|
2656 |
// |
|
2657 |
// Also, if the box is not a replaced element, always use the font height. |
|
2658 |
// This prevents the "big caret" bug described in: |
|
2659 |
// <rdar://problem/3777804> Deleting all content in a document can result in giant tall-as-window insertion point |
|
2660 |
// |
|
2661 |
// FIXME: ignoring :first-line, missing good reason to take care of |
|
2662 |
int fontHeight = style()->font().height(); |
|
2663 |
if (fontHeight > rect.height() || (!isReplaced() && !isTable())) |
|
2664 |
rect.setHeight(fontHeight); |
|
2665 |
||
2666 |
if (extraWidthToEndOfLine) |
|
2667 |
*extraWidthToEndOfLine = x() + width() - rect.right(); |
|
2668 |
||
2669 |
// Move to local coords |
|
2670 |
rect.move(-x(), -y()); |
|
2671 |
return rect; |
|
2672 |
} |
|
2673 |
||
2674 |
int RenderBox::lowestPosition(bool /*includeOverflowInterior*/, bool includeSelf) const |
|
2675 |
{ |
|
2676 |
if (!includeSelf || !width()) |
|
2677 |
return 0; |
|
2678 |
int bottom = height(); |
|
2679 |
if (isRelPositioned()) |
|
2680 |
bottom += relativePositionOffsetY(); |
|
2681 |
return bottom; |
|
2682 |
} |
|
2683 |
||
2684 |
int RenderBox::rightmostPosition(bool /*includeOverflowInterior*/, bool includeSelf) const |
|
2685 |
{ |
|
2686 |
if (!includeSelf || !height()) |
|
2687 |
return 0; |
|
2688 |
int right = width(); |
|
2689 |
if (isRelPositioned()) |
|
2690 |
right += relativePositionOffsetX(); |
|
2691 |
return right; |
|
2692 |
} |
|
2693 |
||
2694 |
int RenderBox::leftmostPosition(bool /*includeOverflowInterior*/, bool includeSelf) const |
|
2695 |
{ |
|
2696 |
if (!includeSelf || !height()) |
|
2697 |
return width(); |
|
2698 |
int left = 0; |
|
2699 |
if (isRelPositioned()) |
|
2700 |
left += relativePositionOffsetX(); |
|
2701 |
return left; |
|
2702 |
} |
|
2703 |
||
2704 |
VisiblePosition RenderBox::positionForPoint(const IntPoint& point) |
|
2705 |
{ |
|
2706 |
// no children...return this render object's element, if there is one, and offset 0 |
|
2707 |
if (!firstChild()) |
|
2708 |
return createVisiblePosition(firstDeepEditingPositionForNode(node())); |
|
2709 |
||
2710 |
int xPos = point.x(); |
|
2711 |
int yPos = point.y(); |
|
2712 |
||
2713 |
if (isTable() && node()) { |
|
2714 |
int right = contentWidth() + borderRight() + paddingRight() + borderLeft() + paddingLeft(); |
|
2715 |
int bottom = contentHeight() + borderTop() + paddingTop() + borderBottom() + paddingBottom(); |
|
2716 |
||
2717 |
if (xPos < 0 || xPos > right || yPos < 0 || yPos > bottom) { |
|
2718 |
if (xPos <= right / 2) |
|
2719 |
return createVisiblePosition(firstDeepEditingPositionForNode(node())); |
|
2720 |
return createVisiblePosition(lastDeepEditingPositionForNode(node())); |
|
2721 |
} |
|
2722 |
} |
|
2723 |
||
2724 |
// Pass off to the closest child. |
|
2725 |
int minDist = INT_MAX; |
|
2726 |
RenderBox* closestRenderer = 0; |
|
2727 |
int newX = xPos; |
|
2728 |
int newY = yPos; |
|
2729 |
if (isTableRow()) { |
|
2730 |
newX += x(); |
|
2731 |
newY += y(); |
|
2732 |
} |
|
2733 |
for (RenderObject* renderObject = firstChild(); renderObject; renderObject = renderObject->nextSibling()) { |
|
2734 |
if ((!renderObject->firstChild() && !renderObject->isInline() && !renderObject->isBlockFlow() ) |
|
2735 |
|| renderObject->style()->visibility() != VISIBLE) |
|
2736 |
continue; |
|
2737 |
||
2738 |
if (!renderObject->isBox()) |
|
2739 |
continue; |
|
2740 |
||
2741 |
RenderBox* renderer = toRenderBox(renderObject); |
|
2742 |
||
2743 |
int top = renderer->borderTop() + renderer->paddingTop() + (isTableRow() ? 0 : renderer->y()); |
|
2744 |
int bottom = top + renderer->contentHeight(); |
|
2745 |
int left = renderer->borderLeft() + renderer->paddingLeft() + (isTableRow() ? 0 : renderer->x()); |
|
2746 |
int right = left + renderer->contentWidth(); |
|
2747 |
||
2748 |
if (xPos <= right && xPos >= left && yPos <= top && yPos >= bottom) { |
|
2749 |
if (renderer->isTableRow()) |
|
2750 |
return renderer->positionForCoordinates(xPos + newX - renderer->x(), yPos + newY - renderer->y()); |
|
2751 |
return renderer->positionForCoordinates(xPos - renderer->x(), yPos - renderer->y()); |
|
2752 |
} |
|
2753 |
||
2754 |
// Find the distance from (x, y) to the box. Split the space around the box into 8 pieces |
|
2755 |
// and use a different compare depending on which piece (x, y) is in. |
|
2756 |
IntPoint cmp; |
|
2757 |
if (xPos > right) { |
|
2758 |
if (yPos < top) |
|
2759 |
cmp = IntPoint(right, top); |
|
2760 |
else if (yPos > bottom) |
|
2761 |
cmp = IntPoint(right, bottom); |
|
2762 |
else |
|
2763 |
cmp = IntPoint(right, yPos); |
|
2764 |
} else if (xPos < left) { |
|
2765 |
if (yPos < top) |
|
2766 |
cmp = IntPoint(left, top); |
|
2767 |
else if (yPos > bottom) |
|
2768 |
cmp = IntPoint(left, bottom); |
|
2769 |
else |
|
2770 |
cmp = IntPoint(left, yPos); |
|
2771 |
} else { |
|
2772 |
if (yPos < top) |
|
2773 |
cmp = IntPoint(xPos, top); |
|
2774 |
else |
|
2775 |
cmp = IntPoint(xPos, bottom); |
|
2776 |
} |
|
2777 |
||
2778 |
int x1minusx2 = cmp.x() - xPos; |
|
2779 |
int y1minusy2 = cmp.y() - yPos; |
|
2780 |
||
2781 |
int dist = x1minusx2 * x1minusx2 + y1minusy2 * y1minusy2; |
|
2782 |
if (dist < minDist) { |
|
2783 |
closestRenderer = renderer; |
|
2784 |
minDist = dist; |
|
2785 |
} |
|
2786 |
} |
|
2787 |
||
2788 |
if (closestRenderer) |
|
2789 |
return closestRenderer->positionForCoordinates(newX - closestRenderer->x(), newY - closestRenderer->y()); |
|
2790 |
||
2791 |
return createVisiblePosition(firstDeepEditingPositionForNode(node())); |
|
2792 |
} |
|
2793 |
||
2794 |
bool RenderBox::shrinkToAvoidFloats() const |
|
2795 |
{ |
|
2796 |
// FIXME: Technically we should be able to shrink replaced elements on a line, but this is difficult to accomplish, since this |
|
2797 |
// involves doing a relayout during findNextLineBreak and somehow overriding the containingBlockWidth method to return the |
|
2798 |
// current remaining width on a line. |
|
2799 |
if ((isInline() && !isHTMLMarquee()) || !avoidsFloats()) |
|
2800 |
return false; |
|
2801 |
||
2802 |
// All auto-width objects that avoid floats should always use lineWidth. |
|
2803 |
return style()->width().isAuto(); |
|
2804 |
} |
|
2805 |
||
2806 |
bool RenderBox::avoidsFloats() const |
|
2807 |
{ |
|
2808 |
return isReplaced() || hasOverflowClip() || isHR(); |
|
2809 |
} |
|
2810 |
||
2811 |
void RenderBox::addShadowOverflow() |
|
2812 |
{ |
|
2813 |
int shadowLeft; |
|
2814 |
int shadowRight; |
|
2815 |
int shadowTop; |
|
2816 |
int shadowBottom; |
|
2817 |
style()->getBoxShadowExtent(shadowTop, shadowRight, shadowBottom, shadowLeft); |
|
2818 |
IntRect borderBox = borderBoxRect(); |
|
2819 |
int overflowLeft = borderBox.x() + shadowLeft; |
|
2820 |
int overflowRight = borderBox.right() + shadowRight; |
|
2821 |
int overflowTop = borderBox.y() + shadowTop; |
|
2822 |
int overflowBottom = borderBox.bottom() + shadowBottom; |
|
2823 |
addVisualOverflow(IntRect(overflowLeft, overflowTop, overflowRight - overflowLeft, overflowBottom - overflowTop)); |
|
2824 |
} |
|
2825 |
||
2826 |
void RenderBox::addOverflowFromChild(RenderBox* child, const IntSize& delta) |
|
2827 |
{ |
|
2828 |
// Update our overflow in case the child spills out the block, but only if we were going to paint |
|
2829 |
// the child block ourselves. |
|
2830 |
if (child->hasSelfPaintingLayer()) |
|
2831 |
return; |
|
2832 |
||
2833 |
// Only propagate layout overflow from the child if the child isn't clipping its overflow. If it is, then |
|
2834 |
// its overflow is internal to it, and we don't care about it. |
|
2835 |
IntRect childLayoutOverflowRect = child->hasOverflowClip() ? child->borderBoxRect() : child->layoutOverflowRect(); |
|
2836 |
childLayoutOverflowRect.move(delta); |
|
2837 |
addLayoutOverflow(childLayoutOverflowRect); |
|
2838 |
||
2839 |
// Add in visual overflow from the child. Even if the child clips its overflow, it may still |
|
2840 |
// have visual overflow of its own set from box shadows or reflections. It is unnecessary to propagate this |
|
2841 |
// overflow if we are clipping our own overflow. |
|
2842 |
if (hasOverflowClip()) |
|
2843 |
return; |
|
2844 |
IntRect childVisualOverflowRect = child->visualOverflowRect(); |
|
2845 |
childVisualOverflowRect.move(delta); |
|
2846 |
addVisualOverflow(childVisualOverflowRect); |
|
2847 |
} |
|
2848 |
||
2849 |
void RenderBox::addLayoutOverflow(const IntRect& rect) |
|
2850 |
{ |
|
2851 |
IntRect borderBox = borderBoxRect(); |
|
2852 |
if (borderBox.contains(rect)) |
|
2853 |
return; |
|
2854 |
||
2855 |
if (!m_overflow) |
|
2856 |
m_overflow.set(new RenderOverflow(borderBox)); |
|
2857 |
||
2858 |
m_overflow->addLayoutOverflow(rect); |
|
2859 |
} |
|
2860 |
||
2861 |
void RenderBox::addVisualOverflow(const IntRect& rect) |
|
2862 |
{ |
|
2863 |
IntRect borderBox = borderBoxRect(); |
|
2864 |
if (borderBox.contains(rect)) |
|
2865 |
return; |
|
2866 |
||
2867 |
if (!m_overflow) |
|
2868 |
m_overflow.set(new RenderOverflow(borderBox)); |
|
2869 |
||
2870 |
m_overflow->addVisualOverflow(rect); |
|
2871 |
} |
|
2872 |
||
2873 |
void RenderBox::clearLayoutOverflow() |
|
2874 |
{ |
|
2875 |
if (!m_overflow) |
|
2876 |
return; |
|
2877 |
||
2878 |
if (visualOverflowRect() == borderBoxRect()) { |
|
2879 |
m_overflow.clear(); |
|
2880 |
return; |
|
2881 |
} |
|
2882 |
||
2883 |
m_overflow->resetLayoutOverflow(borderBoxRect()); |
|
2884 |
} |
|
2885 |
||
2886 |
#if ENABLE(SVG) |
|
2887 |
||
2888 |
TransformationMatrix RenderBox::localTransform() const |
|
2889 |
{ |
|
2890 |
return TransformationMatrix(1, 0, 0, 1, x(), y()); |
|
2891 |
} |
|
2892 |
||
2893 |
#endif |
|
2894 |
||
2895 |
} // namespace WebCore |