Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <algorithm> | 5 #include <algorithm> |
| 6 #include <string> | 6 #include <string> |
| 7 | 7 |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/metrics/user_metrics_action.h" | 10 #include "base/metrics/user_metrics_action.h" |
| 11 #include "chrome/browser/extensions/extension_action_manager.h" | 11 #include "chrome/browser/extensions/extension_action_manager.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
|
msw
2016/04/26 23:44:31
nit: remove
| |
| 13 #include "chrome/browser/ui/browser.h" | 13 #include "chrome/browser/ui/browser.h" |
| 14 #include "chrome/browser/ui/browser_window.h" | 14 #include "chrome/browser/ui/browser_window.h" |
|
msw
2016/04/26 23:44:31
nit: remove?
| |
| 15 #include "chrome/browser/ui/chrome_pages.h" | 15 #include "chrome/browser/ui/chrome_pages.h" |
| 16 #include "chrome/browser/ui/extensions/extension_installed_bubble.h" | 16 #include "chrome/browser/ui/extensions/extension_installed_bubble.h" |
| 17 #include "chrome/browser/ui/singleton_tabs.h" | 17 #include "chrome/browser/ui/singleton_tabs.h" |
| 18 #include "chrome/browser/ui/sync/bubble_sync_promo_delegate.h" | 18 #include "chrome/browser/ui/sync/bubble_sync_promo_delegate.h" |
| 19 #include "chrome/browser/ui/views/frame/browser_view.h" | 19 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 20 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" | 20 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" |
| 21 #include "chrome/browser/ui/views/location_bar/location_icon_view.h" | 21 #include "chrome/browser/ui/views/location_bar/location_icon_view.h" |
|
msw
2016/04/26 23:44:31
nit: remove
Evan Stade
2016/04/27 15:44:09
This one is needed. The rest have been removed.
| |
| 22 #include "chrome/browser/ui/views/location_bar/page_action_with_badge_view.h" | 22 #include "chrome/browser/ui/views/location_bar/page_action_with_badge_view.h" |
| 23 #include "chrome/browser/ui/views/sync/bubble_sync_promo_view.h" | 23 #include "chrome/browser/ui/views/sync/bubble_sync_promo_view.h" |
| 24 #include "chrome/browser/ui/views/toolbar/app_menu_button.h" | 24 #include "chrome/browser/ui/views/toolbar/app_menu_button.h" |
| 25 #include "chrome/browser/ui/views/toolbar/browser_actions_container.h" | 25 #include "chrome/browser/ui/views/toolbar/browser_actions_container.h" |
| 26 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" | 26 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" |
| 27 #include "chrome/common/url_constants.h" | 27 #include "chrome/common/url_constants.h" |
| 28 #include "chrome/grit/chromium_strings.h" | 28 #include "chrome/grit/chromium_strings.h" |
| 29 #include "chrome/grit/generated_resources.h" | 29 #include "chrome/grit/generated_resources.h" |
| 30 #include "components/bubble/bubble_controller.h" | 30 #include "components/bubble/bubble_controller.h" |
| 31 #include "components/bubble/bubble_ui.h" | 31 #include "components/bubble/bubble_ui.h" |
| 32 #include "content/public/browser/user_metrics.h" | 32 #include "content/public/browser/user_metrics.h" |
| 33 #include "extensions/common/extension.h" | 33 #include "extensions/common/extension.h" |
| 34 #include "ui/base/l10n/l10n_util.h" | 34 #include "ui/base/l10n/l10n_util.h" |
| 35 #include "ui/base/resource/resource_bundle.h" | 35 #include "ui/base/resource/resource_bundle.h" |
| 36 #include "ui/gfx/image/image_skia_operations.h" | |
| 36 #include "ui/gfx/render_text.h" | 37 #include "ui/gfx/render_text.h" |
|
msw
2016/04/26 23:44:31
nit: remove
| |
| 37 #include "ui/gfx/text_elider.h" | 38 #include "ui/gfx/text_elider.h" |
|
msw
2016/04/26 23:44:31
nit: remove
| |
| 38 #include "ui/resources/grit/ui_resources.h" | 39 #include "ui/resources/grit/ui_resources.h" |
| 39 #include "ui/views/bubble/bubble_dialog_delegate.h" | 40 #include "ui/views/bubble/bubble_dialog_delegate.h" |
| 40 #include "ui/views/bubble/bubble_frame_view.h" | 41 #include "ui/views/bubble/bubble_frame_view.h" |
|
msw
2016/04/26 23:44:31
nit: remove
| |
| 41 #include "ui/views/controls/button/button.h" | 42 #include "ui/views/controls/button/button.h" |
|
msw
2016/04/26 23:44:31
nit: remove
| |
| 42 #include "ui/views/controls/button/image_button.h" | 43 #include "ui/views/controls/button/image_button.h" |
|
msw
2016/04/26 23:44:31
nit: remove
| |
| 43 #include "ui/views/controls/image_view.h" | 44 #include "ui/views/controls/image_view.h" |
|
msw
2016/04/26 23:44:32
nit: remove
| |
| 44 #include "ui/views/controls/label.h" | 45 #include "ui/views/controls/label.h" |
| 45 #include "ui/views/controls/link.h" | 46 #include "ui/views/controls/link.h" |
| 46 #include "ui/views/controls/link_listener.h" | 47 #include "ui/views/controls/link_listener.h" |
| 47 #include "ui/views/layout/box_layout.h" | 48 #include "ui/views/layout/box_layout.h" |
| 48 #include "ui/views/layout/grid_layout.h" | |
| 49 #include "ui/views/layout/layout_constants.h" | 49 #include "ui/views/layout/layout_constants.h" |
| 50 | 50 |
| 51 using extensions::Extension; | 51 using extensions::Extension; |
| 52 | 52 |
| 53 namespace { | 53 namespace { |
| 54 | 54 |
| 55 const int kIconSize = 43; | 55 const int kIconSize = 43; |
| 56 | 56 |
| 57 const int kRightColumnWidth = 285; | 57 const int kRightColumnWidth = 285; |
| 58 | 58 |
| 59 views::Label* CreateLabel(const base::string16& text, | 59 views::Label* CreateLabel(const base::string16& text, |
| 60 const gfx::FontList& font) { | 60 const gfx::FontList& font) { |
| 61 views::Label* label = new views::Label(text, font); | 61 views::Label* label = new views::Label(text, font); |
| 62 label->SetMultiLine(true); | 62 label->SetMultiLine(true); |
| 63 label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 63 label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 64 label->SizeToFit(kRightColumnWidth); | |
| 64 return label; | 65 return label; |
| 65 } | 66 } |
| 66 | 67 |
| 67 class HeadingAndCloseButtonView : public views::View { | |
| 68 public: | |
| 69 HeadingAndCloseButtonView(views::Label* heading, views::LabelButton* close) | |
| 70 : heading_(heading), close_(close) { | |
| 71 AddChildView(heading_); | |
| 72 AddChildView(close_); | |
| 73 } | |
| 74 ~HeadingAndCloseButtonView() override {} | |
| 75 | |
| 76 void Layout() override { | |
| 77 gfx::Size close_size = close_->GetPreferredSize(); | |
| 78 gfx::Size view_size = size(); | |
| 79 | |
| 80 // Close button is in the upper right and always gets its full desired size. | |
| 81 close_->SetBounds(view_size.width() - close_size.width(), | |
| 82 0, | |
| 83 close_size.width(), | |
| 84 close_size.height()); | |
| 85 // The heading takes up the remaining room (modulo padding). | |
| 86 heading_->SetBounds( | |
| 87 0, | |
| 88 0, | |
| 89 view_size.width() - close_size.width() - | |
| 90 views::kUnrelatedControlHorizontalSpacing, | |
| 91 view_size.height()); | |
| 92 } | |
| 93 | |
| 94 gfx::Size GetPreferredSize() const override { | |
| 95 gfx::Size heading_size = heading_->GetPreferredSize(); | |
| 96 gfx::Size close_size = close_->GetPreferredSize(); | |
| 97 return gfx::Size(kRightColumnWidth, | |
| 98 std::max(heading_size.height(), close_size.height())); | |
| 99 } | |
| 100 | |
| 101 int GetHeightForWidth(int width) const override { | |
| 102 gfx::Size close_size = close_->GetPreferredSize(); | |
| 103 int heading_width = width - views::kUnrelatedControlHorizontalSpacing - | |
| 104 close_size.width(); | |
| 105 return std::max(heading_->GetHeightForWidth(heading_width), | |
| 106 close_size.height()); | |
| 107 } | |
| 108 | |
| 109 private: | |
| 110 views::Label* heading_; | |
| 111 views::LabelButton* close_; | |
| 112 | |
| 113 DISALLOW_COPY_AND_ASSIGN(HeadingAndCloseButtonView); | |
| 114 }; | |
| 115 | |
| 116 // Provides feedback to the user upon successful installation of an | 68 // Provides feedback to the user upon successful installation of an |
| 117 // extension. Depending on the type of extension, the Bubble will | 69 // extension. Depending on the type of extension, the Bubble will |
| 118 // point to: | 70 // point to: |
| 119 // OMNIBOX_KEYWORD-> The omnibox. | 71 // OMNIBOX_KEYWORD-> The omnibox. |
| 120 // BROWSER_ACTION -> The browserAction icon in the toolbar. | 72 // BROWSER_ACTION -> The browserAction icon in the toolbar. |
| 121 // PAGE_ACTION -> A preview of the pageAction icon in the location | 73 // PAGE_ACTION -> A preview of the pageAction icon in the location |
| 122 // bar which is shown while the Bubble is shown. | 74 // bar which is shown while the Bubble is shown. |
| 123 // GENERIC -> The app menu. This case includes pageActions that don't | 75 // GENERIC -> The app menu. This case includes pageActions that don't |
| 124 // specify a default icon. | 76 // specify a default icon. |
| 125 class ExtensionInstalledBubbleView : public BubbleSyncPromoDelegate, | 77 class ExtensionInstalledBubbleView : public BubbleSyncPromoDelegate, |
| 126 public views::BubbleDialogDelegateView, | 78 public views::BubbleDialogDelegateView, |
| 127 public views::ButtonListener, | |
| 128 public views::LinkListener { | 79 public views::LinkListener { |
| 129 public: | 80 public: |
| 130 explicit ExtensionInstalledBubbleView(ExtensionInstalledBubble* bubble); | 81 explicit ExtensionInstalledBubbleView(ExtensionInstalledBubble* bubble); |
| 131 ~ExtensionInstalledBubbleView() override; | 82 ~ExtensionInstalledBubbleView() override; |
| 132 | 83 |
| 133 // Recalculate the anchor position for this bubble. | 84 // Recalculate the anchor position for this bubble. |
| 134 void UpdateAnchorView(); | 85 void UpdateAnchorView(); |
| 135 | 86 |
| 136 void CloseBubble(); | 87 void CloseBubble(); |
| 137 | 88 |
| 138 private: | 89 private: |
| 139 Browser* browser() { return controller_->browser(); } | 90 Browser* browser() { return controller_->browser(); } |
| 140 | 91 |
| 141 // views::BubbleDialogDelegateView: | 92 // views::BubbleDialogDelegateView: |
| 142 void Init() override; | 93 base::string16 GetWindowTitle() const override; |
| 94 gfx::ImageSkia GetWindowIcon() override; | |
| 95 bool ShouldShowWindowIcon() const override; | |
| 96 bool ShouldShowCloseButton() const override; | |
| 143 View* CreateFootnoteView() override; | 97 View* CreateFootnoteView() override; |
| 144 int GetDialogButtons() const override; | 98 int GetDialogButtons() const override; |
| 99 void Init() override; | |
| 145 | 100 |
| 146 // BubbleSyncPromoDelegate: | 101 // BubbleSyncPromoDelegate: |
| 147 void OnSignInLinkClicked() override; | 102 void OnSignInLinkClicked() override; |
| 148 | 103 |
| 149 // views::LinkListener: | 104 // views::LinkListener: |
| 150 void LinkClicked(views::Link* source, int event_flags) override; | 105 void LinkClicked(views::Link* source, int event_flags) override; |
| 151 | 106 |
| 152 // views::ButtonListener: | 107 // Gets the size of the icon, capped at kIconSize. |
| 153 void ButtonPressed(views::Button* sender, const ui::Event& event) override; | 108 gfx::Size GetIconSize() const; |
| 154 | 109 |
| 155 ExtensionInstalledBubble* controller_; | 110 ExtensionInstalledBubble* controller_; |
| 156 ExtensionInstalledBubble::BubbleType type_; | 111 ExtensionInstalledBubble::BubbleType type_; |
| 157 ExtensionInstalledBubble::AnchorPosition anchor_position_; | 112 ExtensionInstalledBubble::AnchorPosition anchor_position_; |
| 158 | 113 |
| 159 // The button to close the bubble. | |
| 160 views::LabelButton* close_; | |
| 161 | |
| 162 // The shortcut to open the manage shortcuts page. | 114 // The shortcut to open the manage shortcuts page. |
| 163 views::Link* manage_shortcut_; | 115 views::Link* manage_shortcut_; |
| 164 | 116 |
| 165 DISALLOW_COPY_AND_ASSIGN(ExtensionInstalledBubbleView); | 117 DISALLOW_COPY_AND_ASSIGN(ExtensionInstalledBubbleView); |
| 166 }; | 118 }; |
| 167 | 119 |
| 168 ExtensionInstalledBubbleView::ExtensionInstalledBubbleView( | 120 ExtensionInstalledBubbleView::ExtensionInstalledBubbleView( |
| 169 ExtensionInstalledBubble* controller) | 121 ExtensionInstalledBubble* controller) |
| 170 : BubbleDialogDelegateView(nullptr, | 122 : BubbleDialogDelegateView(nullptr, |
| 171 controller->anchor_position() == | 123 controller->anchor_position() == |
| 172 ExtensionInstalledBubble::ANCHOR_OMNIBOX | 124 ExtensionInstalledBubble::ANCHOR_OMNIBOX |
| 173 ? views::BubbleBorder::TOP_LEFT | 125 ? views::BubbleBorder::TOP_LEFT |
| 174 : views::BubbleBorder::TOP_RIGHT), | 126 : views::BubbleBorder::TOP_RIGHT), |
| 175 controller_(controller), | 127 controller_(controller), |
| 176 close_(nullptr), | |
| 177 manage_shortcut_(nullptr) {} | 128 manage_shortcut_(nullptr) {} |
| 178 | 129 |
| 179 ExtensionInstalledBubbleView::~ExtensionInstalledBubbleView() {} | 130 ExtensionInstalledBubbleView::~ExtensionInstalledBubbleView() {} |
| 180 | 131 |
| 181 void ExtensionInstalledBubbleView::UpdateAnchorView() { | 132 void ExtensionInstalledBubbleView::UpdateAnchorView() { |
| 182 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser()); | 133 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser()); |
| 183 | 134 |
| 184 views::View* reference_view = nullptr; | 135 views::View* reference_view = nullptr; |
| 185 switch (controller_->anchor_position()) { | 136 switch (controller_->anchor_position()) { |
| 186 case ExtensionInstalledBubble::ANCHOR_BROWSER_ACTION: { | 137 case ExtensionInstalledBubble::ANCHOR_BROWSER_ACTION: { |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 233 BrowserView::GetBrowserViewForBrowser(browser()); | 184 BrowserView::GetBrowserViewForBrowser(browser()); |
| 234 browser_view->GetLocationBarView()->SetPreviewEnabledPageAction( | 185 browser_view->GetLocationBarView()->SetPreviewEnabledPageAction( |
| 235 extensions::ExtensionActionManager::Get(browser()->profile()) | 186 extensions::ExtensionActionManager::Get(browser()->profile()) |
| 236 ->GetPageAction(*controller_->extension()), | 187 ->GetPageAction(*controller_->extension()), |
| 237 false); // preview_enabled | 188 false); // preview_enabled |
| 238 } | 189 } |
| 239 controller_ = nullptr; | 190 controller_ = nullptr; |
| 240 GetWidget()->Close(); | 191 GetWidget()->Close(); |
| 241 } | 192 } |
| 242 | 193 |
| 194 base::string16 ExtensionInstalledBubbleView::GetWindowTitle() const { | |
| 195 // Add the heading (for all options). | |
| 196 base::string16 extension_name = | |
| 197 base::UTF8ToUTF16(controller_->extension()->name()); | |
| 198 base::i18n::AdjustStringForLocaleDirection(&extension_name); | |
| 199 return l10n_util::GetStringFUTF16(IDS_EXTENSION_INSTALLED_HEADING, | |
| 200 extension_name); | |
| 201 } | |
| 202 | |
| 203 gfx::ImageSkia ExtensionInstalledBubbleView::GetWindowIcon() { | |
| 204 const SkBitmap& bitmap = controller_->icon(); | |
| 205 return gfx::ImageSkiaOperations::CreateResizedImage( | |
| 206 gfx::ImageSkia::CreateFrom1xBitmap(bitmap), | |
| 207 skia::ImageOperations::RESIZE_BEST, GetIconSize()); | |
| 208 } | |
| 209 | |
| 210 bool ExtensionInstalledBubbleView::ShouldShowWindowIcon() const { | |
| 211 return true; | |
| 212 } | |
| 213 | |
| 243 views::View* ExtensionInstalledBubbleView::CreateFootnoteView() { | 214 views::View* ExtensionInstalledBubbleView::CreateFootnoteView() { |
| 244 if (!(controller_->options() & ExtensionInstalledBubble::SIGN_IN_PROMO)) | 215 if (!(controller_->options() & ExtensionInstalledBubble::SIGN_IN_PROMO)) |
| 245 return nullptr; | 216 return nullptr; |
| 246 | 217 |
| 247 return new BubbleSyncPromoView(this, | 218 return new BubbleSyncPromoView(this, |
| 248 IDS_EXTENSION_INSTALLED_SYNC_PROMO_LINK_NEW, | 219 IDS_EXTENSION_INSTALLED_SYNC_PROMO_LINK_NEW, |
| 249 IDS_EXTENSION_INSTALLED_SYNC_PROMO_NEW); | 220 IDS_EXTENSION_INSTALLED_SYNC_PROMO_NEW); |
| 250 } | 221 } |
| 251 | 222 |
| 252 int ExtensionInstalledBubbleView::GetDialogButtons() const { | 223 int ExtensionInstalledBubbleView::GetDialogButtons() const { |
| 253 return ui::DIALOG_BUTTON_NONE; | 224 return ui::DIALOG_BUTTON_NONE; |
| 254 } | 225 } |
| 255 | 226 |
| 256 void ExtensionInstalledBubbleView::OnSignInLinkClicked() { | 227 bool ExtensionInstalledBubbleView::ShouldShowCloseButton() const { |
| 257 chrome::ShowBrowserSignin( | 228 return true; |
| 258 browser(), | |
| 259 signin_metrics::AccessPoint::ACCESS_POINT_EXTENSION_INSTALL_BUBBLE); | |
| 260 CloseBubble(); | |
| 261 } | |
| 262 | |
| 263 void ExtensionInstalledBubbleView::ButtonPressed(views::Button* sender, | |
| 264 const ui::Event& event) { | |
| 265 DCHECK_EQ(sender, close_); | |
| 266 CloseBubble(); | |
| 267 } | |
| 268 | |
| 269 void ExtensionInstalledBubbleView::LinkClicked(views::Link* source, | |
| 270 int event_flags) { | |
| 271 DCHECK_EQ(manage_shortcut_, source); | |
| 272 | |
| 273 std::string configure_url = chrome::kChromeUIExtensionsURL; | |
| 274 configure_url += chrome::kExtensionConfigureCommandsSubPage; | |
| 275 chrome::NavigateParams params( | |
| 276 chrome::GetSingletonTabNavigateParams(browser(), GURL(configure_url))); | |
| 277 chrome::Navigate(¶ms); | |
| 278 CloseBubble(); | |
| 279 } | 229 } |
| 280 | 230 |
| 281 void ExtensionInstalledBubbleView::Init() { | 231 void ExtensionInstalledBubbleView::Init() { |
| 232 gfx::Insets insets = margins(); | |
| 233 set_margins(gfx::Insets(0, insets.left(), insets.bottom(), insets.right())); | |
|
msw
2016/04/26 23:44:32
nit: add a explanatory comment (why is this needed
Evan Stade
2016/04/27 15:44:09
Done.
| |
| 234 | |
| 282 UpdateAnchorView(); | 235 UpdateAnchorView(); |
| 283 | 236 |
| 284 // The Extension Installed bubble takes on various forms, depending on the | 237 // The Extension Installed bubble takes on various forms, depending on the |
| 285 // type of extension installed. In general, though, they are all similar: | 238 // type of extension installed. In general, though, they are all similar: |
| 286 // | 239 // |
| 287 // ------------------------- | 240 // ------------------------- |
| 288 // | | Heading [X] | | 241 // | | Heading [X] | |
|
msw
2016/04/26 23:44:31
optional nit: s/Heading/Title/, s/[X]/(x)/
Evan Stade
2016/04/27 15:44:09
Done.
| |
| 289 // | Icon | Info | | 242 // | Icon | Info | |
|
msw
2016/04/26 23:44:32
q: Is this representation of the vertical layout o
Evan Stade
2016/04/27 15:44:09
It already wasn't accurate in the vertical dimensi
| |
| 290 // | | Extra info | | 243 // | | Extra info | |
| 291 // ------------------------- | 244 // ------------------------- |
| 292 // | 245 // |
| 293 // Icon and Heading are always shown (as well as the close button). | 246 // Icon and Heading are always shown (as well as the close button). |
| 294 // Info is shown for browser actions, page actions and Omnibox keyword | 247 // Info is shown for browser actions, page actions and Omnibox keyword |
| 295 // extensions and might list keyboard shorcut for the former two types. | 248 // extensions and might list keyboard shorcut for the former two types. |
| 296 // Extra info is... | 249 // Extra info is... |
| 297 // ... for other types, either a description of how to manage the extension | 250 // ... for other types, either a description of how to manage the extension |
| 298 // or a link to configure the keybinding shortcut (if one exists). | 251 // or a link to configure the keybinding shortcut (if one exists). |
| 299 // Extra info can include a promo for signing into sync. | 252 // Extra info can include a promo for signing into sync. |
| 300 | 253 |
| 301 // The number of rows in the content section of the bubble. | 254 // The number of rows in the content section of the bubble. |
| 302 int main_content_row_count = 1; | 255 int main_content_row_count = 1; |
| 303 if (controller_->options() & ExtensionInstalledBubble::HOW_TO_USE) | 256 if (controller_->options() & ExtensionInstalledBubble::HOW_TO_USE) |
| 304 ++main_content_row_count; | 257 ++main_content_row_count; |
| 305 if (controller_->options() & ExtensionInstalledBubble::SHOW_KEYBINDING) | 258 if (controller_->options() & ExtensionInstalledBubble::SHOW_KEYBINDING) |
| 306 ++main_content_row_count; | 259 ++main_content_row_count; |
| 307 if (controller_->options() & ExtensionInstalledBubble::HOW_TO_MANAGE) | 260 if (controller_->options() & ExtensionInstalledBubble::HOW_TO_MANAGE) |
| 308 ++main_content_row_count; | 261 ++main_content_row_count; |
| 309 | 262 |
| 310 views::GridLayout* layout = new views::GridLayout(this); | 263 std::unique_ptr<views::BoxLayout> layout( |
| 311 SetLayoutManager(layout); | 264 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, |
| 312 | 265 views::kRelatedControlVerticalSpacing)); |
| 313 const int cs_id = 0; | 266 layout->set_inside_border_insets(gfx::Insets( |
|
msw
2016/04/26 23:44:31
nit: add a explanatory comment (why is this needed
Evan Stade
2016/04/27 15:44:09
Done.
| |
| 314 | 267 0, GetIconSize().width() + views::kUnrelatedControlHorizontalSpacing, 0, |
| 315 views::ColumnSet* main_cs = layout->AddColumnSet(cs_id); | 268 0)); |
| 316 // Icon column. | 269 SetLayoutManager(layout.release()); |
| 317 main_cs->AddColumn(views::GridLayout::CENTER, views::GridLayout::LEADING, 0, | |
| 318 views::GridLayout::USE_PREF, 0, 0); | |
| 319 main_cs->AddPaddingColumn(0, views::kUnrelatedControlHorizontalSpacing); | |
| 320 // Heading column. | |
| 321 main_cs->AddColumn(views::GridLayout::LEADING, views::GridLayout::LEADING, 0, | |
| 322 views::GridLayout::FIXED, kRightColumnWidth, 0); | |
| 323 | 270 |
| 324 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 271 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 325 const gfx::FontList& font_list = rb.GetFontList(ui::ResourceBundle::BaseFont); | 272 const gfx::FontList& font_list = rb.GetFontList(ui::ResourceBundle::BaseFont); |
|
msw
2016/04/26 23:44:31
nit: specifying the base font is not necessary for
| |
| 326 | 273 |
| 327 const SkBitmap& bitmap = controller_->icon(); | 274 if (controller_->options() & ExtensionInstalledBubble::HOW_TO_USE) |
| 328 // Add the icon (for all options). | 275 AddChildView(CreateLabel(controller_->GetHowToUseDescription(), font_list)); |
| 329 // Scale down to 43x43, but allow smaller icons (don't scale up). | |
| 330 gfx::Size size(bitmap.width(), bitmap.height()); | |
| 331 if (size.width() > kIconSize || size.height() > kIconSize) | |
| 332 size = gfx::Size(kIconSize, kIconSize); | |
| 333 views::ImageView* icon = new views::ImageView(); | |
| 334 icon->SetImageSize(size); | |
| 335 icon->SetImage(gfx::ImageSkia::CreateFrom1xBitmap(bitmap)); | |
| 336 | |
| 337 layout->StartRow(0, cs_id); | |
| 338 layout->AddView(icon, 1, main_content_row_count); | |
| 339 | |
| 340 // Add the heading (for all options). | |
| 341 base::string16 extension_name = | |
| 342 base::UTF8ToUTF16(controller_->extension()->name()); | |
| 343 base::i18n::AdjustStringForLocaleDirection(&extension_name); | |
| 344 views::Label* heading = | |
| 345 CreateLabel(l10n_util::GetStringFUTF16(IDS_EXTENSION_INSTALLED_HEADING, | |
| 346 extension_name), | |
| 347 rb.GetFontList(ui::ResourceBundle::MediumFont)); | |
| 348 | |
| 349 close_ = views::BubbleFrameView::CreateCloseButton(this); | |
|
msw
2016/04/26 23:44:32
fyi: AppListDialogContainer will be the last exter
| |
| 350 | |
| 351 HeadingAndCloseButtonView* heading_and_close = | |
| 352 new HeadingAndCloseButtonView(heading, close_); | |
| 353 | |
| 354 layout->AddView(heading_and_close); | |
| 355 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | |
| 356 | |
| 357 auto add_content_view = [&layout, &cs_id](views::View* view) { | |
| 358 layout->StartRow(0, cs_id); | |
| 359 // Skip the icon column. | |
| 360 layout->SkipColumns(1); | |
| 361 layout->AddView(view); | |
| 362 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | |
| 363 }; | |
| 364 | |
| 365 if (controller_->options() & ExtensionInstalledBubble::HOW_TO_USE) { | |
| 366 add_content_view( | |
| 367 CreateLabel(controller_->GetHowToUseDescription(), font_list)); | |
| 368 } | |
| 369 | 276 |
| 370 if (controller_->options() & ExtensionInstalledBubble::SHOW_KEYBINDING) { | 277 if (controller_->options() & ExtensionInstalledBubble::SHOW_KEYBINDING) { |
| 371 manage_shortcut_ = new views::Link( | 278 manage_shortcut_ = new views::Link( |
| 372 l10n_util::GetStringUTF16(IDS_EXTENSION_INSTALLED_MANAGE_SHORTCUTS)); | 279 l10n_util::GetStringUTF16(IDS_EXTENSION_INSTALLED_MANAGE_SHORTCUTS)); |
| 373 manage_shortcut_->set_listener(this); | 280 manage_shortcut_->set_listener(this); |
| 374 manage_shortcut_->SetUnderline(false); | 281 manage_shortcut_->SetUnderline(false); |
| 375 add_content_view(manage_shortcut_); | 282 AddChildView(manage_shortcut_); |
| 376 } | 283 } |
| 377 | 284 |
| 378 if (controller_->options() & ExtensionInstalledBubble::HOW_TO_MANAGE) { | 285 if (controller_->options() & ExtensionInstalledBubble::HOW_TO_MANAGE) { |
| 379 add_content_view(CreateLabel( | 286 AddChildView(CreateLabel( |
| 380 l10n_util::GetStringUTF16(IDS_EXTENSION_INSTALLED_MANAGE_INFO), | 287 l10n_util::GetStringUTF16(IDS_EXTENSION_INSTALLED_MANAGE_INFO), |
| 381 font_list)); | 288 font_list)); |
| 382 } | 289 } |
| 383 } | 290 } |
| 384 | 291 |
| 292 void ExtensionInstalledBubbleView::OnSignInLinkClicked() { | |
| 293 chrome::ShowBrowserSignin( | |
| 294 browser(), | |
| 295 signin_metrics::AccessPoint::ACCESS_POINT_EXTENSION_INSTALL_BUBBLE); | |
| 296 CloseBubble(); | |
| 297 } | |
| 298 | |
| 299 void ExtensionInstalledBubbleView::LinkClicked(views::Link* source, | |
| 300 int event_flags) { | |
| 301 DCHECK_EQ(manage_shortcut_, source); | |
| 302 | |
| 303 std::string configure_url = chrome::kChromeUIExtensionsURL; | |
| 304 configure_url += chrome::kExtensionConfigureCommandsSubPage; | |
| 305 chrome::NavigateParams params( | |
| 306 chrome::GetSingletonTabNavigateParams(browser(), GURL(configure_url))); | |
| 307 chrome::Navigate(¶ms); | |
| 308 CloseBubble(); | |
| 309 } | |
| 310 | |
| 311 gfx::Size ExtensionInstalledBubbleView::GetIconSize() const { | |
| 312 const SkBitmap& bitmap = controller_->icon(); | |
| 313 // Scale down to 43x43, but allow smaller icons (don't scale up). | |
| 314 gfx::Size size(bitmap.width(), bitmap.height()); | |
| 315 return size.width() > kIconSize || size.height() > kIconSize | |
| 316 ? gfx::Size(kIconSize, kIconSize) | |
| 317 : size; | |
| 318 } | |
| 319 | |
| 385 // NB: This bubble is using the temporarily-deprecated bubble manager interface | 320 // NB: This bubble is using the temporarily-deprecated bubble manager interface |
| 386 // BubbleUi. Do not copy this pattern. | 321 // BubbleUi. Do not copy this pattern. |
| 387 class ExtensionInstalledBubbleUi : public BubbleUi, | 322 class ExtensionInstalledBubbleUi : public BubbleUi, |
| 388 public views::WidgetObserver { | 323 public views::WidgetObserver { |
| 389 public: | 324 public: |
| 390 explicit ExtensionInstalledBubbleUi(ExtensionInstalledBubble* bubble); | 325 explicit ExtensionInstalledBubbleUi(ExtensionInstalledBubble* bubble); |
| 391 ~ExtensionInstalledBubbleUi() override; | 326 ~ExtensionInstalledBubbleUi() override; |
| 392 | 327 |
| 393 // BubbleUi: | 328 // BubbleUi: |
| 394 void Show(BubbleReference bubble_reference) override; | 329 void Show(BubbleReference bubble_reference) override; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 451 ->browser_actions(); | 386 ->browser_actions(); |
| 452 return !container->animating(); | 387 return !container->animating(); |
| 453 } | 388 } |
| 454 return true; | 389 return true; |
| 455 } | 390 } |
| 456 | 391 |
| 457 // Implemented here to create the platform specific instance of the BubbleUi. | 392 // Implemented here to create the platform specific instance of the BubbleUi. |
| 458 std::unique_ptr<BubbleUi> ExtensionInstalledBubble::BuildBubbleUi() { | 393 std::unique_ptr<BubbleUi> ExtensionInstalledBubble::BuildBubbleUi() { |
| 459 return base::WrapUnique(new ExtensionInstalledBubbleUi(this)); | 394 return base::WrapUnique(new ExtensionInstalledBubbleUi(this)); |
| 460 } | 395 } |
| OLD | NEW |