- Revision
- 196090
- Author
- [email protected]
- Date
- 2016-02-03 16:01:46 -0800 (Wed, 03 Feb 2016)
Log Message
Accepted candidates should not be autocorrected
https://bugs.webkit.org/show_bug.cgi?id=153813
-and corresponding-
rdar://problem/24066924
Reviewed by Darin Adler.
New document marker to mark inserted candidates. This was we can treat
inserted candidates just like a RejectedCorrection and we won’t accidentally
autocorrect them later on.
* dom/DocumentMarker.h:
(WebCore::DocumentMarker::AllMarkers::AllMarkers):
* editing/AlternativeTextController.cpp:
(WebCore::AlternativeTextController::processMarkersOnTextToBeReplacedByResult):
When handling an acceptant candidate, set m_isHandlingAcceptedCandidate to
true while the text is being inserted, and then mark the range as an accepted
candidate.
* editing/Editor.cpp:
(WebCore::Editor::handleAcceptedCandidate):
* editing/Editor.h:
(WebCore::Editor::isHandlingAcceptedCandidate):
If frame.editor. isHandlingAcceptedCandidate() then return early from
markMisspellingsAfterTyping.
* editing/TypingCommand.cpp:
(WebCore::TypingCommand::markMisspellingsAfterTyping):
Add some test infrastructure.
* testing/Internals.cpp:
(WebCore::Internals::handleAcceptedCandidate):
* testing/Internals.h:
* testing/Internals.idl:
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (196089 => 196090)
--- trunk/Source/WebCore/ChangeLog 2016-02-04 00:00:24 UTC (rev 196089)
+++ trunk/Source/WebCore/ChangeLog 2016-02-04 00:01:46 UTC (rev 196090)
@@ -1,3 +1,39 @@
+2016-02-03 Beth Dakin <[email protected]>
+
+ Accepted candidates should not be autocorrected
+ https://bugs.webkit.org/show_bug.cgi?id=153813
+ -and corresponding-
+ rdar://problem/24066924
+
+ Reviewed by Darin Adler.
+
+ New document marker to mark inserted candidates. This was we can treat
+ inserted candidates just like a RejectedCorrection and we won’t accidentally
+ autocorrect them later on.
+ * dom/DocumentMarker.h:
+ (WebCore::DocumentMarker::AllMarkers::AllMarkers):
+ * editing/AlternativeTextController.cpp:
+ (WebCore::AlternativeTextController::processMarkersOnTextToBeReplacedByResult):
+
+ When handling an acceptant candidate, set m_isHandlingAcceptedCandidate to
+ true while the text is being inserted, and then mark the range as an accepted
+ candidate.
+ * editing/Editor.cpp:
+ (WebCore::Editor::handleAcceptedCandidate):
+ * editing/Editor.h:
+ (WebCore::Editor::isHandlingAcceptedCandidate):
+
+ If frame.editor. isHandlingAcceptedCandidate() then return early from
+ markMisspellingsAfterTyping.
+ * editing/TypingCommand.cpp:
+ (WebCore::TypingCommand::markMisspellingsAfterTyping):
+
+ Add some test infrastructure.
+ * testing/Internals.cpp:
+ (WebCore::Internals::handleAcceptedCandidate):
+ * testing/Internals.h:
+ * testing/Internals.idl:
+
2016-02-03 Jer Noble <[email protected]>
[Win] Pass entire request (rather than just URL) to clients of WebCoreAVCFResourceLoader
Modified: trunk/Source/WebCore/dom/DocumentMarker.h (196089 => 196090)
--- trunk/Source/WebCore/dom/DocumentMarker.h 2016-02-04 00:00:24 UTC (rev 196089)
+++ trunk/Source/WebCore/dom/DocumentMarker.h 2016-02-04 00:01:46 UTC (rev 196090)
@@ -79,6 +79,8 @@
DictationPhraseWithAlternatives = 1 << 11,
DictationResult = 1 << 12,
#endif
+ // This marker indicates that the user has selected a text candidate.
+ AcceptedCandidate = 1 << 13,
};
class MarkerTypes {
@@ -102,12 +104,12 @@
AllMarkers()
#if !PLATFORM(IOS)
#if !ENABLE(TELEPHONE_NUMBER_DETECTION)
- : MarkerTypes(Spelling | Grammar | TextMatch | Replacement | CorrectionIndicator | RejectedCorrection | Autocorrected | SpellCheckingExemption | DeletedAutocorrection | DictationAlternatives)
+ : MarkerTypes(Spelling | Grammar | TextMatch | Replacement | CorrectionIndicator | RejectedCorrection | Autocorrected | SpellCheckingExemption | DeletedAutocorrection | DictationAlternatives | AcceptedCandidate)
#else
- : MarkerTypes(Spelling | Grammar | TextMatch | Replacement | CorrectionIndicator | RejectedCorrection | Autocorrected | SpellCheckingExemption | DeletedAutocorrection | DictationAlternatives | TelephoneNumber)
+ : MarkerTypes(Spelling | Grammar | TextMatch | Replacement | CorrectionIndicator | RejectedCorrection | Autocorrected | SpellCheckingExemption | DeletedAutocorrection | DictationAlternatives | TelephoneNumber | AcceptedCandidate)
#endif // !ENABLE(TELEPHONE_NUMBER_DETECTION)
#else
- : MarkerTypes(Spelling | Grammar | TextMatch | Replacement | CorrectionIndicator | RejectedCorrection | Autocorrected | SpellCheckingExemption | DeletedAutocorrection | DictationAlternatives | TelephoneNumber | DictationPhraseWithAlternatives | DictationResult)
+ : MarkerTypes(Spelling | Grammar | TextMatch | Replacement | CorrectionIndicator | RejectedCorrection | Autocorrected | SpellCheckingExemption | DeletedAutocorrection | DictationAlternatives | TelephoneNumber | DictationPhraseWithAlternatives | DictationResult | AcceptedCandidate)
#endif // !PLATFORM(IOS)
{
}
Modified: trunk/Source/WebCore/editing/AlternativeTextController.cpp (196089 => 196090)
--- trunk/Source/WebCore/editing/AlternativeTextController.cpp 2016-02-04 00:00:24 UTC (rev 196089)
+++ trunk/Source/WebCore/editing/AlternativeTextController.cpp 2016-02-04 00:01:46 UTC (rev 196090)
@@ -600,6 +600,9 @@
if (markerController.hasMarkers(rangeWithAlternative, DocumentMarker::RejectedCorrection))
return false;
+ if (markerController.hasMarkers(rangeWithAlternative, DocumentMarker::AcceptedCandidate))
+ return false;
+
Position beginningOfRange = rangeWithAlternative->startPosition();
Position precedingCharacterPosition = beginningOfRange.previous();
RefPtr<Range> precedingCharacterRange = Range::create(*m_frame.document(), precedingCharacterPosition, beginningOfRange);
Modified: trunk/Source/WebCore/editing/Editor.cpp (196089 => 196090)
--- trunk/Source/WebCore/editing/Editor.cpp 2016-02-04 00:00:24 UTC (rev 196089)
+++ trunk/Source/WebCore/editing/Editor.cpp 2016-02-04 00:01:46 UTC (rev 196090)
@@ -3557,15 +3557,26 @@
{
const VisibleSelection& selection = m_frame.selection().selection();
RefPtr<Range> candidateRange = candidateRangeForSelection(m_frame);
+ int candidateLength = acceptedCandidate.length;
+ m_isHandlingAcceptedCandidate = true;
+
if (candidateWouldReplaceText(selection))
m_frame.selection().setSelectedRange(candidateRange.get(), UPSTREAM, true);
insertText(acceptedCandidate.replacement, 0);
// Some candidates come with a space built in, and we do not need to add another space in that case.
- if (!acceptedCandidate.replacement.endsWith(' '))
+ if (!acceptedCandidate.replacement.endsWith(' ')) {
insertText(ASCIILiteral(" "), 0);
+ ++candidateLength;
+ }
+
+ RefPtr<Range> insertedCandidateRange = rangeExpandedAroundPositionByCharacters(selection.visibleStart(), candidateLength);
+ if (insertedCandidateRange)
+ insertedCandidateRange->startContainer().document().markers().addMarker(insertedCandidateRange.get(), DocumentMarker::AcceptedCandidate, acceptedCandidate.replacement);
+
+ m_isHandlingAcceptedCandidate = false;
}
bool Editor::unifiedTextCheckerEnabled() const
Modified: trunk/Source/WebCore/editing/Editor.h (196089 => 196090)
--- trunk/Source/WebCore/editing/Editor.h 2016-02-04 00:00:24 UTC (rev 196089)
+++ trunk/Source/WebCore/editing/Editor.h 2016-02-04 00:01:46 UTC (rev 196090)
@@ -457,6 +457,7 @@
WEBCORE_EXPORT String stringForCandidateRequest() const;
WEBCORE_EXPORT void handleAcceptedCandidate(TextCheckingResult);
+ bool isHandlingAcceptedCandidate() const { return m_isHandlingAcceptedCandidate; }
private:
class WebContentReader;
@@ -519,6 +520,7 @@
Timer m_editorUIUpdateTimer;
bool m_editorUIUpdateTimerShouldCheckSpellingAndGrammar;
bool m_editorUIUpdateTimerWasTriggeredByDictation;
+ bool m_isHandlingAcceptedCandidate { false };
#if ENABLE(TELEPHONE_NUMBER_DETECTION) && !PLATFORM(IOS)
bool shouldDetectTelephoneNumbers();
Modified: trunk/Source/WebCore/editing/TypingCommand.cpp (196089 => 196090)
--- trunk/Source/WebCore/editing/TypingCommand.cpp 2016-02-04 00:00:24 UTC (rev 196089)
+++ trunk/Source/WebCore/editing/TypingCommand.cpp 2016-02-04 00:01:46 UTC (rev 196090)
@@ -301,6 +301,8 @@
&& !frame.editor().isAutomaticDashSubstitutionEnabled()
&& !frame.editor().isAutomaticTextReplacementEnabled())
return;
+ if (frame.editor().isHandlingAcceptedCandidate())
+ return;
#else
if (!frame.editor().isContinuousSpellCheckingEnabled())
return;
Modified: trunk/Source/WebCore/testing/Internals.cpp (196089 => 196090)
--- trunk/Source/WebCore/testing/Internals.cpp 2016-02-04 00:00:24 UTC (rev 196089)
+++ trunk/Source/WebCore/testing/Internals.cpp 2016-02-04 00:01:46 UTC (rev 196090)
@@ -1790,6 +1790,18 @@
#endif
}
+void Internals::handleAcceptedCandidate(const String& candidate, ExceptionCode&)
+{
+ if (!contextDocument() || !contextDocument()->frame())
+ return;
+
+ TextCheckingResult result;
+ result.type = TextCheckingTypeNone;
+ result.length = candidate.length();
+ result.replacement = candidate;
+ contextDocument()->frame()->editor().handleAcceptedCandidate(result);
+}
+
bool Internals::isOverwriteModeEnabled(ExceptionCode&)
{
Document* document = contextDocument();
Modified: trunk/Source/WebCore/testing/Internals.h (196089 => 196090)
--- trunk/Source/WebCore/testing/Internals.h 2016-02-04 00:00:24 UTC (rev 196089)
+++ trunk/Source/WebCore/testing/Internals.h 2016-02-04 00:01:46 UTC (rev 196090)
@@ -221,6 +221,8 @@
void setAutomaticTextReplacementEnabled(bool enabled, ExceptionCode&);
void setAutomaticSpellingCorrectionEnabled(bool enabled, ExceptionCode&);
+ void handleAcceptedCandidate(const String& candidate, ExceptionCode&);
+
bool isOverwriteModeEnabled(ExceptionCode&);
void toggleOverwriteModeEnabled(ExceptionCode&);
Modified: trunk/Source/WebCore/testing/Internals.idl (196089 => 196090)
--- trunk/Source/WebCore/testing/Internals.idl 2016-02-04 00:00:24 UTC (rev 196089)
+++ trunk/Source/WebCore/testing/Internals.idl 2016-02-04 00:01:46 UTC (rev 196090)
@@ -205,6 +205,8 @@
[RaisesException] void setAutomaticTextReplacementEnabled(boolean enabled);
[RaisesException] void setAutomaticSpellingCorrectionEnabled(boolean enabled);
+ [RaisesException] void handleAcceptedCandidate(DOMString candidate);
+
[RaisesException] boolean isOverwriteModeEnabled();
[RaisesException] void toggleOverwriteModeEnabled();