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 virtual void OnNativeThemeChanged(const ui::NativeTheme* theme) OVERRIDE; | 53 virtual void OnNativeThemeChanged(const ui::NativeTheme* theme) OVERRIDE; |
57 | 54 |
58 private: | 55 private: |
59 // Overridden from views::MenuButtonListener. | 56 // Overridden from views::MenuButtonListener. |
60 virtual void OnMenuButtonClicked(View* source, | 57 virtual void OnMenuButtonClicked(View* source, |
61 const gfx::Point& point) OVERRIDE; | 58 const gfx::Point& point) OVERRIDE; |
62 | 59 |
63 PermissionMenuModel* menu_model_; // Owned by |PermissionSelectorView|. | 60 PermissionMenuModel* menu_model_; // Owned by |PermissionSelectorView|. |
64 scoped_ptr<views::MenuRunner> menu_runner_; | 61 scoped_ptr<views::MenuRunner> menu_runner_; |
65 | 62 |
66 DISALLOW_COPY_AND_ASSIGN(PermissionMenuButton); | 63 DISALLOW_COPY_AND_ASSIGN(PermissionMenuButton); |
67 }; | 64 }; |
68 | 65 |
69 /////////////////////////////////////////////////////////////////////////////// | 66 /////////////////////////////////////////////////////////////////////////////// |
70 // PermissionMenuButton | 67 // PermissionMenuButton |
71 /////////////////////////////////////////////////////////////////////////////// | 68 /////////////////////////////////////////////////////////////////////////////// |
72 | 69 |
73 PermissionMenuButton::PermissionMenuButton(const base::string16& text, | 70 PermissionMenuButton::PermissionMenuButton(const base::string16& text, |
74 PermissionMenuModel* model, | 71 PermissionMenuModel* model, |
75 bool show_menu_marker) | 72 bool show_menu_marker) |
76 : MenuButton(NULL, text, this, show_menu_marker), | 73 : MenuButton(NULL, text, this, show_menu_marker), |
77 menu_model_(model) { | 74 menu_model_(model) { |
78 | |
79 } | 75 } |
80 | 76 |
81 PermissionMenuButton::~PermissionMenuButton() { | 77 PermissionMenuButton::~PermissionMenuButton() { |
82 } | 78 } |
83 | 79 |
84 gfx::Size PermissionMenuButton::GetPreferredSize() const { | |
85 gfx::Insets insets = GetInsets(); | |
86 // Scale the button to the current text size. | |
87 gfx::Size prefsize(text_size_.width() + insets.width(), | |
88 text_size_.height() + insets.height()); | |
89 if (max_width_ > 0) | |
90 prefsize.set_width(std::min(max_width_, prefsize.width())); | |
91 if (show_menu_marker()) { | |
92 prefsize.Enlarge(menu_marker()->width() + | |
93 views::MenuButton::kMenuMarkerPaddingLeft + | |
94 views::MenuButton::kMenuMarkerPaddingRight, | |
95 0); | |
96 } | |
97 return prefsize; | |
98 } | |
99 | |
100 void PermissionMenuButton::SetText(const base::string16& text) { | 80 void PermissionMenuButton::SetText(const base::string16& text) { |
101 MenuButton::SetText(text); | 81 MenuButton::SetText(text); |
102 SizeToPreferredSize(); | 82 SizeToPreferredSize(); |
103 } | 83 } |
104 | 84 |
105 void PermissionMenuButton::GetAccessibleState(ui::AXViewState* state) { | 85 void PermissionMenuButton::GetAccessibleState(ui::AXViewState* state) { |
106 MenuButton::GetAccessibleState(state); | 86 MenuButton::GetAccessibleState(state); |
107 state->value = text(); | 87 state->value = GetText(); |
108 } | 88 } |
109 | 89 |
110 void PermissionMenuButton::OnNativeThemeChanged(const ui::NativeTheme* theme) { | 90 void PermissionMenuButton::OnNativeThemeChanged(const ui::NativeTheme* theme) { |
111 SetEnabledColor(theme->GetSystemColor( | 91 SetTextColor(views::Button::STATE_NORMAL, GetNativeTheme()->GetSystemColor( |
112 ui::NativeTheme::kColorId_LabelEnabledColor)); | 92 ui::NativeTheme::kColorId_LabelEnabledColor)); |
113 SetHoverColor(theme->GetSystemColor( | 93 SetTextColor(views::Button::STATE_HOVERED, GetNativeTheme()->GetSystemColor( |
114 ui::NativeTheme::kColorId_LabelEnabledColor)); | 94 ui::NativeTheme::kColorId_LabelEnabledColor)); |
115 SetDisabledColor(theme->GetSystemColor( | 95 SetTextColor(views::Button::STATE_DISABLED, GetNativeTheme()->GetSystemColor( |
116 ui::NativeTheme::kColorId_LabelDisabledColor)); | 96 ui::NativeTheme::kColorId_LabelDisabledColor)); |
117 } | 97 } |
118 | 98 |
119 void PermissionMenuButton::OnMenuButtonClicked(View* source, | 99 void PermissionMenuButton::OnMenuButtonClicked(View* source, |
120 const gfx::Point& point) { | 100 const gfx::Point& point) { |
121 menu_runner_.reset(new views::MenuRunner(menu_model_)); | 101 menu_runner_.reset(new views::MenuRunner(menu_model_)); |
122 | 102 |
123 gfx::Point p(point); | 103 gfx::Point p(point); |
124 p.Offset(-source->width(), 0); | 104 p.Offset(-source->width(), 0); |
125 if (menu_runner_->RunMenuAt(source->GetWidget()->GetTopLevelWidget(), | 105 if (menu_runner_->RunMenuAt(source->GetWidget()->GetTopLevelWidget(), |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 // Update the menu button text to reflect the new setting. | 213 // Update the menu button text to reflect the new setting. |
234 menu_button_->SetText(WebsiteSettingsUI::PermissionActionToUIString( | 214 menu_button_->SetText(WebsiteSettingsUI::PermissionActionToUIString( |
235 permission.setting, | 215 permission.setting, |
236 permission.default_setting, | 216 permission.default_setting, |
237 content_settings::SETTING_SOURCE_USER)); | 217 content_settings::SETTING_SOURCE_USER)); |
238 | 218 |
239 FOR_EACH_OBSERVER(PermissionSelectorViewObserver, | 219 FOR_EACH_OBSERVER(PermissionSelectorViewObserver, |
240 observer_list_, | 220 observer_list_, |
241 OnPermissionChanged(permission)); | 221 OnPermissionChanged(permission)); |
242 } | 222 } |
OLD | NEW |