Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(189)

Side by Side Diff: ash/shelf/shelf_navigator.cc

Issue 2169653002: mash: Move shelf_navigator.* to //ash/common/shelf (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review comments Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ash/shelf/shelf_navigator.h ('k') | ash/shelf/shelf_navigator_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
5 #include "ash/shelf/shelf_navigator.h"
6
7 #include "ash/common/shelf/shelf_model.h"
8
9 namespace ash {
10
11 namespace {
12
13 // Returns true if accelerator processing should skip the shelf item with the
14 // specified type.
15 bool ShouldSkip(ShelfItemType type) {
16 return type == TYPE_APP_LIST || type == TYPE_BROWSER_SHORTCUT ||
17 type == TYPE_APP_SHORTCUT || type == TYPE_WINDOWED_APP;
18 }
19
20 } // namespace
21
22 int GetNextActivatedItemIndex(const ShelfModel& model,
23 CycleDirection direction) {
24 const ShelfItems& items = model.items();
25 int item_count = model.item_count();
26 int current_index = -1;
27 int first_running = -1;
28
29 for (int i = 0; i < item_count; ++i) {
30 const ShelfItem& item = items[i];
31 if (ShouldSkip(item.type))
32 continue;
33
34 if (item.status == STATUS_RUNNING && first_running < 0)
35 first_running = i;
36
37 if (item.status == STATUS_ACTIVE) {
38 current_index = i;
39 break;
40 }
41 }
42
43 // If nothing is active, try to active the first running item.
44 if (current_index < 0) {
45 if (first_running >= 0)
46 return first_running;
47 else
48 return -1;
49 }
50
51 int step = (direction == CYCLE_FORWARD) ? 1 : -1;
52
53 // Find the next item and activate it.
54 for (int i = (current_index + step + item_count) % item_count;
55 i != current_index; i = (i + step + item_count) % item_count) {
56 const ShelfItem& item = items[i];
57 if (ShouldSkip(item.type))
58 continue;
59
60 // Skip already active item.
61 if (item.status == STATUS_ACTIVE)
62 continue;
63
64 return i;
65 }
66
67 return -1;
68 }
69
70 } // namespace ash
OLDNEW
« no previous file with comments | « ash/shelf/shelf_navigator.h ('k') | ash/shelf/shelf_navigator_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698