expand_arrow_view.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. // Copyright 2017 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. #ifndef ASH_APP_LIST_VIEWS_EXPAND_ARROW_VIEW_H_
  5. #define ASH_APP_LIST_VIEWS_EXPAND_ARROW_VIEW_H_
  6. #include <memory>
  7. #include "ash/ash_export.h"
  8. #include "base/memory/weak_ptr.h"
  9. #include "base/timer/timer.h"
  10. #include "ui/views/controls/button/button.h"
  11. #include "ui/views/view_targeter_delegate.h"
  12. namespace gfx {
  13. class SlideAnimation;
  14. } // namespace gfx
  15. namespace ash {
  16. class AppListView;
  17. class ContentsView;
  18. // A tile item for the expand arrow on the start page.
  19. class ASH_EXPORT ExpandArrowView : public views::Button,
  20. public views::ViewTargeterDelegate {
  21. public:
  22. ExpandArrowView(ContentsView* contents_view, AppListView* app_list_view);
  23. ExpandArrowView(const ExpandArrowView&) = delete;
  24. ExpandArrowView& operator=(const ExpandArrowView&) = delete;
  25. ~ExpandArrowView() override;
  26. // views::Button:
  27. void PaintButtonContents(gfx::Canvas* canvas) override;
  28. // views::View:
  29. gfx::Size CalculatePreferredSize() const override;
  30. bool OnKeyPressed(const ui::KeyEvent& event) override;
  31. void OnFocus() override;
  32. void OnBlur() override;
  33. const char* GetClassName() const override;
  34. // Calculates vertical offset between expand arrow circle's positions with app
  35. // list view drag progress |progress| and the current app list progress
  36. // (calculated without taking app list animation state into account).
  37. float CalculateOffsetFromCurrentAppListProgress(double progress) const;
  38. void MaybeEnableHintingAnimation(bool enabled);
  39. bool IsHintingAnimationRunningForTest() {
  40. return hinting_animation_timer_.IsRunning();
  41. }
  42. private:
  43. // gfx::AnimationDelegate:
  44. void AnimationProgressed(const gfx::Animation* animation) override;
  45. void AnimationEnded(const gfx::Animation* animation) override;
  46. void OnButtonPressed();
  47. void TransitToFullscreenAllAppsState();
  48. // Schedule a hinting animation. |is_first_time| indicates whether the
  49. // animation is scheduled for the first time.
  50. void ScheduleHintingAnimation(bool is_first_time);
  51. void StartHintingAnimation();
  52. void ResetHintingAnimation();
  53. // views::ViewTargeterDelegate:
  54. bool DoesIntersectRect(const views::View* target,
  55. const gfx::Rect& rect) const override;
  56. ContentsView* const contents_view_;
  57. AppListView* const app_list_view_; // Owned by the views hierarchy.
  58. // Properties for pulse opacity and size used in animation.
  59. float pulse_opacity_;
  60. int pulse_radius_;
  61. std::unique_ptr<gfx::SlideAnimation> animation_;
  62. // Whether the expand arrow view is pressed or not. If true, animation should
  63. // be canceled.
  64. bool button_pressed_ = false;
  65. // The y position offset of the arrow in this view.
  66. int arrow_y_offset_;
  67. base::OneShotTimer hinting_animation_timer_;
  68. base::WeakPtrFactory<ExpandArrowView> weak_ptr_factory_{this};
  69. };
  70. } // namespace ash
  71. #endif // ASH_APP_LIST_VIEWS_EXPAND_ARROW_VIEW_H_