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 #include "content/browser/web_contents/aura/image_window_delegate.h" 6 7 #include "ui/base/hit_test.h" 8 #include "ui/compositor/compositor.h" 9 #include "ui/gfx/canvas.h" 10 #include "ui/gfx/image/image.h" 11 #include "ui/gfx/image/image_skia.h" 12 #include "ui/gfx/rect.h" 13 #include "ui/gfx/size.h" 14 15 namespace content { 16 17 ImageWindowDelegate::ImageWindowDelegate() 18 : size_mismatch_(false) { 19 } 20 21 ImageWindowDelegate::~ImageWindowDelegate() { 22 } 23 24 void ImageWindowDelegate::SetImage(const gfx::Image& image) { 25 image_ = image; 26 if (!window_size_.IsEmpty() && !image_.IsEmpty()) 27 size_mismatch_ = window_size_ != image_.AsImageSkia().size(); 28 } 29 30 gfx::Size ImageWindowDelegate::GetMinimumSize() const { 31 return gfx::Size(); 32 } 33 34 gfx::Size ImageWindowDelegate::GetMaximumSize() const { 35 return gfx::Size(); 36 } 37 38 void ImageWindowDelegate::OnBoundsChanged(const gfx::Rect& old_bounds, 39 const gfx::Rect& new_bounds) { 40 window_size_ = new_bounds.size(); 41 if (!image_.IsEmpty()) 42 size_mismatch_ = window_size_ != image_.AsImageSkia().size(); 43 } 44 45 gfx::NativeCursor ImageWindowDelegate::GetCursor(const gfx::Point& point) { 46 return gfx::kNullCursor; 47 } 48 49 int ImageWindowDelegate::GetNonClientComponent(const gfx::Point& point) const { 50 return HTNOWHERE; 51 } 52 53 bool ImageWindowDelegate::ShouldDescendIntoChildForEventHandling( 54 aura::Window* child, 55 const gfx::Point& location) { 56 return false; 57 } 58 59 bool ImageWindowDelegate::CanFocus() { 60 return false; 61 } 62 63 void ImageWindowDelegate::OnCaptureLost() { 64 } 65 66 void ImageWindowDelegate::OnPaint(gfx::Canvas* canvas) { 67 if (image_.IsEmpty()) { 68 canvas->DrawColor(SK_ColorGRAY); 69 } else { 70 if (size_mismatch_) 71 canvas->DrawColor(SK_ColorWHITE); 72 canvas->DrawImageInt(image_.AsImageSkia(), 0, 0); 73 } 74 } 75 76 void ImageWindowDelegate::OnDeviceScaleFactorChanged(float scale_factor) { 77 } 78 79 void ImageWindowDelegate::OnWindowDestroying() { 80 } 81 82 void ImageWindowDelegate::OnWindowDestroyed() { 83 delete this; 84 } 85 86 void ImageWindowDelegate::OnWindowTargetVisibilityChanged(bool visible) { 87 } 88 89 bool ImageWindowDelegate::HasHitTestMask() const { 90 return false; 91 } 92 93 void ImageWindowDelegate::GetHitTestMask(gfx::Path* mask) const { 94 } 95 96 scoped_refptr<ui::Texture> ImageWindowDelegate::CopyTexture() { 97 return scoped_refptr<ui::Texture>(); 98 } 99 100 } // namespace content 101