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