| 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/page_info_ui.h" |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 if (ui::MaterialDesignController::IsSecondaryUiMaterial()) { | 202 if (ui::MaterialDesignController::IsSecondaryUiMaterial()) { |
| 203 set_size_to_largest_label(false); | 203 set_size_to_largest_label(false); |
| 204 ModelChanged(); | 204 ModelChanged(); |
| 205 } | 205 } |
| 206 } | 206 } |
| 207 | 207 |
| 208 PermissionCombobox::~PermissionCombobox() {} | 208 PermissionCombobox::~PermissionCombobox() {} |
| 209 | 209 |
| 210 void PermissionCombobox::UpdateSelectedIndex(bool use_default) { | 210 void PermissionCombobox::UpdateSelectedIndex(bool use_default) { |
| 211 int index = model_->GetCheckedIndex(); | 211 int index = model_->GetCheckedIndex(); |
| 212 if (use_default && index == -1) | 212 if (use_default && index == -1) { |
| 213 index = 0; | 213 index = 0; |
| 214 } |
| 214 SetSelectedIndex(index); | 215 SetSelectedIndex(index); |
| 215 } | 216 } |
| 216 | 217 |
| 217 void PermissionCombobox::OnPaintBorder(gfx::Canvas* canvas) { | 218 void PermissionCombobox::OnPaintBorder(gfx::Canvas* canvas) { |
| 218 // No border except a focus indicator for MD mode. | 219 // No border except a focus indicator for MD mode. |
| 219 if (ui::MaterialDesignController::IsSecondaryUiMaterial() && !HasFocus()) | 220 if (ui::MaterialDesignController::IsSecondaryUiMaterial() && !HasFocus()) { |
| 220 return; | 221 return; |
| 222 } |
| 221 Combobox::OnPaintBorder(canvas); | 223 Combobox::OnPaintBorder(canvas); |
| 222 } | 224 } |
| 223 | 225 |
| 224 void PermissionCombobox::OnPerformAction(Combobox* combobox) { | 226 void PermissionCombobox::OnPerformAction(Combobox* combobox) { |
| 225 model_->OnPerformAction(combobox->selected_index()); | 227 model_->OnPerformAction(combobox->selected_index()); |
| 226 } | 228 } |
| 227 | 229 |
| 228 } // namespace internal | 230 } // namespace internal |
| 229 | 231 |
| 230 /////////////////////////////////////////////////////////////////////////////// | 232 /////////////////////////////////////////////////////////////////////////////// |
| (...skipping 24 matching lines...) Expand all Loading... |
| 255 base::Bind(&PermissionSelectorRow::PermissionChanged, | 257 base::Bind(&PermissionSelectorRow::PermissionChanged, |
| 256 base::Unretained(this)))); | 258 base::Unretained(this)))); |
| 257 | 259 |
| 258 // Create the permission menu button. | 260 // Create the permission menu button. |
| 259 #if defined(OS_MACOSX) | 261 #if defined(OS_MACOSX) |
| 260 bool use_real_combobox = true; | 262 bool use_real_combobox = true; |
| 261 #else | 263 #else |
| 262 bool use_real_combobox = | 264 bool use_real_combobox = |
| 263 ui::MaterialDesignController::IsSecondaryUiMaterial(); | 265 ui::MaterialDesignController::IsSecondaryUiMaterial(); |
| 264 #endif | 266 #endif |
| 265 if (use_real_combobox) | 267 if (use_real_combobox) { |
| 266 InitializeComboboxView(layout, permission); | 268 InitializeComboboxView(layout, permission); |
| 267 else | 269 } else { |
| 268 InitializeMenuButtonView(layout, permission); | 270 InitializeMenuButtonView(layout, permission); |
| 271 } |
| 269 | 272 |
| 270 // Show the permission decision reason, if it was not the user. | 273 // Show the permission decision reason, if it was not the user. |
| 271 base::string16 reason = | 274 base::string16 reason = |
| 272 PageInfoUI::PermissionDecisionReasonToUIString(profile, permission, url); | 275 PageInfoUI::PermissionDecisionReasonToUIString(profile, permission, url); |
| 273 if (!reason.empty()) { | 276 if (!reason.empty()) { |
| 274 layout->StartRow(1, 1); | 277 layout->StartRow(1, 1); |
| 275 layout->SkipColumns(1); | 278 layout->SkipColumns(1); |
| 276 views::Label* permission_decision_reason = new views::Label(reason); | 279 views::Label* permission_decision_reason = new views::Label(reason); |
| 277 permission_decision_reason->SetEnabledColor( | 280 permission_decision_reason->SetEnabledColor( |
| 278 PageInfoUI::GetPermissionDecisionTextColor()); | 281 PageInfoUI::GetPermissionDecisionTextColor()); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 293 // Gross. On paper the Combobox and the ComboboxModelAdapter are both owned by | 296 // Gross. On paper the Combobox and the ComboboxModelAdapter are both owned by |
| 294 // this class, but actually, the Combobox is owned by View and will be | 297 // this class, but actually, the Combobox is owned by View and will be |
| 295 // destroyed in ~View(), which runs *after* ~PermissionSelectorRow() is done, | 298 // destroyed in ~View(), which runs *after* ~PermissionSelectorRow() is done, |
| 296 // which means the Combobox gets destroyed after its ComboboxModel, which | 299 // which means the Combobox gets destroyed after its ComboboxModel, which |
| 297 // causes an explosion when the Combobox attempts to stop observing the | 300 // causes an explosion when the Combobox attempts to stop observing the |
| 298 // ComboboxModel. This hack ensures the Combobox is deleted before its | 301 // ComboboxModel. This hack ensures the Combobox is deleted before its |
| 299 // ComboboxModel. | 302 // ComboboxModel. |
| 300 // | 303 // |
| 301 // Technically, the MenuButton has the same problem, but MenuButton doesn't | 304 // Technically, the MenuButton has the same problem, but MenuButton doesn't |
| 302 // use its model in its destructor. | 305 // use its model in its destructor. |
| 303 if (combobox_) | 306 if (combobox_) { |
| 304 combobox_->parent()->RemoveChildView(combobox_); | 307 combobox_->parent()->RemoveChildView(combobox_); |
| 308 } |
| 305 } | 309 } |
| 306 | 310 |
| 307 void PermissionSelectorRow::InitializeMenuButtonView( | 311 void PermissionSelectorRow::InitializeMenuButtonView( |
| 308 views::GridLayout* layout, | 312 views::GridLayout* layout, |
| 309 const PageInfoUI::PermissionInfo& permission) { | 313 const PageInfoUI::PermissionInfo& permission) { |
| 310 bool button_enabled = | 314 bool button_enabled = |
| 311 permission.source == content_settings::SETTING_SOURCE_USER; | 315 permission.source == content_settings::SETTING_SOURCE_USER; |
| 312 menu_button_ = new internal::PermissionMenuButton( | 316 menu_button_ = new internal::PermissionMenuButton( |
| 313 PageInfoUI::PermissionActionToUIString( | 317 PageInfoUI::PermissionActionToUIString( |
| 314 profile_, permission.type, permission.setting, | 318 profile_, permission.type, permission.setting, |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 349 menu_button_->SizeToPreferredSize(); | 353 menu_button_->SizeToPreferredSize(); |
| 350 // Re-layout will be done at the |PageInfoBubbleView| level, since | 354 // Re-layout will be done at the |PageInfoBubbleView| level, since |
| 351 // that view may need to resize itself to accomodate the new sizes of its | 355 // that view may need to resize itself to accomodate the new sizes of its |
| 352 // contents. | 356 // contents. |
| 353 menu_button_->InvalidateLayout(); | 357 menu_button_->InvalidateLayout(); |
| 354 } else if (combobox_) { | 358 } else if (combobox_) { |
| 355 bool use_default = permission.setting == CONTENT_SETTING_DEFAULT; | 359 bool use_default = permission.setting == CONTENT_SETTING_DEFAULT; |
| 356 combobox_->UpdateSelectedIndex(use_default); | 360 combobox_->UpdateSelectedIndex(use_default); |
| 357 } | 361 } |
| 358 | 362 |
| 359 for (PermissionSelectorRowObserver& observer : observer_list_) | 363 for (PermissionSelectorRowObserver& observer : observer_list_) { |
| 360 observer.OnPermissionChanged(permission); | 364 observer.OnPermissionChanged(permission); |
| 365 } |
| 361 } | 366 } |
| 362 | 367 |
| 363 views::View* PermissionSelectorRow::button() { | 368 views::View* PermissionSelectorRow::button() { |
| 364 // These casts are required because the two arms of a ?: cannot have different | 369 // These casts are required because the two arms of a ?: cannot have different |
| 365 // types T1 and T2, even if the resulting value of the ?: is about to be a T | 370 // types T1 and T2, even if the resulting value of the ?: is about to be a T |
| 366 // and T1 and T2 are both subtypes of T. | 371 // and T1 and T2 are both subtypes of T. |
| 367 return menu_button_ ? static_cast<views::View*>(menu_button_) | 372 return menu_button_ ? static_cast<views::View*>(menu_button_) |
| 368 : static_cast<views::View*>(combobox_); | 373 : static_cast<views::View*>(combobox_); |
| 369 } | 374 } |
| OLD | NEW |