From 654f455bd7e8ecf1bff05911d70e106a054ee785 Mon Sep 17 00:00:00 2001
From: Pierre Rossi <pierre.rossi@digia.com>
Date: Wed, 20 Aug 2014 19:41:23 +0200
Subject: [PATCH] Tweak the back and forward buttons

To have a more "discoverable" UX, and cleaner UI (requiring private
QML API for now).

Change-Id: Ic275287d429149a1c353a1cbdc5b7f9b19e57410
Reviewed-by: Gabriel de Dietrich <gabriel.dedietrich@digia.com>
Reviewed-by: Jocelyn Turcotte <jocelyn.turcotte@digia.com>
---
 tests/quicktestbrowser/ButtonWithMenu.qml   | 70 +++++++++++++++++++++
 tests/quicktestbrowser/quicktestbrowser.pro |  3 +-
 tests/quicktestbrowser/quickwindow.qml      | 22 ++-----
 tests/quicktestbrowser/resources.qrc        |  1 +
 4 files changed, 79 insertions(+), 17 deletions(-)
 create mode 100644 tests/quicktestbrowser/ButtonWithMenu.qml

diff --git a/tests/quicktestbrowser/ButtonWithMenu.qml b/tests/quicktestbrowser/ButtonWithMenu.qml
new file mode 100644
index 000000000..8058b958a
--- /dev/null
+++ b/tests/quicktestbrowser/ButtonWithMenu.qml
@@ -0,0 +1,70 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtWebEngine module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+**   * Redistributions of source code must retain the above copyright
+**     notice, this list of conditions and the following disclaimer.
+**   * Redistributions in binary form must reproduce the above copyright
+**     notice, this list of conditions and the following disclaimer in
+**     the documentation and/or other materials provided with the
+**     distribution.
+**   * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
+**     of its contributors may be used to endorse or promote products derived
+**     from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.3
+import QtQuick.Controls 1.2
+
+// The QtQuick controls guys are slackers, so we need to make our own stuff
+
+ToolButton {
+    id: root
+    property Menu longPressMenu
+    function showMenu() {
+        longPressMenu.__popup(0, root.height, 0)
+    }
+
+    Binding {
+        target: longPressMenu
+        property: "__visualItem"
+        value: root
+    }
+
+    MouseArea {
+        anchors.fill: parent
+        acceptedButtons: Qt.LeftButton | Qt.RightButton
+        onClicked: {
+            if (mouse.button == Qt.RightButton)
+                showMenu()
+            else
+                root.clicked()
+        }
+        onPressAndHold: showMenu()
+    }
+}
diff --git a/tests/quicktestbrowser/quicktestbrowser.pro b/tests/quicktestbrowser/quicktestbrowser.pro
index a6ee521d4..ac8fe74b3 100644
--- a/tests/quicktestbrowser/quicktestbrowser.pro
+++ b/tests/quicktestbrowser/quicktestbrowser.pro
@@ -8,7 +8,8 @@ HEADERS = quickwindow.h \
 SOURCES = quickwindow.cpp \
           main.cpp
 
-OTHER_FILES += ContextMenuExtras.qml \
+OTHER_FILES += ButtonWithMenu.qml \
+               ContextMenuExtras.qml \
                FeaturePermissionBar.qml \
                quickwindow.qml
 
diff --git a/tests/quicktestbrowser/quickwindow.qml b/tests/quicktestbrowser/quickwindow.qml
index 0fb50dd23..ca1f75c04 100644
--- a/tests/quicktestbrowser/quickwindow.qml
+++ b/tests/quicktestbrowser/quickwindow.qml
@@ -148,31 +148,21 @@ ApplicationWindow {
         id: navigationBar
             RowLayout {
                 anchors.fill: parent;
-                ToolButton {
+                ButtonWithMenu {
                     id: backButton
                     iconSource: "icons/go-previous.png"
-                    onClicked: currentWebView.goBack()
                     enabled: currentWebView && currentWebView.canGoBack
                     activeFocusOnTab: !browserWindow.platformIsMac
-
-                    MouseArea {
-                        anchors.fill: parent
-                        acceptedButtons: Qt.RightButton
-                        onClicked: backHistoryMenu.popup()
-                    }
+                    onClicked: currentWebView.goBack()
+                    longPressMenu: backHistoryMenu
                 }
-                ToolButton {
+                ButtonWithMenu {
                     id: forwardButton
                     iconSource: "icons/go-next.png"
-                    onClicked: currentWebView.goForward()
                     enabled: currentWebView && currentWebView.canGoForward
                     activeFocusOnTab: !browserWindow.platformIsMac
-
-                    MouseArea {
-                        anchors.fill: parent
-                        acceptedButtons: Qt.RightButton
-                        onClicked: forwardHistoryMenu.popup()
-                    }
+                    onClicked: currentWebView.goForward()
+                    longPressMenu: forwardHistoryMenu
                 }
                 ToolButton {
                     id: reloadButton
diff --git a/tests/quicktestbrowser/resources.qrc b/tests/quicktestbrowser/resources.qrc
index 1226be00b..cdc3d2304 100644
--- a/tests/quicktestbrowser/resources.qrc
+++ b/tests/quicktestbrowser/resources.qrc
@@ -3,6 +3,7 @@
         <file>quickwindow.qml</file>
         <file>ContextMenuExtras.qml</file>
         <file>FeaturePermissionBar.qml</file>
+        <file>ButtonWithMenu.qml</file>
     </qresource>
     <qresource prefix="icons">
         <!-- To the risk of this breaking more often, do not duplicate the resources since this application won't be deployed -->
-- 
GitLab