Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/autofill/save_card_icon_view.h" | 5 #include "chrome/browser/ui/views/autofill/save_card_icon_view.h" |
| 6 | 6 |
| 7 #include "chrome/app/chrome_command_ids.h" | 7 #include "chrome/app/chrome_command_ids.h" |
| 8 #include "chrome/browser/ui/autofill/save_card_bubble_controller_impl.h" | 8 #include "chrome/browser/ui/autofill/save_card_bubble_controller_impl.h" |
| 9 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
| 10 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 10 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 11 #include "chrome/browser/ui/view_ids.h" | 11 #include "chrome/browser/ui/view_ids.h" |
| 12 #include "chrome/browser/ui/views/autofill/save_card_bubble_views.h" | 12 #include "chrome/browser/ui/views/autofill/save_card_bubble_views.h" |
| 13 #include "chrome/grit/generated_resources.h" | 13 #include "chrome/grit/generated_resources.h" |
| 14 #include "ui/base/l10n/l10n_util.h" | 14 #include "ui/base/l10n/l10n_util.h" |
| 15 #include "ui/gfx/vector_icons_public.h" | 15 #include "ui/gfx/vector_icons_public.h" |
| 16 | 16 |
| 17 namespace autofill { | 17 namespace autofill { |
| 18 | 18 |
| 19 SaveCardIconView::SaveCardIconView(CommandUpdater* command_updater, | 19 SaveCardIconView::SaveCardIconView(CommandUpdater* command_updater, |
| 20 Browser* browser) | 20 Browser* browser) |
| 21 : BubbleIconView(command_updater, IDC_SAVE_CREDIT_CARD_FOR_PAGE), | 21 : BubbleIconView(command_updater, IDC_SAVE_CREDIT_CARD_FOR_PAGE), |
| 22 browser_(browser) { | 22 browser_(browser) { |
| 23 set_id(VIEW_ID_SAVE_CREDIT_CARD_BUTTON); | 23 set_id(VIEW_ID_SAVE_CREDIT_CARD_BUTTON); |
| 24 SetTooltipText(l10n_util::GetStringUTF16(IDS_TOOLTIP_SAVE_CREDIT_CARD)); | 24 SetTooltipText(l10n_util::GetStringUTF16(IDS_TOOLTIP_SAVE_CREDIT_CARD)); |
| 25 if (browser) | |
| 26 browser->tab_strip_model()->AddObserver(this); | |
| 25 } | 27 } |
| 26 | 28 |
| 27 SaveCardIconView::~SaveCardIconView() {} | 29 SaveCardIconView::~SaveCardIconView() {} |
| 28 | 30 |
| 29 void SaveCardIconView::OnExecuting( | 31 void SaveCardIconView::OnExecuting( |
| 30 BubbleIconView::ExecuteSource execute_source) {} | 32 BubbleIconView::ExecuteSource execute_source) {} |
| 31 | 33 |
| 34 bool SaveCardIconView::OnMousePressed(const ui::MouseEvent& event) { | |
|
Evan Stade
2016/01/11 18:05:24
BubbleIconView handles more than just mouses, it a
Justin Donnelly
2016/01/11 19:32:37
Understood.
| |
| 35 bool result = BubbleIconView::OnMousePressed(event); | |
| 36 | |
| 37 SaveCardBubbleControllerImpl* controller = GetController(); | |
| 38 if (controller) | |
| 39 controller->HideBubble(); | |
| 40 | |
| 41 return result; | |
| 42 } | |
| 43 | |
| 32 views::BubbleDelegateView* SaveCardIconView::GetBubble() const { | 44 views::BubbleDelegateView* SaveCardIconView::GetBubble() const { |
| 33 if (!browser_) | 45 SaveCardBubbleControllerImpl* controller = GetController(); |
| 34 return nullptr; | |
| 35 content::WebContents* web_contents = | |
| 36 browser_->tab_strip_model()->GetActiveWebContents(); | |
| 37 if (!web_contents) | |
| 38 return nullptr; | |
| 39 autofill::SaveCardBubbleControllerImpl* controller = | |
| 40 autofill::SaveCardBubbleControllerImpl::FromWebContents(web_contents); | |
| 41 if (!controller) | 46 if (!controller) |
| 42 return nullptr; | 47 return nullptr; |
| 43 | 48 |
| 44 return static_cast<autofill::SaveCardBubbleViews*>( | 49 return static_cast<autofill::SaveCardBubbleViews*>( |
| 45 controller->save_card_bubble_view()); | 50 controller->save_card_bubble_view()); |
| 46 } | 51 } |
| 47 | 52 |
| 48 gfx::VectorIconId SaveCardIconView::GetVectorIcon() const { | 53 gfx::VectorIconId SaveCardIconView::GetVectorIcon() const { |
| 49 return gfx::VectorIconId::CREDIT_CARD; | 54 return gfx::VectorIconId::CREDIT_CARD; |
| 50 } | 55 } |
| 51 | 56 |
| 57 void SaveCardIconView::TabDeactivated(content::WebContents* contents) { | |
| 58 SaveCardBubbleControllerImpl* controller = GetController(); | |
| 59 if (controller) | |
| 60 controller->HideBubble(); | |
| 61 } | |
| 62 | |
| 63 SaveCardBubbleControllerImpl* SaveCardIconView::GetController() const { | |
| 64 if (!browser_) | |
| 65 return nullptr; | |
| 66 content::WebContents* web_contents = | |
| 67 browser_->tab_strip_model()->GetActiveWebContents(); | |
| 68 if (!web_contents) | |
| 69 return nullptr; | |
| 70 return autofill::SaveCardBubbleControllerImpl::FromWebContents(web_contents); | |
| 71 } | |
| 72 | |
| 52 } // namespace autofill | 73 } // namespace autofill |
| OLD | NEW |