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

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: 89deg hack 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
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
140 // Implementation of ui::AnimationDelegate:
141 virtual void AnimationProgressed(const ui::Animation* animation) OVERRIDE;
142
143 private:
144 // A view which displays all the details of an IssueAdviceInfoEntry.
145 class DetailsView : public views::View {
146 public:
147 explicit DetailsView(int horizontal_space);
148 virtual ~DetailsView() {}
149
150 // Implementation of views::View:
151 virtual gfx::Size GetPreferredSize() OVERRIDE;
152
153 void AddDetail(const string16& detail);
154
155 // Animates this to be a height proportional to |state|.
156 void AnimateToState(double state);
157
158 private:
159 views::GridLayout* layout_;
160 double state_;
161
162 DISALLOW_COPY_AND_ASSIGN(DetailsView);
163 };
164
165 // The dialog that owns |this|. It's also an ancestor in the View hierarchy.
166 ExtensionInstallDialogView* owner_;
167
168 // A view for showing |issue_advice.details|.
169 DetailsView* details_view_;
170
171 // The '>' zippy control.
172 views::ImageView* arrow_view_;
173
174 views::GridLayout* layout_;
175 ui::SlideAnimation slide_animation_;
176
177 DISALLOW_COPY_AND_ASSIGN(IssueAdviceView);
178 };
179
180 } // namespace
181
111 ExtensionInstallDialogView::ExtensionInstallDialogView( 182 ExtensionInstallDialogView::ExtensionInstallDialogView(
112 content::PageNavigator* navigator, 183 content::PageNavigator* navigator,
113 ExtensionInstallPrompt::Delegate* delegate, 184 ExtensionInstallPrompt::Delegate* delegate,
114 const ExtensionInstallPrompt::Prompt& prompt) 185 const ExtensionInstallPrompt::Prompt& prompt)
115 : navigator_(navigator), 186 : navigator_(navigator),
116 delegate_(delegate), 187 delegate_(delegate),
117 prompt_(prompt) { 188 prompt_(prompt) {
118 // Possible grid layouts: 189 // Possible grid layouts:
119 // Inline install 190 // Inline install
120 // w/ permissions no permissions 191 // w/ permissions no permissions
121 // +--------------------+------+ +--------------+------+ 192 // +--------------------+------+ +--------------+------+
122 // | heading | icon | | heading | icon | 193 // | heading | icon | | heading | icon |
123 // +--------------------| | +--------------| | 194 // +--------------------| | +--------------| |
124 // | rating | | | rating | | 195 // | rating | | | rating | |
125 // +--------------------| | +--------------+ | 196 // +--------------------| | +--------------+ |
126 // | user_count | | | user_count | | 197 // | user_count | | | user_count | |
127 // +--------------------| | +--------------| | 198 // +--------------------| | +--------------| |
128 // | store_link | | | store_link | | 199 // | store_link | | | store_link | |
129 // +--------------------+------+ +--------------+------+ 200 // +--------------------+------+ +--------------+------+
130 // | separator | 201 // | separator |
131 // +--------------------+------+ 202 // +--------------------+------+
132 // | permissions_header | | 203 // | permissions_header | |
133 // +--------------------+------+ 204 // +--------------------+------+
134 // | permission1 | | 205 // | permission1 | |
135 // +--------------------+------+ 206 // +--------------------+------+
136 // | permission2 | | 207 // | permission2 | |
137 // +--------------------+------+ 208 // +--------------------+------+
138 // 209 //
139 // Regular install 210 // Regular install
140 // w/ permissions no permissions 211 // w/ permissions XOR oauth issues no permissions
141 // +--------------------+------+ +--------------+------+ 212 // +--------------------+------+ +--------------+------+
142 // | heading | icon | | heading | icon | 213 // | heading | icon | | heading | icon |
143 // +--------------------| | +--------------+------+ 214 // +--------------------| | +--------------+------+
144 // | permissions_header | | 215 // | permissions_header | |
145 // +--------------------| | 216 // +--------------------| |
146 // | permission1 | | 217 // | permission1 | |
147 // +--------------------| | 218 // +--------------------| |
148 // | permission2 | | 219 // | permission2 | |
149 // +--------------------+------+ 220 // +--------------------+------+
221 //
222 // w/ permissions AND oauth issues
223 // +--------------------+------+
224 // | heading | icon |
225 // +--------------------| |
226 // | permissions_header | |
227 // +--------------------| |
228 // | permission1 | |
229 // +--------------------| |
230 // | permission2 | |
231 // +--------------------+------+
232 // | oauth header |
233 // +---------------------------+
234 // | oauth issue 1 |
235 // +---------------------------+
236 // | oauth issue 2 |
237 // +---------------------------+
150 238
151 views::GridLayout* layout = views::GridLayout::CreatePanel(this); 239 views::GridLayout* layout = views::GridLayout::CreatePanel(this);
152 SetLayoutManager(layout); 240 SetLayoutManager(layout);
153 241
154 int column_set_id = 0; 242 int column_set_id = 0;
155 views::ColumnSet* column_set = layout->AddColumnSet(column_set_id); 243 views::ColumnSet* column_set = layout->AddColumnSet(column_set_id);
156 int left_column_width = prompt.GetPermissionCount() > 0 ? 244 int left_column_width = prompt.GetPermissionCount() > 0 ?
157 kPermissionsLeftColumnWidth : kNoPermissionsLeftColumnWidth; 245 kPermissionsLeftColumnWidth : kNoPermissionsLeftColumnWidth;
158 if (is_bundle_install()) 246 if (is_bundle_install())
159 left_column_width = kBundleLeftColumnWidth; 247 left_column_width = kBundleLeftColumnWidth;
160 248
161 column_set->AddColumn(views::GridLayout::LEADING, 249 column_set->AddColumn(views::GridLayout::LEADING,
162 views::GridLayout::FILL, 250 views::GridLayout::FILL,
163 0, // no resizing 251 0, // no resizing
164 views::GridLayout::USE_PREF, 252 views::GridLayout::USE_PREF,
165 0, // no fixed with 253 0, // no fixed width
166 left_column_width); 254 left_column_width);
167 if (!is_bundle_install()) { 255 if (!is_bundle_install()) {
168 column_set->AddPaddingColumn(0, views::kPanelHorizMargin); 256 column_set->AddPaddingColumn(0, views::kPanelHorizMargin);
169 column_set->AddColumn(views::GridLayout::LEADING, 257 column_set->AddColumn(views::GridLayout::LEADING,
170 views::GridLayout::LEADING, 258 views::GridLayout::LEADING,
171 0, // no resizing 259 0, // no resizing
172 views::GridLayout::USE_PREF, 260 views::GridLayout::USE_PREF,
173 0, // no fixed width 261 0, // no fixed width
174 kIconSize); 262 kIconSize);
175 } 263 }
(...skipping 20 matching lines...) Expand all
196 icon->SetHorizontalAlignment(views::ImageView::CENTER); 284 icon->SetHorizontalAlignment(views::ImageView::CENTER);
197 icon->SetVerticalAlignment(views::ImageView::CENTER); 285 icon->SetVerticalAlignment(views::ImageView::CENTER);
198 int icon_row_span = 1; 286 int icon_row_span = 1;
199 if (is_inline_install()) { 287 if (is_inline_install()) {
200 // Also span the rating, user_count and store_link rows. 288 // Also span the rating, user_count and store_link rows.
201 icon_row_span = 4; 289 icon_row_span = 4;
202 } else if (prompt.GetPermissionCount()) { 290 } else if (prompt.GetPermissionCount()) {
203 // Also span the permission header and each of the permission rows (all 291 // Also span the permission header and each of the permission rows (all
204 // have a padding row above it). 292 // have a padding row above it).
205 icon_row_span = 3 + prompt.GetPermissionCount() * 2; 293 icon_row_span = 3 + prompt.GetPermissionCount() * 2;
294 } else if (prompt.GetOAuthIssueCount()) {
295 // Also span the permission header and each of the permission rows (all
296 // have a padding row above it).
297 icon_row_span = 3 + prompt.GetOAuthIssueCount() * 2;
206 } 298 }
207 layout->AddView(icon, 1, icon_row_span); 299 layout->AddView(icon, 1, icon_row_span);
208 } 300 }
209 301
210 if (is_inline_install()) { 302 if (is_inline_install()) {
211 layout->StartRow(0, column_set_id); 303 layout->StartRow(0, column_set_id);
212 views::View* rating = new views::View(); 304 views::View* rating = new views::View();
213 rating->SetLayoutManager(new views::BoxLayout( 305 rating->SetLayoutManager(new views::BoxLayout(
214 views::BoxLayout::kHorizontal, 0, 0, 0)); 306 views::BoxLayout::kHorizontal, 0, 0, 0));
215 layout->AddView(rating); 307 layout->AddView(rating);
(...skipping 23 matching lines...) Expand all
239 331
240 if (is_bundle_install()) { 332 if (is_bundle_install()) {
241 BundleInstaller::ItemList items = prompt_.bundle()->GetItemsWithState( 333 BundleInstaller::ItemList items = prompt_.bundle()->GetItemsWithState(
242 BundleInstaller::Item::STATE_PENDING); 334 BundleInstaller::Item::STATE_PENDING);
243 for (size_t i = 0; i < items.size(); ++i) { 335 for (size_t i = 0; i < items.size(); ++i) {
244 string16 extension_name = UTF8ToUTF16(items[i].localized_name); 336 string16 extension_name = UTF8ToUTF16(items[i].localized_name);
245 base::i18n::AdjustStringForLocaleDirection(&extension_name); 337 base::i18n::AdjustStringForLocaleDirection(&extension_name);
246 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); 338 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
247 layout->StartRow(0, column_set_id); 339 layout->StartRow(0, column_set_id);
248 views::Label* extension_label = new views::Label( 340 views::Label* extension_label = new views::Label(
249 l10n_util::GetStringFUTF16( 341 PrepareForDisplay(extension_name, true));
250 IDS_EXTENSION_PERMISSION_LINE, extension_name));
251 extension_label->SetMultiLine(true); 342 extension_label->SetMultiLine(true);
252 extension_label->SetHorizontalAlignment(views::Label::ALIGN_LEFT); 343 extension_label->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
253 extension_label->SizeToFit(left_column_width); 344 extension_label->SizeToFit(left_column_width);
254 layout->AddView(extension_label); 345 layout->AddView(extension_label);
255 } 346 }
256 } 347 }
257 348
258 if (prompt.GetPermissionCount()) { 349 if (prompt.GetPermissionCount()) {
259 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); 350 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
260 351
(...skipping 26 matching lines...) Expand all
287 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); 378 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
288 layout->StartRow(0, column_set_id); 379 layout->StartRow(0, column_set_id);
289 views::Label* permission_label = new views::Label( 380 views::Label* permission_label = new views::Label(
290 prompt.GetPermission(i)); 381 prompt.GetPermission(i));
291 permission_label->SetMultiLine(true); 382 permission_label->SetMultiLine(true);
292 permission_label->SetHorizontalAlignment(views::Label::ALIGN_LEFT); 383 permission_label->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
293 permission_label->SizeToFit(left_column_width); 384 permission_label->SizeToFit(left_column_width);
294 layout->AddView(permission_label); 385 layout->AddView(permission_label);
295 } 386 }
296 } 387 }
388
389 if (prompt.GetOAuthIssueCount()) {
390 // Slide in under the permissions; stretch all the way to the right of the
391 // dialog.
392 int space_for_oauth = left_column_width;
393 if (prompt.GetPermissionCount()) {
394 space_for_oauth += kIconSize;
395 column_set = layout->AddColumnSet(++column_set_id);
396 column_set->AddColumn(views::GridLayout::FILL,
397 views::GridLayout::FILL,
398 1,
399 views::GridLayout::USE_PREF,
400 0, // no fixed width
401 space_for_oauth);
402 }
403
404 layout->StartRowWithPadding(0, column_set_id,
405 0, views::kRelatedControlVerticalSpacing);
406 views::Label* oauth_header = new views::Label(prompt.GetOAuthHeading());
407 oauth_header->SetMultiLine(true);
408 oauth_header->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
409 oauth_header->SizeToFit(left_column_width);
410 layout->AddView(oauth_header);
411
412 for (size_t i = 0; i < prompt.GetOAuthIssueCount(); ++i) {
413 layout->StartRowWithPadding(
414 0, column_set_id,
415 0, views::kRelatedControlVerticalSpacing);
416
417 IssueAdviceView* issue_advice_view =
418 new IssueAdviceView(this, prompt.GetOAuthIssue(i), space_for_oauth);
419 layout->AddView(issue_advice_view);
420 }
421 }
297 } 422 }
298 423
299 ExtensionInstallDialogView::~ExtensionInstallDialogView() { 424 ExtensionInstallDialogView::~ExtensionInstallDialogView() {
300 } 425 }
301 426
427 void ExtensionInstallDialogView::SizeToContents() {
428 GetWidget()->SetSize(GetWidget()->non_client_view()->GetPreferredSize());
429 }
430
302 string16 ExtensionInstallDialogView::GetDialogButtonLabel( 431 string16 ExtensionInstallDialogView::GetDialogButtonLabel(
303 ui::DialogButton button) const { 432 ui::DialogButton button) const {
304 switch (button) { 433 switch (button) {
305 case ui::DIALOG_BUTTON_OK: 434 case ui::DIALOG_BUTTON_OK:
306 return prompt_.GetAcceptButtonLabel(); 435 return prompt_.GetAcceptButtonLabel();
307 case ui::DIALOG_BUTTON_CANCEL: 436 case ui::DIALOG_BUTTON_CANCEL:
308 return prompt_.HasAbortButtonLabel() ? 437 return prompt_.HasAbortButtonLabel() ?
309 prompt_.GetAbortButtonLabel() : 438 prompt_.GetAbortButtonLabel() :
310 l10n_util::GetStringUTF16(IDS_CANCEL); 439 l10n_util::GetStringUTF16(IDS_CANCEL);
311 default: 440 default:
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 482
354 void ShowExtensionInstallDialogImpl( 483 void ShowExtensionInstallDialogImpl(
355 gfx::NativeWindow parent, 484 gfx::NativeWindow parent,
356 content::PageNavigator* navigator, 485 content::PageNavigator* navigator,
357 ExtensionInstallPrompt::Delegate* delegate, 486 ExtensionInstallPrompt::Delegate* delegate,
358 const ExtensionInstallPrompt::Prompt& prompt) { 487 const ExtensionInstallPrompt::Prompt& prompt) {
359 views::Widget::CreateWindowWithParent( 488 views::Widget::CreateWindowWithParent(
360 new ExtensionInstallDialogView(navigator, delegate, prompt), 489 new ExtensionInstallDialogView(navigator, delegate, prompt),
361 parent)->Show(); 490 parent)->Show();
362 } 491 }
492
493 // IssueAdviceView::DetailsView ------------------------------------------------
494
495 IssueAdviceView::DetailsView::DetailsView(int horizontal_space)
496 : layout_(new views::GridLayout(this)),
497 state_(0) {
498 SetLayoutManager(layout_);
499 views::ColumnSet* column_set = layout_->AddColumnSet(0);
500 column_set->AddColumn(views::GridLayout::LEADING,
501 views::GridLayout::LEADING,
502 0,
503 views::GridLayout::FIXED,
504 horizontal_space,
505 0);
506 }
507
508 void IssueAdviceView::DetailsView::AddDetail(const string16& detail) {
509 layout_->StartRowWithPadding(0, 0,
510 0, views::kRelatedControlSmallVerticalSpacing);
511 views::Label* detail_label =
512 new views::Label(PrepareForDisplay(detail, true));
513 detail_label->SetMultiLine(true);
514 detail_label->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
515 layout_->AddView(detail_label);
516 }
517
518 gfx::Size IssueAdviceView::DetailsView::GetPreferredSize() {
519 gfx::Size size = views::View::GetPreferredSize();
520 return gfx::Size(size.width(), size.height() * state_);
521 }
522
523 void IssueAdviceView::DetailsView::AnimateToState(double state) {
524 state_ = state;
525 PreferredSizeChanged();
526 SchedulePaint();
527 }
528
529 // IssueAdviceView -------------------------------------------------------------
530
531 IssueAdviceView::IssueAdviceView(ExtensionInstallDialogView* owner,
532 const IssueAdviceInfoEntry& issue_advice,
533 int horizontal_space)
534 : owner_(owner),
535 details_view_(NULL),
536 arrow_view_(NULL),
537 layout_(new views::GridLayout(this)),
Peter Kasting 2012/07/28 00:45:55 Nit: If you want, you can make this member into a
Evan Stade 2012/07/28 01:13:10 sure
538 slide_animation_(this) {
539 // TODO(estade): replace this with a more appropriate image.
540 const gfx::ImageSkia& image = *ui::ResourceBundle::GetSharedInstance().
541 GetImageSkiaNamed(IDR_OMNIBOX_TTS);
542
543 SetLayoutManager(layout_);
544 int column_set_id = 0;
545 views::ColumnSet* column_set = layout_->AddColumnSet(column_set_id);
546 if (!issue_advice.details.empty()) {
547 column_set->AddColumn(views::GridLayout::LEADING,
548 views::GridLayout::LEADING,
549 0,
550 views::GridLayout::FIXED,
551 image.width(),
552 0);
553 horizontal_space -= image.width();
554 details_view_ = new DetailsView(horizontal_space);
555 }
556 column_set->AddColumn(views::GridLayout::LEADING,
557 views::GridLayout::FILL,
558 0,
559 views::GridLayout::FIXED,
560 horizontal_space,
561 0);
562 layout_->StartRow(0, column_set_id);
563
564 if (details_view_) {
565 arrow_view_ = new views::ImageView();
566 arrow_view_->SetImage(image);
567 arrow_view_->SetVerticalAlignment(views::ImageView::CENTER);
568 layout_->AddView(arrow_view_);
569 }
570
571 views::Label* description_label =
572 new views::Label(PrepareForDisplay(issue_advice.description,
573 !details_view_));
574 description_label->SetMultiLine(true);
575 description_label->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
576 description_label->SizeToFit(horizontal_space);
577 layout_->AddView(description_label);
578
579 if (!details_view_)
580 return;
581
582 layout_->StartRow(0, column_set_id);
583 layout_->SkipColumns(1);
584 layout_->AddView(details_view_);
585
586 for (size_t i = 0; i < issue_advice.details.size(); ++i)
587 details_view_->AddDetail(issue_advice.details[i]);
588 }
589
590 bool IssueAdviceView::OnMousePressed(const views::MouseEvent& event) {
591 return details_view_ && event.IsLeftMouseButton();
592 }
593
594 void IssueAdviceView::OnMouseReleased(const views::MouseEvent& event) {
595 if (slide_animation_.IsShowing())
596 slide_animation_.Hide();
597 else
598 slide_animation_.Show();
599 }
600
601 void IssueAdviceView::AnimationProgressed(const ui::Animation* animation) {
602 DCHECK_EQ(animation, &slide_animation_);
603
604 if (details_view_)
605 details_view_->AnimateToState(animation->GetCurrentValue());
606
607 if (arrow_view_) {
608 ui::Transform rotate;
609 if (animation->GetCurrentValue() != 0.0) {
610 rotate.SetTranslate(-arrow_view_->width() / 2.0,
611 -arrow_view_->height() / 2.0);
612 // TODO(estade): for some reason there are rendering errors at 90 degrees.
613 // Figure out why.
614 rotate.ConcatRotate(animation->GetCurrentValue() * 89);
615 rotate.ConcatTranslate(arrow_view_->width() / 2.0,
616 arrow_view_->height() / 2.0);
617 }
618 arrow_view_->SetTransform(rotate);
619 }
620 }
621
622 void IssueAdviceView::ChildPreferredSizeChanged(views::View* child) {
623 owner_->SizeToContents();
624 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/gtk/extensions/extension_install_dialog_gtk.cc ('k') | chrome/browser/ui/views/web_intent_picker_views.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698