Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #ifndef UI_AURA_SHELL_LAUNCHER_MODEL_H_ | 5 #ifndef UI_AURA_SHELL_LAUNCHER_MODEL_H_ |
| 6 #define UI_AURA_SHELL_LAUNCHER_MODEL_H_ | 6 #define UI_AURA_SHELL_LAUNCHER_MODEL_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/observer_list.h" | 11 #include "base/observer_list.h" |
| 12 #include "ui/aura_shell/aura_shell_export.h" | 12 #include "ui/aura_shell/aura_shell_export.h" |
| 13 #include "ui/aura_shell/launcher/launcher_types.h" | |
| 13 | 14 |
| 14 namespace views { | 15 namespace views { |
| 15 class View; | 16 class View; |
| 16 } | 17 } |
| 17 | 18 |
| 18 namespace aura_shell { | 19 namespace aura_shell { |
| 19 | 20 |
| 20 class LauncherModelObserver; | 21 class LauncherModelObserver; |
| 21 | 22 |
| 22 // Model used by LauncherView. | 23 // Model used by LauncherView. |
| 23 class AURA_SHELL_EXPORT LauncherModel { | 24 class AURA_SHELL_EXPORT LauncherModel { |
| 24 public: | 25 public: |
| 25 LauncherModel(); | 26 LauncherModel(); |
| 26 ~LauncherModel(); | 27 ~LauncherModel(); |
| 27 | 28 |
| 28 // Adds a new view to the model. The model takes ownership of the view. | 29 static LauncherModel* instance() { return instance_; } |
| 29 void AddItem(views::View* view, int index, bool draggable); | |
| 30 | 30 |
| 31 // Removes an item by the view. | 31 // Adds a new item to the model. |
| 32 void RemoveItem(views::View* view); | 32 void Add(int index, const LauncherItem& item); |
| 33 | 33 |
| 34 // Removes the item at |index|. | 34 // Removes the item at |index|. |
| 35 void RemoveItemAt(int index); | 35 void RemoveItemAt(int index); |
| 36 | 36 |
| 37 // The selected index; -1 if nothing is selected. | 37 // Changes the images of the specified item. |
| 38 void SetSelectedIndex(int index); | 38 void SetTabbedImages(int index, const LauncherTabbedImages& images); |
| 39 int selected_index() const { return selected_index_; } | 39 void SetAppImage(int index, const SkBitmap& image); |
| 40 | 40 |
| 41 // Returns the index of |view|, or -1 if view isn't contained in this model. | 41 const LauncherItems& items() const { return items_; } |
| 42 int IndexOfItemByView(views::View* view); | |
| 43 int item_count() const { return static_cast<int>(items_.size()); } | 42 int item_count() const { return static_cast<int>(items_.size()); } |
| 44 views::View* view_at(int index) { return items_[index].view; } | |
| 45 bool is_draggable(int index) { return items_[index].draggable; } | |
| 46 | 43 |
| 47 void AddObserver(LauncherModelObserver* observer); | 44 void AddObserver(LauncherModelObserver* observer); |
| 48 void RemoveObserver(LauncherModelObserver* observer); | 45 void RemoveObserver(LauncherModelObserver* observer); |
| 49 | 46 |
| 50 private: | 47 private: |
| 51 struct Item { | 48 LauncherItems items_; |
| 52 Item() : view(NULL), draggable(false) {} | 49 ObserverList<LauncherModelObserver> observers_; |
| 53 | 50 |
| 54 // The view, we own this. | 51 static LauncherModel* instance_; |
|
Ben Goodger (Google)
2011/10/13 03:03:39
I'm not sure you'll want this to be global like th
| |
| 55 views::View* view; | |
| 56 bool draggable; | |
| 57 }; | |
| 58 typedef std::vector<Item> Items; | |
| 59 | |
| 60 Items items_; | |
| 61 int selected_index_; | |
| 62 ObserverList<LauncherModelObserver> observers_; | |
| 63 | 52 |
| 64 DISALLOW_COPY_AND_ASSIGN(LauncherModel); | 53 DISALLOW_COPY_AND_ASSIGN(LauncherModel); |
| 65 }; | 54 }; |
| 66 | 55 |
| 67 } // namespace aura_shell | 56 } // namespace aura_shell |
| 68 | 57 |
| 69 #endif // UI_AURA_SHELL_LAUNCHER_MODEL_H_ | 58 #endif // UI_AURA_SHELL_LAUNCHER_MODEL_H_ |
| OLD | NEW |