1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ash/shelf/shelf_navigator.h"
7 #include "ash/shelf/shelf_model.h"
13 // Returns true if accelerator processing should skip the shelf item with the
15 bool ShouldSkip(ShelfItemType type
) {
16 return type
== TYPE_APP_LIST
||
17 type
== TYPE_BROWSER_SHORTCUT
||
18 type
== TYPE_APP_SHORTCUT
||
19 type
== TYPE_WINDOWED_APP
;
24 int GetNextActivatedItemIndex(const ShelfModel
& model
,
25 CycleDirection direction
) {
26 const ShelfItems
& items
= model
.items();
27 int item_count
= model
.item_count();
28 int current_index
= -1;
29 int first_running
= -1;
31 for (int i
= 0; i
< item_count
; ++i
) {
32 const ShelfItem
& item
= items
[i
];
33 if (ShouldSkip(item
.type
))
36 if (item
.status
== STATUS_RUNNING
&& first_running
< 0)
39 if (item
.status
== STATUS_ACTIVE
) {
45 // If nothing is active, try to active the first running item.
46 if (current_index
< 0) {
47 if (first_running
>= 0)
53 int step
= (direction
== CYCLE_FORWARD
) ? 1 : -1;
55 // Find the next item and activate it.
56 for (int i
= (current_index
+ step
+ item_count
) % item_count
;
57 i
!= current_index
; i
= (i
+ step
+ item_count
) % item_count
) {
58 const ShelfItem
& item
= items
[i
];
59 if (ShouldSkip(item
.type
))
62 // Skip already active item.
63 if (item
.status
== STATUS_ACTIVE
)