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

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

Issue 10824054: add oauth2 zippies to views extension install dialog (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review Created 8 years, 4 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
« no previous file with comments | « chrome/browser/ui/gtk/extensions/extension_install_dialog_gtk.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <vector> 5 #include <vector>
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/i18n/rtl.h" 9 #include "base/i18n/rtl.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
11 #include "base/utf_string_conversions.h" 11 #include "base/utf_string_conversions.h"
12 #include "chrome/browser/extensions/bundle_installer.h" 12 #include "chrome/browser/extensions/bundle_installer.h"
13 #include "chrome/browser/extensions/extension_install_dialog.h" 13 #include "chrome/browser/extensions/extension_install_dialog.h"
14 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/common/extensions/extension.h" 15 #include "chrome/common/extensions/extension.h"
16 #include "content/public/browser/page_navigator.h" 16 #include "content/public/browser/page_navigator.h"
17 #include "grit/generated_resources.h" 17 #include "grit/generated_resources.h"
18 #include "grit/theme_resources.h"
19 #include "ui/base/animation/animation_delegate.h"
20 #include "ui/base/animation/slide_animation.h"
18 #include "ui/base/l10n/l10n_util.h" 21 #include "ui/base/l10n/l10n_util.h"
19 #include "ui/base/resource/resource_bundle.h" 22 #include "ui/base/resource/resource_bundle.h"
23 #include "ui/gfx/point3.h"
24 #include "ui/gfx/transform.h"
20 #include "ui/views/border.h" 25 #include "ui/views/border.h"
21 #include "ui/views/controls/image_view.h" 26 #include "ui/views/controls/image_view.h"
22 #include "ui/views/controls/label.h" 27 #include "ui/views/controls/label.h"
23 #include "ui/views/controls/link.h" 28 #include "ui/views/controls/link.h"
24 #include "ui/views/controls/link_listener.h" 29 #include "ui/views/controls/link_listener.h"
25 #include "ui/views/controls/separator.h" 30 #include "ui/views/controls/separator.h"
26 #include "ui/views/layout/box_layout.h" 31 #include "ui/views/layout/box_layout.h"
27 #include "ui/views/layout/grid_layout.h" 32 #include "ui/views/layout/grid_layout.h"
28 #include "ui/views/layout/layout_constants.h" 33 #include "ui/views/layout/layout_constants.h"
29 #include "ui/views/view.h" 34 #include "ui/views/view.h"
(...skipping 30 matching lines...) Expand all
60 65
61 const int kRatingFontSizeDelta = -1; 66 const int kRatingFontSizeDelta = -1;
62 67
63 void AddResourceIcon(const gfx::ImageSkia* skia_image, void* data) { 68 void AddResourceIcon(const gfx::ImageSkia* skia_image, void* data) {
64 views::View* parent = static_cast<views::View*>(data); 69 views::View* parent = static_cast<views::View*>(data);
65 views::ImageView* image_view = new views::ImageView(); 70 views::ImageView* image_view = new views::ImageView();
66 image_view->SetImage(*skia_image); 71 image_view->SetImage(*skia_image);
67 parent->AddChildView(image_view); 72 parent->AddChildView(image_view);
68 } 73 }
69 74
70 } // namespace 75 // Creates a string for displaying |message| to the user. If it has to look
76 // like a entry in a bullet point list, one is added.
77 string16 PrepareForDisplay(const string16& message, bool bullet_point) {
78 return bullet_point ? l10n_util::GetStringFUTF16(
79 IDS_EXTENSION_PERMISSION_LINE,
80 message) : message;
81 }
71 82
72 // Implements the extension installation dialog for TOOLKIT_VIEWS. 83 // Implements the extension installation dialog for TOOLKIT_VIEWS.
73 class ExtensionInstallDialogView : public views::DialogDelegateView, 84 class ExtensionInstallDialogView : public views::DialogDelegateView,
74 public views::LinkListener { 85 public views::LinkListener {
75 public: 86 public:
76 ExtensionInstallDialogView(content::PageNavigator* navigator, 87 ExtensionInstallDialogView(content::PageNavigator* navigator,
77 ExtensionInstallPrompt::Delegate* delegate, 88 ExtensionInstallPrompt::Delegate* delegate,
78 const ExtensionInstallPrompt::Prompt& prompt); 89 const ExtensionInstallPrompt::Prompt& prompt);
79 virtual ~ExtensionInstallDialogView(); 90 virtual ~ExtensionInstallDialogView();
80 91
92 // Changes the size of the containing widget to match the preferred size
93 // of this dialog.
94 void SizeToContents();
95
81 private: 96 private:
82 // views::DialogDelegateView: 97 // views::DialogDelegateView:
83 virtual string16 GetDialogButtonLabel(ui::DialogButton button) const OVERRIDE; 98 virtual string16 GetDialogButtonLabel(ui::DialogButton button) const OVERRIDE;
84 virtual int GetDefaultDialogButton() const OVERRIDE; 99 virtual int GetDefaultDialogButton() const OVERRIDE;
85 virtual bool Cancel() OVERRIDE; 100 virtual bool Cancel() OVERRIDE;
86 virtual bool Accept() OVERRIDE; 101 virtual bool Accept() OVERRIDE;
87 102
88 // views::WidgetDelegate: 103 // views::WidgetDelegate:
89 virtual ui::ModalType GetModalType() const OVERRIDE; 104 virtual ui::ModalType GetModalType() const OVERRIDE;
90 virtual string16 GetWindowTitle() const OVERRIDE; 105 virtual string16 GetWindowTitle() const OVERRIDE;
(...skipping 10 matching lines...) Expand all
101 return prompt_.type() == ExtensionInstallPrompt::BUNDLE_INSTALL_PROMPT; 116 return prompt_.type() == ExtensionInstallPrompt::BUNDLE_INSTALL_PROMPT;
102 } 117 }
103 118
104 content::PageNavigator* navigator_; 119 content::PageNavigator* navigator_;
105 ExtensionInstallPrompt::Delegate* delegate_; 120 ExtensionInstallPrompt::Delegate* delegate_;
106 ExtensionInstallPrompt::Prompt prompt_; 121 ExtensionInstallPrompt::Prompt prompt_;
107 122
108 DISALLOW_COPY_AND_ASSIGN(ExtensionInstallDialogView); 123 DISALLOW_COPY_AND_ASSIGN(ExtensionInstallDialogView);
109 }; 124 };
110 125
126 // A view to display a single IssueAdviceInfoEntry.
127 class IssueAdviceView : public views::View,
128 public ui::AnimationDelegate {
129 public:
130 IssueAdviceView(ExtensionInstallDialogView* owner,
131 const IssueAdviceInfoEntry& issue_advice,
132 int horizontal_space);
133 virtual ~IssueAdviceView() {}
134
135 // Implementation of views::View:
136 virtual bool OnMousePressed(const views::MouseEvent& event) OVERRIDE;
137 virtual void OnMouseReleased(const views::MouseEvent& event) OVERRIDE;
138 virtual void ChildPreferredSizeChanged(views::View* child) OVERRIDE;
139 virtual void ViewHierarchyChanged(bool is_add, View* parent, View* child)
140 OVERRIDE;
Peter Kasting 2012/07/27 03:38:03 Nit: I think our normal practice here is to treat
Evan Stade 2012/07/28 00:20:12 function removed.
141
142 // Implementation of ui::AnimationDelegate:
143 virtual void AnimationProgressed(const ui::Animation* animation) OVERRIDE;
144
145 private:
146 // A view which displays all the details of an IssueAdviceInfoEntry.
147 class DetailsView : public views::View {
148 public:
149 explicit DetailsView(int horizontal_space);
150 virtual ~DetailsView() {}
151
152 // Implementation of views::View:
153 virtual gfx::Size GetPreferredSize() OVERRIDE;
154
155 void AddDetail(const string16& detail);
156
157 // Animates this to be a height proportional to |state|.
158 void AnimateToState(double state);
159
160 private:
161 views::GridLayout* layout_;
162 double state_;
163
164 DISALLOW_COPY_AND_ASSIGN(DetailsView);
165 };
166
167 // The dialog that owns |this|. It's also an ancestor in the View hierarchy.
168 ExtensionInstallDialogView* owner_;
169
170 // The data that backs |this|.
171 IssueAdviceInfoEntry issue_advice_;
172
173 // The amount of horizontal space that |this| should occupy.
174 int horizontal_space_;
175
176 // A view for showing |issue_advice_.details|.
177 DetailsView* details_view_;
178
179 // The '>' zippy control.
180 views::ImageView* arrow_view_;
181
182 views::GridLayout* layout_;
183 ui::SlideAnimation slide_animation_;
184
185 DISALLOW_COPY_AND_ASSIGN(IssueAdviceView);
186 };
187
188 } // namespace
189
111 ExtensionInstallDialogView::ExtensionInstallDialogView( 190 ExtensionInstallDialogView::ExtensionInstallDialogView(
112 content::PageNavigator* navigator, 191 content::PageNavigator* navigator,
113 ExtensionInstallPrompt::Delegate* delegate, 192 ExtensionInstallPrompt::Delegate* delegate,
114 const ExtensionInstallPrompt::Prompt& prompt) 193 const ExtensionInstallPrompt::Prompt& prompt)
115 : navigator_(navigator), 194 : navigator_(navigator),
116 delegate_(delegate), 195 delegate_(delegate),
117 prompt_(prompt) { 196 prompt_(prompt) {
118 // Possible grid layouts: 197 // Possible grid layouts:
119 // Inline install 198 // Inline install
120 // w/ permissions no permissions 199 // w/ permissions no permissions
121 // +--------------------+------+ +--------------+------+ 200 // +--------------------+------+ +--------------+------+
122 // | heading | icon | | heading | icon | 201 // | heading | icon | | heading | icon |
123 // +--------------------| | +--------------| | 202 // +--------------------| | +--------------| |
124 // | rating | | | rating | | 203 // | rating | | | rating | |
125 // +--------------------| | +--------------+ | 204 // +--------------------| | +--------------+ |
126 // | user_count | | | user_count | | 205 // | user_count | | | user_count | |
127 // +--------------------| | +--------------| | 206 // +--------------------| | +--------------| |
128 // | store_link | | | store_link | | 207 // | store_link | | | store_link | |
129 // +--------------------+------+ +--------------+------+ 208 // +--------------------+------+ +--------------+------+
130 // | separator | 209 // | separator |
131 // +--------------------+------+ 210 // +--------------------+------+
132 // | permissions_header | | 211 // | permissions_header | |
133 // +--------------------+------+ 212 // +--------------------+------+
134 // | permission1 | | 213 // | permission1 | |
135 // +--------------------+------+ 214 // +--------------------+------+
136 // | permission2 | | 215 // | permission2 | |
137 // +--------------------+------+ 216 // +--------------------+------+
138 // 217 //
139 // Regular install 218 // Regular install
140 // w/ permissions no permissions 219 // w/ permissions XOR oauth issues no permissions
141 // +--------------------+------+ +--------------+------+ 220 // +--------------------+------+ +--------------+------+
142 // | heading | icon | | heading | icon | 221 // | heading | icon | | heading | icon |
143 // +--------------------| | +--------------+------+ 222 // +--------------------| | +--------------+------+
144 // | permissions_header | | 223 // | permissions_header | |
145 // +--------------------| | 224 // +--------------------| |
146 // | permission1 | | 225 // | permission1 | |
147 // +--------------------| | 226 // +--------------------| |
148 // | permission2 | | 227 // | permission2 | |
149 // +--------------------+------+ 228 // +--------------------+------+
229 //
230 // w/ permissions AND oauth issues
231 // +--------------------+------+
232 // | heading | icon |
233 // +--------------------| |
234 // | permissions_header | |
235 // +--------------------| |
236 // | permission1 | |
237 // +--------------------| |
238 // | permission2 | |
239 // +--------------------+------+
240 // | oauth header |
241 // +---------------------------+
242 // | oauth issue 1 |
243 // +---------------------------+
244 // | oauth issue 2 |
245 // +---------------------------+
150 246
151 views::GridLayout* layout = views::GridLayout::CreatePanel(this); 247 views::GridLayout* layout = views::GridLayout::CreatePanel(this);
152 SetLayoutManager(layout); 248 SetLayoutManager(layout);
153 249
154 int column_set_id = 0; 250 int column_set_id = 0;
155 views::ColumnSet* column_set = layout->AddColumnSet(column_set_id); 251 views::ColumnSet* column_set = layout->AddColumnSet(column_set_id);
156 int left_column_width = prompt.GetPermissionCount() > 0 ? 252 int left_column_width = prompt.GetPermissionCount() > 0 ?
157 kPermissionsLeftColumnWidth : kNoPermissionsLeftColumnWidth; 253 kPermissionsLeftColumnWidth : kNoPermissionsLeftColumnWidth;
158 if (is_bundle_install()) 254 if (is_bundle_install())
159 left_column_width = kBundleLeftColumnWidth; 255 left_column_width = kBundleLeftColumnWidth;
160 256
161 column_set->AddColumn(views::GridLayout::LEADING, 257 column_set->AddColumn(views::GridLayout::LEADING,
162 views::GridLayout::FILL, 258 views::GridLayout::FILL,
163 0, // no resizing 259 0, // no resizing
164 views::GridLayout::USE_PREF, 260 views::GridLayout::USE_PREF,
165 0, // no fixed with 261 0, // no fixed width
166 left_column_width); 262 left_column_width);
167 if (!is_bundle_install()) { 263 if (!is_bundle_install()) {
168 column_set->AddPaddingColumn(0, views::kPanelHorizMargin); 264 column_set->AddPaddingColumn(0, views::kPanelHorizMargin);
169 column_set->AddColumn(views::GridLayout::LEADING, 265 column_set->AddColumn(views::GridLayout::LEADING,
170 views::GridLayout::LEADING, 266 views::GridLayout::LEADING,
171 0, // no resizing 267 0, // no resizing
172 views::GridLayout::USE_PREF, 268 views::GridLayout::USE_PREF,
173 0, // no fixed width 269 0, // no fixed width
174 kIconSize); 270 kIconSize);
175 } 271 }
(...skipping 20 matching lines...) Expand all
196 icon->SetHorizontalAlignment(views::ImageView::CENTER); 292 icon->SetHorizontalAlignment(views::ImageView::CENTER);
197 icon->SetVerticalAlignment(views::ImageView::CENTER); 293 icon->SetVerticalAlignment(views::ImageView::CENTER);
198 int icon_row_span = 1; 294 int icon_row_span = 1;
199 if (is_inline_install()) { 295 if (is_inline_install()) {
200 // Also span the rating, user_count and store_link rows. 296 // Also span the rating, user_count and store_link rows.
201 icon_row_span = 4; 297 icon_row_span = 4;
202 } else if (prompt.GetPermissionCount()) { 298 } else if (prompt.GetPermissionCount()) {
203 // Also span the permission header and each of the permission rows (all 299 // Also span the permission header and each of the permission rows (all
204 // have a padding row above it). 300 // have a padding row above it).
205 icon_row_span = 3 + prompt.GetPermissionCount() * 2; 301 icon_row_span = 3 + prompt.GetPermissionCount() * 2;
302 } else if (prompt.GetOAuthIssueCount()) {
303 // Also span the permission header and each of the permission rows (all
304 // have a padding row above it).
305 icon_row_span = 3 + prompt.GetOAuthIssueCount() * 2;
206 } 306 }
207 layout->AddView(icon, 1, icon_row_span); 307 layout->AddView(icon, 1, icon_row_span);
208 } 308 }
209 309
210 if (is_inline_install()) { 310 if (is_inline_install()) {
211 layout->StartRow(0, column_set_id); 311 layout->StartRow(0, column_set_id);
212 views::View* rating = new views::View(); 312 views::View* rating = new views::View();
213 rating->SetLayoutManager(new views::BoxLayout( 313 rating->SetLayoutManager(new views::BoxLayout(
214 views::BoxLayout::kHorizontal, 0, 0, 0)); 314 views::BoxLayout::kHorizontal, 0, 0, 0));
215 layout->AddView(rating); 315 layout->AddView(rating);
(...skipping 23 matching lines...) Expand all
239 339
240 if (is_bundle_install()) { 340 if (is_bundle_install()) {
241 BundleInstaller::ItemList items = prompt_.bundle()->GetItemsWithState( 341 BundleInstaller::ItemList items = prompt_.bundle()->GetItemsWithState(
242 BundleInstaller::Item::STATE_PENDING); 342 BundleInstaller::Item::STATE_PENDING);
243 for (size_t i = 0; i < items.size(); ++i) { 343 for (size_t i = 0; i < items.size(); ++i) {
244 string16 extension_name = UTF8ToUTF16(items[i].localized_name); 344 string16 extension_name = UTF8ToUTF16(items[i].localized_name);
245 base::i18n::AdjustStringForLocaleDirection(&extension_name); 345 base::i18n::AdjustStringForLocaleDirection(&extension_name);
246 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); 346 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
247 layout->StartRow(0, column_set_id); 347 layout->StartRow(0, column_set_id);
248 views::Label* extension_label = new views::Label( 348 views::Label* extension_label = new views::Label(
249 l10n_util::GetStringFUTF16( 349 PrepareForDisplay(extension_name, true));
250 IDS_EXTENSION_PERMISSION_LINE, extension_name));
251 extension_label->SetMultiLine(true); 350 extension_label->SetMultiLine(true);
252 extension_label->SetHorizontalAlignment(views::Label::ALIGN_LEFT); 351 extension_label->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
253 extension_label->SizeToFit(left_column_width); 352 extension_label->SizeToFit(left_column_width);
254 layout->AddView(extension_label); 353 layout->AddView(extension_label);
255 } 354 }
256 } 355 }
257 356
258 if (prompt.GetPermissionCount()) { 357 if (prompt.GetPermissionCount()) {
259 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); 358 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
260 359
(...skipping 26 matching lines...) Expand all
287 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); 386 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
288 layout->StartRow(0, column_set_id); 387 layout->StartRow(0, column_set_id);
289 views::Label* permission_label = new views::Label( 388 views::Label* permission_label = new views::Label(
290 prompt.GetPermission(i)); 389 prompt.GetPermission(i));
291 permission_label->SetMultiLine(true); 390 permission_label->SetMultiLine(true);
292 permission_label->SetHorizontalAlignment(views::Label::ALIGN_LEFT); 391 permission_label->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
293 permission_label->SizeToFit(left_column_width); 392 permission_label->SizeToFit(left_column_width);
294 layout->AddView(permission_label); 393 layout->AddView(permission_label);
295 } 394 }
296 } 395 }
396
397 if (prompt.GetOAuthIssueCount()) {
398 // Slide in under the permissions; stretch all the way to the right of the
399 // dialog.
400 int space_for_oauth = left_column_width;
401 if (prompt.GetPermissionCount()) {
402 space_for_oauth += kIconSize;
403 column_set = layout->AddColumnSet(++column_set_id);
404 column_set->AddColumn(views::GridLayout::FILL,
405 views::GridLayout::FILL,
406 1,
407 views::GridLayout::USE_PREF,
408 0, // no fixed width
409 space_for_oauth);
410 }
411
412 layout->StartRowWithPadding(0, column_set_id,
413 0, views::kRelatedControlVerticalSpacing);
414 views::Label* oauth_header = new views::Label(prompt.GetOAuthHeading());
415 oauth_header->SetMultiLine(true);
416 oauth_header->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
417 oauth_header->SizeToFit(left_column_width);
418 layout->AddView(oauth_header);
419
420 for (size_t i = 0; i < prompt.GetOAuthIssueCount(); ++i) {
421 layout->StartRowWithPadding(
422 0, column_set_id,
423 0, views::kRelatedControlVerticalSpacing);
424
425 IssueAdviceView* issue_advice_view =
426 new IssueAdviceView(this, prompt.GetOAuthIssue(i), space_for_oauth);
427 layout->AddView(issue_advice_view);
428 }
429 }
297 } 430 }
298 431
299 ExtensionInstallDialogView::~ExtensionInstallDialogView() { 432 ExtensionInstallDialogView::~ExtensionInstallDialogView() {
300 } 433 }
301 434
435 void ExtensionInstallDialogView::SizeToContents() {
436 GetWidget()->SetSize(GetWidget()->non_client_view()->GetPreferredSize());
437 }
438
302 string16 ExtensionInstallDialogView::GetDialogButtonLabel( 439 string16 ExtensionInstallDialogView::GetDialogButtonLabel(
303 ui::DialogButton button) const { 440 ui::DialogButton button) const {
304 switch (button) { 441 switch (button) {
305 case ui::DIALOG_BUTTON_OK: 442 case ui::DIALOG_BUTTON_OK:
306 return prompt_.GetAcceptButtonLabel(); 443 return prompt_.GetAcceptButtonLabel();
307 case ui::DIALOG_BUTTON_CANCEL: 444 case ui::DIALOG_BUTTON_CANCEL:
308 return prompt_.HasAbortButtonLabel() ? 445 return prompt_.HasAbortButtonLabel() ?
309 prompt_.GetAbortButtonLabel() : 446 prompt_.GetAbortButtonLabel() :
310 l10n_util::GetStringUTF16(IDS_CANCEL); 447 l10n_util::GetStringUTF16(IDS_CANCEL);
311 default: 448 default:
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 490
354 void ShowExtensionInstallDialogImpl( 491 void ShowExtensionInstallDialogImpl(
355 gfx::NativeWindow parent, 492 gfx::NativeWindow parent,
356 content::PageNavigator* navigator, 493 content::PageNavigator* navigator,
357 ExtensionInstallPrompt::Delegate* delegate, 494 ExtensionInstallPrompt::Delegate* delegate,
358 const ExtensionInstallPrompt::Prompt& prompt) { 495 const ExtensionInstallPrompt::Prompt& prompt) {
359 views::Widget::CreateWindowWithParent( 496 views::Widget::CreateWindowWithParent(
360 new ExtensionInstallDialogView(navigator, delegate, prompt), 497 new ExtensionInstallDialogView(navigator, delegate, prompt),
361 parent)->Show(); 498 parent)->Show();
362 } 499 }
500
501 // IssueAdviceView::DetailsView ------------------------------------------------
502
503 IssueAdviceView::DetailsView::DetailsView(int horizontal_space)
504 : layout_(new views::GridLayout(this)),
505 state_(0) {
506 SetLayoutManager(layout_);
Evan Stade 2012/07/27 03:06:54 does this also need to be in ViewHierarchyChanged?
Peter Kasting 2012/07/27 03:38:03 It doesn't (and I'm leaning toward nuking that any
507 views::ColumnSet* column_set = layout_->AddColumnSet(0);
508 column_set->AddColumn(views::GridLayout::LEADING,
509 views::GridLayout::LEADING,
510 0,
511 views::GridLayout::FIXED,
512 horizontal_space,
513 0);
514 }
515
516 void IssueAdviceView::DetailsView::AddDetail(const string16& detail) {
517 layout_->StartRowWithPadding(0, 0,
518 0, views::kRelatedControlSmallVerticalSpacing);
Peter Kasting 2012/07/27 03:38:03 Tiny nit: Slightly unusual wrapping... normally we
Evan Stade 2012/07/28 00:20:12 the reason I grouped like this is because the firs
519 views::Label* detail_label =
520 new views::Label(PrepareForDisplay(detail, true));
521 detail_label->SetMultiLine(true);
522 detail_label->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
523 layout_->AddView(detail_label);
524 }
525
526 gfx::Size IssueAdviceView::DetailsView::GetPreferredSize() {
527 gfx::Size size = views::View::GetPreferredSize();
528 return gfx::Size(size.width(), size.height() * state_);
529 }
530
531 void IssueAdviceView::DetailsView::AnimateToState(double state) {
532 state_ = state;
533 PreferredSizeChanged();
534 SchedulePaint();
535 }
536
537 // IssueAdviceView -------------------------------------------------------------
538
539 IssueAdviceView::IssueAdviceView(ExtensionInstallDialogView* owner,
540 const IssueAdviceInfoEntry& issue_advice,
541 int horizontal_space)
542 : owner_(owner),
543 issue_advice_(issue_advice),
Peter Kasting 2012/07/27 03:38:03 Nit: If ViewHierarchyChanged() gets nuked, do you
Evan Stade 2012/07/28 00:20:12 no
544 horizontal_space_(horizontal_space),
Peter Kasting 2012/07/27 03:38:03 Nit: If ViewHierarchyChanged() gets nuked and you
Evan Stade 2012/07/28 00:20:12 I like having the DetailsView code in the DetailsV
545 details_view_(NULL),
546 arrow_view_(NULL),
547 layout_(new views::GridLayout(this)),
548 slide_animation_(this) {
549 }
550
551 void IssueAdviceView::ViewHierarchyChanged(
552 bool is_add, View* parent, View* child) {
553 if (!is_add || child != this)
554 return;
555
556 // TODO(estade): replace this with a more appropriate image.
557 const gfx::ImageSkia& image = *ui::ResourceBundle::GetSharedInstance().
558 GetImageSkiaNamed(IDR_OMNIBOX_TTS);
559
560 SetLayoutManager(layout_);
561 int column_set_id = 0;
562 views::ColumnSet* column_set = layout_->AddColumnSet(column_set_id);
563 if (!issue_advice_.details.empty()) {
564 column_set->AddColumn(views::GridLayout::LEADING,
565 views::GridLayout::LEADING,
566 0,
567 views::GridLayout::FIXED,
568 image.width(),
569 0);
570 horizontal_space_ -= image.width();
571 details_view_ = new DetailsView(horizontal_space_);
572 }
573 column_set->AddColumn(views::GridLayout::LEADING,
574 views::GridLayout::FILL,
575 0,
576 views::GridLayout::FIXED,
577 horizontal_space_,
578 0);
579 layout_->StartRow(0, column_set_id);
580
581 if (details_view_) {
582 arrow_view_ = new views::ImageView();
583 arrow_view_->SetImage(image);
584 arrow_view_->SetVerticalAlignment(views::ImageView::CENTER);
585 layout_->AddView(arrow_view_);
586 }
587
588 views::Label* description_label =
589 new views::Label(PrepareForDisplay(issue_advice_.description,
590 !details_view_));
591 description_label->SetMultiLine(true);
592 description_label->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
593 description_label->SizeToFit(horizontal_space_);
594 layout_->AddView(description_label);
595
596 if (!details_view_)
597 return;
598
599 layout_->StartRow(0, column_set_id);
600 layout_->SkipColumns(1);
601 layout_->AddView(details_view_);
602
603 for (size_t i = 0; i < issue_advice_.details.size(); ++i)
604 details_view_->AddDetail(issue_advice_.details[i]);
605 }
606
607 bool IssueAdviceView::OnMousePressed(const views::MouseEvent& event) {
608 return details_view_ && event.IsLeftMouseButton();
609 }
610
611 void IssueAdviceView::OnMouseReleased(const views::MouseEvent& event) {
612 if (slide_animation_.IsShowing())
613 slide_animation_.Hide();
614 else
615 slide_animation_.Show();
616 }
617
618 void IssueAdviceView::AnimationProgressed(const ui::Animation* animation) {
619 DCHECK_EQ(animation, &slide_animation_);
620
621 if (details_view_)
622 details_view_->AnimateToState(animation->GetCurrentValue());
623
624 if (arrow_view_) {
625 ui::Transform rotate;
626 if (animation->GetCurrentValue() != 0.0) {
627 rotate.SetTranslate(-arrow_view_->width() / 2.0,
628 -arrow_view_->height() / 2.0);
629 rotate.ConcatRotate(animation->GetCurrentValue() * 90);
630 rotate.ConcatTranslate(arrow_view_->width() / 2.0,
631 arrow_view_->height() / 2.0);
632 }
633 arrow_view_->SetTransform(rotate);
634 }
635 }
636
637 void IssueAdviceView::ChildPreferredSizeChanged(views::View* child) {
638 owner_->SizeToContents();
639 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/gtk/extensions/extension_install_dialog_gtk.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698