window_position_in_root_monitor.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // Copyright 2018 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 UI_AURA_EXTRA_WINDOW_POSITION_IN_ROOT_MONITOR_H_
  5. #define UI_AURA_EXTRA_WINDOW_POSITION_IN_ROOT_MONITOR_H_
  6. #include <vector>
  7. #include "base/callback.h"
  8. #include "ui/aura/window_observer.h"
  9. #include "ui/aura_extra/aura_extra_export.h"
  10. namespace aura_extra {
  11. // WindowPositionInRootMonitor notifies a callback any time the position of a
  12. // window, relative to the root, changes. Changes are only sent when attached
  13. // to a valid root.
  14. class AURA_EXTRA_EXPORT WindowPositionInRootMonitor
  15. : public aura::WindowObserver {
  16. public:
  17. WindowPositionInRootMonitor(aura::Window* window,
  18. base::RepeatingClosure callback);
  19. WindowPositionInRootMonitor(const WindowPositionInRootMonitor&) = delete;
  20. WindowPositionInRootMonitor& operator=(const WindowPositionInRootMonitor&) =
  21. delete;
  22. ~WindowPositionInRootMonitor() override;
  23. private:
  24. // Adds |window| and all its ancestors to |ancestors_|.
  25. void AddAncestors(aura::Window* window);
  26. // aura::WindowObserver:
  27. void OnWindowDestroyed(aura::Window* window) override;
  28. void OnWindowParentChanged(aura::Window* window,
  29. aura::Window* parent) override;
  30. void OnWindowBoundsChanged(aura::Window* window,
  31. const gfx::Rect& old_bounds,
  32. const gfx::Rect& new_bounds,
  33. ui::PropertyChangeReason reason) override;
  34. base::RepeatingClosure callback_;
  35. // The windows being watched. This contains the window supplied to the
  36. // constructor and all it's ancestors. This is empty if the window is deleted.
  37. std::vector<aura::Window*> ancestors_;
  38. };
  39. } // namespace aura_extra
  40. #endif // UI_AURA_EXTRA_WINDOW_POSITION_IN_ROOT_MONITOR_H_