| 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/website_settings/permission_selector_view.h" | 5 #include "chrome/browser/ui/views/website_settings/permission_selector_view.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/views/website_settings/website_settings_popup_view.h
" | 10 #include "chrome/browser/ui/views/website_settings/website_settings_popup_view.h
" |
| 11 #include "chrome/browser/ui/website_settings/permission_menu_model.h" | 11 #include "chrome/browser/ui/website_settings/permission_menu_model.h" |
| 12 #include "chrome/browser/ui/website_settings/website_settings_ui.h" | 12 #include "chrome/browser/ui/website_settings/website_settings_ui.h" |
| 13 #include "chrome/grit/generated_resources.h" | 13 #include "chrome/grit/generated_resources.h" |
| 14 #include "ui/accessibility/ax_view_state.h" | 14 #include "ui/accessibility/ax_view_state.h" |
| 15 #include "ui/base/l10n/l10n_util.h" | 15 #include "ui/base/l10n/l10n_util.h" |
| 16 #include "ui/base/material_design/material_design_controller.h" |
| 16 #include "ui/base/models/combobox_model.h" | 17 #include "ui/base/models/combobox_model.h" |
| 17 #include "ui/gfx/image/image.h" | 18 #include "ui/gfx/image/image.h" |
| 18 #include "ui/views/controls/button/menu_button.h" | 19 #include "ui/views/controls/button/menu_button.h" |
| 19 #include "ui/views/controls/combobox/combobox.h" | 20 #include "ui/views/controls/combobox/combobox.h" |
| 20 #include "ui/views/controls/combobox/combobox_listener.h" | 21 #include "ui/views/controls/combobox/combobox_listener.h" |
| 21 #include "ui/views/controls/image_view.h" | 22 #include "ui/views/controls/image_view.h" |
| 22 #include "ui/views/controls/label.h" | 23 #include "ui/views/controls/label.h" |
| 23 #include "ui/views/controls/menu/menu_runner.h" | 24 #include "ui/views/controls/menu/menu_runner.h" |
| 24 #include "ui/views/layout/grid_layout.h" | 25 #include "ui/views/layout/grid_layout.h" |
| 25 #include "ui/views/view.h" | 26 #include "ui/views/view.h" |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 public: | 174 public: |
| 174 PermissionCombobox(const base::string16& text, | 175 PermissionCombobox(const base::string16& text, |
| 175 ComboboxModelAdapter* model, | 176 ComboboxModelAdapter* model, |
| 176 bool enabled, | 177 bool enabled, |
| 177 bool use_default); | 178 bool use_default); |
| 178 ~PermissionCombobox() override; | 179 ~PermissionCombobox() override; |
| 179 | 180 |
| 180 void UpdateSelectedIndex(bool use_default); | 181 void UpdateSelectedIndex(bool use_default); |
| 181 | 182 |
| 182 private: | 183 private: |
| 184 // views::Combobox: |
| 185 void OnPaintBorder(gfx::Canvas* canvas) override; |
| 186 |
| 183 // views::ComboboxListener: | 187 // views::ComboboxListener: |
| 184 void OnPerformAction(Combobox* combobox) override; | 188 void OnPerformAction(Combobox* combobox) override; |
| 185 | 189 |
| 186 ComboboxModelAdapter* model_; | 190 ComboboxModelAdapter* model_; |
| 187 }; | 191 }; |
| 188 | 192 |
| 189 PermissionCombobox::PermissionCombobox(const base::string16& text, | 193 PermissionCombobox::PermissionCombobox(const base::string16& text, |
| 190 ComboboxModelAdapter* model, | 194 ComboboxModelAdapter* model, |
| 191 bool enabled, | 195 bool enabled, |
| 192 bool use_default) | 196 bool use_default) |
| 193 : views::Combobox(model), model_(model) { | 197 : views::Combobox(model), model_(model) { |
| 194 set_listener(this); | 198 set_listener(this); |
| 195 SetEnabled(enabled); | 199 SetEnabled(enabled); |
| 196 UpdateSelectedIndex(use_default); | 200 UpdateSelectedIndex(use_default); |
| 201 if (ui::MaterialDesignController::IsSecondaryUiMaterial()) { |
| 202 set_size_to_largest_label(false); |
| 203 ModelChanged(); |
| 204 } |
| 197 } | 205 } |
| 198 | 206 |
| 199 PermissionCombobox::~PermissionCombobox() {} | 207 PermissionCombobox::~PermissionCombobox() {} |
| 200 | 208 |
| 201 void PermissionCombobox::UpdateSelectedIndex(bool use_default) { | 209 void PermissionCombobox::UpdateSelectedIndex(bool use_default) { |
| 202 int index = model_->GetCheckedIndex(); | 210 int index = model_->GetCheckedIndex(); |
| 203 if (use_default && index == -1) { | 211 if (use_default && index == -1) { |
| 204 LOG(ERROR) << "ow!"; | 212 LOG(ERROR) << "ow!"; |
| 205 index = 0; | 213 index = 0; |
| 206 } | 214 } |
| 207 SetSelectedIndex(index); | 215 SetSelectedIndex(index); |
| 208 } | 216 } |
| 209 | 217 |
| 218 void PermissionCombobox::OnPaintBorder(gfx::Canvas* canvas) { |
| 219 // No border except a focus indicator for MD mode. |
| 220 if (ui::MaterialDesignController::IsSecondaryUiMaterial() && !HasFocus()) |
| 221 return; |
| 222 Combobox::OnPaintBorder(canvas); |
| 223 } |
| 224 |
| 210 void PermissionCombobox::OnPerformAction(Combobox* combobox) { | 225 void PermissionCombobox::OnPerformAction(Combobox* combobox) { |
| 211 model_->OnPerformAction(combobox->selected_index()); | 226 model_->OnPerformAction(combobox->selected_index()); |
| 212 } | 227 } |
| 213 | 228 |
| 214 } // namespace internal | 229 } // namespace internal |
| 215 | 230 |
| 216 /////////////////////////////////////////////////////////////////////////////// | 231 /////////////////////////////////////////////////////////////////////////////// |
| 217 // PermissionSelectorView | 232 // PermissionSelectorView |
| 218 /////////////////////////////////////////////////////////////////////////////// | 233 /////////////////////////////////////////////////////////////////////////////// |
| 219 | 234 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 1, | 278 1, |
| 264 1, | 279 1, |
| 265 views::GridLayout::LEADING, | 280 views::GridLayout::LEADING, |
| 266 views::GridLayout::CENTER); | 281 views::GridLayout::CENTER); |
| 267 // Create the menu model. | 282 // Create the menu model. |
| 268 menu_model_.reset(new PermissionMenuModel( | 283 menu_model_.reset(new PermissionMenuModel( |
| 269 url, | 284 url, |
| 270 permission, | 285 permission, |
| 271 base::Bind(&PermissionSelectorView::PermissionChanged, | 286 base::Bind(&PermissionSelectorView::PermissionChanged, |
| 272 base::Unretained(this)))); | 287 base::Unretained(this)))); |
| 288 |
| 273 // Create the permission menu button. | 289 // Create the permission menu button. |
| 274 #if defined(OS_MACOSX) | 290 #if defined(OS_MACOSX) |
| 275 InitializeComboboxView(layout, permission); | 291 bool use_real_combobox = true; |
| 276 #else | 292 #else |
| 277 InitializeMenuButtonView(layout, permission); | 293 bool use_real_combobox = |
| 294 ui::MaterialDesignController::IsSecondaryUiMaterial(); |
| 278 #endif | 295 #endif |
| 296 if (use_real_combobox) |
| 297 InitializeComboboxView(layout, permission); |
| 298 else |
| 299 InitializeMenuButtonView(layout, permission); |
| 279 } | 300 } |
| 280 | 301 |
| 281 void PermissionSelectorView::AddObserver( | 302 void PermissionSelectorView::AddObserver( |
| 282 PermissionSelectorViewObserver* observer) { | 303 PermissionSelectorViewObserver* observer) { |
| 283 observer_list_.AddObserver(observer); | 304 observer_list_.AddObserver(observer); |
| 284 } | 305 } |
| 285 | 306 |
| 286 void PermissionSelectorView::ChildPreferredSizeChanged(View* child) { | 307 void PermissionSelectorView::ChildPreferredSizeChanged(View* child) { |
| 287 SizeToPreferredSize(); | 308 SizeToPreferredSize(); |
| 288 // FIXME: The parent is only a plain |View| that is used as a | 309 // FIXME: The parent is only a plain |View| that is used as a |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 menu_button_->SizeToPreferredSize(); | 379 menu_button_->SizeToPreferredSize(); |
| 359 } else if (combobox_) { | 380 } else if (combobox_) { |
| 360 bool use_default = permission.setting == CONTENT_SETTING_DEFAULT; | 381 bool use_default = permission.setting == CONTENT_SETTING_DEFAULT; |
| 361 combobox_->UpdateSelectedIndex(use_default); | 382 combobox_->UpdateSelectedIndex(use_default); |
| 362 } | 383 } |
| 363 | 384 |
| 364 FOR_EACH_OBSERVER(PermissionSelectorViewObserver, | 385 FOR_EACH_OBSERVER(PermissionSelectorViewObserver, |
| 365 observer_list_, | 386 observer_list_, |
| 366 OnPermissionChanged(permission)); | 387 OnPermissionChanged(permission)); |
| 367 } | 388 } |
| OLD | NEW |