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

Side by Side Diff: chrome/browser/ui/views/desktop_ios_promotion/desktop_ios_promotion_bubble_view.cc

Issue 2694893002: Integrate SMS service with Desktop iOS promotion (Closed)
Patch Set: change the ownership of desktopioscontroller Created 3 years, 10 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
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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/desktop_ios_promotion/desktop_ios_promotion_vi ew.h" 5 #include "chrome/browser/ui/views/desktop_ios_promotion/desktop_ios_promotion_bu bble_view.h"
6 6
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/browser/profiles/profile.h"
8 #include "chrome/browser/ui/browser.h" 9 #include "chrome/browser/ui/browser.h"
9 #include "chrome/browser/ui/desktop_ios_promotion/desktop_ios_promotion_controll er.h" 10 #include "chrome/browser/ui/desktop_ios_promotion/desktop_ios_promotion_controll er.h"
10 #include "chrome/browser/ui/views/passwords/manage_passwords_bubble_view.h" 11 #include "chrome/browser/ui/views/passwords/manage_passwords_bubble_view.h"
11 #include "chrome/grit/generated_resources.h" 12 #include "chrome/grit/generated_resources.h"
12 #include "ui/base/l10n/l10n_util.h" 13 #include "ui/base/l10n/l10n_util.h"
14 #include "ui/base/resource/resource_bundle.h"
13 #include "ui/views/controls/button/button.h" 15 #include "ui/views/controls/button/button.h"
14 #include "ui/views/controls/button/md_text_button.h" 16 #include "ui/views/controls/button/md_text_button.h"
15 #include "ui/views/controls/link.h"
16 #include "ui/views/layout/grid_layout.h" 17 #include "ui/views/layout/grid_layout.h"
17 #include "ui/views/layout/layout_constants.h" 18 #include "ui/views/layout/layout_constants.h"
18 19
19 namespace { 20 namespace {
20 21
21 int GetDesiredBubbleMaxWidth( 22 int GetDesiredBubbleMaxWidth(
22 desktop_ios_promotion::PromotionEntryPoint entry_point) { 23 desktop_ios_promotion::PromotionEntryPoint entry_point) {
23 if (entry_point == 24 if (entry_point ==
24 desktop_ios_promotion::PromotionEntryPoint::SAVE_PASSWORD_BUBBLE) { 25 desktop_ios_promotion::PromotionEntryPoint::SAVE_PASSWORD_BUBBLE) {
25 return ManagePasswordsBubbleView::kDesiredBubbleWidth; 26 return ManagePasswordsBubbleView::kDesiredBubbleWidth;
26 } 27 }
27 return 0; 28 return 0;
28 } 29 }
29 30
30 } // namespace 31 } // namespace
31 32
32 DesktopIOSPromotionView::DesktopIOSPromotionView( 33 DesktopIOSPromotionBubbleView::DesktopIOSPromotionBubbleView(
33 desktop_ios_promotion::PromotionEntryPoint entry_point) { 34 Profile* profile,
34 promotion_controller_ = new DesktopIOSPromotionController(); 35 desktop_ios_promotion::PromotionEntryPoint entry_point)
35 int bubbleWidth = ::GetDesiredBubbleMaxWidth(entry_point); 36 : recovery_phone_label_(new views::Label()),
37 promotion_controller_(
sky 2017/02/18 16:40:45 I believe you leak this, use a unique_ptr. Now tha
mrefaat 2017/02/18 17:33:14 Done.
38 new DesktopIOSPromotionController(profile, entry_point)) {
39 promotion_controller_->SetPromotionView(this);
40 int bubble_width =
41 ::GetDesiredBubbleMaxWidth(promotion_controller_->entry_point());
36 views::GridLayout* layout = new views::GridLayout(this); 42 views::GridLayout* layout = new views::GridLayout(this);
37 layout->set_minimum_size(gfx::Size(bubbleWidth, 0)); 43 layout->set_minimum_size(gfx::Size(bubble_width, 0));
38 SetLayoutManager(layout); 44 SetLayoutManager(layout);
39 send_sms_button_ = views::MdTextButton::CreateSecondaryUiBlueButton( 45 send_sms_button_ = views::MdTextButton::CreateSecondaryUiBlueButton(
40 this, l10n_util::GetStringUTF16(IDS_DESKTOP_TO_IOS_PROMO_SEND_TO_PHONE)); 46 this, l10n_util::GetStringUTF16(IDS_DESKTOP_TO_IOS_PROMO_SEND_TO_PHONE));
41 no_button_ = views::MdTextButton::CreateSecondaryUiButton( 47 no_button_ = views::MdTextButton::CreateSecondaryUiButton(
42 this, l10n_util::GetStringUTF16(IDS_DESKTOP_TO_IOS_PROMO_NO_THANKS)); 48 this, l10n_util::GetStringUTF16(IDS_DESKTOP_TO_IOS_PROMO_NO_THANKS));
43 49
44 constexpr int kLabelColumnSet = 1; 50 constexpr int kLabelColumnSet = 1;
45 views::ColumnSet* column_set = layout->AddColumnSet(kLabelColumnSet); 51 views::ColumnSet* column_set = layout->AddColumnSet(kLabelColumnSet);
52 column_set->AddPaddingColumn(0, 8);
46 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 0, 53 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 0,
47 views::GridLayout::FIXED, bubbleWidth, 0); 54 views::GridLayout::FIXED, bubble_width, 0);
48 55
49 constexpr int kDoubleButtonColumnSet = 2; 56 constexpr int kDoubleButtonColumnSet = 2;
50 column_set = layout->AddColumnSet(kDoubleButtonColumnSet); 57 column_set = layout->AddColumnSet(kDoubleButtonColumnSet);
51 column_set->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER, 58 column_set->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER,
52 1, views::GridLayout::USE_PREF, 0, 0); 59 1, views::GridLayout::USE_PREF, 0, 0);
53 column_set->AddPaddingColumn(0, views::kRelatedButtonHSpacing); 60 column_set->AddPaddingColumn(0, views::kRelatedButtonHSpacing);
54 column_set->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER, 61 column_set->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER,
55 0, views::GridLayout::USE_PREF, 0, 0); 62 0, views::GridLayout::USE_PREF, 0, 0);
56 63 constexpr int kPhoneNumberColumnSet = 3;
64 column_set = layout->AddColumnSet(kPhoneNumberColumnSet);
65 column_set->AddPaddingColumn(0, 32);
66 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 0,
67 views::GridLayout::FIXED, bubble_width, 0);
57 views::Label* label = 68 views::Label* label =
58 new views::Label(desktop_ios_promotion::GetPromoBubbleText(entry_point)); 69 new views::Label(desktop_ios_promotion::GetPromoBubbleText(
70 promotion_controller_->entry_point()));
71 label->SetEnabledColor(SK_ColorGRAY);
59 label->SetMultiLine(true); 72 label->SetMultiLine(true);
60 label->SetHorizontalAlignment(gfx::ALIGN_LEFT); 73 label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
61 layout->StartRow(0, kLabelColumnSet); 74 layout->StartRow(0, kLabelColumnSet);
62 layout->AddView(label); 75 layout->AddView(label);
76 layout->StartRow(0, kPhoneNumberColumnSet);
77 UpdateRecoveryPhoneLabel();
78 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance();
79 recovery_phone_label_->SetFontList(
80 rb->GetFontList(ui::ResourceBundle::BoldFont));
81 recovery_phone_label_->SetEnabledColor(SK_ColorGRAY);
82 recovery_phone_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
83 layout->AddView(recovery_phone_label_);
63 layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing); 84 layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing);
64 layout->StartRow(0, kDoubleButtonColumnSet); 85 layout->StartRow(0, kDoubleButtonColumnSet);
65 layout->AddView(send_sms_button_); 86 layout->AddView(send_sms_button_);
66 layout->AddView(no_button_); 87 layout->AddView(no_button_);
67 88
68 // TODO(crbug.com/676655): Log impression. 89 promotion_controller_->OnPromotionShown();
69 } 90 }
70 91
71 void DesktopIOSPromotionView::ButtonPressed(views::Button* sender, 92 DesktopIOSPromotionBubbleView::~DesktopIOSPromotionBubbleView() = default;
72 const ui::Event& event) { 93
94 void DesktopIOSPromotionBubbleView::ButtonPressed(views::Button* sender,
95 const ui::Event& event) {
73 if (sender == send_sms_button_) { 96 if (sender == send_sms_button_) {
74 promotion_controller_->OnSendSMSClicked(); 97 promotion_controller_->OnSendSMSClicked();
75 } else if (sender == no_button_) { 98 } else if (sender == no_button_) {
76 promotion_controller_->OnNoThanksClicked(); 99 promotion_controller_->OnNoThanksClicked();
77 } else { 100 } else {
78 NOTREACHED(); 101 NOTREACHED();
79 } 102 }
80 GetWidget()->Close(); 103 GetWidget()->Close();
81 } 104 }
105
106 void DesktopIOSPromotionBubbleView::UpdateRecoveryPhoneLabel() {
107 recovery_phone_label_->SetText(
108 base::UTF8ToUTF16(promotion_controller_->GetUsersRecoveryPhoneNumber()));
109 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698