| 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> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/stl_util.h" | 14 #include "base/stl_util.h" |
| 15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
| 16 #include "chrome/browser/media/webrtc/media_capture_devices_dispatcher.h" | 16 #include "chrome/browser/media/webrtc/media_capture_devices_dispatcher.h" |
| 17 #include "chrome/browser/plugins/plugin_finder.h" | 17 #include "chrome/browser/plugins/plugin_finder.h" |
| 18 #include "chrome/browser/plugins/plugin_metadata.h" | 18 #include "chrome/browser/plugins/plugin_metadata.h" |
| 19 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h" | 19 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h" |
| 20 #include "chrome/browser/ui/layout_constants.h" | 20 #include "chrome/browser/ui/layout_constants.h" |
| 21 #include "chrome/browser/ui/views/harmony/chrome_layout_delegate.h" |
| 21 #include "chrome/browser/ui/views/harmony/chrome_typography.h" | 22 #include "chrome/browser/ui/views/harmony/chrome_typography.h" |
| 22 #include "chrome/browser/ui/views/harmony/layout_delegate.h" | |
| 23 #include "chrome/grit/generated_resources.h" | 23 #include "chrome/grit/generated_resources.h" |
| 24 #include "components/content_settings/core/browser/host_content_settings_map.h" | 24 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| 25 #include "components/strings/grit/components_strings.h" | 25 #include "components/strings/grit/components_strings.h" |
| 26 #include "content/public/browser/navigation_handle.h" | 26 #include "content/public/browser/navigation_handle.h" |
| 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" |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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); |
| 185 } | 185 } |
| 186 | 186 |
| 187 gfx::Size ContentSettingBubbleContents::GetPreferredSize() const { | 187 gfx::Size ContentSettingBubbleContents::GetPreferredSize() const { |
| 188 gfx::Size preferred_size(views::View::GetPreferredSize()); | 188 gfx::Size preferred_size(views::View::GetPreferredSize()); |
| 189 int preferred_width = LayoutDelegate::Get()->GetDialogPreferredWidth( | 189 int preferred_width = |
| 190 LayoutDelegate::DialogWidth::SMALL); | 190 ChromeLayoutDelegate::Get()->GetDialogPreferredWidth(DialogWidth::SMALL); |
| 191 if (!preferred_width) | 191 if (!preferred_width) |
| 192 preferred_width = (!content_setting_bubble_model_->bubble_content() | 192 preferred_width = (!content_setting_bubble_model_->bubble_content() |
| 193 .domain_lists.empty() && | 193 .domain_lists.empty() && |
| 194 (kMinMultiLineContentsWidth > preferred_size.width())) | 194 (kMinMultiLineContentsWidth > preferred_size.width())) |
| 195 ? kMinMultiLineContentsWidth | 195 ? kMinMultiLineContentsWidth |
| 196 : preferred_size.width(); | 196 : preferred_size.width(); |
| 197 else | 197 else |
| 198 preferred_width -= margins().width(); | 198 preferred_width -= margins().width(); |
| 199 if (content_setting_bubble_model_->AsSubresourceFilterBubbleModel()) { | 199 if (content_setting_bubble_model_->AsSubresourceFilterBubbleModel()) { |
| 200 preferred_size.set_width(std::min(preferred_width, | 200 preferred_size.set_width(std::min(preferred_width, |
| 201 kMaxDefaultContentsWidth)); | 201 kMaxDefaultContentsWidth)); |
| 202 } else { | 202 } else { |
| 203 preferred_size.set_width(std::min(preferred_width, kMaxContentsWidth)); | 203 preferred_size.set_width(std::min(preferred_width, kMaxContentsWidth)); |
| 204 } | 204 } |
| 205 return preferred_size; | 205 return preferred_size; |
| 206 } | 206 } |
| 207 | 207 |
| 208 void ContentSettingBubbleContents::Init() { | 208 void ContentSettingBubbleContents::Init() { |
| 209 using views::GridLayout; | 209 using views::GridLayout; |
| 210 | 210 |
| 211 GridLayout* layout = new views::GridLayout(this); | 211 GridLayout* layout = new views::GridLayout(this); |
| 212 SetLayoutManager(layout); | 212 SetLayoutManager(layout); |
| 213 const LayoutDelegate* layout_delegate = LayoutDelegate::Get(); | 213 const ChromeLayoutDelegate* layout_delegate = ChromeLayoutDelegate::Get(); |
| 214 const int related_control_horizontal_spacing = layout_delegate->GetMetric( | 214 const int related_control_horizontal_spacing = |
| 215 LayoutDelegate::Metric::RELATED_CONTROL_HORIZONTAL_SPACING); | 215 layout_delegate->GetDistanceMetric( |
| 216 const int related_control_vertical_spacing = layout_delegate->GetMetric( | 216 ChromeDistanceMetric::RELATED_CONTROL_HORIZONTAL); |
| 217 LayoutDelegate::Metric::RELATED_CONTROL_VERTICAL_SPACING); | 217 const int related_control_vertical_spacing = |
| 218 const int unrelated_control_vertical_spacing = layout_delegate->GetMetric( | 218 layout_delegate->GetDistanceMetric( |
| 219 LayoutDelegate::Metric::UNRELATED_CONTROL_VERTICAL_SPACING); | 219 ChromeDistanceMetric::RELATED_CONTROL_VERTICAL); |
| 220 const int unrelated_control_vertical_spacing = |
| 221 layout_delegate->GetDistanceMetric( |
| 222 ChromeDistanceMetric::UNRELATED_CONTROL_VERTICAL); |
| 220 | 223 |
| 221 const int kSingleColumnSetId = 0; | 224 const int kSingleColumnSetId = 0; |
| 222 views::ColumnSet* column_set = layout->AddColumnSet(kSingleColumnSetId); | 225 views::ColumnSet* column_set = layout->AddColumnSet(kSingleColumnSetId); |
| 223 column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 1, | 226 column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 1, |
| 224 GridLayout::USE_PREF, 0, 0); | 227 GridLayout::USE_PREF, 0, 0); |
| 225 column_set->AddPaddingColumn(0, related_control_horizontal_spacing); | 228 column_set->AddPaddingColumn(0, related_control_horizontal_spacing); |
| 226 column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 1, | 229 column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 1, |
| 227 GridLayout::USE_PREF, 0, 0); | 230 GridLayout::USE_PREF, 0, 0); |
| 228 | 231 |
| 229 const ContentSettingBubbleModel::BubbleContent& bubble_content = | 232 const ContentSettingBubbleModel::BubbleContent& bubble_content = |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 row++; | 300 row++; |
| 298 bubble_content_empty = false; | 301 bubble_content_empty = false; |
| 299 } | 302 } |
| 300 } | 303 } |
| 301 | 304 |
| 302 const int indented_kSingleColumnSetId = 3; | 305 const int indented_kSingleColumnSetId = 3; |
| 303 // Insert a column set with greater indent. | 306 // Insert a column set with greater indent. |
| 304 views::ColumnSet* indented_single_column_set = | 307 views::ColumnSet* indented_single_column_set = |
| 305 layout->AddColumnSet(indented_kSingleColumnSetId); | 308 layout->AddColumnSet(indented_kSingleColumnSetId); |
| 306 indented_single_column_set->AddPaddingColumn( | 309 indented_single_column_set->AddPaddingColumn( |
| 307 0, | 310 0, layout_delegate->GetDistanceMetric( |
| 308 layout_delegate->GetMetric( | 311 ChromeDistanceMetric::SUBSECTION_HORIZONTAL_INDENT)); |
| 309 LayoutDelegate::Metric::SUBSECTION_HORIZONTAL_INDENT)); | |
| 310 indented_single_column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, | 312 indented_single_column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, |
| 311 1, GridLayout::USE_PREF, 0, 0); | 313 1, GridLayout::USE_PREF, 0, 0); |
| 312 | 314 |
| 313 const ContentSettingBubbleModel::RadioGroup& radio_group = | 315 const ContentSettingBubbleModel::RadioGroup& radio_group = |
| 314 bubble_content.radio_group; | 316 bubble_content.radio_group; |
| 315 if (!radio_group.radio_items.empty()) { | 317 if (!radio_group.radio_items.empty()) { |
| 316 if (!bubble_content_empty) | 318 if (!bubble_content_empty) |
| 317 layout->AddPaddingRow(0, related_control_vertical_spacing); | 319 layout->AddPaddingRow(0, related_control_vertical_spacing); |
| 318 for (ContentSettingBubbleModel::RadioItems::const_iterator i( | 320 for (ContentSettingBubbleModel::RadioItems::const_iterator i( |
| 319 radio_group.radio_items.begin()); | 321 radio_group.radio_items.begin()); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 340 // to call SetChecked() on them. | 342 // to call SetChecked() on them. |
| 341 radio_group_[radio_group.default_item]->SetChecked(true); | 343 radio_group_[radio_group.default_item]->SetChecked(true); |
| 342 } | 344 } |
| 343 | 345 |
| 344 // Layout code for the media device menus. | 346 // Layout code for the media device menus. |
| 345 if (content_setting_bubble_model_->AsMediaStreamBubbleModel()) { | 347 if (content_setting_bubble_model_->AsMediaStreamBubbleModel()) { |
| 346 const int kMediaMenuColumnSetId = 4; | 348 const int kMediaMenuColumnSetId = 4; |
| 347 views::ColumnSet* menu_column_set = | 349 views::ColumnSet* menu_column_set = |
| 348 layout->AddColumnSet(kMediaMenuColumnSetId); | 350 layout->AddColumnSet(kMediaMenuColumnSetId); |
| 349 menu_column_set->AddPaddingColumn( | 351 menu_column_set->AddPaddingColumn( |
| 350 0, | 352 0, layout_delegate->GetDistanceMetric( |
| 351 layout_delegate->GetMetric( | 353 ChromeDistanceMetric::SUBSECTION_HORIZONTAL_INDENT)); |
| 352 LayoutDelegate::Metric::SUBSECTION_HORIZONTAL_INDENT)); | |
| 353 menu_column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 0, | 354 menu_column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 0, |
| 354 GridLayout::USE_PREF, 0, 0); | 355 GridLayout::USE_PREF, 0, 0); |
| 355 menu_column_set->AddPaddingColumn(0, related_control_horizontal_spacing); | 356 menu_column_set->AddPaddingColumn(0, related_control_horizontal_spacing); |
| 356 menu_column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 1, | 357 menu_column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 1, |
| 357 GridLayout::USE_PREF, 0, 0); | 358 GridLayout::USE_PREF, 0, 0); |
| 358 | 359 |
| 359 for (ContentSettingBubbleModel::MediaMenuMap::const_iterator i( | 360 for (ContentSettingBubbleModel::MediaMenuMap::const_iterator i( |
| 360 bubble_content.media_menus.begin()); | 361 bubble_content.media_menus.begin()); |
| 361 i != bubble_content.media_menus.end(); ++i) { | 362 i != bubble_content.media_menus.end(); ++i) { |
| 362 if (!bubble_content_empty) | 363 if (!bubble_content_empty) |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 507 DCHECK(i != list_item_links_.end()); | 508 DCHECK(i != list_item_links_.end()); |
| 508 content_setting_bubble_model_->OnListItemClicked(i->second); | 509 content_setting_bubble_model_->OnListItemClicked(i->second); |
| 509 } | 510 } |
| 510 | 511 |
| 511 void ContentSettingBubbleContents::OnPerformAction(views::Combobox* combobox) { | 512 void ContentSettingBubbleContents::OnPerformAction(views::Combobox* combobox) { |
| 512 MediaComboboxModel* model = | 513 MediaComboboxModel* model = |
| 513 static_cast<MediaComboboxModel*>(combobox->model()); | 514 static_cast<MediaComboboxModel*>(combobox->model()); |
| 514 content_setting_bubble_model_->OnMediaMenuClicked( | 515 content_setting_bubble_model_->OnMediaMenuClicked( |
| 515 model->type(), model->GetDevices()[combobox->selected_index()].id); | 516 model->type(), model->GetDevices()[combobox->selected_index()].id); |
| 516 } | 517 } |
| OLD | NEW |