Commit c3bf3d91 authored by Anupam Snigdha's avatar Anupam Snigdha Committed by Commit Bot

EditContext Prototype

This change contains the prototype implementation of EditContext
event APIs. For more details about this change please refer to
https://chromium-review.googlesource.com/c/chromium/src/+/1591870
EditContext simplifies the process of integrating a web app with advanced
text input methods such as IME, VK shape-writing, speech recognition etc.
EditContext decouples text input from the HTML DOM view.
Rather than having the web platform infer the data required to enable
sophisticated text input mechanisms from the HTML DOM, the author will
provide that data explicitly through the API surface of the EditContext.
Additionally, EditContext communicates events driven from text input UI
to JavaScript.

Explainer: https://github.com/MicrosoftEdge/MSEdgeExplainers/blob/
master/EditContext/explainer.md

Bug: 999184

Change-Id: Ice8c14b931e1253101ff96592b9b47e60b07ad01
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1864318Reviewed-by: default avatarYoshifumi Inoue <yosin@chromium.org>
Reviewed-by: default avatarKent Tamura <tkent@chromium.org>
Commit-Queue: Anupam Snigdha <snianu@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#709368}
parent 829cc13a
...@@ -343,6 +343,8 @@ generate_event_interfaces("core_event_interfaces") { ...@@ -343,6 +343,8 @@ generate_event_interfaces("core_event_interfaces") {
"display_lock/before_activate_event.idl", "display_lock/before_activate_event.idl",
"dom/events/custom_event.idl", "dom/events/custom_event.idl",
"dom/events/event.idl", "dom/events/event.idl",
"editing/ime/text_format_update_event.idl",
"editing/ime/text_update_event.idl",
"events/animation_event.idl", "events/animation_event.idl",
"events/animation_playback_event.idl", "events/animation_playback_event.idl",
"events/application_cache_error_event.idl", "events/application_cache_error_event.idl",
......
...@@ -143,6 +143,8 @@ core_idl_files = ...@@ -143,6 +143,8 @@ core_idl_files =
"trustedtypes/trusted_type_policy.idl", "trustedtypes/trusted_type_policy.idl",
"trustedtypes/trusted_type_policy_factory.idl", "trustedtypes/trusted_type_policy_factory.idl",
"editing/selection.idl", "editing/selection.idl",
"editing/ime/text_update_event.idl",
"editing/ime/text_format_update_event.idl",
"events/animation_event.idl", "events/animation_event.idl",
"events/animation_playback_event.idl", "events/animation_playback_event.idl",
"events/application_cache_error_event.idl", "events/application_cache_error_event.idl",
...@@ -624,6 +626,8 @@ core_dictionary_idl_files = ...@@ -624,6 +626,8 @@ core_dictionary_idl_files =
"dom/events/event_init.idl", "dom/events/event_init.idl",
"dom/events/event_listener_options.idl", "dom/events/event_listener_options.idl",
"dom/events/event_modifier_init.idl", "dom/events/event_modifier_init.idl",
"editing/ime/text_update_event_init.idl",
"editing/ime/text_format_update_event_init.idl",
"events/animation_event_init.idl", "events/animation_event_init.idl",
"events/animation_playback_event_init.idl", "events/animation_playback_event_init.idl",
"events/application_cache_error_event_init.idl", "events/application_cache_error_event_init.idl",
......
...@@ -150,6 +150,10 @@ blink_core_sources("editing") { ...@@ -150,6 +150,10 @@ blink_core_sources("editing") {
"ime/ime_text_span_vector_builder.h", "ime/ime_text_span_vector_builder.h",
"ime/input_method_controller.cc", "ime/input_method_controller.cc",
"ime/input_method_controller.h", "ime/input_method_controller.h",
"ime/text_format_update_event.cc",
"ime/text_format_update_event.h",
"ime/text_update_event.cc",
"ime/text_update_event.h",
"inline_box_position.cc", "inline_box_position.cc",
"inline_box_position.h", "inline_box_position.h",
"inline_box_traversal.cc", "inline_box_traversal.cc",
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "third_party/blink/renderer/core/editing/ime/text_format_update_event.h"
#include "third_party/blink/renderer/core/editing/ime/text_format_update_event_init.h"
#include "third_party/blink/renderer/core/event_interface_names.h"
#include "third_party/blink/renderer/core/event_type_names.h"
namespace blink {
TextFormatUpdateEvent::TextFormatUpdateEvent(
const TextFormatUpdateEventInit* dict) {
if (dict->hasFormatRangeStart())
format_range_start_ = dict->formatRangeStart();
if (dict->hasFormatRangeEnd())
format_range_end_ = dict->formatRangeEnd();
if (dict->hasUnderlineColor())
underline_color_ = dict->underlineColor();
if (dict->hasBackgroundColor())
background_color_ = dict->backgroundColor();
if (dict->hasTextDecorationColor())
text_decoration_color_ = dict->textDecorationColor();
if (dict->hasTextUnderlineStyle())
text_underline_style_ = dict->textUnderlineStyle();
}
TextFormatUpdateEvent::TextFormatUpdateEvent(
uint32_t format_range_start,
uint32_t format_range_end,
const String& underline_color,
const String& background_color,
const String& text_decoration_color,
const String& text_underline_style)
: Event(event_type_names::kTextformatupdate,
Bubbles::kNo,
Cancelable::kYes,
ComposedMode::kComposed,
base::TimeTicks::Now()),
format_range_start_(format_range_start),
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) {}
TextFormatUpdateEvent* TextFormatUpdateEvent::Create(
const TextFormatUpdateEventInit* dict) {
return MakeGarbageCollected<TextFormatUpdateEvent>(dict);
}
TextFormatUpdateEvent::~TextFormatUpdateEvent() = default;
uint32_t TextFormatUpdateEvent::formatRangeStart() const {
return format_range_start_;
}
uint32_t TextFormatUpdateEvent::formatRangeEnd() const {
return format_range_end_;
}
String TextFormatUpdateEvent::underlineColor() const {
return underline_color_;
}
String TextFormatUpdateEvent::backgroundColor() const {
return background_color_;
}
String TextFormatUpdateEvent::textDecorationColor() const {
return text_decoration_color_;
}
String TextFormatUpdateEvent::textUnderlineStyle() const {
return text_underline_style_;
}
const AtomicString& TextFormatUpdateEvent::InterfaceName() const {
return event_interface_names::kTextFormatUpdateEvent;
}
} // namespace blink
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_EVENTS_TEXT_FORMAT_UPDATE_EVENT_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_EVENTS_TEXT_FORMAT_UPDATE_EVENT_H_
#include "base/macros.h"
#include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/core/dom/events/event.h"
namespace blink {
class TextFormatUpdateEventInit;
class TextFormatUpdateEvent;
// The textformatupdate event is fired when the input method desires a specific
// region to be styled in a certain fashion, limited to the style properties
// that correspond with the properties that are exposed on TextFormatUpdateEvent
// (e.g. backgroundColor, textDecoration, etc.). The consumer of the EditContext
// should update their view accordingly to provide the user with visual feedback
// as prescribed by the software keyboard. Note that this may have accessibility
// implications, as the IME may not be aware of the color scheme of the editable
// contents (i.e. may be requesting blue highlight on text that was already
// blue).
class CORE_EXPORT TextFormatUpdateEvent final : public Event {
DEFINE_WRAPPERTYPEINFO();
public:
TextFormatUpdateEvent(const TextFormatUpdateEventInit* dict);
TextFormatUpdateEvent(uint32_t format_range_start,
uint32_t format_range_end,
const String& underline_color,
const String& background_color,
const String& text_decoration_color,
const String& text_underline_style);
static TextFormatUpdateEvent* Create(const TextFormatUpdateEventInit* dict);
~TextFormatUpdateEvent() override;
uint32_t formatRangeStart() const;
uint32_t formatRangeEnd() const;
String underlineColor() const;
String backgroundColor() const;
String textDecorationColor() const;
String textUnderlineStyle() const;
const AtomicString& InterfaceName() const override;
// member variables to keep track of the event parameters
private:
uint32_t format_range_start_ = 0;
uint32_t format_range_end_ = 0;
String underline_color_;
String background_color_;
String text_decoration_color_;
String text_underline_style_;
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_CORE_EVENTS_TEXT_FORMAT_UPDATE_EVENT_H_
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// The textformatupdate event is fired when the input method desires a specific
// region to be styled in a certain fashion, limited to the style properties
// that correspond with the properties that are exposed on TextFormatUpdateEvent
// (e.g. backgroundColor, textDecoration, etc.).
// Explainer: https://github.com/MicrosoftEdge/MSEdgeExplainers/blob/master/EditContext/explainer.md
[
Constructor(optional TextFormatUpdateEventInit options),
Exposed=Window,
RuntimeEnabled=EditContext
] interface TextFormatUpdateEvent : Event {
readonly attribute unsigned long formatRangeStart;
readonly attribute unsigned long formatRangeEnd;
readonly attribute DOMString underlineColor;
readonly attribute DOMString backgroundColor;
readonly attribute DOMString textDecorationColor;
readonly attribute DOMString textUnderlineStyle;
};
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
dictionary TextFormatUpdateEventInit {
unsigned long formatRangeStart;
unsigned long formatRangeEnd;
DOMString underlineColor;
DOMString backgroundColor;
DOMString textDecorationColor;
DOMString textUnderlineStyle;
};
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "third_party/blink/renderer/core/editing/ime/text_update_event.h"
#include "third_party/blink/renderer/core/editing/ime/text_update_event_init.h"
#include "third_party/blink/renderer/core/event_interface_names.h"
#include "third_party/blink/renderer/core/event_type_names.h"
namespace blink {
TextUpdateEvent::TextUpdateEvent(const TextUpdateEventInit* dict) {
if (dict->hasUpdateText())
update_text_ = dict->updateText();
if (dict->hasUpdateRangeStart())
update_range_start_ = dict->updateRangeStart();
if (dict->hasUpdateRangeEnd())
update_range_end_ = dict->updateRangeEnd();
if (dict->hasNewSelectionStart())
new_selection_start_ = dict->newSelectionStart();
if (dict->hasNewSelectionEnd())
new_selection_end_ = dict->newSelectionEnd();
}
TextUpdateEvent::TextUpdateEvent(const String& update_text,
uint32_t update_range_start,
uint32_t update_range_end,
uint32_t new_selection_start,
uint32_t new_selection_end)
: Event(event_type_names::kTextupdate,
Bubbles::kNo,
Cancelable::kYes,
ComposedMode::kComposed,
base::TimeTicks::Now()),
update_text_(update_text),
update_range_start_(update_range_start),
update_range_end_(update_range_end),
new_selection_start_(new_selection_start),
new_selection_end_(new_selection_end) {}
TextUpdateEvent* TextUpdateEvent::Create(const TextUpdateEventInit* dict) {
return MakeGarbageCollected<TextUpdateEvent>(dict);
}
TextUpdateEvent::~TextUpdateEvent() = default;
String TextUpdateEvent::updateText() const {
return update_text_;
}
uint32_t TextUpdateEvent::updateRangeStart() const {
return update_range_start_;
}
uint32_t TextUpdateEvent::updateRangeEnd() const {
return update_range_end_;
}
uint32_t TextUpdateEvent::newSelectionStart() const {
return new_selection_start_;
}
uint32_t TextUpdateEvent::newSelectionEnd() const {
return new_selection_end_;
}
const AtomicString& TextUpdateEvent::InterfaceName() const {
return event_interface_names::kTextUpdateEvent;
}
} // namespace blink
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_EVENTS_TEXT_UPDATE_EVENT_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_EVENTS_TEXT_UPDATE_EVENT_H_
#include "base/macros.h"
#include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/core/dom/events/event.h"
namespace blink {
class TextUpdateEventInit;
class TextUpdateEvent;
// The textupdate event will be fired on the EditContext when user input has
// resulted in characters being applied to the editable region. The event
// signals the fact that the software keyboard or IME updated the text (and as
// such that state is reflected in the shared buffer at the time the event is
// fired). This can be a single character update, in the case of typical typing
// scenarios, or multiple-character insertion based on the user changing
// composition candidates. Even though text updates are the results of the
// software keyboard modifying the buffer, the creator of the EditContext is
// ultimately responsible for keeping its underlying model up-to-date with the
// content that is being edited as well as telling the EditContext about such
// changes. These could get out of sync, for example, when updates to the
// editable content come in through other means (the backspace key is a
// canonical example — no textupdate is fired in this case, and the consumer of
// the EditContext should detect the keydown event and remove characters as
// appropriate).
class CORE_EXPORT TextUpdateEvent final : public Event {
DEFINE_WRAPPERTYPEINFO();
public:
TextUpdateEvent(const TextUpdateEventInit* dict);
TextUpdateEvent(const String& update_text,
uint32_t update_range_start,
uint32_t update_range_end,
uint32_t new_selection_start,
uint32_t new_selection_end);
static TextUpdateEvent* Create(const TextUpdateEventInit* dict);
~TextUpdateEvent() override;
String updateText() const;
uint32_t updateRangeStart() const;
uint32_t updateRangeEnd() const;
uint32_t newSelectionStart() const;
uint32_t newSelectionEnd() const;
const AtomicString& InterfaceName() const override;
// member variables to keep track of the event parameters
private:
String update_text_;
uint32_t update_range_start_ = 0;
uint32_t update_range_end_ = 0;
uint32_t new_selection_start_ = 0;
uint32_t new_selection_end_ = 0;
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_CORE_EVENTS_TEXT_UPDATE_EVENT_H_
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// The textupdate event will be fired on the EditContext when user input has
// resulted in characters being applied to the editable region. The event
// signals the fact that the software keyboard or IME updated the text (and as
// such that state is reflected in the shared buffer at the time the event is
// fired).
// Explainer: https://github.com/MicrosoftEdge/MSEdgeExplainers/blob/master/EditContext/explainer.md
[
Constructor(optional TextUpdateEventInit options),
Exposed=Window,
RuntimeEnabled=EditContext
] interface TextUpdateEvent : Event {
readonly attribute unsigned long updateRangeStart;
readonly attribute unsigned long updateRangeEnd;
readonly attribute DOMString updateText;
readonly attribute unsigned long newSelectionStart;
readonly attribute unsigned long newSelectionEnd;
};
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
dictionary TextUpdateEventInit {
unsigned long updateRangeStart;
unsigned long updateRangeEnd;
DOMString updateText;
unsigned long newSelectionStart;
unsigned long newSelectionEnd;
};
...@@ -274,6 +274,8 @@ ...@@ -274,6 +274,8 @@
"sync", "sync",
"terminate", "terminate",
"textInput", "textInput",
"textupdate",
"textformatupdate",
"timeout", "timeout",
"timeupdate", "timeupdate",
"toggle", "toggle",
......
...@@ -564,6 +564,11 @@ ...@@ -564,6 +564,11 @@
{ {
name: "DocumentWrite", name: "DocumentWrite",
}, },
{
name: "EditContext",
settable_from_internals: true,
status: "test",
},
{ {
// http://crbug.com/707656 content editable in LayoutNG. // http://crbug.com/707656 content editable in LayoutNG.
name: "EditingNG", name: "EditingNG",
......
...@@ -7928,6 +7928,15 @@ interface TextEvent : UIEvent ...@@ -7928,6 +7928,15 @@ interface TextEvent : UIEvent
getter data getter data
method constructor method constructor
method initTextEvent method initTextEvent
interface TextFormatUpdateEvent : Event
attribute @@toStringTag
getter backgroundColor
getter formatRangeEnd
getter formatRangeStart
getter textDecorationColor
getter textUnderlineStyle
getter underlineColor
method constructor
interface TextMetrics interface TextMetrics
attribute @@toStringTag attribute @@toStringTag
getter actualBoundingBoxAscent getter actualBoundingBoxAscent
...@@ -7991,6 +8000,14 @@ interface TextTrackList : EventTarget ...@@ -7991,6 +8000,14 @@ interface TextTrackList : EventTarget
setter onaddtrack setter onaddtrack
setter onchange setter onchange
setter onremovetrack setter onremovetrack
interface TextUpdateEvent : Event
attribute @@toStringTag
getter newSelectionEnd
getter newSelectionStart
getter updateRangeEnd
getter updateRangeStart
getter updateText
method constructor
interface TimeRanges interface TimeRanges
attribute @@toStringTag attribute @@toStringTag
getter length getter length
......
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