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