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( ...@@ -126,6 +126,7 @@ void EditContext::DispatchTextFormatEvent(
// TODO(snianu): Try to accumulate the ranges with similar formats and fire // TODO(snianu): Try to accumulate the ranges with similar formats and fire
// one event. // one event.
DCHECK(has_composition_); DCHECK(has_composition_);
String underline_thickness;
String underline_style; String underline_style;
for (const auto& ime_text_span : ime_text_spans) { for (const auto& ime_text_span : ime_text_spans) {
const int format_range_start = const int format_range_start =
...@@ -135,17 +136,31 @@ void EditContext::DispatchTextFormatEvent( ...@@ -135,17 +136,31 @@ void EditContext::DispatchTextFormatEvent(
switch (ime_text_span.thickness) { switch (ime_text_span.thickness) {
case ui::ImeTextSpan::Thickness::kNone: case ui::ImeTextSpan::Thickness::kNone:
underline_style = "None"; underline_thickness = "None";
break; break;
case ui::ImeTextSpan::Thickness::kThin: case ui::ImeTextSpan::Thickness::kThin:
underline_style = "Thin"; underline_thickness = "Thin";
break; break;
case ui::ImeTextSpan::Thickness::kThick: case ui::ImeTextSpan::Thickness::kThick:
underline_style = "Thick"; underline_thickness = "Thick";
break; break;
default: }
switch (ime_text_span.underline_style) {
case ui::ImeTextSpan::UnderlineStyle::kNone:
underline_style = "None"; underline_style = "None";
break; 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>( TextFormatUpdateEvent* event = MakeGarbageCollected<TextFormatUpdateEvent>(
format_range_start, format_range_end, format_range_start, format_range_end,
...@@ -155,7 +170,9 @@ void EditContext::DispatchTextFormatEvent( ...@@ -155,7 +170,9 @@ void EditContext::DispatchTextFormatEvent(
ime_text_span.background_color), ime_text_span.background_color),
cssvalue::CSSColorValue::SerializeAsCSSComponentValue( cssvalue::CSSColorValue::SerializeAsCSSComponentValue(
ime_text_span.suggestion_highlight_color), ime_text_span.suggestion_highlight_color),
underline_style); cssvalue::CSSColorValue::SerializeAsCSSComponentValue(
ime_text_span.text_color),
underline_thickness, underline_style);
DispatchEvent(*event); DispatchEvent(*event);
} }
} }
......
...@@ -24,11 +24,17 @@ TextFormatUpdateEvent::TextFormatUpdateEvent( ...@@ -24,11 +24,17 @@ TextFormatUpdateEvent::TextFormatUpdateEvent(
if (dict->hasBackgroundColor()) if (dict->hasBackgroundColor())
background_color_ = dict->backgroundColor(); background_color_ = dict->backgroundColor();
if (dict->hasTextDecorationColor()) if (dict->hasSuggestionHighlightColor())
text_decoration_color_ = dict->textDecorationColor(); suggestion_highlight_color_ = dict->suggestionHighlightColor();
if (dict->hasTextUnderlineStyle()) if (dict->hasTextColor())
text_underline_style_ = dict->textUnderlineStyle(); text_color_ = dict->textColor();
if (dict->hasUnderlineThickness())
underline_thickness_ = dict->underlineThickness();
if (dict->hasUnderlineStyle())
underline_style_ = dict->underlineStyle();
} }
TextFormatUpdateEvent::TextFormatUpdateEvent( TextFormatUpdateEvent::TextFormatUpdateEvent(
...@@ -36,8 +42,10 @@ TextFormatUpdateEvent::TextFormatUpdateEvent( ...@@ -36,8 +42,10 @@ TextFormatUpdateEvent::TextFormatUpdateEvent(
uint32_t format_range_end, uint32_t format_range_end,
const String& underline_color, const String& underline_color,
const String& background_color, const String& background_color,
const String& text_decoration_color, const String& suggestion_highlight_color,
const String& text_underline_style) const String& text_color,
const String& underline_thickness,
const String& underline_style)
: Event(event_type_names::kTextformatupdate, : Event(event_type_names::kTextformatupdate,
Bubbles::kNo, Bubbles::kNo,
Cancelable::kYes, Cancelable::kYes,
...@@ -47,8 +55,10 @@ TextFormatUpdateEvent::TextFormatUpdateEvent( ...@@ -47,8 +55,10 @@ TextFormatUpdateEvent::TextFormatUpdateEvent(
format_range_end_(format_range_end), format_range_end_(format_range_end),
underline_color_(underline_color), underline_color_(underline_color),
background_color_(background_color), background_color_(background_color),
text_decoration_color_(text_decoration_color), suggestion_highlight_color_(suggestion_highlight_color),
text_underline_style_(text_underline_style) {} text_color_(text_color),
underline_thickness_(underline_thickness),
underline_style_(underline_style) {}
TextFormatUpdateEvent* TextFormatUpdateEvent::Create( TextFormatUpdateEvent* TextFormatUpdateEvent::Create(
const TextFormatUpdateEventInit* dict) { const TextFormatUpdateEventInit* dict) {
...@@ -73,12 +83,20 @@ String TextFormatUpdateEvent::backgroundColor() const { ...@@ -73,12 +83,20 @@ String TextFormatUpdateEvent::backgroundColor() const {
return background_color_; return background_color_;
} }
String TextFormatUpdateEvent::textDecorationColor() const { String TextFormatUpdateEvent::suggestionHighlightColor() const {
return text_decoration_color_; return suggestion_highlight_color_;
}
String TextFormatUpdateEvent::textColor() const {
return text_color_;
}
String TextFormatUpdateEvent::underlineThickness() const {
return underline_thickness_;
} }
String TextFormatUpdateEvent::textUnderlineStyle() const { String TextFormatUpdateEvent::underlineStyle() const {
return text_underline_style_; return underline_style_;
} }
const AtomicString& TextFormatUpdateEvent::InterfaceName() const { const AtomicString& TextFormatUpdateEvent::InterfaceName() const {
......
...@@ -33,7 +33,9 @@ class CORE_EXPORT TextFormatUpdateEvent final : public Event { ...@@ -33,7 +33,9 @@ class CORE_EXPORT TextFormatUpdateEvent final : public Event {
const String& underline_color, const String& underline_color,
const String& background_color, const String& background_color,
const String& text_decoration_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); static TextFormatUpdateEvent* Create(const TextFormatUpdateEventInit* dict);
~TextFormatUpdateEvent() override; ~TextFormatUpdateEvent() override;
...@@ -41,8 +43,10 @@ class CORE_EXPORT TextFormatUpdateEvent final : public Event { ...@@ -41,8 +43,10 @@ class CORE_EXPORT TextFormatUpdateEvent final : public Event {
uint32_t formatRangeEnd() const; uint32_t formatRangeEnd() const;
String underlineColor() const; String underlineColor() const;
String backgroundColor() const; String backgroundColor() const;
String textDecorationColor() const; String suggestionHighlightColor() const;
String textUnderlineStyle() const; String textColor() const;
String underlineThickness() const;
String underlineStyle() const;
const AtomicString& InterfaceName() const override; const AtomicString& InterfaceName() const override;
// member variables to keep track of the event parameters // member variables to keep track of the event parameters
...@@ -51,8 +55,10 @@ class CORE_EXPORT TextFormatUpdateEvent final : public Event { ...@@ -51,8 +55,10 @@ class CORE_EXPORT TextFormatUpdateEvent final : public Event {
uint32_t format_range_end_ = 0; uint32_t format_range_end_ = 0;
String underline_color_; String underline_color_;
String background_color_; String background_color_;
String text_decoration_color_; String suggestion_highlight_color_;
String text_underline_style_; String text_color_;
String underline_thickness_;
String underline_style_;
}; };
} // namespace blink } // namespace blink
......
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
readonly attribute unsigned long formatRangeEnd; readonly attribute unsigned long formatRangeEnd;
readonly attribute DOMString underlineColor; readonly attribute DOMString underlineColor;
readonly attribute DOMString backgroundColor; readonly attribute DOMString backgroundColor;
readonly attribute DOMString textDecorationColor; readonly attribute DOMString suggestionHighlightColor;
readonly attribute DOMString textUnderlineStyle; readonly attribute DOMString textColor;
readonly attribute DOMString underlineThickness;
readonly attribute DOMString underlineStyle;
}; };
...@@ -7,6 +7,8 @@ dictionary TextFormatUpdateEventInit { ...@@ -7,6 +7,8 @@ dictionary TextFormatUpdateEventInit {
unsigned long formatRangeEnd; unsigned long formatRangeEnd;
DOMString underlineColor; DOMString underlineColor;
DOMString backgroundColor; DOMString backgroundColor;
DOMString textDecorationColor; DOMString suggestionHighlightColor;
DOMString textUnderlineStyle; DOMString textColor;
DOMString underlineThickness;
DOMString underlineStyle;
}; };
...@@ -75,10 +75,12 @@ test(function() { ...@@ -75,10 +75,12 @@ test(function() {
test.innerHTML = ""; test.innerHTML = "";
let formatRangeStart = 0; let formatRangeStart = 0;
let formatRangeEnd = 0; let formatRangeEnd = 0;
let underlineTextColor = ""; let underlineColor = "";
let backgroundTextColor = ""; let backgroundColor = "";
let compositionTextDecorationColor = ""; let textColor = "";
let suggestionHighlightColor = "";
let compositionTextUnderlineStyle = ""; let compositionTextUnderlineStyle = "";
let compositionTextUnderlineThickness = "";
// Add EditContext event listeners // Add EditContext event listeners
editContext.addEventListener("textupdate", e => { editContext.addEventListener("textupdate", e => {
// Update the text in the div // Update the text in the div
...@@ -91,8 +93,10 @@ test(function() { ...@@ -91,8 +93,10 @@ test(function() {
formatRangeEnd = e.formatRangeEnd; formatRangeEnd = e.formatRangeEnd;
underlineColor = e.underlineColor; underlineColor = e.underlineColor;
backgroundColor = e.backgroundColor; backgroundColor = e.backgroundColor;
compositionTextDecorationColor = e.textDecorationColor; textColor = e.textColor;
compositionTextUnderlineStyle = e.textUnderlineStyle; suggestionHighlightColor = e.suggestionHighlightColor;
compositionTextUnderlineStyle = e.underlineStyle;
compositionTextUnderlineThickness = e.underlineThickness;
}); });
test.focus(); test.focus();
...@@ -103,8 +107,10 @@ test(function() { ...@@ -103,8 +107,10 @@ test(function() {
assert_equals(formatRangeEnd, 3); assert_equals(formatRangeEnd, 3);
assert_equals(underlineColor, "rgba(0, 0, 0, 0)"); assert_equals(underlineColor, "rgba(0, 0, 0, 0)");
assert_equals(backgroundColor, "rgba(0, 0, 0, 0)"); assert_equals(backgroundColor, "rgba(0, 0, 0, 0)");
assert_equals(compositionTextDecorationColor, "rgba(0, 0, 0, 0)"); assert_equals(textColor, "rgba(0, 0, 0, 0)");
assert_equals(compositionTextUnderlineStyle, "Thin"); assert_equals(suggestionHighlightColor, "rgba(0, 0, 0, 0)");
assert_equals(compositionTextUnderlineStyle, "Solid");
assert_equals(compositionTextUnderlineThickness, "Thin");
}, 'Testing EditContext TextFormatUpdate'); }, 'Testing EditContext TextFormatUpdate');
test(function() { test(function() {
......
...@@ -8397,9 +8397,11 @@ interface TextFormatUpdateEvent : Event ...@@ -8397,9 +8397,11 @@ interface TextFormatUpdateEvent : Event
getter backgroundColor getter backgroundColor
getter formatRangeEnd getter formatRangeEnd
getter formatRangeStart getter formatRangeStart
getter textDecorationColor getter suggestionHighlightColor
getter textUnderlineStyle getter textColor
getter underlineColor getter underlineColor
getter underlineStyle
getter underlineThickness
method constructor method constructor
interface TextMetrics interface TextMetrics
attribute @@toStringTag 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