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 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
141 ContentSettingBubbleContents::ContentSettingBubbleContents( | 141 ContentSettingBubbleContents::ContentSettingBubbleContents( |
142 ContentSettingBubbleModel* content_setting_bubble_model, | 142 ContentSettingBubbleModel* content_setting_bubble_model, |
143 WebContents* web_contents, | 143 WebContents* web_contents, |
144 views::View* anchor_view, | 144 views::View* anchor_view, |
145 views::BubbleBorder::Arrow arrow) | 145 views::BubbleBorder::Arrow arrow) |
146 : BubbleDelegateView(anchor_view, arrow), | 146 : BubbleDelegateView(anchor_view, arrow), |
147 content_setting_bubble_model_(content_setting_bubble_model), | 147 content_setting_bubble_model_(content_setting_bubble_model), |
148 web_contents_(web_contents), | 148 web_contents_(web_contents), |
149 custom_link_(NULL), | 149 custom_link_(NULL), |
150 manage_link_(NULL), | 150 manage_link_(NULL), |
151 close_button_(NULL) { | 151 close_button_(NULL), |
152 never_button_(NULL), | |
Peter Kasting
2013/09/09 18:19:02
Nit: This isn't a good name for this button. Perh
npentrel
2013/09/09 22:08:34
Done.
| |
153 save_button_(NULL) { | |
152 // Compensate for built-in vertical padding in the anchor view's image. | 154 // Compensate for built-in vertical padding in the anchor view's image. |
153 set_anchor_view_insets(gfx::Insets(5, 0, 5, 0)); | 155 set_anchor_view_insets(gfx::Insets(5, 0, 5, 0)); |
154 | 156 |
155 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED, | 157 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED, |
156 content::Source<WebContents>(web_contents)); | 158 content::Source<WebContents>(web_contents)); |
157 } | 159 } |
158 | 160 |
159 ContentSettingBubbleContents::~ContentSettingBubbleContents() { | 161 ContentSettingBubbleContents::~ContentSettingBubbleContents() { |
160 STLDeleteValues(&media_menus_); | 162 STLDeleteValues(&media_menus_); |
161 } | 163 } |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
382 } | 384 } |
383 | 385 |
384 if (!bubble_content_empty) { | 386 if (!bubble_content_empty) { |
385 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | 387 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
386 layout->StartRow(0, kSingleColumnSetId); | 388 layout->StartRow(0, kSingleColumnSetId); |
387 layout->AddView(new views::Separator(views::Separator::HORIZONTAL), 1, 1, | 389 layout->AddView(new views::Separator(views::Separator::HORIZONTAL), 1, 1, |
388 GridLayout::FILL, GridLayout::FILL); | 390 GridLayout::FILL, GridLayout::FILL); |
389 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | 391 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
390 } | 392 } |
391 | 393 |
392 const int kDoubleColumnSetId = 1; | 394 if (content_setting_bubble_model_->content_type() == |
393 views::ColumnSet* double_column_set = | 395 CONTENT_SETTINGS_TYPE_SAVE_PASSWORD) { |
394 layout->AddColumnSet(kDoubleColumnSetId); | 396 const int kDoubleColumnSetId = 2; |
Peter Kasting
2013/09/09 18:19:02
Tiny nit: Why order these as (2, 1) instead of (1,
npentrel
2013/09/09 22:08:34
Changed the order. However it is not possible to p
Peter Kasting
2013/09/10 00:22:11
You misunderstood the intent of my comment; sorry
npentrel
2013/09/10 16:46:38
Done. Gotcha.
| |
395 double_column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 1, | 397 views::ColumnSet* double_column_set = |
396 GridLayout::USE_PREF, 0, 0); | 398 layout->AddColumnSet(kDoubleColumnSetId); |
397 double_column_set->AddPaddingColumn( | 399 double_column_set->AddColumn(GridLayout::TRAILING, GridLayout::CENTER, 1, |
398 0, views::kUnrelatedControlHorizontalSpacing); | 400 GridLayout::USE_PREF, 0, 0); |
399 double_column_set->AddColumn(GridLayout::TRAILING, GridLayout::CENTER, 0, | 401 double_column_set->AddPaddingColumn( |
400 GridLayout::USE_PREF, 0, 0); | 402 0, views::kRelatedControlSmallVerticalSpacing); |
403 double_column_set->AddColumn(GridLayout::TRAILING, GridLayout::CENTER, 0, | |
404 GridLayout::USE_PREF, 0, 0); | |
401 | 405 |
402 layout->StartRow(0, kDoubleColumnSetId); | 406 const int kSingleColumnRightSetId = 1; |
403 manage_link_ = new views::Link(UTF8ToUTF16(bubble_content.manage_link)); | 407 views::ColumnSet* right_column_set = |
404 manage_link_->set_listener(this); | 408 layout->AddColumnSet(kSingleColumnRightSetId); |
405 layout->AddView(manage_link_); | 409 right_column_set->AddColumn(GridLayout::TRAILING, GridLayout::FILL, 1, |
406 if (content_setting_bubble_model_->content_type() != | 410 GridLayout::USE_PREF, 0, 0); |
407 CONTENT_SETTINGS_TYPE_SAVE_PASSWORD) { | 411 |
412 never_button_ = new views::LabelButton( | |
413 this, l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_BLACKLIST_BUTTON)); | |
414 never_button_->SetStyle(views::Button::STYLE_NATIVE_TEXTBUTTON); | |
415 save_button_ = new views::LabelButton( | |
416 this, l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_SAVE_BUTTON)); | |
417 save_button_->SetStyle(views::Button::STYLE_NATIVE_TEXTBUTTON); | |
418 manage_link_ = new views::Link(UTF8ToUTF16(bubble_content.manage_link)); | |
419 manage_link_->set_listener(this); | |
420 | |
421 // Buttons row | |
Peter Kasting
2013/09/09 18:19:02
Nit: These comments add nothing to the code (plus,
npentrel
2013/09/09 22:08:34
Done.
| |
422 layout->StartRow(0, kDoubleColumnSetId); | |
423 layout->AddView(never_button_); | |
424 layout->AddView(save_button_); | |
425 | |
426 // Manage link row | |
427 layout->StartRow(0, kSingleColumnRightSetId); | |
428 layout->AddView(manage_link_); | |
429 } else { | |
430 const int kDoubleColumnSetId = 1; | |
431 views::ColumnSet* double_column_set = | |
432 layout->AddColumnSet(kDoubleColumnSetId); | |
433 double_column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 1, | |
434 GridLayout::USE_PREF, 0, 0); | |
435 double_column_set->AddPaddingColumn( | |
436 0, views::kUnrelatedControlHorizontalSpacing); | |
437 double_column_set->AddColumn(GridLayout::TRAILING, GridLayout::CENTER, 0, | |
438 GridLayout::USE_PREF, 0, 0); | |
439 | |
440 layout->StartRow(0, kDoubleColumnSetId); | |
441 manage_link_ = new views::Link(UTF8ToUTF16(bubble_content.manage_link)); | |
442 manage_link_->set_listener(this); | |
443 layout->AddView(manage_link_); | |
444 | |
408 close_button_ = | 445 close_button_ = |
409 new views::LabelButton(this, l10n_util::GetStringUTF16(IDS_DONE)); | 446 new views::LabelButton(this, l10n_util::GetStringUTF16(IDS_DONE)); |
410 close_button_->SetStyle(views::Button::STYLE_NATIVE_TEXTBUTTON); | 447 close_button_->SetStyle(views::Button::STYLE_NATIVE_TEXTBUTTON); |
411 layout->AddView(close_button_); | 448 layout->AddView(close_button_); |
412 } | 449 } |
413 } | 450 } |
414 | 451 |
415 void ContentSettingBubbleContents::ButtonPressed(views::Button* sender, | 452 void ContentSettingBubbleContents::ButtonPressed(views::Button* sender, |
416 const ui::Event& event) { | 453 const ui::Event& event) { |
454 if (sender == save_button_) { | |
Peter Kasting
2013/09/09 18:19:02
Nit: You can simplify this function by handling th
npentrel
2013/09/09 22:08:34
That does not quite work because of the NOTREACHED
Peter Kasting
2013/09/10 00:22:11
My intent was for you to discard the NOTREACHED.
npentrel
2013/09/10 16:46:38
Done.
| |
455 content_setting_bubble_model_->OnSaveClicked(); | |
456 StartFade(false); | |
457 return; | |
458 } | |
459 if (sender == never_button_) { | |
460 content_setting_bubble_model_->OnCancelClicked(); | |
461 StartFade(false); | |
462 return; | |
463 } | |
417 if (sender == close_button_) { | 464 if (sender == close_button_) { |
418 content_setting_bubble_model_->OnDoneClicked(); | 465 content_setting_bubble_model_->OnDoneClicked(); |
419 StartFade(false); | 466 StartFade(false); |
420 return; | 467 return; |
421 } | 468 } |
422 | 469 |
423 for (RadioGroup::const_iterator i(radio_group_.begin()); | 470 for (RadioGroup::const_iterator i(radio_group_.begin()); |
Peter Kasting
2013/09/09 18:19:02
Nit: This doesn't need a loop, it's just std::find
npentrel
2013/09/09 22:08:34
Done.
| |
424 i != radio_group_.end(); ++i) { | 471 i != radio_group_.end(); ++i) { |
425 if (sender == *i) { | 472 if (sender == *i) { |
426 content_setting_bubble_model_->OnRadioClicked(i - radio_group_.begin()); | 473 content_setting_bubble_model_->OnRadioClicked(i - radio_group_.begin()); |
427 return; | 474 return; |
428 } | 475 } |
429 } | 476 } |
430 NOTREACHED() << "unknown radio"; | 477 NOTREACHED() << "unknown radio"; |
431 } | 478 } |
432 | 479 |
433 void ContentSettingBubbleContents::LinkClicked(views::Link* source, | 480 void ContentSettingBubbleContents::LinkClicked(views::Link* source, |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
487 int width = button->GetPreferredSize().width(); | 534 int width = button->GetPreferredSize().width(); |
488 for (int i = 0; i < menu_model->GetItemCount(); ++i) { | 535 for (int i = 0; i < menu_model->GetItemCount(); ++i) { |
489 button->SetText(menu_model->GetLabelAt(i)); | 536 button->SetText(menu_model->GetLabelAt(i)); |
490 width = std::max(width, button->GetPreferredSize().width()); | 537 width = std::max(width, button->GetPreferredSize().width()); |
491 } | 538 } |
492 | 539 |
493 // Recover the title for the menu button. | 540 // Recover the title for the menu button. |
494 button->SetText(title); | 541 button->SetText(title); |
495 return width; | 542 return width; |
496 } | 543 } |
OLD | NEW |