Chromium Code Reviews| 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 c19121ee003cbbcfcc1514687d54ab80e6589498..f1de3122b05d66b2e042da0f463131557257e202 100644 |
| --- a/third_party/WebKit/Source/core/layout/LayoutBox.cpp |
| +++ b/third_party/WebKit/Source/core/layout/LayoutBox.cpp |
| @@ -56,6 +56,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" |
| @@ -145,6 +146,7 @@ void LayoutBox::willBeDestroyed() |
| void LayoutBox::insertedIntoTree() |
| { |
| LayoutBoxModelObject::insertedIntoTree(); |
| + addScrollSnapMapping(); |
| if (isOrthogonalWritingModeRoot()) |
| markOrthogonalWritingModeRoot(); |
| @@ -155,6 +157,7 @@ void LayoutBox::willBeRemovedFromTree() |
| if (!documentBeingDestroyed() && isOrthogonalWritingModeRoot()) |
| unmarkOrthogonalWritingModeRoot(); |
| + clearScrollSnapMapping(); |
| LayoutBoxModelObject::willBeRemovedFromTree(); |
| } |
| @@ -167,7 +170,7 @@ void LayoutBox::removeFloatingOrPositionedChildFromBlockLists() |
| if (isFloating()) { |
| LayoutBlockFlow* parentBlockFlow = nullptr; |
| - for (LayoutObject* curr = parent(); curr && !curr->isLayoutView(); curr = curr->parent()) { |
| + for (LayoutObject* curr = parent(); curr && !curr-isLayoutView(); curr = curr->parent()) { |
|
skobes
2016/03/07 03:42:27
This change looks unintended.
majidvp
2016/05/03 17:23:36
Ops! It compiles with no warning and does not trip
|
| if (curr->isLayoutBlockFlow()) { |
| LayoutBlockFlow* currBlockFlow = toLayoutBlockFlow(curr); |
| if (!parentBlockFlow || currBlockFlow->containsFloat(this)) |
| @@ -301,6 +304,8 @@ void LayoutBox::styleDidChange(StyleDifference diff, const ComputedStyle* oldSty |
| LayoutFlowThread* flowThread = flowThreadContainingBlock(); |
| if (flowThread && flowThread != this) |
| flowThread->flowThreadDescendantStyleDidChange(this, diff, *oldStyle); |
| + |
| + updateScrollSnapMappingAfterStyleChange(&newStyle, oldStyle); |
| } |
| ASSERT(!isInline() || isAtomicInlineLevel()); // Non-atomic inlines should be LayoutInline or LayoutText, not LayoutBox. |
| @@ -373,6 +378,34 @@ 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->getScrollSnapType() : ScrollSnapTypeNone; |
|
skobes
2016/03/07 03:42:27
You have an extra space after :
(here and through
majidvp
2016/05/03 17:23:36
Done.
|
| + ScrollSnapType newSnapType = newStyle ? newStyle->getScrollSnapType() : 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; |
| + if (oldSnapCoordinate != newSnapCoordinate) |
| + snapCoordinator->snapAreaDidChange(*this, newSnapCoordinate); |
| +} |
| + |
| +void LayoutBox::addScrollSnapMapping() |
| +{ |
| + updateScrollSnapMappingAfterStyleChange(style(), nullptr); |
| +} |
| + |
| +void LayoutBox::clearScrollSnapMapping() |
| +{ |
| + updateScrollSnapMappingAfterStyleChange(nullptr, style()); |
| +} |
| + |
| void LayoutBox::updateFromStyle() |
| { |
| LayoutBoxModelObject::updateFromStyle(); |
| @@ -4672,4 +4705,46 @@ void LayoutBox::IntrinsicSizingInfo::transpose() |
| std::swap(hasWidth, hasHeight); |
| } |
| +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; |
|
skobes
2016/03/07 03:42:27
If container is null, we don't need m_rareData. P
majidvp
2016/05/03 17:23:36
Good point. Although we still want to clear existi
|
| + |
| + if (container) |
| + container->addSnapArea(*this); |
| +} |
| + |
| +void LayoutBox::clearSnapAreas() |
| +{ |
| + if (SnapAreaSet* areas = snapAreas()) { |
| + for (auto& snapArea : *areas) |
| + snapArea->m_rareData->m_snapContainer = nullptr; |
| + areas->clear(); |
| + } |
| +} |
| + |
| +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 |