wallpaper_view.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. // Copyright (c) 2012 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_WALLPAPER_WALLPAPER_VIEW_H_
  5. #define ASH_WALLPAPER_WALLPAPER_VIEW_H_
  6. #include "ash/wallpaper/wallpaper_base_view.h"
  7. #include "ash/wallpaper/wallpaper_constants.h"
  8. #include "ui/views/context_menu_controller.h"
  9. namespace aura {
  10. class Window;
  11. }
  12. namespace ash {
  13. // The desktop wallpaper view that, in addition to painting the wallpaper, can
  14. // also add blur and dimming effects, as well as handle context menu requests.
  15. class WallpaperView : public WallpaperBaseView,
  16. public views::ContextMenuController {
  17. public:
  18. explicit WallpaperView(float blur_sigma);
  19. WallpaperView(const WallpaperView&) = delete;
  20. WallpaperView& operator=(const WallpaperView&) = delete;
  21. ~WallpaperView() override;
  22. // Clears cached image. Must be called when wallpaper image is changed.
  23. void ClearCachedImage();
  24. // Enables/Disables the lock shield layer.
  25. void SetLockShieldEnabled(bool enabled);
  26. void set_blur_sigma(float blur_sigma) { blur_sigma_ = blur_sigma; }
  27. float blur_sigma() const { return blur_sigma_; }
  28. views::View* shield_view_for_testing() { return shield_view_; }
  29. private:
  30. // views::View:
  31. const char* GetClassName() const override;
  32. bool OnMousePressed(const ui::MouseEvent& event) override;
  33. void OnBoundsChanged(const gfx::Rect& previous_bounds) override;
  34. // views::ContextMenuController:
  35. void ShowContextMenuForViewImpl(views::View* source,
  36. const gfx::Point& point,
  37. ui::MenuSourceType source_type) override;
  38. // WallpaperBaseView:
  39. void DrawWallpaper(const gfx::ImageSkia& wallpaper,
  40. const gfx::Rect& src,
  41. const gfx::Rect& dst,
  42. const cc::PaintFlags& flags,
  43. gfx::Canvas* canvas) override;
  44. // Blur sigma to draw wallpaper.
  45. float blur_sigma_ = wallpaper_constants::kClear;
  46. // A view to hold solid color layer to hide desktop, in case compositor
  47. // failed to draw its content due to memory shortage.
  48. views::View* shield_view_ = nullptr;
  49. // A cached downsampled image of the wallpaper image. It will help wallpaper
  50. // blur/brightness animations be more performant.
  51. absl::optional<gfx::ImageSkia> small_image_;
  52. };
  53. std::unique_ptr<views::Widget> CreateWallpaperWidget(
  54. aura::Window* root_window,
  55. float blur_sigma,
  56. bool locked,
  57. WallpaperView** out_wallpaper_view);
  58. } // namespace ash
  59. #endif // ASH_WALLPAPER_WALLPAPER_VIEW_H_