diff options
-rw-r--r-- | chrome/browser/browser_prefs.cc | 9 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_prefs.cc | 15 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_prefs.h | 2 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_toolbar_model.cc | 13 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_toolbar_model.h | 15 | ||||
-rw-r--r-- | chrome/browser/extensions/extensions_service_unittest.cc | 2 | ||||
-rw-r--r-- | chrome/browser/gtk/browser_actions_toolbar_gtk.cc | 35 | ||||
-rw-r--r-- | chrome/browser/gtk/browser_actions_toolbar_gtk.h | 6 | ||||
-rw-r--r-- | chrome/common/pref_names.cc | 4 | ||||
-rw-r--r-- | chrome/common/pref_names.h | 1 |
10 files changed, 71 insertions, 31 deletions
diff --git a/chrome/browser/browser_prefs.cc b/chrome/browser/browser_prefs.cc index 8d6b8ce..a973d43 100644 --- a/chrome/browser/browser_prefs.cc +++ b/chrome/browser/browser_prefs.cc @@ -13,6 +13,7 @@ #include "chrome/browser/dom_ui/new_tab_ui.h" #include "chrome/browser/download/download_manager.h" #include "chrome/browser/extensions/extension_dom_ui.h" +#include "chrome/browser/extensions/extension_prefs.h" #include "chrome/browser/extensions/extensions_ui.h" #include "chrome/browser/external_protocol_handler.h" #include "chrome/browser/geolocation/geolocation_prefs.h" @@ -70,7 +71,7 @@ void RegisterLocalState(PrefService* local_state) { chrome_browser_net::RegisterPrefs(local_state); bookmark_utils::RegisterPrefs(local_state); PageInfoModel::RegisterPrefs(local_state); -#if defined(TOOLKIT_VIEWS) // TODO(port): whittle this down as we port +#if defined(TOOLKIT_VIEWS) BrowserView::RegisterBrowserViewPrefs(local_state); #endif TaskManager::RegisterPrefs(local_state); @@ -98,10 +99,10 @@ void RegisterUserPrefs(PrefService* user_prefs) { HostZoomMap::RegisterUserPrefs(user_prefs); DevToolsManager::RegisterUserPrefs(user_prefs); Blacklist::RegisterUserPrefs(user_prefs); -#if defined(TOOLKIT_VIEWS) // TODO(port): whittle this down as we port. + ExtensionPrefs::RegisterUserPrefs(user_prefs); +#if defined(TOOLKIT_VIEWS) BrowserActionsContainer::RegisterUserPrefs(user_prefs); -#endif -#if defined(TOOLKIT_GTK) +#elif defined(TOOLKIT_GTK) BrowserWindowGtk::RegisterUserPrefs(user_prefs); #endif #if defined(OS_CHROMEOS) diff --git a/chrome/browser/extensions/extension_prefs.cc b/chrome/browser/extensions/extension_prefs.cc index d4879ac..c9f391f 100644 --- a/chrome/browser/extensions/extension_prefs.cc +++ b/chrome/browser/extensions/extension_prefs.cc @@ -5,6 +5,7 @@ #include "base/string_util.h" #include "chrome/browser/extensions/extension_prefs.h" #include "chrome/common/extensions/extension.h" +#include "chrome/common/pref_names.h" using base::Time; @@ -60,12 +61,6 @@ const wchar_t kPrefIncognitoEnabled[] = L"incognito"; ExtensionPrefs::ExtensionPrefs(PrefService* prefs, const FilePath& root_dir) : prefs_(prefs), install_directory_(root_dir) { - if (!prefs_->FindPreference(kExtensionsPref)) - prefs_->RegisterDictionaryPref(kExtensionsPref); - if (!prefs->FindPreference(kExtensionShelf)) - prefs->RegisterListPref(kExtensionShelf); - if (!prefs->FindPreference(kExtensionToolbar)) - prefs->RegisterListPref(kExtensionToolbar); MakePathsRelative(); } @@ -580,3 +575,11 @@ ExtensionPrefs::ExtensionsInfo* ExtensionPrefs::CollectExtensionsInfo( return extensions_info; } + +// static +void ExtensionPrefs::RegisterUserPrefs(PrefService* prefs) { + prefs->RegisterDictionaryPref(kExtensionsPref); + prefs->RegisterListPref(kExtensionShelf); + prefs->RegisterListPref(kExtensionToolbar); + prefs->RegisterIntegerPref(prefs::kExtensionToolbarSize, -1); +} diff --git a/chrome/browser/extensions/extension_prefs.h b/chrome/browser/extensions/extension_prefs.h index 1d16631..4b026c2 100644 --- a/chrome/browser/extensions/extension_prefs.h +++ b/chrome/browser/extensions/extension_prefs.h @@ -105,6 +105,8 @@ class ExtensionPrefs { // Caller takes ownership of returned structure. static ExtensionsInfo* CollectExtensionsInfo(ExtensionPrefs* extension_prefs); + static void RegisterUserPrefs(PrefService* prefs); + private: // Converts absolute paths in the pref to paths relative to the diff --git a/chrome/browser/extensions/extension_toolbar_model.cc b/chrome/browser/extensions/extension_toolbar_model.cc index ab16d5b..0d8472e 100644 --- a/chrome/browser/extensions/extension_toolbar_model.cc +++ b/chrome/browser/extensions/extension_toolbar_model.cc @@ -6,11 +6,15 @@ #include "chrome/browser/extensions/extension_prefs.h" #include "chrome/browser/extensions/extensions_service.h" +#include "chrome/browser/pref_service.h" +#include "chrome/browser/profile.h" #include "chrome/common/extensions/extension.h" #include "chrome/common/notification_service.h" +#include "chrome/common/pref_names.h" ExtensionToolbarModel::ExtensionToolbarModel(ExtensionsService* service) - : service_(service) { + : service_(service), + prefs_(service->profile()->GetPrefs()) { DCHECK(service_); registrar_.Add(this, NotificationType::EXTENSION_LOADED, @@ -21,6 +25,8 @@ ExtensionToolbarModel::ExtensionToolbarModel(ExtensionsService* service) Source<Profile>(service_->profile())); registrar_.Add(this, NotificationType::EXTENSIONS_READY, Source<Profile>(service_->profile())); + + visible_icon_count_ = prefs_->GetInteger(prefs::kExtensionToolbarSize); } ExtensionToolbarModel::~ExtensionToolbarModel() { @@ -65,6 +71,11 @@ void ExtensionToolbarModel::MoveBrowserAction(Extension* extension, UpdatePrefs(); } +void ExtensionToolbarModel::SetVisibleIconCount(int count) { + visible_icon_count_ = count == static_cast<int>(size()) ? -1 : count; + prefs_->SetInteger(prefs::kExtensionToolbarSize, visible_icon_count_); +} + void ExtensionToolbarModel::Observe(NotificationType type, const NotificationSource& source, const NotificationDetails& details) { diff --git a/chrome/browser/extensions/extension_toolbar_model.h b/chrome/browser/extensions/extension_toolbar_model.h index 2341493b5..44f7950 100644 --- a/chrome/browser/extensions/extension_toolbar_model.h +++ b/chrome/browser/extensions/extension_toolbar_model.h @@ -11,6 +11,7 @@ #include "chrome/common/notification_registrar.h" class ExtensionsService; +class PrefService; // Model for the browser actions toolbar. class ExtensionToolbarModel : public NotificationObserver { @@ -37,9 +38,11 @@ class ExtensionToolbarModel : public NotificationObserver { void AddObserver(Observer* observer); void RemoveObserver(Observer* observer); void MoveBrowserAction(Extension* extension, int index); - // TODO(estade): implement these. - void SetVisibleIconCount(int count) {} - int GetVisibleIconCount() { return -1; } + // If count == size(), this will set the visible icon count to -1, meaning + // "show all actions". + void SetVisibleIconCount(int count); + // As above, a return value of -1 represents "show all actions". + int GetVisibleIconCount() { return visible_icon_count_; } size_t size() const { return toolitems_.size(); @@ -83,6 +86,8 @@ class ExtensionToolbarModel : public NotificationObserver { // Our ExtensionsService, guaranteed to outlive us. ExtensionsService* service_; + PrefService* prefs_; + // Ordered list of browser action buttons. ExtensionList toolitems_; @@ -92,6 +97,10 @@ class ExtensionToolbarModel : public NotificationObserver { // Keeps track of where the last extension to get disabled was in the list. size_t last_extension_removed_index_; + // The number of icons visible (the rest should be hidden in the overflow + // chevron). + int visible_icon_count_; + NotificationRegistrar registrar_; }; diff --git a/chrome/browser/extensions/extensions_service_unittest.cc b/chrome/browser/extensions/extensions_service_unittest.cc index e5cf7b4..5de4f3e 100644 --- a/chrome/browser/extensions/extensions_service_unittest.cc +++ b/chrome/browser/extensions/extensions_service_unittest.cc @@ -236,6 +236,8 @@ void ExtensionsServiceTestBase::InitializeExtensionsService( const FilePath& pref_file, const FilePath& extensions_install_dir) { ExtensionTestingProfile* profile = new ExtensionTestingProfile(); prefs_.reset(new PrefService(pref_file)); + Profile::RegisterUserPrefs(prefs_.get()); + browser::RegisterUserPrefs(prefs_.get()); profile_.reset(profile); CommandLine::ForCurrentProcess()->AppendSwitch( diff --git a/chrome/browser/gtk/browser_actions_toolbar_gtk.cc b/chrome/browser/gtk/browser_actions_toolbar_gtk.cc index 7a9ecdf..60c509f 100644 --- a/chrome/browser/gtk/browser_actions_toolbar_gtk.cc +++ b/chrome/browser/gtk/browser_actions_toolbar_gtk.cc @@ -277,6 +277,8 @@ class BrowserActionButton : public NotificationObserver, friend class BrowserActionsToolbarGtk; }; +// BrowserActionsToolbarGtk ---------------------------------------------------- + BrowserActionsToolbarGtk::BrowserActionsToolbarGtk(Browser* browser) : browser_(browser), profile_(browser->profile()), @@ -330,8 +332,11 @@ BrowserActionsToolbarGtk::BrowserActionsToolbarGtk(Browser* browser) G_CALLBACK(OnHierarchyChangedThunk), this); int showing_actions = model_->GetVisibleIconCount(); - if (showing_actions >= 0) + if (showing_actions >= 0) { SetButtonHBoxWidth(WidthForIconCount(showing_actions)); + if (showing_actions < static_cast<int>(model_->size())) + gtk_widget_show(overflow_button_.widget()); + } ViewIDUtil::SetID(button_hbox_, VIEW_ID_BROWSER_ACTION_TOOLBAR); } @@ -453,21 +458,21 @@ void BrowserActionsToolbarGtk::AnimateToShowNIcons(int count) { resize_animation_.Show(); } -void BrowserActionsToolbarGtk::ButtonAddedOrRemoved() { - // TODO(estade): this is a little bit janky looking when the removed button - // is not the farthest right button. +void BrowserActionsToolbarGtk::BrowserActionAdded(Extension* extension, + int index) { + CreateButtonForExtension(extension, index); + + // If we are still initializing the container, don't bother animating. + if (model_->size() != extension_button_map_.size()) + return; + + // Animate the addition if we are showing all browser action buttons. if (!GTK_WIDGET_VISIBLE(overflow_button_.widget())) { AnimateToShowNIcons(button_count()); model_->SetVisibleIconCount(button_count()); } } -void BrowserActionsToolbarGtk::BrowserActionAdded(Extension* extension, - int index) { - CreateButtonForExtension(extension, index); - ButtonAddedOrRemoved(); -} - void BrowserActionsToolbarGtk::BrowserActionRemoved(Extension* extension) { if (drag_button_ != NULL) { // Break the current drag. @@ -475,7 +480,13 @@ void BrowserActionsToolbarGtk::BrowserActionRemoved(Extension* extension) { } RemoveButtonForExtension(extension); - ButtonAddedOrRemoved(); + + if (!GTK_WIDGET_VISIBLE(overflow_button_.widget())) { + AnimateToShowNIcons(button_count()); + model_->SetVisibleIconCount(button_count()); + } else if (button_count() <= model_->GetVisibleIconCount()) { + gtk_widget_hide(overflow_button_.widget()); + } } void BrowserActionsToolbarGtk::BrowserActionMoved(Extension* extension, @@ -556,7 +567,6 @@ void BrowserActionsToolbarGtk::SetButtonHBoxWidth(int new_width) { gtk_chrome_shrinkable_hbox_get_visible_child_count( GTK_CHROME_SHRINKABLE_HBOX(button_hbox_)); - model_->SetVisibleIconCount(showing_icon_count); if (model_->size() > static_cast<size_t>(showing_icon_count)) { if (!GTK_WIDGET_VISIBLE(overflow_button_.widget())) { // When the overflow chevron shows for the first time, take that @@ -698,6 +708,7 @@ gboolean BrowserActionsToolbarGtk::OnGripperButtonRelease( gtk_chrome_shrinkable_hbox_get_visible_child_count( GTK_CHROME_SHRINKABLE_HBOX(button_hbox_)); AnimateToShowNIcons(visible_icon_count); + model_->SetVisibleIconCount(visible_icon_count); return FALSE; } diff --git a/chrome/browser/gtk/browser_actions_toolbar_gtk.h b/chrome/browser/gtk/browser_actions_toolbar_gtk.h index e2d9739..11b3537 100644 --- a/chrome/browser/gtk/browser_actions_toolbar_gtk.h +++ b/chrome/browser/gtk/browser_actions_toolbar_gtk.h @@ -81,10 +81,6 @@ class BrowserActionsToolbarGtk : public ExtensionToolbarModel::Observer, // visibility of the overflow button will not change. void AnimateToShowNIcons(int count); - // If the toolbar is at max width and a button is added or removed, then make - // sure it stays at the max width. - void ButtonAddedOrRemoved(); - // Returns true if this extension should be shown in this toolbar. This can // return false if we are in an incognito window and the extension is disabled // for incognito. @@ -110,7 +106,7 @@ class BrowserActionsToolbarGtk : public ExtensionToolbarModel::Observer, void DragStarted(BrowserActionButton* button, GdkDragContext* drag_context); // Sets the width of the button area of the toolbar to |new_width|, clamping - // it to appropriate values and updating the model. + // it to appropriate values. void SetButtonHBoxWidth(int new_width); CHROMEGTK_CALLBACK_4(BrowserActionsToolbarGtk, gboolean, OnDragMotion, diff --git a/chrome/common/pref_names.cc b/chrome/common/pref_names.cc index 70de4c7..a926587 100644 --- a/chrome/common/pref_names.cc +++ b/chrome/common/pref_names.cc @@ -269,6 +269,10 @@ const wchar_t kCurrentThemeDisplayProperties[] = // (showing developer packing tools and extensions details) const wchar_t kExtensionsUIDeveloperMode[] = L"extensions.ui.developer_mode"; +// Integer pref that tracks the number of browser actions visible in the browser +// actions toolbar. +const wchar_t kExtensionToolbarSize[] = L"extensions.toolbarsize"; + // Boolean that indicates whether we should check if we are the default browser // on start-up. const wchar_t kCheckDefaultBrowser[] = L"browser.check_default_browser"; diff --git a/chrome/common/pref_names.h b/chrome/common/pref_names.h index f8b49e1..240e401 100644 --- a/chrome/common/pref_names.h +++ b/chrome/common/pref_names.h @@ -109,6 +109,7 @@ extern const wchar_t kCurrentThemeColors[]; extern const wchar_t kCurrentThemeTints[]; extern const wchar_t kCurrentThemeDisplayProperties[]; extern const wchar_t kExtensionsUIDeveloperMode[]; +extern const wchar_t kExtensionToolbarSize[]; extern const wchar_t kCheckDefaultBrowser[]; #if defined(OS_MACOSX) extern const wchar_t kShowUpdatePromotionInfoBar[]; |