PDFPlugin: Context menus in RTL are left-aligned
authortimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 3 Aug 2018 01:11:46 +0000 (01:11 +0000)
committertimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 3 Aug 2018 01:11:46 +0000 (01:11 +0000)
https://bugs.webkit.org/show_bug.cgi?id=188292
<rdar://problem/32293787>

Reviewed by Simon Fraser.

* WebProcess/Plugins/PDF/PDFLayerControllerSPI.h:
Add some SPI.

* WebProcess/Plugins/PDF/PDFPlugin.mm:
(WebKit::PDFPlugin::handleContextMenuEvent):
Translate UI layout direction back into the platform enum, and pass it to PDFKit.

* WebProcess/WebPage/WebPage.h:
(WebKit::WebPage::userInterfaceLayoutDirection const):
Add a getter for UI layout direction.

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

Source/WebKit/ChangeLog
Source/WebKit/WebProcess/Plugins/PDF/PDFLayerControllerSPI.h
Source/WebKit/WebProcess/Plugins/PDF/PDFPlugin.mm
Source/WebKit/WebProcess/WebPage/WebPage.h

index 00e39db..1473d31 100644 (file)
@@ -1,3 +1,22 @@
+2018-08-02  Tim Horton  <timothy_horton@apple.com>
+
+        PDFPlugin: Context menus in RTL are left-aligned
+        https://bugs.webkit.org/show_bug.cgi?id=188292
+        <rdar://problem/32293787>
+
+        Reviewed by Simon Fraser.
+
+        * WebProcess/Plugins/PDF/PDFLayerControllerSPI.h:
+        Add some SPI.
+
+        * WebProcess/Plugins/PDF/PDFPlugin.mm:
+        (WebKit::PDFPlugin::handleContextMenuEvent):
+        Translate UI layout direction back into the platform enum, and pass it to PDFKit.
+
+        * WebProcess/WebPage/WebPage.h:
+        (WebKit::WebPage::userInterfaceLayoutDirection const):
+        Add a getter for UI layout direction.
+
 2018-08-02  Chris Dumez  <cdumez@apple.com>
 
         Regression(r234486): assertion hit in ~CallbackAggregator()
index 8fafcf6..5bfc261 100644 (file)
@@ -101,6 +101,9 @@ typedef NS_ENUM(NSInteger, PDFLayerControllerCursorType) {
 - (void)mouseEntered:(NSEvent *)event;
 - (void)mouseExited:(NSEvent *)event;
 
+#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101300
+- (NSMenu *)menuForEvent:(NSEvent *)event withUserInterfaceLayoutDirection:(NSUserInterfaceLayoutDirection)direction;
+#endif
 - (NSMenu *)menuForEvent:(NSEvent *)event;
 
 - (NSArray *)findString:(NSString *)string caseSensitive:(BOOL)isCaseSensitive highlightMatches:(BOOL)shouldHighlightMatches;
index 9f0d948..3c895bc 100644 (file)
@@ -1588,34 +1588,41 @@ bool PDFPlugin::showContextMenuAtPoint(const IntPoint& point)
 
 bool PDFPlugin::handleContextMenuEvent(const WebMouseEvent& event)
 {
+    if (!webFrame()->page())
+        return false;
+
+    WebPage* webPage = webFrame()->page();
     FrameView* frameView = webFrame()->coreFrame()->view();
     IntPoint point = frameView->contentsToScreen(IntRect(frameView->windowToContents(event.position()), IntSize())).location();
 
-    if (NSMenu *nsMenu = [m_pdfLayerController menuForEvent:nsEventForWebMouseEvent(event)]) {
-        Vector<PDFContextMenuItem> items;
-        auto itemCount = [nsMenu numberOfItems];
-        for (int i = 0; i < itemCount; i++) {
-            auto item = [nsMenu itemAtIndex:i];
-            if ([item submenu])
-                continue;
-            PDFContextMenuItem menuItem { String([item title]), !![item isEnabled], !![item isSeparatorItem], static_cast<int>([item state]), [item action], i };
-            items.append(WTFMove(menuItem));
-        }
-        PDFContextMenu contextMenu { point, WTFMove(items) };
+#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101300
+    NSUserInterfaceLayoutDirection uiLayoutDirection = webPage->userInterfaceLayoutDirection() == UserInterfaceLayoutDirection::LTR ? NSUserInterfaceLayoutDirectionLeftToRight : NSUserInterfaceLayoutDirectionRightToLeft;
+    NSMenu *nsMenu = [m_pdfLayerController menuForEvent:nsEventForWebMouseEvent(event) withUserInterfaceLayoutDirection:uiLayoutDirection];
+#else
+    NSMenu *nsMenu = [m_pdfLayerController menuForEvent:nsEventForWebMouseEvent(event)];
+#endif
 
-        if (!webFrame()->page())
-            return false;
+    if (!nsMenu)
+        return false;
+    
+    Vector<PDFContextMenuItem> items;
+    auto itemCount = [nsMenu numberOfItems];
+    for (int i = 0; i < itemCount; i++) {
+        auto item = [nsMenu itemAtIndex:i];
+        if ([item submenu])
+            continue;
+        PDFContextMenuItem menuItem { String([item title]), !![item isEnabled], !![item isSeparatorItem], static_cast<int>([item state]), [item action], i };
+        items.append(WTFMove(menuItem));
+    }
+    PDFContextMenu contextMenu { point, WTFMove(items) };
 
-        std::optional<int> selectedIndex = -1;
-        webFrame()->page()->sendSync(Messages::WebPageProxy::ShowPDFContextMenu(contextMenu), Messages::WebPageProxy::ShowPDFContextMenu::Reply(selectedIndex));
+    std::optional<int> selectedIndex = -1;
+    webPage->sendSync(Messages::WebPageProxy::ShowPDFContextMenu(contextMenu), Messages::WebPageProxy::ShowPDFContextMenu::Reply(selectedIndex));
 
-        if (selectedIndex && *selectedIndex >= 0 && *selectedIndex < itemCount)
-            [nsMenu performActionForItemAtIndex:*selectedIndex];
+    if (selectedIndex && *selectedIndex >= 0 && *selectedIndex < itemCount)
+        [nsMenu performActionForItemAtIndex:*selectedIndex];
 
-        return true;
-    }
-    
-    return false;
+    return true;
 }
 
 bool PDFPlugin::handleKeyboardEvent(const WebKeyboardEvent& event)
index 827ad6c..cbbc48c 100644 (file)
@@ -1086,6 +1086,8 @@ public:
 
     UserContentControllerIdentifier userContentControllerIdentifier() const { return m_userContentController->identifier(); }
 
+    WebCore::UserInterfaceLayoutDirection userInterfaceLayoutDirection() const { return m_userInterfaceLayoutDirection; }
+
     bool isSuspended() const { return m_isSuspended; }
 
     void didReceiveWebPageMessage(IPC::Connection&, IPC::Decoder&);