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/page_info/permission_selector_row.h" | 5 #include "chrome/browser/ui/views/page_info/permission_selector_row.h" |
6 | 6 |
7 #include "base/i18n/rtl.h" | 7 #include "base/i18n/rtl.h" |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "chrome/browser/ui/page_info/page_info_ui.h" |
10 #include "chrome/browser/ui/page_info/permission_menu_model.h" | 11 #include "chrome/browser/ui/page_info/permission_menu_model.h" |
11 #include "chrome/browser/ui/page_info/website_settings_ui.h" | |
12 #include "chrome/browser/ui/views/page_info/non_accessible_image_view.h" | 12 #include "chrome/browser/ui/views/page_info/non_accessible_image_view.h" |
13 #include "chrome/browser/ui/views/page_info/website_settings_popup_view.h" | 13 #include "chrome/browser/ui/views/page_info/page_info_popup_view.h" |
14 #include "chrome/grit/generated_resources.h" | 14 #include "chrome/grit/generated_resources.h" |
15 #include "ui/accessibility/ax_node_data.h" | 15 #include "ui/accessibility/ax_node_data.h" |
16 #include "ui/base/material_design/material_design_controller.h" | 16 #include "ui/base/material_design/material_design_controller.h" |
17 #include "ui/base/models/combobox_model.h" | 17 #include "ui/base/models/combobox_model.h" |
18 #include "ui/gfx/image/image.h" | 18 #include "ui/gfx/image/image.h" |
19 #include "ui/views/controls/button/menu_button.h" | 19 #include "ui/views/controls/button/menu_button.h" |
20 #include "ui/views/controls/combobox/combobox.h" | 20 #include "ui/views/controls/combobox/combobox.h" |
21 #include "ui/views/controls/combobox/combobox_listener.h" | 21 #include "ui/views/controls/combobox/combobox_listener.h" |
22 #include "ui/views/controls/image_view.h" | 22 #include "ui/views/controls/image_view.h" |
23 #include "ui/views/controls/label.h" | 23 #include "ui/views/controls/label.h" |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 | 228 |
229 } // namespace internal | 229 } // namespace internal |
230 | 230 |
231 /////////////////////////////////////////////////////////////////////////////// | 231 /////////////////////////////////////////////////////////////////////////////// |
232 // PermissionSelectorRow | 232 // PermissionSelectorRow |
233 /////////////////////////////////////////////////////////////////////////////// | 233 /////////////////////////////////////////////////////////////////////////////// |
234 | 234 |
235 PermissionSelectorRow::PermissionSelectorRow( | 235 PermissionSelectorRow::PermissionSelectorRow( |
236 Profile* profile, | 236 Profile* profile, |
237 const GURL& url, | 237 const GURL& url, |
238 const WebsiteSettingsUI::PermissionInfo& permission, | 238 const PageInfoUI::PermissionInfo& permission, |
239 views::GridLayout* layout) | 239 views::GridLayout* layout) |
240 : profile_(profile), icon_(NULL), menu_button_(NULL), combobox_(NULL) { | 240 : profile_(profile), icon_(NULL), menu_button_(NULL), combobox_(NULL) { |
241 // Create the permission icon. | 241 // Create the permission icon. |
242 icon_ = new NonAccessibleImageView(); | 242 icon_ = new NonAccessibleImageView(); |
243 const gfx::Image& image = WebsiteSettingsUI::GetPermissionIcon(permission); | 243 const gfx::Image& image = PageInfoUI::GetPermissionIcon(permission); |
244 icon_->SetImage(image.ToImageSkia()); | 244 icon_->SetImage(image.ToImageSkia()); |
245 layout->AddView(icon_, 1, 1, views::GridLayout::CENTER, | 245 layout->AddView(icon_, 1, 1, views::GridLayout::CENTER, |
246 views::GridLayout::CENTER); | 246 views::GridLayout::CENTER); |
247 // Create the label that displays the permission type. | 247 // Create the label that displays the permission type. |
248 label_ = new views::Label( | 248 label_ = |
249 WebsiteSettingsUI::PermissionTypeToUIString(permission.type)); | 249 new views::Label(PageInfoUI::PermissionTypeToUIString(permission.type)); |
250 layout->AddView(label_, 1, 1, views::GridLayout::LEADING, | 250 layout->AddView(label_, 1, 1, views::GridLayout::LEADING, |
251 views::GridLayout::CENTER); | 251 views::GridLayout::CENTER); |
252 // Create the menu model. | 252 // Create the menu model. |
253 menu_model_.reset(new PermissionMenuModel( | 253 menu_model_.reset(new PermissionMenuModel( |
254 profile, url, permission, | 254 profile, url, permission, |
255 base::Bind(&PermissionSelectorRow::PermissionChanged, | 255 base::Bind(&PermissionSelectorRow::PermissionChanged, |
256 base::Unretained(this)))); | 256 base::Unretained(this)))); |
257 | 257 |
258 // Create the permission menu button. | 258 // Create the permission menu button. |
259 #if defined(OS_MACOSX) | 259 #if defined(OS_MACOSX) |
(...skipping 23 matching lines...) Expand all Loading... |
283 // ComboboxModel. | 283 // ComboboxModel. |
284 // | 284 // |
285 // Technically, the MenuButton has the same problem, but MenuButton doesn't | 285 // Technically, the MenuButton has the same problem, but MenuButton doesn't |
286 // use its model in its destructor. | 286 // use its model in its destructor. |
287 if (combobox_) | 287 if (combobox_) |
288 combobox_->parent()->RemoveChildView(combobox_); | 288 combobox_->parent()->RemoveChildView(combobox_); |
289 } | 289 } |
290 | 290 |
291 void PermissionSelectorRow::InitializeMenuButtonView( | 291 void PermissionSelectorRow::InitializeMenuButtonView( |
292 views::GridLayout* layout, | 292 views::GridLayout* layout, |
293 const WebsiteSettingsUI::PermissionInfo& permission) { | 293 const PageInfoUI::PermissionInfo& permission) { |
294 bool button_enabled = | 294 bool button_enabled = |
295 permission.source == content_settings::SETTING_SOURCE_USER; | 295 permission.source == content_settings::SETTING_SOURCE_USER; |
296 menu_button_ = new internal::PermissionMenuButton( | 296 menu_button_ = new internal::PermissionMenuButton( |
297 WebsiteSettingsUI::PermissionActionToUIString( | 297 PageInfoUI::PermissionActionToUIString( |
298 profile_, permission.type, permission.setting, | 298 profile_, permission.type, permission.setting, |
299 permission.default_setting, permission.source), | 299 permission.default_setting, permission.source), |
300 menu_model_.get(), button_enabled); | 300 menu_model_.get(), button_enabled); |
301 menu_button_->SetEnabled(button_enabled); | 301 menu_button_->SetEnabled(button_enabled); |
302 menu_button_->SetAccessibleName( | 302 menu_button_->SetAccessibleName( |
303 WebsiteSettingsUI::PermissionTypeToUIString(permission.type)); | 303 PageInfoUI::PermissionTypeToUIString(permission.type)); |
304 layout->AddView(menu_button_); | 304 layout->AddView(menu_button_); |
305 } | 305 } |
306 | 306 |
307 void PermissionSelectorRow::InitializeComboboxView( | 307 void PermissionSelectorRow::InitializeComboboxView( |
308 views::GridLayout* layout, | 308 views::GridLayout* layout, |
309 const WebsiteSettingsUI::PermissionInfo& permission) { | 309 const PageInfoUI::PermissionInfo& permission) { |
310 bool button_enabled = | 310 bool button_enabled = |
311 permission.source == content_settings::SETTING_SOURCE_USER; | 311 permission.source == content_settings::SETTING_SOURCE_USER; |
312 combobox_model_adapter_.reset( | 312 combobox_model_adapter_.reset( |
313 new internal::ComboboxModelAdapter(menu_model_.get())); | 313 new internal::ComboboxModelAdapter(menu_model_.get())); |
314 combobox_ = new internal::PermissionCombobox(combobox_model_adapter_.get(), | 314 combobox_ = new internal::PermissionCombobox(combobox_model_adapter_.get(), |
315 button_enabled, true); | 315 button_enabled, true); |
316 combobox_->SetEnabled(button_enabled); | 316 combobox_->SetEnabled(button_enabled); |
317 combobox_->SetAccessibleName( | 317 combobox_->SetAccessibleName( |
318 WebsiteSettingsUI::PermissionTypeToUIString(permission.type)); | 318 PageInfoUI::PermissionTypeToUIString(permission.type)); |
319 layout->AddView(combobox_); | 319 layout->AddView(combobox_); |
320 } | 320 } |
321 | 321 |
322 void PermissionSelectorRow::PermissionChanged( | 322 void PermissionSelectorRow::PermissionChanged( |
323 const WebsiteSettingsUI::PermissionInfo& permission) { | 323 const PageInfoUI::PermissionInfo& permission) { |
324 // Change the permission icon to reflect the selected setting. | 324 // Change the permission icon to reflect the selected setting. |
325 const gfx::Image& image = WebsiteSettingsUI::GetPermissionIcon(permission); | 325 const gfx::Image& image = PageInfoUI::GetPermissionIcon(permission); |
326 icon_->SetImage(image.ToImageSkia()); | 326 icon_->SetImage(image.ToImageSkia()); |
327 | 327 |
328 // Update the menu button text to reflect the new setting. | 328 // Update the menu button text to reflect the new setting. |
329 if (menu_button_) { | 329 if (menu_button_) { |
330 menu_button_->SetText(WebsiteSettingsUI::PermissionActionToUIString( | 330 menu_button_->SetText(PageInfoUI::PermissionActionToUIString( |
331 profile_, permission.type, permission.setting, | 331 profile_, permission.type, permission.setting, |
332 permission.default_setting, content_settings::SETTING_SOURCE_USER)); | 332 permission.default_setting, content_settings::SETTING_SOURCE_USER)); |
333 menu_button_->SizeToPreferredSize(); | 333 menu_button_->SizeToPreferredSize(); |
334 // Re-layout will be done at the |WebsiteSettingsPopupView| level, since | 334 // Re-layout will be done at the |PageInfoPopupView| level, since |
335 // that view may need to resize itself to accomodate the new sizes of its | 335 // that view may need to resize itself to accomodate the new sizes of its |
336 // contents. | 336 // contents. |
337 menu_button_->InvalidateLayout(); | 337 menu_button_->InvalidateLayout(); |
338 } else if (combobox_) { | 338 } else if (combobox_) { |
339 bool use_default = permission.setting == CONTENT_SETTING_DEFAULT; | 339 bool use_default = permission.setting == CONTENT_SETTING_DEFAULT; |
340 combobox_->UpdateSelectedIndex(use_default); | 340 combobox_->UpdateSelectedIndex(use_default); |
341 } | 341 } |
342 | 342 |
343 for (PermissionSelectorRowObserver& observer : observer_list_) | 343 for (PermissionSelectorRowObserver& observer : observer_list_) |
344 observer.OnPermissionChanged(permission); | 344 observer.OnPermissionChanged(permission); |
345 } | 345 } |
346 | 346 |
347 views::View* PermissionSelectorRow::button() { | 347 views::View* PermissionSelectorRow::button() { |
348 // These casts are required because the two arms of a ?: cannot have different | 348 // These casts are required because the two arms of a ?: cannot have different |
349 // types T1 and T2, even if the resulting value of the ?: is about to be a T | 349 // types T1 and T2, even if the resulting value of the ?: is about to be a T |
350 // and T1 and T2 are both subtypes of T. | 350 // and T1 and T2 are both subtypes of T. |
351 return menu_button_ ? static_cast<views::View*>(menu_button_) | 351 return menu_button_ ? static_cast<views::View*>(menu_button_) |
352 : static_cast<views::View*>(combobox_); | 352 : static_cast<views::View*>(combobox_); |
353 } | 353 } |
OLD | NEW |