Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(416)

Side by Side Diff: chrome/browser/ui/views/content_setting_bubble_contents.cc

Issue 2793413002: [subresource_filter] Update the desktop UI according to mocks (Closed)
Patch Set: engedy review Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/ui/views/content_setting_bubble_contents.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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"
38 #include "ui/views/controls/button/menu_button.h" 37 #include "ui/views/controls/button/menu_button.h"
39 #include "ui/views/controls/button/radio_button.h" 38 #include "ui/views/controls/button/radio_button.h"
40 #include "ui/views/controls/combobox/combobox.h" 39 #include "ui/views/controls/combobox/combobox.h"
41 #include "ui/views/controls/image_view.h" 40 #include "ui/views/controls/image_view.h"
42 #include "ui/views/controls/label.h" 41 #include "ui/views/controls/label.h"
43 #include "ui/views/controls/link.h" 42 #include "ui/views/controls/link.h"
44 #include "ui/views/controls/menu/menu_config.h" 43 #include "ui/views/controls/menu/menu_config.h"
45 #include "ui/views/controls/menu/menu_runner.h" 44 #include "ui/views/controls/menu/menu_runner.h"
46 #include "ui/views/controls/separator.h" 45 #include "ui/views/controls/separator.h"
47 #include "ui/views/layout/grid_layout.h" 46 #include "ui/views/layout/grid_layout.h"
48 #include "ui/views/layout/layout_constants.h" 47 #include "ui/views/layout/layout_constants.h"
49 #include "ui/views/native_cursor.h" 48 #include "ui/views/native_cursor.h"
49 #include "ui/views/window/dialog_client_view.h"
50 50
51 namespace { 51 namespace {
52 52
53 // If we don't clamp the maximum width, then very long URLs and titles can make 53 // If we don't clamp the maximum width, then very long URLs and titles can make
54 // the bubble arbitrarily wide. 54 // the bubble arbitrarily wide.
55 const int kMaxContentsWidth = 500; 55 const int kMaxContentsWidth = 500;
56 56
57 // The new default width for the content settings bubble. The review process to 57 // The new default width for the content settings bubble. The review process to
58 // the width on per-bubble basis is tracked with https://crbug.com/649650. 58 // the width on per-bubble basis is tracked with https://crbug.com/649650.
59 const int kMaxDefaultContentsWidth = 320; 59 const int kMaxDefaultContentsWidth = 320;
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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));
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(
477 content_setting_bubble_model_->OnManageLinkClicked(); 487 manage_checkbox_->checked());
488
489 // Toggling the check state may change the dialog button text.
490 GetDialogClientView()->UpdateDialogButtons();
478 } else { 491 } else {
479 RadioGroup::const_iterator i( 492 RadioGroup::const_iterator i(
480 std::find(radio_group_.begin(), radio_group_.end(), sender)); 493 std::find(radio_group_.begin(), radio_group_.end(), sender));
481 DCHECK(i != radio_group_.end()); 494 DCHECK(i != radio_group_.end());
482 content_setting_bubble_model_->OnRadioClicked(i - radio_group_.begin()); 495 content_setting_bubble_model_->OnRadioClicked(i - radio_group_.begin());
483 } 496 }
484 } 497 }
485 498
486 void ContentSettingBubbleContents::LinkClicked(views::Link* source, 499 void ContentSettingBubbleContents::LinkClicked(views::Link* source,
487 int event_flags) { 500 int event_flags) {
(...skipping 19 matching lines...) Expand all
507 DCHECK(i != list_item_links_.end()); 520 DCHECK(i != list_item_links_.end());
508 content_setting_bubble_model_->OnListItemClicked(i->second); 521 content_setting_bubble_model_->OnListItemClicked(i->second);
509 } 522 }
510 523
511 void ContentSettingBubbleContents::OnPerformAction(views::Combobox* combobox) { 524 void ContentSettingBubbleContents::OnPerformAction(views::Combobox* combobox) {
512 MediaComboboxModel* model = 525 MediaComboboxModel* model =
513 static_cast<MediaComboboxModel*>(combobox->model()); 526 static_cast<MediaComboboxModel*>(combobox->model());
514 content_setting_bubble_model_->OnMediaMenuClicked( 527 content_setting_bubble_model_->OnMediaMenuClicked(
515 model->type(), model->GetDevices()[combobox->selected_index()].id); 528 model->type(), model->GetDevices()[combobox->selected_index()].id);
516 } 529 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/content_setting_bubble_contents.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698