| 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. |
| 11 * | 11 * |
| 12 * This library is distributed in the hope that it will be useful, | 12 * This library is distributed in the hope that it will be useful, |
| 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 * Library General Public License for more details. | 15 * Library General Public License for more details. |
| 16 * | 16 * |
| 17 * You should have received a copy of the GNU Library General Public License | 17 * You should have received a copy of the GNU Library General Public License |
| 18 * along with this library; see the file COPYING.LIB. If not, write to | 18 * along with this library; see the file COPYING.LIB. If not, write to |
| 19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 20 * Boston, MA 02110-1301, USA. | 20 * Boston, MA 02110-1301, USA. |
| 21 * | 21 * |
| 22 */ | 22 */ |
| 23 | 23 |
| 24 #include "config.h" | 24 #include "config.h" |
| 25 #include "core/rendering/RenderReplaced.h" | 25 #include "core/layout/LayoutReplaced.h" |
| 26 | 26 |
| 27 #include "core/editing/PositionWithAffinity.h" | 27 #include "core/editing/PositionWithAffinity.h" |
| 28 #include "core/layout/Layer.h" | 28 #include "core/layout/Layer.h" |
| 29 #include "core/layout/LayoutImage.h" | 29 #include "core/layout/LayoutImage.h" |
| 30 #include "core/paint/ReplacedPainter.h" | 30 #include "core/paint/ReplacedPainter.h" |
| 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 RenderReplaced::defaultWidth = 300; | 37 const int LayoutReplaced::defaultWidth = 300; |
| 38 const int RenderReplaced::defaultHeight = 150; | 38 const int LayoutReplaced::defaultHeight = 150; |
| 39 | 39 |
| 40 RenderReplaced::RenderReplaced(Element* element) | 40 LayoutReplaced::LayoutReplaced(Element* element) |
| 41 : RenderBox(element) | 41 : RenderBox(element) |
| 42 , m_intrinsicSize(defaultWidth, defaultHeight) | 42 , m_intrinsicSize(defaultWidth, defaultHeight) |
| 43 { | 43 { |
| 44 setReplaced(true); | 44 setReplaced(true); |
| 45 } | 45 } |
| 46 | 46 |
| 47 RenderReplaced::RenderReplaced(Element* element, const LayoutSize& intrinsicSize
) | 47 LayoutReplaced::LayoutReplaced(Element* element, const LayoutSize& intrinsicSize
) |
| 48 : RenderBox(element) | 48 : RenderBox(element) |
| 49 , m_intrinsicSize(intrinsicSize) | 49 , m_intrinsicSize(intrinsicSize) |
| 50 { | 50 { |
| 51 setReplaced(true); | 51 setReplaced(true); |
| 52 } | 52 } |
| 53 | 53 |
| 54 RenderReplaced::~RenderReplaced() | 54 LayoutReplaced::~LayoutReplaced() |
| 55 { | 55 { |
| 56 } | 56 } |
| 57 | 57 |
| 58 void RenderReplaced::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 RenderBox::willBeDestroyed(); |
| 64 } | 64 } |
| 65 | 65 |
| 66 void RenderReplaced::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 RenderBox::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 RenderReplaced::layout() | 76 void LayoutReplaced::layout() |
| 77 { | 77 { |
| 78 ASSERT(needsLayout()); | 78 ASSERT(needsLayout()); |
| 79 | 79 |
| 80 LayoutRect oldContentRect = replacedContentRect(); | 80 LayoutRect oldContentRect = replacedContentRect(); |
| 81 | 81 |
| 82 setHeight(minimumReplacedHeight()); | 82 setHeight(minimumReplacedHeight()); |
| 83 | 83 |
| 84 updateLogicalWidth(); | 84 updateLogicalWidth(); |
| 85 updateLogicalHeight(); | 85 updateLogicalHeight(); |
| 86 | 86 |
| 87 m_overflow.clear(); | 87 m_overflow.clear(); |
| 88 addVisualEffectOverflow(); | 88 addVisualEffectOverflow(); |
| 89 updateLayerTransformAfterLayout(); | 89 updateLayerTransformAfterLayout(); |
| 90 invalidateBackgroundObscurationStatus(); | 90 invalidateBackgroundObscurationStatus(); |
| 91 | 91 |
| 92 clearNeedsLayout(); | 92 clearNeedsLayout(); |
| 93 | 93 |
| 94 if (replacedContentRect() != oldContentRect) | 94 if (replacedContentRect() != oldContentRect) |
| 95 setShouldDoFullPaintInvalidation(); | 95 setShouldDoFullPaintInvalidation(); |
| 96 } | 96 } |
| 97 | 97 |
| 98 void RenderReplaced::intrinsicSizeChanged() | 98 void LayoutReplaced::intrinsicSizeChanged() |
| 99 { | 99 { |
| 100 int scaledWidth = static_cast<int>(defaultWidth * style()->effectiveZoom()); | 100 int scaledWidth = static_cast<int>(defaultWidth * style()->effectiveZoom()); |
| 101 int scaledHeight = static_cast<int>(defaultHeight * style()->effectiveZoom()
); | 101 int scaledHeight = static_cast<int>(defaultHeight * style()->effectiveZoom()
); |
| 102 m_intrinsicSize = LayoutSize(scaledWidth, scaledHeight); | 102 m_intrinsicSize = LayoutSize(scaledWidth, scaledHeight); |
| 103 setNeedsLayoutAndPrefWidthsRecalcAndFullPaintInvalidation(); | 103 setNeedsLayoutAndPrefWidthsRecalcAndFullPaintInvalidation(); |
| 104 } | 104 } |
| 105 | 105 |
| 106 void RenderReplaced::paint(const PaintInfo& paintInfo, const LayoutPoint& paintO
ffset) | 106 void LayoutReplaced::paint(const PaintInfo& paintInfo, const LayoutPoint& paintO
ffset) |
| 107 { | 107 { |
| 108 ReplacedPainter(*this).paint(paintInfo, paintOffset); | 108 ReplacedPainter(*this).paint(paintInfo, paintOffset); |
| 109 } | 109 } |
| 110 | 110 |
| 111 bool RenderReplaced::shouldPaint(const PaintInfo& paintInfo, const LayoutPoint&
paintOffset) const | 111 bool LayoutReplaced::shouldPaint(const PaintInfo& paintInfo, const LayoutPoint&
paintOffset) const |
| 112 { | 112 { |
| 113 if (paintInfo.phase != PaintPhaseForeground && paintInfo.phase != PaintPhase
Outline && paintInfo.phase != PaintPhaseSelfOutline | 113 if (paintInfo.phase != PaintPhaseForeground && paintInfo.phase != PaintPhase
Outline && paintInfo.phase != PaintPhaseSelfOutline |
| 114 && paintInfo.phase != PaintPhaseSelection && paintInfo.phase != PaintPha
seMask && paintInfo.phase != PaintPhaseClippingMask) | 114 && paintInfo.phase != PaintPhaseSelection && paintInfo.phase != PaintPha
seMask && paintInfo.phase != PaintPhaseClippingMask) |
| 115 return false; | 115 return false; |
| 116 | 116 |
| 117 if (!paintInfo.shouldPaintWithinRoot(this)) | 117 if (!paintInfo.shouldPaintWithinRoot(this)) |
| 118 return false; | 118 return false; |
| 119 | 119 |
| 120 // if we're invisible or haven't received a layout yet, then just bail. | 120 // if we're invisible or haven't received a layout yet, then just bail. |
| 121 if (style()->visibility() != VISIBLE) | 121 if (style()->visibility() != VISIBLE) |
| (...skipping 13 matching lines...) Expand all Loading... |
| 135 | 135 |
| 136 if (adjustedPaintOffset.x() + visualOverflowRect().x() >= paintInfo.rect.max
X() || adjustedPaintOffset.x() + visualOverflowRect().maxX() <= paintInfo.rect.x
()) | 136 if (adjustedPaintOffset.x() + visualOverflowRect().x() >= paintInfo.rect.max
X() || adjustedPaintOffset.x() + visualOverflowRect().maxX() <= paintInfo.rect.x
()) |
| 137 return false; | 137 return false; |
| 138 | 138 |
| 139 if (top >= paintInfo.rect.maxY() || bottom <= paintInfo.rect.y()) | 139 if (top >= paintInfo.rect.maxY() || bottom <= paintInfo.rect.y()) |
| 140 return false; | 140 return false; |
| 141 | 141 |
| 142 return true; | 142 return true; |
| 143 } | 143 } |
| 144 | 144 |
| 145 bool RenderReplaced::hasReplacedLogicalHeight() const | 145 bool LayoutReplaced::hasReplacedLogicalHeight() const |
| 146 { | 146 { |
| 147 if (style()->logicalHeight().isAuto()) | 147 if (style()->logicalHeight().isAuto()) |
| 148 return false; | 148 return false; |
| 149 | 149 |
| 150 if (style()->logicalHeight().isSpecified()) { | 150 if (style()->logicalHeight().isSpecified()) { |
| 151 if (hasAutoHeightOrContainingBlockWithAutoHeight()) | 151 if (hasAutoHeightOrContainingBlockWithAutoHeight()) |
| 152 return false; | 152 return false; |
| 153 return true; | 153 return true; |
| 154 } | 154 } |
| 155 | 155 |
| 156 if (style()->logicalHeight().isIntrinsic()) | 156 if (style()->logicalHeight().isIntrinsic()) |
| 157 return true; | 157 return true; |
| 158 | 158 |
| 159 return false; | 159 return false; |
| 160 } | 160 } |
| 161 | 161 |
| 162 bool RenderReplaced::needsPreferredWidthsRecalculation() const | 162 bool LayoutReplaced::needsPreferredWidthsRecalculation() const |
| 163 { | 163 { |
| 164 // If the height is a percentage and the width is auto, then the containingB
locks's height changing can cause | 164 // If the height is a percentage and the width is auto, then the containingB
locks's height changing can cause |
| 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 RenderReplaced::computeAspectRatioInformationForRenderBox(RenderBox* conten
tRenderer, FloatSize& constrainedSize, double& intrinsicRatio) const | 175 void LayoutReplaced::computeAspectRatioInformationForRenderBox(RenderBox* 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 22 matching lines...) Expand all Loading... |
| 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(RenderBox::computeReplacedLogicalHeight() * int
rinsicSize.width() / intrinsicSize.height()); |
| 214 constrainedSize.setHeight(RenderBox::computeReplacedLogicalWidth() * int
rinsicSize.height() / intrinsicSize.width()); | 214 constrainedSize.setHeight(RenderBox::computeReplacedLogicalWidth() * int
rinsicSize.height() / intrinsicSize.width()); |
| 215 } | 215 } |
| 216 } | 216 } |
| 217 | 217 |
| 218 LayoutRect RenderReplaced::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; |
| 225 } | 225 } |
| 226 | 226 |
| 227 LayoutSize intrinsicSize = overriddenIntrinsicSize ? *overriddenIntrinsicSiz
e : this->intrinsicSize(); | 227 LayoutSize intrinsicSize = overriddenIntrinsicSize ? *overriddenIntrinsicSiz
e : this->intrinsicSize(); |
| 228 if (!intrinsicSize.width() || !intrinsicSize.height()) | 228 if (!intrinsicSize.width() || !intrinsicSize.height()) |
| (...skipping 17 matching lines...) Expand all Loading... |
| 246 ASSERT_NOT_REACHED(); | 246 ASSERT_NOT_REACHED(); |
| 247 } | 247 } |
| 248 | 248 |
| 249 LayoutUnit xOffset = minimumValueForLength(style()->objectPosition().x(), co
ntentRect.width() - finalRect.width()); | 249 LayoutUnit xOffset = minimumValueForLength(style()->objectPosition().x(), co
ntentRect.width() - finalRect.width()); |
| 250 LayoutUnit yOffset = minimumValueForLength(style()->objectPosition().y(), co
ntentRect.height() - finalRect.height()); | 250 LayoutUnit yOffset = minimumValueForLength(style()->objectPosition().y(), co
ntentRect.height() - finalRect.height()); |
| 251 finalRect.move(xOffset, yOffset); | 251 finalRect.move(xOffset, yOffset); |
| 252 | 252 |
| 253 return finalRect; | 253 return finalRect; |
| 254 } | 254 } |
| 255 | 255 |
| 256 void RenderReplaced::computeIntrinsicRatioInformation(FloatSize& intrinsicSize,
double& intrinsicRatio) const | 256 void LayoutReplaced::computeIntrinsicRatioInformation(FloatSize& intrinsicSize,
double& intrinsicRatio) const |
| 257 { | 257 { |
| 258 // If there's an embeddedContentBox() of a remote, referenced document avail
able, this code-path should never be used. | 258 // If there's an embeddedContentBox() of a remote, referenced document avail
able, this code-path should never be used. |
| 259 ASSERT(!embeddedContentBox()); | 259 ASSERT(!embeddedContentBox()); |
| 260 intrinsicSize = FloatSize(intrinsicLogicalWidth().toFloat(), intrinsicLogica
lHeight().toFloat()); | 260 intrinsicSize = FloatSize(intrinsicLogicalWidth().toFloat(), intrinsicLogica
lHeight().toFloat()); |
| 261 | 261 |
| 262 // Figure out if we need to compute an intrinsic ratio. | 262 // Figure out if we need to compute an intrinsic ratio. |
| 263 if (intrinsicSize.isEmpty() || !rendererHasAspectRatio(this)) | 263 if (intrinsicSize.isEmpty() || !rendererHasAspectRatio(this)) |
| 264 return; | 264 return; |
| 265 | 265 |
| 266 intrinsicRatio = intrinsicSize.width() / intrinsicSize.height(); | 266 intrinsicRatio = intrinsicSize.width() / intrinsicSize.height(); |
| 267 } | 267 } |
| 268 | 268 |
| 269 LayoutUnit RenderReplaced::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 RenderBox* 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 computeAspectRatioInformationForRenderBox(contentRenderer, constrainedSize,
intrinsicRatio); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 // Otherwise, if 'width' has a computed value of 'auto', but none of the
conditions above are met, then the used value of 'width' becomes 300px. If 300p
x is too | 321 // Otherwise, if 'width' has a computed value of 'auto', but none of the
conditions above are met, then the used value of 'width' becomes 300px. If 300p
x is too |
| 322 // wide to fit the device, UAs should use the width of the largest recta
ngle that has a 2:1 ratio and fits the device instead. | 322 // wide to fit the device, UAs should use the width of the largest recta
ngle that has a 2:1 ratio and fits the device instead. |
| 323 // Note: We fall through and instead return intrinsicLogicalWidth() here
- to preserve existing WebKit behavior, which might or might not be correct, or
desired. | 323 // Note: We fall through and instead return intrinsicLogicalWidth() here
- to preserve existing WebKit behavior, which might or might not be correct, or
desired. |
| 324 // Changing this to return cDefaultWidth, will affect lots of test resul
ts. Eg. some tests assume that a blank <img> tag (which implies width/height=aut
o) | 324 // Changing this to return cDefaultWidth, will affect lots of test resul
ts. Eg. some tests assume that a blank <img> tag (which implies width/height=aut
o) |
| 325 // has no intrinsic size, which is wrong per CSS 2.1, but matches our be
havior since a long time. | 325 // has no intrinsic size, which is wrong per CSS 2.1, but matches our be
havior since a long time. |
| 326 } | 326 } |
| 327 | 327 |
| 328 return computeReplacedLogicalWidthRespectingMinMaxWidth(intrinsicLogicalWidt
h(), shouldComputePreferred); | 328 return computeReplacedLogicalWidthRespectingMinMaxWidth(intrinsicLogicalWidt
h(), shouldComputePreferred); |
| 329 } | 329 } |
| 330 | 330 |
| 331 LayoutUnit RenderReplaced::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 RenderBox* 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; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 355 | 355 |
| 356 // Otherwise, if 'height' has a computed value of 'auto', and the element ha
s an intrinsic height, then that intrinsic height is the used value of 'height'. | 356 // Otherwise, if 'height' has a computed value of 'auto', and the element ha
s an intrinsic height, then that intrinsic height is the used value of 'height'. |
| 357 if (hasIntrinsicHeight) | 357 if (hasIntrinsicHeight) |
| 358 return computeReplacedLogicalHeightRespectingMinMaxHeight(constrainedSiz
e.height()); | 358 return computeReplacedLogicalHeightRespectingMinMaxHeight(constrainedSiz
e.height()); |
| 359 | 359 |
| 360 // Otherwise, if 'height' has a computed value of 'auto', but none of the co
nditions above are met, then the used value of 'height' must be set to the heigh
t | 360 // Otherwise, if 'height' has a computed value of 'auto', but none of the co
nditions above are met, then the used value of 'height' must be set to the heigh
t |
| 361 // of the largest rectangle that has a 2:1 ratio, has a height not greater t
han 150px, and has a width not greater than the device width. | 361 // of the largest rectangle that has a 2:1 ratio, has a height not greater t
han 150px, and has a width not greater than the device width. |
| 362 return computeReplacedLogicalHeightRespectingMinMaxHeight(intrinsicLogicalHe
ight()); | 362 return computeReplacedLogicalHeightRespectingMinMaxHeight(intrinsicLogicalHe
ight()); |
| 363 } | 363 } |
| 364 | 364 |
| 365 void RenderReplaced::computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth,
LayoutUnit& maxLogicalWidth) const | 365 void LayoutReplaced::computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth,
LayoutUnit& maxLogicalWidth) const |
| 366 { | 366 { |
| 367 minLogicalWidth = maxLogicalWidth = intrinsicLogicalWidth(); | 367 minLogicalWidth = maxLogicalWidth = intrinsicLogicalWidth(); |
| 368 } | 368 } |
| 369 | 369 |
| 370 void RenderReplaced::computePreferredLogicalWidths() | 370 void LayoutReplaced::computePreferredLogicalWidths() |
| 371 { | 371 { |
| 372 ASSERT(preferredLogicalWidthsDirty()); | 372 ASSERT(preferredLogicalWidthsDirty()); |
| 373 | 373 |
| 374 // We cannot resolve any percent logical width here as the available logical | 374 // We cannot resolve any percent logical width here as the available logical |
| 375 // width may not be set on our containing block. | 375 // width may not be set on our containing block. |
| 376 if (style()->logicalWidth().isPercent()) | 376 if (style()->logicalWidth().isPercent()) |
| 377 computeIntrinsicLogicalWidths(m_minPreferredLogicalWidth, m_maxPreferred
LogicalWidth); | 377 computeIntrinsicLogicalWidths(m_minPreferredLogicalWidth, m_maxPreferred
LogicalWidth); |
| 378 else | 378 else |
| 379 m_minPreferredLogicalWidth = m_maxPreferredLogicalWidth = computeReplace
dLogicalWidth(ComputePreferred); | 379 m_minPreferredLogicalWidth = m_maxPreferredLogicalWidth = computeReplace
dLogicalWidth(ComputePreferred); |
| 380 | 380 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 392 m_minPreferredLogicalWidth = std::min(m_minPreferredLogicalWidth, adjust
ContentBoxLogicalWidthForBoxSizing(styleToUse.logicalMaxWidth().value())); | 392 m_minPreferredLogicalWidth = std::min(m_minPreferredLogicalWidth, adjust
ContentBoxLogicalWidthForBoxSizing(styleToUse.logicalMaxWidth().value())); |
| 393 } | 393 } |
| 394 | 394 |
| 395 LayoutUnit borderAndPadding = borderAndPaddingLogicalWidth(); | 395 LayoutUnit borderAndPadding = borderAndPaddingLogicalWidth(); |
| 396 m_minPreferredLogicalWidth += borderAndPadding; | 396 m_minPreferredLogicalWidth += borderAndPadding; |
| 397 m_maxPreferredLogicalWidth += borderAndPadding; | 397 m_maxPreferredLogicalWidth += borderAndPadding; |
| 398 | 398 |
| 399 clearPreferredLogicalWidthsDirty(); | 399 clearPreferredLogicalWidthsDirty(); |
| 400 } | 400 } |
| 401 | 401 |
| 402 PositionWithAffinity RenderReplaced::positionForPoint(const LayoutPoint& point) | 402 PositionWithAffinity LayoutReplaced::positionForPoint(const LayoutPoint& point) |
| 403 { | 403 { |
| 404 // FIXME: This code is buggy if the replaced element is relative positioned. | 404 // FIXME: This code is buggy if the replaced element is relative positioned. |
| 405 InlineBox* box = inlineBoxWrapper(); | 405 InlineBox* box = inlineBoxWrapper(); |
| 406 RootInlineBox* rootBox = box ? &box->root() : 0; | 406 RootInlineBox* rootBox = box ? &box->root() : 0; |
| 407 | 407 |
| 408 LayoutUnit top = rootBox ? rootBox->selectionTop() : logicalTop(); | 408 LayoutUnit top = rootBox ? rootBox->selectionTop() : logicalTop(); |
| 409 LayoutUnit bottom = rootBox ? rootBox->selectionBottom() : logicalBottom(); | 409 LayoutUnit bottom = rootBox ? rootBox->selectionBottom() : logicalBottom(); |
| 410 | 410 |
| 411 LayoutUnit blockDirectionPosition = isHorizontalWritingMode() ? point.y() +
location().y() : point.x() + location().x(); | 411 LayoutUnit blockDirectionPosition = isHorizontalWritingMode() ? point.y() +
location().y() : point.x() + location().x(); |
| 412 LayoutUnit lineDirectionPosition = isHorizontalWritingMode() ? point.x() + l
ocation().x() : point.y() + location().y(); | 412 LayoutUnit lineDirectionPosition = isHorizontalWritingMode() ? point.x() + l
ocation().x() : point.y() + location().y(); |
| 413 | 413 |
| 414 if (blockDirectionPosition < top) | 414 if (blockDirectionPosition < top) |
| 415 return createPositionWithAffinity(caretMinOffset(), DOWNSTREAM); // coor
dinates are above | 415 return createPositionWithAffinity(caretMinOffset(), DOWNSTREAM); // coor
dinates are above |
| 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 RenderBox::positionForPoint(point); |
| 427 } | 427 } |
| 428 | 428 |
| 429 LayoutRect RenderReplaced::selectionRectForPaintInvalidation(const LayoutLayerMo
delObject* paintInvalidationContainer) const | 429 LayoutRect LayoutReplaced::selectionRectForPaintInvalidation(const LayoutLayerMo
delObject* 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(); |
| 437 mapRectToPaintInvalidationBacking(paintInvalidationContainer, rect, 0); | 437 mapRectToPaintInvalidationBacking(paintInvalidationContainer, rect, 0); |
| 438 // FIXME: groupedMapping() leaks the squashing abstraction. | 438 // FIXME: groupedMapping() leaks the squashing abstraction. |
| 439 if (paintInvalidationContainer->layer()->groupedMapping()) | 439 if (paintInvalidationContainer->layer()->groupedMapping()) |
| 440 Layer::mapRectToPaintBackingCoordinates(paintInvalidationContainer, rect
); | 440 Layer::mapRectToPaintBackingCoordinates(paintInvalidationContainer, rect
); |
| 441 return rect; | 441 return rect; |
| 442 } | 442 } |
| 443 | 443 |
| 444 LayoutRect RenderReplaced::localSelectionRect(bool checkWhetherSelected) const | 444 LayoutRect LayoutReplaced::localSelectionRect(bool checkWhetherSelected) const |
| 445 { | 445 { |
| 446 if (checkWhetherSelected && !isSelected()) | 446 if (checkWhetherSelected && !isSelected()) |
| 447 return LayoutRect(); | 447 return LayoutRect(); |
| 448 | 448 |
| 449 if (!inlineBoxWrapper()) | 449 if (!inlineBoxWrapper()) { |
| 450 // We're a block-level replaced element. Just return our own dimensions
. | 450 // We're a block-level replaced element. Just return our own dimensions
. |
| 451 return LayoutRect(LayoutPoint(), size()); | 451 return LayoutRect(LayoutPoint(), size()); |
| 452 } |
| 452 | 453 |
| 453 RootInlineBox& root = inlineBoxWrapper()->root(); | 454 RootInlineBox& root = inlineBoxWrapper()->root(); |
| 454 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(); |
| 455 if (root.block().style()->isHorizontalWritingMode()) | 456 if (root.block().style()->isHorizontalWritingMode()) |
| 456 return LayoutRect(0, newLogicalTop, size().width(), root.selectionHeight
()); | 457 return LayoutRect(0, newLogicalTop, size().width(), root.selectionHeight
()); |
| 457 return LayoutRect(newLogicalTop, 0, root.selectionHeight(), size().height())
; | 458 return LayoutRect(newLogicalTop, 0, root.selectionHeight(), size().height())
; |
| 458 } | 459 } |
| 459 | 460 |
| 460 void RenderReplaced::setSelectionState(SelectionState state) | 461 void LayoutReplaced::setSelectionState(SelectionState state) |
| 461 { | 462 { |
| 462 // 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. |
| 463 RenderBox::setSelectionState(state); | 464 RenderBox::setSelectionState(state); |
| 464 | 465 |
| 465 if (!inlineBoxWrapper()) | 466 if (!inlineBoxWrapper()) |
| 466 return; | 467 return; |
| 467 | 468 |
| 468 // 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 |
| 469 // 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. |
| 470 if (hasLayer()) | 471 if (hasLayer()) |
| 471 setPreviousPaintInvalidationRect(boundsRectForPaintInvalidation(containe
rForPaintInvalidation())); | 472 setPreviousPaintInvalidationRect(boundsRectForPaintInvalidation(containe
rForPaintInvalidation())); |
| 472 | 473 |
| 473 if (canUpdateSelectionOnRootLineBoxes()) | 474 if (canUpdateSelectionOnRootLineBoxes()) |
| 474 inlineBoxWrapper()->root().setHasSelectedChildren(isSelected()); | 475 inlineBoxWrapper()->root().setHasSelectedChildren(isSelected()); |
| 475 } | 476 } |
| 476 | 477 |
| 477 bool RenderReplaced::isSelected() const | 478 bool LayoutReplaced::isSelected() const |
| 478 { | 479 { |
| 479 SelectionState s = selectionState(); | 480 SelectionState s = selectionState(); |
| 480 if (s == SelectionNone) | 481 if (s == SelectionNone) |
| 481 return false; | 482 return false; |
| 482 if (s == SelectionInside) | 483 if (s == SelectionInside) |
| 483 return true; | 484 return true; |
| 484 | 485 |
| 485 int selectionStart, selectionEnd; | 486 int selectionStart, selectionEnd; |
| 486 selectionStartEnd(selectionStart, selectionEnd); | 487 selectionStartEnd(selectionStart, selectionEnd); |
| 487 if (s == SelectionStart) | 488 if (s == SelectionStart) |
| 488 return selectionStart == 0; | 489 return selectionStart == 0; |
| 489 | 490 |
| 490 int end = node()->hasChildren() ? node()->countChildren() : 1; | 491 int end = node()->hasChildren() ? node()->countChildren() : 1; |
| 491 if (s == SelectionEnd) | 492 if (s == SelectionEnd) |
| 492 return selectionEnd == end; | 493 return selectionEnd == end; |
| 493 if (s == SelectionBoth) | 494 if (s == SelectionBoth) |
| 494 return selectionStart == 0 && selectionEnd == end; | 495 return selectionStart == 0 && selectionEnd == end; |
| 495 | 496 |
| 496 ASSERT(0); | 497 ASSERT(0); |
| 497 return false; | 498 return false; |
| 498 } | 499 } |
| 499 LayoutRect RenderReplaced::clippedOverflowRectForPaintInvalidation(const LayoutL
ayerModelObject* paintInvalidationContainer, const PaintInvalidationState* paint
InvalidationState) const | 500 LayoutRect LayoutReplaced::clippedOverflowRectForPaintInvalidation(const LayoutL
ayerModelObject* paintInvalidationContainer, const PaintInvalidationState* paint
InvalidationState) const |
| 500 { | 501 { |
| 501 if (style()->visibility() != VISIBLE && !enclosingLayer()->hasVisibleContent
()) | 502 if (style()->visibility() != VISIBLE && !enclosingLayer()->hasVisibleContent
()) |
| 502 return LayoutRect(); | 503 return LayoutRect(); |
| 503 | 504 |
| 504 // 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 |
| 505 // for paint invalidation to avoid selection painting glitches. | 506 // for paint invalidation to avoid selection painting glitches. |
| 506 LayoutRect r = isSelected() ? localSelectionRect() : visualOverflowRect(); | 507 LayoutRect r = isSelected() ? localSelectionRect() : visualOverflowRect(); |
| 507 mapRectToPaintInvalidationBacking(paintInvalidationContainer, r, paintInvali
dationState); | 508 mapRectToPaintInvalidationBacking(paintInvalidationContainer, r, paintInvali
dationState); |
| 508 return r; | 509 return r; |
| 509 } | 510 } |
| 510 | 511 |
| 511 } | 512 } |
| OLD | NEW |