view_observer.h 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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
  3. // found in the LICENSE file.
  4. #ifndef UI_VIEWS_VIEW_OBSERVER_H_
  5. #define UI_VIEWS_VIEW_OBSERVER_H_
  6. #include "ui/views/views_export.h"
  7. namespace views {
  8. class View;
  9. struct ViewHierarchyChangedDetails;
  10. // ViewObserver is used to observe changes to a View. The first argument to all
  11. // ViewObserver functions is the View the observer was added to.
  12. class VIEWS_EXPORT ViewObserver {
  13. public:
  14. // Called when |child| is added as a child to |observed_view|.
  15. virtual void OnChildViewAdded(View* observed_view, View* child) {}
  16. // Called when |child| is removed as a child of |observed_view|.
  17. virtual void OnChildViewRemoved(View* observed_view, View* child) {}
  18. // Called when |observed_view|, an ancestor, or its Widget has its visibility
  19. // changed. |starting_view| is who |View::SetVisible()| was called on (or null
  20. // if the Widget visibility changed).
  21. virtual void OnViewVisibilityChanged(View* observed_view,
  22. View* starting_view) {}
  23. // Called from View::PreferredSizeChanged().
  24. virtual void OnViewPreferredSizeChanged(View* observed_view) {}
  25. // Called when the bounds of |observed_view| change.
  26. virtual void OnViewBoundsChanged(View* observed_view) {}
  27. // Called when the bounds of |observed_view|'s layer change.
  28. virtual void OnLayerTargetBoundsChanged(View* observed_view) {}
  29. // Called when the `observed_view`'s layer transform changes.
  30. // TODO(crbug.com/1203386): This is temporarily added to support a migration.
  31. // Do not use for new call sites, we should instead figure out how to
  32. // migrate this method (and possibly others) into callbacks.
  33. virtual void OnViewLayerTransformed(View* observed_view) {}
  34. // Called when `observed_view`'s layer clip rect changes.
  35. virtual void OnViewLayerClipRectChanged(View* observed_view) {}
  36. // Called when View::ViewHierarchyChanged() is called.
  37. virtual void OnViewHierarchyChanged(
  38. View* observed_view,
  39. const ViewHierarchyChangedDetails& details) {}
  40. // Called when View::AddedToWidget() is called.
  41. virtual void OnViewAddedToWidget(View* observed_view) {}
  42. // Called when View::RemovedFromWidget() is called.
  43. virtual void OnViewRemovedFromWidget(View* observed_view) {}
  44. // Called when a child is reordered among its siblings, specifically
  45. // View::ReorderChildView() is called on |observed_view|.
  46. virtual void OnChildViewReordered(View* observed_view, View* child) {}
  47. // Called when the active UI theme or NativeTheme has changed for
  48. // |observed_view|.
  49. virtual void OnViewThemeChanged(View* observed_view) {}
  50. // Called from ~View.
  51. virtual void OnViewIsDeleting(View* observed_view) {}
  52. // Called immediately after |observed_view| has gained focus.
  53. virtual void OnViewFocused(View* observed_view) {}
  54. // Called immediately after |observed_view| has lost focus.
  55. virtual void OnViewBlurred(View* observed_view) {}
  56. protected:
  57. virtual ~ViewObserver() = default;
  58. };
  59. } // namespace views
  60. #endif // UI_VIEWS_VIEW_OBSERVER_H_