This source file includes following definitions.
- GetParent
- view
- DialogDestroyed
- GetDefaultDialogButton
- GetModalType
- show_in_app_list_
- Show
- ExtensionUninstallAccepted
- ExtensionUninstallCanceled
- GetDialogButtonLabel
- Accept
- Cancel
- GetWindowTitle
- GetPreferredSize
- Layout
- Create
#include "chrome/browser/extensions/extension_uninstall_dialog.h"
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/ui/app_list/app_list_service.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/views/constrained_window_views.h"
#include "extensions/common/extension.h"
#include "grit/generated_resources.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/compositor/compositor.h"
#include "ui/compositor/layer.h"
#include "ui/views/controls/image_view.h"
#include "ui/views/controls/label.h"
#include "ui/views/layout/layout_constants.h"
#include "ui/views/view.h"
#include "ui/views/widget/widget.h"
#include "ui/views/window/dialog_delegate.h"
#if defined(USE_ASH)
#include "ash/shell.h"
#endif
namespace {
const int kRightColumnWidth = 210;
const int kIconSize = 69;
class ExtensionUninstallDialogDelegateView;
gfx::NativeWindow GetParent(Browser* browser) {
if (browser && browser->window())
return browser->window()->GetNativeWindow();
return NULL;
}
class ExtensionUninstallDialogViews : public ExtensionUninstallDialog {
public:
ExtensionUninstallDialogViews(Profile* profile,
Browser* browser,
ExtensionUninstallDialog::Delegate* delegate);
virtual ~ExtensionUninstallDialogViews();
void ExtensionUninstallAccepted();
void ExtensionUninstallCanceled();
ExtensionUninstallDialogDelegateView* view() { return view_; }
private:
virtual void Show() OVERRIDE;
ExtensionUninstallDialogDelegateView* view_;
bool show_in_app_list_;
DISALLOW_COPY_AND_ASSIGN(ExtensionUninstallDialogViews);
};
class ExtensionUninstallDialogDelegateView : public views::DialogDelegateView {
public:
ExtensionUninstallDialogDelegateView(
ExtensionUninstallDialogViews* dialog_view,
const extensions::Extension* extension,
const extensions::Extension* triggering_extension,
gfx::ImageSkia* icon);
virtual ~ExtensionUninstallDialogDelegateView();
void DialogDestroyed() { dialog_ = NULL; }
private:
virtual base::string16 GetDialogButtonLabel(
ui::DialogButton button) const OVERRIDE;
virtual int GetDefaultDialogButton() const OVERRIDE {
return ui::DIALOG_BUTTON_CANCEL;
}
virtual bool Accept() OVERRIDE;
virtual bool Cancel() OVERRIDE;
virtual ui::ModalType GetModalType() const OVERRIDE {
return ui::MODAL_TYPE_WINDOW;
}
virtual base::string16 GetWindowTitle() const OVERRIDE;
virtual gfx::Size GetPreferredSize() OVERRIDE;
virtual void Layout() OVERRIDE;
ExtensionUninstallDialogViews* dialog_;
views::ImageView* icon_;
views::Label* heading_;
DISALLOW_COPY_AND_ASSIGN(ExtensionUninstallDialogDelegateView);
};
ExtensionUninstallDialogViews::ExtensionUninstallDialogViews(
Profile* profile,
Browser* browser,
ExtensionUninstallDialog::Delegate* delegate)
: ExtensionUninstallDialog(profile, browser, delegate),
view_(NULL),
show_in_app_list_(!browser) {
}
ExtensionUninstallDialogViews::~ExtensionUninstallDialogViews() {
if (view_) {
view_->DialogDestroyed();
view_->GetWidget()->CloseNow();
}
}
void ExtensionUninstallDialogViews::Show() {
gfx::NativeWindow parent = show_in_app_list_ ?
AppListService::Get(chrome::GetActiveDesktop())->GetAppListWindow() :
GetParent(browser_);
if (browser_ && !parent) {
delegate_->ExtensionUninstallCanceled();
return;
}
view_ = new ExtensionUninstallDialogDelegateView(
this, extension_, triggering_extension_, &icon_);
CreateBrowserModalDialogViews(view_, parent)->Show();
}
void ExtensionUninstallDialogViews::ExtensionUninstallAccepted() {
view_ = NULL;
delegate_->ExtensionUninstallAccepted();
}
void ExtensionUninstallDialogViews::ExtensionUninstallCanceled() {
view_ = NULL;
delegate_->ExtensionUninstallCanceled();
}
ExtensionUninstallDialogDelegateView::ExtensionUninstallDialogDelegateView(
ExtensionUninstallDialogViews* dialog_view,
const extensions::Extension* extension,
const extensions::Extension* triggering_extension,
gfx::ImageSkia* icon)
: dialog_(dialog_view) {
gfx::Size size(icon->width(), icon->height());
if (size.width() > kIconSize || size.height() > kIconSize)
size = gfx::Size(kIconSize, kIconSize);
icon_ = new views::ImageView();
icon_->SetImageSize(size);
icon_->SetImage(*icon);
AddChildView(icon_);
heading_ = new views::Label(base::UTF8ToUTF16(dialog_->GetHeadingText()));
heading_->SetMultiLine(true);
heading_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
AddChildView(heading_);
}
ExtensionUninstallDialogDelegateView::~ExtensionUninstallDialogDelegateView() {
}
base::string16 ExtensionUninstallDialogDelegateView::GetDialogButtonLabel(
ui::DialogButton button) const {
return l10n_util::GetStringUTF16((button == ui::DIALOG_BUTTON_OK) ?
IDS_EXTENSION_PROMPT_UNINSTALL_BUTTON : IDS_CANCEL);
}
bool ExtensionUninstallDialogDelegateView::Accept() {
if (dialog_)
dialog_->ExtensionUninstallAccepted();
return true;
}
bool ExtensionUninstallDialogDelegateView::Cancel() {
if (dialog_)
dialog_->ExtensionUninstallCanceled();
return true;
}
base::string16 ExtensionUninstallDialogDelegateView::GetWindowTitle() const {
return l10n_util::GetStringUTF16(IDS_EXTENSION_UNINSTALL_PROMPT_TITLE);
}
gfx::Size ExtensionUninstallDialogDelegateView::GetPreferredSize() {
int width = kRightColumnWidth;
width += kIconSize;
width += views::kButtonHEdgeMarginNew * 2;
width += views::kRelatedControlHorizontalSpacing;
int height = views::kPanelVertMargin * 2;
height += heading_->GetHeightForWidth(kRightColumnWidth);
return gfx::Size(width,
std::max(height, kIconSize + views::kPanelVertMargin * 2));
}
void ExtensionUninstallDialogDelegateView::Layout() {
int x = views::kButtonHEdgeMarginNew;
int y = views::kPanelVertMargin;
heading_->SizeToFit(kRightColumnWidth);
if (heading_->height() <= kIconSize) {
icon_->SetBounds(x, y, kIconSize, kIconSize);
x += kIconSize;
x += views::kRelatedControlHorizontalSpacing;
heading_->SetX(x);
heading_->SetY(y + (kIconSize - heading_->height()) / 2);
} else {
icon_->SetBounds(x,
y + (heading_->height() - kIconSize) / 2,
kIconSize,
kIconSize);
x += kIconSize;
x += views::kRelatedControlHorizontalSpacing;
heading_->SetX(x);
heading_->SetY(y);
}
}
}
ExtensionUninstallDialog* ExtensionUninstallDialog::Create(
Profile* profile,
Browser* browser,
Delegate* delegate) {
return new ExtensionUninstallDialogViews(profile, browser, delegate);
}