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.
5 #ifndef UI_AURA_EXTRA_IMAGE_WINDOW_DELEGATE_H_
6 #define UI_AURA_EXTRA_IMAGE_WINDOW_DELEGATE_H_
8 #include "third_party/skia/include/core/SkColor.h"
9 #include "ui/aura/window_delegate.h"
10 #include "ui/aura_extra/aura_extra_export.h"
11 #include "ui/gfx/geometry/size.h"
12 #include "ui/gfx/geometry/vector2d.h"
13 #include "ui/gfx/image/image.h"
15 namespace aura_extra
{
17 // An ImageWindowDelegate paints an image for a Window, possibly also filling
18 // the window with a specified backround color. The delegate does not consume
21 // The delegate destroys itself when the Window is destroyed. This is done in
22 // |OnWindowDestroyed()| function which subclasses can override to prevent
24 class AURA_EXTRA_EXPORT ImageWindowDelegate
: public aura::WindowDelegate
{
26 ImageWindowDelegate();
28 void SetImage(const gfx::Image
& image
);
30 void set_background_color(SkColor color
) { background_color_
= color
; }
31 void set_image_offset(gfx::Vector2d offset
) { offset_
= offset
; }
33 bool has_image() const { return !image_
.IsEmpty(); }
36 ~ImageWindowDelegate() override
;
38 // Overridden from aura::WindowDelegate:
39 gfx::Size
GetMinimumSize() const override
;
40 gfx::Size
GetMaximumSize() const override
;
41 void OnBoundsChanged(const gfx::Rect
& old_bounds
,
42 const gfx::Rect
& new_bounds
) override
;
43 ui::TextInputClient
* GetFocusedTextInputClient() override
;
44 gfx::NativeCursor
GetCursor(const gfx::Point
& point
) override
;
45 int GetNonClientComponent(const gfx::Point
& point
) const override
;
46 bool ShouldDescendIntoChildForEventHandling(
48 const gfx::Point
& location
) override
;
49 bool CanFocus() override
;
50 void OnCaptureLost() override
;
51 void OnPaint(gfx::Canvas
* canvas
) override
;
52 void OnDeviceScaleFactorChanged(float device_scale_factor
) override
;
53 void OnWindowDestroying(aura::Window
* window
) override
;
54 void OnWindowDestroyed(aura::Window
* window
) override
;
55 void OnWindowTargetVisibilityChanged(bool visible
) override
;
56 bool HasHitTestMask() const override
;
57 void GetHitTestMask(gfx::Path
* mask
) const override
;
60 SkColor background_color_
;
62 gfx::Vector2d offset_
;
64 gfx::Size window_size_
;
66 // Keeps track of whether the window size matches the image size or not. If
67 // the image size is smaller than the window size, then the delegate fills the
68 // missing regions with |background_color_| (defult is white).
71 DISALLOW_COPY_AND_ASSIGN(ImageWindowDelegate
);
74 } // namespace aura_extra
76 #endif // UI_AURA_EXTRA_IMAGE_WINDOW_DELEGATE_H_