Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(114)

Side by Side Diff: chrome/browser/ui/ash/launcher/chrome_mash_shelf_controller.cc

Issue 1839223003: Add basic Chrome interaction with the mash shelf. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Sync and rebase. Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/ash/launcher/chrome_mash_shelf_controller.h"
6
7 #include "chrome/browser/profiles/profile_manager.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"
11 #include "components/prefs/pref_service.h"
12 #include "content/public/common/mojo_shell_connection.h"
13 #include "mojo/shell/public/cpp/connector.h"
14 #include "skia/public/type_converters.h"
15 #include "ui/base/resource/resource_bundle.h"
16
17 class ChromeShelfItemDelegate : public mash::shelf::mojom::ShelfItemDelegate {
18 public:
19 ChromeShelfItemDelegate() : item_delegate_binding_(this) {}
20 ~ChromeShelfItemDelegate() override {}
21
22 mash::shelf::mojom::ShelfItemDelegateAssociatedPtrInfo
23 CreateInterfacePtrInfoAndBind(mojo::AssociatedGroup* associated_group) {
24 DCHECK(!item_delegate_binding_.is_bound());
25 mash::shelf::mojom::ShelfItemDelegateAssociatedPtrInfo ptr_info;
26 item_delegate_binding_.Bind(&ptr_info, associated_group);
27 return ptr_info;
28 }
29
30 private:
31 // mash::shelf::mojom::ShelfItemDelegate:
32 void ExecuteCommand(uint32_t command_id, int32_t event_flags) override {
33 NOTIMPLEMENTED();
34 }
35 void ItemPinned() override { NOTIMPLEMENTED(); }
36 void ItemUnpinned() override { NOTIMPLEMENTED(); }
37 void ItemReordered(uint32_t order) override { NOTIMPLEMENTED(); }
38
39 mojo::AssociatedBinding<mash::shelf::mojom::ShelfItemDelegate>
40 item_delegate_binding_;
41
42 DISALLOW_COPY_AND_ASSIGN(ChromeShelfItemDelegate);
43 };
44
45 // static
46 ChromeMashShelfController* ChromeMashShelfController::instance_ = nullptr;
47
48 ChromeMashShelfController::~ChromeMashShelfController() {}
49
50 // static
51 ChromeMashShelfController* ChromeMashShelfController::CreateInstance() {
52 DCHECK(!instance_);
53 instance_ = new ChromeMashShelfController();
54 instance_->Init();
55 return instance_;
56 }
57
58 ChromeMashShelfController::ChromeMashShelfController()
59 : observer_binding_(this) {}
60
61 void ChromeMashShelfController::Init() {
62 mojo::Connector* connector =
63 content::MojoShellConnection::Get()->GetConnector();
64 connector->ConnectToInterface("mojo:ash_sysui", &shelf_controller_);
65
66 // Set shelf alignment and auto-hide behavior from preferences.
67 Profile* profile = ProfileManager::GetActiveUserProfile();
68
69 const std::string& alignment_value =
70 profile->GetPrefs()->GetString(prefs::kShelfAlignmentLocal);
71 shelf_controller_->SetAlignment(static_cast<mash::shelf::mojom::Alignment>(
72 ash::AlignmentFromPref(alignment_value)));
73
74 const std::string& auto_hide_value =
75 profile->GetPrefs()->GetString(prefs::kShelfAutoHideBehaviorLocal);
76 shelf_controller_->SetAutoHideBehavior(
77 static_cast<mash::shelf::mojom::AutoHideBehavior>(
78 ash::AutoHideBehaviorFromPref(auto_hide_value)));
79
80 // Create a test shortcut item to a fake application.
81 mash::shelf::mojom::ShelfItemPtr item(mash::shelf::mojom::ShelfItem::New());
82 std::string item_id("mojo:fake_app");
83 item->id = item_id;
84 item->title = "Fake Mojo App (test pinned shelf item)";
85 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
86 const gfx::Image& image = rb.GetImageNamed(IDR_PRODUCT_LOGO_32);
87 item->image = skia::mojom::Bitmap::From(*image.ToSkBitmap());
88 scoped_ptr<ChromeShelfItemDelegate> delegate(new ChromeShelfItemDelegate());
89 shelf_controller_->AddItem(std::move(item),
90 delegate->CreateInterfacePtrInfoAndBind(
91 shelf_controller_.associated_group()));
92 app_id_to_item_delegate_.insert(std::make_pair(item_id, std::move(delegate)));
93
94 // Start observing the shelf now that it has been initialized.
95 mash::shelf::mojom::ShelfObserverAssociatedPtrInfo ptr_info;
96 observer_binding_.Bind(&ptr_info, shelf_controller_.associated_group());
97 shelf_controller_->AddObserver(std::move(ptr_info));
98 }
99
100 void ChromeMashShelfController::OnAlignmentChanged(
101 mash::shelf::mojom::Alignment alignment) {
102 const char* value =
103 ash::AlignmentToPref(static_cast<ash::ShelfAlignment>(alignment));
104 Profile* profile = ProfileManager::GetActiveUserProfile();
105 profile->GetPrefs()->SetString(prefs::kShelfAlignmentLocal, value);
106 }
107
108 void ChromeMashShelfController::OnAutoHideBehaviorChanged(
109 mash::shelf::mojom::AutoHideBehavior auto_hide) {
110 const char* value = ash::AutoHideBehaviorToPref(
111 static_cast<ash::ShelfAutoHideBehavior>(auto_hide));
112 if (!value)
113 return;
114 Profile* profile = ProfileManager::GetActiveUserProfile();
115 profile->GetPrefs()->SetString(prefs::kShelfAutoHideBehaviorLocal, value);
116 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698