image_window_delegate.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // Copyright (c) 2013 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_AURA_EXTRA_IMAGE_WINDOW_DELEGATE_H_
  5. #define UI_AURA_EXTRA_IMAGE_WINDOW_DELEGATE_H_
  6. #include "third_party/skia/include/core/SkColor.h"
  7. #include "ui/aura/window_delegate.h"
  8. #include "ui/aura_extra/aura_extra_export.h"
  9. #include "ui/gfx/geometry/size.h"
  10. #include "ui/gfx/geometry/vector2d.h"
  11. #include "ui/gfx/image/image.h"
  12. namespace aura_extra {
  13. // An ImageWindowDelegate paints an image for a Window. If there is uncovered
  14. // area, it also fills the window with a background color when specified.
  15. // The delegate does not consume any event.
  16. //
  17. // The delegate destroys itself when the Window is destroyed. This is done in
  18. // |OnWindowDestroyed()| function which subclasses can override to prevent
  19. // self-destroying.
  20. class AURA_EXTRA_EXPORT ImageWindowDelegate : public aura::WindowDelegate {
  21. public:
  22. ImageWindowDelegate();
  23. ImageWindowDelegate(const ImageWindowDelegate&) = delete;
  24. ImageWindowDelegate& operator=(const ImageWindowDelegate&) = delete;
  25. void SetImage(const gfx::Image& image);
  26. void set_background_color(SkColor color) { background_color_ = color; }
  27. void set_image_offset(const gfx::Vector2d& offset) { offset_ = offset; }
  28. bool has_image() const { return !image_.IsEmpty(); }
  29. protected:
  30. ~ImageWindowDelegate() override;
  31. // Overridden from aura::WindowDelegate:
  32. gfx::Size GetMinimumSize() const override;
  33. gfx::Size GetMaximumSize() const override;
  34. void OnBoundsChanged(const gfx::Rect& old_bounds,
  35. const gfx::Rect& new_bounds) override;
  36. gfx::NativeCursor GetCursor(const gfx::Point& point) override;
  37. int GetNonClientComponent(const gfx::Point& point) const override;
  38. bool ShouldDescendIntoChildForEventHandling(
  39. aura::Window* child,
  40. const gfx::Point& location) override;
  41. bool CanFocus() override;
  42. void OnCaptureLost() override;
  43. void OnPaint(const ui::PaintContext& context) override;
  44. void OnDeviceScaleFactorChanged(float old_device_scale_factor,
  45. float new_device_scale_factor) override;
  46. void OnWindowDestroying(aura::Window* window) override;
  47. void OnWindowDestroyed(aura::Window* window) override;
  48. void OnWindowTargetVisibilityChanged(bool visible) override;
  49. bool HasHitTestMask() const override;
  50. void GetHitTestMask(SkPath* mask) const override;
  51. protected:
  52. SkColor background_color_ = SK_ColorTRANSPARENT;
  53. gfx::Image image_;
  54. gfx::Vector2d offset_;
  55. gfx::Size window_size_;
  56. // Keeps track of whether the window size matches the image size or not. If
  57. // the image size is smaller than the window size, then the delegate fills the
  58. // missing regions with |background_color_| (default is transparent).
  59. bool size_mismatch_ = false;
  60. };
  61. } // namespace aura_extra
  62. #endif // UI_AURA_EXTRA_IMAGE_WINDOW_DELEGATE_H_