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

Unified 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: Move chrome_launcher_prefs from ash to aura. 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/ash/launcher/chrome_mash_shelf_controller.cc
diff --git a/chrome/browser/ui/ash/launcher/chrome_mash_shelf_controller.cc b/chrome/browser/ui/ash/launcher/chrome_mash_shelf_controller.cc
new file mode 100644
index 0000000000000000000000000000000000000000..fada074027101805ba9908907f1d7bf3a5f3f82e
--- /dev/null
+++ b/chrome/browser/ui/ash/launcher/chrome_mash_shelf_controller.cc
@@ -0,0 +1,96 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/ui/ash/launcher/chrome_mash_shelf_controller.h"
+
+#include "chrome/browser/profiles/profile_manager.h"
+#include "chrome/browser/ui/ash/chrome_launcher_prefs.h"
+#include "chrome/common/pref_names.h"
+#include "chrome/grit/theme_resources.h"
+#include "components/prefs/pref_service.h"
+#include "content/public/common/mojo_shell_connection.h"
+#include "mojo/shell/public/cpp/connector.h"
+#include "skia/public/type_converters.h"
+#include "ui/base/resource/resource_bundle.h"
+
+// static
+ChromeMashShelfController* ChromeMashShelfController::instance_ = NULL;
James Cook 2016/04/06 04:29:52 drive-by nit: nullptr
msw 2016/04/07 20:34:57 Done.
+
+ChromeMashShelfController::~ChromeMashShelfController() {}
+
+// static
+ChromeMashShelfController* ChromeMashShelfController::CreateInstance() {
+ DCHECK(!instance_);
+ instance_ = new ChromeMashShelfController();
+ instance_->Init();
+ return instance_;
+}
+
+ChromeMashShelfController::ChromeMashShelfController()
+ : observer_binding_(this), item_delegate_binding_(this) {}
+
+void ChromeMashShelfController::Init() {
+ mojo::Connector* connector =
+ content::MojoShellConnection::Get()->GetConnector();
+ connector->ConnectToInterface("mojo:ash_sysui", &shelf_);
+
+ // Set shelf alignment and auto-hide behavior from preferences.
+ Profile* profile = ProfileManager::GetActiveUserProfile();
+
+ const std::string& alignment_value =
+ profile->GetPrefs()->GetString(prefs::kShelfAlignmentLocal);
+ shelf_->SetAlignment(static_cast<mash::shelf::mojom::Alignment>(
+ ash::AlignmentFromPref(alignment_value)));
+
+ const std::string& auto_hide_value =
+ profile->GetPrefs()->GetString(prefs::kShelfAutoHideBehaviorLocal);
+ shelf_->SetAutoHideBehavior(static_cast<mash::shelf::mojom::AutoHideBehavior>(
+ ash::AutoHideBehaviorFromPref(auto_hide_value)));
+
+ // Create a test shortcut item to a fake application.
+ mash::shelf::mojom::ShelfItemPtr item(mash::shelf::mojom::ShelfItem::New());
+ item->id = "mojo:fake_app";
+ item->title = "Fake Mojo App (test pinned shelf item)";
+ ResourceBundle& rb = ResourceBundle::GetSharedInstance();
+ const gfx::Image& image = rb.GetImageNamed(IDR_PRODUCT_LOGO_32);
+ item->image = skia::mojom::Bitmap::From(*image.ToSkBitmap());
+ shelf_->AddItem(std::move(item),
+ item_delegate_binding_.CreateInterfacePtrAndBind());
+
+ // Start observing the shelf now that it has been initialized.
+ shelf_->AddObserver(observer_binding_.CreateInterfacePtrAndBind());
+}
+
+void ChromeMashShelfController::OnAlignmentChanged(
+ mash::shelf::mojom::Alignment alignment) {
+ const char* value =
+ ash::AlignmentToPref(static_cast<ash::ShelfAlignment>(alignment));
+ Profile* profile = ProfileManager::GetActiveUserProfile();
+ profile->GetPrefs()->SetString(prefs::kShelfAlignmentLocal, value);
+}
+
+void ChromeMashShelfController::OnAutoHideBehaviorChanged(
+ mash::shelf::mojom::AutoHideBehavior auto_hide) {
+ const char* value = ash::AutoHideBehaviorToPref(
+ static_cast<ash::ShelfAutoHideBehavior>(auto_hide));
+ if (!value)
+ return;
+ Profile* profile = ProfileManager::GetActiveUserProfile();
+ profile->GetPrefs()->SetString(prefs::kShelfAutoHideBehaviorLocal, value);
+}
+
+void ChromeMashShelfController::ExecuteCommand(const mojo::String& id,
+ uint32_t command_id,
+ int32_t event_flags) {
+ NOTIMPLEMENTED();
+}
+
+void ChromeMashShelfController::ItemRemoved(const mojo::String& id) {
+ NOTIMPLEMENTED();
+}
+
+void ChromeMashShelfController::ItemReordered(const mojo::String& id,
+ uint32_t order) {
+ NOTIMPLEMENTED();
+}

Powered by Google App Engine
This is Rietveld 408576698