Fix incorrect handling of accelerators on constrained web dailogs.
[chromium-blink-merge.git] / ash / launcher / launcher_model.h
blobce52126a3e622c6d56fc646a76253e923e19f162
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 #ifndef ASH_LAUNCHER_LAUNCHER_MODEL_H_
6 #define ASH_LAUNCHER_LAUNCHER_MODEL_H_
8 #include "ash/ash_export.h"
9 #include "ash/launcher/launcher_types.h"
10 #include "base/basictypes.h"
11 #include "base/observer_list.h"
13 namespace ash {
15 class LauncherModelObserver;
17 // Model used by LauncherView.
18 class ASH_EXPORT LauncherModel {
19 public:
20 enum Status {
21 STATUS_NORMAL,
22 // A status that indicates apps are syncing/loading.
23 STATUS_LOADING,
26 LauncherModel();
27 ~LauncherModel();
29 // Adds a new item to the model. Returns the resulting index.
30 int Add(const LauncherItem& item);
32 // Adds the item. |index| is the requested insertion index, which may be
33 // modified to meet type-based ordering. Returns the actual insertion index.
34 int AddAt(int index, const LauncherItem& item);
36 // Removes the item at |index|.
37 void RemoveItemAt(int index);
39 // Moves the item at |index| to |target_index|. |target_index| is in terms
40 // of the model *after* the item at |index| is removed.
41 void Move(int index, int target_index);
43 // Resets the item at the specified index. The item maintains its existing
44 // id and type.
45 void Set(int index, const LauncherItem& item);
47 // Returns the index of the item by id.
48 int ItemIndexByID(int id) const;
50 // Returns the index of the first panel or the index where the first panel
51 // would go if there are no panels.
52 int FirstPanelIndex() const;
54 // Returns the id assigned to the next item added.
55 LauncherID next_id() const { return next_id_; }
57 // Returns an iterator into items() for the item with the specified id, or
58 // items().end() if there is no item with the specified id.
59 LauncherItems::const_iterator ItemByID(LauncherID id) const;
61 const LauncherItems& items() const { return items_; }
62 int item_count() const { return static_cast<int>(items_.size()); }
64 void SetStatus(Status status);
65 Status status() const { return status_; }
67 void AddObserver(LauncherModelObserver* observer);
68 void RemoveObserver(LauncherModelObserver* observer);
70 private:
71 // Makes sure |index| is in line with the type-based order of items. If that
72 // is not the case, adjusts index by shifting it to the valid range and
73 // returns the new value.
74 int ValidateInsertionIndex(LauncherItemType type, int index) const;
76 // ID assigned to the next item.
77 LauncherID next_id_;
78 LauncherItems items_;
79 Status status_;
80 ObserverList<LauncherModelObserver> observers_;
82 DISALLOW_COPY_AND_ASSIGN(LauncherModel);
85 } // namespace ash
87 #endif // ASH_LAUNCHER_LAUNCHER_MODEL_H_