mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-25 09:57:32 +09:00
Issue #2404 - Enable CSS aspect-ratio sizing
This commit is contained in:
parent
6a37c361c2
commit
7159f5fa08
3 changed files with 67 additions and 6 deletions
|
|
@ -1170,6 +1170,8 @@ protected:
|
|||
|
||||
// Property specific parsing routines
|
||||
bool ParseImageLayers(const nsCSSPropertyID aTable[]);
|
||||
bool ParseAspectRatio(nsCSSValue& aValue);
|
||||
bool ParseAspectRatioRatio(nsCSSValue& aValue);
|
||||
|
||||
struct ImageLayersShorthandParseState {
|
||||
nsCSSValue& mColor;
|
||||
|
|
@ -13270,6 +13272,59 @@ CSSParserImpl::ParsePropertyByFunction(nsCSSPropertyID aPropID)
|
|||
#define BG_CLR (BG_CENTER | BG_LEFT | BG_RIGHT)
|
||||
#define BG_LR (BG_LEFT | BG_RIGHT)
|
||||
|
||||
bool
|
||||
CSSParserImpl::ParseAspectRatioRatio(nsCSSValue& aValue)
|
||||
{
|
||||
nsCSSValue width;
|
||||
if (!ParseNonNegativeNumber(width)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
float w = width.GetFloatValue();
|
||||
float h = 1.0f;
|
||||
if (ExpectSymbol('/', true)) {
|
||||
nsCSSValue height;
|
||||
if (!ParseNonNegativeNumber(height)) {
|
||||
return false;
|
||||
}
|
||||
h = height.GetFloatValue();
|
||||
}
|
||||
|
||||
// Degenerate ratios behave as auto in layout.
|
||||
aValue.SetFloatValue(w == 0.0f || h == 0.0f ? 0.0f : w / h,
|
||||
eCSSUnit_Number);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
CSSParserImpl::ParseAspectRatio(nsCSSValue& aValue)
|
||||
{
|
||||
if (ParseSingleTokenVariant(aValue, VARIANT_INHERIT, nullptr)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
nsCSSValue autoValue;
|
||||
bool hasAuto = ParseSingleTokenVariant(autoValue, VARIANT_AUTO, nullptr);
|
||||
|
||||
nsCSSValue ratioValue;
|
||||
bool hasRatio = ParseAspectRatioRatio(ratioValue);
|
||||
if (!hasAuto && !hasRatio) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (hasRatio) {
|
||||
if (!hasAuto) {
|
||||
// The grammar is "auto || <ratio>", so auto may appear after the ratio.
|
||||
ParseSingleTokenVariant(autoValue, VARIANT_AUTO, nullptr);
|
||||
}
|
||||
aValue = ratioValue;
|
||||
return true;
|
||||
}
|
||||
|
||||
aValue.SetAutoValue();
|
||||
return true;
|
||||
}
|
||||
|
||||
CSSParseResult
|
||||
CSSParserImpl::ParseBoxProperty(nsCSSValue& aValue,
|
||||
nsCSSPropertyID aPropID)
|
||||
|
|
@ -13308,6 +13363,8 @@ CSSParserImpl::ParseSingleValuePropertyByFunction(nsCSSValue& aValue,
|
|||
switch (aPropID) {
|
||||
case eCSSProperty_clip_path:
|
||||
return ParseClipPath(aValue);
|
||||
case eCSSProperty_aspect_ratio:
|
||||
return ParseAspectRatio(aValue);
|
||||
case eCSSProperty_contain:
|
||||
return ParseContain(aValue);
|
||||
case eCSSProperty_font_family:
|
||||
|
|
|
|||
|
|
@ -7021,4 +7021,3 @@ nsComputedDOMStyle::DoGetOverflowBlockEnd()
|
|||
{
|
||||
return DoGetOverflowBlock();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9310,11 +9310,16 @@ 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);
|
||||
// aspect-ratio: auto | <ratio>
|
||||
const nsCSSValue* aspectRatio = aRuleData->ValueForAspectRatio();
|
||||
if (aspectRatio->GetUnit() == eCSSUnit_Auto) {
|
||||
pos->mAspectRatio = 0.0f;
|
||||
} else {
|
||||
SetFactor(*aspectRatio,
|
||||
pos->mAspectRatio, conditions,
|
||||
parentPos->mAspectRatio, 0.0f,
|
||||
SETFCT_UNSET_INITIAL | SETFCT_POSITIVE | SETFCT_NONE);
|
||||
}
|
||||
|
||||
// box-sizing: enum, inherit, initial
|
||||
SetValue(*aRuleData->ValueForBoxSizing(),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue