OLD | NEW |
---|---|
(Empty) | |
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_H_ | |
6 #define UI_VIEWS_CONTROLS_BUTTON_LABEL_BUTTON_H_ | |
7 | |
8 #include <string> | |
9 | |
10 #include "base/compiler_specific.h" | |
11 #include "third_party/skia/include/core/SkColor.h" | |
12 #include "ui/gfx/image/image.h" | |
13 #include "ui/views/controls/button/custom_button.h" | |
14 #include "ui/views/controls/image_view.h" | |
15 #include "ui/views/controls/label.h" | |
16 #include "ui/views/native_theme_delegate.h" | |
17 | |
18 namespace views { | |
19 | |
20 // LabelButton is an alternative to TextButton, it's not focusable by default. | |
21 class VIEWS_EXPORT LabelButton : public CustomButton, | |
22 public NativeThemeDelegate { | |
23 public: | |
24 LabelButton(ButtonListener* listener, const string16& text); | |
25 virtual ~LabelButton(); | |
26 | |
27 // Get or set the image shown for the specified button state. | |
28 // GetImage returns the image for BS_NORMAL if the state's image is empty. | |
29 const gfx::ImageSkia& GetImage(ButtonState for_state); | |
30 void SetImage(ButtonState for_state, const gfx::ImageSkia& image); | |
31 | |
32 // The Label accessor and utility functions. | |
33 Label* GetLabel() const; | |
sky
2012/10/11 19:32:01
Is there a need to expose this? I think the label
msw
2012/10/11 20:27:01
Done; (required adding GetText() and [G|S]etTextMu
| |
34 void SetText(const string16& text); | |
35 void SetTextColor(ButtonState for_state, SkColor color); | |
36 | |
37 // Get or set the horizontal alignment used for the button. | |
38 // The optional image will lead the text, unless the button is right-aligned. | |
39 Label::Alignment GetHorizontalAlignment() const; | |
40 void SetHorizontalAlignment(Label::Alignment alignment); | |
41 | |
42 // Call set_min_size(gfx::Size()) to clear the monotonically increasing size. | |
43 void set_min_size(gfx::Size min_size) { min_size_ = min_size; } | |
44 void set_max_size(gfx::Size max_size) { max_size_ = max_size; } | |
45 | |
46 bool default_button() const { return default_button_; } | |
47 void SetDefaultButton(bool default_button); | |
48 | |
49 bool native_theme() const { return native_theme_; } | |
50 void SetNativeTheme(bool native_theme); | |
51 | |
52 // Overridden from CustomButton: | |
53 virtual void StateChanged() OVERRIDE; | |
54 | |
55 // Overridden from View: | |
56 virtual gfx::Size GetPreferredSize() OVERRIDE; | |
57 virtual std::string GetClassName() const OVERRIDE; | |
58 virtual void ChildPreferredSizeChanged(View* child) OVERRIDE; | |
59 | |
60 protected: | |
61 // Overridden from NativeThemeDelegate: | |
62 virtual ui::NativeTheme::Part GetThemePart() const OVERRIDE; | |
63 virtual gfx::Rect GetThemePaintRect() const OVERRIDE; | |
64 virtual ui::NativeTheme::State GetThemeState( | |
65 ui::NativeTheme::ExtraParams* params) const OVERRIDE; | |
66 virtual const ui::Animation* GetThemeAnimation() const OVERRIDE; | |
67 virtual ui::NativeTheme::State GetBackgroundThemeState( | |
68 ui::NativeTheme::ExtraParams* params) const OVERRIDE; | |
69 virtual ui::NativeTheme::State GetForegroundThemeState( | |
70 ui::NativeTheme::ExtraParams* params) const OVERRIDE; | |
71 | |
72 // Fill |params| with information about the button. | |
73 virtual void GetExtraParams(ui::NativeTheme::ExtraParams* params) const; | |
74 | |
75 private: | |
76 // Call to reset the LayoutManager on alignment (or major content) changes. | |
77 void UpdateLayout(); | |
78 | |
79 // The image and label shown in the button; owned by this class. | |
80 scoped_ptr<ImageView> image_; | |
81 scoped_ptr<Label> label_; | |
82 | |
83 // The images and colors for each button state. | |
84 gfx::ImageSkia button_state_images_[BS_COUNT]; | |
85 SkColor button_state_colors_[BS_COUNT]; | |
86 | |
87 // |min_size_| increases monotonically with the preferred size. | |
88 gfx::Size min_size_; | |
89 // |max_size_| may be set to clamp the preferred size. | |
90 gfx::Size max_size_; | |
91 | |
92 // Flag indicating default button behavior via accelerator handling. | |
93 bool default_button_; | |
94 | |
95 // Flag indicating native theme styling (or Views styling). | |
96 bool native_theme_; | |
97 | |
98 DISALLOW_COPY_AND_ASSIGN(LabelButton); | |
99 }; | |
100 | |
101 } // namespace views | |
102 | |
103 #endif // UI_VIEWS_CONTROLS_BUTTON_LABEL_BUTTON_H_ | |
OLD | NEW |