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

Side by Side Diff: third_party/WebKit/Source/core/layout/LayoutObject.cpp

Issue 2394053004: Clear scroll anchor on all parent scrollers from ScrollAnchor::clear (Closed)
Patch Set: Created 4 years, 2 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) 2000 Dirk Mueller (mueller@kde.org) 4 * (C) 2000 Dirk Mueller (mueller@kde.org)
5 * (C) 2004 Allan Sandfeld Jensen (kde@carewolf.com) 5 * (C) 2004 Allan Sandfeld Jensen (kde@carewolf.com)
6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2011 Apple Inc. All rights reserv ed. 6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2011 Apple Inc. All rights reserv ed.
7 * Copyright (C) 2009 Google Inc. All rights reserved. 7 * Copyright (C) 2009 Google Inc. All rights reserved.
8 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmo bile.com/) 8 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmo bile.com/)
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 24 matching lines...) Expand all
35 #include "core/dom/shadow/ShadowRoot.h" 35 #include "core/dom/shadow/ShadowRoot.h"
36 #include "core/editing/EditingUtilities.h" 36 #include "core/editing/EditingUtilities.h"
37 #include "core/editing/FrameSelection.h" 37 #include "core/editing/FrameSelection.h"
38 #include "core/editing/TextAffinity.h" 38 #include "core/editing/TextAffinity.h"
39 #include "core/frame/DeprecatedScheduleStyleRecalcDuringLayout.h" 39 #include "core/frame/DeprecatedScheduleStyleRecalcDuringLayout.h"
40 #include "core/frame/EventHandlerRegistry.h" 40 #include "core/frame/EventHandlerRegistry.h"
41 #include "core/frame/FrameView.h" 41 #include "core/frame/FrameView.h"
42 #include "core/frame/LocalFrame.h" 42 #include "core/frame/LocalFrame.h"
43 #include "core/frame/Settings.h" 43 #include "core/frame/Settings.h"
44 #include "core/html/HTMLElement.h" 44 #include "core/html/HTMLElement.h"
45 #include "core/html/HTMLFrameOwnerElement.h"
45 #include "core/html/HTMLHtmlElement.h" 46 #include "core/html/HTMLHtmlElement.h"
46 #include "core/html/HTMLTableCellElement.h" 47 #include "core/html/HTMLTableCellElement.h"
47 #include "core/html/HTMLTableElement.h" 48 #include "core/html/HTMLTableElement.h"
48 #include "core/input/EventHandler.h" 49 #include "core/input/EventHandler.h"
49 #include "core/inspector/InstanceCounters.h" 50 #include "core/inspector/InstanceCounters.h"
50 #include "core/layout/HitTestResult.h" 51 #include "core/layout/HitTestResult.h"
51 #include "core/layout/LayoutCounter.h" 52 #include "core/layout/LayoutCounter.h"
52 #include "core/layout/LayoutDeprecatedFlexibleBox.h" 53 #include "core/layout/LayoutDeprecatedFlexibleBox.h"
53 #include "core/layout/LayoutFlexibleBox.h" 54 #include "core/layout/LayoutFlexibleBox.h"
54 #include "core/layout/LayoutFlowThread.h" 55 #include "core/layout/LayoutFlowThread.h"
(...skipping 2515 matching lines...) Expand 10 before | Expand all | Expand 10 after
2570 layer->dirtyVisibleContentStatus(); 2571 layer->dirtyVisibleContentStatus();
2571 } 2572 }
2572 2573
2573 if (parent()->childrenInline()) 2574 if (parent()->childrenInline())
2574 parent()->dirtyLinesFromChangedChild(this); 2575 parent()->dirtyLinesFromChangedChild(this);
2575 2576
2576 if (LayoutFlowThread* flowThread = flowThreadContainingBlock()) 2577 if (LayoutFlowThread* flowThread = flowThreadContainingBlock())
2577 flowThread->flowThreadDescendantWasInserted(this); 2578 flowThread->flowThreadDescendantWasInserted(this);
2578 } 2579 }
2579 2580
2580 enum FindReferencingScrollAnchorsBehavior { DontClear, Clear }; 2581 enum FindScrollAnchorsBehavior { FindReferencing, ClearReferencing, ClearAll };
2581 2582
2582 static bool findReferencingScrollAnchors( 2583 // Returns true if scroller has layoutObject as its anchor.
2583 LayoutObject* layoutObject, 2584 static bool clearScrollAnchorForScroller(ScrollableArea* scroller,
ymalik 2016/10/06 19:51:13 @skobes, a note to make reviewing easier. This fu
2584 FindReferencingScrollAnchorsBehavior behavior) { 2585 LayoutObject* layoutObject,
2586 FindScrollAnchorsBehavior behavior) {
2587 DCHECK(scroller);
2588 ScrollAnchor* anchor = scroller->scrollAnchor();
2589 DCHECK(anchor);
2590 bool refersTo = false;
2591 if (anchor->refersTo(layoutObject)) {
2592 refersTo = true;
2593 if (behavior == FindReferencing)
2594 return refersTo;
2595 layoutObject->setIsScrollAnchorObject(false);
2596 anchor->releaseAnchor();
2597 } else if (behavior == ClearAll && anchor->anchorObject()) {
2598 anchor->anchorObject()->setIsScrollAnchorObject(false);
2599 anchor->releaseAnchor();
2600 }
2601 return refersTo;
2602 }
2603
2604 // Returns true if any of scroller in the parent chain of layoutObject has
2605 // layoutObject as its anchor. If FindScrollAnchorsBehavior is ClearAll, all
2606 // the scrollers in the parent chain of layoutObject will have their scroll
2607 // anchor cleared. If FindScrollAnchorsBehavior is ClearReferencing, all the
2608 // scrollers in the parent chain of layoutObject that have layoutObject as their
2609 // anchor will have their scroll anchor cleared.
2610 static bool findScrollAnchors(LayoutObject* layoutObject,
2611 FindScrollAnchorsBehavior behavior) {
2585 PaintLayer* layer = nullptr; 2612 PaintLayer* layer = nullptr;
2586 if (LayoutObject* parent = layoutObject->parent()) 2613 if (LayoutObject* parent = layoutObject->parent())
2587 layer = parent->enclosingLayer(); 2614 layer = parent->enclosingLayer();
2588 bool found = false; 2615 bool found = false;
2589 2616
2590 // Walk up the layer tree to clear any scroll anchors that reference us. 2617 // Walk up the layer tree to clear scroll anchors if required.
2591 while (layer) { 2618 while (layer) {
2592 if (PaintLayerScrollableArea* scrollableArea = layer->getScrollableArea()) { 2619 if (PaintLayerScrollableArea* scroller = layer->getScrollableArea()) {
2593 ScrollAnchor* anchor = scrollableArea->scrollAnchor(); 2620 found = clearScrollAnchorForScroller(scroller, layoutObject, behavior) ||
2594 DCHECK(anchor); 2621 found;
2595 if (anchor->refersTo(layoutObject)) { 2622 if (found && behavior == FindReferencing)
2596 found = true; 2623 return found;
2597 if (behavior == Clear)
2598 anchor->notifyRemoved(layoutObject);
2599 else
2600 return true;
2601 }
2602 } 2624 }
2603 layer = layer->parent(); 2625 layer = layer->parent();
2604 } 2626 }
2627
2605 if (FrameView* view = layoutObject->frameView()) { 2628 if (FrameView* view = layoutObject->frameView()) {
2606 ScrollAnchor* anchor = view->scrollAnchor(); 2629 found = clearScrollAnchorForScroller(view, layoutObject, behavior) || found;
2607 DCHECK(anchor); 2630 if (found && behavior == FindReferencing)
2608 if (anchor->refersTo(layoutObject)) { 2631 return found;
2609 found = true; 2632 }
2610 if (behavior == Clear) 2633
2611 anchor->notifyRemoved(layoutObject); 2634 // Continue walk past frame boundary.
2612 } 2635 if (layoutObject->document().localOwner()) {
2636 found =
2637 findScrollAnchors(layoutObject->document().localOwner()->layoutObject(),
2638 behavior) ||
2639 found;
2613 } 2640 }
2614 return found; 2641 return found;
2615 } 2642 }
2616 2643
2617 void LayoutObject::willBeRemovedFromTree() { 2644 void LayoutObject::willBeRemovedFromTree() {
2618 // FIXME: We should ASSERT(isRooted()) but we have some out-of-order removals which would need to be fixed first. 2645 // FIXME: We should ASSERT(isRooted()) but we have some out-of-order removals which would need to be fixed first.
2619 2646
2620 // If we remove a visible child from an invisible parent, we don't know the la yer visibility any more. 2647 // If we remove a visible child from an invisible parent, we don't know the la yer visibility any more.
2621 PaintLayer* layer = nullptr; 2648 PaintLayer* layer = nullptr;
2622 if (parent()->style()->visibility() != EVisibility::Visible && 2649 if (parent()->style()->visibility() != EVisibility::Visible &&
(...skipping 13 matching lines...) Expand all
2636 if (isOutOfFlowPositioned() && parent()->childrenInline()) 2663 if (isOutOfFlowPositioned() && parent()->childrenInline())
2637 parent()->dirtyLinesFromChangedChild(this); 2664 parent()->dirtyLinesFromChangedChild(this);
2638 2665
2639 removeFromLayoutFlowThread(); 2666 removeFromLayoutFlowThread();
2640 2667
2641 // Update cached boundaries in SVG layoutObjects if a child is removed. 2668 // Update cached boundaries in SVG layoutObjects if a child is removed.
2642 if (parent()->isSVG()) 2669 if (parent()->isSVG())
2643 parent()->setNeedsBoundariesUpdate(); 2670 parent()->setNeedsBoundariesUpdate();
2644 2671
2645 if (RuntimeEnabledFeatures::scrollAnchoringEnabled() && 2672 if (RuntimeEnabledFeatures::scrollAnchoringEnabled() &&
2646 m_bitfields.isScrollAnchorObject()) { 2673 m_bitfields.isScrollAnchorObject())
2647 // Clear the bit first so that anchor.clear() doesn't recurse into findRefer encingScrollAnchors. 2674 findScrollAnchors(this, ClearReferencing);
2648 m_bitfields.setIsScrollAnchorObject(false); 2675 }
2649 findReferencingScrollAnchors(this, Clear); 2676
2677 void LayoutObject::maybeClearIsScrollAnchorObject() {
2678 if (m_bitfields.isScrollAnchorObject()) {
2679 m_bitfields.setIsScrollAnchorObject(
2680 findScrollAnchors(this, FindReferencing));
2650 } 2681 }
2651 } 2682 }
2652 2683
2653 void LayoutObject::maybeClearIsScrollAnchorObject() { 2684 void LayoutObject::clearScrollAnchors() {
2654 if (m_bitfields.isScrollAnchorObject()) 2685 findScrollAnchors(this, ClearAll);
2655 m_bitfields.setIsScrollAnchorObject(
2656 findReferencingScrollAnchors(this, DontClear));
2657 } 2686 }
2658 2687
2659 void LayoutObject::removeFromLayoutFlowThread() { 2688 void LayoutObject::removeFromLayoutFlowThread() {
2660 if (!isInsideFlowThread()) 2689 if (!isInsideFlowThread())
2661 return; 2690 return;
2662 2691
2663 // Sometimes we remove the element from the flow, but it's not destroyed at th at time. 2692 // Sometimes we remove the element from the flow, but it's not destroyed at th at time.
2664 // It's only until later when we actually destroy it and remove all the childr en from it. 2693 // It's only until later when we actually destroy it and remove all the childr en from it.
2665 // Currently, that happens for firstLetter elements and list markers. 2694 // Currently, that happens for firstLetter elements and list markers.
2666 // Pass in the flow thread so that we don't have to look it up for all the chi ldren. 2695 // Pass in the flow thread so that we don't have to look it up for all the chi ldren.
(...skipping 789 matching lines...) Expand 10 before | Expand all | Expand 10 after
3456 const blink::LayoutObject* root = object1; 3485 const blink::LayoutObject* root = object1;
3457 while (root->parent()) 3486 while (root->parent())
3458 root = root->parent(); 3487 root = root->parent();
3459 root->showLayoutTreeAndMark(object1, "*", object2, "-", 0); 3488 root->showLayoutTreeAndMark(object1, "*", object2, "-", 0);
3460 } else { 3489 } else {
3461 WTFLogAlways("%s", "Cannot showLayoutTree. Root is (nil)"); 3490 WTFLogAlways("%s", "Cannot showLayoutTree. Root is (nil)");
3462 } 3491 }
3463 } 3492 }
3464 3493
3465 #endif 3494 #endif
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/layout/LayoutObject.h ('k') | third_party/WebKit/Source/core/layout/ScrollAnchor.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698