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

Unified Diff: third_party/WebKit/Source/core/layout/ScrollAnchor.cpp

Issue 1640973005: Implement findAnchor and computeRelativeOffset in ScrollAnchor. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@anchor-hookup
Patch Set: Created 4 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/layout/ScrollAnchorTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/layout/ScrollAnchor.cpp
diff --git a/third_party/WebKit/Source/core/layout/ScrollAnchor.cpp b/third_party/WebKit/Source/core/layout/ScrollAnchor.cpp
index 0b4a85d02dd0c068b629815050c143fe62b3e1c0..e1a4e7e1645f8b56163c30568ff8480ebfd6dda0 100644
--- a/third_party/WebKit/Source/core/layout/ScrollAnchor.cpp
+++ b/third_party/WebKit/Source/core/layout/ScrollAnchor.cpp
@@ -4,6 +4,10 @@
#include "core/layout/ScrollAnchor.h"
+#include "core/frame/FrameView.h"
+#include "core/layout/LayoutBox.h"
+#include "core/layout/LayoutView.h"
+#include "core/paint/PaintLayerScrollableArea.h"
#include "platform/scroll/ScrollableArea.h"
#include "wtf/Assertions.h"
@@ -20,16 +24,40 @@ ScrollAnchor::~ScrollAnchor()
{
}
+static LayoutBox* scrollerLayoutBox(const ScrollableArea* scroller)
+{
+ LayoutBox* box = scroller->isFrameView()
+ ? toFrameView(scroller)->layoutView()
+ : &toPaintLayerScrollableArea(scroller)->box();
+ ASSERT(box);
+ return box;
+}
+
static LayoutObject* findAnchor(const ScrollableArea* scroller)
{
- // TODO(skobes): implement.
- return nullptr;
+ LayoutBox* scrollerBox = scrollerLayoutBox(scroller);
+
+ FloatRect absoluteVisibleRect = scroller->isFrameView()
+ ? scroller->visibleContentRect()
+ : 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
+ FloatQuad(FloatRect(scrollerBox->overflowClipRect(LayoutPoint())))).boundingBox();
+
+ LayoutObject* child = scrollerBox->nextInPreOrder(scrollerBox);
+ LayoutObject* candidate = nullptr;
+ 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
+ FloatRect childRect = child->absoluteBoundingBoxFloatRect();
+ if (absoluteVisibleRect.intersects(childRect))
+ 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
+ if (absoluteVisibleRect.contains(childRect))
+ break;
+ child = child->nextInPreOrder(scrollerBox);
+ }
+ return candidate;
}
static DoublePoint computeRelativeOffset(const ScrollableArea* scroller, const LayoutObject* layoutObject)
{
- // TODO(skobes): implement.
- return DoublePoint();
+ return DoublePoint(layoutObject->localToAbsolute() - scrollerLayoutBox(scroller)->localToAbsolute());
}
void ScrollAnchor::save()
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/layout/ScrollAnchorTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698