Diff
Modified: trunk/Source/WebKit2/ChangeLog (175497 => 175498)
--- trunk/Source/WebKit2/ChangeLog 2014-11-04 01:03:42 UTC (rev 175497)
+++ trunk/Source/WebKit2/ChangeLog 2014-11-04 01:05:51 UTC (rev 175498)
@@ -1,3 +1,43 @@
+2014-11-03 Beth Dakin <bda...@apple.com>
+
+ Implement action menus for editable text with spelling suggestions
+ https://bugs.webkit.org/show_bug.cgi?id=138333
+ -and corresponding-
+ rdar://problem/18742371
+
+ Reviewed by Tim Horton.
+
+ New types.
+ * Shared/API/c/WKActionMenuItemTypes.h:
+ * Shared/API/c/WKActionMenuTypes.h:
+
+ ActionMenuHitTestResult now stores the String result of the lookup.
+ * Shared/mac/ActionMenuHitTestResult.h:
+ * Shared/mac/ActionMenuHitTestResult.mm:
+ (WebKit::ActionMenuHitTestResult::encode):
+ (WebKit::ActionMenuHitTestResult::decode):
+
+ Make getGuessesForWord() public so we can call it from WKActionMenuController.
+ * UIProcess/WebPageProxy.h:
+ * UIProcess/mac/WKActionMenuController.mm:
+
+ Select the text for all types of text menus.
+ (-[WKActionMenuController isMenuForTextContent]):
+ (-[WKActionMenuController willOpenMenu:withEvent:]):
+
+ Spelling suggestions are presented in a sub-menu and will replace the selection
+ when chosen.
+ (-[WKActionMenuController _defaultMenuItemsForEditableTextWithSuggestions:]):
+ (-[WKActionMenuController _changeSelectionToSuggestion:]):
+ (-[WKActionMenuController _createActionMenuItemForTag:]):
+ (-[WKActionMenuController _defaultMenuItems:]):
+
+ New function to store the lookupText as a String on the ActionMenuHitTestResult.
+ * WebProcess/WebPage/WebPage.h:
+ * WebProcess/WebPage/mac/WebPageMac.mm:
+ (WebKit::WebPage::performActionMenuHitTestAtLocation):
+ (WebKit::WebPage::lookupTextAtLocation):
+
2014-11-03 Simon Fraser <simon.fra...@apple.com>
Add page overlays that show regions with mouseWheel event handlers, and the non-fast-scrollable region, and code to toggle them in MiniBrowser WK2
Modified: trunk/Source/WebKit2/Shared/API/c/WKActionMenuItemTypes.h (175497 => 175498)
--- trunk/Source/WebKit2/Shared/API/c/WKActionMenuItemTypes.h 2014-11-04 01:03:42 UTC (rev 175497)
+++ trunk/Source/WebKit2/Shared/API/c/WKActionMenuItemTypes.h 2014-11-04 01:05:51 UTC (rev 175498)
@@ -43,7 +43,8 @@
kWKContextActionItemTagShareImage,
kWKContextActionItemTagCopyText,
kWKContextActionItemTagLookupText,
- kWKContextActionItemTagPaste
+ kWKContextActionItemTagPaste,
+ kWKContextActionItemTagTextSuggestions
};
#ifdef __cplusplus
Modified: trunk/Source/WebKit2/Shared/API/c/WKActionMenuTypes.h (175497 => 175498)
--- trunk/Source/WebKit2/Shared/API/c/WKActionMenuTypes.h 2014-11-04 01:03:42 UTC (rev 175497)
+++ trunk/Source/WebKit2/Shared/API/c/WKActionMenuTypes.h 2014-11-04 01:05:51 UTC (rev 175498)
@@ -38,7 +38,8 @@
kWKActionMenuImage,
kWKActionMenuDataDetectedItem,
kWKActionMenuReadOnlyText,
- kWKActionMenuEditableText
+ kWKActionMenuEditableText,
+ kWKActionMenuEditableTextWithSuggestions
};
typedef uint32_t _WKActionMenuType;
Modified: trunk/Source/WebKit2/Shared/mac/ActionMenuHitTestResult.h (175497 => 175498)
--- trunk/Source/WebKit2/Shared/mac/ActionMenuHitTestResult.h 2014-11-04 01:03:42 UTC (rev 175497)
+++ trunk/Source/WebKit2/Shared/mac/ActionMenuHitTestResult.h 2014-11-04 01:05:51 UTC (rev 175498)
@@ -29,6 +29,7 @@
#include "ShareableBitmap.h"
#include "WebHitTestResult.h"
#include <WebCore/FloatRect.h>
+#include <wtf/text/WTFString.h>
OBJC_CLASS DDActionContext;
@@ -46,6 +47,7 @@
WebCore::FloatPoint hitTestLocationInViewCooordinates;
WebHitTestResult::Data hitTestResult;
+ String lookupText;
RefPtr<ShareableBitmap> image;
RetainPtr<DDActionContext> actionContext;
Modified: trunk/Source/WebKit2/Shared/mac/ActionMenuHitTestResult.mm (175497 => 175498)
--- trunk/Source/WebKit2/Shared/mac/ActionMenuHitTestResult.mm 2014-11-04 01:03:42 UTC (rev 175497)
+++ trunk/Source/WebKit2/Shared/mac/ActionMenuHitTestResult.mm 2014-11-04 01:05:51 UTC (rev 175498)
@@ -38,6 +38,7 @@
{
encoder << hitTestLocationInViewCooordinates;
encoder << hitTestResult;
+ encoder << lookupText;
ShareableBitmap::Handle handle;
@@ -70,6 +71,9 @@
if (!decoder.decode(actionMenuHitTestResult.hitTestResult))
return false;
+ if (!decoder.decode(actionMenuHitTestResult.lookupText))
+ return false;
+
ShareableBitmap::Handle handle;
if (!decoder.decode(handle))
return false;
Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.h (175497 => 175498)
--- trunk/Source/WebKit2/UIProcess/WebPageProxy.h 2014-11-04 01:03:42 UTC (rev 175497)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.h 2014-11-04 01:05:51 UTC (rev 175498)
@@ -935,6 +935,11 @@
bool accessibilityObjectReadNext();
#endif
+#if USE(UNIFIED_TEXT_CHECKING)
+ void checkTextOfParagraph(const String& text, uint64_t checkingTypes, Vector<WebCore::TextCheckingResult>& results);
+#endif
+ void getGuessesForWord(const String& word, const String& context, Vector<String>& guesses);
+
private:
WebPageProxy(PageClient&, WebProcessProxy&, uint64_t pageID, const WebPageConfiguration&);
void platformInitialize();
@@ -1166,15 +1171,11 @@
#endif
// Spelling and grammar.
-#if USE(UNIFIED_TEXT_CHECKING)
- void checkTextOfParagraph(const String& text, uint64_t checkingTypes, Vector<WebCore::TextCheckingResult>& results);
-#endif
void checkSpellingOfString(const String& text, int32_t& misspellingLocation, int32_t& misspellingLength);
void checkGrammarOfString(const String& text, Vector<WebCore::GrammarDetail>&, int32_t& badGrammarLocation, int32_t& badGrammarLength);
void spellingUIIsShowing(bool&);
void updateSpellingUIWithMisspelledWord(const String& misspelledWord);
void updateSpellingUIWithGrammarString(const String& badGrammarPhrase, const WebCore::GrammarDetail&);
- void getGuessesForWord(const String& word, const String& context, Vector<String>& guesses);
void learnWord(const String& word);
void ignoreWord(const String& word);
void requestCheckingOfString(uint64_t requestID, const WebCore::TextCheckingRequestData&);
Modified: trunk/Source/WebKit2/UIProcess/mac/WKActionMenuController.mm (175497 => 175498)
--- trunk/Source/WebKit2/UIProcess/mac/WKActionMenuController.mm 2014-11-04 01:03:42 UTC (rev 175497)
+++ trunk/Source/WebKit2/UIProcess/mac/WKActionMenuController.mm 2014-11-04 01:05:51 UTC (rev 175498)
@@ -110,12 +110,17 @@
[self _updateActionMenuItemsForStage:MenuUpdateStage::PrepareForMenu];
}
+- (BOOL)isMenuForTextContent
+{
+ return _type == kWKActionMenuReadOnlyText || _type == kWKActionMenuEditableText || _type == kWKActionMenuEditableTextWithSuggestions;
+}
+
- (void)willOpenMenu:(NSMenu *)menu withEvent:(NSEvent *)event
{
if (menu != _wkView.actionMenu)
return;
- if (_type != kWKActionMenuReadOnlyText && _type != kWKActionMenuEditableText)
+ if (![self isMenuForTextContent])
return;
// Action menus for text should highlight the text so that it is clear what the action menu actions
@@ -338,21 +343,65 @@
return @[ copyTextItem.get(), lookupTextItem.get(), pasteItem.get() ];
}
--(void)_copySelection:(id)sender
+- (NSArray *)_defaultMenuItemsForEditableTextWithSuggestions
{
+ if (_hitTestResult.lookupText.isEmpty())
+ return @[ ];
+
+ Vector<TextCheckingResult> results;
+ _page->checkTextOfParagraph(_hitTestResult.lookupText, NSTextCheckingTypeSpelling, results);
+ if (results.isEmpty())
+ return @[ ];
+
+ Vector<String> guesses;
+ _page->getGuessesForWord(_hitTestResult.lookupText, String(), guesses);
+ if (guesses.isEmpty())
+ return @[ ];
+
+ RetainPtr<NSMenu> spellingSubMenu = adoptNS([[NSMenu alloc] init]);
+ for (const auto& guess : guesses) {
+ RetainPtr<NSMenuItem> item = adoptNS([[NSMenuItem alloc] initWithTitle:guess action:@selector(_changeSelectionToSuggestion:) keyEquivalent:@""]);
+ [item setRepresentedObject:guess];
+ [item setTarget:self];
+ [spellingSubMenu addItem:item.get()];
+ }
+
+ RetainPtr<NSMenuItem> copyTextItem = [self _createActionMenuItemForTag:kWKContextActionItemTagCopyText];
+ RetainPtr<NSMenuItem> lookupTextItem = [self _createActionMenuItemForTag:kWKContextActionItemTagLookupText];
+ RetainPtr<NSMenuItem> pasteItem = [self _createActionMenuItemForTag:kWKContextActionItemTagPaste];
+ RetainPtr<NSMenuItem> textSuggestionsItem = [self _createActionMenuItemForTag:kWKContextActionItemTagTextSuggestions];
+
+ [textSuggestionsItem setSubmenu:spellingSubMenu.get()];
+
+ return @[ copyTextItem.get(), lookupTextItem.get(), pasteItem.get(), textSuggestionsItem.get() ];
+}
+
+- (void)_copySelection:(id)sender
+{
_page->executeEditCommand("copy");
}
--(void)_paste:(id)sender
+- (void)_paste:(id)sender
{
_page->executeEditCommand("paste");
}
--(void)_lookupText:(id)sender
+- (void)_lookupText:(id)sender
{
_page->performDictionaryLookupOfCurrentSelection();
}
+- (void)_changeSelectionToSuggestion:(id)sender
+{
+ NSString *selectedCorrection = [sender representedObject];
+ if (!selectedCorrection)
+ return;
+
+ ASSERT([selectedCorrection isKindOfClass:[NSString class]]);
+
+ _page->changeSpellingToWord(selectedCorrection);
+}
+
#pragma mark NSMenuDelegate implementation
- (void)menuNeedsUpdate:(NSMenu *)menu
@@ -468,6 +517,11 @@
image = [NSImage imageNamed:@"NSActionMenuPaste"];
break;
+ case kWKContextActionItemTagTextSuggestions:
+ title = @"Suggestions";
+ image = [NSImage imageNamed:@"NSActionMenuSpelling"];
+ break;
+
default:
ASSERT_NOT_REACHED();
return nil;
@@ -530,6 +584,12 @@
}
if (hitTestResult->isContentEditable()) {
+ NSArray *editableTextWithSuggestions = [self _defaultMenuItemsForEditableTextWithSuggestions];
+ if (editableTextWithSuggestions.count) {
+ _type = kWKActionMenuEditableTextWithSuggestions;
+ return editableTextWithSuggestions;
+ }
+
_type = kWKActionMenuEditableText;
return [self _defaultMenuItemsForEditableText];
}
Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h (175497 => 175498)
--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h 2014-11-04 01:03:42 UTC (rev 175497)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h 2014-11-04 01:05:51 UTC (rev 175498)
@@ -1049,6 +1049,7 @@
#if PLATFORM(MAC)
void performActionMenuHitTestAtLocation(WebCore::FloatPoint);
+ PassRefPtr<WebCore::Range> lookupTextAtLocation(WebCore::FloatPoint);
void selectLookupTextAtLocation(WebCore::FloatPoint);
#endif
Modified: trunk/Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm (175497 => 175498)
--- trunk/Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm 2014-11-04 01:03:42 UTC (rev 175497)
+++ trunk/Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm 2014-11-04 01:05:51 UTC (rev 175498)
@@ -1152,6 +1152,9 @@
actionMenuResult.hitTestLocationInViewCooordinates = locationInViewCooordinates;
actionMenuResult.hitTestResult = WebHitTestResult::Data(hitTestResult);
+ RefPtr<WebCore::Range> lookupRange = lookupTextAtLocation(locationInViewCooordinates);
+ actionMenuResult.lookupText = lookupRange ? lookupRange->text() : String();
+
if (Image* image = hitTestResult.image()) {
actionMenuResult.image = ShareableBitmap::createShareable(IntSize(image->size()), ShareableBitmap::SupportsAlpha);
if (actionMenuResult.image)
@@ -1172,6 +1175,18 @@
send(Messages::WebPageProxy::DidPerformActionMenuHitTest(actionMenuResult, InjectedBundleUserMessageEncoder(userData.get())));
}
+PassRefPtr<WebCore::Range> WebPage::lookupTextAtLocation(FloatPoint locationInViewCooordinates)
+{
+ MainFrame& mainFrame = corePage()->mainFrame();
+ if (!mainFrame.view() || !mainFrame.view()->renderView())
+ return nullptr;
+
+ IntPoint point = roundedIntPoint(locationInViewCooordinates);
+ HitTestResult result = mainFrame.eventHandler().hitTestResultAtPoint(m_page->mainFrame().view()->windowToContents(point), HitTestRequest::ReadOnly | HitTestRequest::Active | HitTestRequest::AllowChildFrameContent | HitTestRequest::IgnoreClipping);
+ NSDictionary *options = nil;
+ return rangeForDictionaryLookupAtHitTestResult(result, &options);
+}
+
void WebPage::selectLookupTextAtLocation(FloatPoint locationInWindowCooordinates)
{
MainFrame& mainFrame = corePage()->mainFrame();