| 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 #ifndef CHROME_BROWSER_UI_GTK_WEBSITE_SETTINGS_PERMISSION_SELECTOR_H_ | 5 #ifndef CHROME_BROWSER_UI_GTK_WEBSITE_SETTINGS_PERMISSION_SELECTOR_H_ |
| 6 #define CHROME_BROWSER_UI_GTK_WEBSITE_SETTINGS_PERMISSION_SELECTOR_H_ | 6 #define CHROME_BROWSER_UI_GTK_WEBSITE_SETTINGS_PERMISSION_SELECTOR_H_ |
| 7 | 7 |
| 8 #include <gtk/gtk.h> |
| 9 |
| 8 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 9 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/observer_list.h" | 13 #include "base/observer_list.h" |
| 14 #include "chrome/browser/ui/website_settings/permission_menu_model.h" |
| 11 #include "chrome/browser/ui/gtk/website_settings/permission_selector_observer.h" | 15 #include "chrome/browser/ui/gtk/website_settings/permission_selector_observer.h" |
| 12 #include "chrome/common/content_settings.h" | 16 #include "chrome/common/content_settings.h" |
| 13 #include "chrome/common/content_settings_types.h" | 17 #include "chrome/common/content_settings_types.h" |
| 14 #include "ui/base/gtk/gtk_signal.h" | 18 #include "ui/base/gtk/gtk_signal.h" |
| 15 | 19 |
| 20 class MenuGtk; |
| 16 class GtkThemeService; | 21 class GtkThemeService; |
| 17 typedef struct _GParamSpec GParamSpec; | |
| 18 typedef struct _GtkWidget GtkWidget; | |
| 19 | 22 |
| 20 // The class |PermissionSelector| allows to change the permission |setting| of a | 23 // The class |PermissionSelector| allows to change the permission |setting| of a |
| 21 // given permission |type|. | 24 // given permission |type|. |
| 22 class PermissionSelector { | 25 class PermissionSelector : public PermissionMenuModel::Delegate { |
| 23 public: | 26 public: |
| 24 // Creates a |PermissionSelector| for the given permission |type|. |setting| | 27 // Creates a |PermissionSelector| for the given permission |type|. |setting| |
| 25 // is the current permissions setting. It is possible to pass | 28 // is the current permissions setting. It is possible to pass |
| 26 // |CONTENT_SETTING_DEFAULT| as value for |setting|. |default_setting| is the | 29 // |CONTENT_SETTING_DEFAULT| as value for |setting|. |default_setting| is the |
| 27 // effective default setting for the given permission |type|. It is not | 30 // effective default setting for the given permission |type|. It is not |
| 28 // allowed to pass |CONTENT_SETTING_DEFAULT| as value for |default_setting|. | 31 // allowed to pass |CONTENT_SETTING_DEFAULT| as value for |default_setting|. |
| 29 PermissionSelector(GtkThemeService* theme_service_, | 32 PermissionSelector(GtkThemeService* theme_service_, |
| 30 ContentSettingsType type, | 33 ContentSettingsType type, |
| 31 ContentSetting setting, | 34 ContentSetting setting, |
| 32 ContentSetting default_setting); | 35 ContentSetting default_setting, |
| 33 ~PermissionSelector(); | 36 content_settings::SettingSource source); |
| 37 virtual ~PermissionSelector(); |
| 34 | 38 |
| 35 // Creates the UI for the |PermissionSelector| and returns the widget that | 39 // Returns the container widget that contains all |PermissionSelector| UI |
| 36 // contains the UI elements. The ownership of the widget is transfered to the | 40 // widgets. |
| 37 // caller. | 41 GtkWidget* widget() { return widget_; } |
| 38 GtkWidget* CreateUI(); | |
| 39 | 42 |
| 40 // Adds an |observer|. | 43 // Adds an |observer|. |
| 41 void AddObserver(PermissionSelectorObserver* observer); | 44 void AddObserver(PermissionSelectorObserver* observer); |
| 42 | 45 |
| 43 // Returns the current permission setting. | 46 // Returns the current permission setting. |
| 44 ContentSetting setting() const { return setting_; } | 47 ContentSetting GetSetting() const; |
| 45 | 48 |
| 46 // Returns the permissions type. | 49 // Returns the permissions type. |
| 47 ContentSettingsType type() const { return type_; } | 50 ContentSettingsType GetType() const; |
| 48 | 51 |
| 49 private: | 52 private: |
| 50 CHROMEGTK_CALLBACK_0(PermissionSelector, void, OnPermissionChanged); | 53 // Gtk callback to intercept mouse clicks to the menu buttons. |
| 51 CHROMEGTK_CALLBACK_1(PermissionSelector, void, OnComboBoxShown, GParamSpec*); | 54 CHROMEGTK_CALLBACK_1(PermissionSelector, gboolean, OnMenuButtonPressEvent, |
| 55 GdkEventButton*); |
| 52 | 56 |
| 53 GtkThemeService* theme_service_; | 57 // PermissionMenuModel::PermissionMenuDelegate implementation. |
| 58 virtual void ExecuteCommand(int command_id) OVERRIDE; |
| 59 virtual bool IsCommandIdChecked(int command_id) OVERRIDE; |
| 54 | 60 |
| 55 // The permission type. | 61 // The container widget that contains the PermissionSelecter UI widgets. |
| 56 ContentSettingsType type_; | 62 GtkWidget* widget_; // Owned by the widget hierarchy. |
| 57 // The current permission setting. | 63 |
| 58 ContentSetting setting_; | 64 // The button that toggles the permission |menu_|. |
| 59 // The effective default setting. This is required to create the proper UI | 65 GtkWidget* menu_button_; // Owned by the widget hierarchy. |
| 60 // string for the default setting. | 66 |
| 61 ContentSetting default_setting_; | 67 // The menu that provides the permission settings. |
| 68 scoped_ptr<MenuGtk> menu_; |
| 69 |
| 70 // The model for the permission |menu_|. |
| 71 scoped_ptr<PermissionMenuModel> menu_model_; |
| 62 | 72 |
| 63 // The permission type icon. The icon is changed depending on the selected | 73 // The permission type icon. The icon is changed depending on the selected |
| 64 // setting. | 74 // setting. |
| 65 // Owned by the widget hierarchy created by the CreateUI method. | 75 // Owned by the widget hierarchy created by the CreateUI method. |
| 66 GtkWidget* icon_; | 76 GtkWidget* icon_; |
| 67 | 77 |
| 78 // The site permission (the |ContentSettingsType|) for which the menu model |
| 79 // provides settings. |
| 80 ContentSettingsType type_; |
| 81 |
| 82 // The global default setting for the permission |type_|. |
| 83 ContentSetting default_setting_; |
| 84 |
| 85 // The currently active setting for the permission |type_|. |
| 86 ContentSetting setting_; |
| 87 |
| 68 ObserverList<PermissionSelectorObserver, false> observer_list_; | 88 ObserverList<PermissionSelectorObserver, false> observer_list_; |
| 69 | 89 |
| 70 DISALLOW_COPY_AND_ASSIGN(PermissionSelector); | 90 DISALLOW_COPY_AND_ASSIGN(PermissionSelector); |
| 71 }; | 91 }; |
| 72 | 92 |
| 73 #endif // CHROME_BROWSER_UI_GTK_WEBSITE_SETTINGS_PERMISSION_SELECTOR_H_ | 93 #endif // CHROME_BROWSER_UI_GTK_WEBSITE_SETTINGS_PERMISSION_SELECTOR_H_ |
| OLD | NEW |