~uriboni/webbrowser-app/tab-context-menu

« back to all changes in this revision

Viewing changes to src/app/webbrowser/Browser.qml

  • Committer: CI Train Bot
  • Author(s): Arthur Mello, Ugo Riboni, Olivier Tilloy
  • Date: 2015-08-12 19:53:13 UTC
  • mfrom: (1126.1.5 wide-views-newtab-history)
  • Revision ID: ci-train-bot@canonical.com-20150812195313-u5v7kzrj8hfiacsj
Wide screen versions of the history view and new tab view, per design specification.
This adds a build dependency on qml-module-qt-labs-settings (for unit tests). Fixes: #1351157, #1481647

Show diffs side-by-side

added added

removed removed

Lines of Context:
119
119
        property string searchEngine: settingsDefaults.searchEngine
120
120
        property string allowOpenInBackgroundTab: settingsDefaults.allowOpenInBackgroundTab
121
121
        property bool restoreSession: settingsDefaults.restoreSession
 
122
        property int newTabDefaultSection: settingsDefaults.newTabDefaultSection
122
123
 
123
124
        function restoreDefaults() {
124
125
            homepage  = settingsDefaults.homepage
125
126
            searchEngine = settingsDefaults.searchEngine
126
127
            allowOpenInBackgroundTab = settingsDefaults.allowOpenInBackgroundTab
127
128
            restoreSession = settingsDefaults.restoreSession
 
129
            newTabDefaultSection = settingsDefaults.newTabDefaultSection
128
130
        }
129
131
    }
130
132
 
135
137
        readonly property string searchEngine: "google"
136
138
        readonly property string allowOpenInBackgroundTab: "default"
137
139
        readonly property bool restoreSession: true
 
140
        readonly property int newTabDefaultSection: 0
138
141
    }
139
142
 
140
143
    FocusScope {
141
144
        anchors.fill: parent
142
 
        visible: !settingsContainer.visible && !historyViewContainer.visible
 
145
        visible: !settingsContainer.visible && !historyViewLoader.active
143
146
 
144
147
        TabChrome {
145
148
            id: invisibleTabChrome
219
222
                }
220
223
            }
221
224
            active: false
 
225
            asynchronous: true
222
226
 
223
227
            Connections {
224
228
                target: browser
230
234
                }
231
235
            }
232
236
 
233
 
            sourceComponent: browser.incognito ? newPrivateTabViewComponent : newTabViewComponent
 
237
            sourceComponent: browser.incognito ? newPrivateTabView :
 
238
                             (browser.wide ? newTabViewWide : newTabView)
234
239
 
235
240
            Component {
236
 
                id: newTabViewComponent
 
241
                id: newTabView
237
242
 
238
243
                NewTabView {
239
 
                    historyModel: browser.historyModel
240
 
                    bookmarksModel: browser.bookmarksModel
241
 
                    settingsObject: settings
242
 
                    onBookmarkClicked: {
243
 
                        chrome.requestedUrl = url
244
 
                        currentWebview.url = url
245
 
                        tabContainer.forceActiveFocus()
246
 
                    }
247
 
                    onBookmarkRemoved: browser.bookmarksModel.remove(url)
248
 
                    onHistoryEntryClicked: {
249
 
                        chrome.requestedUrl = url
250
 
                        currentWebview.url = url
251
 
                        tabContainer.forceActiveFocus()
252
 
                    }
253
 
                }
254
 
            }
255
 
 
256
 
            Component {
257
 
                id: newPrivateTabViewComponent
258
 
 
259
 
                NewPrivateTabView { }
260
 
            }
261
 
            asynchronous: true
 
244
                    anchors.fill: parent
 
245
                    historyModel: browser.historyModel
 
246
                    bookmarksModel: browser.bookmarksModel
 
247
                    settingsObject: settings
 
248
                    focus: true
 
249
                    onBookmarkClicked: {
 
250
                        chrome.requestedUrl = url
 
251
                        currentWebview.url = url
 
252
                        tabContainer.forceActiveFocus()
 
253
                    }
 
254
                    onBookmarkRemoved: browser.bookmarksModel.remove(url)
 
255
                    onHistoryEntryClicked: {
 
256
                        chrome.requestedUrl = url
 
257
                        currentWebview.url = url
 
258
                        tabContainer.forceActiveFocus()
 
259
                    }
 
260
                }
 
261
            }
 
262
 
 
263
            Component {
 
264
                id: newTabViewWide
 
265
 
 
266
                NewTabViewWide {
 
267
                    anchors.fill: parent
 
268
                    historyModel: browser.historyModel
 
269
                    bookmarksModel: browser.bookmarksModel
 
270
                    settingsObject: settings
 
271
                    focus: true
 
272
                    onBookmarkClicked: {
 
273
                        chrome.requestedUrl = url
 
274
                        currentWebview.url = url
 
275
                        tabContainer.forceActiveFocus()
 
276
                    }
 
277
                    onBookmarkRemoved: browser.bookmarksModel.remove(url)
 
278
                    onHistoryEntryClicked: {
 
279
                        chrome.requestedUrl = url
 
280
                        currentWebview.url = url
 
281
                        tabContainer.forceActiveFocus()
 
282
                    }
 
283
                    onReleasingKeyboardFocus: chrome.focus = true
 
284
                }
 
285
            }
 
286
 
 
287
            Component {
 
288
                id: newPrivateTabView
 
289
 
 
290
                NewPrivateTabView { anchors.fill: parent }
 
291
            }
262
292
        }
263
293
 
264
294
        SearchEngine {
327
357
                    text: i18n.tr("History")
328
358
                    iconName: "history"
329
359
                    enabled: browser.historyModel
330
 
                    onTriggered: {
331
 
                        historyViewComponent.createObject(historyViewContainer)
332
 
                        historyViewContainer.focus = true
333
 
                    }
 
360
                    onTriggered: historyViewLoader.active = true
334
361
                },
335
362
                Action {
336
363
                    objectName: "tabs"
391
418
            canSimplifyText: !browser.wide
392
419
            editing: activeFocus || suggestionsList.activeFocus
393
420
 
394
 
            Keys.onDownPressed: if (suggestionsList.count) suggestionsList.focus = true
 
421
            Keys.onDownPressed: {
 
422
                if (suggestionsList.count) suggestionsList.focus = true
 
423
                else if (newTabViewLoader.status == Loader.Ready) {
 
424
                    newTabViewLoader.focus = true
 
425
                }
 
426
            }
 
427
 
395
428
            Keys.onEscapePressed: {
396
429
                if (chrome.findInPageMode) {
397
430
                    chrome.findInPageMode = false
715
748
        }
716
749
    }
717
750
 
718
 
    FocusScope {
719
 
        id: historyViewContainer
720
 
        objectName: "historyView"
 
751
    Loader {
 
752
        id: historyViewLoader
721
753
 
722
 
        visible: children.length > 0
723
754
        anchors.fill: parent
 
755
        active: false
 
756
        sourceComponent: browser.wide ? historyViewWideComponent : historyViewComponent
 
757
 
 
758
        onStatusChanged: {
 
759
            if (status == Loader.Ready) {
 
760
                historyViewLoader.item.forceActiveFocus()
 
761
            } else {
 
762
                internal.resetFocus()
 
763
            }
 
764
        }
 
765
 
 
766
        Keys.onEscapePressed: historyViewLoader.active = false
 
767
 
 
768
        Timer {
 
769
            // Set the model asynchronously to ensure
 
770
            // the view is displayed as early as possible.
 
771
            running: historyViewLoader.active
 
772
            interval: 1
 
773
            onTriggered: historyViewLoader.item.historyModel = browser.historyModel
 
774
        }
724
775
 
725
776
        Component {
726
777
            id: historyViewComponent
727
778
 
728
779
            HistoryView {
729
780
                anchors.fill: parent
730
 
                visible: historyViewContainer.children.length == 1
731
 
                focus: true
 
781
 
 
782
                onSeeMoreEntriesClicked: {
 
783
                    var view = expandedHistoryViewComponent.createObject(expandedHistoryViewContainer, {model: model})
 
784
                    view.onHistoryEntryClicked.connect(done)
 
785
                }
 
786
                onDone: historyViewLoader.active = false
 
787
 
 
788
                FocusScope {
 
789
                    id: expandedHistoryViewContainer
 
790
    
 
791
                    visible: children.length > 0
 
792
                    anchors.fill: parent
 
793
 
 
794
                    Component {
 
795
                        id: expandedHistoryViewComponent
 
796
 
 
797
                        ExpandedHistoryView {
 
798
                            anchors.fill: parent
 
799
 
 
800
                            onHistoryEntryClicked: {
 
801
                                browser.openUrlInNewTab(url, true)
 
802
                                done()
 
803
                            }
 
804
                            onHistoryEntryRemoved: {
 
805
                                if (count == 1) {
 
806
                                    done()
 
807
                                }
 
808
                                browser.historyModel.removeEntryByUrl(url)
 
809
                            }
 
810
                            onDone: destroy()
 
811
                        }
 
812
                    }
 
813
                }
 
814
            }
 
815
        }
 
816
 
 
817
        Component {
 
818
            id: historyViewWideComponent
 
819
 
 
820
            HistoryViewWide {
 
821
                anchors.fill: parent
732
822
 
733
823
                Keys.onEscapePressed: {
734
 
                    destroy()
 
824
                    historyViewLoader.active = false
735
825
                    internal.resetFocus()
736
826
                }
737
827
 
743
833
                    onTriggered: historyModel = browser.historyModel
744
834
                }
745
835
 
746
 
                onSeeMoreEntriesClicked: {
747
 
                    var view = expandedHistoryViewComponent.createObject(historyViewContainer, {model: model})
748
 
                    view.onHistoryEntryClicked.connect(destroy)
749
 
                }
750
 
                onDone: destroy()
751
 
            }
752
 
        }
753
 
 
754
 
        Component {
755
 
            id: expandedHistoryViewComponent
756
 
 
757
 
            ExpandedHistoryView {
758
 
                anchors.fill: parent
759
 
 
760
836
                onHistoryEntryClicked: {
761
837
                    browser.openUrlInNewTab(url, true)
762
838
                    done()
763
839
                }
764
 
                onHistoryEntryRemoved: {
765
 
                    if (count == 1) {
766
 
                        done()
767
 
                    }
768
 
                    browser.historyModel.removeEntryByUrl(url)
769
 
                }
770
 
                onDone: destroy()
 
840
                onHistoryEntryRemoved: browser.historyModel.removeEntryByUrl(url)
 
841
                onNewTabRequested: browser.openUrlInNewTab("", true)
 
842
                onDone: historyViewLoader.active = false
771
843
            }
772
844
        }
773
845
    }
1134
1206
            PopupUtils.open(bookmarkOptionsComponent,
1135
1207
                            chrome.bookmarkTogglePlaceHolder,
1136
1208
                            {"bookmarkUrl": url,
1137
 
                             "bookmarkTitle": title}) 
 
1209
                             "bookmarkTitle": title})
1138
1210
        }
1139
1211
    }
1140
1212
 
1449
1521
            modifiers: Qt.ControlModifier
1450
1522
            key: Qt.Key_H
1451
1523
            enabled: chrome.visible
1452
 
            onTriggered: {
1453
 
                if (historyViewContainer.children.length === 0) {
1454
 
                    historyViewComponent.createObject(historyViewContainer)
1455
 
                    historyViewContainer.focus = true
1456
 
                }
1457
 
            }
 
1524
            onTriggered: historyViewLoader.active = true
1458
1525
        }
1459
1526
 
1460
1527
        // Alt+← or Backspace: Goes to the previous page in history