Index: ui/views/background.cc |
diff --git a/ui/views/background.cc b/ui/views/background.cc |
index 190a5a62c346e714f9b7c4dad8a8d79321132a0d..e036490a0c24950c931077dd106f41cbbad5b055 100644 |
--- a/ui/views/background.cc |
+++ b/ui/views/background.cc |
@@ -6,11 +6,14 @@ |
#include "base/logging.h" |
#include "base/macros.h" |
+#include "base/scoped_observer.h" |
#include "build/build_config.h" |
#include "ui/gfx/canvas.h" |
+#include "ui/gfx/color_palette.h" |
#include "ui/gfx/color_utils.h" |
#include "ui/views/painter.h" |
#include "ui/views/view.h" |
+#include "ui/views/view_observer.h" |
#if defined(OS_WIN) |
#include "skia/ext/skia_utils_win.h" |
@@ -36,6 +39,32 @@ class SolidBackground : public Background { |
DISALLOW_COPY_AND_ASSIGN(SolidBackground); |
}; |
+// ThemedSolidBackground is a solid background that stays in sync with a view's |
+// native theme. |
+class ThemedSolidBackground : public SolidBackground, public ViewObserver { |
+ public: |
+ explicit ThemedSolidBackground(View* view, ui::NativeTheme::ColorId color_id) |
+ : SolidBackground(gfx::kPlaceholderColor), |
+ observer_(this), |
+ color_id_(color_id) { |
+ observer_.Add(view); |
+ OnViewNativeThemeChanged(view); |
+ } |
+ ~ThemedSolidBackground() override {} |
+ |
+ // ViewObserver: |
+ void OnViewNativeThemeChanged(View* view) override { |
+ SetNativeControlColor(view->GetNativeTheme()->GetSystemColor(color_id_)); |
+ view->SchedulePaint(); |
+ } |
+ |
+ private: |
+ ScopedObserver<View, ViewObserver> observer_; |
+ ui::NativeTheme::ColorId color_id_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(ThemedSolidBackground); |
+}; |
+ |
class BackgroundPainter : public Background { |
public: |
explicit BackgroundPainter(std::unique_ptr<Painter> painter) |
@@ -73,6 +102,13 @@ Background* Background::CreateSolidBackground(SkColor color) { |
} |
// static |
+Background* Background::CreateThemedSolidBackground( |
+ View* view, |
+ ui::NativeTheme::ColorId color_id) { |
+ return new ThemedSolidBackground(view, color_id); |
+} |
+ |
+// static |
Background* Background::CreateStandardPanelBackground() { |
// TODO(beng): Should be in NativeTheme. |
return CreateSolidBackground(SK_ColorWHITE); |