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_bubble_views.h" | 5 #include "chrome/browser/ui/views/autofill/save_card_bubble_views.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 25 #include "ui/views/layout/box_layout.h" | 25 #include "ui/views/layout/box_layout.h" |
| 26 #include "ui/views/layout/layout_constants.h" | 26 #include "ui/views/layout/layout_constants.h" |
| 27 | 27 |
| 28 namespace autofill { | 28 namespace autofill { |
| 29 | 29 |
| 30 namespace { | 30 namespace { |
| 31 | 31 |
| 32 // Fixed width of the bubble. | 32 // Fixed width of the bubble. |
| 33 const int kBubbleWidth = 395; | 33 const int kBubbleWidth = 395; |
| 34 | 34 |
| 35 // TODO(bondd): BubbleManager will eventually move this logic somewhere else, | |
| 36 // and then kIsOkButtonOnLeftSide can be removed from here and | |
| 37 // dialog_client_view.cc. | |
| 38 #if defined(OS_WIN) || defined(OS_CHROMEOS) | |
| 39 const bool kIsOkButtonOnLeftSide = true; | |
| 40 #else | |
| 41 const bool kIsOkButtonOnLeftSide = false; | |
| 42 #endif | |
| 43 | |
| 44 scoped_ptr<views::StyledLabel> CreateLegalMessageLineLabel( | 35 scoped_ptr<views::StyledLabel> CreateLegalMessageLineLabel( |
| 45 const LegalMessageLine& line, | 36 const LegalMessageLine& line, |
| 46 views::StyledLabelListener* listener) { | 37 views::StyledLabelListener* listener) { |
| 47 scoped_ptr<views::StyledLabel> label( | 38 scoped_ptr<views::StyledLabel> label( |
| 48 new views::StyledLabel(line.text(), listener)); | 39 new views::StyledLabel(line.text(), listener)); |
| 49 for (const LegalMessageLine::Link& link : line.links()) { | 40 for (const LegalMessageLine::Link& link : line.links()) { |
| 50 label->AddStyleRange(link.range, | 41 label->AddStyleRange(link.range, |
| 51 views::StyledLabel::RangeStyleInfo::CreateForLink()); | 42 views::StyledLabel::RangeStyleInfo::CreateForLink()); |
| 52 } | 43 } |
| 53 return label; | 44 return label; |
| 54 } | 45 } |
| 55 | 46 |
| 56 } // namespace | 47 } // namespace |
| 57 | 48 |
| 58 SaveCardBubbleViews::SaveCardBubbleViews(views::View* anchor_view, | 49 SaveCardBubbleViews::SaveCardBubbleViews(views::View* anchor_view, |
| 59 content::WebContents* web_contents, | 50 content::WebContents* web_contents, |
| 60 SaveCardBubbleController* controller) | 51 SaveCardBubbleController* controller) |
| 61 : LocationBarBubbleDelegateView(anchor_view, web_contents), | 52 : LocationBarBubbleDelegateView(anchor_view, web_contents), |
| 62 controller_(controller), | 53 controller_(controller), |
| 63 save_button_(nullptr), | |
| 64 cancel_button_(nullptr), | |
| 65 learn_more_link_(nullptr) { | 54 learn_more_link_(nullptr) { |
| 66 DCHECK(controller); | 55 DCHECK(controller); |
| 67 views::BubbleDelegateView::CreateBubble(this); | 56 views::BubbleDialogDelegateView::CreateBubble(this); |
| 68 } | 57 } |
| 69 | 58 |
| 70 SaveCardBubbleViews::~SaveCardBubbleViews() {} | 59 SaveCardBubbleViews::~SaveCardBubbleViews() {} |
| 71 | 60 |
| 72 void SaveCardBubbleViews::Show(DisplayReason reason) { | 61 void SaveCardBubbleViews::Show(DisplayReason reason) { |
| 73 ShowForReason(reason); | 62 ShowForReason(reason); |
| 74 } | 63 } |
| 75 | 64 |
| 76 void SaveCardBubbleViews::Hide() { | 65 void SaveCardBubbleViews::Hide() { |
| 77 controller_ = nullptr; | 66 controller_ = nullptr; |
| 78 Close(); | 67 Close(); |
| 79 } | 68 } |
| 80 | 69 |
| 70 views::View* SaveCardBubbleViews::CreateExtraView() { | |
| 71 if (!learn_more_link_) { | |
| 72 learn_more_link_ = | |
| 73 new views::Link(l10n_util::GetStringUTF16(IDS_LEARN_MORE)); | |
| 74 learn_more_link_->SetUnderline(false); | |
| 75 learn_more_link_->set_listener(this); | |
| 76 } | |
| 77 return learn_more_link_; | |
| 78 } | |
| 79 | |
| 81 views::View* SaveCardBubbleViews::CreateFootnoteView() { | 80 views::View* SaveCardBubbleViews::CreateFootnoteView() { |
| 82 if (controller_->GetLegalMessageLines().empty()) | 81 if (controller_->GetLegalMessageLines().empty()) |
| 83 return nullptr; | 82 return nullptr; |
| 84 | 83 |
| 85 // Use BoxLayout to provide insets around the label. | 84 // Use BoxLayout to provide insets around the label. |
| 86 View* view = new View(); | 85 View* view = new View(); |
| 87 view->SetLayoutManager( | 86 view->SetLayoutManager( |
| 88 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); | 87 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); |
| 89 | 88 |
| 90 // Add a StyledLabel for each line of the legal message. | 89 // Add a StyledLabel for each line of the legal message. |
| 91 for (const LegalMessageLine& line : controller_->GetLegalMessageLines()) | 90 for (const LegalMessageLine& line : controller_->GetLegalMessageLines()) |
| 92 view->AddChildView(CreateLegalMessageLineLabel(line, this).release()); | 91 view->AddChildView(CreateLegalMessageLineLabel(line, this).release()); |
| 93 | 92 |
| 94 return view; | 93 return view; |
| 95 } | 94 } |
| 96 | 95 |
| 96 bool SaveCardBubbleViews::Accept() { | |
| 97 controller_->OnSaveButton(); | |
| 98 return true; | |
|
msw
2016/03/03 23:01:39
nit: maybe return LocationBarBubbleDelegateView::A
Evan Stade
2016/03/07 18:36:38
I don't think that's right. This seems like a situ
| |
| 99 } | |
| 100 | |
| 101 bool SaveCardBubbleViews::Cancel() { | |
| 102 controller_->OnCancelButton(); | |
| 103 return true; | |
|
msw
2016/03/03 23:01:39
nit: maybe return LocationBarBubbleDelegateView::C
Evan Stade
2016/03/07 18:36:38
ditto
| |
| 104 } | |
| 105 | |
| 106 int SaveCardBubbleViews::GetDialogButtons() const { | |
| 107 // This is the default for BubbleDialogDelegateView, but it's not the default | |
| 108 // for LocationBarBubbleDelegateView. | |
| 109 return ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL; | |
| 110 } | |
| 111 | |
| 112 base::string16 SaveCardBubbleViews::GetDialogButtonLabel( | |
| 113 ui::DialogButton button) const { | |
| 114 return l10n_util::GetStringUTF16(button == ui::DIALOG_BUTTON_OK | |
| 115 ? IDS_AUTOFILL_SAVE_CARD_PROMPT_ACCEPT | |
| 116 : IDS_AUTOFILL_SAVE_CARD_PROMPT_DENY); | |
| 117 } | |
| 118 | |
| 119 bool SaveCardBubbleViews::ShouldDefaultButtonBeBlue() const { | |
| 120 return true; | |
| 121 } | |
| 122 | |
| 97 gfx::Size SaveCardBubbleViews::GetPreferredSize() const { | 123 gfx::Size SaveCardBubbleViews::GetPreferredSize() const { |
| 98 return gfx::Size(kBubbleWidth, GetHeightForWidth(kBubbleWidth)); | 124 return gfx::Size(kBubbleWidth, GetHeightForWidth(kBubbleWidth)); |
| 99 } | 125 } |
| 100 | 126 |
| 101 views::View* SaveCardBubbleViews::GetInitiallyFocusedView() { | |
| 102 return save_button_; | |
| 103 } | |
| 104 | |
| 105 base::string16 SaveCardBubbleViews::GetWindowTitle() const { | 127 base::string16 SaveCardBubbleViews::GetWindowTitle() const { |
| 106 return controller_->GetWindowTitle(); | 128 return controller_->GetWindowTitle(); |
| 107 } | 129 } |
| 108 | 130 |
| 109 void SaveCardBubbleViews::WindowClosing() { | 131 void SaveCardBubbleViews::WindowClosing() { |
| 110 if (controller_) | 132 if (controller_) |
| 111 controller_->OnBubbleClosed(); | 133 controller_->OnBubbleClosed(); |
| 112 } | 134 } |
| 113 | 135 |
| 114 void SaveCardBubbleViews::ButtonPressed(views::Button* sender, | |
| 115 const ui::Event& event) { | |
| 116 if (sender == save_button_) { | |
| 117 controller_->OnSaveButton(); | |
| 118 } else { | |
| 119 DCHECK_EQ(sender, cancel_button_); | |
| 120 controller_->OnCancelButton(); | |
| 121 } | |
| 122 Close(); | |
| 123 } | |
| 124 | |
| 125 void SaveCardBubbleViews::LinkClicked(views::Link* source, int event_flags) { | 136 void SaveCardBubbleViews::LinkClicked(views::Link* source, int event_flags) { |
| 126 DCHECK_EQ(source, learn_more_link_); | 137 DCHECK_EQ(source, learn_more_link_); |
| 127 controller_->OnLearnMoreClicked(); | 138 controller_->OnLearnMoreClicked(); |
| 128 } | 139 } |
| 129 | 140 |
| 130 void SaveCardBubbleViews::StyledLabelLinkClicked(views::StyledLabel* label, | 141 void SaveCardBubbleViews::StyledLabelLinkClicked(views::StyledLabel* label, |
| 131 const gfx::Range& range, | 142 const gfx::Range& range, |
| 132 int event_flags) { | 143 int event_flags) { |
| 133 // Index of |label| within its parent's view hierarchy is the same as the | 144 // Index of |label| within its parent's view hierarchy is the same as the |
| 134 // legal message line index. DCHECK this assumption to guard against future | 145 // legal message line index. DCHECK this assumption to guard against future |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 182 | 193 |
| 183 // Optionally add label that will contain an explanation for upload. | 194 // Optionally add label that will contain an explanation for upload. |
| 184 base::string16 explanation = controller_->GetExplanatoryMessage(); | 195 base::string16 explanation = controller_->GetExplanatoryMessage(); |
| 185 if (!explanation.empty()) { | 196 if (!explanation.empty()) { |
| 186 views::Label* explanation_label = new views::Label(explanation); | 197 views::Label* explanation_label = new views::Label(explanation); |
| 187 explanation_label->SetMultiLine(true); | 198 explanation_label->SetMultiLine(true); |
| 188 explanation_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 199 explanation_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 189 view->AddChildView(explanation_label); | 200 view->AddChildView(explanation_label); |
| 190 } | 201 } |
| 191 | 202 |
| 192 // Add "learn more" link and accept/cancel buttons. | |
| 193 views::View* button_view = new views::View(); | |
| 194 views::BoxLayout* button_view_layout = new views::BoxLayout( | |
| 195 views::BoxLayout::kHorizontal, 0, 0, views::kRelatedButtonHSpacing); | |
| 196 button_view->SetLayoutManager(button_view_layout); | |
| 197 view->AddChildView(button_view); | |
| 198 | |
| 199 learn_more_link_ = new views::Link(l10n_util::GetStringUTF16(IDS_LEARN_MORE)); | |
| 200 learn_more_link_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
| 201 learn_more_link_->SetUnderline(false); | |
| 202 learn_more_link_->set_listener(this); | |
| 203 button_view->AddChildView(learn_more_link_); | |
| 204 button_view_layout->SetFlexForView(learn_more_link_, 1); | |
| 205 | |
| 206 save_button_ = new views::BlueButton( | |
| 207 this, l10n_util::GetStringUTF16(IDS_AUTOFILL_SAVE_CARD_PROMPT_ACCEPT)); | |
| 208 save_button_->SetIsDefault(true); | |
| 209 | |
| 210 cancel_button_ = new views::LabelButton( | |
| 211 this, l10n_util::GetStringUTF16(IDS_AUTOFILL_SAVE_CARD_PROMPT_DENY)); | |
| 212 cancel_button_->SetStyle(views::Button::STYLE_BUTTON); | |
| 213 | |
| 214 if (kIsOkButtonOnLeftSide) { | |
| 215 button_view->AddChildView(save_button_); | |
| 216 button_view->AddChildView(cancel_button_); | |
| 217 } else { | |
| 218 button_view->AddChildView(cancel_button_); | |
| 219 button_view->AddChildView(save_button_); | |
| 220 } | |
| 221 | |
| 222 return view; | 203 return view; |
| 223 } | 204 } |
| 224 | 205 |
| 225 void SaveCardBubbleViews::Init() { | 206 void SaveCardBubbleViews::Init() { |
| 226 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); | 207 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); |
| 227 AddChildView(CreateMainContentView().release()); | 208 AddChildView(CreateMainContentView().release()); |
| 228 } | 209 } |
| 229 | 210 |
| 230 } // namespace autofill | 211 } // namespace autofill |
| OLD | NEW |