image_window_delegate.h revision 5d1f7b1de12d16ceb2c938c56701a3e8bfa558f7
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
5#ifndef CONTENT_BROWSER_WEB_CONTENTS_AURA_IMAGE_WINDOW_DELEGATE_H_
6#define CONTENT_BROWSER_WEB_CONTENTS_AURA_IMAGE_WINDOW_DELEGATE_H_
7
8#include "content/common/content_export.h"
9#include "ui/aura/window_delegate.h"
10#include "ui/gfx/image/image.h"
11#include "ui/gfx/size.h"
12
13namespace content {
14
15// An ImageWindowDelegate paints an image for a Window. The delegate destroys
16// itself when the Window is destroyed. The delegate does not consume any event.
17class CONTENT_EXPORT ImageWindowDelegate : public aura::WindowDelegate {
18 public:
19  ImageWindowDelegate();
20
21  void SetImage(const gfx::Image& image);
22  bool has_image() const { return !image_.IsEmpty(); }
23
24 protected:
25  virtual ~ImageWindowDelegate();
26
27  // Overridden from aura::WindowDelegate:
28  virtual gfx::Size GetMinimumSize() const OVERRIDE;
29  virtual gfx::Size GetMaximumSize() const OVERRIDE;
30  virtual void OnBoundsChanged(const gfx::Rect& old_bounds,
31                               const gfx::Rect& new_bounds) OVERRIDE;
32  virtual gfx::NativeCursor GetCursor(const gfx::Point& point) OVERRIDE;
33  virtual int GetNonClientComponent(const gfx::Point& point) const OVERRIDE;
34  virtual bool ShouldDescendIntoChildForEventHandling(
35      aura::Window* child,
36      const gfx::Point& location) OVERRIDE;
37  virtual bool CanFocus() OVERRIDE;
38  virtual void OnCaptureLost() OVERRIDE;
39  virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
40  virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE;
41  virtual void OnWindowDestroying() OVERRIDE;
42  virtual void OnWindowDestroyed() OVERRIDE;
43  virtual void OnWindowTargetVisibilityChanged(bool visible) OVERRIDE;
44  virtual bool HasHitTestMask() const OVERRIDE;
45  virtual void GetHitTestMask(gfx::Path* mask) const OVERRIDE;
46  virtual void DidRecreateLayer(ui::Layer* old_layer,
47                                ui::Layer* new_layer) OVERRIDE;
48
49 protected:
50  gfx::Image image_;
51  gfx::Size window_size_;
52
53  // Keeps track of whether the window size matches the image size or not. If
54  // the image size is smaller than the window size, then the delegate paints a
55  // white background for the missing regions.
56  bool size_mismatch_;
57
58  DISALLOW_COPY_AND_ASSIGN(ImageWindowDelegate);
59};
60
61}  // namespace content
62
63#endif  // CONTENT_BROWSER_WEB_CONTENTS_AURA_IMAGE_WINDOW_DELEGATE_H_
64