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 "chrome/grit/generated_resources.h" | 10 #include "chrome/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 ~PermissionMenuButton() override; | 46 ~PermissionMenuButton() override; |
47 | 47 |
48 // Overridden from views::LabelButton. | |
49 void SetText(const base::string16& text) override; | |
50 | |
51 // Overridden from views::View. | 48 // Overridden from views::View. |
52 void GetAccessibleState(ui::AXViewState* state) override; | 49 void GetAccessibleState(ui::AXViewState* state) override; |
53 void OnNativeThemeChanged(const ui::NativeTheme* theme) override; | 50 void OnNativeThemeChanged(const ui::NativeTheme* theme) override; |
54 | 51 |
55 private: | 52 private: |
56 // Overridden from views::MenuButtonListener. | 53 // Overridden from views::MenuButtonListener. |
57 void OnMenuButtonClicked(View* source, const gfx::Point& point) override; | 54 void OnMenuButtonClicked(View* source, const gfx::Point& point) override; |
58 | 55 |
59 PermissionMenuModel* menu_model_; // Owned by |PermissionSelectorView|. | 56 PermissionMenuModel* menu_model_; // Owned by |PermissionSelectorView|. |
60 scoped_ptr<views::MenuRunner> menu_runner_; | 57 scoped_ptr<views::MenuRunner> menu_runner_; |
61 | 58 |
62 DISALLOW_COPY_AND_ASSIGN(PermissionMenuButton); | 59 DISALLOW_COPY_AND_ASSIGN(PermissionMenuButton); |
63 }; | 60 }; |
64 | 61 |
65 /////////////////////////////////////////////////////////////////////////////// | 62 /////////////////////////////////////////////////////////////////////////////// |
66 // PermissionMenuButton | 63 // PermissionMenuButton |
67 /////////////////////////////////////////////////////////////////////////////// | 64 /////////////////////////////////////////////////////////////////////////////// |
68 | 65 |
69 PermissionMenuButton::PermissionMenuButton(const base::string16& text, | 66 PermissionMenuButton::PermissionMenuButton(const base::string16& text, |
70 PermissionMenuModel* model, | 67 PermissionMenuModel* model, |
71 bool show_menu_marker) | 68 bool show_menu_marker) |
72 : MenuButton(NULL, text, this, show_menu_marker), | 69 : MenuButton(NULL, text, this, show_menu_marker), |
73 menu_model_(model) { | 70 menu_model_(model) { |
74 } | 71 } |
75 | 72 |
76 PermissionMenuButton::~PermissionMenuButton() { | 73 PermissionMenuButton::~PermissionMenuButton() { |
77 } | 74 } |
78 | 75 |
79 void PermissionMenuButton::SetText(const base::string16& text) { | |
80 MenuButton::SetText(text); | |
81 SizeToPreferredSize(); | |
82 } | |
83 | |
84 void PermissionMenuButton::GetAccessibleState(ui::AXViewState* state) { | 76 void PermissionMenuButton::GetAccessibleState(ui::AXViewState* state) { |
85 MenuButton::GetAccessibleState(state); | 77 MenuButton::GetAccessibleState(state); |
86 state->value = GetText(); | 78 state->value = GetText(); |
87 } | 79 } |
88 | 80 |
89 void PermissionMenuButton::OnNativeThemeChanged(const ui::NativeTheme* theme) { | 81 void PermissionMenuButton::OnNativeThemeChanged(const ui::NativeTheme* theme) { |
90 SetTextColor(views::Button::STATE_NORMAL, GetNativeTheme()->GetSystemColor( | 82 SetTextColor(views::Button::STATE_NORMAL, theme->GetSystemColor( |
91 ui::NativeTheme::kColorId_LabelEnabledColor)); | 83 ui::NativeTheme::kColorId_LabelEnabledColor)); |
92 SetTextColor(views::Button::STATE_HOVERED, GetNativeTheme()->GetSystemColor( | 84 SetTextColor(views::Button::STATE_HOVERED, theme->GetSystemColor( |
93 ui::NativeTheme::kColorId_LabelEnabledColor)); | 85 ui::NativeTheme::kColorId_LabelEnabledColor)); |
94 SetTextColor(views::Button::STATE_DISABLED, GetNativeTheme()->GetSystemColor( | 86 SetTextColor(views::Button::STATE_DISABLED, theme->GetSystemColor( |
95 ui::NativeTheme::kColorId_LabelDisabledColor)); | 87 ui::NativeTheme::kColorId_LabelDisabledColor)); |
96 } | 88 } |
97 | 89 |
98 void PermissionMenuButton::OnMenuButtonClicked(View* source, | 90 void PermissionMenuButton::OnMenuButtonClicked(View* source, |
99 const gfx::Point& point) { | 91 const gfx::Point& point) { |
100 menu_runner_.reset( | 92 menu_runner_.reset( |
101 new views::MenuRunner(menu_model_, views::MenuRunner::HAS_MNEMONICS)); | 93 new views::MenuRunner(menu_model_, views::MenuRunner::HAS_MNEMONICS)); |
102 | 94 |
103 gfx::Point p(point); | 95 gfx::Point p(point); |
104 p.Offset(-source->width(), 0); | 96 p.Offset(-source->width(), 0); |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 void PermissionSelectorView::PermissionChanged( | 198 void PermissionSelectorView::PermissionChanged( |
207 const WebsiteSettingsUI::PermissionInfo& permission) { | 199 const WebsiteSettingsUI::PermissionInfo& permission) { |
208 // Change the permission icon to reflect the selected setting. | 200 // Change the permission icon to reflect the selected setting. |
209 const gfx::Image& image = WebsiteSettingsUI::GetPermissionIcon(permission); | 201 const gfx::Image& image = WebsiteSettingsUI::GetPermissionIcon(permission); |
210 icon_->SetImage(image.ToImageSkia()); | 202 icon_->SetImage(image.ToImageSkia()); |
211 | 203 |
212 // Update the menu button text to reflect the new setting. | 204 // Update the menu button text to reflect the new setting. |
213 menu_button_->SetText(WebsiteSettingsUI::PermissionActionToUIString( | 205 menu_button_->SetText(WebsiteSettingsUI::PermissionActionToUIString( |
214 permission.type, permission.setting, permission.default_setting, | 206 permission.type, permission.setting, permission.default_setting, |
215 content_settings::SETTING_SOURCE_USER)); | 207 content_settings::SETTING_SOURCE_USER)); |
| 208 menu_button_->SizeToPreferredSize(); |
216 | 209 |
217 FOR_EACH_OBSERVER(PermissionSelectorViewObserver, | 210 FOR_EACH_OBSERVER(PermissionSelectorViewObserver, |
218 observer_list_, | 211 observer_list_, |
219 OnPermissionChanged(permission)); | 212 OnPermissionChanged(permission)); |
220 } | 213 } |
OLD | NEW |