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