Chromium Code Reviews| 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 | 18 |
| 19 namespace test { | 19 namespace test { |
| 20 class InkDropHostViewTestApi; | 20 class InkDropHostViewTestApi; |
| 21 } // namespace test | 21 } // namespace test |
| 22 | 22 |
| 23 class InkDropRipple; | 23 class InkDropRipple; |
| 24 class InkDropHighlight; | 24 class InkDropHighlight; |
| 25 class InkDropImpl; | |
| 25 | 26 |
| 26 // A view that provides InkDropHost functionality. | 27 // A view that provides InkDropHost functionality. |
| 27 class VIEWS_EXPORT InkDropHostView : public View, public InkDropHost { | 28 class VIEWS_EXPORT InkDropHostView : public View, public InkDropHost { |
| 28 public: | 29 public: |
| 29 InkDropHostView(); | 30 InkDropHostView(); |
| 30 ~InkDropHostView() override; | 31 ~InkDropHostView() override; |
| 31 | 32 |
| 32 // Overridden from InkDropHost: | 33 // Overridden from InkDropHost: |
| 33 void AddInkDropLayer(ui::Layer* ink_drop_layer) override; | 34 void AddInkDropLayer(ui::Layer* ink_drop_layer) override; |
| 34 void RemoveInkDropLayer(ui::Layer* ink_drop_layer) override; | 35 void RemoveInkDropLayer(ui::Layer* ink_drop_layer) override; |
| 36 std::unique_ptr<InkDrop> CreateInkDrop() override; | |
| 35 std::unique_ptr<InkDropRipple> CreateInkDropRipple() const override; | 37 std::unique_ptr<InkDropRipple> CreateInkDropRipple() const override; |
| 36 std::unique_ptr<InkDropHighlight> CreateInkDropHighlight() const override; | 38 std::unique_ptr<InkDropHighlight> CreateInkDropHighlight() const override; |
| 37 | 39 |
| 38 void set_ink_drop_size(const gfx::Size& size) { ink_drop_size_ = size; } | |
| 39 | |
| 40 protected: | 40 protected: |
| 41 // Used in SetInkDropMode() to specify whether the ink drop effect is enabled | 41 // Used in SetInkDropMode() to specify whether the ink drop effect is enabled |
| 42 // or not for the view. In case of having an ink drop, it also specifies | 42 // or not for the view. In case of having an ink drop, it also specifies |
| 43 // whether the default gesture event handler for the ink drop should be | 43 // whether the default gesture event handler for the ink drop should be |
| 44 // installed or the subclass will handle gesture events itself. | 44 // installed or the subclass will handle gesture events itself. |
| 45 enum class InkDropMode { | 45 enum class InkDropMode { |
| 46 OFF, | 46 OFF, |
| 47 ON, | 47 ON, |
| 48 ON_NO_GESTURE_HANDLER, | 48 ON_NO_GESTURE_HANDLER, |
| 49 }; | 49 }; |
| 50 | 50 |
| 51 static gfx::Size CalculateLargeInkDropSize(const gfx::Size small_size); | |
|
sky
2016/11/02 02:52:11
const gfx::Size&
bruthig
2016/11/04 18:50:36
Done.
| |
| 52 | |
| 51 static const int kInkDropSmallCornerRadius; | 53 static const int kInkDropSmallCornerRadius; |
| 54 static const int kInkDropLargeCornerRadius; | |
|
sky
2016/11/02 02:52:11
constants before functions.
bruthig
2016/11/04 18:50:36
Done.
| |
| 52 | 55 |
| 53 void set_ink_drop_visible_opacity(float visible_opacity) { | 56 void set_ink_drop_visible_opacity(float visible_opacity) { |
| 54 ink_drop_visible_opacity_ = visible_opacity; | 57 ink_drop_visible_opacity_ = visible_opacity; |
| 55 } | 58 } |
| 56 float ink_drop_visible_opacity() const { return ink_drop_visible_opacity_; } | 59 float ink_drop_visible_opacity() const { return ink_drop_visible_opacity_; } |
| 57 | 60 |
| 58 // Returns the default InkDropRipple centered on |center_point|. | 61 // Returns the default InkDropRipple centered on |center_point|. |
| 59 std::unique_ptr<InkDropRipple> CreateDefaultInkDropRipple( | 62 std::unique_ptr<InkDropRipple> CreateDefaultInkDropRipple( |
| 60 const gfx::Point& center_point) const; | 63 const gfx::Point& center_point) const; |
| 61 | 64 |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 80 void VisibilityChanged(View* starting_from, bool is_visible) override; | 83 void VisibilityChanged(View* starting_from, bool is_visible) override; |
| 81 void OnFocus() override; | 84 void OnFocus() override; |
| 82 void OnBlur() override; | 85 void OnBlur() override; |
| 83 void OnMouseEvent(ui::MouseEvent* event) override; | 86 void OnMouseEvent(ui::MouseEvent* event) override; |
| 84 | 87 |
| 85 // Overrideable methods to allow views to provide minor tweaks to the default | 88 // Overrideable methods to allow views to provide minor tweaks to the default |
| 86 // ink drop. | 89 // ink drop. |
| 87 virtual SkColor GetInkDropBaseColor() const; | 90 virtual SkColor GetInkDropBaseColor() const; |
| 88 | 91 |
| 89 // Should return true if the ink drop is also used to depict focus. | 92 // Should return true if the ink drop is also used to depict focus. |
| 93 // TODO(bruthig): Make this a configuration of InkDropImpl. | |
| 90 virtual bool ShouldShowInkDropForFocus() const; | 94 virtual bool ShouldShowInkDropForFocus() const; |
| 91 | 95 |
| 92 InkDrop* ink_drop() { return ink_drop_.get(); } | 96 InkDrop* ink_drop() { return ink_drop_.get(); } |
| 93 | 97 |
| 94 // Toggle to enable/disable an InkDrop on this View. Descendants can override | 98 // Toggle to enable/disable an InkDrop on this View. Descendants can override |
| 95 // CreateInkDropHighlight() and CreateInkDropRipple() to change the look/feel | 99 // CreateInkDrop(), CreateInkDropHighlight() and CreateInkDropRipple() to |
| 96 // of the InkDrop. | 100 // change the look/feel of the InkDrop. |
| 97 void SetInkDropMode(InkDropMode ink_drop_mode); | 101 void SetInkDropMode(InkDropMode ink_drop_mode); |
| 98 | 102 |
| 103 // Returns an InkDropImpl configured to work well with a | |
| 104 // flood-fill ink drop ripple. | |
| 105 std::unique_ptr<InkDropImpl> CreateDefaultFloodFillInkDropImpl(); | |
| 106 | |
| 107 // Returns a InkDropImpl with default configuration. The base implementation | |
| 108 // of CreateInkDrop() delegates to this function. | |
| 109 std::unique_ptr<InkDropImpl> CreateDefaultInkDropImpl(); | |
| 110 | |
| 99 private: | 111 private: |
| 100 class InkDropGestureHandler; | 112 class InkDropGestureHandler; |
| 101 friend class InkDropGestureHandler; | 113 friend class InkDropGestureHandler; |
| 102 friend class test::InkDropHostViewTestApi; | 114 friend class test::InkDropHostViewTestApi; |
| 103 | 115 |
| 104 // The last user Event to trigger an ink drop ripple animation. | 116 // The last user Event to trigger an ink drop ripple animation. |
| 105 std::unique_ptr<ui::LocatedEvent> last_ripple_triggering_event_; | 117 std::unique_ptr<ui::LocatedEvent> last_ripple_triggering_event_; |
| 106 | 118 |
| 107 std::unique_ptr<InkDrop> ink_drop_; | 119 std::unique_ptr<InkDrop> ink_drop_; |
| 108 | 120 |
| 109 // Intentionally declared after |ink_drop_| so that it doesn't access a | 121 // Intentionally declared after |ink_drop_| so that it doesn't access a |
| 110 // destroyed |ink_drop_| during destruction. | 122 // destroyed |ink_drop_| during destruction. |
| 111 std::unique_ptr<InkDropGestureHandler> gesture_handler_; | 123 std::unique_ptr<InkDropGestureHandler> gesture_handler_; |
| 112 | 124 |
| 113 gfx::Size ink_drop_size_; | |
| 114 | |
| 115 float ink_drop_visible_opacity_; | 125 float ink_drop_visible_opacity_; |
| 116 | 126 |
| 117 // Determines whether the view was already painting to layer before adding ink | 127 // Determines whether the view was already painting to layer before adding ink |
| 118 // drop layer. | 128 // drop layer. |
| 119 bool old_paint_to_layer_; | 129 bool old_paint_to_layer_; |
| 120 | 130 |
| 121 bool destroying_; | 131 bool destroying_; |
| 122 | 132 |
| 123 DISALLOW_COPY_AND_ASSIGN(InkDropHostView); | 133 DISALLOW_COPY_AND_ASSIGN(InkDropHostView); |
| 124 }; | 134 }; |
| 125 } // namespace views | 135 } // namespace views |
| 126 | 136 |
| 127 #endif // UI_VIEWS_ANIMATION_INK_DROP_HOST_VIEW_H_ | 137 #endif // UI_VIEWS_ANIMATION_INK_DROP_HOST_VIEW_H_ |
| OLD | NEW |