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

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: rebase and fix merge 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 2513 matching lines...) Expand 10 before | Expand all | Expand 10 after
2568 layer->dirtyVisibleContentStatus(); 2569 layer->dirtyVisibleContentStatus();
2569 } 2570 }
2570 2571
2571 if (parent()->childrenInline()) 2572 if (parent()->childrenInline())
2572 parent()->dirtyLinesFromChangedChild(this); 2573 parent()->dirtyLinesFromChangedChild(this);
2573 2574
2574 if (LayoutFlowThread* flowThread = flowThreadContainingBlock()) 2575 if (LayoutFlowThread* flowThread = flowThreadContainingBlock())
2575 flowThread->flowThreadDescendantWasInserted(this); 2576 flowThread->flowThreadDescendantWasInserted(this);
2576 } 2577 }
2577 2578
2578 enum FindReferencingScrollAnchorsBehavior { DontClear, Clear }; 2579 enum FindScrollAnchorsBehavior { FindReferencing, ClearReferencing, ClearAll };
2579 2580
2580 static bool findReferencingScrollAnchors( 2581 // Returns true if scroller has layoutObject as its anchor.
2581 LayoutObject* layoutObject, 2582 static bool clearScrollAnchorForScroller(ScrollableArea* scroller,
2582 FindReferencingScrollAnchorsBehavior behavior) { 2583 LayoutObject* layoutObject,
2584 FindScrollAnchorsBehavior behavior) {
2585 DCHECK(scroller);
2586 ScrollAnchor* anchor = scroller->scrollAnchor();
2587 DCHECK(anchor);
2588 bool refersTo = false;
2589 if (anchor->refersTo(layoutObject)) {
2590 refersTo = true;
2591 if (behavior == FindReferencing)
2592 return refersTo;
2593 layoutObject->setIsScrollAnchorObject(false);
2594 anchor->releaseAnchor();
2595 } else if (behavior == ClearAll && anchor->anchorObject()) {
2596 anchor->anchorObject()->setIsScrollAnchorObject(false);
2597 anchor->releaseAnchor();
2598 }
2599 return refersTo;
2600 }
2601
2602 // Returns true if any of scroller in the parent chain of layoutObject has
2603 // layoutObject as its anchor. If FindScrollAnchorsBehavior is ClearAll, all
2604 // the scrollers in the parent chain of layoutObject will have their scroll
2605 // anchor cleared. If FindScrollAnchorsBehavior is ClearReferencing, all the
2606 // scrollers in the parent chain of layoutObject that have layoutObject as their
2607 // anchor will have their scroll anchor cleared.
2608 static bool findScrollAnchors(LayoutObject* layoutObject,
2609 FindScrollAnchorsBehavior behavior) {
2583 PaintLayer* layer = nullptr; 2610 PaintLayer* layer = nullptr;
2584 if (LayoutObject* parent = layoutObject->parent()) 2611 if (LayoutObject* parent = layoutObject->parent())
2585 layer = parent->enclosingLayer(); 2612 layer = parent->enclosingLayer();
2586 bool found = false; 2613 bool found = false;
2587 2614
2588 // Walk up the layer tree to clear any scroll anchors that reference us. 2615 // Walk up the layer tree to clear scroll anchors if required.
2589 while (layer) { 2616 while (layer) {
2590 if (PaintLayerScrollableArea* scrollableArea = layer->getScrollableArea()) { 2617 if (PaintLayerScrollableArea* scroller = layer->getScrollableArea()) {
2591 ScrollAnchor* anchor = scrollableArea->scrollAnchor(); 2618 found = clearScrollAnchorForScroller(scroller, layoutObject, behavior) ||
2592 DCHECK(anchor); 2619 found;
2593 if (anchor->refersTo(layoutObject)) { 2620 if (found && behavior == FindReferencing)
2594 found = true; 2621 return found;
2595 if (behavior == Clear)
2596 anchor->notifyRemoved(layoutObject);
2597 else
2598 return true;
2599 }
2600 } 2622 }
2601 layer = layer->parent(); 2623 layer = layer->parent();
2602 } 2624 }
2625
2603 if (FrameView* view = layoutObject->frameView()) { 2626 if (FrameView* view = layoutObject->frameView()) {
2604 ScrollAnchor* anchor = view->scrollAnchor(); 2627 found = clearScrollAnchorForScroller(view, layoutObject, behavior) || found;
2605 DCHECK(anchor); 2628 if (found && behavior == FindReferencing)
2606 if (anchor->refersTo(layoutObject)) { 2629 return found;
2607 found = true; 2630 }
2608 if (behavior == Clear) 2631
2609 anchor->notifyRemoved(layoutObject); 2632 // Continue walk past frame boundary.
skobes 2016/10/10 21:34:35 Hmm, do we actually want this behavior? We don't
ymalik 2016/10/11 19:54:22 hmm you're right. I was under the impression that
2610 } 2633 if (layoutObject->document().localOwner()) {
2634 found =
2635 findScrollAnchors(layoutObject->document().localOwner()->layoutObject(),
2636 behavior) ||
2637 found;
2611 } 2638 }
2612 return found; 2639 return found;
2613 } 2640 }
2614 2641
2615 void LayoutObject::willBeRemovedFromTree() { 2642 void LayoutObject::willBeRemovedFromTree() {
2616 // FIXME: We should ASSERT(isRooted()) but we have some out-of-order removals which would need to be fixed first. 2643 // FIXME: We should ASSERT(isRooted()) but we have some out-of-order removals which would need to be fixed first.
2617 2644
2618 // If we remove a visible child from an invisible parent, we don't know the la yer visibility any more. 2645 // If we remove a visible child from an invisible parent, we don't know the la yer visibility any more.
2619 PaintLayer* layer = nullptr; 2646 PaintLayer* layer = nullptr;
2620 if (parent()->style()->visibility() != EVisibility::Visible && 2647 if (parent()->style()->visibility() != EVisibility::Visible &&
(...skipping 13 matching lines...) Expand all
2634 if (isOutOfFlowPositioned() && parent()->childrenInline()) 2661 if (isOutOfFlowPositioned() && parent()->childrenInline())
2635 parent()->dirtyLinesFromChangedChild(this); 2662 parent()->dirtyLinesFromChangedChild(this);
2636 2663
2637 removeFromLayoutFlowThread(); 2664 removeFromLayoutFlowThread();
2638 2665
2639 // Update cached boundaries in SVG layoutObjects if a child is removed. 2666 // Update cached boundaries in SVG layoutObjects if a child is removed.
2640 if (parent()->isSVG()) 2667 if (parent()->isSVG())
2641 parent()->setNeedsBoundariesUpdate(); 2668 parent()->setNeedsBoundariesUpdate();
2642 2669
2643 if (RuntimeEnabledFeatures::scrollAnchoringEnabled() && 2670 if (RuntimeEnabledFeatures::scrollAnchoringEnabled() &&
2644 m_bitfields.isScrollAnchorObject()) { 2671 m_bitfields.isScrollAnchorObject())
2645 // Clear the bit first so that anchor.clear() doesn't recurse into findRefer encingScrollAnchors. 2672 findScrollAnchors(this, ClearReferencing);
2646 m_bitfields.setIsScrollAnchorObject(false); 2673 }
2647 findReferencingScrollAnchors(this, Clear); 2674
2675 void LayoutObject::maybeClearIsScrollAnchorObject() {
2676 if (m_bitfields.isScrollAnchorObject()) {
2677 m_bitfields.setIsScrollAnchorObject(
2678 findScrollAnchors(this, FindReferencing));
2648 } 2679 }
2649 } 2680 }
2650 2681
2651 void LayoutObject::maybeClearIsScrollAnchorObject() { 2682 void LayoutObject::clearScrollAnchors() {
2652 if (m_bitfields.isScrollAnchorObject()) 2683 findScrollAnchors(this, ClearAll);
2653 m_bitfields.setIsScrollAnchorObject(
2654 findReferencingScrollAnchors(this, DontClear));
2655 } 2684 }
2656 2685
2657 void LayoutObject::removeFromLayoutFlowThread() { 2686 void LayoutObject::removeFromLayoutFlowThread() {
2658 if (!isInsideFlowThread()) 2687 if (!isInsideFlowThread())
2659 return; 2688 return;
2660 2689
2661 // Sometimes we remove the element from the flow, but it's not destroyed at th at time. 2690 // Sometimes we remove the element from the flow, but it's not destroyed at th at time.
2662 // It's only until later when we actually destroy it and remove all the childr en from it. 2691 // It's only until later when we actually destroy it and remove all the childr en from it.
2663 // Currently, that happens for firstLetter elements and list markers. 2692 // Currently, that happens for firstLetter elements and list markers.
2664 // Pass in the flow thread so that we don't have to look it up for all the chi ldren. 2693 // 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
3454 const blink::LayoutObject* root = object1; 3483 const blink::LayoutObject* root = object1;
3455 while (root->parent()) 3484 while (root->parent())
3456 root = root->parent(); 3485 root = root->parent();
3457 root->showLayoutTreeAndMark(object1, "*", object2, "-", 0); 3486 root->showLayoutTreeAndMark(object1, "*", object2, "-", 0);
3458 } else { 3487 } else {
3459 WTFLogAlways("%s", "Cannot showLayoutTree. Root is (nil)"); 3488 WTFLogAlways("%s", "Cannot showLayoutTree. Root is (nil)");
3460 } 3489 }
3461 } 3490 }
3462 3491
3463 #endif 3492 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698