Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "core/layout/ScrollAnchor.h" | 5 #include "core/layout/ScrollAnchor.h" |
| 6 | 6 |
| 7 #include "core/frame/FrameView.h" | |
| 8 #include "core/layout/LayoutBox.h" | |
| 9 #include "core/layout/LayoutView.h" | |
| 10 #include "core/paint/PaintLayerScrollableArea.h" | |
| 7 #include "platform/scroll/ScrollableArea.h" | 11 #include "platform/scroll/ScrollableArea.h" |
| 8 #include "wtf/Assertions.h" | 12 #include "wtf/Assertions.h" |
| 9 | 13 |
| 10 namespace blink { | 14 namespace blink { |
| 11 | 15 |
| 12 ScrollAnchor::ScrollAnchor(ScrollableArea* scroller) | 16 ScrollAnchor::ScrollAnchor(ScrollableArea* scroller) |
| 13 : m_scroller(scroller) | 17 : m_scroller(scroller) |
| 14 { | 18 { |
| 15 ASSERT(m_scroller); | 19 ASSERT(m_scroller); |
| 16 ASSERT(m_scroller->isFrameView() || m_scroller->isPaintLayerScrollableArea() ); | 20 ASSERT(m_scroller->isFrameView() || m_scroller->isPaintLayerScrollableArea() ); |
| 17 } | 21 } |
| 18 | 22 |
| 19 ScrollAnchor::~ScrollAnchor() | 23 ScrollAnchor::~ScrollAnchor() |
| 20 { | 24 { |
| 21 } | 25 } |
| 22 | 26 |
| 27 static LayoutBox* scrollerLayoutBox(const ScrollableArea* scroller) | |
| 28 { | |
| 29 LayoutBox* box = scroller->isFrameView() | |
| 30 ? toFrameView(scroller)->layoutView() | |
| 31 : &toPaintLayerScrollableArea(scroller)->box(); | |
| 32 ASSERT(box); | |
| 33 return box; | |
| 34 } | |
| 35 | |
| 23 static LayoutObject* findAnchor(const ScrollableArea* scroller) | 36 static LayoutObject* findAnchor(const ScrollableArea* scroller) |
| 24 { | 37 { |
| 25 // TODO(skobes): implement. | 38 LayoutBox* scrollerBox = scrollerLayoutBox(scroller); |
| 26 return nullptr; | 39 |
| 40 FloatRect absoluteVisibleRect = scroller->isFrameView() | |
| 41 ? scroller->visibleContentRect() | |
| 42 : scrollerBox->localToAbsoluteQuad( | |
|
chrishtr
2016/02/02 17:56:15
absolute maps to the space of the containing view,
skobes
2016/02/02 23:03:55
I agree, however it may require some new plumbing
| |
| 43 FloatQuad(FloatRect(scrollerBox->overflowClipRect(LayoutPoint())))). boundingBox(); | |
| 44 | |
| 45 LayoutObject* child = scrollerBox->nextInPreOrder(scrollerBox); | |
| 46 LayoutObject* candidate = nullptr; | |
| 47 while (child) { | |
|
ojan
2016/02/02 06:26:41
I think we'll need to think about how out of flow
skobes
2016/02/02 23:03:55
Yes I expect we'll add a bunch of edge cases and e
| |
| 48 FloatRect childRect = child->absoluteBoundingBoxFloatRect(); | |
| 49 if (absoluteVisibleRect.intersects(childRect)) | |
| 50 candidate = child; | |
|
ojan
2016/02/02 06:26:41
I think we can make this more efficient by restart
skobes
2016/02/02 23:03:55
I was thinking we should prefer a fully-contained
ojan
2016/02/03 01:37:03
Do A and B both partially overlap the viewport in
skobes
2016/02/04 01:51:15
Yes, A and B both partially overlap (perhaps A con
| |
| 51 if (absoluteVisibleRect.contains(childRect)) | |
| 52 break; | |
| 53 child = child->nextInPreOrder(scrollerBox); | |
| 54 } | |
| 55 return candidate; | |
| 27 } | 56 } |
| 28 | 57 |
| 29 static DoublePoint computeRelativeOffset(const ScrollableArea* scroller, const L ayoutObject* layoutObject) | 58 static DoublePoint computeRelativeOffset(const ScrollableArea* scroller, const L ayoutObject* layoutObject) |
| 30 { | 59 { |
| 31 // TODO(skobes): implement. | 60 return DoublePoint(layoutObject->localToAbsolute() - scrollerLayoutBox(scrol ler)->localToAbsolute()); |
| 32 return DoublePoint(); | |
| 33 } | 61 } |
| 34 | 62 |
| 35 void ScrollAnchor::save() | 63 void ScrollAnchor::save() |
| 36 { | 64 { |
| 37 if (!m_layoutObject) | 65 if (!m_layoutObject) |
| 38 m_layoutObject = findAnchor(m_scroller); | 66 m_layoutObject = findAnchor(m_scroller); |
| 39 | 67 |
| 40 if (m_layoutObject) | 68 if (m_layoutObject) |
| 41 m_savedRelativeOffset = computeRelativeOffset(m_scroller, m_layoutObject ); | 69 m_savedRelativeOffset = computeRelativeOffset(m_scroller, m_layoutObject ); |
| 42 } | 70 } |
| 43 | 71 |
| 44 void ScrollAnchor::restore() | 72 void ScrollAnchor::restore() |
| 45 { | 73 { |
| 46 if (!m_layoutObject) | 74 if (!m_layoutObject) |
| 47 return; | 75 return; |
| 48 | 76 |
| 49 DoubleSize adjustment = computeRelativeOffset(m_scroller, m_layoutObject) - m_savedRelativeOffset; | 77 DoubleSize adjustment = computeRelativeOffset(m_scroller, m_layoutObject) - m_savedRelativeOffset; |
| 50 if (!adjustment.isZero()) | 78 if (!adjustment.isZero()) |
| 51 m_scroller->setScrollPosition(m_scroller->scrollPositionDouble() + adjus tment, AnchoringScroll); | 79 m_scroller->setScrollPosition(m_scroller->scrollPositionDouble() + adjus tment, AnchoringScroll); |
| 52 } | 80 } |
| 53 | 81 |
| 54 } // namespace blink | 82 } // namespace blink |
| OLD | NEW |