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

Side by Side Diff: Source/core/rendering/style/RenderStyle.cpp

Issue 195793009: [CSS Shapes] inset does not properly clamp large corner radii (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Oops, add tests Created 6 years, 9 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) 1999 Antti Koivisto (koivisto@kde.org) 2 * Copyright (C) 1999 Antti Koivisto (koivisto@kde.org)
3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved. 3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved.
4 * Copyright (C) 2011 Adobe Systems Incorporated. All rights reserved. 4 * Copyright (C) 2011 Adobe Systems Incorporated. All rights reserved.
5 * 5 *
6 * This library is free software; you can redistribute it and/or 6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public 7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either 8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version. 9 * version 2 of the License, or (at your option) any later version.
10 * 10 *
(...skipping 19 matching lines...) Expand all
30 #include "core/rendering/TextAutosizer.h" 30 #include "core/rendering/TextAutosizer.h"
31 #include "core/rendering/style/ContentData.h" 31 #include "core/rendering/style/ContentData.h"
32 #include "core/rendering/style/CursorList.h" 32 #include "core/rendering/style/CursorList.h"
33 #include "core/rendering/style/QuotesData.h" 33 #include "core/rendering/style/QuotesData.h"
34 #include "core/rendering/style/ShadowList.h" 34 #include "core/rendering/style/ShadowList.h"
35 #include "core/rendering/style/StyleImage.h" 35 #include "core/rendering/style/StyleImage.h"
36 #include "core/rendering/style/StyleInheritedData.h" 36 #include "core/rendering/style/StyleInheritedData.h"
37 #include "platform/LengthFunctions.h" 37 #include "platform/LengthFunctions.h"
38 #include "platform/fonts/Font.h" 38 #include "platform/fonts/Font.h"
39 #include "platform/fonts/FontSelector.h" 39 #include "platform/fonts/FontSelector.h"
40 #include "platform/geometry/FloatRoundedRect.h"
40 #include "wtf/MathExtras.h" 41 #include "wtf/MathExtras.h"
41 42
42 using namespace std; 43 using namespace std;
43 44
44 namespace WebCore { 45 namespace WebCore {
45 46
46 struct SameSizeAsBorderValue { 47 struct SameSizeAsBorderValue {
47 RGBA32 m_color; 48 RGBA32 m_color;
48 unsigned m_width; 49 unsigned m_width;
49 }; 50 };
(...skipping 869 matching lines...) Expand 10 before | Expand all | Expand 10 after
919 IntSize(valueForLength(border.topLeft().width(), size.width()), 920 IntSize(valueForLength(border.topLeft().width(), size.width()),
920 valueForLength(border.topLeft().height(), size.height())), 921 valueForLength(border.topLeft().height(), size.height())),
921 IntSize(valueForLength(border.topRight().width(), size.width()), 922 IntSize(valueForLength(border.topRight().width(), size.width()),
922 valueForLength(border.topRight().height(), size.height())), 923 valueForLength(border.topRight().height(), size.height())),
923 IntSize(valueForLength(border.bottomLeft().width(), size.width()), 924 IntSize(valueForLength(border.bottomLeft().width(), size.width()),
924 valueForLength(border.bottomLeft().height(), size.height())), 925 valueForLength(border.bottomLeft().height(), size.height())),
925 IntSize(valueForLength(border.bottomRight().width(), size.width()), 926 IntSize(valueForLength(border.bottomRight().width(), size.width()),
926 valueForLength(border.bottomRight().height(), size.height()))); 927 valueForLength(border.bottomRight().height(), size.height())));
927 } 928 }
928 929
929 static float calcConstraintScaleFor(const IntRect& rect, const RoundedRect::Radi i& radii)
930 {
931 // Constrain corner radii using CSS3 rules:
932 // http://www.w3.org/TR/css3-background/#the-border-radius
933
934 float factor = 1;
935 unsigned radiiSum;
936
937 // top
938 radiiSum = static_cast<unsigned>(radii.topLeft().width()) + static_cast<unsi gned>(radii.topRight().width()); // Casts to avoid integer overflow.
939 if (radiiSum > static_cast<unsigned>(rect.width()))
940 factor = min(static_cast<float>(rect.width()) / radiiSum, factor);
941
942 // bottom
943 radiiSum = static_cast<unsigned>(radii.bottomLeft().width()) + static_cast<u nsigned>(radii.bottomRight().width());
944 if (radiiSum > static_cast<unsigned>(rect.width()))
945 factor = min(static_cast<float>(rect.width()) / radiiSum, factor);
946
947 // left
948 radiiSum = static_cast<unsigned>(radii.topLeft().height()) + static_cast<uns igned>(radii.bottomLeft().height());
949 if (radiiSum > static_cast<unsigned>(rect.height()))
950 factor = min(static_cast<float>(rect.height()) / radiiSum, factor);
951
952 // right
953 radiiSum = static_cast<unsigned>(radii.topRight().height()) + static_cast<un signed>(radii.bottomRight().height());
954 if (radiiSum > static_cast<unsigned>(rect.height()))
955 factor = min(static_cast<float>(rect.height()) / radiiSum, factor);
956
957 ASSERT(factor <= 1);
958 return factor;
959 }
960
961 StyleImage* RenderStyle::listStyleImage() const { return rareInheritedData->list StyleImage.get(); } 930 StyleImage* RenderStyle::listStyleImage() const { return rareInheritedData->list StyleImage.get(); }
962 void RenderStyle::setListStyleImage(PassRefPtr<StyleImage> v) 931 void RenderStyle::setListStyleImage(PassRefPtr<StyleImage> v)
963 { 932 {
964 if (rareInheritedData->listStyleImage != v) 933 if (rareInheritedData->listStyleImage != v)
965 rareInheritedData.access()->listStyleImage = v; 934 rareInheritedData.access()->listStyleImage = v;
966 } 935 }
967 936
968 Color RenderStyle::color() const { return inherited->color; } 937 Color RenderStyle::color() const { return inherited->color; }
969 Color RenderStyle::visitedLinkColor() const { return inherited->visitedLinkColor ; } 938 Color RenderStyle::visitedLinkColor() const { return inherited->visitedLinkColor ; }
970 void RenderStyle::setColor(const Color& v) { SET_VAR(inherited, color, v); } 939 void RenderStyle::setColor(const Color& v) { SET_VAR(inherited, color, v); }
971 void RenderStyle::setVisitedLinkColor(const Color& v) { SET_VAR(inherited, visit edLinkColor, v); } 940 void RenderStyle::setVisitedLinkColor(const Color& v) { SET_VAR(inherited, visit edLinkColor, v); }
972 941
973 short RenderStyle::horizontalBorderSpacing() const { return inherited->horizonta l_border_spacing; } 942 short RenderStyle::horizontalBorderSpacing() const { return inherited->horizonta l_border_spacing; }
974 short RenderStyle::verticalBorderSpacing() const { return inherited->vertical_bo rder_spacing; } 943 short RenderStyle::verticalBorderSpacing() const { return inherited->vertical_bo rder_spacing; }
975 void RenderStyle::setHorizontalBorderSpacing(short v) { SET_VAR(inherited, horiz ontal_border_spacing, v); } 944 void RenderStyle::setHorizontalBorderSpacing(short v) { SET_VAR(inherited, horiz ontal_border_spacing, v); }
976 void RenderStyle::setVerticalBorderSpacing(short v) { SET_VAR(inherited, vertica l_border_spacing, v); } 945 void RenderStyle::setVerticalBorderSpacing(short v) { SET_VAR(inherited, vertica l_border_spacing, v); }
977 946
978 RoundedRect RenderStyle::getRoundedBorderFor(const LayoutRect& borderRect, bool includeLogicalLeftEdge, bool includeLogicalRightEdge) const 947 RoundedRect RenderStyle::getRoundedBorderFor(const LayoutRect& borderRect, bool includeLogicalLeftEdge, bool includeLogicalRightEdge) const
979 { 948 {
980 IntRect snappedBorderRect(pixelSnappedIntRect(borderRect)); 949 IntRect snappedBorderRect(pixelSnappedIntRect(borderRect));
981 RoundedRect roundedRect(snappedBorderRect); 950 RoundedRect roundedRect(snappedBorderRect);
982 if (hasBorderRadius()) { 951 if (hasBorderRadius()) {
983 RoundedRect::Radii radii = calcRadiiFor(surround->border, snappedBorderR ect.size()); 952 RoundedRect::Radii radii = calcRadiiFor(surround->border, snappedBorderR ect.size());
984 radii.scale(calcConstraintScaleFor(snappedBorderRect, radii)); 953 radii.scale(calcBorderRadiiConstraintScaleFor(borderRect, radii));
985 roundedRect.includeLogicalEdges(radii, isHorizontalWritingMode(), includ eLogicalLeftEdge, includeLogicalRightEdge); 954 roundedRect.includeLogicalEdges(radii, isHorizontalWritingMode(), includ eLogicalLeftEdge, includeLogicalRightEdge);
986 } 955 }
987 return roundedRect; 956 return roundedRect;
988 } 957 }
989 958
990 RoundedRect RenderStyle::getRoundedInnerBorderFor(const LayoutRect& borderRect, bool includeLogicalLeftEdge, bool includeLogicalRightEdge) const 959 RoundedRect RenderStyle::getRoundedInnerBorderFor(const LayoutRect& borderRect, bool includeLogicalLeftEdge, bool includeLogicalRightEdge) const
991 { 960 {
992 bool horizontal = isHorizontalWritingMode(); 961 bool horizontal = isHorizontalWritingMode();
993 962
994 int leftWidth = (!horizontal || includeLogicalLeftEdge) ? borderLeftWidth() : 0; 963 int leftWidth = (!horizontal || includeLogicalLeftEdge) ? borderLeftWidth() : 0;
(...skipping 624 matching lines...) Expand 10 before | Expand all | Expand 10 after
1619 } 1588 }
1620 1589
1621 void RenderStyle::setBorderImageOutset(const BorderImageLengthBox& outset) 1590 void RenderStyle::setBorderImageOutset(const BorderImageLengthBox& outset)
1622 { 1591 {
1623 if (surround->border.m_image.outset() == outset) 1592 if (surround->border.m_image.outset() == outset)
1624 return; 1593 return;
1625 surround.access()->border.m_image.setOutset(outset); 1594 surround.access()->border.m_image.setOutset(outset);
1626 } 1595 }
1627 1596
1628 } // namespace WebCore 1597 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698