Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(133)

Unified Diff: ui/views/background.cc

Issue 2838273002: Reland 097f9cde453ea57eb4aa037f44add782391c5eb9 (Closed)
Patch Set: rebase Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/views/background.h ('k') | ui/views/bubble/tray_bubble_view.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/background.cc
diff --git a/ui/views/background.cc b/ui/views/background.cc
index 190a5a62c346e714f9b7c4dad8a8d79321132a0d..901aa03b849dc8dfcbdcd4e565964a0b95b5b8c1 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,33 @@ 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();
+ }
+ void OnViewIsDeleting(View* view) override { observer_.Remove(view); }
+
+ 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 +103,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);
« no previous file with comments | « ui/views/background.h ('k') | ui/views/bubble/tray_bubble_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698