| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ash/shelf/shelf_navigator.h" | 5 #include "ash/shelf/shelf_navigator.h" |
| 6 | 6 |
| 7 #include "ash/shelf/shelf_model.h" | 7 #include "ash/shelf/shelf_model.h" |
| 8 | 8 |
| 9 namespace ash { | 9 namespace ash { |
| 10 | 10 |
| 11 namespace { | 11 namespace { |
| 12 | 12 |
| 13 // Returns true if accelerator processing should skip the shelf item with the | 13 // Returns true if accelerator processing should skip the shelf item with the |
| 14 // specified type. | 14 // specified type. |
| 15 bool ShouldSkip(ShelfItemType type) { | 15 bool ShouldSkip(ShelfItemType type) { |
| 16 return type == TYPE_APP_LIST || | 16 return type == TYPE_APP_LIST || |
| 17 type == TYPE_BROWSER_SHORTCUT || | 17 type == TYPE_BROWSER_SHORTCUT || |
| 18 type == TYPE_APP_SHORTCUT || | 18 type == TYPE_APP_SHORTCUT || |
| 19 type == TYPE_WINDOWED_APP; | 19 type == TYPE_WINDOWED_APP; |
| 20 } | 20 } |
| 21 | 21 |
| 22 } // namespace | 22 } // namespace |
| 23 | 23 |
| 24 int GetNextActivatedItemIndex(const ShelfModel& model, | 24 int GetNextActivatedItemIndex(const ShelfModel& model, |
| 25 CycleDirection direction) { | 25 CycleDirection direction) { |
| 26 const LauncherItems& items = model.items(); | 26 const ShelfItems& items = model.items(); |
| 27 int item_count = model.item_count(); | 27 int item_count = model.item_count(); |
| 28 int current_index = -1; | 28 int current_index = -1; |
| 29 int first_running = -1; | 29 int first_running = -1; |
| 30 | 30 |
| 31 for (int i = 0; i < item_count; ++i) { | 31 for (int i = 0; i < item_count; ++i) { |
| 32 const LauncherItem& item = items[i]; | 32 const ShelfItem& item = items[i]; |
| 33 if (ShouldSkip(item.type)) | 33 if (ShouldSkip(item.type)) |
| 34 continue; | 34 continue; |
| 35 | 35 |
| 36 if (item.status == STATUS_RUNNING && first_running < 0) | 36 if (item.status == STATUS_RUNNING && first_running < 0) |
| 37 first_running = i; | 37 first_running = i; |
| 38 | 38 |
| 39 if (item.status == STATUS_ACTIVE) { | 39 if (item.status == STATUS_ACTIVE) { |
| 40 current_index = i; | 40 current_index = i; |
| 41 break; | 41 break; |
| 42 } | 42 } |
| 43 } | 43 } |
| 44 | 44 |
| 45 // If nothing is active, try to active the first running item. | 45 // If nothing is active, try to active the first running item. |
| 46 if (current_index < 0) { | 46 if (current_index < 0) { |
| 47 if (first_running >= 0) | 47 if (first_running >= 0) |
| 48 return first_running; | 48 return first_running; |
| 49 else | 49 else |
| 50 return -1; | 50 return -1; |
| 51 } | 51 } |
| 52 | 52 |
| 53 int step = (direction == CYCLE_FORWARD) ? 1 : -1; | 53 int step = (direction == CYCLE_FORWARD) ? 1 : -1; |
| 54 | 54 |
| 55 // Find the next item and activate it. | 55 // Find the next item and activate it. |
| 56 for (int i = (current_index + step + item_count) % item_count; | 56 for (int i = (current_index + step + item_count) % item_count; |
| 57 i != current_index; i = (i + step + item_count) % item_count) { | 57 i != current_index; i = (i + step + item_count) % item_count) { |
| 58 const LauncherItem& item = items[i]; | 58 const ShelfItem& item = items[i]; |
| 59 if (ShouldSkip(item.type)) | 59 if (ShouldSkip(item.type)) |
| 60 continue; | 60 continue; |
| 61 | 61 |
| 62 // Skip already active item. | 62 // Skip already active item. |
| 63 if (item.status == STATUS_ACTIVE) | 63 if (item.status == STATUS_ACTIVE) |
| 64 continue; | 64 continue; |
| 65 | 65 |
| 66 return i; | 66 return i; |
| 67 } | 67 } |
| 68 | 68 |
| 69 return -1; | 69 return -1; |
| 70 } | 70 } |
| 71 | 71 |
| 72 } // namespace ash | 72 } // namespace ash |
| OLD | NEW |