| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Adobe Systems Incorporated. All rights reserved. | 2 * Copyright (C) 2012 Adobe Systems Incorporated. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above | 8 * 1. Redistributions of source code must retain the above |
| 9 * copyright notice, this list of conditions and the following | 9 * copyright notice, this list of conditions and the following |
| 10 * disclaimer. | 10 * disclaimer. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF | 25 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF |
| 26 * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 26 * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 27 * SUCH DAMAGE. | 27 * SUCH DAMAGE. |
| 28 */ | 28 */ |
| 29 | 29 |
| 30 #include "config.h" | 30 #include "config.h" |
| 31 #include "core/layout/shapes/ShapeOutsideInfo.h" | 31 #include "core/layout/shapes/ShapeOutsideInfo.h" |
| 32 | 32 |
| 33 #include "core/inspector/ConsoleMessage.h" | 33 #include "core/inspector/ConsoleMessage.h" |
| 34 #include "core/layout/FloatingObjects.h" | 34 #include "core/layout/FloatingObjects.h" |
| 35 #include "core/layout/LayoutBox.h" |
| 35 #include "core/layout/LayoutImage.h" | 36 #include "core/layout/LayoutImage.h" |
| 36 #include "core/rendering/RenderBlockFlow.h" | 37 #include "core/rendering/RenderBlockFlow.h" |
| 37 #include "core/rendering/RenderBox.h" | |
| 38 #include "platform/LengthFunctions.h" | 38 #include "platform/LengthFunctions.h" |
| 39 #include "public/platform/Platform.h" | 39 #include "public/platform/Platform.h" |
| 40 | 40 |
| 41 namespace blink { | 41 namespace blink { |
| 42 | 42 |
| 43 CSSBoxType referenceBox(const ShapeValue& shapeValue) | 43 CSSBoxType referenceBox(const ShapeValue& shapeValue) |
| 44 { | 44 { |
| 45 if (shapeValue.cssBox() == BoxMissing) | 45 if (shapeValue.cssBox() == BoxMissing) |
| 46 return MarginBox; | 46 return MarginBox; |
| 47 return shapeValue.cssBox(); | 47 return shapeValue.cssBox(); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 if (imageResource.isAccessAllowed(&document, document.securityOrigin())) | 92 if (imageResource.isAccessAllowed(&document, document.securityOrigin())) |
| 93 return true; | 93 return true; |
| 94 | 94 |
| 95 const KURL& url = imageResource.url(); | 95 const KURL& url = imageResource.url(); |
| 96 String urlString = url.isNull() ? "''" : url.elidedString(); | 96 String urlString = url.isNull() ? "''" : url.elidedString(); |
| 97 document.addConsoleMessage(ConsoleMessage::create(SecurityMessageSource, Err
orMessageLevel, "Unsafe attempt to load URL " + urlString + ".")); | 97 document.addConsoleMessage(ConsoleMessage::create(SecurityMessageSource, Err
orMessageLevel, "Unsafe attempt to load URL " + urlString + ".")); |
| 98 | 98 |
| 99 return false; | 99 return false; |
| 100 } | 100 } |
| 101 | 101 |
| 102 static LayoutRect getShapeImageMarginRect(const RenderBox& renderBox, const Layo
utSize& referenceBoxLogicalSize) | 102 static LayoutRect getShapeImageMarginRect(const LayoutBox& layoutBox, const Layo
utSize& referenceBoxLogicalSize) |
| 103 { | 103 { |
| 104 LayoutPoint marginBoxOrigin(-renderBox.marginLogicalLeft() - renderBox.borde
rAndPaddingLogicalLeft(), -renderBox.marginBefore() - renderBox.borderBefore() -
renderBox.paddingBefore()); | 104 LayoutPoint marginBoxOrigin(-layoutBox.marginLogicalLeft() - layoutBox.borde
rAndPaddingLogicalLeft(), -layoutBox.marginBefore() - layoutBox.borderBefore() -
layoutBox.paddingBefore()); |
| 105 LayoutSize marginBoxSizeDelta(renderBox.marginLogicalWidth() + renderBox.bor
derAndPaddingLogicalWidth(), renderBox.marginLogicalHeight() + renderBox.borderA
ndPaddingLogicalHeight()); | 105 LayoutSize marginBoxSizeDelta(layoutBox.marginLogicalWidth() + layoutBox.bor
derAndPaddingLogicalWidth(), layoutBox.marginLogicalHeight() + layoutBox.borderA
ndPaddingLogicalHeight()); |
| 106 LayoutSize marginRectSize(referenceBoxLogicalSize + marginBoxSizeDelta); | 106 LayoutSize marginRectSize(referenceBoxLogicalSize + marginBoxSizeDelta); |
| 107 marginRectSize.clampNegativeToZero(); | 107 marginRectSize.clampNegativeToZero(); |
| 108 return LayoutRect(marginBoxOrigin, marginRectSize); | 108 return LayoutRect(marginBoxOrigin, marginRectSize); |
| 109 } | 109 } |
| 110 | 110 |
| 111 static bool isValidRasterShapeRect(const LayoutRect& rect) | 111 static bool isValidRasterShapeRect(const LayoutRect& rect) |
| 112 { | 112 { |
| 113 static double maxImageSizeBytes = 0; | 113 static double maxImageSizeBytes = 0; |
| 114 if (!maxImageSizeBytes) { | 114 if (!maxImageSizeBytes) { |
| 115 size_t size32MaxBytes = 0xFFFFFFFF / 4; // Some platforms don't limit m
axDecodedImageBytes. | 115 size_t size32MaxBytes = 0xFFFFFFFF / 4; // Some platforms don't limit m
axDecodedImageBytes. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 127 const LayoutRect& imageRect = (m_renderer.isLayoutImage()) | 127 const LayoutRect& imageRect = (m_renderer.isLayoutImage()) |
| 128 ? toLayoutImage(m_renderer).replacedContentRect() | 128 ? toLayoutImage(m_renderer).replacedContentRect() |
| 129 : LayoutRect(LayoutPoint(), LayoutSize(imageSize)); | 129 : LayoutRect(LayoutPoint(), LayoutSize(imageSize)); |
| 130 | 130 |
| 131 if (!isValidRasterShapeRect(marginRect) || !isValidRasterShapeRect(imageRect
)) { | 131 if (!isValidRasterShapeRect(marginRect) || !isValidRasterShapeRect(imageRect
)) { |
| 132 m_renderer.document().addConsoleMessage(ConsoleMessage::create(Rendering
MessageSource, ErrorMessageLevel, "The shape-outside image is too large.")); | 132 m_renderer.document().addConsoleMessage(ConsoleMessage::create(Rendering
MessageSource, ErrorMessageLevel, "The shape-outside image is too large.")); |
| 133 return Shape::createEmptyRasterShape(writingMode, margin); | 133 return Shape::createEmptyRasterShape(writingMode, margin); |
| 134 } | 134 } |
| 135 | 135 |
| 136 ASSERT(!styleImage->isPendingImage()); | 136 ASSERT(!styleImage->isPendingImage()); |
| 137 RefPtr<Image> image = styleImage->image(const_cast<RenderBox*>(&m_renderer),
imageSize); | 137 RefPtr<Image> image = styleImage->image(const_cast<LayoutBox*>(&m_renderer),
imageSize); |
| 138 | 138 |
| 139 return Shape::createRasterShape(image.get(), shapeImageThreshold, imageRect,
marginRect, writingMode, margin); | 139 return Shape::createRasterShape(image.get(), shapeImageThreshold, imageRect,
marginRect, writingMode, margin); |
| 140 } | 140 } |
| 141 | 141 |
| 142 const Shape& ShapeOutsideInfo::computedShape() const | 142 const Shape& ShapeOutsideInfo::computedShape() const |
| 143 { | 143 { |
| 144 if (Shape* shape = m_shape.get()) | 144 if (Shape* shape = m_shape.get()) |
| 145 return *shape; | 145 return *shape; |
| 146 | 146 |
| 147 TemporaryChange<bool> isInComputingShape(m_isComputingShape, true); | 147 TemporaryChange<bool> isInComputingShape(m_isComputingShape, true); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 171 const FloatRoundedRect& shapeRect = style.getRoundedBorderFor(LayoutRect
(LayoutPoint(), m_referenceBoxLogicalSize), m_renderer.view()); | 171 const FloatRoundedRect& shapeRect = style.getRoundedBorderFor(LayoutRect
(LayoutPoint(), m_referenceBoxLogicalSize), m_renderer.view()); |
| 172 m_shape = Shape::createLayoutBoxShape(shapeRect, writingMode, margin); | 172 m_shape = Shape::createLayoutBoxShape(shapeRect, writingMode, margin); |
| 173 break; | 173 break; |
| 174 } | 174 } |
| 175 } | 175 } |
| 176 | 176 |
| 177 ASSERT(m_shape); | 177 ASSERT(m_shape); |
| 178 return *m_shape; | 178 return *m_shape; |
| 179 } | 179 } |
| 180 | 180 |
| 181 inline LayoutUnit borderBeforeInWritingMode(const RenderBox& renderer, WritingMo
de writingMode) | 181 inline LayoutUnit borderBeforeInWritingMode(const LayoutBox& renderer, WritingMo
de writingMode) |
| 182 { | 182 { |
| 183 switch (writingMode) { | 183 switch (writingMode) { |
| 184 case TopToBottomWritingMode: return renderer.borderTop(); | 184 case TopToBottomWritingMode: return renderer.borderTop(); |
| 185 case BottomToTopWritingMode: return renderer.borderBottom(); | 185 case BottomToTopWritingMode: return renderer.borderBottom(); |
| 186 case LeftToRightWritingMode: return renderer.borderLeft(); | 186 case LeftToRightWritingMode: return renderer.borderLeft(); |
| 187 case RightToLeftWritingMode: return renderer.borderRight(); | 187 case RightToLeftWritingMode: return renderer.borderRight(); |
| 188 } | 188 } |
| 189 | 189 |
| 190 ASSERT_NOT_REACHED(); | 190 ASSERT_NOT_REACHED(); |
| 191 return renderer.borderBefore(); | 191 return renderer.borderBefore(); |
| 192 } | 192 } |
| 193 | 193 |
| 194 inline LayoutUnit borderAndPaddingBeforeInWritingMode(const RenderBox& renderer,
WritingMode writingMode) | 194 inline LayoutUnit borderAndPaddingBeforeInWritingMode(const LayoutBox& renderer,
WritingMode writingMode) |
| 195 { | 195 { |
| 196 switch (writingMode) { | 196 switch (writingMode) { |
| 197 case TopToBottomWritingMode: return renderer.borderTop() + renderer.paddingT
op(); | 197 case TopToBottomWritingMode: return renderer.borderTop() + renderer.paddingT
op(); |
| 198 case BottomToTopWritingMode: return renderer.borderBottom() + renderer.paddi
ngBottom(); | 198 case BottomToTopWritingMode: return renderer.borderBottom() + renderer.paddi
ngBottom(); |
| 199 case LeftToRightWritingMode: return renderer.borderLeft() + renderer.padding
Left(); | 199 case LeftToRightWritingMode: return renderer.borderLeft() + renderer.padding
Left(); |
| 200 case RightToLeftWritingMode: return renderer.borderRight() + renderer.paddin
gRight(); | 200 case RightToLeftWritingMode: return renderer.borderRight() + renderer.paddin
gRight(); |
| 201 } | 201 } |
| 202 | 202 |
| 203 ASSERT_NOT_REACHED(); | 203 ASSERT_NOT_REACHED(); |
| 204 return renderer.borderAndPaddingBefore(); | 204 return renderer.borderAndPaddingBefore(); |
| 205 } | 205 } |
| 206 | 206 |
| 207 LayoutUnit ShapeOutsideInfo::logicalTopOffset() const | 207 LayoutUnit ShapeOutsideInfo::logicalTopOffset() const |
| 208 { | 208 { |
| 209 switch (referenceBox(*m_renderer.style()->shapeOutside())) { | 209 switch (referenceBox(*m_renderer.style()->shapeOutside())) { |
| 210 case MarginBox: return -m_renderer.marginBefore(m_renderer.containingBlock()
->style()); | 210 case MarginBox: return -m_renderer.marginBefore(m_renderer.containingBlock()
->style()); |
| 211 case BorderBox: return LayoutUnit(); | 211 case BorderBox: return LayoutUnit(); |
| 212 case PaddingBox: return borderBeforeInWritingMode(m_renderer, m_renderer.con
tainingBlock()->style()->writingMode()); | 212 case PaddingBox: return borderBeforeInWritingMode(m_renderer, m_renderer.con
tainingBlock()->style()->writingMode()); |
| 213 case ContentBox: return borderAndPaddingBeforeInWritingMode(m_renderer, m_re
nderer.containingBlock()->style()->writingMode()); | 213 case ContentBox: return borderAndPaddingBeforeInWritingMode(m_renderer, m_re
nderer.containingBlock()->style()->writingMode()); |
| 214 case BoxMissing: break; | 214 case BoxMissing: break; |
| 215 } | 215 } |
| 216 | 216 |
| 217 ASSERT_NOT_REACHED(); | 217 ASSERT_NOT_REACHED(); |
| 218 return LayoutUnit(); | 218 return LayoutUnit(); |
| 219 } | 219 } |
| 220 | 220 |
| 221 inline LayoutUnit borderStartWithStyleForWritingMode(const RenderBox& renderer,
const LayoutStyle* style) | 221 inline LayoutUnit borderStartWithStyleForWritingMode(const LayoutBox& renderer,
const LayoutStyle* style) |
| 222 { | 222 { |
| 223 if (style->isHorizontalWritingMode()) { | 223 if (style->isHorizontalWritingMode()) { |
| 224 if (style->isLeftToRightDirection()) | 224 if (style->isLeftToRightDirection()) |
| 225 return renderer.borderLeft(); | 225 return renderer.borderLeft(); |
| 226 | 226 |
| 227 return renderer.borderRight(); | 227 return renderer.borderRight(); |
| 228 } | 228 } |
| 229 if (style->isLeftToRightDirection()) | 229 if (style->isLeftToRightDirection()) |
| 230 return renderer.borderTop(); | 230 return renderer.borderTop(); |
| 231 | 231 |
| 232 return renderer.borderBottom(); | 232 return renderer.borderBottom(); |
| 233 } | 233 } |
| 234 | 234 |
| 235 inline LayoutUnit borderAndPaddingStartWithStyleForWritingMode(const RenderBox&
renderer, const LayoutStyle* style) | 235 inline LayoutUnit borderAndPaddingStartWithStyleForWritingMode(const LayoutBox&
renderer, const LayoutStyle* style) |
| 236 { | 236 { |
| 237 if (style->isHorizontalWritingMode()) { | 237 if (style->isHorizontalWritingMode()) { |
| 238 if (style->isLeftToRightDirection()) | 238 if (style->isLeftToRightDirection()) |
| 239 return renderer.borderLeft() + renderer.paddingLeft(); | 239 return renderer.borderLeft() + renderer.paddingLeft(); |
| 240 | 240 |
| 241 return renderer.borderRight() + renderer.paddingRight(); | 241 return renderer.borderRight() + renderer.paddingRight(); |
| 242 } | 242 } |
| 243 if (style->isLeftToRightDirection()) | 243 if (style->isLeftToRightDirection()) |
| 244 return renderer.borderTop() + renderer.paddingTop(); | 244 return renderer.borderTop() + renderer.paddingTop(); |
| 245 | 245 |
| 246 return renderer.borderBottom() + renderer.paddingBottom(); | 246 return renderer.borderBottom() + renderer.paddingBottom(); |
| 247 } | 247 } |
| 248 | 248 |
| 249 LayoutUnit ShapeOutsideInfo::logicalLeftOffset() const | 249 LayoutUnit ShapeOutsideInfo::logicalLeftOffset() const |
| 250 { | 250 { |
| 251 switch (referenceBox(*m_renderer.style()->shapeOutside())) { | 251 switch (referenceBox(*m_renderer.style()->shapeOutside())) { |
| 252 case MarginBox: return -m_renderer.marginStart(m_renderer.containingBlock()-
>style()); | 252 case MarginBox: return -m_renderer.marginStart(m_renderer.containingBlock()-
>style()); |
| 253 case BorderBox: return LayoutUnit(); | 253 case BorderBox: return LayoutUnit(); |
| 254 case PaddingBox: return borderStartWithStyleForWritingMode(m_renderer, m_ren
derer.containingBlock()->style()); | 254 case PaddingBox: return borderStartWithStyleForWritingMode(m_renderer, m_ren
derer.containingBlock()->style()); |
| 255 case ContentBox: return borderAndPaddingStartWithStyleForWritingMode(m_rende
rer, m_renderer.containingBlock()->style()); | 255 case ContentBox: return borderAndPaddingStartWithStyleForWritingMode(m_rende
rer, m_renderer.containingBlock()->style()); |
| 256 case BoxMissing: break; | 256 case BoxMissing: break; |
| 257 } | 257 } |
| 258 | 258 |
| 259 ASSERT_NOT_REACHED(); | 259 ASSERT_NOT_REACHED(); |
| 260 return LayoutUnit(); | 260 return LayoutUnit(); |
| 261 } | 261 } |
| 262 | 262 |
| 263 | 263 |
| 264 bool ShapeOutsideInfo::isEnabledFor(const RenderBox& box) | 264 bool ShapeOutsideInfo::isEnabledFor(const LayoutBox& box) |
| 265 { | 265 { |
| 266 ShapeValue* shapeValue = box.style()->shapeOutside(); | 266 ShapeValue* shapeValue = box.style()->shapeOutside(); |
| 267 if (!box.isFloating() || !shapeValue) | 267 if (!box.isFloating() || !shapeValue) |
| 268 return false; | 268 return false; |
| 269 | 269 |
| 270 switch (shapeValue->type()) { | 270 switch (shapeValue->type()) { |
| 271 case ShapeValue::Shape: | 271 case ShapeValue::Shape: |
| 272 return shapeValue->shape(); | 272 return shapeValue->shape(); |
| 273 case ShapeValue::Image: | 273 case ShapeValue::Image: |
| 274 return shapeValue->isImageValid() && checkShapeImageOrigin(box.document(
), *(shapeValue->image())); | 274 return shapeValue->isImageValid() && checkShapeImageOrigin(box.document(
), *(shapeValue->image())); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 } | 343 } |
| 344 | 344 |
| 345 FloatSize ShapeOutsideInfo::shapeToRendererSize(FloatSize size) const | 345 FloatSize ShapeOutsideInfo::shapeToRendererSize(FloatSize size) const |
| 346 { | 346 { |
| 347 if (!m_renderer.style()->isHorizontalWritingMode()) | 347 if (!m_renderer.style()->isHorizontalWritingMode()) |
| 348 return size.transposedSize(); | 348 return size.transposedSize(); |
| 349 return size; | 349 return size; |
| 350 } | 350 } |
| 351 | 351 |
| 352 } // namespace blink | 352 } // namespace blink |
| OLD | NEW |