28
28
property Item activeFocusItem: Window.activeFocusItem
32
title: "ListItem focus test"
37
function setupListView(showContent, orientation, reverseDirection) {
39
var test = testCase.loadTest(listView);
40
test.orientation = orientation;
41
if (reverseDirection) {
42
if (orientation === ListView.Horizontal) {
43
test.layoutDirection = Qt.RightToLeft;
45
test.verticalLayoutDirection = ListView.BottomToTop;
49
test.delegate = listItemWithContent;
51
test.delegate = simpleListItem;
58
onTriggered: directionSections.setupListView(switchContentAction.showContent,
59
ListView.Vertical, false);
63
onTriggered: directionSections.setupListView(switchContentAction.showContent,
64
ListView.Horizontal, false);
68
onTriggered: directionSections.setupListView(switchContentAction.showContent,
69
ListView.Vertical, true);
73
onTriggered: directionSections.setupListView(switchContentAction.showContent,
74
ListView.Horizontal, true);
79
trailingActionBar.actions: [
81
id: switchContentAction
82
property bool showContent: false
83
iconName: showContent ? "select" : "select-none"
85
showContent = !showContent;
86
if (directionSections.selectedIndex >= 0) {
87
directionSections.actions[directionSections.selectedIndex].trigger();
96
objectName: "topFocusItem"
33
97
activeFocusOnTab: true
35
103
height: units.gu(2)
106
color: topFocusItem.activeFocus ? UbuntuColors.orange : UbuntuColors.silk
42
topMargin: topItem.height
114
top: topFocusItem.bottom
115
bottom: bottomFocusItem.top
121
objectName: "bottomFocusItem"
122
activeFocusOnTab: true
126
bottom: parent.bottom
131
color: bottomFocusItem.activeFocus ? UbuntuColors.orange : UbuntuColors.silk
47
136
id: simpleListItem
49
139
objectName: "simple" + index
50
140
property int itemIndex: index
144
leftMargin: units.gu(2)
145
verticalCenter: parent.verticalCenter
147
text: listItem.objectName
61
159
spacing: units.gu(1)
62
160
CheckBox { objectName: "checkbox" + listItem.itemIndex }
63
161
Switch { objectName: "switch" + listItem.itemIndex }
64
Button { objectName: "button" + listItem.itemIndex; text: "test" }
162
Button { objectName: "button" + listItem.itemIndex; text: "test " + itemIndex }
66
164
leadingActions: ListItemActions {
124
223
// Tab/Backtab focuses the First ListItem in a ListView
125
224
function test_focusing_listview_focuses_first_item_data() {
127
{tag: "Tab, no content", preFocus: topItem, delegate: simpleListItem, key: Qt.Key_Tab, focusItem: "simple0"},
128
{tag: "Tab, with content", preFocus: topItem, delegate: listItemWithContent, key: Qt.Key_Tab, focusItem: "withContent0"},
129
{tag: "Backtab, no content", preFocus: topItem, delegate: simpleListItem, key: Qt.Key_Backtab, focusItem: "simple0"},
130
{tag: "Backtab, with content", preFocus: topItem, delegate: listItemWithContent, key: Qt.Key_Backtab, focusItem: "withContent0"},
226
{tag: "Tab, no content", preFocus: topFocusItem, delegate: simpleListItem, key: Qt.Key_Tab, focusItem: "simple0"},
227
{tag: "Tab, with content", preFocus: topFocusItem, delegate: listItemWithContent, key: Qt.Key_Tab, focusItem: "withContent0"},
228
{tag: "Backtab, no content", preFocus: bottomFocusItem, delegate: simpleListItem, key: Qt.Key_Backtab, focusItem: "simple0"},
229
{tag: "Backtab, with content", preFocus: bottomFocusItem, delegate: listItemWithContent, key: Qt.Key_Backtab, focusItem: "withContent0"},
133
232
function test_focusing_listview_focuses_first_item(data) {
156
255
focusItems: ["simple1", "simple2", "simple3"]
257
{ tag: "BottomToTop up, no content, bottom to top direction, from beginning",
258
delegate: simpleListItem,
259
orientation: ListView.Vertical,
260
direction: ListView.BottomToTop,
264
focusItems: ["simple1", "simple2", "simple3"]
159
267
tag: "Down, no contents, near end",
160
268
delegate: simpleListItem,
165
273
// Don't navigate beyond the last item:
166
274
focusItems: ["simple"+(n-2), "simple"+(n-1), "simple"+(n-1)]
277
tag: "BottomToTop up, no contents, near end",
278
delegate: simpleListItem,
279
orientation: ListView.Vertical,
280
direction: ListView.BottomToTop,
284
// Don't navigate beyond the last item:
285
focusItems: ["simple"+(n-2), "simple"+(n-1), "simple"+(n-1)]
168
287
{ tag: "Up, no content, near beginning",
169
288
delegate: simpleListItem,
170
289
orientation: ListView.Vertical,
174
293
focusItems: ["simple1", "simple0", "simple0"]
295
{ tag: "BottomToTop down, no content, near beginning",
296
delegate: simpleListItem,
297
orientation: ListView.Vertical,
298
direction: ListView.BottomToTop,
302
focusItems: ["simple1", "simple0", "simple0"]
177
305
tag: "Up, no contents, from end",
178
306
delegate: simpleListItem,
183
311
focusItems: ["simple"+(n-2), "simple"+(n-3), "simple"+(n-4)]
314
tag: "BottomToTop down, no contents, from end",
315
delegate: simpleListItem,
316
orientation: ListView.Vertical,
317
direction: ListView.BottomToTop,
321
focusItems: ["simple"+(n-2), "simple"+(n-3), "simple"+(n-4)]
185
323
{ tag: "Left, no content, near beginning",
186
324
delegate: simpleListItem,
187
325
orientation: ListView.Horizontal,
191
329
focusItems: ["simple1", "simple0", "simple0"]
331
{ tag: "RightToLeft right, no content, near beginning",
332
delegate: simpleListItem,
333
orientation: ListView.Horizontal,
334
direction: Qt.RightToLeft,
338
focusItems: ["simple1", "simple0", "simple0"]
193
340
{ tag: "Left, no content, from end",
194
341
delegate: simpleListItem,
195
342
orientation: ListView.Horizontal,
199
346
focusItems: ["simple"+(n-2), "simple"+(n-3), "simple"+(n-4)]
348
{ tag: "RightToLeft right, no content, from end",
349
delegate: simpleListItem,
350
orientation: ListView.Horizontal,
351
direction: Qt.RightToLeft,
355
focusItems: ["simple"+(n-2), "simple"+(n-3), "simple"+(n-4)]
201
357
{ tag: "Right, no content, from beginning",
202
358
delegate: simpleListItem,
203
359
orientation: ListView.Horizontal,
207
363
focusItems: ["simple1", "simple2", "simple3", "simple4", "simple5"]
365
{ tag: "RightToLeft left, no content, from beginning",
366
delegate: simpleListItem,
367
orientation: ListView.Horizontal,
368
direction: Qt.RightToLeft,
372
focusItems: ["simple1", "simple2", "simple3", "simple4", "simple5"]
209
374
{ tag: "Right, no content, near end",
210
375
delegate: simpleListItem,
211
376
orientation: ListView.Horizontal,
215
380
focusItems: ["simple"+(n-2), "simple"+(n-1), "simple"+(n-1)]
382
{ tag: "RightToLeft left, no content, near end",
383
delegate: simpleListItem,
384
orientation: ListView.Horizontal,
385
direction: Qt.RightToLeft,
389
focusItems: ["simple"+(n-2), "simple"+(n-1), "simple"+(n-1)]
217
391
{ tag: "Down, with content, from beginning",
218
392
delegate: listItemWithContent,
219
393
orientation: ListView.Vertical,
223
397
focusItems: ["withContent1", "withContent2", "withContent3"]
399
{ tag: "BottomToTop up, with content, from beginning",
400
delegate: listItemWithContent,
401
orientation: ListView.Vertical,
402
direction: ListView.BottomToTop,
406
focusItems: ["withContent1", "withContent2", "withContent3"]
225
408
{ tag: "Down, with content, near end",
226
409
delegate: listItemWithContent,
227
410
orientation: ListView.Vertical,
231
414
focusItems: ["withContent"+(n-2), "withContent"+(n-1), "withContent"+(n-1)]
416
{ tag: "BottomToTop up, with content, near end",
417
delegate: listItemWithContent,
418
orientation: ListView.Vertical,
419
direction: ListView.BottomToTop,
423
focusItems: ["withContent"+(n-2), "withContent"+(n-1), "withContent"+(n-1)]
233
425
{ tag: "Up, with content, near beginning",
234
426
delegate: listItemWithContent,
235
427
orientation: ListView.Vertical,
239
431
focusItems: ["withContent1", "withContent0", "withContent0"]
433
{ tag: "BottomToTop down, with content, near beginning",
434
delegate: listItemWithContent,
435
orientation: ListView.Vertical,
436
direction: ListView.BottomToTop,
440
focusItems: ["withContent1", "withContent0", "withContent0"]
241
442
{ tag: "Up, with content, from end",
242
443
delegate: listItemWithContent,
243
444
orientation: ListView.Vertical,
247
448
focusItems: ["withContent"+(n-2), "withContent"+(n-3)]
450
{ tag: "BottomToTop down, with content, from end",
451
delegate: listItemWithContent,
452
orientation: ListView.Vertical,
453
direction: ListView.BottomToTop,
457
focusItems: ["withContent"+(n-2), "withContent"+(n-3)]
249
459
// Horizontal navigation for ListItems with content is not supported.
253
463
var test = loadTest(listView);
254
464
test.orientation = data.orientation;
255
465
test.delegate = data.delegate;
466
// The cases where data.direction is set to ListView.BottomtoTop or Qt.RightToLeft
467
// are regression tests for bug #1605634.
468
if (data.direction) {
469
if (data.orientation === ListView.Horizontal) {
470
test.layoutDirection = data.direction;
472
test.verticalLayoutDirection = data.direction;
256
475
test.currentIndex = data.initialIndex;
257
476
waitForRendering(test, 500);
258
477
keyClick(Qt.Key_Tab);
296
515
// Tab/Backtab focuses, next Tab/Backtab focuses out of ListItem in a ListView
297
516
function test_tab_backtab_navigates_away_of_listview_data() {
299
{tag: "Tab, simple", preFocus: topItem, delegate: simpleListItem, key: Qt.Key_Tab},
300
{tag: "Tab, with content", preFocus: topItem, delegate: listItemWithContent, key: Qt.Key_Tab},
301
{tag: "BackTab, simple", preFocus: topItem, delegate: simpleListItem, key: Qt.Key_Backtab},
302
{tag: "BackTab, with content", preFocus: topItem, delegate: listItemWithContent, key: Qt.Key_Backtab},
518
{tag: "Tab, simple", preFocus: topFocusItem, delegate: simpleListItem, key: Qt.Key_Tab},
519
{tag: "Tab, with content", preFocus: topFocusItem, delegate: listItemWithContent, key: Qt.Key_Tab},
520
{tag: "BackTab, simple", preFocus: bottomFocusItem, delegate: simpleListItem, key: Qt.Key_Backtab},
521
{tag: "BackTab, with content", preFocus: bottomFocusItem, delegate: listItemWithContent, key: Qt.Key_Backtab},
305
524
function test_tab_backtab_navigates_away_of_listview(data) {
310
529
verify(data.preFocus.activeFocus);
311
530
// the first tab focuses the ListView and its first child
312
531
keyClick(data.key);
313
tryCompare(test, "activeFocus", true, 500, "Focus hasn't been gained bythe ListItem");
532
tryCompare(test, "activeFocus", true, 500, "Focus hasn't been gained by the ListItem");
315
534
// the second tab should leave the ListView
316
535
keyClick(data.key);
320
539
// testing Tab/Backtab navigation when in a generic item
321
540
function test_tab_navigation_when_not_in_listview_data() {
323
{tag: "Tabs", firstFocus: topItem, key: Qt.Key_Tab,
542
{tag: "Tabs", firstFocus: topFocusItem, key: Qt.Key_Tab,
324
543
focusItems: ["withContent0", "checkbox0", "switch0", "button0"
325
544
, "withContent1", "checkbox1", "switch1", "button1"]},
326
{tag: "Backtabs", firstFocus: topItem, key: Qt.Key_Backtab,
545
{tag: "Backtabs", firstFocus: bottomFocusItem, key: Qt.Key_Backtab,
327
546
focusItems: ["simple1", "simple0"
328
547
, "button1", "switch1", "checkbox1", "withContent1"]},
409
628
{tag: "Tabs in ListView", test: listView, delegate: listItemWithContent, testPlan: [
410
629
{key: Qt.Key_Tab, focus: "withContent0"},
411
{key: Qt.Key_Tab, focus: "topItem"},
630
{key: Qt.Key_Tab, focus: "bottomFocusItem"},
412
631
{key: Qt.Key_Backtab, focus: "withContent0"},
414
633
{tag: "Tab and navigate in ListView", test: listView, delegate: listItemWithContent, testPlan: [
421
640
{key: Qt.Key_Right, focus: "switch2"},
422
641
{key: Qt.Key_Down, focus: "withContent3"},
423
642
{key: Qt.Key_Down, focus: "withContent4"},
424
{key: Qt.Key_Backtab, focus: "topItem"},
643
{key: Qt.Key_Backtab, focus: "topFocusItem"},
425
644
{key: Qt.Key_Tab, focus: "withContent4"},
427
646
{tag: "Tab and navigate in generic", test: generic, testPlan: [
434
653
{key: Qt.Key_Right, focus: "withContent0"},
435
654
{key: Qt.Key_Down, focus: "withContent0"},
436
655
{key: Qt.Key_Down, focus: "withContent0"},
437
{key: Qt.Key_Backtab, focus: "topItem"},
656
{key: Qt.Key_Backtab, focus: "topFocusItem"},
438
657
{key: Qt.Key_Tab, focus: "withContent0"},
440
659
{tag: "Mixed Tab and navigate keys in generic", test: generic, testPlan: [