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

Side by Side Diff: ash/sysui/shelf_delegate_mus.cc

Issue 2171813004: mash: Fold ShelfItemDelegateManager into ShelfModel (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: explicitly destroy ShelfItemDelegates Created 4 years, 5 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 unified diff | Download patch
« no previous file with comments | « ash/shell/window_watcher.cc ('k') | ash/test/shelf_item_delegate_manager_test_api.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/sysui/shelf_delegate_mus.h" 5 #include "ash/sysui/shelf_delegate_mus.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "ash/common/shelf/shelf_item_delegate.h" 9 #include "ash/common/shelf/shelf_item_delegate.h"
10 #include "ash/common/shelf/shelf_item_delegate_manager.h"
11 #include "ash/common/shelf/shelf_menu_model.h" 10 #include "ash/common/shelf/shelf_menu_model.h"
12 #include "ash/common/shelf/shelf_model.h" 11 #include "ash/common/shelf/shelf_model.h"
13 #include "ash/common/shelf/shelf_types.h" 12 #include "ash/common/shelf/shelf_types.h"
13 #include "ash/common/wm_shell.h"
14 #include "ash/shelf/shelf.h" 14 #include "ash/shelf/shelf.h"
15 #include "ash/shelf/shelf_layout_manager.h" 15 #include "ash/shelf/shelf_layout_manager.h"
16 #include "ash/shelf/shelf_widget.h" 16 #include "ash/shelf/shelf_widget.h"
17 #include "ash/shell.h"
18 #include "base/strings/string_util.h" 17 #include "base/strings/string_util.h"
19 #include "mojo/common/common_type_converters.h" 18 #include "mojo/common/common_type_converters.h"
20 #include "services/shell/public/cpp/connector.h" 19 #include "services/shell/public/cpp/connector.h"
21 #include "services/ui/public/cpp/property_type_converters.h" 20 #include "services/ui/public/cpp/property_type_converters.h"
22 #include "services/ui/public/cpp/window.h" 21 #include "services/ui/public/cpp/window.h"
23 #include "services/ui/public/cpp/window_property.h" 22 #include "services/ui/public/cpp/window_property.h"
24 #include "ui/aura/mus/mus_util.h" 23 #include "ui/aura/mus/mus_util.h"
25 #include "ui/base/resource/resource_bundle.h" 24 #include "ui/base/resource/resource_bundle.h"
26 #include "ui/gfx/image/image_skia.h" 25 #include "ui/gfx/image/image_skia.h"
27 #include "ui/resources/grit/ui_resources.h" 26 #include "ui/resources/grit/ui_resources.h"
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 bool pinned_ = false; 145 bool pinned_ = false;
147 std::map<uint32_t, base::string16> window_id_to_title_; 146 std::map<uint32_t, base::string16> window_id_to_title_;
148 base::string16 title_; 147 base::string16 title_;
149 UserWindowController* user_window_controller_; 148 UserWindowController* user_window_controller_;
150 149
151 DISALLOW_COPY_AND_ASSIGN(ShelfItemDelegateMus); 150 DISALLOW_COPY_AND_ASSIGN(ShelfItemDelegateMus);
152 }; 151 };
153 152
154 ShelfItemDelegateMus* GetShelfItemDelegate(ShelfID shelf_id) { 153 ShelfItemDelegateMus* GetShelfItemDelegate(ShelfID shelf_id) {
155 return static_cast<ShelfItemDelegateMus*>( 154 return static_cast<ShelfItemDelegateMus*>(
156 Shell::GetInstance()->shelf_item_delegate_manager()->GetShelfItemDelegate( 155 WmShell::Get()->shelf_model()->GetShelfItemDelegate(shelf_id));
157 shelf_id));
158 } 156 }
159 157
160 // Returns an icon image from an SkBitmap, or the default shelf icon 158 // Returns an icon image from an SkBitmap, or the default shelf icon
161 // image if the bitmap is empty. Assumes the bitmap is a 1x icon. 159 // image if the bitmap is empty. Assumes the bitmap is a 1x icon.
162 // TODO(jamescook): Support other scale factors. 160 // TODO(jamescook): Support other scale factors.
163 gfx::ImageSkia GetShelfIconFromBitmap(const SkBitmap& bitmap) { 161 gfx::ImageSkia GetShelfIconFromBitmap(const SkBitmap& bitmap) {
164 gfx::ImageSkia icon_image; 162 gfx::ImageSkia icon_image;
165 if (!bitmap.isNull()) { 163 if (!bitmap.isNull()) {
166 icon_image = gfx::ImageSkia::CreateFrom1xBitmap(bitmap); 164 icon_image = gfx::ImageSkia::CreateFrom1xBitmap(bitmap);
167 } else { 165 } else {
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 shelf_item.type = TYPE_APP_SHORTCUT; 313 shelf_item.type = TYPE_APP_SHORTCUT;
316 shelf_item.status = STATUS_CLOSED; 314 shelf_item.status = STATUS_CLOSED;
317 shelf_item.image = GetShelfIconFromBitmap(item->image); 315 shelf_item.image = GetShelfIconFromBitmap(item->image);
318 model_->Add(shelf_item); 316 model_->Add(shelf_item);
319 317
320 std::unique_ptr<ShelfItemDelegateMus> item_delegate( 318 std::unique_ptr<ShelfItemDelegateMus> item_delegate(
321 new ShelfItemDelegateMus(user_window_controller_.get())); 319 new ShelfItemDelegateMus(user_window_controller_.get()));
322 item_delegate->SetDelegate(std::move(delegate)); 320 item_delegate->SetDelegate(std::move(delegate));
323 item_delegate->set_pinned(true); 321 item_delegate->set_pinned(true);
324 item_delegate->set_title(item->app_title.To<base::string16>()); 322 item_delegate->set_title(item->app_title.To<base::string16>());
325 Shell::GetInstance()->shelf_item_delegate_manager()->SetShelfItemDelegate( 323 model_->SetShelfItemDelegate(shelf_id, std::move(item_delegate));
326 shelf_id, std::move(item_delegate));
327 } 324 }
328 325
329 void ShelfDelegateMus::UnpinItem(const mojo::String& app_id) { 326 void ShelfDelegateMus::UnpinItem(const mojo::String& app_id) {
330 if (!app_id_to_shelf_id_.count(app_id.To<std::string>())) 327 if (!app_id_to_shelf_id_.count(app_id.To<std::string>()))
331 return; 328 return;
332 ShelfID shelf_id = app_id_to_shelf_id_[app_id.To<std::string>()]; 329 ShelfID shelf_id = app_id_to_shelf_id_[app_id.To<std::string>()];
333 ShelfItemDelegateMus* item_delegate = GetShelfItemDelegate(shelf_id); 330 ShelfItemDelegateMus* item_delegate = GetShelfItemDelegate(shelf_id);
334 DCHECK(item_delegate->pinned()); 331 DCHECK(item_delegate->pinned());
335 item_delegate->set_pinned(false); 332 item_delegate->set_pinned(false);
336 if (item_delegate->window_id_to_title().empty()) { 333 if (item_delegate->window_id_to_title().empty()) {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 ShelfItem item; 383 ShelfItem item;
387 item.type = TYPE_PLATFORM_APP; 384 item.type = TYPE_PLATFORM_APP;
388 item.status = user_window->window_has_focus ? STATUS_ACTIVE : STATUS_RUNNING; 385 item.status = user_window->window_has_focus ? STATUS_ACTIVE : STATUS_RUNNING;
389 item.image = GetShelfIconFromSerializedBitmap(user_window->window_app_icon); 386 item.image = GetShelfIconFromSerializedBitmap(user_window->window_app_icon);
390 model_->Add(item); 387 model_->Add(item);
391 388
392 std::unique_ptr<ShelfItemDelegateMus> item_delegate( 389 std::unique_ptr<ShelfItemDelegateMus> item_delegate(
393 new ShelfItemDelegateMus(user_window_controller_.get())); 390 new ShelfItemDelegateMus(user_window_controller_.get()));
394 item_delegate->AddWindow(user_window->window_id, 391 item_delegate->AddWindow(user_window->window_id,
395 user_window->window_title.To<base::string16>()); 392 user_window->window_title.To<base::string16>());
396 Shell::GetInstance()->shelf_item_delegate_manager()->SetShelfItemDelegate( 393 model_->SetShelfItemDelegate(shelf_id, std::move(item_delegate));
397 shelf_id, std::move(item_delegate));
398 } 394 }
399 395
400 void ShelfDelegateMus::OnUserWindowRemoved(uint32_t window_id) { 396 void ShelfDelegateMus::OnUserWindowRemoved(uint32_t window_id) {
401 if (!window_id_to_shelf_id_.count(window_id)) 397 if (!window_id_to_shelf_id_.count(window_id))
402 return; 398 return;
403 ShelfID shelf_id = window_id_to_shelf_id_[window_id]; 399 ShelfID shelf_id = window_id_to_shelf_id_[window_id];
404 ShelfItemDelegateMus* item_delegate = GetShelfItemDelegate(shelf_id); 400 ShelfItemDelegateMus* item_delegate = GetShelfItemDelegate(shelf_id);
405 item_delegate->RemoveWindow(window_id); 401 item_delegate->RemoveWindow(window_id);
406 window_id_to_shelf_id_.erase(window_id); 402 window_id_to_shelf_id_.erase(window_id);
407 if (item_delegate->window_id_to_title().empty() && !item_delegate->pinned()) { 403 if (item_delegate->window_id_to_title().empty() && !item_delegate->pinned()) {
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 StatusAreaWidget* status_widget = widget->status_area_widget(); 469 StatusAreaWidget* status_widget = widget->status_area_widget();
474 ui::Window* status_window = 470 ui::Window* status_window =
475 aura::GetMusWindow(status_widget->GetNativeWindow()); 471 aura::GetMusWindow(status_widget->GetNativeWindow());
476 gfx::Size status_size = status_widget->GetWindowBoundsInScreen().size(); 472 gfx::Size status_size = status_widget->GetWindowBoundsInScreen().size();
477 status_window->SetSharedProperty<gfx::Size>( 473 status_window->SetSharedProperty<gfx::Size>(
478 ui::mojom::WindowManager::kPreferredSize_Property, status_size); 474 ui::mojom::WindowManager::kPreferredSize_Property, status_size);
479 } 475 }
480 476
481 } // namespace sysui 477 } // namespace sysui
482 } // namespace ash 478 } // namespace ash
OLDNEW
« no previous file with comments | « ash/shell/window_watcher.cc ('k') | ash/test/shelf_item_delegate_manager_test_api.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698