Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 Loading... | |
| 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 DetailsView(); | |
| 148 virtual ~DetailsView() {} | |
| 149 | |
| 150 // Implementation of views::View: | |
| 151 virtual gfx::Size GetPreferredSize() OVERRIDE; | |
| 152 | |
| 153 // Animates this to be a height proportional to |state|. | |
| 154 void AnimateToState(double state); | |
| 155 | |
| 156 private: | |
| 157 double state_; | |
| 158 | |
| 159 DISALLOW_COPY_AND_ASSIGN(DetailsView); | |
| 160 }; | |
| 161 | |
| 162 // The dialog that owns |this|. It's also an ancestor in the View hierarchy. | |
| 163 ExtensionInstallDialogView* owner_; | |
| 164 | |
| 165 // The data that backs |this|. | |
| 166 IssueAdviceInfoEntry issue_advice_; | |
| 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 Loading... | |
| 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 Loading... | |
| 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 Loading... | |
| 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 layout->AddPaddingRow(0, views::kRelatedControlSmallVerticalSpacing); | |
|
Peter Kasting
2012/07/27 00:45:09
This results in two "small vertical spacing" paddi
Evan Stade
2012/07/27 03:06:54
I was doing this intentionally for reasons I won't
| |
| 413 for (size_t i = 0; i < prompt.GetOAuthIssueCount(); ++i) { | |
| 414 layout->StartRowWithPadding( | |
| 415 0, column_set_id, | |
| 416 0, views::kRelatedControlSmallVerticalSpacing); | |
| 417 | |
| 418 IssueAdviceView* issue_advice_view = | |
| 419 new IssueAdviceView(this, prompt.GetOAuthIssue(i), space_for_oauth); | |
| 420 layout->AddView(issue_advice_view); | |
| 421 } | |
| 422 } | |
| 297 } | 423 } |
| 298 | 424 |
| 299 ExtensionInstallDialogView::~ExtensionInstallDialogView() { | 425 ExtensionInstallDialogView::~ExtensionInstallDialogView() { |
| 300 } | 426 } |
| 301 | 427 |
| 428 void ExtensionInstallDialogView::SizeToContents() { | |
| 429 GetWidget()->SetSize(GetWidget()->non_client_view()->GetPreferredSize()); | |
| 430 } | |
| 431 | |
| 302 string16 ExtensionInstallDialogView::GetDialogButtonLabel( | 432 string16 ExtensionInstallDialogView::GetDialogButtonLabel( |
| 303 ui::DialogButton button) const { | 433 ui::DialogButton button) const { |
| 304 switch (button) { | 434 switch (button) { |
| 305 case ui::DIALOG_BUTTON_OK: | 435 case ui::DIALOG_BUTTON_OK: |
| 306 return prompt_.GetAcceptButtonLabel(); | 436 return prompt_.GetAcceptButtonLabel(); |
| 307 case ui::DIALOG_BUTTON_CANCEL: | 437 case ui::DIALOG_BUTTON_CANCEL: |
| 308 return prompt_.HasAbortButtonLabel() ? | 438 return prompt_.HasAbortButtonLabel() ? |
| 309 prompt_.GetAbortButtonLabel() : | 439 prompt_.GetAbortButtonLabel() : |
| 310 l10n_util::GetStringUTF16(IDS_CANCEL); | 440 l10n_util::GetStringUTF16(IDS_CANCEL); |
| 311 default: | 441 default: |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 353 | 483 |
| 354 void ShowExtensionInstallDialogImpl( | 484 void ShowExtensionInstallDialogImpl( |
| 355 gfx::NativeWindow parent, | 485 gfx::NativeWindow parent, |
| 356 content::PageNavigator* navigator, | 486 content::PageNavigator* navigator, |
| 357 ExtensionInstallPrompt::Delegate* delegate, | 487 ExtensionInstallPrompt::Delegate* delegate, |
| 358 const ExtensionInstallPrompt::Prompt& prompt) { | 488 const ExtensionInstallPrompt::Prompt& prompt) { |
| 359 views::Widget::CreateWindowWithParent( | 489 views::Widget::CreateWindowWithParent( |
| 360 new ExtensionInstallDialogView(navigator, delegate, prompt), | 490 new ExtensionInstallDialogView(navigator, delegate, prompt), |
| 361 parent)->Show(); | 491 parent)->Show(); |
| 362 } | 492 } |
| 493 | |
| 494 // IssueAdviceView::DetailsView ------------------------------------------------ | |
| 495 | |
| 496 IssueAdviceView::DetailsView::DetailsView() : state_(0) { | |
| 497 SetLayoutManager(new views::BoxLayout( | |
| 498 views::BoxLayout::kHorizontal, | |
| 499 0, 0, views::kRelatedControlSmallVerticalSpacing)); | |
| 500 } | |
| 501 | |
| 502 gfx::Size IssueAdviceView::DetailsView::GetPreferredSize() { | |
| 503 gfx::Size size = views::View::GetPreferredSize(); | |
| 504 return gfx::Size(size.width(), size.height() * state_); | |
| 505 } | |
| 506 | |
| 507 void IssueAdviceView::DetailsView::AnimateToState(double state) { | |
| 508 state_ = state; | |
| 509 PreferredSizeChanged(); | |
| 510 SchedulePaint(); | |
| 511 } | |
| 512 | |
| 513 // IssueAdviceView ------------------------------------------------------------- | |
| 514 | |
| 515 IssueAdviceView::IssueAdviceView(ExtensionInstallDialogView* owner, | |
| 516 const IssueAdviceInfoEntry& issue_advice, | |
| 517 int horizontal_space) | |
| 518 : owner_(owner), | |
| 519 issue_advice_(issue_advice), | |
| 520 details_view_(issue_advice.details.empty() ? NULL : new DetailsView()), | |
| 521 arrow_view_(NULL), | |
| 522 layout_(new views::GridLayout(this)), | |
| 523 slide_animation_(this) { | |
| 524 // TODO(estade): replace this with a more appropriate image. | |
| 525 const gfx::ImageSkia& image = *ui::ResourceBundle::GetSharedInstance(). | |
| 526 GetImageSkiaNamed(IDR_OMNIBOX_TTS); | |
| 527 | |
| 528 SetLayoutManager(layout_); | |
|
Peter Kasting
2012/07/27 00:45:09
Nit: By convention we'd normally do most of this i
Evan Stade
2012/07/27 03:06:54
well as long as |this| owns them, and |this| gets
Peter Kasting
2012/07/27 03:38:03
Oh, sorry, I didn't realize that with a layout man
tfarina
2012/07/27 03:50:34
View owns the LayoutManager, when you do SetLayout
Peter Kasting
2012/07/27 03:53:55
The issue was the ownership of the views inside th
| |
| 529 int column_set_id = 0; | |
| 530 views::ColumnSet* column_set = layout_->AddColumnSet(column_set_id); | |
| 531 if (details_view_) { | |
| 532 column_set->AddColumn(views::GridLayout::LEADING, | |
| 533 views::GridLayout::LEADING, | |
| 534 0, | |
| 535 views::GridLayout::FIXED, | |
| 536 image.width(), | |
| 537 0); | |
| 538 horizontal_space -= image.width(); | |
| 539 } | |
| 540 column_set->AddColumn(views::GridLayout::LEADING, | |
| 541 views::GridLayout::FILL, | |
| 542 0, | |
| 543 views::GridLayout::FIXED, | |
| 544 horizontal_space, | |
| 545 0); | |
| 546 layout_->StartRow(0, column_set_id); | |
| 547 | |
| 548 if (details_view_) { | |
| 549 arrow_view_ = new views::ImageView(); | |
| 550 arrow_view_->SetImage(image); | |
| 551 arrow_view_->SetVerticalAlignment(views::ImageView::CENTER); | |
| 552 layout_->AddView(arrow_view_); | |
| 553 } | |
| 554 | |
| 555 views::Label* description_label = | |
| 556 new views::Label(PrepareForDisplay(issue_advice.description, | |
| 557 !details_view_)); | |
| 558 description_label->SetMultiLine(true); | |
| 559 description_label->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | |
| 560 description_label->SizeToFit(horizontal_space); | |
| 561 layout_->AddView(description_label); | |
| 562 | |
| 563 if (!details_view_) | |
| 564 return; | |
| 565 | |
| 566 layout_->StartRowWithPadding(0, column_set_id, | |
| 567 0, views::kRelatedControlSmallVerticalSpacing); | |
| 568 layout_->SkipColumns(1); | |
| 569 layout_->AddView(details_view_); | |
| 570 | |
| 571 details_view_->SetLayoutManager( | |
| 572 new views::BoxLayout(views::BoxLayout::kVertical, | |
| 573 0, 0, views::kRelatedControlSmallVerticalSpacing)); | |
| 574 | |
| 575 for (size_t i = 0; i < issue_advice.details.size(); ++i) { | |
|
Peter Kasting
2012/07/27 00:45:09
Just making sure -- it looks like as the details v
Evan Stade
2012/07/27 03:06:54
yes, that happens. I can create a video of it if y
Peter Kasting
2012/07/27 03:38:03
Don't worry, I believe you :)
| |
| 576 views::Label* detail_label = | |
| 577 new views::Label(PrepareForDisplay(issue_advice.details[i], true)); | |
| 578 detail_label->SetMultiLine(true); | |
| 579 detail_label->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | |
| 580 detail_label->SizeToFit(horizontal_space); | |
| 581 details_view_->AddChildView(detail_label); | |
| 582 } | |
| 583 } | |
| 584 | |
| 585 bool IssueAdviceView::OnMousePressed(const views::MouseEvent& event) { | |
| 586 return details_view_ && event.IsLeftMouseButton(); | |
| 587 } | |
| 588 | |
| 589 void IssueAdviceView::OnMouseReleased(const views::MouseEvent& event) { | |
| 590 if (slide_animation_.IsShowing()) | |
|
Peter Kasting
2012/07/27 00:45:09
Nit: I'm not sure this is quite right -- seems lik
Evan Stade
2012/07/27 03:06:54
IsShowing() refers to the goal state actually, so
Peter Kasting
2012/07/27 03:38:03
Awesome!
| |
| 591 slide_animation_.Hide(); | |
| 592 else | |
| 593 slide_animation_.Show(); | |
| 594 } | |
| 595 | |
| 596 void IssueAdviceView::AnimationProgressed(const ui::Animation* animation) { | |
| 597 DCHECK_EQ(animation, &slide_animation_); | |
| 598 | |
| 599 if (details_view_) | |
| 600 details_view_->AnimateToState(animation->GetCurrentValue()); | |
| 601 | |
| 602 if (arrow_view_) { | |
| 603 ui::Transform rotate; | |
| 604 if (animation->GetCurrentValue() != 0.0) { | |
| 605 rotate.SetTranslate(-arrow_view_->width() / 2.0, | |
| 606 -arrow_view_->height() / 2.0); | |
| 607 rotate.ConcatRotate(animation->GetCurrentValue() * 90); | |
| 608 rotate.ConcatTranslate(arrow_view_->width() / 2.0, | |
| 609 arrow_view_->height() / 2.0); | |
| 610 } | |
| 611 arrow_view_->SetTransform(rotate); | |
| 612 } | |
| 613 } | |
| 614 | |
| 615 void IssueAdviceView::ChildPreferredSizeChanged(views::View* child) { | |
| 616 owner_->SizeToContents(); | |
| 617 } | |
| OLD | NEW |