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/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
8 #include "chrome/browser/ui/website_settings/website_settings_ui.h" | 8 #include "chrome/browser/ui/website_settings/website_settings_ui.h" |
9 #include "grit/generated_resources.h" | 9 #include "grit/generated_resources.h" |
10 #include "ui/base/l10n/l10n_util.h" | 10 #include "ui/base/l10n/l10n_util.h" |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
84 | 84 |
85 // The |PermissionMenuButton| provides a menu for selecting a setting a | 85 // The |PermissionMenuButton| provides a menu for selecting a setting a |
86 // permissions type. | 86 // permissions type. |
87 class PermissionMenuButton : public views::MenuButton, | 87 class PermissionMenuButton : public views::MenuButton, |
88 public views::MenuButtonListener { | 88 public views::MenuButtonListener { |
89 public: | 89 public: |
90 // Creates a new |PermissionMenuButton| with the passed |text|. The ownership | 90 // Creates a new |PermissionMenuButton| with the passed |text|. The ownership |
91 // of the |model| remains with the caller and is not transfered to the | 91 // of the |model| remains with the caller and is not transfered to the |
92 // |PermissionMenuButton|. | 92 // |PermissionMenuButton|. |
93 PermissionMenuButton(const string16& text, | 93 PermissionMenuButton(const string16& text, |
94 PermissionMenuModel* model); | 94 PermissionMenuModel* model, |
95 bool show_menu_marker); | |
Finnur
2012/08/03 08:16:48
Document the new parameter.
markusheintz_
2012/08/03 10:52:49
Done.
| |
95 virtual ~PermissionMenuButton(); | 96 virtual ~PermissionMenuButton(); |
96 | 97 |
97 // Overridden from views::MenuButton. | 98 // Overridden from views::MenuButton. |
98 virtual gfx::Size GetPreferredSize() OVERRIDE; | 99 virtual gfx::Size GetPreferredSize() OVERRIDE; |
99 | 100 |
100 // Overridden from views::TextButton. | 101 // Overridden from views::TextButton. |
101 virtual void SetText(const string16& text) OVERRIDE; | 102 virtual void SetText(const string16& text) OVERRIDE; |
102 | 103 |
103 private: | 104 private: |
104 // Overridden from views::MenuButtonListener. | 105 // Overridden from views::MenuButtonListener. |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
161 void PermissionMenuModel::ExecuteCommand(int command_id) { | 162 void PermissionMenuModel::ExecuteCommand(int command_id) { |
162 current_setting_ = kSettingsForCommandIDs[command_id]; | 163 current_setting_ = kSettingsForCommandIDs[command_id]; |
163 permission_selector_->SelectionChanged(); | 164 permission_selector_->SelectionChanged(); |
164 } | 165 } |
165 | 166 |
166 /////////////////////////////////////////////////////////////////////////////// | 167 /////////////////////////////////////////////////////////////////////////////// |
167 // PermissionMenuButton | 168 // PermissionMenuButton |
168 /////////////////////////////////////////////////////////////////////////////// | 169 /////////////////////////////////////////////////////////////////////////////// |
169 | 170 |
170 PermissionMenuButton::PermissionMenuButton(const string16& text, | 171 PermissionMenuButton::PermissionMenuButton(const string16& text, |
171 PermissionMenuModel* model) | 172 PermissionMenuModel* model, |
172 : ALLOW_THIS_IN_INITIALIZER_LIST(MenuButton(NULL, text, this, true)), | 173 bool show_menu_marker) |
174 : ALLOW_THIS_IN_INITIALIZER_LIST(MenuButton(NULL, text, this, | |
175 show_menu_marker)), | |
173 menu_model_(model) { | 176 menu_model_(model) { |
174 } | 177 } |
175 | 178 |
176 PermissionMenuButton::~PermissionMenuButton() { | 179 PermissionMenuButton::~PermissionMenuButton() { |
177 } | 180 } |
178 | 181 |
179 gfx::Size PermissionMenuButton::GetPreferredSize() { | 182 gfx::Size PermissionMenuButton::GetPreferredSize() { |
180 gfx::Insets insets = GetInsets(); | 183 gfx::Insets insets = GetInsets(); |
181 // Scale the button to the current text size. | 184 // Scale the button to the current text size. |
182 gfx::Size prefsize(text_size_.width() + insets.width(), | 185 gfx::Size prefsize(text_size_.width() + insets.width(), |
(...skipping 29 matching lines...) Expand all Loading... | |
212 views::MenuRunner::HAS_MNEMONICS) == views::MenuRunner::MENU_DELETED) | 215 views::MenuRunner::HAS_MNEMONICS) == views::MenuRunner::MENU_DELETED) |
213 return; | 216 return; |
214 } | 217 } |
215 | 218 |
216 } // namespace internal | 219 } // namespace internal |
217 | 220 |
218 /////////////////////////////////////////////////////////////////////////////// | 221 /////////////////////////////////////////////////////////////////////////////// |
219 // PermissionSelectorView | 222 // PermissionSelectorView |
220 /////////////////////////////////////////////////////////////////////////////// | 223 /////////////////////////////////////////////////////////////////////////////// |
221 | 224 |
222 PermissionSelectorView::PermissionSelectorView(ContentSettingsType type, | 225 PermissionSelectorView::PermissionSelectorView( |
223 ContentSetting default_setting, | 226 ContentSettingsType type, |
224 ContentSetting current_setting) | 227 ContentSetting default_setting, |
228 ContentSetting current_setting, | |
229 content_settings::SettingSource source) | |
225 : icon_(NULL), | 230 : icon_(NULL), |
226 menu_button_(NULL) { | 231 menu_button_(NULL) { |
227 views::GridLayout* layout = new views::GridLayout(this); | 232 views::GridLayout* layout = new views::GridLayout(this); |
228 SetLayoutManager(layout); | 233 SetLayoutManager(layout); |
229 const int column_set_id = 0; | 234 const int column_set_id = 0; |
230 views::ColumnSet* column_set = layout->AddColumnSet(column_set_id); | 235 views::ColumnSet* column_set = layout->AddColumnSet(column_set_id); |
231 column_set->AddColumn(views::GridLayout::FILL, | 236 column_set->AddColumn(views::GridLayout::FILL, |
232 views::GridLayout::FILL, | 237 views::GridLayout::FILL, |
233 1, | 238 1, |
234 views::GridLayout::FIXED, | 239 views::GridLayout::FIXED, |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
267 IDS_WEBSITE_SETTINGS_PERMISSION_TYPE, | 272 IDS_WEBSITE_SETTINGS_PERMISSION_TYPE, |
268 WebsiteSettingsUI::PermissionTypeToUIString(type))); | 273 WebsiteSettingsUI::PermissionTypeToUIString(type))); |
269 layout->AddView(label, | 274 layout->AddView(label, |
270 1, | 275 1, |
271 1, | 276 1, |
272 views::GridLayout::LEADING, | 277 views::GridLayout::LEADING, |
273 views::GridLayout::CENTER); | 278 views::GridLayout::CENTER); |
274 // Create the permission menu button. | 279 // Create the permission menu button. |
275 menu_button_model_.reset(new internal::PermissionMenuModel( | 280 menu_button_model_.reset(new internal::PermissionMenuModel( |
276 type, default_setting, current_setting, this)); | 281 type, default_setting, current_setting, this)); |
282 bool button_enabled = source == content_settings::SETTING_SOURCE_USER; | |
277 menu_button_ = new internal::PermissionMenuButton( | 283 menu_button_ = new internal::PermissionMenuButton( |
278 WebsiteSettingsUI::PermissionActionToUIString(current_setting, | 284 WebsiteSettingsUI::PermissionActionToUIString(current_setting, |
279 default_setting), | 285 default_setting, |
280 menu_button_model_.get()); | 286 source), |
287 menu_button_model_.get(), | |
288 button_enabled); | |
289 menu_button_->SetEnabled(button_enabled); | |
281 layout->AddView(menu_button_); | 290 layout->AddView(menu_button_); |
282 } | 291 } |
283 | 292 |
284 void PermissionSelectorView::AddObserver( | 293 void PermissionSelectorView::AddObserver( |
285 PermissionSelectorViewObserver* observer) { | 294 PermissionSelectorViewObserver* observer) { |
286 observer_list_.AddObserver(observer); | 295 observer_list_.AddObserver(observer); |
287 } | 296 } |
288 | 297 |
289 void PermissionSelectorView::SelectionChanged() { | 298 void PermissionSelectorView::SelectionChanged() { |
290 // Update the icon to reflect the new setting. | 299 // Update the icon to reflect the new setting. |
291 ContentSetting effective_setting = menu_button_model_->current_setting(); | 300 ContentSetting effective_setting = menu_button_model_->current_setting(); |
292 if (effective_setting == CONTENT_SETTING_DEFAULT) | 301 if (effective_setting == CONTENT_SETTING_DEFAULT) |
293 effective_setting = menu_button_model_->default_setting(); | 302 effective_setting = menu_button_model_->default_setting(); |
294 const gfx::Image& image = WebsiteSettingsUI::GetPermissionIcon( | 303 const gfx::Image& image = WebsiteSettingsUI::GetPermissionIcon( |
295 menu_button_model_->site_permission(), effective_setting); | 304 menu_button_model_->site_permission(), effective_setting); |
296 icon_->SetImage(image.ToImageSkia()); | 305 icon_->SetImage(image.ToImageSkia()); |
297 | 306 |
298 // Update the menu button text to reflect the new setting. | 307 // Update the menu button text to reflect the new setting. |
299 menu_button_->SetText(WebsiteSettingsUI::PermissionActionToUIString( | 308 menu_button_->SetText(WebsiteSettingsUI::PermissionActionToUIString( |
300 menu_button_model_->current_setting(), | 309 menu_button_model_->current_setting(), |
301 menu_button_model_->default_setting())); | 310 menu_button_model_->default_setting(), |
311 content_settings::SETTING_SOURCE_USER)); | |
312 | |
302 | 313 |
303 FOR_EACH_OBSERVER(PermissionSelectorViewObserver, | 314 FOR_EACH_OBSERVER(PermissionSelectorViewObserver, |
304 observer_list_, | 315 observer_list_, |
305 OnPermissionChanged(this)); | 316 OnPermissionChanged(this)); |
306 } | 317 } |
307 | 318 |
308 ContentSetting PermissionSelectorView::GetSelectedSetting() const { | 319 ContentSetting PermissionSelectorView::GetSelectedSetting() const { |
309 return menu_button_model_->current_setting(); | 320 return menu_button_model_->current_setting(); |
310 } | 321 } |
311 | 322 |
312 ContentSettingsType PermissionSelectorView::GetPermissionType() const { | 323 ContentSettingsType PermissionSelectorView::GetPermissionType() const { |
313 return menu_button_model_->site_permission(); | 324 return menu_button_model_->site_permission(); |
314 } | 325 } |
315 | 326 |
316 void PermissionSelectorView::ChildPreferredSizeChanged(View* child) { | 327 void PermissionSelectorView::ChildPreferredSizeChanged(View* child) { |
317 SizeToPreferredSize(); | 328 SizeToPreferredSize(); |
318 // FIXME: The parent is only a plain |View| that is used as a | 329 // FIXME: The parent is only a plain |View| that is used as a |
319 // container/box/panel. The SizeToPreferredSize method of the parent is | 330 // container/box/panel. The SizeToPreferredSize method of the parent is |
320 // called here directly in order not to implement a custom |View| class with | 331 // called here directly in order not to implement a custom |View| class with |
321 // its own implementation of the ChildPreferredSizeChanged method. | 332 // its own implementation of the ChildPreferredSizeChanged method. |
322 parent()->SizeToPreferredSize(); | 333 parent()->SizeToPreferredSize(); |
323 } | 334 } |
324 | 335 |
325 PermissionSelectorView::~PermissionSelectorView() { | 336 PermissionSelectorView::~PermissionSelectorView() { |
326 } | 337 } |
OLD | NEW |