mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-13 13:25:37 +00:00
Bug 1460456
part 3 - Add scrollbar-{face,track}-color properties. r=heycam
MozReview-Commit-ID: ImNfHHfzRdM --HG-- extra : rebase_source : 58caf9fff4ad62d4413de688ad115e89a5929ea6
This commit is contained in:
parent
b0413cb441
commit
4c114dbee6
@ -24,6 +24,7 @@ class nsAtom;
|
||||
class nsIWidget;
|
||||
|
||||
namespace mozilla {
|
||||
class ComputedStyle;
|
||||
namespace layers {
|
||||
class StackingContextHelper;
|
||||
class WebRenderLayerManager;
|
||||
@ -72,6 +73,14 @@ public:
|
||||
const nsRect& aRect,
|
||||
const nsRect& aDirtyRect) = 0;
|
||||
|
||||
/**
|
||||
* Get the used color of the given widget when it's specified as auto.
|
||||
* It's currently only used for scrollbar-*-color properties.
|
||||
*/
|
||||
virtual nscolor GetWidgetAutoColor(mozilla::ComputedStyle* aStyle,
|
||||
uint8_t aWidgetType)
|
||||
{ return NS_RGB(0, 0, 0); }
|
||||
|
||||
/**
|
||||
* Create WebRender commands for the theme background.
|
||||
* @return true if the theme knows how to create WebRender commands for the
|
||||
|
@ -1180,6 +1180,32 @@ nsComputedDOMStyle::SetValueFromComplexColor(nsROCSSPrimitiveValue* aValue,
|
||||
SetToRGBAColor(aValue, aColor.CalcColor(mComputedStyle));
|
||||
}
|
||||
|
||||
void
|
||||
nsComputedDOMStyle::SetValueForWidgetColor(nsROCSSPrimitiveValue* aValue,
|
||||
const StyleComplexColor& aColor,
|
||||
uint8_t aWidgetType)
|
||||
{
|
||||
if (!aColor.mIsAuto) {
|
||||
SetToRGBAColor(aValue, aColor.CalcColor(mComputedStyle));
|
||||
return;
|
||||
}
|
||||
nsPresContext* presContext = mPresShell->GetPresContext();
|
||||
MOZ_ASSERT(presContext);
|
||||
if (nsContentUtils::ShouldResistFingerprinting(presContext->GetDocShell())) {
|
||||
// Return transparent when resisting fingerprinting.
|
||||
SetToRGBAColor(aValue, NS_RGBA(0, 0, 0, 0));
|
||||
return;
|
||||
}
|
||||
if (nsITheme* theme = presContext->GetTheme()) {
|
||||
nscolor color = theme->GetWidgetAutoColor(mComputedStyle, aWidgetType);
|
||||
SetToRGBAColor(aValue, color);
|
||||
} else {
|
||||
// If we don't have theme, we don't know what value it should be,
|
||||
// just give it a transparent fallback.
|
||||
SetToRGBAColor(aValue, NS_RGBA(0, 0, 0, 0));
|
||||
}
|
||||
}
|
||||
|
||||
already_AddRefed<CSSValue>
|
||||
nsComputedDOMStyle::DoGetColor()
|
||||
{
|
||||
@ -3770,6 +3796,24 @@ nsComputedDOMStyle::DoGetScrollSnapCoordinate()
|
||||
}
|
||||
}
|
||||
|
||||
already_AddRefed<CSSValue>
|
||||
nsComputedDOMStyle::DoGetScrollbarFaceColor()
|
||||
{
|
||||
RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
|
||||
SetValueForWidgetColor(val, StyleUserInterface()->mScrollbarFaceColor,
|
||||
NS_THEME_SCROLLBARTHUMB_VERTICAL);
|
||||
return val.forget();
|
||||
}
|
||||
|
||||
already_AddRefed<CSSValue>
|
||||
nsComputedDOMStyle::DoGetScrollbarTrackColor()
|
||||
{
|
||||
RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
|
||||
SetValueForWidgetColor(val, StyleUserInterface()->mScrollbarTrackColor,
|
||||
NS_THEME_SCROLLBAR_VERTICAL);
|
||||
return val.forget();
|
||||
}
|
||||
|
||||
already_AddRefed<CSSValue>
|
||||
nsComputedDOMStyle::DoGetOutlineWidth()
|
||||
{
|
||||
|
@ -509,6 +509,8 @@ private:
|
||||
already_AddRefed<CSSValue> DoGetScrollSnapPointsY();
|
||||
already_AddRefed<CSSValue> DoGetScrollSnapDestination();
|
||||
already_AddRefed<CSSValue> DoGetScrollSnapCoordinate();
|
||||
already_AddRefed<CSSValue> DoGetScrollbarFaceColor();
|
||||
already_AddRefed<CSSValue> DoGetScrollbarTrackColor();
|
||||
already_AddRefed<CSSValue> DoGetShapeImageThreshold();
|
||||
already_AddRefed<CSSValue> DoGetShapeMargin();
|
||||
already_AddRefed<CSSValue> DoGetShapeOutside();
|
||||
@ -621,6 +623,9 @@ private:
|
||||
void SetToRGBAColor(nsROCSSPrimitiveValue* aValue, nscolor aColor);
|
||||
void SetValueFromComplexColor(nsROCSSPrimitiveValue* aValue,
|
||||
const mozilla::StyleComplexColor& aColor);
|
||||
void SetValueForWidgetColor(nsROCSSPrimitiveValue* aValue,
|
||||
const mozilla::StyleComplexColor& aColor,
|
||||
uint8_t aWidgetType);
|
||||
void SetValueToStyleImage(const nsStyleImage& aStyleImage,
|
||||
nsROCSSPrimitiveValue* aValue);
|
||||
void SetValueToPositionCoord(const mozilla::Position::Coord& aCoord,
|
||||
|
@ -233,6 +233,8 @@ 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_face_color, ScrollbarFaceColor)
|
||||
COMPUTED_STYLE_PROP(scrollbar_track_color, ScrollbarTrackColor)
|
||||
COMPUTED_STYLE_PROP(shape_image_threshold, ShapeImageThreshold)
|
||||
COMPUTED_STYLE_PROP(shape_margin, ShapeMargin)
|
||||
COMPUTED_STYLE_PROP(shape_outside, ShapeOutside)
|
||||
|
@ -4619,6 +4619,8 @@ nsStyleUserInterface::nsStyleUserInterface(const nsPresContext* aContext)
|
||||
, mPointerEvents(NS_STYLE_POINTER_EVENTS_AUTO)
|
||||
, mCursor(NS_STYLE_CURSOR_AUTO)
|
||||
, mCaretColor(StyleComplexColor::Auto())
|
||||
, mScrollbarFaceColor(StyleComplexColor::Auto())
|
||||
, mScrollbarTrackColor(StyleComplexColor::Auto())
|
||||
{
|
||||
MOZ_COUNT_CTOR(nsStyleUserInterface);
|
||||
}
|
||||
@ -4631,6 +4633,8 @@ nsStyleUserInterface::nsStyleUserInterface(const nsStyleUserInterface& aSource)
|
||||
, mCursor(aSource.mCursor)
|
||||
, mCursorImages(aSource.mCursorImages)
|
||||
, mCaretColor(aSource.mCaretColor)
|
||||
, mScrollbarFaceColor(aSource.mScrollbarFaceColor)
|
||||
, mScrollbarTrackColor(aSource.mScrollbarTrackColor)
|
||||
{
|
||||
MOZ_COUNT_CTOR(nsStyleUserInterface);
|
||||
}
|
||||
@ -4699,7 +4703,9 @@ nsStyleUserInterface::CalcDifference(const nsStyleUserInterface& aNewData) const
|
||||
hint |= nsChangeHint_NeutralChange;
|
||||
}
|
||||
|
||||
if (mCaretColor != aNewData.mCaretColor) {
|
||||
if (mCaretColor != aNewData.mCaretColor ||
|
||||
mScrollbarFaceColor != aNewData.mScrollbarFaceColor ||
|
||||
mScrollbarTrackColor != aNewData.mScrollbarTrackColor) {
|
||||
hint |= nsChangeHint_RepaintFrame;
|
||||
}
|
||||
|
||||
|
@ -2893,7 +2893,15 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleUserInterface
|
||||
nsTArray<nsCursorImage> mCursorImages; // [inherited] images and coords
|
||||
mozilla::StyleComplexColor mCaretColor; // [inherited]
|
||||
|
||||
mozilla::StyleComplexColor mScrollbarFaceColor; // [inherited]
|
||||
mozilla::StyleComplexColor mScrollbarTrackColor; // [inherited]
|
||||
|
||||
inline uint8_t GetEffectivePointerEvents(nsIFrame* aFrame) const;
|
||||
|
||||
bool HasCustomScrollbars() const
|
||||
{
|
||||
return !mScrollbarFaceColor.mIsAuto || !mScrollbarTrackColor.mIsAuto;
|
||||
}
|
||||
};
|
||||
|
||||
struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleXUL
|
||||
|
@ -8363,3 +8363,22 @@ if (IsCSSPropertyPrefEnabled("layout.css.unset-value.enabled")) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (IsCSSPropertyPrefEnabled("layout.css.scrollbar-colors.enabled")) {
|
||||
gCSSProperties["scrollbar-face-color"] = {
|
||||
domProp: "scrollbarFaceColor",
|
||||
inherited: true,
|
||||
type: CSS_TYPE_LONGHAND,
|
||||
initial_values: [ "auto" ],
|
||||
other_values: [ "red", "blue", "#ffff00" ],
|
||||
invalid_values: [ "ffff00" ]
|
||||
};
|
||||
gCSSProperties["scrollbar-track-color"] = {
|
||||
domProp: "scrollbarTrackColor",
|
||||
inherited: true,
|
||||
type: CSS_TYPE_LONGHAND,
|
||||
initial_values: [ "auto" ],
|
||||
other_values: [ "red", "blue", "#ffff00" ],
|
||||
invalid_values: [ "ffff00" ]
|
||||
};
|
||||
}
|
||||
|
@ -324,6 +324,19 @@ if (IsCSSPropertyPrefEnabled("layout.css.individual-transform.enabled") &&
|
||||
supported_properties["translate"] = [ test_translate_transition ];
|
||||
}
|
||||
|
||||
if (IsCSSPropertyPrefEnabled("layout.css.scrollbar-colors.enabled")) {
|
||||
supported_properties["scrollbar-face-color"] = [
|
||||
test_color_transition,
|
||||
test_true_currentcolor_transition,
|
||||
test_auto_color_transition,
|
||||
];
|
||||
supported_properties["scrollbar-track-color"] = [
|
||||
test_color_transition,
|
||||
test_true_currentcolor_transition,
|
||||
test_auto_color_transition,
|
||||
];
|
||||
}
|
||||
|
||||
var div = document.getElementById("display");
|
||||
var OMTAdiv = document.getElementById("transformTest");
|
||||
var cs = getComputedStyle(div, "");
|
||||
|
@ -2846,6 +2846,9 @@ pref("layout.css.isolation.enabled", true);
|
||||
// Is support for CSS Filters enabled?
|
||||
pref("layout.css.filters.enabled", true);
|
||||
|
||||
// Is support for CSS Scrollbar color properties enabled?
|
||||
pref("layout.css.scrollbar-colors.enabled", false);
|
||||
|
||||
// Set the threshold distance in CSS pixels below which scrolling will snap to
|
||||
// an edge, when scroll snapping is set to "proximity".
|
||||
pref("layout.css.scroll-snap.proximity-threshold", 200);
|
||||
|
@ -1436,6 +1436,7 @@ impl Clone for ${style_struct.gecko_struct_name} {
|
||||
# Types used with predefined_type()-defined properties that we can auto-generate.
|
||||
predefined_types = {
|
||||
"Color": impl_color,
|
||||
"ColorOrAuto": impl_color,
|
||||
"GreaterThanOrEqualToOneNumber": impl_simple,
|
||||
"Integer": impl_simple,
|
||||
"length::LengthOrAuto": impl_style_coord,
|
||||
@ -5305,7 +5306,7 @@ clip-path
|
||||
</%self:impl_trait>
|
||||
|
||||
<%self:impl_trait style_struct_name="InheritedUI"
|
||||
skip_longhands="cursor caret-color">
|
||||
skip_longhands="cursor">
|
||||
pub fn set_cursor(&mut self, v: longhands::cursor::computed_value::T) {
|
||||
use style_traits::cursor::CursorKind;
|
||||
|
||||
@ -5451,8 +5452,6 @@ clip-path
|
||||
|
||||
longhands::cursor::computed_value::T { images, keyword }
|
||||
}
|
||||
|
||||
<%call expr="impl_color('caret_color', 'mCaretColor')"></%call>
|
||||
</%self:impl_trait>
|
||||
|
||||
<%self:impl_trait style_struct_name="Column"
|
||||
|
@ -50,3 +50,25 @@ ${helpers.predefined_type(
|
||||
ignored_when_colors_disabled=True,
|
||||
products="gecko",
|
||||
)}
|
||||
|
||||
// Only scrollbar-face-color and scrollbar-track-color are added here.
|
||||
// These two are the only common parts of scrollbar among Windows and
|
||||
// macOS. We may or may not want to provide other properties to allow
|
||||
// finer-grain control.
|
||||
//
|
||||
// NOTE The syntax in spec is currently `normal | <color>`, but I think
|
||||
// reusing `auto | <color>` as `caret-color` makes more sense. See
|
||||
// https://github.com/w3c/csswg-drafts/issues/2660
|
||||
% for part in ["face", "track"]:
|
||||
${helpers.predefined_type(
|
||||
"scrollbar-%s-color" % part,
|
||||
"ColorOrAuto",
|
||||
"Either::Second(Auto)",
|
||||
spec="https://drafts.csswg.org/css-scrollbars-1/#scrollbar-color-properties",
|
||||
gecko_pref="layout.css.scrollbar-colors.enabled",
|
||||
animation_value_type="ColorOrAuto",
|
||||
ignored_when_colors_disabled=True,
|
||||
enabled_in="chrome",
|
||||
products="gecko",
|
||||
)}
|
||||
% endfor
|
||||
|
Loading…
Reference in New Issue
Block a user