| 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/common/test/test_shelf_delegate.h" | 5 #include "ash/common/test/test_shelf_delegate.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "ash/common/shelf/shelf_model.h" | 9 #include "ash/common/shelf/shelf_model.h" |
| 10 #include "ash/common/shelf/wm_shelf.h" | 10 #include "ash/common/shelf/wm_shelf.h" |
| 11 #include "ash/common/shell_observer.h" | 11 #include "ash/common/shell_observer.h" |
| 12 #include "ash/common/test/test_shelf_item_delegate.h" | 12 #include "ash/common/test/test_shelf_item_delegate.h" |
| 13 #include "ash/common/wm_shell.h" | 13 #include "ash/common/wm_shell.h" |
| 14 #include "ash/common/wm_window.h" | 14 #include "ash/common/wm_window.h" |
| 15 #include "ash/common/wm_window_property.h" | |
| 16 #include "ash/root_window_controller.h" | 15 #include "ash/root_window_controller.h" |
| 16 #include "ash/wm/window_properties.h" |
| 17 #include "base/memory/ptr_util.h" | 17 #include "base/memory/ptr_util.h" |
| 18 #include "ui/aura/window.h" | 18 #include "ui/aura/window.h" |
| 19 | 19 |
| 20 namespace ash { | 20 namespace ash { |
| 21 namespace test { | 21 namespace test { |
| 22 | 22 |
| 23 TestShelfDelegate* TestShelfDelegate::instance_ = nullptr; | 23 TestShelfDelegate* TestShelfDelegate::instance_ = nullptr; |
| 24 | 24 |
| 25 // A ShellObserver that sets the shelf alignment and auto hide behavior when the | 25 // A ShellObserver that sets the shelf alignment and auto hide behavior when the |
| 26 // shelf is created, to simulate ChromeLauncherController's behavior. | 26 // shelf is created, to simulate ChromeLauncherController's behavior. |
| (...skipping 28 matching lines...) Expand all Loading... |
| 55 instance_ = nullptr; | 55 instance_ = nullptr; |
| 56 } | 56 } |
| 57 | 57 |
| 58 void TestShelfDelegate::AddShelfItem(WmWindow* window) { | 58 void TestShelfDelegate::AddShelfItem(WmWindow* window) { |
| 59 AddShelfItem(window, STATUS_CLOSED); | 59 AddShelfItem(window, STATUS_CLOSED); |
| 60 } | 60 } |
| 61 | 61 |
| 62 void TestShelfDelegate::AddShelfItem(WmWindow* window, | 62 void TestShelfDelegate::AddShelfItem(WmWindow* window, |
| 63 const std::string& app_id) { | 63 const std::string& app_id) { |
| 64 AddShelfItem(window, STATUS_CLOSED); | 64 AddShelfItem(window, STATUS_CLOSED); |
| 65 ShelfID shelf_id = window->GetIntProperty(WmWindowProperty::SHELF_ID); | 65 ShelfID shelf_id = window->aura_window()->GetProperty(kShelfIDKey); |
| 66 AddShelfIDToAppIDMapping(shelf_id, app_id); | 66 AddShelfIDToAppIDMapping(shelf_id, app_id); |
| 67 } | 67 } |
| 68 | 68 |
| 69 void TestShelfDelegate::AddShelfItem(WmWindow* window, ShelfItemStatus status) { | 69 void TestShelfDelegate::AddShelfItem(WmWindow* window, ShelfItemStatus status) { |
| 70 ShelfItem item; | 70 ShelfItem item; |
| 71 if (window->GetType() == ui::wm::WINDOW_TYPE_PANEL) | 71 if (window->GetType() == ui::wm::WINDOW_TYPE_PANEL) |
| 72 item.type = TYPE_APP_PANEL; | 72 item.type = TYPE_APP_PANEL; |
| 73 else | 73 else |
| 74 item.type = TYPE_APP; | 74 item.type = TYPE_APP; |
| 75 ShelfModel* model = WmShell::Get()->shelf_model(); | 75 ShelfModel* model = WmShell::Get()->shelf_model(); |
| 76 ShelfID id = model->next_id(); | 76 ShelfID id = model->next_id(); |
| 77 item.status = status; | 77 item.status = status; |
| 78 model->Add(item); | 78 model->Add(item); |
| 79 window->aura_window()->AddObserver(this); | 79 window->aura_window()->AddObserver(this); |
| 80 | 80 |
| 81 model->SetShelfItemDelegate(id, | 81 model->SetShelfItemDelegate(id, |
| 82 base::MakeUnique<TestShelfItemDelegate>(window)); | 82 base::MakeUnique<TestShelfItemDelegate>(window)); |
| 83 window->SetIntProperty(WmWindowProperty::SHELF_ID, id); | 83 window->aura_window()->SetProperty(kShelfIDKey, id); |
| 84 } | 84 } |
| 85 | 85 |
| 86 void TestShelfDelegate::RemoveShelfItemForWindow(WmWindow* window) { | 86 void TestShelfDelegate::RemoveShelfItemForWindow(WmWindow* window) { |
| 87 ShelfID shelf_id = window->GetIntProperty(WmWindowProperty::SHELF_ID); | 87 ShelfID shelf_id = window->aura_window()->GetProperty(kShelfIDKey); |
| 88 if (shelf_id == 0) | 88 if (shelf_id == 0) |
| 89 return; | 89 return; |
| 90 ShelfModel* model = WmShell::Get()->shelf_model(); | 90 ShelfModel* model = WmShell::Get()->shelf_model(); |
| 91 int index = model->ItemIndexByID(shelf_id); | 91 int index = model->ItemIndexByID(shelf_id); |
| 92 DCHECK_NE(-1, index); | 92 DCHECK_NE(-1, index); |
| 93 model->RemoveItemAt(index); | 93 model->RemoveItemAt(index); |
| 94 window->aura_window()->RemoveObserver(this); | 94 window->aura_window()->RemoveObserver(this); |
| 95 if (HasShelfIDToAppIDMapping(shelf_id)) { | 95 if (HasShelfIDToAppIDMapping(shelf_id)) { |
| 96 const std::string& app_id = GetAppIDForShelfID(shelf_id); | 96 const std::string& app_id = GetAppIDForShelfID(shelf_id); |
| 97 if (IsAppPinned(app_id)) | 97 if (IsAppPinned(app_id)) |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 const std::string& app_id) { | 153 const std::string& app_id) { |
| 154 shelf_id_to_app_id_map_[shelf_id] = app_id; | 154 shelf_id_to_app_id_map_[shelf_id] = app_id; |
| 155 } | 155 } |
| 156 | 156 |
| 157 void TestShelfDelegate::RemoveShelfIDToAppIDMapping(ShelfID shelf_id) { | 157 void TestShelfDelegate::RemoveShelfIDToAppIDMapping(ShelfID shelf_id) { |
| 158 shelf_id_to_app_id_map_.erase(shelf_id); | 158 shelf_id_to_app_id_map_.erase(shelf_id); |
| 159 } | 159 } |
| 160 | 160 |
| 161 } // namespace test | 161 } // namespace test |
| 162 } // namespace ash | 162 } // namespace ash |
| OLD | NEW |