| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 UI_VIEWS_ANIMATION_INK_DROP_HOST_VIEW_H_ | 5 #ifndef UI_VIEWS_ANIMATION_INK_DROP_HOST_VIEW_H_ |
| 6 #define UI_VIEWS_ANIMATION_INK_DROP_HOST_VIEW_H_ | 6 #define UI_VIEWS_ANIMATION_INK_DROP_HOST_VIEW_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "third_party/skia/include/core/SkColor.h" | 10 #include "third_party/skia/include/core/SkColor.h" |
| 11 #include "ui/gfx/geometry/point.h" | 11 #include "ui/gfx/geometry/point.h" |
| 12 #include "ui/gfx/geometry/size.h" | 12 #include "ui/gfx/geometry/size.h" |
| 13 #include "ui/views/animation/ink_drop.h" | 13 #include "ui/views/animation/ink_drop.h" |
| 14 #include "ui/views/animation/ink_drop_host.h" | 14 #include "ui/views/animation/ink_drop_host.h" |
| 15 #include "ui/views/view.h" | 15 #include "ui/views/view.h" |
| 16 | 16 |
| 17 namespace views { | 17 namespace views { |
| 18 class InkDropImpl; |
| 18 | 19 |
| 19 namespace test { | 20 namespace test { |
| 20 class InkDropHostViewTestApi; | 21 class InkDropHostViewTestApi; |
| 21 } // namespace test | 22 } // namespace test |
| 22 | 23 |
| 23 class InkDropRipple; | |
| 24 class InkDropHighlight; | |
| 25 | |
| 26 // A view that provides InkDropHost functionality. | 24 // A view that provides InkDropHost functionality. |
| 27 class VIEWS_EXPORT InkDropHostView : public View, public InkDropHost { | 25 class VIEWS_EXPORT InkDropHostView : public View, public InkDropHost { |
| 28 public: | 26 public: |
| 29 // Used in SetInkDropMode() to specify whether the ink drop effect is enabled | 27 // Used in SetInkDropMode() to specify whether the ink drop effect is enabled |
| 30 // or not for the view. In case of having an ink drop, it also specifies | 28 // or not for the view. In case of having an ink drop, it also specifies |
| 31 // whether the default gesture event handler for the ink drop should be | 29 // whether the default gesture event handler for the ink drop should be |
| 32 // installed or the subclass will handle gesture events itself. | 30 // installed or the subclass will handle gesture events itself. |
| 33 enum class InkDropMode { | 31 enum class InkDropMode { |
| 34 OFF, | 32 OFF, |
| 35 ON, | 33 ON, |
| 36 ON_NO_GESTURE_HANDLER, | 34 ON_NO_GESTURE_HANDLER, |
| 37 }; | 35 }; |
| 38 | 36 |
| 39 InkDropHostView(); | 37 InkDropHostView(); |
| 40 ~InkDropHostView() override; | 38 ~InkDropHostView() override; |
| 41 | 39 |
| 42 // Overridden from InkDropHost: | 40 // Overridden from InkDropHost: |
| 43 void AddInkDropLayer(ui::Layer* ink_drop_layer) override; | 41 void AddInkDropLayer(ui::Layer* ink_drop_layer) override; |
| 44 void RemoveInkDropLayer(ui::Layer* ink_drop_layer) override; | 42 void RemoveInkDropLayer(ui::Layer* ink_drop_layer) override; |
| 43 std::unique_ptr<InkDrop> CreateInkDrop() override; |
| 45 std::unique_ptr<InkDropRipple> CreateInkDropRipple() const override; | 44 std::unique_ptr<InkDropRipple> CreateInkDropRipple() const override; |
| 46 std::unique_ptr<InkDropHighlight> CreateInkDropHighlight() const override; | 45 std::unique_ptr<InkDropHighlight> CreateInkDropHighlight() const override; |
| 47 | 46 |
| 48 void set_ink_drop_size(const gfx::Size& size) { ink_drop_size_ = size; } | |
| 49 | |
| 50 // Toggle to enable/disable an InkDrop on this View. Descendants can override | 47 // Toggle to enable/disable an InkDrop on this View. Descendants can override |
| 51 // CreateInkDropHighlight() and CreateInkDropRipple() to change the look/feel | 48 // CreateInkDropHighlight() and CreateInkDropRipple() to change the look/feel |
| 52 // of the InkDrop. | 49 // of the InkDrop. |
| 50 // |
| 51 // TODO(bruthig): Add an easier mechanism than overriding functions to allow |
| 52 // subclasses/clients to specify the flavor of ink drop. |
| 53 void SetInkDropMode(InkDropMode ink_drop_mode); | 53 void SetInkDropMode(InkDropMode ink_drop_mode); |
| 54 | 54 |
| 55 protected: | 55 protected: |
| 56 static const int kInkDropSmallCornerRadius; | 56 static const int kInkDropSmallCornerRadius; |
| 57 static const int kInkDropLargeCornerRadius; |
| 58 |
| 59 // Returns a large ink drop size based on the |small_size| that works well |
| 60 // with the SquareInkDropRipple animation durations. |
| 61 static gfx::Size CalculateLargeInkDropSize(const gfx::Size& small_size); |
| 57 | 62 |
| 58 void set_ink_drop_visible_opacity(float visible_opacity) { | 63 void set_ink_drop_visible_opacity(float visible_opacity) { |
| 59 ink_drop_visible_opacity_ = visible_opacity; | 64 ink_drop_visible_opacity_ = visible_opacity; |
| 60 } | 65 } |
| 61 float ink_drop_visible_opacity() const { return ink_drop_visible_opacity_; } | 66 float ink_drop_visible_opacity() const { return ink_drop_visible_opacity_; } |
| 62 | 67 |
| 63 // Returns the default InkDropRipple centered on |center_point|. | 68 // Returns the default InkDropRipple centered on |center_point|. |
| 64 std::unique_ptr<InkDropRipple> CreateDefaultInkDropRipple( | 69 std::unique_ptr<InkDropRipple> CreateDefaultInkDropRipple( |
| 65 const gfx::Point& center_point) const; | 70 const gfx::Point& center_point) const; |
| 66 | 71 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 84 // View: | 89 // View: |
| 85 void VisibilityChanged(View* starting_from, bool is_visible) override; | 90 void VisibilityChanged(View* starting_from, bool is_visible) override; |
| 86 void OnFocus() override; | 91 void OnFocus() override; |
| 87 void OnBlur() override; | 92 void OnBlur() override; |
| 88 void OnMouseEvent(ui::MouseEvent* event) override; | 93 void OnMouseEvent(ui::MouseEvent* event) override; |
| 89 | 94 |
| 90 // Overrideable methods to allow views to provide minor tweaks to the default | 95 // Overrideable methods to allow views to provide minor tweaks to the default |
| 91 // ink drop. | 96 // ink drop. |
| 92 virtual SkColor GetInkDropBaseColor() const; | 97 virtual SkColor GetInkDropBaseColor() const; |
| 93 | 98 |
| 94 // Should return true if the ink drop is also used to depict focus. | |
| 95 virtual bool ShouldShowInkDropForFocus() const; | |
| 96 | |
| 97 // Provides access to |ink_drop_|. Implements lazy initialization of | 99 // Provides access to |ink_drop_|. Implements lazy initialization of |
| 98 // |ink_drop_| so as to avoid virtual method calls during construction since | 100 // |ink_drop_| so as to avoid virtual method calls during construction since |
| 99 // subclasses should be able to call SetInkDropMode() during construction. | 101 // subclasses should be able to call SetInkDropMode() during construction. |
| 100 InkDrop* GetInkDrop(); | 102 InkDrop* GetInkDrop(); |
| 101 | 103 |
| 104 // Returns an InkDropImpl configured to work well with a |
| 105 // flood-fill ink drop ripple. |
| 106 std::unique_ptr<InkDropImpl> CreateDefaultFloodFillInkDropImpl(); |
| 107 |
| 108 // Returns an InkDropImpl with default configuration. The base implementation |
| 109 // of CreateInkDrop() delegates to this function. |
| 110 std::unique_ptr<InkDropImpl> CreateDefaultInkDropImpl(); |
| 111 |
| 102 private: | 112 private: |
| 103 class InkDropGestureHandler; | 113 class InkDropGestureHandler; |
| 104 friend class InkDropGestureHandler; | 114 friend class InkDropGestureHandler; |
| 105 friend class test::InkDropHostViewTestApi; | 115 friend class test::InkDropHostViewTestApi; |
| 106 | 116 |
| 107 // The last user Event to trigger an ink drop ripple animation. | 117 // The last user Event to trigger an ink drop ripple animation. |
| 108 std::unique_ptr<ui::LocatedEvent> last_ripple_triggering_event_; | 118 std::unique_ptr<ui::LocatedEvent> last_ripple_triggering_event_; |
| 109 | 119 |
| 110 // Defines what type of |ink_drop_| to create. | 120 // Defines what type of |ink_drop_| to create. |
| 111 InkDropMode ink_drop_mode_; | 121 InkDropMode ink_drop_mode_; |
| 112 | 122 |
| 113 // Should not be accessed directly. Use GetInkDrop() instead. | 123 // Should not be accessed directly. Use GetInkDrop() instead. |
| 114 std::unique_ptr<InkDrop> ink_drop_; | 124 std::unique_ptr<InkDrop> ink_drop_; |
| 115 | 125 |
| 116 // Intentionally declared after |ink_drop_| so that it doesn't access a | 126 // Intentionally declared after |ink_drop_| so that it doesn't access a |
| 117 // destroyed |ink_drop_| during destruction. | 127 // destroyed |ink_drop_| during destruction. |
| 118 std::unique_ptr<InkDropGestureHandler> gesture_handler_; | 128 std::unique_ptr<InkDropGestureHandler> gesture_handler_; |
| 119 | 129 |
| 120 gfx::Size ink_drop_size_; | |
| 121 | |
| 122 float ink_drop_visible_opacity_; | 130 float ink_drop_visible_opacity_; |
| 123 | 131 |
| 124 // Determines whether the view was already painting to layer before adding ink | 132 // Determines whether the view was already painting to layer before adding ink |
| 125 // drop layer. | 133 // drop layer. |
| 126 bool old_paint_to_layer_; | 134 bool old_paint_to_layer_; |
| 127 | 135 |
| 128 bool destroying_; | 136 bool destroying_; |
| 129 | 137 |
| 130 DISALLOW_COPY_AND_ASSIGN(InkDropHostView); | 138 DISALLOW_COPY_AND_ASSIGN(InkDropHostView); |
| 131 }; | 139 }; |
| 132 } // namespace views | 140 } // namespace views |
| 133 | 141 |
| 134 #endif // UI_VIEWS_ANIMATION_INK_DROP_HOST_VIEW_H_ | 142 #endif // UI_VIEWS_ANIMATION_INK_DROP_HOST_VIEW_H_ |
| OLD | NEW |