| 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) 2001 Dirk Mueller (mueller@kde.org) | 4 * (C) 2001 Dirk Mueller (mueller@kde.org) |
| 5 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All r
ights reserved. | 5 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All r
ights reserved. |
| 6 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t
orchmobile.com/) | 6 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t
orchmobile.com/) |
| 7 * Copyright (C) 2011 Google Inc. All rights reserved. | 7 * Copyright (C) 2011 Google Inc. All rights reserved. |
| 8 * | 8 * |
| 9 * This library is free software; you can redistribute it and/or | 9 * This library is free software; you can redistribute it and/or |
| 10 * modify it under the terms of the GNU Library General Public | 10 * modify it under the terms of the GNU Library General Public |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 */ | 24 */ |
| 25 | 25 |
| 26 #include "config.h" | 26 #include "config.h" |
| 27 #include "core/dom/LayoutTreeBuilder.h" | 27 #include "core/dom/LayoutTreeBuilder.h" |
| 28 | 28 |
| 29 #include "core/HTMLNames.h" | 29 #include "core/HTMLNames.h" |
| 30 #include "core/SVGNames.h" | 30 #include "core/SVGNames.h" |
| 31 #include "core/css/resolver/StyleResolver.h" | 31 #include "core/css/resolver/StyleResolver.h" |
| 32 #include "core/dom/FirstLetterPseudoElement.h" | 32 #include "core/dom/FirstLetterPseudoElement.h" |
| 33 #include "core/dom/Fullscreen.h" | 33 #include "core/dom/Fullscreen.h" |
| 34 #include "core/dom/MarkerPseudoElement.h" |
| 34 #include "core/dom/Node.h" | 35 #include "core/dom/Node.h" |
| 35 #include "core/dom/PseudoElement.h" | 36 #include "core/dom/PseudoElement.h" |
| 36 #include "core/dom/Text.h" | 37 #include "core/dom/Text.h" |
| 37 #include "core/dom/shadow/InsertionPoint.h" | 38 #include "core/dom/shadow/InsertionPoint.h" |
| 38 #include "core/layout/LayoutFullScreen.h" | 39 #include "core/layout/LayoutFullScreen.h" |
| 39 #include "core/layout/LayoutObject.h" | 40 #include "core/layout/LayoutObject.h" |
| 40 #include "core/layout/LayoutText.h" | 41 #include "core/layout/LayoutText.h" |
| 41 #include "core/layout/LayoutView.h" | 42 #include "core/layout/LayoutView.h" |
| 42 #include "core/svg/SVGElement.h" | 43 #include "core/svg/SVGElement.h" |
| 43 #include "platform/RuntimeEnabledFeatures.h" | 44 #include "platform/RuntimeEnabledFeatures.h" |
| 44 | 45 |
| 45 namespace blink { | 46 namespace blink { |
| 46 | 47 |
| 47 LayoutTreeBuilderForElement::LayoutTreeBuilderForElement(Element& element, Compu
tedStyle* style) | 48 LayoutTreeBuilderForElement::LayoutTreeBuilderForElement(Element& element, Compu
tedStyle* style) |
| 48 : LayoutTreeBuilder(element, nullptr) | 49 : LayoutTreeBuilder(element, nullptr) |
| 49 , m_style(style) | 50 , m_style(style) |
| 50 { | 51 { |
| 51 ASSERT(!isActiveInsertionPoint(element)); | 52 ASSERT(!isActiveInsertionPoint(element)); |
| 52 if (element.isFirstLetterPseudoElement()) { | 53 if (element.isFirstLetterPseudoElement()) { |
| 53 if (LayoutObject* nextLayoutObject = FirstLetterPseudoElement::firstLett
erTextRenderer(element)) | 54 if (LayoutObject* nextLayoutObject = FirstLetterPseudoElement::firstLett
erTextRenderer(element)) |
| 54 m_layoutObjectParent = nextLayoutObject->parent(); | 55 m_layoutObjectParent = nextLayoutObject->parent(); |
| 55 } else if (ContainerNode* containerNode = LayoutTreeBuilderTraversal::parent
(element)) { | 56 } else if (ContainerNode* containerNode = LayoutTreeBuilderTraversal::parent
(element)) { |
| 56 m_layoutObjectParent = containerNode->layoutObject(); | 57 m_layoutObjectParent = containerNode->layoutObject(); |
| 57 } | 58 } |
| 58 } | 59 } |
| 59 | 60 |
| 60 LayoutObject* LayoutTreeBuilderForElement::nextLayoutObject() const | 61 LayoutObject* LayoutTreeBuilderForElement::nextLayoutObject(LayoutObject* parent
LayoutObject) const |
| 61 { | 62 { |
| 62 ASSERT(m_layoutObjectParent); | 63 ASSERT(m_layoutObjectParent); |
| 63 | 64 |
| 64 if (m_node->isInTopLayer()) | 65 if (m_node->isInTopLayer()) |
| 65 return LayoutTreeBuilderTraversal::nextInTopLayer(*m_node); | 66 return LayoutTreeBuilderTraversal::nextInTopLayer(*m_node); |
| 66 | 67 |
| 67 if (m_node->isFirstLetterPseudoElement()) | 68 if (m_node->isFirstLetterPseudoElement()) |
| 68 return FirstLetterPseudoElement::firstLetterTextRenderer(*m_node); | 69 return FirstLetterPseudoElement::firstLetterTextRenderer(*m_node); |
| 69 | 70 |
| 71 if (m_node->isMarkerPseudoElement()) { |
| 72 ASSERT(parentLayoutObject); |
| 73 return MarkerPseudoElement::firstNonMarkerChild(parentLayoutObject); |
| 74 } |
| 75 |
| 70 return LayoutTreeBuilder::nextLayoutObject(); | 76 return LayoutTreeBuilder::nextLayoutObject(); |
| 71 } | 77 } |
| 72 | 78 |
| 73 LayoutObject* LayoutTreeBuilderForElement::parentLayoutObject() const | 79 LayoutObject* LayoutTreeBuilderForElement::parentLayoutObject() const |
| 74 { | 80 { |
| 75 LayoutObject* parentLayoutObject = LayoutTreeBuilder::parentLayoutObject(); | 81 LayoutObject* parentLayoutObject = LayoutTreeBuilder::parentLayoutObject(); |
| 76 | 82 |
| 83 if (m_node->isMarkerPseudoElement()) { |
| 84 ASSERT(m_layoutObjectParent->isLayoutBlockFlow()); |
| 85 if (LayoutObject* markerLayoutObject = MarkerPseudoElement::getParentOfF
irstLineBox(toLayoutBlockFlow(m_layoutObjectParent), nullptr)) |
| 86 return markerLayoutObject; |
| 87 } |
| 88 |
| 77 if (parentLayoutObject) { | 89 if (parentLayoutObject) { |
| 78 // FIXME: Guarding this by parentLayoutObject isn't quite right as the s
pec for | 90 // FIXME: Guarding this by parentRenderer isn't quite right as the spec
for |
| 79 // top layer only talks about display: none ancestors so putting a <dial
og> inside an | 91 // top layer only talks about display: none ancestors so putting a <dial
og> inside an |
| 80 // <optgroup> seems like it should still work even though this check wil
l prevent it. | 92 // <optgroup> seems like it should still work even though this check wil
l prevent it. |
| 81 if (m_node->isInTopLayer()) | 93 if (m_node->isInTopLayer()) |
| 82 return m_node->document().layoutView(); | 94 return m_node->document().layoutView(); |
| 83 } | 95 } |
| 84 | 96 |
| 85 return parentLayoutObject; | 97 return parentLayoutObject; |
| 86 } | 98 } |
| 87 | 99 |
| 88 bool LayoutTreeBuilderForElement::shouldCreateLayoutObject() const | 100 bool LayoutTreeBuilderForElement::shouldCreateLayoutObject() const |
| 89 { | 101 { |
| 90 if (!m_layoutObjectParent) | 102 if (!m_layoutObjectParent) |
| 91 return false; | 103 return false; |
| 92 | 104 |
| 93 // FIXME: Should the following be in SVGElement::layoutObjectIsNeeded()? | 105 // FIXME: Should the following be in SVGElement::layoutObjectIsNeeded()? |
| 94 if (m_node->isSVGElement()) { | 106 if (m_node->isSVGElement()) { |
| 95 // SVG elements only render when inside <svg>, or if the element is an <
svg> itself. | 107 // SVG elements only render when inside <svg>, or if the element is an <
svg> itself. |
| 96 if (!isSVGSVGElement(*m_node) && (!m_layoutObjectParent->node() || !m_la
youtObjectParent->node()->isSVGElement())) | 108 if (!isSVGSVGElement(*m_node) && (!m_layoutObjectParent->node() || !m_la
youtObjectParent->node()->isSVGElement())) |
| 97 return false; | 109 return false; |
| 98 if (!toSVGElement(m_node)->isValid()) | 110 if (!toSVGElement(m_node)->isValid()) |
| 99 return false; | 111 return false; |
| 100 } | 112 } |
| 101 | 113 |
| 102 LayoutObject* parentLayoutObject = this->parentLayoutObject(); | 114 LayoutObject* parentLayoutObject = this->parentLayoutObject(); |
| 103 if (!parentLayoutObject) | 115 if (!parentLayoutObject) |
| 104 return false; | 116 return false; |
| 105 if (!parentLayoutObject->canHaveChildren()) | 117 if (!parentLayoutObject->canHaveChildren()) |
| 106 return false; | 118 return false; |
| 107 | 119 |
| 120 if (m_node->isMarkerPseudoElement() && m_layoutObjectParent->style()->displa
y() == LIST_ITEM) |
| 121 return true; |
| 122 |
| 108 return m_node->layoutObjectIsNeeded(style()); | 123 return m_node->layoutObjectIsNeeded(style()); |
| 109 } | 124 } |
| 110 | 125 |
| 111 ComputedStyle& LayoutTreeBuilderForElement::style() const | 126 ComputedStyle& LayoutTreeBuilderForElement::style() const |
| 112 { | 127 { |
| 113 if (!m_style) | 128 if (!m_style) |
| 114 m_style = m_node->styleForLayoutObject(); | 129 m_style = m_node->styleForLayoutObject(); |
| 115 return *m_style; | 130 return *m_style; |
| 116 } | 131 } |
| 117 | 132 |
| 118 void LayoutTreeBuilderForElement::createLayoutObject() | 133 void LayoutTreeBuilderForElement::createLayoutObject() |
| 119 { | 134 { |
| 120 ComputedStyle& style = this->style(); | 135 ComputedStyle& style = this->style(); |
| 121 | 136 |
| 122 LayoutObject* newLayoutObject = m_node->createLayoutObject(style); | 137 LayoutObject* newLayoutObject = m_node->createLayoutObject(style); |
| 123 if (!newLayoutObject) | 138 if (!newLayoutObject) |
| 124 return; | 139 return; |
| 125 | 140 |
| 126 LayoutObject* parentLayoutObject = this->parentLayoutObject(); | 141 LayoutObject* parentLayoutObject = this->parentLayoutObject(); |
| 127 | 142 |
| 128 if (!parentLayoutObject->isChildAllowed(newLayoutObject, style)) { | 143 if (!parentLayoutObject->isChildAllowed(newLayoutObject, style)) { |
| 129 newLayoutObject->destroy(); | 144 newLayoutObject->destroy(); |
| 130 return; | 145 return; |
| 131 } | 146 } |
| 132 | 147 |
| 133 // Make sure the LayoutObject already knows it is going to be added to a Lay
outFlowThread before we set the style | 148 // Make sure the LayoutObject already knows it is going to be added to a Lay
outFlowThread before we set the style |
| 134 // for the first time. Otherwise code using inLayoutFlowThread() in the styl
eWillChange and styleDidChange will fail. | 149 // for the first time. Otherwise code using inLayoutFlowThread() in the styl
eWillChange and styleDidChange will fail. |
| 135 newLayoutObject->setFlowThreadState(parentLayoutObject->flowThreadState()); | 150 newLayoutObject->setFlowThreadState(parentLayoutObject->flowThreadState()); |
| 136 | 151 |
| 137 LayoutObject* nextLayoutObject = this->nextLayoutObject(); | 152 LayoutObject* nextLayoutObject = this->nextLayoutObject(parentLayoutObject); |
| 138 m_node->setLayoutObject(newLayoutObject); | 153 m_node->setLayoutObject(newLayoutObject); |
| 139 newLayoutObject->setStyle(&style); // setStyle() can depend on layoutObject(
) already being set. | 154 newLayoutObject->setStyle(&style); // setStyle() can depend on layoutObject(
) already being set. |
| 140 | 155 |
| 141 if (Fullscreen::isActiveFullScreenElement(*m_node)) { | 156 if (Fullscreen::isActiveFullScreenElement(*m_node)) { |
| 142 newLayoutObject = LayoutFullScreen::wrapRenderer(newLayoutObject, parent
LayoutObject, &m_node->document()); | 157 newLayoutObject = LayoutFullScreen::wrapRenderer(newLayoutObject, parent
LayoutObject, &m_node->document()); |
| 143 if (!newLayoutObject) | 158 if (!newLayoutObject) |
| 144 return; | 159 return; |
| 145 } | 160 } |
| 146 | 161 |
| 147 // Note: Adding newLayoutObject instead of layoutObject(). layoutObject() ma
y be a child of newLayoutObject. | 162 // Note: Adding newLayoutObject instead of layoutObject(). layoutObject() ma
y be a child of newLayoutObject. |
| (...skipping 18 matching lines...) Expand all Loading... |
| 166 newLayoutObject->setFlowThreadState(parentLayoutObject->flowThreadState()); | 181 newLayoutObject->setFlowThreadState(parentLayoutObject->flowThreadState()); |
| 167 | 182 |
| 168 LayoutObject* nextLayoutObject = this->nextLayoutObject(); | 183 LayoutObject* nextLayoutObject = this->nextLayoutObject(); |
| 169 m_node->setLayoutObject(newLayoutObject); | 184 m_node->setLayoutObject(newLayoutObject); |
| 170 // Parent takes care of the animations, no need to call setAnimatableStyle. | 185 // Parent takes care of the animations, no need to call setAnimatableStyle. |
| 171 newLayoutObject->setStyle(&style); | 186 newLayoutObject->setStyle(&style); |
| 172 parentLayoutObject->addChild(newLayoutObject, nextLayoutObject); | 187 parentLayoutObject->addChild(newLayoutObject, nextLayoutObject); |
| 173 } | 188 } |
| 174 | 189 |
| 175 } | 190 } |
| OLD | NEW |