summaryrefslogtreecommitdiffstats
path: root/chrome/browser/gtk/gtk_theme_provider.h
blob: 408ba0c5052aff30773faef967e007fb987a0119 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_GTK_GTK_THEME_PROVIDER_H_
#define CHROME_BROWSER_GTK_GTK_THEME_PROVIDER_H_

#include "chrome/browser/browser_theme_provider.h"

#include "skia/ext/skia_utils.h"

class Profile;

typedef struct _GtkStyle GtkStyle;
typedef struct _GtkWidget GtkWidget;

// Specialization of BrowserThemeProvider which supplies system colors.
class GtkThemeProvider : public BrowserThemeProvider {
 public:
  GtkThemeProvider();
  virtual ~GtkThemeProvider();

  // Overridden from BrowserThemeProvider:
  //
  // Sets that we aren't using the system theme, then calls
  // BrowserThemeProvider's implementation.
  virtual void SetTheme(Extension* extension);
  virtual void UseDefaultTheme();
  virtual void SetNativeTheme();

  // Whether we should use the GTK system theme.
  static bool UseSystemThemeGraphics(Profile* profile);

 private:
  // Load theme data from preferences, possibly picking colors from GTK.
  virtual void LoadThemePrefs();

  // Possibly creates a theme specific version of theme_toolbar_default.
  // (minimally acceptable version right now, which is just a fill of the bg
  // color; this should instead invoke gtk_draw_box(...) for complex theme
  // engines.)
  virtual SkBitmap* LoadThemeBitmap(int id);

  // Handles signal from GTK that our theme has been changed.
  static void OnStyleSet(GtkWidget* widget,
                         GtkStyle* previous_style,
                         GtkThemeProvider* provider);

  void LoadGtkValues();

  // Sets the underlying theme colors/tints from a GTK color.
  void SetThemeColorFromGtk(const char* id, GdkColor* color);
  void SetThemeTintFromGtk(const char* id, GdkColor* color,
                           const skia::HSL& default_tint);

  // A GtkWidget that exists only so we can look at its properties (and take
  // its colors).
  GtkWidget* fake_window_;
};

// A Helper struct used throughout the GTK themeing code. It retrieves settings
// from the Profile once at creation time, instead of at every access time. A
// large motivation for making this struct is so that we only have to pass one
// parameter around when configuring things due to a theme event. This way, we
// can use a lot of GTK convenience features likt gtk_container_foreach().
struct GtkThemeProperties {
  GtkThemeProperties(Profile* profile);

  // A wrapper around ThemeProvider::GetColor, transforming the result to a
  // GdkColor.
  GdkColor GetGdkColor(int id);

  bool use_gtk_rendering;
  ThemeProvider* provider;
};

#endif  // CHROME_BROWSER_GTK_GTK_THEME_PROVIDER_H_