resize_shadow.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. // Copyright (c) 2012 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_WM_RESIZE_SHADOW_H_
  5. #define ASH_WM_RESIZE_SHADOW_H_
  6. #include <memory>
  7. #include "ash/public/cpp/resize_shadow_type.h"
  8. #include "third_party/skia/include/core/SkColor.h"
  9. #include "ui/base/hit_test.h"
  10. namespace aura {
  11. class Window;
  12. }
  13. namespace ui {
  14. class Layer;
  15. }
  16. namespace gfx {
  17. class Rect;
  18. }
  19. namespace ash {
  20. // A class to render the resize edge effect when the user moves their mouse
  21. // over a sizing edge. This is just a visual effect; the actual resize is
  22. // handled by the EventFilter.
  23. class ResizeShadow {
  24. public:
  25. // Resize shadow parameters. Default params values are unresizable window
  26. // shadow.
  27. struct InitParams {
  28. // The width of the resize shadow that appears on edge of the window.
  29. int thickness = 8;
  30. // The corner radius of the resize shadow.
  31. int shadow_corner_radius = 2;
  32. // The corner radius of the window.
  33. int window_corner_radius = 2;
  34. // The opacity of the resize shadow.
  35. float opacity = 0.5f;
  36. // The color of the resize shadow.
  37. SkColor color = SK_ColorBLACK;
  38. // Controls whether the resize shadow shall respond to hit testing or not.
  39. bool hit_test_enabled = true;
  40. int hide_duration_ms = 100;
  41. };
  42. ResizeShadow(aura::Window* window,
  43. const InitParams& params,
  44. ResizeShadowType type);
  45. ResizeShadow(const ResizeShadow&) = delete;
  46. ResizeShadow& operator=(const ResizeShadow&) = delete;
  47. ~ResizeShadow();
  48. int GetLastHitTestForTest() const { return last_hit_test_; }
  49. const ui::Layer* GetLayerForTest() const { return layer_.get(); }
  50. ResizeShadowType GetResizeShadowTypeForTest() const { return type_; }
  51. private:
  52. friend class ResizeShadowController;
  53. // Shows resize effects for one or more edges based on a |hit_test| code, such
  54. // as HTRIGHT or HTBOTTOMRIGHT.
  55. void ShowForHitTest(int hit_test = HTNOWHERE);
  56. // Hides all resize effects.
  57. void Hide();
  58. // Reparents |layer_| so that it's behind the layer of |window_|.
  59. void ReparentLayer();
  60. // Updates bounds and visibility of |layer_|.
  61. void UpdateBoundsAndVisibility();
  62. void UpdateBounds(const gfx::Rect& window_bounds);
  63. // Updates the |last_hist_test_| with given |hit_test| code.
  64. void UpdateHitTest(int hit_test);
  65. // The window associated with this shadow. Guaranteed to be alive for the
  66. // lifetime of `this`.
  67. aura::Window* window_;
  68. // The layer to which the shadow is drawn. The layer is stacked beneath the
  69. // layer of |window_|.
  70. std::unique_ptr<ui::Layer> layer_;
  71. // Hit test value from last call to ShowForHitTest(). Used to prevent
  72. // repeatedly triggering the same animations for the same hit.
  73. int last_hit_test_ = HTNOWHERE;
  74. InitParams params_;
  75. // The type of the resize shadow. Used to identify variations of resize
  76. // shadow.
  77. ResizeShadowType type_;
  78. bool visible_ = false;
  79. };
  80. } // namespace ash
  81. #endif // ASH_WM_RESIZE_SHADOW_H_