| 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" | 15 #include "ash/common/wm_window_property.h" |
| 16 #include "ash/root_window_controller.h" | 16 #include "ash/root_window_controller.h" |
| 17 #include "base/memory/ptr_util.h" | 17 #include "base/memory/ptr_util.h" |
| 18 #include "ui/aura/window.h" |
| 18 | 19 |
| 19 namespace ash { | 20 namespace ash { |
| 20 namespace test { | 21 namespace test { |
| 21 | 22 |
| 22 TestShelfDelegate* TestShelfDelegate::instance_ = nullptr; | 23 TestShelfDelegate* TestShelfDelegate::instance_ = nullptr; |
| 23 | 24 |
| 24 // 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 |
| 25 // shelf is created, to simulate ChromeLauncherController's behavior. | 26 // shelf is created, to simulate ChromeLauncherController's behavior. |
| 26 class ShelfInitializer : public ShellObserver { | 27 class ShelfInitializer : public ShellObserver { |
| 27 public: | 28 public: |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 void TestShelfDelegate::AddShelfItem(WmWindow* window, ShelfItemStatus status) { | 69 void TestShelfDelegate::AddShelfItem(WmWindow* window, ShelfItemStatus status) { |
| 69 ShelfItem item; | 70 ShelfItem item; |
| 70 if (window->GetType() == ui::wm::WINDOW_TYPE_PANEL) | 71 if (window->GetType() == ui::wm::WINDOW_TYPE_PANEL) |
| 71 item.type = TYPE_APP_PANEL; | 72 item.type = TYPE_APP_PANEL; |
| 72 else | 73 else |
| 73 item.type = TYPE_APP; | 74 item.type = TYPE_APP; |
| 74 ShelfModel* model = WmShell::Get()->shelf_model(); | 75 ShelfModel* model = WmShell::Get()->shelf_model(); |
| 75 ShelfID id = model->next_id(); | 76 ShelfID id = model->next_id(); |
| 76 item.status = status; | 77 item.status = status; |
| 77 model->Add(item); | 78 model->Add(item); |
| 78 window->AddObserver(this); | 79 window->aura_window()->AddObserver(this); |
| 79 | 80 |
| 80 model->SetShelfItemDelegate(id, | 81 model->SetShelfItemDelegate(id, |
| 81 base::MakeUnique<TestShelfItemDelegate>(window)); | 82 base::MakeUnique<TestShelfItemDelegate>(window)); |
| 82 window->SetIntProperty(WmWindowProperty::SHELF_ID, id); | 83 window->SetIntProperty(WmWindowProperty::SHELF_ID, id); |
| 83 } | 84 } |
| 84 | 85 |
| 85 void TestShelfDelegate::RemoveShelfItemForWindow(WmWindow* window) { | 86 void TestShelfDelegate::RemoveShelfItemForWindow(WmWindow* window) { |
| 86 ShelfID shelf_id = window->GetIntProperty(WmWindowProperty::SHELF_ID); | 87 ShelfID shelf_id = window->GetIntProperty(WmWindowProperty::SHELF_ID); |
| 87 if (shelf_id == 0) | 88 if (shelf_id == 0) |
| 88 return; | 89 return; |
| 89 ShelfModel* model = WmShell::Get()->shelf_model(); | 90 ShelfModel* model = WmShell::Get()->shelf_model(); |
| 90 int index = model->ItemIndexByID(shelf_id); | 91 int index = model->ItemIndexByID(shelf_id); |
| 91 DCHECK_NE(-1, index); | 92 DCHECK_NE(-1, index); |
| 92 model->RemoveItemAt(index); | 93 model->RemoveItemAt(index); |
| 93 window->RemoveObserver(this); | 94 window->aura_window()->RemoveObserver(this); |
| 94 if (HasShelfIDToAppIDMapping(shelf_id)) { | 95 if (HasShelfIDToAppIDMapping(shelf_id)) { |
| 95 const std::string& app_id = GetAppIDForShelfID(shelf_id); | 96 const std::string& app_id = GetAppIDForShelfID(shelf_id); |
| 96 if (IsAppPinned(app_id)) | 97 if (IsAppPinned(app_id)) |
| 97 UnpinAppWithID(app_id); | 98 UnpinAppWithID(app_id); |
| 98 if (HasShelfIDToAppIDMapping(shelf_id)) | 99 if (HasShelfIDToAppIDMapping(shelf_id)) |
| 99 RemoveShelfIDToAppIDMapping(shelf_id); | 100 RemoveShelfIDToAppIDMapping(shelf_id); |
| 100 } | 101 } |
| 101 } | 102 } |
| 102 | 103 |
| 103 void TestShelfDelegate::OnWindowDestroying(WmWindow* window) { | 104 void TestShelfDelegate::OnWindowDestroying(aura::Window* window) { |
| 104 RemoveShelfItemForWindow(window); | 105 RemoveShelfItemForWindow(WmWindow::Get(window)); |
| 105 } | 106 } |
| 106 | 107 |
| 107 void TestShelfDelegate::OnWindowTreeChanging(WmWindow* window, | 108 void TestShelfDelegate::OnWindowHierarchyChanging( |
| 108 const TreeChangeParams& params) { | 109 const HierarchyChangeParams& params) { |
| 109 // The window may be legitimately reparented while staying open if it moves | 110 // The window may be legitimately reparented while staying open if it moves |
| 110 // to another display or container. If the window does not have a new parent | 111 // to another display or container. If the window does not have a new parent |
| 111 // then remove the shelf item. | 112 // then remove the shelf item. |
| 112 if (!params.new_parent) | 113 if (!params.new_parent) |
| 113 RemoveShelfItemForWindow(params.target); | 114 RemoveShelfItemForWindow(WmWindow::Get(params.target)); |
| 114 } | 115 } |
| 115 | 116 |
| 116 ShelfID TestShelfDelegate::GetShelfIDForAppID(const std::string& app_id) { | 117 ShelfID TestShelfDelegate::GetShelfIDForAppID(const std::string& app_id) { |
| 117 for (auto const& iter : shelf_id_to_app_id_map_) { | 118 for (auto const& iter : shelf_id_to_app_id_map_) { |
| 118 if (iter.second == app_id) | 119 if (iter.second == app_id) |
| 119 return iter.first; | 120 return iter.first; |
| 120 } | 121 } |
| 121 return 0; | 122 return 0; |
| 122 } | 123 } |
| 123 | 124 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 152 const std::string& app_id) { | 153 const std::string& app_id) { |
| 153 shelf_id_to_app_id_map_[shelf_id] = app_id; | 154 shelf_id_to_app_id_map_[shelf_id] = app_id; |
| 154 } | 155 } |
| 155 | 156 |
| 156 void TestShelfDelegate::RemoveShelfIDToAppIDMapping(ShelfID shelf_id) { | 157 void TestShelfDelegate::RemoveShelfIDToAppIDMapping(ShelfID shelf_id) { |
| 157 shelf_id_to_app_id_map_.erase(shelf_id); | 158 shelf_id_to_app_id_map_.erase(shelf_id); |
| 158 } | 159 } |
| 159 | 160 |
| 160 } // namespace test | 161 } // namespace test |
| 161 } // namespace ash | 162 } // namespace ash |
| OLD | NEW |