From 65da2431f9ee9711e971002ae17043c1a3d36a3f Mon Sep 17 00:00:00 2001 From: Moonchild Date: Wed, 6 Jan 2021 23:57:26 +0000 Subject: Issue #1705 - Part 4: Add scrollbar-width CSS keyword to CSS parser. This should be all parts needed to add a brand new enum keyword including getting the computed style from it... --- layout/style/nsCSSKeywordList.h | 1 + layout/style/nsCSSPropList.h | 10 ++++++++++ layout/style/nsCSSProps.cpp | 6 ++++++ layout/style/nsCSSProps.h | 1 + layout/style/nsComputedDOMStyle.cpp | 10 ++++++++++ layout/style/nsComputedDOMStyle.h | 1 + layout/style/nsComputedDOMStylePropertyList.h | 1 + layout/style/nsRuleNode.cpp | 9 +++++++++ layout/style/nsStyleConsts.h | 7 +++++++ layout/style/nsStyleStruct.cpp | 9 +++++++++ layout/style/nsStyleStruct.h | 1 + layout/style/test/property_database.js | 12 ++++++++++++ 12 files changed, 68 insertions(+) (limited to 'layout') diff --git a/layout/style/nsCSSKeywordList.h b/layout/style/nsCSSKeywordList.h index 86ba59142..689ff47eb 100644 --- a/layout/style/nsCSSKeywordList.h +++ b/layout/style/nsCSSKeywordList.h @@ -509,6 +509,7 @@ CSS_KEY(scrollbar, scrollbar) CSS_KEY(scrollbar-small, scrollbar_small) CSS_KEY(scrollbar-horizontal, scrollbar_horizontal) CSS_KEY(scrollbar-vertical, scrollbar_vertical) +CSS_KEY(scrollbar-width, scrollbar_width) CSS_KEY(se-resize, se_resize) CSS_KEY(select-after, select_after) CSS_KEY(select-all, select_all) diff --git a/layout/style/nsCSSPropList.h b/layout/style/nsCSSPropList.h index 658ea68d7..e78dafcc5 100644 --- a/layout/style/nsCSSPropList.h +++ b/layout/style/nsCSSPropList.h @@ -3709,6 +3709,16 @@ CSS_PROP_DISPLAY( kScrollSnapTypeKTable, CSS_PROP_NO_OFFSET, eStyleAnimType_Discrete) +CSS_PROP_USERINTERFACE( + scrollbar-width, + scrollbar_width, + ScrollbarWidth, + CSS_PROPERTY_PARSE_VALUE, + "layout.css.scrollbar-width.enabled", + VARIANT_HK, + kScrollbarWidthKTable, + CSS_PROP_NO_OFFSET, + eStyleAnimType_Discrete) CSS_PROP_DISPLAY( shape-outside, shape_outside, diff --git a/layout/style/nsCSSProps.cpp b/layout/style/nsCSSProps.cpp index e0cda2488..b6ffe7952 100644 --- a/layout/style/nsCSSProps.cpp +++ b/layout/style/nsCSSProps.cpp @@ -2009,6 +2009,12 @@ const KTableEntry nsCSSProps::kScrollSnapTypeKTable[] = { { eCSSKeyword_UNKNOWN, -1 } }; +const KTableEntry nsCSSProps::kScrollbarWidthKTable[] = { + { eCSSKeyword_auto, StyleScrollbarWidth::Auto }, + { eCSSKeyword_thin, StyleScrollbarWidth::Thin }, + { eCSSKeyword_none, StyleScrollbarWidth::None } +}; + const KTableEntry nsCSSProps::kStackSizingKTable[] = { { eCSSKeyword_ignore, NS_STYLE_STACK_SIZING_IGNORE }, { eCSSKeyword_stretch_to_fit, NS_STYLE_STACK_SIZING_STRETCH_TO_FIT }, diff --git a/layout/style/nsCSSProps.h b/layout/style/nsCSSProps.h index 34d457c08..7b8c56860 100644 --- a/layout/style/nsCSSProps.h +++ b/layout/style/nsCSSProps.h @@ -856,6 +856,7 @@ public: static const KTableEntry kRubyPositionKTable[]; static const KTableEntry kScrollBehaviorKTable[]; static const KTableEntry kScrollSnapTypeKTable[]; + static const KTableEntry kScrollbarWidthKTable[]; static const KTableEntry kSpeakKTable[]; static const KTableEntry kSpeakHeaderKTable[]; static const KTableEntry kSpeakNumeralKTable[]; diff --git a/layout/style/nsComputedDOMStyle.cpp b/layout/style/nsComputedDOMStyle.cpp index 748f990b7..7ac5fa604 100644 --- a/layout/style/nsComputedDOMStyle.cpp +++ b/layout/style/nsComputedDOMStyle.cpp @@ -3305,6 +3305,16 @@ nsComputedDOMStyle::DoGetScrollSnapTypeY() return val.forget(); } +already_AddRefed +nsComputedDOMStyle::DoGetScrollbarWidth() +{ + RefPtr val = new nsROCSSPrimitiveValue; + val->SetIdent( + nsCSSProps::ValueToKeywordEnum(StyleUserInterface()->mScrollbarWidth, + nsCSSProps::kScrollbarWidthKTable)); + return val.forget(); +} + already_AddRefed nsComputedDOMStyle::GetScrollSnapPoints(const nsStyleCoord& aCoord) { diff --git a/layout/style/nsComputedDOMStyle.h b/layout/style/nsComputedDOMStyle.h index 35a614268..38a61e23c 100644 --- a/layout/style/nsComputedDOMStyle.h +++ b/layout/style/nsComputedDOMStyle.h @@ -492,6 +492,7 @@ private: already_AddRefed DoGetCursor(); already_AddRefed DoGetForceBrokenImageIcon(); already_AddRefed DoGetIMEMode(); + already_AddRefed DoGetScrollbarWidth(); already_AddRefed DoGetUserFocus(); already_AddRefed DoGetUserInput(); already_AddRefed DoGetUserModify(); diff --git a/layout/style/nsComputedDOMStylePropertyList.h b/layout/style/nsComputedDOMStylePropertyList.h index 6a18a7ad0..ec223cda4 100644 --- a/layout/style/nsComputedDOMStylePropertyList.h +++ b/layout/style/nsComputedDOMStylePropertyList.h @@ -226,6 +226,7 @@ COMPUTED_STYLE_PROP(scroll_snap_points_x, ScrollSnapPointsX) COMPUTED_STYLE_PROP(scroll_snap_points_y, ScrollSnapPointsY) COMPUTED_STYLE_PROP(scroll_snap_type_x, ScrollSnapTypeX) COMPUTED_STYLE_PROP(scroll_snap_type_y, ScrollSnapTypeY) +COMPUTED_STYLE_PROP(scrollbar_width, ScrollbarWidth) COMPUTED_STYLE_PROP(shape_outside, ShapeOutside) //// COMPUTED_STYLE_PROP(size, Size) COMPUTED_STYLE_PROP(tab_size, TabSize) diff --git a/layout/style/nsRuleNode.cpp b/layout/style/nsRuleNode.cpp index 504b66ac2..04715aa99 100644 --- a/layout/style/nsRuleNode.cpp +++ b/layout/style/nsRuleNode.cpp @@ -1394,6 +1394,7 @@ struct SetEnumValueHelper DEFINE_ENUM_CLASS_SETTER(StyleFillRule, Nonzero, Evenodd) DEFINE_ENUM_CLASS_SETTER(StyleFloat, None, InlineEnd) DEFINE_ENUM_CLASS_SETTER(StyleFloatEdge, ContentBox, MarginBox) + DEFINE_ENUM_CLASS_SETTER(StyleScrollbarWidth, Auto, None) DEFINE_ENUM_CLASS_SETTER(StyleTextJustify, None, InterCharacter) DEFINE_ENUM_CLASS_SETTER(StyleUserFocus, None, SelectMenu) DEFINE_ENUM_CLASS_SETTER(StyleUserSelect, None, MozText) @@ -5235,6 +5236,14 @@ nsRuleNode::ComputeUserInterfaceData(void* aStartStruct, // caret-color: auto, color, inherit setComplexColor(aRuleData->ValueForCaretColor(), &nsStyleUserInterface::mCaretColor); + + // scrollbar-width: auto, thin, none + SetValue(*aRuleData->ValueForScrollbarWidth(), + ui->mScrollbarWidth, + conditions, + SETVAL_ENUMERATED, + parentUI->mScrollbarWidth, + StyleScrollbarWidth::Auto); COMPUTE_END_INHERITED(UserInterface, ui) } diff --git a/layout/style/nsStyleConsts.h b/layout/style/nsStyleConsts.h index e6a0cc65a..308a66647 100644 --- a/layout/style/nsStyleConsts.h +++ b/layout/style/nsStyleConsts.h @@ -187,6 +187,13 @@ enum class StyleFloatEdge : uint8_t { MarginBox, }; +// scrollbar-width +enum class StyleScrollbarWidth : uint8_t { + Auto, + Thin, + None, +}; + // shape-box for shape-outside enum class StyleShapeOutsideShapeBox : uint8_t { NoBox, diff --git a/layout/style/nsStyleStruct.cpp b/layout/style/nsStyleStruct.cpp index d2d89a57d..acf287ea8 100644 --- a/layout/style/nsStyleStruct.cpp +++ b/layout/style/nsStyleStruct.cpp @@ -4024,6 +4024,7 @@ nsStyleUserInterface::nsStyleUserInterface(StyleStructContext aContext) , mPointerEvents(NS_STYLE_POINTER_EVENTS_AUTO) , mCursor(NS_STYLE_CURSOR_AUTO) , mCaretColor(StyleComplexColor::Auto()) + , mScrollbarWidth(StyleScrollbarWidth::Auto) { MOZ_COUNT_CTOR(nsStyleUserInterface); } @@ -4036,6 +4037,7 @@ nsStyleUserInterface::nsStyleUserInterface(const nsStyleUserInterface& aSource) , mCursor(aSource.mCursor) , mCursorImages(aSource.mCursorImages) , mCaretColor(aSource.mCaretColor) + , mScrollbarWidth(aSource.mScrollbarWidth) { MOZ_COUNT_CTOR(nsStyleUserInterface); } @@ -4087,6 +4089,13 @@ nsStyleUserInterface::CalcDifference(const nsStyleUserInterface& aNewData) const if (mCaretColor != aNewData.mCaretColor) { hint |= nsChangeHint_RepaintFrame; } + + if (mScrollbarWidth != aNewData.mScrollbarWidth) { + // For scrollbar-width change, we need some special handling similar + // to overflow properties. Specifically, we may need to reconstruct + // the scrollbar or force reflow of the viewport scrollbar. + hint |= nsChangeHint_ScrollbarChange; + } return hint; } diff --git a/layout/style/nsStyleStruct.h b/layout/style/nsStyleStruct.h index 831808edf..35ff071a5 100644 --- a/layout/style/nsStyleStruct.h +++ b/layout/style/nsStyleStruct.h @@ -3417,6 +3417,7 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleUserInterface uint8_t mCursor; // [inherited] See nsStyleConsts.h nsTArray mCursorImages; // [inherited] images and coords mozilla::StyleComplexColor mCaretColor; // [inherited] + mozilla::StyleScrollbarWidth mScrollbarWidth; inline uint8_t GetEffectivePointerEvents(nsIFrame* aFrame) const; }; diff --git a/layout/style/test/property_database.js b/layout/style/test/property_database.js index 635431e8f..1d5dc989f 100644 --- a/layout/style/test/property_database.js +++ b/layout/style/test/property_database.js @@ -7944,6 +7944,18 @@ for (var prop in gCSSProperties) { } } +if (IsCSSPropertyPrefEnabled("layout.css.scrollbar-width.enabled")) { + gCSSProperties["scrollbar-width"] = { + domProp: "scrollbarWidth", + inherited: false, + type: CSS_TYPE_LONGHAND, + initial_values: [ "auto" ], + other_values: [ "none", "thin" ], + invalid_values: [ "1px" ] + }; +} + + if (false) { // TODO These properties are chrome-only, and are not exposed via CSSOM. // We may still want to find a way to test them. See bug 1206999. -- cgit v1.2.3