Skip to content

Commit

Permalink
Add value to ImeTextSpan::Type enum for misspelling suggestions
Browse files Browse the repository at this point in the history
Currently, the Type enums in the ImeTextSpan classes (ui::ImeTextSpan,
blink::ImeTextSpan, and blink::WebImeTextSpan) define two values: kComposition,
for composition markers, and kSuggestion, for Android SuggestionSpans. This
CL adds a third value, kMisspellingSuggestion, for Android SuggestionSpans that
represent misspellings. Misspelling suggestions will behave differently in two
ways from regular suggestions:

- They will not be added to an editable region with spell checking disabled.
- They will be removed if one of their suggested replacements is chosen.

Bug: 672259
Cq-Include-Trybots: master.tryserver.chromium.linux:linux_site_isolation
Change-Id: Ie4b3d2f67ef53b5819380261da5d91ac0209a7ff
Reviewed-on: https://chromium-review.googlesource.com/660689
Reviewed-by: Scott Violet <sky@chromium.org>
Reviewed-by: Yoshifumi Inoue <yosin@chromium.org>
Reviewed-by: Will Harris <wfh@chromium.org>
Commit-Queue: Ryan Landay <rlanday@chromium.org>
Cr-Commit-Position: refs/heads/master@{#501843}
  • Loading branch information
rlanday authored and Commit Bot committed Sep 14, 2017
1 parent 8ae03b5 commit 69ac1e4
Show file tree
Hide file tree
Showing 15 changed files with 96 additions and 83 deletions.
20 changes: 5 additions & 15 deletions content/browser/browser_plugin/browser_plugin_guest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "content/common/browser_plugin/browser_plugin_messages.h"
#include "content/common/content_constants_internal.h"
#include "content/common/drag_messages.h"
#include "content/common/input/ime_text_span_conversions.h"
#include "content/common/input_messages.h"
#include "content/common/site_isolation_policy.h"
#include "content/common/text_input_state.h"
Expand All @@ -62,26 +63,15 @@ namespace content {

namespace {

ui::ImeTextSpan::Type ConvertWebTypeToUiType(blink::WebImeTextSpan::Type type) {
switch (type) {
case blink::WebImeTextSpan::Type::kComposition:
return ui::ImeTextSpan::Type::kComposition;
case blink::WebImeTextSpan::Type::kSuggestion:
return ui::ImeTextSpan::Type::kSuggestion;
}

NOTREACHED();
return ui::ImeTextSpan::Type::kComposition;
}

std::vector<ui::ImeTextSpan> ConvertToUiImeTextSpan(
const std::vector<blink::WebImeTextSpan>& ime_text_spans) {
std::vector<ui::ImeTextSpan> ui_ime_text_spans;
for (const auto& ime_text_span : ime_text_spans) {
ui_ime_text_spans.emplace_back(ui::ImeTextSpan(
ConvertWebTypeToUiType(ime_text_span.type), ime_text_span.start_offset,
ime_text_span.end_offset, ime_text_span.underline_color,
ime_text_span.thick, ime_text_span.background_color,
ConvertWebImeTextSpanTypeToUiType(ime_text_span.type),
ime_text_span.start_offset, ime_text_span.end_offset,
ime_text_span.underline_color, ime_text_span.thick,
ime_text_span.background_color,
ime_text_span.suggestion_highlight_color, ime_text_span.suggestions));
}
return ui_ime_text_spans;
Expand Down
20 changes: 2 additions & 18 deletions content/browser/frame_host/input/legacy_ipc_frame_input_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,11 @@
#include "base/strings/utf_string_conversions.h"
#include "content/browser/renderer_host/input/legacy_input_router_impl.h"
#include "content/browser/renderer_host/render_widget_host_impl.h"
#include "content/common/input/ime_text_span_conversions.h"
#include "content/common/input_messages.h"

namespace content {

namespace {

blink::WebImeTextSpan::Type ConvertUiImeTextSpanTypeToBlinkType(
ui::ImeTextSpan::Type type) {
switch (type) {
case ui::ImeTextSpan::Type::kComposition:
return blink::WebImeTextSpan::Type::kComposition;
case ui::ImeTextSpan::Type::kSuggestion:
return blink::WebImeTextSpan::Type::kSuggestion;
}

NOTREACHED();
return blink::WebImeTextSpan::Type::kComposition;
}

} // namespace

LegacyIPCFrameInputHandler::LegacyIPCFrameInputHandler(
RenderFrameHostImpl* frame_host)
: frame_host_(frame_host), routing_id_(frame_host->GetRoutingID()) {}
Expand All @@ -41,7 +25,7 @@ void LegacyIPCFrameInputHandler::SetCompositionFromExistingText(
std::vector<blink::WebImeTextSpan> ime_text_spans;
for (const auto& ime_text_span : ui_ime_text_spans) {
blink::WebImeTextSpan blink_ime_text_span(
ConvertUiImeTextSpanTypeToBlinkType(ime_text_span.type),
ConvertUiImeTextSpanTypeToWebType(ime_text_span.type),
ime_text_span.start_offset, ime_text_span.end_offset,
ime_text_span.underline_color, ime_text_span.thick,
ime_text_span.background_color,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,19 @@
#include "build/build_config.h"
#include "content/browser/renderer_host/input/legacy_input_router_impl.h"
#include "content/browser/renderer_host/render_widget_host_impl.h"
#include "content/common/input/ime_text_span_conversions.h"
#include "content/common/input_messages.h"

namespace content {

namespace {

blink::WebImeTextSpan::Type ConvertUiImeTextSpanTypeToBlinkType(
ui::ImeTextSpan::Type type) {
switch (type) {
case ui::ImeTextSpan::Type::kComposition:
return blink::WebImeTextSpan::Type::kComposition;
case ui::ImeTextSpan::Type::kSuggestion:
return blink::WebImeTextSpan::Type::kSuggestion;
}

NOTREACHED();
return blink::WebImeTextSpan::Type::kComposition;
}

std::vector<blink::WebImeTextSpan> ConvertToBlinkImeTextSpan(
const std::vector<ui::ImeTextSpan>& ui_ime_text_spans) {
std::vector<blink::WebImeTextSpan> ime_text_spans;
for (const auto& ime_text_span : ui_ime_text_spans) {
ime_text_spans.emplace_back(blink::WebImeTextSpan(
ConvertUiImeTextSpanTypeToBlinkType(ime_text_span.type),
ConvertUiImeTextSpanTypeToWebType(ime_text_span.type),
ime_text_span.start_offset, ime_text_span.end_offset,
ime_text_span.underline_color, ime_text_span.thick,
ime_text_span.background_color,
Expand Down
2 changes: 2 additions & 0 deletions content/common/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ source_set("common") {
"input/event_with_latency_info.h",
"input/gesture_event_stream_validator.cc",
"input/gesture_event_stream_validator.h",
"input/ime_text_span_conversions.cc",
"input/ime_text_span_conversions.h",
"input/input_event.cc",
"input/input_event.h",
"input/input_event_ack.cc",
Expand Down
2 changes: 1 addition & 1 deletion content/common/content_param_traits_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ IPC_ENUM_TRAITS_MIN_MAX_VALUE(blink::WebInputEvent::Type,
IPC_ENUM_TRAITS_MAX_VALUE(blink::WebPageVisibilityState,
blink::kWebPageVisibilityStateLast)
IPC_ENUM_TRAITS_MAX_VALUE(blink::WebImeTextSpan::Type,
blink::WebImeTextSpan::Type::kSuggestion)
blink::WebImeTextSpan::Type::kMisspellingSuggestion)

IPC_STRUCT_TRAITS_BEGIN(blink::WebImeTextSpan)
IPC_STRUCT_TRAITS_MEMBER(type)
Expand Down
41 changes: 41 additions & 0 deletions content/common/input/ime_text_span_conversions.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright 2017 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 "content/common/input/ime_text_span_conversions.h"

#include "base/logging.h"

namespace content {

blink::WebImeTextSpan::Type ConvertUiImeTextSpanTypeToWebType(
ui::ImeTextSpan::Type type) {
switch (type) {
case ui::ImeTextSpan::Type::kComposition:
return blink::WebImeTextSpan::Type::kComposition;
case ui::ImeTextSpan::Type::kSuggestion:
return blink::WebImeTextSpan::Type::kSuggestion;
case ui::ImeTextSpan::Type::kMisspellingSuggestion:
return blink::WebImeTextSpan::Type::kMisspellingSuggestion;
}

NOTREACHED();
return blink::WebImeTextSpan::Type::kComposition;
}

ui::ImeTextSpan::Type ConvertWebImeTextSpanTypeToUiType(
blink::WebImeTextSpan::Type type) {
switch (type) {
case blink::WebImeTextSpan::Type::kComposition:
return ui::ImeTextSpan::Type::kComposition;
case blink::WebImeTextSpan::Type::kSuggestion:
return ui::ImeTextSpan::Type::kSuggestion;
case blink::WebImeTextSpan::Type::kMisspellingSuggestion:
return ui::ImeTextSpan::Type::kMisspellingSuggestion;
}

NOTREACHED();
return ui::ImeTextSpan::Type::kComposition;
}

} // namespace content
20 changes: 20 additions & 0 deletions content/common/input/ime_text_span_conversions.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright 2017 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 CONTENT_COMMON_INPUT_IME_TEXT_SPAN_CONVERSIONS_H_
#define CONTENT_COMMON_INPUT_IME_TEXT_SPAN_CONVERSIONS_H_

#include "third_party/WebKit/public/web/WebImeTextSpan.h"
#include "ui/base/ime/ime_text_span.h"

namespace content {

blink::WebImeTextSpan::Type ConvertUiImeTextSpanTypeToWebType(
ui::ImeTextSpan::Type type);
ui::ImeTextSpan::Type ConvertWebImeTextSpanTypeToUiType(
blink::WebImeTextSpan::Type type);

} // namespace content

#endif // CONTENT_COMMON_INPUT_IME_TEXT_SPAN_CONVERSIONS_H_
20 changes: 2 additions & 18 deletions content/renderer/input/frame_input_handler_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "base/bind.h"
#include "base/debug/stack_trace.h"
#include "base/logging.h"
#include "content/common/input/ime_text_span_conversions.h"
#include "content/renderer/gpu/render_widget_compositor.h"
#include "content/renderer/ime_event_guard.h"
#include "content/renderer/input/widget_input_handler_manager.h"
Expand All @@ -20,23 +21,6 @@

namespace content {

namespace {

blink::WebImeTextSpan::Type ConvertUiImeTextSpanTypeToBlinkType(
ui::ImeTextSpan::Type type) {
switch (type) {
case ui::ImeTextSpan::Type::kComposition:
return blink::WebImeTextSpan::Type::kComposition;
case ui::ImeTextSpan::Type::kSuggestion:
return blink::WebImeTextSpan::Type::kSuggestion;
}

NOTREACHED();
return blink::WebImeTextSpan::Type::kComposition;
}

} // namespace

FrameInputHandlerImpl::FrameInputHandlerImpl(
base::WeakPtr<RenderFrameImpl> render_frame,
mojom::FrameInputHandlerRequest request)
Expand Down Expand Up @@ -99,7 +83,7 @@ void FrameInputHandlerImpl::SetCompositionFromExistingText(
std::vector<blink::WebImeTextSpan> ime_text_spans;
for (const auto& ime_text_span : ui_ime_text_spans) {
blink::WebImeTextSpan blink_ime_text_span(
ConvertUiImeTextSpanTypeToBlinkType(ime_text_span.type),
ConvertUiImeTextSpanTypeToWebType(ime_text_span.type),
ime_text_span.start_offset, ime_text_span.end_offset,
ime_text_span.underline_color, ime_text_span.thick,
ime_text_span.background_color,
Expand Down
16 changes: 2 additions & 14 deletions content/renderer/input/widget_input_handler_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "base/bind.h"
#include "base/logging.h"
#include "content/common/input/ime_text_span_conversions.h"
#include "content/common/input_messages.h"
#include "content/renderer/gpu/render_widget_compositor.h"
#include "content/renderer/ime_event_guard.h"
Expand All @@ -24,25 +25,12 @@ namespace content {

namespace {

blink::WebImeTextSpan::Type ConvertUiImeTextSpanTypeToBlinkType(
ui::ImeTextSpan::Type type) {
switch (type) {
case ui::ImeTextSpan::Type::kComposition:
return blink::WebImeTextSpan::Type::kComposition;
case ui::ImeTextSpan::Type::kSuggestion:
return blink::WebImeTextSpan::Type::kSuggestion;
}

NOTREACHED();
return blink::WebImeTextSpan::Type::kComposition;
}

std::vector<blink::WebImeTextSpan> ConvertUIImeTextSpansToBlinkImeTextSpans(
const std::vector<ui::ImeTextSpan>& ui_ime_text_spans) {
std::vector<blink::WebImeTextSpan> ime_text_spans;
for (const auto& ime_text_span : ui_ime_text_spans) {
blink::WebImeTextSpan blink_ime_text_span(
ConvertUiImeTextSpanTypeToBlinkType(ime_text_span.type),
ConvertUiImeTextSpanTypeToWebType(ime_text_span.type),
ime_text_span.start_offset, ime_text_span.end_offset,
ime_text_span.underline_color, ime_text_span.thick,
ime_text_span.background_color,
Expand Down
1 change: 1 addition & 0 deletions services/ui/public/interfaces/ime/ime.mojom
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ struct CandidateWindowEntry {
enum ImeTextSpanType {
kComposition,
kSuggestion,
kMisspellingSuggestion,
};

// Represents an underlined segment of text currently composed by IME.
Expand Down
5 changes: 5 additions & 0 deletions services/ui/public/interfaces/ime/ime_struct_traits.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ EnumTraits<ui::mojom::ImeTextSpanType, ui::ImeTextSpan::Type>::ToMojom(
return ui::mojom::ImeTextSpanType::kComposition;
case ui::ImeTextSpan::Type::kSuggestion:
return ui::mojom::ImeTextSpanType::kSuggestion;
case ui::ImeTextSpan::Type::kMisspellingSuggestion:
return ui::mojom::ImeTextSpanType::kMisspellingSuggestion;
}

NOTREACHED();
Expand All @@ -92,6 +94,9 @@ bool EnumTraits<ui::mojom::ImeTextSpanType, ui::ImeTextSpan::Type>::FromMojom(
case ui::mojom::ImeTextSpanType::kSuggestion:
*out = ui::ImeTextSpan::Type::kSuggestion;
return true;
case ui::mojom::ImeTextSpanType::kMisspellingSuggestion:
*out = ui::ImeTextSpan::Type::kMisspellingSuggestion;
return true;
}

NOTREACHED();
Expand Down
2 changes: 2 additions & 0 deletions third_party/WebKit/Source/core/editing/ImeTextSpan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ ImeTextSpan::Type ConvertWebTypeToType(WebImeTextSpan::Type type) {
return ImeTextSpan::Type::kComposition;
case WebImeTextSpan::Type::kSuggestion:
return ImeTextSpan::Type::kSuggestion;
case WebImeTextSpan::Type::kMisspellingSuggestion:
return ImeTextSpan::Type::kMisspellingSuggestion;
}

NOTREACHED();
Expand Down
2 changes: 1 addition & 1 deletion third_party/WebKit/Source/core/editing/ImeTextSpan.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class CORE_EXPORT ImeTextSpan {
DISALLOW_NEW_EXCEPT_PLACEMENT_NEW();

public:
enum class Type { kComposition, kSuggestion };
enum class Type { kComposition, kSuggestion, kMisspellingSuggestion };

ImeTextSpan(Type,
unsigned start_offset,
Expand Down
8 changes: 6 additions & 2 deletions third_party/WebKit/public/web/WebImeTextSpan.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,15 @@ namespace blink {
// setComposition() method.
struct WebImeTextSpan {
enum class Type {
// Creates a composition marker
// Creates a composition marker.
kComposition,
// Creates a suggestion marker that isn't cleared after the user picks a
// replacement
// replacement.
kSuggestion,
// Creates a suggestion marker that is cleared after the user picks a
// replacement, and will be ignored if added to an element with spell
// checking disabled.
kMisspellingSuggestion,
};

WebImeTextSpan()
Expand Down
4 changes: 4 additions & 0 deletions ui/base/ime/ime_text_span.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ struct UI_BASE_IME_EXPORT ImeTextSpan {
// Creates a suggestion marker that isn't cleared after the user picks a
// replacement.
kSuggestion,
// Creates a suggestion marker that is cleared after the user picks a
// replacement, and will be ignored if added to an element with spell
// checking disabled.
kMisspellingSuggestion,
};

// The default constructor is used by generated Mojo code.
Expand Down

0 comments on commit 69ac1e4

Please sign in to comment.