summaryrefslogtreecommitdiffstats
path: root/ui/aura_extra/image_window_delegate.h
blob: ea36cd978575f56322e1c1ec29ec48e1f3302de8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef UI_AURA_EXTRA_IMAGE_WINDOW_DELEGATE_H_
#define UI_AURA_EXTRA_IMAGE_WINDOW_DELEGATE_H_

#include "third_party/skia/include/core/SkColor.h"
#include "ui/aura/window_delegate.h"
#include "ui/aura_extra/aura_extra_export.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/geometry/vector2d.h"
#include "ui/gfx/image/image.h"

namespace aura_extra {

// An ImageWindowDelegate paints an image for a Window, possibly also filling
// the window with a specified backround color. The delegate does not consume
// any event.
//
// The delegate destroys itself when the Window is destroyed. This is done in
// |OnWindowDestroyed()| function which subclasses can override to prevent
// self-destroying.
class AURA_EXTRA_EXPORT ImageWindowDelegate : public aura::WindowDelegate {
 public:
  ImageWindowDelegate();

  void SetImage(const gfx::Image& image);

  void set_background_color(SkColor color) { background_color_ = color; }
  void set_image_offset(gfx::Vector2d offset) { offset_ = offset; }

  bool has_image() const { return !image_.IsEmpty(); }

 protected:
  ~ImageWindowDelegate() override;

  // Overridden from aura::WindowDelegate:
  gfx::Size GetMinimumSize() const override;
  gfx::Size GetMaximumSize() const override;
  void OnBoundsChanged(const gfx::Rect& old_bounds,
                       const gfx::Rect& new_bounds) override;
  ui::TextInputClient* GetFocusedTextInputClient() override;
  gfx::NativeCursor GetCursor(const gfx::Point& point) override;
  int GetNonClientComponent(const gfx::Point& point) const override;
  bool ShouldDescendIntoChildForEventHandling(
      aura::Window* child,
      const gfx::Point& location) override;
  bool CanFocus() override;
  void OnCaptureLost() override;
  void OnPaint(gfx::Canvas* canvas) override;
  void OnDeviceScaleFactorChanged(float device_scale_factor) override;
  void OnWindowDestroying(aura::Window* window) override;
  void OnWindowDestroyed(aura::Window* window) override;
  void OnWindowTargetVisibilityChanged(bool visible) override;
  bool HasHitTestMask() const override;
  void GetHitTestMask(gfx::Path* mask) const override;

 protected:
  SkColor background_color_;
  gfx::Image image_;
  gfx::Vector2d offset_;

  gfx::Size window_size_;

  // Keeps track of whether the window size matches the image size or not. If
  // the image size is smaller than the window size, then the delegate fills the
  // missing regions with |background_color_| (defult is white).
  bool size_mismatch_;

  DISALLOW_COPY_AND_ASSIGN(ImageWindowDelegate);
};

}  // namespace aura_extra

#endif  // UI_AURA_EXTRA_IMAGE_WINDOW_DELEGATE_H_