| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011 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_BUTTON_H_ | |
| 6 #define UI_VIEWS_CONTROLS_BUTTON_BUTTON_H_ | |
| 7 | |
| 8 #include "ui/native_theme/native_theme.h" | |
| 9 #include "ui/views/view.h" | |
| 10 | |
| 11 namespace views { | |
| 12 | |
| 13 class Button; | |
| 14 class Event; | |
| 15 | |
| 16 // An interface implemented by an object to let it know that a button was | |
| 17 // pressed. | |
| 18 class VIEWS_EXPORT ButtonListener { | |
| 19 public: | |
| 20 virtual void ButtonPressed(Button* sender, const ui::Event& event) = 0; | |
| 21 | |
| 22 protected: | |
| 23 virtual ~ButtonListener() {} | |
| 24 }; | |
| 25 | |
| 26 // A View representing a button. Depending on the specific type, the button | |
| 27 // could be implemented by a native control or custom rendered. | |
| 28 class VIEWS_EXPORT Button : public View { | |
| 29 public: | |
| 30 virtual ~Button(); | |
| 31 | |
| 32 // Button states for various button sub-types. | |
| 33 enum ButtonState { | |
| 34 STATE_NORMAL = 0, | |
| 35 STATE_HOVERED, | |
| 36 STATE_PRESSED, | |
| 37 STATE_DISABLED, | |
| 38 STATE_COUNT, | |
| 39 }; | |
| 40 | |
| 41 // Button styles with associated images and border painters. | |
| 42 // TODO(msw): Add Menu, ComboBox, etc. | |
| 43 enum ButtonStyle { | |
| 44 STYLE_BUTTON = 0, | |
| 45 STYLE_TEXTBUTTON, | |
| 46 STYLE_COUNT, | |
| 47 }; | |
| 48 | |
| 49 static ButtonState GetButtonStateFrom(ui::NativeTheme::State state); | |
| 50 | |
| 51 void SetTooltipText(const base::string16& tooltip_text); | |
| 52 | |
| 53 int tag() const { return tag_; } | |
| 54 void set_tag(int tag) { tag_ = tag; } | |
| 55 | |
| 56 void SetAccessibleName(const base::string16& name); | |
| 57 | |
| 58 // Overridden from View: | |
| 59 virtual bool GetTooltipText(const gfx::Point& p, | |
| 60 base::string16* tooltip) const override; | |
| 61 virtual void GetAccessibleState(ui::AXViewState* state) override; | |
| 62 | |
| 63 protected: | |
| 64 // Construct the Button with a Listener. The listener can be NULL. This can be | |
| 65 // true of buttons that don't have a listener - e.g. menubuttons where there's | |
| 66 // no default action and checkboxes. | |
| 67 explicit Button(ButtonListener* listener); | |
| 68 | |
| 69 // Cause the button to notify the listener that a click occurred. | |
| 70 virtual void NotifyClick(const ui::Event& event); | |
| 71 | |
| 72 // The button's listener. Notified when clicked. | |
| 73 ButtonListener* listener_; | |
| 74 | |
| 75 private: | |
| 76 // The text shown in a tooltip. | |
| 77 base::string16 tooltip_text_; | |
| 78 | |
| 79 // Accessibility data. | |
| 80 base::string16 accessible_name_; | |
| 81 | |
| 82 // The id tag associated with this button. Used to disambiguate buttons in | |
| 83 // the ButtonListener implementation. | |
| 84 int tag_; | |
| 85 | |
| 86 DISALLOW_COPY_AND_ASSIGN(Button); | |
| 87 }; | |
| 88 | |
| 89 } // namespace views | |
| 90 | |
| 91 #endif // UI_VIEWS_CONTROLS_BUTTON_BUTTON_H_ | |
| OLD | NEW |