| 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" |
| 11 #include "chrome/browser/ui/autofill/autofill_dialog_types.h" | 11 #include "chrome/browser/ui/autofill/autofill_dialog_types.h" |
| 12 #include "chrome/browser/ui/autofill/save_card_bubble_controller.h" | 12 #include "chrome/browser/ui/autofill/save_card_bubble_controller.h" |
| 13 #include "components/autofill/core/browser/legal_message_line.h" |
| 13 #include "grit/components_strings.h" | 14 #include "grit/components_strings.h" |
| 14 #include "ui/base/l10n/l10n_util.h" | 15 #include "ui/base/l10n/l10n_util.h" |
| 15 #include "ui/views/bubble/bubble_frame_view.h" | 16 #include "ui/views/bubble/bubble_frame_view.h" |
| 16 #include "ui/views/controls/button/blue_button.h" | 17 #include "ui/views/controls/button/blue_button.h" |
| 17 #include "ui/views/controls/button/label_button.h" | 18 #include "ui/views/controls/button/label_button.h" |
| 18 #include "ui/views/controls/label.h" | 19 #include "ui/views/controls/label.h" |
| 19 #include "ui/views/controls/link.h" | 20 #include "ui/views/controls/link.h" |
| 20 #include "ui/views/controls/styled_label.h" | 21 #include "ui/views/controls/styled_label.h" |
| 21 #include "ui/views/layout/box_layout.h" | 22 #include "ui/views/layout/box_layout.h" |
| 22 #include "ui/views/layout/grid_layout.h" | 23 #include "ui/views/layout/grid_layout.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 34 // TODO(bondd): BubbleManager will eventually move this logic somewhere else, | 35 // TODO(bondd): BubbleManager will eventually move this logic somewhere else, |
| 35 // and then kIsOkButtonOnLeftSide can be removed from here and | 36 // and then kIsOkButtonOnLeftSide can be removed from here and |
| 36 // dialog_client_view.cc. | 37 // dialog_client_view.cc. |
| 37 #if defined(OS_WIN) || defined(OS_CHROMEOS) | 38 #if defined(OS_WIN) || defined(OS_CHROMEOS) |
| 38 const bool kIsOkButtonOnLeftSide = true; | 39 const bool kIsOkButtonOnLeftSide = true; |
| 39 #else | 40 #else |
| 40 const bool kIsOkButtonOnLeftSide = false; | 41 const bool kIsOkButtonOnLeftSide = false; |
| 41 #endif | 42 #endif |
| 42 | 43 |
| 43 scoped_ptr<views::StyledLabel> CreateLegalMessageLineLabel( | 44 scoped_ptr<views::StyledLabel> CreateLegalMessageLineLabel( |
| 44 const SaveCardBubbleController::LegalMessageLine& line, | 45 const LegalMessageLine& line, |
| 45 views::StyledLabelListener* listener) { | 46 views::StyledLabelListener* listener) { |
| 46 scoped_ptr<views::StyledLabel> label( | 47 scoped_ptr<views::StyledLabel> label( |
| 47 new views::StyledLabel(line.text, listener)); | 48 new views::StyledLabel(line.text(), listener)); |
| 48 for (const SaveCardBubbleController::LegalMessageLine::Link& link : | 49 for (const LegalMessageLine::Link& link : line.links()) { |
| 49 line.links) { | |
| 50 label->AddStyleRange(link.range, | 50 label->AddStyleRange(link.range, |
| 51 views::StyledLabel::RangeStyleInfo::CreateForLink()); | 51 views::StyledLabel::RangeStyleInfo::CreateForLink()); |
| 52 } | 52 } |
| 53 return label; | 53 return label; |
| 54 } | 54 } |
| 55 | 55 |
| 56 } // namespace | 56 } // namespace |
| 57 | 57 |
| 58 SaveCardBubbleViews::SaveCardBubbleViews(views::View* anchor_view, | 58 SaveCardBubbleViews::SaveCardBubbleViews(views::View* anchor_view, |
| 59 content::WebContents* web_contents, | 59 content::WebContents* web_contents, |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 const gfx::Range& range, | 115 const gfx::Range& range, |
| 116 int event_flags) { | 116 int event_flags) { |
| 117 // Index of |label| within its parent's view hierarchy is the same as the | 117 // Index of |label| within its parent's view hierarchy is the same as the |
| 118 // legal message line index. DCHECK this assumption to guard against future | 118 // legal message line index. DCHECK this assumption to guard against future |
| 119 // layout changes. | 119 // layout changes. |
| 120 DCHECK_EQ(static_cast<size_t>(label->parent()->child_count()), | 120 DCHECK_EQ(static_cast<size_t>(label->parent()->child_count()), |
| 121 controller_->GetLegalMessageLines().size()); | 121 controller_->GetLegalMessageLines().size()); |
| 122 | 122 |
| 123 const auto& links = | 123 const auto& links = |
| 124 controller_->GetLegalMessageLines()[label->parent()->GetIndexOf(label)] | 124 controller_->GetLegalMessageLines()[label->parent()->GetIndexOf(label)] |
| 125 .links; | 125 .links(); |
| 126 for (const SaveCardBubbleController::LegalMessageLine::Link& link : links) { | 126 for (const LegalMessageLine::Link& link : links) { |
| 127 if (link.range == range) { | 127 if (link.range == range) { |
| 128 controller_->OnLegalMessageLinkClicked(link.url); | 128 controller_->OnLegalMessageLinkClicked(link.url); |
| 129 return; | 129 return; |
| 130 } | 130 } |
| 131 } | 131 } |
| 132 | 132 |
| 133 // |range| was not found. | 133 // |range| was not found. |
| 134 NOTREACHED(); | 134 NOTREACHED(); |
| 135 } | 135 } |
| 136 | 136 |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 view->SetLayoutManager( | 222 view->SetLayoutManager( |
| 223 new views::BoxLayout(views::BoxLayout::kVertical, | 223 new views::BoxLayout(views::BoxLayout::kVertical, |
| 224 GetBubbleFrameView()->GetTitleInsets().left(), | 224 GetBubbleFrameView()->GetTitleInsets().left(), |
| 225 views::kRelatedControlVerticalSpacing, 0)); | 225 views::kRelatedControlVerticalSpacing, 0)); |
| 226 view->SetBorder( | 226 view->SetBorder( |
| 227 views::Border::CreateSolidSidedBorder(1, 0, 0, 0, kSubtleBorderColor)); | 227 views::Border::CreateSolidSidedBorder(1, 0, 0, 0, kSubtleBorderColor)); |
| 228 view->set_background( | 228 view->set_background( |
| 229 views::Background::CreateSolidBackground(kLightShadingColor)); | 229 views::Background::CreateSolidBackground(kLightShadingColor)); |
| 230 | 230 |
| 231 // Add a StyledLabel for each line of the legal message. | 231 // Add a StyledLabel for each line of the legal message. |
| 232 for (const SaveCardBubbleController::LegalMessageLine& line : | 232 for (const LegalMessageLine& line : controller_->GetLegalMessageLines()) |
| 233 controller_->GetLegalMessageLines()) { | |
| 234 view->AddChildView(CreateLegalMessageLineLabel(line, this).release()); | 233 view->AddChildView(CreateLegalMessageLineLabel(line, this).release()); |
| 235 } | |
| 236 | 234 |
| 237 return view; | 235 return view; |
| 238 } | 236 } |
| 239 | 237 |
| 240 void SaveCardBubbleViews::Init() { | 238 void SaveCardBubbleViews::Init() { |
| 241 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); | 239 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); |
| 242 AddChildView(CreateMainContentView().release()); | 240 AddChildView(CreateMainContentView().release()); |
| 243 if (!controller_->GetLegalMessageLines().empty()) | 241 if (!controller_->GetLegalMessageLines().empty()) |
| 244 AddChildView(CreateFootnoteView().release()); | 242 AddChildView(CreateFootnoteView().release()); |
| 245 | 243 |
| 246 set_margins(gfx::Insets(1, 0, 1, 0)); | 244 set_margins(gfx::Insets(1, 0, 1, 0)); |
| 247 } | 245 } |
| 248 | 246 |
| 249 } // namespace autofill | 247 } // namespace autofill |
| OLD | NEW |