Fix incorrect handling of accelerators on constrained web dailogs.
[chromium-blink-merge.git] / ash / launcher / launcher_navigator.cc
blob3ae142461b915995f20bcb5a0351e9aead33a426
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"
9 namespace ash {
11 namespace {
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;
21 } // namespace
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))
33 continue;
35 if (item.status == ash::STATUS_RUNNING && first_running < 0)
36 first_running = i;
38 if (item.status == ash::STATUS_ACTIVE) {
39 current_index = i;
40 break;
44 // If nothing is active, try to active the first running item.
45 if (current_index < 0) {
46 if (first_running >= 0)
47 return first_running;
48 else
49 return -1;
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))
59 continue;
61 // Skip already active item.
62 if (item.status == ash::STATUS_ACTIVE)
63 continue;
65 return i;
68 return -1;
71 } // namespace ash