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_VIEWS_CONTROLS_BUTTON_LABEL_BUTTON_BORDER_H_
6 #define UI_VIEWS_CONTROLS_BUTTON_LABEL_BUTTON_BORDER_H_
7 
8 #include <memory>
9 
10 #include "base/compiler_specific.h"
11 #include "base/macros.h"
12 #include "ui/gfx/geometry/insets.h"
13 #include "ui/views/border.h"
14 #include "ui/views/controls/button/button.h"
15 #include "ui/views/painter.h"
16 
17 namespace views {
18 
19 // An empty Border with customizable insets used by a LabelButton.
20 class VIEWS_EXPORT LabelButtonBorder : public Border {
21  public:
22   LabelButtonBorder();
23   ~LabelButtonBorder() override;
24 
set_insets(const gfx::Insets & insets)25   void set_insets(const gfx::Insets& insets) { insets_ = insets; }
26 
27   // Returns true if |this| is able to paint for the given |focused| and |state|
28   // values.
29   virtual bool PaintsButtonState(bool focused, Button::ButtonState state);
30 
31   // Overridden from Border:
32   void Paint(const View& view, gfx::Canvas* canvas) override;
33   gfx::Insets GetInsets() const override;
34   gfx::Size GetMinimumSize() const override;
35 
36  private:
37   gfx::Insets insets_;
38 
39   DISALLOW_COPY_AND_ASSIGN(LabelButtonBorder);
40 };
41 
42 // A Border that paints a LabelButton's background frame using image assets.
43 class VIEWS_EXPORT LabelButtonAssetBorder : public LabelButtonBorder {
44  public:
45   LabelButtonAssetBorder();
46   ~LabelButtonAssetBorder() override;
47 
48   // Returns the default insets.
49   static gfx::Insets GetDefaultInsets();
50 
51   // Overridden from LabelButtonBorder:
52   bool PaintsButtonState(bool focused, Button::ButtonState state) override;
53 
54   // Overridden from Border:
55   void Paint(const View& view, gfx::Canvas* canvas) override;
56   gfx::Size GetMinimumSize() const override;
57 
58   // Get or set the painter used for the specified |focused| button |state|.
59   // LabelButtonAssetBorder takes and retains ownership of |painter|.
60   Painter* GetPainter(bool focused, Button::ButtonState state);
61   void SetPainter(bool focused,
62                   Button::ButtonState state,
63                   std::unique_ptr<Painter> painter);
64 
65  private:
66   // The painters used for each unfocused or focused button state.
67   std::unique_ptr<Painter> painters_[2][Button::STATE_COUNT];
68 
69   DISALLOW_COPY_AND_ASSIGN(LabelButtonAssetBorder);
70 };
71 
72 }  // namespace views
73 
74 #endif  // UI_VIEWS_CONTROLS_BUTTON_LABEL_BUTTON_BORDER_H_
75