| 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/test/test_shelf_delegate.h" | 5 #include "ash/test/test_shelf_delegate.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "ash/aura/wm_window_aura.h" |
| 9 #include "ash/common/shelf/shelf_model.h" | 10 #include "ash/common/shelf/shelf_model.h" |
| 10 #include "ash/shelf/shelf_util.h" | 11 #include "ash/common/wm_window_property.h" |
| 11 #include "ash/test/test_shelf_item_delegate.h" | 12 #include "ash/test/test_shelf_item_delegate.h" |
| 12 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 14 #include "ui/aura/window.h" | 15 #include "ui/aura/window.h" |
| 15 | 16 |
| 16 namespace ash { | 17 namespace ash { |
| 17 namespace test { | 18 namespace test { |
| 18 | 19 |
| 19 TestShelfDelegate* TestShelfDelegate::instance_ = NULL; | 20 TestShelfDelegate* TestShelfDelegate::instance_ = NULL; |
| 20 | 21 |
| 21 TestShelfDelegate::TestShelfDelegate(ShelfModel* model) : model_(model) { | 22 TestShelfDelegate::TestShelfDelegate(ShelfModel* model) : model_(model) { |
| 22 CHECK(!instance_); | 23 CHECK(!instance_); |
| 23 instance_ = this; | 24 instance_ = this; |
| 24 } | 25 } |
| 25 | 26 |
| 26 TestShelfDelegate::~TestShelfDelegate() { | 27 TestShelfDelegate::~TestShelfDelegate() { |
| 27 instance_ = NULL; | 28 instance_ = NULL; |
| 28 } | 29 } |
| 29 | 30 |
| 30 void TestShelfDelegate::AddShelfItem(aura::Window* window) { | 31 void TestShelfDelegate::AddShelfItem(aura::Window* window) { |
| 31 AddShelfItem(window, STATUS_CLOSED); | 32 AddShelfItem(window, STATUS_CLOSED); |
| 32 } | 33 } |
| 33 | 34 |
| 34 void TestShelfDelegate::AddShelfItem(aura::Window* window, | 35 void TestShelfDelegate::AddShelfItem(aura::Window* window, |
| 35 const std::string& app_id) { | 36 const std::string& app_id) { |
| 36 AddShelfItem(window, STATUS_CLOSED); | 37 AddShelfItem(window, STATUS_CLOSED); |
| 37 AddShelfIDToAppIDMapping(GetShelfIDForWindow(window), app_id); | 38 WmWindow* wm_window = WmWindowAura::Get(window); |
| 39 ShelfID shelf_id = wm_window->GetIntProperty(WmWindowProperty::SHELF_ID); |
| 40 AddShelfIDToAppIDMapping(shelf_id, app_id); |
| 38 } | 41 } |
| 39 | 42 |
| 40 void TestShelfDelegate::AddShelfItem(aura::Window* window, | 43 void TestShelfDelegate::AddShelfItem(aura::Window* window, |
| 41 ShelfItemStatus status) { | 44 ShelfItemStatus status) { |
| 42 ShelfItem item; | 45 ShelfItem item; |
| 43 if (window->type() == ui::wm::WINDOW_TYPE_PANEL) | 46 if (window->type() == ui::wm::WINDOW_TYPE_PANEL) |
| 44 item.type = TYPE_APP_PANEL; | 47 item.type = TYPE_APP_PANEL; |
| 45 else | 48 else |
| 46 item.type = TYPE_PLATFORM_APP; | 49 item.type = TYPE_PLATFORM_APP; |
| 47 ShelfID id = model_->next_id(); | 50 ShelfID id = model_->next_id(); |
| 48 item.status = status; | 51 item.status = status; |
| 49 model_->Add(item); | 52 model_->Add(item); |
| 50 window->AddObserver(this); | 53 window->AddObserver(this); |
| 51 | 54 |
| 52 std::unique_ptr<ShelfItemDelegate> delegate( | 55 std::unique_ptr<ShelfItemDelegate> delegate( |
| 53 new TestShelfItemDelegate(window)); | 56 new TestShelfItemDelegate(window)); |
| 54 model_->SetShelfItemDelegate(id, std::move(delegate)); | 57 model_->SetShelfItemDelegate(id, std::move(delegate)); |
| 55 SetShelfIDForWindow(id, window); | 58 WmWindowAura::Get(window)->SetIntProperty(WmWindowProperty::SHELF_ID, id); |
| 56 } | 59 } |
| 57 | 60 |
| 58 void TestShelfDelegate::RemoveShelfItemForWindow(aura::Window* window) { | 61 void TestShelfDelegate::RemoveShelfItemForWindow(aura::Window* window) { |
| 59 ShelfID shelf_id = GetShelfIDForWindow(window); | 62 WmWindow* wm_window = WmWindowAura::Get(window); |
| 63 ShelfID shelf_id = wm_window->GetIntProperty(WmWindowProperty::SHELF_ID); |
| 60 if (shelf_id == 0) | 64 if (shelf_id == 0) |
| 61 return; | 65 return; |
| 62 int index = model_->ItemIndexByID(shelf_id); | 66 int index = model_->ItemIndexByID(shelf_id); |
| 63 DCHECK_NE(-1, index); | 67 DCHECK_NE(-1, index); |
| 64 model_->RemoveItemAt(index); | 68 model_->RemoveItemAt(index); |
| 65 window->RemoveObserver(this); | 69 window->RemoveObserver(this); |
| 66 if (HasShelfIDToAppIDMapping(shelf_id)) { | 70 if (HasShelfIDToAppIDMapping(shelf_id)) { |
| 67 const std::string& app_id = GetAppIDForShelfID(shelf_id); | 71 const std::string& app_id = GetAppIDForShelfID(shelf_id); |
| 68 if (IsAppPinned(app_id)) | 72 if (IsAppPinned(app_id)) |
| 69 UnpinAppWithID(app_id); | 73 UnpinAppWithID(app_id); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 const std::string& app_id) { | 140 const std::string& app_id) { |
| 137 shelf_id_to_app_id_map_[shelf_id] = app_id; | 141 shelf_id_to_app_id_map_[shelf_id] = app_id; |
| 138 } | 142 } |
| 139 | 143 |
| 140 void TestShelfDelegate::RemoveShelfIDToAppIDMapping(ShelfID shelf_id) { | 144 void TestShelfDelegate::RemoveShelfIDToAppIDMapping(ShelfID shelf_id) { |
| 141 shelf_id_to_app_id_map_.erase(shelf_id); | 145 shelf_id_to_app_id_map_.erase(shelf_id); |
| 142 } | 146 } |
| 143 | 147 |
| 144 } // namespace test | 148 } // namespace test |
| 145 } // namespace ash | 149 } // namespace ash |
| OLD | NEW |