2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Dirk Mueller (mueller@kde.org)
5 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved.
6 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
7 * Copyright (C) 2011 Google Inc. All rights reserved.
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Library General Public License for more details.
19 * You should have received a copy of the GNU Library General Public License
20 * along with this library; see the file COPYING.LIB. If not, write to
21 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 * Boston, MA 02110-1301, USA.
26 #ifndef LayoutTreeBuilder_h
27 #define LayoutTreeBuilder_h
29 #include "core/dom/Document.h"
30 #include "core/dom/LayoutTreeBuilderTraversal.h"
31 #include "core/dom/Node.h"
32 #include "core/dom/Text.h"
33 #include "core/layout/LayoutObject.h"
34 #include "wtf/RefPtr.h"
40 template <typename NodeType
>
41 class LayoutTreeBuilder
{
44 LayoutTreeBuilder(NodeType
& node
, LayoutObject
* layoutObjectParent
)
46 , m_layoutObjectParent(layoutObjectParent
)
48 ASSERT(!node
.layoutObject());
49 ASSERT(node
.needsAttach());
50 ASSERT(node
.document().inStyleRecalc());
51 ASSERT(node
.inActiveDocument());
54 LayoutObject
* nextLayoutObject() const
56 ASSERT(m_layoutObjectParent
);
58 // Avoid an O(N^2) walk over the children when reattaching all children of a node.
59 if (m_layoutObjectParent
->node() && m_layoutObjectParent
->node()->needsAttach())
62 return LayoutTreeBuilderTraversal::nextSiblingLayoutObject(*m_node
);
65 RawPtrWillBeMember
<NodeType
> m_node
;
66 LayoutObject
* m_layoutObjectParent
;
69 class LayoutTreeBuilderForElement
: public LayoutTreeBuilder
<Element
> {
71 LayoutTreeBuilderForElement(Element
&, ComputedStyle
*);
73 void createLayoutObjectIfNeeded()
75 if (shouldCreateLayoutObject())
80 LayoutObject
* parentLayoutObject() const;
81 LayoutObject
* nextLayoutObject() const;
82 bool shouldCreateLayoutObject() const;
83 ComputedStyle
& style() const;
84 void createLayoutObject();
86 mutable RefPtr
<ComputedStyle
> m_style
;
89 class LayoutTreeBuilderForText
: public LayoutTreeBuilder
<Text
> {
91 LayoutTreeBuilderForText(Text
& text
, LayoutObject
* layoutParent
)
92 : LayoutTreeBuilder(text
, layoutParent
) { }
94 void createLayoutObject();