Commit f6315341 authored by Sidney San Martín's avatar Sidney San Martín Committed by Commit Bot

macOS text substitutions: More granularity in how HTML attributes change behavior.

With this change, `autocorrect=off` turns off all substitutions, and
`spellcheck=false` just turns off quote and dash substitution, leaving
custom substitutions on.

Bug: 42434
Change-Id: I9ddf49f765e0ce061c8431563768f02e802d919b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1672539
Auto-Submit: Sidney San Martín <sdy@chromium.org>
Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
Commit-Queue: Avi Drissman <avi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#671798}
parent 8df9cf09
......@@ -166,8 +166,8 @@ void ExtractUnderlines(NSAttributedString* string,
NSTextCheckingTypes userEnabledTextCheckingTypes_;
NSTextCheckingTypes userDisabledTextCheckingTypes_;
}
@property(readonly) NSTextCheckingType allowedTextCheckingTypes;
@property(readonly) NSTextCheckingType enabledTextCheckingTypes;
@property(readonly) BOOL inputAllowsTextSubstitution;
@property(readonly) NSSpellChecker* spellChecker;
- (void)processedWheelEvent:(const blink::WebMouseWheelEvent&)event
......@@ -254,16 +254,6 @@ void ExtractUnderlines(NSAttributedString* string,
host_->OnBoundsInWindowChanged(gfxViewBoundsInWindow, true);
}
- (BOOL)inputAllowsTextSubstitution {
if (textInputType_ == ui::TEXT_INPUT_TYPE_NONE)
return NO;
if (textInputType_ == ui::TEXT_INPUT_TYPE_PASSWORD)
return NO;
if (textInputFlags_ & blink::kWebTextInputFlagSpellcheckOff)
return NO;
return YES;
}
- (NSSpellChecker*)spellChecker {
if (spellCheckerForTesting_)
return spellCheckerForTesting_;
......@@ -271,11 +261,9 @@ void ExtractUnderlines(NSAttributedString* string,
}
- (void)requestTextSubstitutions {
if (!self.inputAllowsTextSubstitution)
return;
NSTextCheckingType enabledTextCheckingTypes = self.enabledTextCheckingTypes;
if (!enabledTextCheckingTypes)
NSTextCheckingType textCheckingTypes =
self.allowedTextCheckingTypes & self.enabledTextCheckingTypes;
if (!textCheckingTypes)
return;
NSString* availableText = base::SysUTF16ToNSString(textSelectionText_);
......@@ -286,7 +274,7 @@ void ExtractUnderlines(NSAttributedString* string,
auto* textCheckingResults =
[self.spellChecker checkString:availableText
range:NSMakeRange(0, availableText.length)
types:enabledTextCheckingTypes
types:textCheckingTypes
options:nil
inSpellDocumentWithTag:0
orthography:nullptr
......@@ -414,6 +402,19 @@ void ExtractUnderlines(NSAttributedString* string,
}];
}
- (NSTextCheckingType)allowedTextCheckingTypes {
if (textInputType_ == ui::TEXT_INPUT_TYPE_NONE)
return 0;
if (textInputType_ == ui::TEXT_INPUT_TYPE_PASSWORD)
return 0;
if (textInputFlags_ & blink::kWebTextInputFlagAutocorrectOff)
return 0;
NSTextCheckingType checkingTypes = NSTextCheckingTypeReplacement;
if (!(textInputFlags_ & blink::kWebTextInputFlagSpellcheckOff))
checkingTypes |= NSTextCheckingTypeQuote | NSTextCheckingTypeDash;
return checkingTypes;
}
- (NSTextCheckingType)enabledTextCheckingTypes {
NSTextCheckingType checkingTypes = 0;
if (NSSpellChecker.automaticQuoteSubstitutionEnabled)
......@@ -1561,7 +1562,7 @@ void ExtractUnderlines(NSAttributedString* string,
(self.enabledTextCheckingTypes & representedTextCheckingType)
? NSControlStateValueOn
: NSControlStateValueOff;
return self.inputAllowsTextSubstitution;
return (self.allowedTextCheckingTypes & representedTextCheckingType) != 0;
}
}
......
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