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

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: Final feedback addressed 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_layout_provider.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
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 ChromeLayoutProvider::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 ChromeLayoutProvider* provider = ChromeLayoutProvider::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 provider->GetDistanceMetric(views::DISTANCE_RELATED_CONTROL_HORIZONTAL);
216 const int related_control_vertical_spacing = layout_delegate->GetMetric( 216 const int related_control_vertical_spacing =
217 LayoutDelegate::Metric::RELATED_CONTROL_VERTICAL_SPACING); 217 provider->GetDistanceMetric(views::DISTANCE_RELATED_CONTROL_VERTICAL);
218 const int unrelated_control_vertical_spacing = layout_delegate->GetMetric( 218 const int unrelated_control_vertical_spacing =
219 LayoutDelegate::Metric::UNRELATED_CONTROL_VERTICAL_SPACING); 219 provider->GetDistanceMetric(DISTANCE_UNRELATED_CONTROL_VERTICAL);
220 220
221 const int kSingleColumnSetId = 0; 221 const int kSingleColumnSetId = 0;
222 views::ColumnSet* column_set = layout->AddColumnSet(kSingleColumnSetId); 222 views::ColumnSet* column_set = layout->AddColumnSet(kSingleColumnSetId);
223 column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 1, 223 column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 1,
224 GridLayout::USE_PREF, 0, 0); 224 GridLayout::USE_PREF, 0, 0);
225 column_set->AddPaddingColumn(0, related_control_horizontal_spacing); 225 column_set->AddPaddingColumn(0, related_control_horizontal_spacing);
226 column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 1, 226 column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 1,
227 GridLayout::USE_PREF, 0, 0); 227 GridLayout::USE_PREF, 0, 0);
228 228
229 const ContentSettingBubbleModel::BubbleContent& bubble_content = 229 const ContentSettingBubbleModel::BubbleContent& bubble_content =
230 content_setting_bubble_model_->bubble_content(); 230 content_setting_bubble_model_->bubble_content();
231 bool bubble_content_empty = true; 231 bool bubble_content_empty = true;
232 232
233 if (!bubble_content.title.empty()) { 233 if (!bubble_content.title.empty()) {
234 const int title_context = 234 const int title_context =
235 layout_delegate->IsHarmonyMode() 235 provider->IsHarmonyMode()
236 ? static_cast<int>(views::style::CONTEXT_DIALOG_TITLE) 236 ? static_cast<int>(views::style::CONTEXT_DIALOG_TITLE)
237 : CONTEXT_BODY_TEXT_SMALL; 237 : CONTEXT_BODY_TEXT_SMALL;
238 views::Label* title_label = 238 views::Label* title_label =
239 new views::Label(bubble_content.title, title_context); 239 new views::Label(bubble_content.title, title_context);
240 title_label->SetMultiLine(true); 240 title_label->SetMultiLine(true);
241 title_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); 241 title_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
242 layout->StartRow(0, kSingleColumnSetId); 242 layout->StartRow(0, kSingleColumnSetId);
243 layout->AddView(title_label); 243 layout->AddView(title_label);
244 bubble_content_empty = false; 244 bubble_content_empty = false;
245 } 245 }
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 row++; 296 row++;
297 bubble_content_empty = false; 297 bubble_content_empty = false;
298 } 298 }
299 } 299 }
300 300
301 const int indented_kSingleColumnSetId = 3; 301 const int indented_kSingleColumnSetId = 3;
302 // Insert a column set with greater indent. 302 // Insert a column set with greater indent.
303 views::ColumnSet* indented_single_column_set = 303 views::ColumnSet* indented_single_column_set =
304 layout->AddColumnSet(indented_kSingleColumnSetId); 304 layout->AddColumnSet(indented_kSingleColumnSetId);
305 indented_single_column_set->AddPaddingColumn( 305 indented_single_column_set->AddPaddingColumn(
306 0, 306 0, provider->GetDistanceMetric(DISTANCE_SUBSECTION_HORIZONTAL_INDENT));
307 layout_delegate->GetMetric(
308 LayoutDelegate::Metric::SUBSECTION_HORIZONTAL_INDENT));
309 indented_single_column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 307 indented_single_column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL,
310 1, GridLayout::USE_PREF, 0, 0); 308 1, GridLayout::USE_PREF, 0, 0);
311 309
312 const ContentSettingBubbleModel::RadioGroup& radio_group = 310 const ContentSettingBubbleModel::RadioGroup& radio_group =
313 bubble_content.radio_group; 311 bubble_content.radio_group;
314 if (!radio_group.radio_items.empty()) { 312 if (!radio_group.radio_items.empty()) {
315 if (!bubble_content_empty) 313 if (!bubble_content_empty)
316 layout->AddPaddingRow(0, related_control_vertical_spacing); 314 layout->AddPaddingRow(0, related_control_vertical_spacing);
317 for (ContentSettingBubbleModel::RadioItems::const_iterator i( 315 for (ContentSettingBubbleModel::RadioItems::const_iterator i(
318 radio_group.radio_items.begin()); 316 radio_group.radio_items.begin());
319 i != radio_group.radio_items.end(); ++i) { 317 i != radio_group.radio_items.end(); ++i) {
320 views::RadioButton* radio = new views::RadioButton(*i, 0); 318 views::RadioButton* radio = new views::RadioButton(*i, 0);
321 radio->SetEnabled(bubble_content.radio_group_enabled); 319 radio->SetEnabled(bubble_content.radio_group_enabled);
322 radio->set_listener(this); 320 radio->set_listener(this);
323 if (layout_delegate->IsHarmonyMode()) { 321 if (provider->IsHarmonyMode()) {
324 std::unique_ptr<views::LabelButtonBorder> border = 322 std::unique_ptr<views::LabelButtonBorder> border =
325 radio->CreateDefaultBorder(); 323 radio->CreateDefaultBorder();
326 gfx::Insets insets = border->GetInsets(); 324 gfx::Insets insets = border->GetInsets();
327 border->set_insets( 325 border->set_insets(
328 gfx::Insets(insets.top(), 0, insets.bottom(), insets.right())); 326 gfx::Insets(insets.top(), 0, insets.bottom(), insets.right()));
329 radio->SetBorder(std::move(border)); 327 radio->SetBorder(std::move(border));
330 } 328 }
331 radio_group_.push_back(radio); 329 radio_group_.push_back(radio);
332 layout->StartRow(0, indented_kSingleColumnSetId); 330 layout->StartRow(0, indented_kSingleColumnSetId);
333 layout->AddView(radio); 331 layout->AddView(radio);
334 bubble_content_empty = false; 332 bubble_content_empty = false;
335 } 333 }
336 DCHECK(!radio_group_.empty()); 334 DCHECK(!radio_group_.empty());
337 // Now that the buttons have been added to the view hierarchy, it's safe 335 // Now that the buttons have been added to the view hierarchy, it's safe
338 // to call SetChecked() on them. 336 // to call SetChecked() on them.
339 radio_group_[radio_group.default_item]->SetChecked(true); 337 radio_group_[radio_group.default_item]->SetChecked(true);
340 } 338 }
341 339
342 // Layout code for the media device menus. 340 // Layout code for the media device menus.
343 if (content_setting_bubble_model_->AsMediaStreamBubbleModel()) { 341 if (content_setting_bubble_model_->AsMediaStreamBubbleModel()) {
344 const int kMediaMenuColumnSetId = 4; 342 const int kMediaMenuColumnSetId = 4;
345 views::ColumnSet* menu_column_set = 343 views::ColumnSet* menu_column_set =
346 layout->AddColumnSet(kMediaMenuColumnSetId); 344 layout->AddColumnSet(kMediaMenuColumnSetId);
347 menu_column_set->AddPaddingColumn( 345 menu_column_set->AddPaddingColumn(
348 0, 346 0, provider->GetDistanceMetric(DISTANCE_SUBSECTION_HORIZONTAL_INDENT));
349 layout_delegate->GetMetric(
350 LayoutDelegate::Metric::SUBSECTION_HORIZONTAL_INDENT));
351 menu_column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 0, 347 menu_column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 0,
352 GridLayout::USE_PREF, 0, 0); 348 GridLayout::USE_PREF, 0, 0);
353 menu_column_set->AddPaddingColumn(0, related_control_horizontal_spacing); 349 menu_column_set->AddPaddingColumn(0, related_control_horizontal_spacing);
354 menu_column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 1, 350 menu_column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 1,
355 GridLayout::USE_PREF, 0, 0); 351 GridLayout::USE_PREF, 0, 0);
356 352
357 for (ContentSettingBubbleModel::MediaMenuMap::const_iterator i( 353 for (ContentSettingBubbleModel::MediaMenuMap::const_iterator i(
358 bubble_content.media_menus.begin()); 354 bubble_content.media_menus.begin());
359 i != bubble_content.media_menus.end(); ++i) { 355 i != bubble_content.media_menus.end(); ++i) {
360 if (!bubble_content_empty) 356 if (!bubble_content_empty)
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 410
415 if (bubble_content.show_manage_text_as_checkbox) { 411 if (bubble_content.show_manage_text_as_checkbox) {
416 manage_checkbox_ = new views::Checkbox(bubble_content.manage_text); 412 manage_checkbox_ = new views::Checkbox(bubble_content.manage_text);
417 manage_checkbox_->set_listener(this); 413 manage_checkbox_->set_listener(this);
418 layout->AddPaddingRow(0, related_control_vertical_spacing); 414 layout->AddPaddingRow(0, related_control_vertical_spacing);
419 layout->StartRow(0, indented_kSingleColumnSetId); 415 layout->StartRow(0, indented_kSingleColumnSetId);
420 layout->AddView(manage_checkbox_); 416 layout->AddView(manage_checkbox_);
421 } 417 }
422 418
423 if (!bubble_content_empty) { 419 if (!bubble_content_empty) {
424 if (!layout_delegate->IsHarmonyMode()) { 420 if (!provider->IsHarmonyMode()) {
425 layout->AddPaddingRow(0, related_control_vertical_spacing); 421 layout->AddPaddingRow(0, related_control_vertical_spacing);
426 layout->StartRow(0, kSingleColumnSetId); 422 layout->StartRow(0, kSingleColumnSetId);
427 layout->AddView(new views::Separator(), 1, 1, GridLayout::FILL, 423 layout->AddView(new views::Separator(), 1, 1, GridLayout::FILL,
428 GridLayout::FILL); 424 GridLayout::FILL);
429 } 425 }
430 layout->AddPaddingRow(0, related_control_vertical_spacing); 426 layout->AddPaddingRow(0, related_control_vertical_spacing);
431 } 427 }
432 } 428 }
433 429
434 views::View* ContentSettingBubbleContents::CreateExtraView() { 430 views::View* ContentSettingBubbleContents::CreateExtraView() {
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 DCHECK(i != list_item_links_.end()); 512 DCHECK(i != list_item_links_.end());
517 content_setting_bubble_model_->OnListItemClicked(i->second); 513 content_setting_bubble_model_->OnListItemClicked(i->second);
518 } 514 }
519 515
520 void ContentSettingBubbleContents::OnPerformAction(views::Combobox* combobox) { 516 void ContentSettingBubbleContents::OnPerformAction(views::Combobox* combobox) {
521 MediaComboboxModel* model = 517 MediaComboboxModel* model =
522 static_cast<MediaComboboxModel*>(combobox->model()); 518 static_cast<MediaComboboxModel*>(combobox->model());
523 content_setting_bubble_model_->OnMediaMenuClicked( 519 content_setting_bubble_model_->OnMediaMenuClicked(
524 model->type(), model->GetDevices()[combobox->selected_index()].id); 520 model->type(), model->GetDevices()[combobox->selected_index()].id);
525 } 521 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/collected_cookies_views.cc ('k') | chrome/browser/ui/views/cookie_info_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698