Chromium Code Reviews| 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 // Get or set the text shown on the button. | |
| 33 const string16& GetText() const; | |
| 34 void SetText(const string16& text); | |
| 35 | |
| 36 // Set the text color shown for the specified button state. | |
| 37 void SetTextColor(ButtonState for_state, SkColor color); | |
| 38 | |
| 39 // Get or Set the text's multi-line property to break on '\n', etc. | |
| 40 bool GetTextMultiLine() const; | |
| 41 void SetTextMultiLine(bool text_multi_line); | |
| 42 | |
| 43 // Get or set the horizontal alignment used for the button. | |
| 44 // The optional image will lead the text, unless the button is right-aligned. | |
| 45 Label::Alignment GetHorizontalAlignment() const; | |
| 46 void SetHorizontalAlignment(Label::Alignment alignment); | |
| 47 | |
| 48 // Call set_min_size(gfx::Size()) to clear the monotonically increasing size. | |
| 49 void set_min_size(gfx::Size min_size) { min_size_ = min_size; } | |
|
sky
2012/10/11 23:01:56
const gfx::Size&
msw
2012/10/15 16:48:34
Done.
| |
| 50 void set_max_size(gfx::Size max_size) { max_size_ = max_size; } | |
| 51 | |
| 52 bool default_button() const { return default_button_; } | |
| 53 void SetDefaultButton(bool default_button); | |
| 54 | |
| 55 bool native_theme() const { return native_theme_; } | |
|
sky
2012/10/11 23:01:56
It isn't readily obvious what this does. Document
msw
2012/10/15 16:48:34
Done.
| |
| 56 void SetNativeTheme(bool native_theme); | |
| 57 | |
| 58 // Overridden from CustomButton: | |
| 59 virtual void StateChanged() OVERRIDE; | |
| 60 | |
| 61 // Overridden from View: | |
| 62 virtual gfx::Size GetPreferredSize() OVERRIDE; | |
| 63 virtual std::string GetClassName() const OVERRIDE; | |
| 64 virtual void ChildPreferredSizeChanged(View* child) OVERRIDE; | |
| 65 | |
| 66 protected: | |
| 67 // Overridden from NativeThemeDelegate: | |
| 68 virtual ui::NativeTheme::Part GetThemePart() const OVERRIDE; | |
| 69 virtual gfx::Rect GetThemePaintRect() const OVERRIDE; | |
| 70 virtual ui::NativeTheme::State GetThemeState( | |
| 71 ui::NativeTheme::ExtraParams* params) const OVERRIDE; | |
| 72 virtual const ui::Animation* GetThemeAnimation() const OVERRIDE; | |
| 73 virtual ui::NativeTheme::State GetBackgroundThemeState( | |
| 74 ui::NativeTheme::ExtraParams* params) const OVERRIDE; | |
| 75 virtual ui::NativeTheme::State GetForegroundThemeState( | |
| 76 ui::NativeTheme::ExtraParams* params) const OVERRIDE; | |
| 77 | |
| 78 // Fill |params| with information about the button. | |
| 79 virtual void GetExtraParams(ui::NativeTheme::ExtraParams* params) const; | |
| 80 | |
| 81 private: | |
| 82 FRIEND_TEST_ALL_PREFIXES(LabelButtonTest, Init); | |
| 83 | |
| 84 // Call to reset the LayoutManager on alignment (or major content) changes. | |
| 85 void UpdateLayout(); | |
| 86 | |
| 87 // The image and label shown in the button; owned by this class. | |
| 88 scoped_ptr<ImageView> image_; | |
| 89 scoped_ptr<Label> label_; | |
| 90 | |
| 91 // The images and colors for each button state. | |
| 92 gfx::ImageSkia button_state_images_[BS_COUNT]; | |
| 93 SkColor button_state_colors_[BS_COUNT]; | |
| 94 | |
| 95 // |min_size_| increases monotonically with the preferred size. | |
| 96 gfx::Size min_size_; | |
| 97 // |max_size_| may be set to clamp the preferred size. | |
| 98 gfx::Size max_size_; | |
| 99 | |
| 100 // Flag indicating default button behavior via accelerator handling. | |
| 101 bool default_button_; | |
| 102 | |
| 103 // Flag indicating native theme styling (or Views styling). | |
| 104 bool native_theme_; | |
| 105 | |
| 106 DISALLOW_COPY_AND_ASSIGN(LabelButton); | |
| 107 }; | |
| 108 | |
| 109 } // namespace views | |
| 110 | |
| 111 #endif // UI_VIEWS_CONTROLS_BUTTON_LABEL_BUTTON_H_ | |
| OLD | NEW |