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

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

Issue 2758323002: Broke out layout metric information from ViewsDelegate to LayoutProvider (Closed)
Patch Set: Deleted LayoutDelegate and HarmonyLayoutDelegate. 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
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>
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_typography.h" 21 #include "chrome/browser/ui/views/harmony/chrome_typography.h"
22 #include "chrome/browser/ui/views/harmony/layout_delegate.h" 22 #include "chrome/browser/ui/views/harmony/chrome_views_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
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 ChromeViewsLayoutDelegate::Get()->GetDialogPreferredWidth(
191 DialogWidth::SMALL);
191 if (!preferred_width) 192 if (!preferred_width)
192 preferred_width = (!content_setting_bubble_model_->bubble_content() 193 preferred_width = (!content_setting_bubble_model_->bubble_content()
193 .domain_lists.empty() && 194 .domain_lists.empty() &&
194 (kMinMultiLineContentsWidth > preferred_size.width())) 195 (kMinMultiLineContentsWidth > preferred_size.width()))
195 ? kMinMultiLineContentsWidth 196 ? kMinMultiLineContentsWidth
196 : preferred_size.width(); 197 : preferred_size.width();
197 else 198 else
198 preferred_width -= margins().width(); 199 preferred_width -= margins().width();
199 if (content_setting_bubble_model_->AsSubresourceFilterBubbleModel()) { 200 if (content_setting_bubble_model_->AsSubresourceFilterBubbleModel()) {
200 preferred_size.set_width(std::min(preferred_width, 201 preferred_size.set_width(std::min(preferred_width,
201 kMaxDefaultContentsWidth)); 202 kMaxDefaultContentsWidth));
202 } else { 203 } else {
203 preferred_size.set_width(std::min(preferred_width, kMaxContentsWidth)); 204 preferred_size.set_width(std::min(preferred_width, kMaxContentsWidth));
204 } 205 }
205 return preferred_size; 206 return preferred_size;
206 } 207 }
207 208
208 void ContentSettingBubbleContents::Init() { 209 void ContentSettingBubbleContents::Init() {
209 using views::GridLayout; 210 using views::GridLayout;
210 211
211 GridLayout* layout = new views::GridLayout(this); 212 GridLayout* layout = new views::GridLayout(this);
212 SetLayoutManager(layout); 213 SetLayoutManager(layout);
213 const LayoutDelegate* layout_delegate = LayoutDelegate::Get(); 214 const ChromeViewsLayoutDelegate* layout_delegate =
214 const int related_control_horizontal_spacing = layout_delegate->GetMetric( 215 ChromeViewsLayoutDelegate::Get();
215 LayoutDelegate::Metric::RELATED_CONTROL_HORIZONTAL_SPACING); 216 const int related_control_horizontal_spacing =
216 const int related_control_vertical_spacing = layout_delegate->GetMetric( 217 layout_delegate->GetDistanceMetric(
217 LayoutDelegate::Metric::RELATED_CONTROL_VERTICAL_SPACING); 218 ChromeDistanceMetric::RELATED_CONTROL_HORIZONTAL);
218 const int unrelated_control_vertical_spacing = layout_delegate->GetMetric( 219 const int related_control_vertical_spacing =
219 LayoutDelegate::Metric::UNRELATED_CONTROL_VERTICAL_SPACING); 220 layout_delegate->GetDistanceMetric(
221 ChromeDistanceMetric::RELATED_CONTROL_VERTICAL);
222 const int unrelated_control_vertical_spacing =
223 layout_delegate->GetDistanceMetric(
224 ChromeDistanceMetric::UNRELATED_CONTROL_VERTICAL);
220 225
221 const int kSingleColumnSetId = 0; 226 const int kSingleColumnSetId = 0;
222 views::ColumnSet* column_set = layout->AddColumnSet(kSingleColumnSetId); 227 views::ColumnSet* column_set = layout->AddColumnSet(kSingleColumnSetId);
223 column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 1, 228 column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 1,
224 GridLayout::USE_PREF, 0, 0); 229 GridLayout::USE_PREF, 0, 0);
225 column_set->AddPaddingColumn(0, related_control_horizontal_spacing); 230 column_set->AddPaddingColumn(0, related_control_horizontal_spacing);
226 column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 1, 231 column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 1,
227 GridLayout::USE_PREF, 0, 0); 232 GridLayout::USE_PREF, 0, 0);
228 233
229 const ContentSettingBubbleModel::BubbleContent& bubble_content = 234 const ContentSettingBubbleModel::BubbleContent& bubble_content =
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 row++; 302 row++;
298 bubble_content_empty = false; 303 bubble_content_empty = false;
299 } 304 }
300 } 305 }
301 306
302 const int indented_kSingleColumnSetId = 3; 307 const int indented_kSingleColumnSetId = 3;
303 // Insert a column set with greater indent. 308 // Insert a column set with greater indent.
304 views::ColumnSet* indented_single_column_set = 309 views::ColumnSet* indented_single_column_set =
305 layout->AddColumnSet(indented_kSingleColumnSetId); 310 layout->AddColumnSet(indented_kSingleColumnSetId);
306 indented_single_column_set->AddPaddingColumn( 311 indented_single_column_set->AddPaddingColumn(
307 0, 312 0, layout_delegate->GetDistanceMetric(
308 layout_delegate->GetMetric( 313 ChromeDistanceMetric::SUBSECTION_HORIZONTAL_INDENT));
309 LayoutDelegate::Metric::SUBSECTION_HORIZONTAL_INDENT));
310 indented_single_column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 314 indented_single_column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL,
311 1, GridLayout::USE_PREF, 0, 0); 315 1, GridLayout::USE_PREF, 0, 0);
312 316
313 const ContentSettingBubbleModel::RadioGroup& radio_group = 317 const ContentSettingBubbleModel::RadioGroup& radio_group =
314 bubble_content.radio_group; 318 bubble_content.radio_group;
315 if (!radio_group.radio_items.empty()) { 319 if (!radio_group.radio_items.empty()) {
316 if (!bubble_content_empty) 320 if (!bubble_content_empty)
317 layout->AddPaddingRow(0, related_control_vertical_spacing); 321 layout->AddPaddingRow(0, related_control_vertical_spacing);
318 for (ContentSettingBubbleModel::RadioItems::const_iterator i( 322 for (ContentSettingBubbleModel::RadioItems::const_iterator i(
319 radio_group.radio_items.begin()); 323 radio_group.radio_items.begin());
(...skipping 20 matching lines...) Expand all
340 // to call SetChecked() on them. 344 // to call SetChecked() on them.
341 radio_group_[radio_group.default_item]->SetChecked(true); 345 radio_group_[radio_group.default_item]->SetChecked(true);
342 } 346 }
343 347
344 // Layout code for the media device menus. 348 // Layout code for the media device menus.
345 if (content_setting_bubble_model_->AsMediaStreamBubbleModel()) { 349 if (content_setting_bubble_model_->AsMediaStreamBubbleModel()) {
346 const int kMediaMenuColumnSetId = 4; 350 const int kMediaMenuColumnSetId = 4;
347 views::ColumnSet* menu_column_set = 351 views::ColumnSet* menu_column_set =
348 layout->AddColumnSet(kMediaMenuColumnSetId); 352 layout->AddColumnSet(kMediaMenuColumnSetId);
349 menu_column_set->AddPaddingColumn( 353 menu_column_set->AddPaddingColumn(
350 0, 354 0, layout_delegate->GetDistanceMetric(
351 layout_delegate->GetMetric( 355 ChromeDistanceMetric::SUBSECTION_HORIZONTAL_INDENT));
352 LayoutDelegate::Metric::SUBSECTION_HORIZONTAL_INDENT));
353 menu_column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 0, 356 menu_column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 0,
354 GridLayout::USE_PREF, 0, 0); 357 GridLayout::USE_PREF, 0, 0);
355 menu_column_set->AddPaddingColumn(0, related_control_horizontal_spacing); 358 menu_column_set->AddPaddingColumn(0, related_control_horizontal_spacing);
356 menu_column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 1, 359 menu_column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 1,
357 GridLayout::USE_PREF, 0, 0); 360 GridLayout::USE_PREF, 0, 0);
358 361
359 for (ContentSettingBubbleModel::MediaMenuMap::const_iterator i( 362 for (ContentSettingBubbleModel::MediaMenuMap::const_iterator i(
360 bubble_content.media_menus.begin()); 363 bubble_content.media_menus.begin());
361 i != bubble_content.media_menus.end(); ++i) { 364 i != bubble_content.media_menus.end(); ++i) {
362 if (!bubble_content_empty) 365 if (!bubble_content_empty)
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 DCHECK(i != list_item_links_.end()); 510 DCHECK(i != list_item_links_.end());
508 content_setting_bubble_model_->OnListItemClicked(i->second); 511 content_setting_bubble_model_->OnListItemClicked(i->second);
509 } 512 }
510 513
511 void ContentSettingBubbleContents::OnPerformAction(views::Combobox* combobox) { 514 void ContentSettingBubbleContents::OnPerformAction(views::Combobox* combobox) {
512 MediaComboboxModel* model = 515 MediaComboboxModel* model =
513 static_cast<MediaComboboxModel*>(combobox->model()); 516 static_cast<MediaComboboxModel*>(combobox->model());
514 content_setting_bubble_model_->OnMediaMenuClicked( 517 content_setting_bubble_model_->OnMediaMenuClicked(
515 model->type(), model->GetDevices()[combobox->selected_index()].id); 518 model->type(), model->GetDevices()[combobox->selected_index()].id);
516 } 519 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698