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

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

Issue 1456813002: Calculate Background Image Geometries using sub-pixel values (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: MOAR expectations 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 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 670 matching lines...) Expand 10 before | Expand all | Expand 10 after
681 } 681 }
682 682
683 LayoutUnit LayoutBoxModelObject::computedCSSPadding(const Length& padding) const 683 LayoutUnit LayoutBoxModelObject::computedCSSPadding(const Length& padding) const
684 { 684 {
685 LayoutUnit w = 0; 685 LayoutUnit w = 0;
686 if (padding.hasPercent()) 686 if (padding.hasPercent())
687 w = containingBlockLogicalWidthForContent(); 687 w = containingBlockLogicalWidthForContent();
688 return minimumValueForLength(padding, w); 688 return minimumValueForLength(padding, w);
689 } 689 }
690 690
691 static inline int resolveWidthForRatio(int height, const FloatSize& intrinsicRat io) 691 static inline LayoutUnit resolveWidthForRatio(LayoutUnit height, const FloatSize & intrinsicRatio)
692 { 692 {
693 return ceilf(height * intrinsicRatio.width() / intrinsicRatio.height()); 693 return height * intrinsicRatio.width() / intrinsicRatio.height();
694 } 694 }
695 695
696 static inline int resolveHeightForRatio(int width, const FloatSize& intrinsicRat io) 696 static inline LayoutUnit resolveHeightForRatio(LayoutUnit width, const FloatSize & intrinsicRatio)
697 { 697 {
698 return ceilf(width * intrinsicRatio.height() / intrinsicRatio.width()); 698 return width * intrinsicRatio.height() / intrinsicRatio.width();
699 } 699 }
700 700
701 static inline IntSize resolveAgainstIntrinsicWidthOrHeightAndRatio(const IntSize & size, const FloatSize& intrinsicRatio, int useWidth, int useHeight) 701 static inline LayoutSize resolveAgainstIntrinsicWidthOrHeightAndRatio(const Layo utSize& size, const FloatSize& intrinsicRatio, LayoutUnit useWidth, LayoutUnit u seHeight)
702 { 702 {
703 if (intrinsicRatio.isEmpty()) { 703 if (intrinsicRatio.isEmpty()) {
704 if (useWidth) 704 if (useWidth)
705 return IntSize(useWidth, size.height()); 705 return LayoutSize(useWidth, size.height());
706 return IntSize(size.width(), useHeight); 706 return LayoutSize(size.width(), useHeight);
707 } 707 }
708 708
709 if (useWidth) 709 if (useWidth)
710 return IntSize(useWidth, resolveHeightForRatio(useWidth, intrinsicRatio) ); 710 return LayoutSize(useWidth, resolveHeightForRatio(useWidth, intrinsicRat io));
711 return IntSize(resolveWidthForRatio(useHeight, intrinsicRatio), useHeight); 711 return LayoutSize(resolveWidthForRatio(useHeight, intrinsicRatio), useHeight );
712 } 712 }
713 713
714 static inline IntSize resolveAgainstIntrinsicRatio(const IntSize& size, const Fl oatSize& intrinsicRatio) 714 static inline LayoutSize resolveAgainstIntrinsicRatio(const LayoutSize& size, co nst FloatSize& intrinsicRatio)
715 { 715 {
716 // Two possible solutions: (size.width(), solutionHeight) or (solutionWidth, size.height()) 716 // Two possible solutions: (size.width(), solutionHeight) or (solutionWidth, size.height())
717 // "... must be assumed to be the largest dimensions..." = easiest answer: t he rect with the largest surface area. 717 // "... must be assumed to be the largest dimensions..." = easiest answer: t he rect with the largest surface area.
718 718
719 int solutionWidth = resolveWidthForRatio(size.height(), intrinsicRatio); 719 LayoutUnit solutionWidth = resolveWidthForRatio(size.height(), intrinsicRati o);
720 int solutionHeight = resolveHeightForRatio(size.width(), intrinsicRatio); 720 LayoutUnit solutionHeight = resolveHeightForRatio(size.width(), intrinsicRat io);
721 if (solutionWidth <= size.width()) { 721 if (solutionWidth <= size.width()) {
722 if (solutionHeight <= size.height()) { 722 if (solutionHeight <= size.height()) {
723 // If both solutions fit, choose the one covering the larger area. 723 // If both solutions fit, choose the one covering the larger area.
724 int areaOne = solutionWidth * size.height(); 724 LayoutUnit areaOne = solutionWidth * size.height();
725 int areaTwo = size.width() * solutionHeight; 725 LayoutUnit areaTwo = size.width() * solutionHeight;
726 if (areaOne < areaTwo) 726 if (areaOne < areaTwo)
727 return IntSize(size.width(), solutionHeight); 727 return LayoutSize(size.width(), solutionHeight);
728 return IntSize(solutionWidth, size.height()); 728 return LayoutSize(solutionWidth, size.height());
729 } 729 }
730 730
731 // Only the first solution fits. 731 // Only the first solution fits.
732 return IntSize(solutionWidth, size.height()); 732 return LayoutSize(solutionWidth, size.height());
733 } 733 }
734 734
735 // Only the second solution fits, assert that. 735 // Only the second solution fits, assert that.
736 ASSERT(solutionHeight <= size.height()); 736 ASSERT(solutionHeight <= size.height());
737 return IntSize(size.width(), solutionHeight); 737 return LayoutSize(size.width(), solutionHeight);
738 } 738 }
739 739
740 IntSize LayoutBoxModelObject::calculateImageIntrinsicDimensions(StyleImage* imag e, const IntSize& positioningAreaSize, ScaleByEffectiveZoomOrNot shouldScaleOrNo t) const 740 LayoutSize LayoutBoxModelObject::calculateImageIntrinsicDimensions(StyleImage* i mage, const LayoutSize& positioningAreaSize, ScaleByEffectiveZoomOrNot shouldSca leOrNot) const
741 { 741 {
742 // A generated image without a fixed size, will always return the container size as intrinsic size. 742 // A generated image without a fixed size, will always return the container size as intrinsic size.
743 if (image->isGeneratedImage() && image->usesImageContainerSize()) 743 if (image->isGeneratedImage() && image->usesImageContainerSize())
744 return IntSize(positioningAreaSize.width(), positioningAreaSize.height() ); 744 return positioningAreaSize;
745 745
746 Length intrinsicWidth(Fixed); 746 Length intrinsicWidth(Fixed);
747 Length intrinsicHeight(Fixed); 747 Length intrinsicHeight(Fixed);
748 FloatSize intrinsicRatio; 748 FloatSize intrinsicRatio;
749 image->computeIntrinsicDimensions(this, intrinsicWidth, intrinsicHeight, int rinsicRatio); 749 image->computeIntrinsicDimensions(this, intrinsicWidth, intrinsicHeight, int rinsicRatio);
750 750
751 ASSERT(intrinsicWidth.isFixed()); 751 ASSERT(intrinsicWidth.isFixed());
752 ASSERT(intrinsicHeight.isFixed()); 752 ASSERT(intrinsicHeight.isFixed());
753 753
754 IntSize resolvedSize(intrinsicWidth.value(), intrinsicHeight.value()); 754 LayoutSize resolvedSize(intrinsicWidth.value(), intrinsicHeight.value());
755 IntSize minimumSize(resolvedSize.width() > 0 ? 1 : 0, resolvedSize.height() > 0 ? 1 : 0); 755 LayoutSize minimumSize(resolvedSize.width() > LayoutUnit() ? LayoutUnit(1) : LayoutUnit(),
756 resolvedSize.height() > LayoutUnit() ? LayoutUnit(1) : LayoutUnit());
756 if (shouldScaleOrNot == ScaleByEffectiveZoom) 757 if (shouldScaleOrNot == ScaleByEffectiveZoom)
757 resolvedSize.scale(style()->effectiveZoom()); 758 resolvedSize.scale(style()->effectiveZoom());
758 resolvedSize.clampToMinimumSize(minimumSize); 759 resolvedSize.clampToMinimumSize(minimumSize);
759 760
760 if (!resolvedSize.isEmpty()) 761 if (!resolvedSize.isEmpty())
761 return resolvedSize; 762 return resolvedSize;
762 763
763 // If the image has one of either an intrinsic width or an intrinsic height: 764 // If the image has one of either an intrinsic width or an intrinsic height:
764 // * and an intrinsic aspect ratio, then the missing dimension is calculated from the given dimension and the ratio. 765 // * and an intrinsic aspect ratio, then the missing dimension is calculated from the given dimension and the ratio.
765 // * and no intrinsic aspect ratio, then the missing dimension is assumed to be the size of the rectangle that 766 // * and no intrinsic aspect ratio, then the missing dimension is assumed to be the size of the rectangle that
766 // establishes the coordinate system for the 'background-position' propert y. 767 // establishes the coordinate system for the 'background-position' propert y.
767 if (resolvedSize.width() > 0 || resolvedSize.height() > 0) 768 if (resolvedSize.width() > LayoutUnit() || resolvedSize.height() > LayoutUni t())
768 return resolveAgainstIntrinsicWidthOrHeightAndRatio(positioningAreaSize, intrinsicRatio, resolvedSize.width(), resolvedSize.height()); 769 return resolveAgainstIntrinsicWidthOrHeightAndRatio(positioningAreaSize, intrinsicRatio, resolvedSize.width(), resolvedSize.height());
769 770
770 // If the image has no intrinsic dimensions and has an intrinsic ratio the d imensions must be assumed to be the 771 // If the image has no intrinsic dimensions and has an intrinsic ratio the d imensions must be assumed to be the
771 // largest dimensions at that ratio such that neither dimension exceeds the dimensions of the rectangle that 772 // largest dimensions at that ratio such that neither dimension exceeds the dimensions of the rectangle that
772 // establishes the coordinate system for the 'background-position' property. 773 // establishes the coordinate system for the 'background-position' property.
773 if (!intrinsicRatio.isEmpty()) 774 if (!intrinsicRatio.isEmpty())
774 return resolveAgainstIntrinsicRatio(positioningAreaSize, intrinsicRatio) ; 775 return resolveAgainstIntrinsicRatio(positioningAreaSize, intrinsicRatio) ;
775 776
776 // If the image has no intrinsic ratio either, then the dimensions must be a ssumed to be the rectangle that 777 // If the image has no intrinsic ratio either, then the dimensions must be a ssumed to be the rectangle that
777 // establishes the coordinate system for the 'background-position' property. 778 // establishes the coordinate system for the 'background-position' property.
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
1057 if (rootElementStyle->hasBackground()) 1058 if (rootElementStyle->hasBackground())
1058 return false; 1059 return false;
1059 1060
1060 if (node() != document().firstBodyElement()) 1061 if (node() != document().firstBodyElement())
1061 return false; 1062 return false;
1062 1063
1063 return true; 1064 return true;
1064 } 1065 }
1065 1066
1066 } // namespace blink 1067 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/layout/LayoutBoxModelObject.h ('k') | third_party/WebKit/Source/core/layout/LayoutListMarker.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698