Diff
Modified: trunk/Source/WebCore/ChangeLog (195080 => 195081)
--- trunk/Source/WebCore/ChangeLog 2016-01-14 23:07:44 UTC (rev 195080)
+++ trunk/Source/WebCore/ChangeLog 2016-01-15 00:07:36 UTC (rev 195081)
@@ -1,5 +1,21 @@
2016-01-14 Beth Dakin <[email protected]>
+ WK1 and WK2 should share more candidate request code
+ https://bugs.webkit.org/show_bug.cgi?id=153108
+
+ Reviewed by Simon Fraser.
+
+ requestCandidatesForSelection() does not need to be exposed as an
+ EditorClient function. WK1 can just call invoke this code from the existing
+ respondToChangedSelection EditorClient function, which is what WK2 does.
+ * editing/Editor.cpp:
+ (WebCore::Editor::respondToChangedSelection):
+ * loader/EmptyClients.h:
+ * page/EditorClient.h:
+ (WebCore::EditorClient::supportsGlobalSelection):
+
+2016-01-14 Beth Dakin <[email protected]>
+
WK2: Request completion candidates when needed
https://bugs.webkit.org/show_bug.cgi?id=153040
-and corresponding-
Modified: trunk/Source/WebCore/editing/Editor.cpp (195080 => 195081)
--- trunk/Source/WebCore/editing/Editor.cpp 2016-01-14 23:07:44 UTC (rev 195080)
+++ trunk/Source/WebCore/editing/Editor.cpp 2016-01-15 00:07:36 UTC (rev 195081)
@@ -3264,11 +3264,6 @@
if (client())
client()->respondToChangedSelection(&m_frame);
-#if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101200
- if (client() && canEdit())
- client()->requestCandidatesForSelection(m_frame.selection().selection());
-#endif
-
#if ENABLE(TELEPHONE_NUMBER_DETECTION) && !PLATFORM(IOS)
if (shouldDetectTelephoneNumbers())
m_telephoneNumberDetectionUpdateTimer.startOneShot(0);
Modified: trunk/Source/WebCore/loader/EmptyClients.h (195080 => 195081)
--- trunk/Source/WebCore/loader/EmptyClients.h 2016-01-14 23:07:44 UTC (rev 195080)
+++ trunk/Source/WebCore/loader/EmptyClients.h 2016-01-15 00:07:36 UTC (rev 195081)
@@ -537,10 +537,6 @@
virtual void willSetInputMethodState() override { }
virtual void setInputMethodState(bool) override { }
-#if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101200
- virtual void requestCandidatesForSelection(const VisibleSelection&) override { }
-#endif
-
private:
EmptyTextCheckerClient m_textCheckerClient;
};
Modified: trunk/Source/WebCore/page/EditorClient.h (195080 => 195081)
--- trunk/Source/WebCore/page/EditorClient.h 2016-01-14 23:07:44 UTC (rev 195080)
+++ trunk/Source/WebCore/page/EditorClient.h 2016-01-15 00:07:36 UTC (rev 195081)
@@ -186,10 +186,6 @@
// Support for global selections, used on platforms like the X Window System that treat
// selection as a type of clipboard.
virtual bool supportsGlobalSelection() { return false; }
-
-#if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101200
- virtual void requestCandidatesForSelection(const VisibleSelection&) = 0;
-#endif
};
}
Modified: trunk/Source/WebKit/mac/ChangeLog (195080 => 195081)
--- trunk/Source/WebKit/mac/ChangeLog 2016-01-14 23:07:44 UTC (rev 195080)
+++ trunk/Source/WebKit/mac/ChangeLog 2016-01-15 00:07:36 UTC (rev 195081)
@@ -1,3 +1,25 @@
+2016-01-14 Beth Dakin <[email protected]>
+
+ WK1 and WK2 should share more candidate request code
+ https://bugs.webkit.org/show_bug.cgi?id=153108
+
+ Reviewed by Simon Fraser.
+
+ requestCandidatesForSelection() does not need to be exposed as an
+ EditorClient function. WK1 can just call invoke this code from the existing
+ respondToChangedSelection EditorClient function, which is what WK2 does.
+ * WebCoreSupport/WebEditorClient.h:
+ * WebCoreSupport/WebEditorClient.mm:
+ (WebEditorClient::respondToChangedSelection):
+
+ Cleanup — use some code that was moved to WebCore::Editor.
+ (WebEditorClient::requestCandidatesForSelection):
+ (WebEditorClient::handleRequestedCandidates):
+ (textCheckingResultFromNSTextCheckingResult):
+ (WebEditorClient::handleAcceptedCandidate):
+ (candidateRangeForSelection): Deleted.
+ (candidateWouldReplaceText): Deleted.
+
2016-01-13 Chris Dumez <[email protected]>
Unreviewed, rolling out r194900.
Modified: trunk/Source/WebKit/mac/WebCoreSupport/WebEditorClient.h (195080 => 195081)
--- trunk/Source/WebKit/mac/WebCoreSupport/WebEditorClient.h 2016-01-14 23:07:44 UTC (rev 195080)
+++ trunk/Source/WebKit/mac/WebCoreSupport/WebEditorClient.h 2016-01-15 00:07:36 UTC (rev 195081)
@@ -170,7 +170,7 @@
virtual void requestCheckingOfString(PassRefPtr<WebCore::TextCheckingRequest>) override;
#if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101200
- virtual void requestCandidatesForSelection(const WebCore::VisibleSelection&) override;
+ void requestCandidatesForSelection(const WebCore::VisibleSelection&);
void handleRequestedCandidates(NSInteger, NSArray<NSTextCheckingResult *> *);
void handleAcceptedCandidate(NSTextCheckingResult *);
#endif
Modified: trunk/Source/WebKit/mac/WebCoreSupport/WebEditorClient.mm (195080 => 195081)
--- trunk/Source/WebKit/mac/WebCoreSupport/WebEditorClient.mm 2016-01-14 23:07:44 UTC (rev 195080)
+++ trunk/Source/WebKit/mac/WebCoreSupport/WebEditorClient.mm 2016-01-15 00:07:36 UTC (rev 195081)
@@ -367,6 +367,11 @@
if (![m_webView _isClosing])
WebThreadPostNotification(WebViewDidChangeSelectionNotification, m_webView, nil);
#endif
+
+#if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101200
+ if (frame->editor().canEdit())
+ requestCandidatesForSelection(frame->selection().selection());
+#endif
}
void WebEditorClient::discardedComposition(Frame*)
@@ -1124,15 +1129,12 @@
VisiblePosition selectionStart = selection.visibleStart();
VisiblePosition selectionEnd = selection.visibleEnd();
-
- // Use the surrounding paragraphs of text as context.
VisiblePosition paragraphStart = startOfParagraph(selectionStart);
VisiblePosition paragraphEnd = endOfParagraph(selectionEnd);
int lengthToSelectionStart = TextIterator::rangeLength(makeRange(paragraphStart, selectionStart).get());
int lengthToSelectionEnd = TextIterator::rangeLength(makeRange(paragraphStart, selectionEnd).get());
NSRange rangeForCandidates = NSMakeRange(lengthToSelectionStart, lengthToSelectionEnd - lengthToSelectionStart);
-
String fullPlainTextStringOfParagraph = plainText(makeRange(paragraphStart, paragraphEnd).get());
NSTextCheckingTypes checkingTypes = NSTextCheckingTypeSpelling | NSTextCheckingTypeReplacement | NSTextCheckingTypeCorrection;
@@ -1146,20 +1148,6 @@
}];
}
-static RefPtr<Range> candidateRangeForSelection(const VisibleSelection& selection, Frame* frame)
-{
- return selection.isCaret() ? wordRangeFromPosition(selection.start()) : frame->selection().toNormalizedRange();
-}
-
-static bool candidateWouldReplaceText(const VisibleSelection& selection)
-{
- // If the character behind the caret in the current selection is anything but a space or a newline then we should
- // replace the whole current word with the candidate.
- UChar32 characterAfterSelection, characterBeforeSelection, twoCharacterBeforeSelection = 0;
- charactersAroundPosition(selection.visibleStart(), characterAfterSelection, characterBeforeSelection, twoCharacterBeforeSelection);
- return !(characterBeforeSelection == '\0' || characterBeforeSelection == '\n' || characterBeforeSelection == ' ');
-}
-
void WebEditorClient::handleRequestedCandidates(NSInteger sequenceNumber, NSArray<NSTextCheckingResult *> *candidates)
{
Frame* frame = core([m_webView _selectedOrMainFrame]);
@@ -1170,14 +1158,7 @@
if (selection != m_lastSelectionForRequestedCandidates)
return;
- RefPtr<Range> rangeForCurrentlyTypedString = candidateRangeForSelection(selection, frame);
- NSString *currentlyTypedString;
- if (rangeForCurrentlyTypedString && candidateWouldReplaceText(selection))
- currentlyTypedString = plainText(rangeForCurrentlyTypedString.get());
- else
- currentlyTypedString = @"";
-
- RefPtr<Range> selectedRange = frame->selection().selection().toNormalizedRange();
+ RefPtr<Range> selectedRange = selection.toNormalizedRange();
if (!selectedRange)
return;
@@ -1188,7 +1169,7 @@
rectForSelectionCandidates = frame->view()->contentsToWindow(quads[0].enclosingBoundingBox());
auto weakEditor = m_weakPtrFactory.createWeakPtr();
- [[NSSpellChecker sharedSpellChecker] showCandidates:candidates forString:currentlyTypedString inRect:rectForSelectionCandidates view:m_webView completionHandler:[weakEditor](NSTextCheckingResult *acceptedCandidate) {
+ [[NSSpellChecker sharedSpellChecker] showCandidates:candidates forString:frame->editor().stringForCandidateRequest() inRect:rectForSelectionCandidates view:m_webView completionHandler:[weakEditor](NSTextCheckingResult *acceptedCandidate) {
dispatch_async(dispatch_get_main_queue(), ^{
if (!weakEditor)
return;
@@ -1198,6 +1179,32 @@
}
+static WebCore::TextCheckingResult textCheckingResultFromNSTextCheckingResult(NSTextCheckingResult *nsResult)
+{
+ WebCore::TextCheckingResult result;
+
+ switch ([nsResult resultType]) {
+ case NSTextCheckingTypeSpelling:
+ result.type = WebCore::TextCheckingTypeSpelling;
+ break;
+ case NSTextCheckingTypeReplacement:
+ result.type = WebCore::TextCheckingTypeReplacement;
+ break;
+ case NSTextCheckingTypeCorrection:
+ result.type = WebCore::TextCheckingTypeCorrection;
+ break;
+ default:
+ result.type = WebCore::TextCheckingTypeNone;
+ }
+
+ NSRange resultRange = [nsResult range];
+ result.location = resultRange.location;
+ result.length = resultRange.length;
+ result.replacement = [nsResult replacementString];
+
+ return result;
+}
+
void WebEditorClient::handleAcceptedCandidate(NSTextCheckingResult *acceptedCandidate)
{
Frame* frame = core([m_webView _selectedOrMainFrame]);
@@ -1208,16 +1215,7 @@
if (selection != m_lastSelectionForRequestedCandidates)
return;
- RefPtr<Range> candidateRange = candidateRangeForSelection(selection, frame);
-
- frame->editor().setIgnoreCompositionSelectionChange(true);
-
- if (candidateWouldReplaceText(selection))
- frame->selection().setSelectedRange(candidateRange.get(), UPSTREAM, true);
-
- frame->editor().insertText(acceptedCandidate.replacementString, 0);
- frame->editor().insertText(String(" "), 0);
- frame->editor().setIgnoreCompositionSelectionChange(false);
+ frame->editor().handleAcceptedCandidate(textCheckingResultFromNSTextCheckingResult(acceptedCandidate));
}
#endif // PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101200
Modified: trunk/Source/WebKit2/ChangeLog (195080 => 195081)
--- trunk/Source/WebKit2/ChangeLog 2016-01-14 23:07:44 UTC (rev 195080)
+++ trunk/Source/WebKit2/ChangeLog 2016-01-15 00:07:36 UTC (rev 195081)
@@ -1,5 +1,17 @@
2016-01-14 Beth Dakin <[email protected]>
+ WK1 and WK2 should share more candidate request code
+ https://bugs.webkit.org/show_bug.cgi?id=153108
+
+ Reviewed by Simon Fraser.
+
+ requestCandidatesForSelection() does not need to be exposed as an
+ EditorClient function. WK1 can just call invoke this code from the existing
+ respondToChangedSelection EditorClient function, which is what WK2 does.
+ * WebProcess/WebCoreSupport/WebEditorClient.h:
+
+2016-01-14 Beth Dakin <[email protected]>
+
WK2: Request completion candidates when needed
https://bugs.webkit.org/show_bug.cgi?id=153040
-and corresponding-
Modified: trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebEditorClient.h (195080 => 195081)
--- trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebEditorClient.h 2016-01-14 23:07:44 UTC (rev 195080)
+++ trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebEditorClient.h 2016-01-15 00:07:36 UTC (rev 195081)
@@ -150,10 +150,6 @@
virtual void setInputMethodState(bool enabled) override;
virtual void requestCheckingOfString(WTF::PassRefPtr<WebCore::TextCheckingRequest>) override;
-#if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101200
- virtual void requestCandidatesForSelection(const WebCore::VisibleSelection&) override { }
-#endif
-
#if PLATFORM(GTK)
virtual bool shouldShowUnicodeMenu() override;
#endif