Title: [191761] trunk/Source/WebKit2
Revision
191761
Author
[email protected]
Date
2015-10-29 16:13:10 -0700 (Thu, 29 Oct 2015)

Log Message

WKView being inside WKWebView leads to weird API issues
https://bugs.webkit.org/show_bug.cgi?id=150174

Reviewed by Anders Carlsson.

* Platform/spi/mac/AppKitSPI.h:
* UIProcess/API/mac/WKView.mm:
(-[WKView validRequestorForSendType:returnType:]):
(-[WKView readSelectionFromPasteboard:]):
(-[WKView changeFont:]):
(-[WKView startSpeaking:]):
(-[WKView stopSpeaking:]):
(-[WKView showGuessPanel:]):
(-[WKView checkSpelling:]):
(-[WKView changeSpelling:]):
(-[WKView toggleContinuousSpellChecking:]):
(-[WKView isGrammarCheckingEnabled]):
(-[WKView setGrammarCheckingEnabled:]):
(-[WKView toggleGrammarChecking:]):
(-[WKView toggleAutomaticSpellingCorrection:]):
(-[WKView orderFrontSubstitutionsPanel:]):
(-[WKView toggleSmartInsertDelete:]):
(-[WKView isAutomaticQuoteSubstitutionEnabled]):
(-[WKView setAutomaticQuoteSubstitutionEnabled:]):
(-[WKView toggleAutomaticQuoteSubstitution:]):
(-[WKView isAutomaticDashSubstitutionEnabled]):
(-[WKView setAutomaticDashSubstitutionEnabled:]):
(-[WKView toggleAutomaticDashSubstitution:]):
(-[WKView isAutomaticLinkDetectionEnabled]):
(-[WKView setAutomaticLinkDetectionEnabled:]):
(-[WKView toggleAutomaticLinkDetection:]):
(-[WKView isAutomaticTextReplacementEnabled]):
(-[WKView setAutomaticTextReplacementEnabled:]):
(-[WKView toggleAutomaticTextReplacement:]):
(-[WKView uppercaseWord:]):
(-[WKView lowercaseWord:]):
(-[WKView capitalizeWord:]):
* UIProcess/Cocoa/WebViewImpl.h:
* UIProcess/Cocoa/WebViewImpl.mm:
(WebKit::WebViewImpl::readSelectionFromPasteboard):
(WebKit::WebViewImpl::validRequestorForSendAndReturnTypes):
(WebKit::WebViewImpl::changeFontFromFontPanel):
(WebKit::WebViewImpl::startSpeaking):
(WebKit::WebViewImpl::stopSpeaking):
(WebKit::WebViewImpl::showGuessPanel):
(WebKit::WebViewImpl::checkSpelling):
(WebKit::WebViewImpl::changeSpelling):
(WebKit::WebViewImpl::toggleContinuousSpellChecking):
(WebKit::WebViewImpl::isGrammarCheckingEnabled):
(WebKit::WebViewImpl::setGrammarCheckingEnabled):
(WebKit::WebViewImpl::toggleGrammarChecking):
(WebKit::WebViewImpl::toggleAutomaticSpellingCorrection):
(WebKit::WebViewImpl::orderFrontSubstitutionsPanel):
(WebKit::WebViewImpl::toggleSmartInsertDelete):
(WebKit::WebViewImpl::isAutomaticQuoteSubstitutionEnabled):
(WebKit::WebViewImpl::setAutomaticQuoteSubstitutionEnabled):
(WebKit::WebViewImpl::toggleAutomaticQuoteSubstitution):
(WebKit::WebViewImpl::isAutomaticDashSubstitutionEnabled):
(WebKit::WebViewImpl::setAutomaticDashSubstitutionEnabled):
(WebKit::WebViewImpl::toggleAutomaticDashSubstitution):
(WebKit::WebViewImpl::isAutomaticLinkDetectionEnabled):
(WebKit::WebViewImpl::setAutomaticLinkDetectionEnabled):
(WebKit::WebViewImpl::toggleAutomaticLinkDetection):
(WebKit::WebViewImpl::setAutomaticTextReplacementEnabled):
(WebKit::WebViewImpl::toggleAutomaticTextReplacement):
(WebKit::WebViewImpl::uppercaseWord):
(WebKit::WebViewImpl::lowercaseWord):
(WebKit::WebViewImpl::capitalizeWord):
Move spellcheck and related bits.

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (191760 => 191761)


--- trunk/Source/WebKit2/ChangeLog	2015-10-29 22:35:37 UTC (rev 191760)
+++ trunk/Source/WebKit2/ChangeLog	2015-10-29 23:13:10 UTC (rev 191761)
@@ -1,3 +1,75 @@
+2015-10-29  Tim Horton  <[email protected]>
+
+        WKView being inside WKWebView leads to weird API issues
+        https://bugs.webkit.org/show_bug.cgi?id=150174
+
+        Reviewed by Anders Carlsson.
+
+        * Platform/spi/mac/AppKitSPI.h:
+        * UIProcess/API/mac/WKView.mm:
+        (-[WKView validRequestorForSendType:returnType:]):
+        (-[WKView readSelectionFromPasteboard:]):
+        (-[WKView changeFont:]):
+        (-[WKView startSpeaking:]):
+        (-[WKView stopSpeaking:]):
+        (-[WKView showGuessPanel:]):
+        (-[WKView checkSpelling:]):
+        (-[WKView changeSpelling:]):
+        (-[WKView toggleContinuousSpellChecking:]):
+        (-[WKView isGrammarCheckingEnabled]):
+        (-[WKView setGrammarCheckingEnabled:]):
+        (-[WKView toggleGrammarChecking:]):
+        (-[WKView toggleAutomaticSpellingCorrection:]):
+        (-[WKView orderFrontSubstitutionsPanel:]):
+        (-[WKView toggleSmartInsertDelete:]):
+        (-[WKView isAutomaticQuoteSubstitutionEnabled]):
+        (-[WKView setAutomaticQuoteSubstitutionEnabled:]):
+        (-[WKView toggleAutomaticQuoteSubstitution:]):
+        (-[WKView isAutomaticDashSubstitutionEnabled]):
+        (-[WKView setAutomaticDashSubstitutionEnabled:]):
+        (-[WKView toggleAutomaticDashSubstitution:]):
+        (-[WKView isAutomaticLinkDetectionEnabled]):
+        (-[WKView setAutomaticLinkDetectionEnabled:]):
+        (-[WKView toggleAutomaticLinkDetection:]):
+        (-[WKView isAutomaticTextReplacementEnabled]):
+        (-[WKView setAutomaticTextReplacementEnabled:]):
+        (-[WKView toggleAutomaticTextReplacement:]):
+        (-[WKView uppercaseWord:]):
+        (-[WKView lowercaseWord:]):
+        (-[WKView capitalizeWord:]):
+        * UIProcess/Cocoa/WebViewImpl.h:
+        * UIProcess/Cocoa/WebViewImpl.mm:
+        (WebKit::WebViewImpl::readSelectionFromPasteboard):
+        (WebKit::WebViewImpl::validRequestorForSendAndReturnTypes):
+        (WebKit::WebViewImpl::changeFontFromFontPanel):
+        (WebKit::WebViewImpl::startSpeaking):
+        (WebKit::WebViewImpl::stopSpeaking):
+        (WebKit::WebViewImpl::showGuessPanel):
+        (WebKit::WebViewImpl::checkSpelling):
+        (WebKit::WebViewImpl::changeSpelling):
+        (WebKit::WebViewImpl::toggleContinuousSpellChecking):
+        (WebKit::WebViewImpl::isGrammarCheckingEnabled):
+        (WebKit::WebViewImpl::setGrammarCheckingEnabled):
+        (WebKit::WebViewImpl::toggleGrammarChecking):
+        (WebKit::WebViewImpl::toggleAutomaticSpellingCorrection):
+        (WebKit::WebViewImpl::orderFrontSubstitutionsPanel):
+        (WebKit::WebViewImpl::toggleSmartInsertDelete):
+        (WebKit::WebViewImpl::isAutomaticQuoteSubstitutionEnabled):
+        (WebKit::WebViewImpl::setAutomaticQuoteSubstitutionEnabled):
+        (WebKit::WebViewImpl::toggleAutomaticQuoteSubstitution):
+        (WebKit::WebViewImpl::isAutomaticDashSubstitutionEnabled):
+        (WebKit::WebViewImpl::setAutomaticDashSubstitutionEnabled):
+        (WebKit::WebViewImpl::toggleAutomaticDashSubstitution):
+        (WebKit::WebViewImpl::isAutomaticLinkDetectionEnabled):
+        (WebKit::WebViewImpl::setAutomaticLinkDetectionEnabled):
+        (WebKit::WebViewImpl::toggleAutomaticLinkDetection):
+        (WebKit::WebViewImpl::setAutomaticTextReplacementEnabled):
+        (WebKit::WebViewImpl::toggleAutomaticTextReplacement):
+        (WebKit::WebViewImpl::uppercaseWord):
+        (WebKit::WebViewImpl::lowercaseWord):
+        (WebKit::WebViewImpl::capitalizeWord):
+        Move spellcheck and related bits.
+
 2015-10-29  Eric Carlson  <[email protected]>
 
         Revert inadvertent changes

Modified: trunk/Source/WebKit2/Platform/spi/mac/AppKitSPI.h (191760 => 191761)


--- trunk/Source/WebKit2/Platform/spi/mac/AppKitSPI.h	2015-10-29 22:35:37 UTC (rev 191760)
+++ trunk/Source/WebKit2/Platform/spi/mac/AppKitSPI.h	2015-10-29 23:13:10 UTC (rev 191761)
@@ -36,3 +36,10 @@
 @end
 
 #endif // USE(APPLE_INTERNAL_SDK)
+
+@interface NSApplication ()
+
+- (void)speakString:(NSString *)string;
+- (void)_setCurrentEvent:(NSEvent *)event;
+
+@end

Modified: trunk/Source/WebKit2/UIProcess/API/mac/WKView.mm (191760 => 191761)


--- trunk/Source/WebKit2/UIProcess/API/mac/WKView.mm	2015-10-29 22:35:37 UTC (rev 191760)
+++ trunk/Source/WebKit2/UIProcess/API/mac/WKView.mm	2015-10-29 23:13:10 UTC (rev 191761)
@@ -35,6 +35,7 @@
 
 #import "APILegacyContextHistoryClient.h"
 #import "APIPageConfiguration.h"
+#import "AppKitSPI.h"
 #import "AttributedString.h"
 #import "DataReference.h"
 #import "EditingRange.h"
@@ -109,11 +110,6 @@
 #import "WKBrowsingContextGroupPrivate.h"
 #import "WKProcessGroupPrivate.h"
 
-@interface NSApplication (WKNSApplicationDetails)
-- (void)speakString:(NSString *)string;
-- (void)_setCurrentEvent:(NSEvent *)event;
-@end
-
 #if USE(ASYNC_NSTEXTINPUTCLIENT)
 @interface NSTextInputContext (WKNSTextInputContextDetails)
 - (void)handleEvent:(NSEvent *)theEvent completionHandler:(void(^)(BOOL handled))completionHandler;
@@ -381,8 +377,6 @@
 
 #undef WEBCORE_COMMAND
 
-// This method is needed to support Mac OS X services.
-
 - (BOOL)writeSelectionToPasteboard:(NSPasteboard *)pasteboard types:(NSArray *)types
 {
     return _data->_impl->writeSelectionToPasteboard(pasteboard, types);
@@ -393,48 +387,19 @@
     _data->_impl->centerSelectionInVisibleArea();
 }
 
-// This method is needed to support Mac OS X services.
-
 - (id)validRequestorForSendType:(NSString *)sendType returnType:(NSString *)returnType
 {
-    EditorState editorState = _data->_page->editorState();
-    BOOL isValidSendType = NO;
-
-    if (sendType && !editorState.selectionIsNone) {
-        if (editorState.isInPlugin)
-            isValidSendType = [sendType isEqualToString:NSStringPboardType];
-        else
-            isValidSendType = [PasteboardTypes::forSelection() containsObject:sendType];
-    }
-
-    BOOL isValidReturnType = NO;
-    if (!returnType)
-        isValidReturnType = YES;
-    else if ([PasteboardTypes::forEditing() containsObject:returnType] && editorState.isContentEditable) {
-        // We can insert strings in any editable context.  We can insert other types, like images, only in rich edit contexts.
-        isValidReturnType = editorState.isContentRichlyEditable || [returnType isEqualToString:NSStringPboardType];
-    }
-    if (isValidSendType && isValidReturnType)
-        return self;
-    return [[self nextResponder] validRequestorForSendType:sendType returnType:returnType];
+    return _data->_impl->validRequestorForSendAndReturnTypes(sendType, returnType);
 }
 
-// This method is needed to support Mac OS X services.
-
 - (BOOL)readSelectionFromPasteboard:(NSPasteboard *)pasteboard 
 {
-    return _data->_page->readSelectionFromPasteboard([pasteboard name]);
+    return _data->_impl->readSelectionFromPasteboard(pasteboard);
 }
 
-// Font panel support.
-
 - (void)changeFont:(id)sender
 {
-    NSFontManager *fontManager = [NSFontManager sharedFontManager];
-    NSFont *font = [fontManager convertFont:[fontManager selectedFont]];
-    if (!font)
-        return;
-    _data->_page->setFont([font familyName], [font pointSize], [[font fontDescriptor] symbolicTraits]);
+    _data->_impl->changeFontFromFontPanel();
 }
 
 /*
@@ -475,202 +440,137 @@
 
 - (IBAction)startSpeaking:(id)sender
 {
-    _data->_page->getSelectionOrContentsAsString([self](const String& string, WebKit::CallbackBase::Error error) {
-        if (error != WebKit::CallbackBase::Error::None)
-            return;
-        if (!string)
-            return;
-
-        [NSApp speakString:string];
-    });
+    _data->_impl->startSpeaking();
 }
 
 - (IBAction)stopSpeaking:(id)sender
 {
-    [NSApp stopSpeaking:sender];
+    _data->_impl->stopSpeaking(sender);
 }
 
 - (IBAction)showGuessPanel:(id)sender
 {
-    NSSpellChecker *checker = [NSSpellChecker sharedSpellChecker];
-    if (!checker) {
-        LOG_ERROR("No NSSpellChecker");
-        return;
-    }
-    
-    NSPanel *spellingPanel = [checker spellingPanel];
-    if ([spellingPanel isVisible]) {
-        [spellingPanel orderOut:sender];
-        return;
-    }
-    
-    _data->_page->advanceToNextMisspelling(true);
-    [spellingPanel orderFront:sender];
+    _data->_impl->showGuessPanel(sender);
 }
 
 - (IBAction)checkSpelling:(id)sender
 {
-    _data->_page->advanceToNextMisspelling(false);
+    _data->_impl->checkSpelling();
 }
 
 - (void)changeSpelling:(id)sender
 {
-    NSString *word = [[sender selectedCell] stringValue];
-
-    _data->_page->changeSpellingToWord(word);
+    _data->_impl->changeSpelling(sender);
 }
 
 - (IBAction)toggleContinuousSpellChecking:(id)sender
 {
-    bool spellCheckingEnabled = !TextChecker::state().isContinuousSpellCheckingEnabled;
-    TextChecker::setContinuousSpellCheckingEnabled(spellCheckingEnabled);
-
-    _data->_page->process().updateTextCheckerState();
+    _data->_impl->toggleContinuousSpellChecking();
 }
 
 - (BOOL)isGrammarCheckingEnabled
 {
-    return TextChecker::state().isGrammarCheckingEnabled;
+    return _data->_impl->isGrammarCheckingEnabled();
 }
 
 - (void)setGrammarCheckingEnabled:(BOOL)flag
 {
-    if (static_cast<bool>(flag) == TextChecker::state().isGrammarCheckingEnabled)
-        return;
-    
-    TextChecker::setGrammarCheckingEnabled(flag);
-    _data->_page->process().updateTextCheckerState();
+    _data->_impl->setGrammarCheckingEnabled(flag);
 }
 
 - (IBAction)toggleGrammarChecking:(id)sender
 {
-    bool grammarCheckingEnabled = !TextChecker::state().isGrammarCheckingEnabled;
-    TextChecker::setGrammarCheckingEnabled(grammarCheckingEnabled);
-
-    _data->_page->process().updateTextCheckerState();
+    _data->_impl->toggleGrammarChecking();
 }
 
 - (IBAction)toggleAutomaticSpellingCorrection:(id)sender
 {
-    TextChecker::setAutomaticSpellingCorrectionEnabled(!TextChecker::state().isAutomaticSpellingCorrectionEnabled);
-
-    _data->_page->process().updateTextCheckerState();
+    _data->_impl->toggleAutomaticSpellingCorrection();
 }
 
 - (void)orderFrontSubstitutionsPanel:(id)sender
 {
-    NSSpellChecker *checker = [NSSpellChecker sharedSpellChecker];
-    if (!checker) {
-        LOG_ERROR("No NSSpellChecker");
-        return;
-    }
-    
-    NSPanel *substitutionsPanel = [checker substitutionsPanel];
-    if ([substitutionsPanel isVisible]) {
-        [substitutionsPanel orderOut:sender];
-        return;
-    }
-    [substitutionsPanel orderFront:sender];
+    _data->_impl->orderFrontSubstitutionsPanel(sender);
 }
 
 - (IBAction)toggleSmartInsertDelete:(id)sender
 {
-    _data->_page->setSmartInsertDeleteEnabled(!_data->_page->isSmartInsertDeleteEnabled());
+    _data->_impl->toggleSmartInsertDelete();
 }
 
 - (BOOL)isAutomaticQuoteSubstitutionEnabled
 {
-    return TextChecker::state().isAutomaticQuoteSubstitutionEnabled;
+    return _data->_impl->isAutomaticQuoteSubstitutionEnabled();
 }
 
 - (void)setAutomaticQuoteSubstitutionEnabled:(BOOL)flag
 {
-    if (static_cast<bool>(flag) == TextChecker::state().isAutomaticQuoteSubstitutionEnabled)
-        return;
-
-    TextChecker::setAutomaticQuoteSubstitutionEnabled(flag);
-    _data->_page->process().updateTextCheckerState();
+    _data->_impl->setAutomaticQuoteSubstitutionEnabled(flag);
 }
 
 - (void)toggleAutomaticQuoteSubstitution:(id)sender
 {
-    TextChecker::setAutomaticQuoteSubstitutionEnabled(!TextChecker::state().isAutomaticQuoteSubstitutionEnabled);
-    _data->_page->process().updateTextCheckerState();
+    _data->_impl->toggleAutomaticQuoteSubstitution();
 }
 
 - (BOOL)isAutomaticDashSubstitutionEnabled
 {
-    return TextChecker::state().isAutomaticDashSubstitutionEnabled;
+    return _data->_impl->isAutomaticDashSubstitutionEnabled();
 }
 
 - (void)setAutomaticDashSubstitutionEnabled:(BOOL)flag
 {
-    if (static_cast<bool>(flag) == TextChecker::state().isAutomaticDashSubstitutionEnabled)
-        return;
-
-    TextChecker::setAutomaticDashSubstitutionEnabled(flag);
-    _data->_page->process().updateTextCheckerState();
+    _data->_impl->setAutomaticDashSubstitutionEnabled(flag);
 }
 
 - (void)toggleAutomaticDashSubstitution:(id)sender
 {
-    TextChecker::setAutomaticDashSubstitutionEnabled(!TextChecker::state().isAutomaticDashSubstitutionEnabled);
-    _data->_page->process().updateTextCheckerState();
+    _data->_impl->toggleAutomaticDashSubstitution();
 }
 
 - (BOOL)isAutomaticLinkDetectionEnabled
 {
-    return TextChecker::state().isAutomaticLinkDetectionEnabled;
+    return _data->_impl->isAutomaticLinkDetectionEnabled();
 }
 
 - (void)setAutomaticLinkDetectionEnabled:(BOOL)flag
 {
-    if (static_cast<bool>(flag) == TextChecker::state().isAutomaticLinkDetectionEnabled)
-        return;
-
-    TextChecker::setAutomaticLinkDetectionEnabled(flag);
-    _data->_page->process().updateTextCheckerState();
+    _data->_impl->setAutomaticLinkDetectionEnabled(flag);
 }
 
 - (void)toggleAutomaticLinkDetection:(id)sender
 {
-    TextChecker::setAutomaticLinkDetectionEnabled(!TextChecker::state().isAutomaticLinkDetectionEnabled);
-    _data->_page->process().updateTextCheckerState();
+    _data->_impl->toggleAutomaticLinkDetection();
 }
 
 - (BOOL)isAutomaticTextReplacementEnabled
 {
-    return TextChecker::state().isAutomaticTextReplacementEnabled;
+    return _data->_impl->isAutomaticTextReplacementEnabled();
 }
 
 - (void)setAutomaticTextReplacementEnabled:(BOOL)flag
 {
-    if (static_cast<bool>(flag) == TextChecker::state().isAutomaticTextReplacementEnabled)
-        return;
-
-    TextChecker::setAutomaticTextReplacementEnabled(flag);
-    _data->_page->process().updateTextCheckerState();
+    _data->_impl->setAutomaticTextReplacementEnabled(flag);
 }
 
 - (void)toggleAutomaticTextReplacement:(id)sender
 {
-    TextChecker::setAutomaticTextReplacementEnabled(!TextChecker::state().isAutomaticTextReplacementEnabled);
-    _data->_page->process().updateTextCheckerState();
+    _data->_impl->toggleAutomaticTextReplacement();
 }
 
 - (void)uppercaseWord:(id)sender
 {
-    _data->_page->uppercaseWord();
+    _data->_impl->uppercaseWord();
 }
 
 - (void)lowercaseWord:(id)sender
 {
-    _data->_page->lowercaseWord();
+    _data->_impl->lowercaseWord();
 }
 
 - (void)capitalizeWord:(id)sender
 {
-    _data->_page->capitalizeWord();
+    _data->_impl->capitalizeWord();
 }
 
 // Events

Modified: trunk/Source/WebKit2/UIProcess/Cocoa/WebViewImpl.h (191760 => 191761)


--- trunk/Source/WebKit2/UIProcess/Cocoa/WebViewImpl.h	2015-10-29 22:35:37 UTC (rev 191760)
+++ trunk/Source/WebKit2/UIProcess/Cocoa/WebViewImpl.h	2015-10-29 23:13:10 UTC (rev 191761)
@@ -230,12 +230,45 @@
     void registerEditCommand(RefPtr<WebEditCommandProxy>, WebPageProxy::UndoOrRedo);
     void clearAllEditCommands();
     bool writeSelectionToPasteboard(NSPasteboard *, NSArray *types);
+    bool readSelectionFromPasteboard(NSPasteboard *);
+    id validRequestorForSendAndReturnTypes(NSString *sendType, NSString *returnType);
     void centerSelectionInVisibleArea();
     void selectionDidChange();
     void startObservingFontPanel();
     void updateFontPanelIfNeeded();
+    void changeFontFromFontPanel();
     bool validateUserInterfaceItem(id <NSValidatedUserInterfaceItem>);
 
+    void startSpeaking();
+    void stopSpeaking(id);
+
+    void showGuessPanel(id);
+    void checkSpelling();
+    void changeSpelling(id);
+    void toggleContinuousSpellChecking();
+
+    bool isGrammarCheckingEnabled();
+    void setGrammarCheckingEnabled(bool);
+    void toggleGrammarChecking();
+    void toggleAutomaticSpellingCorrection();
+    void orderFrontSubstitutionsPanel(id);
+    void toggleSmartInsertDelete();
+    bool isAutomaticQuoteSubstitutionEnabled();
+    void setAutomaticQuoteSubstitutionEnabled(bool);
+    void toggleAutomaticQuoteSubstitution();
+    bool isAutomaticDashSubstitutionEnabled();
+    void setAutomaticDashSubstitutionEnabled(bool);
+    void toggleAutomaticDashSubstitution();
+    bool isAutomaticLinkDetectionEnabled();
+    void setAutomaticLinkDetectionEnabled(bool);
+    void toggleAutomaticLinkDetection();
+    bool isAutomaticTextReplacementEnabled();
+    void setAutomaticTextReplacementEnabled(bool);
+    void toggleAutomaticTextReplacement();
+    void uppercaseWord();
+    void lowercaseWord();
+    void capitalizeWord();
+
     void preferencesDidChange();
 
     void setTextIndicator(WebCore::TextIndicator&, WebCore::TextIndicatorWindowLifetime = WebCore::TextIndicatorWindowLifetime::Permanent);

Modified: trunk/Source/WebKit2/UIProcess/Cocoa/WebViewImpl.mm (191760 => 191761)


--- trunk/Source/WebKit2/UIProcess/Cocoa/WebViewImpl.mm	2015-10-29 22:35:37 UTC (rev 191760)
+++ trunk/Source/WebKit2/UIProcess/Cocoa/WebViewImpl.mm	2015-10-29 23:13:10 UTC (rev 191761)
@@ -28,6 +28,7 @@
 
 #if PLATFORM(MAC)
 
+#import "AppKitSPI.h"
 #import "ColorSpaceData.h"
 #import "GenericCallback.h"
 #import "Logging.h"
@@ -1583,6 +1584,35 @@
     return true;
 }
 
+bool WebViewImpl::readSelectionFromPasteboard(NSPasteboard *pasteboard)
+{
+    return m_page.readSelectionFromPasteboard([pasteboard name]);
+}
+
+id WebViewImpl::validRequestorForSendAndReturnTypes(NSString *sendType, NSString *returnType)
+{
+    EditorState editorState = m_page.editorState();
+    bool isValidSendType = false;
+
+    if (sendType && !editorState.selectionIsNone) {
+        if (editorState.isInPlugin)
+            isValidSendType = [sendType isEqualToString:NSStringPboardType];
+        else
+            isValidSendType = [PasteboardTypes::forSelection() containsObject:sendType];
+    }
+
+    bool isValidReturnType = false;
+    if (!returnType)
+        isValidReturnType = true;
+    else if ([PasteboardTypes::forEditing() containsObject:returnType] && editorState.isContentEditable) {
+        // We can insert strings in any editable context.  We can insert other types, like images, only in rich edit contexts.
+        isValidReturnType = editorState.isContentRichlyEditable || [returnType isEqualToString:NSStringPboardType];
+    }
+    if (isValidSendType && isValidReturnType)
+        return m_view;
+    return [[m_view nextResponder] validRequestorForSendType:sendType returnType:returnType];
+}
+
 void WebViewImpl::centerSelectionInVisibleArea()
 {
     m_page.centerSelectionInVisibleArea();
@@ -1612,6 +1642,15 @@
     }
 }
 
+void WebViewImpl::changeFontFromFontPanel()
+{
+    NSFontManager *fontManager = [NSFontManager sharedFontManager];
+    NSFont *font = [fontManager convertFont:fontManager.selectedFont];
+    if (!font)
+        return;
+    m_page.setFont(font.familyName, font.pointSize, font.fontDescriptor.symbolicTraits);
+}
+
 static NSMenuItem *menuItem(id <NSValidatedUserInterfaceItem> item)
 {
     if (![(NSObject *)item isKindOfClass:[NSMenuItem class]])
@@ -1747,6 +1786,206 @@
     }
 }
 
+void WebViewImpl::startSpeaking()
+{
+    m_page.getSelectionOrContentsAsString([](const String& string, WebKit::CallbackBase::Error error) {
+        if (error != WebKit::CallbackBase::Error::None)
+            return;
+        if (!string)
+            return;
+
+        [NSApp speakString:string];
+    });
+}
+
+void WebViewImpl::stopSpeaking(id sender)
+{
+    [NSApp stopSpeaking:sender];
+}
+
+void WebViewImpl::showGuessPanel(id sender)
+{
+    NSSpellChecker *checker = [NSSpellChecker sharedSpellChecker];
+    if (!checker) {
+        LOG_ERROR("No NSSpellChecker");
+        return;
+    }
+
+    NSPanel *spellingPanel = [checker spellingPanel];
+    if ([spellingPanel isVisible]) {
+        [spellingPanel orderOut:sender];
+        return;
+    }
+
+    m_page.advanceToNextMisspelling(true);
+    [spellingPanel orderFront:sender];
+}
+
+void WebViewImpl::checkSpelling()
+{
+    m_page.advanceToNextMisspelling(false);
+}
+
+void WebViewImpl::changeSpelling(id sender)
+{
+    NSString *word = [[sender selectedCell] stringValue];
+
+    m_page.changeSpellingToWord(word);
+}
+
+void WebViewImpl::toggleContinuousSpellChecking()
+{
+    bool spellCheckingEnabled = !TextChecker::state().isContinuousSpellCheckingEnabled;
+    TextChecker::setContinuousSpellCheckingEnabled(spellCheckingEnabled);
+
+    m_page.process().updateTextCheckerState();
+}
+
+bool WebViewImpl::isGrammarCheckingEnabled()
+{
+    return TextChecker::state().isGrammarCheckingEnabled;
+}
+
+void WebViewImpl::setGrammarCheckingEnabled(bool flag)
+{
+    if (static_cast<bool>(flag) == TextChecker::state().isGrammarCheckingEnabled)
+        return;
+
+    TextChecker::setGrammarCheckingEnabled(flag);
+    m_page.process().updateTextCheckerState();
+}
+
+void WebViewImpl::toggleGrammarChecking()
+{
+    bool grammarCheckingEnabled = !TextChecker::state().isGrammarCheckingEnabled;
+    TextChecker::setGrammarCheckingEnabled(grammarCheckingEnabled);
+
+    m_page.process().updateTextCheckerState();
+}
+
+void WebViewImpl::toggleAutomaticSpellingCorrection()
+{
+    TextChecker::setAutomaticSpellingCorrectionEnabled(!TextChecker::state().isAutomaticSpellingCorrectionEnabled);
+
+    m_page.process().updateTextCheckerState();
+}
+
+void WebViewImpl::orderFrontSubstitutionsPanel(id sender)
+{
+    NSSpellChecker *checker = [NSSpellChecker sharedSpellChecker];
+    if (!checker) {
+        LOG_ERROR("No NSSpellChecker");
+        return;
+    }
+
+    NSPanel *substitutionsPanel = [checker substitutionsPanel];
+    if ([substitutionsPanel isVisible]) {
+        [substitutionsPanel orderOut:sender];
+        return;
+    }
+    [substitutionsPanel orderFront:sender];
+}
+
+void WebViewImpl::toggleSmartInsertDelete()
+{
+    m_page.setSmartInsertDeleteEnabled(!m_page.isSmartInsertDeleteEnabled());
+}
+
+bool WebViewImpl::isAutomaticQuoteSubstitutionEnabled()
+{
+    return TextChecker::state().isAutomaticQuoteSubstitutionEnabled;
+}
+
+void WebViewImpl::setAutomaticQuoteSubstitutionEnabled(bool flag)
+{
+    if (static_cast<bool>(flag) == TextChecker::state().isAutomaticQuoteSubstitutionEnabled)
+        return;
+
+    TextChecker::setAutomaticQuoteSubstitutionEnabled(flag);
+    m_page.process().updateTextCheckerState();
+}
+
+void WebViewImpl::toggleAutomaticQuoteSubstitution()
+{
+    TextChecker::setAutomaticQuoteSubstitutionEnabled(!TextChecker::state().isAutomaticQuoteSubstitutionEnabled);
+    m_page.process().updateTextCheckerState();
+}
+
+bool WebViewImpl::isAutomaticDashSubstitutionEnabled()
+{
+    return TextChecker::state().isAutomaticDashSubstitutionEnabled;
+}
+
+void WebViewImpl::setAutomaticDashSubstitutionEnabled(bool flag)
+{
+    if (static_cast<bool>(flag) == TextChecker::state().isAutomaticDashSubstitutionEnabled)
+        return;
+
+    TextChecker::setAutomaticDashSubstitutionEnabled(flag);
+    m_page.process().updateTextCheckerState();
+}
+
+void WebViewImpl::toggleAutomaticDashSubstitution()
+{
+    TextChecker::setAutomaticDashSubstitutionEnabled(!TextChecker::state().isAutomaticDashSubstitutionEnabled);
+    m_page.process().updateTextCheckerState();
+}
+
+bool WebViewImpl::isAutomaticLinkDetectionEnabled()
+{
+    return TextChecker::state().isAutomaticLinkDetectionEnabled;
+}
+
+void WebViewImpl::setAutomaticLinkDetectionEnabled(bool flag)
+{
+    if (static_cast<bool>(flag) == TextChecker::state().isAutomaticLinkDetectionEnabled)
+        return;
+
+    TextChecker::setAutomaticLinkDetectionEnabled(flag);
+    m_page.process().updateTextCheckerState();
+}
+
+void WebViewImpl::toggleAutomaticLinkDetection()
+{
+    TextChecker::setAutomaticLinkDetectionEnabled(!TextChecker::state().isAutomaticLinkDetectionEnabled);
+    m_page.process().updateTextCheckerState();
+}
+
+bool WebViewImpl::isAutomaticTextReplacementEnabled()
+{
+    return TextChecker::state().isAutomaticTextReplacementEnabled;
+}
+
+void WebViewImpl::setAutomaticTextReplacementEnabled(bool flag)
+{
+    if (static_cast<bool>(flag) == TextChecker::state().isAutomaticTextReplacementEnabled)
+        return;
+    
+    TextChecker::setAutomaticTextReplacementEnabled(flag);
+    m_page.process().updateTextCheckerState();
+}
+
+void WebViewImpl::toggleAutomaticTextReplacement()
+{
+    TextChecker::setAutomaticTextReplacementEnabled(!TextChecker::state().isAutomaticTextReplacementEnabled);
+    m_page.process().updateTextCheckerState();
+}
+
+void WebViewImpl::uppercaseWord()
+{
+    m_page.uppercaseWord();
+}
+
+void WebViewImpl::lowercaseWord()
+{
+    m_page.lowercaseWord();
+}
+
+void WebViewImpl::capitalizeWord()
+{
+    m_page.capitalizeWord();
+}
+
 void WebViewImpl::preferencesDidChange()
 {
     BOOL needsViewFrameInWindowCoordinates = m_page.preferences().pluginsEnabled();

Modified: trunk/Source/WebKit2/UIProcess/mac/WebPageProxyMac.mm (191760 => 191761)


--- trunk/Source/WebKit2/UIProcess/mac/WebPageProxyMac.mm	2015-10-29 22:35:37 UTC (rev 191760)
+++ trunk/Source/WebKit2/UIProcess/mac/WebPageProxyMac.mm	2015-10-29 23:13:10 UTC (rev 191761)
@@ -29,6 +29,7 @@
 #if PLATFORM(MAC)
 
 #import "APIUIClient.h"
+#import "AppKitSPI.h"
 #import "AttributedString.h"
 #import "ColorSpaceData.h"
 #import "DataReference.h"
@@ -57,10 +58,6 @@
 #import <wtf/NeverDestroyed.h>
 #import <wtf/text/StringConcatenate.h>
 
-@interface NSApplication ()
-- (void)speakString:(NSString *)string;
-@end
-
 #define MESSAGE_CHECK(assertion) MESSAGE_CHECK_BASE(assertion, process().connection())
 #define MESSAGE_CHECK_URL(url) MESSAGE_CHECK_BASE(m_process->checkURLReceivedFromWebProcess(url), m_process->connection())
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to