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

Side by Side Diff: chrome/browser/ui/views/extensions/extension_generic_dialog_view.cc

Issue 6721013: extensions: Refactor ExtensionInstallUI class. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove the file Created 9 years, 9 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/file_util.h" 5 #include "base/basictypes.h"
6 #include "base/compiler_specific.h"
6 #include "base/string_util.h" 7 #include "base/string_util.h"
7 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
8 #include "chrome/browser/browser_list.h" 9 #include "chrome/browser/browser_list.h"
9 #include "chrome/browser/browser_window.h" 10 #include "chrome/browser/browser_window.h"
10 #include "chrome/browser/extensions/extension_install_dialog.h" 11 #include "chrome/browser/extensions/extension_generic_dialog.h"
11 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/ui/views/window.h" 13 #include "chrome/browser/ui/views/window.h"
13 #include "chrome/common/extensions/extension.h" 14 #include "chrome/common/extensions/extension.h"
14 #include "grit/generated_resources.h" 15 #include "grit/generated_resources.h"
15 #include "ui/base/l10n/l10n_util.h" 16 #include "ui/base/l10n/l10n_util.h"
16 #include "views/controls/button/checkbox.h" 17 #include "views/controls/button/checkbox.h"
17 #include "views/controls/image_view.h" 18 #include "views/controls/image_view.h"
18 #include "views/controls/label.h" 19 #include "views/controls/label.h"
19 #include "views/controls/link.h" 20 #include "views/controls/link.h"
20 #include "views/layout/layout_constants.h" 21 #include "views/layout/layout_constants.h"
21 #include "views/view.h" 22 #include "views/view.h"
22 #include "views/window/dialog_delegate.h" 23 #include "views/window/dialog_delegate.h"
23 #include "views/window/window.h" 24 #include "views/window/window.h"
24 25
25 namespace { 26 namespace {
26 27
27 const int kRightColumnWidth = 210; 28 const int kRightColumnWidth = 210;
28 const int kIconSize = 69; 29 const int kIconSize = 69;
29 30
30 // Implements the extension installation prompt for Windows. 31 // Implements the extension installation prompt for Windows.
31 class InstallDialogContent : public views::View, public views::DialogDelegate { 32 class ExtensionGenericDialogView : public views::View,
33 public views::DialogDelegate {
32 public: 34 public:
33 InstallDialogContent(ExtensionInstallUI::Delegate* delegate, 35 ExtensionGenericDialogView(ExtensionGenericDialog::Delegate* delegate,
34 const Extension* extension, 36 const Extension* extension,
35 SkBitmap* icon, 37 SkBitmap* icon,
36 ExtensionInstallUI::PromptType type) 38 ExtensionGenericDialog::DialogType type)
37 : delegate_(delegate), icon_(NULL), type_(type) { 39 : delegate_(delegate), icon_(NULL), type_(type) {
38 // Scale down to icon size, but allow smaller icons (don't scale up). 40 // Scale down to icon size, but allow smaller icons (don't scale up).
39 gfx::Size size(icon->width(), icon->height()); 41 gfx::Size size(icon->width(), icon->height());
40 if (size.width() > kIconSize || size.height() > kIconSize) 42 if (size.width() > kIconSize || size.height() > kIconSize)
41 size = gfx::Size(kIconSize, kIconSize); 43 size = gfx::Size(kIconSize, kIconSize);
42 icon_ = new views::ImageView(); 44 icon_ = new views::ImageView();
43 icon_->SetImageSize(size); 45 icon_->SetImageSize(size);
44 icon_->SetImage(*icon); 46 icon_->SetImage(*icon);
45 AddChildView(icon_); 47 AddChildView(icon_);
46 48
47 heading_ = new views::Label(UTF16ToWide( 49 heading_ = new views::Label(UTF16ToWide(
48 l10n_util::GetStringFUTF16(ExtensionInstallUI::kHeadingIds[type_], 50 l10n_util::GetStringFUTF16(ExtensionGenericDialog::kHeadingIds[type_],
49 UTF8ToUTF16(extension->name())))); 51 UTF8ToUTF16(extension->name()))));
50 heading_->SetMultiLine(true); 52 heading_->SetMultiLine(true);
51 heading_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); 53 heading_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
52 AddChildView(heading_); 54 AddChildView(heading_);
53 } 55 }
54 56
55 private: 57 private:
56 // DialogDelegate 58 // views::DialogDelegate:
57 virtual std::wstring GetDialogButtonLabel( 59 virtual std::wstring GetDialogButtonLabel(
58 MessageBoxFlags::DialogButton button) const { 60 MessageBoxFlags::DialogButton button) const OVERRIDE {
59 switch (button) { 61 switch (button) {
60 case MessageBoxFlags::DIALOGBUTTON_OK: 62 case MessageBoxFlags::DIALOGBUTTON_OK:
61 return UTF16ToWide( 63 return UTF16ToWide(
62 l10n_util::GetStringUTF16(ExtensionInstallUI::kButtonIds[type_])); 64 l10n_util::GetStringUTF16(
65 ExtensionGenericDialog::kButtonIds[type_]));
63 case MessageBoxFlags::DIALOGBUTTON_CANCEL: 66 case MessageBoxFlags::DIALOGBUTTON_CANCEL:
64 return UTF16ToWide(l10n_util::GetStringUTF16(IDS_CANCEL)); 67 return UTF16ToWide(l10n_util::GetStringUTF16(IDS_CANCEL));
65 default: 68 default:
66 NOTREACHED(); 69 NOTREACHED();
67 return L""; 70 return L"";
68 } 71 }
69 } 72 }
70 73
71 virtual int GetDefaultDialogButton() const { 74 virtual int GetDefaultDialogButton() const OVERRIDE {
72 return MessageBoxFlags::DIALOGBUTTON_CANCEL; 75 return MessageBoxFlags::DIALOGBUTTON_CANCEL;
73 } 76 }
74 77
75 virtual bool Accept() { 78 virtual bool Accept() OVERRIDE {
76 delegate_->InstallUIProceed(); 79 delegate_->ExtensionDialogAccepted();
77 return true; 80 return true;
78 } 81 }
79 82
80 virtual bool Cancel() { 83 virtual bool Cancel() OVERRIDE {
81 delegate_->InstallUIAbort(); 84 delegate_->ExtensionDialogCanceled();
82 return true; 85 return true;
83 } 86 }
84 87
85 // WindowDelegate 88 // views::WindowDelegate:
86 virtual bool IsModal() const { return true; } 89 virtual bool IsModal() const OVERRIDE { return true; }
87 virtual std::wstring GetWindowTitle() const { 90 virtual std::wstring GetWindowTitle() const OVERRIDE {
88 return UTF16ToWide( 91 return UTF16ToWide(
89 l10n_util::GetStringUTF16(ExtensionInstallUI::kTitleIds[type_])); 92 l10n_util::GetStringUTF16(ExtensionGenericDialog::kTitleIds[type_]));
90 } 93 }
91 virtual views::View* GetContentsView() { return this; } 94 virtual views::View* GetContentsView() { return this; }
92 95
93 // View 96 // views::View:
94 virtual gfx::Size GetPreferredSize() { 97 virtual gfx::Size GetPreferredSize() OVERRIDE {
95 int width = kRightColumnWidth; 98 int width = kRightColumnWidth;
96 width += kIconSize; 99 width += kIconSize;
97 width += views::kPanelHorizMargin * 3; 100 width += views::kPanelHorizMargin * 3;
98 101
99 int height = views::kPanelVertMargin * 2; 102 int height = views::kPanelVertMargin * 2;
100 height += heading_->GetHeightForWidth(kRightColumnWidth); 103 height += heading_->GetHeightForWidth(kRightColumnWidth);
101 104
102 return gfx::Size(width, 105 return gfx::Size(width,
103 std::max(height, kIconSize + views::kPanelVertMargin * 2)); 106 std::max(height, kIconSize + views::kPanelVertMargin * 2));
104 } 107 }
105 108
106 virtual void Layout() { 109 virtual void Layout() OVERRIDE {
107 int x = views::kPanelHorizMargin; 110 int x = views::kPanelHorizMargin;
108 int y = views::kPanelVertMargin; 111 int y = views::kPanelVertMargin;
109 112
110 heading_->SizeToFit(kRightColumnWidth); 113 heading_->SizeToFit(kRightColumnWidth);
111 114
112 if (heading_->height() <= kIconSize) { 115 if (heading_->height() <= kIconSize) {
113 icon_->SetBounds(x, y, kIconSize, kIconSize); 116 icon_->SetBounds(x, y, kIconSize, kIconSize);
114 x += kIconSize; 117 x += kIconSize;
115 x += views::kPanelHorizMargin; 118 x += views::kPanelHorizMargin;
116 119
117 heading_->SetX(x); 120 heading_->SetX(x);
118 heading_->SetY(y + (kIconSize - heading_->height()) / 2); 121 heading_->SetY(y + (kIconSize - heading_->height()) / 2);
119 } else { 122 } else {
120 icon_->SetBounds(x, 123 icon_->SetBounds(x,
121 y + (heading_->height() - kIconSize) / 2, 124 y + (heading_->height() - kIconSize) / 2,
122 kIconSize, 125 kIconSize,
123 kIconSize); 126 kIconSize);
124 x += kIconSize; 127 x += kIconSize;
125 x += views::kPanelHorizMargin; 128 x += views::kPanelHorizMargin;
126 129
127 heading_->SetX(x); 130 heading_->SetX(x);
128 heading_->SetY(y); 131 heading_->SetY(y);
129 } 132 }
130 } 133 }
131 134
132 ExtensionInstallUI::Delegate* delegate_; 135 ExtensionGenericDialog::Delegate* delegate_;
133 views::ImageView* icon_; 136 views::ImageView* icon_;
134 views::Label* heading_; 137 views::Label* heading_;
135 ExtensionInstallUI::PromptType type_; 138 ExtensionGenericDialog::DialogType type_;
136 139
137 DISALLOW_COPY_AND_ASSIGN(InstallDialogContent); 140 DISALLOW_COPY_AND_ASSIGN(ExtensionGenericDialogView);
138 }; 141 };
139 142
140 } // namespace 143 } // namespace
141 144
142 void ShowExtensionInstallDialog(Profile* profile, 145 // static
143 ExtensionInstallUI::Delegate* delegate, 146 void ExtensionGenericDialog::Show(Profile* profile,
144 const Extension* extension, 147 ExtensionGenericDialog::Delegate* delegate,
145 SkBitmap* icon, 148 const Extension* extension,
146 ExtensionInstallUI::PromptType type) { 149 SkBitmap* icon,
150 ExtensionGenericDialog::DialogType type) {
147 Browser* browser = BrowserList::GetLastActiveWithProfile(profile); 151 Browser* browser = BrowserList::GetLastActiveWithProfile(profile);
148 if (!browser) { 152 if (!browser) {
149 delegate->InstallUIAbort(); 153 delegate->ExtensionDialogCanceled();
150 return; 154 return;
151 } 155 }
152 156
153 BrowserWindow* window = browser->window(); 157 BrowserWindow* window = browser->window();
154 if (!window) { 158 if (!window) {
155 delegate->InstallUIAbort(); 159 delegate->ExtensionDialogCanceled();
156 return; 160 return;
157 } 161 }
158 162
159 browser::CreateViewsWindow(window->GetNativeHandle(), gfx::Rect(), 163 browser::CreateViewsWindow(window->GetNativeHandle(), gfx::Rect(),
160 new InstallDialogContent(delegate, extension, icon, type))->Show(); 164 new ExtensionGenericDialogView(delegate, extension, icon, type))->Show();
161 } 165 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698