Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(166)

Side by Side Diff: Source/core/dom/Element.cpp

Issue 166033005: Port Node's previousElementSibling() / nextElementSibling() to ElementTraversal (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Peter Kelly (pmk@post.com) 4 * (C) 2001 Peter Kelly (pmk@post.com)
5 * (C) 2001 Dirk Mueller (mueller@kde.org) 5 * (C) 2001 Dirk Mueller (mueller@kde.org)
6 * (C) 2007 David Smith (catfish.man@gmail.com) 6 * (C) 2007 David Smith (catfish.man@gmail.com)
7 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012, 2013 Apple Inc. All rights reserved. 7 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012, 2013 Apple Inc. All rights reserved.
8 * (C) 2007 Eric Seidel (eric@webkit.org) 8 * (C) 2007 Eric Seidel (eric@webkit.org)
9 * 9 *
10 * This library is free software; you can redistribute it and/or 10 * This library is free software; you can redistribute it and/or
(...skipping 30 matching lines...) Expand all
41 #include "core/css/StylePropertySet.h" 41 #include "core/css/StylePropertySet.h"
42 #include "core/css/parser/BisonCSSParser.h" 42 #include "core/css/parser/BisonCSSParser.h"
43 #include "core/css/resolver/StyleResolver.h" 43 #include "core/css/resolver/StyleResolver.h"
44 #include "core/dom/Attr.h" 44 #include "core/dom/Attr.h"
45 #include "core/dom/CSSSelectorWatch.h" 45 #include "core/dom/CSSSelectorWatch.h"
46 #include "core/dom/ClientRect.h" 46 #include "core/dom/ClientRect.h"
47 #include "core/dom/ClientRectList.h" 47 #include "core/dom/ClientRectList.h"
48 #include "core/dom/DatasetDOMStringMap.h" 48 #include "core/dom/DatasetDOMStringMap.h"
49 #include "core/dom/ElementDataCache.h" 49 #include "core/dom/ElementDataCache.h"
50 #include "core/dom/ElementRareData.h" 50 #include "core/dom/ElementRareData.h"
51 #include "core/dom/ElementTraversal.h"
51 #include "core/dom/ExceptionCode.h" 52 #include "core/dom/ExceptionCode.h"
52 #include "core/dom/FullscreenElementStack.h" 53 #include "core/dom/FullscreenElementStack.h"
53 #include "core/dom/MutationObserverInterestGroup.h" 54 #include "core/dom/MutationObserverInterestGroup.h"
54 #include "core/dom/MutationRecord.h" 55 #include "core/dom/MutationRecord.h"
55 #include "core/dom/NamedNodeMap.h" 56 #include "core/dom/NamedNodeMap.h"
56 #include "core/dom/NodeRenderStyle.h" 57 #include "core/dom/NodeRenderStyle.h"
57 #include "core/dom/PostAttachCallbacks.h" 58 #include "core/dom/PostAttachCallbacks.h"
58 #include "core/dom/PresentationAttributeStyle.h" 59 #include "core/dom/PresentationAttributeStyle.h"
59 #include "core/dom/PseudoElement.h" 60 #include "core/dom/PseudoElement.h"
60 #include "core/dom/RenderTreeBuilder.h" 61 #include "core/dom/RenderTreeBuilder.h"
(...skipping 1816 matching lines...) Expand 10 before | Expand all | Expand 10 after
1877 1878
1878 // :first-child. In the parser callback case, we don't have to check anythi ng, since we were right the first time. 1879 // :first-child. In the parser callback case, we don't have to check anythi ng, since we were right the first time.
1879 // In the DOM case, we only need to do something if |afterChange| is not 0. 1880 // In the DOM case, we only need to do something if |afterChange| is not 0.
1880 // |afterChange| is 0 in the parser case, so it works out that we'll skip th is block. 1881 // |afterChange| is 0 in the parser case, so it works out that we'll skip th is block.
1881 if (childrenAffectedByFirstChildRules() && afterChange) { 1882 if (childrenAffectedByFirstChildRules() && afterChange) {
1882 // Find our new first child. 1883 // Find our new first child.
1883 Node* newFirstChild = firstElementChild(); 1884 Node* newFirstChild = firstElementChild();
1884 RenderStyle* newFirstChildStyle = newFirstChild ? newFirstChild->renderS tyle() : 0; 1885 RenderStyle* newFirstChildStyle = newFirstChild ? newFirstChild->renderS tyle() : 0;
1885 1886
1886 // Find the first element node following |afterChange| 1887 // Find the first element node following |afterChange|
1887 Node* firstElementAfterInsertion = afterChange->isElementNode() ? afterC hange : afterChange->nextElementSibling(); 1888 Node* firstElementAfterInsertion = afterChange->isElementNode() ? afterC hange : ElementTraversal::nextSibling(*afterChange);
1888 RenderStyle* firstElementAfterInsertionStyle = firstElementAfterInsertio n ? firstElementAfterInsertion->renderStyle() : 0; 1889 RenderStyle* firstElementAfterInsertionStyle = firstElementAfterInsertio n ? firstElementAfterInsertion->renderStyle() : 0;
1889 1890
1890 // This is the insert/append case. 1891 // This is the insert/append case.
1891 if (newFirstChild != firstElementAfterInsertion && firstElementAfterInse rtionStyle && firstElementAfterInsertionStyle->firstChildState()) 1892 if (newFirstChild != firstElementAfterInsertion && firstElementAfterInse rtionStyle && firstElementAfterInsertionStyle->firstChildState())
1892 firstElementAfterInsertion->setNeedsStyleRecalc(SubtreeStyleChange); 1893 firstElementAfterInsertion->setNeedsStyleRecalc(SubtreeStyleChange);
1893 1894
1894 // We also have to handle node removal. 1895 // We also have to handle node removal.
1895 if (childCountDelta < 0 && newFirstChild == firstElementAfterInsertion & & newFirstChild && (!newFirstChildStyle || !newFirstChildStyle->firstChildState( ))) 1896 if (childCountDelta < 0 && newFirstChild == firstElementAfterInsertion & & newFirstChild && (!newFirstChildStyle || !newFirstChildStyle->firstChildState( )))
1896 newFirstChild->setNeedsStyleRecalc(SubtreeStyleChange); 1897 newFirstChild->setNeedsStyleRecalc(SubtreeStyleChange);
1897 } 1898 }
1898 1899
1899 // :last-child. In the parser callback case, we don't have to check anythin g, since we were right the first time. 1900 // :last-child. In the parser callback case, we don't have to check anythin g, since we were right the first time.
1900 // In the DOM case, we only need to do something if |afterChange| is not 0. 1901 // In the DOM case, we only need to do something if |afterChange| is not 0.
1901 if (childrenAffectedByLastChildRules() && beforeChange) { 1902 if (childrenAffectedByLastChildRules() && beforeChange) {
1902 // Find our new last child. 1903 // Find our new last child.
1903 Node* newLastChild = lastElementChild(); 1904 Node* newLastChild = lastElementChild();
1904 RenderStyle* newLastChildStyle = newLastChild ? newLastChild->renderStyl e() : 0; 1905 RenderStyle* newLastChildStyle = newLastChild ? newLastChild->renderStyl e() : 0;
1905 1906
1906 // Find the last element node going backwards from |beforeChange| 1907 // Find the last element node going backwards from |beforeChange|
1907 Node* lastElementBeforeInsertion = beforeChange->isElementNode() ? befor eChange : beforeChange->previousElementSibling(); 1908 Node* lastElementBeforeInsertion = beforeChange->isElementNode() ? befor eChange : ElementTraversal::previousSibling(*beforeChange);
1908 RenderStyle* lastElementBeforeInsertionStyle = lastElementBeforeInsertio n ? lastElementBeforeInsertion->renderStyle() : 0; 1909 RenderStyle* lastElementBeforeInsertionStyle = lastElementBeforeInsertio n ? lastElementBeforeInsertion->renderStyle() : 0;
1909 1910
1910 if (newLastChild != lastElementBeforeInsertion && lastElementBeforeInser tionStyle && lastElementBeforeInsertionStyle->lastChildState()) 1911 if (newLastChild != lastElementBeforeInsertion && lastElementBeforeInser tionStyle && lastElementBeforeInsertionStyle->lastChildState())
1911 lastElementBeforeInsertion->setNeedsStyleRecalc(SubtreeStyleChange); 1912 lastElementBeforeInsertion->setNeedsStyleRecalc(SubtreeStyleChange);
1912 1913
1913 // We also have to handle node removal. The parser callback case is sim ilar to node removal as well in that we need to change the last child 1914 // We also have to handle node removal. The parser callback case is sim ilar to node removal as well in that we need to change the last child
1914 // to match now. 1915 // to match now.
1915 if ((childCountDelta < 0 || finishedParsingCallback) && newLastChild == lastElementBeforeInsertion && newLastChild && (!newLastChildStyle || !newLastChi ldStyle->lastChildState())) 1916 if ((childCountDelta < 0 || finishedParsingCallback) && newLastChild == lastElementBeforeInsertion && newLastChild && (!newLastChildStyle || !newLastChi ldStyle->lastChildState()))
1916 newLastChild->setNeedsStyleRecalc(SubtreeStyleChange); 1917 newLastChild->setNeedsStyleRecalc(SubtreeStyleChange);
1917 } 1918 }
1918 1919
1919 // The + selector. We need to invalidate the first element following the in sertion point. It is the only possible element 1920 // The + selector. We need to invalidate the first element following the in sertion point. It is the only possible element
1920 // that could be affected by this DOM change. 1921 // that could be affected by this DOM change.
1921 if (childrenAffectedByDirectAdjacentRules() && afterChange) { 1922 if (childrenAffectedByDirectAdjacentRules() && afterChange) {
1922 if (Node* firstElementAfterInsertion = afterChange->isElementNode() ? af terChange : afterChange->nextElementSibling()) 1923 if (Node* firstElementAfterInsertion = afterChange->isElementNode() ? af terChange : ElementTraversal::nextSibling(*afterChange))
1923 firstElementAfterInsertion->setNeedsStyleRecalc(SubtreeStyleChange); 1924 firstElementAfterInsertion->setNeedsStyleRecalc(SubtreeStyleChange);
1924 } 1925 }
1925 } 1926 }
1926 1927
1927 void Element::childrenChanged(bool changedByParser, Node* beforeChange, Node* af terChange, int childCountDelta) 1928 void Element::childrenChanged(bool changedByParser, Node* beforeChange, Node* af terChange, int childCountDelta)
1928 { 1929 {
1929 ContainerNode::childrenChanged(changedByParser, beforeChange, afterChange, c hildCountDelta); 1930 ContainerNode::childrenChanged(changedByParser, beforeChange, afterChange, c hildCountDelta);
1930 if (changedByParser) 1931 if (changedByParser)
1931 checkForEmptyStyleChange(renderStyle()); 1932 checkForEmptyStyleChange(renderStyle());
1932 else 1933 else
(...skipping 1692 matching lines...) Expand 10 before | Expand all | Expand 10 after
3625 // Before doing so, we need to resolve issues in HTMLSelectElement::recalcLi stItems 3626 // Before doing so, we need to resolve issues in HTMLSelectElement::recalcLi stItems
3626 // and RenderMenuList::setText. See also https://bugs.webkit.org/show_bug.cg i?id=88405 3627 // and RenderMenuList::setText. See also https://bugs.webkit.org/show_bug.cg i?id=88405
3627 if (hasTagName(optionTag) || hasTagName(optgroupTag)) 3628 if (hasTagName(optionTag) || hasTagName(optgroupTag))
3628 return false; 3629 return false;
3629 if (FullscreenElementStack::isActiveFullScreenElement(this)) 3630 if (FullscreenElementStack::isActiveFullScreenElement(this))
3630 return false; 3631 return false;
3631 return true; 3632 return true;
3632 } 3633 }
3633 3634
3634 } // namespace WebCore 3635 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698