| OLD | NEW |
| 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/mus/shelf_delegate_mus.h" | 5 #include "ash/mus/shelf_delegate_mus.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "ash/shelf/shelf.h" | 9 #include "ash/shelf/shelf.h" |
| 10 #include "ash/shelf/shelf_item_delegate.h" | 10 #include "ash/shelf/shelf_item_delegate.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 | 35 |
| 36 namespace { | 36 namespace { |
| 37 | 37 |
| 38 // A ShelfItemDelegate used for pinned items and open user windows. | 38 // A ShelfItemDelegate used for pinned items and open user windows. |
| 39 class ShelfItemDelegateMus : public ShelfItemDelegate { | 39 class ShelfItemDelegateMus : public ShelfItemDelegate { |
| 40 public: | 40 public: |
| 41 explicit ShelfItemDelegateMus(UserWindowController* user_window_controller) | 41 explicit ShelfItemDelegateMus(UserWindowController* user_window_controller) |
| 42 : user_window_controller_(user_window_controller) {} | 42 : user_window_controller_(user_window_controller) {} |
| 43 ~ShelfItemDelegateMus() override {} | 43 ~ShelfItemDelegateMus() override {} |
| 44 | 44 |
| 45 void SetDelegate( |
| 46 mash::shelf::mojom::ShelfItemDelegateAssociatedPtrInfo delegate) { |
| 47 delegate_.Bind(std::move(delegate)); |
| 48 } |
| 49 |
| 45 bool pinned() const { return pinned_; } | 50 bool pinned() const { return pinned_; } |
| 46 void set_pinned(bool pinned) { pinned_ = pinned; } | 51 void set_pinned(bool pinned) { pinned_ = pinned; } |
| 47 | 52 |
| 48 void AddWindow(uint32_t id, const base::string16& title) { | 53 void AddWindow(uint32_t id, const base::string16& title) { |
| 49 DCHECK(!window_id_to_title_.count(id)); | 54 DCHECK(!window_id_to_title_.count(id)); |
| 50 window_id_to_title_.insert(std::make_pair(id, title)); | 55 window_id_to_title_.insert(std::make_pair(id, title)); |
| 51 } | 56 } |
| 52 void RemoveWindow(uint32_t id) { window_id_to_title_.erase(id); } | 57 void RemoveWindow(uint32_t id) { window_id_to_title_.erase(id); } |
| 53 void SetWindowTitle(uint32_t id, const base::string16& title) { | 58 void SetWindowTitle(uint32_t id, const base::string16& title) { |
| 54 DCHECK(window_id_to_title_.count(id)); | 59 DCHECK(window_id_to_title_.count(id)); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 | 100 |
| 96 private: | 101 private: |
| 97 ShelfItemDelegateMus* item_delegate_; | 102 ShelfItemDelegateMus* item_delegate_; |
| 98 | 103 |
| 99 DISALLOW_COPY_AND_ASSIGN(ShelfMenuModelMus); | 104 DISALLOW_COPY_AND_ASSIGN(ShelfMenuModelMus); |
| 100 }; | 105 }; |
| 101 | 106 |
| 102 // ShelfItemDelegate: | 107 // ShelfItemDelegate: |
| 103 ShelfItemDelegate::PerformedAction ItemSelected( | 108 ShelfItemDelegate::PerformedAction ItemSelected( |
| 104 const ui::Event& event) override { | 109 const ui::Event& event) override { |
| 110 if (window_id_to_title_.empty()) { |
| 111 delegate_->LaunchItem(); |
| 112 return kNewWindowCreated; |
| 113 } |
| 105 if (window_id_to_title_.size() == 1) { | 114 if (window_id_to_title_.size() == 1) { |
| 106 user_window_controller_->FocusUserWindow( | 115 user_window_controller_->FocusUserWindow( |
| 107 window_id_to_title_.begin()->first); | 116 window_id_to_title_.begin()->first); |
| 108 return kExistingWindowActivated; | 117 return kExistingWindowActivated; |
| 109 } | 118 } |
| 110 return kNoAction; | 119 return kNoAction; |
| 111 } | 120 } |
| 112 | 121 |
| 113 base::string16 GetTitle() override { | 122 base::string16 GetTitle() override { |
| 114 return window_id_to_title_.empty() ? title_ | 123 return window_id_to_title_.empty() ? title_ |
| (...skipping 11 matching lines...) Expand all Loading... |
| 126 | 135 |
| 127 bool IsDraggable() override { | 136 bool IsDraggable() override { |
| 128 NOTIMPLEMENTED(); | 137 NOTIMPLEMENTED(); |
| 129 return false; | 138 return false; |
| 130 } | 139 } |
| 131 | 140 |
| 132 bool ShouldShowTooltip() override { return true; } | 141 bool ShouldShowTooltip() override { return true; } |
| 133 | 142 |
| 134 void Close() override { NOTIMPLEMENTED(); } | 143 void Close() override { NOTIMPLEMENTED(); } |
| 135 | 144 |
| 145 mash::shelf::mojom::ShelfItemDelegateAssociatedPtr delegate_; |
| 136 bool pinned_ = false; | 146 bool pinned_ = false; |
| 137 std::map<uint32_t, base::string16> window_id_to_title_; | 147 std::map<uint32_t, base::string16> window_id_to_title_; |
| 138 base::string16 title_; | 148 base::string16 title_; |
| 139 UserWindowController* user_window_controller_; | 149 UserWindowController* user_window_controller_; |
| 140 | 150 |
| 141 DISALLOW_COPY_AND_ASSIGN(ShelfItemDelegateMus); | 151 DISALLOW_COPY_AND_ASSIGN(ShelfItemDelegateMus); |
| 142 }; | 152 }; |
| 143 | 153 |
| 144 ShelfItemDelegateMus* GetShelfItemDelegate(ShelfID shelf_id) { | 154 ShelfItemDelegateMus* GetShelfItemDelegate(ShelfID shelf_id) { |
| 145 return static_cast<ShelfItemDelegateMus*>( | 155 return static_cast<ShelfItemDelegateMus*>( |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 Shell::GetPrimaryRootWindow()); | 280 Shell::GetPrimaryRootWindow()); |
| 271 } | 281 } |
| 272 | 282 |
| 273 void ShelfDelegateMus::PinItem( | 283 void ShelfDelegateMus::PinItem( |
| 274 mash::shelf::mojom::ShelfItemPtr item, | 284 mash::shelf::mojom::ShelfItemPtr item, |
| 275 mash::shelf::mojom::ShelfItemDelegateAssociatedPtrInfo delegate) { | 285 mash::shelf::mojom::ShelfItemDelegateAssociatedPtrInfo delegate) { |
| 276 std::string app_id(item->app_id.To<std::string>()); | 286 std::string app_id(item->app_id.To<std::string>()); |
| 277 if (app_id_to_shelf_id_.count(app_id)) { | 287 if (app_id_to_shelf_id_.count(app_id)) { |
| 278 ShelfID shelf_id = app_id_to_shelf_id_[app_id]; | 288 ShelfID shelf_id = app_id_to_shelf_id_[app_id]; |
| 279 ShelfItemDelegateMus* item_delegate = GetShelfItemDelegate(shelf_id); | 289 ShelfItemDelegateMus* item_delegate = GetShelfItemDelegate(shelf_id); |
| 290 item_delegate->SetDelegate(std::move(delegate)); |
| 280 item_delegate->set_pinned(true); | 291 item_delegate->set_pinned(true); |
| 281 return; | 292 return; |
| 282 } | 293 } |
| 283 | 294 |
| 284 ShelfID shelf_id = model_->next_id(); | 295 ShelfID shelf_id = model_->next_id(); |
| 285 app_id_to_shelf_id_.insert(std::make_pair(app_id, shelf_id)); | 296 app_id_to_shelf_id_.insert(std::make_pair(app_id, shelf_id)); |
| 286 shelf_id_to_app_id_.insert(std::make_pair(shelf_id, app_id)); | 297 shelf_id_to_app_id_.insert(std::make_pair(shelf_id, app_id)); |
| 287 | 298 |
| 288 ShelfItem shelf_item; | 299 ShelfItem shelf_item; |
| 289 shelf_item.type = TYPE_APP_SHORTCUT; | 300 shelf_item.type = TYPE_APP_SHORTCUT; |
| 290 shelf_item.status = STATUS_CLOSED; | 301 shelf_item.status = STATUS_CLOSED; |
| 291 shelf_item.image = GetShelfIconFromBitmap(item->image.To<SkBitmap>()); | 302 shelf_item.image = GetShelfIconFromBitmap(item->image.To<SkBitmap>()); |
| 292 model_->Add(shelf_item); | 303 model_->Add(shelf_item); |
| 293 | 304 |
| 294 std::unique_ptr<ShelfItemDelegateMus> item_delegate( | 305 std::unique_ptr<ShelfItemDelegateMus> item_delegate( |
| 295 new ShelfItemDelegateMus(user_window_controller_.get())); | 306 new ShelfItemDelegateMus(user_window_controller_.get())); |
| 307 item_delegate->SetDelegate(std::move(delegate)); |
| 296 item_delegate->set_pinned(true); | 308 item_delegate->set_pinned(true); |
| 297 item_delegate->set_title(item->app_title.To<base::string16>()); | 309 item_delegate->set_title(item->app_title.To<base::string16>()); |
| 298 Shell::GetInstance()->shelf_item_delegate_manager()->SetShelfItemDelegate( | 310 Shell::GetInstance()->shelf_item_delegate_manager()->SetShelfItemDelegate( |
| 299 shelf_id, std::move(item_delegate)); | 311 shelf_id, std::move(item_delegate)); |
| 300 } | 312 } |
| 301 | 313 |
| 302 void ShelfDelegateMus::UnpinItem(const mojo::String& app_id) { | 314 void ShelfDelegateMus::UnpinItem(const mojo::String& app_id) { |
| 303 if (!app_id_to_shelf_id_.count(app_id.To<std::string>())) | 315 if (!app_id_to_shelf_id_.count(app_id.To<std::string>())) |
| 304 return; | 316 return; |
| 305 ShelfID shelf_id = app_id_to_shelf_id_[app_id.To<std::string>()]; | 317 ShelfID shelf_id = app_id_to_shelf_id_[app_id.To<std::string>()]; |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 439 StatusAreaWidget* status_widget = widget->status_area_widget(); | 451 StatusAreaWidget* status_widget = widget->status_area_widget(); |
| 440 mus::Window* status_window = | 452 mus::Window* status_window = |
| 441 aura::GetMusWindow(status_widget->GetNativeWindow()); | 453 aura::GetMusWindow(status_widget->GetNativeWindow()); |
| 442 gfx::Size status_size = status_widget->GetWindowBoundsInScreen().size(); | 454 gfx::Size status_size = status_widget->GetWindowBoundsInScreen().size(); |
| 443 status_window->SetSharedProperty<gfx::Size>( | 455 status_window->SetSharedProperty<gfx::Size>( |
| 444 mus::mojom::WindowManager::kPreferredSize_Property, status_size); | 456 mus::mojom::WindowManager::kPreferredSize_Property, status_size); |
| 445 } | 457 } |
| 446 | 458 |
| 447 } // namespace sysui | 459 } // namespace sysui |
| 448 } // namespace ash | 460 } // namespace ash |
| OLD | NEW |