Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef UI_BASE_THEME_PROVIDER_H_ |
| 6 | #define UI_BASE_THEME_PROVIDER_H_ |
| 7 | |
| 8 | #include "base/basictypes.h" |
| 9 | #include "third_party/skia/include/core/SkColor.h" |
| 10 | #include "ui/base/layout.h" |
| 11 | #include "ui/base/ui_export.h" |
| 12 | |
| 13 | #if defined(OS_MACOSX) |
| 14 | #ifdef __OBJC__ |
| 15 | @class NSColor; |
| 16 | @class NSGradient; |
| 17 | @class NSImage; |
| 18 | #else |
| 19 | class NSColor; |
| 20 | class NSGradient; |
| 21 | class NSImage; |
| 22 | #endif // __OBJC__ |
| 23 | #elif !defined(OS_WIN) |
| 24 | typedef struct _GdkColor GdkColor; |
| 25 | typedef struct _GdkPixbuf GdkPixbuf; |
| 26 | #endif // OS_* |
| 27 | |
| 28 | class SkBitmap; |
| 29 | |
| 30 | namespace base { |
| 31 | class RefCountedMemory; |
| 32 | } |
| 33 | |
| 34 | namespace gfx { |
| 35 | class ImageSkia; |
| 36 | } |
| 37 | |
| 38 | namespace ui { |
| 39 | |
| 40 | //////////////////////////////////////////////////////////////////////////////// |
| 41 | // |
| 42 | // ThemeProvider |
| 43 | // |
| 44 | // ThemeProvider is an abstract class that defines the API that should be |
| 45 | // implemented to provide bitmaps and color information for a given theme. |
| 46 | // |
| 47 | //////////////////////////////////////////////////////////////////////////////// |
| 48 | |
| 49 | class UI_EXPORT ThemeProvider { |
| 50 | public: |
| 51 | virtual ~ThemeProvider(); |
| 52 | |
| 53 | // Get the image specified by |id|. An implementation of ThemeProvider should |
| 54 | // have its own source of ids (e.g. an enum, or external resource bundle). |
| 55 | virtual gfx::ImageSkia* GetImageSkiaNamed(int id) const = 0; |
| 56 | |
| 57 | // Get the color specified by |id|. |
| 58 | virtual SkColor GetColor(int id) const = 0; |
| 59 | |
| 60 | // Get the property (e.g. an alignment expressed in an enum, or a width or |
| 61 | // height) specified by |id|. |
| 62 | virtual bool GetDisplayProperty(int id, int* result) const = 0; |
| 63 | |
| 64 | // Whether we should use the native system frame (typically Aero glass) or |
| 65 | // a custom frame. |
| 66 | virtual bool ShouldUseNativeFrame() const = 0; |
| 67 | |
| 68 | // Whether or not we have a certain image. Used for when the default theme |
| 69 | // doesn't provide a certain image, but custom themes might (badges, etc). |
| 70 | virtual bool HasCustomImage(int id) const = 0; |
| 71 | |
| 72 | // Reads the image data from the theme file into the specified vector. Only |
| 73 | // valid for un-themed resources and the themed IDR_THEME_NTP_* in most |
| 74 | // implementations of ThemeProvider. Returns NULL on error. |
| 75 | virtual base::RefCountedMemory* GetRawData( |
| 76 | int id, |
| 77 | ui::ScaleFactor scale_factor) const = 0; |
| 78 | |
| 79 | #if defined(OS_MACOSX) && !defined(TOOLKIT_VIEWS) |
| 80 | // Gets the NSImage with the specified |id|. |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 81 | virtual NSImage* GetNSImageNamed(int id) const = 0; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 82 | |
| 83 | // Gets the NSImage that GetNSImageNamed (above) would return, but returns it |
| 84 | // as a pattern color. |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 85 | virtual NSColor* GetNSImageColorNamed(int id) const = 0; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 86 | |
| 87 | // Gets the NSColor with the specified |id|. |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 88 | virtual NSColor* GetNSColor(int id) const = 0; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 89 | |
| 90 | // Gets the NSColor for tinting with the specified |id|. |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 91 | virtual NSColor* GetNSColorTint(int id) const = 0; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 92 | |
| 93 | // Gets the NSGradient with the specified |id|. |
| 94 | virtual NSGradient* GetNSGradient(int id) const = 0; |
| 95 | #elif defined(OS_POSIX) && !defined(TOOLKIT_VIEWS) && !defined(OS_ANDROID) |
| 96 | // Gets the GdkPixbuf with the specified |id|. Returns a pointer to a shared |
| 97 | // instance of the GdkPixbuf. This shared GdkPixbuf is owned by the theme |
| 98 | // provider and should not be freed. |
| 99 | // |
| 100 | // The bitmap is assumed to exist. This function will log in release, and |
| 101 | // assert in debug mode if it does not. On failure, this will return a |
| 102 | // pointer to a shared empty placeholder bitmap so it will be visible what |
| 103 | // is missing. |
| 104 | |
| 105 | // As above, but flips it in RTL locales. |
| 106 | virtual GdkPixbuf* GetRTLEnabledPixbufNamed(int id) const = 0; |
| 107 | #endif |
| 108 | }; |
| 109 | |
| 110 | } // namespace ui |
| 111 | |
| 112 | #endif // UI_BASE_THEME_PROVIDER_H_ |