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

Unified Diff: mash/shelf/shelf_model.cc

Issue 1585363002: Fork a subset of ash/shelf for use in mash. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Revert ash changes. Created 4 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: mash/shelf/shelf_model.cc
diff --git a/ash/shelf/shelf_model.cc b/mash/shelf/shelf_model.cc
similarity index 74%
copy from ash/shelf/shelf_model.cc
copy to mash/shelf/shelf_model.cc
index e04af42d1f712a8b4b761f6b6e4749a3fe48d640..e81c8a4d26dbaa733a60b5cdd9daf7dc1f73651f 100644
--- a/ash/shelf/shelf_model.cc
+++ b/mash/shelf/shelf_model.cc
@@ -2,14 +2,16 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "ash/shelf/shelf_model.h"
+#include "mash/shelf/shelf_model.h"
#include <algorithm>
-#include "ash/ash_switches.h"
-#include "ash/shelf/shelf_model_observer.h"
+#include "mash/shelf/shelf_model_observer.h"
+#include "mojo/common/common_type_converters.h"
+#include "mojo/shell/public/cpp/application_impl.h"
-namespace ash {
+namespace mash {
+namespace shelf {
namespace {
@@ -24,6 +26,7 @@ int ShelfItemTypeToWeight(ShelfItemType type) {
return 1;
case TYPE_WINDOWED_APP:
case TYPE_PLATFORM_APP:
+ case TYPE_MOJO_APP:
return 2;
case TYPE_DIALOG:
return 3;
@@ -44,14 +47,18 @@ bool CompareByWeight(const ShelfItem& a, const ShelfItem& b) {
} // namespace
-ShelfModel::ShelfModel() : next_id_(1), status_(STATUS_NORMAL) {
+ShelfModel::ShelfModel(mojo::ApplicationImpl* app)
+ : next_id_(1), status_(STATUS_NORMAL), binding_(this) {
+ app->ConnectToService("mojo:desktop_wm", &user_window_controller_);
+ user_window_controller_->AddUserWindowObserver(
+ binding_.CreateInterfacePtrAndBind());
}
ShelfModel::~ShelfModel() {
}
int ShelfModel::Add(const ShelfItem& item) {
- return AddAt(items_.size(), item);
+ return AddAt(static_cast<int>(items_.size()), item);
}
int ShelfModel::AddAt(int index, const ShelfItem& item) {
@@ -118,7 +125,7 @@ int ShelfModel::ItemIndexByID(ShelfID id) const {
int ShelfModel::GetItemIndexForType(ShelfItemType type) {
for (size_t i = 0; i < items_.size(); ++i) {
if (items_[i].type == type)
- return i;
+ return static_cast<int>(i);
}
return -1;
}
@@ -182,4 +189,41 @@ int ShelfModel::ValidateInsertionIndex(ShelfItemType type, int index) const {
return index;
}
-} // namespace ash
+void ShelfModel::OnUserWindowObserverAdded(
+ mojo::Array<mash::wm::mojom::UserWindowPtr> user_windows) {
+ for (size_t i = 0; i < user_windows.size(); ++i)
+ OnUserWindowAdded(std::move(user_windows[i]));
+}
+
+void ShelfModel::OnUserWindowAdded(mash::wm::mojom::UserWindowPtr user_window) {
+ ShelfItem item;
+ item.type = TYPE_MOJO_APP;
+ item.status = STATUS_RUNNING;
+ item.window_id = user_window->window_id;
+ item.title = user_window->window_title.To<base::string16>();
+ Add(item);
+}
+
+void ShelfModel::OnUserWindowRemoved(uint32_t window_id) {
+ RemoveItemAt(ItemIndexByWindowID(window_id));
+}
+
+void ShelfModel::OnUserWindowTitleChanged(uint32_t window_id,
+ const mojo::String& window_title) {
+ const int index = ItemIndexByWindowID(window_id);
+ ShelfItem old_item(items_[index]);
+ items_[index].title = window_title.To<base::string16>();
+ FOR_EACH_OBSERVER(ShelfModelObserver, observers_,
+ ShelfItemChanged(index, old_item));
+}
+
+int ShelfModel::ItemIndexByWindowID(uint32_t window_id) const {
+ for (size_t i = 0; i < items_.size(); ++i) {
+ if (items_[i].window_id == window_id)
+ return static_cast<int>(i);
+ }
+ return -1;
+}
+
+} // namespace shelf
+} // namespace mash

Powered by Google App Engine
This is Rietveld 408576698