| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_GTK_GTK_THEME_PROVIDER_H_ | 5 #ifndef CHROME_BROWSER_GTK_GTK_THEME_PROVIDER_H_ |
| 6 #define CHROME_BROWSER_GTK_GTK_THEME_PROVIDER_H_ | 6 #define CHROME_BROWSER_GTK_GTK_THEME_PROVIDER_H_ |
| 7 | 7 |
| 8 #include <map> | |
| 9 #include <string> | 8 #include <string> |
| 10 #include <vector> | 9 #include <vector> |
| 11 | 10 |
| 12 #include "chrome/browser/browser_theme_provider.h" | 11 #include "chrome/browser/browser_theme_provider.h" |
| 13 #include "chrome/common/notification_observer.h" | 12 #include "chrome/common/notification_observer.h" |
| 14 #include "chrome/common/owned_widget_gtk.h" | 13 #include "chrome/common/owned_widget_gtk.h" |
| 15 | 14 |
| 16 #include "skia/ext/skia_utils.h" | 15 #include "skia/ext/skia_utils.h" |
| 17 | 16 |
| 18 class CairoCachedSurface; | |
| 19 class Profile; | 17 class Profile; |
| 20 | 18 |
| 21 typedef struct _GdkDisplay GdkDisplay; | |
| 22 typedef struct _GtkStyle GtkStyle; | 19 typedef struct _GtkStyle GtkStyle; |
| 23 typedef struct _GtkWidget GtkWidget; | 20 typedef struct _GtkWidget GtkWidget; |
| 24 | 21 |
| 25 // Specialization of BrowserThemeProvider which supplies system colors. | 22 // Specialization of BrowserThemeProvider which supplies system colors. |
| 26 class GtkThemeProvider : public BrowserThemeProvider, | 23 class GtkThemeProvider : public BrowserThemeProvider, |
| 27 public NotificationObserver { | 24 public NotificationObserver { |
| 28 public: | 25 public: |
| 29 // Returns GtkThemeProvider, casted from our superclass. | 26 // Returns GtkThemeProvider, casted from our superclass. |
| 30 static GtkThemeProvider* GetFrom(Profile* profile); | 27 static GtkThemeProvider* GetFrom(Profile* profile); |
| 31 | 28 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 GdkColor GetGdkColor(int id); | 60 GdkColor GetGdkColor(int id); |
| 64 | 61 |
| 65 // A weighted average between the text color and the background color of a | 62 // A weighted average between the text color and the background color of a |
| 66 // label. Used for borders between GTK stuff and the webcontent. | 63 // label. Used for borders between GTK stuff and the webcontent. |
| 67 GdkColor GetBorderColor(); | 64 GdkColor GetBorderColor(); |
| 68 | 65 |
| 69 // Expose the inner widgets. Only used for testing. | 66 // Expose the inner widgets. Only used for testing. |
| 70 GtkWidget* fake_window() { return fake_window_; } | 67 GtkWidget* fake_window() { return fake_window_; } |
| 71 GtkWidget* fake_label() { return fake_label_.get(); } | 68 GtkWidget* fake_label() { return fake_label_.get(); } |
| 72 | 69 |
| 73 // Returns a CairoCachedSurface for a particular Display. CairoCachedSurfaces | |
| 74 // (hopefully) live on the X server, instead of the client so we don't have | |
| 75 // to send the image to the server on each expose. | |
| 76 CairoCachedSurface* GetSurfaceNamed(int id, GtkWidget* widget_on_display); | |
| 77 | |
| 78 protected: | 70 protected: |
| 79 // Possibly creates a theme specific version of theme_toolbar_default. | 71 // Possibly creates a theme specific version of theme_toolbar_default. |
| 80 // (minimally acceptable version right now, which is just a fill of the bg | 72 // (minimally acceptable version right now, which is just a fill of the bg |
| 81 // color; this should instead invoke gtk_draw_box(...) for complex theme | 73 // color; this should instead invoke gtk_draw_box(...) for complex theme |
| 82 // engines.) | 74 // engines.) |
| 83 virtual SkBitmap* LoadThemeBitmap(int id); | 75 virtual SkBitmap* LoadThemeBitmap(int id); |
| 84 | 76 |
| 85 private: | 77 private: |
| 86 // Load theme data from preferences, possibly picking colors from GTK. | 78 // Load theme data from preferences, possibly picking colors from GTK. |
| 87 virtual void LoadThemePrefs(); | 79 virtual void LoadThemePrefs(); |
| 88 | 80 |
| 89 // Let all the browser views know that themes have changed. | 81 // Let all the browser views know that themes have changed. |
| 90 virtual void NotifyThemeChanged(); | 82 virtual void NotifyThemeChanged(); |
| 91 | 83 |
| 92 // If use_gtk_ is true, completely ignores this call. Otherwise passes it to | 84 // If use_gtk_ is true, completely ignores this call. Otherwise passes it to |
| 93 // the superclass. | 85 // the superclass. |
| 94 virtual void SaveThemeBitmap(const std::string resource_name, int id); | 86 virtual void SaveThemeBitmap(const std::string resource_name, int id); |
| 95 | 87 |
| 96 // Additionally frees the CairoCachedSurfaces. | |
| 97 virtual void FreePlatformCaches(); | |
| 98 | |
| 99 // Handles signal from GTK that our theme has been changed. | 88 // Handles signal from GTK that our theme has been changed. |
| 100 static void OnStyleSet(GtkWidget* widget, | 89 static void OnStyleSet(GtkWidget* widget, |
| 101 GtkStyle* previous_style, | 90 GtkStyle* previous_style, |
| 102 GtkThemeProvider* provider); | 91 GtkThemeProvider* provider); |
| 103 | 92 |
| 104 void LoadGtkValues(); | 93 void LoadGtkValues(); |
| 105 | 94 |
| 106 // Sets the underlying theme colors/tints from a GTK color. | 95 // Sets the underlying theme colors/tints from a GTK color. |
| 107 void SetThemeColorFromGtk(const char* id, GdkColor* color); | 96 void SetThemeColorFromGtk(const char* id, GdkColor* color); |
| 108 void SetThemeTintFromGtk(const char* id, GdkColor* color, | 97 void SetThemeTintFromGtk(const char* id, GdkColor* color, |
| 109 const skia::HSL& default_tint); | 98 const skia::HSL& default_tint); |
| 110 | 99 |
| 111 // A notification from the GtkChromeButton GObject destructor that we should | 100 // A notification from the GtkChromeButton GObject destructor that we should |
| 112 // remove it from our internal list. | 101 // remove it from our internal list. |
| 113 static void OnDestroyChromeButton(GtkWidget* button, | 102 static void OnDestroyChromeButton(GtkWidget* button, |
| 114 GtkThemeProvider* provider); | 103 GtkThemeProvider* provider); |
| 115 | 104 |
| 116 // Whether we should be using gtk rendering. | 105 // Whether we should be using gtk rendering. |
| 117 bool use_gtk_; | 106 bool use_gtk_; |
| 118 | 107 |
| 119 // GtkWidgets that exist only so we can look at their properties (and take | 108 // GtkWidgets that exist only so we can look at their properties (and take |
| 120 // their colors). | 109 // their colors). |
| 121 GtkWidget* fake_window_; | 110 GtkWidget* fake_window_; |
| 122 OwnedWidgetGtk fake_label_; | 111 OwnedWidgetGtk fake_label_; |
| 123 | 112 |
| 124 // A list of all GtkChromeButton instances. We hold on to these to notify | 113 // A list of all GtkChromeButton instances. We hold on to these to notify |
| 125 // them of theme changes. | 114 // them of theme changes. |
| 126 std::vector<GtkWidget*> chrome_buttons_; | 115 std::vector<GtkWidget*> chrome_buttons_; |
| 127 | |
| 128 // Cairo surfaces for each GdkDisplay. | |
| 129 typedef std::map<int, CairoCachedSurface*> CairoCachedSurfaceMap; | |
| 130 typedef std::map<GdkDisplay*, CairoCachedSurfaceMap> PerDisplaySurfaceMap; | |
| 131 PerDisplaySurfaceMap per_display_surfaces_; | |
| 132 }; | 116 }; |
| 133 | 117 |
| 134 #endif // CHROME_BROWSER_GTK_GTK_THEME_PROVIDER_H_ | 118 #endif // CHROME_BROWSER_GTK_GTK_THEME_PROVIDER_H_ |
| OLD | NEW |