Web Inspector: RTL: keyboard shortcuts with directionality need to be flipped (forward/back, etc)
https://bugs.webkit.org/show_bug.cgi?id=165761

Reviewed by Matt Baker.

Original patch by Devin Rousso.

* UserInterface/Views/ContentBrowser.js:
(WebInspector.ContentBrowser):
* UserInterface/Views/TabBrowser.js:
(WebInspector.TabBrowser):
Flip the functionality of keyboard shortcuts when in RTL so that the action of
pressing the left or right arrows/curly braces matches what happens when the
corresponding left or right buttons are clicked.

* UserInterface/Views/DataGrid.js:
(WebInspector.DataGrid.prototype._keyDown):
* UserInterface/Views/LogContentView.js:
(WebInspector.LogContentView.prototype._keyDown):
* UserInterface/Views/TreeOutline.js:
(WebInspector.TreeOutline.prototype._treeKeyDown):
Flip the Left and Right keyboard shortcuts to expand/collapse the selected item when in RTL.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@214514 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebInspectorUI/ChangeLog b/Source/WebInspectorUI/ChangeLog
index 6579ce5..8b90133 100644
--- a/Source/WebInspectorUI/ChangeLog
+++ b/Source/WebInspectorUI/ChangeLog
@@ -1,5 +1,30 @@
 2017-03-28  Brian Burg  <bburg@apple.com>
 
+        Web Inspector: RTL: keyboard shortcuts with directionality need to be flipped (forward/back, etc)
+        https://bugs.webkit.org/show_bug.cgi?id=165761
+
+        Reviewed by Matt Baker.
+
+        Original patch by Devin Rousso.
+
+        * UserInterface/Views/ContentBrowser.js:
+        (WebInspector.ContentBrowser):
+        * UserInterface/Views/TabBrowser.js:
+        (WebInspector.TabBrowser):
+        Flip the functionality of keyboard shortcuts when in RTL so that the action of
+        pressing the left or right arrows/curly braces matches what happens when the
+        corresponding left or right buttons are clicked.
+
+        * UserInterface/Views/DataGrid.js:
+        (WebInspector.DataGrid.prototype._keyDown):
+        * UserInterface/Views/LogContentView.js:
+        (WebInspector.LogContentView.prototype._keyDown):
+        * UserInterface/Views/TreeOutline.js:
+        (WebInspector.TreeOutline.prototype._treeKeyDown):
+        Flip the Left and Right keyboard shortcuts to expand/collapse the selected item when in RTL.
+
+2017-03-28  Brian Burg  <bburg@apple.com>
+
         Web Inspector: Add "Disable Caches" option that only applies to the inspected page while Web Inspector is open
         https://bugs.webkit.org/show_bug.cgi?id=169865
         <rdar://problem/31250573>
diff --git a/Source/WebInspectorUI/UserInterface/Views/ContentBrowser.js b/Source/WebInspectorUI/UserInterface/Views/ContentBrowser.js
index dd5687b..856e880 100644
--- a/Source/WebInspectorUI/UserInterface/Views/ContentBrowser.js
+++ b/Source/WebInspectorUI/UserInterface/Views/ContentBrowser.js
@@ -39,23 +39,30 @@
         this.addSubview(this._contentViewContainer);
 
         if (!disableBackForward) {
-            this._backKeyboardShortcut = new WebInspector.KeyboardShortcut(WebInspector.KeyboardShortcut.Modifier.CommandOrControl | WebInspector.KeyboardShortcut.Modifier.Control, WebInspector.KeyboardShortcut.Key.Left, this._backButtonClicked.bind(this), this.element);
-            this._forwardKeyboardShortcut = new WebInspector.KeyboardShortcut(WebInspector.KeyboardShortcut.Modifier.CommandOrControl | WebInspector.KeyboardShortcut.Modifier.Control, WebInspector.KeyboardShortcut.Key.Right, this._forwardButtonClicked.bind(this), this.element);
+            let isRTL = WebInspector.resolvedLayoutDirection() === WebInspector.LayoutDirection.RTL;
+
+            let goBack = () => { this.goBack(); };
+            let goForward = () => { this.goForward(); };
+
+            let backShortcutKey = isRTL ? WebInspector.KeyboardShortcut.Key.Right : WebInspector.KeyboardShortcut.Key.Left;
+            let forwardShortcutKey = isRTL ? WebInspector.KeyboardShortcut.Key.Left : WebInspector.KeyboardShortcut.Key.Right;
+            this._backKeyboardShortcut = new WebInspector.KeyboardShortcut(WebInspector.KeyboardShortcut.Modifier.CommandOrControl | WebInspector.KeyboardShortcut.Modifier.Control, backShortcutKey, goBack, this.element);
+            this._forwardKeyboardShortcut = new WebInspector.KeyboardShortcut(WebInspector.KeyboardShortcut.Modifier.CommandOrControl | WebInspector.KeyboardShortcut.Modifier.Control, forwardShortcutKey, goForward, this.element);
 
             let leftArrow = "Images/BackForwardArrows.svg#left-arrow-mask";
             let rightArrow = "Images/BackForwardArrows.svg#right-arrow-mask";
-            let backButtonImage = WebInspector.resolvedLayoutDirection() === WebInspector.LayoutDirection.RTL ? rightArrow : leftArrow;
-            let forwardButtonImage = WebInspector.resolvedLayoutDirection() === WebInspector.LayoutDirection.RTL ? leftArrow : rightArrow;
+            let backButtonImage = isRTL ? rightArrow : leftArrow;
+            let forwardButtonImage = isRTL ? leftArrow : rightArrow;
 
-            this._backButtonNavigationItem = new WebInspector.ButtonNavigationItem("back", WebInspector.UIString("Back (%s)").format(this._backKeyboardShortcut.displayName), backButtonImage, 8, 13);
-            this._backButtonNavigationItem.addEventListener(WebInspector.ButtonNavigationItem.Event.Clicked, this._backButtonClicked, this);
-            this._backButtonNavigationItem.enabled = false;
-            this._navigationBar.addNavigationItem(this._backButtonNavigationItem);
+            this._backNavigationItem = new WebInspector.ButtonNavigationItem("back", WebInspector.UIString("Back (%s)").format(this._backKeyboardShortcut.displayName), backButtonImage, 8, 13);
+            this._backNavigationItem.addEventListener(WebInspector.ButtonNavigationItem.Event.Clicked, goBack);
+            this._backNavigationItem.enabled = false;
+            this._navigationBar.addNavigationItem(this._backNavigationItem);
 
-            this._forwardButtonNavigationItem = new WebInspector.ButtonNavigationItem("forward", WebInspector.UIString("Forward (%s)").format(this._forwardKeyboardShortcut.displayName), forwardButtonImage, 8, 13);
-            this._forwardButtonNavigationItem.addEventListener(WebInspector.ButtonNavigationItem.Event.Clicked, this._forwardButtonClicked, this);
-            this._forwardButtonNavigationItem.enabled = false;
-            this._navigationBar.addNavigationItem(this._forwardButtonNavigationItem);
+            this._forwardNavigationItem = new WebInspector.ButtonNavigationItem("forward", WebInspector.UIString("Forward (%s)").format(this._forwardKeyboardShortcut.displayName), forwardButtonImage, 8, 13);
+            this._forwardNavigationItem.addEventListener(WebInspector.ButtonNavigationItem.Event.Clicked, goForward);
+            this._forwardNavigationItem.enabled = false;
+            this._navigationBar.addNavigationItem(this._forwardNavigationItem);
 
             this._navigationBar.addNavigationItem(new WebInspector.DividerNavigationItem);
         }
@@ -282,16 +289,6 @@
 
     // Private
 
-    _backButtonClicked(event)
-    {
-        this.goBack();
-    }
-
-    _forwardButtonClicked(event)
-    {
-        this.goForward();
-    }
-
     _findBannerDidShow(event)
     {
         var currentContentView = this.currentContentView;
@@ -363,11 +360,11 @@
 
     _updateBackForwardButtons()
     {
-        if (!this._backButtonNavigationItem || !this._forwardButtonNavigationItem)
+        if (!this._backNavigationItem || !this._forwardNavigationItem)
             return;
 
-        this._backButtonNavigationItem.enabled = this.canGoBack();
-        this._forwardButtonNavigationItem.enabled = this.canGoForward();
+        this._backNavigationItem.enabled = this.canGoBack();
+        this._forwardNavigationItem.enabled = this.canGoForward();
     }
 
     _updateContentViewNavigationItems()
diff --git a/Source/WebInspectorUI/UserInterface/Views/DataGrid.js b/Source/WebInspectorUI/UserInterface/Views/DataGrid.js
index 3815cb6..346e37c 100644
--- a/Source/WebInspectorUI/UserInterface/Views/DataGrid.js
+++ b/Source/WebInspectorUI/UserInterface/Views/DataGrid.js
@@ -1371,6 +1371,8 @@
         if (!this.selectedNode || event.shiftKey || event.metaKey || event.ctrlKey || this._editing)
             return;
 
+        let isRTL = WebInspector.resolvedLayoutDirection() === WebInspector.LayoutDirection.RTL;
+
         var handled = false;
         var nextSelectedNode;
         if (event.keyIdentifier === "Up" && !event.altKey) {
@@ -1383,7 +1385,7 @@
             while (nextSelectedNode && !nextSelectedNode.selectable)
                 nextSelectedNode = nextSelectedNode.traverseNextNode(true);
             handled = nextSelectedNode ? true : false;
-        } else if (event.keyIdentifier === "Left") {
+        } else if ((!isRTL && event.keyIdentifier === "Left") || (isRTL && event.keyIdentifier === "Right")) {
             if (this.selectedNode.expanded) {
                 if (event.altKey)
                     this.selectedNode.collapseRecursively();
@@ -1398,7 +1400,7 @@
                 } else if (this.selectedNode.parent)
                     this.selectedNode.parent.collapse();
             }
-        } else if (event.keyIdentifier === "Right") {
+        } else if ((!isRTL && event.keyIdentifier === "Right") || (isRTL && event.keyIdentifier === "Left")) {
             if (!this.selectedNode.revealed) {
                 this.selectedNode.reveal();
                 handled = true;
diff --git a/Source/WebInspectorUI/UserInterface/Views/LogContentView.js b/Source/WebInspectorUI/UserInterface/Views/LogContentView.js
index 3dd01db..1c7e5ef 100644
--- a/Source/WebInspectorUI/UserInterface/Views/LogContentView.js
+++ b/Source/WebInspectorUI/UserInterface/Views/LogContentView.js
@@ -737,6 +737,8 @@
 
     _keyDown(event)
     {
+        let isRTL = WebInspector.resolvedLayoutDirection() === WebInspector.LayoutDirection.RTL;
+
         if (this._keyboardShortcutCommandA.matchesEvent(event))
             this._commandAWasPressed(event);
         else if (this._keyboardShortcutEsc.matchesEvent(event))
@@ -745,9 +747,9 @@
             this._upArrowWasPressed(event);
         else if (event.keyIdentifier === "Down")
             this._downArrowWasPressed(event);
-        else if (event.keyIdentifier === "Left")
+        else if ((!isRTL && event.keyIdentifier === "Left") || (isRTL && event.keyIdentifier === "Right"))
             this._leftArrowWasPressed(event);
-        else if (event.keyIdentifier === "Right")
+        else if ((!isRTL && event.keyIdentifier === "Right") || (isRTL && event.keyIdentifier === "Left"))
             this._rightArrowWasPressed(event);
         else if (event.keyIdentifier === "Enter" && event.metaKey)
             this._commandEnterWasPressed(event);
diff --git a/Source/WebInspectorUI/UserInterface/Views/TabBrowser.js b/Source/WebInspectorUI/UserInterface/Views/TabBrowser.js
index 7fe7a2a..ab19d64 100644
--- a/Source/WebInspectorUI/UserInterface/Views/TabBrowser.js
+++ b/Source/WebInspectorUI/UserInterface/Views/TabBrowser.js
@@ -54,15 +54,26 @@
         let showNextTab = () => { this._showNextTab(); };
         let showPreviousTab = () => { this._showPreviousTab(); };
 
-        this._showNextTabKeyboardShortcut1 = new WebInspector.KeyboardShortcut(WebInspector.KeyboardShortcut.Modifier.CommandOrControl | WebInspector.KeyboardShortcut.Modifier.Shift, WebInspector.KeyboardShortcut.Key.RightCurlyBrace, showNextTab);
-        this._showPreviousTabKeyboardShortcut1 = new WebInspector.KeyboardShortcut(WebInspector.KeyboardShortcut.Modifier.CommandOrControl | WebInspector.KeyboardShortcut.Modifier.Shift, WebInspector.KeyboardShortcut.Key.LeftCurlyBrace, showPreviousTab);
-        this._showNextTabKeyboardShortcut2 = new WebInspector.KeyboardShortcut(WebInspector.KeyboardShortcut.Modifier.Control, WebInspector.KeyboardShortcut.Key.Tab, showNextTab);
-        this._showPreviousTabKeyboardShortcut2 = new WebInspector.KeyboardShortcut(WebInspector.KeyboardShortcut.Modifier.Control | WebInspector.KeyboardShortcut.Modifier.Shift, WebInspector.KeyboardShortcut.Key.Tab, showPreviousTab);
+        let isRTL = WebInspector.resolvedLayoutDirection() === WebInspector.LayoutDirection.RTL;
 
-        this._showNextTabKeyboardShortcut3 = new WebInspector.KeyboardShortcut(WebInspector.KeyboardShortcut.Modifier.CommandOrControl | WebInspector.KeyboardShortcut.Modifier.Shift, WebInspector.KeyboardShortcut.Key.Right, this._showNextTabCheckingForEditableField.bind(this));
-        this._showNextTabKeyboardShortcut3.implicitlyPreventsDefault = false;
-        this._showPreviousTabKeyboardShortcut3 = new WebInspector.KeyboardShortcut(WebInspector.KeyboardShortcut.Modifier.CommandOrControl | WebInspector.KeyboardShortcut.Modifier.Shift, WebInspector.KeyboardShortcut.Key.Left, this._showPreviousTabCheckingForEditableField.bind(this));
-        this._showPreviousTabKeyboardShortcut3.implicitlyPreventsDefault = false;
+        let nextKey1 = isRTL ? WebInspector.KeyboardShortcut.Key.LeftCurlyBrace : WebInspector.KeyboardShortcut.Key.RightCurlyBrace;
+        let previousKey1 = isRTL ? WebInspector.KeyboardShortcut.Key.RightCurlyBrace : WebInspector.KeyboardShortcut.Key.LeftCurlyBrace;
+
+        this._showNextTabKeyboardShortcut1 = new WebInspector.KeyboardShortcut(WebInspector.KeyboardShortcut.Modifier.CommandOrControl | WebInspector.KeyboardShortcut.Modifier.Shift, nextKey1, showNextTab);
+        this._showPreviousTabKeyboardShortcut1 = new WebInspector.KeyboardShortcut(WebInspector.KeyboardShortcut.Modifier.CommandOrControl | WebInspector.KeyboardShortcut.Modifier.Shift, previousKey1, showPreviousTab);
+
+        let nextModifier2 = isRTL ? WebInspector.KeyboardShortcut.Modifier.Shift : 0;
+        let previousModifier2 = isRTL ? 0 : WebInspector.KeyboardShortcut.Modifier.Shift;
+
+        this._showNextTabKeyboardShortcut2 = new WebInspector.KeyboardShortcut(WebInspector.KeyboardShortcut.Modifier.Control | nextModifier2, WebInspector.KeyboardShortcut.Key.Tab, showNextTab);
+        this._showPreviousTabKeyboardShortcut2 = new WebInspector.KeyboardShortcut(WebInspector.KeyboardShortcut.Modifier.Control | previousModifier2, WebInspector.KeyboardShortcut.Key.Tab, showPreviousTab);
+
+        let previousTabKey = isRTL ? WebInspector.KeyboardShortcut.Key.Right : WebInspector.KeyboardShortcut.Key.Left;
+        let nextTabKey = isRTL ? WebInspector.KeyboardShortcut.Key.Left : WebInspector.KeyboardShortcut.Key.Right;
+        this._previousTabKeyboardShortcut = new WebInspector.KeyboardShortcut(WebInspector.KeyboardShortcut.Modifier.CommandOrControl | WebInspector.KeyboardShortcut.Modifier.Shift, previousTabKey, this._showPreviousTabCheckingForEditableField.bind(this));
+        this._previousTabKeyboardShortcut.implicitlyPreventsDefault = false;
+        this._nextTabKeyboardShortcut = new WebInspector.KeyboardShortcut(WebInspector.KeyboardShortcut.Modifier.CommandOrControl | WebInspector.KeyboardShortcut.Modifier.Shift, nextTabKey, this._showNextTabCheckingForEditableField.bind(this));
+        this._nextTabKeyboardShortcut.implicitlyPreventsDefault = false;
 
         this._tabBar.addEventListener(WebInspector.TabBar.Event.TabBarItemSelected, this._tabBarItemSelected, this);
         this._tabBar.addEventListener(WebInspector.TabBar.Event.TabBarItemAdded, this._tabBarItemAdded, this);
diff --git a/Source/WebInspectorUI/UserInterface/Views/TreeOutline.js b/Source/WebInspectorUI/UserInterface/Views/TreeOutline.js
index e309d44..d8fc8a1 100644
--- a/Source/WebInspectorUI/UserInterface/Views/TreeOutline.js
+++ b/Source/WebInspectorUI/UserInterface/Views/TreeOutline.js
@@ -482,6 +482,8 @@
         if (!this.selectedTreeElement || event.shiftKey || event.metaKey || event.ctrlKey)
             return;
 
+        let isRTL = WebInspector.resolvedLayoutDirection() === WebInspector.LayoutDirection.RTL;
+
         var handled = false;
         var nextSelectedElement;
         if (event.keyIdentifier === "Up" && !event.altKey) {
@@ -494,7 +496,7 @@
             while (nextSelectedElement && !nextSelectedElement.selectable)
                 nextSelectedElement = nextSelectedElement.traverseNextTreeElement(true);
             handled = nextSelectedElement ? true : false;
-        } else if (event.keyIdentifier === "Left") {
+        } else if ((!isRTL && event.keyIdentifier === "Left") || (isRTL && event.keyIdentifier === "Right")) {
             if (this.selectedTreeElement.expanded) {
                 if (event.altKey)
                     this.selectedTreeElement.collapseRecursively();
@@ -511,7 +513,7 @@
                 } else if (this.selectedTreeElement.parent)
                     this.selectedTreeElement.parent.collapse();
             }
-        } else if (event.keyIdentifier === "Right") {
+        } else if ((!isRTL && event.keyIdentifier === "Right") || (isRTL && event.keyIdentifier === "Left")) {
             if (!this.selectedTreeElement.revealed()) {
                 this.selectedTreeElement.reveal();
                 handled = true;