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
=== modified file 'shell/hud/Hud.qml'
--- shell/hud/Hud.qml 2012-04-04 07:46:44 +0000
+++ shell/hud/Hud.qml 2012-04-04 08:50:24 +0000
@@ -58,7 +58,6 @@
58 if (active) {58 if (active) {
59 shellManager.hudShell.forceActivateWindow()59 shellManager.hudShell.forceActivateWindow()
60 appIcon = getActiveWindowIcon()60 appIcon = getActiveWindowIcon()
61 resultList.focus = true
62 } else {61 } else {
63 hudModel.endSearch()62 hudModel.endSearch()
64 resultList.currentIndex = -163 resultList.currentIndex = -1
@@ -78,6 +77,12 @@
7877
79 Keys.onPressed: {78 Keys.onPressed: {
80 if (event.key == Qt.Key_Escape) toggleHud()79 if (event.key == Qt.Key_Escape) toggleHud()
80 else if (event.key == Qt.Key_Down) {
81 resultList.incrementCurrentIndex()
82 }
83 else if (event.key == Qt.Key_Up) {
84 resultList.decrementCurrentIndex()
85 }
81 }86 }
8287
83 function toggleHud() {88 function toggleHud() {
@@ -193,6 +198,7 @@
193198
194 SearchEntry {199 SearchEntry {
195 id: searchEntry200 id: searchEntry
201 focus: true
196202
197 anchors.top: parent.top203 anchors.top: parent.top
198 anchors.left: parent.left204 anchors.left: parent.left
@@ -215,7 +221,7 @@
215 ListView {221 ListView {
216 id: resultList222 id: resultList
217223
218 focus: true224 focus: false
219225
220 Accessible.name: "result list"226 Accessible.name: "result list"
221227
@@ -234,12 +240,12 @@
234240
235 icon: iconName /* expose this property for tile */241 icon: iconName /* expose this property for tile */
236242
243 current: ListView.isCurrentItem
244
237 onClicked: executeResult(resultId)245 onClicked: executeResult(resultId)
238 onMouseOverChanged: {246 onMouseOverChanged: {
239 if (mouseOver) {247 if (mouseOver) {
240 resultList.currentIndex = model.index;248 resultList.currentIndex = model.index;
241 // workaround for loosing highlight for mouse if search entry steals focus - see https://bugs.launchpad.net/unity-2d/+bug/966180
242 forceActiveFocus();
243 }249 }
244 }250 }
245 }251 }
246252
=== modified file 'shell/hud/ResultItem.qml'
--- shell/hud/ResultItem.qml 2012-04-03 16:30:19 +0000
+++ shell/hud/ResultItem.qml 2012-04-04 08:50:24 +0000
@@ -21,6 +21,7 @@
2121
22AbstractButton {22AbstractButton {
23 id: delegate23 id: delegate
24 property bool current: false
24 property string icon: ""25 property string icon: ""
2526
26 Accessible.name: plainText27 Accessible.name: plainText
@@ -47,11 +48,10 @@
47 anchors.bottom: parent.bottom48 anchors.bottom: parent.bottom
4849
49 border.color: "white"50 border.color: "white"
50 border.width: (parent.state == "selected"51 border.width: (current || parent.state == "pressed") ? 2 : 0
51 || parent.state == "pressed") ? 2 : 0
52 color: {52 color: {
53 if (parent.state == "selected") return "#21ffffff"53 if ( parent.state == "pressed" ) return "white"
54 else if ( parent.state == "pressed" ) return "white"54 else if (current) return "#21ffffff"
55 else return "transparent"55 else return "transparent"
56 }56 }
57 radius: 757 radius: 7
5858
=== modified file 'tests/hud/hud-search-tests.rb'
--- tests/hud/hud-search-tests.rb 2012-04-03 16:11:22 +0000
+++ tests/hud/hud-search-tests.rb 2012-04-04 08:50:24 +0000
@@ -43,8 +43,8 @@
43#43#
44# Verify that given ResultItem is highlighted and active.44# Verify that given ResultItem is highlighted and active.
45def item_is_highlighted(results, index)45def item_is_highlighted(results, index)
46 verify_equal('true', TIMEOUT, "Result item ##{index+1} should have focus") {46 verify_equal('true', TIMEOUT, "Result item ##{index+1} should be 'current'") {
47 results[index]['activeFocus']47 results[index]['current']
48 }48 }
4949
50 verify_equal(HUD_HIGHLIGHT_COLOR, TIMEOUT, "Result item ##{index+1} should be highlighted") {50 verify_equal(HUD_HIGHLIGHT_COLOR, TIMEOUT, "Result item ##{index+1} should be highlighted") {
@@ -59,12 +59,8 @@
59 results.count {|x| x.QDeclarativeRectangle(:name=>'container')['color'] == HUD_HIGHLIGHT_COLOR}59 results.count {|x| x.QDeclarativeRectangle(:name=>'container')['color'] == HUD_HIGHLIGHT_COLOR}
60 }60 }
6161
62 verify_equal(1, 0, 'Exactly one item has focus') {62 verify_equal(1, 0, "Exactly one item is 'current'") {
63 results.count {|x| x['activeFocus'] == 'true'}63 results.count {|x| x['current'] == 'true'}
64 }
65
66 verify_equal(1, 0, "Exactly one item has 'selected' state ") {
67 results.count {|x| x['state'] == 'selected'}
68 }64 }
69end65end
7066

Subscribers

People subscribed via source and target branches