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 "chrome/browser/ui/views/extensions/extension_installed_bubble_view.h" | 5 #include "chrome/browser/ui/views/extensions/extension_installed_bubble_view.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/metrics/user_metrics_action.h" | 11 #include "base/metrics/user_metrics_action.h" |
| 12 #include "chrome/browser/extensions/extension_action_manager.h" | 12 #include "chrome/browser/extensions/extension_action_manager.h" |
| 13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 14 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
| 15 #include "chrome/browser/ui/browser_window.h" | 15 #include "chrome/browser/ui/browser_window.h" |
| 16 #include "chrome/browser/ui/chrome_pages.h" | 16 #include "chrome/browser/ui/chrome_pages.h" |
| 17 #include "chrome/browser/ui/singleton_tabs.h" | 17 #include "chrome/browser/ui/singleton_tabs.h" |
| 18 #include "chrome/browser/ui/views/frame/browser_view.h" | 18 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 19 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" | 19 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" |
| 20 #include "chrome/browser/ui/views/location_bar/location_icon_view.h" | |
| 20 #include "chrome/browser/ui/views/location_bar/page_action_with_badge_view.h" | 21 #include "chrome/browser/ui/views/location_bar/page_action_with_badge_view.h" |
| 21 #include "chrome/browser/ui/views/sync/bubble_sync_promo_view.h" | 22 #include "chrome/browser/ui/views/sync/bubble_sync_promo_view.h" |
| 22 #include "chrome/browser/ui/views/toolbar/app_menu_button.h" | 23 #include "chrome/browser/ui/views/toolbar/app_menu_button.h" |
| 23 #include "chrome/browser/ui/views/toolbar/browser_actions_container.h" | 24 #include "chrome/browser/ui/views/toolbar/browser_actions_container.h" |
| 24 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" | 25 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" |
| 25 #include "chrome/common/url_constants.h" | 26 #include "chrome/common/url_constants.h" |
| 26 #include "chrome/grit/chromium_strings.h" | 27 #include "chrome/grit/chromium_strings.h" |
| 27 #include "chrome/grit/generated_resources.h" | 28 #include "chrome/grit/generated_resources.h" |
| 28 #include "components/bubble/bubble_controller.h" | 29 #include "components/bubble/bubble_controller.h" |
| 29 #include "components/bubble/bubble_ui.h" | 30 #include "components/bubble/bubble_ui.h" |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 106 private: | 107 private: |
| 107 views::Label* heading_; | 108 views::Label* heading_; |
| 108 views::LabelButton* close_; | 109 views::LabelButton* close_; |
| 109 | 110 |
| 110 DISALLOW_COPY_AND_ASSIGN(HeadingAndCloseButtonView); | 111 DISALLOW_COPY_AND_ASSIGN(HeadingAndCloseButtonView); |
| 111 }; | 112 }; |
| 112 | 113 |
| 113 } // namespace | 114 } // namespace |
| 114 | 115 |
| 115 ExtensionInstalledBubbleView::ExtensionInstalledBubbleView( | 116 ExtensionInstalledBubbleView::ExtensionInstalledBubbleView( |
| 116 ExtensionInstalledBubble* bubble, | 117 ExtensionInstalledBubble* controller) |
| 117 BubbleReference bubble_reference) | 118 : BubbleDialogDelegateView(nullptr, |
| 118 : bubble_(bubble), | 119 controller->anchor_position() == |
| 119 bubble_reference_(bubble_reference), | 120 ExtensionInstalledBubble::ANCHOR_OMNIBOX |
| 120 extension_(bubble->extension()), | 121 ? views::BubbleBorder::TOP_LEFT |
| 121 browser_(bubble->browser()), | 122 : views::BubbleBorder::TOP_RIGHT), |
| 122 type_(bubble->type()), | 123 controller_(controller), |
| 123 anchor_position_(bubble->anchor_position()), | |
| 124 close_(nullptr), | 124 close_(nullptr), |
| 125 manage_shortcut_(nullptr) {} | 125 manage_shortcut_(nullptr) {} |
| 126 | 126 |
| 127 ExtensionInstalledBubbleView::~ExtensionInstalledBubbleView() {} | 127 ExtensionInstalledBubbleView::~ExtensionInstalledBubbleView() {} |
| 128 | 128 |
| 129 void ExtensionInstalledBubbleView::UpdateAnchorView() { | 129 void ExtensionInstalledBubbleView::UpdateAnchorView() { |
|
msw
2016/04/07 21:48:57
nit q: Should this function also update the arrow?
Evan Stade
2016/04/07 22:19:15
I don't think that can change (because the control
msw
2016/04/07 22:30:58
Acknowledged.
| |
| 130 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser_); | 130 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser()); |
| 131 | 131 |
| 132 views::View* reference_view = nullptr; | 132 views::View* reference_view = nullptr; |
| 133 switch (anchor_position_) { | 133 switch (controller_->anchor_position()) { |
| 134 case ExtensionInstalledBubble::ANCHOR_BROWSER_ACTION: { | 134 case ExtensionInstalledBubble::ANCHOR_BROWSER_ACTION: { |
| 135 BrowserActionsContainer* container = | 135 BrowserActionsContainer* container = |
| 136 browser_view->GetToolbarView()->browser_actions(); | 136 browser_view->GetToolbarView()->browser_actions(); |
| 137 // Hitting this DCHECK means |ShouldShow| failed. | 137 // Hitting this DCHECK means |ShouldShow| failed. |
| 138 DCHECK(!container->animating()); | 138 DCHECK(!container->animating()); |
| 139 | 139 |
| 140 reference_view = container->GetViewForId(extension_->id()); | 140 reference_view = container->GetViewForId(controller_->extension()->id()); |
| 141 // If the view is not visible then it is in the chevron, so point the | 141 // If the view is not visible then it is in the chevron, so point the |
| 142 // install bubble to the chevron instead. If this is an incognito window, | 142 // install bubble to the chevron instead. If this is an incognito window, |
| 143 // both could be invisible. | 143 // both could be invisible. |
| 144 if (!reference_view || !reference_view->visible()) { | 144 if (!reference_view || !reference_view->visible()) { |
| 145 reference_view = container->chevron(); | 145 reference_view = container->chevron(); |
| 146 if (!reference_view || !reference_view->visible()) | 146 if (!reference_view || !reference_view->visible()) |
| 147 reference_view = nullptr; // fall back to app menu below. | 147 reference_view = nullptr; // fall back to app menu below. |
| 148 } | 148 } |
| 149 break; | 149 break; |
| 150 } | 150 } |
| 151 case ExtensionInstalledBubble::ANCHOR_PAGE_ACTION: { | 151 case ExtensionInstalledBubble::ANCHOR_PAGE_ACTION: { |
| 152 LocationBarView* location_bar_view = browser_view->GetLocationBarView(); | 152 LocationBarView* location_bar_view = browser_view->GetLocationBarView(); |
| 153 ExtensionAction* page_action = | 153 ExtensionAction* page_action = |
| 154 extensions::ExtensionActionManager::Get(browser_->profile()) | 154 extensions::ExtensionActionManager::Get(browser()->profile()) |
| 155 ->GetPageAction(*extension_); | 155 ->GetPageAction(*controller_->extension()); |
| 156 location_bar_view->SetPreviewEnabledPageAction(page_action, | 156 location_bar_view->SetPreviewEnabledPageAction(page_action, |
| 157 true); // preview_enabled | 157 true); // preview_enabled |
| 158 reference_view = location_bar_view->GetPageActionView(page_action); | 158 reference_view = location_bar_view->GetPageActionView(page_action); |
| 159 DCHECK(reference_view); | 159 DCHECK(reference_view); |
| 160 break; | 160 break; |
| 161 } | 161 } |
| 162 case ExtensionInstalledBubble::ANCHOR_OMNIBOX: { | 162 case ExtensionInstalledBubble::ANCHOR_OMNIBOX: { |
| 163 LocationBarView* location_bar_view = browser_view->GetLocationBarView(); | 163 reference_view = browser_view->GetLocationBarView()->location_icon_view(); |
| 164 reference_view = location_bar_view; | |
| 165 DCHECK(reference_view); | |
| 166 break; | 164 break; |
| 167 } | 165 } |
| 168 case ExtensionInstalledBubble::ANCHOR_APP_MENU: | 166 case ExtensionInstalledBubble::ANCHOR_APP_MENU: |
| 169 // Will be caught below. | 167 // Will be caught below. |
| 170 break; | 168 break; |
| 171 } | 169 } |
| 172 | 170 |
| 173 // Default case. | 171 // Default case. |
| 174 if (!reference_view) | 172 if (!reference_view) |
| 175 reference_view = browser_view->GetToolbarView()->app_menu_button(); | 173 reference_view = browser_view->GetToolbarView()->app_menu_button(); |
| 176 SetAnchorView(reference_view); | 174 SetAnchorView(reference_view); |
| 177 } | 175 } |
| 178 | 176 |
| 179 views::View* ExtensionInstalledBubbleView::CreateFootnoteView() { | 177 views::View* ExtensionInstalledBubbleView::CreateFootnoteView() { |
| 180 if (!(bubble_->options() & ExtensionInstalledBubble::SIGN_IN_PROMO)) | 178 if (!(controller_->options() & ExtensionInstalledBubble::SIGN_IN_PROMO)) |
| 181 return nullptr; | 179 return nullptr; |
| 182 | 180 |
| 183 return new BubbleSyncPromoView(this, | 181 return new BubbleSyncPromoView(this, |
| 184 IDS_EXTENSION_INSTALLED_SYNC_PROMO_LINK_NEW, | 182 IDS_EXTENSION_INSTALLED_SYNC_PROMO_LINK_NEW, |
| 185 IDS_EXTENSION_INSTALLED_SYNC_PROMO_NEW); | 183 IDS_EXTENSION_INSTALLED_SYNC_PROMO_NEW); |
| 186 } | 184 } |
| 187 | 185 |
| 186 int ExtensionInstalledBubbleView::GetDialogButtons() const { | |
| 187 return ui::DIALOG_BUTTON_NONE; | |
| 188 } | |
| 189 | |
| 188 void ExtensionInstalledBubbleView::WindowClosing() { | 190 void ExtensionInstalledBubbleView::WindowClosing() { |
| 189 if (anchor_position_ == ExtensionInstalledBubble::ANCHOR_PAGE_ACTION) { | 191 if (controller_->anchor_position() == |
| 190 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser_); | 192 ExtensionInstalledBubble::ANCHOR_PAGE_ACTION) { |
| 193 BrowserView* browser_view = | |
| 194 BrowserView::GetBrowserViewForBrowser(browser()); | |
| 191 browser_view->GetLocationBarView()->SetPreviewEnabledPageAction( | 195 browser_view->GetLocationBarView()->SetPreviewEnabledPageAction( |
| 192 extensions::ExtensionActionManager::Get(browser_->profile()) | 196 extensions::ExtensionActionManager::Get(browser()->profile()) |
| 193 ->GetPageAction(*extension_), | 197 ->GetPageAction(*controller_->extension()), |
| 194 false); // preview_enabled | 198 false); // preview_enabled |
| 195 } | 199 } |
| 196 } | 200 } |
| 197 | 201 |
| 198 gfx::Rect ExtensionInstalledBubbleView::GetAnchorRect() const { | |
| 199 // For omnibox keyword bubbles, move the arrow to point to the left edge | |
| 200 // of the omnibox, just to the right of the icon. | |
| 201 if (type_ == ExtensionInstalledBubble::OMNIBOX_KEYWORD) { | |
|
msw
2016/04/07 21:48:57
These bubbles shouldn't point to the left omnibox
Evan Stade
2016/04/07 22:19:15
I accomplished this in a simpler way, see L163
msw
2016/04/07 22:30:59
Ah, I figured this really wanted the left edge, no
| |
| 202 const LocationBarView* location_bar_view = | |
| 203 BrowserView::GetBrowserViewForBrowser(browser_)->GetLocationBarView(); | |
| 204 return gfx::Rect(location_bar_view->GetOmniboxViewOrigin(), | |
| 205 gfx::Size(0, location_bar_view->omnibox_view()->height())); | |
| 206 } | |
| 207 return views::BubbleDelegateView::GetAnchorRect(); | |
| 208 } | |
| 209 | |
| 210 void ExtensionInstalledBubbleView::OnWidgetClosing(views::Widget* widget) { | |
| 211 if (bubble_reference_) { | |
| 212 DCHECK_EQ(widget, GetWidget()); | |
| 213 // A more specific close reason should already be recorded. | |
| 214 // This is the catch-all close reason for this bubble. | |
| 215 bubble_reference_->CloseBubble(BUBBLE_CLOSE_FOCUS_LOST); | |
| 216 } | |
| 217 } | |
| 218 | |
| 219 void ExtensionInstalledBubbleView::OnWidgetActivationChanged( | |
| 220 views::Widget* widget, | |
| 221 bool active) { | |
| 222 if (!active && bubble_reference_ && widget == GetWidget()) | |
| 223 bubble_reference_->CloseBubble(BUBBLE_CLOSE_FOCUS_LOST); | |
| 224 } | |
| 225 | |
| 226 bool ExtensionInstalledBubbleView::AcceleratorPressed( | |
| 227 const ui::Accelerator& accelerator) { | |
| 228 if (!close_on_esc() || accelerator.key_code() != ui::VKEY_ESCAPE) | |
| 229 return false; | |
| 230 DCHECK(bubble_reference_); | |
| 231 bool did_close = bubble_reference_->CloseBubble(BUBBLE_CLOSE_USER_DISMISSED); | |
|
msw
2016/04/07 21:48:57
Was this implementing the close on esc behavior? D
Evan Stade
2016/04/07 22:19:15
DCV handles close on escape.
msw
2016/04/07 22:30:59
Acknowledged.
| |
| 232 DCHECK(did_close); | |
| 233 return true; | |
| 234 } | |
| 235 | |
| 236 void ExtensionInstalledBubbleView::OnSignInLinkClicked() { | 202 void ExtensionInstalledBubbleView::OnSignInLinkClicked() { |
| 237 GetWidget()->Close(); | 203 GetWidget()->Close(); |
| 238 chrome::ShowBrowserSignin( | 204 chrome::ShowBrowserSignin( |
| 239 browser_, | 205 browser(), |
| 240 signin_metrics::AccessPoint::ACCESS_POINT_EXTENSION_INSTALL_BUBBLE); | 206 signin_metrics::AccessPoint::ACCESS_POINT_EXTENSION_INSTALL_BUBBLE); |
| 241 } | 207 } |
| 242 | 208 |
| 243 void ExtensionInstalledBubbleView::ButtonPressed(views::Button* sender, | 209 void ExtensionInstalledBubbleView::ButtonPressed(views::Button* sender, |
| 244 const ui::Event& event) { | 210 const ui::Event& event) { |
| 245 DCHECK_EQ(sender, close_); | 211 DCHECK_EQ(sender, close_); |
| 246 GetWidget()->Close(); | 212 GetWidget()->Close(); |
| 247 } | 213 } |
| 248 | 214 |
| 249 void ExtensionInstalledBubbleView::LinkClicked(views::Link* source, | 215 void ExtensionInstalledBubbleView::LinkClicked(views::Link* source, |
| 250 int event_flags) { | 216 int event_flags) { |
| 251 DCHECK_EQ(manage_shortcut_, source); | 217 DCHECK_EQ(manage_shortcut_, source); |
| 252 GetWidget()->Close(); | 218 GetWidget()->Close(); |
| 253 | 219 |
| 254 std::string configure_url = chrome::kChromeUIExtensionsURL; | 220 std::string configure_url = chrome::kChromeUIExtensionsURL; |
| 255 configure_url += chrome::kExtensionConfigureCommandsSubPage; | 221 configure_url += chrome::kExtensionConfigureCommandsSubPage; |
| 256 chrome::NavigateParams params( | 222 chrome::NavigateParams params( |
| 257 chrome::GetSingletonTabNavigateParams(browser_, GURL(configure_url))); | 223 chrome::GetSingletonTabNavigateParams(browser(), GURL(configure_url))); |
| 258 chrome::Navigate(¶ms); | 224 chrome::Navigate(¶ms); |
| 259 } | 225 } |
| 260 | 226 |
| 261 void ExtensionInstalledBubbleView::InitLayout() { | 227 void ExtensionInstalledBubbleView::Init() { |
| 228 UpdateAnchorView(); | |
| 229 | |
| 262 // The Extension Installed bubble takes on various forms, depending on the | 230 // The Extension Installed bubble takes on various forms, depending on the |
| 263 // type of extension installed. In general, though, they are all similar: | 231 // type of extension installed. In general, though, they are all similar: |
| 264 // | 232 // |
| 265 // ------------------------- | 233 // ------------------------- |
| 266 // | | Heading [X] | | 234 // | | Heading [X] | |
| 267 // | Icon | Info | | 235 // | Icon | Info | |
| 268 // | | Extra info | | 236 // | | Extra info | |
| 269 // ------------------------- | 237 // ------------------------- |
| 270 // | 238 // |
| 271 // Icon and Heading are always shown (as well as the close button). | 239 // Icon and Heading are always shown (as well as the close button). |
| 272 // Info is shown for browser actions, page actions and Omnibox keyword | 240 // Info is shown for browser actions, page actions and Omnibox keyword |
| 273 // extensions and might list keyboard shorcut for the former two types. | 241 // extensions and might list keyboard shorcut for the former two types. |
| 274 // Extra info is... | 242 // Extra info is... |
| 275 // ... for other types, either a description of how to manage the extension | 243 // ... for other types, either a description of how to manage the extension |
| 276 // or a link to configure the keybinding shortcut (if one exists). | 244 // or a link to configure the keybinding shortcut (if one exists). |
| 277 // Extra info can include a promo for signing into sync. | 245 // Extra info can include a promo for signing into sync. |
| 278 | 246 |
| 279 const ExtensionInstalledBubble& bubble = *bubble_; | |
| 280 // The number of rows in the content section of the bubble. | 247 // The number of rows in the content section of the bubble. |
| 281 int main_content_row_count = 1; | 248 int main_content_row_count = 1; |
| 282 if (bubble.options() & ExtensionInstalledBubble::HOW_TO_USE) | 249 if (controller_->options() & ExtensionInstalledBubble::HOW_TO_USE) |
| 283 ++main_content_row_count; | 250 ++main_content_row_count; |
| 284 if (bubble.options() & ExtensionInstalledBubble::SHOW_KEYBINDING) | 251 if (controller_->options() & ExtensionInstalledBubble::SHOW_KEYBINDING) |
| 285 ++main_content_row_count; | 252 ++main_content_row_count; |
| 286 if (bubble.options() & ExtensionInstalledBubble::HOW_TO_MANAGE) | 253 if (controller_->options() & ExtensionInstalledBubble::HOW_TO_MANAGE) |
| 287 ++main_content_row_count; | 254 ++main_content_row_count; |
| 288 | 255 |
| 289 views::GridLayout* layout = new views::GridLayout(this); | 256 views::GridLayout* layout = new views::GridLayout(this); |
| 290 SetLayoutManager(layout); | 257 SetLayoutManager(layout); |
| 291 | 258 |
| 292 const int cs_id = 0; | 259 const int cs_id = 0; |
| 293 | 260 |
| 294 views::ColumnSet* main_cs = layout->AddColumnSet(cs_id); | 261 views::ColumnSet* main_cs = layout->AddColumnSet(cs_id); |
| 295 // Icon column. | 262 // Icon column. |
| 296 main_cs->AddColumn(views::GridLayout::CENTER, views::GridLayout::LEADING, 0, | 263 main_cs->AddColumn(views::GridLayout::CENTER, views::GridLayout::LEADING, 0, |
| 297 views::GridLayout::USE_PREF, 0, 0); | 264 views::GridLayout::USE_PREF, 0, 0); |
| 298 main_cs->AddPaddingColumn(0, views::kUnrelatedControlHorizontalSpacing); | 265 main_cs->AddPaddingColumn(0, views::kUnrelatedControlHorizontalSpacing); |
| 299 // Heading column. | 266 // Heading column. |
| 300 main_cs->AddColumn(views::GridLayout::LEADING, views::GridLayout::LEADING, 0, | 267 main_cs->AddColumn(views::GridLayout::LEADING, views::GridLayout::LEADING, 0, |
| 301 views::GridLayout::FIXED, kRightColumnWidth, 0); | 268 views::GridLayout::FIXED, kRightColumnWidth, 0); |
| 302 | 269 |
| 303 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 270 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 304 const gfx::FontList& font_list = rb.GetFontList(ui::ResourceBundle::BaseFont); | 271 const gfx::FontList& font_list = rb.GetFontList(ui::ResourceBundle::BaseFont); |
| 305 | 272 |
| 306 const SkBitmap& bitmap = bubble.icon(); | 273 const SkBitmap& bitmap = controller_->icon(); |
| 307 // Add the icon (for all options). | 274 // Add the icon (for all options). |
| 308 // Scale down to 43x43, but allow smaller icons (don't scale up). | 275 // Scale down to 43x43, but allow smaller icons (don't scale up). |
| 309 gfx::Size size(bitmap.width(), bitmap.height()); | 276 gfx::Size size(bitmap.width(), bitmap.height()); |
| 310 if (size.width() > kIconSize || size.height() > kIconSize) | 277 if (size.width() > kIconSize || size.height() > kIconSize) |
| 311 size = gfx::Size(kIconSize, kIconSize); | 278 size = gfx::Size(kIconSize, kIconSize); |
| 312 views::ImageView* icon = new views::ImageView(); | 279 views::ImageView* icon = new views::ImageView(); |
| 313 icon->SetImageSize(size); | 280 icon->SetImageSize(size); |
| 314 icon->SetImage(gfx::ImageSkia::CreateFrom1xBitmap(bitmap)); | 281 icon->SetImage(gfx::ImageSkia::CreateFrom1xBitmap(bitmap)); |
| 315 | 282 |
| 316 layout->StartRow(0, cs_id); | 283 layout->StartRow(0, cs_id); |
| 317 layout->AddView(icon, 1, main_content_row_count); | 284 layout->AddView(icon, 1, main_content_row_count); |
| 318 | 285 |
| 319 // Add the heading (for all options). | 286 // Add the heading (for all options). |
| 320 base::string16 extension_name = base::UTF8ToUTF16(extension_->name()); | 287 base::string16 extension_name = |
| 288 base::UTF8ToUTF16(controller_->extension()->name()); | |
| 321 base::i18n::AdjustStringForLocaleDirection(&extension_name); | 289 base::i18n::AdjustStringForLocaleDirection(&extension_name); |
| 322 views::Label* heading = | 290 views::Label* heading = |
| 323 CreateLabel(l10n_util::GetStringFUTF16(IDS_EXTENSION_INSTALLED_HEADING, | 291 CreateLabel(l10n_util::GetStringFUTF16(IDS_EXTENSION_INSTALLED_HEADING, |
| 324 extension_name), | 292 extension_name), |
| 325 rb.GetFontList(ui::ResourceBundle::MediumFont)); | 293 rb.GetFontList(ui::ResourceBundle::MediumFont)); |
| 326 | 294 |
| 327 close_ = views::BubbleFrameView::CreateCloseButton(this); | 295 close_ = views::BubbleFrameView::CreateCloseButton(this); |
| 328 | 296 |
| 329 HeadingAndCloseButtonView* heading_and_close = | 297 HeadingAndCloseButtonView* heading_and_close = |
| 330 new HeadingAndCloseButtonView(heading, close_); | 298 new HeadingAndCloseButtonView(heading, close_); |
| 331 | 299 |
| 332 layout->AddView(heading_and_close); | 300 layout->AddView(heading_and_close); |
| 333 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | 301 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
| 334 | 302 |
| 335 auto add_content_view = [&layout, &cs_id](views::View* view) { | 303 auto add_content_view = [&layout, &cs_id](views::View* view) { |
| 336 layout->StartRow(0, cs_id); | 304 layout->StartRow(0, cs_id); |
| 337 // Skip the icon column. | 305 // Skip the icon column. |
| 338 layout->SkipColumns(1); | 306 layout->SkipColumns(1); |
| 339 layout->AddView(view); | 307 layout->AddView(view); |
| 340 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | 308 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
| 341 }; | 309 }; |
| 342 | 310 |
| 343 if (bubble.options() & ExtensionInstalledBubble::HOW_TO_USE) { | 311 if (controller_->options() & ExtensionInstalledBubble::HOW_TO_USE) { |
| 344 add_content_view(CreateLabel(bubble.GetHowToUseDescription(), font_list)); | 312 add_content_view( |
| 313 CreateLabel(controller_->GetHowToUseDescription(), font_list)); | |
| 345 } | 314 } |
| 346 | 315 |
| 347 if (bubble.options() & ExtensionInstalledBubble::SHOW_KEYBINDING) { | 316 if (controller_->options() & ExtensionInstalledBubble::SHOW_KEYBINDING) { |
| 348 manage_shortcut_ = new views::Link( | 317 manage_shortcut_ = new views::Link( |
| 349 l10n_util::GetStringUTF16(IDS_EXTENSION_INSTALLED_MANAGE_SHORTCUTS)); | 318 l10n_util::GetStringUTF16(IDS_EXTENSION_INSTALLED_MANAGE_SHORTCUTS)); |
| 350 manage_shortcut_->set_listener(this); | 319 manage_shortcut_->set_listener(this); |
| 351 manage_shortcut_->SetUnderline(false); | 320 manage_shortcut_->SetUnderline(false); |
| 352 add_content_view(manage_shortcut_); | 321 add_content_view(manage_shortcut_); |
| 353 } | 322 } |
| 354 | 323 |
| 355 if (bubble.options() & ExtensionInstalledBubble::HOW_TO_MANAGE) { | 324 if (controller_->options() & ExtensionInstalledBubble::HOW_TO_MANAGE) { |
| 356 add_content_view(CreateLabel( | 325 add_content_view(CreateLabel( |
| 357 l10n_util::GetStringUTF16(IDS_EXTENSION_INSTALLED_MANAGE_INFO), | 326 l10n_util::GetStringUTF16(IDS_EXTENSION_INSTALLED_MANAGE_INFO), |
| 358 font_list)); | 327 font_list)); |
| 359 } | 328 } |
| 360 } | 329 } |
| 361 | 330 |
| 362 // Views specific implementation. | 331 // Views specific implementation. |
| 363 bool ExtensionInstalledBubble::ShouldShow() { | 332 bool ExtensionInstalledBubble::ShouldShow() { |
| 364 if (anchor_position() == ANCHOR_BROWSER_ACTION) { | 333 if (anchor_position() == ANCHOR_BROWSER_ACTION) { |
| 365 BrowserActionsContainer* container = | 334 BrowserActionsContainer* container = |
| 366 BrowserView::GetBrowserViewForBrowser(browser()) | 335 BrowserView::GetBrowserViewForBrowser(browser()) |
| 367 ->GetToolbarView() | 336 ->GetToolbarView() |
| 368 ->browser_actions(); | 337 ->browser_actions(); |
| 369 return !container->animating(); | 338 return !container->animating(); |
| 370 } | 339 } |
| 371 return true; | 340 return true; |
| 372 } | 341 } |
| 373 | 342 |
| 343 // NB: This bubble is using the temporarily-deprecated bubble manager interface | |
| 344 // BubbleUi. Do not copy this pattern. | |
| 374 class ExtensionInstalledBubbleUi : public BubbleUi { | 345 class ExtensionInstalledBubbleUi : public BubbleUi { |
| 375 public: | 346 public: |
| 376 explicit ExtensionInstalledBubbleUi(ExtensionInstalledBubble* bubble); | 347 explicit ExtensionInstalledBubbleUi(ExtensionInstalledBubble* bubble); |
| 377 ~ExtensionInstalledBubbleUi() override; | 348 ~ExtensionInstalledBubbleUi() override; |
| 378 | 349 |
| 379 private: | 350 private: |
| 380 // BubbleUi: | 351 // BubbleUi: |
| 381 void Show(BubbleReference bubble_reference) override; | 352 void Show(BubbleReference bubble_reference) override; |
| 382 void Close() override; | 353 void Close() override; |
| 383 void UpdateAnchorPosition() override; | 354 void UpdateAnchorPosition() override; |
| 384 | 355 |
| 385 ExtensionInstalledBubble* bubble_; | 356 ExtensionInstalledBubble* bubble_; |
| 386 ExtensionInstalledBubbleView* delegate_view_; | 357 ExtensionInstalledBubbleView* bubble_view_; |
| 387 | 358 |
| 388 DISALLOW_COPY_AND_ASSIGN(ExtensionInstalledBubbleUi); | 359 DISALLOW_COPY_AND_ASSIGN(ExtensionInstalledBubbleUi); |
| 389 }; | 360 }; |
| 390 | 361 |
| 391 // Implemented here to create the platform specific instance of the BubbleUi. | 362 // Implemented here to create the platform specific instance of the BubbleUi. |
| 392 scoped_ptr<BubbleUi> ExtensionInstalledBubble::BuildBubbleUi() { | 363 scoped_ptr<BubbleUi> ExtensionInstalledBubble::BuildBubbleUi() { |
| 393 return make_scoped_ptr(new ExtensionInstalledBubbleUi(this)); | 364 return make_scoped_ptr(new ExtensionInstalledBubbleUi(this)); |
| 394 } | 365 } |
| 395 | 366 |
| 396 ExtensionInstalledBubbleUi::ExtensionInstalledBubbleUi( | 367 ExtensionInstalledBubbleUi::ExtensionInstalledBubbleUi( |
| 397 ExtensionInstalledBubble* bubble) | 368 ExtensionInstalledBubble* bubble) |
| 398 : bubble_(bubble), delegate_view_(nullptr) { | 369 : bubble_(bubble), bubble_view_(nullptr) { |
| 399 DCHECK(bubble_); | 370 DCHECK(bubble_); |
| 400 } | 371 } |
| 401 | 372 |
| 402 ExtensionInstalledBubbleUi::~ExtensionInstalledBubbleUi() {} | 373 ExtensionInstalledBubbleUi::~ExtensionInstalledBubbleUi() {} |
| 403 | 374 |
| 404 void ExtensionInstalledBubbleUi::Show(BubbleReference bubble_reference) { | 375 void ExtensionInstalledBubbleUi::Show(BubbleReference /*bubble_reference*/) { |
| 405 // Owned by widget. | 376 bubble_view_ = new ExtensionInstalledBubbleView(bubble_); |
| 406 delegate_view_ = new ExtensionInstalledBubbleView(bubble_, bubble_reference); | |
| 407 delegate_view_->UpdateAnchorView(); | |
| 408 | 377 |
| 409 delegate_view_->set_arrow(bubble_->type() == bubble_->OMNIBOX_KEYWORD | 378 views::BubbleDialogDelegateView::CreateBubble(bubble_view_)->Show(); |
| 410 ? views::BubbleBorder::TOP_LEFT | |
| 411 : views::BubbleBorder::TOP_RIGHT); | |
| 412 | |
| 413 delegate_view_->InitLayout(); | |
| 414 | |
| 415 views::BubbleDelegateView::CreateBubble(delegate_view_)->Show(); | |
| 416 content::RecordAction( | 379 content::RecordAction( |
| 417 base::UserMetricsAction("Signin_Impression_FromExtensionInstallBubble")); | 380 base::UserMetricsAction("Signin_Impression_FromExtensionInstallBubble")); |
| 418 } | 381 } |
| 419 | 382 |
| 420 void ExtensionInstalledBubbleUi::Close() { | 383 void ExtensionInstalledBubbleUi::Close() { |
| 421 if (delegate_view_) { | 384 if (bubble_view_) { |
| 422 delegate_view_->GetWidget()->Close(); | 385 bubble_view_->GetWidget()->Close(); |
| 423 delegate_view_ = nullptr; | 386 bubble_view_ = nullptr; |
| 424 } | 387 } |
| 425 } | 388 } |
| 426 | 389 |
| 427 void ExtensionInstalledBubbleUi::UpdateAnchorPosition() { | 390 void ExtensionInstalledBubbleUi::UpdateAnchorPosition() { |
| 428 DCHECK(delegate_view_); | 391 DCHECK(bubble_view_); |
| 429 delegate_view_->UpdateAnchorView(); | 392 bubble_view_->UpdateAnchorView(); |
| 430 } | 393 } |
| OLD | NEW |