| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
| 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) | 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) |
| 4 * (C) 2007 David Smith (catfish.man@gmail.com) | 4 * (C) 2007 David Smith (catfish.man@gmail.com) |
| 5 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc.
All rights reserved. | 5 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc.
All rights reserved. |
| 6 * Copyright (C) Research In Motion Limited 2010. All rights reserved. | 6 * Copyright (C) Research In Motion Limited 2010. All rights reserved. |
| 7 * | 7 * |
| 8 * This library is free software; you can redistribute it and/or | 8 * This library is free software; you can redistribute it and/or |
| 9 * modify it under the terms of the GNU Library General Public | 9 * modify it under the terms of the GNU Library General Public |
| 10 * License as published by the Free Software Foundation; either | 10 * License as published by the Free Software Foundation; either |
| 11 * version 2 of the License, or (at your option) any later version. | 11 * version 2 of the License, or (at your option) any later version. |
| 12 * | 12 * |
| 13 * This library is distributed in the hope that it will be useful, | 13 * This library is distributed in the hope that it will be useful, |
| 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 * Library General Public License for more details. | 16 * Library General Public License for more details. |
| 17 * | 17 * |
| 18 * You should have received a copy of the GNU Library General Public License | 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 | 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, | 20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 21 * Boston, MA 02110-1301, USA. | 21 * Boston, MA 02110-1301, USA. |
| 22 */ | 22 */ |
| 23 | 23 |
| 24 #include "core/layout/FloatingObjects.h" | 24 #include "core/layout/FloatingObjects.h" |
| 25 | 25 |
| 26 #include "core/layout/LayoutBlockFlow.h" | 26 #include "core/layout/LayoutBlockFlow.h" |
| 27 #include "core/layout/LayoutBox.h" | 27 #include "core/layout/LayoutBox.h" |
| 28 #include "core/layout/LayoutView.h" | 28 #include "core/layout/LayoutView.h" |
| 29 #include "core/layout/shapes/ShapeOutsideInfo.h" | 29 #include "core/layout/shapes/ShapeOutsideInfo.h" |
| 30 #include "core/paint/PaintLayer.h" |
| 31 #include "platform/RuntimeEnabledFeatures.h" |
| 30 #include "wtf/PtrUtil.h" | 32 #include "wtf/PtrUtil.h" |
| 31 | |
| 32 #include <algorithm> | 33 #include <algorithm> |
| 33 #include <memory> | 34 #include <memory> |
| 34 | 35 |
| 35 using namespace WTF; | 36 using namespace WTF; |
| 36 | 37 |
| 37 namespace blink { | 38 namespace blink { |
| 38 | 39 |
| 39 struct SameSizeAsFloatingObject { | 40 struct SameSizeAsFloatingObject { |
| 40 void* pointers[2]; | 41 void* pointers[2]; |
| 41 LayoutRect rect; | 42 LayoutRect rect; |
| 42 uint32_t bitfields : 8; | 43 uint32_t bitfields : 8; |
| 43 }; | 44 }; |
| 44 | 45 |
| 45 static_assert(sizeof(FloatingObject) == sizeof(SameSizeAsFloatingObject), "Float
ingObject should stay small"); | 46 static_assert(sizeof(FloatingObject) == sizeof(SameSizeAsFloatingObject), "Float
ingObject should stay small"); |
| 46 | 47 |
| 47 FloatingObject::FloatingObject(LayoutBox* layoutObject) | 48 FloatingObject::FloatingObject(LayoutBox* layoutObject) |
| 48 : m_layoutObject(layoutObject) | 49 : m_layoutObject(layoutObject) |
| 49 , m_originatingLine(nullptr) | 50 , m_originatingLine(nullptr) |
| 50 // TODO(wkorman): Do we need to change this to take param as it used to? | |
| 51 , m_shouldPaint(true) | 51 , m_shouldPaint(true) |
| 52 , m_isDescendant(false) | 52 , m_isDescendant(false) |
| 53 , m_isPlaced(false) | 53 , m_isPlaced(false) |
| 54 , m_isLowestNonOverhangingFloatInChild(false) | 54 , m_isLowestNonOverhangingFloatInChild(false) |
| 55 #if ENABLE(ASSERT) | 55 #if ENABLE(ASSERT) |
| 56 , m_isInPlacedTree(false) | 56 , m_isInPlacedTree(false) |
| 57 #endif | 57 #endif |
| 58 { | 58 { |
| 59 EFloat type = layoutObject->style()->floating(); | 59 EFloat type = layoutObject->style()->floating(); |
| 60 ASSERT(type != NoFloat); | 60 ASSERT(type != NoFloat); |
| 61 if (type == LeftFloat) | 61 if (type == LeftFloat) |
| 62 m_type = FloatLeft; | 62 m_type = FloatLeft; |
| 63 else if (type == RightFloat) | 63 else if (type == RightFloat) |
| 64 m_type = FloatRight; | 64 m_type = FloatRight; |
| 65 } | 65 } |
| 66 | 66 |
| 67 FloatingObject::FloatingObject(LayoutBox* layoutObject, Type type, const LayoutR
ect& frameRect, bool shouldPaint, bool isDescendant, bool isLowestNonOverhanging
FloatInChild, bool performingUnsafeClone) | 67 FloatingObject::FloatingObject(LayoutBox* layoutObject, Type type, const LayoutR
ect& frameRect, bool shouldPaint, bool isDescendant, bool isLowestNonOverhanging
FloatInChild, bool performingUnsafeClone) |
| 68 : m_layoutObject(layoutObject) | 68 : m_layoutObject(layoutObject) |
| 69 , m_originatingLine(nullptr) | 69 , m_originatingLine(nullptr) |
| 70 , m_frameRect(frameRect) | 70 , m_frameRect(frameRect) |
| 71 , m_type(type) | 71 , m_type(type) |
| 72 , m_shouldPaint(shouldPaint) | |
| 73 , m_isDescendant(isDescendant) | 72 , m_isDescendant(isDescendant) |
| 74 , m_isPlaced(true) | 73 , m_isPlaced(true) |
| 75 , m_isLowestNonOverhangingFloatInChild(isLowestNonOverhangingFloatInChild) | 74 , m_isLowestNonOverhangingFloatInChild(isLowestNonOverhangingFloatInChild) |
| 76 #if ENABLE(ASSERT) | 75 #if ENABLE(ASSERT) |
| 77 , m_isInPlacedTree(false) | 76 , m_isInPlacedTree(false) |
| 78 #endif | 77 #endif |
| 79 { | 78 { |
| 79 m_shouldPaint = shouldPaint; |
| 80 // TODO(chrishtr): Avoid the following hack when performing an unsafe clone. |
| 81 // This avoids a use-after-free bug due to the fact that we sometimes fail t
o remove |
| 82 // floats from their container when detaching (crbug.com/619380). This is ac
tually a bug in the |
| 83 // floats detach machinery, which needs to be fixed, in which case this work
around can be removed. |
| 84 // In any case, it should be safe because moving floats from one owner to an
other should cause layout, |
| 85 // which will in turn update the m_shouldPaint property. |
| 86 if (!performingUnsafeClone) |
| 87 m_shouldPaint = m_shouldPaint || shouldPaintForCompositedLayoutPart(); |
| 88 } |
| 89 |
| 90 bool FloatingObject::shouldPaintForCompositedLayoutPart() |
| 91 { |
| 92 // HACK: only non-self-painting floats should paint. However, due to the fun
damental compositing bug, some LayoutPart objects |
| 93 // may become self-painting due to being composited. This leads to a chicken
-egg issue because layout may not depend on compositing. |
| 94 // If this is the case, set shouldPaint() to true even if the layer is techn
ically self-painting. This lets the float which contains |
| 95 // a LayoutPart start painting as soon as it stops being composited, without
having to re-layout the float. |
| 96 // This hack can be removed after SPv2. |
| 97 return m_layoutObject->layer() && m_layoutObject->layer()->isSelfPaintingOnl
yBecauseIsCompositedPart() && !RuntimeEnabledFeatures::slimmingPaintV2Enabled(); |
| 80 } | 98 } |
| 81 | 99 |
| 82 std::unique_ptr<FloatingObject> FloatingObject::create(LayoutBox* layoutObject) | 100 std::unique_ptr<FloatingObject> FloatingObject::create(LayoutBox* layoutObject) |
| 83 { | 101 { |
| 84 std::unique_ptr<FloatingObject> newObj = wrapUnique(new FloatingObject(layou
tObject)); | 102 std::unique_ptr<FloatingObject> newObj = wrapUnique(new FloatingObject(layou
tObject)); |
| 85 | 103 |
| 86 // If a layer exists, the float will paint itself. Otherwise someone else wi
ll. | 104 // If a layer exists, the float will paint itself. Otherwise someone else wi
ll. |
| 87 newObj->setShouldPaint(!layoutObject->hasSelfPaintingLayer()); | 105 newObj->setShouldPaint(!layoutObject->hasSelfPaintingLayer() || newObj->shou
ldPaintForCompositedLayoutPart()); |
| 88 | 106 |
| 89 newObj->setIsDescendant(true); | 107 newObj->setIsDescendant(true); |
| 90 | 108 |
| 91 return newObj; | 109 return newObj; |
| 92 } | 110 } |
| 93 | 111 |
| 112 bool FloatingObject::shouldPaint() const |
| 113 { |
| 114 return m_shouldPaint && !m_layoutObject->hasSelfPaintingLayer(); |
| 115 } |
| 116 |
| 94 std::unique_ptr<FloatingObject> FloatingObject::copyToNewContainer(LayoutSize of
fset, bool shouldPaint, bool isDescendant) const | 117 std::unique_ptr<FloatingObject> FloatingObject::copyToNewContainer(LayoutSize of
fset, bool shouldPaint, bool isDescendant) const |
| 95 { | 118 { |
| 96 return wrapUnique(new FloatingObject(layoutObject(), getType(), LayoutRect(f
rameRect().location() - offset, frameRect().size()), shouldPaint, isDescendant,
isLowestNonOverhangingFloatInChild())); | 119 return wrapUnique(new FloatingObject(layoutObject(), getType(), LayoutRect(f
rameRect().location() - offset, frameRect().size()), shouldPaint, isDescendant,
isLowestNonOverhangingFloatInChild())); |
| 97 } | 120 } |
| 98 | 121 |
| 99 std::unique_ptr<FloatingObject> FloatingObject::unsafeClone() const | 122 std::unique_ptr<FloatingObject> FloatingObject::unsafeClone() const |
| 100 { | 123 { |
| 101 std::unique_ptr<FloatingObject> cloneObject = wrapUnique(new FloatingObject(
layoutObject(), getType(), m_frameRect, m_shouldPaint, m_isDescendant, false, tr
ue)); | 124 std::unique_ptr<FloatingObject> cloneObject = wrapUnique(new FloatingObject(
layoutObject(), getType(), m_frameRect, m_shouldPaint, m_isDescendant, false, tr
ue)); |
| 102 cloneObject->m_isPlaced = m_isPlaced; | 125 cloneObject->m_isPlaced = m_isPlaced; |
| 103 return cloneObject; | 126 return cloneObject; |
| (...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 624 } | 647 } |
| 625 | 648 |
| 626 String ValueToString<FloatingObject*>::toString(const FloatingObject* floatingOb
ject) | 649 String ValueToString<FloatingObject*>::toString(const FloatingObject* floatingOb
ject) |
| 627 { | 650 { |
| 628 return String::format("%p (%gx%g %gx%g)", floatingObject, floatingObject->fr
ameRect().x().toFloat(), floatingObject->frameRect().y().toFloat(), floatingObje
ct->frameRect().maxX().toFloat(), floatingObject->frameRect().maxY().toFloat()); | 651 return String::format("%p (%gx%g %gx%g)", floatingObject, floatingObject->fr
ameRect().x().toFloat(), floatingObject->frameRect().y().toFloat(), floatingObje
ct->frameRect().maxX().toFloat(), floatingObject->frameRect().maxY().toFloat()); |
| 629 } | 652 } |
| 630 #endif | 653 #endif |
| 631 | 654 |
| 632 | 655 |
| 633 } // namespace blink | 656 } // namespace blink |
| OLD | NEW |