Merge lp:~zsombi/ubuntu-ui-toolkit/focusing-improvements into lp:ubuntu-ui-toolkit/staging

Proposed by Zsombor Egri
Status: Merged
Approved by: Zsombor Egri
Approved revision: 1229
Merged at revision: 1228
Proposed branch: lp:~zsombi/ubuntu-ui-toolkit/focusing-improvements
Merge into: lp:ubuntu-ui-toolkit/staging
Diff against target: 254 lines (+36/-111)
6 files modified
modules/Ubuntu/Components/AbstractButton.qml (+0/-1)
modules/Ubuntu/Components/Pickers/Picker.qml (+0/-1)
modules/Ubuntu/Components/plugin/ucstyleditembase.cpp (+22/-54)
modules/Ubuntu/Components/plugin/ucstyleditembase.h (+1/-0)
tests/unit_x11/tst_components/tst_focus.qml (+12/-0)
tests/unit_x11/tst_components/tst_styleditem.qml (+1/-55)
To merge this branch: bzr merge lp:~zsombi/ubuntu-ui-toolkit/focusing-improvements
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Approve
Cris Dywan Approve
Review via email: mp+232972@code.launchpad.net

Commit message

Focus should not be taken by a component if disabled. Complete child filtering properly.

To post a comment you must log in.
Revision history for this message
Zsombor Egri (zsombi) wrote :

The child filtering wasn't completed in teh original MR :/ the setFiltersChildMouseEvents() call was there without having the childMouseEventsFilter() being implemented. This caused us to have all sorts of workarounds for which QtQuick provides a solution. Mea culpa.

Revision history for this message
Cris Dywan (kalikiana) wrote :

This makes quite a bit of sense. I wonder how neither of us noticed before… looks sensible.

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
1228. By Zsombor Egri

remove unused d-pointer causing build warning

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
1229. By Zsombor Egri

documentation fix

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'modules/Ubuntu/Components/AbstractButton.qml'
2--- modules/Ubuntu/Components/AbstractButton.qml 2014-08-21 05:24:14 +0000
3+++ modules/Ubuntu/Components/AbstractButton.qml 2014-09-02 12:49:18 +0000
4@@ -103,7 +103,6 @@
5 hoverEnabled: true
6
7 onClicked: {
8- button.requestFocus();
9 if (button.__acceptEvents) {
10 pressEffect.start()
11 button.clicked()
12
13=== modified file 'modules/Ubuntu/Components/Pickers/Picker.qml'
14--- modules/Ubuntu/Components/Pickers/Picker.qml 2014-08-21 05:24:14 +0000
15+++ modules/Ubuntu/Components/Pickers/Picker.qml 2014-09-02 12:49:18 +0000
16@@ -294,7 +294,6 @@
17 width: parent ? parent.width : 0
18 clip: true
19 focus: true
20- Mouse.onClicked: picker.requestFocus()
21
22 model: picker.model
23 delegate: picker.delegate
24
25=== modified file 'modules/Ubuntu/Components/plugin/ucstyleditembase.cpp'
26--- modules/Ubuntu/Components/plugin/ucstyleditembase.cpp 2014-08-22 16:09:46 +0000
27+++ modules/Ubuntu/Components/plugin/ucstyleditembase.cpp 2014-09-02 12:49:18 +0000
28@@ -86,7 +86,7 @@
29 }
30
31 /*!
32- * \qmlmethod void StyledItemBase::requestFocus()
33+ * \qmlmethod void StyledItemBase::requestFocus(Qt::FocusReason reason)
34 * \since Ubuntu.Components 1.1
35 * The function is similar to \c forceActiveFocus except that it sets focus only
36 * if all the ancestors have activeFocusOnPressed set. Returns true if the request
37@@ -96,7 +96,7 @@
38 {
39 Q_D(UCStyledItemBase);
40 bool focusable = d->isParentFocusable();
41- if (focusable) {
42+ if (focusable && isEnabled()) {
43 QQuickItem::forceActiveFocus(reason);
44 }
45 return focusable;
46@@ -151,57 +151,6 @@
47 * }
48 * \endqml
49 *
50- * StyledItem cannot gain focus automaically if there is a MouseArea or other
51- * component grabbing mouse events placed over it. In that case the focus must
52- * be grabbed by the overlapping area explicitly either by calling the \l requestFocus
53- * function or by forwarding mouse events to the covered StyledItem area.
54- * \qml
55- * import QtQuick 2.2
56- * import Ubuntu.Components 1.1
57- *
58- * Column {
59- * width: units.gu(50)
60- * height: units.gu(100)
61- *
62- * StyledItem {
63- * id: scope1
64- * width: parent.width
65- * height: units.gu(30)
66- * activeFocusOnPress: false
67- * Rectangle {
68- * focus: true
69- * anchors {
70- * fill: parent
71- * margins: units.gu(1)
72- * }
73- * color: !activeFocus ? "red" : "green"
74- * MouseArea {
75- * anchors.fill: parent
76- * onClicked: scope1.requestFocus()
77- * }
78- * }
79- * }
80- * StyledItem {
81- * id: scope2
82- * width: parent.width
83- * height: units.gu(30)
84- * activeFocusOnPress: false
85- * Rectangle {
86- * focus: true
87- * anchors {
88- * fill: parent
89- * margins: units.gu(1)
90- * }
91- * color: !activeFocus ? "red" : "green"
92- * MouseArea {
93- * anchors.fill: parent
94- * Mouse.forwardTo: [scope2]
95- * }
96- * }
97- * }
98- * }
99- * \endqml
100- *
101 * The default value is \c false.
102 */
103 bool UCStyledItemBase::activefocusOnPress() const
104@@ -223,8 +172,27 @@
105 void UCStyledItemBase::mousePressEvent(QMouseEvent *event)
106 {
107 QQuickItem::mousePressEvent(event);
108- Q_D(UCStyledItemBase);
109 requestFocus(Qt::MouseFocusReason);
110 }
111
112+// filter children events as well, so we can catch mouse presses done over child
113+// MouseAreas or other mouse grabbers
114+bool UCStyledItemBase::childMouseEventFilter(QQuickItem *child, QEvent *event)
115+{
116+ // only filter pressed events
117+ if (event->type() == QEvent::MouseButtonPress) {
118+ QMouseEvent *mouse = static_cast<QMouseEvent*>(event);
119+ // the event may occur outside of the parent's boundaries if not clipped
120+ // therefore must check containment
121+ QPointF point = mapFromItem(child, mouse->localPos());
122+ if (contains(point)) {
123+ QMouseEvent press(event->type(), point, mouse->windowPos(), mouse->screenPos(),
124+ mouse->button(), mouse->buttons(), mouse->modifiers());
125+ mousePressEvent(&press);
126+ }
127+ }
128+ // let the event be passed to children
129+ return false;
130+}
131+
132 #include "moc_ucstyleditembase.cpp"
133
134=== modified file 'modules/Ubuntu/Components/plugin/ucstyleditembase.h'
135--- modules/Ubuntu/Components/plugin/ucstyleditembase.h 2014-08-20 12:56:51 +0000
136+++ modules/Ubuntu/Components/plugin/ucstyleditembase.h 2014-09-02 12:49:18 +0000
137@@ -44,6 +44,7 @@
138 UCStyledItemBase(UCStyledItemBasePrivate &, QQuickItem *parent);
139
140 void mousePressEvent(QMouseEvent *event);
141+ bool childMouseEventFilter(QQuickItem *child, QEvent *event);
142
143 private:
144 Q_DECLARE_PRIVATE(UCStyledItemBase)
145
146=== modified file 'tests/unit_x11/tst_components/tst_focus.qml'
147--- tests/unit_x11/tst_components/tst_focus.qml 2014-08-18 16:02:33 +0000
148+++ tests/unit_x11/tst_components/tst_focus.qml 2014-09-02 12:49:18 +0000
149@@ -82,6 +82,12 @@
150 Slider {
151 id: slider
152 }
153+ StyledItem {
154+ id: disabledButton
155+ enabled: false
156+ width: units.gu(20)
157+ height: units.gu(6)
158+ }
159 ComboButton {
160 id: comboButton
161 Rectangle {
162@@ -211,6 +217,7 @@
163 compare(dropdownButton.focus, true, "Dropdown button hasn't got focused!");
164 compare(comboButton.focus, true, "ComboButton hasn't been focused!");
165 comboButton.expanded = false;
166+ waitForRendering(comboButton);
167 }
168
169 function test_popover_refocus_data() {
170@@ -236,5 +243,10 @@
171 popupCloseSpy.wait();
172 verify(popoverTest.focus, "Button focus not restored.");
173 }
174+
175+ function test_disabled_component_does_not_focus() {
176+ mousePress(disabledButton, centerOf(disabledButton).x, centerOf(disabledButton).y);
177+ compare(disabledButton.focus, false, "Disabled component shoudl not focus");
178+ }
179 }
180 }
181
182=== modified file 'tests/unit_x11/tst_components/tst_styleditem.qml'
183--- tests/unit_x11/tst_components/tst_styleditem.qml 2014-08-20 12:40:19 +0000
184+++ tests/unit_x11/tst_components/tst_styleditem.qml 2014-09-02 12:49:18 +0000
185@@ -90,58 +90,6 @@
186 }
187 }
188 }
189- StyledItem {
190- id: activeScope2
191- objectName: "activeScope"
192- width: units.gu(50)
193- height: units.gu(20)
194- activeFocusOnPress: true
195-
196- Rectangle {
197- width: height
198- height: units.gu(10)
199- color: "green"
200- anchors.centerIn: parent
201-
202- StyledItem {
203- objectName: "in_active_scope"
204- activeFocusOnPress: true
205- anchors.fill: parent
206- MouseArea {
207- focus: true
208- objectName: "mouseArea"
209- anchors.fill: parent
210- onClicked: parent.requestFocus()
211- }
212- }
213- }
214- }
215- StyledItem {
216- id: activeScope3
217- objectName: "activeScope"
218- width: units.gu(50)
219- height: units.gu(20)
220- activeFocusOnPress: true
221-
222- Rectangle {
223- width: height
224- height: units.gu(10)
225- color: "green"
226- anchors.centerIn: parent
227-
228- StyledItem {
229- objectName: "in_active_scope"
230- activeFocusOnPress: true
231- anchors.fill: parent
232- MouseArea {
233- focus: true
234- objectName: "mouseArea"
235- anchors.fill: parent
236- Mouse.forwardTo: [parent]
237- }
238- }
239- }
240- }
241 }
242
243 UbuntuTestCase {
244@@ -152,9 +100,7 @@
245 return [
246 {tag: "main scope is passive", mainScope: passiveScope, innerScope: "in_passive_scope", focusing: false},
247 {tag: "main scope is active", mainScope: activeScope, innerScope: "in_active_scope", focusing: true},
248- {tag: "MouseArea as child, suppressing", mainScope: activeScope1, innerScope: "mouseArea", focusing: false},
249- {tag: "MouseArea as child, gaining", mainScope: activeScope2, innerScope: "mouseArea", focusing: true},
250- {tag: "MouseArea as child, forwarding", mainScope: activeScope3, innerScope: "mouseArea", focusing: true},
251+ {tag: "MouseArea as child, gaining", mainScope: activeScope1, innerScope: "mouseArea", focusing: true},
252 ];
253 }
254 function test_scope_focusing(data) {

Subscribers

People subscribed via source and target branches