| 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 "chrome/browser/ui/ash/launcher/chrome_mash_shelf_controller.h" | 5 #include "chrome/browser/ui/ash/launcher/chrome_mash_shelf_controller.h" |
| 6 | 6 |
| 7 #include "chrome/browser/profiles/profile_manager.h" | 7 #include "chrome/browser/profiles/profile_manager.h" |
| 8 #include "chrome/browser/ui/ash/chrome_launcher_prefs.h" | 8 #include "chrome/browser/ui/ash/chrome_launcher_prefs.h" |
| 9 #include "chrome/grit/theme_resources.h" | 9 #include "chrome/grit/theme_resources.h" |
| 10 #include "content/public/common/mojo_shell_connection.h" | 10 #include "content/public/common/mojo_shell_connection.h" |
| 11 #include "services/shell/public/cpp/connector.h" | 11 #include "services/shell/public/cpp/connector.h" |
| 12 #include "skia/public/type_converters.h" | 12 #include "skia/public/type_converters.h" |
| 13 #include "ui/base/resource/resource_bundle.h" | 13 #include "ui/base/resource/resource_bundle.h" |
| 14 #include "ui/gfx/screen.h" | 14 #include "ui/display/screen.h" |
| 15 | 15 |
| 16 class ChromeShelfItemDelegate : public mash::shelf::mojom::ShelfItemDelegate { | 16 class ChromeShelfItemDelegate : public mash::shelf::mojom::ShelfItemDelegate { |
| 17 public: | 17 public: |
| 18 ChromeShelfItemDelegate() : item_delegate_binding_(this) {} | 18 ChromeShelfItemDelegate() : item_delegate_binding_(this) {} |
| 19 ~ChromeShelfItemDelegate() override {} | 19 ~ChromeShelfItemDelegate() override {} |
| 20 | 20 |
| 21 mash::shelf::mojom::ShelfItemDelegateAssociatedPtrInfo | 21 mash::shelf::mojom::ShelfItemDelegateAssociatedPtrInfo |
| 22 CreateInterfacePtrInfoAndBind(mojo::AssociatedGroup* associated_group) { | 22 CreateInterfacePtrInfoAndBind(mojo::AssociatedGroup* associated_group) { |
| 23 DCHECK(!item_delegate_binding_.is_bound()); | 23 DCHECK(!item_delegate_binding_.is_bound()); |
| 24 mash::shelf::mojom::ShelfItemDelegateAssociatedPtrInfo ptr_info; | 24 mash::shelf::mojom::ShelfItemDelegateAssociatedPtrInfo ptr_info; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 ChromeMashShelfController::ChromeMashShelfController() | 57 ChromeMashShelfController::ChromeMashShelfController() |
| 58 : observer_binding_(this) {} | 58 : observer_binding_(this) {} |
| 59 | 59 |
| 60 void ChromeMashShelfController::Init() { | 60 void ChromeMashShelfController::Init() { |
| 61 shell::Connector* connector = | 61 shell::Connector* connector = |
| 62 content::MojoShellConnection::Get()->GetConnector(); | 62 content::MojoShellConnection::Get()->GetConnector(); |
| 63 connector->ConnectToInterface("mojo:ash_sysui", &shelf_controller_); | 63 connector->ConnectToInterface("mojo:ash_sysui", &shelf_controller_); |
| 64 | 64 |
| 65 // Set shelf alignment and auto-hide behavior from preferences. | 65 // Set shelf alignment and auto-hide behavior from preferences. |
| 66 Profile* profile = ProfileManager::GetActiveUserProfile(); | 66 Profile* profile = ProfileManager::GetActiveUserProfile(); |
| 67 int64_t display_id = gfx::Screen::GetScreen()->GetPrimaryDisplay().id(); | 67 int64_t display_id = display::Screen::GetScreen()->GetPrimaryDisplay().id(); |
| 68 shelf_controller_->SetAlignment(static_cast<mash::shelf::mojom::Alignment>( | 68 shelf_controller_->SetAlignment(static_cast<mash::shelf::mojom::Alignment>( |
| 69 ash::GetShelfAlignmentPref(profile->GetPrefs(), display_id))); | 69 ash::GetShelfAlignmentPref(profile->GetPrefs(), display_id))); |
| 70 shelf_controller_->SetAutoHideBehavior( | 70 shelf_controller_->SetAutoHideBehavior( |
| 71 static_cast<mash::shelf::mojom::AutoHideBehavior>( | 71 static_cast<mash::shelf::mojom::AutoHideBehavior>( |
| 72 ash::GetShelfAutoHideBehaviorPref(profile->GetPrefs(), display_id))); | 72 ash::GetShelfAutoHideBehaviorPref(profile->GetPrefs(), display_id))); |
| 73 | 73 |
| 74 // Create a test shortcut item to a fake application. | 74 // Create a test shortcut item to a fake application. |
| 75 mash::shelf::mojom::ShelfItemPtr item(mash::shelf::mojom::ShelfItem::New()); | 75 mash::shelf::mojom::ShelfItemPtr item(mash::shelf::mojom::ShelfItem::New()); |
| 76 std::string item_id("mojo:fake_app"); | 76 std::string item_id("mojo:fake_app"); |
| 77 item->app_id = item_id; | 77 item->app_id = item_id; |
| 78 item->app_title = "Fake Mojo App (test pinned shelf item)"; | 78 item->app_title = "Fake Mojo App (test pinned shelf item)"; |
| 79 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 79 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 80 const gfx::Image& image = rb.GetImageNamed(IDR_PRODUCT_LOGO_32); | 80 const gfx::Image& image = rb.GetImageNamed(IDR_PRODUCT_LOGO_32); |
| 81 item->image = skia::mojom::Bitmap::From(*image.ToSkBitmap()); | 81 item->image = skia::mojom::Bitmap::From(*image.ToSkBitmap()); |
| 82 std::unique_ptr<ChromeShelfItemDelegate> delegate( | 82 std::unique_ptr<ChromeShelfItemDelegate> delegate( |
| 83 new ChromeShelfItemDelegate()); | 83 new ChromeShelfItemDelegate()); |
| 84 shelf_controller_->PinItem(std::move(item), | 84 shelf_controller_->PinItem(std::move(item), |
| 85 delegate->CreateInterfacePtrInfoAndBind( | 85 delegate->CreateInterfacePtrInfoAndBind( |
| 86 shelf_controller_.associated_group())); | 86 shelf_controller_.associated_group())); |
| 87 app_id_to_item_delegate_.insert(std::make_pair(item_id, std::move(delegate))); | 87 app_id_to_item_delegate_.insert(std::make_pair(item_id, std::move(delegate))); |
| 88 | 88 |
| 89 // Start observing the shelf now that it has been initialized. | 89 // Start observing the shelf now that it has been initialized. |
| 90 mash::shelf::mojom::ShelfObserverAssociatedPtrInfo ptr_info; | 90 mash::shelf::mojom::ShelfObserverAssociatedPtrInfo ptr_info; |
| 91 observer_binding_.Bind(&ptr_info, shelf_controller_.associated_group()); | 91 observer_binding_.Bind(&ptr_info, shelf_controller_.associated_group()); |
| 92 shelf_controller_->AddObserver(std::move(ptr_info)); | 92 shelf_controller_->AddObserver(std::move(ptr_info)); |
| 93 } | 93 } |
| 94 | 94 |
| 95 void ChromeMashShelfController::OnAlignmentChanged( | 95 void ChromeMashShelfController::OnAlignmentChanged( |
| 96 mash::shelf::mojom::Alignment alignment) { | 96 mash::shelf::mojom::Alignment alignment) { |
| 97 ash::SetShelfAlignmentPref(ProfileManager::GetActiveUserProfile()->GetPrefs(), | 97 ash::SetShelfAlignmentPref( |
| 98 gfx::Screen::GetScreen()->GetPrimaryDisplay().id(), | 98 ProfileManager::GetActiveUserProfile()->GetPrefs(), |
| 99 static_cast<ash::wm::ShelfAlignment>(alignment)); | 99 display::Screen::GetScreen()->GetPrimaryDisplay().id(), |
| 100 static_cast<ash::wm::ShelfAlignment>(alignment)); |
| 100 } | 101 } |
| 101 | 102 |
| 102 void ChromeMashShelfController::OnAutoHideBehaviorChanged( | 103 void ChromeMashShelfController::OnAutoHideBehaviorChanged( |
| 103 mash::shelf::mojom::AutoHideBehavior auto_hide) { | 104 mash::shelf::mojom::AutoHideBehavior auto_hide) { |
| 104 ash::SetShelfAutoHideBehaviorPref( | 105 ash::SetShelfAutoHideBehaviorPref( |
| 105 ProfileManager::GetActiveUserProfile()->GetPrefs(), | 106 ProfileManager::GetActiveUserProfile()->GetPrefs(), |
| 106 gfx::Screen::GetScreen()->GetPrimaryDisplay().id(), | 107 display::Screen::GetScreen()->GetPrimaryDisplay().id(), |
| 107 static_cast<ash::ShelfAutoHideBehavior>(auto_hide)); | 108 static_cast<ash::ShelfAutoHideBehavior>(auto_hide)); |
| 108 } | 109 } |
| OLD | NEW |