| 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/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "chrome/browser/ui/website_settings/permission_menu_model.h" | 8 #include "chrome/browser/ui/website_settings/permission_menu_model.h" |
| 9 #include "chrome/browser/ui/website_settings/website_settings_ui.h" | 9 #include "chrome/browser/ui/website_settings/website_settings_ui.h" |
| 10 #include "grit/generated_resources.h" | 10 #include "grit/generated_resources.h" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 // Creates a new |PermissionMenuButton| with the passed |text|. The ownership | 38 // Creates a new |PermissionMenuButton| with the passed |text|. The ownership |
| 39 // of the |model| remains with the caller and is not transfered to the | 39 // of the |model| remains with the caller and is not transfered to the |
| 40 // |PermissionMenuButton|. If the |show_menu_marker| flag is true, then a | 40 // |PermissionMenuButton|. If the |show_menu_marker| flag is true, then a |
| 41 // small icon is be displayed next to the button |text|, indicating that the | 41 // small icon is be displayed next to the button |text|, indicating that the |
| 42 // button opens a drop down menu. | 42 // button opens a drop down menu. |
| 43 PermissionMenuButton(const base::string16& text, | 43 PermissionMenuButton(const base::string16& text, |
| 44 PermissionMenuModel* model, | 44 PermissionMenuModel* model, |
| 45 bool show_menu_marker); | 45 bool show_menu_marker); |
| 46 virtual ~PermissionMenuButton(); | 46 virtual ~PermissionMenuButton(); |
| 47 | 47 |
| 48 // Overridden from views::MenuButton. | |
| 49 virtual gfx::Size GetPreferredSize() const OVERRIDE; | |
| 50 | |
| 51 // Overridden from views::TextButton. | 48 // Overridden from views::TextButton. |
| 52 virtual void SetText(const base::string16& text) OVERRIDE; | 49 virtual void SetText(const base::string16& text) OVERRIDE; |
| 53 | 50 |
| 54 // Overridden from views::View. | 51 // Overridden from views::View. |
| 55 virtual void GetAccessibleState(ui::AXViewState* state) OVERRIDE; | 52 virtual void GetAccessibleState(ui::AXViewState* state) OVERRIDE; |
| 56 | 53 |
| 57 private: | 54 private: |
| 58 // Overridden from views::MenuButtonListener. | 55 // Overridden from views::MenuButtonListener. |
| 59 virtual void OnMenuButtonClicked(View* source, | 56 virtual void OnMenuButtonClicked(View* source, |
| 60 const gfx::Point& point) OVERRIDE; | 57 const gfx::Point& point) OVERRIDE; |
| 61 | 58 |
| 62 PermissionMenuModel* menu_model_; // Owned by |PermissionSelectorView|. | 59 PermissionMenuModel* menu_model_; // Owned by |PermissionSelectorView|. |
| 63 scoped_ptr<views::MenuRunner> menu_runner_; | 60 scoped_ptr<views::MenuRunner> menu_runner_; |
| 64 | 61 |
| 65 DISALLOW_COPY_AND_ASSIGN(PermissionMenuButton); | 62 DISALLOW_COPY_AND_ASSIGN(PermissionMenuButton); |
| 66 }; | 63 }; |
| 67 | 64 |
| 68 /////////////////////////////////////////////////////////////////////////////// | 65 /////////////////////////////////////////////////////////////////////////////// |
| 69 // PermissionMenuButton | 66 // PermissionMenuButton |
| 70 /////////////////////////////////////////////////////////////////////////////// | 67 /////////////////////////////////////////////////////////////////////////////// |
| 71 | 68 |
| 72 PermissionMenuButton::PermissionMenuButton(const base::string16& text, | 69 PermissionMenuButton::PermissionMenuButton(const base::string16& text, |
| 73 PermissionMenuModel* model, | 70 PermissionMenuModel* model, |
| 74 bool show_menu_marker) | 71 bool show_menu_marker) |
| 75 : MenuButton(NULL, text, this, show_menu_marker), | 72 : MenuButton(NULL, text, this, show_menu_marker), |
| 76 menu_model_(model) { | 73 menu_model_(model) { |
| 77 SetEnabledColor(GetNativeTheme()->GetSystemColor( | 74 SetTextColor(views::Button::STATE_NORMAL, GetNativeTheme()->GetSystemColor( |
| 78 ui::NativeTheme::kColorId_LabelEnabledColor)); | 75 ui::NativeTheme::kColorId_LabelEnabledColor)); |
| 79 SetHoverColor(GetNativeTheme()->GetSystemColor( | 76 SetTextColor(views::Button::STATE_HOVERED, GetNativeTheme()->GetSystemColor( |
| 80 ui::NativeTheme::kColorId_LabelEnabledColor)); | 77 ui::NativeTheme::kColorId_LabelEnabledColor)); |
| 81 SetDisabledColor(GetNativeTheme()->GetSystemColor( | 78 SetTextColor(views::Button::STATE_DISABLED, GetNativeTheme()->GetSystemColor( |
| 82 ui::NativeTheme::kColorId_LabelDisabledColor)); | 79 ui::NativeTheme::kColorId_LabelDisabledColor)); |
| 83 } | 80 } |
| 84 | 81 |
| 85 PermissionMenuButton::~PermissionMenuButton() { | 82 PermissionMenuButton::~PermissionMenuButton() { |
| 86 } | 83 } |
| 87 | 84 |
| 88 gfx::Size PermissionMenuButton::GetPreferredSize() const { | |
| 89 gfx::Insets insets = GetInsets(); | |
| 90 // Scale the button to the current text size. | |
| 91 gfx::Size prefsize(text_size_.width() + insets.width(), | |
| 92 text_size_.height() + insets.height()); | |
| 93 if (max_width_ > 0) | |
| 94 prefsize.set_width(std::min(max_width_, prefsize.width())); | |
| 95 if (show_menu_marker()) { | |
| 96 prefsize.Enlarge(menu_marker()->width() + | |
| 97 views::MenuButton::kMenuMarkerPaddingLeft + | |
| 98 views::MenuButton::kMenuMarkerPaddingRight, | |
| 99 0); | |
| 100 } | |
| 101 return prefsize; | |
| 102 } | |
| 103 | |
| 104 void PermissionMenuButton::SetText(const base::string16& text) { | 85 void PermissionMenuButton::SetText(const base::string16& text) { |
| 105 MenuButton::SetText(text); | 86 MenuButton::SetText(text); |
| 106 SizeToPreferredSize(); | 87 SizeToPreferredSize(); |
| 107 } | 88 } |
| 108 | 89 |
| 109 void PermissionMenuButton::GetAccessibleState(ui::AXViewState* state) { | 90 void PermissionMenuButton::GetAccessibleState(ui::AXViewState* state) { |
| 110 MenuButton::GetAccessibleState(state); | 91 MenuButton::GetAccessibleState(state); |
| 111 state->value = text(); | 92 state->value = GetText(); |
| 112 } | 93 } |
| 113 | 94 |
| 114 void PermissionMenuButton::OnMenuButtonClicked(View* source, | 95 void PermissionMenuButton::OnMenuButtonClicked(View* source, |
| 115 const gfx::Point& point) { | 96 const gfx::Point& point) { |
| 116 menu_runner_.reset(new views::MenuRunner(menu_model_)); | 97 menu_runner_.reset(new views::MenuRunner(menu_model_)); |
| 117 | 98 |
| 118 gfx::Point p(point); | 99 gfx::Point p(point); |
| 119 p.Offset(-source->width(), 0); | 100 p.Offset(-source->width(), 0); |
| 120 if (menu_runner_->RunMenuAt(source->GetWidget()->GetTopLevelWidget(), | 101 if (menu_runner_->RunMenuAt(source->GetWidget()->GetTopLevelWidget(), |
| 121 this, | 102 this, |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 // Update the menu button text to reflect the new setting. | 209 // Update the menu button text to reflect the new setting. |
| 229 menu_button_->SetText(WebsiteSettingsUI::PermissionActionToUIString( | 210 menu_button_->SetText(WebsiteSettingsUI::PermissionActionToUIString( |
| 230 permission.setting, | 211 permission.setting, |
| 231 permission.default_setting, | 212 permission.default_setting, |
| 232 content_settings::SETTING_SOURCE_USER)); | 213 content_settings::SETTING_SOURCE_USER)); |
| 233 | 214 |
| 234 FOR_EACH_OBSERVER(PermissionSelectorViewObserver, | 215 FOR_EACH_OBSERVER(PermissionSelectorViewObserver, |
| 235 observer_list_, | 216 observer_list_, |
| 236 OnPermissionChanged(permission)); | 217 OnPermissionChanged(permission)); |
| 237 } | 218 } |
| OLD | NEW |