Commit 395f9295 authored by erg@google.com's avatar erg@google.com

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
parent 91ed49a3
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
BlockedPopupContainer* BlockedPopupContainer::Create( BlockedPopupContainer* BlockedPopupContainer::Create(
TabContents* owner, Profile* profile) { TabContents* owner, Profile* profile) {
BlockedPopupContainer* container = BlockedPopupContainer* container =
new BlockedPopupContainer(owner, profile->GetPrefs()); new BlockedPopupContainer(owner, profile);
BlockedPopupContainerView* view = BlockedPopupContainerView* view =
BlockedPopupContainerView::Create(container); BlockedPopupContainerView::Create(container);
container->set_view(view); container->set_view(view);
...@@ -25,7 +25,7 @@ BlockedPopupContainer* BlockedPopupContainer::Create( ...@@ -25,7 +25,7 @@ BlockedPopupContainer* BlockedPopupContainer::Create(
BlockedPopupContainer* BlockedPopupContainer::Create( BlockedPopupContainer* BlockedPopupContainer::Create(
TabContents* owner, Profile* profile, BlockedPopupContainerView* view) { TabContents* owner, Profile* profile, BlockedPopupContainerView* view) {
BlockedPopupContainer* container = BlockedPopupContainer* container =
new BlockedPopupContainer(owner, profile->GetPrefs()); new BlockedPopupContainer(owner, profile);
container->set_view(view); container->set_view(view);
return container; return container;
} }
...@@ -346,11 +346,12 @@ void BlockedPopupContainer::EraseDataForPopupAndUpdateUI( ...@@ -346,11 +346,12 @@ void BlockedPopupContainer::EraseDataForPopupAndUpdateUI(
// private: // private:
BlockedPopupContainer::BlockedPopupContainer(TabContents* owner, BlockedPopupContainer::BlockedPopupContainer(TabContents* owner,
PrefService* prefs) Profile* profile)
: owner_(owner), : owner_(owner),
prefs_(prefs), prefs_(profile->GetPrefs()),
has_been_dismissed_(false), has_been_dismissed_(false),
view_(NULL) { view_(NULL),
profile_(profile) {
// Copy whitelist pref into local member that's easier to use. // Copy whitelist pref into local member that's easier to use.
const ListValue* whitelist_pref = const ListValue* whitelist_pref =
prefs_->GetList(prefs::kPopupWhitelistedHosts); prefs_->GetList(prefs::kPopupWhitelistedHosts);
......
...@@ -81,6 +81,9 @@ class BlockedPopupContainer : public TabContentsDelegate, ...@@ -81,6 +81,9 @@ class BlockedPopupContainer : public TabContentsDelegate,
static void RegisterUserPrefs(PrefService* prefs); 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 // Sets this BlockedPopupContainer's view. BlockedPopupContainer now owns
// |view| and is responsible for calling Destroy() on it. // |view| and is responsible for calling Destroy() on it.
void set_view(BlockedPopupContainerView* view) { view_ = view; } void set_view(BlockedPopupContainerView* view) { view_ = view; }
...@@ -229,7 +232,7 @@ class BlockedPopupContainer : public TabContentsDelegate, ...@@ -229,7 +232,7 @@ class BlockedPopupContainer : public TabContentsDelegate,
typedef std::set<std::string> Whitelist; typedef std::set<std::string> Whitelist;
// Creates a container for a certain TabContents: // 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 // Either hides the view if there are no popups, or updates the label if
// there are. // there are.
...@@ -267,6 +270,9 @@ class BlockedPopupContainer : public TabContentsDelegate, ...@@ -267,6 +270,9 @@ class BlockedPopupContainer : public TabContentsDelegate,
// Our platform specific view. // Our platform specific view.
BlockedPopupContainerView* view_; BlockedPopupContainerView* view_;
// The profile for the browser associated with the container.
Profile* profile_;
DISALLOW_IMPLICIT_CONSTRUCTORS(BlockedPopupContainer); DISALLOW_IMPLICIT_CONSTRUCTORS(BlockedPopupContainer);
}; };
......
...@@ -53,7 +53,7 @@ class BlockedPopupContainerTest : public RenderViewHostTestHarness { ...@@ -53,7 +53,7 @@ class BlockedPopupContainerTest : public RenderViewHostTestHarness {
protected: protected:
virtual void SetUp() { virtual void SetUp() {
RenderViewHostTestHarness::SetUp(); RenderViewHostTestHarness::SetUp();
container_ = new BlockedPopupContainer(contents(), profile()->GetPrefs()); container_ = new BlockedPopupContainer(contents(), profile());
container_->set_view(&mock); container_->set_view(&mock);
contents_->set_blocked_popup_container(container_); contents_->set_blocked_popup_container(container_);
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "base/string_util.h" #include "base/string_util.h"
#include "chrome/browser/gtk/custom_button.h" #include "chrome/browser/gtk/custom_button.h"
#include "chrome/browser/gtk/gtk_chrome_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/profile.h"
#include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/browser/tab_contents/tab_contents.h"
#include "chrome/browser/tab_contents/tab_contents_view_gtk.h" #include "chrome/browser/tab_contents/tab_contents_view_gtk.h"
...@@ -60,6 +61,14 @@ void BlockedPopupContainerViewGtk::GetURLAndTitleForPopup( ...@@ -60,6 +61,14 @@ void BlockedPopupContainerViewGtk::GetURLAndTitleForPopup(
*title = tab_contents->GetTitle(); *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: // Overridden from BlockedPopupContainerView:
void BlockedPopupContainerViewGtk::SetPosition() { void BlockedPopupContainerViewGtk::SetPosition() {
// No-op. Not required with the GTK version. // No-op. Not required with the GTK version.
...@@ -122,8 +131,12 @@ void BlockedPopupContainerViewGtk::ExecuteCommand(int id) { ...@@ -122,8 +131,12 @@ void BlockedPopupContainerViewGtk::ExecuteCommand(int id) {
BlockedPopupContainerViewGtk::BlockedPopupContainerViewGtk( BlockedPopupContainerViewGtk::BlockedPopupContainerViewGtk(
BlockedPopupContainer* container) BlockedPopupContainer* container)
: model_(container), : model_(container),
use_gtk_rendering_(false),
close_button_(CustomDrawButton::CloseButton()) { close_button_(CustomDrawButton::CloseButton()) {
Init(); Init();
GtkThemeProperties properties(container->profile());
UserChangedTheme(&properties);
} }
void BlockedPopupContainerViewGtk::Init() { void BlockedPopupContainerViewGtk::Init() {
...@@ -185,13 +198,10 @@ void BlockedPopupContainerViewGtk::OnCloseButtonClicked( ...@@ -185,13 +198,10 @@ void BlockedPopupContainerViewGtk::OnCloseButtonClicked(
} }
gboolean BlockedPopupContainerViewGtk::OnContainerExpose( gboolean BlockedPopupContainerViewGtk::OnContainerExpose(
GtkWidget* widget, GdkEventExpose* event) { GtkWidget* widget, GdkEventExpose* event,
// TODO(erg): When evanm comes through the code, adding gtk theme support, BlockedPopupContainerViewGtk* container) {
// 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.
int width = widget->allocation.width; int width = widget->allocation.width;
int height = widget->allocation.height; int height = widget->allocation.height;
int half_width = width / 2;
// Clip to our damage rect // Clip to our damage rect
cairo_t* cr = gdk_cairo_create(GDK_DRAWABLE(widget->window)); cairo_t* cr = gdk_cairo_create(GDK_DRAWABLE(widget->window));
...@@ -199,19 +209,29 @@ gboolean BlockedPopupContainerViewGtk::OnContainerExpose( ...@@ -199,19 +209,29 @@ gboolean BlockedPopupContainerViewGtk::OnContainerExpose(
event->area.width, event->area.height); event->area.width, event->area.height);
cairo_clip(cr); cairo_clip(cr);
// Draws our background gradient. if (!container->use_gtk_rendering_) {
cairo_pattern_t* pattern = cairo_pattern_create_linear( // TODO(erg): We draw the gradient background only when GTK themes are
half_width, 0, half_width, height); // off. This isn't a perfect solution as this isn't themed! The views
cairo_pattern_add_color_stop_rgb( // version doesn't appear to be themed either, so at least for now,
pattern, 0.0, // constants are OK.
kBackgroundColorTop[0], kBackgroundColorTop[1], kBackgroundColorTop[2]); int half_width = width / 2;
cairo_pattern_add_color_stop_rgb( cairo_pattern_t* pattern = cairo_pattern_create_linear(
pattern, 1.0, half_width, 0, half_width, height);
kBackgroundColorBottom[0], kBackgroundColorBottom[1], cairo_pattern_add_color_stop_rgb(
kBackgroundColorBottom[2]); pattern, 0.0,
cairo_set_source(cr, pattern); kBackgroundColorTop[0], kBackgroundColorTop[1], kBackgroundColorTop[2]);
cairo_paint(cr); cairo_pattern_add_color_stop_rgb(
cairo_pattern_destroy(pattern); 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. // Sets up our stroke pen.
cairo_set_source_rgb(cr, kBorderColor[0], kBorderColor[1], kBorderColor[2]); cairo_set_source_rgb(cr, kBorderColor[0], kBorderColor[1], kBorderColor[2]);
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
class BlockedPopupContainerInternalView; class BlockedPopupContainerInternalView;
class CustomDrawButton; class CustomDrawButton;
class GtkThemeProperties;
class MenuGtk; class MenuGtk;
class PrefService; class PrefService;
class Profile; class Profile;
...@@ -41,6 +42,10 @@ class BlockedPopupContainerViewGtk : public BlockedPopupContainerView, ...@@ -41,6 +42,10 @@ class BlockedPopupContainerViewGtk : public BlockedPopupContainerView,
string16* url, string16* url,
string16* title) const; 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(); } GtkWidget* widget() { return container_.get(); }
// Overridden from BlockedPopupContainerView: // Overridden from BlockedPopupContainerView:
...@@ -72,7 +77,8 @@ class BlockedPopupContainerViewGtk : public BlockedPopupContainerView, ...@@ -72,7 +77,8 @@ class BlockedPopupContainerViewGtk : public BlockedPopupContainerView,
BlockedPopupContainerViewGtk* container); BlockedPopupContainerViewGtk* container);
// Draws |container_| with a custom background. // 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. // Our model; calling the shots.
BlockedPopupContainer* model_; BlockedPopupContainer* model_;
...@@ -83,6 +89,9 @@ class BlockedPopupContainerViewGtk : public BlockedPopupContainerView, ...@@ -83,6 +89,9 @@ class BlockedPopupContainerViewGtk : public BlockedPopupContainerView,
// The "Blocked Popups: XXX" button. // The "Blocked Popups: XXX" button.
GtkWidget* menu_button_; GtkWidget* menu_button_;
// Whether we should let GTK paint the background and the button decorations.
bool use_gtk_rendering_;
// Closes the container. // Closes the container.
scoped_ptr<CustomDrawButton> close_button_; scoped_ptr<CustomDrawButton> close_button_;
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include "chrome/browser/gtk/constrained_window_gtk.h" #include "chrome/browser/gtk/constrained_window_gtk.h"
#include "chrome/browser/gtk/gtk_dnd_util.h" #include "chrome/browser/gtk/gtk_dnd_util.h"
#include "chrome/browser/gtk/gtk_floating_container.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/gtk/sad_tab_gtk.h"
#include "chrome/browser/renderer_host/render_view_host.h" #include "chrome/browser/renderer_host/render_view_host.h"
#include "chrome/browser/renderer_host/render_view_host_factory.h" #include "chrome/browser/renderer_host/render_view_host_factory.h"
...@@ -28,6 +29,7 @@ ...@@ -28,6 +29,7 @@
#include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/browser/tab_contents/tab_contents.h"
#include "chrome/browser/tab_contents/tab_contents_delegate.h" #include "chrome/browser/tab_contents/tab_contents_delegate.h"
#include "chrome/common/gtk_util.h" #include "chrome/common/gtk_util.h"
#include "chrome/common/notification_service.h"
#include "chrome/common/notification_source.h" #include "chrome/common/notification_source.h"
#include "chrome/common/notification_type.h" #include "chrome/common/notification_type.h"
#include "webkit/glue/webdropdata.h" #include "webkit/glue/webdropdata.h"
...@@ -120,7 +122,7 @@ class WebDragDest { ...@@ -120,7 +122,7 @@ class WebDragDest {
g_signal_connect(widget, "drag-drop", g_signal_connect(widget, "drag-drop",
G_CALLBACK(OnDragDropThunk), this); G_CALLBACK(OnDragDropThunk), this);
g_signal_connect(widget, "drag-data-received", g_signal_connect(widget, "drag-data-received",
G_CALLBACK(OnDragDataReceivedThunk),this); G_CALLBACK(OnDragDataReceivedThunk), this);
destroy_handler_ = g_signal_connect(widget, "destroy", destroy_handler_ = g_signal_connect(widget, "destroy",
G_CALLBACK(gtk_widget_destroyed), &widget_); G_CALLBACK(gtk_widget_destroyed), &widget_);
...@@ -320,6 +322,8 @@ TabContentsViewGtk::TabContentsViewGtk(TabContents* tab_contents) ...@@ -320,6 +322,8 @@ TabContentsViewGtk::TabContentsViewGtk(TabContents* tab_contents)
gtk_widget_show(floating_.get()); gtk_widget_show(floating_.get());
registrar_.Add(this, NotificationType::TAB_CONTENTS_CONNECTED, registrar_.Add(this, NotificationType::TAB_CONTENTS_CONNECTED,
Source<TabContents>(tab_contents)); Source<TabContents>(tab_contents));
registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED,
NotificationService::AllSources());
} }
TabContentsViewGtk::~TabContentsViewGtk() { TabContentsViewGtk::~TabContentsViewGtk() {
...@@ -541,6 +545,11 @@ void TabContentsViewGtk::Observe(NotificationType type, ...@@ -541,6 +545,11 @@ void TabContentsViewGtk::Observe(NotificationType type,
sad_tab_.reset(); sad_tab_.reset();
break; break;
} }
case NotificationType::BROWSER_THEME_CHANGED: {
GtkThemeProperties properties(tab_contents()->profile());
UserChangedTheme(&properties);
break;
}
default: default:
NOTREACHED() << "Got a notification we didn't register for."; NOTREACHED() << "Got a notification we didn't register for.";
break; break;
...@@ -658,6 +667,15 @@ void TabContentsViewGtk::OnDragEnd(GtkWidget* widget, ...@@ -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) { void TabContentsViewGtk::InsertIntoContentArea(GtkWidget* widget) {
gtk_fixed_put(GTK_FIXED(fixed_), widget, 0, 0); gtk_fixed_put(GTK_FIXED(fixed_), widget, 0, 0);
} }
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
class BlockedPopupContainerViewGtk; class BlockedPopupContainerViewGtk;
class ConstrainedWindowGtk; class ConstrainedWindowGtk;
class GtkThemeProperties;
class RenderViewContextMenuGtk; class RenderViewContextMenuGtk;
class SadTabGtk; class SadTabGtk;
class WebDragDest; class WebDragDest;
...@@ -85,6 +86,9 @@ class TabContentsViewGtk : public TabContentsView, ...@@ -85,6 +86,9 @@ class TabContentsViewGtk : public TabContentsView,
// Tell webkit the drag is over. // Tell webkit the drag is over.
void DragEnded(); void DragEnded();
// Called when the theme is changed.
void UserChangedTheme(GtkThemeProperties* properties);
// We keep track of the timestamp of the latest mousedown event. // We keep track of the timestamp of the latest mousedown event.
static gboolean OnMouseDown(GtkWidget* widget, static gboolean OnMouseDown(GtkWidget* widget,
GdkEventButton* event, TabContentsViewGtk* view); GdkEventButton* event, TabContentsViewGtk* view);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment