diff options
author | erg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-07 21:31:39 +0000 |
---|---|---|
committer | erg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-07 21:31:39 +0000 |
commit | 395f9295b3e370746846dbe6073a0d43ab7e4af5 (patch) | |
tree | 2b505a988e91b4700268aaba2cdb9601c9122998 | |
parent | 91ed49a3f98ff91be98d786f44da18d4bf182a32 (diff) | |
download | chromium_src-395f9295b3e370746846dbe6073a0d43ab7e4af5.zip chromium_src-395f9295b3e370746846dbe6073a0d43ab7e4af5.tar.gz chromium_src-395f9295b3e370746846dbe6073a0d43ab7e4af5.tar.bz2 |
GTK Themes: Theme the popup notification.
TEST=Open popuptest.com in one tab and anything else in another. Switch between
GTK theme and normal. Theme of blocked popup container should change, even when
not the active tab.
http://crbug.com/13967
Review URL: http://codereview.chromium.org/149277
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@20085 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/blocked_popup_container.cc | 11 | ||||
-rw-r--r-- | chrome/browser/blocked_popup_container.h | 8 | ||||
-rw-r--r-- | chrome/browser/blocked_popup_container_unittest.cc | 2 | ||||
-rw-r--r-- | chrome/browser/gtk/blocked_popup_container_view_gtk.cc | 56 | ||||
-rw-r--r-- | chrome/browser/gtk/blocked_popup_container_view_gtk.h | 11 | ||||
-rw-r--r-- | chrome/browser/tab_contents/tab_contents_view_gtk.cc | 20 | ||||
-rw-r--r-- | chrome/browser/tab_contents/tab_contents_view_gtk.h | 4 |
7 files changed, 85 insertions, 27 deletions
diff --git a/chrome/browser/blocked_popup_container.cc b/chrome/browser/blocked_popup_container.cc index 65d2e09..13bd6a7 100644 --- a/chrome/browser/blocked_popup_container.cc +++ b/chrome/browser/blocked_popup_container.cc @@ -14,7 +14,7 @@ BlockedPopupContainer* BlockedPopupContainer::Create( TabContents* owner, Profile* profile) { BlockedPopupContainer* container = - new BlockedPopupContainer(owner, profile->GetPrefs()); + new BlockedPopupContainer(owner, profile); BlockedPopupContainerView* view = BlockedPopupContainerView::Create(container); container->set_view(view); @@ -25,7 +25,7 @@ BlockedPopupContainer* BlockedPopupContainer::Create( BlockedPopupContainer* BlockedPopupContainer::Create( TabContents* owner, Profile* profile, BlockedPopupContainerView* view) { BlockedPopupContainer* container = - new BlockedPopupContainer(owner, profile->GetPrefs()); + new BlockedPopupContainer(owner, profile); container->set_view(view); return container; } @@ -346,11 +346,12 @@ void BlockedPopupContainer::EraseDataForPopupAndUpdateUI( // private: BlockedPopupContainer::BlockedPopupContainer(TabContents* owner, - PrefService* prefs) + Profile* profile) : owner_(owner), - prefs_(prefs), + prefs_(profile->GetPrefs()), has_been_dismissed_(false), - view_(NULL) { + view_(NULL), + profile_(profile) { // Copy whitelist pref into local member that's easier to use. const ListValue* whitelist_pref = prefs_->GetList(prefs::kPopupWhitelistedHosts); diff --git a/chrome/browser/blocked_popup_container.h b/chrome/browser/blocked_popup_container.h index c632438..ebffd23 100644 --- a/chrome/browser/blocked_popup_container.h +++ b/chrome/browser/blocked_popup_container.h @@ -81,6 +81,9 @@ class BlockedPopupContainer : public TabContentsDelegate, static void RegisterUserPrefs(PrefService* prefs); + // Returns the profile associated with the Browser this container exists in. + Profile* profile() const { return profile_; } + // Sets this BlockedPopupContainer's view. BlockedPopupContainer now owns // |view| and is responsible for calling Destroy() on it. void set_view(BlockedPopupContainerView* view) { view_ = view; } @@ -229,7 +232,7 @@ class BlockedPopupContainer : public TabContentsDelegate, typedef std::set<std::string> Whitelist; // Creates a container for a certain TabContents: - BlockedPopupContainer(TabContents* owner, PrefService* prefs); + BlockedPopupContainer(TabContents* owner, Profile* profile); // Either hides the view if there are no popups, or updates the label if // there are. @@ -267,6 +270,9 @@ class BlockedPopupContainer : public TabContentsDelegate, // Our platform specific view. BlockedPopupContainerView* view_; + // The profile for the browser associated with the container. + Profile* profile_; + DISALLOW_IMPLICIT_CONSTRUCTORS(BlockedPopupContainer); }; diff --git a/chrome/browser/blocked_popup_container_unittest.cc b/chrome/browser/blocked_popup_container_unittest.cc index b23cab7..4828074d 100644 --- a/chrome/browser/blocked_popup_container_unittest.cc +++ b/chrome/browser/blocked_popup_container_unittest.cc @@ -53,7 +53,7 @@ class BlockedPopupContainerTest : public RenderViewHostTestHarness { protected: virtual void SetUp() { RenderViewHostTestHarness::SetUp(); - container_ = new BlockedPopupContainer(contents(), profile()->GetPrefs()); + container_ = new BlockedPopupContainer(contents(), profile()); container_->set_view(&mock); contents_->set_blocked_popup_container(container_); diff --git a/chrome/browser/gtk/blocked_popup_container_view_gtk.cc b/chrome/browser/gtk/blocked_popup_container_view_gtk.cc index cc62286..785da3f 100644 --- a/chrome/browser/gtk/blocked_popup_container_view_gtk.cc +++ b/chrome/browser/gtk/blocked_popup_container_view_gtk.cc @@ -9,6 +9,7 @@ #include "base/string_util.h" #include "chrome/browser/gtk/custom_button.h" #include "chrome/browser/gtk/gtk_chrome_button.h" +#include "chrome/browser/gtk/gtk_theme_provider.h" #include "chrome/browser/profile.h" #include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/browser/tab_contents/tab_contents_view_gtk.h" @@ -60,6 +61,14 @@ void BlockedPopupContainerViewGtk::GetURLAndTitleForPopup( *title = tab_contents->GetTitle(); } +void BlockedPopupContainerViewGtk::UserChangedTheme( + GtkThemeProperties* properties) { + use_gtk_rendering_ = properties->use_gtk_rendering; + + gtk_chrome_button_set_use_gtk_rendering( + GTK_CHROME_BUTTON(menu_button_), use_gtk_rendering_); +} + // Overridden from BlockedPopupContainerView: void BlockedPopupContainerViewGtk::SetPosition() { // No-op. Not required with the GTK version. @@ -122,8 +131,12 @@ void BlockedPopupContainerViewGtk::ExecuteCommand(int id) { BlockedPopupContainerViewGtk::BlockedPopupContainerViewGtk( BlockedPopupContainer* container) : model_(container), + use_gtk_rendering_(false), close_button_(CustomDrawButton::CloseButton()) { Init(); + + GtkThemeProperties properties(container->profile()); + UserChangedTheme(&properties); } void BlockedPopupContainerViewGtk::Init() { @@ -185,13 +198,10 @@ void BlockedPopupContainerViewGtk::OnCloseButtonClicked( } gboolean BlockedPopupContainerViewGtk::OnContainerExpose( - GtkWidget* widget, GdkEventExpose* event) { - // TODO(erg): When evanm comes through the code, adding gtk theme support, - // what's here needs to go in a if block and the else should just paint the - // normal theme background with a border around the outsides. + GtkWidget* widget, GdkEventExpose* event, + BlockedPopupContainerViewGtk* container) { int width = widget->allocation.width; int height = widget->allocation.height; - int half_width = width / 2; // Clip to our damage rect cairo_t* cr = gdk_cairo_create(GDK_DRAWABLE(widget->window)); @@ -199,19 +209,29 @@ gboolean BlockedPopupContainerViewGtk::OnContainerExpose( event->area.width, event->area.height); cairo_clip(cr); - // Draws our background gradient. - cairo_pattern_t* pattern = cairo_pattern_create_linear( - half_width, 0, half_width, height); - cairo_pattern_add_color_stop_rgb( - pattern, 0.0, - kBackgroundColorTop[0], kBackgroundColorTop[1], kBackgroundColorTop[2]); - cairo_pattern_add_color_stop_rgb( - pattern, 1.0, - kBackgroundColorBottom[0], kBackgroundColorBottom[1], - kBackgroundColorBottom[2]); - cairo_set_source(cr, pattern); - cairo_paint(cr); - cairo_pattern_destroy(pattern); + if (!container->use_gtk_rendering_) { + // TODO(erg): We draw the gradient background only when GTK themes are + // off. This isn't a perfect solution as this isn't themed! The views + // version doesn't appear to be themed either, so at least for now, + // constants are OK. + int half_width = width / 2; + cairo_pattern_t* pattern = cairo_pattern_create_linear( + half_width, 0, half_width, height); + cairo_pattern_add_color_stop_rgb( + pattern, 0.0, + kBackgroundColorTop[0], kBackgroundColorTop[1], kBackgroundColorTop[2]); + cairo_pattern_add_color_stop_rgb( + pattern, 1.0, + kBackgroundColorBottom[0], kBackgroundColorBottom[1], + kBackgroundColorBottom[2]); + cairo_set_source(cr, pattern); + cairo_paint(cr); + cairo_pattern_destroy(pattern); + } + + // TODO(erg): We need to figure out the border situation, too. We aren't + // provided a color from the theme system and the Windows implementation + // still uses constants for color. See the status bubble, too. // Sets up our stroke pen. cairo_set_source_rgb(cr, kBorderColor[0], kBorderColor[1], kBorderColor[2]); diff --git a/chrome/browser/gtk/blocked_popup_container_view_gtk.h b/chrome/browser/gtk/blocked_popup_container_view_gtk.h index c5fdc1a..dab57f4 100644 --- a/chrome/browser/gtk/blocked_popup_container_view_gtk.h +++ b/chrome/browser/gtk/blocked_popup_container_view_gtk.h @@ -15,6 +15,7 @@ class BlockedPopupContainerInternalView; class CustomDrawButton; +class GtkThemeProperties; class MenuGtk; class PrefService; class Profile; @@ -41,6 +42,10 @@ class BlockedPopupContainerViewGtk : public BlockedPopupContainerView, string16* url, string16* title) const; + // Notification that the theme has changed at that we should detect new + // values. + void UserChangedTheme(GtkThemeProperties* properties); + GtkWidget* widget() { return container_.get(); } // Overridden from BlockedPopupContainerView: @@ -72,7 +77,8 @@ class BlockedPopupContainerViewGtk : public BlockedPopupContainerView, BlockedPopupContainerViewGtk* container); // Draws |container_| with a custom background. - static gboolean OnContainerExpose(GtkWidget* widget, GdkEventExpose* event); + static gboolean OnContainerExpose(GtkWidget* widget, GdkEventExpose* event, + BlockedPopupContainerViewGtk* container); // Our model; calling the shots. BlockedPopupContainer* model_; @@ -83,6 +89,9 @@ class BlockedPopupContainerViewGtk : public BlockedPopupContainerView, // The "Blocked Popups: XXX" button. GtkWidget* menu_button_; + // Whether we should let GTK paint the background and the button decorations. + bool use_gtk_rendering_; + // Closes the container. scoped_ptr<CustomDrawButton> close_button_; diff --git a/chrome/browser/tab_contents/tab_contents_view_gtk.cc b/chrome/browser/tab_contents/tab_contents_view_gtk.cc index 4a64bab..5fe6e38 100644 --- a/chrome/browser/tab_contents/tab_contents_view_gtk.cc +++ b/chrome/browser/tab_contents/tab_contents_view_gtk.cc @@ -19,6 +19,7 @@ #include "chrome/browser/gtk/constrained_window_gtk.h" #include "chrome/browser/gtk/gtk_dnd_util.h" #include "chrome/browser/gtk/gtk_floating_container.h" +#include "chrome/browser/gtk/gtk_theme_provider.h" #include "chrome/browser/gtk/sad_tab_gtk.h" #include "chrome/browser/renderer_host/render_view_host.h" #include "chrome/browser/renderer_host/render_view_host_factory.h" @@ -28,6 +29,7 @@ #include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/browser/tab_contents/tab_contents_delegate.h" #include "chrome/common/gtk_util.h" +#include "chrome/common/notification_service.h" #include "chrome/common/notification_source.h" #include "chrome/common/notification_type.h" #include "webkit/glue/webdropdata.h" @@ -120,7 +122,7 @@ class WebDragDest { g_signal_connect(widget, "drag-drop", G_CALLBACK(OnDragDropThunk), this); g_signal_connect(widget, "drag-data-received", - G_CALLBACK(OnDragDataReceivedThunk),this); + G_CALLBACK(OnDragDataReceivedThunk), this); destroy_handler_ = g_signal_connect(widget, "destroy", G_CALLBACK(gtk_widget_destroyed), &widget_); @@ -320,6 +322,8 @@ TabContentsViewGtk::TabContentsViewGtk(TabContents* tab_contents) gtk_widget_show(floating_.get()); registrar_.Add(this, NotificationType::TAB_CONTENTS_CONNECTED, Source<TabContents>(tab_contents)); + registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED, + NotificationService::AllSources()); } TabContentsViewGtk::~TabContentsViewGtk() { @@ -541,6 +545,11 @@ void TabContentsViewGtk::Observe(NotificationType type, sad_tab_.reset(); break; } + case NotificationType::BROWSER_THEME_CHANGED: { + GtkThemeProperties properties(tab_contents()->profile()); + UserChangedTheme(&properties); + break; + } default: NOTREACHED() << "Got a notification we didn't register for."; break; @@ -658,6 +667,15 @@ void TabContentsViewGtk::OnDragEnd(GtkWidget* widget, // ----------------------------------------------------------------------------- +void TabContentsViewGtk::UserChangedTheme(GtkThemeProperties* properties) { + if (popup_view_) + popup_view_->UserChangedTheme(properties); + + // TODO(erg): Plumb the selected text color, etc from here all the way to + // RenderThemeChromiumLinux.cpp in WebKit through our associated + // RenderViewHost. +} + void TabContentsViewGtk::InsertIntoContentArea(GtkWidget* widget) { gtk_fixed_put(GTK_FIXED(fixed_), widget, 0, 0); } diff --git a/chrome/browser/tab_contents/tab_contents_view_gtk.h b/chrome/browser/tab_contents/tab_contents_view_gtk.h index 897d2b7..aa440d9 100644 --- a/chrome/browser/tab_contents/tab_contents_view_gtk.h +++ b/chrome/browser/tab_contents/tab_contents_view_gtk.h @@ -18,6 +18,7 @@ class BlockedPopupContainerViewGtk; class ConstrainedWindowGtk; +class GtkThemeProperties; class RenderViewContextMenuGtk; class SadTabGtk; class WebDragDest; @@ -85,6 +86,9 @@ class TabContentsViewGtk : public TabContentsView, // Tell webkit the drag is over. void DragEnded(); + // Called when the theme is changed. + void UserChangedTheme(GtkThemeProperties* properties); + // We keep track of the timestamp of the latest mousedown event. static gboolean OnMouseDown(GtkWidget* widget, GdkEventButton* event, TabContentsViewGtk* view); |