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

Side by Side Diff: third_party/WebKit/Source/core/dom/Document.cpp

Issue 2778153003: Use the flat tree for hover handling. (Closed)
Patch Set: Use the flat tree for hover handling. Created 3 years, 8 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 Dirk Mueller (mueller@kde.org) 4 * (C) 2001 Dirk Mueller (mueller@kde.org)
5 * (C) 2006 Alexey Proskuryakov (ap@webkit.org) 5 * (C) 2006 Alexey Proskuryakov (ap@webkit.org)
6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2011, 2012 Apple Inc. All 6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2011, 2012 Apple Inc. All
7 * rights reserved. 7 * rights reserved.
8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. 8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved.
9 * (http://www.torchmobile.com/) 9 * (http://www.torchmobile.com/)
10 * Copyright (C) 2008, 2009, 2011, 2012 Google Inc. All rights reserved. 10 * Copyright (C) 2008, 2009, 2011, 2012 Google Inc. All rights reserved.
(...skipping 6127 matching lines...) Expand 10 before | Expand all | Expand 10 after
6138 !m_snapCoordinator) 6138 !m_snapCoordinator)
6139 m_snapCoordinator = SnapCoordinator::create(); 6139 m_snapCoordinator = SnapCoordinator::create();
6140 6140
6141 return m_snapCoordinator.get(); 6141 return m_snapCoordinator.get();
6142 } 6142 }
6143 6143
6144 void Document::setContextFeatures(ContextFeatures& features) { 6144 void Document::setContextFeatures(ContextFeatures& features) {
6145 m_contextFeatures = &features; 6145 m_contextFeatures = &features;
6146 } 6146 }
6147 6147
6148 static LayoutObject* nearestCommonHoverAncestor(LayoutObject* obj1,
6149 LayoutObject* obj2) {
6150 if (!obj1 || !obj2)
6151 return 0;
6152
6153 for (LayoutObject* currObj1 = obj1; currObj1;
6154 currObj1 = currObj1->hoverAncestor()) {
6155 for (LayoutObject* currObj2 = obj2; currObj2;
6156 currObj2 = currObj2->hoverAncestor()) {
6157 if (currObj1 == currObj2)
6158 return currObj1;
6159 }
6160 }
6161
6162 return 0;
6163 }
6164
6165 // TODO(mustaq) |request| parameter maybe a misuse of HitTestRequest in 6148 // TODO(mustaq) |request| parameter maybe a misuse of HitTestRequest in
6166 // updateHoverActiveState() since the function doesn't bother with hit-testing. 6149 // updateHoverActiveState() since the function doesn't bother with hit-testing.
6167 void Document::updateHoverActiveState(const HitTestRequest& request, 6150 void Document::updateHoverActiveState(const HitTestRequest& request,
6168 Element* innerElement, 6151 Element* innerElement,
6169 Scrollbar* hitScrollbar) { 6152 Scrollbar* hitScrollbar) {
6170 DCHECK(!request.readOnly()); 6153 DCHECK(!request.readOnly());
6171 6154
6172 if (request.active() && m_frame) 6155 if (request.active() && m_frame)
6173 m_frame->eventHandler().notifyElementActivated(); 6156 m_frame->eventHandler().notifyElementActivated();
6174 6157
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
6232 6215
6233 // Check to see if the hovered node has changed. 6216 // Check to see if the hovered node has changed.
6234 // If it hasn't, we do not need to do anything. 6217 // If it hasn't, we do not need to do anything.
6235 Node* newHoverNode = innerElementInDocument; 6218 Node* newHoverNode = innerElementInDocument;
6236 while (newHoverNode && !newHoverNode->layoutObject()) 6219 while (newHoverNode && !newHoverNode->layoutObject())
6237 newHoverNode = newHoverNode->parentOrShadowHostNode(); 6220 newHoverNode = newHoverNode->parentOrShadowHostNode();
6238 6221
6239 // Update our current hover node. 6222 // Update our current hover node.
6240 setHoverNode(newHoverNode); 6223 setHoverNode(newHoverNode);
6241 6224
6242 // We have two different objects. Fetch their layoutObjects. 6225 // Update the old hover node distribution if needed, in case it's been
6243 LayoutObject* oldHoverObj = 6226 // detached.
6244 oldHoverNode ? oldHoverNode->layoutObject() : nullptr; 6227 //
6245 LayoutObject* newHoverObj = 6228 // TODO(ecobos@igalia.com): Probably detached nodes should never appear here.
6246 newHoverNode ? newHoverNode->layoutObject() : nullptr; 6229 if (oldHoverNode)
6230 oldHoverNode->updateDistribution();
rune 2017/03/30 12:25:19 I just noticed, there a call to Document::updateDi
6247 6231
6248 // Locate the common ancestor layout object for the two layoutObjects. 6232 Node* ancestor =
6249 LayoutObject* ancestor = nearestCommonHoverAncestor(oldHoverObj, newHoverObj); 6233 (oldHoverNode && newHoverNode)
6250 Node* ancestorNode(ancestor ? ancestor->node() : nullptr); 6234 ? FlatTreeTraversal::commonAncestor(*oldHoverNode, *newHoverNode)
6235 : nullptr;
6251 6236
6252 HeapVector<Member<Node>, 32> nodesToRemoveFromChain; 6237 HeapVector<Member<Node>, 32> nodesToRemoveFromChain;
6253 HeapVector<Member<Node>, 32> nodesToAddToChain; 6238 HeapVector<Member<Node>, 32> nodesToAddToChain;
6254 6239
6255 if (oldHoverObj != newHoverObj) { 6240 if (oldHoverNode != newHoverNode) {
6256 // If the old hovered node is not nil but it's layoutObject is, it was
6257 // probably detached as part of the :hover style (for instance by setting
6258 // display:none in the :hover pseudo-class). In this case, the old hovered
6259 // element (and its ancestors) must be updated, to ensure it's normal style
6260 // is re-applied.
6261 if (oldHoverNode && !oldHoverObj) {
6262 for (Node& node : NodeTraversal::inclusiveAncestorsOf(*oldHoverNode)) {
6263 if (!mustBeInActiveChain ||
6264 (node.isElementNode() && toElement(node).inActiveChain()))
6265 nodesToRemoveFromChain.push_back(node);
6266 }
6267 }
6268
6269 // The old hover path only needs to be cleared up to (and not including) the 6241 // The old hover path only needs to be cleared up to (and not including) the
6270 // common ancestor; 6242 // common ancestor;
6271 for (LayoutObject* curr = oldHoverObj; curr && curr != ancestor; 6243 for (Node* curr = oldHoverNode; curr && curr != ancestor;
6272 curr = curr->hoverAncestor()) { 6244 curr = FlatTreeTraversal::parent(*curr)) {
6273 if (curr->node() && !curr->isText() && 6245 if (!curr->isTextNode() &&
6274 (!mustBeInActiveChain || curr->node()->inActiveChain())) 6246 (!mustBeInActiveChain || curr->inActiveChain()))
6275 nodesToRemoveFromChain.push_back(curr->node()); 6247 nodesToRemoveFromChain.push_back(curr);
6276 } 6248 }
6277
6278 // TODO(mustaq): The two loops above may push a single node twice into
6279 // nodesToRemoveFromChain. There must be a better way.
6280 } 6249 }
6281 6250
6282 // Now set the hover state for our new object up to the root. 6251 // Now set the hover state for our new object up to the root.
6283 for (LayoutObject* curr = newHoverObj; curr; curr = curr->hoverAncestor()) { 6252 for (Node* curr = newHoverNode; curr;
6284 if (curr->node() && !curr->isText() && 6253 curr = FlatTreeTraversal::parent(*curr)) {
6285 (!mustBeInActiveChain || curr->node()->inActiveChain())) 6254 if (!curr->isTextNode() && (!mustBeInActiveChain || curr->inActiveChain()))
6286 nodesToAddToChain.push_back(curr->node()); 6255 nodesToAddToChain.push_back(curr);
6287 } 6256 }
6288 6257
6289 size_t removeCount = nodesToRemoveFromChain.size(); 6258 for (Node* node : nodesToRemoveFromChain)
6290 for (size_t i = 0; i < removeCount; ++i) { 6259 node->setHovered(false);
6291 nodesToRemoveFromChain[i]->setHovered(false);
6292 }
6293 6260
6294 bool sawCommonAncestor = false; 6261 bool sawCommonAncestor = false;
6295 size_t addCount = nodesToAddToChain.size(); 6262 for (Node* node : nodesToAddToChain) {
6296 for (size_t i = 0; i < addCount; ++i) {
6297 // Elements past the common ancestor do not change hover state, but might 6263 // Elements past the common ancestor do not change hover state, but might
6298 // change active state. 6264 // change active state.
6299 if (ancestorNode && nodesToAddToChain[i] == ancestorNode) 6265 if (node == ancestor)
6300 sawCommonAncestor = true; 6266 sawCommonAncestor = true;
6301 if (allowActiveChanges) 6267 if (allowActiveChanges)
6302 nodesToAddToChain[i]->setActive(true); 6268 node->setActive(true);
6303 if (!sawCommonAncestor || nodesToAddToChain[i] == m_hoverNode) { 6269 if (!sawCommonAncestor || node == m_hoverNode)
6304 nodesToAddToChain[i]->setHovered(true); 6270 node->setHovered(true);
6305 }
6306 } 6271 }
6307 } 6272 }
6308 6273
6309 bool Document::haveScriptBlockingStylesheetsLoaded() const { 6274 bool Document::haveScriptBlockingStylesheetsLoaded() const {
6310 return m_styleEngine->haveScriptBlockingStylesheetsLoaded(); 6275 return m_styleEngine->haveScriptBlockingStylesheetsLoaded();
6311 } 6276 }
6312 6277
6313 bool Document::haveRenderBlockingStylesheetsLoaded() const { 6278 bool Document::haveRenderBlockingStylesheetsLoaded() const {
6314 if (RuntimeEnabledFeatures::cssInBodyDoesNotBlockPaintEnabled()) 6279 if (RuntimeEnabledFeatures::cssInBodyDoesNotBlockPaintEnabled())
6315 return m_styleEngine->haveRenderBlockingStylesheetsLoaded(); 6280 return m_styleEngine->haveRenderBlockingStylesheetsLoaded();
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
6663 } 6628 }
6664 6629
6665 void showLiveDocumentInstances() { 6630 void showLiveDocumentInstances() {
6666 WeakDocumentSet& set = liveDocumentSet(); 6631 WeakDocumentSet& set = liveDocumentSet();
6667 fprintf(stderr, "There are %u documents currently alive:\n", set.size()); 6632 fprintf(stderr, "There are %u documents currently alive:\n", set.size());
6668 for (blink::Document* document : set) 6633 for (blink::Document* document : set)
6669 fprintf(stderr, "- Document %p URL: %s\n", document, 6634 fprintf(stderr, "- Document %p URL: %s\n", document,
6670 document->url().getString().utf8().data()); 6635 document->url().getString().utf8().data());
6671 } 6636 }
6672 #endif 6637 #endif
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698