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

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: add SetIcon and call it 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_install_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(ExtensionInstallUI::Delegate* delegate,
34 const Extension* extension, 36 const Extension* extension,
35 SkBitmap* icon, 37 SkBitmap* icon,
36 ExtensionInstallUI::PromptType type) 38 ExtensionInstallUI::PromptType 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(ExtensionInstallUI::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(ExtensionInstallUI::kButtonIds[type_]));
63 case MessageBoxFlags::DIALOGBUTTON_CANCEL: 65 case MessageBoxFlags::DIALOGBUTTON_CANCEL:
64 return UTF16ToWide(l10n_util::GetStringUTF16(IDS_CANCEL)); 66 return UTF16ToWide(l10n_util::GetStringUTF16(IDS_CANCEL));
65 default: 67 default:
66 NOTREACHED(); 68 NOTREACHED();
67 return L""; 69 return L"";
68 } 70 }
69 } 71 }
70 72
71 virtual int GetDefaultDialogButton() const { 73 virtual int GetDefaultDialogButton() const OVERRIDE {
72 return MessageBoxFlags::DIALOGBUTTON_CANCEL; 74 return MessageBoxFlags::DIALOGBUTTON_CANCEL;
73 } 75 }
74 76
75 virtual bool Accept() { 77 virtual bool Accept() OVERRIDE {
76 delegate_->InstallUIProceed(); 78 delegate_->InstallUIProceed();
77 return true; 79 return true;
78 } 80 }
79 81
80 virtual bool Cancel() { 82 virtual bool Cancel() OVERRIDE {
81 delegate_->InstallUIAbort(); 83 delegate_->InstallUIAbort();
82 return true; 84 return true;
83 } 85 }
84 86
85 // WindowDelegate 87 // views::WindowDelegate:
86 virtual bool IsModal() const { return true; } 88 virtual bool IsModal() const OVERRIDE { return true; }
87 virtual std::wstring GetWindowTitle() const { 89 virtual std::wstring GetWindowTitle() const OVERRIDE {
88 return UTF16ToWide( 90 return UTF16ToWide(
89 l10n_util::GetStringUTF16(ExtensionInstallUI::kTitleIds[type_])); 91 l10n_util::GetStringUTF16(ExtensionInstallUI::kTitleIds[type_]));
90 } 92 }
91 virtual views::View* GetContentsView() { return this; } 93 virtual views::View* GetContentsView() { return this; }
92 94
93 // View 95 // views::View:
94 virtual gfx::Size GetPreferredSize() { 96 virtual gfx::Size GetPreferredSize() OVERRIDE {
95 int width = kRightColumnWidth; 97 int width = kRightColumnWidth;
96 width += kIconSize; 98 width += kIconSize;
97 width += views::kPanelHorizMargin * 3; 99 width += views::kPanelHorizMargin * 3;
98 100
99 int height = views::kPanelVertMargin * 2; 101 int height = views::kPanelVertMargin * 2;
100 height += heading_->GetHeightForWidth(kRightColumnWidth); 102 height += heading_->GetHeightForWidth(kRightColumnWidth);
101 103
102 return gfx::Size(width, 104 return gfx::Size(width,
103 std::max(height, kIconSize + views::kPanelVertMargin * 2)); 105 std::max(height, kIconSize + views::kPanelVertMargin * 2));
104 } 106 }
105 107
106 virtual void Layout() { 108 virtual void Layout() OVERRIDE {
107 int x = views::kPanelHorizMargin; 109 int x = views::kPanelHorizMargin;
108 int y = views::kPanelVertMargin; 110 int y = views::kPanelVertMargin;
109 111
110 heading_->SizeToFit(kRightColumnWidth); 112 heading_->SizeToFit(kRightColumnWidth);
111 113
112 if (heading_->height() <= kIconSize) { 114 if (heading_->height() <= kIconSize) {
113 icon_->SetBounds(x, y, kIconSize, kIconSize); 115 icon_->SetBounds(x, y, kIconSize, kIconSize);
114 x += kIconSize; 116 x += kIconSize;
115 x += views::kPanelHorizMargin; 117 x += views::kPanelHorizMargin;
116 118
(...skipping 10 matching lines...) Expand all
127 heading_->SetX(x); 129 heading_->SetX(x);
128 heading_->SetY(y); 130 heading_->SetY(y);
129 } 131 }
130 } 132 }
131 133
132 ExtensionInstallUI::Delegate* delegate_; 134 ExtensionInstallUI::Delegate* delegate_;
133 views::ImageView* icon_; 135 views::ImageView* icon_;
134 views::Label* heading_; 136 views::Label* heading_;
135 ExtensionInstallUI::PromptType type_; 137 ExtensionInstallUI::PromptType type_;
136 138
137 DISALLOW_COPY_AND_ASSIGN(InstallDialogContent); 139 DISALLOW_COPY_AND_ASSIGN(ExtensionGenericDialogView);
138 }; 140 };
139 141
140 } // namespace 142 } // namespace
141 143
142 void ShowExtensionInstallDialog(Profile* profile, 144 void ShowGenericExtensionDialog(Profile* profile,
143 ExtensionInstallUI::Delegate* delegate, 145 ExtensionInstallUI::Delegate* delegate,
144 const Extension* extension, 146 const Extension* extension,
145 SkBitmap* icon, 147 SkBitmap* icon,
146 ExtensionInstallUI::PromptType type) { 148 ExtensionInstallUI::PromptType type) {
147 Browser* browser = BrowserList::GetLastActiveWithProfile(profile); 149 Browser* browser = BrowserList::GetLastActiveWithProfile(profile);
148 if (!browser) { 150 if (!browser) {
149 delegate->InstallUIAbort(); 151 delegate->InstallUIAbort();
150 return; 152 return;
151 } 153 }
152 154
153 BrowserWindow* window = browser->window(); 155 BrowserWindow* window = browser->window();
154 if (!window) { 156 if (!window) {
155 delegate->InstallUIAbort(); 157 delegate->InstallUIAbort();
156 return; 158 return;
157 } 159 }
158 160
159 browser::CreateViewsWindow(window->GetNativeHandle(), gfx::Rect(), 161 browser::CreateViewsWindow(window->GetNativeHandle(), gfx::Rect(),
160 new InstallDialogContent(delegate, extension, icon, type))->Show(); 162 new ExtensionGenericDialogView(delegate, extension, icon, type))->Show();
161 } 163 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698