1 // Copyright (c) 2012 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/launcher/launcher_navigator.h"
7 #include "ash/launcher/launcher_model.h"
13 // Returns true if accelerator processing should skip the launcher item with
14 // the specified type.
15 bool ShouldSkip(ash::LauncherItemType type
) {
16 return type
== ash::TYPE_APP_LIST
||
17 type
== ash::TYPE_BROWSER_SHORTCUT
||
18 type
== ash::TYPE_APP_SHORTCUT
;
23 int GetNextActivatedItemIndex(const LauncherModel
& model
,
24 CycleDirection direction
) {
25 const ash::LauncherItems
& items
= model
.items();
26 int item_count
= model
.item_count();
27 int current_index
= -1;
28 int first_running
= -1;
30 for (int i
= 0; i
< item_count
; ++i
) {
31 const ash::LauncherItem
& item
= items
[i
];
32 if (ShouldSkip(item
.type
))
35 if (item
.status
== ash::STATUS_RUNNING
&& first_running
< 0)
38 if (item
.status
== ash::STATUS_ACTIVE
) {
44 // If nothing is active, try to active the first running item.
45 if (current_index
< 0) {
46 if (first_running
>= 0)
52 int step
= (direction
== CYCLE_FORWARD
) ? 1 : -1;
54 // Find the next item and activate it.
55 for (int i
= (current_index
+ step
+ item_count
) % item_count
;
56 i
!= current_index
; i
= (i
+ step
+ item_count
) % item_count
) {
57 const ash::LauncherItem
& item
= items
[i
];
58 if (ShouldSkip(item
.type
))
61 // Skip already active item.
62 if (item
.status
== ash::STATUS_ACTIVE
)