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

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

Issue 1188563005: Compute snap offsets (both repeat and element based) (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fix compile issue Created 5 years, 1 month 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
Index: third_party/WebKit/Source/core/layout/LayoutBox.cpp
diff --git a/third_party/WebKit/Source/core/layout/LayoutBox.cpp b/third_party/WebKit/Source/core/layout/LayoutBox.cpp
index 4a4f729789e74e74629b83a48ea724f4c655a1f7..49d2bb7edf98d0337b4c1d2623f64c2c774cc1d0 100644
--- a/third_party/WebKit/Source/core/layout/LayoutBox.cpp
+++ b/third_party/WebKit/Source/core/layout/LayoutBox.cpp
@@ -55,6 +55,7 @@
#include "core/layout/shapes/ShapeOutsideInfo.h"
#include "core/page/AutoscrollController.h"
#include "core/page/Page.h"
+#include "core/page/scrolling/SnapCoordinator.h"
#include "core/paint/BackgroundImageGeometry.h"
#include "core/paint/BoxPainter.h"
#include "core/paint/PaintLayer.h"
@@ -118,6 +119,7 @@ void LayoutBox::willBeDestroyed()
clearOverrideSize();
clearContainingBlockOverrideSize();
clearExtraInlineAndBlockOffests();
+ clearScrollSnapMapping();
LayoutBlock::removePercentHeightDescendantIfNeeded(this);
@@ -126,6 +128,12 @@ void LayoutBox::willBeDestroyed()
LayoutBoxModelObject::willBeDestroyed();
}
+void LayoutBox::insertedIntoTree()
+{
+ LayoutObject::insertedIntoTree();
+ addScrollSnapMapping();
+}
+
void LayoutBox::removeFloatingOrPositionedChildFromBlockLists()
{
ASSERT(isFloatingOrOutOfFlowPositioned());
@@ -260,6 +268,8 @@ void LayoutBox::styleDidChange(StyleDifference diff, const ComputedStyle* oldSty
LayoutFlowThread* flowThread = flowThreadContainingBlock();
if (flowThread && flowThread != this)
flowThread->flowThreadDescendantStyleDidChange(this, diff, *oldStyle);
+
+ updateScrollSnapMappingAfterStyleChange(&newStyle, oldStyle);
esprehn 2015/12/01 18:31:11 newStyle should be a reference, don't do & here.
majidvp 2015/12/03 17:54:16 Good point. I have now changed the code to make |a
}
}
@@ -330,6 +340,40 @@ void LayoutBox::updateGridPositionAfterStyleChange(const ComputedStyle* oldStyle
toLayoutGrid(parent())->dirtyGrid();
}
+void LayoutBox::updateScrollSnapMappingAfterStyleChange(const ComputedStyle* newStyle, const ComputedStyle* oldStyle)
+{
+ SnapCoordinator* snapCoordinator = document().snapCoordinator();
+ if (!snapCoordinator)
+ return;
+
+ ScrollSnapType oldSnapType = oldStyle ? oldStyle->scrollSnapType() : ScrollSnapTypeNone;
+ ScrollSnapType newSnapType = newStyle ? newStyle->scrollSnapType() : ScrollSnapTypeNone;
+ if (oldSnapType != newSnapType)
+ snapCoordinator->snapContainerDidChange(*this, newSnapType);
+
+ Vector<LengthPoint> emptyVector;
+ const Vector<LengthPoint>& oldSnapCoordinate = oldStyle ? oldStyle->scrollSnapCoordinate() : emptyVector;
+ const Vector<LengthPoint>& newSnapCoordinate = newStyle ? newStyle->scrollSnapCoordinate() : emptyVector;
esprehn 2015/12/01 18:31:11 newStyle can't be null, you don't need the null ch
majidvp 2015/12/03 17:54:16 See above.
+ if (oldSnapCoordinate != newSnapCoordinate)
+ snapCoordinator->snapAreaDidChange(*this, newSnapCoordinate);
+}
+
+void LayoutBox::addScrollSnapMapping()
+{
+ updateScrollSnapMappingAfterStyleChange(style(), nullptr);
+}
+
+void LayoutBox::clearScrollSnapMapping()
+{
+ if (SnapAreaSet* areas = snapAreas()) {
+ for (auto& snapArea : *areas)
+ snapArea->m_rareData->m_snapContainer = nullptr;
+ areas->clear();
+ }
+
+ this->setSnapContainer(nullptr);
esprehn 2015/12/01 18:31:11 Why do you need this-> ?
majidvp 2015/12/03 17:54:16 Done.
+}
+
void LayoutBox::updateFromStyle()
{
LayoutBoxModelObject::updateFromStyle();
@@ -4845,4 +4889,38 @@ ShapeOutsideInfo* LayoutBox::shapeOutsideInfo() const
return ShapeOutsideInfo::isEnabledFor(*this) ? ShapeOutsideInfo::info(*this) : nullptr;
}
+LayoutBox* LayoutBox::snapContainer() const
+{
+ return m_rareData ? m_rareData->m_snapContainer : nullptr;
+}
+
+void LayoutBox::setSnapContainer(LayoutBox* container)
+{
+ if (LayoutBox* currentContainer = snapContainer())
+ currentContainer->removeSnapArea(*this);
+
+ ensureRareData().m_snapContainer = container;
+
+ if (container)
+ container->addSnapArea(*this);
+}
+
+
+void LayoutBox::addSnapArea(const LayoutBox& snapArea)
+{
+ ensureRareData().ensureSnapAreas().add(&snapArea);
+}
+
+void LayoutBox::removeSnapArea(const LayoutBox& snapArea)
+{
+ if (m_rareData && m_rareData->m_snapAreas) {
+ m_rareData->m_snapAreas->remove(&snapArea);
+ }
+}
+
+SnapAreaSet* LayoutBox::snapAreas() const
+{
+ return m_rareData ? m_rareData->m_snapAreas.get() : nullptr;
+}
+
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698