Chromium Code Reviews| 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 14 matching lines...) Expand all Loading... | |
| 25 #include "core/layout/LayoutReplaced.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/LayoutAnalyzer.h" | 28 #include "core/layout/LayoutAnalyzer.h" |
| 29 #include "core/layout/LayoutBlock.h" | 29 #include "core/layout/LayoutBlock.h" |
| 30 #include "core/layout/LayoutImage.h" | 30 #include "core/layout/LayoutImage.h" |
| 31 #include "core/layout/LayoutView.h" | 31 #include "core/layout/LayoutView.h" |
| 32 #include "core/paint/PaintInfo.h" | 32 #include "core/paint/PaintInfo.h" |
| 33 #include "core/paint/PaintLayer.h" | 33 #include "core/paint/PaintLayer.h" |
| 34 #include "core/paint/ReplacedPainter.h" | 34 #include "core/paint/ReplacedPainter.h" |
| 35 #include "core/svg/SVGSVGElement.h" | |
| 35 #include "platform/LengthFunctions.h" | 36 #include "platform/LengthFunctions.h" |
| 36 | 37 |
| 37 namespace blink { | 38 namespace blink { |
| 38 | 39 |
| 39 const int LayoutReplaced::defaultWidth = 300; | 40 const int LayoutReplaced::defaultWidth = 300; |
| 40 const int LayoutReplaced::defaultHeight = 150; | 41 const int LayoutReplaced::defaultHeight = 150; |
| 41 | 42 |
| 42 LayoutReplaced::LayoutReplaced(Element* element) | 43 LayoutReplaced::LayoutReplaced(Element* element) |
| 43 : LayoutBox(element) | 44 : LayoutBox(element) |
| 44 , m_intrinsicSize(defaultWidth, defaultHeight) | 45 , m_intrinsicSize(defaultWidth, defaultHeight) |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 259 ASSERT(!embeddedContentBox()); | 260 ASSERT(!embeddedContentBox()); |
| 260 intrinsicSize = FloatSize(intrinsicLogicalWidth().toFloat(), intrinsicLogica lHeight().toFloat()); | 261 intrinsicSize = FloatSize(intrinsicLogicalWidth().toFloat(), intrinsicLogica lHeight().toFloat()); |
| 261 | 262 |
| 262 // Figure out if we need to compute an intrinsic ratio. | 263 // Figure out if we need to compute an intrinsic ratio. |
| 263 if (intrinsicSize.isEmpty() || !layoutObjectHasAspectRatio(this)) | 264 if (intrinsicSize.isEmpty() || !layoutObjectHasAspectRatio(this)) |
| 264 return; | 265 return; |
| 265 | 266 |
| 266 intrinsicRatio = intrinsicSize.width() / intrinsicSize.height(); | 267 intrinsicRatio = intrinsicSize.width() / intrinsicSize.height(); |
| 267 } | 268 } |
| 268 | 269 |
| 270 static bool hasIntrinsicWidthForLayoutBox(LayoutBox* layoutObject) | |
| 271 { | |
| 272 if (layoutObject && layoutObject->isSVGRoot()) { | |
| 273 SVGSVGElement* svg = toSVGSVGElement(layoutObject->node()); | |
| 274 ASSERT(svg); | |
| 275 return svg->hasIntrinsicWidth(); | |
| 276 } | |
| 277 | |
| 278 return false; | |
| 279 } | |
| 280 | |
| 281 static bool hasIntrinsicHeightForLayoutBox(LayoutBox* layoutObject) | |
| 282 { | |
| 283 if (layoutObject && layoutObject->isSVGRoot()) { | |
| 284 SVGSVGElement* svg = toSVGSVGElement(layoutObject->node()); | |
| 285 ASSERT(svg); | |
| 286 return svg->hasIntrinsicHeight(); | |
| 287 } | |
| 288 | |
| 289 return false; | |
| 290 } | |
| 291 | |
| 269 LayoutUnit LayoutReplaced::computeReplacedLogicalWidth(ShouldComputePreferred sh ouldComputePreferred) const | 292 LayoutUnit LayoutReplaced::computeReplacedLogicalWidth(ShouldComputePreferred sh ouldComputePreferred) const |
| 270 { | 293 { |
| 271 if (style()->logicalWidth().isSpecified() || style()->logicalWidth().isIntri nsic()) | 294 if (style()->logicalWidth().isSpecified() || style()->logicalWidth().isIntri nsic()) |
| 272 return computeReplacedLogicalWidthRespectingMinMaxWidth(computeReplacedL ogicalWidthUsing(MainOrPreferredSize, style()->logicalWidth()), shouldComputePre ferred); | 295 return computeReplacedLogicalWidthRespectingMinMaxWidth(computeReplacedL ogicalWidthUsing(MainOrPreferredSize, style()->logicalWidth()), shouldComputePre ferred); |
| 273 | 296 |
| 274 LayoutBox* contentLayoutObject = embeddedContentBox(); | 297 LayoutBox* contentLayoutObject = embeddedContentBox(); |
| 275 | 298 |
| 276 // 10.3.2 Inline, replaced elements: http://www.w3.org/TR/CSS21/visudet.html #inline-replaced-width | 299 // 10.3.2 Inline, replaced elements: http://www.w3.org/TR/CSS21/visudet.html #inline-replaced-width |
| 277 double intrinsicRatio = 0; | 300 double intrinsicRatio = 0; |
| 278 FloatSize constrainedSize; | 301 FloatSize constrainedSize; |
| 279 computeAspectRatioInformationForLayoutBox(contentLayoutObject, constrainedSi ze, intrinsicRatio); | 302 computeAspectRatioInformationForLayoutBox(contentLayoutObject, constrainedSi ze, intrinsicRatio); |
| 280 | 303 |
| 281 if (style()->logicalWidth().isAuto()) { | 304 if (style()->logicalWidth().isAuto()) { |
| 282 bool computedHeightIsAuto = hasAutoHeightOrContainingBlockWithAutoHeight (); | 305 bool computedHeightIsAuto = hasAutoHeightOrContainingBlockWithAutoHeight (); |
| 283 bool hasIntrinsicWidth = constrainedSize.width() > 0; | 306 bool hasIntrinsicWidth = constrainedSize.width() > 0 || hasIntrinsicWidt hForLayoutBox(contentLayoutObject); |
|
davve
2016/01/20 07:54:22
While I think this is safer than the previous fix,
| |
| 284 | 307 |
| 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'. | 308 // 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) | 309 if (computedHeightIsAuto && hasIntrinsicWidth) |
| 287 return computeReplacedLogicalWidthRespectingMinMaxWidth(constrainedS ize.width(), shouldComputePreferred); | 310 return computeReplacedLogicalWidthRespectingMinMaxWidth(constrainedS ize.width(), shouldComputePreferred); |
| 288 | 311 |
| 289 bool hasIntrinsicHeight = constrainedSize.height() > 0; | 312 bool hasIntrinsicHeight = constrainedSize.height() > 0; |
| 290 if (intrinsicRatio) { | 313 if (intrinsicRatio) { |
| 291 // If 'height' and 'width' both have computed values of 'auto' and t he element has no intrinsic width, but does have an intrinsic height and intrins ic ratio; | 314 // If 'height' and 'width' both have computed values of 'auto' and t he element has no intrinsic width, but does have an intrinsic height and intrins ic ratio; |
| 292 // or if 'width' has a computed value of 'auto', 'height' has some o ther computed value, and the element does have an intrinsic ratio; then the used value | 315 // or if 'width' has a computed value of 'auto', 'height' has some o ther computed value, and the element does have an intrinsic ratio; then the used value |
| 293 // of 'width' is: (used height) * (intrinsic ratio) | 316 // of 'width' is: (used height) * (intrinsic ratio) |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 335 return computeReplacedLogicalHeightRespectingMinMaxHeight(computeReplace dLogicalHeightUsing(MainOrPreferredSize, style()->logicalHeight())); | 358 return computeReplacedLogicalHeightRespectingMinMaxHeight(computeReplace dLogicalHeightUsing(MainOrPreferredSize, style()->logicalHeight())); |
| 336 | 359 |
| 337 LayoutBox* contentLayoutObject = embeddedContentBox(); | 360 LayoutBox* contentLayoutObject = embeddedContentBox(); |
| 338 | 361 |
| 339 // 10.6.2 Inline, replaced elements: http://www.w3.org/TR/CSS21/visudet.html #inline-replaced-height | 362 // 10.6.2 Inline, replaced elements: http://www.w3.org/TR/CSS21/visudet.html #inline-replaced-height |
| 340 double intrinsicRatio = 0; | 363 double intrinsicRatio = 0; |
| 341 FloatSize constrainedSize; | 364 FloatSize constrainedSize; |
| 342 computeAspectRatioInformationForLayoutBox(contentLayoutObject, constrainedSi ze, intrinsicRatio); | 365 computeAspectRatioInformationForLayoutBox(contentLayoutObject, constrainedSi ze, intrinsicRatio); |
| 343 | 366 |
| 344 bool widthIsAuto = style()->logicalWidth().isAuto(); | 367 bool widthIsAuto = style()->logicalWidth().isAuto(); |
| 345 bool hasIntrinsicHeight = constrainedSize.height() > 0; | 368 bool hasIntrinsicHeight = constrainedSize.height() > 0 || hasIntrinsicHeight ForLayoutBox(contentLayoutObject); |
| 346 | 369 |
| 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'. | 370 // 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) | 371 if (widthIsAuto && hasIntrinsicHeight) |
| 349 return computeReplacedLogicalHeightRespectingMinMaxHeight(constrainedSiz e.height()); | 372 return computeReplacedLogicalHeightRespectingMinMaxHeight(constrainedSiz e.height()); |
| 350 | 373 |
| 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: | 374 // 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) | 375 // (used width) / (intrinsic ratio) |
| 353 if (intrinsicRatio) | 376 if (intrinsicRatio) |
| 354 return computeReplacedLogicalHeightRespectingMinMaxHeight(availableLogic alWidth() / intrinsicRatio); | 377 return computeReplacedLogicalHeightRespectingMinMaxHeight(availableLogic alWidth() / intrinsicRatio); |
| 355 | 378 |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 470 // We only include the space below the baseline in our layer's cached paint invalidation rect if the | 493 // We only include the space below the baseline in our layer's cached paint invalidation rect if the |
| 471 // image is selected. Since the selection state has changed update the rect. | 494 // image is selected. Since the selection state has changed update the rect. |
| 472 if (hasLayer()) | 495 if (hasLayer()) |
| 473 setPreviousPaintInvalidationRect(boundsRectForPaintInvalidation(containe rForPaintInvalidation())); | 496 setPreviousPaintInvalidationRect(boundsRectForPaintInvalidation(containe rForPaintInvalidation())); |
| 474 | 497 |
| 475 if (canUpdateSelectionOnRootLineBoxes()) | 498 if (canUpdateSelectionOnRootLineBoxes()) |
| 476 inlineBoxWrapper()->root().setHasSelectedChildren(state != SelectionNone ); | 499 inlineBoxWrapper()->root().setHasSelectedChildren(state != SelectionNone ); |
| 477 } | 500 } |
| 478 | 501 |
| 479 } | 502 } |
| OLD | NEW |