Bug 1063162 part 2 - Implement caret-color property. r=dholbert

MozReview-Commit-ID: DH7CX1d477R

--HG--
extra : rebase_source : 29c57f59a3073a05beed1c4160e2fd74d3e29617
This commit is contained in:
Xidorn Quan 2016-12-22 11:04:15 +11:00
Родитель 51c845d50b
Коммит 262d2eb93a
16 изменённых файлов: 117 добавлений и 2 удалений

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

@ -2857,6 +2857,7 @@ exports.CSS_PROPERTIES = {
"box-shadow", "box-shadow",
"box-sizing", "box-sizing",
"caption-side", "caption-side",
"caret-color",
"clear", "clear",
"clip", "clip",
"clip-path", "clip-path",
@ -5261,6 +5262,28 @@ exports.CSS_PROPERTIES = {
"unset" "unset"
] ]
}, },
"caret-color": {
"isInherited": true,
"subproperties": [
"caret-color"
],
"supports": [
2
],
"values": [
"COLOR",
"auto",
"currentColor",
"hsl",
"hsla",
"inherit",
"initial",
"rgb",
"rgba",
"transparent",
"unset"
]
},
"clear": { "clear": {
"isInherited": false, "isInherited": false,
"subproperties": [ "subproperties": [

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

@ -1882,8 +1882,7 @@ nsIFrame::DisplayCaret(nsDisplayListBuilder* aBuilder,
nscolor nscolor
nsIFrame::GetCaretColorAt(int32_t aOffset) nsIFrame::GetCaretColorAt(int32_t aOffset)
{ {
// Use text color. return StyleColor()->CalcComplexColor(StyleUserInterface()->mCaretColor);
return StyleColor()->mColor;
} }
bool bool

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

@ -0,0 +1,18 @@
<!DOCTYPE html>
<style>
@font-face {
font-family: Ahem;
src: url(../fonts/Ahem.ttf);
}
div {
font: 16px/1 Ahem;
width: 1em;
background: green;
}
</style>
<div><span></span></div>
<script>
let $div = document.querySelector('div');
let $span = document.querySelector('span');
$div.style.height = $span.getBoundingClientRect().height + 'px';
</script>

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

@ -0,0 +1,17 @@
<!DOCTYPE html>
<style>
@font-face {
font-family: Ahem;
src: url(../fonts/Ahem.ttf);
}
textarea {
caret-color: green;
font: 16px/1 Ahem;
outline: none;
border: 0 none;
resize: none;
padding: 0;
margin: 0;
}
</style>
<textarea autofocus></textarea>

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

@ -0,0 +1 @@
pref(ui.caretWidth,16) needs-focus == caret-color-01.html caret-color-01-ref.html

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

@ -130,6 +130,9 @@ include css-sizing/reftest.list
# css transitions # css transitions
include css-transitions/reftest.list include css-transitions/reftest.list
# css ui
include css-ui/reftest.list
# css :-moz-ui-invalid # css :-moz-ui-invalid
include css-ui-invalid/reftest.list include css-ui-invalid/reftest.list

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

@ -1381,6 +1381,17 @@ CSS_PROP_TABLEBORDER(
kCaptionSideKTable, kCaptionSideKTable,
CSS_PROP_NO_OFFSET, CSS_PROP_NO_OFFSET,
eStyleAnimType_Discrete) eStyleAnimType_Discrete)
CSS_PROP_USERINTERFACE(
caret-color,
caret_color,
CaretColor,
CSS_PROPERTY_PARSE_VALUE |
CSS_PROPERTY_IGNORED_WHEN_COLORS_DISABLED,
"",
VARIANT_AUTO | VARIANT_HC,
nullptr,
offsetof(nsStyleUserInterface, mCaretColor),
eStyleAnimType_ComplexColor)
CSS_PROP_DISPLAY( CSS_PROP_DISPLAY(
clear, clear,
clear, clear,

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

@ -4143,6 +4143,14 @@ nsComputedDOMStyle::DoGetUnicodeBidi()
return val.forget(); return val.forget();
} }
already_AddRefed<CSSValue>
nsComputedDOMStyle::DoGetCaretColor()
{
RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
SetValueFromComplexColor(val, StyleUserInterface()->mCaretColor);
return val.forget();
}
already_AddRefed<CSSValue> already_AddRefed<CSSValue>
nsComputedDOMStyle::DoGetCursor() nsComputedDOMStyle::DoGetCursor()
{ {

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

@ -482,6 +482,7 @@ private:
already_AddRefed<CSSValue> DoGetShapeOutside(); already_AddRefed<CSSValue> DoGetShapeOutside();
/* User interface properties */ /* User interface properties */
already_AddRefed<CSSValue> DoGetCaretColor();
already_AddRefed<CSSValue> DoGetCursor(); already_AddRefed<CSSValue> DoGetCursor();
already_AddRefed<CSSValue> DoGetForceBrokenImageIcon(); already_AddRefed<CSSValue> DoGetForceBrokenImageIcon();
already_AddRefed<CSSValue> DoGetIMEMode(); already_AddRefed<CSSValue> DoGetIMEMode();

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

@ -101,6 +101,7 @@ COMPUTED_STYLE_PROP(box_decoration_break, BoxDecorationBreak)
COMPUTED_STYLE_PROP(box_shadow, BoxShadow) COMPUTED_STYLE_PROP(box_shadow, BoxShadow)
COMPUTED_STYLE_PROP(box_sizing, BoxSizing) COMPUTED_STYLE_PROP(box_sizing, BoxSizing)
COMPUTED_STYLE_PROP(caption_side, CaptionSide) COMPUTED_STYLE_PROP(caption_side, CaptionSide)
COMPUTED_STYLE_PROP(caret_color, CaretColor)
COMPUTED_STYLE_PROP(clear, Clear) COMPUTED_STYLE_PROP(clear, Clear)
COMPUTED_STYLE_PROP(clip, Clip) COMPUTED_STYLE_PROP(clip, Clip)
COMPUTED_STYLE_PROP(color, Color) COMPUTED_STYLE_PROP(color, Color)

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

@ -1142,6 +1142,8 @@ SetComplexColor(const nsCSSValue& aValue,
aResult = StyleComplexColor::CurrentColor(); aResult = StyleComplexColor::CurrentColor();
} else if (unit == eCSSUnit_ComplexColor) { } else if (unit == eCSSUnit_ComplexColor) {
aResult = aValue.GetStyleComplexColorValue(); aResult = aValue.GetStyleComplexColorValue();
} else if (unit == eCSSUnit_Auto) {
aResult = StyleComplexColor::Auto();
} else { } else {
nscolor resultColor; nscolor resultColor;
if (!SetColor(aValue, aParentColor.mColor, aPresContext, if (!SetColor(aValue, aParentColor.mColor, aPresContext,
@ -5294,6 +5296,14 @@ nsRuleNode::ComputeUserInterfaceData(void* aStartStruct,
parentUI->mPointerEvents, parentUI->mPointerEvents,
NS_STYLE_POINTER_EVENTS_AUTO); NS_STYLE_POINTER_EVENTS_AUTO);
// caret-color: auto, color, inherit
const nsCSSValue* caretColorValue = aRuleData->ValueForCaretColor();
SetComplexColor<eUnsetInherit>(*caretColorValue,
parentUI->mCaretColor,
StyleComplexColor::Auto(),
mPresContext,
ui->mCaretColor, conditions);
COMPUTE_END_INHERITED(UserInterface, ui) COMPUTE_END_INHERITED(UserInterface, ui)
} }

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

@ -3974,6 +3974,7 @@ nsStyleUserInterface::nsStyleUserInterface(StyleStructContext aContext)
, mUserFocus(StyleUserFocus::None) , mUserFocus(StyleUserFocus::None)
, mPointerEvents(NS_STYLE_POINTER_EVENTS_AUTO) , mPointerEvents(NS_STYLE_POINTER_EVENTS_AUTO)
, mCursor(NS_STYLE_CURSOR_AUTO) , mCursor(NS_STYLE_CURSOR_AUTO)
, mCaretColor(StyleComplexColor::Auto())
{ {
MOZ_COUNT_CTOR(nsStyleUserInterface); MOZ_COUNT_CTOR(nsStyleUserInterface);
} }
@ -3985,6 +3986,7 @@ nsStyleUserInterface::nsStyleUserInterface(const nsStyleUserInterface& aSource)
, mPointerEvents(aSource.mPointerEvents) , mPointerEvents(aSource.mPointerEvents)
, mCursor(aSource.mCursor) , mCursor(aSource.mCursor)
, mCursorImages(aSource.mCursorImages) , mCursorImages(aSource.mCursorImages)
, mCaretColor(aSource.mCaretColor)
{ {
MOZ_COUNT_CTOR(nsStyleUserInterface); MOZ_COUNT_CTOR(nsStyleUserInterface);
} }
@ -4046,6 +4048,10 @@ nsStyleUserInterface::CalcDifference(const nsStyleUserInterface& aNewData) const
hint |= nsChangeHint_NeutralChange; hint |= nsChangeHint_NeutralChange;
} }
if (mCaretColor != aNewData.mCaretColor) {
hint |= nsChangeHint_RepaintFrame;
}
return hint; return hint;
} }

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

@ -3400,6 +3400,7 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleUserInterface
uint8_t mCursor; // [inherited] See nsStyleConsts.h uint8_t mCursor; // [inherited] See nsStyleConsts.h
nsTArray<nsCursorImage> mCursorImages; // [inherited] images and coords nsTArray<nsCursorImage> mCursorImages; // [inherited] images and coords
mozilla::StyleComplexColor mCaretColor; // [inherited]
inline uint8_t GetEffectivePointerEvents(nsIFrame* aFrame) const; inline uint8_t GetEffectivePointerEvents(nsIFrame* aFrame) const;
}; };

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

@ -2836,6 +2836,18 @@ var gCSSProperties = {
other_values: [ "bottom", "left", "right", "top-outside", "bottom-outside" ], other_values: [ "bottom", "left", "right", "top-outside", "bottom-outside" ],
invalid_values: [] invalid_values: []
}, },
"caret-color": {
domProp: "caretColor",
inherited: true,
type: CSS_TYPE_LONGHAND,
prerequisites: { "color": "black" },
// Though "auto" is an independent computed-value time keyword value,
// it is not distinguishable from currentcolor because getComputedStyle
// always returns used value for <color>.
initial_values: [ "auto", "currentcolor", "black", "rgb(0,0,0)" ],
other_values: [ "green", "transparent", "rgba(128,128,128,.5)", "#123" ],
invalid_values: [ "#0", "#00", "#00000", "cc00ff" ]
},
"clear": { "clear": {
domProp: "clear", domProp: "clear",
inherited: false, inherited: false,

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

@ -129,6 +129,9 @@ var supported_properties = {
"bottom": [ test_length_transition, test_percent_transition, "bottom": [ test_length_transition, test_percent_transition,
test_length_percent_calc_transition, test_length_percent_calc_transition,
test_length_unclamped, test_percent_unclamped ], test_length_unclamped, test_percent_unclamped ],
"caret-color": [ test_color_transition,
test_true_currentcolor_transition,
test_auto_color_transition ],
"clip": [ test_rect_transition ], "clip": [ test_rect_transition ],
"clip-path": [ test_clip_path_transition ], "clip-path": [ test_clip_path_transition ],
"color": [ test_color_transition, "color": [ test_color_transition,

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

@ -8,6 +8,7 @@ user_pref("gfx.color_management.force_srgb", true);
user_pref("gfx.logging.level", 1); user_pref("gfx.logging.level", 1);
user_pref("browser.dom.window.dump.enabled", true); user_pref("browser.dom.window.dump.enabled", true);
user_pref("ui.caretBlinkTime", -1); user_pref("ui.caretBlinkTime", -1);
user_pref("ui.caretWidth", 1);
user_pref("dom.send_after_paint_to_content", true); user_pref("dom.send_after_paint_to_content", true);
// no slow script dialogs // no slow script dialogs
user_pref("dom.max_script_run_time", 0); user_pref("dom.max_script_run_time", 0);