| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/chooser_content_view.h" | 5 #include "chrome/browser/ui/views/chooser_content_view.h" |
| 6 | 6 |
| 7 #include "base/numerics/safe_conversions.h" | 7 #include "base/numerics/safe_conversions.h" |
| 8 #include "chrome/grit/generated_resources.h" | 8 #include "chrome/grit/generated_resources.h" |
| 9 #include "ui/base/l10n/l10n_util.h" | 9 #include "ui/base/l10n/l10n_util.h" |
| 10 #include "ui/base/resource/resource_bundle.h" | 10 #include "ui/base/resource/resource_bundle.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 | 32 |
| 33 // The lookup table for signal strength level image. | 33 // The lookup table for signal strength level image. |
| 34 const int kSignalStrengthLevelImageIds[5] = {IDR_SIGNAL_0_BAR, IDR_SIGNAL_1_BAR, | 34 const int kSignalStrengthLevelImageIds[5] = {IDR_SIGNAL_0_BAR, IDR_SIGNAL_1_BAR, |
| 35 IDR_SIGNAL_2_BAR, IDR_SIGNAL_3_BAR, | 35 IDR_SIGNAL_2_BAR, IDR_SIGNAL_3_BAR, |
| 36 IDR_SIGNAL_4_BAR}; | 36 IDR_SIGNAL_4_BAR}; |
| 37 | 37 |
| 38 } // namespace | 38 } // namespace |
| 39 | 39 |
| 40 ChooserContentView::ChooserContentView( | 40 ChooserContentView::ChooserContentView( |
| 41 views::TableViewObserver* table_view_observer, | 41 views::TableViewObserver* table_view_observer, |
| 42 std::unique_ptr<ChooserController> chooser_controller) | 42 std::unique_ptr<ChooserController> chooser_controller, |
| 43 views::StyledLabel* footnote_link) |
| 43 : chooser_controller_(std::move(chooser_controller)), | 44 : chooser_controller_(std::move(chooser_controller)), |
| 45 footnote_link_(footnote_link), |
| 44 help_text_(l10n_util::GetStringFUTF16( | 46 help_text_(l10n_util::GetStringFUTF16( |
| 45 IDS_DEVICE_CHOOSER_GET_HELP_LINK_WITH_SCANNING_STATUS, | 47 IDS_DEVICE_CHOOSER_GET_HELP_LINK_WITH_SCANNING_STATUS, |
| 46 base::string16())), | 48 base::string16())), |
| 47 help_and_scanning_text_(l10n_util::GetStringFUTF16( | 49 help_and_scanning_text_(l10n_util::GetStringFUTF16( |
| 48 IDS_DEVICE_CHOOSER_GET_HELP_LINK_WITH_SCANNING_STATUS, | 50 IDS_DEVICE_CHOOSER_GET_HELP_LINK_WITH_SCANNING_STATUS, |
| 49 l10n_util::GetStringUTF16(IDS_BLUETOOTH_DEVICE_CHOOSER_SCANNING))) { | 51 l10n_util::GetStringUTF16(IDS_BLUETOOTH_DEVICE_CHOOSER_SCANNING))) { |
| 50 base::string16 re_scan_text = | 52 base::string16 re_scan_text = |
| 51 l10n_util::GetStringUTF16(IDS_BLUETOOTH_DEVICE_CHOOSER_RE_SCAN); | 53 l10n_util::GetStringUTF16(IDS_BLUETOOTH_DEVICE_CHOOSER_RE_SCAN); |
| 52 std::vector<size_t> offsets; | 54 std::vector<size_t> offsets; |
| 53 help_and_re_scan_text_ = l10n_util::GetStringFUTF16( | 55 help_and_re_scan_text_ = l10n_util::GetStringFUTF16( |
| (...skipping 25 matching lines...) Expand all Loading... |
| 79 IDS_BLUETOOTH_DEVICE_CHOOSER_TURN_ON_BLUETOOTH_LINK_TEXT); | 81 IDS_BLUETOOTH_DEVICE_CHOOSER_TURN_ON_BLUETOOTH_LINK_TEXT); |
| 80 size_t offset = 0; | 82 size_t offset = 0; |
| 81 base::string16 text = l10n_util::GetStringFUTF16( | 83 base::string16 text = l10n_util::GetStringFUTF16( |
| 82 IDS_BLUETOOTH_DEVICE_CHOOSER_TURN_ADAPTER_OFF, link_text, &offset); | 84 IDS_BLUETOOTH_DEVICE_CHOOSER_TURN_ADAPTER_OFF, link_text, &offset); |
| 83 turn_adapter_off_help_ = new views::StyledLabel(text, this); | 85 turn_adapter_off_help_ = new views::StyledLabel(text, this); |
| 84 turn_adapter_off_help_->AddStyleRange( | 86 turn_adapter_off_help_->AddStyleRange( |
| 85 gfx::Range(0, link_text.size()), | 87 gfx::Range(0, link_text.size()), |
| 86 views::StyledLabel::RangeStyleInfo::CreateForLink()); | 88 views::StyledLabel::RangeStyleInfo::CreateForLink()); |
| 87 turn_adapter_off_help_->SetVisible(false); | 89 turn_adapter_off_help_->SetVisible(false); |
| 88 AddChildView(turn_adapter_off_help_); | 90 AddChildView(turn_adapter_off_help_); |
| 91 DCHECK(footnote_link_); |
| 92 footnote_link_->SetText(help_text_); |
| 93 footnote_link_->set_listener(this); |
| 94 footnote_link_->AddStyleRange( |
| 95 help_text_range_, views::StyledLabel::RangeStyleInfo::CreateForLink()); |
| 89 } | 96 } |
| 90 | 97 |
| 91 ChooserContentView::~ChooserContentView() { | 98 ChooserContentView::~ChooserContentView() { |
| 92 chooser_controller_->set_view(nullptr); | 99 chooser_controller_->set_view(nullptr); |
| 93 table_view_->SetObserver(nullptr); | 100 table_view_->SetObserver(nullptr); |
| 94 table_view_->SetModel(nullptr); | 101 table_view_->SetModel(nullptr); |
| 95 } | 102 } |
| 96 | 103 |
| 97 gfx::Size ChooserContentView::GetPreferredSize() const { | 104 gfx::Size ChooserContentView::GetPreferredSize() const { |
| 98 return gfx::Size(kChooserWidth, kChooserHeight); | 105 return gfx::Size(kChooserWidth, kChooserHeight); |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 return button == ui::DIALOG_BUTTON_OK | 279 return button == ui::DIALOG_BUTTON_OK |
| 273 ? chooser_controller_->GetOkButtonLabel() | 280 ? chooser_controller_->GetOkButtonLabel() |
| 274 : l10n_util::GetStringUTF16(IDS_DEVICE_CHOOSER_CANCEL_BUTTON_TEXT); | 281 : l10n_util::GetStringUTF16(IDS_DEVICE_CHOOSER_CANCEL_BUTTON_TEXT); |
| 275 } | 282 } |
| 276 | 283 |
| 277 bool ChooserContentView::IsDialogButtonEnabled(ui::DialogButton button) const { | 284 bool ChooserContentView::IsDialogButtonEnabled(ui::DialogButton button) const { |
| 278 return button != ui::DIALOG_BUTTON_OK || | 285 return button != ui::DIALOG_BUTTON_OK || |
| 279 !table_view_->selection_model().empty(); | 286 !table_view_->selection_model().empty(); |
| 280 } | 287 } |
| 281 | 288 |
| 282 views::StyledLabel* ChooserContentView::CreateFootnoteView() { | |
| 283 footnote_link_ = new views::StyledLabel(help_text_, this); | |
| 284 footnote_link_->AddStyleRange( | |
| 285 help_text_range_, views::StyledLabel::RangeStyleInfo::CreateForLink()); | |
| 286 return footnote_link_; | |
| 287 } | |
| 288 | |
| 289 void ChooserContentView::Accept() { | 289 void ChooserContentView::Accept() { |
| 290 chooser_controller_->Select(table_view_->selection_model().active()); | 290 chooser_controller_->Select(table_view_->selection_model().active()); |
| 291 } | 291 } |
| 292 | 292 |
| 293 void ChooserContentView::Cancel() { | 293 void ChooserContentView::Cancel() { |
| 294 chooser_controller_->Cancel(); | 294 chooser_controller_->Cancel(); |
| 295 } | 295 } |
| 296 | 296 |
| 297 void ChooserContentView::Close() { | 297 void ChooserContentView::Close() { |
| 298 chooser_controller_->Close(); | 298 chooser_controller_->Close(); |
| 299 } | 299 } |
| 300 | 300 |
| 301 void ChooserContentView::UpdateTableView() { | 301 void ChooserContentView::UpdateTableView() { |
| 302 if (chooser_controller_->NumOptions() == 0) { | 302 if (chooser_controller_->NumOptions() == 0) { |
| 303 table_view_->OnModelChanged(); | 303 table_view_->OnModelChanged(); |
| 304 table_view_->SetEnabled(false); | 304 table_view_->SetEnabled(false); |
| 305 } else { | 305 } else { |
| 306 table_view_->SetEnabled(true); | 306 table_view_->SetEnabled(true); |
| 307 } | 307 } |
| 308 } | 308 } |
| 309 | 309 |
| 310 void ChooserContentView::SetGetHelpAndReScanLink() { | 310 void ChooserContentView::SetGetHelpAndReScanLink() { |
| 311 footnote_link_->SetText(help_and_re_scan_text_); | 311 footnote_link_->SetText(help_and_re_scan_text_); |
| 312 footnote_link_->AddStyleRange( | 312 footnote_link_->AddStyleRange( |
| 313 help_text_range_, views::StyledLabel::RangeStyleInfo::CreateForLink()); | 313 help_text_range_, views::StyledLabel::RangeStyleInfo::CreateForLink()); |
| 314 footnote_link_->AddStyleRange( | 314 footnote_link_->AddStyleRange( |
| 315 re_scan_text_range_, views::StyledLabel::RangeStyleInfo::CreateForLink()); | 315 re_scan_text_range_, views::StyledLabel::RangeStyleInfo::CreateForLink()); |
| 316 } | 316 } |
| OLD | NEW |