Diff
Modified: trunk/Source/WebCore/ChangeLog (182572 => 182573)
--- trunk/Source/WebCore/ChangeLog 2015-04-08 22:47:26 UTC (rev 182572)
+++ trunk/Source/WebCore/ChangeLog 2015-04-08 23:11:38 UTC (rev 182573)
@@ -1,3 +1,43 @@
+2015-04-08 Brady Eidson <[email protected]>
+
+ Expose the "Share" menu for links, images, and media.
+ <rdar://problem/20435340> and https://bugs.webkit.org/show_bug.cgi?id=143502
+
+ Reviewed by Tim Horton.
+
+ * loader/EmptyClients.h:
+ * page/ContextMenuClient.h:
+ (WebCore::ContextMenuClient::shareSelectedTextMenuItem): Deleted.
+
+ * page/ContextMenuController.cpp:
+ (WebCore::ContextMenuController::populate):
+ (WebCore::selectionContainsPossibleWord): Deleted.
+ * page/ContextMenuController.h:
+ (WebCore::ContextMenuController::page):
+
+ * platform/ContextMenuItem.cpp:
+ (WebCore::ContextMenuItem::ContextMenuItem):
+ (WebCore::ContextMenuItem::isNull):
+ (WebCore::ContextMenuItem::shareMenuItem):
+ (WebCore::ContextMenuItem::supportsShareMenu): Deleted.
+ (WebCore::ContextMenuItem::shareSelectedTextMenuItem): Deleted.
+ * platform/ContextMenuItem.h:
+
+ * platform/gtk/ContextMenuItemGtk.cpp:
+ (WebCore::ContextMenuItem::shareMenuItem): Return a null item.
+ (WebCore::ContextMenuItem::supportsShareMenu): Deleted.
+ (WebCore::ContextMenuItem::shareSelectedTextMenuItem): Deleted.
+
+ * platform/mac/ContextMenuItemMac.mm:
+ (WebCore::ContextMenuItem::shareMenuItem): Create a full-featured Share menu item instead of just for selected text.
+ (WebCore::ContextMenuItem::supportsShareMenu): Deleted.
+ (WebCore::ContextMenuItem::shareSelectedTextMenuItem): Deleted.
+
+ * rendering/HitTestResult.cpp:
+ (WebCore::HitTestResult::selectedText): Instead of calculating selected text outside the HitTestResult, let the
+ HitTestResult do what it does best: Calculate things!
+ * rendering/HitTestResult.h:
+
2015-04-08 Per Arne Vollan <[email protected]>
[Curl] Compile error in CurlCacheEntry::parseResponseHeaders method.
Modified: trunk/Source/WebCore/loader/EmptyClients.h (182572 => 182573)
--- trunk/Source/WebCore/loader/EmptyClients.h 2015-04-08 22:47:26 UTC (rev 182572)
+++ trunk/Source/WebCore/loader/EmptyClients.h 2015-04-08 23:11:38 UTC (rev 182573)
@@ -557,6 +557,8 @@
virtual void speak(const String&) override { }
virtual void stopSpeaking() override { }
+ virtual ContextMenuItem shareMenuItem(const HitTestResult&) override { return ContextMenuItem(); }
+
#if PLATFORM(COCOA)
virtual void searchWithSpotlight() override { }
#endif
Modified: trunk/Source/WebCore/page/ContextMenuClient.h (182572 => 182573)
--- trunk/Source/WebCore/page/ContextMenuClient.h 2015-04-08 22:47:26 UTC (rev 182572)
+++ trunk/Source/WebCore/page/ContextMenuClient.h 2015-04-08 23:11:38 UTC (rev 182573)
@@ -58,9 +58,10 @@
virtual void speak(const String&) = 0;
virtual void stopSpeaking() = 0;
+ virtual ContextMenuItem shareMenuItem(const HitTestResult&) = 0;
+
#if PLATFORM(COCOA)
virtual void searchWithSpotlight() = 0;
- virtual ContextMenuItem shareSelectedTextMenuItem(const String& selectedText) { return ContextMenuItem::shareSelectedTextMenuItem(selectedText); }
#endif
#if USE(ACCESSIBILITY_CONTEXT_MENUS)
Modified: trunk/Source/WebCore/page/ContextMenuController.cpp (182572 => 182573)
--- trunk/Source/WebCore/page/ContextMenuController.cpp 2015-04-08 22:47:26 UTC (rev 182572)
+++ trunk/Source/WebCore/page/ContextMenuController.cpp 2015-04-08 23:11:38 UTC (rev 182573)
@@ -731,19 +731,6 @@
#endif
-static bool selectionContainsPossibleWord(Frame* frame)
-{
- // Current algorithm: look for a character that's not just a separator.
- for (TextIterator it(frame->selection().toNormalizedRange().get()); !it.atEnd(); it.advance()) {
- int length = it.text().length();
- for (int i = 0; i < length; ++i) {
- if (!(U_GET_GC_MASK(it.text()[i]) & U_GC_Z_MASK))
- return true;
- }
- }
- return false;
-}
-
#if PLATFORM(COCOA)
#define SUPPORTS_TOGGLE_VIDEO_FULLSCREEN 1
#else
@@ -826,6 +813,8 @@
ContextMenuItem SelectAllItem(ActionType, ContextMenuItemTagSelectAll, contextMenuItemTagSelectAll());
#endif
+ ContextMenuItem ShareMenuItem = m_client.shareMenuItem(m_context.hitTestResult());
+
Node* node = m_context.hitTestResult().innerNonSharedNode();
if (!node)
return;
@@ -844,6 +833,9 @@
#endif
if (!m_context.hitTestResult().isContentEditable()) {
+ String selectedString = m_context.hitTestResult().selectedText();
+ m_context.setSelectedText(selectedString);
+
FrameLoader& loader = frame->loader();
URL linkURL = m_context.hitTestResult().absoluteLinkURL();
if (!linkURL.isEmpty()) {
@@ -892,10 +884,8 @@
if (imageURL.isEmpty() && linkURL.isEmpty() && mediaURL.isEmpty()) {
if (m_context.hitTestResult().isSelected()) {
- String selectedString;
- if (selectionContainsPossibleWord(frame)) {
+ if (!selectedString.isEmpty()) {
#if PLATFORM(COCOA)
- selectedString = frame->displayStringModifiedByEncoding(frame->editor().selectedText());
ContextMenuItem LookUpInDictionaryItem(ActionType, ContextMenuItemTagLookUpInDictionary, contextMenuItemTagLookUpInDictionary(selectedString));
appendItem(LookUpInDictionaryItem, m_contextMenu.get());
@@ -911,12 +901,9 @@
#if PLATFORM(COCOA)
appendItem(*separatorItem(), m_contextMenu.get());
- if (!selectedString.isEmpty() && ContextMenuItem::supportsShareMenu()) {
- ContextMenuItem ShareItem(m_client.shareSelectedTextMenuItem(selectedString));
- appendItem(ShareItem, m_contextMenu.get());
+ if (!ShareMenuItem.isNull()) {
+ appendItem(ShareMenuItem, m_contextMenu.get());
appendItem(*separatorItem(), m_contextMenu.get());
-
- m_context.setSelectedText(selectedString);
}
ContextMenuItem SpeechMenuItem(SubmenuType, ContextMenuItemTagSpeechMenu, contextMenuItemTagSpeechMenu());
@@ -950,7 +937,15 @@
if (frame->page() && !frame->isMainFrame())
appendItem(OpenFrameItem, m_contextMenu.get());
+
+ if (!ShareMenuItem.isNull()) {
+ appendItem(*separatorItem(), m_contextMenu.get());
+ appendItem(ShareMenuItem, m_contextMenu.get());
+ }
}
+ } else if (!ShareMenuItem.isNull()) {
+ appendItem(*separatorItem(), m_contextMenu.get());
+ appendItem(ShareMenuItem, m_contextMenu.get());
}
} else { // Make an editing context menu
bool inPasswordField = frame->selection().selection().isInPasswordField();
@@ -1028,10 +1023,10 @@
appendItem(*separatorItem(), m_contextMenu.get());
}
- if (m_context.hitTestResult().isSelected() && !inPasswordField && selectionContainsPossibleWord(frame)) {
+ String selectedText = m_context.hitTestResult().selectedText();
+ if (m_context.hitTestResult().isSelected() && !inPasswordField && !selectedText.isEmpty()) {
#if PLATFORM(COCOA)
- String selectedString = frame->displayStringModifiedByEncoding(frame->editor().selectedText());
- ContextMenuItem LookUpInDictionaryItem(ActionType, ContextMenuItemTagLookUpInDictionary, contextMenuItemTagLookUpInDictionary(selectedString));
+ ContextMenuItem LookUpInDictionaryItem(ActionType, ContextMenuItemTagLookUpInDictionary, contextMenuItemTagLookUpInDictionary(selectedText));
appendItem(LookUpInDictionaryItem, m_contextMenu.get());
#endif
@@ -1111,6 +1106,11 @@
}
#endif
}
+
+ if (!ShareMenuItem.isNull()) {
+ appendItem(*separatorItem(), m_contextMenu.get());
+ appendItem(ShareMenuItem, m_contextMenu.get());
+ }
}
}
Modified: trunk/Source/WebCore/page/ContextMenuController.h (182572 => 182573)
--- trunk/Source/WebCore/page/ContextMenuController.h 2015-04-08 22:47:26 UTC (rev 182572)
+++ trunk/Source/WebCore/page/ContextMenuController.h 2015-04-08 23:11:38 UTC (rev 182573)
@@ -48,6 +48,8 @@
ContextMenuController(Page&, ContextMenuClient&);
~ContextMenuController();
+ Page& page() { return m_page; }
+
ContextMenu* contextMenu() const { return m_contextMenu.get(); }
WEBCORE_EXPORT void clearContextMenu();
Modified: trunk/Source/WebCore/platform/ContextMenuItem.cpp (182572 => 182573)
--- trunk/Source/WebCore/platform/ContextMenuItem.cpp 2015-04-08 22:47:26 UTC (rev 182572)
+++ trunk/Source/WebCore/platform/ContextMenuItem.cpp 2015-04-08 23:11:38 UTC (rev 182573)
@@ -62,10 +62,24 @@
{
}
+ContextMenuItem::ContextMenuItem()
+ : m_type(SeparatorType)
+ , m_action(ContextMenuItemTagNoAction)
+ , m_enabled(false)
+ , m_checked(false)
+{
+}
+
ContextMenuItem::~ContextMenuItem()
{
}
+bool ContextMenuItem::isNull() const
+{
+ // FIXME: This is a bit of a hack. Cross-platform ContextMenuItem users need a concrete way to track "isNull".
+ return m_action == ContextMenuItemTagNoAction && m_title.isNull() && m_subMenuItems.isEmpty();
+}
+
void ContextMenuItem::setSubMenu(ContextMenu* subMenu)
{
if (subMenu) {
@@ -117,13 +131,8 @@
return m_enabled;
}
-bool ContextMenuItem::supportsShareMenu()
+ContextMenuItem ContextMenuItem::shareMenuItem(const URL&, const URL&, Image*, const String&)
{
- return false;
-}
-
-ContextMenuItem ContextMenuItem::shareSelectedTextMenuItem(const String&)
-{
return ContextMenuItem(SubmenuType, ContextMenuItemTagShareMenu, emptyString());
}
Modified: trunk/Source/WebCore/platform/ContextMenuItem.h (182572 => 182573)
--- trunk/Source/WebCore/platform/ContextMenuItem.h 2015-04-08 22:47:26 UTC (rev 182572)
+++ trunk/Source/WebCore/platform/ContextMenuItem.h 2015-04-08 23:11:38 UTC (rev 182573)
@@ -45,6 +45,8 @@
namespace WebCore {
class ContextMenu;
+ class Image;
+ class URL;
// This enum needs to be in sync with the WebMenuItemTag enum in WebUIDelegate.h and the
// extra values in WebUIDelegatePrivate.h
@@ -206,8 +208,7 @@
void setSubMenu(ContextMenu*);
- static bool supportsShareMenu();
- WEBCORE_EXPORT static ContextMenuItem shareSelectedTextMenuItem(const String&);
+ WEBCORE_EXPORT static ContextMenuItem shareMenuItem(const URL& absoluteLinkURL, const URL& downloadableMediaURL, Image*, const String& selectedText);
#if PLATFORM(GTK)
GtkAction* gtkAction() const;
@@ -216,7 +217,10 @@
#if USE(CROSS_PLATFORM_CONTEXT_MENUS)
ContextMenuItem(ContextMenuAction, const String&, bool enabled, bool checked, const Vector<ContextMenuItem>& subMenuItems);
explicit ContextMenuItem(const PlatformContextMenuItem&);
+ ContextMenuItem();
+ bool isNull() const;
+
// On Windows, the title (dwTypeData of the MENUITEMINFO) is not set in this function. Callers can set the title themselves,
// and handle the lifetime of the title, if they need it.
PlatformContextMenuItem platformContextMenuItem() const;
@@ -230,7 +234,7 @@
WEBCORE_EXPORT explicit ContextMenuItem(PlatformMenuItemDescription);
explicit ContextMenuItem(ContextMenu* subMenu);
ContextMenuItem(ContextMenuAction, const String&, bool enabled, bool checked, Vector<ContextMenuItem>& submenuItems);
- ContextMenuItem();
+ WEBCORE_EXPORT ContextMenuItem();
bool isNull() const { return !m_platformDescription; }
Modified: trunk/Source/WebCore/platform/gtk/ContextMenuItemGtk.cpp (182572 => 182573)
--- trunk/Source/WebCore/platform/gtk/ContextMenuItemGtk.cpp 2015-04-08 22:47:26 UTC (rev 182572)
+++ trunk/Source/WebCore/platform/gtk/ContextMenuItemGtk.cpp 2015-04-08 23:11:38 UTC (rev 182573)
@@ -288,13 +288,8 @@
return gtk_activatable_get_related_action(GTK_ACTIVATABLE(m_platformDescription));
}
-bool ContextMenuItem::supportsShareMenu()
+ContextMenuItem ContextMenuItem::shareMenuItem(const URL&, const URL&, Image*, const String&)
{
- return false;
-}
-
-ContextMenuItem ContextMenuItem::shareSelectedTextMenuItem(const String&)
-{
return ContextMenuItem(SubmenuType, ContextMenuItemTagShareMenu, emptyString());
}
Modified: trunk/Source/WebCore/platform/mac/ContextMenuItemMac.mm (182572 => 182573)
--- trunk/Source/WebCore/platform/mac/ContextMenuItemMac.mm 2015-04-08 22:47:26 UTC (rev 182572)
+++ trunk/Source/WebCore/platform/mac/ContextMenuItemMac.mm 2015-04-08 23:11:38 UTC (rev 182573)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2006 Apple Inc. All rights reserved.
+ * Copyright (C) 2006, 2015 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -29,7 +29,13 @@
#if ENABLE(CONTEXT_MENUS)
#include "ContextMenu.h"
+#include "Document.h"
+#include "Frame.h"
+#include "HitTestResult.h"
+#include "Image.h"
#include "NSMenuSPI.h"
+#include "Node.h"
+#include "URL.h"
namespace WebCore {
@@ -190,15 +196,32 @@
return [m_platformDescription.get() state] == NSOnState;
}
-bool ContextMenuItem::supportsShareMenu()
+ContextMenuItem ContextMenuItem::shareMenuItem(const URL& absoluteLinkURL, const URL& downloadableMediaURL, Image* image, const String& selectedText)
{
- static bool supportsShareMenu = [[NSMenuItem class] respondsToSelector:@selector(standardShareMenuItemWithItems:)];
- return supportsShareMenu;
-}
+ if (![[NSMenuItem class] respondsToSelector:@selector(standardShareMenuItemWithItems:)])
+ return ContextMenuItem();
-ContextMenuItem ContextMenuItem::shareSelectedTextMenuItem(const String& selectedText)
-{
- ContextMenuItem item([NSMenuItem standardShareMenuItemWithItems:@[ (NSString *)selectedText ]]);
+ RetainPtr<NSMutableArray> items = adoptNS([[NSMutableArray alloc] init]);
+
+ if (!absoluteLinkURL.isEmpty())
+ [items addObject:(NSURL *)absoluteLinkURL];
+
+ if (!downloadableMediaURL.isEmpty())
+ [items addObject:(NSURL *)downloadableMediaURL];
+
+ if (image) {
+ NSImage *nsImage = image->getNSImage();
+ if (nsImage)
+ [items addObject:nsImage];
+ }
+
+ if (!selectedText.isEmpty())
+ [items addObject:(NSString *)selectedText];
+
+ if (![items count])
+ return ContextMenuItem();
+
+ ContextMenuItem item([NSMenuItem standardShareMenuItemWithItems:items.get()]);
item.setAction(ContextMenuItemTagShareMenu);
return item;
}
Modified: trunk/Source/WebCore/rendering/HitTestResult.cpp (182572 => 182573)
--- trunk/Source/WebCore/rendering/HitTestResult.cpp 2015-04-08 22:47:26 UTC (rev 182572)
+++ trunk/Source/WebCore/rendering/HitTestResult.cpp 2015-04-08 23:11:38 UTC (rev 182573)
@@ -51,6 +51,7 @@
#include "SVGNames.h"
#include "Scrollbar.h"
#include "ShadowRoot.h"
+#include "TextIterator.h"
#include "UserGestureIndicator.h"
#include "VisibleUnits.h"
#include "XLinkNames.h"
@@ -189,6 +190,26 @@
return frame->selection().contains(m_hitTestLocation.point());
}
+String HitTestResult::selectedText() const
+{
+ if (!m_innerNonSharedNode)
+ return emptyString();
+
+ Frame* frame = m_innerNonSharedNode->document().frame();
+ if (!frame)
+ return emptyString();
+
+ // Look for a character that's not just a separator.
+ for (TextIterator it(frame->selection().toNormalizedRange().get()); !it.atEnd(); it.advance()) {
+ int length = it.text().length();
+ for (int i = 0; i < length; ++i) {
+ if (!(U_GET_GC_MASK(it.text()[i]) & U_GC_Z_MASK))
+ return frame->displayStringModifiedByEncoding(frame->editor().selectedText());
+ }
+ }
+ return emptyString();
+}
+
String HitTestResult::spellingToolTip(TextDirection& dir) const
{
dir = LTR;
Modified: trunk/Source/WebCore/rendering/HitTestResult.h (182572 => 182573)
--- trunk/Source/WebCore/rendering/HitTestResult.h 2015-04-08 22:47:26 UTC (rev 182572)
+++ trunk/Source/WebCore/rendering/HitTestResult.h 2015-04-08 23:11:38 UTC (rev 182573)
@@ -94,6 +94,7 @@
WEBCORE_EXPORT Frame* targetFrame() const;
WEBCORE_EXPORT bool isSelected() const;
+ WEBCORE_EXPORT String selectedText() const;
WEBCORE_EXPORT String spellingToolTip(TextDirection&) const;
String replacedString() const;
WEBCORE_EXPORT String title(TextDirection&) const;
Modified: trunk/Source/WebKit/mac/ChangeLog (182572 => 182573)
--- trunk/Source/WebKit/mac/ChangeLog 2015-04-08 22:47:26 UTC (rev 182572)
+++ trunk/Source/WebKit/mac/ChangeLog 2015-04-08 23:11:38 UTC (rev 182573)
@@ -1,3 +1,14 @@
+2015-04-08 Brady Eidson <[email protected]>
+
+ Expose the "Share" menu for links, images, and media.
+ <rdar://problem/20435340> and https://bugs.webkit.org/show_bug.cgi?id=143502
+
+ Reviewed by Tim Horton.
+
+ * WebCoreSupport/WebContextMenuClient.h:
+ * WebCoreSupport/WebContextMenuClient.mm:
+ (WebContextMenuClient::shareMenuItem):
+
2015-04-08 Anders Carlsson <[email protected]>
Move some ApplicationCache static member functions to ApplicationCacheStorage
Modified: trunk/Source/WebKit/mac/WebCoreSupport/WebContextMenuClient.h (182572 => 182573)
--- trunk/Source/WebKit/mac/WebCoreSupport/WebContextMenuClient.h 2015-04-08 22:47:26 UTC (rev 182572)
+++ trunk/Source/WebKit/mac/WebCoreSupport/WebContextMenuClient.h 2015-04-08 23:11:38 UTC (rev 182573)
@@ -57,6 +57,7 @@
virtual bool isSpeaking() override;
virtual void speak(const WTF::String&) override;
virtual void stopSpeaking() override;
+ virtual WebCore::ContextMenuItem shareMenuItem(const WebCore::HitTestResult&) override;
virtual void searchWithSpotlight() override;
virtual void showContextMenu() override;
Modified: trunk/Source/WebKit/mac/WebCoreSupport/WebContextMenuClient.mm (182572 => 182573)
--- trunk/Source/WebKit/mac/WebCoreSupport/WebContextMenuClient.mm 2015-04-08 22:47:26 UTC (rev 182572)
+++ trunk/Source/WebKit/mac/WebCoreSupport/WebContextMenuClient.mm 2015-04-08 23:11:38 UTC (rev 182573)
@@ -366,6 +366,26 @@
[NSApp stopSpeaking:nil];
}
+ContextMenuItem WebContextMenuClient::shareMenuItem(const HitTestResult& hitTestResult)
+{
+ if (![[NSMenuItem class] respondsToSelector:@selector(standardShareMenuItemWithItems:)])
+ return ContextMenuItem();
+
+ Node* node = hitTestResult.innerNonSharedNode();
+ if (!node)
+ return ContextMenuItem();
+
+ Frame* frame = node->document().frame();
+ if (!frame)
+ return ContextMenuItem();
+
+ URL downloadableMediaURL;
+ if (!hitTestResult.absoluteMediaURL().isEmpty() && hitTestResult.isDownloadableMedia())
+ downloadableMediaURL = hitTestResult.absoluteMediaURL();
+
+ return ContextMenuItem::shareMenuItem(hitTestResult.absoluteLinkURL(), downloadableMediaURL, hitTestResult.image(), hitTestResult.selectedText());
+}
+
bool WebContextMenuClient::clientFloatRectForNode(Node& node, FloatRect& rect) const
{
RenderObject* renderer = node.renderer();
Modified: trunk/Source/WebKit/win/ChangeLog (182572 => 182573)
--- trunk/Source/WebKit/win/ChangeLog 2015-04-08 22:47:26 UTC (rev 182572)
+++ trunk/Source/WebKit/win/ChangeLog 2015-04-08 23:11:38 UTC (rev 182573)
@@ -1,3 +1,14 @@
+2015-04-08 Brady Eidson <[email protected]>
+
+ Expose the "Share" menu for links, images, and media.
+ <rdar://problem/20435340> and https://bugs.webkit.org/show_bug.cgi?id=143502
+
+ Reviewed by Tim Horton.
+
+ * WebCoreSupport/WebContextMenuClient.cpp:
+ (WebContextMenuClient::shareMenuItem):
+ * WebCoreSupport/WebContextMenuClient.h:
+
2015-04-08 Anders Carlsson <[email protected]>
Add a WebApplicationCache::storage() and use it instead of the WebCore singleton
Modified: trunk/Source/WebKit/win/WebCoreSupport/WebContextMenuClient.cpp (182572 => 182573)
--- trunk/Source/WebKit/win/WebCoreSupport/WebContextMenuClient.cpp 2015-04-08 22:47:26 UTC (rev 182572)
+++ trunk/Source/WebKit/win/WebCoreSupport/WebContextMenuClient.cpp 2015-04-08 23:11:38 UTC (rev 182573)
@@ -144,3 +144,9 @@
notImplemented();
return false;
}
+
+ContextMenuItem WebContextMenuClient::shareMenuItem(const HitTestResult&)
+{
+ notImplemented();
+ return ContextMenuItem();
+}
Modified: trunk/Source/WebKit/win/WebCoreSupport/WebContextMenuClient.h (182572 => 182573)
--- trunk/Source/WebKit/win/WebCoreSupport/WebContextMenuClient.h 2015-04-08 22:47:26 UTC (rev 182572)
+++ trunk/Source/WebKit/win/WebCoreSupport/WebContextMenuClient.h 2015-04-08 23:11:38 UTC (rev 182573)
@@ -45,6 +45,8 @@
virtual void stopSpeaking();
virtual bool isSpeaking();
+ virtual WebCore::ContextMenuItem shareMenuItem(const WebCore::HitTestResult&);
+
private:
WebView* m_webView;
};
Modified: trunk/Source/WebKit2/ChangeLog (182572 => 182573)
--- trunk/Source/WebKit2/ChangeLog 2015-04-08 22:47:26 UTC (rev 182572)
+++ trunk/Source/WebKit2/ChangeLog 2015-04-08 23:11:38 UTC (rev 182573)
@@ -1,3 +1,30 @@
+2015-04-08 Brady Eidson <[email protected]>
+
+ Expose the "Share" menu for links, images, and media.
+ <rdar://problem/20435340> and https://bugs.webkit.org/show_bug.cgi?id=143502
+
+ Reviewed by Tim Horton.
+
+ * Shared/ContextMenuContextData.cpp:
+ (WebKit::ContextMenuContextData::ContextMenuContextData):
+
+ * Shared/WebHitTestResult.cpp:
+ (WebKit::WebHitTestResult::Data::Data):
+ * Shared/WebHitTestResult.h:
+
+ * UIProcess/WebPageProxy.cpp:
+ (WebKit::WebPageProxy::internalShowContextMenu):
+
+ * WebProcess/WebCoreSupport/WebContextMenuClient.cpp:
+ (WebKit::WebContextMenuClient::shareMenuItem):
+ * WebProcess/WebCoreSupport/WebContextMenuClient.h:
+
+ * WebProcess/WebCoreSupport/mac/WebContextMenuClientMac.mm:
+ (WebKit::WebContextMenuClient::shareSelectedTextMenuItem): Deleted.
+
+ * WebProcess/WebPage/mac/WebPageMac.mm:
+ (WebKit::WebPage::performActionMenuHitTestAtLocation):
+
2015-04-08 Anders Carlsson <[email protected]>
Add encoding and decoding of ints to WKRemoteObjectCoder
Modified: trunk/Source/WebKit2/Shared/ContextMenuContextData.cpp (182572 => 182573)
--- trunk/Source/WebKit2/Shared/ContextMenuContextData.cpp 2015-04-08 22:47:26 UTC (rev 182572)
+++ trunk/Source/WebKit2/Shared/ContextMenuContextData.cpp 2015-04-08 23:11:38 UTC (rev 182573)
@@ -45,7 +45,7 @@
}
ContextMenuContextData::ContextMenuContextData(const ContextMenuContext& context)
- : m_webHitTestResultData(WebHitTestResult::Data(context.hitTestResult()))
+ : m_webHitTestResultData(context.hitTestResult(), true)
, m_selectedText(context.selectedText())
#if ENABLE(SERVICE_CONTROLS)
, m_selectionIsEditable(false)
Modified: trunk/Source/WebKit2/Shared/WebHitTestResult.cpp (182572 => 182573)
--- trunk/Source/WebKit2/Shared/WebHitTestResult.cpp 2015-04-08 22:47:26 UTC (rev 182572)
+++ trunk/Source/WebKit2/Shared/WebHitTestResult.cpp 2015-04-08 23:11:38 UTC (rev 182573)
@@ -62,6 +62,38 @@
{
}
+WebHitTestResult::Data::Data(const WebCore::HitTestResult& hitTestResult, bool includeImage)
+ : absoluteImageURL(hitTestResult.absoluteImageURL().string())
+ , absolutePDFURL(hitTestResult.absolutePDFURL().string())
+ , absoluteLinkURL(hitTestResult.absoluteLinkURL().string())
+ , absoluteMediaURL(hitTestResult.absoluteMediaURL().string())
+ , linkLabel(hitTestResult.textContent())
+ , linkTitle(hitTestResult.titleDisplayString())
+ , isContentEditable(hitTestResult.isContentEditable())
+ , elementBoundingBox(elementBoundingBoxInWindowCoordinates(hitTestResult))
+ , isScrollbar(hitTestResult.scrollbar())
+ , isSelected(hitTestResult.isSelected())
+ , isTextNode(hitTestResult.innerNode() && hitTestResult.innerNode()->isTextNode())
+ , isOverTextInsideFormControlElement(hitTestResult.isOverTextInsideFormControlElement())
+ , allowsCopy(hitTestResult.allowsCopy())
+ , isDownloadableMedia(hitTestResult.isDownloadableMedia())
+ , imageSize(0)
+{
+ if (!includeImage)
+ return;
+
+ if (Image* image = hitTestResult.image()) {
+ RefPtr<SharedBuffer> buffer = image->data();
+ String imageExtension = image->filenameExtension();
+ if (!imageExtension.isEmpty() && buffer) {
+ imageSharedMemory = SharedMemory::create(buffer->size());
+ memcpy(imageSharedMemory->data(), buffer->data(), buffer->size());
+ imageExtension = imageExtension;
+ imageSize = buffer->size();
+ }
+ }
+}
+
WebHitTestResult::Data::~Data()
{
}
Modified: trunk/Source/WebKit2/Shared/WebHitTestResult.h (182572 => 182573)
--- trunk/Source/WebKit2/Shared/WebHitTestResult.h 2015-04-08 22:47:26 UTC (rev 182572)
+++ trunk/Source/WebKit2/Shared/WebHitTestResult.h 2015-04-08 23:11:38 UTC (rev 182573)
@@ -84,6 +84,7 @@
Data();
explicit Data(const WebCore::HitTestResult&);
+ Data(const WebCore::HitTestResult&, bool includeImage);
~Data();
void encode(IPC::ArgumentEncoder&) const;
Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp (182572 => 182573)
--- trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp 2015-04-08 22:47:26 UTC (rev 182572)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp 2015-04-08 23:11:38 UTC (rev 182573)
@@ -100,6 +100,7 @@
#include "WebProtectionSpace.h"
#include "WebUserContentControllerProxy.h"
#include "WebsiteDataStore.h"
+#include <WebCore/BitmapImage.h>
#include <WebCore/DragController.h>
#include <WebCore/DragData.h>
#include <WebCore/FloatRect.h>
@@ -4042,8 +4043,23 @@
continue;
}
- // Currently we only support the share menu for text selection, so create the appropriate menu item for that text selection now.
- ContextMenuItem coreItem = ContextMenuItem::shareSelectedTextMenuItem(contextMenuContextData.selectedText());
+ // Create the real Share menu item
+ URL absoluteLinkURL;
+ if (!contextMenuContextData.webHitTestResultData().absoluteLinkURL.isEmpty())
+ absoluteLinkURL = URL(ParsedURLString, contextMenuContextData.webHitTestResultData().absoluteLinkURL);
+
+ URL downloadableMediaURL;
+ if (!contextMenuContextData.webHitTestResultData().absoluteMediaURL.isEmpty() && contextMenuContextData.webHitTestResultData().isDownloadableMedia)
+ downloadableMediaURL = URL(ParsedURLString, contextMenuContextData.webHitTestResultData().absoluteMediaURL);
+
+ RefPtr<Image> image;
+ if (contextMenuContextData.webHitTestResultData().imageSharedMemory && contextMenuContextData.webHitTestResultData().imageSize) {
+ image = BitmapImage::create();
+ RefPtr<SharedBuffer> imageData = SharedBuffer::create((unsigned char*)contextMenuContextData.webHitTestResultData().imageSharedMemory->data(), contextMenuContextData.webHitTestResultData().imageSize);
+ image->setData(imageData.release(), true);
+ }
+
+ ContextMenuItem coreItem = ContextMenuItem::shareMenuItem(absoluteLinkURL, downloadableMediaURL, image.get(), contextMenuContextData.selectedText());
proposedAPIItems.append(WebContextMenuItem::create(coreItem));
}
Modified: trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebContextMenuClient.cpp (182572 => 182573)
--- trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebContextMenuClient.cpp 2015-04-08 22:47:26 UTC (rev 182572)
+++ trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebContextMenuClient.cpp 2015-04-08 23:11:38 UTC (rev 182573)
@@ -74,6 +74,11 @@
ASSERT_NOT_REACHED();
}
+ContextMenuItem WebContextMenuClient::shareMenuItem(const HitTestResult&)
+{
+ return ContextMenuItem(SubmenuType, ContextMenuItemTagShareMenu, emptyString());
+}
+
#if !PLATFORM(COCOA)
void WebContextMenuClient::searchWithGoogle(const Frame* frame)
{
Modified: trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebContextMenuClient.h (182572 => 182573)
--- trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebContextMenuClient.h 2015-04-08 22:47:26 UTC (rev 182572)
+++ trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebContextMenuClient.h 2015-04-08 23:11:38 UTC (rev 182573)
@@ -57,10 +57,10 @@
virtual bool isSpeaking() override;
virtual void speak(const String&) override;
virtual void stopSpeaking() override;
-
+ virtual WebCore::ContextMenuItem shareMenuItem(const WebCore::HitTestResult&) override;
+
#if PLATFORM(COCOA)
virtual void searchWithSpotlight() override;
- virtual WebCore::ContextMenuItem shareSelectedTextMenuItem(const String&) override;
#endif
#if USE(ACCESSIBILITY_CONTEXT_MENUS)
Modified: trunk/Source/WebKit2/WebProcess/WebCoreSupport/mac/WebContextMenuClientMac.mm (182572 => 182573)
--- trunk/Source/WebKit2/WebProcess/WebCoreSupport/mac/WebContextMenuClientMac.mm 2015-04-08 22:47:26 UTC (rev 182572)
+++ trunk/Source/WebKit2/WebProcess/WebCoreSupport/mac/WebContextMenuClientMac.mm 2015-04-08 23:11:38 UTC (rev 182573)
@@ -94,11 +94,6 @@
m_page->send(Messages::WebPageProxy::SearchWithSpotlight(selectedString));
}
-ContextMenuItem WebContextMenuClient::shareSelectedTextMenuItem(const String& selectedText)
-{
- return ContextMenuItem(SubmenuType, ContextMenuItemTagShareMenu, emptyString());
-}
-
} // namespace WebKit
#endif // ENABLE(CONTEXT_MENUS)
Modified: trunk/Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm (182572 => 182573)
--- trunk/Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm 2015-04-08 22:47:26 UTC (rev 182572)
+++ trunk/Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm 2015-04-08 23:11:38 UTC (rev 182573)
@@ -1033,7 +1033,7 @@
actionMenuHitTestPreventsDefault = element->dispatchMouseForceWillBegin();
}
- WebHitTestResult::Data actionMenuResult(hitTestResult);
+ WebHitTestResult::Data actionMenuResult(hitTestResult, !forImmediateAction);
actionMenuResult.hitTestLocationInViewCooordinates = locationInViewCooordinates;
RefPtr<Range> selectionRange = corePage()->focusController().focusedOrMainFrame().selection().selection().firstRange();
@@ -1059,19 +1059,6 @@
m_lastActionMenuRangeForSelection = lookupRange;
m_lastActionMenuHitTestResult = hitTestResult;
- if (!forImmediateAction) {
- if (Image* image = hitTestResult.image()) {
- RefPtr<SharedBuffer> buffer = image->data();
- String imageExtension = image->filenameExtension();
- if (!imageExtension.isEmpty() && buffer) {
- actionMenuResult.imageSharedMemory = SharedMemory::create(buffer->size());
- memcpy(actionMenuResult.imageSharedMemory->data(), buffer->data(), buffer->size());
- actionMenuResult.imageExtension = imageExtension;
- actionMenuResult.imageSize = buffer->size();
- }
- }
- }
-
bool pageOverlayDidOverrideDataDetectors = false;
for (const auto& overlay : mainFrame.pageOverlayController().pageOverlays()) {
WebPageOverlay* webOverlay = WebPageOverlay::fromCoreOverlay(*overlay);