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 #ifndef ASH_SHELF_SHELF_MODEL_H_ | 5 #ifndef MASH_SHELF_SHELF_MODEL_H_ |
6 #define ASH_SHELF_SHELF_MODEL_H_ | 6 #define MASH_SHELF_SHELF_MODEL_H_ |
7 | 7 |
8 #include "ash/ash_export.h" | |
9 #include "ash/shelf/shelf_item_types.h" | |
10 #include "base/macros.h" | 8 #include "base/macros.h" |
11 #include "base/observer_list.h" | 9 #include "base/observer_list.h" |
| 10 #include "mash/shelf/shelf_item_types.h" |
| 11 #include "mash/wm/public/interfaces/user_window_controller.mojom.h" |
| 12 #include "mojo/public/cpp/bindings/binding.h" |
12 | 13 |
13 namespace ash { | 14 namespace mojo { |
| 15 class ApplicationImpl; |
| 16 } |
| 17 |
| 18 namespace mash { |
| 19 namespace shelf { |
14 | 20 |
15 class ShelfModelObserver; | 21 class ShelfModelObserver; |
16 | 22 |
17 // Model used by ShelfView. | 23 // Model used by ShelfView. |
18 class ASH_EXPORT ShelfModel { | 24 class ShelfModel : public mash::wm::mojom::UserWindowObserver { |
19 public: | 25 public: |
20 enum Status { | 26 enum Status { |
21 STATUS_NORMAL, | 27 STATUS_NORMAL, |
22 // A status that indicates apps are syncing/loading. | 28 // A status that indicates apps are syncing/loading. |
23 STATUS_LOADING, | 29 STATUS_LOADING, |
24 }; | 30 }; |
25 | 31 |
26 ShelfModel(); | 32 explicit ShelfModel(mojo::ApplicationImpl* app); |
27 ~ShelfModel(); | 33 ~ShelfModel() override; |
28 | 34 |
29 // Adds a new item to the model. Returns the resulting index. | 35 // Adds a new item to the model. Returns the resulting index. |
30 int Add(const ShelfItem& item); | 36 int Add(const ShelfItem& item); |
31 | 37 |
32 // Adds the item. |index| is the requested insertion index, which may be | 38 // Adds the item. |index| is the requested insertion index, which may be |
33 // modified to meet type-based ordering. Returns the actual insertion index. | 39 // modified to meet type-based ordering. Returns the actual insertion index. |
34 int AddAt(int index, const ShelfItem& item); | 40 int AddAt(int index, const ShelfItem& item); |
35 | 41 |
36 // Removes the item at |index|. | 42 // Removes the item at |index|. |
37 void RemoveItemAt(int index); | 43 void RemoveItemAt(int index); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 | 79 |
74 const ShelfItems& items() const { return items_; } | 80 const ShelfItems& items() const { return items_; } |
75 int item_count() const { return static_cast<int>(items_.size()); } | 81 int item_count() const { return static_cast<int>(items_.size()); } |
76 | 82 |
77 void SetStatus(Status status); | 83 void SetStatus(Status status); |
78 Status status() const { return status_; } | 84 Status status() const { return status_; } |
79 | 85 |
80 void AddObserver(ShelfModelObserver* observer); | 86 void AddObserver(ShelfModelObserver* observer); |
81 void RemoveObserver(ShelfModelObserver* observer); | 87 void RemoveObserver(ShelfModelObserver* observer); |
82 | 88 |
| 89 // TODO(msw): Do not expose this member, used by ShelfView to FocusUserWindow. |
| 90 mash::wm::mojom::UserWindowController* user_window_controller() const { |
| 91 return user_window_controller_.get(); |
| 92 } |
| 93 |
83 private: | 94 private: |
| 95 // Overridden from mash::wm::mojom::UserWindowObserver: |
| 96 void OnUserWindowObserverAdded( |
| 97 mojo::Array<mash::wm::mojom::UserWindowPtr> user_windows) override; |
| 98 void OnUserWindowAdded(mash::wm::mojom::UserWindowPtr user_window) override; |
| 99 void OnUserWindowRemoved(uint32_t window_id) override; |
| 100 void OnUserWindowTitleChanged(uint32_t window_id, |
| 101 const mojo::String& window_title) override; |
| 102 |
84 // Makes sure |index| is in line with the type-based order of items. If that | 103 // Makes sure |index| is in line with the type-based order of items. If that |
85 // is not the case, adjusts index by shifting it to the valid range and | 104 // is not the case, adjusts index by shifting it to the valid range and |
86 // returns the new value. | 105 // returns the new value. |
87 int ValidateInsertionIndex(ShelfItemType type, int index) const; | 106 int ValidateInsertionIndex(ShelfItemType type, int index) const; |
88 | 107 |
| 108 // Return the index of the item by window id. |
| 109 int ItemIndexByWindowID(uint32_t window_id) const; |
| 110 |
89 // ID assigned to the next item. | 111 // ID assigned to the next item. |
90 ShelfID next_id_; | 112 ShelfID next_id_; |
91 | 113 |
92 ShelfItems items_; | 114 ShelfItems items_; |
93 Status status_; | 115 Status status_; |
94 base::ObserverList<ShelfModelObserver> observers_; | 116 base::ObserverList<ShelfModelObserver> observers_; |
95 | 117 |
| 118 mash::wm::mojom::UserWindowControllerPtr user_window_controller_; |
| 119 mojo::Binding<mash::wm::mojom::UserWindowObserver> binding_; |
| 120 |
96 DISALLOW_COPY_AND_ASSIGN(ShelfModel); | 121 DISALLOW_COPY_AND_ASSIGN(ShelfModel); |
97 }; | 122 }; |
98 | 123 |
99 } // namespace ash | 124 } // namespace shelf |
| 125 } // namespace mash |
100 | 126 |
101 #endif // ASH_SHELF_SHELF_MODEL_H_ | 127 #endif // MASH_SHELF_SHELF_MODEL_H_ |
OLD | NEW |