Merge lp:~osomon/webbrowser-app/autofocus-addressbar-wide into lp:webbrowser-app

Proposed by Olivier Tilloy
Status: Merged
Approved by: Olivier Tilloy
Approved revision: 1329
Merged at revision: 1331
Proposed branch: lp:~osomon/webbrowser-app/autofocus-addressbar-wide
Merge into: lp:webbrowser-app
Diff against target: 413 lines (+84/-59)
6 files modified
src/app/webbrowser/Browser.qml (+42/-12)
tests/autopilot/webbrowser_app/tests/__init__.py (+4/-5)
tests/autopilot/webbrowser_app/tests/test_keyboard.py (+9/-11)
tests/autopilot/webbrowser_app/tests/test_private.py (+2/-3)
tests/autopilot/webbrowser_app/tests/test_sad_tab.py (+6/-6)
tests/autopilot/webbrowser_app/tests/test_tabs.py (+21/-22)
To merge this branch: bzr merge lp:~osomon/webbrowser-app/autofocus-addressbar-wide
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Needs Fixing
Ubuntu Phablet Team Pending
Review via email: mp+283418@code.launchpad.net

Commit message

Automatically focus the address bar when opening a new tab in wide mode (instead of inferring a "desktop" form factor).
This is not exactly the correct fix (which would require the QInputInfo API), but is better than the current situation anyway.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/app/webbrowser/Browser.qml'
2--- src/app/webbrowser/Browser.qml 2016-01-12 14:37:11 +0000
3+++ src/app/webbrowser/Browser.qml 2016-01-21 10:33:49 +0000
4@@ -66,7 +66,7 @@
5 onCurrentIndexChanged: {
6 // Remove focus from the address bar when the current tab
7 // changes to ensure that its contents are updated.
8- tabContainer.forceActiveFocus()
9+ contentsContainer.forceActiveFocus()
10
11 // In narrow mode, the tabslist is a stack:
12 // the current tab is always at the top.
13@@ -170,6 +170,7 @@
14 }
15
16 FocusScope {
17+ id: contentsContainer
18 anchors.fill: parent
19 visible: !settingsViewLoader.active && !historyViewLoader.active && !bookmarksViewLoader.active && !downloadsViewLoader.active
20
21@@ -181,9 +182,15 @@
22 top: parent.top
23 }
24 height: parent.height - osk.height
25+
26+ focus: !errorSheetLoader.focus &&
27+ !invalidCertificateErrorSheetLoader.focus &&
28+ !newTabViewLoader.focus &&
29+ !sadTabLoader.focus
30 }
31
32 Loader {
33+ id: errorSheetLoader
34 anchors {
35 fill: tabContainer
36 topMargin: (chrome.state == "shown") ? chrome.height : 0
37@@ -193,10 +200,12 @@
38 url: currentWebview ? currentWebview.url : ""
39 onRefreshClicked: currentWebview.reload()
40 }
41+ focus: item.visible
42 asynchronous: true
43 }
44
45 Loader {
46+ id: invalidCertificateErrorSheetLoader
47 anchors {
48 fill: tabContainer
49 topMargin: (chrome.state == "shown") ? chrome.height : 0
50@@ -214,6 +223,7 @@
51 currentWebview.resetCertificateError()
52 }
53 }
54+ focus: item.visible
55 asynchronous: true
56 }
57
58@@ -235,6 +245,7 @@
59 }
60 }
61 active: false
62+ focus: active
63 asynchronous: true
64
65 Connections {
66@@ -301,12 +312,14 @@
67 }
68
69 Loader {
70+ id: sadTabLoader
71 anchors {
72 fill: tabContainer
73 topMargin: (chrome.state == "shown") ? chrome.height : 0
74 }
75
76 active: webProcessMonitor.crashed || (webProcessMonitor.killed && !currentWebview.loading)
77+ focus: active
78
79 sourceComponent: SadTab {
80 webview: currentWebview
81@@ -421,6 +434,7 @@
82 state = ""
83 recentToolbar.state = "hidden"
84 tabslist.reset()
85+ internal.resetFocus()
86 }
87 }
88
89@@ -1489,9 +1503,8 @@
90 if (recentView.visible) {
91 recentView.focus = true
92 } else if (tab) {
93- if (!tab.url.toString() && !tab.initialUrl.toString() &&
94- (formFactor == "desktop")) {
95- focusAddressBar()
96+ if (!tab.url.toString() && !tab.initialUrl.toString()) {
97+ maybeFocusAddressBar()
98 } else {
99 tabContainer.forceActiveFocus()
100 }
101@@ -1507,14 +1520,31 @@
102
103 function resetFocus() {
104 if (browser.currentWebview) {
105- if (!browser.currentWebview.url.toString() && (formFactor == "desktop")) {
106- internal.focusAddressBar()
107+ if (!browser.currentWebview.url.toString()) {
108+ internal.maybeFocusAddressBar()
109 } else {
110- tabContainer.forceActiveFocus()
111+ contentsContainer.forceActiveFocus()
112 }
113 }
114 }
115
116+ function maybeFocusAddressBar() {
117+ // XXX: this is not the right condition, but it is better than
118+ // inferring a "desktop" form factor from various heuristics.
119+ // The real fix is to detect whether there is a physical keyboard
120+ // connected, for which there is currently no API yet (there will
121+ // be a QInputInfo API in a future version of Qt).
122+ // Wide mode might be in use on a device without a physical
123+ // keyboard (e.g. a 10" tablet), and conversely the browser window
124+ // might be shrinked to a narrow layout on a desktop setup with a
125+ // physical keyboard and no OSK.
126+ if (browser.wide) {
127+ focusAddressBar()
128+ } else {
129+ contentsContainer.forceActiveFocus()
130+ }
131+ }
132+
133 // Invalid certificates the user has explicitly allowed for this session
134 property var allowedCertificateErrors: []
135
136@@ -1580,8 +1610,8 @@
137 if (load) {
138 tab.load()
139 }
140- if (!url.toString() && (formFactor == "desktop")) {
141- internal.focusAddressBar()
142+ if (!url.toString()) {
143+ internal.maybeFocusAddressBar()
144 }
145 }
146
147@@ -1741,8 +1771,8 @@
148 browser.openUrlInNewTab(settings.homepage, true, false)
149 }
150 tabsModel.currentTab.load()
151- if (!tabsModel.currentTab.url.toString() && !tabsModel.currentTab.restoreState && (formFactor == "desktop")) {
152- internal.focusAddressBar()
153+ if (!tabsModel.currentTab.url.toString() && !tabsModel.currentTab.restoreState) {
154+ internal.maybeFocusAddressBar()
155 }
156
157 BookmarksModel.databasePath = dataLocation + "/bookmarks.sqlite"
158@@ -1784,7 +1814,7 @@
159 if (browser.incognito) {
160 browser.incognito = false
161 internal.resetFocus()
162- } else if ((formFactor == "desktop") || browser.wide) {
163+ } else if (browser.wide) {
164 Qt.quit()
165 }
166 }
167
168=== modified file 'tests/autopilot/webbrowser_app/tests/__init__.py'
169--- tests/autopilot/webbrowser_app/tests/__init__.py 2015-10-26 11:09:25 +0000
170+++ tests/autopilot/webbrowser_app/tests/__init__.py 2016-01-21 10:33:49 +0000
171@@ -1,6 +1,6 @@
172 # -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
173 #
174-# Copyright 2013-2015 Canonical
175+# Copyright 2013-2016 Canonical
176 #
177 # This program is free software: you can redistribute it and/or modify it
178 # under the terms of the GNU General Public License version 3, as published
179@@ -174,10 +174,9 @@
180 self.assert_number_webviews_eventually(new_count)
181 new_tab_view = self.main_window.get_new_tab_view()
182
183- if model() == 'Desktop':
184- self.assertThat(
185- self.main_window.address_bar.activeFocus,
186- Eventually(Equals(True)))
187+ if self.main_window.wide:
188+ self.assertThat(self.main_window.address_bar.activeFocus,
189+ Eventually(Equals(True)))
190
191 if not self.main_window.wide and expand_view:
192 more_button = new_tab_view.get_bookmarks_more_button()
193
194=== modified file 'tests/autopilot/webbrowser_app/tests/test_keyboard.py'
195--- tests/autopilot/webbrowser_app/tests/test_keyboard.py 2015-12-22 18:15:29 +0000
196+++ tests/autopilot/webbrowser_app/tests/test_keyboard.py 2016-01-21 10:33:49 +0000
197@@ -1,6 +1,6 @@
198 # -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
199 #
200-# Copyright 2015 Canonical
201+# Copyright 2015-2016 Canonical
202 #
203 # This program is free software: you can redistribute it and/or modify it
204 # under the terms of the GNU General Public License version 3, as published
205@@ -147,26 +147,28 @@
206 self.check_tab_number(0)
207
208 def test_close_tabs_ctrl_f4(self):
209+ wide = self.main_window.wide
210 self.open_tabs(1)
211 self.check_tab_number(1)
212 self.main_window.press_key('Ctrl+F4')
213 self.check_tab_number(0)
214 self.main_window.press_key('Ctrl+F4')
215- if model() == 'Desktop':
216- # On desktop, closing the last open tab exits the application
217+ if wide:
218+ # closing the last open tab exits the application
219 self.app.process.wait()
220 else:
221 webview = self.main_window.get_current_webview()
222 self.assertThat(webview.url, Equals(""))
223
224 def test_close_tabs_ctrl_w(self):
225+ wide = self.main_window.wide
226 self.open_tabs(1)
227 self.check_tab_number(1)
228 self.main_window.press_key('Ctrl+w')
229 self.check_tab_number(0)
230 self.main_window.press_key('Ctrl+w')
231- if model() == 'Desktop':
232- # On desktop, closing the last open tab exits the application
233+ if wide:
234+ # closing the last open tab exits the application
235 self.app.process.wait()
236 else:
237 webview = self.main_window.get_current_webview()
238@@ -181,12 +183,8 @@
239 self.main_window.press_key('Ctrl+w')
240 self.check_tab_number(0)
241 self.main_window.press_key('Ctrl+F4')
242- if model() == 'Desktop':
243- # On desktop, closing the last open tab exits the application
244- self.app.process.wait()
245- else:
246- webview = self.main_window.get_current_webview()
247- self.assertThat(webview.url, Equals(""))
248+ webview = self.main_window.get_current_webview()
249+ self.assertThat(webview.url, Equals(""))
250
251 def test_select_address_bar_ctrl_l(self):
252 self.main_window.press_key('Ctrl+l')
253
254=== modified file 'tests/autopilot/webbrowser_app/tests/test_private.py'
255--- tests/autopilot/webbrowser_app/tests/test_private.py 2015-11-23 17:12:15 +0000
256+++ tests/autopilot/webbrowser_app/tests/test_private.py 2016-01-21 10:33:49 +0000
257@@ -1,6 +1,6 @@
258 # -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
259 #
260-# Copyright 2015 Canonical
261+# Copyright 2015-2016 Canonical
262 #
263 # This program is free software: you can redistribute it and/or modify it
264 # under the terms of the GNU General Public License version 3, as published
265@@ -16,7 +16,6 @@
266
267 from testtools.matchers import Equals, NotEquals
268 from autopilot.matchers import Eventually
269-from autopilot.platform import model
270
271 from webbrowser_app.tests import StartOpenRemotePageTestCaseBase
272
273@@ -31,7 +30,7 @@
274 self.assert_number_incognito_webviews_eventually(1)
275 self.assertTrue(self.main_window.is_new_private_tab_view_visible())
276 self.assertThat(address_bar.activeFocus,
277- Eventually(Equals(model() == 'Desktop')))
278+ Eventually(Equals(self.main_window.wide)))
279 self.assertThat(address_bar.text, Eventually(Equals("")))
280
281 self.main_window.leave_private_mode()
282
283=== modified file 'tests/autopilot/webbrowser_app/tests/test_sad_tab.py'
284--- tests/autopilot/webbrowser_app/tests/test_sad_tab.py 2015-09-09 12:14:06 +0000
285+++ tests/autopilot/webbrowser_app/tests/test_sad_tab.py 2016-01-21 10:33:49 +0000
286@@ -1,6 +1,6 @@
287 # -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
288 #
289-# Copyright 2015 Canonical
290+# Copyright 2015-2016 Canonical
291 #
292 # This program is free software: you can redistribute it and/or modify it
293 # under the terms of the GNU General Public License version 3, as published
294@@ -17,8 +17,6 @@
295 import signal
296 import time
297
298-from autopilot.platform import model
299-
300 from webbrowser_app.tests import StartOpenRemotePageTestCaseBase
301
302
303@@ -43,10 +41,11 @@
304 self.assert_home_page_eventually_loaded()
305
306 def test_close_tab_web_process_killed(self):
307+ wide = self.main_window.wide
308 sad_tab = self._kill_web_process()
309 sad_tab.click_close_tab_button()
310- if model() == 'Desktop':
311- # On desktop, closing the last open tab exits the application
312+ if wide:
313+ # closing the last open tab exits the application
314 self.app.process.wait()
315 return
316 sad_tab.wait_until_destroyed()
317@@ -64,9 +63,10 @@
318 self.assert_home_page_eventually_loaded()
319
320 def test_close_tab_web_process_crashed(self):
321+ wide = self.main_window.wide
322 sad_tab = self._crash_web_process()
323 sad_tab.click_close_tab_button()
324- if model() == 'Desktop':
325+ if wide:
326 # On desktop, closing the last open tab exits the application
327 self.app.process.wait()
328 return
329
330=== modified file 'tests/autopilot/webbrowser_app/tests/test_tabs.py'
331--- tests/autopilot/webbrowser_app/tests/test_tabs.py 2015-12-03 10:47:22 +0000
332+++ tests/autopilot/webbrowser_app/tests/test_tabs.py 2016-01-21 10:33:49 +0000
333@@ -1,6 +1,6 @@
334 # -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
335 #
336-# Copyright 2013-2015 Canonical
337+# Copyright 2013-2016 Canonical
338 #
339 # This program is free software: you can redistribute it and/or modify it
340 # under the terms of the GNU General Public License version 3, as published
341@@ -59,16 +59,9 @@
342 def test_close_last_open_tab(self):
343 tabs_view = self.main_window.get_tabs_view()
344 tabs_view.get_previews()[0].close()
345- if model() == 'Desktop':
346- # On desktop, closing the last open tab exits the application
347- self.app.process.wait()
348- return
349 tabs_view.visible.wait_for(False)
350 self.assert_number_webviews_eventually(1)
351 self.main_window.get_new_tab_view()
352- if model() == 'Desktop':
353- address_bar = self.main_window.address_bar
354- self.assertThat(address_bar.activeFocus, Eventually(Equals(True)))
355 webview = self.main_window.get_current_webview()
356 self.assertThat(webview.url, Equals(""))
357
358@@ -140,6 +133,9 @@
359 """Test that switching between tabs correctly resets focus to the
360 webview if a page is loaded, and to the address bar if we are in
361 the new page view"""
362+ if not self.main_window.wide:
363+ self.skipTest("only on wide form factors")
364+
365 address_bar = self.main_window.address_bar
366
367 self.main_window.press_key('Ctrl+t')
368@@ -174,18 +170,20 @@
369 self.main_window.press_key('Ctrl+t')
370
371 self.main_window.press_key('Ctrl+w')
372- self.assertThat(address_bar.activeFocus, Eventually(Equals(True)))
373-
374- self.main_window.press_key('Ctrl+w')
375- webview = self.main_window.get_current_webview()
376- self.assertThat(webview.activeFocus, Eventually(Equals(True)))
377-
378- self.main_window.press_key('Ctrl+w')
379- webview = self.main_window.get_current_webview()
380- self.assertThat(webview.activeFocus, Eventually(Equals(True)))
381-
382- self.main_window.press_key('Ctrl+w')
383- self.assertThat(address_bar.activeFocus, Eventually(Equals(True)))
384+ if self.main_window.wide:
385+ self.assertThat(address_bar.activeFocus, Eventually(Equals(True)))
386+
387+ self.main_window.press_key('Ctrl+w')
388+ webview = self.main_window.get_current_webview()
389+ self.assertThat(webview.activeFocus, Eventually(Equals(True)))
390+
391+ self.main_window.press_key('Ctrl+w')
392+ webview = self.main_window.get_current_webview()
393+ self.assertThat(webview.activeFocus, Eventually(Equals(True)))
394+
395+ self.main_window.press_key('Ctrl+w')
396+ if self.main_window.wide:
397+ self.assertThat(address_bar.activeFocus, Eventually(Equals(True)))
398
399
400 class TestTabsManagement(StartOpenRemotePageTestCaseBase, TestTabsMixin):
401@@ -271,9 +269,10 @@
402 toolbar.click_button("doneButton")
403 tabs_view.visible.wait_for(False)
404 webview = self.main_window.get_current_webview()
405+ wide = self.main_window.wide
406 self.pointing_device.click_object(webview)
407- if model() == 'Desktop':
408- # On desktop, closing the last open tab exits the application
409+ if wide:
410+ # closing the last open tab exits the application
411 self.app.process.wait()
412 return
413 webview.wait_until_destroyed()

Subscribers

People subscribed via source and target branches

to status/vote changes: