1 // Copyright 2013 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 CHROME_BROWSER_THEMES_CUSTOM_THEME_SUPPLIER_H_ 6 #define CHROME_BROWSER_THEMES_CUSTOM_THEME_SUPPLIER_H_ 7 8 #include "base/memory/ref_counted.h" 9 #include "content/public/browser/browser_thread.h" 10 #include "third_party/skia/include/core/SkColor.h" 11 #include "ui/base/layout.h" 12 13 namespace base { 14 class RefCountedMemory; 15 } 16 17 namespace color_utils { 18 struct HSL; 19 } 20 21 namespace gfx { 22 class Image; 23 } 24 25 // A representation of a theme. All theme properties can be accessed through the 26 // public methods. Subclasses are expected to override all methods which should 27 // provide non-default values. 28 class CustomThemeSupplier : public base::RefCountedThreadSafe< 29 CustomThemeSupplier, content::BrowserThread::DeleteOnFileThread> { 30 public: 31 enum ThemeType { 32 EXTENSION, 33 NATIVE_X11, 34 MANAGED_USER_THEME, 35 }; 36 37 explicit CustomThemeSupplier(ThemeType type); 38 39 ThemeType get_theme_type() const { 40 return theme_type_; 41 } 42 43 // Called when the theme starts being used. 44 virtual void StartUsingTheme(); 45 46 // Called when the theme is not used anymore. 47 virtual void StopUsingTheme(); 48 49 // If the theme specifies data for the corresponding |id|, returns true and 50 // writes the corresponding value to the output parameter. These methods 51 // should not return the default data. These methods should only be called 52 // from the UI thread. 53 virtual bool GetTint(int id, color_utils::HSL* hsl) const; 54 virtual bool GetColor(int id, SkColor* color) const; 55 virtual bool GetDisplayProperty(int id, int* result) const; 56 57 // Returns the theme image for |id|. Returns an empty image if no image is 58 // found for |id|. 59 virtual gfx::Image GetImageNamed(int id); 60 61 // Returns the raw PNG encoded data for IDR_THEME_NTP_*. This method only 62 // works for the NTP attribution and background resources. 63 virtual base::RefCountedMemory* GetRawData( 64 int id, ui::ScaleFactor scale_factor) const; 65 66 // Whether this theme provides an image for |id|. 67 virtual bool HasCustomImage(int id) const; 68 69 protected: 70 virtual ~CustomThemeSupplier(); 71 72 private: 73 friend struct content::BrowserThread::DeleteOnThread< 74 content::BrowserThread::FILE>; 75 friend class base::DeleteHelper<CustomThemeSupplier>; 76 77 ThemeType theme_type_; 78 79 DISALLOW_COPY_AND_ASSIGN(CustomThemeSupplier); 80 }; 81 82 #endif // CHROME_BROWSER_THEMES_CUSTOM_THEME_SUPPLIER_H_ 83