| 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 return false; | 44 return false; |
| 45 } | 45 } |
| 46 | 46 |
| 47 void ParentDetails::didTraverseInsertionPoint(const InsertionPoint* insertionPoi
nt) | 47 void ParentDetails::didTraverseInsertionPoint(const InsertionPoint* insertionPoi
nt) |
| 48 { | 48 { |
| 49 if (!m_insertionPoint) { | 49 if (!m_insertionPoint) { |
| 50 m_insertionPoint = insertionPoint; | 50 m_insertionPoint = insertionPoint; |
| 51 } | 51 } |
| 52 } | 52 } |
| 53 | 53 |
| 54 inline static void assertPseudoElementParent(const PseudoElement& pseudoElement) |
| 55 { |
| 56 DCHECK(pseudoElement.parentNode()); |
| 57 DCHECK(pseudoElement.parentNode()->canParticipateInFlatTree()); |
| 58 } |
| 59 |
| 54 ContainerNode* parent(const Node& node, ParentDetails* details) | 60 ContainerNode* parent(const Node& node, ParentDetails* details) |
| 55 { | 61 { |
| 56 // TODO(hayato): Uncomment this once we can be sure LayoutTreeBuilderTravers
al::parent() is used only for a node in a document. | 62 // TODO(hayato): Uncomment this once we can be sure LayoutTreeBuilderTravers
al::parent() is used only for a node which is connected. |
| 57 // DCHECK(node.isConnected()); | 63 // DCHECK(node.isConnected()); |
| 64 if (node.isPseudoElement()) { |
| 65 assertPseudoElementParent(toPseudoElement(node)); |
| 66 return node.parentNode(); |
| 67 } |
| 58 return FlatTreeTraversal::parent(node, details); | 68 return FlatTreeTraversal::parent(node, details); |
| 59 } | 69 } |
| 60 | 70 |
| 61 Node* nextSibling(const Node& node) | 71 Node* nextSibling(const Node& node) |
| 62 { | 72 { |
| 63 if (node.isBeforePseudoElement()) { | 73 if (node.isBeforePseudoElement()) { |
| 64 if (Node* next = FlatTreeTraversal::firstChild(*FlatTreeTraversal::paren
t(node))) | 74 assertPseudoElementParent(toPseudoElement(node)); |
| 75 if (Node* next = FlatTreeTraversal::firstChild(*node.parentNode())) |
| 65 return next; | 76 return next; |
| 66 } else { | 77 } else { |
| 78 if (node.isAfterPseudoElement()) |
| 79 return nullptr; |
| 67 if (Node* next = FlatTreeTraversal::nextSibling(node)) | 80 if (Node* next = FlatTreeTraversal::nextSibling(node)) |
| 68 return next; | 81 return next; |
| 69 if (node.isAfterPseudoElement()) | |
| 70 return 0; | |
| 71 } | 82 } |
| 72 | 83 |
| 73 Node* parent = FlatTreeTraversal::parent(node); | 84 Node* parent = FlatTreeTraversal::parent(node); |
| 74 if (parent && parent->isElementNode()) | 85 if (parent && parent->isElementNode()) |
| 75 return toElement(parent)->pseudoElement(PseudoIdAfter); | 86 return toElement(parent)->pseudoElement(PseudoIdAfter); |
| 76 | 87 |
| 77 return 0; | 88 return nullptr; |
| 78 } | 89 } |
| 79 | 90 |
| 80 Node* previousSibling(const Node& node) | 91 Node* previousSibling(const Node& node) |
| 81 { | 92 { |
| 82 if (node.isAfterPseudoElement()) { | 93 if (node.isAfterPseudoElement()) { |
| 83 if (Node* previous = FlatTreeTraversal::lastChild(*FlatTreeTraversal::pa
rent(node))) | 94 assertPseudoElementParent(toPseudoElement(node)); |
| 95 if (Node* previous = FlatTreeTraversal::lastChild(*node.parentNode())) |
| 84 return previous; | 96 return previous; |
| 85 } else { | 97 } else { |
| 98 if (node.isBeforePseudoElement()) |
| 99 return nullptr; |
| 86 if (Node* previous = FlatTreeTraversal::previousSibling(node)) | 100 if (Node* previous = FlatTreeTraversal::previousSibling(node)) |
| 87 return previous; | 101 return previous; |
| 88 if (node.isBeforePseudoElement()) | |
| 89 return 0; | |
| 90 } | 102 } |
| 91 | 103 |
| 92 Node* parent = FlatTreeTraversal::parent(node); | 104 Node* parent = FlatTreeTraversal::parent(node); |
| 93 if (parent && parent->isElementNode()) | 105 if (parent && parent->isElementNode()) |
| 94 return toElement(parent)->pseudoElement(PseudoIdBefore); | 106 return toElement(parent)->pseudoElement(PseudoIdBefore); |
| 95 | 107 |
| 96 return 0; | 108 return nullptr; |
| 97 } | 109 } |
| 98 | 110 |
| 99 static Node* lastChild(const Node& node) | 111 static Node* lastChild(const Node& node) |
| 100 { | 112 { |
| 101 return FlatTreeTraversal::lastChild(node); | 113 return FlatTreeTraversal::lastChild(node); |
| 102 } | 114 } |
| 103 | 115 |
| 104 static Node* pseudoAwarePreviousSibling(const Node& node) | 116 static Node* pseudoAwarePreviousSibling(const Node& node) |
| 105 { | 117 { |
| 106 Node* previousNode = previousSibling(node); | 118 Node* previousNode = previousSibling(node); |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 for (size_t i = position + 1; i < topLayerElements.size(); ++i) { | 255 for (size_t i = position + 1; i < topLayerElements.size(); ++i) { |
| 244 if (LayoutObject* layoutObject = topLayerElements[i]->layoutObject()) | 256 if (LayoutObject* layoutObject = topLayerElements[i]->layoutObject()) |
| 245 return layoutObject; | 257 return layoutObject; |
| 246 } | 258 } |
| 247 return 0; | 259 return 0; |
| 248 } | 260 } |
| 249 | 261 |
| 250 } // namespace LayoutTreeBuilderTraversal | 262 } // namespace LayoutTreeBuilderTraversal |
| 251 | 263 |
| 252 } // namespace blink | 264 } // namespace blink |
| OLD | NEW |