OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Neither the name of Google Inc. nor the names of its | 10 * * Neither the name of Google Inc. nor the names of its |
(...skipping 17 matching lines...) Expand all Loading... | |
28 | 28 |
29 #include "core/HTMLNames.h" | 29 #include "core/HTMLNames.h" |
30 #include "core/dom/PseudoElement.h" | 30 #include "core/dom/PseudoElement.h" |
31 #include "core/dom/shadow/FlatTreeTraversal.h" | 31 #include "core/dom/shadow/FlatTreeTraversal.h" |
32 #include "core/layout/LayoutObject.h" | 32 #include "core/layout/LayoutObject.h" |
33 | 33 |
34 namespace blink { | 34 namespace blink { |
35 | 35 |
36 namespace LayoutTreeBuilderTraversal { | 36 namespace LayoutTreeBuilderTraversal { |
37 | 37 |
38 inline static bool hasDisplayContentsStyle(const Node& node) { | |
39 return node.isElementNode() && toElement(node).displayContentsStyle(); | |
40 } | |
41 | |
38 static bool isLayoutObjectReparented(const LayoutObject* layoutObject) { | 42 static bool isLayoutObjectReparented(const LayoutObject* layoutObject) { |
39 if (!layoutObject->node()->isElementNode()) | 43 if (!layoutObject->node()->isElementNode()) |
40 return false; | 44 return false; |
45 | |
41 if (toElement(layoutObject->node())->isInTopLayer()) | 46 if (toElement(layoutObject->node())->isInTopLayer()) |
42 return true; | 47 return true; |
48 | |
49 if (layoutObject->node()->parentNode() && | |
50 hasDisplayContentsStyle(*layoutObject->node()->parentNode())) | |
51 return true; | |
52 | |
43 return false; | 53 return false; |
44 } | 54 } |
45 | 55 |
46 void ParentDetails::didTraverseInsertionPoint( | 56 void ParentDetails::didTraverseInsertionPoint( |
47 const InsertionPoint* insertionPoint) { | 57 const InsertionPoint* insertionPoint) { |
48 if (!m_insertionPoint) { | 58 if (!m_insertionPoint) { |
49 m_insertionPoint = insertionPoint; | 59 m_insertionPoint = insertionPoint; |
50 } | 60 } |
51 } | 61 } |
52 | 62 |
53 inline static void assertPseudoElementParent( | 63 inline static void assertPseudoElementParent( |
54 const PseudoElement& pseudoElement) { | 64 const PseudoElement& pseudoElement) { |
55 DCHECK(pseudoElement.parentNode()); | 65 DCHECK(pseudoElement.parentNode()); |
56 DCHECK(pseudoElement.parentNode()->canParticipateInFlatTree()); | 66 DCHECK(pseudoElement.parentNode()->canParticipateInFlatTree()); |
57 } | 67 } |
58 | 68 |
59 ContainerNode* parent(const Node& node, ParentDetails* details) { | 69 ContainerNode* parent(const Node& node, ParentDetails* details) { |
60 // TODO(hayato): Uncomment this once we can be sure | 70 // TODO(hayato): Uncomment this once we can be sure |
61 // LayoutTreeBuilderTraversal::parent() is used only for a node which is | 71 // LayoutTreeBuilderTraversal::parent() is used only for a node which is |
62 // connected. | 72 // connected. |
63 // DCHECK(node.isConnected()); | 73 // DCHECK(node.isConnected()); |
64 if (node.isPseudoElement()) { | 74 if (node.isPseudoElement()) { |
65 assertPseudoElementParent(toPseudoElement(node)); | 75 assertPseudoElementParent(toPseudoElement(node)); |
66 return node.parentNode(); | 76 return node.parentNode(); |
67 } | 77 } |
68 return FlatTreeTraversal::parent(node, details); | 78 return FlatTreeTraversal::parent(node, details); |
69 } | 79 } |
70 | 80 |
81 LayoutObject* parentLayoutObject(const Node& node) { | |
82 ContainerNode* parent = LayoutTreeBuilderTraversal::parent(node); | |
83 | |
84 while (parent && hasDisplayContentsStyle(*parent)) { | |
85 parent = LayoutTreeBuilderTraversal::parent(*parent); | |
86 } | |
87 | |
88 return parent ? parent->layoutObject() : 0; | |
jfernandez
2016/10/27 17:08:02
use nullptr instead of 0
| |
89 } | |
90 | |
71 Node* nextSibling(const Node& node) { | 91 Node* nextSibling(const Node& node) { |
72 if (node.isBeforePseudoElement()) { | 92 if (node.isBeforePseudoElement()) { |
73 assertPseudoElementParent(toPseudoElement(node)); | 93 assertPseudoElementParent(toPseudoElement(node)); |
74 if (Node* next = FlatTreeTraversal::firstChild(*node.parentNode())) | 94 if (Node* next = FlatTreeTraversal::firstChild(*node.parentNode())) |
75 return next; | 95 return next; |
76 } else { | 96 } else { |
77 if (node.isAfterPseudoElement()) | 97 if (node.isAfterPseudoElement()) |
78 return nullptr; | 98 return nullptr; |
79 if (Node* next = FlatTreeTraversal::nextSibling(node)) | 99 if (Node* next = FlatTreeTraversal::nextSibling(node)) |
80 return next; | 100 return next; |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
248 for (size_t i = position + 1; i < topLayerElements.size(); ++i) { | 268 for (size_t i = position + 1; i < topLayerElements.size(); ++i) { |
249 if (LayoutObject* layoutObject = topLayerElements[i]->layoutObject()) | 269 if (LayoutObject* layoutObject = topLayerElements[i]->layoutObject()) |
250 return layoutObject; | 270 return layoutObject; |
251 } | 271 } |
252 return 0; | 272 return 0; |
253 } | 273 } |
254 | 274 |
255 } // namespace LayoutTreeBuilderTraversal | 275 } // namespace LayoutTreeBuilderTraversal |
256 | 276 |
257 } // namespace blink | 277 } // namespace blink |
OLD | NEW |