| 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 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 ContentSettingBubbleContents::ContentSettingBubbleContents( | 140 ContentSettingBubbleContents::ContentSettingBubbleContents( |
| 141 ContentSettingBubbleModel* content_setting_bubble_model, | 141 ContentSettingBubbleModel* content_setting_bubble_model, |
| 142 content::WebContents* web_contents, | 142 content::WebContents* web_contents, |
| 143 views::View* anchor_view, | 143 views::View* anchor_view, |
| 144 views::BubbleBorder::Arrow arrow) | 144 views::BubbleBorder::Arrow arrow) |
| 145 : content::WebContentsObserver(web_contents), | 145 : content::WebContentsObserver(web_contents), |
| 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 custom_link_(NULL), | 148 custom_link_(NULL), |
| 149 manage_link_(NULL), | 149 manage_link_(NULL), |
| 150 close_button_(NULL) { | 150 close_button_(NULL), |
| 151 learn_more_link_(NULL) { |
| 151 // Compensate for built-in vertical padding in the anchor view's image. | 152 // Compensate for built-in vertical padding in the anchor view's image. |
| 152 set_anchor_view_insets(gfx::Insets(5, 0, 5, 0)); | 153 set_anchor_view_insets(gfx::Insets(5, 0, 5, 0)); |
| 153 } | 154 } |
| 154 | 155 |
| 155 ContentSettingBubbleContents::~ContentSettingBubbleContents() { | 156 ContentSettingBubbleContents::~ContentSettingBubbleContents() { |
| 156 STLDeleteValues(&media_menus_); | 157 STLDeleteValues(&media_menus_); |
| 157 } | 158 } |
| 158 | 159 |
| 159 gfx::Size ContentSettingBubbleContents::GetPreferredSize() const { | 160 gfx::Size ContentSettingBubbleContents::GetPreferredSize() const { |
| 160 gfx::Size preferred_size(views::View::GetPreferredSize()); | 161 gfx::Size preferred_size(views::View::GetPreferredSize()); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 182 void ContentSettingBubbleContents::Init() { | 183 void ContentSettingBubbleContents::Init() { |
| 183 using views::GridLayout; | 184 using views::GridLayout; |
| 184 | 185 |
| 185 GridLayout* layout = new views::GridLayout(this); | 186 GridLayout* layout = new views::GridLayout(this); |
| 186 SetLayoutManager(layout); | 187 SetLayoutManager(layout); |
| 187 | 188 |
| 188 const int kSingleColumnSetId = 0; | 189 const int kSingleColumnSetId = 0; |
| 189 views::ColumnSet* column_set = layout->AddColumnSet(kSingleColumnSetId); | 190 views::ColumnSet* column_set = layout->AddColumnSet(kSingleColumnSetId); |
| 190 column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 1, | 191 column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 1, |
| 191 GridLayout::USE_PREF, 0, 0); | 192 GridLayout::USE_PREF, 0, 0); |
| 193 column_set->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing); |
| 194 column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 1, |
| 195 GridLayout::USE_PREF, 0, 0); |
| 192 | 196 |
| 193 const ContentSettingBubbleModel::BubbleContent& bubble_content = | 197 const ContentSettingBubbleModel::BubbleContent& bubble_content = |
| 194 content_setting_bubble_model_->bubble_content(); | 198 content_setting_bubble_model_->bubble_content(); |
| 195 bool bubble_content_empty = true; | 199 bool bubble_content_empty = true; |
| 196 | 200 |
| 197 if (!bubble_content.title.empty()) { | 201 if (!bubble_content.title.empty()) { |
| 198 views::Label* title_label = new views::Label(base::UTF8ToUTF16( | 202 views::Label* title_label = new views::Label(base::UTF8ToUTF16( |
| 199 bubble_content.title)); | 203 bubble_content.title)); |
| 200 title_label->SetMultiLine(true); | 204 title_label->SetMultiLine(true); |
| 201 title_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 205 title_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 202 layout->StartRow(0, kSingleColumnSetId); | 206 layout->StartRow(0, kSingleColumnSetId); |
| 203 layout->AddView(title_label); | 207 layout->AddView(title_label); |
| 204 bubble_content_empty = false; | 208 bubble_content_empty = false; |
| 205 } | 209 } |
| 206 | 210 |
| 211 if (!bubble_content.learn_more_link.empty()) { |
| 212 learn_more_link_ = |
| 213 new views::Link(base::UTF8ToUTF16(bubble_content.learn_more_link)); |
| 214 learn_more_link_->set_listener(this); |
| 215 learn_more_link_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 216 layout->AddView(learn_more_link_); |
| 217 bubble_content_empty = false; |
| 218 } |
| 219 |
| 207 if (content_setting_bubble_model_->content_type() == | 220 if (content_setting_bubble_model_->content_type() == |
| 208 CONTENT_SETTINGS_TYPE_POPUPS) { | 221 CONTENT_SETTINGS_TYPE_POPUPS) { |
| 209 const int kPopupColumnSetId = 2; | 222 const int kPopupColumnSetId = 2; |
| 210 views::ColumnSet* popup_column_set = | 223 views::ColumnSet* popup_column_set = |
| 211 layout->AddColumnSet(kPopupColumnSetId); | 224 layout->AddColumnSet(kPopupColumnSetId); |
| 212 popup_column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 0, | 225 popup_column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 0, |
| 213 GridLayout::USE_PREF, 0, 0); | 226 GridLayout::USE_PREF, 0, 0); |
| 214 popup_column_set->AddPaddingColumn( | 227 popup_column_set->AddPaddingColumn( |
| 215 0, views::kRelatedControlHorizontalSpacing); | 228 0, views::kRelatedControlHorizontalSpacing); |
| 216 popup_column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 1, | 229 popup_column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 1, |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 420 content_setting_bubble_model_->OnRadioClicked(i - radio_group_.begin()); | 433 content_setting_bubble_model_->OnRadioClicked(i - radio_group_.begin()); |
| 421 return; | 434 return; |
| 422 } | 435 } |
| 423 DCHECK_EQ(sender, close_button_); | 436 DCHECK_EQ(sender, close_button_); |
| 424 content_setting_bubble_model_->OnDoneClicked(); | 437 content_setting_bubble_model_->OnDoneClicked(); |
| 425 GetWidget()->Close(); | 438 GetWidget()->Close(); |
| 426 } | 439 } |
| 427 | 440 |
| 428 void ContentSettingBubbleContents::LinkClicked(views::Link* source, | 441 void ContentSettingBubbleContents::LinkClicked(views::Link* source, |
| 429 int event_flags) { | 442 int event_flags) { |
| 443 if (source == learn_more_link_) { |
| 444 content_setting_bubble_model_->OnLearnMoreLinkClicked(); |
| 445 GetWidget()->Close(); |
| 446 return; |
| 447 } |
| 430 if (source == custom_link_) { | 448 if (source == custom_link_) { |
| 431 content_setting_bubble_model_->OnCustomLinkClicked(); | 449 content_setting_bubble_model_->OnCustomLinkClicked(); |
| 432 GetWidget()->Close(); | 450 GetWidget()->Close(); |
| 433 return; | 451 return; |
| 434 } | 452 } |
| 435 if (source == manage_link_) { | 453 if (source == manage_link_) { |
| 436 GetWidget()->Close(); | 454 GetWidget()->Close(); |
| 437 content_setting_bubble_model_->OnManageLinkClicked(); | 455 content_setting_bubble_model_->OnManageLinkClicked(); |
| 438 // CAREFUL: Showing the settings window activates it, which deactivates the | 456 // CAREFUL: Showing the settings window activates it, which deactivates the |
| 439 // info bubble, which causes it to close, which deletes us. | 457 // info bubble, which causes it to close, which deletes us. |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 472 int width = button->GetPreferredSize().width(); | 490 int width = button->GetPreferredSize().width(); |
| 473 for (int i = 0; i < menu_model->GetItemCount(); ++i) { | 491 for (int i = 0; i < menu_model->GetItemCount(); ++i) { |
| 474 button->SetText(menu_model->GetLabelAt(i)); | 492 button->SetText(menu_model->GetLabelAt(i)); |
| 475 width = std::max(width, button->GetPreferredSize().width()); | 493 width = std::max(width, button->GetPreferredSize().width()); |
| 476 } | 494 } |
| 477 | 495 |
| 478 // Recover the title for the menu button. | 496 // Recover the title for the menu button. |
| 479 button->SetText(title); | 497 button->SetText(title); |
| 480 return width; | 498 return width; |
| 481 } | 499 } |
| OLD | NEW |