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/layout_delegate.h" | |
21 #include "chrome/grit/generated_resources.h" | 22 #include "chrome/grit/generated_resources.h" |
22 #include "components/content_settings/core/browser/host_content_settings_map.h" | 23 #include "components/content_settings/core/browser/host_content_settings_map.h" |
23 #include "components/strings/grit/components_strings.h" | 24 #include "components/strings/grit/components_strings.h" |
24 #include "content/public/browser/plugin_service.h" | 25 #include "content/public/browser/plugin_service.h" |
25 #include "content/public/browser/web_contents.h" | 26 #include "content/public/browser/web_contents.h" |
26 #include "ui/base/cursor/cursor.h" | 27 #include "ui/base/cursor/cursor.h" |
27 #include "ui/base/l10n/l10n_util.h" | 28 #include "ui/base/l10n/l10n_util.h" |
28 #include "ui/base/models/simple_menu_model.h" | 29 #include "ui/base/models/simple_menu_model.h" |
29 #include "ui/base/resource/resource_bundle.h" | 30 #include "ui/base/resource/resource_bundle.h" |
30 #include "ui/gfx/font_list.h" | 31 #include "ui/gfx/font_list.h" |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
193 preferred_size.set_width(std::min(preferred_width, kMaxContentsWidth)); | 194 preferred_size.set_width(std::min(preferred_width, kMaxContentsWidth)); |
194 } | 195 } |
195 return preferred_size; | 196 return preferred_size; |
196 } | 197 } |
197 | 198 |
198 void ContentSettingBubbleContents::Init() { | 199 void ContentSettingBubbleContents::Init() { |
199 using views::GridLayout; | 200 using views::GridLayout; |
200 | 201 |
201 GridLayout* layout = new views::GridLayout(this); | 202 GridLayout* layout = new views::GridLayout(this); |
202 SetLayoutManager(layout); | 203 SetLayoutManager(layout); |
204 const LayoutDelegate* layout_delegate = LayoutDelegate::Get(); | |
203 | 205 |
204 const int kSingleColumnSetId = 0; | 206 const int kSingleColumnSetId = 0; |
205 views::ColumnSet* column_set = layout->AddColumnSet(kSingleColumnSetId); | 207 views::ColumnSet* column_set = layout->AddColumnSet(kSingleColumnSetId); |
206 column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 1, | 208 column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 1, |
207 GridLayout::USE_PREF, 0, 0); | 209 GridLayout::USE_PREF, 0, 0); |
208 column_set->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing); | 210 column_set->AddPaddingColumn(0, layout_delegate->GetLayoutDistance( |
211 LayoutDelegate::LayoutDistanceType:: | |
212 RELATED_CONTROL_HORIZONTAL_SPACING)); | |
Peter Kasting
2016/12/12 22:24:16
Seems unfortunate that we have to write something
kylix_rd
2016/12/13 14:21:23
Good point. I was slavishly following the examples
| |
209 column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 1, | 213 column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 1, |
210 GridLayout::USE_PREF, 0, 0); | 214 GridLayout::USE_PREF, 0, 0); |
211 | 215 |
212 const ContentSettingBubbleModel::BubbleContent& bubble_content = | 216 const ContentSettingBubbleModel::BubbleContent& bubble_content = |
213 content_setting_bubble_model_->bubble_content(); | 217 content_setting_bubble_model_->bubble_content(); |
214 bool bubble_content_empty = true; | 218 bool bubble_content_empty = true; |
215 | 219 |
216 if (!bubble_content.title.empty()) { | 220 if (!bubble_content.title.empty()) { |
217 views::Label* title_label = new views::Label(bubble_content.title); | 221 views::Label* title_label = new views::Label(bubble_content.title); |
218 title_label->SetMultiLine(true); | 222 title_label->SetMultiLine(true); |
219 title_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 223 title_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
220 layout->StartRow(0, kSingleColumnSetId); | 224 layout->StartRow(0, kSingleColumnSetId); |
221 layout->AddView(title_label); | 225 layout->AddView(title_label); |
222 bubble_content_empty = false; | 226 bubble_content_empty = false; |
223 } | 227 } |
224 | 228 |
225 if (!bubble_content.message.empty()) { | 229 if (!bubble_content.message.empty()) { |
226 views::Label* message_label = new views::Label(bubble_content.message); | 230 views::Label* message_label = new views::Label(bubble_content.message); |
227 layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing); | 231 layout->AddPaddingRow(0, layout_delegate->GetLayoutDistance( |
232 LayoutDelegate::LayoutDistanceType:: | |
233 UNRELATED_CONTROL_VERTICAL_SPACING)); | |
228 message_label->SetMultiLine(true); | 234 message_label->SetMultiLine(true); |
229 message_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 235 message_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
230 layout->StartRow(0, kSingleColumnSetId); | 236 layout->StartRow(0, kSingleColumnSetId); |
231 layout->AddView(message_label); | 237 layout->AddView(message_label); |
232 bubble_content_empty = false; | 238 bubble_content_empty = false; |
233 } | 239 } |
234 | 240 |
235 if (!bubble_content.learn_more_link.empty()) { | 241 if (!bubble_content.learn_more_link.empty()) { |
236 learn_more_link_ = | 242 learn_more_link_ = |
237 new views::Link(base::UTF8ToUTF16(bubble_content.learn_more_link)); | 243 new views::Link(base::UTF8ToUTF16(bubble_content.learn_more_link)); |
238 learn_more_link_->set_listener(this); | 244 learn_more_link_->set_listener(this); |
239 learn_more_link_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 245 learn_more_link_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
240 layout->AddView(learn_more_link_); | 246 layout->AddView(learn_more_link_); |
241 bubble_content_empty = false; | 247 bubble_content_empty = false; |
242 } | 248 } |
243 | 249 |
244 // Layout for the item list (blocked plugins and popups). | 250 // Layout for the item list (blocked plugins and popups). |
245 if (!bubble_content.list_items.empty()) { | 251 if (!bubble_content.list_items.empty()) { |
246 const int kItemListColumnSetId = 2; | 252 const int kItemListColumnSetId = 2; |
247 views::ColumnSet* item_list_column_set = | 253 views::ColumnSet* item_list_column_set = |
248 layout->AddColumnSet(kItemListColumnSetId); | 254 layout->AddColumnSet(kItemListColumnSetId); |
249 item_list_column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 0, | 255 item_list_column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 0, |
250 GridLayout::USE_PREF, 0, 0); | 256 GridLayout::USE_PREF, 0, 0); |
251 item_list_column_set->AddPaddingColumn( | 257 item_list_column_set->AddPaddingColumn( |
252 0, views::kRelatedControlHorizontalSpacing); | 258 0, layout_delegate->GetLayoutDistance( |
259 LayoutDelegate::LayoutDistanceType:: | |
260 RELATED_CONTROL_HORIZONTAL_SPACING)); | |
253 item_list_column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 1, | 261 item_list_column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 1, |
254 GridLayout::USE_PREF, 0, 0); | 262 GridLayout::USE_PREF, 0, 0); |
255 | 263 |
256 int row = 0; | 264 int row = 0; |
257 for (const ContentSettingBubbleModel::ListItem& list_item : | 265 for (const ContentSettingBubbleModel::ListItem& list_item : |
258 bubble_content.list_items) { | 266 bubble_content.list_items) { |
259 if (!bubble_content_empty) | 267 if (!bubble_content_empty) |
260 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | 268 layout->AddPaddingRow(0, layout_delegate->GetLayoutDistance( |
269 LayoutDelegate::LayoutDistanceType:: | |
270 RELATED_CONTROL_VERTICAL_SPACING)); | |
261 layout->StartRow(0, kItemListColumnSetId); | 271 layout->StartRow(0, kItemListColumnSetId); |
262 if (list_item.has_link) { | 272 if (list_item.has_link) { |
263 views::Link* link = new views::Link(base::UTF8ToUTF16(list_item.title)); | 273 views::Link* link = new views::Link(base::UTF8ToUTF16(list_item.title)); |
264 link->set_listener(this); | 274 link->set_listener(this); |
265 link->SetElideBehavior(gfx::ELIDE_MIDDLE); | 275 link->SetElideBehavior(gfx::ELIDE_MIDDLE); |
266 list_item_links_[link] = row; | 276 list_item_links_[link] = row; |
267 layout->AddView(new Favicon(list_item.image, this, link)); | 277 layout->AddView(new Favicon(list_item.image, this, link)); |
268 layout->AddView(link); | 278 layout->AddView(link); |
269 } else { | 279 } else { |
270 views::ImageView* icon = new views::ImageView(); | 280 views::ImageView* icon = new views::ImageView(); |
(...skipping 11 matching lines...) Expand all Loading... | |
282 views::ColumnSet* indented_single_column_set = | 292 views::ColumnSet* indented_single_column_set = |
283 layout->AddColumnSet(indented_kSingleColumnSetId); | 293 layout->AddColumnSet(indented_kSingleColumnSetId); |
284 indented_single_column_set->AddPaddingColumn(0, views::kCheckboxIndent); | 294 indented_single_column_set->AddPaddingColumn(0, views::kCheckboxIndent); |
285 indented_single_column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, | 295 indented_single_column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, |
286 1, GridLayout::USE_PREF, 0, 0); | 296 1, GridLayout::USE_PREF, 0, 0); |
287 | 297 |
288 const ContentSettingBubbleModel::RadioGroup& radio_group = | 298 const ContentSettingBubbleModel::RadioGroup& radio_group = |
289 bubble_content.radio_group; | 299 bubble_content.radio_group; |
290 if (!radio_group.radio_items.empty()) { | 300 if (!radio_group.radio_items.empty()) { |
291 if (!bubble_content_empty) | 301 if (!bubble_content_empty) |
292 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | 302 layout->AddPaddingRow(0, layout_delegate->GetLayoutDistance( |
303 LayoutDelegate::LayoutDistanceType:: | |
304 RELATED_CONTROL_VERTICAL_SPACING)); | |
293 for (ContentSettingBubbleModel::RadioItems::const_iterator i( | 305 for (ContentSettingBubbleModel::RadioItems::const_iterator i( |
294 radio_group.radio_items.begin()); | 306 radio_group.radio_items.begin()); |
295 i != radio_group.radio_items.end(); ++i) { | 307 i != radio_group.radio_items.end(); ++i) { |
296 views::RadioButton* radio = | 308 views::RadioButton* radio = |
297 new views::RadioButton(base::UTF8ToUTF16(*i), 0); | 309 new views::RadioButton(base::UTF8ToUTF16(*i), 0); |
298 radio->SetEnabled(bubble_content.radio_group_enabled); | 310 radio->SetEnabled(bubble_content.radio_group_enabled); |
299 radio->set_listener(this); | 311 radio->set_listener(this); |
300 radio_group_.push_back(radio); | 312 radio_group_.push_back(radio); |
301 layout->StartRow(0, indented_kSingleColumnSetId); | 313 layout->StartRow(0, indented_kSingleColumnSetId); |
302 layout->AddView(radio); | 314 layout->AddView(radio); |
303 bubble_content_empty = false; | 315 bubble_content_empty = false; |
304 } | 316 } |
305 DCHECK(!radio_group_.empty()); | 317 DCHECK(!radio_group_.empty()); |
306 // Now that the buttons have been added to the view hierarchy, it's safe | 318 // Now that the buttons have been added to the view hierarchy, it's safe |
307 // to call SetChecked() on them. | 319 // to call SetChecked() on them. |
308 radio_group_[radio_group.default_item]->SetChecked(true); | 320 radio_group_[radio_group.default_item]->SetChecked(true); |
309 } | 321 } |
310 | 322 |
311 // Layout code for the media device menus. | 323 // Layout code for the media device menus. |
312 if (content_setting_bubble_model_->AsMediaStreamBubbleModel()) { | 324 if (content_setting_bubble_model_->AsMediaStreamBubbleModel()) { |
313 const int kMediaMenuColumnSetId = 4; | 325 const int kMediaMenuColumnSetId = 4; |
314 views::ColumnSet* menu_column_set = | 326 views::ColumnSet* menu_column_set = |
315 layout->AddColumnSet(kMediaMenuColumnSetId); | 327 layout->AddColumnSet(kMediaMenuColumnSetId); |
316 menu_column_set->AddPaddingColumn(0, views::kCheckboxIndent); | 328 menu_column_set->AddPaddingColumn(0, views::kCheckboxIndent); |
317 menu_column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 0, | 329 menu_column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 0, |
318 GridLayout::USE_PREF, 0, 0); | 330 GridLayout::USE_PREF, 0, 0); |
319 menu_column_set->AddPaddingColumn( | 331 menu_column_set->AddPaddingColumn( |
320 0, views::kRelatedControlHorizontalSpacing); | 332 0, views::kRelatedControlHorizontalSpacing); |
Peter Kasting
2016/12/12 22:24:16
Do you need to fix this one?
kylix_rd
2016/12/13 14:21:23
Doh! And that's why we have code reviews...
| |
321 menu_column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 1, | 333 menu_column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 1, |
322 GridLayout::USE_PREF, 0, 0); | 334 GridLayout::USE_PREF, 0, 0); |
323 | 335 |
324 for (ContentSettingBubbleModel::MediaMenuMap::const_iterator i( | 336 for (ContentSettingBubbleModel::MediaMenuMap::const_iterator i( |
325 bubble_content.media_menus.begin()); | 337 bubble_content.media_menus.begin()); |
326 i != bubble_content.media_menus.end(); ++i) { | 338 i != bubble_content.media_menus.end(); ++i) { |
327 if (!bubble_content_empty) | 339 if (!bubble_content_empty) |
328 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | 340 layout->AddPaddingRow(0, layout_delegate->GetLayoutDistance( |
341 LayoutDelegate::LayoutDistanceType:: | |
342 RELATED_CONTROL_VERTICAL_SPACING)); | |
329 layout->StartRow(0, kMediaMenuColumnSetId); | 343 layout->StartRow(0, kMediaMenuColumnSetId); |
330 | 344 |
331 views::Label* label = | 345 views::Label* label = |
332 new views::Label(base::UTF8ToUTF16(i->second.label)); | 346 new views::Label(base::UTF8ToUTF16(i->second.label)); |
333 label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 347 label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
334 layout->AddView(label); | 348 layout->AddView(label); |
335 | 349 |
336 combobox_models_.emplace_back(i->first); | 350 combobox_models_.emplace_back(i->first); |
337 MediaComboboxModel* model = &combobox_models_.back(); | 351 MediaComboboxModel* model = &combobox_models_.back(); |
338 views::Combobox* combobox = new views::Combobox(model); | 352 views::Combobox* combobox = new views::Combobox(model); |
(...skipping 30 matching lines...) Expand all Loading... | |
369 } | 383 } |
370 bubble_content_empty = false; | 384 bubble_content_empty = false; |
371 } | 385 } |
372 | 386 |
373 if (!bubble_content.custom_link.empty()) { | 387 if (!bubble_content.custom_link.empty()) { |
374 custom_link_ = | 388 custom_link_ = |
375 new views::Link(base::UTF8ToUTF16(bubble_content.custom_link)); | 389 new views::Link(base::UTF8ToUTF16(bubble_content.custom_link)); |
376 custom_link_->SetEnabled(bubble_content.custom_link_enabled); | 390 custom_link_->SetEnabled(bubble_content.custom_link_enabled); |
377 custom_link_->set_listener(this); | 391 custom_link_->set_listener(this); |
378 if (!bubble_content_empty) | 392 if (!bubble_content_empty) |
379 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | 393 layout->AddPaddingRow(0, layout_delegate->GetLayoutDistance( |
394 LayoutDelegate::LayoutDistanceType:: | |
395 RELATED_CONTROL_VERTICAL_SPACING)); | |
380 layout->StartRow(0, kSingleColumnSetId); | 396 layout->StartRow(0, kSingleColumnSetId); |
381 layout->AddView(custom_link_); | 397 layout->AddView(custom_link_); |
382 bubble_content_empty = false; | 398 bubble_content_empty = false; |
383 } | 399 } |
384 | 400 |
385 if (!bubble_content_empty) { | 401 if (!bubble_content_empty) { |
386 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | 402 layout->AddPaddingRow(0, layout_delegate->GetLayoutDistance( |
403 LayoutDelegate::LayoutDistanceType:: | |
404 RELATED_CONTROL_VERTICAL_SPACING)); | |
387 layout->StartRow(0, kSingleColumnSetId); | 405 layout->StartRow(0, kSingleColumnSetId); |
388 layout->AddView(new views::Separator(views::Separator::HORIZONTAL), 1, 1, | 406 layout->AddView(new views::Separator(views::Separator::HORIZONTAL), 1, 1, |
389 GridLayout::FILL, GridLayout::FILL); | 407 GridLayout::FILL, GridLayout::FILL); |
390 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | 408 layout->AddPaddingRow(0, layout_delegate->GetLayoutDistance( |
409 LayoutDelegate::LayoutDistanceType:: | |
410 RELATED_CONTROL_VERTICAL_SPACING)); | |
391 } | 411 } |
392 } | 412 } |
393 | 413 |
394 views::View* ContentSettingBubbleContents::CreateExtraView() { | 414 views::View* ContentSettingBubbleContents::CreateExtraView() { |
395 if (content_setting_bubble_model_->bubble_content() | 415 if (content_setting_bubble_model_->bubble_content() |
396 .show_manage_text_as_button) { | 416 .show_manage_text_as_button) { |
397 manage_button_ = views::MdTextButton::CreateSecondaryUiButton( | 417 manage_button_ = views::MdTextButton::CreateSecondaryUiButton( |
398 this, base::UTF8ToUTF16( | 418 this, base::UTF8ToUTF16( |
399 content_setting_bubble_model_->bubble_content().manage_text)); | 419 content_setting_bubble_model_->bubble_content().manage_text)); |
400 return manage_button_; | 420 return manage_button_; |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
469 DCHECK(i != list_item_links_.end()); | 489 DCHECK(i != list_item_links_.end()); |
470 content_setting_bubble_model_->OnListItemClicked(i->second); | 490 content_setting_bubble_model_->OnListItemClicked(i->second); |
471 } | 491 } |
472 | 492 |
473 void ContentSettingBubbleContents::OnPerformAction(views::Combobox* combobox) { | 493 void ContentSettingBubbleContents::OnPerformAction(views::Combobox* combobox) { |
474 MediaComboboxModel* model = | 494 MediaComboboxModel* model = |
475 static_cast<MediaComboboxModel*>(combobox->model()); | 495 static_cast<MediaComboboxModel*>(combobox->model()); |
476 content_setting_bubble_model_->OnMediaMenuClicked( | 496 content_setting_bubble_model_->OnMediaMenuClicked( |
477 model->type(), model->GetDevices()[combobox->selected_index()].id); | 497 model->type(), model->GetDevices()[combobox->selected_index()].id); |
478 } | 498 } |
OLD | NEW |