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/size.h" | 12 #include "ui/gfx/geometry/size.h" |
| 12 #include "ui/views/animation/ink_drop.h" | 13 #include "ui/views/animation/ink_drop.h" |
| 13 #include "ui/views/animation/ink_drop_host.h" | 14 #include "ui/views/animation/ink_drop_host.h" |
| 14 #include "ui/views/view.h" | 15 #include "ui/views/view.h" |
| 15 | 16 |
| 16 namespace views { | 17 namespace views { |
| 17 | 18 |
| 18 namespace test { | 19 namespace test { |
| 19 class InkDropHostViewTestApi; | 20 class InkDropHostViewTestApi; |
| 20 } // namespace test | 21 } // namespace test |
| 21 | 22 |
| 22 class InkDropRipple; | 23 class InkDropRipple; |
| 23 class InkDropHighlight; | 24 class InkDropHighlight; |
| 24 | 25 |
| 25 // A view that provides InkDropHost functionality. | 26 // A view that provides InkDropHost functionality. |
| 26 class VIEWS_EXPORT InkDropHostView : public View, public InkDropHost { | 27 class VIEWS_EXPORT InkDropHostView : public View, public InkDropHost { |
| 27 public: | 28 public: |
| 29 InkDropHostView(); | |
| 30 ~InkDropHostView() override; | |
| 31 | |
| 28 // Overridden from InkDropHost: | 32 // Overridden from InkDropHost: |
| 29 void AddInkDropLayer(ui::Layer* ink_drop_layer) override; | 33 void AddInkDropLayer(ui::Layer* ink_drop_layer) override; |
| 30 void RemoveInkDropLayer(ui::Layer* ink_drop_layer) override; | 34 void RemoveInkDropLayer(ui::Layer* ink_drop_layer) override; |
| 31 std::unique_ptr<InkDropRipple> CreateInkDropRipple() const override; | 35 std::unique_ptr<InkDropRipple> CreateInkDropRipple() const override; |
| 32 std::unique_ptr<InkDropHighlight> CreateInkDropHighlight() const override; | 36 std::unique_ptr<InkDropHighlight> CreateInkDropHighlight() const override; |
| 33 | 37 |
| 34 void set_ink_drop_size(const gfx::Size& size) { ink_drop_size_ = size; } | 38 void set_ink_drop_size(const gfx::Size& size) { ink_drop_size_ = size; } |
| 35 | 39 |
| 36 protected: | 40 protected: |
| 37 InkDropHostView(); | 41 static const int kInkDropSmallCornerRadius; |
| 38 ~InkDropHostView() override; | |
| 39 | 42 |
| 40 static const int kInkDropSmallCornerRadius; | 43 const ui::Event* last_ripple_triggering_event() const { |
|
Evan Stade
2016/06/14 21:13:24
is this used somewhere
bruthig
2016/06/14 21:57:01
Removed.
| |
| 44 return last_ripple_triggering_event_.get(); | |
| 45 } | |
| 46 | |
| 47 // Returns the default InkDropRipple centered on |center_point|. | |
| 48 std::unique_ptr<InkDropRipple> CreateDefaultInkDropRipple( | |
| 49 const gfx::Point& center_point) const; | |
| 50 | |
| 51 // Returns the default InkDropHighlight centered on |center_point|. | |
| 52 std::unique_ptr<InkDropHighlight> CreateDefaultInkDropHighlight( | |
| 53 const gfx::Point& center_point) const; | |
| 54 | |
| 55 // Returns the point of the |last_ripple_triggereing_event_| if it was a | |
|
Evan Stade
2016/06/14 21:13:24
nit: spelling
bruthig
2016/06/14 21:57:01
Done.
| |
| 56 // LocatedEvent, otherwise the center point of the local bounds is returned. | |
| 57 gfx::Point GetInkDropCenterBasedOnLastEvent() const; | |
| 58 | |
| 59 // Animates |ink_drop_| to the desired |ink_drop_state|. Caches |event| as the | |
| 60 // last_ripple_triggering_event(). | |
| 61 // | |
| 62 // *** NOTE ***: |event| has been plumbed through on a best effort basis for | |
| 63 // the purposes of centering ink drop ripples on located Events. Thus nullptr | |
| 64 // has been used by clients who do not have an Event instance available to | |
| 65 // them. | |
| 66 void AnimateInkDrop(InkDropState state, const ui::Event* event); | |
|
Evan Stade
2016/06/14 21:13:24
|event| should be a located event to make it more
bruthig
2016/06/14 21:57:01
Done.
| |
| 41 | 67 |
| 42 // View: | 68 // View: |
| 43 void VisibilityChanged(View* starting_from, bool is_visible) override; | 69 void VisibilityChanged(View* starting_from, bool is_visible) override; |
| 44 void OnFocus() override; | 70 void OnFocus() override; |
| 45 void OnBlur() override; | 71 void OnBlur() override; |
| 46 void OnMouseEvent(ui::MouseEvent* event) override; | 72 void OnMouseEvent(ui::MouseEvent* event) override; |
| 47 | 73 |
| 48 // Overrideable methods to allow views to provide minor tweaks to the default | 74 // Overrideable methods to allow views to provide minor tweaks to the default |
| 49 // ink drop. | 75 // ink drop. |
| 50 virtual gfx::Point GetInkDropCenter() const; | |
| 51 virtual SkColor GetInkDropBaseColor() const; | 76 virtual SkColor GetInkDropBaseColor() const; |
| 52 | 77 |
| 53 // Should return true if the ink drop is also used to depict focus. | 78 // Should return true if the ink drop is also used to depict focus. |
| 54 virtual bool ShouldShowInkDropForFocus() const; | 79 virtual bool ShouldShowInkDropForFocus() const; |
| 55 | 80 |
| 56 InkDrop* ink_drop() { return ink_drop_.get(); } | 81 InkDrop* ink_drop() { return ink_drop_.get(); } |
| 57 | 82 |
| 58 // Toggle to enable/disable an InkDrop on this View. Descendants can override | 83 // Toggle to enable/disable an InkDrop on this View. Descendants can override |
| 59 // CreateInkDropHighlight() and CreateInkDropRipple() to change the look/feel | 84 // CreateInkDropHighlight() and CreateInkDropRipple() to change the look/feel |
| 60 // of the InkDrop. | 85 // of the InkDrop. |
| 61 void SetHasInkDrop(bool has_an_ink_drop); | 86 void SetHasInkDrop(bool has_an_ink_drop); |
| 62 | 87 |
| 63 // Animates |ink_drop_| to the desired |ink_drop_state|. | |
| 64 // | |
| 65 // TODO(bruthig): Enhance to accept a ui::Event parameter so InkDrops can be | |
| 66 // centered (see https://crbug.com/597273) and disabled for touch events on | |
| 67 // Windows (see https://crbug.com/595315). | |
| 68 void AnimateInkDrop(InkDropState ink_drop_state); | |
| 69 | |
| 70 private: | 88 private: |
| 71 class InkDropGestureHandler; | 89 class InkDropGestureHandler; |
| 90 friend class InkDropGestureHandler; | |
| 72 friend class test::InkDropHostViewTestApi; | 91 friend class test::InkDropHostViewTestApi; |
| 73 | 92 |
| 93 // The last user Event to trigger an ink drop ripple animation. | |
| 94 std::unique_ptr<ui::Event> last_ripple_triggering_event_; | |
| 95 | |
| 74 std::unique_ptr<InkDrop> ink_drop_; | 96 std::unique_ptr<InkDrop> ink_drop_; |
| 75 | 97 |
| 76 // Intentionally declared after |ink_drop_| so that it doesn't access a | 98 // Intentionally declared after |ink_drop_| so that it doesn't access a |
| 77 // destroyed |ink_drop_| during destruction. | 99 // destroyed |ink_drop_| during destruction. |
| 78 std::unique_ptr<InkDropGestureHandler> gesture_handler_; | 100 std::unique_ptr<InkDropGestureHandler> gesture_handler_; |
| 79 | 101 |
| 80 gfx::Size ink_drop_size_; | 102 gfx::Size ink_drop_size_; |
| 81 | 103 |
| 82 bool destroying_; | 104 bool destroying_; |
| 83 | 105 |
| 84 DISALLOW_COPY_AND_ASSIGN(InkDropHostView); | 106 DISALLOW_COPY_AND_ASSIGN(InkDropHostView); |
| 85 }; | 107 }; |
| 86 } // namespace views | 108 } // namespace views |
| 87 | 109 |
| 88 #endif // UI_VIEWS_ANIMATION_INK_DROP_HOST_VIEW_H_ | 110 #endif // UI_VIEWS_ANIMATION_INK_DROP_HOST_VIEW_H_ |
| OLD | NEW |