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

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

Issue 2965603002: Update hover states when dragging the mouse into an element (Closed)
Patch Set: hover active chain Created 3 years, 5 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 | « third_party/WebKit/LayoutTests/platform/win/editing/selection/drag-select-1-expected.png ('k') | 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 6471 matching lines...) Expand 10 before | Expand all | Expand 10 after
6482 // Do not set hover state if event is from touch and on mobile. 6482 // Do not set hover state if event is from touch and on mobile.
6483 bool allow_hover_changes = 6483 bool allow_hover_changes =
6484 !(request.TouchEvent() && GetPage() && 6484 !(request.TouchEvent() && GetPage() &&
6485 GetPage()->GetVisualViewport().ShouldDisableDesktopWorkarounds()); 6485 GetPage()->GetVisualViewport().ShouldDisableDesktopWorkarounds());
6486 6486
6487 // If the mouse has just been pressed, set :active on the chain. Those (and 6487 // If the mouse has just been pressed, set :active on the chain. Those (and
6488 // only those) nodes should remain :active until the mouse is released. 6488 // only those) nodes should remain :active until the mouse is released.
6489 bool allow_active_changes = !old_active_element && ActiveHoverElement(); 6489 bool allow_active_changes = !old_active_element && ActiveHoverElement();
6490 6490
6491 // If the mouse is down and if this is a mouse move event, we want to restrict 6491 // If the mouse is down and if this is a mouse move event, we want to restrict
6492 // changes in :hover/:active to only apply to elements that are in the :active 6492 // changes in :active to only apply to elements that are in the :active
6493 // chain that we froze at the time the mouse went down. 6493 // chain that we froze at the time the mouse went down.
6494 bool must_be_in_active_chain = request.Active() && request.Move(); 6494 bool must_be_in_active_chain = request.Active() && request.Move();
6495 6495
6496 Element* old_hover_element = HoverElement(); 6496 Element* old_hover_element = HoverElement();
6497 6497
6498 // The passed in innerElement may not be a result of a hit test for the 6498 // The passed in innerElement may not be a result of a hit test for the
6499 // current up-to-date flat/layout tree. That means the element may be 6499 // current up-to-date flat/layout tree. That means the element may be
6500 // display:none at this point. Skip up the ancestor chain until we reach an 6500 // display:none at this point. Skip up the ancestor chain until we reach an
6501 // element with a layoutObject or a display:contents element. 6501 // element with a layoutObject or a display:contents element.
6502 Element* new_hover_element = 6502 Element* new_hover_element =
6503 SkipDisplayNoneAncestors(inner_element_in_document); 6503 SkipDisplayNoneAncestors(inner_element_in_document);
6504 6504
6505 // Update our current hover element. 6505 // Update our current hover element.
6506 if (allow_hover_changes) 6506 if (allow_hover_changes)
6507 SetHoverElement(new_hover_element); 6507 SetHoverElement(new_hover_element);
6508 6508
6509 Node* ancestor_element = nullptr; 6509 Node* ancestor_element = nullptr;
6510 if (old_hover_element && old_hover_element->isConnected() && 6510 if (old_hover_element && old_hover_element->isConnected() &&
6511 new_hover_element) { 6511 new_hover_element) {
6512 Node* ancestor = FlatTreeTraversal::CommonAncestor(*old_hover_element, 6512 Node* ancestor = FlatTreeTraversal::CommonAncestor(*old_hover_element,
6513 *new_hover_element); 6513 *new_hover_element);
6514 if (ancestor && ancestor->IsElementNode()) 6514 if (ancestor && ancestor->IsElementNode())
6515 ancestor_element = ToElement(ancestor); 6515 ancestor_element = ToElement(ancestor);
6516 } 6516 }
6517 6517
6518 HeapVector<Member<Element>, 32> elements_to_remove_from_chain; 6518 HeapVector<Member<Element>, 32> elements_to_remove_from_chain;
6519 HeapVector<Member<Element>, 32> elements_to_add_to_chain; 6519 HeapVector<Member<Element>, 32> elements_to_add_to_active_chain;
6520 HeapVector<Member<Element>, 32> elements_to_add_to_hover_chain;
6520 6521
6521 if (old_hover_element != new_hover_element) { 6522 if (old_hover_element != new_hover_element) {
6522 // The old hover path only needs to be cleared up to (and not including) the 6523 // The old hover path only needs to be cleared up to (and not including) the
6523 // common ancestor; 6524 // common ancestor;
6524 // 6525 //
6525 // FIXME(ecobos@igalia.com): oldHoverElement may be disconnected from the 6526 // FIXME(ecobos@igalia.com): oldHoverElement may be disconnected from the
6526 // tree already. This is due to our handling of m_hoverElement in 6527 // tree already. This is due to our handling of m_hoverElement in
6527 // hoveredElementDetached (which assumes all the parents are hovered) and 6528 // hoveredElementDetached (which assumes all the parents are hovered) and
6528 // mustBeInActiveChain (which makes this not hold). 6529 // mustBeInActiveChain (which makes this not hold).
6529 // 6530 //
6530 // In that case, none of the nodes in the chain have the flags, so there's 6531 // In that case, none of the nodes in the chain have the flags, so there's
6531 // no problem in skipping this step. 6532 // no problem in skipping this step.
Navid Zolghadr 2017/07/04 17:51:59 I believe this comment doesn't hold anymore. Does
lanwei 2017/07/06 15:33:38 Done.
6532 if (old_hover_element && old_hover_element->isConnected()) { 6533 if (old_hover_element && old_hover_element->isConnected()) {
6533 for (Element* curr = old_hover_element; curr && curr != ancestor_element; 6534 for (Element* curr = old_hover_element; curr && curr != ancestor_element;
6534 curr = FlatTreeTraversal::ParentElement(*curr)) { 6535 curr = FlatTreeTraversal::ParentElement(*curr)) {
6535 if (!must_be_in_active_chain || curr->InActiveChain()) 6536 elements_to_remove_from_chain.push_back(curr);
6536 elements_to_remove_from_chain.push_back(curr);
6537 } 6537 }
6538 } 6538 }
6539 } 6539 }
6540 6540
6541 // Now set the hover state for our new object up to the root. 6541 // Now set the hover state for our new object up to the root.
6542 for (Element* curr = new_hover_element; curr; 6542 for (Element* curr = new_hover_element; curr;
6543 curr = FlatTreeTraversal::ParentElement(*curr)) { 6543 curr = FlatTreeTraversal::ParentElement(*curr)) {
6544 elements_to_add_to_hover_chain.push_back(curr);
Navid Zolghadr 2017/07/04 17:51:59 Do we need a check like old_hover_element != new_h
6544 if (!must_be_in_active_chain || curr->InActiveChain()) 6545 if (!must_be_in_active_chain || curr->InActiveChain())
6545 elements_to_add_to_chain.push_back(curr); 6546 elements_to_add_to_active_chain.push_back(curr);
6546 } 6547 }
6547 6548
6548 if (allow_hover_changes) { 6549 if (allow_hover_changes) {
6549 for (Element* element : elements_to_remove_from_chain) 6550 for (Element* element : elements_to_remove_from_chain)
6550 element->SetHovered(false); 6551 element->SetHovered(false);
6551 } 6552 }
6552 6553
6554 // Elements past the common ancestor do not change hover state, but might
6555 // change active state.
6556 for (Element* element : elements_to_add_to_active_chain) {
6557 if (allow_active_changes)
6558 element->SetActive(true);
6559 }
6560
6553 bool saw_common_ancestor = false; 6561 bool saw_common_ancestor = false;
6554 for (Element* element : elements_to_add_to_chain) { 6562 for (Element* element : elements_to_add_to_hover_chain) {
6555 // Elements past the common ancestor do not change hover state, but might
6556 // change active state.
6557 if (element == ancestor_element) 6563 if (element == ancestor_element)
6558 saw_common_ancestor = true; 6564 saw_common_ancestor = true;
6559 if (allow_active_changes)
6560 element->SetActive(true);
6561 if (allow_hover_changes && 6565 if (allow_hover_changes &&
6562 (!saw_common_ancestor || element == hover_element_)) 6566 (!saw_common_ancestor || element == hover_element_))
6563 element->SetHovered(true); 6567 element->SetHovered(true);
6564 } 6568 }
6565 } 6569 }
6566 6570
6567 bool Document::HaveScriptBlockingStylesheetsLoaded() const { 6571 bool Document::HaveScriptBlockingStylesheetsLoaded() const {
6568 return style_engine_->HaveScriptBlockingStylesheetsLoaded(); 6572 return style_engine_->HaveScriptBlockingStylesheetsLoaded();
6569 } 6573 }
6570 6574
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after
6920 } 6924 }
6921 6925
6922 void showLiveDocumentInstances() { 6926 void showLiveDocumentInstances() {
6923 WeakDocumentSet& set = liveDocumentSet(); 6927 WeakDocumentSet& set = liveDocumentSet();
6924 fprintf(stderr, "There are %u documents currently alive:\n", set.size()); 6928 fprintf(stderr, "There are %u documents currently alive:\n", set.size());
6925 for (blink::Document* document : set) 6929 for (blink::Document* document : set)
6926 fprintf(stderr, "- Document %p URL: %s\n", document, 6930 fprintf(stderr, "- Document %p URL: %s\n", document,
6927 document->Url().GetString().Utf8().data()); 6931 document->Url().GetString().Utf8().data());
6928 } 6932 }
6929 #endif 6933 #endif
OLDNEW
« no previous file with comments | « third_party/WebKit/LayoutTests/platform/win/editing/selection/drag-select-1-expected.png ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698