summaryrefslogtreecommitdiff
path: root/dom
diff options
context:
space:
mode:
authorMoonchild <moonchild@palemoon.org>2020-08-08 19:59:24 +0000
committerGitHub <noreply@github.com>2020-08-08 19:59:24 +0000
commit666e370292fc20813e885f8d88ad7ac384790627 (patch)
tree72d7c3850d18118ba0f3eb571ebf27f3a11d5373 /dom
parentb5762c6c27c3d2de499c5f8ea6e10bed445b7455 (diff)
parent05ee48943cdf2c48c24a43bdb289eabb1cd08e9a (diff)
downloaduxp-666e370292fc20813e885f8d88ad7ac384790627.tar.gz
Merge pull request #1613 from RealityRipple/AspectRatio
[Image/CSS] Intrinsic Aspect Ratio
Diffstat (limited to 'dom')
-rw-r--r--dom/html/HTMLImageElement.cpp2
-rw-r--r--dom/html/HTMLImageElement.h5
-rw-r--r--dom/html/nsGenericHTMLElement.cpp58
-rw-r--r--dom/html/nsGenericHTMLElement.h4
4 files changed, 52 insertions, 17 deletions
diff --git a/dom/html/HTMLImageElement.cpp b/dom/html/HTMLImageElement.cpp
index 444c352e2c..d042a9fe6f 100644
--- a/dom/html/HTMLImageElement.cpp
+++ b/dom/html/HTMLImageElement.cpp
@@ -325,7 +325,7 @@ HTMLImageElement::MapAttributesIntoRule(const nsMappedAttributes* aAttributes,
nsGenericHTMLElement::MapImageAlignAttributeInto(aAttributes, aData);
nsGenericHTMLElement::MapImageBorderAttributeInto(aAttributes, aData);
nsGenericHTMLElement::MapImageMarginAttributeInto(aAttributes, aData);
- nsGenericHTMLElement::MapImageSizeAttributesInto(aAttributes, aData);
+ nsGenericHTMLElement::MapImageSizeAttributesInto(aAttributes, aData, true);
nsGenericHTMLElement::MapCommonAttributesInto(aAttributes, aData);
}
diff --git a/dom/html/HTMLImageElement.h b/dom/html/HTMLImageElement.h
index bb4a098824..23cac4afb9 100644
--- a/dom/html/HTMLImageElement.h
+++ b/dom/html/HTMLImageElement.h
@@ -196,6 +196,11 @@ public:
return GetReferrerPolicyAsEnum();
}
+ bool IsAwaitingLoad() const
+ {
+ return !!mPendingImageLoadTask;
+ }
+
int32_t X();
int32_t Y();
// Uses XPCOM GetLowsrc.
diff --git a/dom/html/nsGenericHTMLElement.cpp b/dom/html/nsGenericHTMLElement.cpp
index b52e61ce6e..35ce8533bf 100644
--- a/dom/html/nsGenericHTMLElement.cpp
+++ b/dom/html/nsGenericHTMLElement.cpp
@@ -1449,29 +1449,57 @@ nsGenericHTMLElement::MapImageMarginAttributeInto(const nsMappedAttributes* aAtt
void
nsGenericHTMLElement::MapImageSizeAttributesInto(const nsMappedAttributes* aAttributes,
- nsRuleData* aData)
+ nsRuleData* aData,
+ bool aMapAspectRatio)
{
if (!(aData->mSIDs & NS_STYLE_INHERIT_BIT(Position)))
return;
+ auto* aWidth = aAttributes->GetAttr(nsGkAtoms::width);
+ auto* aHeight = aAttributes->GetAttr(nsGkAtoms::height);
+
// width: value
- nsCSSValue* width = aData->ValueForWidth();
- if (width->GetUnit() == eCSSUnit_Null) {
- const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::width);
- if (value && value->Type() == nsAttrValue::eInteger)
- width->SetFloatValue((float)value->GetIntegerValue(), eCSSUnit_Pixel);
- else if (value && value->Type() == nsAttrValue::ePercent)
- width->SetPercentValue(value->GetPercentValue());
+ if (aWidth) {
+ nsCSSValue* cWidth = aData->ValueForWidth();
+ if (cWidth->GetUnit() == eCSSUnit_Null) {
+ if (aWidth->Type() == nsAttrValue::eInteger)
+ cWidth->SetFloatValue((float)aWidth->GetIntegerValue(), eCSSUnit_Pixel);
+ else if (aWidth->Type() == nsAttrValue::ePercent)
+ cWidth->SetPercentValue(aWidth->GetPercentValue());
+ }
}
// height: value
- nsCSSValue* height = aData->ValueForHeight();
- if (height->GetUnit() == eCSSUnit_Null) {
- const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::height);
- if (value && value->Type() == nsAttrValue::eInteger)
- height->SetFloatValue((float)value->GetIntegerValue(), eCSSUnit_Pixel);
- else if (value && value->Type() == nsAttrValue::ePercent)
- height->SetPercentValue(value->GetPercentValue());
+ if (aHeight) {
+ nsCSSValue* cHeight = aData->ValueForHeight();
+ if (cHeight->GetUnit() == eCSSUnit_Null) {
+ if (aHeight->Type() == nsAttrValue::eInteger)
+ cHeight->SetFloatValue((float)aHeight->GetIntegerValue(), eCSSUnit_Pixel);
+ else if (aHeight->Type() == nsAttrValue::ePercent)
+ cHeight->SetPercentValue(aHeight->GetPercentValue());
+ }
+ }
+
+ if (Preferences::GetBool("layout.css.intrinsic-aspect-ratio.enabled") &&
+ aMapAspectRatio && aWidth && aHeight) {
+ Maybe<double> w;
+ if (aWidth->Type() == nsAttrValue::eInteger) {
+ w.emplace(aWidth->GetIntegerValue());
+ } else if (aWidth->Type() == nsAttrValue::eDoubleValue) {
+ w.emplace(aWidth->GetDoubleValue());
+ }
+
+ Maybe<double> h;
+ if (aHeight->Type() == nsAttrValue::eInteger) {
+ h.emplace(aHeight->GetIntegerValue());
+ } else if (aHeight->Type() == nsAttrValue::eDoubleValue) {
+ h.emplace(aHeight->GetDoubleValue());
+ }
+
+ if (w && h && *w != 0 && *h != 0) {
+ nsCSSValue* aspect_ratio = aData->ValueForAspectRatio();
+ aspect_ratio->SetFloatValue((float(*w) / float(*h)), eCSSUnit_Number);
+ }
}
}
diff --git a/dom/html/nsGenericHTMLElement.h b/dom/html/nsGenericHTMLElement.h
index c9169df117..8412ea0dc8 100644
--- a/dom/html/nsGenericHTMLElement.h
+++ b/dom/html/nsGenericHTMLElement.h
@@ -702,10 +702,12 @@ public:
*
* @param aAttributes the list of attributes to map
* @param aData the returned rule data [INOUT]
+ * @param aMapAspectRatio map width and height attributes on aspect-ratio
* @see GetAttributeMappingFunction
*/
static void MapImageSizeAttributesInto(const nsMappedAttributes* aAttributes,
- nsRuleData* aData);
+ nsRuleData* aData,
+ bool = false);
/**
* Helper to map the background attribute
* into a style struct.