diff options
author | erg@chromium.org <erg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-11 21:58:13 +0000 |
---|---|---|
committer | erg@chromium.org <erg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-11 21:58:13 +0000 |
commit | f321a984b66500ea0063549612992cf784da12b6 (patch) | |
tree | 4bf959d1aeb5a871f0dcedf7e801d54e530c46e8 | |
parent | 0fb2bd939380e4d46bad10eb597bff4980ca7db2 (diff) | |
download | chromium_src-f321a984b66500ea0063549612992cf784da12b6.zip chromium_src-f321a984b66500ea0063549612992cf784da12b6.tar.gz chromium_src-f321a984b66500ea0063549612992cf784da12b6.tar.bz2 |
GTK Themes: Use a consistent border color along all webcontent.
The color used in the status bubble is now used in the top margin
and in the download bar. This doesn't convert the popup notification,
as that needs additional changes...
Review URL: http://codereview.chromium.org/164345
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@23089 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/gtk/download_shelf_gtk.cc | 14 | ||||
-rw-r--r-- | chrome/browser/gtk/download_shelf_gtk.h | 3 | ||||
-rw-r--r-- | chrome/browser/gtk/find_bar_gtk.cc | 19 | ||||
-rw-r--r-- | chrome/browser/gtk/find_bar_gtk.h | 12 | ||||
-rw-r--r-- | chrome/browser/gtk/gtk_theme_provider.cc | 24 | ||||
-rw-r--r-- | chrome/browser/gtk/gtk_theme_provider.h | 4 | ||||
-rw-r--r-- | chrome/browser/gtk/status_bubble_gtk.cc | 18 |
7 files changed, 71 insertions, 23 deletions
diff --git a/chrome/browser/gtk/download_shelf_gtk.cc b/chrome/browser/gtk/download_shelf_gtk.cc index 9601fd06..e628cf2 100644 --- a/chrome/browser/gtk/download_shelf_gtk.cc +++ b/chrome/browser/gtk/download_shelf_gtk.cc @@ -61,9 +61,8 @@ DownloadShelfGtk::DownloadShelfGtk(Browser* browser, GtkWidget* parent) // event box so we can color the background. // Create the top border. - GtkWidget* top_border = gtk_event_box_new(); - gtk_widget_set_size_request(GTK_WIDGET(top_border), 0, 1); - gtk_widget_modify_bg(top_border, GTK_STATE_NORMAL, &kBorderColor); + top_border_ = gtk_event_box_new(); + gtk_widget_set_size_request(GTK_WIDGET(top_border_), 0, 1); // Create |hbox_|. hbox_.Own(gtk_hbox_new(FALSE, kDownloadItemPadding)); @@ -79,7 +78,7 @@ DownloadShelfGtk::DownloadShelfGtk(Browser* browser, GtkWidget* parent) gtk_container_add(GTK_CONTAINER(padding), hbox_.get()); GtkWidget* vbox = gtk_vbox_new(FALSE, 0); - gtk_box_pack_start(GTK_BOX(vbox), top_border, FALSE, FALSE, 0); + gtk_box_pack_start(GTK_BOX(vbox), top_border_, FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(vbox), padding_bg_, FALSE, FALSE, 0); // Put the shelf in an event box so it gets its own window, which makes it @@ -179,6 +178,13 @@ void DownloadShelfGtk::Observe(NotificationType type, GdkColor color = theme_provider_->GetGdkColor( BrowserThemeProvider::COLOR_TOOLBAR); gtk_widget_modify_bg(padding_bg_, GTK_STATE_NORMAL, &color); + + if (theme_provider_->UseGtkTheme()) { + GdkColor color = theme_provider_->GetBorderColor(); + gtk_widget_modify_bg(top_border_, GTK_STATE_NORMAL, &color); + } else { + gtk_widget_modify_bg(top_border_, GTK_STATE_NORMAL, &kBorderColor); + } } } diff --git a/chrome/browser/gtk/download_shelf_gtk.h b/chrome/browser/gtk/download_shelf_gtk.h index 80d7b85..e5bb01b 100644 --- a/chrome/browser/gtk/download_shelf_gtk.h +++ b/chrome/browser/gtk/download_shelf_gtk.h @@ -71,6 +71,9 @@ class DownloadShelfGtk : public DownloadShelf, // for an explanation of the widget layout. OwnedWidgetGtk shelf_; + // Top level event box which draws the one pixel border. + GtkWidget* top_border_; + // A GtkEventBox which we color. GtkWidget* padding_bg_; diff --git a/chrome/browser/gtk/find_bar_gtk.cc b/chrome/browser/gtk/find_bar_gtk.cc index 8bfbc85..cfc37fe 100644 --- a/chrome/browser/gtk/find_bar_gtk.cc +++ b/chrome/browser/gtk/find_bar_gtk.cc @@ -21,6 +21,7 @@ #include "chrome/browser/gtk/tabs/tab_strip_gtk.h" #include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/common/gtk_util.h" +#include "chrome/common/notification_service.h" #include "grit/generated_resources.h" #include "webkit/api/public/gtk/WebInputEventFactory.h" @@ -150,7 +151,6 @@ void FindBarGtk::InitWidgets() { fixed_.Own(gtk_fixed_new()); border_ = gtk_event_box_new(); gtk_widget_set_size_request(border_, 1, 1); - gtk_widget_modify_bg(border_, GTK_STATE_NORMAL, &kFrameBorderColor); gtk_fixed_put(GTK_FIXED(widget()), border_, 0, 0); gtk_fixed_put(GTK_FIXED(widget()), slide_widget(), 0, 0); @@ -235,6 +235,10 @@ void FindBarGtk::InitWidgets() { 1, 1, 1, 0); gtk_util::CenterWidgetInHBox(hbox, border_bin_aa, true, 0); + theme_provider_->InitThemesFor(this); + registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED, + NotificationService::AllSources()); + // We take care to avoid showing the slide animator widget. gtk_widget_show_all(container_); gtk_widget_show(widget()); @@ -390,6 +394,19 @@ FindBarTesting* FindBarGtk::GetFindBarTesting() { return this; } +void FindBarGtk::Observe(NotificationType type, + const NotificationSource& source, + const NotificationDetails& details) { + DCHECK_EQ(type.value, NotificationType::BROWSER_THEME_CHANGED); + + if (theme_provider_->UseGtkTheme()) { + GdkColor color = theme_provider_->GetBorderColor(); + gtk_widget_modify_bg(border_, GTK_STATE_NORMAL, &color); + } else { + gtk_widget_modify_bg(border_, GTK_STATE_NORMAL, &kFrameBorderColor); + } +} + bool FindBarGtk::GetFindBarWindowInfo(gfx::Point* position, bool* fully_visible) { NOTIMPLEMENTED(); diff --git a/chrome/browser/gtk/find_bar_gtk.h b/chrome/browser/gtk/find_bar_gtk.h index 020b814..cd46e39 100644 --- a/chrome/browser/gtk/find_bar_gtk.h +++ b/chrome/browser/gtk/find_bar_gtk.h @@ -11,6 +11,8 @@ #include "base/scoped_ptr.h" #include "chrome/browser/find_bar.h" #include "chrome/browser/gtk/focus_store_gtk.h" +#include "chrome/common/notification_observer.h" +#include "chrome/common/notification_registrar.h" #include "chrome/common/owned_widget_gtk.h" class Browser; @@ -25,7 +27,8 @@ class TabContentsContainerGtk; // Currently this class contains both a model and a view. We may want to // eventually pull out the model specific bits and share with Windows. class FindBarGtk : public FindBar, - public FindBarTesting { + public FindBarTesting, + public NotificationObserver { public: explicit FindBarGtk(Browser* browser); virtual ~FindBarGtk(); @@ -60,6 +63,11 @@ class FindBarGtk : public FindBar, virtual bool GetFindBarWindowInfo(gfx::Point* position, bool* fully_visible); + // Overridden from NotificationObserver: + virtual void Observe(NotificationType type, + const NotificationSource& source, + const NotificationDetails& details); + private: void InitWidgets(); @@ -170,6 +178,8 @@ class FindBarGtk : public FindBar, scoped_ptr<NineBox> dialog_background_; + NotificationRegistrar registrar_; + DISALLOW_COPY_AND_ASSIGN(FindBarGtk); }; diff --git a/chrome/browser/gtk/gtk_theme_provider.cc b/chrome/browser/gtk/gtk_theme_provider.cc index 4a4075f..0643143 100644 --- a/chrome/browser/gtk/gtk_theme_provider.cc +++ b/chrome/browser/gtk/gtk_theme_provider.cc @@ -34,6 +34,10 @@ const skia::HSL kDefaultFrameShift = { -1, -1, 0.4 }; // different color. const double kMinimumLuminanceDifference = 0.1; +// Number of times that the background color should be counted when trying to +// calculate the border color in GTK theme mode. +const int kBgWeight = 3; + // Converts a GdkColor to a SkColor. SkColor GdkToSkColor(GdkColor* color) { return SkColorSetRGB(color->red >> 8, @@ -135,6 +139,26 @@ GdkColor GtkThemeProvider::GetGdkColor(int id) { return gdkcolor; } +GdkColor GtkThemeProvider::GetBorderColor() { + GtkStyle* style = gtk_rc_get_style(fake_window_); + + // Creates a weighted average between the text and base color where + // the base color counts more than once. + GdkColor color; + color.pixel = 0; + color.red = (style->text[GTK_STATE_NORMAL].red + + (style->bg[GTK_STATE_NORMAL].red * kBgWeight)) / + (1 + kBgWeight); + color.green = (style->text[GTK_STATE_NORMAL].green + + (style->bg[GTK_STATE_NORMAL].green * kBgWeight)) / + (1 + kBgWeight); + color.blue = (style->text[GTK_STATE_NORMAL].blue + + (style->bg[GTK_STATE_NORMAL].blue * kBgWeight)) / + (1 + kBgWeight); + + return color; +} + void GtkThemeProvider::LoadThemePrefs() { if (use_gtk_) { LoadGtkValues(); diff --git a/chrome/browser/gtk/gtk_theme_provider.h b/chrome/browser/gtk/gtk_theme_provider.h index a182414..dbffe57 100644 --- a/chrome/browser/gtk/gtk_theme_provider.h +++ b/chrome/browser/gtk/gtk_theme_provider.h @@ -58,6 +58,10 @@ class GtkThemeProvider : public BrowserThemeProvider, // GdkColor. GdkColor GetGdkColor(int id); + // A weighted average between the text color and the background color of a + // label. Used for borders between GTK stuff and the webcontent. + GdkColor GetBorderColor(); + private: // Load theme data from preferences, possibly picking colors from GTK. virtual void LoadThemePrefs(); diff --git a/chrome/browser/gtk/status_bubble_gtk.cc b/chrome/browser/gtk/status_bubble_gtk.cc index 962b0f2..a951e52 100644 --- a/chrome/browser/gtk/status_bubble_gtk.cc +++ b/chrome/browser/gtk/status_bubble_gtk.cc @@ -31,10 +31,6 @@ const int kCornerSize = 4; // Milliseconds before we hide the status bubble widget when you mouseout. const int kHideDelay = 250; -// Number of times that the background color should be counted when trying to -// calculate the border color in GTK theme mode. -const int kBgWeight = 3; - // Reverses a point in RTL mode. GdkPoint MakeBidiGdkPoint(gint x, gint y, gint width, bool ltr) { GdkPoint point = {ltr ? x : width - x, y}; @@ -211,19 +207,7 @@ void StatusBubbleGtk::UserChangedTheme() { gtk_widget_modify_fg(label_, GTK_STATE_NORMAL, NULL); gtk_widget_modify_bg(container_.get(), GTK_STATE_NORMAL, NULL); - // Creates a weighted average between the text and base color where - // the base color counts more than once. - GtkStyle* style = gtk_rc_get_style(container_.get()); - border_color_.pixel = 0; - border_color_.red = (style->text[GTK_STATE_NORMAL].red + - (style->bg[GTK_STATE_NORMAL].red * kBgWeight)) / - (1 + kBgWeight); - border_color_.green = (style->text[GTK_STATE_NORMAL].green + - (style->bg[GTK_STATE_NORMAL].green * kBgWeight)) / - (1 + kBgWeight); - border_color_.blue = (style->text[GTK_STATE_NORMAL].blue + - (style->bg[GTK_STATE_NORMAL].blue * kBgWeight)) / - (1 + kBgWeight); + border_color_ = theme_provider_->GetBorderColor(); } else { // TODO(erg): This is the closest to "text that will look good on a // toolbar" that I can find. Maybe in later iterations of the theme system, |