1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
|
/*
* Copyright (C) 1999 Lars Knoll (knoll@kde.org)
* (C) 1999 Antti Koivisto (koivisto@kde.org)
* (C) 2001 Dirk Mueller (mueller@kde.org)
* Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All
* rights reserved.
* Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved.
* (http://www.torchmobile.com/)
* Copyright (C) 2011 Google Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
*/
#include "core/dom/LayoutTreeBuilder.h"
#include "core/HTMLNames.h"
#include "core/SVGNames.h"
#include "core/css/resolver/StyleResolver.h"
#include "core/dom/FirstLetterPseudoElement.h"
#include "core/dom/Fullscreen.h"
#include "core/dom/Node.h"
#include "core/dom/PseudoElement.h"
#include "core/dom/Text.h"
#include "core/dom/shadow/InsertionPoint.h"
#include "core/layout/LayoutFullScreen.h"
#include "core/layout/LayoutObject.h"
#include "core/layout/LayoutText.h"
#include "core/layout/LayoutView.h"
#include "core/svg/SVGElement.h"
#include "platform/RuntimeEnabledFeatures.h"
namespace blink {
LayoutTreeBuilderForElement::LayoutTreeBuilderForElement(Element& element,
ComputedStyle* style)
: LayoutTreeBuilder(element, nullptr), m_style(style) {
DCHECK(!element.isActiveSlotOrActiveInsertionPoint());
if (element.isFirstLetterPseudoElement()) {
if (LayoutObject* nextLayoutObject =
FirstLetterPseudoElement::firstLetterTextLayoutObject(element))
m_layoutObjectParent = nextLayoutObject->parent();
} else if (ContainerNode* containerNode =
LayoutTreeBuilderTraversal::parent(element)) {
m_layoutObjectParent = containerNode->layoutObject();
}
}
LayoutObject* LayoutTreeBuilderForElement::nextLayoutObject() const {
DCHECK(m_layoutObjectParent);
if (m_node->isInTopLayer())
return LayoutTreeBuilderTraversal::nextInTopLayer(*m_node);
if (m_node->isFirstLetterPseudoElement())
return FirstLetterPseudoElement::firstLetterTextLayoutObject(*m_node);
return LayoutTreeBuilder::nextLayoutObject();
}
LayoutObject* LayoutTreeBuilderForElement::parentLayoutObject() const {
if (m_layoutObjectParent) {
// FIXME: Guarding this by parentLayoutObject isn't quite right as the spec
// for top layer only talks about display: none ancestors so putting a
// <dialog> inside an <optgroup> seems like it should still work even though
// this check will prevent it.
if (m_node->isInTopLayer())
return m_node->document().layoutView();
}
return m_layoutObjectParent;
}
DISABLE_CFI_PERF
bool LayoutTreeBuilderForElement::shouldCreateLayoutObject() const {
if (!m_layoutObjectParent)
return false;
// FIXME: Should the following be in SVGElement::layoutObjectIsNeeded()?
if (m_node->isSVGElement()) {
// SVG elements only render when inside <svg>, or if the element is an <svg>
// itself.
if (!isSVGSVGElement(*m_node) &&
(!m_layoutObjectParent->node() ||
!m_layoutObjectParent->node()->isSVGElement()))
return false;
if (!toSVGElement(m_node)->isValid())
return false;
}
LayoutObject* parentLayoutObject = this->parentLayoutObject();
if (!parentLayoutObject)
return false;
if (!parentLayoutObject->canHaveChildren())
return false;
return m_node->layoutObjectIsNeeded(style());
}
ComputedStyle& LayoutTreeBuilderForElement::style() const {
if (!m_style)
m_style = m_node->styleForLayoutObject();
return *m_style;
}
DISABLE_CFI_PERF
void LayoutTreeBuilderForElement::createLayoutObject() {
ComputedStyle& style = this->style();
LayoutObject* newLayoutObject = m_node->createLayoutObject(style);
if (!newLayoutObject)
return;
LayoutObject* parentLayoutObject = this->parentLayoutObject();
if (!parentLayoutObject->isChildAllowed(newLayoutObject, style)) {
newLayoutObject->destroy();
return;
}
// Make sure the LayoutObject already knows it is going to be added to a
// LayoutFlowThread before we set the style for the first time. Otherwise code
// using inLayoutFlowThread() in the styleWillChange and styleDidChange will
// fail.
newLayoutObject->setIsInsideFlowThread(
parentLayoutObject->isInsideFlowThread());
LayoutObject* nextLayoutObject = this->nextLayoutObject();
m_node->setLayoutObject(newLayoutObject);
newLayoutObject->setStyle(
&style); // setStyle() can depend on layoutObject() already being set.
if (Fullscreen::isCurrentFullScreenElement(*m_node)) {
newLayoutObject = LayoutFullScreen::wrapLayoutObject(
newLayoutObject, parentLayoutObject, &m_node->document());
if (!newLayoutObject)
return;
}
// Note: Adding newLayoutObject instead of layoutObject(). layoutObject() may
// be a child of newLayoutObject.
parentLayoutObject->addChild(newLayoutObject, nextLayoutObject);
}
void LayoutTreeBuilderForText::createLayoutObject() {
ComputedStyle& style = m_layoutObjectParent->mutableStyleRef();
DCHECK(m_node->textLayoutObjectIsNeeded(style, *m_layoutObjectParent));
LayoutText* newLayoutObject = m_node->createTextLayoutObject(style);
if (!m_layoutObjectParent->isChildAllowed(newLayoutObject, style)) {
newLayoutObject->destroy();
return;
}
// Make sure the LayoutObject already knows it is going to be added to a
// LayoutFlowThread before we set the style for the first time. Otherwise code
// using inLayoutFlowThread() in the styleWillChange and styleDidChange will
// fail.
newLayoutObject->setIsInsideFlowThread(
m_layoutObjectParent->isInsideFlowThread());
LayoutObject* nextLayoutObject = this->nextLayoutObject();
m_node->setLayoutObject(newLayoutObject);
// Parent takes care of the animations, no need to call setAnimatableStyle.
newLayoutObject->setStyle(&style);
m_layoutObjectParent->addChild(newLayoutObject, nextLayoutObject);
}
} // namespace blink
|