Commit 1281b53e authored by My Nguyen's avatar My Nguyen Committed by Commit Bot

Add RemoveSuggestionMarkerByType

InputMethod isn't notified of the change in focus until the focus is
already changed. Let InputMethodController handle autocorrect marker
removal.

Bug: 1114877
Change-Id: I1e5a8f0ae1e52d3ec2aa0f97f0479bf987787451
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2345932
Commit-Queue: My Nguyen <myy@chromium.org>
Reviewed-by: default avatarYoshifumi Inoue <yosin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#796737}
parent 6e0097aa
......@@ -1779,6 +1779,8 @@ WebTextInputType InputMethodController::TextInputType() const {
void InputMethodController::WillChangeFocus() {
FinishComposingText(kKeepSelection);
GetDocument().Markers().RemoveSuggestionMarkerByType(
SuggestionMarker::SuggestionType::kAutocorrect);
}
void InputMethodController::Trace(Visitor* visitor) const {
......
......@@ -922,6 +922,25 @@ void DocumentMarkerController::RemoveSuggestionMarkerByType(
}
}
void DocumentMarkerController::RemoveSuggestionMarkerByType(
const SuggestionMarker::SuggestionType& type) {
if (!PossiblyHasMarkers(DocumentMarker::kSuggestion))
return;
DCHECK(!markers_.IsEmpty());
for (const auto& node_markers : markers_) {
MarkerLists* markers = node_markers.value;
DocumentMarkerList* const list =
ListForType(markers, DocumentMarker::kSuggestion);
if (!list)
continue;
if (To<SuggestionMarkerListImpl>(list)->RemoveMarkerByType(type)) {
InvalidatePaintForNode(*node_markers.key);
return;
}
}
}
void DocumentMarkerController::RemoveSuggestionMarkerByTag(const Text& text,
int32_t marker_tag) {
MarkerLists* markers = markers_.at(&text);
......
......@@ -91,6 +91,8 @@ class CORE_EXPORT DocumentMarkerController final
void RemoveSuggestionMarkerByType(
const EphemeralRangeInFlatTree& range,
const SuggestionMarker::SuggestionType& type);
void RemoveSuggestionMarkerByType(
const SuggestionMarker::SuggestionType& type);
// Removes suggestion marker with |RemoveOnFinishComposing::kRemove|.
void RemoveSuggestionMarkerInRangeOnFinish(const EphemeralRangeInFlatTree&);
void RepaintMarkers(
......
......@@ -382,7 +382,7 @@ TEST_F(DocumentMarkerControllerTest, RemoveSuggestionMarkerByTag) {
EXPECT_EQ(0u, MarkerController().Markers().size());
}
TEST_F(DocumentMarkerControllerTest, RemoveSuggestionMarkerByType) {
TEST_F(DocumentMarkerControllerTest, RemoveSuggestionMarkerByTypeWithRange) {
SetBodyContent("<div contenteditable>foo</div>");
Element* div = GetDocument().QuerySelector("div");
Node* text = div->firstChild();
......@@ -396,6 +396,34 @@ TEST_F(DocumentMarkerControllerTest, RemoveSuggestionMarkerByType) {
EXPECT_EQ(0u, MarkerController().Markers().size());
}
TEST_F(DocumentMarkerControllerTest, RemoveSuggestionMarkerByType) {
SetBodyContent("<div contenteditable>123 456</div>");
Element* div = GetDocument().QuerySelector("div");
Node* text = div->firstChild();
// Add an autocorrect marker on "123"
MarkerController().AddSuggestionMarker(
EphemeralRange(Position(text, 0), Position(text, 3)),
SuggestionMarkerProperties::Builder()
.SetType(SuggestionMarker::SuggestionType::kAutocorrect)
.Build());
// Add a misspelling suggestion marker on "123"
MarkerController().AddSuggestionMarker(
EphemeralRange(Position(text, 0), Position(text, 3)),
SuggestionMarkerProperties::Builder()
.SetType(SuggestionMarker::SuggestionType::kMisspelling)
.Build());
EXPECT_EQ(2u, MarkerController().Markers().size());
MarkerController().RemoveSuggestionMarkerByType(
SuggestionMarker::SuggestionType::kAutocorrect);
EXPECT_EQ(1u, MarkerController().Markers().size());
EXPECT_EQ(SuggestionMarker::SuggestionType::kMisspelling,
To<SuggestionMarker>(MarkerController().Markers()[0].Get())
->GetSuggestionType());
}
TEST_F(DocumentMarkerControllerTest, RemoveSuggestionMarkerInRangeOnFinish) {
SetBodyContent("<div contenteditable>foo</div>");
Element* div = GetDocument().QuerySelector("div");
......
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