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

Side by Side 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: rebase Created 4 years, 9 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) 2005 Allan Sandfeld Jensen (kde@carewolf.com) 4 * (C) 2005 Allan Sandfeld Jensen (kde@carewolf.com)
5 * (C) 2005, 2006 Samuel Weinig (sam.weinig@gmail.com) 5 * (C) 2005, 2006 Samuel Weinig (sam.weinig@gmail.com)
6 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserv ed. 6 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserv ed.
7 * Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved. 7 * Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved.
8 * 8 *
9 * This library is free software; you can redistribute it and/or 9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public 10 * modify it under the terms of the GNU Library General Public
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 #include "core/layout/LayoutPart.h" 49 #include "core/layout/LayoutPart.h"
50 #include "core/layout/LayoutReplica.h" 50 #include "core/layout/LayoutReplica.h"
51 #include "core/layout/LayoutScrollbarPart.h" 51 #include "core/layout/LayoutScrollbarPart.h"
52 #include "core/layout/LayoutTableCell.h" 52 #include "core/layout/LayoutTableCell.h"
53 #include "core/layout/LayoutView.h" 53 #include "core/layout/LayoutView.h"
54 #include "core/layout/api/LineLayoutBox.h" 54 #include "core/layout/api/LineLayoutBox.h"
55 #include "core/layout/compositing/PaintLayerCompositor.h" 55 #include "core/layout/compositing/PaintLayerCompositor.h"
56 #include "core/layout/shapes/ShapeOutsideInfo.h" 56 #include "core/layout/shapes/ShapeOutsideInfo.h"
57 #include "core/page/AutoscrollController.h" 57 #include "core/page/AutoscrollController.h"
58 #include "core/page/Page.h" 58 #include "core/page/Page.h"
59 #include "core/page/scrolling/SnapCoordinator.h"
59 #include "core/paint/BackgroundImageGeometry.h" 60 #include "core/paint/BackgroundImageGeometry.h"
60 #include "core/paint/BoxPainter.h" 61 #include "core/paint/BoxPainter.h"
61 #include "core/paint/PaintLayer.h" 62 #include "core/paint/PaintLayer.h"
62 #include "core/style/ShadowList.h" 63 #include "core/style/ShadowList.h"
63 #include "platform/LengthFunctions.h" 64 #include "platform/LengthFunctions.h"
64 #include "platform/geometry/DoubleRect.h" 65 #include "platform/geometry/DoubleRect.h"
65 #include "platform/geometry/FloatQuad.h" 66 #include "platform/geometry/FloatQuad.h"
66 #include "platform/geometry/FloatRoundedRect.h" 67 #include "platform/geometry/FloatRoundedRect.h"
67 #include "platform/geometry/TransformState.h" 68 #include "platform/geometry/TransformState.h"
68 #include "platform/graphics/GraphicsContext.h" 69 #include "platform/graphics/GraphicsContext.h"
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 unmarkOrthogonalWritingModeRoot(); 139 unmarkOrthogonalWritingModeRoot();
139 140
140 ShapeOutsideInfo::removeInfo(*this); 141 ShapeOutsideInfo::removeInfo(*this);
141 142
142 LayoutBoxModelObject::willBeDestroyed(); 143 LayoutBoxModelObject::willBeDestroyed();
143 } 144 }
144 145
145 void LayoutBox::insertedIntoTree() 146 void LayoutBox::insertedIntoTree()
146 { 147 {
147 LayoutBoxModelObject::insertedIntoTree(); 148 LayoutBoxModelObject::insertedIntoTree();
149 addScrollSnapMapping();
148 150
149 if (isOrthogonalWritingModeRoot()) 151 if (isOrthogonalWritingModeRoot())
150 markOrthogonalWritingModeRoot(); 152 markOrthogonalWritingModeRoot();
151 } 153 }
152 154
153 void LayoutBox::willBeRemovedFromTree() 155 void LayoutBox::willBeRemovedFromTree()
154 { 156 {
155 if (!documentBeingDestroyed() && isOrthogonalWritingModeRoot()) 157 if (!documentBeingDestroyed() && isOrthogonalWritingModeRoot())
156 unmarkOrthogonalWritingModeRoot(); 158 unmarkOrthogonalWritingModeRoot();
157 159
160 clearScrollSnapMapping();
158 LayoutBoxModelObject::willBeRemovedFromTree(); 161 LayoutBoxModelObject::willBeRemovedFromTree();
159 } 162 }
160 163
161 void LayoutBox::removeFloatingOrPositionedChildFromBlockLists() 164 void LayoutBox::removeFloatingOrPositionedChildFromBlockLists()
162 { 165 {
163 ASSERT(isFloatingOrOutOfFlowPositioned()); 166 ASSERT(isFloatingOrOutOfFlowPositioned());
164 167
165 if (documentBeingDestroyed()) 168 if (documentBeingDestroyed())
166 return; 169 return;
167 170
168 if (isFloating()) { 171 if (isFloating()) {
169 LayoutBlockFlow* parentBlockFlow = nullptr; 172 LayoutBlockFlow* parentBlockFlow = nullptr;
170 for (LayoutObject* curr = parent(); curr && !curr->isLayoutView(); curr = curr->parent()) { 173 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
171 if (curr->isLayoutBlockFlow()) { 174 if (curr->isLayoutBlockFlow()) {
172 LayoutBlockFlow* currBlockFlow = toLayoutBlockFlow(curr); 175 LayoutBlockFlow* currBlockFlow = toLayoutBlockFlow(curr);
173 if (!parentBlockFlow || currBlockFlow->containsFloat(this)) 176 if (!parentBlockFlow || currBlockFlow->containsFloat(this))
174 parentBlockFlow = currBlockFlow; 177 parentBlockFlow = currBlockFlow;
175 } 178 }
176 } 179 }
177 180
178 if (parentBlockFlow) { 181 if (parentBlockFlow) {
179 parentBlockFlow->markSiblingsWithFloatsForLayout(this); 182 parentBlockFlow->markSiblingsWithFloatsForLayout(this);
180 parentBlockFlow->markAllDescendantsWithFloatsForLayout(this, false); 183 parentBlockFlow->markAllDescendantsWithFloatsForLayout(this, false);
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 297
295 if (LayoutMultiColumnSpannerPlaceholder* placeholder = this->spannerPlacehol der()) 298 if (LayoutMultiColumnSpannerPlaceholder* placeholder = this->spannerPlacehol der())
296 placeholder->layoutObjectInFlowThreadStyleDidChange(oldStyle); 299 placeholder->layoutObjectInFlowThreadStyleDidChange(oldStyle);
297 300
298 updateBackgroundAttachmentFixedStatusAfterStyleChange(); 301 updateBackgroundAttachmentFixedStatusAfterStyleChange();
299 302
300 if (oldStyle) { 303 if (oldStyle) {
301 LayoutFlowThread* flowThread = flowThreadContainingBlock(); 304 LayoutFlowThread* flowThread = flowThreadContainingBlock();
302 if (flowThread && flowThread != this) 305 if (flowThread && flowThread != this)
303 flowThread->flowThreadDescendantStyleDidChange(this, diff, *oldStyle ); 306 flowThread->flowThreadDescendantStyleDidChange(this, diff, *oldStyle );
307
308 updateScrollSnapMappingAfterStyleChange(&newStyle, oldStyle);
304 } 309 }
305 310
306 ASSERT(!isInline() || isAtomicInlineLevel()); // Non-atomic inlines should b e LayoutInline or LayoutText, not LayoutBox. 311 ASSERT(!isInline() || isAtomicInlineLevel()); // Non-atomic inlines should b e LayoutInline or LayoutText, not LayoutBox.
307 } 312 }
308 313
309 void LayoutBox::updateBackgroundAttachmentFixedStatusAfterStyleChange() 314 void LayoutBox::updateBackgroundAttachmentFixedStatusAfterStyleChange()
310 { 315 {
311 if (!frameView()) 316 if (!frameView())
312 return; 317 return;
313 318
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 && oldStyle->gridRowEnd() == style()->gridRowEnd() 371 && oldStyle->gridRowEnd() == style()->gridRowEnd()
367 && oldStyle->order() == style()->order() 372 && oldStyle->order() == style()->order()
368 && oldStyle->hasOutOfFlowPosition() == style()->hasOutOfFlowPosition()) 373 && oldStyle->hasOutOfFlowPosition() == style()->hasOutOfFlowPosition())
369 return; 374 return;
370 375
371 // It should be possible to not dirty the grid in some cases (like moving an explicitly placed grid item). 376 // It should be possible to not dirty the grid in some cases (like moving an explicitly placed grid item).
372 // For now, it's more simple to just always recompute the grid. 377 // For now, it's more simple to just always recompute the grid.
373 toLayoutGrid(parent())->dirtyGrid(); 378 toLayoutGrid(parent())->dirtyGrid();
374 } 379 }
375 380
381 void LayoutBox::updateScrollSnapMappingAfterStyleChange(const ComputedStyle* new Style, const ComputedStyle* oldStyle)
382 {
383 SnapCoordinator* snapCoordinator = document().snapCoordinator();
384 if (!snapCoordinator)
385 return;
386
387 ScrollSnapType oldSnapType = oldStyle ? oldStyle->getScrollSnapType() : Scr ollSnapTypeNone;
skobes 2016/03/07 03:42:27 You have an extra space after : (here and through
majidvp 2016/05/03 17:23:36 Done.
388 ScrollSnapType newSnapType = newStyle ? newStyle->getScrollSnapType() : Scr ollSnapTypeNone;
389 if (oldSnapType != newSnapType)
390 snapCoordinator->snapContainerDidChange(*this, newSnapType);
391
392 Vector<LengthPoint> emptyVector;
393 const Vector<LengthPoint>& oldSnapCoordinate = oldStyle ? oldStyle->scrollSn apCoordinate() : emptyVector;
394 const Vector<LengthPoint>& newSnapCoordinate = newStyle ? newStyle->scrollSn apCoordinate() : emptyVector;
395 if (oldSnapCoordinate != newSnapCoordinate)
396 snapCoordinator->snapAreaDidChange(*this, newSnapCoordinate);
397 }
398
399 void LayoutBox::addScrollSnapMapping()
400 {
401 updateScrollSnapMappingAfterStyleChange(style(), nullptr);
402 }
403
404 void LayoutBox::clearScrollSnapMapping()
405 {
406 updateScrollSnapMappingAfterStyleChange(nullptr, style());
407 }
408
376 void LayoutBox::updateFromStyle() 409 void LayoutBox::updateFromStyle()
377 { 410 {
378 LayoutBoxModelObject::updateFromStyle(); 411 LayoutBoxModelObject::updateFromStyle();
379 412
380 const ComputedStyle& styleToUse = styleRef(); 413 const ComputedStyle& styleToUse = styleRef();
381 setFloating(!isOutOfFlowPositioned() && styleToUse.isFloating()); 414 setFloating(!isOutOfFlowPositioned() && styleToUse.isFloating());
382 setHasTransformRelatedProperty(styleToUse.hasTransformRelatedProperty()); 415 setHasTransformRelatedProperty(styleToUse.hasTransformRelatedProperty());
383 setHasReflection(styleToUse.boxReflect()); 416 setHasReflection(styleToUse.boxReflect());
384 } 417 }
385 418
(...skipping 4279 matching lines...) Expand 10 before | Expand all | Expand 10 after
4665 } 4698 }
4666 } 4699 }
4667 4700
4668 void LayoutBox::IntrinsicSizingInfo::transpose() 4701 void LayoutBox::IntrinsicSizingInfo::transpose()
4669 { 4702 {
4670 size = size.transposedSize(); 4703 size = size.transposedSize();
4671 aspectRatio = aspectRatio.transposedSize(); 4704 aspectRatio = aspectRatio.transposedSize();
4672 std::swap(hasWidth, hasHeight); 4705 std::swap(hasWidth, hasHeight);
4673 } 4706 }
4674 4707
4708 LayoutBox* LayoutBox::snapContainer() const
4709 {
4710 return m_rareData ? m_rareData->m_snapContainer : nullptr;
4711 }
4712
4713 void LayoutBox::setSnapContainer(LayoutBox* container)
4714 {
4715 if (LayoutBox* currentContainer = snapContainer())
4716 currentContainer->removeSnapArea(*this);
4717
4718 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
4719
4720 if (container)
4721 container->addSnapArea(*this);
4722 }
4723
4724 void LayoutBox::clearSnapAreas()
4725 {
4726 if (SnapAreaSet* areas = snapAreas()) {
4727 for (auto& snapArea : *areas)
4728 snapArea->m_rareData->m_snapContainer = nullptr;
4729 areas->clear();
4730 }
4731 }
4732
4733 void LayoutBox::addSnapArea(const LayoutBox& snapArea)
4734 {
4735 ensureRareData().ensureSnapAreas().add(&snapArea);
4736 }
4737
4738 void LayoutBox::removeSnapArea(const LayoutBox& snapArea)
4739 {
4740 if (m_rareData && m_rareData->m_snapAreas) {
4741 m_rareData->m_snapAreas->remove(&snapArea);
4742 }
4743 }
4744
4745 SnapAreaSet* LayoutBox::snapAreas() const
4746 {
4747 return m_rareData ? m_rareData->m_snapAreas.get() : nullptr;
4748 }
4749
4675 } // namespace blink 4750 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698