Chromium Code Reviews| Index: ash/mus/shelf_delegate_mus.cc |
| diff --git a/ash/mus/shelf_delegate_mus.cc b/ash/mus/shelf_delegate_mus.cc |
| index 7b3309114489fcfa61290c671ceff2d7729eb30a..516020499e5c852c7d7eb0ce4b3b76f52b4f87e6 100644 |
| --- a/ash/mus/shelf_delegate_mus.cc |
| +++ b/ash/mus/shelf_delegate_mus.cc |
| @@ -9,6 +9,7 @@ |
| #include "ash/shelf/shelf_item_delegate_manager.h" |
| #include "ash/shelf/shelf_layout_manager.h" |
| #include "ash/shelf/shelf_model.h" |
| +#include "ash/shelf/shelf_types.h" |
| #include "ash/shelf/shelf_widget.h" |
| #include "ash/shell.h" |
| #include "base/strings/string_util.h" |
| @@ -17,6 +18,7 @@ |
| #include "components/mus/public/cpp/window_property.h" |
| #include "mojo/common/common_type_converters.h" |
| #include "mojo/shell/public/cpp/connector.h" |
| +#include "skia/public/type_converters.h" |
| #include "ui/aura/mus/mus_util.h" |
| #include "ui/base/resource/resource_bundle.h" |
| #include "ui/gfx/image/image_skia.h" |
| @@ -30,24 +32,28 @@ namespace sysui { |
| namespace { |
| +// A ShelfItemDelegate used for pinned items and open user windows. |
| class ShelfItemDelegateMus : public ShelfItemDelegate { |
| public: |
| - ShelfItemDelegateMus(uint32_t window_id, |
| - const base::string16& title, |
| + ShelfItemDelegateMus(const base::string16& title, |
| UserWindowController* user_window_controller) |
| - : window_id_(window_id), |
| - title_(title), |
| - user_window_controller_(user_window_controller) {} |
| + : title_(title), user_window_controller_(user_window_controller) {} |
| ~ShelfItemDelegateMus() override {} |
| void UpdateTitle(const base::string16& new_title) { title_ = new_title; } |
| + void set_window_id(uint32_t window_id) { window_id_ = window_id; } |
|
sky
2016/04/07 22:02:46
Document when this changes (maybe it should DCHECK
msw
2016/04/08 21:20:48
Moved back to ctor. (this is super temporary; we n
|
| + |
| private: |
| // ShelfItemDelegate: |
| ShelfItemDelegate::PerformedAction ItemSelected( |
| const ui::Event& event) override { |
| - user_window_controller_->FocusUserWindow(window_id_); |
| - return kExistingWindowActivated; |
| + if (window_id_ != 0) { |
| + user_window_controller_->FocusUserWindow(window_id_); |
| + return kExistingWindowActivated; |
| + } |
| + NOTIMPLEMENTED(); |
| + return kNoAction; |
| } |
| base::string16 GetTitle() override { return title_; } |
| @@ -72,20 +78,17 @@ class ShelfItemDelegateMus : public ShelfItemDelegate { |
| void Close() override { NOTIMPLEMENTED(); } |
| // TODO(msw): Support multiple open windows per button. |
| - uint32_t window_id_; |
| + uint32_t window_id_ = 0; |
| base::string16 title_; |
| UserWindowController* user_window_controller_; |
| DISALLOW_COPY_AND_ASSIGN(ShelfItemDelegateMus); |
| }; |
| -// Returns an icon image from a serialized SkBitmap, or the default shelf icon |
| +// Returns an icon image from an SkBitmap, or the default shelf icon |
| // image if the bitmap is empty. Assumes the bitmap is a 1x icon. |
| // TODO(jamescook): Support other scale factors. |
| -gfx::ImageSkia GetShelfIconFromBitmap( |
| - const mojo::Array<uint8_t>& serialized_bitmap) { |
| - // Convert the data to an ImageSkia. |
| - SkBitmap bitmap = mojo::ConvertTo<SkBitmap>(serialized_bitmap.storage()); |
| +gfx::ImageSkia GetShelfIconFromBitmap(const SkBitmap& bitmap) { |
| gfx::ImageSkia icon_image; |
| if (!bitmap.isNull()) { |
| icon_image = gfx::ImageSkia::CreateFrom1xBitmap(bitmap); |
| @@ -97,6 +100,13 @@ gfx::ImageSkia GetShelfIconFromBitmap( |
| return icon_image; |
| } |
| +// Returns an icon image from a serialized SkBitmap. |
| +gfx::ImageSkia GetShelfIconFromSerializedBitmap( |
| + const mojo::Array<uint8_t>& serialized_bitmap) { |
| + SkBitmap bitmap = mojo::ConvertTo<SkBitmap>(serialized_bitmap.storage()); |
| + return GetShelfIconFromBitmap(bitmap); |
| +} |
| + |
| } // namespace |
| ShelfDelegateMus::ShelfDelegateMus(ShelfModel* model) |
| @@ -111,14 +121,14 @@ ShelfDelegateMus::ShelfDelegateMus(ShelfModel* model) |
| ShelfDelegateMus::~ShelfDelegateMus() {} |
| void ShelfDelegateMus::OnShelfCreated(Shelf* shelf) { |
| - ash::ShelfWidget* widget = shelf->shelf_widget(); |
| - ash::ShelfLayoutManager* layout_manager = widget->shelf_layout_manager(); |
| + ShelfWidget* widget = shelf->shelf_widget(); |
| + ShelfLayoutManager* layout_manager = widget->shelf_layout_manager(); |
| mus::Window* window = aura::GetMusWindow(widget->GetNativeWindow()); |
| gfx::Size size = layout_manager->GetIdealBounds().size(); |
| window->SetSharedProperty<gfx::Size>( |
| mus::mojom::WindowManager::kPreferredSize_Property, size); |
| - ash::StatusAreaWidget* status_widget = widget->status_area_widget(); |
| + StatusAreaWidget* status_widget = widget->status_area_widget(); |
| mus::Window* status_window = |
| aura::GetMusWindow(status_widget->GetNativeWindow()); |
| gfx::Size status_size = status_widget->GetWindowBoundsInScreen().size(); |
| @@ -131,11 +141,18 @@ void ShelfDelegateMus::OnShelfDestroyed(Shelf* shelf) { |
| } |
| void ShelfDelegateMus::OnShelfAlignmentChanged(Shelf* shelf) { |
| - NOTIMPLEMENTED(); |
| + observers_.ForAllPtrs([shelf](mash::shelf::mojom::ShelfObserver* observer) { |
| + observer->OnAlignmentChanged( |
| + static_cast<mash::shelf::mojom::Alignment>(shelf->GetAlignment())); |
| + }); |
| } |
| void ShelfDelegateMus::OnShelfAutoHideBehaviorChanged(Shelf* shelf) { |
| - NOTIMPLEMENTED(); |
| + observers_.ForAllPtrs([shelf](mash::shelf::mojom::ShelfObserver* observer) { |
| + observer->OnAutoHideBehaviorChanged( |
| + static_cast<mash::shelf::mojom::AutoHideBehavior>( |
| + shelf->auto_hide_behavior())); |
| + }); |
| } |
| ShelfID ShelfDelegateMus::GetShelfIDForAppID(const std::string& app_id) { |
| @@ -166,6 +183,57 @@ void ShelfDelegateMus::UnpinAppWithID(const std::string& app_id) { |
| NOTIMPLEMENTED(); |
| } |
| +void ShelfDelegateMus::AddObserver( |
| + mash::shelf::mojom::ShelfObserverAssociatedPtrInfo observer) { |
| + mash::shelf::mojom::ShelfObserverAssociatedPtr observer_ptr; |
| + observer_ptr.Bind(std::move(observer)); |
| + // Notify the observer of the current state. |
| + Shelf* shelf = Shelf::ForPrimaryDisplay(); |
|
sky
2016/04/07 22:02:46
Do we support shelfs for different displays? If we
msw
2016/04/08 21:20:48
I asked Robert "Does mash support some test way to
sky
2016/04/08 23:08:24
Mus itself supports multiple displays. But I'm fin
|
| + observer_ptr->OnAlignmentChanged( |
| + static_cast<mash::shelf::mojom::Alignment>(shelf->GetAlignment())); |
| + observer_ptr->OnAutoHideBehaviorChanged( |
| + static_cast<mash::shelf::mojom::AutoHideBehavior>( |
| + shelf->auto_hide_behavior())); |
| + observers_.AddInterfacePtr(std::move(observer_ptr)); |
| +} |
| + |
| +void ShelfDelegateMus::SetAlignment(mash::shelf::mojom::Alignment alignment) { |
| + ShelfAlignment value = static_cast<ShelfAlignment>(alignment); |
| + Shell::GetInstance()->SetShelfAlignment(value, Shell::GetPrimaryRootWindow()); |
| +} |
| + |
| +void ShelfDelegateMus::SetAutoHideBehavior( |
| + mash::shelf::mojom::AutoHideBehavior auto_hide) { |
| + ShelfAutoHideBehavior value = static_cast<ShelfAutoHideBehavior>(auto_hide); |
| + Shell::GetInstance()->SetShelfAutoHideBehavior(value, |
| + Shell::GetPrimaryRootWindow()); |
| +} |
| + |
| +void ShelfDelegateMus::AddItem( |
| + mash::shelf::mojom::ShelfItemPtr item, |
| + mash::shelf::mojom::ShelfItemDelegateAssociatedPtrInfo delegate) { |
| + ShelfItem shelf_item; |
| + shelf_item.type = TYPE_APP_SHORTCUT; |
| + shelf_item.status = STATUS_CLOSED; |
| + shelf_item.image = GetShelfIconFromBitmap(item->image.To<SkBitmap>()); |
| + |
| + std::string item_id(item->id.To<std::string>()); |
|
sky
2016/04/07 22:02:46
Ignore request if item_id is in app_id_to_shelf_id
msw
2016/04/08 21:20:48
Done.
|
| + ShelfID shelf_id = model_->next_id(); |
| + app_id_to_shelf_id_.insert(std::make_pair(item_id, shelf_id)); |
| + model_->Add(shelf_item); |
| + |
| + scoped_ptr<ShelfItemDelegateMus> item_delegate(new ShelfItemDelegateMus( |
| + item->title.To<base::string16>(), user_window_controller_.get())); |
| + Shell::GetInstance()->shelf_item_delegate_manager()->SetShelfItemDelegate( |
| + shelf_id, std::move(item_delegate)); |
| +} |
| + |
| +void ShelfDelegateMus::RemoveItem(const mojo::String& id) { |
| + std::string item_id(id.To<std::string>()); |
| + DCHECK(app_id_to_shelf_id_.count(item_id)); |
| + model_->RemoveItemAt(model_->ItemIndexByID(app_id_to_shelf_id_[item_id])); |
| +} |
| + |
| void ShelfDelegateMus::OnUserWindowObserverAdded( |
| mojo::Array<mash::wm::mojom::UserWindowPtr> user_windows) { |
| for (size_t i = 0; i < user_windows.size(); ++i) |
| @@ -177,19 +245,19 @@ void ShelfDelegateMus::OnUserWindowAdded( |
| ShelfItem item; |
| item.type = TYPE_PLATFORM_APP; |
| item.status = user_window->window_has_focus ? STATUS_ACTIVE : STATUS_RUNNING; |
| - item.image = GetShelfIconFromBitmap(user_window->window_app_icon); |
| + item.image = GetShelfIconFromSerializedBitmap(user_window->window_app_icon); |
| ShelfID shelf_id = model_->next_id(); |
| window_id_to_shelf_id_.insert( |
| std::make_pair(user_window->window_id, shelf_id)); |
| model_->Add(item); |
| - ShelfItemDelegateManager* manager = |
| - Shell::GetInstance()->shelf_item_delegate_manager(); |
| - scoped_ptr<ShelfItemDelegate> delegate(new ShelfItemDelegateMus( |
| - user_window->window_id, user_window->window_title.To<base::string16>(), |
| - user_window_controller_.get())); |
| - manager->SetShelfItemDelegate(shelf_id, std::move(delegate)); |
| + scoped_ptr<ShelfItemDelegateMus> item_delegate( |
| + new ShelfItemDelegateMus(user_window->window_title.To<base::string16>(), |
| + user_window_controller_.get())); |
| + item_delegate->set_window_id(user_window->window_id); |
| + Shell::GetInstance()->shelf_item_delegate_manager()->SetShelfItemDelegate( |
| + shelf_id, std::move(item_delegate)); |
| } |
| void ShelfDelegateMus::OnUserWindowRemoved(uint32_t window_id) { |
| @@ -232,7 +300,7 @@ void ShelfDelegateMus::OnUserWindowAppIconChanged( |
| int index = model_->ItemIndexByID(shelf_id); |
| DCHECK_GE(index, 0); |
| ShelfItem item = *model_->ItemByID(shelf_id); |
| - item.image = GetShelfIconFromBitmap(app_icon); |
| + item.image = GetShelfIconFromSerializedBitmap(app_icon); |
| model_->Set(index, item); |
| } |