| 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 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 // ContentSettingBubbleContents ----------------------------------------------- | 139 // ContentSettingBubbleContents ----------------------------------------------- |
| 140 | 140 |
| 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 cancel_button_(NULL), |
| 150 save_button_(NULL), |
| 149 custom_link_(NULL), | 151 custom_link_(NULL), |
| 150 manage_link_(NULL), | 152 manage_link_(NULL), |
| 151 close_button_(NULL), | 153 close_button_(NULL) { |
| 152 never_button_(NULL), | |
| 153 save_button_(NULL) { | |
| 154 // 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. |
| 155 set_anchor_view_insets(gfx::Insets(5, 0, 5, 0)); | 155 set_anchor_view_insets(gfx::Insets(5, 0, 5, 0)); |
| 156 | 156 |
| 157 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED, | 157 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED, |
| 158 content::Source<WebContents>(web_contents)); | 158 content::Source<WebContents>(web_contents)); |
| 159 } | 159 } |
| 160 | 160 |
| 161 ContentSettingBubbleContents::~ContentSettingBubbleContents() { | 161 ContentSettingBubbleContents::~ContentSettingBubbleContents() { |
| 162 STLDeleteValues(&media_menus_); | 162 STLDeleteValues(&media_menus_); |
| 163 } | 163 } |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 custom_link_ = new views::Link(UTF8ToUTF16(bubble_content.custom_link)); | 376 custom_link_ = new views::Link(UTF8ToUTF16(bubble_content.custom_link)); |
| 377 custom_link_->SetEnabled(bubble_content.custom_link_enabled); | 377 custom_link_->SetEnabled(bubble_content.custom_link_enabled); |
| 378 custom_link_->set_listener(this); | 378 custom_link_->set_listener(this); |
| 379 if (!bubble_content_empty) | 379 if (!bubble_content_empty) |
| 380 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | 380 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
| 381 layout->StartRow(0, kSingleColumnSetId); | 381 layout->StartRow(0, kSingleColumnSetId); |
| 382 layout->AddView(custom_link_); | 382 layout->AddView(custom_link_); |
| 383 bubble_content_empty = false; | 383 bubble_content_empty = false; |
| 384 } | 384 } |
| 385 | 385 |
| 386 if (!bubble_content_empty) { | 386 const int kDoubleColumnSetId = 1; |
| 387 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | 387 views::ColumnSet* double_column_set = |
| 388 layout->StartRow(0, kSingleColumnSetId); | 388 layout->AddColumnSet(kDoubleColumnSetId); |
| 389 layout->AddView(new views::Separator(views::Separator::HORIZONTAL), 1, 1, | |
| 390 GridLayout::FILL, GridLayout::FILL); | |
| 391 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | |
| 392 } | |
| 393 | |
| 394 if (content_setting_bubble_model_->content_type() == | 389 if (content_setting_bubble_model_->content_type() == |
| 395 CONTENT_SETTINGS_TYPE_SAVE_PASSWORD) { | 390 CONTENT_SETTINGS_TYPE_SAVE_PASSWORD) { |
| 396 const int kDoubleColumnSetId = 2; | |
| 397 views::ColumnSet* double_column_set = | |
| 398 layout->AddColumnSet(kDoubleColumnSetId); | |
| 399 double_column_set->AddColumn(GridLayout::TRAILING, GridLayout::CENTER, 1, | 391 double_column_set->AddColumn(GridLayout::TRAILING, GridLayout::CENTER, 1, |
| 400 GridLayout::USE_PREF, 0, 0); | 392 GridLayout::USE_PREF, 0, 0); |
| 401 double_column_set->AddPaddingColumn( | 393 double_column_set->AddPaddingColumn( |
| 402 0, views::kRelatedControlSmallVerticalSpacing); | 394 0, views::kRelatedControlSmallVerticalSpacing); |
| 403 double_column_set->AddColumn(GridLayout::TRAILING, GridLayout::CENTER, 0, | 395 double_column_set->AddColumn(GridLayout::TRAILING, GridLayout::CENTER, 0, |
| 404 GridLayout::USE_PREF, 0, 0); | 396 GridLayout::USE_PREF, 0, 0); |
| 405 | 397 |
| 406 const int kSingleColumnRightSetId = 1; | 398 const int kSingleColumnRightSetId = 2; |
| 407 views::ColumnSet* right_column_set = | 399 views::ColumnSet* right_column_set = |
| 408 layout->AddColumnSet(kSingleColumnRightSetId); | 400 layout->AddColumnSet(kSingleColumnRightSetId); |
| 409 right_column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 1, | 401 right_column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 1, |
| 410 GridLayout::USE_PREF, 0, 0); | 402 GridLayout::USE_PREF, 0, 0); |
| 411 | 403 |
| 412 never_button_ = new views::LabelButton( | 404 cancel_button_ = new views::LabelButton( |
| 413 this, l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_BLACKLIST_BUTTON)); | 405 this, l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_BLACKLIST_BUTTON)); |
| 414 never_button_->SetStyle(views::Button::STYLE_NATIVE_TEXTBUTTON); | 406 cancel_button_->SetStyle(views::Button::STYLE_NATIVE_TEXTBUTTON); |
| 415 save_button_ = new views::LabelButton( | 407 save_button_ = new views::LabelButton( |
| 416 this, l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_SAVE_BUTTON)); | 408 this, l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_SAVE_BUTTON)); |
| 417 save_button_->SetStyle(views::Button::STYLE_NATIVE_TEXTBUTTON); | 409 save_button_->SetStyle(views::Button::STYLE_NATIVE_TEXTBUTTON); |
| 418 manage_link_ = new views::Link(UTF8ToUTF16(bubble_content.manage_link)); | 410 manage_link_ = new views::Link(UTF8ToUTF16(bubble_content.manage_link)); |
| 419 manage_link_->set_listener(this); | 411 manage_link_->set_listener(this); |
| 420 | 412 |
| 421 // Buttons row | 413 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
| 414 |
| 422 layout->StartRow(0, kDoubleColumnSetId); | 415 layout->StartRow(0, kDoubleColumnSetId); |
| 423 layout->AddView(never_button_); | 416 layout->AddView(cancel_button_); |
| 424 layout->AddView(save_button_); | 417 layout->AddView(save_button_); |
| 425 | 418 |
| 426 // Manage link row | 419 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
| 420 layout->StartRow(0, kSingleColumnSetId); |
| 421 layout->AddView(new views::Separator(views::Separator::HORIZONTAL), 1, 1, |
| 422 GridLayout::FILL, GridLayout::FILL); |
| 423 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
| 424 |
| 427 layout->StartRow(0, kSingleColumnRightSetId); | 425 layout->StartRow(0, kSingleColumnRightSetId); |
| 428 layout->AddView(manage_link_); | 426 layout->AddView(manage_link_); |
| 429 } else { | 427 } else { |
| 430 const int kDoubleColumnSetId = 1; | 428 if (!bubble_content_empty) { |
| 431 views::ColumnSet* double_column_set = | 429 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
| 432 layout->AddColumnSet(kDoubleColumnSetId); | 430 layout->StartRow(0, kSingleColumnSetId); |
| 431 layout->AddView(new views::Separator(views::Separator::HORIZONTAL), 1, 1, |
| 432 GridLayout::FILL, GridLayout::FILL); |
| 433 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
| 434 } |
| 435 |
| 433 double_column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 1, | 436 double_column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 1, |
| 434 GridLayout::USE_PREF, 0, 0); | 437 GridLayout::USE_PREF, 0, 0); |
| 435 double_column_set->AddPaddingColumn( | 438 double_column_set->AddPaddingColumn( |
| 436 0, views::kUnrelatedControlHorizontalSpacing); | 439 0, views::kUnrelatedControlHorizontalSpacing); |
| 437 double_column_set->AddColumn(GridLayout::TRAILING, GridLayout::CENTER, 0, | 440 double_column_set->AddColumn(GridLayout::TRAILING, GridLayout::CENTER, 0, |
| 438 GridLayout::USE_PREF, 0, 0); | 441 GridLayout::USE_PREF, 0, 0); |
| 439 | 442 |
| 440 layout->StartRow(0, kDoubleColumnSetId); | 443 layout->StartRow(0, kDoubleColumnSetId); |
| 441 manage_link_ = new views::Link(UTF8ToUTF16(bubble_content.manage_link)); | 444 manage_link_ = new views::Link(UTF8ToUTF16(bubble_content.manage_link)); |
| 442 manage_link_->set_listener(this); | 445 manage_link_->set_listener(this); |
| 443 layout->AddView(manage_link_); | 446 layout->AddView(manage_link_); |
| 444 | 447 |
| 445 close_button_ = | 448 close_button_ = |
| 446 new views::LabelButton(this, l10n_util::GetStringUTF16(IDS_DONE)); | 449 new views::LabelButton(this, l10n_util::GetStringUTF16(IDS_DONE)); |
| 447 close_button_->SetStyle(views::Button::STYLE_NATIVE_TEXTBUTTON); | 450 close_button_->SetStyle(views::Button::STYLE_NATIVE_TEXTBUTTON); |
| 448 layout->AddView(close_button_); | 451 layout->AddView(close_button_); |
| 449 } | 452 } |
| 450 } | 453 } |
| 451 | 454 |
| 452 void ContentSettingBubbleContents::ButtonPressed(views::Button* sender, | 455 void ContentSettingBubbleContents::ButtonPressed(views::Button* sender, |
| 453 const ui::Event& event) { | 456 const ui::Event& event) { |
| 454 if (sender == save_button_) { | 457 RadioGroup::const_iterator i( |
| 455 content_setting_bubble_model_->OnSaveClicked(); | 458 std::find(radio_group_.begin(), radio_group_.end(), sender)); |
| 456 StartFade(false); | 459 if (i != radio_group_.end()) { |
| 457 return; | 460 content_setting_bubble_model_->OnRadioClicked(i - radio_group_.begin()); |
| 458 } | |
| 459 if (sender == never_button_) { | |
| 460 content_setting_bubble_model_->OnCancelClicked(); | |
| 461 StartFade(false); | |
| 462 return; | |
| 463 } | |
| 464 if (sender == close_button_) { | |
| 465 content_setting_bubble_model_->OnDoneClicked(); | |
| 466 StartFade(false); | |
| 467 return; | 461 return; |
| 468 } | 462 } |
| 469 | 463 |
| 470 for (RadioGroup::const_iterator i(radio_group_.begin()); | 464 if (sender == save_button_) |
| 471 i != radio_group_.end(); ++i) { | 465 content_setting_bubble_model_->OnSaveClicked(); |
| 472 if (sender == *i) { | 466 else if (sender == cancel_button_) |
| 473 content_setting_bubble_model_->OnRadioClicked(i - radio_group_.begin()); | 467 content_setting_bubble_model_->OnCancelClicked(); |
| 474 return; | 468 else if (sender == close_button_) |
| 475 } | 469 content_setting_bubble_model_->OnDoneClicked(); |
| 476 } | 470 else |
| 477 NOTREACHED() << "unknown radio"; | 471 NOTREACHED(); |
| 472 StartFade(false); |
| 478 } | 473 } |
| 479 | 474 |
| 480 void ContentSettingBubbleContents::LinkClicked(views::Link* source, | 475 void ContentSettingBubbleContents::LinkClicked(views::Link* source, |
| 481 int event_flags) { | 476 int event_flags) { |
| 482 if (source == custom_link_) { | 477 if (source == custom_link_) { |
| 483 content_setting_bubble_model_->OnCustomLinkClicked(); | 478 content_setting_bubble_model_->OnCustomLinkClicked(); |
| 484 StartFade(false); | 479 StartFade(false); |
| 485 return; | 480 return; |
| 486 } | 481 } |
| 487 if (source == manage_link_) { | 482 if (source == manage_link_) { |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 534 int width = button->GetPreferredSize().width(); | 529 int width = button->GetPreferredSize().width(); |
| 535 for (int i = 0; i < menu_model->GetItemCount(); ++i) { | 530 for (int i = 0; i < menu_model->GetItemCount(); ++i) { |
| 536 button->SetText(menu_model->GetLabelAt(i)); | 531 button->SetText(menu_model->GetLabelAt(i)); |
| 537 width = std::max(width, button->GetPreferredSize().width()); | 532 width = std::max(width, button->GetPreferredSize().width()); |
| 538 } | 533 } |
| 539 | 534 |
| 540 // Recover the title for the menu button. | 535 // Recover the title for the menu button. |
| 541 button->SetText(title); | 536 button->SetText(title); |
| 542 return width; | 537 return width; |
| 543 } | 538 } |
| OLD | NEW |