Index: chrome/browser/ui/views/extensions/extension_uninstall_dialog_view.cc |
diff --git a/chrome/browser/ui/views/extensions/extension_uninstall_dialog_view.cc b/chrome/browser/ui/views/extensions/extension_uninstall_dialog_view.cc |
old mode 100644 |
new mode 100755 |
index 343ee5b3bc71fac6143b9ad8c233f9b4fd6486b4..6af6ff5dca0425a577a092d0d057c0671cd291f9 |
--- a/chrome/browser/ui/views/extensions/extension_uninstall_dialog_view.cc |
+++ b/chrome/browser/ui/views/extensions/extension_uninstall_dialog_view.cc |
@@ -14,6 +14,8 @@ |
#include "chrome/common/extensions/extension.h" |
#include "grit/generated_resources.h" |
#include "ui/base/l10n/l10n_util.h" |
+#include "ui/gfx/compositor/compositor.h" |
+#include "ui/gfx/compositor/layer.h" |
#include "views/controls/image_view.h" |
#include "views/controls/label.h" |
#include "views/layout/layout_constants.h" |
@@ -26,135 +28,211 @@ namespace { |
const int kRightColumnWidth = 210; |
const int kIconSize = 69; |
-class ExtensionUninstallDialogView : public views::DialogDelegateView { |
+class ExtensionUninstallDialogDelegateView; |
+ |
+// Views implementation of the uninstall dialog. |
+class ExtensionUninstallDialogViews : public ExtensionUninstallDialog { |
public: |
- ExtensionUninstallDialogView(ExtensionUninstallDialog::Delegate* delegate, |
- const Extension* extension, |
- SkBitmap* icon) |
- : delegate_(delegate), |
- icon_(NULL) { |
- // Scale down to icon size, but allow smaller icons (don't scale up). |
- 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(UTF16ToWide( |
- l10n_util::GetStringFUTF16(IDS_EXTENSION_UNINSTALL_PROMPT_HEADING, |
- UTF8ToUTF16(extension->name())))); |
- heading_->SetMultiLine(true); |
- heading_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); |
- AddChildView(heading_); |
- } |
+ ExtensionUninstallDialogViews(Profile* profile, |
+ ExtensionUninstallDialog::Delegate* delegate); |
+ virtual ~ExtensionUninstallDialogViews(); |
+ |
+ // Forwards the accept and cancels to the delegate. |
+ void ExtensionUninstallAccepted(); |
+ void ExtensionUninstallCanceled(); |
+ |
+ ExtensionUninstallDialogDelegateView* view() { return view_; } |
private: |
- // views::DialogDelegateView: |
+ void Show() OVERRIDE; |
+ |
+ ExtensionUninstallDialogDelegateView* view_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(ExtensionUninstallDialogViews); |
+}; |
+ |
+// The dialog's view, owned by the views framework. |
+class ExtensionUninstallDialogDelegateView : public views::DialogDelegateView { |
+ public: |
+ ExtensionUninstallDialogDelegateView( |
+ ExtensionUninstallDialogViews* dialog_view, |
+ const Extension* extension, |
+ SkBitmap* icon); |
+ virtual ~ExtensionUninstallDialogDelegateView(); |
+ |
+ // Called when the ExtensionUninstallDialog has been destroyed to make sure |
+ // we invalidate pointers. |
+ void DialogDestroyed() { dialog_ = NULL; } |
+ |
+ private: |
+ // views::DialogDelegate: |
virtual std::wstring GetDialogButtonLabel( |
- MessageBoxFlags::DialogButton button) const OVERRIDE { |
- switch (button) { |
- case MessageBoxFlags::DIALOGBUTTON_OK: |
- return UTF16ToWide( |
- l10n_util::GetStringUTF16( |
- IDS_EXTENSION_PROMPT_UNINSTALL_BUTTON)); |
- case MessageBoxFlags::DIALOGBUTTON_CANCEL: |
- return UTF16ToWide(l10n_util::GetStringUTF16(IDS_CANCEL)); |
- default: |
- NOTREACHED(); |
- return L""; |
- } |
- } |
+ MessageBoxFlags::DialogButton button) const OVERRIDE; |
virtual int GetDefaultDialogButton() const OVERRIDE { |
return MessageBoxFlags::DIALOGBUTTON_CANCEL; |
} |
- virtual bool Accept() OVERRIDE { |
- delegate_->ExtensionDialogAccepted(); |
- return true; |
- } |
- |
- virtual bool Cancel() OVERRIDE { |
- delegate_->ExtensionDialogCanceled(); |
- return true; |
- } |
+ virtual bool Accept() OVERRIDE; |
+ virtual bool Cancel() OVERRIDE; |
// views::WidgetDelegate: |
virtual bool IsModal() const OVERRIDE { return true; } |
- virtual std::wstring GetWindowTitle() const OVERRIDE { |
- return UTF16ToWide( |
- l10n_util::GetStringUTF16(IDS_EXTENSION_UNINSTALL_PROMPT_TITLE)); |
- } |
- virtual views::View* GetContentsView() { return this; } |
+ virtual views::View* GetContentsView() OVERRIDE { return this; } |
+ virtual std::wstring GetWindowTitle() const OVERRIDE; |
// views::View: |
- virtual gfx::Size GetPreferredSize() OVERRIDE { |
- int width = kRightColumnWidth; |
- width += kIconSize; |
- width += views::kPanelHorizMargin * 3; |
+ virtual gfx::Size GetPreferredSize() OVERRIDE; |
- int height = views::kPanelVertMargin * 2; |
- height += heading_->GetHeightForWidth(kRightColumnWidth); |
+ virtual void Layout() OVERRIDE; |
- return gfx::Size(width, |
- std::max(height, kIconSize + views::kPanelVertMargin * 2)); |
- } |
+ ExtensionUninstallDialogViews* dialog_; |
- virtual void Layout() OVERRIDE { |
- int x = views::kPanelHorizMargin; |
- int y = views::kPanelVertMargin; |
- |
- heading_->SizeToFit(kRightColumnWidth); |
- |
- if (heading_->height() <= kIconSize) { |
- icon_->SetBounds(x, y, kIconSize, kIconSize); |
- x += kIconSize; |
- x += views::kPanelHorizMargin; |
- |
- 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::kPanelHorizMargin; |
- |
- heading_->SetX(x); |
- heading_->SetY(y); |
- } |
- } |
- |
- ExtensionUninstallDialog::Delegate* delegate_; |
views::ImageView* icon_; |
views::Label* heading_; |
- DISALLOW_COPY_AND_ASSIGN(ExtensionUninstallDialogView); |
+ DISALLOW_COPY_AND_ASSIGN(ExtensionUninstallDialogDelegateView); |
}; |
-} // namespace |
+ExtensionUninstallDialogViews::ExtensionUninstallDialogViews( |
+ Profile* profile, ExtensionUninstallDialog::Delegate* delegate) |
+ : ExtensionUninstallDialog(profile, delegate) {} |
-// static |
-void ExtensionUninstallDialog::Show( |
- Profile* profile, |
- ExtensionUninstallDialog::Delegate* delegate, |
- const Extension* extension, |
- SkBitmap* icon) { |
- Browser* browser = BrowserList::GetLastActiveWithProfile(profile); |
+ExtensionUninstallDialogViews::~ExtensionUninstallDialogViews() { |
+ // Close the widget (the views framework will delete view_). |
+ if (view_) { |
+ view_->DialogDestroyed(); |
+ view_->GetWidget()->CloseNow(); |
+ } |
+} |
+ |
+void ExtensionUninstallDialogViews::Show() { |
+ Browser* browser = BrowserList::GetLastActiveWithProfile(profile_); |
if (!browser) { |
- delegate->ExtensionDialogCanceled(); |
+ delegate_->ExtensionUninstallCanceled(); |
return; |
} |
BrowserWindow* window = browser->window(); |
if (!window) { |
- delegate->ExtensionDialogCanceled(); |
+ delegate_->ExtensionUninstallCanceled(); |
return; |
} |
- browser::CreateViewsWindow(window->GetNativeHandle(), |
- new ExtensionUninstallDialogView(delegate, extension, icon))->Show(); |
+ view_ = new ExtensionUninstallDialogDelegateView(this, extension_, &icon_); |
+ browser::CreateViewsWindow(window->GetNativeHandle(), view_)->Show(); |
+} |
+ |
+void ExtensionUninstallDialogViews::ExtensionUninstallAccepted() { |
+ // The widget gets destroyed when the dialog is accepted. |
+ view_ = NULL; |
+ delegate_->ExtensionUninstallAccepted(); |
+} |
+ |
+void ExtensionUninstallDialogViews::ExtensionUninstallCanceled() { |
+ // The widget gets destroyed when the dialog is canceled. |
+ view_ = NULL; |
+ delegate_->ExtensionUninstallCanceled(); |
+} |
+ |
+ExtensionUninstallDialogDelegateView::ExtensionUninstallDialogDelegateView( |
+ ExtensionUninstallDialogViews* dialog_view, |
+ const Extension* extension, |
+ SkBitmap* icon) |
+ : dialog_(dialog_view) { |
+ // Scale down to icon size, but allow smaller icons (don't scale up). |
+ 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(UTF16ToWide( |
+ l10n_util::GetStringFUTF16(IDS_EXTENSION_UNINSTALL_PROMPT_HEADING, |
+ UTF8ToUTF16(extension->name())))); |
+ heading_->SetMultiLine(true); |
+ AddChildView(heading_); |
+} |
+ |
+ExtensionUninstallDialogDelegateView::~ExtensionUninstallDialogDelegateView() { |
+} |
+ |
+std::wstring ExtensionUninstallDialogDelegateView::GetDialogButtonLabel( |
+ MessageBoxFlags::DialogButton button) const { |
+ switch (button) { |
+ case MessageBoxFlags::DIALOGBUTTON_OK: |
+ return UTF16ToWide( |
+ l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_UNINSTALL_BUTTON)); |
+ case MessageBoxFlags::DIALOGBUTTON_CANCEL: |
+ return UTF16ToWide(l10n_util::GetStringUTF16(IDS_CANCEL)); |
+ default: |
+ NOTREACHED(); |
+ return L""; |
+ } |
+} |
+ |
+bool ExtensionUninstallDialogDelegateView::Accept() { |
+ if (dialog_) |
+ dialog_->ExtensionUninstallAccepted(); |
+ return true; |
+} |
+ |
+bool ExtensionUninstallDialogDelegateView::Cancel() { |
+ if (dialog_) |
+ dialog_->ExtensionUninstallCanceled(); |
+ return true; |
+} |
+ |
+std::wstring ExtensionUninstallDialogDelegateView::GetWindowTitle() const { |
+ return UTF16ToWide( |
+ l10n_util::GetStringUTF16(IDS_EXTENSION_UNINSTALL_PROMPT_TITLE)); |
+} |
+ |
+ |
+gfx::Size ExtensionUninstallDialogDelegateView::GetPreferredSize() { |
+ int width = kRightColumnWidth; |
+ width += kIconSize; |
+ width += views::kPanelHorizMargin * 3; |
+ |
+ 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::kPanelHorizMargin; |
+ int y = views::kPanelVertMargin; |
+ |
+ heading_->SizeToFit(kRightColumnWidth); |
+ |
+ if (heading_->height() <= kIconSize) { |
+ icon_->SetBounds(x, y, kIconSize, kIconSize); |
+ x += kIconSize; |
+ x += views::kPanelHorizMargin; |
+ |
+ 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::kPanelHorizMargin; |
+ |
+ heading_->SetX(x); |
+ heading_->SetY(y); |
+ } |
+} |
+ |
+} // namespace |
+ |
+// static |
+ExtensionUninstallDialog* ExtensionUninstallDialog::Create( |
+ Profile* profile, Delegate* delegate) { |
+ return new ExtensionUninstallDialogViews(profile, delegate); |
} |