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 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
204 | 204 |
205 if (!bubble_content.learn_more_link.empty()) { | 205 if (!bubble_content.learn_more_link.empty()) { |
206 learn_more_link_ = | 206 learn_more_link_ = |
207 new views::Link(base::UTF8ToUTF16(bubble_content.learn_more_link)); | 207 new views::Link(base::UTF8ToUTF16(bubble_content.learn_more_link)); |
208 learn_more_link_->set_listener(this); | 208 learn_more_link_->set_listener(this); |
209 learn_more_link_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 209 learn_more_link_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
210 layout->AddView(learn_more_link_); | 210 layout->AddView(learn_more_link_); |
211 bubble_content_empty = false; | 211 bubble_content_empty = false; |
212 } | 212 } |
213 | 213 |
214 if (!bubble_content.plugin_names.empty()) { | 214 // Layout for the item list (blocked plugins and popups). |
215 const int kPluginsColumnSetId = 4; | 215 if (!bubble_content.list_items.empty()) { |
216 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | 216 const int kItemListColumnSetId = 2; |
217 views::ColumnSet* plugins_column_set = | 217 views::ColumnSet* item_list_column_set = |
218 layout->AddColumnSet(kPluginsColumnSetId); | 218 layout->AddColumnSet(kItemListColumnSetId); |
219 plugins_column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 1, | 219 item_list_column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 0, |
220 GridLayout::USE_PREF, 0, 0); | 220 GridLayout::USE_PREF, 0, 0); |
221 plugins_column_set->AddPaddingColumn( | 221 item_list_column_set->AddPaddingColumn( |
222 0, views::kRelatedControlHorizontalSpacing); | 222 0, views::kRelatedControlHorizontalSpacing); |
223 plugins_column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 1, | 223 item_list_column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 1, |
224 GridLayout::USE_PREF, 0, 0); | 224 GridLayout::USE_PREF, 0, 0); |
225 | 225 |
226 views::Label* plugin_names_label = | 226 for (std::vector<ContentSettingBubbleModel::ListItem>::const_iterator i( |
msw
2015/03/20 22:06:34
ditto nit: range or auto
meacer
2015/03/20 23:39:42
Done.
| |
227 new views::Label(bubble_content.plugin_names); | 227 bubble_content.list_items.begin()); |
228 plugin_names_label->SetMultiLine(true); | 228 i != bubble_content.list_items.end(); ++i) { |
229 plugin_names_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
230 layout->StartRow(0, kPluginsColumnSetId); | |
231 layout->AddView(plugin_names_label); | |
232 bubble_content_empty = false; | |
233 } | |
234 | |
235 if (content_setting_bubble_model_->content_type() == | |
236 CONTENT_SETTINGS_TYPE_POPUPS) { | |
237 const int kPopupColumnSetId = 2; | |
238 views::ColumnSet* popup_column_set = | |
239 layout->AddColumnSet(kPopupColumnSetId); | |
240 popup_column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 0, | |
241 GridLayout::USE_PREF, 0, 0); | |
242 popup_column_set->AddPaddingColumn( | |
243 0, views::kRelatedControlHorizontalSpacing); | |
244 popup_column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 1, | |
245 GridLayout::USE_PREF, 0, 0); | |
246 | |
247 for (std::vector<ContentSettingBubbleModel::PopupItem>::const_iterator | |
248 i(bubble_content.popup_items.begin()); | |
249 i != bubble_content.popup_items.end(); ++i) { | |
250 if (!bubble_content_empty) | 229 if (!bubble_content_empty) |
251 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | 230 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
252 layout->StartRow(0, kPopupColumnSetId); | 231 layout->StartRow(0, kItemListColumnSetId); |
253 | 232 if (i->has_link) { |
254 views::Link* link = new views::Link(base::UTF8ToUTF16(i->title)); | 233 views::Link* link = new views::Link(base::UTF8ToUTF16(i->title)); |
255 link->set_listener(this); | 234 link->set_listener(this); |
256 link->SetElideBehavior(gfx::ELIDE_MIDDLE); | 235 link->SetElideBehavior(gfx::ELIDE_MIDDLE); |
257 popup_links_[link] = i - bubble_content.popup_items.begin(); | 236 list_item_links_[link] = i - bubble_content.list_items.begin(); |
258 layout->AddView(new Favicon(i->image, this, link)); | 237 layout->AddView(new Favicon(i->image, this, link)); |
259 layout->AddView(link); | 238 layout->AddView(link); |
239 } else { | |
240 views::Label* label = new views::Label(base::UTF8ToUTF16(i->title)); | |
241 layout->AddView(new Favicon(i->image, this, NULL)); | |
242 layout->AddView(label); | |
243 } | |
260 bubble_content_empty = false; | 244 bubble_content_empty = false; |
261 } | 245 } |
262 } | 246 } |
263 | 247 |
264 const int indented_kSingleColumnSetId = 3; | 248 const int indented_kSingleColumnSetId = 3; |
265 // Insert a column set with greater indent. | 249 // Insert a column set with greater indent. |
266 views::ColumnSet* indented_single_column_set = | 250 views::ColumnSet* indented_single_column_set = |
267 layout->AddColumnSet(indented_kSingleColumnSetId); | 251 layout->AddColumnSet(indented_kSingleColumnSetId); |
268 indented_single_column_set->AddPaddingColumn(0, views::kCheckboxIndent); | 252 indented_single_column_set->AddPaddingColumn(0, views::kCheckboxIndent); |
269 indented_single_column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, | 253 indented_single_column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
456 return; | 440 return; |
457 } | 441 } |
458 if (source == manage_link_) { | 442 if (source == manage_link_) { |
459 GetWidget()->Close(); | 443 GetWidget()->Close(); |
460 content_setting_bubble_model_->OnManageLinkClicked(); | 444 content_setting_bubble_model_->OnManageLinkClicked(); |
461 // CAREFUL: Showing the settings window activates it, which deactivates the | 445 // CAREFUL: Showing the settings window activates it, which deactivates the |
462 // info bubble, which causes it to close, which deletes us. | 446 // info bubble, which causes it to close, which deletes us. |
463 return; | 447 return; |
464 } | 448 } |
465 | 449 |
466 PopupLinks::const_iterator i(popup_links_.find(source)); | 450 ListItemLinks::const_iterator i(list_item_links_.find(source)); |
467 DCHECK(i != popup_links_.end()); | 451 DCHECK(i != list_item_links_.end()); |
468 content_setting_bubble_model_->OnPopupClicked(i->second); | 452 content_setting_bubble_model_->OnListItemClicked(i->second); |
469 } | 453 } |
470 | 454 |
471 void ContentSettingBubbleContents::OnMenuButtonClicked( | 455 void ContentSettingBubbleContents::OnMenuButtonClicked( |
472 views::View* source, | 456 views::View* source, |
473 const gfx::Point& point) { | 457 const gfx::Point& point) { |
474 MediaMenuPartsMap::iterator j(media_menus_.find( | 458 MediaMenuPartsMap::iterator j(media_menus_.find( |
475 static_cast<views::MenuButton*>(source))); | 459 static_cast<views::MenuButton*>(source))); |
476 DCHECK(j != media_menus_.end()); | 460 DCHECK(j != media_menus_.end()); |
477 menu_runner_.reset(new views::MenuRunner(j->second->menu_model.get(), | 461 menu_runner_.reset(new views::MenuRunner(j->second->menu_model.get(), |
478 views::MenuRunner::HAS_MNEMONICS)); | 462 views::MenuRunner::HAS_MNEMONICS)); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
513 // Make sure the width is at least kMinMediaMenuButtonWidth. The | 497 // Make sure the width is at least kMinMediaMenuButtonWidth. The |
514 // maximum width will be clamped by kMaxContentsWidth of the view. | 498 // maximum width will be clamped by kMaxContentsWidth of the view. |
515 menu_width = std::max(kMinMediaMenuButtonWidth, menu_width + margins); | 499 menu_width = std::max(kMinMediaMenuButtonWidth, menu_width + margins); |
516 | 500 |
517 for (MediaMenuPartsMap::const_iterator i = media_menus_.begin(); | 501 for (MediaMenuPartsMap::const_iterator i = media_menus_.begin(); |
518 i != media_menus_.end(); ++i) { | 502 i != media_menus_.end(); ++i) { |
519 i->first->SetMinSize(gfx::Size(menu_width, 0)); | 503 i->first->SetMinSize(gfx::Size(menu_width, 0)); |
520 i->first->SetMaxSize(gfx::Size(menu_width, 0)); | 504 i->first->SetMaxSize(gfx::Size(menu_width, 0)); |
521 } | 505 } |
522 } | 506 } |
OLD | NEW |