| Index: ash/mus/shelf_delegate_mus.cc
|
| diff --git a/ash/mus/shelf_delegate_mus.cc b/ash/mus/shelf_delegate_mus.cc
|
| index d023996170881886f9167c4adfee52803dce19c8..2102ff2cc07201f4f6a4c258eb466095fd8d9a12 100644
|
| --- a/ash/mus/shelf_delegate_mus.cc
|
| +++ b/ash/mus/shelf_delegate_mus.cc
|
| @@ -11,6 +11,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"
|
| @@ -19,6 +20,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"
|
| @@ -32,6 +34,7 @@ namespace sysui {
|
|
|
| namespace {
|
|
|
| +// A ShelfItemDelegate used for pinned items and open user windows.
|
| class ShelfItemDelegateMus : public ShelfItemDelegate {
|
| public:
|
| ShelfItemDelegateMus(uint32_t window_id,
|
| @@ -48,8 +51,12 @@ class ShelfItemDelegateMus : public ShelfItemDelegate {
|
| // 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_; }
|
| @@ -81,13 +88,10 @@ class ShelfItemDelegateMus : public ShelfItemDelegate {
|
| 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);
|
| @@ -99,6 +103,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)
|
| @@ -113,14 +124,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();
|
| @@ -133,11 +144,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) {
|
| @@ -168,6 +186,59 @@ 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();
|
| + 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_.AddPtr(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>());
|
| + if (app_id_to_shelf_id_.count(item_id))
|
| + return;
|
| + 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(
|
| + 0, 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)
|
| @@ -179,19 +250,18 @@ 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();
|
| - std::unique_ptr<ShelfItemDelegate> delegate(new ShelfItemDelegateMus(
|
| + std::unique_ptr<ShelfItemDelegate> item_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));
|
| + Shell::GetInstance()->shelf_item_delegate_manager()->SetShelfItemDelegate(
|
| + shelf_id, std::move(item_delegate));
|
| }
|
|
|
| void ShelfDelegateMus::OnUserWindowRemoved(uint32_t window_id) {
|
| @@ -234,7 +304,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);
|
| }
|
|
|
|
|