OLD | NEW |
---|---|
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_vi ew.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" |
13 #include "ui/views/controls/button/button.h" | 14 #include "ui/views/controls/button/button.h" |
14 #include "ui/views/controls/button/md_text_button.h" | 15 #include "ui/views/controls/button/md_text_button.h" |
15 #include "ui/views/controls/link.h" | |
16 #include "ui/views/layout/grid_layout.h" | 16 #include "ui/views/layout/grid_layout.h" |
17 #include "ui/views/layout/layout_constants.h" | 17 #include "ui/views/layout/layout_constants.h" |
18 | 18 |
19 namespace { | 19 namespace { |
20 | 20 |
21 int GetDesiredBubbleMaxWidth( | 21 int GetDesiredBubbleMaxWidth( |
22 desktop_ios_promotion::PromotionEntryPoint entry_point) { | 22 desktop_ios_promotion::PromotionEntryPoint entry_point) { |
23 if (entry_point == | 23 if (entry_point == |
24 desktop_ios_promotion::PromotionEntryPoint::SAVE_PASSWORD_BUBBLE) { | 24 desktop_ios_promotion::PromotionEntryPoint::SAVE_PASSWORD_BUBBLE) { |
25 return ManagePasswordsBubbleView::kDesiredBubbleWidth; | 25 return ManagePasswordsBubbleView::kDesiredBubbleWidth; |
26 } | 26 } |
27 return 0; | 27 return 0; |
28 } | 28 } |
29 | 29 |
30 } // namespace | 30 } // namespace |
31 | 31 |
32 DesktopIOSPromotionView::DesktopIOSPromotionView( | 32 DesktopIOSPromotionView::DesktopIOSPromotionView( |
33 desktop_ios_promotion::PromotionEntryPoint entry_point) { | 33 DesktopIOSPromotionController* controller) |
34 promotion_controller_ = new DesktopIOSPromotionController(); | 34 : promotion_controller_(controller) { |
35 int bubbleWidth = ::GetDesiredBubbleMaxWidth(entry_point); | 35 controller->SetPromotionView(this); |
36 int bubbleWidth = | |
sky
2017/02/17 19:06:26
bubble_width
mrefaat
2017/02/17 21:53:13
Done.
| |
37 ::GetDesiredBubbleMaxWidth(promotion_controller_->GetEntryPoint()); | |
36 views::GridLayout* layout = new views::GridLayout(this); | 38 views::GridLayout* layout = new views::GridLayout(this); |
37 layout->set_minimum_size(gfx::Size(bubbleWidth, 0)); | 39 layout->set_minimum_size(gfx::Size(bubbleWidth, 0)); |
38 SetLayoutManager(layout); | 40 SetLayoutManager(layout); |
39 send_sms_button_ = views::MdTextButton::CreateSecondaryUiBlueButton( | 41 send_sms_button_ = views::MdTextButton::CreateSecondaryUiBlueButton( |
40 this, l10n_util::GetStringUTF16(IDS_DESKTOP_TO_IOS_PROMO_SEND_TO_PHONE)); | 42 this, l10n_util::GetStringUTF16(IDS_DESKTOP_TO_IOS_PROMO_SEND_TO_PHONE)); |
41 no_button_ = views::MdTextButton::CreateSecondaryUiButton( | 43 no_button_ = views::MdTextButton::CreateSecondaryUiButton( |
42 this, l10n_util::GetStringUTF16(IDS_DESKTOP_TO_IOS_PROMO_NO_THANKS)); | 44 this, l10n_util::GetStringUTF16(IDS_DESKTOP_TO_IOS_PROMO_NO_THANKS)); |
43 | 45 |
44 constexpr int kLabelColumnSet = 1; | 46 constexpr int kLabelColumnSet = 1; |
45 views::ColumnSet* column_set = layout->AddColumnSet(kLabelColumnSet); | 47 views::ColumnSet* column_set = layout->AddColumnSet(kLabelColumnSet); |
48 column_set->AddPaddingColumn(0, views::kPanelHorizMargin); | |
46 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 0, | 49 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 0, |
47 views::GridLayout::FIXED, bubbleWidth, 0); | 50 views::GridLayout::FIXED, bubbleWidth, 0); |
48 | 51 |
49 constexpr int kDoubleButtonColumnSet = 2; | 52 constexpr int kDoubleButtonColumnSet = 2; |
50 column_set = layout->AddColumnSet(kDoubleButtonColumnSet); | 53 column_set = layout->AddColumnSet(kDoubleButtonColumnSet); |
51 column_set->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER, | 54 column_set->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER, |
52 1, views::GridLayout::USE_PREF, 0, 0); | 55 1, views::GridLayout::USE_PREF, 0, 0); |
53 column_set->AddPaddingColumn(0, views::kRelatedButtonHSpacing); | 56 column_set->AddPaddingColumn(0, views::kRelatedButtonHSpacing); |
54 column_set->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER, | 57 column_set->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER, |
55 0, views::GridLayout::USE_PREF, 0, 0); | 58 0, views::GridLayout::USE_PREF, 0, 0); |
56 | 59 |
57 views::Label* label = | 60 views::Label* label = |
58 new views::Label(desktop_ios_promotion::GetPromoBubbleText(entry_point)); | 61 new views::Label(desktop_ios_promotion::GetPromoBubbleText( |
62 promotion_controller_->GetEntryPoint())); | |
63 VLOG(0) << base::UTF8ToUTF16( | |
sky
2017/02/17 00:57:23
Remove this. If you really really want to log, use
mrefaat
2017/02/17 04:31:49
i had it for debugging - forgot to delete it. Than
| |
64 promotion_controller_->GetUsersRecoveryPhoneNumber()); | |
65 recovery_phone_label_ = new views::Label( | |
66 base::UTF8ToUTF16(promotion_controller_->GetUsersRecoveryPhoneNumber())); | |
59 label->SetMultiLine(true); | 67 label->SetMultiLine(true); |
60 label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 68 label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
61 layout->StartRow(0, kLabelColumnSet); | 69 layout->StartRow(0, kLabelColumnSet); |
62 layout->AddView(label); | 70 layout->AddView(label); |
71 layout->StartRow(0, kLabelColumnSet); | |
72 layout->AddView(recovery_phone_label_); | |
63 layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing); | 73 layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing); |
64 layout->StartRow(0, kDoubleButtonColumnSet); | 74 layout->StartRow(0, kDoubleButtonColumnSet); |
65 layout->AddView(send_sms_button_); | 75 layout->AddView(send_sms_button_); |
66 layout->AddView(no_button_); | 76 layout->AddView(no_button_); |
67 | 77 |
68 // TODO(crbug.com/676655): Log impression. | 78 promotion_controller_->OnPromotionShown(); |
69 } | 79 } |
70 | 80 |
81 DesktopIOSPromotionView::~DesktopIOSPromotionView() = default; | |
82 | |
71 void DesktopIOSPromotionView::ButtonPressed(views::Button* sender, | 83 void DesktopIOSPromotionView::ButtonPressed(views::Button* sender, |
72 const ui::Event& event) { | 84 const ui::Event& event) { |
73 if (sender == send_sms_button_) { | 85 if (sender == send_sms_button_) { |
74 promotion_controller_->OnSendSMSClicked(); | 86 promotion_controller_->OnSendSMSClicked(); |
75 } else if (sender == no_button_) { | 87 } else if (sender == no_button_) { |
76 promotion_controller_->OnNoThanksClicked(); | 88 promotion_controller_->OnNoThanksClicked(); |
77 } else { | 89 } else { |
78 NOTREACHED(); | 90 NOTREACHED(); |
79 } | 91 } |
80 GetWidget()->Close(); | 92 GetWidget()->Close(); |
81 } | 93 } |
94 | |
95 void DesktopIOSPromotionView::UpdateRecoveryPhoneLabel() { | |
96 if (recovery_phone_label_) | |
sky
2017/02/17 00:57:23
{}
sky
2017/02/17 00:57:23
Under what circumstances could recovery_phone_labe
mrefaat
2017/02/17 04:31:49
If this was called before the constructor finishes
mrefaat
2017/02/17 04:31:49
Done.
sky
2017/02/17 19:06:25
Initialize recovery_phone_label_ in the member ini
mrefaat
2017/02/17 21:53:13
Done.
| |
97 recovery_phone_label_->SetText(base::UTF8ToUTF16( | |
98 promotion_controller_->GetUsersRecoveryPhoneNumber())); | |
99 } | |
100 | |
101 DesktopIOSPromotion* CreateDesktopIOSPromotionView( | |
102 DesktopIOSPromotionController* controller) { | |
103 return new DesktopIOSPromotionView(controller); | |
104 } | |
OLD | NEW |