Commit c3e49228 authored by sashab@chromium.org's avatar sashab@chromium.org

Added Pin/Unpin button to the App Info Dialog on ChromeOS

Since the "Create Shortcuts" button is disabled on ChromeOS, add a
pin/unpin button that allows pinning and unpinning the app from the
shelf. This is the functional equivalent of creating shortcuts on
ChromeOS.

Based off https://codereview.chromium.org/335523002/.

BUG=385526

Review URL: https://codereview.chromium.org/340453004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@278351 0039d316-1c4b-4281-b951-d872f2087c98
parent 3b668780
...@@ -30,7 +30,7 @@ void ShowAppInfoDialog(AppListControllerDelegate* app_list_controller_delegate, ...@@ -30,7 +30,7 @@ void ShowAppInfoDialog(AppListControllerDelegate* app_list_controller_delegate,
DCHECK(app_list_window); DCHECK(app_list_window);
gfx::Rect app_list_bounds = app_list_controller_delegate->GetAppListBounds(); gfx::Rect app_list_bounds = app_list_controller_delegate->GetAppListBounds();
views::View* app_info_view = new AppInfoDialog(profile, app); views::View* app_info_view = new AppInfoDialog(app_list_window, profile, app);
views::Widget* dialog_widget = AppListDialogContentsView::CreateDialogWidget( views::Widget* dialog_widget = AppListDialogContentsView::CreateDialogWidget(
app_list_window, app_list_window,
app_list_bounds, app_list_bounds,
...@@ -39,7 +39,9 @@ void ShowAppInfoDialog(AppListControllerDelegate* app_list_controller_delegate, ...@@ -39,7 +39,9 @@ void ShowAppInfoDialog(AppListControllerDelegate* app_list_controller_delegate,
dialog_widget->Show(); dialog_widget->Show();
} }
AppInfoDialog::AppInfoDialog(Profile* profile, const extensions::Extension* app) AppInfoDialog::AppInfoDialog(gfx::NativeWindow parent_window,
Profile* profile,
const extensions::Extension* app)
: dialog_header_(NULL), dialog_body_(NULL), dialog_footer_(NULL) { : dialog_header_(NULL), dialog_body_(NULL), dialog_footer_(NULL) {
views::GridLayout* layout = new views::GridLayout(this); views::GridLayout* layout = new views::GridLayout(this);
SetLayoutManager(layout); SetLayoutManager(layout);
...@@ -59,7 +61,7 @@ AppInfoDialog::AppInfoDialog(Profile* profile, const extensions::Extension* app) ...@@ -59,7 +61,7 @@ AppInfoDialog::AppInfoDialog(Profile* profile, const extensions::Extension* app)
dialog_header_->SetBorder(views::Border::CreateSolidSidedBorder( dialog_header_->SetBorder(views::Border::CreateSolidSidedBorder(
0, 0, kHorizontalSeparatorHeight, 0, app_list::kDialogSeparatorColor)); 0, 0, kHorizontalSeparatorHeight, 0, app_list::kDialogSeparatorColor));
dialog_footer_ = new AppInfoFooterPanel(profile, app); dialog_footer_ = new AppInfoFooterPanel(parent_window, profile, app);
dialog_footer_->SetBorder(views::Border::CreateSolidSidedBorder( dialog_footer_->SetBorder(views::Border::CreateSolidSidedBorder(
kHorizontalSeparatorHeight, 0, 0, 0, app_list::kDialogSeparatorColor)); kHorizontalSeparatorHeight, 0, 0, 0, app_list::kDialogSeparatorColor));
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#ifndef CHROME_BROWSER_UI_VIEWS_APPS_APP_INFO_DIALOG_APP_INFO_DIALOG_VIEWS_H_ #ifndef CHROME_BROWSER_UI_VIEWS_APPS_APP_INFO_DIALOG_APP_INFO_DIALOG_VIEWS_H_
#define CHROME_BROWSER_UI_VIEWS_APPS_APP_INFO_DIALOG_APP_INFO_DIALOG_VIEWS_H_ #define CHROME_BROWSER_UI_VIEWS_APPS_APP_INFO_DIALOG_APP_INFO_DIALOG_VIEWS_H_
#include "ui/gfx/native_widget_types.h"
#include "ui/views/view.h" #include "ui/views/view.h"
class Profile; class Profile;
...@@ -21,7 +22,9 @@ class ScrollView; ...@@ -21,7 +22,9 @@ class ScrollView;
class AppInfoDialog : public views::View { class AppInfoDialog : public views::View {
public: public:
AppInfoDialog(Profile* profile, const extensions::Extension* app); AppInfoDialog(gfx::NativeWindow parent_window,
Profile* profile,
const extensions::Extension* app);
virtual ~AppInfoDialog(); virtual ~AppInfoDialog();
private: private:
......
...@@ -4,9 +4,13 @@ ...@@ -4,9 +4,13 @@
#include "chrome/browser/ui/views/apps/app_info_dialog/app_info_footer_panel.h" #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/extensions/extension_service.h"
#include "chrome/browser/profiles/profile.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/browser_dialogs.h"
#include "chrome/browser/ui/host_desktop.h"
#include "extensions/browser/extension_system.h" #include "extensions/browser/extension_system.h"
#include "extensions/browser/management_policy.h" #include "extensions/browser/management_policy.h"
#include "extensions/common/extension.h" #include "extensions/common/extension.h"
...@@ -19,10 +23,14 @@ ...@@ -19,10 +23,14 @@
#include "ui/views/view.h" #include "ui/views/view.h"
#include "ui/views/widget/widget.h" #include "ui/views/widget/widget.h"
AppInfoFooterPanel::AppInfoFooterPanel(Profile* profile, AppInfoFooterPanel::AppInfoFooterPanel(gfx::NativeWindow parent_window,
Profile* profile,
const extensions::Extension* app) const extensions::Extension* app)
: AppInfoPanel(profile, app), : AppInfoPanel(profile, app),
parent_window_(parent_window),
create_shortcuts_button_(NULL), create_shortcuts_button_(NULL),
pin_to_shelf_button_(NULL),
unpin_from_shelf_button_(NULL),
remove_button_(NULL), remove_button_(NULL),
weak_ptr_factory_(this) { weak_ptr_factory_(this) {
CreateButtons(); CreateButtons();
...@@ -47,6 +55,15 @@ void AppInfoFooterPanel::CreateButtons() { ...@@ -47,6 +55,15 @@ void AppInfoFooterPanel::CreateButtons() {
create_shortcuts_button_->SetStyle(views::Button::STYLE_BUTTON); 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()) { if (CanUninstallApp()) {
remove_button_ = new views::LabelButton( remove_button_ = new views::LabelButton(
this, this,
...@@ -59,14 +76,33 @@ void AppInfoFooterPanel::LayoutButtons() { ...@@ -59,14 +76,33 @@ void AppInfoFooterPanel::LayoutButtons() {
if (create_shortcuts_button_) if (create_shortcuts_button_)
AddChildView(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_) if (remove_button_)
AddChildView(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, void AppInfoFooterPanel::ButtonPressed(views::Button* sender,
const ui::Event& event) { const ui::Event& event) {
if (sender == create_shortcuts_button_) { if (sender == create_shortcuts_button_) {
CreateShortcuts(); CreateShortcuts();
} else if (sender == pin_to_shelf_button_) {
SetPinnedToShelf(true);
} else if (sender == unpin_from_shelf_button_) {
SetPinnedToShelf(false);
} else if (sender == remove_button_) { } else if (sender == remove_button_) {
UninstallApp(); UninstallApp();
} else { } else {
...@@ -96,12 +132,31 @@ void AppInfoFooterPanel::CreateShortcuts() { ...@@ -96,12 +132,31 @@ void AppInfoFooterPanel::CreateShortcuts() {
} }
bool AppInfoFooterPanel::CanCreateShortcuts() const { bool AppInfoFooterPanel::CanCreateShortcuts() const {
// ChromeOS can pin apps to the app launcher, but can't create shortcuts. // Ash platforms can't create shortcuts.
#if defined(OS_CHROMEOS) return (chrome::GetHostDesktopTypeForNativeWindow(parent_window_) !=
return false; chrome::HOST_DESKTOP_TYPE_ASH);
#else }
return true;
#endif 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() { void AppInfoFooterPanel::UninstallApp() {
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "chrome/browser/extensions/extension_uninstall_dialog.h" #include "chrome/browser/extensions/extension_uninstall_dialog.h"
#include "chrome/browser/ui/views/apps/app_info_dialog/app_info_panel.h" #include "chrome/browser/ui/views/apps/app_info_dialog/app_info_panel.h"
#include "ui/gfx/native_widget_types.h"
#include "ui/views/controls/button/button.h" #include "ui/views/controls/button/button.h"
class Profile; class Profile;
...@@ -33,13 +34,19 @@ class AppInfoFooterPanel ...@@ -33,13 +34,19 @@ class AppInfoFooterPanel
public extensions::ExtensionUninstallDialog::Delegate, public extensions::ExtensionUninstallDialog::Delegate,
public base::SupportsWeakPtr<AppInfoFooterPanel> { public base::SupportsWeakPtr<AppInfoFooterPanel> {
public: public:
AppInfoFooterPanel(Profile* profile, const extensions::Extension* app); AppInfoFooterPanel(gfx::NativeWindow parent_window,
Profile* profile,
const extensions::Extension* app);
virtual ~AppInfoFooterPanel(); virtual ~AppInfoFooterPanel();
private: private:
void CreateButtons(); void CreateButtons();
void LayoutButtons(); void LayoutButtons();
// Updates the visibility of the pin/unpin buttons so that only one is visible
// at a time.
void UpdatePinButtons();
// Overridden from views::ButtonListener: // Overridden from views::ButtonListener:
virtual void ButtonPressed(views::Button* sender, virtual void ButtonPressed(views::Button* sender,
const ui::Event& event) OVERRIDE; const ui::Event& event) OVERRIDE;
...@@ -53,12 +60,21 @@ class AppInfoFooterPanel ...@@ -53,12 +60,21 @@ class AppInfoFooterPanel
void CreateShortcuts(); void CreateShortcuts();
bool CanCreateShortcuts() const; bool CanCreateShortcuts() const;
// Pins and unpins the app from the shelf. Must only be called if
// CanSetPinnedToShelf() returns true.
void SetPinnedToShelf(bool value);
bool CanSetPinnedToShelf() const;
// Uninstall the app. Must only be called if CanUninstallApp() returns true. // Uninstall the app. Must only be called if CanUninstallApp() returns true.
void UninstallApp(); void UninstallApp();
bool CanUninstallApp() const; bool CanUninstallApp() const;
gfx::NativeWindow parent_window_;
// UI elements on the dialog. Elements are NULL if they are not displayed. // UI elements on the dialog. Elements are NULL if they are not displayed.
views::LabelButton* create_shortcuts_button_; views::LabelButton* create_shortcuts_button_;
views::LabelButton* pin_to_shelf_button_;
views::LabelButton* unpin_from_shelf_button_;
views::LabelButton* remove_button_; views::LabelButton* remove_button_;
scoped_ptr<extensions::ExtensionUninstallDialog> extension_uninstall_dialog_; scoped_ptr<extensions::ExtensionUninstallDialog> extension_uninstall_dialog_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment