Merge lp:~stolowski/unity-2d/hud-focus-fix into lp:unity-2d

Proposed by Paweł Stołowski
Status: Merged
Approved by: Albert Astals Cid
Approved revision: 1043
Merged at revision: 1040
Proposed branch: lp:~stolowski/unity-2d/hud-focus-fix
Merge into: lp:unity-2d
Diff against target: 112 lines (+18/-16)
3 files modified
shell/hud/Hud.qml (+10/-4)
shell/hud/ResultItem.qml (+4/-4)
tests/hud/hud-search-tests.rb (+4/-8)
To merge this branch: bzr merge lp:~stolowski/unity-2d/hud-focus-fix
Reviewer Review Type Date Requested Status
Albert Astals Cid (community) Approve
Review via email: mp+100745@code.launchpad.net

Commit message

[hud] Prevent search entry from stealing focus on mouse click, rendering up/down keys unusable.

Up/Down keys update currentIndex of resultsList. Changed color & width property code in ResultItem to report color/width based on whether it's current item, rather than relying on "selected" state of AbstractButton.

Description of the change

[hud] Prevent search entry from stealing focus on mouse click, rendering up/down keys unusable.
   Up/Down keys update currentIndex of resultsList. Changed color & width property code in ResultItem
   to report color/width based on whether it's current item, rather than relying on "selected" state
   of AbstractButton.

To post a comment you must log in.
Revision history for this message
Albert Astals Cid (aacid) wrote :

Wondering if
verify_equal('false', TIMEOUT, "Result item ##{index+1} should not have focus") {
we can have something that tests the item is the current one (using that current property)?

Also you don't need focus: false since it's the default value, so you can just remove it I think (unless you want to explicitely have it there)

review: Needs Fixing
lp:~stolowski/unity-2d/hud-focus-fix updated
1042. By Paweł Stołowski

Check for 'pressed' state first to highlight current item correctly on click.

1043. By Paweł Stołowski

Test 'current' property of ResultItem in tests.

Revision history for this message
Albert Astals Cid (aacid) wrote :

Looks great

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'shell/hud/Hud.qml'
2--- shell/hud/Hud.qml 2012-04-04 07:46:44 +0000
3+++ shell/hud/Hud.qml 2012-04-04 08:50:24 +0000
4@@ -58,7 +58,6 @@
5 if (active) {
6 shellManager.hudShell.forceActivateWindow()
7 appIcon = getActiveWindowIcon()
8- resultList.focus = true
9 } else {
10 hudModel.endSearch()
11 resultList.currentIndex = -1
12@@ -78,6 +77,12 @@
13
14 Keys.onPressed: {
15 if (event.key == Qt.Key_Escape) toggleHud()
16+ else if (event.key == Qt.Key_Down) {
17+ resultList.incrementCurrentIndex()
18+ }
19+ else if (event.key == Qt.Key_Up) {
20+ resultList.decrementCurrentIndex()
21+ }
22 }
23
24 function toggleHud() {
25@@ -193,6 +198,7 @@
26
27 SearchEntry {
28 id: searchEntry
29+ focus: true
30
31 anchors.top: parent.top
32 anchors.left: parent.left
33@@ -215,7 +221,7 @@
34 ListView {
35 id: resultList
36
37- focus: true
38+ focus: false
39
40 Accessible.name: "result list"
41
42@@ -234,12 +240,12 @@
43
44 icon: iconName /* expose this property for tile */
45
46+ current: ListView.isCurrentItem
47+
48 onClicked: executeResult(resultId)
49 onMouseOverChanged: {
50 if (mouseOver) {
51 resultList.currentIndex = model.index;
52- // workaround for loosing highlight for mouse if search entry steals focus - see https://bugs.launchpad.net/unity-2d/+bug/966180
53- forceActiveFocus();
54 }
55 }
56 }
57
58=== modified file 'shell/hud/ResultItem.qml'
59--- shell/hud/ResultItem.qml 2012-04-03 16:30:19 +0000
60+++ shell/hud/ResultItem.qml 2012-04-04 08:50:24 +0000
61@@ -21,6 +21,7 @@
62
63 AbstractButton {
64 id: delegate
65+ property bool current: false
66 property string icon: ""
67
68 Accessible.name: plainText
69@@ -47,11 +48,10 @@
70 anchors.bottom: parent.bottom
71
72 border.color: "white"
73- border.width: (parent.state == "selected"
74- || parent.state == "pressed") ? 2 : 0
75+ border.width: (current || parent.state == "pressed") ? 2 : 0
76 color: {
77- if (parent.state == "selected") return "#21ffffff"
78- else if ( parent.state == "pressed" ) return "white"
79+ if ( parent.state == "pressed" ) return "white"
80+ else if (current) return "#21ffffff"
81 else return "transparent"
82 }
83 radius: 7
84
85=== modified file 'tests/hud/hud-search-tests.rb'
86--- tests/hud/hud-search-tests.rb 2012-04-03 16:11:22 +0000
87+++ tests/hud/hud-search-tests.rb 2012-04-04 08:50:24 +0000
88@@ -43,8 +43,8 @@
89 #
90 # Verify that given ResultItem is highlighted and active.
91 def item_is_highlighted(results, index)
92- verify_equal('true', TIMEOUT, "Result item ##{index+1} should have focus") {
93- results[index]['activeFocus']
94+ verify_equal('true', TIMEOUT, "Result item ##{index+1} should be 'current'") {
95+ results[index]['current']
96 }
97
98 verify_equal(HUD_HIGHLIGHT_COLOR, TIMEOUT, "Result item ##{index+1} should be highlighted") {
99@@ -59,12 +59,8 @@
100 results.count {|x| x.QDeclarativeRectangle(:name=>'container')['color'] == HUD_HIGHLIGHT_COLOR}
101 }
102
103- verify_equal(1, 0, 'Exactly one item has focus') {
104- results.count {|x| x['activeFocus'] == 'true'}
105- }
106-
107- verify_equal(1, 0, "Exactly one item has 'selected' state ") {
108- results.count {|x| x['state'] == 'selected'}
109+ verify_equal(1, 0, "Exactly one item is 'current'") {
110+ results.count {|x| x['current'] == 'true'}
111 }
112 end
113

Subscribers

People subscribed via source and target branches