window_backdrop.h 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. // Copyright 2020 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_PUBLIC_CPP_WINDOW_BACKDROP_H_
  5. #define ASH_PUBLIC_CPP_WINDOW_BACKDROP_H_
  6. #include "ash/public/cpp/ash_public_export.h"
  7. #include "base/observer_list.h"
  8. #include "third_party/skia/include/core/SkColor.h"
  9. namespace aura {
  10. class Window;
  11. }
  12. namespace ash {
  13. // The window backdrop property that associates with a window. It's owned by
  14. // a window through its kWindowBackdropKey property. It's not supposed to
  15. // manually clear the kWindowBackdropKey property, as WindowBackdrop::Get()
  16. // will create a new one as soon as it's called. If you want to modify the
  17. // window's backdrop, please do so by modifying its mode/type value to achieve
  18. // that.
  19. class ASH_PUBLIC_EXPORT WindowBackdrop {
  20. public:
  21. enum class BackdropMode {
  22. kAuto, // The window manager decides if the window should have a backdrop.
  23. kEnabled, // The window should always have a backdrop.
  24. kDisabled, // The window should never have a backdrop.
  25. };
  26. enum class BackdropType {
  27. kOpaque, // The backdrop is fully-opaque black
  28. kSemiOpaque, // The backdrop is semi-opaque black
  29. };
  30. class Observer : public base::CheckedObserver {
  31. public:
  32. virtual void OnWindowBackdropPropertyChanged(aura::Window* window) {}
  33. };
  34. explicit WindowBackdrop(aura::Window* window);
  35. ~WindowBackdrop();
  36. // Returns the WindowBackdrop for |window|. The returned value is owned by
  37. // |window|.
  38. static WindowBackdrop* Get(aura::Window* window);
  39. BackdropMode mode() const { return mode_; }
  40. BackdropType type() const { return type_; }
  41. bool temporarily_disabled() const { return temporarily_disabled_; }
  42. void SetBackdropMode(BackdropMode mode);
  43. void SetBackdropType(BackdropType type);
  44. // Disable the backdrop on the window. However, the backdrop mode and type can
  45. // still be modified even when backdrop is disabled but will have no effect on
  46. // the backdrop. After backdrop is re-enabled, the mode and type will take
  47. // effect again.
  48. void DisableBackdrop();
  49. void RestoreBackdrop();
  50. // Returns the backdrop color according to its type.
  51. SkColor GetBackdropColor() const;
  52. void AddObserver(Observer* observer);
  53. void RemoveObserver(Observer* observer);
  54. private:
  55. WindowBackdrop(const WindowBackdrop&) = delete;
  56. WindowBackdrop& operator=(const WindowBackdrop&) = delete;
  57. void NotifyWindowBackdropPropertyChanged();
  58. // The window that this WindowBackdrop associates with. Will be valid during
  59. // this WindowBackdrop's lifetime.
  60. aura::Window* window_;
  61. BackdropMode mode_ = BackdropMode::kAuto;
  62. BackdropType type_ = BackdropType::kOpaque;
  63. // When this variable is true, the window backdrop is temporarily disabled
  64. // and changing its backdrop setting above (mode/type) will not have any
  65. // effect. Only when this variable is reset back to false, the window can have
  66. // its customized backdrop setting.
  67. // This can be useful when we need to disable window backdrop temporarily
  68. // during e.g. window dragging or window animation.
  69. bool temporarily_disabled_ = false;
  70. base::ObserverList<Observer> observers_;
  71. };
  72. } // namespace ash
  73. #endif // ASH_PUBLIC_CPP_WINDOW_BACKDROP_H_