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

Side by Side Diff: Source/core/rendering/RenderBoxModelObject.cpp

Issue 82083002: Move viewport unit resolution to style recalc time (Closed) Base URL: https://chromium.googlesource.com/chromium/blink@master
Patch Set: actually fix zoom handling Created 7 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 Apple Inc. All rights reserved. 6 * Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
7 * Copyright (C) 2010 Google Inc. All rights reserved. 7 * Copyright (C) 2010 Google 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 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 LayoutSize offset = accumulateInFlowPositionOffsets(this); 233 LayoutSize offset = accumulateInFlowPositionOffsets(this);
234 234
235 RenderBlock* containingBlock = this->containingBlock(); 235 RenderBlock* containingBlock = this->containingBlock();
236 236
237 // Objects that shrink to avoid floats normally use available line width whe n computing containing block width. However 237 // Objects that shrink to avoid floats normally use available line width whe n computing containing block width. However
238 // in the case of relative positioning using percentages, we can't do this. The offset should always be resolved using the 238 // in the case of relative positioning using percentages, we can't do this. The offset should always be resolved using the
239 // available width of the containing block. Therefore we don't use containi ngBlockLogicalWidthForContent() here, but instead explicitly 239 // available width of the containing block. Therefore we don't use containi ngBlockLogicalWidthForContent() here, but instead explicitly
240 // call availableWidth on our containing block. 240 // call availableWidth on our containing block.
241 if (!style()->left().isAuto()) { 241 if (!style()->left().isAuto()) {
242 if (!style()->right().isAuto() && !containingBlock->style()->isLeftToRig htDirection()) 242 if (!style()->right().isAuto() && !containingBlock->style()->isLeftToRig htDirection())
243 offset.setWidth(-valueForLength(style()->right(), containingBlock->a vailableWidth(), view())); 243 offset.setWidth(-valueForLength(style()->right(), containingBlock->a vailableWidth()));
244 else 244 else
245 offset.expand(valueForLength(style()->left(), containingBlock->avail ableWidth(), view()), 0); 245 offset.expand(valueForLength(style()->left(), containingBlock->avail ableWidth()), 0);
246 } else if (!style()->right().isAuto()) { 246 } else if (!style()->right().isAuto()) {
247 offset.expand(-valueForLength(style()->right(), containingBlock->availab leWidth(), view()), 0); 247 offset.expand(-valueForLength(style()->right(), containingBlock->availab leWidth()), 0);
248 } 248 }
249 249
250 // If the containing block of a relatively positioned element does not 250 // If the containing block of a relatively positioned element does not
251 // specify a height, a percentage top or bottom offset should be resolved as 251 // specify a height, a percentage top or bottom offset should be resolved as
252 // auto. An exception to this is if the containing block has the WinIE quirk 252 // auto. An exception to this is if the containing block has the WinIE quirk
253 // where <html> and <body> assume the size of the viewport. In this case, 253 // where <html> and <body> assume the size of the viewport. In this case,
254 // calculate the percent offset based on this height. 254 // calculate the percent offset based on this height.
255 // See <https://bugs.webkit.org/show_bug.cgi?id=26396>. 255 // See <https://bugs.webkit.org/show_bug.cgi?id=26396>.
256 if (!style()->top().isAuto() 256 if (!style()->top().isAuto()
257 && (!containingBlock->hasAutoHeightOrContainingBlockWithAutoHeight() 257 && (!containingBlock->hasAutoHeightOrContainingBlockWithAutoHeight()
258 || !style()->top().isPercent() 258 || !style()->top().isPercent()
259 || containingBlock->stretchesToViewport())) 259 || containingBlock->stretchesToViewport()))
260 offset.expand(0, valueForLength(style()->top(), containingBlock->availab leHeight(), view())); 260 offset.expand(0, valueForLength(style()->top(), containingBlock->availab leHeight()));
261 261
262 else if (!style()->bottom().isAuto() 262 else if (!style()->bottom().isAuto()
263 && (!containingBlock->hasAutoHeightOrContainingBlockWithAutoHeight() 263 && (!containingBlock->hasAutoHeightOrContainingBlockWithAutoHeight()
264 || !style()->bottom().isPercent() 264 || !style()->bottom().isPercent()
265 || containingBlock->stretchesToViewport())) 265 || containingBlock->stretchesToViewport()))
266 offset.expand(0, -valueForLength(style()->bottom(), containingBlock->ava ilableHeight(), view())); 266 offset.expand(0, -valueForLength(style()->bottom(), containingBlock->ava ilableHeight()));
267 267
268 return offset; 268 return offset;
269 } 269 }
270 270
271 LayoutPoint RenderBoxModelObject::adjustedPositionRelativeToOffsetParent(const L ayoutPoint& startPoint) const 271 LayoutPoint RenderBoxModelObject::adjustedPositionRelativeToOffsetParent(const L ayoutPoint& startPoint) const
272 { 272 {
273 // If the element is the HTML body element or doesn't have a parent 273 // If the element is the HTML body element or doesn't have a parent
274 // return 0 and stop this algorithm. 274 // return 0 and stop this algorithm.
275 if (isBody() || !parent()) 275 if (isBody() || !parent())
276 return LayoutPoint(); 276 return LayoutPoint();
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 321
322 void RenderBoxModelObject::computeStickyPositionConstraints(StickyPositionViewpo rtConstraints& constraints, const FloatRect& viewportRect) const 322 void RenderBoxModelObject::computeStickyPositionConstraints(StickyPositionViewpo rtConstraints& constraints, const FloatRect& viewportRect) const
323 { 323 {
324 RenderBlock* containingBlock = this->containingBlock(); 324 RenderBlock* containingBlock = this->containingBlock();
325 325
326 LayoutRect containerContentRect = containingBlock->contentBoxRect(); 326 LayoutRect containerContentRect = containingBlock->contentBoxRect();
327 LayoutUnit maxWidth = containingBlock->availableLogicalWidth(); 327 LayoutUnit maxWidth = containingBlock->availableLogicalWidth();
328 328
329 // Sticky positioned element ignore any override logical width on the contai ning block (as they don't call 329 // Sticky positioned element ignore any override logical width on the contai ning block (as they don't call
330 // containingBlockLogicalWidthForContent). It's unclear whether this is tota lly fine. 330 // containingBlockLogicalWidthForContent). It's unclear whether this is tota lly fine.
331 LayoutBoxExtent minMargin(minimumValueForLength(style()->marginTop(), maxWid th, view()), 331 LayoutBoxExtent minMargin(minimumValueForLength(style()->marginTop(), maxWid th),
332 minimumValueForLength(style()->marginRight(), maxWidth, view()), 332 minimumValueForLength(style()->marginRight(), maxWidth),
333 minimumValueForLength(style()->marginBottom(), maxWidth, view()), 333 minimumValueForLength(style()->marginBottom(), maxWidth),
334 minimumValueForLength(style()->marginLeft(), maxWidth, view())); 334 minimumValueForLength(style()->marginLeft(), maxWidth));
335 335
336 // Compute the container-relative area within which the sticky element is al lowed to move. 336 // Compute the container-relative area within which the sticky element is al lowed to move.
337 containerContentRect.contract(minMargin); 337 containerContentRect.contract(minMargin);
338 // Map to the view to avoid including page scale factor. 338 // Map to the view to avoid including page scale factor.
339 constraints.setAbsoluteContainingBlockRect(containingBlock->localToContainer Quad(FloatRect(containerContentRect), view()).boundingBox()); 339 constraints.setAbsoluteContainingBlockRect(containingBlock->localToContainer Quad(FloatRect(containerContentRect), view()).boundingBox());
340 340
341 LayoutRect stickyBoxRect = frameRectForStickyPositioning(); 341 LayoutRect stickyBoxRect = frameRectForStickyPositioning();
342 LayoutRect flippedStickyBoxRect = stickyBoxRect; 342 LayoutRect flippedStickyBoxRect = stickyBoxRect;
343 containingBlock->flipForWritingMode(flippedStickyBoxRect); 343 containingBlock->flipForWritingMode(flippedStickyBoxRect);
344 LayoutPoint stickyLocation = flippedStickyBoxRect.location(); 344 LayoutPoint stickyLocation = flippedStickyBoxRect.location();
345 345
346 // FIXME: sucks to call localToAbsolute again, but we can't just offset from the previously computed rect if there are transforms. 346 // FIXME: sucks to call localToAbsolute again, but we can't just offset from the previously computed rect if there are transforms.
347 // Map to the view to avoid including page scale factor. 347 // Map to the view to avoid including page scale factor.
348 FloatRect absContainerFrame = containingBlock->localToContainerQuad(FloatRec t(FloatPoint(), containingBlock->size()), view()).boundingBox(); 348 FloatRect absContainerFrame = containingBlock->localToContainerQuad(FloatRec t(FloatPoint(), containingBlock->size()), view()).boundingBox();
349 349
350 // We can't call localToAbsolute on |this| because that will recur. FIXME: F or now, assume that |this| is not transformed. 350 // We can't call localToAbsolute on |this| because that will recur. FIXME: F or now, assume that |this| is not transformed.
351 FloatRect absoluteStickyBoxRect(absContainerFrame.location() + stickyLocatio n, flippedStickyBoxRect.size()); 351 FloatRect absoluteStickyBoxRect(absContainerFrame.location() + stickyLocatio n, flippedStickyBoxRect.size());
352 constraints.setAbsoluteStickyBoxRect(absoluteStickyBoxRect); 352 constraints.setAbsoluteStickyBoxRect(absoluteStickyBoxRect);
353 353
354 if (!style()->left().isAuto()) { 354 if (!style()->left().isAuto()) {
355 constraints.setLeftOffset(valueForLength(style()->left(), viewportRect.w idth(), view())); 355 constraints.setLeftOffset(valueForLength(style()->left(), viewportRect.w idth()));
356 constraints.addAnchorEdge(ViewportConstraints::AnchorEdgeLeft); 356 constraints.addAnchorEdge(ViewportConstraints::AnchorEdgeLeft);
357 } 357 }
358 358
359 if (!style()->right().isAuto()) { 359 if (!style()->right().isAuto()) {
360 constraints.setRightOffset(valueForLength(style()->right(), viewportRect .width(), view())); 360 constraints.setRightOffset(valueForLength(style()->right(), viewportRect .width()));
361 constraints.addAnchorEdge(ViewportConstraints::AnchorEdgeRight); 361 constraints.addAnchorEdge(ViewportConstraints::AnchorEdgeRight);
362 } 362 }
363 363
364 if (!style()->top().isAuto()) { 364 if (!style()->top().isAuto()) {
365 constraints.setTopOffset(valueForLength(style()->top(), viewportRect.hei ght(), view())); 365 constraints.setTopOffset(valueForLength(style()->top(), viewportRect.hei ght()));
366 constraints.addAnchorEdge(ViewportConstraints::AnchorEdgeTop); 366 constraints.addAnchorEdge(ViewportConstraints::AnchorEdgeTop);
367 } 367 }
368 368
369 if (!style()->bottom().isAuto()) { 369 if (!style()->bottom().isAuto()) {
370 constraints.setBottomOffset(valueForLength(style()->bottom(), viewportRe ct.height(), view())); 370 constraints.setBottomOffset(valueForLength(style()->bottom(), viewportRe ct.height()));
371 constraints.addAnchorEdge(ViewportConstraints::AnchorEdgeBottom); 371 constraints.addAnchorEdge(ViewportConstraints::AnchorEdgeBottom);
372 } 372 }
373 } 373 }
374 374
375 LayoutSize RenderBoxModelObject::stickyPositionOffset() const 375 LayoutSize RenderBoxModelObject::stickyPositionOffset() const
376 { 376 {
377 LayoutRect viewportRect = view()->frameView()->viewportConstrainedVisibleCon tentRect(); 377 LayoutRect viewportRect = view()->frameView()->viewportConstrainedVisibleCon tentRect();
378 378
379 StickyPositionViewportConstraints constraints; 379 StickyPositionViewportConstraints constraints;
380 computeStickyPositionConstraints(constraints, viewportRect); 380 computeStickyPositionConstraints(constraints, viewportRect);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 } 414 }
415 415
416 int RenderBoxModelObject::pixelSnappedOffsetHeight() const 416 int RenderBoxModelObject::pixelSnappedOffsetHeight() const
417 { 417 {
418 return snapSizeToPixel(offsetHeight(), offsetTop()); 418 return snapSizeToPixel(offsetHeight(), offsetTop());
419 } 419 }
420 420
421 LayoutUnit RenderBoxModelObject::computedCSSPadding(Length padding) const 421 LayoutUnit RenderBoxModelObject::computedCSSPadding(Length padding) const
422 { 422 {
423 LayoutUnit w = 0; 423 LayoutUnit w = 0;
424 RenderView* renderView = 0;
425 if (padding.isPercent()) 424 if (padding.isPercent())
426 w = containingBlockLogicalWidthForContent(); 425 w = containingBlockLogicalWidthForContent();
427 else if (padding.isViewportPercentage()) 426 return minimumValueForLength(padding, w);
428 renderView = view();
429 return minimumValueForLength(padding, w, renderView);
430 } 427 }
431 428
432 RoundedRect RenderBoxModelObject::getBackgroundRoundedRect(const LayoutRect& bor derRect, InlineFlowBox* box, LayoutUnit inlineBoxWidth, LayoutUnit inlineBoxHeig ht, 429 RoundedRect RenderBoxModelObject::getBackgroundRoundedRect(const LayoutRect& bor derRect, InlineFlowBox* box, LayoutUnit inlineBoxWidth, LayoutUnit inlineBoxHeig ht,
433 bool includeLogicalLeftEdge, bool includeLogicalRightEdge) const 430 bool includeLogicalLeftEdge, bool includeLogicalRightEdge) const
434 { 431 {
435 RenderView* renderView = view(); 432 RoundedRect border = style()->getRoundedBorderFor(borderRect, includeLogical LeftEdge, includeLogicalRightEdge);
436 RoundedRect border = style()->getRoundedBorderFor(borderRect, renderView, in cludeLogicalLeftEdge, includeLogicalRightEdge);
437 if (box && (box->nextLineBox() || box->prevLineBox())) { 433 if (box && (box->nextLineBox() || box->prevLineBox())) {
438 RoundedRect segmentBorder = style()->getRoundedBorderFor(LayoutRect(0, 0 , inlineBoxWidth, inlineBoxHeight), renderView, includeLogicalLeftEdge, includeL ogicalRightEdge); 434 RoundedRect segmentBorder = style()->getRoundedBorderFor(LayoutRect(0, 0 , inlineBoxWidth, inlineBoxHeight), includeLogicalLeftEdge, includeLogicalRightE dge);
439 border.setRadii(segmentBorder.radii()); 435 border.setRadii(segmentBorder.radii());
440 } 436 }
441 437
442 return border; 438 return border;
443 } 439 }
444 440
445 void RenderBoxModelObject::clipRoundedInnerRect(GraphicsContext * context, const LayoutRect& rect, const RoundedRect& clipRect) 441 void RenderBoxModelObject::clipRoundedInnerRect(GraphicsContext * context, const LayoutRect& rect, const RoundedRect& clipRect)
446 { 442 {
447 if (clipRect.isRenderable()) 443 if (clipRect.isRenderable())
448 context->clipRoundedRect(clipRect); 444 context->clipRoundedRect(clipRect);
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after
873 tileSize.setHeight(positioningAreaSize.height() - tileSize.height() <= 1 ? t ileSize.height().ceil() : tileSize.height().floor()); 869 tileSize.setHeight(positioningAreaSize.height() - tileSize.height() <= 1 ? t ileSize.height().ceil() : tileSize.height().floor());
874 } 870 }
875 871
876 IntSize RenderBoxModelObject::calculateFillTileSize(const FillLayer* fillLayer, const IntSize& positioningAreaSize) const 872 IntSize RenderBoxModelObject::calculateFillTileSize(const FillLayer* fillLayer, const IntSize& positioningAreaSize) const
877 { 873 {
878 StyleImage* image = fillLayer->image(); 874 StyleImage* image = fillLayer->image();
879 EFillSizeType type = fillLayer->size().type; 875 EFillSizeType type = fillLayer->size().type;
880 876
881 IntSize imageIntrinsicSize = calculateImageIntrinsicDimensions(image, positi oningAreaSize, ScaleByEffectiveZoom); 877 IntSize imageIntrinsicSize = calculateImageIntrinsicDimensions(image, positi oningAreaSize, ScaleByEffectiveZoom);
882 imageIntrinsicSize.scale(1 / image->imageScaleFactor(), 1 / image->imageScal eFactor()); 878 imageIntrinsicSize.scale(1 / image->imageScaleFactor(), 1 / image->imageScal eFactor());
883 RenderView* renderView = view();
884 switch (type) { 879 switch (type) {
885 case SizeLength: { 880 case SizeLength: {
886 LayoutSize tileSize = positioningAreaSize; 881 LayoutSize tileSize = positioningAreaSize;
887 882
888 Length layerWidth = fillLayer->size().size.width(); 883 Length layerWidth = fillLayer->size().size.width();
889 Length layerHeight = fillLayer->size().size.height(); 884 Length layerHeight = fillLayer->size().size.height();
890 885
891 if (layerWidth.isFixed()) 886 if (layerWidth.isFixed())
892 tileSize.setWidth(layerWidth.value()); 887 tileSize.setWidth(layerWidth.value());
893 else if (layerWidth.isPercent() || layerWidth.isViewportPercentage() ) 888 else if (layerWidth.isPercent())
894 tileSize.setWidth(valueForLength(layerWidth, positioningAreaSize .width(), renderView)); 889 tileSize.setWidth(valueForLength(layerWidth, positioningAreaSize .width()));
895 890
896 if (layerHeight.isFixed()) 891 if (layerHeight.isFixed())
897 tileSize.setHeight(layerHeight.value()); 892 tileSize.setHeight(layerHeight.value());
898 else if (layerHeight.isPercent() || layerHeight.isViewportPercentage ()) 893 else if (layerHeight.isPercent())
899 tileSize.setHeight(valueForLength(layerHeight, positioningAreaSi ze.height(), renderView)); 894 tileSize.setHeight(valueForLength(layerHeight, positioningAreaSi ze.height()));
900 895
901 applySubPixelHeuristicForTileSize(tileSize, positioningAreaSize); 896 applySubPixelHeuristicForTileSize(tileSize, positioningAreaSize);
902 897
903 // If one of the values is auto we have to use the appropriate 898 // If one of the values is auto we have to use the appropriate
904 // scale to maintain our aspect ratio. 899 // scale to maintain our aspect ratio.
905 if (layerWidth.isAuto() && !layerHeight.isAuto()) { 900 if (layerWidth.isAuto() && !layerHeight.isAuto()) {
906 if (imageIntrinsicSize.height()) 901 if (imageIntrinsicSize.height())
907 tileSize.setWidth(imageIntrinsicSize.width() * tileSize.heig ht() / imageIntrinsicSize.height()); 902 tileSize.setWidth(imageIntrinsicSize.width() * tileSize.heig ht() / imageIntrinsicSize.height());
908 } else if (!layerWidth.isAuto() && layerHeight.isAuto()) { 903 } else if (!layerWidth.isAuto() && layerHeight.isAuto()) {
909 if (imageIntrinsicSize.width()) 904 if (imageIntrinsicSize.width())
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
1046 positioningAreaSize = geometry.destRect().size(); 1041 positioningAreaSize = geometry.destRect().size();
1047 } 1042 }
1048 1043
1049 RenderObject* clientForBackgroundImage = backgroundObject ? backgroundObject : this; 1044 RenderObject* clientForBackgroundImage = backgroundObject ? backgroundObject : this;
1050 IntSize fillTileSize = calculateFillTileSize(fillLayer, positioningAreaSize) ; 1045 IntSize fillTileSize = calculateFillTileSize(fillLayer, positioningAreaSize) ;
1051 fillLayer->image()->setContainerSizeForRenderer(clientForBackgroundImage, fi llTileSize, style()->effectiveZoom()); 1046 fillLayer->image()->setContainerSizeForRenderer(clientForBackgroundImage, fi llTileSize, style()->effectiveZoom());
1052 geometry.setTileSize(fillTileSize); 1047 geometry.setTileSize(fillTileSize);
1053 1048
1054 EFillRepeat backgroundRepeatX = fillLayer->repeatX(); 1049 EFillRepeat backgroundRepeatX = fillLayer->repeatX();
1055 EFillRepeat backgroundRepeatY = fillLayer->repeatY(); 1050 EFillRepeat backgroundRepeatY = fillLayer->repeatY();
1056 RenderView* renderView = view();
1057 int availableWidth = positioningAreaSize.width() - geometry.tileSize().width (); 1051 int availableWidth = positioningAreaSize.width() - geometry.tileSize().width ();
1058 int availableHeight = positioningAreaSize.height() - geometry.tileSize().hei ght(); 1052 int availableHeight = positioningAreaSize.height() - geometry.tileSize().hei ght();
1059 1053
1060 LayoutUnit computedXPosition = minimumValueForLength(fillLayer->xPosition(), availableWidth, renderView, true); 1054 LayoutUnit computedXPosition = minimumValueForLength(fillLayer->xPosition(), availableWidth, true);
1061 if (backgroundRepeatX == RoundFill && positioningAreaSize.width() > 0 && fil lTileSize.width() > 0) { 1055 if (backgroundRepeatX == RoundFill && positioningAreaSize.width() > 0 && fil lTileSize.width() > 0) {
1062 long nrTiles = max(1l, lroundf((float)positioningAreaSize.width() / fill TileSize.width())); 1056 long nrTiles = max(1l, lroundf((float)positioningAreaSize.width() / fill TileSize.width()));
1063 1057
1064 if (fillLayer->size().size.height().isAuto() && backgroundRepeatY != Rou ndFill) { 1058 if (fillLayer->size().size.height().isAuto() && backgroundRepeatY != Rou ndFill) {
1065 fillTileSize.setHeight(fillTileSize.height() * positioningAreaSize.w idth() / (nrTiles * fillTileSize.width())); 1059 fillTileSize.setHeight(fillTileSize.height() * positioningAreaSize.w idth() / (nrTiles * fillTileSize.width()));
1066 } 1060 }
1067 1061
1068 fillTileSize.setWidth(positioningAreaSize.width() / nrTiles); 1062 fillTileSize.setWidth(positioningAreaSize.width() / nrTiles);
1069 geometry.setTileSize(fillTileSize); 1063 geometry.setTileSize(fillTileSize);
1070 geometry.setPhaseX(geometry.tileSize().width() ? geometry.tileSize().wid th() - roundToInt(computedXPosition + left) % geometry.tileSize().width() : 0); 1064 geometry.setPhaseX(geometry.tileSize().width() ? geometry.tileSize().wid th() - roundToInt(computedXPosition + left) % geometry.tileSize().width() : 0);
1071 geometry.setSpaceSize(IntSize()); 1065 geometry.setSpaceSize(IntSize());
1072 } 1066 }
1073 1067
1074 LayoutUnit computedYPosition = minimumValueForLength(fillLayer->yPosition(), availableHeight, renderView, true); 1068 LayoutUnit computedYPosition = minimumValueForLength(fillLayer->yPosition(), availableHeight, true);
1075 if (backgroundRepeatY == RoundFill && positioningAreaSize.height() > 0 && fi llTileSize.height() > 0) { 1069 if (backgroundRepeatY == RoundFill && positioningAreaSize.height() > 0 && fi llTileSize.height() > 0) {
1076 long nrTiles = max(1l, lroundf((float)positioningAreaSize.height() / fil lTileSize.height())); 1070 long nrTiles = max(1l, lroundf((float)positioningAreaSize.height() / fil lTileSize.height()));
1077 1071
1078 if (fillLayer->size().size.width().isAuto() && backgroundRepeatX != Roun dFill) { 1072 if (fillLayer->size().size.width().isAuto() && backgroundRepeatX != Roun dFill) {
1079 fillTileSize.setWidth(fillTileSize.width() * positioningAreaSize.hei ght() / (nrTiles * fillTileSize.height())); 1073 fillTileSize.setWidth(fillTileSize.width() * positioningAreaSize.hei ght() / (nrTiles * fillTileSize.height()));
1080 } 1074 }
1081 1075
1082 fillTileSize.setHeight(positioningAreaSize.height() / nrTiles); 1076 fillTileSize.setHeight(positioningAreaSize.height() / nrTiles);
1083 geometry.setTileSize(fillTileSize); 1077 geometry.setTileSize(fillTileSize);
1084 geometry.setPhaseY(geometry.tileSize().height() ? geometry.tileSize().he ight() - roundToInt(computedYPosition + top) % geometry.tileSize().height() : 0) ; 1078 geometry.setPhaseY(geometry.tileSize().height() ? geometry.tileSize().he ight() - roundToInt(computedYPosition + top) % geometry.tileSize().height() : 0) ;
1085 geometry.setSpaceSize(IntSize()); 1079 geometry.setSpaceSize(IntSize());
1086 } 1080 }
1087 1081
1088 if (backgroundRepeatX == RepeatFill) { 1082 if (backgroundRepeatX == RepeatFill) {
1089 geometry.setPhaseX(geometry.tileSize().width() ? geometry.tileSize().wid th() - roundToInt(computedXPosition + left) % geometry.tileSize().width() : 0); 1083 geometry.setPhaseX(geometry.tileSize().width() ? geometry.tileSize().wid th() - roundToInt(computedXPosition + left) % geometry.tileSize().width() : 0);
1090 geometry.setSpaceSize(IntSize()); 1084 geometry.setSpaceSize(IntSize());
1091 } else if (backgroundRepeatX == SpaceFill && fillTileSize.width() > 0) { 1085 } else if (backgroundRepeatX == SpaceFill && fillTileSize.width() > 0) {
1092 int space = getSpace(positioningAreaSize.width(), geometry.tileSize().wi dth()); 1086 int space = getSpace(positioningAreaSize.width(), geometry.tileSize().wi dth());
1093 int actualWidth = geometry.tileSize().width() + space; 1087 int actualWidth = geometry.tileSize().width() + space;
1094 1088
1095 if (space >= 0) { 1089 if (space >= 0) {
1096 computedXPosition = minimumValueForLength(Length(), availableWidth, renderView, true); 1090 computedXPosition = minimumValueForLength(Length(), availableWidth, true);
1097 geometry.setSpaceSize(IntSize(space, 0)); 1091 geometry.setSpaceSize(IntSize(space, 0));
1098 geometry.setPhaseX(actualWidth ? actualWidth - roundToInt(computedXP osition + left) % actualWidth : 0); 1092 geometry.setPhaseX(actualWidth ? actualWidth - roundToInt(computedXP osition + left) % actualWidth : 0);
1099 } else { 1093 } else {
1100 backgroundRepeatX = NoRepeatFill; 1094 backgroundRepeatX = NoRepeatFill;
1101 } 1095 }
1102 } 1096 }
1103 if (backgroundRepeatX == NoRepeatFill) { 1097 if (backgroundRepeatX == NoRepeatFill) {
1104 int xOffset = fillLayer->backgroundXOrigin() == RightEdge ? availableWid th - computedXPosition : computedXPosition; 1098 int xOffset = fillLayer->backgroundXOrigin() == RightEdge ? availableWid th - computedXPosition : computedXPosition;
1105 geometry.setNoRepeatX(left + xOffset); 1099 geometry.setNoRepeatX(left + xOffset);
1106 geometry.setSpaceSize(IntSize(0, geometry.spaceSize().height())); 1100 geometry.setSpaceSize(IntSize(0, geometry.spaceSize().height()));
1107 } 1101 }
1108 1102
1109 if (backgroundRepeatY == RepeatFill) { 1103 if (backgroundRepeatY == RepeatFill) {
1110 geometry.setPhaseY(geometry.tileSize().height() ? geometry.tileSize().he ight() - roundToInt(computedYPosition + top) % geometry.tileSize().height() : 0) ; 1104 geometry.setPhaseY(geometry.tileSize().height() ? geometry.tileSize().he ight() - roundToInt(computedYPosition + top) % geometry.tileSize().height() : 0) ;
1111 geometry.setSpaceSize(IntSize(geometry.spaceSize().width(), 0)); 1105 geometry.setSpaceSize(IntSize(geometry.spaceSize().width(), 0));
1112 } else if (backgroundRepeatY == SpaceFill && fillTileSize.height() > 0) { 1106 } else if (backgroundRepeatY == SpaceFill && fillTileSize.height() > 0) {
1113 int space = getSpace(positioningAreaSize.height(), geometry.tileSize().h eight()); 1107 int space = getSpace(positioningAreaSize.height(), geometry.tileSize().h eight());
1114 int actualHeight = geometry.tileSize().height() + space; 1108 int actualHeight = geometry.tileSize().height() + space;
1115 1109
1116 if (space >= 0) { 1110 if (space >= 0) {
1117 computedYPosition = minimumValueForLength(Length(), availableHeight, renderView, true); 1111 computedYPosition = minimumValueForLength(Length(), availableHeight, true);
1118 geometry.setSpaceSize(IntSize(geometry.spaceSize().width(), space)); 1112 geometry.setSpaceSize(IntSize(geometry.spaceSize().width(), space));
1119 geometry.setPhaseY(actualHeight ? actualHeight - roundToInt(computed YPosition + top) % actualHeight : 0); 1113 geometry.setPhaseY(actualHeight ? actualHeight - roundToInt(computed YPosition + top) % actualHeight : 0);
1120 } else { 1114 } else {
1121 backgroundRepeatY = NoRepeatFill; 1115 backgroundRepeatY = NoRepeatFill;
1122 } 1116 }
1123 } 1117 }
1124 if (backgroundRepeatY == NoRepeatFill) { 1118 if (backgroundRepeatY == NoRepeatFill) {
1125 int yOffset = fillLayer->backgroundYOrigin() == BottomEdge ? availableHe ight - computedYPosition : computedYPosition; 1119 int yOffset = fillLayer->backgroundYOrigin() == BottomEdge ? availableHe ight - computedYPosition : computedYPosition;
1126 geometry.setNoRepeatY(top + yOffset); 1120 geometry.setNoRepeatY(top + yOffset);
1127 geometry.setSpaceSize(IntSize(geometry.spaceSize().width(), 0)); 1121 geometry.setSpaceSize(IntSize(geometry.spaceSize().width(), 0));
1128 } 1122 }
1129 1123
1130 if (fixedAttachment) 1124 if (fixedAttachment)
1131 geometry.useFixedAttachment(snappedPaintRect.location()); 1125 geometry.useFixedAttachment(snappedPaintRect.location());
1132 1126
1133 geometry.clip(snappedPaintRect); 1127 geometry.clip(snappedPaintRect);
1134 geometry.setDestOrigin(geometry.destRect().location()); 1128 geometry.setDestOrigin(geometry.destRect().location());
1135 } 1129 }
1136 1130
1137 static LayoutUnit computeBorderImageSide(const BorderImageLength& borderSlice, L ayoutUnit borderSide, LayoutUnit imageSide, LayoutUnit boxExtent, RenderView* re nderView) 1131 static LayoutUnit computeBorderImageSide(const BorderImageLength& borderSlice, L ayoutUnit borderSide, LayoutUnit imageSide, LayoutUnit boxExtent)
1138 { 1132 {
1139 if (borderSlice.isNumber()) 1133 if (borderSlice.isNumber())
1140 return borderSlice.number() * borderSide; 1134 return borderSlice.number() * borderSide;
1141 if (borderSlice.length().isAuto()) 1135 if (borderSlice.length().isAuto())
1142 return imageSide; 1136 return imageSide;
1143 return valueForLength(borderSlice.length(), boxExtent, renderView); 1137 return valueForLength(borderSlice.length(), boxExtent);
1144 } 1138 }
1145 1139
1146 bool RenderBoxModelObject::paintNinePieceImage(GraphicsContext* graphicsContext, const LayoutRect& rect, const RenderStyle* style, 1140 bool RenderBoxModelObject::paintNinePieceImage(GraphicsContext* graphicsContext, const LayoutRect& rect, const RenderStyle* style,
1147 const NinePieceImage& ninePieceIm age, CompositeOperator op) 1141 const NinePieceImage& ninePieceIm age, CompositeOperator op)
1148 { 1142 {
1149 StyleImage* styleImage = ninePieceImage.image(); 1143 StyleImage* styleImage = ninePieceImage.image();
1150 if (!styleImage) 1144 if (!styleImage)
1151 return false; 1145 return false;
1152 1146
1153 if (!styleImage->isLoaded()) 1147 if (!styleImage->isLoaded())
1154 return true; // Never paint a nine-piece image incrementally, but don't paint the fallback borders either. 1148 return true; // Never paint a nine-piece image incrementally, but don't paint the fallback borders either.
1155 1149
1156 if (!styleImage->canRender(this, style->effectiveZoom())) 1150 if (!styleImage->canRender(this, style->effectiveZoom()))
1157 return false; 1151 return false;
1158 1152
1159 // FIXME: border-image is broken with full page zooming when tiling has to h appen, since the tiling function 1153 // FIXME: border-image is broken with full page zooming when tiling has to h appen, since the tiling function
1160 // doesn't have any understanding of the zoom that is in effect on the tile. 1154 // doesn't have any understanding of the zoom that is in effect on the tile.
1161 LayoutRect rectWithOutsets = rect; 1155 LayoutRect rectWithOutsets = rect;
1162 rectWithOutsets.expand(style->imageOutsets(ninePieceImage)); 1156 rectWithOutsets.expand(style->imageOutsets(ninePieceImage));
1163 IntRect borderImageRect = pixelSnappedIntRect(rectWithOutsets); 1157 IntRect borderImageRect = pixelSnappedIntRect(rectWithOutsets);
1164 1158
1165 IntSize imageSize = calculateImageIntrinsicDimensions(styleImage, borderImag eRect.size(), DoNotScaleByEffectiveZoom); 1159 IntSize imageSize = calculateImageIntrinsicDimensions(styleImage, borderImag eRect.size(), DoNotScaleByEffectiveZoom);
1166 1160
1167 // If both values are ‘auto’ then the intrinsic width and/or height of the i mage should be used, if any. 1161 // If both values are ‘auto’ then the intrinsic width and/or height of the i mage should be used, if any.
1168 styleImage->setContainerSizeForRenderer(this, imageSize, style->effectiveZoo m()); 1162 styleImage->setContainerSizeForRenderer(this, imageSize, style->effectiveZoo m());
1169 1163
1170 int imageWidth = imageSize.width(); 1164 int imageWidth = imageSize.width();
1171 int imageHeight = imageSize.height(); 1165 int imageHeight = imageSize.height();
1172 RenderView* renderView = view();
1173 1166
1174 float imageScaleFactor = styleImage->imageScaleFactor(); 1167 float imageScaleFactor = styleImage->imageScaleFactor();
1175 int topSlice = min<int>(imageHeight, valueForLength(ninePieceImage.imageSlic es().top(), imageHeight, renderView)) * imageScaleFactor; 1168 int topSlice = min<int>(imageHeight, valueForLength(ninePieceImage.imageSlic es().top(), imageHeight)) * imageScaleFactor;
1176 int rightSlice = min<int>(imageWidth, valueForLength(ninePieceImage.imageSli ces().right(), imageWidth, renderView)) * imageScaleFactor; 1169 int rightSlice = min<int>(imageWidth, valueForLength(ninePieceImage.imageSli ces().right(), imageWidth)) * imageScaleFactor;
1177 int bottomSlice = min<int>(imageHeight, valueForLength(ninePieceImage.imageS lices().bottom(), imageHeight, renderView)) * imageScaleFactor; 1170 int bottomSlice = min<int>(imageHeight, valueForLength(ninePieceImage.imageS lices().bottom(), imageHeight)) * imageScaleFactor;
1178 int leftSlice = min<int>(imageWidth, valueForLength(ninePieceImage.imageSlic es().left(), imageWidth, renderView)) * imageScaleFactor; 1171 int leftSlice = min<int>(imageWidth, valueForLength(ninePieceImage.imageSlic es().left(), imageWidth)) * imageScaleFactor;
1179 1172
1180 ENinePieceImageRule hRule = ninePieceImage.horizontalRule(); 1173 ENinePieceImageRule hRule = ninePieceImage.horizontalRule();
1181 ENinePieceImageRule vRule = ninePieceImage.verticalRule(); 1174 ENinePieceImageRule vRule = ninePieceImage.verticalRule();
1182 1175
1183 int topWidth = computeBorderImageSide(ninePieceImage.borderSlices().top(), s tyle->borderTopWidth(), topSlice, borderImageRect.height(), renderView); 1176 int topWidth = computeBorderImageSide(ninePieceImage.borderSlices().top(), s tyle->borderTopWidth(), topSlice, borderImageRect.height());
1184 int rightWidth = computeBorderImageSide(ninePieceImage.borderSlices().right( ), style->borderRightWidth(), rightSlice, borderImageRect.width(), renderView); 1177 int rightWidth = computeBorderImageSide(ninePieceImage.borderSlices().right( ), style->borderRightWidth(), rightSlice, borderImageRect.width());
1185 int bottomWidth = computeBorderImageSide(ninePieceImage.borderSlices().botto m(), style->borderBottomWidth(), bottomSlice, borderImageRect.height(), renderVi ew); 1178 int bottomWidth = computeBorderImageSide(ninePieceImage.borderSlices().botto m(), style->borderBottomWidth(), bottomSlice, borderImageRect.height());
1186 int leftWidth = computeBorderImageSide(ninePieceImage.borderSlices().left(), style->borderLeftWidth(), leftSlice, borderImageRect.width(), renderView); 1179 int leftWidth = computeBorderImageSide(ninePieceImage.borderSlices().left(), style->borderLeftWidth(), leftSlice, borderImageRect.width());
1187 1180
1188 // Reduce the widths if they're too large. 1181 // Reduce the widths if they're too large.
1189 // The spec says: Given Lwidth as the width of the border image area, Lheigh t as its height, and Wside as the border image width 1182 // The spec says: Given Lwidth as the width of the border image area, Lheigh t as its height, and Wside as the border image width
1190 // offset for the side, let f = min(Lwidth/(Wleft+Wright), Lheight/(Wtop+Wbo ttom)). If f < 1, then all W are reduced by 1183 // offset for the side, let f = min(Lwidth/(Wleft+Wright), Lheight/(Wtop+Wbo ttom)). If f < 1, then all W are reduced by
1191 // multiplying them by f. 1184 // multiplying them by f.
1192 int borderSideWidth = max(1, leftWidth + rightWidth); 1185 int borderSideWidth = max(1, leftWidth + rightWidth);
1193 int borderSideHeight = max(1, topWidth + bottomWidth); 1186 int borderSideHeight = max(1, topWidth + bottomWidth);
1194 float borderSideScaleFactor = min((float)borderImageRect.width() / borderSid eWidth, (float)borderImageRect.height() / borderSideHeight); 1187 float borderSideScaleFactor = min((float)borderImageRect.width() / borderSid eWidth, (float)borderImageRect.height() / borderSideHeight);
1195 if (borderSideScaleFactor < 1) { 1188 if (borderSideScaleFactor < 1) {
1196 topWidth *= borderSideScaleFactor; 1189 topWidth *= borderSideScaleFactor;
(...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after
1726 GraphicsContext* graphicsContext = info.context; 1719 GraphicsContext* graphicsContext = info.context;
1727 // border-image is not affected by border-radius. 1720 // border-image is not affected by border-radius.
1728 if (paintNinePieceImage(graphicsContext, rect, style, style->borderImage())) 1721 if (paintNinePieceImage(graphicsContext, rect, style, style->borderImage()))
1729 return; 1722 return;
1730 1723
1731 if (graphicsContext->paintingDisabled()) 1724 if (graphicsContext->paintingDisabled())
1732 return; 1725 return;
1733 1726
1734 BorderEdge edges[4]; 1727 BorderEdge edges[4];
1735 getBorderEdgeInfo(edges, style, includeLogicalLeftEdge, includeLogicalRightE dge); 1728 getBorderEdgeInfo(edges, style, includeLogicalLeftEdge, includeLogicalRightE dge);
1736 RoundedRect outerBorder = style->getRoundedBorderFor(rect, view(), includeLo gicalLeftEdge, includeLogicalRightEdge); 1729 RoundedRect outerBorder = style->getRoundedBorderFor(rect, includeLogicalLef tEdge, includeLogicalRightEdge);
1737 RoundedRect innerBorder = style->getRoundedInnerBorderFor(borderInnerRectAdj ustedForBleedAvoidance(graphicsContext, rect, bleedAvoidance), includeLogicalLef tEdge, includeLogicalRightEdge); 1730 RoundedRect innerBorder = style->getRoundedInnerBorderFor(borderInnerRectAdj ustedForBleedAvoidance(graphicsContext, rect, bleedAvoidance), includeLogicalLef tEdge, includeLogicalRightEdge);
1738 1731
1739 bool haveAlphaColor = false; 1732 bool haveAlphaColor = false;
1740 bool haveAllSolidEdges = true; 1733 bool haveAllSolidEdges = true;
1741 bool haveAllDoubleEdges = true; 1734 bool haveAllDoubleEdges = true;
1742 int numEdgesVisible = 4; 1735 int numEdgesVisible = 4;
1743 bool allEdgesShareColor = true; 1736 bool allEdgesShareColor = true;
1744 int firstVisibleEdge = -1; 1737 int firstVisibleEdge = -1;
1745 BorderEdgeFlags edgesToDraw = 0; 1738 BorderEdgeFlags edgesToDraw = 0;
1746 1739
(...skipping 711 matching lines...) Expand 10 before | Expand all | Expand 10 after
2458 } 2451 }
2459 2452
2460 void RenderBoxModelObject::paintBoxShadow(const PaintInfo& info, const LayoutRec t& paintRect, const RenderStyle* s, ShadowStyle shadowStyle, bool includeLogical LeftEdge, bool includeLogicalRightEdge) 2453 void RenderBoxModelObject::paintBoxShadow(const PaintInfo& info, const LayoutRec t& paintRect, const RenderStyle* s, ShadowStyle shadowStyle, bool includeLogical LeftEdge, bool includeLogicalRightEdge)
2461 { 2454 {
2462 // FIXME: Deal with border-image. Would be great to use border-image as a m ask. 2455 // FIXME: Deal with border-image. Would be great to use border-image as a m ask.
2463 GraphicsContext* context = info.context; 2456 GraphicsContext* context = info.context;
2464 if (context->paintingDisabled() || !s->boxShadow()) 2457 if (context->paintingDisabled() || !s->boxShadow())
2465 return; 2458 return;
2466 2459
2467 RoundedRect border = (shadowStyle == Inset) ? s->getRoundedInnerBorderFor(pa intRect, includeLogicalLeftEdge, includeLogicalRightEdge) 2460 RoundedRect border = (shadowStyle == Inset) ? s->getRoundedInnerBorderFor(pa intRect, includeLogicalLeftEdge, includeLogicalRightEdge)
2468 : s->getRoundedBorderFor(pain tRect, view(), includeLogicalLeftEdge, includeLogicalRightEdge); 2461 : s->getRoundedBorderFor(paintRect, includeLogicalLeftEdge, includeLogic alRightEdge);
2469 2462
2470 bool hasBorderRadius = s->hasBorderRadius(); 2463 bool hasBorderRadius = s->hasBorderRadius();
2471 bool isHorizontal = s->isHorizontalWritingMode(); 2464 bool isHorizontal = s->isHorizontalWritingMode();
2472 bool hasOpaqueBackground = s->visitedDependentColor(CSSPropertyBackgroundCol or).isValid() && s->visitedDependentColor(CSSPropertyBackgroundColor).alpha() == 255; 2465 bool hasOpaqueBackground = s->visitedDependentColor(CSSPropertyBackgroundCol or).isValid() && s->visitedDependentColor(CSSPropertyBackgroundColor).alpha() == 255;
2473 2466
2474 GraphicsContextStateSaver stateSaver(*context, false); 2467 GraphicsContextStateSaver stateSaver(*context, false);
2475 2468
2476 const ShadowList* shadowList = s->boxShadow(); 2469 const ShadowList* shadowList = s->boxShadow();
2477 for (size_t i = shadowList->shadows().size(); i--; ) { 2470 for (size_t i = shadowList->shadows().size(); i--; ) {
2478 const ShadowData& shadow = shadowList->shadows()[i]; 2471 const ShadowData& shadow = shadowList->shadows()[i];
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
2810 ASSERT(!beforeChild || toBoxModelObject == beforeChild->parent()); 2803 ASSERT(!beforeChild || toBoxModelObject == beforeChild->parent());
2811 for (RenderObject* child = startChild; child && child != endChild; ) { 2804 for (RenderObject* child = startChild; child && child != endChild; ) {
2812 // Save our next sibling as moveChildTo will clear it. 2805 // Save our next sibling as moveChildTo will clear it.
2813 RenderObject* nextSibling = child->nextSibling(); 2806 RenderObject* nextSibling = child->nextSibling();
2814 moveChildTo(toBoxModelObject, child, beforeChild, fullRemoveInsert); 2807 moveChildTo(toBoxModelObject, child, beforeChild, fullRemoveInsert);
2815 child = nextSibling; 2808 child = nextSibling;
2816 } 2809 }
2817 } 2810 }
2818 2811
2819 } // namespace WebCore 2812 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698