notification_manager.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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_KEYBOARD_UI_NOTIFICATION_MANAGER_H_
  5. #define ASH_KEYBOARD_UI_NOTIFICATION_MANAGER_H_
  6. #include "ash/keyboard/ui/keyboard_export.h"
  7. #include "base/observer_list.h"
  8. #include "ui/gfx/geometry/rect.h"
  9. namespace ash {
  10. class KeyboardControllerObserver;
  11. }
  12. namespace keyboard {
  13. template <typename T>
  14. class ValueNotificationConsolidator {
  15. public:
  16. explicit ValueNotificationConsolidator(const T& initial_value);
  17. bool ShouldSendNotification(const T& new_value);
  18. private:
  19. T value_;
  20. };
  21. // Logic for consolidating consecutive identical notifications from the
  22. // KeyboardControllerObserver.
  23. class KEYBOARD_EXPORT NotificationManager {
  24. public:
  25. NotificationManager();
  26. // Sends various KeyboardControllerObserver notifications related to bounds
  27. // changes:
  28. // - visual bounds change
  29. // - occluded bounds change
  30. // - layout displacement bounds change
  31. // - general visibility change
  32. void SendNotifications(
  33. bool does_occluded_bounds_affect_layout,
  34. const gfx::Rect& visual_bounds,
  35. const gfx::Rect& occluded_bounds,
  36. const base::ObserverList<ash::KeyboardControllerObserver>::Unchecked&
  37. observers);
  38. bool ShouldSendVisibilityNotification(bool current_visibility);
  39. bool ShouldSendVisualBoundsNotification(const gfx::Rect& new_bounds);
  40. bool ShouldSendOccludedBoundsNotification(const gfx::Rect& new_bounds);
  41. bool ShouldSendWorkspaceDisplacementBoundsNotification(
  42. const gfx::Rect& new_bounds);
  43. private:
  44. // ValueNotificationConsolidator uses == for comparison, but empty rectangles
  45. // ought to be considered equal regardless of location or non-zero dimensions.
  46. // This method will return a default empty (0,0,0,0) rectangle for any 0-area
  47. // rectangle, otherwise it returns the original rectangle, unmodified.
  48. gfx::Rect CanonicalizeEmptyRectangles(const gfx::Rect& rect) const;
  49. ValueNotificationConsolidator<bool> visibility_;
  50. ValueNotificationConsolidator<gfx::Rect> visual_bounds_;
  51. ValueNotificationConsolidator<gfx::Rect> occluded_bounds_;
  52. ValueNotificationConsolidator<gfx::Rect> workspace_displaced_bounds_;
  53. };
  54. } // namespace keyboard
  55. #endif // ASH_KEYBOARD_UI_NOTIFICATION_MANAGER_H_