| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
| 3 * Copyright (C) 2000 Dirk Mueller (mueller@kde.org) | 3 * Copyright (C) 2000 Dirk Mueller (mueller@kde.org) |
| 4 * Copyright (C) 2004, 2006, 2007 Apple Inc. All rights reserved. | 4 * Copyright (C) 2004, 2006, 2007 Apple Inc. All rights reserved. |
| 5 * Copyright (C) Research In Motion Limited 2011-2012. All rights reserved. | 5 * Copyright (C) Research In Motion Limited 2011-2012. All rights reserved. |
| 6 * | 6 * |
| 7 * This library is free software; you can redistribute it and/or | 7 * This library is free software; you can redistribute it and/or |
| 8 * modify it under the terms of the GNU Library General Public | 8 * modify it under the terms of the GNU Library General Public |
| 9 * License as published by the Free Software Foundation; either | 9 * License as published by the Free Software Foundation; either |
| 10 * version 2 of the License, or (at your option) any later version. | 10 * version 2 of the License, or (at your option) any later version. |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 #include "core/rendering/RenderBlock.h" | 31 #include "core/rendering/RenderBlock.h" |
| 32 #include "core/rendering/RenderView.h" | 32 #include "core/rendering/RenderView.h" |
| 33 #include "platform/LengthFunctions.h" | 33 #include "platform/LengthFunctions.h" |
| 34 | 34 |
| 35 namespace blink { | 35 namespace blink { |
| 36 | 36 |
| 37 const int LayoutReplaced::defaultWidth = 300; | 37 const int LayoutReplaced::defaultWidth = 300; |
| 38 const int LayoutReplaced::defaultHeight = 150; | 38 const int LayoutReplaced::defaultHeight = 150; |
| 39 | 39 |
| 40 LayoutReplaced::LayoutReplaced(Element* element) | 40 LayoutReplaced::LayoutReplaced(Element* element) |
| 41 : RenderBox(element) | 41 : LayoutBox(element) |
| 42 , m_intrinsicSize(defaultWidth, defaultHeight) | 42 , m_intrinsicSize(defaultWidth, defaultHeight) |
| 43 { | 43 { |
| 44 setReplaced(true); | 44 setReplaced(true); |
| 45 } | 45 } |
| 46 | 46 |
| 47 LayoutReplaced::LayoutReplaced(Element* element, const LayoutSize& intrinsicSize
) | 47 LayoutReplaced::LayoutReplaced(Element* element, const LayoutSize& intrinsicSize
) |
| 48 : RenderBox(element) | 48 : LayoutBox(element) |
| 49 , m_intrinsicSize(intrinsicSize) | 49 , m_intrinsicSize(intrinsicSize) |
| 50 { | 50 { |
| 51 setReplaced(true); | 51 setReplaced(true); |
| 52 } | 52 } |
| 53 | 53 |
| 54 LayoutReplaced::~LayoutReplaced() | 54 LayoutReplaced::~LayoutReplaced() |
| 55 { | 55 { |
| 56 } | 56 } |
| 57 | 57 |
| 58 void LayoutReplaced::willBeDestroyed() | 58 void LayoutReplaced::willBeDestroyed() |
| 59 { | 59 { |
| 60 if (!documentBeingDestroyed() && parent()) | 60 if (!documentBeingDestroyed() && parent()) |
| 61 parent()->dirtyLinesFromChangedChild(this); | 61 parent()->dirtyLinesFromChangedChild(this); |
| 62 | 62 |
| 63 RenderBox::willBeDestroyed(); | 63 LayoutBox::willBeDestroyed(); |
| 64 } | 64 } |
| 65 | 65 |
| 66 void LayoutReplaced::styleDidChange(StyleDifference diff, const LayoutStyle* old
Style) | 66 void LayoutReplaced::styleDidChange(StyleDifference diff, const LayoutStyle* old
Style) |
| 67 { | 67 { |
| 68 RenderBox::styleDidChange(diff, oldStyle); | 68 LayoutBox::styleDidChange(diff, oldStyle); |
| 69 | 69 |
| 70 bool hadStyle = (oldStyle != 0); | 70 bool hadStyle = (oldStyle != 0); |
| 71 float oldZoom = hadStyle ? oldStyle->effectiveZoom() : LayoutStyle::initialZ
oom(); | 71 float oldZoom = hadStyle ? oldStyle->effectiveZoom() : LayoutStyle::initialZ
oom(); |
| 72 if (style() && style()->effectiveZoom() != oldZoom) | 72 if (style() && style()->effectiveZoom() != oldZoom) |
| 73 intrinsicSizeChanged(); | 73 intrinsicSizeChanged(); |
| 74 } | 74 } |
| 75 | 75 |
| 76 void LayoutReplaced::layout() | 76 void LayoutReplaced::layout() |
| 77 { | 77 { |
| 78 ASSERT(needsLayout()); | 78 ASSERT(needsLayout()); |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 // this node to change it's preferred width because it maintains aspect rati
o. | 165 // this node to change it's preferred width because it maintains aspect rati
o. |
| 166 return hasRelativeLogicalHeight() && style()->logicalWidth().isAuto() && !ha
sAutoHeightOrContainingBlockWithAutoHeight(); | 166 return hasRelativeLogicalHeight() && style()->logicalWidth().isAuto() && !ha
sAutoHeightOrContainingBlockWithAutoHeight(); |
| 167 } | 167 } |
| 168 | 168 |
| 169 static inline bool rendererHasAspectRatio(const LayoutObject* renderer) | 169 static inline bool rendererHasAspectRatio(const LayoutObject* renderer) |
| 170 { | 170 { |
| 171 ASSERT(renderer); | 171 ASSERT(renderer); |
| 172 return renderer->isImage() || renderer->isCanvas() || renderer->isVideo(); | 172 return renderer->isImage() || renderer->isCanvas() || renderer->isVideo(); |
| 173 } | 173 } |
| 174 | 174 |
| 175 void LayoutReplaced::computeAspectRatioInformationForRenderBox(RenderBox* conten
tRenderer, FloatSize& constrainedSize, double& intrinsicRatio) const | 175 void LayoutReplaced::computeAspectRatioInformationForLayoutBox(LayoutBox* conten
tRenderer, FloatSize& constrainedSize, double& intrinsicRatio) const |
| 176 { | 176 { |
| 177 FloatSize intrinsicSize; | 177 FloatSize intrinsicSize; |
| 178 if (contentRenderer) { | 178 if (contentRenderer) { |
| 179 contentRenderer->computeIntrinsicRatioInformation(intrinsicSize, intrins
icRatio); | 179 contentRenderer->computeIntrinsicRatioInformation(intrinsicSize, intrins
icRatio); |
| 180 | 180 |
| 181 // Handle zoom & vertical writing modes here, as the embedded document d
oesn't know about them. | 181 // Handle zoom & vertical writing modes here, as the embedded document d
oesn't know about them. |
| 182 intrinsicSize.scale(style()->effectiveZoom()); | 182 intrinsicSize.scale(style()->effectiveZoom()); |
| 183 if (isLayoutImage()) | 183 if (isLayoutImage()) |
| 184 intrinsicSize.scale(toLayoutImage(this)->imageDevicePixelRatio()); | 184 intrinsicSize.scale(toLayoutImage(this)->imageDevicePixelRatio()); |
| 185 | 185 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 203 // Now constrain the intrinsic size along each axis according to minimum and
maximum width/heights along the | 203 // Now constrain the intrinsic size along each axis according to minimum and
maximum width/heights along the |
| 204 // opposite axis. So for example a maximum width that shrinks our width will
result in the height we compute here | 204 // opposite axis. So for example a maximum width that shrinks our width will
result in the height we compute here |
| 205 // having to shrink in order to preserve the aspect ratio. Because we comput
e these values independently along | 205 // having to shrink in order to preserve the aspect ratio. Because we comput
e these values independently along |
| 206 // each axis, the final returned size may in fact not preserve the aspect ra
tio. | 206 // each axis, the final returned size may in fact not preserve the aspect ra
tio. |
| 207 // FIXME: In the long term, it might be better to just return this code more
to the way it used to be before this | 207 // FIXME: In the long term, it might be better to just return this code more
to the way it used to be before this |
| 208 // function was added, since all it has done is make the code more unclear. | 208 // function was added, since all it has done is make the code more unclear. |
| 209 constrainedSize = intrinsicSize; | 209 constrainedSize = intrinsicSize; |
| 210 if (intrinsicRatio && !intrinsicSize.isEmpty() && style()->logicalWidth().is
Auto() && style()->logicalHeight().isAuto()) { | 210 if (intrinsicRatio && !intrinsicSize.isEmpty() && style()->logicalWidth().is
Auto() && style()->logicalHeight().isAuto()) { |
| 211 // We can't multiply or divide by 'intrinsicRatio' here, it breaks tests
, like fast/images/zoomed-img-size.html, which | 211 // We can't multiply or divide by 'intrinsicRatio' here, it breaks tests
, like fast/images/zoomed-img-size.html, which |
| 212 // can only be fixed once subpixel precision is available for things lik
e intrinsicWidth/Height - which include zoom! | 212 // can only be fixed once subpixel precision is available for things lik
e intrinsicWidth/Height - which include zoom! |
| 213 constrainedSize.setWidth(RenderBox::computeReplacedLogicalHeight() * int
rinsicSize.width() / intrinsicSize.height()); | 213 constrainedSize.setWidth(LayoutBox::computeReplacedLogicalHeight() * int
rinsicSize.width() / intrinsicSize.height()); |
| 214 constrainedSize.setHeight(RenderBox::computeReplacedLogicalWidth() * int
rinsicSize.height() / intrinsicSize.width()); | 214 constrainedSize.setHeight(LayoutBox::computeReplacedLogicalWidth() * int
rinsicSize.height() / intrinsicSize.width()); |
| 215 } | 215 } |
| 216 } | 216 } |
| 217 | 217 |
| 218 LayoutRect LayoutReplaced::replacedContentRect(const LayoutSize* overriddenIntri
nsicSize) const | 218 LayoutRect LayoutReplaced::replacedContentRect(const LayoutSize* overriddenIntri
nsicSize) const |
| 219 { | 219 { |
| 220 LayoutRect contentRect = contentBoxRect(); | 220 LayoutRect contentRect = contentBoxRect(); |
| 221 ObjectFit objectFit = style()->objectFit(); | 221 ObjectFit objectFit = style()->objectFit(); |
| 222 | 222 |
| 223 if (objectFit == ObjectFitFill && style()->objectPosition() == LayoutStyle::
initialObjectPosition()) { | 223 if (objectFit == ObjectFitFill && style()->objectPosition() == LayoutStyle::
initialObjectPosition()) { |
| 224 return contentRect; | 224 return contentRect; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 return; | 264 return; |
| 265 | 265 |
| 266 intrinsicRatio = intrinsicSize.width() / intrinsicSize.height(); | 266 intrinsicRatio = intrinsicSize.width() / intrinsicSize.height(); |
| 267 } | 267 } |
| 268 | 268 |
| 269 LayoutUnit LayoutReplaced::computeReplacedLogicalWidth(ShouldComputePreferred sh
ouldComputePreferred) const | 269 LayoutUnit LayoutReplaced::computeReplacedLogicalWidth(ShouldComputePreferred sh
ouldComputePreferred) const |
| 270 { | 270 { |
| 271 if (style()->logicalWidth().isSpecified() || style()->logicalWidth().isIntri
nsic()) | 271 if (style()->logicalWidth().isSpecified() || style()->logicalWidth().isIntri
nsic()) |
| 272 return computeReplacedLogicalWidthRespectingMinMaxWidth(computeReplacedL
ogicalWidthUsing(style()->logicalWidth()), shouldComputePreferred); | 272 return computeReplacedLogicalWidthRespectingMinMaxWidth(computeReplacedL
ogicalWidthUsing(style()->logicalWidth()), shouldComputePreferred); |
| 273 | 273 |
| 274 RenderBox* contentRenderer = embeddedContentBox(); | 274 LayoutBox* contentRenderer = embeddedContentBox(); |
| 275 | 275 |
| 276 // 10.3.2 Inline, replaced elements: http://www.w3.org/TR/CSS21/visudet.html
#inline-replaced-width | 276 // 10.3.2 Inline, replaced elements: http://www.w3.org/TR/CSS21/visudet.html
#inline-replaced-width |
| 277 double intrinsicRatio = 0; | 277 double intrinsicRatio = 0; |
| 278 FloatSize constrainedSize; | 278 FloatSize constrainedSize; |
| 279 computeAspectRatioInformationForRenderBox(contentRenderer, constrainedSize,
intrinsicRatio); | 279 computeAspectRatioInformationForLayoutBox(contentRenderer, constrainedSize,
intrinsicRatio); |
| 280 | 280 |
| 281 if (style()->logicalWidth().isAuto()) { | 281 if (style()->logicalWidth().isAuto()) { |
| 282 bool computedHeightIsAuto = hasAutoHeightOrContainingBlockWithAutoHeight
(); | 282 bool computedHeightIsAuto = hasAutoHeightOrContainingBlockWithAutoHeight
(); |
| 283 bool hasIntrinsicWidth = constrainedSize.width() > 0; | 283 bool hasIntrinsicWidth = constrainedSize.width() > 0; |
| 284 | 284 |
| 285 // If 'height' and 'width' both have computed values of 'auto' and the e
lement also has an intrinsic width, then that intrinsic width is the used value
of 'width'. | 285 // If 'height' and 'width' both have computed values of 'auto' and the e
lement also has an intrinsic width, then that intrinsic width is the used value
of 'width'. |
| 286 if (computedHeightIsAuto && hasIntrinsicWidth) | 286 if (computedHeightIsAuto && hasIntrinsicWidth) |
| 287 return computeReplacedLogicalWidthRespectingMinMaxWidth(constrainedS
ize.width(), shouldComputePreferred); | 287 return computeReplacedLogicalWidthRespectingMinMaxWidth(constrainedS
ize.width(), shouldComputePreferred); |
| 288 | 288 |
| 289 bool hasIntrinsicHeight = constrainedSize.height() > 0; | 289 bool hasIntrinsicHeight = constrainedSize.height() > 0; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 | 327 |
| 328 return computeReplacedLogicalWidthRespectingMinMaxWidth(intrinsicLogicalWidt
h(), shouldComputePreferred); | 328 return computeReplacedLogicalWidthRespectingMinMaxWidth(intrinsicLogicalWidt
h(), shouldComputePreferred); |
| 329 } | 329 } |
| 330 | 330 |
| 331 LayoutUnit LayoutReplaced::computeReplacedLogicalHeight() const | 331 LayoutUnit LayoutReplaced::computeReplacedLogicalHeight() const |
| 332 { | 332 { |
| 333 // 10.5 Content height: the 'height' property: http://www.w3.org/TR/CSS21/vi
sudet.html#propdef-height | 333 // 10.5 Content height: the 'height' property: http://www.w3.org/TR/CSS21/vi
sudet.html#propdef-height |
| 334 if (hasReplacedLogicalHeight()) | 334 if (hasReplacedLogicalHeight()) |
| 335 return computeReplacedLogicalHeightRespectingMinMaxHeight(computeReplace
dLogicalHeightUsing(style()->logicalHeight())); | 335 return computeReplacedLogicalHeightRespectingMinMaxHeight(computeReplace
dLogicalHeightUsing(style()->logicalHeight())); |
| 336 | 336 |
| 337 RenderBox* contentRenderer = embeddedContentBox(); | 337 LayoutBox* contentRenderer = embeddedContentBox(); |
| 338 | 338 |
| 339 // 10.6.2 Inline, replaced elements: http://www.w3.org/TR/CSS21/visudet.html
#inline-replaced-height | 339 // 10.6.2 Inline, replaced elements: http://www.w3.org/TR/CSS21/visudet.html
#inline-replaced-height |
| 340 double intrinsicRatio = 0; | 340 double intrinsicRatio = 0; |
| 341 FloatSize constrainedSize; | 341 FloatSize constrainedSize; |
| 342 computeAspectRatioInformationForRenderBox(contentRenderer, constrainedSize,
intrinsicRatio); | 342 computeAspectRatioInformationForLayoutBox(contentRenderer, constrainedSize,
intrinsicRatio); |
| 343 | 343 |
| 344 bool widthIsAuto = style()->logicalWidth().isAuto(); | 344 bool widthIsAuto = style()->logicalWidth().isAuto(); |
| 345 bool hasIntrinsicHeight = constrainedSize.height() > 0; | 345 bool hasIntrinsicHeight = constrainedSize.height() > 0; |
| 346 | 346 |
| 347 // If 'height' and 'width' both have computed values of 'auto' and the eleme
nt also has an intrinsic height, then that intrinsic height is the used value of
'height'. | 347 // If 'height' and 'width' both have computed values of 'auto' and the eleme
nt also has an intrinsic height, then that intrinsic height is the used value of
'height'. |
| 348 if (widthIsAuto && hasIntrinsicHeight) | 348 if (widthIsAuto && hasIntrinsicHeight) |
| 349 return computeReplacedLogicalHeightRespectingMinMaxHeight(constrainedSiz
e.height()); | 349 return computeReplacedLogicalHeightRespectingMinMaxHeight(constrainedSiz
e.height()); |
| 350 | 350 |
| 351 // Otherwise, if 'height' has a computed value of 'auto', and the element ha
s an intrinsic ratio then the used value of 'height' is: | 351 // Otherwise, if 'height' has a computed value of 'auto', and the element ha
s an intrinsic ratio then the used value of 'height' is: |
| 352 // (used width) / (intrinsic ratio) | 352 // (used width) / (intrinsic ratio) |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 416 | 416 |
| 417 if (blockDirectionPosition >= bottom) | 417 if (blockDirectionPosition >= bottom) |
| 418 return createPositionWithAffinity(caretMaxOffset(), DOWNSTREAM); // coor
dinates are below | 418 return createPositionWithAffinity(caretMaxOffset(), DOWNSTREAM); // coor
dinates are below |
| 419 | 419 |
| 420 if (node()) { | 420 if (node()) { |
| 421 if (lineDirectionPosition <= logicalLeft() + (logicalWidth() / 2)) | 421 if (lineDirectionPosition <= logicalLeft() + (logicalWidth() / 2)) |
| 422 return createPositionWithAffinity(0, DOWNSTREAM); | 422 return createPositionWithAffinity(0, DOWNSTREAM); |
| 423 return createPositionWithAffinity(1, DOWNSTREAM); | 423 return createPositionWithAffinity(1, DOWNSTREAM); |
| 424 } | 424 } |
| 425 | 425 |
| 426 return RenderBox::positionForPoint(point); | 426 return LayoutBox::positionForPoint(point); |
| 427 } | 427 } |
| 428 | 428 |
| 429 LayoutRect LayoutReplaced::selectionRectForPaintInvalidation(const LayoutBoxMode
lObject* paintInvalidationContainer) const | 429 LayoutRect LayoutReplaced::selectionRectForPaintInvalidation(const LayoutBoxMode
lObject* paintInvalidationContainer) const |
| 430 { | 430 { |
| 431 ASSERT(!needsLayout()); | 431 ASSERT(!needsLayout()); |
| 432 | 432 |
| 433 if (!isSelected()) | 433 if (!isSelected()) |
| 434 return LayoutRect(); | 434 return LayoutRect(); |
| 435 | 435 |
| 436 LayoutRect rect = localSelectionRect(); | 436 LayoutRect rect = localSelectionRect(); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 454 RootInlineBox& root = inlineBoxWrapper()->root(); | 454 RootInlineBox& root = inlineBoxWrapper()->root(); |
| 455 LayoutUnit newLogicalTop = root.block().style()->isFlippedBlocksWritingMode(
) ? inlineBoxWrapper()->logicalBottom() - root.selectionBottom() : root.selectio
nTop() - inlineBoxWrapper()->logicalTop(); | 455 LayoutUnit newLogicalTop = root.block().style()->isFlippedBlocksWritingMode(
) ? inlineBoxWrapper()->logicalBottom() - root.selectionBottom() : root.selectio
nTop() - inlineBoxWrapper()->logicalTop(); |
| 456 if (root.block().style()->isHorizontalWritingMode()) | 456 if (root.block().style()->isHorizontalWritingMode()) |
| 457 return LayoutRect(0, newLogicalTop, size().width(), root.selectionHeight
()); | 457 return LayoutRect(0, newLogicalTop, size().width(), root.selectionHeight
()); |
| 458 return LayoutRect(newLogicalTop, 0, root.selectionHeight(), size().height())
; | 458 return LayoutRect(newLogicalTop, 0, root.selectionHeight(), size().height())
; |
| 459 } | 459 } |
| 460 | 460 |
| 461 void LayoutReplaced::setSelectionState(SelectionState state) | 461 void LayoutReplaced::setSelectionState(SelectionState state) |
| 462 { | 462 { |
| 463 // The selection state for our containing block hierarchy is updated by the
base class call. | 463 // The selection state for our containing block hierarchy is updated by the
base class call. |
| 464 RenderBox::setSelectionState(state); | 464 LayoutBox::setSelectionState(state); |
| 465 | 465 |
| 466 if (!inlineBoxWrapper()) | 466 if (!inlineBoxWrapper()) |
| 467 return; | 467 return; |
| 468 | 468 |
| 469 // We only include the space below the baseline in our layer's cached paint
invalidation rect if the | 469 // We only include the space below the baseline in our layer's cached paint
invalidation rect if the |
| 470 // image is selected. Since the selection state has changed update the rect. | 470 // image is selected. Since the selection state has changed update the rect. |
| 471 if (hasLayer()) | 471 if (hasLayer()) |
| 472 setPreviousPaintInvalidationRect(boundsRectForPaintInvalidation(containe
rForPaintInvalidation())); | 472 setPreviousPaintInvalidationRect(boundsRectForPaintInvalidation(containe
rForPaintInvalidation())); |
| 473 | 473 |
| 474 if (canUpdateSelectionOnRootLineBoxes()) | 474 if (canUpdateSelectionOnRootLineBoxes()) |
| (...skipping 28 matching lines...) Expand all Loading... |
| 503 return LayoutRect(); | 503 return LayoutRect(); |
| 504 | 504 |
| 505 // The selectionRect can project outside of the overflowRect, so take their
union | 505 // The selectionRect can project outside of the overflowRect, so take their
union |
| 506 // for paint invalidation to avoid selection painting glitches. | 506 // for paint invalidation to avoid selection painting glitches. |
| 507 LayoutRect r = isSelected() ? localSelectionRect() : visualOverflowRect(); | 507 LayoutRect r = isSelected() ? localSelectionRect() : visualOverflowRect(); |
| 508 mapRectToPaintInvalidationBacking(paintInvalidationContainer, r, paintInvali
dationState); | 508 mapRectToPaintInvalidationBacking(paintInvalidationContainer, r, paintInvali
dationState); |
| 509 return r; | 509 return r; |
| 510 } | 510 } |
| 511 | 511 |
| 512 } | 512 } |
| OLD | NEW |