resize_shadow_controller.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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_CONTROLLER_H_
  5. #define ASH_WM_RESIZE_SHADOW_CONTROLLER_H_
  6. #include "ash/ash_export.h"
  7. #include "base/containers/flat_map.h"
  8. #include "base/scoped_multi_source_observation.h"
  9. #include "ui/aura/window.h"
  10. #include "ui/aura/window_observer.h"
  11. #include "ui/base/hit_test.h"
  12. #include "ui/gfx/color_palette.h"
  13. namespace ash {
  14. class ResizeShadow;
  15. enum class ResizeShadowType;
  16. // ResizeShadowController observes changes to resizable windows and shows
  17. // a resize handle visual effect when the cursor is near the edges.
  18. class ASH_EXPORT ResizeShadowController : public aura::WindowObserver {
  19. public:
  20. ResizeShadowController();
  21. ResizeShadowController(const ResizeShadowController&) = delete;
  22. ResizeShadowController& operator=(const ResizeShadowController&) = delete;
  23. ~ResizeShadowController() override;
  24. // Shows the appropriate shadow for a given |window| and |hit_test| location.
  25. // If the |window| is invisible, the shadow will not shown.
  26. void ShowShadow(aura::Window* window, int hit_test = HTNOWHERE);
  27. // Shows all shadows.
  28. void TryShowAllShadows();
  29. // Hides the shadow for a |window|, if it has one.
  30. void HideShadow(aura::Window* window);
  31. // Hides all shadows.
  32. void HideAllShadows();
  33. // aura::WindowObserver:
  34. void OnWindowHierarchyChanged(const HierarchyChangeParams& params) override;
  35. void OnWindowVisibilityChanging(aura::Window* window, bool visible) override;
  36. void OnWindowBoundsChanged(aura::Window* window,
  37. const gfx::Rect& old_bounds,
  38. const gfx::Rect& new_bounds,
  39. ui::PropertyChangeReason reason) override;
  40. void OnWindowStackingChanged(aura::Window* window) override;
  41. void OnWindowDestroying(aura::Window* window) override;
  42. void OnWindowPropertyChanged(aura::Window* window,
  43. const void* key,
  44. intptr_t old) override;
  45. void UpdateResizeShadowBoundsOfWindow(aura::Window* window,
  46. const gfx::Rect& bounds);
  47. ResizeShadow* GetShadowForWindowForTest(aura::Window* window);
  48. private:
  49. // Removes all shadows.
  50. void RemoveAllShadows();
  51. // Recreates a shadow for a given |window| and the type from the |window|'s
  52. // property if there's no shadow registered or it has one but its type is
  53. // different. |window_shadows_| owns the memory.
  54. void RecreateShadowIfNeeded(aura::Window* window);
  55. // Returns the resize shadow for |window| or NULL if no shadow exists.
  56. ResizeShadow* GetShadowForWindow(aura::Window* window) const;
  57. // Update shadow visibility for a given |window|.
  58. void UpdateShadowVisibility(aura::Window* window, bool visible) const;
  59. bool ShouldShowShadowForWindow(aura::Window* window) const;
  60. base::flat_map<aura::Window*, std::unique_ptr<ResizeShadow>> window_shadows_;
  61. base::ScopedMultiSourceObservation<aura::Window, aura::WindowObserver>
  62. windows_observation_{this};
  63. };
  64. } // namespace ash
  65. #endif // ASH_WM_RESIZE_SHADOW_CONTROLLER_H_