Chromium Code Reviews| 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 int row = 0; |
| 227 new views::Label(bubble_content.plugin_names); | 227 for (const auto& list_item : bubble_content.list_items) { |
| 228 plugin_names_label->SetMultiLine(true); | |
| 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) | 228 if (!bubble_content_empty) |
| 251 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | 229 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
| 252 layout->StartRow(0, kPopupColumnSetId); | 230 layout->StartRow(0, kItemListColumnSetId); |
| 253 | 231 if (list_item.has_link) { |
| 254 views::Link* link = new views::Link(base::UTF8ToUTF16(i->title)); | 232 views::Link* link = new views::Link(base::UTF8ToUTF16(list_item.title)); |
| 255 link->set_listener(this); | 233 link->set_listener(this); |
| 256 link->SetElideBehavior(gfx::ELIDE_MIDDLE); | 234 link->SetElideBehavior(gfx::ELIDE_MIDDLE); |
| 257 popup_links_[link] = i - bubble_content.popup_items.begin(); | 235 list_item_links_[link] = row++; |
|
msw
2015/03/23 23:54:13
Should |row| be incremented in the label case to m
meacer
2015/03/24 00:14:39
Good catch! It doesn't make a difference for this
| |
| 258 layout->AddView(new Favicon(i->image, this, link)); | 236 layout->AddView(new Favicon(list_item.image, this, link)); |
| 259 layout->AddView(link); | 237 layout->AddView(link); |
| 238 } else { | |
| 239 views::Label* label = | |
| 240 new views::Label(base::UTF8ToUTF16(list_item.title)); | |
| 241 layout->AddView(new Favicon(list_item.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 18 matching lines...) Expand all Loading... | |
| 288 } | 272 } |
| 289 DCHECK(!radio_group_.empty()); | 273 DCHECK(!radio_group_.empty()); |
| 290 // Now that the buttons have been added to the view hierarchy, it's safe | 274 // Now that the buttons have been added to the view hierarchy, it's safe |
| 291 // to call SetChecked() on them. | 275 // to call SetChecked() on them. |
| 292 radio_group_[radio_group.default_item]->SetChecked(true); | 276 radio_group_[radio_group.default_item]->SetChecked(true); |
| 293 } | 277 } |
| 294 | 278 |
| 295 // Layout code for the media device menus. | 279 // Layout code for the media device menus. |
| 296 if (content_setting_bubble_model_->content_type() == | 280 if (content_setting_bubble_model_->content_type() == |
| 297 CONTENT_SETTINGS_TYPE_MEDIASTREAM) { | 281 CONTENT_SETTINGS_TYPE_MEDIASTREAM) { |
| 298 const int kMediaMenuColumnSetId = 2; | 282 const int kMediaMenuColumnSetId = 4; |
| 299 views::ColumnSet* menu_column_set = | 283 views::ColumnSet* menu_column_set = |
| 300 layout->AddColumnSet(kMediaMenuColumnSetId); | 284 layout->AddColumnSet(kMediaMenuColumnSetId); |
| 301 menu_column_set->AddPaddingColumn(0, views::kCheckboxIndent); | 285 menu_column_set->AddPaddingColumn(0, views::kCheckboxIndent); |
| 302 menu_column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 0, | 286 menu_column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 0, |
| 303 GridLayout::USE_PREF, 0, 0); | 287 GridLayout::USE_PREF, 0, 0); |
| 304 menu_column_set->AddPaddingColumn( | 288 menu_column_set->AddPaddingColumn( |
| 305 0, views::kRelatedControlHorizontalSpacing); | 289 0, views::kRelatedControlHorizontalSpacing); |
| 306 menu_column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 1, | 290 menu_column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 1, |
| 307 GridLayout::USE_PREF, 0, 0); | 291 GridLayout::USE_PREF, 0, 0); |
| 308 | 292 |
| (...skipping 147 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 |