diff options
author | erg@chromium.org <erg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-10 22:23:02 +0000 |
---|---|---|
committer | erg@chromium.org <erg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-10 22:23:02 +0000 |
commit | dd14da8f2d18c8f9b6a6c0a9b2bb4e03da92c90c (patch) | |
tree | 418b5e52f4908e3087e87a7c26dd227f4a52f0be /chrome | |
parent | 21116a3982fa6a87189cdd0333315e8f74b36acc (diff) | |
download | chromium_src-dd14da8f2d18c8f9b6a6c0a9b2bb4e03da92c90c.zip chromium_src-dd14da8f2d18c8f9b6a6c0a9b2bb4e03da92c90c.tar.gz chromium_src-dd14da8f2d18c8f9b6a6c0a9b2bb4e03da92c90c.tar.bz2 |
GTK: Always use default frame in popup windows.
Now that glen@ has spoken, make popup windows on linux match the XP behaviour
by never using themed resources for the window frame.
BUG=43938
TEST=none
Review URL: http://codereview.chromium.org/2771011
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@49458 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/gtk/browser_titlebar.cc | 56 | ||||
-rw-r--r-- | chrome/browser/gtk/browser_window_gtk.cc | 42 | ||||
-rw-r--r-- | chrome/browser/gtk/browser_window_gtk.h | 4 | ||||
-rw-r--r-- | chrome/browser/gtk/gtk_theme_provider.cc | 32 | ||||
-rw-r--r-- | chrome/browser/gtk/gtk_theme_provider.h | 12 |
5 files changed, 88 insertions, 58 deletions
diff --git a/chrome/browser/gtk/browser_titlebar.cc b/chrome/browser/gtk/browser_titlebar.cc index a7abbf5..68a4481 100644 --- a/chrome/browser/gtk/browser_titlebar.cc +++ b/chrome/browser/gtk/browser_titlebar.cc @@ -544,38 +544,36 @@ void BrowserTitlebar::UpdateTitlebarAlignment() { } void BrowserTitlebar::UpdateTextColor() { - if (app_mode_title_ && theme_provider_) { - if (theme_provider_->UseGtkTheme()) { - // We don't really have any good options here. - // - // Colors from window manager themes aren't exposed in GTK; the window - // manager is a separate component and when there is information sharing - // (in the case of metacity), it's one way where the window manager reads - // data from the GTK theme (which allows us to do a decent job with - // picking the frame color). - // - // We probably won't match in the majority of cases, but we can at the - // very least make things legible. The default metacity and xfwm themes - // on ubuntu have white text hardcoded. Determine whether black or white - // has more luminosity contrast and then set that color as the text - // color. - GdkColor frame_color; - if (window_has_focus_) { - frame_color = theme_provider_->GetGdkColor( + if (!app_mode_title_) + return; + + if (theme_provider_ && theme_provider_->UseGtkTheme()) { + // We don't really have any good options here. + // + // Colors from window manager themes aren't exposed in GTK; the window + // manager is a separate component and when there is information sharing + // (in the case of metacity), it's one way where the window manager reads + // data from the GTK theme (which allows us to do a decent job with + // picking the frame color). + // + // We probably won't match in the majority of cases, but we can at the + // very least make things legible. The default metacity and xfwm themes + // on ubuntu have white text hardcoded. Determine whether black or white + // has more luminosity contrast and then set that color as the text + // color. + GdkColor frame_color; + if (window_has_focus_) { + frame_color = theme_provider_->GetGdkColor( BrowserThemeProvider::COLOR_FRAME); - } else { - frame_color = theme_provider_->GetGdkColor( - BrowserThemeProvider::COLOR_FRAME_INACTIVE); - } - GdkColor text_color = PickLuminosityContrastingColor( - &frame_color, &gfx::kGdkWhite, &gfx::kGdkBlack); - gtk_util::SetLabelColor(app_mode_title_, &text_color); } else { - GdkColor text_color = theme_provider_->GetGdkColor(window_has_focus_ ? - BrowserThemeProvider::COLOR_TAB_TEXT : - BrowserThemeProvider::COLOR_BACKGROUND_TAB_TEXT); - gtk_util::SetLabelColor(app_mode_title_, &text_color); + frame_color = theme_provider_->GetGdkColor( + BrowserThemeProvider::COLOR_FRAME_INACTIVE); } + GdkColor text_color = PickLuminosityContrastingColor( + &frame_color, &gfx::kGdkWhite, &gfx::kGdkBlack); + gtk_util::SetLabelColor(app_mode_title_, &text_color); + } else { + gtk_util::SetLabelColor(app_mode_title_, &gfx::kGdkWhite); } } diff --git a/chrome/browser/gtk/browser_window_gtk.cc b/chrome/browser/gtk/browser_window_gtk.cc index db11ef6..5d2b7f0 100644 --- a/chrome/browser/gtk/browser_window_gtk.cc +++ b/chrome/browser/gtk/browser_window_gtk.cc @@ -556,18 +556,12 @@ void BrowserWindowGtk::DrawPopupFrame(cairo_t* cr, GtkThemeProvider* theme_provider = GtkThemeProvider::GetFrom( browser()->profile()); - // In popups, we use the tab images for the background, as that's legible - // for text to be written on. - int image_name; - if (IsActive()) { - image_name = IDR_THEME_TOOLBAR; - } else { - bool off_the_record = browser()->profile()->IsOffTheRecord(); - image_name = off_the_record ? IDR_THEME_TAB_BACKGROUND_INCOGNITO : - IDR_THEME_TAB_BACKGROUND; - } - - CairoCachedSurface* surface = theme_provider->GetSurfaceNamed( + // Like DrawCustomFrame(), except that we use the unthemed resources to draw + // the background. We do this because we can't rely on sane images in the + // theme that we can draw text on. (We tried using the tab background, but + // that has inverse saturation from what the user usually expects). + int image_name = GetThemeFrameResource(); + CairoCachedSurface* surface = theme_provider->GetUnthemedSurfaceNamed( image_name, widget); if (event->area.y < surface->Height()) { surface->SetSource(cr, @@ -586,14 +580,7 @@ void BrowserWindowGtk::DrawCustomFrame(cairo_t* cr, GtkThemeProvider* theme_provider = GtkThemeProvider::GetFrom( browser()->profile()); - bool off_the_record = browser()->profile()->IsOffTheRecord(); - int image_name; - if (IsActive()) { - image_name = off_the_record ? IDR_THEME_FRAME_INCOGNITO : IDR_THEME_FRAME; - } else { - image_name = off_the_record ? IDR_THEME_FRAME_INCOGNITO_INACTIVE : - IDR_THEME_FRAME_INACTIVE; - } + int image_name = GetThemeFrameResource(); CairoCachedSurface* surface = theme_provider->GetSurfaceNamed( image_name, widget); @@ -609,7 +596,7 @@ void BrowserWindowGtk::DrawCustomFrame(cairo_t* cr, } if (theme_provider->HasCustomImage(IDR_THEME_FRAME_OVERLAY) && - !off_the_record) { + !browser()->profile()->IsOffTheRecord()) { CairoCachedSurface* theme_overlay = theme_provider->GetSurfaceNamed( IsActive() ? IDR_THEME_FRAME_OVERLAY : IDR_THEME_FRAME_OVERLAY_INACTIVE, widget); @@ -618,6 +605,19 @@ void BrowserWindowGtk::DrawCustomFrame(cairo_t* cr, } } +int BrowserWindowGtk::GetThemeFrameResource() { + bool off_the_record = browser()->profile()->IsOffTheRecord(); + int image_name; + if (IsActive()) { + image_name = off_the_record ? IDR_THEME_FRAME_INCOGNITO : IDR_THEME_FRAME; + } else { + image_name = off_the_record ? IDR_THEME_FRAME_INCOGNITO_INACTIVE : + IDR_THEME_FRAME_INACTIVE; + } + + return image_name; +} + void BrowserWindowGtk::Show() { // The Browser associated with this browser window must become the active // browser at the time Show() is called. This is the natural behaviour under diff --git a/chrome/browser/gtk/browser_window_gtk.h b/chrome/browser/gtk/browser_window_gtk.h index 4ba7d33..2a66f5f 100644 --- a/chrome/browser/gtk/browser_window_gtk.h +++ b/chrome/browser/gtk/browser_window_gtk.h @@ -279,6 +279,10 @@ class BrowserWindowGtk : public BrowserWindow, // Draws the normal custom frame using theme_frame. void DrawCustomFrame(cairo_t* cr, GtkWidget* widget, GdkEventExpose* event); + // Returns which frame image we should use based on the window's current + // activation state / incognito state. + int GetThemeFrameResource(); + // Callback for accelerator activation. |user_data| stores the command id // of the matched accelerator. static gboolean OnGtkAccelerator(GtkAccelGroup* accel_group, diff --git a/chrome/browser/gtk/gtk_theme_provider.cc b/chrome/browser/gtk/gtk_theme_provider.cc index da81bed..1aefdab 100644 --- a/chrome/browser/gtk/gtk_theme_provider.cc +++ b/chrome/browser/gtk/gtk_theme_provider.cc @@ -446,6 +446,26 @@ CairoCachedSurface* GtkThemeProvider::GetSurfaceNamed( return surface; } +CairoCachedSurface* GtkThemeProvider::GetUnthemedSurfaceNamed( + int id, GtkWidget* widget_on_display) { + GdkDisplay* display = gtk_widget_get_display(widget_on_display); + CairoCachedSurfaceMap& surface_map = per_display_unthemed_surfaces_[display]; + + // Check to see if we already have the pixbuf in the cache. + CairoCachedSurfaceMap::const_iterator found = surface_map.find(id); + if (found != surface_map.end()) + return found->second; + + ResourceBundle& rb = ResourceBundle::GetSharedInstance(); + GdkPixbuf* pixbuf = rb.GetPixbufNamed(id); + CairoCachedSurface* surface = new CairoCachedSurface; + surface->UsePixbuf(pixbuf); + + surface_map[id] = surface; + + return surface; +} + // static GdkPixbuf* GtkThemeProvider::GetFolderIcon(bool native) { if (native) { @@ -530,7 +550,8 @@ void GtkThemeProvider::NotifyThemeChanged(Extension* extension) { void GtkThemeProvider::FreePlatformCaches() { BrowserThemeProvider::FreePlatformCaches(); - FreePerDisplaySurfaces(); + FreePerDisplaySurfaces(&per_display_surfaces_); + FreePerDisplaySurfaces(&per_display_unthemed_surfaces_); STLDeleteValues(>k_images_); } @@ -769,15 +790,16 @@ void GtkThemeProvider::SetTintToExactColor(int id, const GdkColor* color) { tints_[id] = hsl; } -void GtkThemeProvider::FreePerDisplaySurfaces() { - for (PerDisplaySurfaceMap::iterator it = per_display_surfaces_.begin(); - it != per_display_surfaces_.end(); ++it) { +void GtkThemeProvider::FreePerDisplaySurfaces( + PerDisplaySurfaceMap* per_display_map) { + for (PerDisplaySurfaceMap::iterator it = per_display_map->begin(); + it != per_display_map->end(); ++it) { for (CairoCachedSurfaceMap::iterator jt = it->second.begin(); jt != it->second.end(); ++jt) { delete jt->second; } } - per_display_surfaces_.clear(); + per_display_map->clear(); } SkBitmap* GtkThemeProvider::GenerateGtkThemeBitmap(int id) const { diff --git a/chrome/browser/gtk/gtk_theme_provider.h b/chrome/browser/gtk/gtk_theme_provider.h index aca0cd9..e6321e9 100644 --- a/chrome/browser/gtk/gtk_theme_provider.h +++ b/chrome/browser/gtk/gtk_theme_provider.h @@ -84,6 +84,11 @@ class GtkThemeProvider : public BrowserThemeProvider, // to send the image to the server on each expose. CairoCachedSurface* GetSurfaceNamed(int id, GtkWidget* widget_on_display); + // Returns a CairoCachedSurface for a particular Display for an image + // resource that's unthemed. + CairoCachedSurface* GetUnthemedSurfaceNamed( + int id, GtkWidget* widget_on_display); + // Returns colors that we pass to webkit to match the system theme. const SkColor& get_focus_ring_color() const { return focus_ring_color_; } const SkColor& get_thumb_active_color() const { return thumb_active_color_; } @@ -117,6 +122,8 @@ class GtkThemeProvider : public BrowserThemeProvider, typedef std::map<int, SkColor> ColorMap; typedef std::map<int, color_utils::HSL> TintMap; typedef std::map<int, SkBitmap*> ImageCache; + typedef std::map<int, CairoCachedSurface*> CairoCachedSurfaceMap; + typedef std::map<GdkDisplay*, CairoCachedSurfaceMap> PerDisplaySurfaceMap; // Clears all the GTK color overrides. virtual void ClearAllThemeData(); @@ -147,7 +154,7 @@ class GtkThemeProvider : public BrowserThemeProvider, // FreePlatformCaches() is called from the BrowserThemeProvider's destructor, // but by the time ~BrowserThemeProvider() is run, the vtable no longer // points to GtkThemeProvider's version. - void FreePerDisplaySurfaces(); + void FreePerDisplaySurfaces(PerDisplaySurfaceMap* per_display_map); // Lazily generates each bitmap used in the gtk theme. SkBitmap* GenerateGtkThemeBitmap(int id) const; @@ -226,9 +233,8 @@ class GtkThemeProvider : public BrowserThemeProvider, mutable ImageCache gtk_images_; // Cairo surfaces for each GdkDisplay. - typedef std::map<int, CairoCachedSurface*> CairoCachedSurfaceMap; - typedef std::map<GdkDisplay*, CairoCachedSurfaceMap> PerDisplaySurfaceMap; PerDisplaySurfaceMap per_display_surfaces_; + PerDisplaySurfaceMap per_display_unthemed_surfaces_; // This is a dummy widget that only exists so we have something to pass to // gtk_widget_render_icon(). |