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

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: Fix compile issue Created 5 years 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 #include "core/layout/LayoutListMarker.h" 48 #include "core/layout/LayoutListMarker.h"
49 #include "core/layout/LayoutMultiColumnSpannerPlaceholder.h" 49 #include "core/layout/LayoutMultiColumnSpannerPlaceholder.h"
50 #include "core/layout/LayoutPart.h" 50 #include "core/layout/LayoutPart.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/compositing/PaintLayerCompositor.h" 54 #include "core/layout/compositing/PaintLayerCompositor.h"
55 #include "core/layout/shapes/ShapeOutsideInfo.h" 55 #include "core/layout/shapes/ShapeOutsideInfo.h"
56 #include "core/page/AutoscrollController.h" 56 #include "core/page/AutoscrollController.h"
57 #include "core/page/Page.h" 57 #include "core/page/Page.h"
58 #include "core/page/scrolling/SnapCoordinator.h"
58 #include "core/paint/BackgroundImageGeometry.h" 59 #include "core/paint/BackgroundImageGeometry.h"
59 #include "core/paint/BoxPainter.h" 60 #include "core/paint/BoxPainter.h"
60 #include "core/paint/PaintLayer.h" 61 #include "core/paint/PaintLayer.h"
61 #include "core/style/ShadowList.h" 62 #include "core/style/ShadowList.h"
62 #include "platform/LengthFunctions.h" 63 #include "platform/LengthFunctions.h"
63 #include "platform/geometry/DoubleRect.h" 64 #include "platform/geometry/DoubleRect.h"
64 #include "platform/geometry/FloatQuad.h" 65 #include "platform/geometry/FloatQuad.h"
65 #include "platform/geometry/FloatRoundedRect.h" 66 #include "platform/geometry/FloatRoundedRect.h"
66 #include "platform/geometry/TransformState.h" 67 #include "platform/geometry/TransformState.h"
67 #include "platform/graphics/GraphicsContext.h" 68 #include "platform/graphics/GraphicsContext.h"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 return OverflowClipPaintLayer; 112 return OverflowClipPaintLayer;
112 113
113 return NoPaintLayer; 114 return NoPaintLayer;
114 } 115 }
115 116
116 void LayoutBox::willBeDestroyed() 117 void LayoutBox::willBeDestroyed()
117 { 118 {
118 clearOverrideSize(); 119 clearOverrideSize();
119 clearContainingBlockOverrideSize(); 120 clearContainingBlockOverrideSize();
120 clearExtraInlineAndBlockOffests(); 121 clearExtraInlineAndBlockOffests();
122 clearScrollSnapMapping();
121 123
122 LayoutBlock::removePercentHeightDescendantIfNeeded(this); 124 LayoutBlock::removePercentHeightDescendantIfNeeded(this);
123 125
124 ShapeOutsideInfo::removeInfo(*this); 126 ShapeOutsideInfo::removeInfo(*this);
125 127
126 LayoutBoxModelObject::willBeDestroyed(); 128 LayoutBoxModelObject::willBeDestroyed();
127 } 129 }
128 130
131 void LayoutBox::insertedIntoTree()
132 {
133 LayoutObject::insertedIntoTree();
134 addScrollSnapMapping();
135 }
136
129 void LayoutBox::removeFloatingOrPositionedChildFromBlockLists() 137 void LayoutBox::removeFloatingOrPositionedChildFromBlockLists()
130 { 138 {
131 ASSERT(isFloatingOrOutOfFlowPositioned()); 139 ASSERT(isFloatingOrOutOfFlowPositioned());
132 140
133 if (documentBeingDestroyed()) 141 if (documentBeingDestroyed())
134 return; 142 return;
135 143
136 if (isFloating()) { 144 if (isFloating()) {
137 LayoutBlockFlow* parentBlockFlow = nullptr; 145 LayoutBlockFlow* parentBlockFlow = nullptr;
138 for (LayoutObject* curr = parent(); curr && !curr->isLayoutView(); curr = curr->parent()) { 146 for (LayoutObject* curr = parent(); curr && !curr->isLayoutView(); curr = curr->parent()) {
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 261
254 if (LayoutMultiColumnSpannerPlaceholder* placeholder = this->spannerPlacehol der()) 262 if (LayoutMultiColumnSpannerPlaceholder* placeholder = this->spannerPlacehol der())
255 placeholder->layoutObjectInFlowThreadStyleDidChange(oldStyle); 263 placeholder->layoutObjectInFlowThreadStyleDidChange(oldStyle);
256 264
257 updateBackgroundAttachmentFixedStatusAfterStyleChange(); 265 updateBackgroundAttachmentFixedStatusAfterStyleChange();
258 266
259 if (oldStyle) { 267 if (oldStyle) {
260 LayoutFlowThread* flowThread = flowThreadContainingBlock(); 268 LayoutFlowThread* flowThread = flowThreadContainingBlock();
261 if (flowThread && flowThread != this) 269 if (flowThread && flowThread != this)
262 flowThread->flowThreadDescendantStyleDidChange(this, diff, *oldStyle ); 270 flowThread->flowThreadDescendantStyleDidChange(this, diff, *oldStyle );
271
272 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
263 } 273 }
264 } 274 }
265 275
266 void LayoutBox::updateBackgroundAttachmentFixedStatusAfterStyleChange() 276 void LayoutBox::updateBackgroundAttachmentFixedStatusAfterStyleChange()
267 { 277 {
268 if (!frameView()) 278 if (!frameView())
269 return; 279 return;
270 280
271 // On low-powered/mobile devices, preventing blitting on a scroll can cause noticeable delays 281 // On low-powered/mobile devices, preventing blitting on a scroll can cause noticeable delays
272 // when scrolling a page with a fixed background image. As an optimization, assuming there are 282 // when scrolling a page with a fixed background image. As an optimization, assuming there are
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 && oldStyle->gridRowEnd() == style()->gridRowEnd() 333 && oldStyle->gridRowEnd() == style()->gridRowEnd()
324 && oldStyle->order() == style()->order() 334 && oldStyle->order() == style()->order()
325 && oldStyle->hasOutOfFlowPosition() == style()->hasOutOfFlowPosition()) 335 && oldStyle->hasOutOfFlowPosition() == style()->hasOutOfFlowPosition())
326 return; 336 return;
327 337
328 // It should be possible to not dirty the grid in some cases (like moving an explicitly placed grid item). 338 // It should be possible to not dirty the grid in some cases (like moving an explicitly placed grid item).
329 // For now, it's more simple to just always recompute the grid. 339 // For now, it's more simple to just always recompute the grid.
330 toLayoutGrid(parent())->dirtyGrid(); 340 toLayoutGrid(parent())->dirtyGrid();
331 } 341 }
332 342
343 void LayoutBox::updateScrollSnapMappingAfterStyleChange(const ComputedStyle* new Style, const ComputedStyle* oldStyle)
344 {
345 SnapCoordinator* snapCoordinator = document().snapCoordinator();
346 if (!snapCoordinator)
347 return;
348
349 ScrollSnapType oldSnapType = oldStyle ? oldStyle->scrollSnapType() : Scroll SnapTypeNone;
350 ScrollSnapType newSnapType = newStyle ? newStyle->scrollSnapType() : Scroll SnapTypeNone;
351 if (oldSnapType != newSnapType)
352 snapCoordinator->snapContainerDidChange(*this, newSnapType);
353
354 Vector<LengthPoint> emptyVector;
355 const Vector<LengthPoint>& oldSnapCoordinate = oldStyle ? oldStyle->scrollSn apCoordinate() : emptyVector;
356 const Vector<LengthPoint>& newSnapCoordinate = newStyle ? newStyle->scrollSn apCoordinate() : 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.
357 if (oldSnapCoordinate != newSnapCoordinate)
358 snapCoordinator->snapAreaDidChange(*this, newSnapCoordinate);
359 }
360
361 void LayoutBox::addScrollSnapMapping()
362 {
363 updateScrollSnapMappingAfterStyleChange(style(), nullptr);
364 }
365
366 void LayoutBox::clearScrollSnapMapping()
367 {
368 if (SnapAreaSet* areas = snapAreas()) {
369 for (auto& snapArea : *areas)
370 snapArea->m_rareData->m_snapContainer = nullptr;
371 areas->clear();
372 }
373
374 this->setSnapContainer(nullptr);
esprehn 2015/12/01 18:31:11 Why do you need this-> ?
majidvp 2015/12/03 17:54:16 Done.
375 }
376
333 void LayoutBox::updateFromStyle() 377 void LayoutBox::updateFromStyle()
334 { 378 {
335 LayoutBoxModelObject::updateFromStyle(); 379 LayoutBoxModelObject::updateFromStyle();
336 380
337 const ComputedStyle& styleToUse = styleRef(); 381 const ComputedStyle& styleToUse = styleRef();
338 bool isViewObject = isLayoutView(); 382 bool isViewObject = isLayoutView();
339 bool rootLayerScrolls = document().settings() && document().settings()->root LayerScrolls(); 383 bool rootLayerScrolls = document().settings() && document().settings()->root LayerScrolls();
340 384
341 // LayoutView of the main frame is resposible from painting base background. 385 // LayoutView of the main frame is resposible from painting base background.
342 if (isViewObject && !document().ownerElement()) 386 if (isViewObject && !document().ownerElement())
(...skipping 4495 matching lines...) Expand 10 before | Expand all | Expand 10 after
4838 4882
4839 StyleImage* borderImage = style()->borderImage().image(); 4883 StyleImage* borderImage = style()->borderImage().image();
4840 return borderImage && borderImage->canRender() && borderImage->isLoaded(); 4884 return borderImage && borderImage->canRender() && borderImage->isLoaded();
4841 } 4885 }
4842 4886
4843 ShapeOutsideInfo* LayoutBox::shapeOutsideInfo() const 4887 ShapeOutsideInfo* LayoutBox::shapeOutsideInfo() const
4844 { 4888 {
4845 return ShapeOutsideInfo::isEnabledFor(*this) ? ShapeOutsideInfo::info(*this) : nullptr; 4889 return ShapeOutsideInfo::isEnabledFor(*this) ? ShapeOutsideInfo::info(*this) : nullptr;
4846 } 4890 }
4847 4891
4892 LayoutBox* LayoutBox::snapContainer() const
4893 {
4894 return m_rareData ? m_rareData->m_snapContainer : nullptr;
4895 }
4896
4897 void LayoutBox::setSnapContainer(LayoutBox* container)
4898 {
4899 if (LayoutBox* currentContainer = snapContainer())
4900 currentContainer->removeSnapArea(*this);
4901
4902 ensureRareData().m_snapContainer = container;
4903
4904 if (container)
4905 container->addSnapArea(*this);
4906 }
4907
4908
4909 void LayoutBox::addSnapArea(const LayoutBox& snapArea)
4910 {
4911 ensureRareData().ensureSnapAreas().add(&snapArea);
4912 }
4913
4914 void LayoutBox::removeSnapArea(const LayoutBox& snapArea)
4915 {
4916 if (m_rareData && m_rareData->m_snapAreas) {
4917 m_rareData->m_snapAreas->remove(&snapArea);
4918 }
4919 }
4920
4921 SnapAreaSet* LayoutBox::snapAreas() const
4922 {
4923 return m_rareData ? m_rareData->m_snapAreas.get() : nullptr;
4924 }
4925
4848 } // namespace blink 4926 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698