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