Commit 0cc01e57 authored by Alex Keng's avatar Alex Keng Committed by Commit Bot

EditContext: add underlineThickness and textColor to TextFormatUpdate event


When TextFormatUpdate event was first introduced [1], ImeTextSpan was
incomplete and we had to map underline thickness to underline style
(which was incorrect). Now we have an updated ImeTextSpan [2], we can
introduce new attributes, textColor and underlineThickness and
correctly return the format info.

Note textUnderlineStyle is renamed to underlineStyle for clarity, and
textDecorationColor is renamed to suggestionHighlightColor since the
value is mapped from ui::ImeTextSpan::suggestion_highlight_color

[1] https://chromium-review.googlesource.com/c/chromium/src/+/1864318
[2] https://source.chromium.org/chromium/chromium/src/+/master:ui/base/ime/ime_text_span.h;l=18;dlc=65548a4764183b6d99b89678d592d49fe3038da5;bpv=1;bpt=0;drc=59cb62c60b608c5aba49542cd59ea95742f2f305

Change-Id: Ib0169931cad2c153565039370ab89b3d8d0b8d9e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2425430
Commit-Queue: Alex Keng <shihken@microsoft.com>
Reviewed-by: default avatarKent Tamura <tkent@chromium.org>
Reviewed-by: default avatarAnupam Snigdha <snianu@microsoft.com>
Reviewed-by: default avatarYoshifumi Inoue <yosin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#810491}
parent 90e2b6c0
......@@ -126,6 +126,7 @@ void EditContext::DispatchTextFormatEvent(
// TODO(snianu): Try to accumulate the ranges with similar formats and fire
// one event.
DCHECK(has_composition_);
String underline_thickness;
String underline_style;
for (const auto& ime_text_span : ime_text_spans) {
const int format_range_start =
......@@ -135,17 +136,31 @@ void EditContext::DispatchTextFormatEvent(
switch (ime_text_span.thickness) {
case ui::ImeTextSpan::Thickness::kNone:
underline_style = "None";
underline_thickness = "None";
break;
case ui::ImeTextSpan::Thickness::kThin:
underline_style = "Thin";
underline_thickness = "Thin";
break;
case ui::ImeTextSpan::Thickness::kThick:
underline_style = "Thick";
underline_thickness = "Thick";
break;
default:
}
switch (ime_text_span.underline_style) {
case ui::ImeTextSpan::UnderlineStyle::kNone:
underline_style = "None";
break;
case ui::ImeTextSpan::UnderlineStyle::kSolid:
underline_style = "Solid";
break;
case ui::ImeTextSpan::UnderlineStyle::kDot:
underline_style = "Dotted";
break;
case ui::ImeTextSpan::UnderlineStyle::kDash:
underline_style = "Dashed";
break;
case ui::ImeTextSpan::UnderlineStyle::kSquiggle:
underline_style = "Squiggle";
break;
}
TextFormatUpdateEvent* event = MakeGarbageCollected<TextFormatUpdateEvent>(
format_range_start, format_range_end,
......@@ -155,7 +170,9 @@ void EditContext::DispatchTextFormatEvent(
ime_text_span.background_color),
cssvalue::CSSColorValue::SerializeAsCSSComponentValue(
ime_text_span.suggestion_highlight_color),
underline_style);
cssvalue::CSSColorValue::SerializeAsCSSComponentValue(
ime_text_span.text_color),
underline_thickness, underline_style);
DispatchEvent(*event);
}
}
......
......@@ -24,11 +24,17 @@ TextFormatUpdateEvent::TextFormatUpdateEvent(
if (dict->hasBackgroundColor())
background_color_ = dict->backgroundColor();
if (dict->hasTextDecorationColor())
text_decoration_color_ = dict->textDecorationColor();
if (dict->hasSuggestionHighlightColor())
suggestion_highlight_color_ = dict->suggestionHighlightColor();
if (dict->hasTextUnderlineStyle())
text_underline_style_ = dict->textUnderlineStyle();
if (dict->hasTextColor())
text_color_ = dict->textColor();
if (dict->hasUnderlineThickness())
underline_thickness_ = dict->underlineThickness();
if (dict->hasUnderlineStyle())
underline_style_ = dict->underlineStyle();
}
TextFormatUpdateEvent::TextFormatUpdateEvent(
......@@ -36,8 +42,10 @@ TextFormatUpdateEvent::TextFormatUpdateEvent(
uint32_t format_range_end,
const String& underline_color,
const String& background_color,
const String& text_decoration_color,
const String& text_underline_style)
const String& suggestion_highlight_color,
const String& text_color,
const String& underline_thickness,
const String& underline_style)
: Event(event_type_names::kTextformatupdate,
Bubbles::kNo,
Cancelable::kYes,
......@@ -47,8 +55,10 @@ TextFormatUpdateEvent::TextFormatUpdateEvent(
format_range_end_(format_range_end),
underline_color_(underline_color),
background_color_(background_color),
text_decoration_color_(text_decoration_color),
text_underline_style_(text_underline_style) {}
suggestion_highlight_color_(suggestion_highlight_color),
text_color_(text_color),
underline_thickness_(underline_thickness),
underline_style_(underline_style) {}
TextFormatUpdateEvent* TextFormatUpdateEvent::Create(
const TextFormatUpdateEventInit* dict) {
......@@ -73,12 +83,20 @@ String TextFormatUpdateEvent::backgroundColor() const {
return background_color_;
}
String TextFormatUpdateEvent::textDecorationColor() const {
return text_decoration_color_;
String TextFormatUpdateEvent::suggestionHighlightColor() const {
return suggestion_highlight_color_;
}
String TextFormatUpdateEvent::textColor() const {
return text_color_;
}
String TextFormatUpdateEvent::underlineThickness() const {
return underline_thickness_;
}
String TextFormatUpdateEvent::textUnderlineStyle() const {
return text_underline_style_;
String TextFormatUpdateEvent::underlineStyle() const {
return underline_style_;
}
const AtomicString& TextFormatUpdateEvent::InterfaceName() const {
......
......@@ -33,7 +33,9 @@ class CORE_EXPORT TextFormatUpdateEvent final : public Event {
const String& underline_color,
const String& background_color,
const String& text_decoration_color,
const String& text_underline_style);
const String& text_color,
const String& underline_thickness,
const String& underline_style);
static TextFormatUpdateEvent* Create(const TextFormatUpdateEventInit* dict);
~TextFormatUpdateEvent() override;
......@@ -41,8 +43,10 @@ class CORE_EXPORT TextFormatUpdateEvent final : public Event {
uint32_t formatRangeEnd() const;
String underlineColor() const;
String backgroundColor() const;
String textDecorationColor() const;
String textUnderlineStyle() const;
String suggestionHighlightColor() const;
String textColor() const;
String underlineThickness() const;
String underlineStyle() const;
const AtomicString& InterfaceName() const override;
// member variables to keep track of the event parameters
......@@ -51,8 +55,10 @@ class CORE_EXPORT TextFormatUpdateEvent final : public Event {
uint32_t format_range_end_ = 0;
String underline_color_;
String background_color_;
String text_decoration_color_;
String text_underline_style_;
String suggestion_highlight_color_;
String text_color_;
String underline_thickness_;
String underline_style_;
};
} // namespace blink
......
......@@ -16,6 +16,8 @@
readonly attribute unsigned long formatRangeEnd;
readonly attribute DOMString underlineColor;
readonly attribute DOMString backgroundColor;
readonly attribute DOMString textDecorationColor;
readonly attribute DOMString textUnderlineStyle;
readonly attribute DOMString suggestionHighlightColor;
readonly attribute DOMString textColor;
readonly attribute DOMString underlineThickness;
readonly attribute DOMString underlineStyle;
};
......@@ -7,6 +7,8 @@ dictionary TextFormatUpdateEventInit {
unsigned long formatRangeEnd;
DOMString underlineColor;
DOMString backgroundColor;
DOMString textDecorationColor;
DOMString textUnderlineStyle;
DOMString suggestionHighlightColor;
DOMString textColor;
DOMString underlineThickness;
DOMString underlineStyle;
};
......@@ -75,10 +75,12 @@ test(function() {
test.innerHTML = "";
let formatRangeStart = 0;
let formatRangeEnd = 0;
let underlineTextColor = "";
let backgroundTextColor = "";
let compositionTextDecorationColor = "";
let underlineColor = "";
let backgroundColor = "";
let textColor = "";
let suggestionHighlightColor = "";
let compositionTextUnderlineStyle = "";
let compositionTextUnderlineThickness = "";
// Add EditContext event listeners
editContext.addEventListener("textupdate", e => {
// Update the text in the div
......@@ -91,8 +93,10 @@ test(function() {
formatRangeEnd = e.formatRangeEnd;
underlineColor = e.underlineColor;
backgroundColor = e.backgroundColor;
compositionTextDecorationColor = e.textDecorationColor;
compositionTextUnderlineStyle = e.textUnderlineStyle;
textColor = e.textColor;
suggestionHighlightColor = e.suggestionHighlightColor;
compositionTextUnderlineStyle = e.underlineStyle;
compositionTextUnderlineThickness = e.underlineThickness;
});
test.focus();
......@@ -103,8 +107,10 @@ test(function() {
assert_equals(formatRangeEnd, 3);
assert_equals(underlineColor, "rgba(0, 0, 0, 0)");
assert_equals(backgroundColor, "rgba(0, 0, 0, 0)");
assert_equals(compositionTextDecorationColor, "rgba(0, 0, 0, 0)");
assert_equals(compositionTextUnderlineStyle, "Thin");
assert_equals(textColor, "rgba(0, 0, 0, 0)");
assert_equals(suggestionHighlightColor, "rgba(0, 0, 0, 0)");
assert_equals(compositionTextUnderlineStyle, "Solid");
assert_equals(compositionTextUnderlineThickness, "Thin");
}, 'Testing EditContext TextFormatUpdate');
test(function() {
......
......@@ -8397,9 +8397,11 @@ interface TextFormatUpdateEvent : Event
getter backgroundColor
getter formatRangeEnd
getter formatRangeStart
getter textDecorationColor
getter textUnderlineStyle
getter suggestionHighlightColor
getter textColor
getter underlineColor
getter underlineStyle
getter underlineThickness
method constructor
interface TextMetrics
attribute @@toStringTag
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment