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