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

Side by Side Diff: sky/engine/core/rendering/RenderBlockFlow.h

Issue 700743002: Remove margin collapsing. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 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 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) 2007 David Smith (catfish.man@gmail.com) 4 * (C) 2007 David Smith (catfish.man@gmail.com)
5 * Copyright (C) 2003-2013 Apple Inc. All rights reserved. 5 * Copyright (C) 2003-2013 Apple Inc. All rights reserved.
6 * Copyright (C) Research In Motion Limited 2010. All rights reserved. 6 * Copyright (C) Research In Motion Limited 2010. All rights reserved.
7 * Copyright (C) 2013 Google Inc. All rights reserved. 7 * Copyright (C) 2013 Google Inc. All rights reserved.
8 * 8 *
9 * Redistribution and use in source and binary forms, with or without 9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are 10 * modification, are permitted provided that the following conditions are
(...skipping 24 matching lines...) Expand all
35 35
36 #ifndef RenderBlockFlow_h 36 #ifndef RenderBlockFlow_h
37 #define RenderBlockFlow_h 37 #define RenderBlockFlow_h
38 38
39 #include "core/rendering/RenderBlock.h" 39 #include "core/rendering/RenderBlock.h"
40 #include "core/rendering/line/TrailingObjects.h" 40 #include "core/rendering/line/TrailingObjects.h"
41 #include "core/rendering/style/RenderStyleConstants.h" 41 #include "core/rendering/style/RenderStyleConstants.h"
42 42
43 namespace blink { 43 namespace blink {
44 44
45 class MarginInfo;
46 class LineBreaker; 45 class LineBreaker;
47 class LineWidth; 46 class LineWidth;
48 class FloatingObject; 47 class FloatingObject;
49 48
50 class RenderBlockFlow : public RenderBlock { 49 class RenderBlockFlow : public RenderBlock {
51 public: 50 public:
52 explicit RenderBlockFlow(ContainerNode*); 51 explicit RenderBlockFlow(ContainerNode*);
53 virtual ~RenderBlockFlow(); 52 virtual ~RenderBlockFlow();
54 virtual void trace(Visitor*) override;
55 53
56 static RenderBlockFlow* createAnonymous(Document*); 54 static RenderBlockFlow* createAnonymous(Document*);
57 55
58 virtual bool isRenderBlockFlow() const override final { return true; } 56 virtual bool isRenderBlockFlow() const override final { return true; }
59 57
60 virtual void layoutBlock(bool relayoutChildren) override; 58 virtual void layoutBlock(bool relayoutChildren) override;
61 59
62 virtual void deleteLineBoxTree() override final; 60 virtual void deleteLineBoxTree() override final;
63 61
64 LayoutUnit availableLogicalWidthForLine(LayoutUnit position, bool shouldInde ntText, LayoutUnit logicalHeight = 0) const 62 LayoutUnit availableLogicalWidthForLine(LayoutUnit position, bool shouldInde ntText, LayoutUnit logicalHeight = 0) const
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 } 132 }
135 133
136 virtual bool updateLogicalWidthAndColumnWidth() override; 134 virtual bool updateLogicalWidthAndColumnWidth() override;
137 135
138 void determineLogicalLeftPositionForChild(RenderBox* child); 136 void determineLogicalLeftPositionForChild(RenderBox* child);
139 137
140 private: 138 private:
141 void layoutBlockFlow(bool relayoutChildren, SubtreeLayoutScope&); 139 void layoutBlockFlow(bool relayoutChildren, SubtreeLayoutScope&);
142 void layoutBlockChildren(bool relayoutChildren, SubtreeLayoutScope&, LayoutU nit beforeEdge, LayoutUnit afterEdge); 140 void layoutBlockChildren(bool relayoutChildren, SubtreeLayoutScope&, LayoutU nit beforeEdge, LayoutUnit afterEdge);
143 141
144 void layoutBlockChild(RenderBox* child, MarginInfo&); 142 void layoutBlockChild(RenderBox* child);
145 void adjustPositionedBlock(RenderBox* child, const MarginInfo&); 143 void adjustPositionedBlock(RenderBox* child);
146 144
147 virtual bool hitTestFloats(const HitTestRequest&, HitTestResult&, const HitT estLocation& locationInContainer, const LayoutPoint& accumulatedOffset) override final; 145 virtual bool hitTestFloats(const HitTestRequest&, HitTestResult&, const HitT estLocation& locationInContainer, const LayoutPoint& accumulatedOffset) override final;
148 146
149 virtual void invalidatePaintForOverflow() override final; 147 virtual void invalidatePaintForOverflow() override final;
150 virtual void paintFloats(PaintInfo&, const LayoutPoint&, bool preservePhase = false) override final; 148 virtual void paintFloats(PaintInfo&, const LayoutPoint&, bool preservePhase = false) override final;
151 149
152 LayoutUnit logicalRightFloatOffsetForLine(LayoutUnit logicalTop, LayoutUnit fixedOffset, LayoutUnit logicalHeight) const; 150 LayoutUnit logicalRightFloatOffsetForLine(LayoutUnit logicalTop, LayoutUnit fixedOffset, LayoutUnit logicalHeight) const;
153 LayoutUnit logicalLeftFloatOffsetForLine(LayoutUnit logicalTop, LayoutUnit f ixedOffset, LayoutUnit logicalHeight) const; 151 LayoutUnit logicalLeftFloatOffsetForLine(LayoutUnit logicalTop, LayoutUnit f ixedOffset, LayoutUnit logicalHeight) const;
154 152
155 LayoutUnit logicalRightOffsetForPositioningFloat(LayoutUnit logicalTop, Layo utUnit fixedOffset, bool applyTextIndent, LayoutUnit* heightRemaining) const; 153 LayoutUnit logicalRightOffsetForPositioningFloat(LayoutUnit logicalTop, Layo utUnit fixedOffset, bool applyTextIndent, LayoutUnit* heightRemaining) const;
(...skipping 13 matching lines...) Expand all
169 , rect(LayoutRect(f->x() - f->marginLeft(), f->y() - f->marginTop(), f->width() + f->marginWidth(), f->height() + f->marginHeight())) 167 , rect(LayoutRect(f->x() - f->marginLeft(), f->y() - f->marginTop(), f->width() + f->marginWidth(), f->height() + f->marginHeight()))
170 , everHadLayout(f->everHadLayout()) 168 , everHadLayout(f->everHadLayout())
171 { 169 {
172 } 170 }
173 171
174 RenderBox* object; 172 RenderBox* object;
175 LayoutRect rect; 173 LayoutRect rect;
176 bool everHadLayout; 174 bool everHadLayout;
177 }; 175 };
178 176
179 class MarginValues {
180 public:
181 MarginValues(LayoutUnit beforePos, LayoutUnit beforeNeg, LayoutUnit afte rPos, LayoutUnit afterNeg)
182 : m_positiveMarginBefore(beforePos)
183 , m_negativeMarginBefore(beforeNeg)
184 , m_positiveMarginAfter(afterPos)
185 , m_negativeMarginAfter(afterNeg)
186 { }
187
188 LayoutUnit positiveMarginBefore() const { return m_positiveMarginBefore; }
189 LayoutUnit negativeMarginBefore() const { return m_negativeMarginBefore; }
190 LayoutUnit positiveMarginAfter() const { return m_positiveMarginAfter; }
191 LayoutUnit negativeMarginAfter() const { return m_negativeMarginAfter; }
192
193 void setPositiveMarginBefore(LayoutUnit pos) { m_positiveMarginBefore = pos; }
194 void setNegativeMarginBefore(LayoutUnit neg) { m_negativeMarginBefore = neg; }
195 void setPositiveMarginAfter(LayoutUnit pos) { m_positiveMarginAfter = po s; }
196 void setNegativeMarginAfter(LayoutUnit neg) { m_negativeMarginAfter = ne g; }
197
198 private:
199 LayoutUnit m_positiveMarginBefore;
200 LayoutUnit m_negativeMarginBefore;
201 LayoutUnit m_positiveMarginAfter;
202 LayoutUnit m_negativeMarginAfter;
203 };
204 MarginValues marginValuesForChild(RenderBox* child) const;
205
206 // Allocated only when some of these fields have non-default values
207 struct RenderBlockFlowRareData : public DummyBase<RenderBlockFlowRareData> {
208 WTF_MAKE_NONCOPYABLE(RenderBlockFlowRareData); WTF_MAKE_FAST_ALLOCATED_W ILL_BE_REMOVED;
209 public:
210 RenderBlockFlowRareData(const RenderBlockFlow* block)
211 : m_margins(positiveMarginBeforeDefault(block), negativeMarginBefore Default(block), positiveMarginAfterDefault(block), negativeMarginAfterDefault(bl ock))
212 , m_discardMarginBefore(false)
213 , m_discardMarginAfter(false)
214 {
215 }
216 void trace(Visitor*);
217
218 static LayoutUnit positiveMarginBeforeDefault(const RenderBlockFlow* blo ck)
219 {
220 return std::max<LayoutUnit>(block->marginBefore(), 0);
221 }
222 static LayoutUnit negativeMarginBeforeDefault(const RenderBlockFlow* blo ck)
223 {
224 return std::max<LayoutUnit>(-block->marginBefore(), 0);
225 }
226 static LayoutUnit positiveMarginAfterDefault(const RenderBlockFlow* bloc k)
227 {
228 return std::max<LayoutUnit>(block->marginAfter(), 0);
229 }
230 static LayoutUnit negativeMarginAfterDefault(const RenderBlockFlow* bloc k)
231 {
232 return std::max<LayoutUnit>(-block->marginAfter(), 0);
233 }
234
235 MarginValues m_margins;
236 bool m_discardMarginBefore : 1;
237 bool m_discardMarginAfter : 1;
238 };
239 LayoutUnit marginOffsetForSelfCollapsingBlock();
240
241 protected: 177 protected:
242 LayoutUnit maxPositiveMarginBefore() const { return m_rareData ? m_rareData- >m_margins.positiveMarginBefore() : RenderBlockFlowRareData::positiveMarginBefor eDefault(this); }
243 LayoutUnit maxNegativeMarginBefore() const { return m_rareData ? m_rareData- >m_margins.negativeMarginBefore() : RenderBlockFlowRareData::negativeMarginBefor eDefault(this); }
244 LayoutUnit maxPositiveMarginAfter() const { return m_rareData ? m_rareData-> m_margins.positiveMarginAfter() : RenderBlockFlowRareData::positiveMarginAfterDe fault(this); }
245 LayoutUnit maxNegativeMarginAfter() const { return m_rareData ? m_rareData-> m_margins.negativeMarginAfter() : RenderBlockFlowRareData::negativeMarginAfterDe fault(this); }
246
247 void setMaxMarginBeforeValues(LayoutUnit pos, LayoutUnit neg);
248 void setMaxMarginAfterValues(LayoutUnit pos, LayoutUnit neg);
249
250 void setMustDiscardMarginBefore(bool = true);
251 void setMustDiscardMarginAfter(bool = true);
252
253 bool mustDiscardMarginBefore() const;
254 bool mustDiscardMarginAfter() const;
255
256 bool mustDiscardMarginBeforeForChild(const RenderBox*) const;
257 bool mustDiscardMarginAfterForChild(const RenderBox*) const;
258
259 bool mustSeparateMarginBeforeForChild(const RenderBox*) const;
260 bool mustSeparateMarginAfterForChild(const RenderBox*) const;
261
262 void initMaxMarginValues()
263 {
264 if (m_rareData) {
265 m_rareData->m_margins = MarginValues(RenderBlockFlowRareData::positi veMarginBeforeDefault(this) , RenderBlockFlowRareData::negativeMarginBeforeDefau lt(this),
266 RenderBlockFlowRareData::positiveMarginAfterDefault(this), Rende rBlockFlowRareData::negativeMarginAfterDefault(this));
267
268 m_rareData->m_discardMarginBefore = false;
269 m_rareData->m_discardMarginAfter = false;
270 }
271 }
272
273 virtual ETextAlign textAlignmentForLine(bool endsWithSoftBreak) const; 178 virtual ETextAlign textAlignmentForLine(bool endsWithSoftBreak) const;
274 private: 179 private:
275 virtual LayoutUnit collapsedMarginBefore() const override final { return max PositiveMarginBefore() - maxNegativeMarginBefore(); }
276 virtual LayoutUnit collapsedMarginAfter() const override final { return maxP ositiveMarginAfter() - maxNegativeMarginAfter(); }
277
278 LayoutUnit collapseMargins(RenderBox* child, MarginInfo&, bool childIsSelfCo llapsing);
279 LayoutUnit estimateLogicalTopPosition(RenderBox* child, const MarginInfo&);
280 void marginBeforeEstimateForChild(RenderBox*, LayoutUnit&, LayoutUnit&, bool &) const;
281 void handleAfterSideOfBlock(RenderBox* lastChild, LayoutUnit top, LayoutUnit bottom, MarginInfo&);
282 void setCollapsedBottomMargin(const MarginInfo&);
283
284 RenderBlockFlowRareData& ensureRareData();
285
286 LayoutUnit m_paintInvalidationLogicalTop; 180 LayoutUnit m_paintInvalidationLogicalTop;
287 LayoutUnit m_paintInvalidationLogicalBottom; 181 LayoutUnit m_paintInvalidationLogicalBottom;
288 182
289 virtual bool isSelfCollapsingBlock() const override;
290
291 protected: 183 protected:
292 OwnPtr<RenderBlockFlowRareData> m_rareData;
293
294 friend class BreakingContext; // FIXME: It uses insertFloatingObject and pos itionNewFloatOnLine, if we move those out from the private scope/add a helper to LineBreaker, we can remove this friend 184 friend class BreakingContext; // FIXME: It uses insertFloatingObject and pos itionNewFloatOnLine, if we move those out from the private scope/add a helper to LineBreaker, we can remove this friend
295 friend class MarginInfo;
296 friend class LineBreaker; 185 friend class LineBreaker;
297 186
298 // FIXME-BLOCKFLOW: These methods have implementations in 187 // FIXME-BLOCKFLOW: These methods have implementations in
299 // RenderBlockLineLayout. They should be moved to the proper header once the 188 // RenderBlockLineLayout. They should be moved to the proper header once the
300 // line layout code is separated from RenderBlock and RenderBlockFlow. 189 // line layout code is separated from RenderBlock and RenderBlockFlow.
301 // START METHODS DEFINED IN RenderBlockLineLayout 190 // START METHODS DEFINED IN RenderBlockLineLayout
302 private: 191 private:
303 InlineFlowBox* createLineBoxes(RenderObject*, const LineInfo&, InlineBox* ch ildBox); 192 InlineFlowBox* createLineBoxes(RenderObject*, const LineInfo&, InlineBox* ch ildBox);
304 RootInlineBox* constructLine(BidiRunList<BidiRun>&, const LineInfo&); 193 RootInlineBox* constructLine(BidiRunList<BidiRun>&, const LineInfo&);
305 void computeInlineDirectionPositionsForLine(RootInlineBox*, const LineInfo&, BidiRun* firstRun, BidiRun* trailingSpaceRun, bool reachedEnd, GlyphOverflowAnd FallbackFontsMap&, VerticalPositionCache&, WordMeasurements&); 194 void computeInlineDirectionPositionsForLine(RootInlineBox*, const LineInfo&, BidiRun* firstRun, BidiRun* trailingSpaceRun, bool reachedEnd, GlyphOverflowAnd FallbackFontsMap&, VerticalPositionCache&, WordMeasurements&);
(...skipping 20 matching lines...) Expand all
326 215
327 // END METHODS DEFINED IN RenderBlockLineLayout 216 // END METHODS DEFINED IN RenderBlockLineLayout
328 217
329 }; 218 };
330 219
331 DEFINE_RENDER_OBJECT_TYPE_CASTS(RenderBlockFlow, isRenderBlockFlow()); 220 DEFINE_RENDER_OBJECT_TYPE_CASTS(RenderBlockFlow, isRenderBlockFlow());
332 221
333 } // namespace blink 222 } // namespace blink
334 223
335 #endif // RenderBlockFlow_h 224 #endif // RenderBlockFlow_h
OLDNEW
« no previous file with comments | « sky/engine/core/rendering/RenderBlock.cpp ('k') | sky/engine/core/rendering/RenderBlockFlow.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698