Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/content_setting_bubble_contents.h" | 5 #include "chrome/browser/ui/views/content_setting_bubble_contents.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 27 #include "content/public/browser/plugin_service.h" | 27 #include "content/public/browser/plugin_service.h" |
| 28 #include "content/public/browser/web_contents.h" | 28 #include "content/public/browser/web_contents.h" |
| 29 #include "ui/base/cursor/cursor.h" | 29 #include "ui/base/cursor/cursor.h" |
| 30 #include "ui/base/default_style.h" | 30 #include "ui/base/default_style.h" |
| 31 #include "ui/base/l10n/l10n_util.h" | 31 #include "ui/base/l10n/l10n_util.h" |
| 32 #include "ui/base/models/simple_menu_model.h" | 32 #include "ui/base/models/simple_menu_model.h" |
| 33 #include "ui/base/resource/resource_bundle.h" | 33 #include "ui/base/resource/resource_bundle.h" |
| 34 #include "ui/gfx/font_list.h" | 34 #include "ui/gfx/font_list.h" |
| 35 #include "ui/gfx/text_utils.h" | 35 #include "ui/gfx/text_utils.h" |
| 36 #include "ui/views/controls/button/label_button_border.h" | 36 #include "ui/views/controls/button/label_button_border.h" |
| 37 #include "ui/views/controls/button/md_text_button.h" | 37 #include "ui/views/controls/button/md_text_button.h" |
|
msw
2017/04/06 00:44:56
nit: remove if no longer needed
Charlie Harrison
2017/04/06 02:04:58
Done.
| |
| 38 #include "ui/views/controls/button/menu_button.h" | 38 #include "ui/views/controls/button/menu_button.h" |
| 39 #include "ui/views/controls/button/radio_button.h" | 39 #include "ui/views/controls/button/radio_button.h" |
| 40 #include "ui/views/controls/combobox/combobox.h" | 40 #include "ui/views/controls/combobox/combobox.h" |
| 41 #include "ui/views/controls/image_view.h" | 41 #include "ui/views/controls/image_view.h" |
| 42 #include "ui/views/controls/label.h" | 42 #include "ui/views/controls/label.h" |
| 43 #include "ui/views/controls/link.h" | 43 #include "ui/views/controls/link.h" |
| 44 #include "ui/views/controls/menu/menu_config.h" | 44 #include "ui/views/controls/menu/menu_config.h" |
| 45 #include "ui/views/controls/menu/menu_runner.h" | 45 #include "ui/views/controls/menu/menu_runner.h" |
| 46 #include "ui/views/controls/separator.h" | 46 #include "ui/views/controls/separator.h" |
| 47 #include "ui/views/layout/grid_layout.h" | 47 #include "ui/views/layout/grid_layout.h" |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 164 ContentSettingBubbleContents::ContentSettingBubbleContents( | 164 ContentSettingBubbleContents::ContentSettingBubbleContents( |
| 165 ContentSettingBubbleModel* content_setting_bubble_model, | 165 ContentSettingBubbleModel* content_setting_bubble_model, |
| 166 content::WebContents* web_contents, | 166 content::WebContents* web_contents, |
| 167 views::View* anchor_view, | 167 views::View* anchor_view, |
| 168 views::BubbleBorder::Arrow arrow) | 168 views::BubbleBorder::Arrow arrow) |
| 169 : content::WebContentsObserver(web_contents), | 169 : content::WebContentsObserver(web_contents), |
| 170 BubbleDialogDelegateView(anchor_view, arrow), | 170 BubbleDialogDelegateView(anchor_view, arrow), |
| 171 content_setting_bubble_model_(content_setting_bubble_model), | 171 content_setting_bubble_model_(content_setting_bubble_model), |
| 172 custom_link_(nullptr), | 172 custom_link_(nullptr), |
| 173 manage_link_(nullptr), | 173 manage_link_(nullptr), |
| 174 manage_button_(nullptr), | 174 manage_checkbox_(nullptr), |
| 175 learn_more_link_(nullptr) { | 175 learn_more_link_(nullptr) { |
| 176 // Compensate for built-in vertical padding in the anchor view's image. | 176 // Compensate for built-in vertical padding in the anchor view's image. |
| 177 set_anchor_view_insets(gfx::Insets( | 177 set_anchor_view_insets(gfx::Insets( |
| 178 GetLayoutConstant(LOCATION_BAR_BUBBLE_ANCHOR_VERTICAL_INSET), 0)); | 178 GetLayoutConstant(LOCATION_BAR_BUBBLE_ANCHOR_VERTICAL_INSET), 0)); |
| 179 } | 179 } |
| 180 | 180 |
| 181 ContentSettingBubbleContents::~ContentSettingBubbleContents() { | 181 ContentSettingBubbleContents::~ContentSettingBubbleContents() { |
| 182 // Must remove the children here so the comboboxes get destroyed before | 182 // Must remove the children here so the comboboxes get destroyed before |
| 183 // their associated models. | 183 // their associated models. |
| 184 RemoveAllChildViews(true); | 184 RemoveAllChildViews(true); |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 409 new views::Link(base::UTF8ToUTF16(bubble_content.custom_link)); | 409 new views::Link(base::UTF8ToUTF16(bubble_content.custom_link)); |
| 410 custom_link_->SetEnabled(bubble_content.custom_link_enabled); | 410 custom_link_->SetEnabled(bubble_content.custom_link_enabled); |
| 411 custom_link_->set_listener(this); | 411 custom_link_->set_listener(this); |
| 412 if (!bubble_content_empty) | 412 if (!bubble_content_empty) |
| 413 layout->AddPaddingRow(0, related_control_vertical_spacing); | 413 layout->AddPaddingRow(0, related_control_vertical_spacing); |
| 414 layout->StartRow(0, kSingleColumnSetId); | 414 layout->StartRow(0, kSingleColumnSetId); |
| 415 layout->AddView(custom_link_); | 415 layout->AddView(custom_link_); |
| 416 bubble_content_empty = false; | 416 bubble_content_empty = false; |
| 417 } | 417 } |
| 418 | 418 |
| 419 if (bubble_content.show_manage_text_as_checkbox) { | |
| 420 manage_checkbox_ = | |
| 421 new views::Checkbox(base::UTF8ToUTF16(bubble_content.manage_text)); | |
|
msw
2017/04/06 00:44:56
aside: BubbleContent::manage_text should probably
Charlie Harrison
2017/04/06 02:04:58
Ack. Let's address this in a followup?
msw
2017/04/06 02:19:29
Acknowledged.
| |
| 422 manage_checkbox_->set_listener(this); | |
| 423 layout->AddPaddingRow(0, related_control_vertical_spacing); | |
| 424 layout->StartRow(0, indented_kSingleColumnSetId); | |
| 425 layout->AddView(manage_checkbox_); | |
| 426 } | |
| 427 | |
| 419 if (!bubble_content_empty) { | 428 if (!bubble_content_empty) { |
| 420 if (!layout_delegate->IsHarmonyMode()) { | 429 if (!layout_delegate->IsHarmonyMode()) { |
| 421 layout->AddPaddingRow(0, related_control_vertical_spacing); | 430 layout->AddPaddingRow(0, related_control_vertical_spacing); |
| 422 layout->StartRow(0, kSingleColumnSetId); | 431 layout->StartRow(0, kSingleColumnSetId); |
| 423 layout->AddView(new views::Separator(), 1, 1, GridLayout::FILL, | 432 layout->AddView(new views::Separator(), 1, 1, GridLayout::FILL, |
| 424 GridLayout::FILL); | 433 GridLayout::FILL); |
| 425 } | 434 } |
| 426 layout->AddPaddingRow(0, related_control_vertical_spacing); | 435 layout->AddPaddingRow(0, related_control_vertical_spacing); |
| 427 } | 436 } |
| 428 } | 437 } |
| 429 | 438 |
| 430 views::View* ContentSettingBubbleContents::CreateExtraView() { | 439 views::View* ContentSettingBubbleContents::CreateExtraView() { |
| 431 if (content_setting_bubble_model_->bubble_content() | 440 const ContentSettingBubbleModel::BubbleContent& bubble_content = |
| 432 .show_manage_text_as_button) { | 441 content_setting_bubble_model_->bubble_content(); |
| 433 manage_button_ = views::MdTextButton::CreateSecondaryUiButton( | 442 // Added as part of the primary view. |
| 434 this, base::UTF8ToUTF16( | 443 if (bubble_content.show_manage_text_as_checkbox) |
| 435 content_setting_bubble_model_->bubble_content().manage_text)); | 444 return nullptr; |
| 436 return manage_button_; | 445 |
| 437 } else { | 446 manage_link_ = new views::Link(base::UTF8ToUTF16(bubble_content.manage_text)); |
| 438 manage_link_ = new views::Link(base::UTF8ToUTF16( | 447 manage_link_->set_listener(this); |
| 439 content_setting_bubble_model_->bubble_content().manage_text)); | 448 return manage_link_; |
| 440 manage_link_->set_listener(this); | |
| 441 return manage_link_; | |
| 442 } | |
| 443 } | 449 } |
| 444 | 450 |
| 445 bool ContentSettingBubbleContents::Accept() { | 451 bool ContentSettingBubbleContents::Accept() { |
| 446 content_setting_bubble_model_->OnDoneClicked(); | 452 content_setting_bubble_model_->OnDoneClicked(); |
| 447 return true; | 453 return true; |
| 448 } | 454 } |
| 449 | 455 |
| 450 bool ContentSettingBubbleContents::Close() { | 456 bool ContentSettingBubbleContents::Close() { |
| 451 return true; | 457 return true; |
| 452 } | 458 } |
| 453 | 459 |
| 454 int ContentSettingBubbleContents::GetDialogButtons() const { | 460 int ContentSettingBubbleContents::GetDialogButtons() const { |
| 455 return ui::DIALOG_BUTTON_OK; | 461 return ui::DIALOG_BUTTON_OK; |
| 456 } | 462 } |
| 457 | 463 |
| 458 base::string16 ContentSettingBubbleContents::GetDialogButtonLabel( | 464 base::string16 ContentSettingBubbleContents::GetDialogButtonLabel( |
| 459 ui::DialogButton button) const { | 465 ui::DialogButton button) const { |
| 466 const base::string16& done_text = | |
| 467 content_setting_bubble_model_->bubble_content().done_button_text; | |
| 468 if (!done_text.empty()) | |
| 469 return done_text; | |
| 460 return l10n_util::GetStringUTF16(IDS_DONE); | 470 return l10n_util::GetStringUTF16(IDS_DONE); |
| 461 } | 471 } |
| 462 | 472 |
| 463 void ContentSettingBubbleContents::DidFinishNavigation( | 473 void ContentSettingBubbleContents::DidFinishNavigation( |
| 464 content::NavigationHandle* navigation_handle) { | 474 content::NavigationHandle* navigation_handle) { |
| 465 if (!navigation_handle->IsInMainFrame() || !navigation_handle->HasCommitted()) | 475 if (!navigation_handle->IsInMainFrame() || !navigation_handle->HasCommitted()) |
| 466 return; | 476 return; |
| 467 | 477 |
| 468 // Content settings are based on the main frame, so if it switches then | 478 // Content settings are based on the main frame, so if it switches then |
| 469 // close up shop. | 479 // close up shop. |
| 470 GetWidget()->Close(); | 480 GetWidget()->Close(); |
| 471 } | 481 } |
| 472 | 482 |
| 473 void ContentSettingBubbleContents::ButtonPressed(views::Button* sender, | 483 void ContentSettingBubbleContents::ButtonPressed(views::Button* sender, |
| 474 const ui::Event& event) { | 484 const ui::Event& event) { |
| 475 if (manage_button_ == sender) { | 485 if (manage_checkbox_ == sender) { |
| 476 GetWidget()->Close(); | 486 content_setting_bubble_model_->OnManageCheckboxChecked( |
|
msw
2017/04/06 00:44:56
This could probably call GetDialogClientView()->Up
Charlie Harrison
2017/04/06 02:04:58
This solution works for me, thanks for the tip.
| |
| 477 content_setting_bubble_model_->OnManageLinkClicked(); | 487 manage_checkbox_->checked()); |
| 478 } else { | 488 } else { |
| 479 RadioGroup::const_iterator i( | 489 RadioGroup::const_iterator i( |
| 480 std::find(radio_group_.begin(), radio_group_.end(), sender)); | 490 std::find(radio_group_.begin(), radio_group_.end(), sender)); |
| 481 DCHECK(i != radio_group_.end()); | 491 DCHECK(i != radio_group_.end()); |
| 482 content_setting_bubble_model_->OnRadioClicked(i - radio_group_.begin()); | 492 content_setting_bubble_model_->OnRadioClicked(i - radio_group_.begin()); |
| 483 } | 493 } |
| 484 } | 494 } |
| 485 | 495 |
| 486 void ContentSettingBubbleContents::LinkClicked(views::Link* source, | 496 void ContentSettingBubbleContents::LinkClicked(views::Link* source, |
| 487 int event_flags) { | 497 int event_flags) { |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 507 DCHECK(i != list_item_links_.end()); | 517 DCHECK(i != list_item_links_.end()); |
| 508 content_setting_bubble_model_->OnListItemClicked(i->second); | 518 content_setting_bubble_model_->OnListItemClicked(i->second); |
| 509 } | 519 } |
| 510 | 520 |
| 511 void ContentSettingBubbleContents::OnPerformAction(views::Combobox* combobox) { | 521 void ContentSettingBubbleContents::OnPerformAction(views::Combobox* combobox) { |
| 512 MediaComboboxModel* model = | 522 MediaComboboxModel* model = |
| 513 static_cast<MediaComboboxModel*>(combobox->model()); | 523 static_cast<MediaComboboxModel*>(combobox->model()); |
| 514 content_setting_bubble_model_->OnMediaMenuClicked( | 524 content_setting_bubble_model_->OnMediaMenuClicked( |
| 515 model->type(), model->GetDevices()[combobox->selected_index()].id); | 525 model->type(), model->GetDevices()[combobox->selected_index()].id); |
| 516 } | 526 } |
| OLD | NEW |