1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc.
4 * All rights reserved.
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
15 *
16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20 *
21 */
22
23 #include "third_party/blink/renderer/core/css/resolver/element_resolve_context.h"
24
25 #include "third_party/blink/renderer/core/dom/layout_tree_builder_traversal.h"
26 #include "third_party/blink/renderer/core/dom/node.h"
27 #include "third_party/blink/renderer/core/dom/node_computed_style.h"
28 #include "third_party/blink/renderer/core/dom/v0_insertion_point.h"
29 #include "third_party/blink/renderer/core/dom/visited_link_state.h"
30
31 namespace blink {
32
ElementResolveContext(Element & element)33 ElementResolveContext::ElementResolveContext(Element& element)
34 : element_(&element),
35 parent_node_(nullptr),
36 layout_parent_(nullptr),
37 element_link_state_(
38 element.GetDocument().GetVisitedLinkState().DetermineLinkState(
39 element)),
40 distributed_to_insertion_point_(false) {
41 if (!element.NeedsDistributionRecalc() &&
42 element.CanParticipateInFlatTree()) {
43 LayoutTreeBuilderTraversal::ParentDetails parent_details;
44 parent_node_ = LayoutTreeBuilderTraversal::Parent(element);
45 layout_parent_ =
46 LayoutTreeBuilderTraversal::LayoutParent(element, &parent_details);
47 distributed_to_insertion_point_ = parent_details.GetInsertionPoint();
48 } else {
49 parent_node_ = nullptr;
50 layout_parent_ = nullptr;
51 }
52
53 if (auto* document_element = element.GetDocument().documentElement()) {
54 if (element != document_element)
55 root_element_style_ = document_element->GetComputedStyle();
56 }
57 }
58
59 } // namespace blink
60