Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/ui/ash/launcher/app_window_launcher_controller.h" | 5 #include "chrome/browser/ui/ash/launcher/app_window_launcher_controller.h" |
| 6 | 6 |
| 7 #include "ash/shelf/shelf_util.h" | 7 #include "ash/shelf/shelf_util.h" |
| 8 #include "ash/shell.h" | 8 #include "ash/shell.h" |
| 9 #include "ash/wm/window_util.h" | 9 #include "ash/wm/window_util.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 144 window_to_app_shelf_id_map_[window] = app_shelf_id; | 144 window_to_app_shelf_id_map_[window] = app_shelf_id; |
| 145 window->AddObserver(this); | 145 window->AddObserver(this); |
| 146 | 146 |
| 147 // Find or create an item controller and launcher item. | 147 // Find or create an item controller and launcher item. |
| 148 std::string app_id = app_window->extension_id(); | 148 std::string app_id = app_window->extension_id(); |
| 149 ash::ShelfItemStatus status = ash::wm::IsActiveWindow(window) | 149 ash::ShelfItemStatus status = ash::wm::IsActiveWindow(window) |
| 150 ? ash::STATUS_ACTIVE | 150 ? ash::STATUS_ACTIVE |
| 151 : ash::STATUS_RUNNING; | 151 : ash::STATUS_RUNNING; |
| 152 AppControllerMap::iterator iter = app_controller_map_.find(app_shelf_id); | 152 AppControllerMap::iterator iter = app_controller_map_.find(app_shelf_id); |
| 153 ash::ShelfID shelf_id = 0; | 153 ash::ShelfID shelf_id = 0; |
| 154 if (iter != app_controller_map_.end()) { | 154 |
| 155 if (!app_window->show_in_shelf() && iter != app_controller_map_.end()) { | |
| 155 AppWindowLauncherItemController* controller = iter->second; | 156 AppWindowLauncherItemController* controller = iter->second; |
| 156 DCHECK(controller->app_id() == app_id); | 157 DCHECK(controller->app_id() == app_id); |
| 157 shelf_id = controller->shelf_id(); | 158 shelf_id = controller->shelf_id(); |
| 158 controller->AddAppWindow(app_window, status); | 159 controller->AddAppWindow(app_window, status); |
| 159 } else { | 160 } else { |
| 160 LauncherItemController::Type type = | 161 LauncherItemController::Type type = |
| 161 app_window->window_type_is_panel() | 162 app_window->window_type_is_panel() |
| 162 ? LauncherItemController::TYPE_APP_PANEL | 163 ? LauncherItemController::TYPE_APP_PANEL |
| 163 : LauncherItemController::TYPE_APP; | 164 : LauncherItemController::TYPE_APP; |
| 164 AppWindowLauncherItemController* controller = | 165 AppWindowLauncherItemController* controller = |
| 165 new AppWindowLauncherItemController(type, app_shelf_id, app_id, owner_); | 166 new AppWindowLauncherItemController(type, app_shelf_id, app_id, owner_); |
| 166 controller->AddAppWindow(app_window, status); | 167 controller->AddAppWindow(app_window, status); |
| 167 // If the app shelf id is not unique, and there is already a shelf | 168 // If the app shelf id is not unique, and there is already a shelf |
| 168 // item for this app id (e.g. pinned), use that shelf item. | 169 // item for this app id (e.g. pinned), use that shelf item, except for the |
| 170 // case when the showInShelf parameter is true. | |
| 169 if (app_shelf_id == app_id) | 171 if (app_shelf_id == app_id) |
| 170 shelf_id = owner_->GetShelfIDForAppID(app_id); | 172 shelf_id = owner_->GetShelfIDForAppID(app_id); |
| 171 if (shelf_id == 0) { | 173 if (shelf_id == 0 || app_window->show_in_shelf()) { |
|
stevenjb
2016/03/17 23:36:15
I think this logic would be more clear in the if s
| |
| 172 shelf_id = owner_->CreateAppLauncherItem(controller, app_id, status); | 174 shelf_id = owner_->CreateAppLauncherItem(controller, app_id, status); |
| 173 // Restore any existing app icon and flag as set. | 175 // Restore any existing app icon and flag as set. |
| 174 const gfx::Image& app_icon = app_window->app_icon(); | 176 const gfx::Image& app_icon = app_window->app_icon(); |
| 175 if (!app_icon.IsEmpty()) { | 177 if (!app_icon.IsEmpty()) { |
| 176 owner_->SetLauncherItemImage(shelf_id, app_icon.AsImageSkia()); | 178 owner_->SetLauncherItemImage(shelf_id, app_icon.AsImageSkia()); |
| 177 controller->set_image_set_by_controller(true); | 179 controller->set_image_set_by_controller(true); |
| 178 } | 180 } |
| 179 } else { | 181 } else { |
| 180 owner_->SetItemController(shelf_id, controller); | 182 owner_->SetItemController(shelf_id, controller); |
| 181 } | 183 } |
| 182 const std::string app_shelf_id = GetAppShelfId(app_window); | 184 // We only need to change the controller associated with the app if the |
| 183 app_controller_map_[app_shelf_id] = controller; | 185 // showInShelf parameter is false. |
|
stevenjb
2016/03/17 23:36:15
Is this true? What if the first window created for
| |
| 186 if (!app_window->show_in_shelf()) { | |
| 187 const std::string app_shelf_id = GetAppShelfId(app_window); | |
| 188 app_controller_map_[app_shelf_id] = controller; | |
| 189 } | |
| 184 } | 190 } |
| 185 owner_->SetItemStatus(shelf_id, status); | 191 owner_->SetItemStatus(shelf_id, status); |
| 186 ash::SetShelfIDForWindow(shelf_id, window); | 192 ash::SetShelfIDForWindow(shelf_id, window); |
| 187 } | 193 } |
| 188 | 194 |
| 189 void AppWindowLauncherController::UnregisterApp(aura::Window* window) { | 195 void AppWindowLauncherController::UnregisterApp(aura::Window* window) { |
| 190 WindowToAppShelfIdMap::iterator iter1 = | 196 WindowToAppShelfIdMap::iterator iter1 = |
| 191 window_to_app_shelf_id_map_.find(window); | 197 window_to_app_shelf_id_map_.find(window); |
| 192 DCHECK(iter1 != window_to_app_shelf_id_map_.end()); | 198 DCHECK(iter1 != window_to_app_shelf_id_map_.end()); |
| 193 std::string app_shelf_id = iter1->second; | 199 std::string app_shelf_id = iter1->second; |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 219 WindowToAppShelfIdMap::iterator iter1 = | 225 WindowToAppShelfIdMap::iterator iter1 = |
| 220 window_to_app_shelf_id_map_.find(window); | 226 window_to_app_shelf_id_map_.find(window); |
| 221 if (iter1 == window_to_app_shelf_id_map_.end()) | 227 if (iter1 == window_to_app_shelf_id_map_.end()) |
| 222 return NULL; | 228 return NULL; |
| 223 std::string app_shelf_id = iter1->second; | 229 std::string app_shelf_id = iter1->second; |
| 224 AppControllerMap::iterator iter2 = app_controller_map_.find(app_shelf_id); | 230 AppControllerMap::iterator iter2 = app_controller_map_.find(app_shelf_id); |
| 225 if (iter2 == app_controller_map_.end()) | 231 if (iter2 == app_controller_map_.end()) |
| 226 return NULL; | 232 return NULL; |
| 227 return iter2->second; | 233 return iter2->second; |
| 228 } | 234 } |
| OLD | NEW |