view_shadow.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // Copyright 2019 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_VIEW_SHADOW_H_
  5. #define ASH_PUBLIC_CPP_VIEW_SHADOW_H_
  6. #include <memory>
  7. #include "ash/public/cpp/ash_public_export.h"
  8. #include "ui/compositor/layer_owner.h"
  9. #include "ui/views/view_observer.h"
  10. namespace ui {
  11. class Shadow;
  12. }
  13. namespace ash {
  14. // Manages the shadow for a view. This forces |view| to paint to layer if it's
  15. // not.
  16. class ASH_PUBLIC_EXPORT ViewShadow : public views::ViewObserver,
  17. public ui::LayerOwner::Observer {
  18. public:
  19. ViewShadow(views::View* view, int elevation);
  20. ViewShadow(const ViewShadow&) = delete;
  21. ViewShadow& operator=(const ViewShadow&) = delete;
  22. ~ViewShadow() override;
  23. // Update the corner radius of the view along with the shadow.
  24. void SetRoundedCornerRadius(int corner_radius);
  25. // ui::LayerOwner::Observer:
  26. void OnLayerRecreated(ui::Layer* old_layer) override;
  27. ui::Shadow* shadow() { return shadow_.get(); }
  28. private:
  29. // views::ViewObserver:
  30. void OnLayerTargetBoundsChanged(views::View* view) override;
  31. void OnViewIsDeleting(views::View* view) override;
  32. views::View* view_;
  33. std::unique_ptr<ui::Shadow> shadow_;
  34. };
  35. } // namespace ash
  36. #endif // ASH_PUBLIC_CPP_VIEW_SHADOW_H_