Bug 1819464 - Part 2: Add content-box and stroke-box into transform-box in style. r=emilio

Also, add a prefernce for content-box and stroke-box. So we have to
define a new type, TransformBox, and let content-box and stroke-box
behind the preference.

Differential Revision: https://phabricator.services.mozilla.com/D185363
This commit is contained in:
Boris Chiou 2023-08-22 19:49:03 +00:00
Родитель bf16b44176
Коммит ce64275561
21 изменённых файлов: 88 добавлений и 39 удалений

Просмотреть файл

@ -11894,11 +11894,13 @@ exports.CSS_PROPERTIES = {
"supports": [],
"values": [
"border-box",
"content-box",
"fill-box",
"inherit",
"initial",
"revert",
"revert-layer",
"stroke-box",
"unset",
"view-box"
]

Просмотреть файл

@ -33,8 +33,8 @@ CSSPoint MotionPathUtils::ComputeAnchorPointAdjustment(const nsIFrame& aFrame) {
}
auto transformBox = aFrame.StyleDisplay()->mTransformBox;
if (transformBox == StyleGeometryBox::ViewBox ||
transformBox == StyleGeometryBox::BorderBox) {
if (transformBox == StyleTransformBox::ViewBox ||
transformBox == StyleTransformBox::BorderBox) {
return {};
}

Просмотреть файл

@ -517,6 +517,7 @@ cbindgen-types = [
{ gecko = "StyleGenericPerspective", servo = "crate::values::generics::box_::Perspective" },
{ gecko = "StyleZIndex", servo = "crate::values::computed::ZIndex" },
{ gecko = "StyleGenericZIndex", servo = "crate::values::generics::position::ZIndex" },
{ gecko = "StyleTransformBox", servo = "crate::values::computed::TransformBox" },
{ gecko = "StyleTransformOrigin", servo = "crate::values::computed::TransformOrigin" },
{ gecko = "StyleTransformStyle", servo = "crate::values::computed::TransformStyle" },
{ gecko = "StyleGenericBorderRadius", servo = "crate::values::generics::border::BorderRadius" },

Просмотреть файл

@ -2175,7 +2175,7 @@ nsStyleDisplay::nsStyleDisplay()
StyleScrollSnapStrictness::None},
mBackfaceVisibility(StyleBackfaceVisibility::Visible),
mTransformStyle(StyleTransformStyle::Flat),
mTransformBox(StyleGeometryBox::ViewBox),
mTransformBox(StyleTransformBox::ViewBox),
mRotate(StyleRotate::None()),
mTranslate(StyleTranslate::None()),
mScale(StyleScale::None()),

Просмотреть файл

@ -1300,7 +1300,7 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleDisplay {
mozilla::StyleBackfaceVisibility mBackfaceVisibility;
mozilla::StyleTransformStyle mTransformStyle;
mozilla::StyleGeometryBox mTransformBox;
mozilla::StyleTransformBox mTransformBox;
mozilla::StyleTransform mTransform;
mozilla::StyleRotate mRotate;

Просмотреть файл

@ -45,10 +45,17 @@ void TransformReferenceBox::EnsureDimensionsAreCached() {
MOZ_ASSERT(mFrame);
const auto box = mFrame->StyleDisplay()->mTransformBox;
if (box == StyleTransformBox::ContentBox ||
box == StyleTransformBox::StrokeBox) {
// TODO: Implement this in the following patches.
return;
}
mIsCached = true;
if (mFrame->HasAnyStateBits(NS_FRAME_SVG_LAYOUT)) {
if (mFrame->StyleDisplay()->mTransformBox == StyleGeometryBox::FillBox) {
if (box == StyleTransformBox::FillBox) {
// Percentages in transforms resolve against the SVG bbox, and the
// transform is relative to the top-left of the SVG bbox.
nsRect bboxInAppUnits = nsLayoutUtils::ComputeGeometryBox(
@ -63,11 +70,9 @@ void TransformReferenceBox::EnsureDimensionsAreCached() {
mHeight = bboxInAppUnits.height;
} else {
// The value 'border-box' is treated as 'view-box' for SVG content.
MOZ_ASSERT(
mFrame->StyleDisplay()->mTransformBox == StyleGeometryBox::ViewBox ||
mFrame->StyleDisplay()->mTransformBox ==
StyleGeometryBox::BorderBox,
"Unexpected value for 'transform-box'");
MOZ_ASSERT(box == StyleTransformBox::ViewBox ||
box == StyleTransformBox::BorderBox,
"Unexpected value for 'transform-box'");
// Percentages in transforms resolve against the width/height of the
// nearest viewport (or its viewBox if one is applied), and the
// transform is relative to {0,0} in current user space.

Просмотреть файл

@ -25,6 +25,7 @@ prefs =
layout.css.animation-composition.enabled=true
layout.css.basic-shape-rect.enabled=true
layout.css.basic-shape-xywh.enabled=true
layout.css.transform-box-content-stroke.enabled=true
support-files =
animation_utils.js
bug1729861.js

Просмотреть файл

@ -3775,7 +3775,7 @@ var gCSSProperties = {
type: CSS_TYPE_LONGHAND,
initial_values: ["view-box"],
other_values: ["fill-box", "border-box"],
invalid_values: ["content-box", "padding-box", "stroke-box", "margin-box"],
invalid_values: ["padding-box", "margin-box"],
},
"transform-origin": {
domProp: "transformOrigin",
@ -11996,6 +11996,15 @@ if (IsCSSPropertyPrefEnabled("layout.css.individual-transform.enabled")) {
};
}
if (
IsCSSPropertyPrefEnabled("layout.css.transform-box-content-stroke.enabled")
) {
gCSSProperties["transform-box"]["other_values"].push(
"content-box",
"stroke-box"
);
}
gCSSProperties["touch-action"] = {
domProp: "touchAction",
inherited: false,

Просмотреть файл

@ -8127,6 +8127,13 @@
mirror: always
rust: true
# Whether content-box and stroke-box are enabled for transform-box.
- name: layout.css.transform-box-content-stroke.enabled
type: RelaxedAtomicBool
value: @IS_NIGHTLY_BUILD@
mirror: always
rust: true
# Whether trigonometric constants and functions are enabled in calc().
- name: layout.css.trig.enabled
type: RelaxedAtomicBool

Просмотреть файл

@ -515,6 +515,7 @@ class Longhand(Property):
"MathDepth",
"MozScriptMinSize",
"MozScriptSizeMultiplier",
"TransformBox",
"TextDecorationSkipInk",
"NonNegativeNumber",
"OffsetRotate",

Просмотреть файл

@ -447,13 +447,12 @@ ${helpers.single_keyword(
affects="paint",
)}
${helpers.single_keyword(
${helpers.predefined_type(
"transform-box",
"view-box border-box fill-box",
"TransformBox",
"computed::TransformBox::ViewBox",
engines="gecko",
gecko_enum_prefix="StyleGeometryBox",
spec="https://drafts.csswg.org/css-transforms/#transform-box",
gecko_inexhaustive="True",
animation_value_type="discrete",
affects="overflow",
)}

Просмотреть файл

@ -101,7 +101,7 @@ pub use self::text::{OverflowWrap, RubyPosition, TextOverflow, WordBreak, WordSp
pub use self::text::{TextAlign, TextAlignLast, TextEmphasisPosition, TextEmphasisStyle};
pub use self::text::{TextDecorationLength, TextDecorationSkipInk, TextJustify};
pub use self::time::Time;
pub use self::transform::{Rotate, Scale, Transform, TransformOperation};
pub use self::transform::{Rotate, Scale, Transform, TransformBox, TransformOperation};
pub use self::transform::{TransformOrigin, TransformStyle, Translate};
#[cfg(feature = "gecko")]
pub use self::ui::CursorImage;

Просмотреть файл

@ -13,6 +13,7 @@ use crate::Zero;
use euclid::default::{Transform3D, Vector3D};
pub use crate::values::generics::transform::TransformStyle;
pub use crate::values::specified::transform::TransformBox;
/// A single operation in a computed CSS `transform`
pub type TransformOperation =

Просмотреть файл

@ -97,7 +97,7 @@ pub use self::text::{TextAlignKeyword, TextDecorationLine, TextOverflow, WordSpa
pub use self::text::{TextDecorationLength, TextDecorationSkipInk, TextJustify, TextTransform};
pub use self::time::Time;
pub use self::transform::{Rotate, Scale, Transform};
pub use self::transform::{TransformOrigin, TransformStyle, Translate};
pub use self::transform::{TransformBox, TransformOrigin, TransformStyle, Translate};
#[cfg(feature = "gecko")]
pub use self::ui::CursorImage;
pub use self::ui::{BoolInteger, Cursor, UserSelect};

Просмотреть файл

@ -35,6 +35,49 @@ pub type TransformOrigin = generic::TransformOrigin<
Length,
>;
#[cfg(feature = "gecko")]
fn all_transform_boxes_are_enabled(_context: &ParserContext) -> bool {
static_prefs::pref!("layout.css.transform-box-content-stroke.enabled")
}
#[cfg(feature = "servo")]
fn all_transform_boxes_are_enabled(_context: &ParserContext) -> bool {
false
}
/// The specified value of `transform-box`.
/// https://drafts.csswg.org/css-transforms-1/#transform-box
// Note: Once we ship everything, we can drop this and just use single_keyword for tranform-box.
#[allow(missing_docs)]
#[derive(
Animate,
Clone,
ComputeSquaredDistance,
Copy,
Debug,
Deserialize,
MallocSizeOf,
Parse,
PartialEq,
Serialize,
SpecifiedValueInfo,
ToAnimatedValue,
ToComputedValue,
ToCss,
ToResolvedValue,
ToShmem,
)]
#[repr(u8)]
pub enum TransformBox {
#[parse(condition = "all_transform_boxes_are_enabled")]
ContentBox,
BorderBox,
FillBox,
#[parse(condition = "all_transform_boxes_are_enabled")]
StrokeBox,
ViewBox,
}
impl TransformOrigin {
/// Returns the initial specified value for `transform-origin`.
#[inline]

Просмотреть файл

@ -168,6 +168,7 @@ include = [
"NonNegativeLengthOrNumberRect",
"Perspective",
"ZIndex",
"TransformBox",
"TransformOrigin",
"LineBreak",
"LineClamp",

Просмотреть файл

@ -1,2 +1,2 @@
prefs: [layout.css.individual-transform.enabled:true, dom.animations-api.compositing.enabled:true, layout.css.backdrop-filter.enabled:true]
prefs: [layout.css.individual-transform.enabled:true, dom.animations-api.compositing.enabled:true, layout.css.backdrop-filter.enabled:true, layout.css.transform-box-content-stroke.enabled:true]
leak-threshold: [default:51200]

Просмотреть файл

@ -1,8 +0,0 @@
[transform-box-computed.html]
expected:
if (os == "android") and fission: [OK, TIMEOUT]
[Property transform-box value 'content-box']
expected: FAIL
[Property transform-box value 'stroke-box']
expected: FAIL

Просмотреть файл

@ -1,3 +0,0 @@
[transform-box-invalid.html]
expected:
if (os == "android") and fission: [OK, TIMEOUT]

Просмотреть файл

@ -1,8 +0,0 @@
[transform-box-valid.html]
expected:
if (os == "android") and fission: [OK, TIMEOUT]
[e.style['transform-box'\] = "content-box" should set the property value]
expected: FAIL
[e.style['transform-box'\] = "stroke-box" should set the property value]
expected: FAIL

Просмотреть файл

@ -1,2 +0,0 @@
[cssbox-stroke-box.html]
expected: FAIL