| 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 CloseBubble(); |
| 68 } |
| 69 |
| 70 views::View* SaveCardBubbleViews::CreateExtraView() { |
| 71 DCHECK(!learn_more_link_); |
| 72 learn_more_link_ = new views::Link(l10n_util::GetStringUTF16(IDS_LEARN_MORE)); |
| 73 learn_more_link_->SetUnderline(false); |
| 74 learn_more_link_->set_listener(this); |
| 75 return learn_more_link_; |
| 79 } | 76 } |
| 80 | 77 |
| 81 views::View* SaveCardBubbleViews::CreateFootnoteView() { | 78 views::View* SaveCardBubbleViews::CreateFootnoteView() { |
| 82 if (controller_->GetLegalMessageLines().empty()) | 79 if (controller_->GetLegalMessageLines().empty()) |
| 83 return nullptr; | 80 return nullptr; |
| 84 | 81 |
| 85 // Use BoxLayout to provide insets around the label. | 82 // Use BoxLayout to provide insets around the label. |
| 86 View* view = new View(); | 83 View* view = new View(); |
| 87 view->SetLayoutManager( | 84 view->SetLayoutManager( |
| 88 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); | 85 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); |
| 89 | 86 |
| 90 // Add a StyledLabel for each line of the legal message. | 87 // Add a StyledLabel for each line of the legal message. |
| 91 for (const LegalMessageLine& line : controller_->GetLegalMessageLines()) | 88 for (const LegalMessageLine& line : controller_->GetLegalMessageLines()) |
| 92 view->AddChildView(CreateLegalMessageLineLabel(line, this).release()); | 89 view->AddChildView(CreateLegalMessageLineLabel(line, this).release()); |
| 93 | 90 |
| 94 return view; | 91 return view; |
| 95 } | 92 } |
| 96 | 93 |
| 94 bool SaveCardBubbleViews::Accept() { |
| 95 controller_->OnSaveButton(); |
| 96 return true; |
| 97 } |
| 98 |
| 99 bool SaveCardBubbleViews::Cancel() { |
| 100 controller_->OnCancelButton(); |
| 101 return true; |
| 102 } |
| 103 |
| 104 int SaveCardBubbleViews::GetDialogButtons() const { |
| 105 // This is the default for BubbleDialogDelegateView, but it's not the default |
| 106 // for LocationBarBubbleDelegateView. |
| 107 return ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL; |
| 108 } |
| 109 |
| 110 base::string16 SaveCardBubbleViews::GetDialogButtonLabel( |
| 111 ui::DialogButton button) const { |
| 112 return l10n_util::GetStringUTF16(button == ui::DIALOG_BUTTON_OK |
| 113 ? IDS_AUTOFILL_SAVE_CARD_PROMPT_ACCEPT |
| 114 : IDS_AUTOFILL_SAVE_CARD_PROMPT_DENY); |
| 115 } |
| 116 |
| 117 bool SaveCardBubbleViews::ShouldDefaultButtonBeBlue() const { |
| 118 return true; |
| 119 } |
| 120 |
| 97 gfx::Size SaveCardBubbleViews::GetPreferredSize() const { | 121 gfx::Size SaveCardBubbleViews::GetPreferredSize() const { |
| 98 return gfx::Size(kBubbleWidth, GetHeightForWidth(kBubbleWidth)); | 122 return gfx::Size(kBubbleWidth, GetHeightForWidth(kBubbleWidth)); |
| 99 } | 123 } |
| 100 | 124 |
| 101 views::View* SaveCardBubbleViews::GetInitiallyFocusedView() { | |
| 102 return save_button_; | |
| 103 } | |
| 104 | |
| 105 base::string16 SaveCardBubbleViews::GetWindowTitle() const { | 125 base::string16 SaveCardBubbleViews::GetWindowTitle() const { |
| 106 return controller_->GetWindowTitle(); | 126 return controller_->GetWindowTitle(); |
| 107 } | 127 } |
| 108 | 128 |
| 109 void SaveCardBubbleViews::WindowClosing() { | 129 void SaveCardBubbleViews::WindowClosing() { |
| 110 if (controller_) | 130 if (controller_) |
| 111 controller_->OnBubbleClosed(); | 131 controller_->OnBubbleClosed(); |
| 112 } | 132 } |
| 113 | 133 |
| 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) { | 134 void SaveCardBubbleViews::LinkClicked(views::Link* source, int event_flags) { |
| 126 DCHECK_EQ(source, learn_more_link_); | 135 DCHECK_EQ(source, learn_more_link_); |
| 127 controller_->OnLearnMoreClicked(); | 136 controller_->OnLearnMoreClicked(); |
| 128 } | 137 } |
| 129 | 138 |
| 130 void SaveCardBubbleViews::StyledLabelLinkClicked(views::StyledLabel* label, | 139 void SaveCardBubbleViews::StyledLabelLinkClicked(views::StyledLabel* label, |
| 131 const gfx::Range& range, | 140 const gfx::Range& range, |
| 132 int event_flags) { | 141 int event_flags) { |
| 133 // Index of |label| within its parent's view hierarchy is the same as the | 142 // 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 | 143 // 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 | 191 |
| 183 // Optionally add label that will contain an explanation for upload. | 192 // Optionally add label that will contain an explanation for upload. |
| 184 base::string16 explanation = controller_->GetExplanatoryMessage(); | 193 base::string16 explanation = controller_->GetExplanatoryMessage(); |
| 185 if (!explanation.empty()) { | 194 if (!explanation.empty()) { |
| 186 views::Label* explanation_label = new views::Label(explanation); | 195 views::Label* explanation_label = new views::Label(explanation); |
| 187 explanation_label->SetMultiLine(true); | 196 explanation_label->SetMultiLine(true); |
| 188 explanation_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 197 explanation_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 189 view->AddChildView(explanation_label); | 198 view->AddChildView(explanation_label); |
| 190 } | 199 } |
| 191 | 200 |
| 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; | 201 return view; |
| 223 } | 202 } |
| 224 | 203 |
| 225 void SaveCardBubbleViews::Init() { | 204 void SaveCardBubbleViews::Init() { |
| 226 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); | 205 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); |
| 227 AddChildView(CreateMainContentView().release()); | 206 AddChildView(CreateMainContentView().release()); |
| 228 } | 207 } |
| 229 | 208 |
| 230 } // namespace autofill | 209 } // namespace autofill |
| OLD | NEW |