Change Image Controls replacement to use selection and paste
authorbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 22 Apr 2014 19:22:28 +0000 (19:22 +0000)
committerbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 22 Apr 2014 19:22:28 +0000 (19:22 +0000)
<rdar://problem/16302722> and https://bugs.webkit.org/show_bug.cgi?id=131992

Reviewed by Tim Horton.

Source/WebCore:
* WebCore.exp.in: Remove deleted symbol.

* html/shadow/mac/ImageControlsButtonElementMac.cpp:
(WebCore::ImageControlsButtonElementMac::defaultEventHandler):

* page/ContextMenuController.cpp:
(WebCore::ContextMenuController::showImageControlsMenu): Select the image element
  before showing the menu.
(WebCore::ContextMenuController::replaceControlledImage): Deleted.
* page/ContextMenuController.h:

Source/WebKit/mac:
* Misc/WebSharingServicePickerController.mm:
(-[WebSharingServicePickerController sharingService:didShareItems:]): Write the
  replacement data to a special pasteboard, then replace the current selection from
  that pasteboard.

Source/WebKit2:
* UIProcess/mac/WebContextMenuProxyMac.mm:
(-[WKSharingServicePickerDelegate sharingService:didShareItems:]): Write the
  replacement data to a special pasteboard, then replace the current selection from
  that pasteboard.

Remove all other code used to support the old replacement mechanism:
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::replaceControlledImage): Deleted.
* UIProcess/WebPageProxy.h:
* UIProcess/mac/WebContextMenuProxyMac.h:
(WebKit::WebContextMenuProxyMac::page):
(WebKit::WebContextMenuProxyMac::replaceControlledImage): Deleted.
* WebProcess/WebPage/WebContextMenu.cpp:
(WebKit::WebContextMenu::replaceControlledImage): Deleted.
* WebProcess/WebPage/WebContextMenu.h:
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::replaceControlledImage): Deleted.
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/WebPage.messages.in:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@167674 268f45cc-cd09-0410-ab3c-d52691b4dbfc

17 files changed:
Source/WebCore/ChangeLog
Source/WebCore/WebCore.exp.in
Source/WebCore/html/shadow/mac/ImageControlsButtonElementMac.cpp
Source/WebCore/page/ContextMenuController.cpp
Source/WebCore/page/ContextMenuController.h
Source/WebKit/mac/ChangeLog
Source/WebKit/mac/Misc/WebSharingServicePickerController.mm
Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/WebPageProxy.cpp
Source/WebKit2/UIProcess/WebPageProxy.h
Source/WebKit2/UIProcess/mac/WebContextMenuProxyMac.h
Source/WebKit2/UIProcess/mac/WebContextMenuProxyMac.mm
Source/WebKit2/WebProcess/WebPage/WebContextMenu.cpp
Source/WebKit2/WebProcess/WebPage/WebContextMenu.h
Source/WebKit2/WebProcess/WebPage/WebPage.cpp
Source/WebKit2/WebProcess/WebPage/WebPage.h
Source/WebKit2/WebProcess/WebPage/WebPage.messages.in

index ac1429b..5be0e95 100644 (file)
@@ -1,3 +1,21 @@
+2014-04-22  Brady Eidson  <beidson@apple.com>
+
+        Change Image Controls replacement to use selection and paste
+        <rdar://problem/16302722> and https://bugs.webkit.org/show_bug.cgi?id=131992
+
+        Reviewed by Tim Horton.
+
+        * WebCore.exp.in: Remove deleted symbol.
+
+        * html/shadow/mac/ImageControlsButtonElementMac.cpp:
+        (WebCore::ImageControlsButtonElementMac::defaultEventHandler):
+
+        * page/ContextMenuController.cpp:
+        (WebCore::ContextMenuController::showImageControlsMenu): Select the image element
+          before showing the menu.
+        (WebCore::ContextMenuController::replaceControlledImage): Deleted.
+        * page/ContextMenuController.h:
+
 2014-04-22  David Hyatt  <hyatt@apple.com>
 
         REGRESSION: Hitting asserts in new flow thread selection code.
index f203b5b..d313473 100644 (file)
@@ -2987,10 +2987,6 @@ __ZNK7WebCore12IconDatabase24shouldStopThreadActivityEv
 __ZNK7WebCore12IconDatabase9isEnabledEv
 #endif
 
-#if ENABLE(IMAGE_CONTROLS)
-__ZN7WebCore21ContextMenuController22replaceControlledImageEN3WTF10PassRefPtrINS_5ImageEEE
-#endif
-
 #if ENABLE(INDEXED_DATABASE)
 __ZN7WebCore10IDBKeyData14setNumberValueEd
 __ZN7WebCore10IDBKeyData6decodeERNS_12KeyedDecoderERS0_
index 1b8bc00..e12e677 100644 (file)
 
 #include "ContextMenuController.h"
 #include "Event.h"
+#include "Frame.h"
+#include "FrameSelection.h"
 #include "HTMLDivElement.h"
 #include "Page.h"
+#include "Range.h"
 #include "RenderBlockFlow.h"
 #include "RenderStyle.h"
 #include "RenderTheme.h"
+#include "ShadowRoot.h"
 
 namespace WebCore {
 
@@ -99,8 +103,33 @@ PassRefPtr<ImageControlsButtonElementMac> ImageControlsButtonElementMac::maybeCr
 void ImageControlsButtonElementMac::defaultEventHandler(Event* event)
 {
     if (event->type() == eventNames().clickEvent) {
-        if (Page* page = document().page())
-            page->contextMenuController().showImageControlsMenu(event);
+        // Before showing the menu, change the current selection to the represented Image element.
+        ContainerNode* parent = parentNode();
+        Element* hostElement = nullptr;
+        while (parent) {
+            if (parent->isShadowRoot()) {
+                hostElement = static_cast<ShadowRoot*>(parent)->hostElement();
+                break;
+            }
+            parent = parent->parentNode();
+        }
+
+        if (!hostElement)
+            return;
+        ASSERT(isHTMLImageElement(hostElement));
+
+        Frame* frame = document().frame();
+        if (!frame)
+            return;
+
+        Page* page = document().page();
+        if (!page)
+            return;
+
+        RefPtr<Range> range = Range::create(document(), Position(hostElement, Position::PositionIsBeforeAnchor), Position(hostElement, Position::PositionIsAfterAnchor));
+        frame->selection().setSelection(VisibleSelection(range.get()));
+
+        page->contextMenuController().showImageControlsMenu(event);
         event->setDefaultHandled();
         return;
     }
index 17ae456..542319a 100644 (file)
@@ -1452,24 +1452,6 @@ void ContextMenuController::showImageControlsMenu(Event* event)
     handleContextMenuEvent(event);
     m_client.showContextMenu();
 }
-
-void ContextMenuController::replaceControlledImage(PassRefPtr<Image> newImage)
-{
-    Node* node = m_context.hitTestResult().innerNonSharedNode();
-    if (!node)
-        return;
-
-    Frame* frame = node->document().frame();
-    if (!frame)
-        return;
-
-    RenderObject* renderer = node->renderer();
-    if (!renderer || !renderer->isRenderImage())
-        return;
-
-    CachedResourceHandle<CachedImage> replacedImage = new CachedImage(URL::fakeURLWithRelativePart("image"), newImage.get(), frame->page()->sessionID());
-    toRenderImage(renderer)->imageResource().setCachedImage(replacedImage.get());
-}
 #endif
 
 } // namespace WebCore
index 858e899..9a4c41c 100644 (file)
@@ -71,7 +71,6 @@ public:
 
 #if ENABLE(IMAGE_CONTROLS)
     void showImageControlsMenu(Event*);
-    void replaceControlledImage(PassRefPtr<Image>);
 #endif
 
 private:
index 6ba1434..eb7f6a6 100644 (file)
@@ -1,3 +1,15 @@
+2014-04-22  Brady Eidson  <beidson@apple.com>
+
+        Change Image Controls replacement to use selection and paste
+        <rdar://problem/16302722> and https://bugs.webkit.org/show_bug.cgi?id=131992
+
+        Reviewed by Tim Horton.
+
+        * Misc/WebSharingServicePickerController.mm:
+        (-[WebSharingServicePickerController sharingService:didShareItems:]): Write the
+          replacement data to a special pasteboard, then replace the current selection from
+          that pasteboard.
+
 2014-04-21  Eric Carlson  <eric.carlson@apple.com>
 
         [Mac] implement WebKitDataCue
index 025aae1..9b9a002 100644 (file)
 #import "WebViewInternal.h"
 #import <AppKit/NSSharingService.h>
 #import <WebCore/BitmapImage.h>
+#import <WebCore/Editor.h>
+#import <WebCore/FocusController.h>
+#import <WebCore/Frame.h>
+#import <WebCore/FrameSelection.h>
 #import <WebCore/ContextMenuController.h>
 #import <WebCore/Page.h>
 
@@ -48,6 +52,8 @@ typedef enum {
 
 #endif
 
+static NSString *imageControlPasteboardName = @"WebKitImageControlsPasteboard";
+
 using namespace WebCore;
 
 @implementation WebSharingServicePickerController
@@ -119,13 +125,21 @@ using namespace WebCore;
 
     RetainPtr<CGImageSourceRef> source = adoptCF(CGImageSourceCreateWithData((CFDataRef)[items objectAtIndex:0], NULL));
     RetainPtr<CGImageRef> cgImage = adoptCF(CGImageSourceCreateImageAtIndex(source.get(), 0, NULL));
-    RefPtr<Image> image = BitmapImage::create(cgImage.get());
+
+    if (!cgImage)
+        return;
 
     Page* page = [_menuClient->webView() page];
     if (!page)
         return;
 
-    page->contextMenuController().replaceControlledImage(image.get());
+    NSPasteboard *pasteboard = [NSPasteboard pasteboardWithName:imageControlPasteboardName];
+    [pasteboard declareTypes:@[ NSPasteboardTypeTIFF ] owner:nil];
+    [pasteboard setData:[items objectAtIndex:0] forType:NSPasteboardTypeTIFF];
+
+    Frame& frame = page->focusController().focusedOrMainFrame();
+    if (!frame.selection().isNone())
+        frame.editor().readSelectionFromPasteboard(imageControlPasteboardName);
 
     [self clear];
 }
index cfb4ec7..5731c82 100644 (file)
@@ -1,3 +1,30 @@
+2014-04-22  Brady Eidson  <beidson@apple.com>
+
+        Change Image Controls replacement to use selection and paste
+        <rdar://problem/16302722> and https://bugs.webkit.org/show_bug.cgi?id=131992
+
+        Reviewed by Tim Horton.
+
+        * UIProcess/mac/WebContextMenuProxyMac.mm:
+        (-[WKSharingServicePickerDelegate sharingService:didShareItems:]): Write the
+          replacement data to a special pasteboard, then replace the current selection from
+          that pasteboard.
+
+        Remove all other code used to support the old replacement mechanism:
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::replaceControlledImage): Deleted.
+        * UIProcess/WebPageProxy.h:
+        * UIProcess/mac/WebContextMenuProxyMac.h:
+        (WebKit::WebContextMenuProxyMac::page):
+        (WebKit::WebContextMenuProxyMac::replaceControlledImage): Deleted.
+        * WebProcess/WebPage/WebContextMenu.cpp:
+        (WebKit::WebContextMenu::replaceControlledImage): Deleted.
+        * WebProcess/WebPage/WebContextMenu.h:
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::replaceControlledImage): Deleted.
+        * WebProcess/WebPage/WebPage.h:
+        * WebProcess/WebPage/WebPage.messages.in:
+
 2014-04-22  Eunmi Lee  <eunmi15.lee@samsung.com>
 
         [EFL][WK2] Remove duplicated code to set size to the DrawingArea.
index a858061..731817c 100644 (file)
@@ -3445,16 +3445,6 @@ void WebPageProxy::internalShowContextMenu(const IntPoint& menuLocation, const C
     m_contextMenuClient.contextMenuDismissed(this);
 }
 
-#if ENABLE(IMAGE_CONTROLS)
-void WebPageProxy::replaceControlledImage(PassRefPtr<ShareableBitmap> newBitmap)
-{
-    RefPtr<ShareableBitmap> bitmap = newBitmap;
-    ShareableBitmap::Handle bitmapHandle;
-    bitmap->createHandle(bitmapHandle);
-    m_process->send(Messages::WebPage::ReplaceControlledImage(bitmapHandle), m_pageID);
-}
-#endif
-
 void WebPageProxy::contextMenuItemSelected(const WebContextMenuItemData& item)
 {
     // Application custom items don't need to round-trip through to WebCore in the WebProcess.
index 4a0bbd7..438c23b 100644 (file)
@@ -1059,10 +1059,6 @@ public:
 
     void takeSnapshot(WebCore::IntRect, WebCore::IntSize bitmapSize, SnapshotOptions, ImageCallback::CallbackFunction);
 
-#if ENABLE(IMAGE_CONTROLS)
-    void replaceControlledImage(PassRefPtr<ShareableBitmap>);
-#endif
-
 private:
     WebPageProxy(PageClient&, WebProcessProxy&, uint64_t pageID, const WebPageConfiguration&);
     void platformInitialize();
index b874936..397bcd2 100644 (file)
@@ -55,9 +55,9 @@ public:
 
 #if ENABLE(IMAGE_CONTROLS)
     void clearImageServicesMenu();
-    void replaceControlledImage(CGImageRef newImage);
 #endif
 
+    WebPageProxy& page() const { return *m_page; }
     NSWindow *window() const;
 
 private:
index c2786c5..3c19a5a 100644 (file)
@@ -56,7 +56,10 @@ typedef enum {
 @property NSSharingServicePickerStyle style;
 - (NSMenu *)menu;
 @end
-#endif
+
+static NSString *imageControlPasteboardName = @"WebKitImageControlsPasteboard";
+
+#endif // ENABLE(IMAGE_CONTROLS)
 
 using namespace WebCore;
 
@@ -231,7 +234,15 @@ using namespace WebCore;
 {
     RetainPtr<CGImageSourceRef> source = adoptCF(CGImageSourceCreateWithData((CFDataRef)[items objectAtIndex:0], NULL));
     RetainPtr<CGImageRef> image = adoptCF(CGImageSourceCreateImageAtIndex(source.get(), 0, NULL));
-    _menuProxy->replaceControlledImage(image.get());
+
+    if (!image)
+        return;
+
+    NSPasteboard *pasteboard = [NSPasteboard pasteboardWithName:imageControlPasteboardName];
+    [pasteboard declareTypes:@[ NSPasteboardTypeTIFF ] owner:nil];
+    [pasteboard setData:[items objectAtIndex:0] forType:NSPasteboardTypeTIFF];
+    
+    _menuProxy->page().readSelectionFromPasteboard(imageControlPasteboardName);
 }
 
 - (NSWindow *)sharingService:(NSSharingService *)sharingService sourceWindowForShareItems:(NSArray *)items sharingContentScope:(NSSharingContentScope *)sharingContentScope
@@ -249,6 +260,7 @@ WebContextMenuProxyMac::WebContextMenuProxyMac(WKView* webView, WebPageProxy* pa
     : m_webView(webView)
     , m_page(page)
 {
+    ASSERT(m_page);
 }
 
 WebContextMenuProxyMac::~WebContextMenuProxyMac()
@@ -433,17 +445,6 @@ NSWindow *WebContextMenuProxyMac::window() const
     return [m_webView window];
 }
 
-#if ENABLE(IMAGE_CONTROLS)
-void WebContextMenuProxyMac::replaceControlledImage(CGImageRef newImage)
-{
-    FloatSize newImageSize(CGImageGetWidth(newImage), CGImageGetHeight(newImage));
-    RefPtr<ShareableBitmap> newBitmap = ShareableBitmap::createShareable(expandedIntSize(newImageSize), ShareableBitmap::SupportsAlpha);
-    newBitmap->createGraphicsContext()->drawNativeImage(newImage, newImageSize, ColorSpaceDeviceRGB, FloatRect(FloatPoint(), newImageSize), FloatRect(FloatPoint(), newImageSize));
-
-    m_page->replaceControlledImage(newBitmap.release());
-}
-#endif
-
 } // namespace WebKit
 
 #endif // PLATFORM(MAC)
index 098669d..28cd34d 100644 (file)
@@ -77,13 +77,6 @@ void WebContextMenu::itemSelected(const WebContextMenuItemData& item)
     m_page->corePage()->contextMenuController().contextMenuItemSelected(&coreItem);
 }
 
-#if ENABLE(IMAGE_CONTROLS)
-void WebContextMenu::replaceControlledImage(PassRefPtr<Image> newImage)
-{
-    m_page->corePage()->contextMenuController().replaceControlledImage(newImage);
-}
-#endif
-
 void WebContextMenu::menuItemsWithUserData(Vector<WebContextMenuItemData> &menuItems, RefPtr<API::Object>& userData) const
 {
     ContextMenuController& controller = m_page->corePage()->contextMenuController();
index d9b1883..fc63afb 100644 (file)
@@ -50,10 +50,6 @@ public:
     void itemSelected(const WebContextMenuItemData&);
     Vector<WebContextMenuItemData> items() const;
 
-#if ENABLE(IMAGE_CONTROLS)
-    void replaceControlledImage(PassRefPtr<WebCore::Image>);
-#endif
-
 private:
     WebContextMenu(WebPage*);
     void menuItemsWithUserData(Vector<WebContextMenuItemData>&, RefPtr<API::Object>&) const;
index bdbd558..f8235d7 100644 (file)
@@ -3114,15 +3114,6 @@ void WebPage::didSelectItemFromActiveContextMenu(const WebContextMenuItemData& i
 }
 #endif
 
-#if ENABLE(IMAGE_CONTROLS)
-void WebPage::replaceControlledImage(const ShareableBitmap::Handle& bitmapHandle)
-{
-    RefPtr<ShareableBitmap> bitmap = ShareableBitmap::create(bitmapHandle);
-    if (bitmap)
-        m_contextMenu->replaceControlledImage(bitmap->createImage());
-}
-#endif
-
 void WebPage::replaceSelectionWithText(Frame* frame, const String& text)
 {
     bool selectReplacement = true;
index d68d2c7..6df340a 100644 (file)
@@ -771,10 +771,6 @@ public:
     PassRefPtr<WebCore::DocumentLoader> createDocumentLoader(WebCore::Frame&, const WebCore::ResourceRequest&, const WebCore::SubstituteData&);
 
     void getBytecodeProfile(uint64_t callbackID);
-
-#if ENABLE(IMAGE_CONTROLS)
-    void replaceControlledImage(const ShareableBitmap::Handle&);
-#endif
     
     // Some platforms require accessibility-enabled processes to spin the run loop so that the WebProcess doesn't hang.
     // While this is not ideal, it does not have to be applied to every platform at the moment.
index 3b0ae77..ab5a4cd 100644 (file)
@@ -362,8 +362,4 @@ messages -> WebPage LegacyReceiver {
     GetBytecodeProfile(uint64_t callbackID)
     
     TakeSnapshot(WebCore::IntRect snapshotRect, WebCore::IntSize bitmapSize, uint32_t options, uint64_t callbackID)
-
-#if ENABLE(IMAGE_CONTROLS)
-    ReplaceControlledImage(WebKit::ShareableBitmap::Handle newBitmapHandle)
-#endif
 }