| 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/permission_menu_model.h" | 10 #include "chrome/browser/ui/page_info/permission_menu_model.h" |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 // PermissionMenuButton called that from its override, the NativeTheme would | 80 // PermissionMenuButton called that from its override, the NativeTheme would |
| 81 // be available, and the button would get native GTK styling on Linux. | 81 // be available, and the button would get native GTK styling on Linux. |
| 82 UpdateThemedBorder(); | 82 UpdateThemedBorder(); |
| 83 | 83 |
| 84 SetFocusForPlatform(); | 84 SetFocusForPlatform(); |
| 85 set_request_focus_on_press(true); | 85 set_request_focus_on_press(true); |
| 86 is_rtl_display_ = | 86 is_rtl_display_ = |
| 87 base::i18n::RIGHT_TO_LEFT == base::i18n::GetStringDirection(text); | 87 base::i18n::RIGHT_TO_LEFT == base::i18n::GetStringDirection(text); |
| 88 } | 88 } |
| 89 | 89 |
| 90 PermissionMenuButton::~PermissionMenuButton() { | 90 PermissionMenuButton::~PermissionMenuButton() {} |
| 91 } | |
| 92 | 91 |
| 93 void PermissionMenuButton::GetAccessibleNodeData(ui::AXNodeData* node_data) { | 92 void PermissionMenuButton::GetAccessibleNodeData(ui::AXNodeData* node_data) { |
| 94 MenuButton::GetAccessibleNodeData(node_data); | 93 MenuButton::GetAccessibleNodeData(node_data); |
| 95 node_data->SetValue(GetText()); | 94 node_data->SetValue(GetText()); |
| 96 } | 95 } |
| 97 | 96 |
| 98 void PermissionMenuButton::OnNativeThemeChanged(const ui::NativeTheme* theme) { | 97 void PermissionMenuButton::OnNativeThemeChanged(const ui::NativeTheme* theme) { |
| 99 SetTextColor(views::Button::STATE_NORMAL, theme->GetSystemColor( | 98 SetTextColor( |
| 100 ui::NativeTheme::kColorId_LabelEnabledColor)); | 99 views::Button::STATE_NORMAL, |
| 101 SetTextColor(views::Button::STATE_HOVERED, theme->GetSystemColor( | 100 theme->GetSystemColor(ui::NativeTheme::kColorId_LabelEnabledColor)); |
| 102 ui::NativeTheme::kColorId_LabelEnabledColor)); | 101 SetTextColor( |
| 103 SetTextColor(views::Button::STATE_DISABLED, theme->GetSystemColor( | 102 views::Button::STATE_HOVERED, |
| 104 ui::NativeTheme::kColorId_LabelDisabledColor)); | 103 theme->GetSystemColor(ui::NativeTheme::kColorId_LabelEnabledColor)); |
| 104 SetTextColor( |
| 105 views::Button::STATE_DISABLED, |
| 106 theme->GetSystemColor(ui::NativeTheme::kColorId_LabelDisabledColor)); |
| 105 } | 107 } |
| 106 | 108 |
| 107 void PermissionMenuButton::OnMenuButtonClicked(views::MenuButton* source, | 109 void PermissionMenuButton::OnMenuButtonClicked(views::MenuButton* source, |
| 108 const gfx::Point& point, | 110 const gfx::Point& point, |
| 109 const ui::Event* event) { | 111 const ui::Event* event) { |
| 110 menu_runner_.reset(new views::MenuRunner( | 112 menu_runner_.reset(new views::MenuRunner( |
| 111 menu_model_, | 113 menu_model_, |
| 112 views::MenuRunner::HAS_MNEMONICS | views::MenuRunner::ASYNC)); | 114 views::MenuRunner::HAS_MNEMONICS | views::MenuRunner::ASYNC)); |
| 113 | 115 |
| 114 gfx::Point p(point); | 116 gfx::Point p(point); |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 label_ = new views::Label( | 248 label_ = new views::Label( |
| 247 WebsiteSettingsUI::PermissionTypeToUIString(permission.type)); | 249 WebsiteSettingsUI::PermissionTypeToUIString(permission.type)); |
| 248 layout->AddView(label_, 1, 1, views::GridLayout::LEADING, | 250 layout->AddView(label_, 1, 1, views::GridLayout::LEADING, |
| 249 views::GridLayout::CENTER); | 251 views::GridLayout::CENTER); |
| 250 // Create the menu model. | 252 // Create the menu model. |
| 251 menu_model_.reset(new PermissionMenuModel( | 253 menu_model_.reset(new PermissionMenuModel( |
| 252 profile, url, permission, | 254 profile, url, permission, |
| 253 base::Bind(&PermissionSelectorRow::PermissionChanged, | 255 base::Bind(&PermissionSelectorRow::PermissionChanged, |
| 254 base::Unretained(this)))); | 256 base::Unretained(this)))); |
| 255 | 257 |
| 256 // Create the permission menu button. | 258 // Create the permission menu button. |
| 257 #if defined(OS_MACOSX) | 259 #if defined(OS_MACOSX) |
| 258 bool use_real_combobox = true; | 260 bool use_real_combobox = true; |
| 259 #else | 261 #else |
| 260 bool use_real_combobox = | 262 bool use_real_combobox = |
| 261 ui::MaterialDesignController::IsSecondaryUiMaterial(); | 263 ui::MaterialDesignController::IsSecondaryUiMaterial(); |
| 262 #endif | 264 #endif |
| 263 if (use_real_combobox) | 265 if (use_real_combobox) |
| 264 InitializeComboboxView(layout, permission); | 266 InitializeComboboxView(layout, permission); |
| 265 else | 267 else |
| 266 InitializeMenuButtonView(layout, permission); | 268 InitializeMenuButtonView(layout, permission); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 layout->AddView(menu_button_); | 304 layout->AddView(menu_button_); |
| 303 } | 305 } |
| 304 | 306 |
| 305 void PermissionSelectorRow::InitializeComboboxView( | 307 void PermissionSelectorRow::InitializeComboboxView( |
| 306 views::GridLayout* layout, | 308 views::GridLayout* layout, |
| 307 const WebsiteSettingsUI::PermissionInfo& permission) { | 309 const WebsiteSettingsUI::PermissionInfo& permission) { |
| 308 bool button_enabled = | 310 bool button_enabled = |
| 309 permission.source == content_settings::SETTING_SOURCE_USER; | 311 permission.source == content_settings::SETTING_SOURCE_USER; |
| 310 combobox_model_adapter_.reset( | 312 combobox_model_adapter_.reset( |
| 311 new internal::ComboboxModelAdapter(menu_model_.get())); | 313 new internal::ComboboxModelAdapter(menu_model_.get())); |
| 312 combobox_ = new internal::PermissionCombobox( | 314 combobox_ = new internal::PermissionCombobox(combobox_model_adapter_.get(), |
| 313 combobox_model_adapter_.get(), button_enabled, true); | 315 button_enabled, true); |
| 314 combobox_->SetEnabled(button_enabled); | 316 combobox_->SetEnabled(button_enabled); |
| 315 combobox_->SetAccessibleName( | 317 combobox_->SetAccessibleName( |
| 316 WebsiteSettingsUI::PermissionTypeToUIString(permission.type)); | 318 WebsiteSettingsUI::PermissionTypeToUIString(permission.type)); |
| 317 layout->AddView(combobox_); | 319 layout->AddView(combobox_); |
| 318 } | 320 } |
| 319 | 321 |
| 320 void PermissionSelectorRow::PermissionChanged( | 322 void PermissionSelectorRow::PermissionChanged( |
| 321 const WebsiteSettingsUI::PermissionInfo& permission) { | 323 const WebsiteSettingsUI::PermissionInfo& permission) { |
| 322 // Change the permission icon to reflect the selected setting. | 324 // Change the permission icon to reflect the selected setting. |
| 323 const gfx::Image& image = WebsiteSettingsUI::GetPermissionIcon(permission); | 325 const gfx::Image& image = WebsiteSettingsUI::GetPermissionIcon(permission); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 342 observer.OnPermissionChanged(permission); | 344 observer.OnPermissionChanged(permission); |
| 343 } | 345 } |
| 344 | 346 |
| 345 views::View* PermissionSelectorRow::button() { | 347 views::View* PermissionSelectorRow::button() { |
| 346 // 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 |
| 347 // 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 |
| 348 // and T1 and T2 are both subtypes of T. | 350 // and T1 and T2 are both subtypes of T. |
| 349 return menu_button_ ? static_cast<views::View*>(menu_button_) | 351 return menu_button_ ? static_cast<views::View*>(menu_button_) |
| 350 : static_cast<views::View*>(combobox_); | 352 : static_cast<views::View*>(combobox_); |
| 351 } | 353 } |
| OLD | NEW |