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

Unified Diff: chrome/browser/ui/views/apps/app_info_dialog/app_info_footer_panel.cc

Issue 340453004: Added Pin/Unpin button to the App Info Dialog on ChromeOS (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rename fixes Created 6 years, 6 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
« no previous file with comments | « chrome/browser/ui/views/apps/app_info_dialog/app_info_footer_panel.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/views/apps/app_info_dialog/app_info_footer_panel.cc
diff --git a/chrome/browser/ui/views/apps/app_info_dialog/app_info_footer_panel.cc b/chrome/browser/ui/views/apps/app_info_dialog/app_info_footer_panel.cc
index db66d64f5bab82693280673993df471fdaa0840f..bea3081e315705b24230126f50881bd0392d9bc2 100644
--- a/chrome/browser/ui/views/apps/app_info_dialog/app_info_footer_panel.cc
+++ b/chrome/browser/ui/views/apps/app_info_dialog/app_info_footer_panel.cc
@@ -4,9 +4,13 @@
#include "chrome/browser/ui/views/apps/app_info_dialog/app_info_footer_panel.h"
+#include "ash/shelf/shelf_delegate.h"
+#include "ash/shell.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/ui/app_list/app_list_controller_delegate.h"
#include "chrome/browser/ui/browser_dialogs.h"
+#include "chrome/browser/ui/host_desktop.h"
#include "extensions/browser/extension_system.h"
#include "extensions/browser/management_policy.h"
#include "extensions/common/extension.h"
@@ -19,10 +23,14 @@
#include "ui/views/view.h"
#include "ui/views/widget/widget.h"
-AppInfoFooterPanel::AppInfoFooterPanel(Profile* profile,
+AppInfoFooterPanel::AppInfoFooterPanel(gfx::NativeWindow parent_window,
+ Profile* profile,
const extensions::Extension* app)
: AppInfoPanel(profile, app),
+ parent_window_(parent_window),
create_shortcuts_button_(NULL),
+ pin_to_shelf_button_(NULL),
+ unpin_from_shelf_button_(NULL),
remove_button_(NULL),
weak_ptr_factory_(this) {
CreateButtons();
@@ -47,6 +55,15 @@ void AppInfoFooterPanel::CreateButtons() {
create_shortcuts_button_->SetStyle(views::Button::STYLE_BUTTON);
}
+ if (CanSetPinnedToShelf()) {
+ pin_to_shelf_button_ = new views::LabelButton(
+ this, l10n_util::GetStringUTF16(IDS_APP_LIST_CONTEXT_MENU_PIN));
+ pin_to_shelf_button_->SetStyle(views::Button::STYLE_BUTTON);
+ unpin_from_shelf_button_ = new views::LabelButton(
+ this, l10n_util::GetStringUTF16(IDS_APP_LIST_CONTEXT_MENU_UNPIN));
+ unpin_from_shelf_button_->SetStyle(views::Button::STYLE_BUTTON);
+ }
+
if (CanUninstallApp()) {
remove_button_ = new views::LabelButton(
this,
@@ -59,14 +76,33 @@ void AppInfoFooterPanel::LayoutButtons() {
if (create_shortcuts_button_)
AddChildView(create_shortcuts_button_);
+ if (pin_to_shelf_button_)
+ AddChildView(pin_to_shelf_button_);
+ if (unpin_from_shelf_button_)
+ AddChildView(unpin_from_shelf_button_);
+ UpdatePinButtons();
+
if (remove_button_)
AddChildView(remove_button_);
}
+void AppInfoFooterPanel::UpdatePinButtons() {
+ if (pin_to_shelf_button_ && unpin_from_shelf_button_) {
+ bool is_pinned =
+ !ash::Shell::GetInstance()->GetShelfDelegate()->IsAppPinned(app_->id());
+ pin_to_shelf_button_->SetVisible(is_pinned);
+ unpin_from_shelf_button_->SetVisible(!is_pinned);
+ }
+}
+
void AppInfoFooterPanel::ButtonPressed(views::Button* sender,
const ui::Event& event) {
if (sender == create_shortcuts_button_) {
CreateShortcuts();
+ } else if (sender == pin_to_shelf_button_) {
+ SetPinnedToShelf(true);
+ } else if (sender == unpin_from_shelf_button_) {
+ SetPinnedToShelf(false);
} else if (sender == remove_button_) {
UninstallApp();
} else {
@@ -96,12 +132,31 @@ void AppInfoFooterPanel::CreateShortcuts() {
}
bool AppInfoFooterPanel::CanCreateShortcuts() const {
-// ChromeOS can pin apps to the app launcher, but can't create shortcuts.
-#if defined(OS_CHROMEOS)
- return false;
-#else
- return true;
-#endif
+ // Ash platforms can't create shortcuts.
+ return (chrome::GetHostDesktopTypeForNativeWindow(parent_window_) !=
+ chrome::HOST_DESKTOP_TYPE_ASH);
+}
+
+void AppInfoFooterPanel::SetPinnedToShelf(bool value) {
+ DCHECK(CanSetPinnedToShelf());
+ ash::ShelfDelegate* shelf_delegate =
+ ash::Shell::GetInstance()->GetShelfDelegate();
+ DCHECK(shelf_delegate);
+ if (value)
+ shelf_delegate->PinAppWithID(app_->id());
+ else
+ shelf_delegate->UnpinAppWithID(app_->id());
+
+ UpdatePinButtons();
+ Layout();
+}
+
+bool AppInfoFooterPanel::CanSetPinnedToShelf() const {
+ // Non-Ash platforms don't have a shelf.
+ if (chrome::GetHostDesktopTypeForNativeWindow(parent_window_) !=
+ chrome::HOST_DESKTOP_TYPE_ASH)
+ return false;
+ return ash::Shell::GetInstance()->GetShelfDelegate()->CanPin();
}
void AppInfoFooterPanel::UninstallApp() {
« no previous file with comments | « chrome/browser/ui/views/apps/app_info_dialog/app_info_footer_panel.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698