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

Side by Side Diff: third_party/WebKit/Source/core/layout/LayoutTableCell.cpp

Issue 1656743002: Removing more implicit LayoutUnit construction (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 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) 1997 Martin Jones (mjones@kde.org) 2 * Copyright (C) 1997 Martin Jones (mjones@kde.org)
3 * (C) 1997 Torben Weis (weis@kde.org) 3 * (C) 1997 Torben Weis (weis@kde.org)
4 * (C) 1998 Waldo Bastian (bastian@kde.org) 4 * (C) 1998 Waldo Bastian (bastian@kde.org)
5 * (C) 1999 Lars Knoll (knoll@kde.org) 5 * (C) 1999 Lars Knoll (knoll@kde.org)
6 * (C) 1999 Antti Koivisto (koivisto@kde.org) 6 * (C) 1999 Antti Koivisto (koivisto@kde.org)
7 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. 7 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. 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 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 if (node() && style()->autoWrap()) { 147 if (node() && style()->autoWrap()) {
148 // See if nowrap was set. 148 // See if nowrap was set.
149 Length w = styleOrColLogicalWidth(); 149 Length w = styleOrColLogicalWidth();
150 const AtomicString& nowrap = toElement(node())->getAttribute(nowrapAttr) ; 150 const AtomicString& nowrap = toElement(node())->getAttribute(nowrapAttr) ;
151 if (!nowrap.isNull() && w.isFixed()) { 151 if (!nowrap.isNull() && w.isFixed()) {
152 // Nowrap is set, but we didn't actually use it because of the 152 // Nowrap is set, but we didn't actually use it because of the
153 // fixed width set on the cell. Even so, it is a WinIE/Moz trait 153 // fixed width set on the cell. Even so, it is a WinIE/Moz trait
154 // to make the minwidth of the cell into the fixed width. They do t his 154 // to make the minwidth of the cell into the fixed width. They do t his
155 // even in strict mode, so do not make this a quirk. Affected the t op 155 // even in strict mode, so do not make this a quirk. Affected the t op
156 // of hiptop.com. 156 // of hiptop.com.
157 m_minPreferredLogicalWidth = std::max<LayoutUnit>(w.value(), m_minPr eferredLogicalWidth); 157 m_minPreferredLogicalWidth = std::max(LayoutUnit(w.value()), m_minPr eferredLogicalWidth);
158 } 158 }
159 } 159 }
160 } 160 }
161 161
162 void LayoutTableCell::addLayerHitTestRects(LayerHitTestRects& layerRects, const PaintLayer* currentLayer, const LayoutPoint& layerOffset, const LayoutRect& cont ainerRect) const 162 void LayoutTableCell::addLayerHitTestRects(LayerHitTestRects& layerRects, const PaintLayer* currentLayer, const LayoutPoint& layerOffset, const LayoutRect& cont ainerRect) const
163 { 163 {
164 LayoutPoint adjustedLayerOffset = layerOffset; 164 LayoutPoint adjustedLayerOffset = layerOffset;
165 // LayoutTableCell's location includes the offset of it's containing LayoutT ableRow, so 165 // LayoutTableCell's location includes the offset of it's containing LayoutT ableRow, so
166 // we need to subtract that again here (as for LayoutTableCell::offsetFromCo ntainer. 166 // we need to subtract that again here (as for LayoutTableCell::offsetFromCo ntainer.
167 if (parent()) 167 if (parent())
168 adjustedLayerOffset -= parentBox()->locationOffset(); 168 adjustedLayerOffset -= parentBox()->locationOffset();
169 LayoutBox::addLayerHitTestRects(layerRects, currentLayer, adjustedLayerOffse t, containerRect); 169 LayoutBox::addLayerHitTestRects(layerRects, currentLayer, adjustedLayerOffse t, containerRect);
170 } 170 }
171 171
172 void LayoutTableCell::computeIntrinsicPadding(int rowHeight, SubtreeLayoutScope& layouter) 172 void LayoutTableCell::computeIntrinsicPadding(int rowHeight, SubtreeLayoutScope& layouter)
173 { 173 {
174 int oldIntrinsicPaddingBefore = intrinsicPaddingBefore(); 174 int oldIntrinsicPaddingBefore = intrinsicPaddingBefore();
175 int oldIntrinsicPaddingAfter = intrinsicPaddingAfter(); 175 int oldIntrinsicPaddingAfter = intrinsicPaddingAfter();
176 int logicalHeightWithoutIntrinsicPadding = pixelSnappedLogicalHeight() - old IntrinsicPaddingBefore - oldIntrinsicPaddingAfter; 176 int logicalHeightWithoutIntrinsicPadding = pixelSnappedLogicalHeight() - old IntrinsicPaddingBefore - oldIntrinsicPaddingAfter;
177 177
178 int intrinsicPaddingBefore = 0; 178 int intrinsicPaddingBefore = 0;
179 switch (style()->verticalAlign()) { 179 switch (style()->verticalAlign()) {
180 case SUB: 180 case SUB:
181 case SUPER: 181 case SUPER:
182 case TEXT_TOP: 182 case TEXT_TOP:
183 case TEXT_BOTTOM: 183 case TEXT_BOTTOM:
184 case LENGTH: 184 case LENGTH:
185 case BASELINE: { 185 case BASELINE: {
186 LayoutUnit baseline = cellBaselinePosition(); 186 int baseline = cellBaselinePosition();
187 if (baseline > borderBefore() + paddingBefore()) 187 if (baseline > borderBefore() + paddingBefore())
188 intrinsicPaddingBefore = section()->rowBaseline(rowIndex()) - (basel ine - oldIntrinsicPaddingBefore); 188 intrinsicPaddingBefore = section()->rowBaseline(rowIndex()) - (basel ine - oldIntrinsicPaddingBefore);
189 break; 189 break;
190 } 190 }
191 case TOP: 191 case TOP:
192 break; 192 break;
193 case MIDDLE: 193 case MIDDLE:
194 intrinsicPaddingBefore = (rowHeight - logicalHeightWithoutIntrinsicPaddi ng) / 2; 194 intrinsicPaddingBefore = (rowHeight - logicalHeightWithoutIntrinsicPaddi ng) / 2;
195 break; 195 break;
196 case BOTTOM: 196 case BOTTOM:
(...skipping 17 matching lines...) Expand all
214 { 214 {
215 } 215 }
216 216
217 void LayoutTableCell::setCellLogicalWidth(int tableLayoutLogicalWidth, SubtreeLa youtScope& layouter) 217 void LayoutTableCell::setCellLogicalWidth(int tableLayoutLogicalWidth, SubtreeLa youtScope& layouter)
218 { 218 {
219 if (tableLayoutLogicalWidth == logicalWidth()) 219 if (tableLayoutLogicalWidth == logicalWidth())
220 return; 220 return;
221 221
222 layouter.setNeedsLayout(this, LayoutInvalidationReason::SizeChanged); 222 layouter.setNeedsLayout(this, LayoutInvalidationReason::SizeChanged);
223 223
224 setLogicalWidth(tableLayoutLogicalWidth); 224 setLogicalWidth(LayoutUnit(tableLayoutLogicalWidth));
225 setCellWidthChanged(true); 225 setCellWidthChanged(true);
226 } 226 }
227 227
228 void LayoutTableCell::layout() 228 void LayoutTableCell::layout()
229 { 229 {
230 ASSERT(needsLayout()); 230 ASSERT(needsLayout());
231 LayoutAnalyzer::Scope analyzer(*this); 231 LayoutAnalyzer::Scope analyzer(*this);
232 232
233 int oldCellBaseline = cellBaselinePosition(); 233 int oldCellBaseline = cellBaselinePosition();
234 layoutBlock(cellWidthChanged()); 234 layoutBlock(cellWidthChanged());
235 235
236 // If we have replaced content, the intrinsic height of our content may have changed since the last time we laid out. If that's the case the intrinsic paddi ng we used 236 // If we have replaced content, the intrinsic height of our content may have changed since the last time we laid out. If that's the case the intrinsic paddi ng we used
237 // for layout (the padding required to push the contents of the cell down to the row's baseline) is included in our new height and baseline and makes both 237 // for layout (the padding required to push the contents of the cell down to the row's baseline) is included in our new height and baseline and makes both
238 // of them wrong. So if our content's intrinsic height has changed push the new content up into the intrinsic padding and relayout so that the rest of 238 // of them wrong. So if our content's intrinsic height has changed push the new content up into the intrinsic padding and relayout so that the rest of
239 // table and row layout can use the correct baseline and height for this cel l. 239 // table and row layout can use the correct baseline and height for this cel l.
240 if (isBaselineAligned() && section()->rowBaseline(rowIndex()) && cellBaselin ePosition() > section()->rowBaseline(rowIndex())) { 240 if (isBaselineAligned() && section()->rowBaseline(rowIndex()) && cellBaselin ePosition() > section()->rowBaseline(rowIndex())) {
241 int newIntrinsicPaddingBefore = (intrinsicPaddingBefore() - (cellBaselin ePosition() - oldCellBaseline).clampNegativeToZero()).clampNegativeToZero(); 241 int newIntrinsicPaddingBefore = std::max(intrinsicPaddingBefore() - std: :max(cellBaselinePosition() - oldCellBaseline, 0), 0);
242 setIntrinsicPaddingBefore(newIntrinsicPaddingBefore); 242 setIntrinsicPaddingBefore(newIntrinsicPaddingBefore);
243 SubtreeLayoutScope layouter(*this); 243 SubtreeLayoutScope layouter(*this);
244 layouter.setNeedsLayout(this, LayoutInvalidationReason::TableChanged); 244 layouter.setNeedsLayout(this, LayoutInvalidationReason::TableChanged);
245 layoutBlock(cellWidthChanged()); 245 layoutBlock(cellWidthChanged());
246 } 246 }
247 247
248 // FIXME: This value isn't the intrinsic content logical height, but we need 248 // FIXME: This value isn't the intrinsic content logical height, but we need
249 // to update the value as its used by flexbox layout. crbug.com/367324 249 // to update the value as its used by flexbox layout. crbug.com/367324
250 setIntrinsicContentLogicalHeight(contentLogicalHeight()); 250 setIntrinsicContentLogicalHeight(contentLogicalHeight());
251 251
252 setCellWidthChanged(false); 252 setCellWidthChanged(false);
253 } 253 }
254 254
255 LayoutUnit LayoutTableCell::paddingTop() const 255 LayoutUnit LayoutTableCell::paddingTop() const
256 { 256 {
257 int result = computedCSSPaddingTop(); 257 LayoutUnit result = computedCSSPaddingTop();
258 if (!isHorizontalWritingMode()) 258 if (isHorizontalWritingMode())
259 return result; 259 result += (style()->writingMode() == TopToBottomWritingMode ? intrinsicP addingBefore() : intrinsicPaddingAfter());
260 return result + (style()->writingMode() == TopToBottomWritingMode ? intrinsi cPaddingBefore() : intrinsicPaddingAfter()); 260 // TODO(leviw): The floor call should be removed when Table is sub-pixel awa re. crbug.com/377847
261 return LayoutUnit(result.floor());
261 } 262 }
262 263
263 LayoutUnit LayoutTableCell::paddingBottom() const 264 LayoutUnit LayoutTableCell::paddingBottom() const
264 { 265 {
265 int result = computedCSSPaddingBottom(); 266 LayoutUnit result = computedCSSPaddingBottom();
266 if (!isHorizontalWritingMode()) 267 if (isHorizontalWritingMode())
267 return result; 268 result += (style()->writingMode() == TopToBottomWritingMode ? intrinsicP addingAfter() : intrinsicPaddingBefore());
268 return result + (style()->writingMode() == TopToBottomWritingMode ? intrinsi cPaddingAfter() : intrinsicPaddingBefore()); 269 // TODO(leviw): The floor call should be removed when Table is sub-pixel awa re. crbug.com/377847
270 return LayoutUnit(result.floor());
269 } 271 }
270 272
271 LayoutUnit LayoutTableCell::paddingLeft() const 273 LayoutUnit LayoutTableCell::paddingLeft() const
272 { 274 {
273 int result = computedCSSPaddingLeft(); 275 LayoutUnit result = computedCSSPaddingLeft();
274 if (isHorizontalWritingMode()) 276 if (!isHorizontalWritingMode())
275 return result; 277 result += (style()->writingMode() == LeftToRightWritingMode ? intrinsicP addingBefore() : intrinsicPaddingAfter());
276 return result + (style()->writingMode() == LeftToRightWritingMode ? intrinsi cPaddingBefore() : intrinsicPaddingAfter()); 278 // TODO(leviw): The floor call should be removed when Table is sub-pixel awa re. crbug.com/377847
279 return LayoutUnit(result.floor());
277 } 280 }
278 281
279 LayoutUnit LayoutTableCell::paddingRight() const 282 LayoutUnit LayoutTableCell::paddingRight() const
280 { 283 {
281 int result = computedCSSPaddingRight(); 284 LayoutUnit result = computedCSSPaddingRight();
282 if (isHorizontalWritingMode()) 285 if (!isHorizontalWritingMode())
283 return result; 286 result += (style()->writingMode() == LeftToRightWritingMode ? intrinsicP addingAfter() : intrinsicPaddingBefore());
284 return result + (style()->writingMode() == LeftToRightWritingMode ? intrinsi cPaddingAfter() : intrinsicPaddingBefore()); 287 // TODO(leviw): The floor call should be removed when Table is sub-pixel awa re. crbug.com/377847
288 return LayoutUnit(result.floor());
285 } 289 }
286 290
287 LayoutUnit LayoutTableCell::paddingBefore() const 291 LayoutUnit LayoutTableCell::paddingBefore() const
288 { 292 {
289 return static_cast<int>(computedCSSPaddingBefore()) + intrinsicPaddingBefore (); 293 return LayoutUnit(computedCSSPaddingBefore().floor() + intrinsicPaddingBefor e());
290 } 294 }
291 295
292 LayoutUnit LayoutTableCell::paddingAfter() const 296 LayoutUnit LayoutTableCell::paddingAfter() const
293 { 297 {
294 return static_cast<int>(computedCSSPaddingAfter()) + intrinsicPaddingAfter() ; 298 return LayoutUnit(computedCSSPaddingAfter().floor() + intrinsicPaddingAfter( ));
295 } 299 }
296 300
297 void LayoutTableCell::setOverrideLogicalContentHeightFromRowHeight(LayoutUnit ro wHeight) 301 void LayoutTableCell::setOverrideLogicalContentHeightFromRowHeight(LayoutUnit ro wHeight)
298 { 302 {
299 clearIntrinsicPadding(); 303 clearIntrinsicPadding();
300 setOverrideLogicalContentHeight((rowHeight - borderAndPaddingLogicalHeight() ).clampNegativeToZero()); 304 setOverrideLogicalContentHeight((rowHeight - borderAndPaddingLogicalHeight() ).clampNegativeToZero());
301 } 305 }
302 306
303 LayoutSize LayoutTableCell::offsetFromContainer(const LayoutObject* o, const Lay outPoint& point, bool* offsetDependsOnPoint) const 307 LayoutSize LayoutTableCell::offsetFromContainer(const LayoutObject* o, const Lay outPoint& point, bool* offsetDependsOnPoint) const
304 { 308 {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 left = std::max(left, above->borderHalfLeft(true)); 347 left = std::max(left, above->borderHalfLeft(true));
344 right = std::max(right, above->borderHalfRight(true)); 348 right = std::max(right, above->borderHalfRight(true));
345 } 349 }
346 } 350 }
347 if (bottom) { 351 if (bottom) {
348 if (LayoutTableCell* below = table()->cellBelow(this)) { 352 if (LayoutTableCell* below = table()->cellBelow(this)) {
349 left = std::max(left, below->borderHalfLeft(true)); 353 left = std::max(left, below->borderHalfLeft(true));
350 right = std::max(right, below->borderHalfRight(true)); 354 right = std::max(right, below->borderHalfRight(true));
351 } 355 }
352 } 356 }
353 LayoutPoint location(std::max<LayoutUnit>(left, -visualOverflowRect().x()), std::max<LayoutUnit>(top, -visualOverflowRect().y())); 357 LayoutPoint location(std::max(LayoutUnit(left), -visualOverflowRect().x()), std::max(LayoutUnit(top), -visualOverflowRect().y()));
354 LayoutRect r(-location.x(), -location.y(), location.x() + std::max(size().wi dth() + right, visualOverflowRect().maxX()), location.y() + std::max(size().heig ht() + bottom, visualOverflowRect().maxY())); 358 LayoutRect r(-location.x(), -location.y(), location.x() + std::max(size().wi dth() + right, visualOverflowRect().maxX()), location.y() + std::max(size().heig ht() + bottom, visualOverflowRect().maxY()));
355 359
356 mapToVisibleRectInAncestorSpace(paintInvalidationContainer, r, paintInvalida tionState); 360 mapToVisibleRectInAncestorSpace(paintInvalidationContainer, r, paintInvalida tionState);
357 return r; 361 return r;
358 } 362 }
359 363
360 void LayoutTableCell::mapToVisibleRectInAncestorSpace(const LayoutBoxModelObject * ancestor, LayoutRect& r, const PaintInvalidationState* paintInvalidationState) const 364 void LayoutTableCell::mapToVisibleRectInAncestorSpace(const LayoutBoxModelObject * ancestor, LayoutRect& r, const PaintInvalidationState* paintInvalidationState) const
361 { 365 {
362 if (ancestor == this) 366 if (ancestor == this)
363 return; 367 return;
364 r.setY(r.y()); 368 r.setY(r.y());
365 if ((!paintInvalidationState || !paintInvalidationState->canMapToContainer(a ncestor)) && parent()) 369 if ((!paintInvalidationState || !paintInvalidationState->canMapToContainer(a ncestor)) && parent())
366 r.moveBy(-parentBox()->location()); // Rows are in the same coordinate s pace, so don't add their offset in. 370 r.moveBy(-parentBox()->location()); // Rows are in the same coordinate s pace, so don't add their offset in.
367 LayoutBlockFlow::mapToVisibleRectInAncestorSpace(ancestor, r, paintInvalidat ionState); 371 LayoutBlockFlow::mapToVisibleRectInAncestorSpace(ancestor, r, paintInvalidat ionState);
368 } 372 }
369 373
370 LayoutUnit LayoutTableCell::cellBaselinePosition() const 374 int LayoutTableCell::cellBaselinePosition() const
371 { 375 {
372 // <http://www.w3.org/TR/2007/CR-CSS21-20070719/tables.html#height-layout>: The baseline of a cell is the baseline of 376 // <http://www.w3.org/TR/2007/CR-CSS21-20070719/tables.html#height-layout>: The baseline of a cell is the baseline of
373 // the first in-flow line box in the cell, or the first in-flow table-row in the cell, whichever comes first. If there 377 // the first in-flow line box in the cell, or the first in-flow table-row in the cell, whichever comes first. If there
374 // is no such line box or table-row, the baseline is the bottom of content e dge of the cell box. 378 // is no such line box or table-row, the baseline is the bottom of content e dge of the cell box.
375 LayoutUnit firstLineBaseline = firstLineBoxBaseline(); 379 int firstLineBaseline = firstLineBoxBaseline();
376 if (firstLineBaseline != -1) 380 if (firstLineBaseline != -1)
377 return firstLineBaseline; 381 return firstLineBaseline;
378 return borderBefore() + paddingBefore() + contentLogicalHeight(); 382 return borderBefore() + paddingBefore() + contentLogicalHeight();
379 } 383 }
380 384
381 void LayoutTableCell::styleDidChange(StyleDifference diff, const ComputedStyle* oldStyle) 385 void LayoutTableCell::styleDidChange(StyleDifference diff, const ComputedStyle* oldStyle)
382 { 386 {
383 ASSERT(style()->display() == TABLE_CELL); 387 ASSERT(style()->display() == TABLE_CELL);
384 388
385 LayoutBlockFlow::styleDidChange(diff, oldStyle); 389 LayoutBlockFlow::styleDidChange(diff, oldStyle);
(...skipping 579 matching lines...) Expand 10 before | Expand all | Expand 10 after
965 TableCellPainter(*this).paintMask(paintInfo, paintOffset); 969 TableCellPainter(*this).paintMask(paintInfo, paintOffset);
966 } 970 }
967 971
968 bool LayoutTableCell::boxShadowShouldBeAppliedToBackground(BackgroundBleedAvoida nce, const InlineFlowBox*) const 972 bool LayoutTableCell::boxShadowShouldBeAppliedToBackground(BackgroundBleedAvoida nce, const InlineFlowBox*) const
969 { 973 {
970 return false; 974 return false;
971 } 975 }
972 976
973 void LayoutTableCell::scrollbarsChanged(bool horizontalScrollbarChanged, bool ve rticalScrollbarChanged) 977 void LayoutTableCell::scrollbarsChanged(bool horizontalScrollbarChanged, bool ve rticalScrollbarChanged)
974 { 978 {
975 LayoutUnit scrollbarHeight = scrollbarLogicalHeight(); 979 int scrollbarHeight = scrollbarLogicalHeight();
976 if (!scrollbarHeight) 980 if (!scrollbarHeight)
977 return; // Not sure if we should be doing something when a scrollbar goe s away or not. 981 return; // Not sure if we should be doing something when a scrollbar goe s away or not.
978 982
979 // We only care if the scrollbar that affects our intrinsic padding has been added. 983 // We only care if the scrollbar that affects our intrinsic padding has been added.
980 if ((isHorizontalWritingMode() && !horizontalScrollbarChanged) 984 if ((isHorizontalWritingMode() && !horizontalScrollbarChanged)
981 || (!isHorizontalWritingMode() && !verticalScrollbarChanged)) 985 || (!isHorizontalWritingMode() && !verticalScrollbarChanged))
982 return; 986 return;
983 987
984 // Shrink our intrinsic padding as much as possible to accommodate the scrol lbar. 988 // Shrink our intrinsic padding as much as possible to accommodate the scrol lbar.
985 if (style()->verticalAlign() == MIDDLE) { 989 if (style()->verticalAlign() == MIDDLE) {
(...skipping 27 matching lines...) Expand all
1013 bool LayoutTableCell::backgroundIsKnownToBeOpaqueInRect(const LayoutRect& localR ect) const 1017 bool LayoutTableCell::backgroundIsKnownToBeOpaqueInRect(const LayoutRect& localR ect) const
1014 { 1018 {
1015 // If this object has layer, the area of collapsed borders should be transpa rent 1019 // If this object has layer, the area of collapsed borders should be transpa rent
1016 // to expose the collapsed borders painted on the underlying layer. 1020 // to expose the collapsed borders painted on the underlying layer.
1017 if (hasLayer() && table()->collapseBorders()) 1021 if (hasLayer() && table()->collapseBorders())
1018 return false; 1022 return false;
1019 return LayoutBlockFlow::backgroundIsKnownToBeOpaqueInRect(localRect); 1023 return LayoutBlockFlow::backgroundIsKnownToBeOpaqueInRect(localRect);
1020 } 1024 }
1021 1025
1022 } // namespace blink 1026 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698