Commit b4e82859 authored by Jaeyong Bae's avatar Jaeyong Bae Committed by Commit Bot

[Spellcheck] Remove spelling markers when readonly, disabled

This patch means removing spelling markers
if the form element is marked as readonly and disabled.

The spec seems pretty clear regarding this [1]:
The value of textarea elements that do not have a readonly attribute
and that are not disabled.

[1] https://html.spec.whatwg.org/multipage/interaction.html#spelling-and-grammar-checking

Bug: 687949
Change-Id: I716d1607d12a603c821211cc0b1933d05b9fdda4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2120992
Commit-Queue: Jaeyong Bae <jdragon.bae@gmail.com>
Reviewed-by: default avatarXiaocheng Hu <xiaochengh@chromium.org>
Reviewed-by: default avatarKent Tamura <tkent@chromium.org>
Cr-Commit-Position: refs/heads/master@{#758191}
parent aa4fbfe7
......@@ -412,7 +412,8 @@ void SpellChecker::RemoveSpellingAndGrammarMarkers(const HTMLElement& element,
ElementsType elements_type) {
// TODO(editing-dev): The use of updateStyleAndLayoutIgnorePendingStylesheets
// needs to be audited. See http://crbug.com/590369 for more details.
GetFrame().GetDocument()->UpdateStyleAndLayoutTreeForNode(&element);
if (elements_type == ElementsType::kOnlyNonEditable)
GetFrame().GetDocument()->UpdateStyleAndLayoutTreeForNode(&element);
for (Node& node : NodeTraversal::InclusiveDescendantsOf(element)) {
auto* text_node = DynamicTo<Text>(node);
......
......@@ -43,6 +43,7 @@
#include "third_party/blink/renderer/core/editing/selection_template.h"
#include "third_party/blink/renderer/core/editing/serializers/serialization.h"
#include "third_party/blink/renderer/core/editing/set_selection_options.h"
#include "third_party/blink/renderer/core/editing/spellcheck/spell_checker.h"
#include "third_party/blink/renderer/core/editing/text_affinity.h"
#include "third_party/blink/renderer/core/editing/visible_position.h"
#include "third_party/blink/renderer/core/frame/local_frame.h"
......@@ -773,6 +774,13 @@ void TextControlElement::ParseAttribute(
params.name == html_names::kDisabledAttr) {
DisabledOrReadonlyAttributeChanged(params.name);
HTMLFormControlElementWithState::ParseAttribute(params);
if (params.new_value.IsNull())
return;
if (HTMLElement* inner_editor = InnerEditorElement()) {
if (auto* frame = GetDocument().GetFrame())
frame->GetSpellChecker().RemoveSpellingAndGrammarMarkers(*inner_editor);
}
} else {
HTMLFormControlElementWithState::ParseAttribute(params);
}
......
......@@ -96,4 +96,29 @@
'Removing "contenteditable" attribute on child still keeps the spelling markers.')
});
spellcheck_test(
'<textarea>|zz. I have a issue.</textarea>',
'',
'<textarea>#zz#. I have ~a~ issue.</textarea>',
{
title: '8) Setup for the initial markers.',
callback: sample => spellcheck_test(
sample,
document => document.querySelector('textarea').setAttribute('readonly', ''),
'<textarea readonly>zz. I have a issue.</textarea>',
'Setting "readonly" attribute removes spelling markers.')
});
spellcheck_test(
'<textarea>|zz. I have a issue.</textarea>',
'',
'<textarea>#zz#. I have ~a~ issue.</textarea>',
{
title: '9) Setup for the initial markers.',
callback: sample => spellcheck_test(
sample,
document => document.querySelector('textarea').setAttribute('disabled', ''),
'<textarea disabled>zz. I have a issue.</textarea>',
'Setting "disabled" attribute removes spelling markers.')
});
</script>
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