// Copyright (c) 2012 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 UI_VIEWS_BACKGROUND_H_ #define UI_VIEWS_BACKGROUND_H_ #include #include #include "base/macros.h" #include "build/build_config.h" #include "third_party/skia/include/core/SkColor.h" #include "ui/views/views_export.h" #if defined(OS_WIN) #include #endif // defined(OS_WIN) namespace gfx { class Canvas; } namespace views { class Painter; class View; ///////////////////////////////////////////////////////////////////////////// // // Background class // // A background implements a way for views to paint a background. The // background can be either solid or based on a gradient. Of course, // Background can be subclassed to implement various effects. // // Any View can have a background. See View::SetBackground() and // View::OnPaintBackground() // ///////////////////////////////////////////////////////////////////////////// class VIEWS_EXPORT Background { public: Background(); virtual ~Background(); // Creates a background that fills the canvas in the specified color. static Background* CreateSolidBackground(SkColor color); // Creates a background that fills the canvas in the specified color. static Background* CreateSolidBackground(int r, int g, int b) { return CreateSolidBackground(SkColorSetRGB(r, g, b)); } // Creates a background that fills the canvas in the specified color. static Background* CreateSolidBackground(int r, int g, int b, int a) { return CreateSolidBackground(SkColorSetARGB(a, r, g, b)); } // Creates Chrome's standard panel background static Background* CreateStandardPanelBackground(); // Creates a Background from the specified Painter. static Background* CreateBackgroundPainter(std::unique_ptr painter); // Render the background for the provided view virtual void Paint(gfx::Canvas* canvas, View* view) const = 0; // Set a solid, opaque color to be used when drawing backgrounds of native // controls. Unfortunately alpha=0 is not an option. void SetNativeControlColor(SkColor color); // Returns the "background color". This is equivalent to the color set in // SetNativeControlColor(). For solid backgrounds, this is the color; for // gradient backgrounds, it's the midpoint of the gradient; for painter // backgrounds, this is not useful (returns a default color). SkColor get_color() const { return color_; } private: SkColor color_; DISALLOW_COPY_AND_ASSIGN(Background); }; } // namespace views #endif // UI_VIEWS_BACKGROUND_H_