| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef ASH_COMMON_SYSTEM_USER_BUTTON_FROM_VIEW_H_ | 5 #ifndef ASH_COMMON_SYSTEM_USER_BUTTON_FROM_VIEW_H_ |
| 6 #define ASH_COMMON_SYSTEM_USER_BUTTON_FROM_VIEW_H_ | 6 #define ASH_COMMON_SYSTEM_USER_BUTTON_FROM_VIEW_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "ash/common/system/tray/tray_popup_ink_drop_style.h" | 10 #include "ash/common/system/tray/tray_popup_ink_drop_style.h" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "ui/gfx/geometry/insets.h" | |
| 13 #include "ui/views/controls/button/custom_button.h" | 12 #include "ui/views/controls/button/custom_button.h" |
| 14 | 13 |
| 15 namespace views { | 14 namespace views { |
| 16 class InkDropContainerView; | 15 class InkDropContainerView; |
| 17 } // namespace views | 16 } // namespace views |
| 18 | 17 |
| 19 namespace ash { | 18 namespace ash { |
| 20 namespace tray { | 19 namespace tray { |
| 21 | 20 |
| 22 // This view is used to wrap it's content and transform it into button. | 21 // This view is used to wrap it's content and transform it into button. |
| 23 class ButtonFromView : public views::CustomButton { | 22 class ButtonFromView : public views::CustomButton { |
| 24 public: | 23 public: |
| 25 // The |content| is the content which is shown within the button. The | 24 // The |content| is the content which is shown within the button. The |
| 26 // |button_listener| will be informed - if provided - when a button was | 25 // |button_listener| will be informed - if provided - when a button was |
| 27 // pressed. If |highlight_on_hover| is set to true, the button will be | 26 // pressed. |
| 28 // highlighted upon hover and show the accessibility caret. | |
| 29 // The |tab_frame_inset| will be used to inset the blue tab frame inside the | |
| 30 // button. | |
| 31 // An accessible label gets computed based upon descendant views of this view. | |
| 32 ButtonFromView(views::View* content, | 27 ButtonFromView(views::View* content, |
| 33 views::ButtonListener* listener, | 28 views::ButtonListener* listener, |
| 34 TrayPopupInkDropStyle ink_drop_style, | 29 TrayPopupInkDropStyle ink_drop_style); |
| 35 bool highlight_on_hover, | |
| 36 const gfx::Insets& tab_frame_inset); | |
| 37 ~ButtonFromView() override; | 30 ~ButtonFromView() override; |
| 38 | 31 |
| 39 // Called when the border should remain even in the non highlighted state. | |
| 40 void ForceBorderVisible(bool show); | |
| 41 | |
| 42 // views::View: | 32 // views::View: |
| 43 void OnMouseEntered(const ui::MouseEvent& event) override; | 33 void OnMouseEntered(const ui::MouseEvent& event) override; |
| 44 void OnMouseExited(const ui::MouseEvent& event) override; | 34 void OnMouseExited(const ui::MouseEvent& event) override; |
| 45 void OnPaint(gfx::Canvas* canvas) override; | 35 void OnPaint(gfx::Canvas* canvas) override; |
| 46 void OnFocus() override; | 36 void OnFocus() override; |
| 47 void OnBlur() override; | 37 void OnBlur() override; |
| 48 void GetAccessibleNodeData(ui::AXNodeData* node_data) override; | 38 void GetAccessibleNodeData(ui::AXNodeData* node_data) override; |
| 49 void Layout() override; | 39 void Layout() override; |
| 50 | 40 |
| 51 // Check if the item is hovered. | 41 // Check if the item is hovered. |
| 52 bool is_hovered_for_test() { return button_hovered_; } | 42 bool is_hovered_for_test() { return button_hovered_; } |
| 53 | 43 |
| 54 protected: | 44 protected: |
| 55 // views::CustomButton: | 45 // views::CustomButton: |
| 56 void AddInkDropLayer(ui::Layer* ink_drop_layer) override; | 46 void AddInkDropLayer(ui::Layer* ink_drop_layer) override; |
| 57 void RemoveInkDropLayer(ui::Layer* ink_drop_layer) override; | 47 void RemoveInkDropLayer(ui::Layer* ink_drop_layer) override; |
| 58 std::unique_ptr<views::InkDrop> CreateInkDrop() override; | 48 std::unique_ptr<views::InkDrop> CreateInkDrop() override; |
| 59 std::unique_ptr<views::InkDropRipple> CreateInkDropRipple() const override; | 49 std::unique_ptr<views::InkDropRipple> CreateInkDropRipple() const override; |
| 60 std::unique_ptr<views::InkDropHighlight> CreateInkDropHighlight() | 50 std::unique_ptr<views::InkDropHighlight> CreateInkDropHighlight() |
| 61 const override; | 51 const override; |
| 62 std::unique_ptr<views::InkDropMask> CreateInkDropMask() const override; | 52 std::unique_ptr<views::InkDropMask> CreateInkDropMask() const override; |
| 63 | 53 |
| 64 private: | 54 private: |
| 65 // Change the hover/active state of the "button" when the status changes. | |
| 66 void ShowActive(); | |
| 67 | |
| 68 // Content of button. | 55 // Content of button. |
| 69 views::View* content_; | 56 views::View* content_; |
| 70 | 57 |
| 71 // Defines the flavor of ink drop ripple/highlight that should be constructed. | 58 // Defines the flavor of ink drop ripple/highlight that should be constructed. |
| 72 TrayPopupInkDropStyle ink_drop_style_; | 59 TrayPopupInkDropStyle ink_drop_style_; |
| 73 | 60 |
| 74 // Whether button should be highligthed on hover. | |
| 75 bool highlight_on_hover_; | |
| 76 | |
| 77 // True if button is hovered. | 61 // True if button is hovered. |
| 78 bool button_hovered_; | 62 bool button_hovered_; |
| 79 | 63 |
| 80 // True if the border should be always visible. | |
| 81 bool show_border_; | |
| 82 | |
| 83 // The insets which get used for the drawn accessibility (tab) frame. | |
| 84 gfx::Insets tab_frame_inset_; | |
| 85 | |
| 86 // A separate view is necessary to hold the ink drop layer so that |this| can | 64 // A separate view is necessary to hold the ink drop layer so that |this| can |
| 87 // host labels with subpixel anti-aliasing enabled. Only used for material | 65 // host labels with subpixel anti-aliasing enabled. |
| 88 // design. | |
| 89 views::InkDropContainerView* ink_drop_container_; | 66 views::InkDropContainerView* ink_drop_container_; |
| 90 | 67 |
| 91 std::unique_ptr<views::InkDropMask> ink_drop_mask_; | 68 std::unique_ptr<views::InkDropMask> ink_drop_mask_; |
| 92 | 69 |
| 93 DISALLOW_COPY_AND_ASSIGN(ButtonFromView); | 70 DISALLOW_COPY_AND_ASSIGN(ButtonFromView); |
| 94 }; | 71 }; |
| 95 | 72 |
| 96 } // namespace tray | 73 } // namespace tray |
| 97 } // namespace ash | 74 } // namespace ash |
| 98 | 75 |
| 99 #endif // ASH_COMMON_SYSTEM_USER_BUTTON_FROM_VIEW_H_ | 76 #endif // ASH_COMMON_SYSTEM_USER_BUTTON_FROM_VIEW_H_ |
| OLD | NEW |