From 3266e0976ff055aefa49b664966229bbb89d1009 Mon Sep 17 00:00:00 2001 From: Andy Date: Fri, 31 Jul 2020 13:01:18 -0700 Subject: Issue #1619 - Convert Intrinsic Ratio to Float https://bugzilla.mozilla.org/show_bug.cgi?id=1547792 Aspect Ratio handling simplified by using floating point integers: - Multiplication of value (or inverse value) to a known side for Scaling - No unequal equal values such as "4/3" vs "8/6" vs "20/15" - Truly "Empty" aspect ratios, even if one dimension is not 0 --- layout/style/nsStyleStruct.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'layout/style') diff --git a/layout/style/nsStyleStruct.cpp b/layout/style/nsStyleStruct.cpp index 200f934c5..9270f2960 100644 --- a/layout/style/nsStyleStruct.cpp +++ b/layout/style/nsStyleStruct.cpp @@ -2731,7 +2731,7 @@ nsStyleImageLayers::Size::DependsOnPositioningAreaSize(const nsStyleImage& aImag } if (imgContainer) { CSSIntSize imageSize; - nsSize imageRatio; + AspectRatio imageRatio; bool hasWidth, hasHeight; nsLayoutUtils::ComputeSizeForDrawing(imgContainer, imageSize, imageRatio, hasWidth, hasHeight); @@ -2744,7 +2744,7 @@ nsStyleImageLayers::Size::DependsOnPositioningAreaSize(const nsStyleImage& aImag // If the image has an intrinsic ratio, rendering will depend on frame // size when background-size is all auto. - if (imageRatio != nsSize(0, 0)) { + if (imageRatio) { return mWidthType == mHeightType; } -- cgit v1.2.3 From 0bbe6ec10589b8540aa86200bf2b209ad4e563ba Mon Sep 17 00:00:00 2001 From: Andy Date: Tue, 4 Aug 2020 13:54:01 -0700 Subject: Issue #1620 - Use Intrinsic Aspect Ratio for Images (uplift) --- layout/style/nsCSSPropList.h | 11 +++++++++++ layout/style/nsRuleNode.cpp | 6 ++++++ layout/style/nsStyleStruct.cpp | 7 +++++++ layout/style/nsStyleStruct.h | 1 + layout/style/test/ListCSSProperties.cpp | 1 + 5 files changed, 26 insertions(+) (limited to 'layout/style') diff --git a/layout/style/nsCSSPropList.h b/layout/style/nsCSSPropList.h index 411f982a4..44bd44cef 100644 --- a/layout/style/nsCSSPropList.h +++ b/layout/style/nsCSSPropList.h @@ -470,6 +470,17 @@ CSS_PROP_DISPLAY( kAppearanceKTable, CSS_PROP_NO_OFFSET, eStyleAnimType_Discrete) +CSS_PROP_POSITION( + aspect-ratio, + aspect_ratio, + AspectRatio, + CSS_PROPERTY_INTERNAL | + CSS_PROPERTY_PARSE_INACCESSIBLE, + "", + VARIANT_NUMBER, + nullptr, + offsetof(nsStylePosition, mAspectRatio), + eStyleAnimType_None) CSS_PROP_DISPLAY( backface-visibility, backface_visibility, diff --git a/layout/style/nsRuleNode.cpp b/layout/style/nsRuleNode.cpp index a0f65c069..1a451a2ef 100644 --- a/layout/style/nsRuleNode.cpp +++ b/layout/style/nsRuleNode.cpp @@ -8544,6 +8544,12 @@ nsRuleNode::ComputePositionData(void* aStartStruct, SETCOORD_UNSET_INITIAL, aContext, mPresContext, conditions); + // aspect-ratio: float, initial + SetFactor(*aRuleData->ValueForAspectRatio(), + pos->mAspectRatio, conditions, + parentPos->mAspectRatio, 0.0f, + SETFCT_UNSET_INITIAL | SETFCT_POSITIVE | SETFCT_NONE); + // box-sizing: enum, inherit, initial SetValue(*aRuleData->ValueForBoxSizing(), pos->mBoxSizing, conditions, diff --git a/layout/style/nsStyleStruct.cpp b/layout/style/nsStyleStruct.cpp index 9270f2960..3b19a4418 100644 --- a/layout/style/nsStyleStruct.cpp +++ b/layout/style/nsStyleStruct.cpp @@ -1408,6 +1408,7 @@ nsStylePosition::nsStylePosition(StyleStructContext aContext) , mGridAutoColumnsMax(eStyleUnit_Auto) , mGridAutoRowsMin(eStyleUnit_Auto) , mGridAutoRowsMax(eStyleUnit_Auto) + , mAspectRatio(0.0f) , mGridAutoFlow(NS_STYLE_GRID_AUTO_FLOW_ROW) , mBoxSizing(StyleBoxSizing::Content) , mAlignContent(NS_STYLE_ALIGN_NORMAL) @@ -1466,6 +1467,7 @@ nsStylePosition::nsStylePosition(const nsStylePosition& aSource) , mGridAutoColumnsMax(aSource.mGridAutoColumnsMax) , mGridAutoRowsMin(aSource.mGridAutoRowsMin) , mGridAutoRowsMax(aSource.mGridAutoRowsMax) + , mAspectRatio(aSource.mAspectRatio) , mGridAutoFlow(aSource.mGridAutoFlow) , mBoxSizing(aSource.mBoxSizing) , mAlignContent(aSource.mAlignContent) @@ -1636,6 +1638,11 @@ nsStylePosition::CalcDifference(const nsStylePosition& aNewData, if (isVertical ? heightChanged : widthChanged) { hint |= nsChangeHint_ReflowHintsForISizeChange; } + + if (mAspectRatio != aNewData.mAspectRatio) { + hint |= nsChangeHint_ReflowHintsForISizeChange | + nsChangeHint_ReflowHintsForBSizeChange; + } } else { if (widthChanged || heightChanged) { hint |= nsChangeHint_NeutralChange; diff --git a/layout/style/nsStyleStruct.h b/layout/style/nsStyleStruct.h index b257c6bb5..4bda817dd 100644 --- a/layout/style/nsStyleStruct.h +++ b/layout/style/nsStyleStruct.h @@ -1815,6 +1815,7 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStylePosition nsStyleCoord mGridAutoColumnsMax; // [reset] coord, percent, enum, calc, flex nsStyleCoord mGridAutoRowsMin; // [reset] coord, percent, enum, calc, flex nsStyleCoord mGridAutoRowsMax; // [reset] coord, percent, enum, calc, flex + float mAspectRatio; // [reset] float uint8_t mGridAutoFlow; // [reset] enumerated. See nsStyleConsts.h mozilla::StyleBoxSizing mBoxSizing; // [reset] see nsStyleConsts.h diff --git a/layout/style/test/ListCSSProperties.cpp b/layout/style/test/ListCSSProperties.cpp index 718032f61..9f727104b 100644 --- a/layout/style/test/ListCSSProperties.cpp +++ b/layout/style/test/ListCSSProperties.cpp @@ -106,6 +106,7 @@ const char *gInaccessibleProperties[] = { "-x-span", "-x-system-font", "-x-text-zoom", + "aspect-ratio", // for now. "-moz-control-character-visibility", "-moz-script-level", // parsed by UA sheets only "-moz-script-size-multiplier", -- cgit v1.2.3 From 5e8e0d05a683cc38b211088bb42355abb5282005 Mon Sep 17 00:00:00 2001 From: Moonchild Date: Mon, 10 Aug 2020 12:13:10 +0200 Subject: [CSS] Alias -webkit-appearance for compatibility reasons Since this is supported as an alias by Firefox and Edge for the same reasons and we have websites using this to (attempt to) override the system-provided styling with their own, leaving out the only supported keyword we'd otherwise have (with -moz- prefix) but still stating -webkit-. TODO: unprefix this completely and make the vendor prefixes aliases. --- layout/style/nsCSSPropAliasList.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'layout/style') diff --git a/layout/style/nsCSSPropAliasList.h b/layout/style/nsCSSPropAliasList.h index f7938af9e..9ec71b2cf 100644 --- a/layout/style/nsCSSPropAliasList.h +++ b/layout/style/nsCSSPropAliasList.h @@ -264,6 +264,11 @@ CSS_PROP_ALIAS(-webkit-animation-timing-function, WebkitAnimationTimingFunction, WEBKIT_PREFIX_PREF) +CSS_PROP_ALIAS(-webkit-appearance, + appearance, + WebkitAppearance, + WEBKIT_PREFIX_PREF) + CSS_PROP_ALIAS(-webkit-filter, filter, WebkitFilter, -- cgit v1.2.3 From c384fa6e25b07b37e9cc406da0c0aef583c61513 Mon Sep 17 00:00:00 2001 From: Gaming4JC Date: Sun, 16 Aug 2020 14:05:16 -0400 Subject: Issue #1620 - Intrinsic Aspect Ratio: Debug Follow up. Newly introduced aspect-ratio property did not have CSS_PROP_LIST_EXCLUDE_INTERNAL defines, resulting in the following assertion: \!nsCSSProps::PropHasFlags(p, (1<<28)) (properties defined outside of #ifndef CSS_PROP_LIST_EXCLUDE_INTERNAL sections must not have the CSS_PROPERTY_INTERNAL flag), at ...layout/style/nsCSSProps.cpp:289 This patch resolves the assertion by adding #ifndef around the aspect-ratio property. --- layout/style/nsCSSPropList.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'layout/style') diff --git a/layout/style/nsCSSPropList.h b/layout/style/nsCSSPropList.h index 44bd44cef..f62aa3827 100644 --- a/layout/style/nsCSSPropList.h +++ b/layout/style/nsCSSPropList.h @@ -470,6 +470,7 @@ CSS_PROP_DISPLAY( kAppearanceKTable, CSS_PROP_NO_OFFSET, eStyleAnimType_Discrete) +#ifndef CSS_PROP_LIST_EXCLUDE_INTERNAL CSS_PROP_POSITION( aspect-ratio, aspect_ratio, @@ -481,6 +482,7 @@ CSS_PROP_POSITION( nullptr, offsetof(nsStylePosition, mAspectRatio), eStyleAnimType_None) +#endif // CSS_PROP_LIST_EXCLUDE_INTERNAL CSS_PROP_DISPLAY( backface-visibility, backface_visibility, -- cgit v1.2.3 From a4780ebaeb123ce9c793b85bb38a1701fad8f7ac Mon Sep 17 00:00:00 2001 From: Moonchild Date: Sun, 30 Aug 2020 09:29:45 +0000 Subject: Issue #1629 - Uplift implementation of behavior for stylesheets. --- layout/style/Loader.cpp | 28 ++++++++++++++++++---------- layout/style/Loader.h | 13 ++++++++++--- 2 files changed, 28 insertions(+), 13 deletions(-) (limited to 'layout/style') diff --git a/layout/style/Loader.cpp b/layout/style/Loader.cpp index 0ce337e29..df523174d 100644 --- a/layout/style/Loader.cpp +++ b/layout/style/Loader.cpp @@ -1277,7 +1277,8 @@ Loader::PrepareSheet(StyleSheet* aSheet, const nsSubstring& aMediaString, nsMediaList* aMediaList, Element* aScopeElement, - bool isAlternate) + bool isAlternate, + bool isExplicitlyEnabled) { NS_PRECONDITION(aSheet, "Must have a sheet!"); @@ -1306,7 +1307,7 @@ Loader::PrepareSheet(StyleSheet* aSheet, sheet->SetMedia(mediaList); sheet->SetTitle(aTitle); - sheet->SetEnabled(!isAlternate); + sheet->SetEnabled(!isAlternate || isExplicitlyEnabled); sheet->SetScopeElement(aScopeElement); } @@ -1984,7 +1985,8 @@ Loader::LoadInlineStyle(nsIContent* aElement, Element* aScopeElement, nsICSSLoaderObserver* aObserver, bool* aCompleted, - bool* aIsAlternate) + bool* aIsAlternate, + bool* aIsExplicitlyEnabled) { LOG(("css::Loader::LoadInlineStyle")); NS_ASSERTION(mParsingDatas.Length() == 0, "We're in the middle of a parse?"); @@ -2016,8 +2018,9 @@ Loader::LoadInlineStyle(nsIContent* aElement, "Inline sheets should not be cached"); LOG((" Sheet is alternate: %d", *aIsAlternate)); + LOG((" Sheet is explicitly enabled: %d", *aIsExplicitlyEnabled)); - PrepareSheet(sheet, aTitle, aMedia, nullptr, aScopeElement, *aIsAlternate); + PrepareSheet(sheet, aTitle, aMedia, nullptr, aScopeElement, *aIsAlternate, *aIsExplicitlyEnabled); if (aElement->HasFlag(NODE_IS_IN_SHADOW_TREE)) { ShadowRoot* containingShadow = aElement->GetContainingShadow(); @@ -2058,7 +2061,8 @@ Loader::LoadStyleLink(nsIContent* aElement, ReferrerPolicy aReferrerPolicy, const nsAString& aIntegrity, nsICSSLoaderObserver* aObserver, - bool* aIsAlternate) + bool* aIsAlternate, + bool* aIsExplicitlyEnabled) { LOG(("css::Loader::LoadStyleLink")); NS_PRECONDITION(aURL, "Must have URL to load"); @@ -2111,8 +2115,9 @@ Loader::LoadStyleLink(nsIContent* aElement, NS_ENSURE_SUCCESS(rv, rv); LOG((" Sheet is alternate: %d", *aIsAlternate)); + LOG((" Sheet is explicitly enabled: %d", *aIsExplicitlyEnabled)); - PrepareSheet(sheet, aTitle, aMedia, nullptr, nullptr, *aIsAlternate); + PrepareSheet(sheet, aTitle, aMedia, nullptr, nullptr, *aIsAlternate, *aIsExplicitlyEnabled); rv = InsertSheetInDoc(sheet, aElement, mDocument); NS_ENSURE_SUCCESS(rv, rv); @@ -2137,9 +2142,10 @@ Loader::LoadStyleLink(nsIContent* aElement, aObserver, principal, requestingNode); NS_ADDREF(data); - // If we have to parse and it's an alternate non-inline, defer it + // If we have to parse and it's an alternate non-inline, defer it unless + // it's explicitly enabled. if (aURL && state == eSheetNeedsParser && mSheets->mLoadingDatas.Count() != 0 && - *aIsAlternate) { + *aIsAlternate && !*aIsExplicitlyEnabled) { LOG((" Deferring alternate sheet load")); URIPrincipalReferrerPolicyAndCORSModeHashKey key(data->mURI, data->mLoaderPrincipal, @@ -2266,6 +2272,7 @@ Loader::LoadChildSheet(StyleSheet* aParentSheet, state = eSheetComplete; } else { bool isAlternate; + bool isExplicitlyEnabled; const nsSubstring& empty = EmptyString(); // For now, use CORS_NONE for child sheets rv = CreateSheet(aURL, nullptr, principal, @@ -2276,7 +2283,7 @@ Loader::LoadChildSheet(StyleSheet* aParentSheet, false, empty, state, &isAlternate, &sheet); NS_ENSURE_SUCCESS(rv, rv); - PrepareSheet(sheet, empty, empty, aMedia, nullptr, isAlternate); + PrepareSheet(sheet, empty, empty, aMedia, nullptr, isAlternate, isExplicitlyEnabled); } rv = InsertChildSheet(sheet, aParentSheet, aParentRule); @@ -2389,6 +2396,7 @@ Loader::InternalLoadNonDocumentSheet(nsIURI* aURL, StyleSheetState state; bool isAlternate; + bool isExplicitlyEnabled; RefPtr sheet; bool syncLoad = (aObserver == nullptr); const nsSubstring& empty = EmptyString(); @@ -2398,7 +2406,7 @@ Loader::InternalLoadNonDocumentSheet(nsIURI* aURL, false, empty, state, &isAlternate, &sheet); NS_ENSURE_SUCCESS(rv, rv); - PrepareSheet(sheet, empty, empty, nullptr, nullptr, isAlternate); + PrepareSheet(sheet, empty, empty, nullptr, nullptr, isAlternate, isExplicitlyEnabled); if (state == eSheetComplete) { LOG((" Sheet already complete")); diff --git a/layout/style/Loader.h b/layout/style/Loader.h index 209783a80..4a3088b6b 100644 --- a/layout/style/Loader.h +++ b/layout/style/Loader.h @@ -230,6 +230,8 @@ public: * @param [out] aCompleted whether parsing of the sheet completed. * @param [out] aIsAlternate whether the stylesheet ended up being an * alternate sheet. + * @param [out] aIsExplicitlyEnabled whether the stylesheet was explicitly + * enabled by having the disabled attribute removed. */ nsresult LoadInlineStyle(nsIContent* aElement, const nsAString& aBuffer, @@ -239,7 +241,8 @@ public: mozilla::dom::Element* aScopeElement, nsICSSLoaderObserver* aObserver, bool* aCompleted, - bool* aIsAlternate); + bool* aIsAlternate, + bool* aIsExplicitlyEnabled); /** * Load a linked (document) stylesheet. If a successful result is returned, @@ -260,6 +263,8 @@ public: * @param [out] aIsAlternate whether the stylesheet actually ended up beinga * an alternate sheet. Note that this need not match * aHasAlternateRel. + * @param [out] aIsExplicitlyEnabled whether the stylesheet was explicitly + * enabled by having the disabled attribute removed. */ nsresult LoadStyleLink(nsIContent* aElement, nsIURI* aURL, @@ -270,7 +275,8 @@ public: ReferrerPolicy aReferrerPolicy, const nsAString& aIntegrity, nsICSSLoaderObserver* aObserver, - bool* aIsAlternate); + bool* aIsAlternate, + bool* aIsExplicitlyEnabled); /** * Load a child (@import-ed) style sheet. In addition to loading the sheet, @@ -476,7 +482,8 @@ private: const nsAString& aMediaString, nsMediaList* aMediaList, dom::Element* aScopeElement, - bool isAlternate); + bool isAlternate, + bool isExplicitlyEnabled); nsresult InsertSheetInDoc(StyleSheet* aSheet, nsIContent* aLinkingContent, -- cgit v1.2.3