image_window_delegate.cc 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#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
15namespace content {
16
17ImageWindowDelegate::ImageWindowDelegate()
18    : size_mismatch_(false) {
19}
20
21ImageWindowDelegate::~ImageWindowDelegate() {
22}
23
24void 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
30gfx::Size ImageWindowDelegate::GetMinimumSize() const {
31  return gfx::Size();
32}
33
34gfx::Size ImageWindowDelegate::GetMaximumSize() const {
35  return gfx::Size();
36}
37
38void 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
45gfx::NativeCursor ImageWindowDelegate::GetCursor(const gfx::Point& point) {
46  return gfx::kNullCursor;
47}
48
49int ImageWindowDelegate::GetNonClientComponent(const gfx::Point& point) const {
50  return HTNOWHERE;
51}
52
53bool ImageWindowDelegate::ShouldDescendIntoChildForEventHandling(
54    aura::Window* child,
55    const gfx::Point& location) {
56  return false;
57}
58
59bool ImageWindowDelegate::CanFocus() {
60  return false;
61}
62
63void ImageWindowDelegate::OnCaptureLost() {
64}
65
66void 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
76void ImageWindowDelegate::OnDeviceScaleFactorChanged(float scale_factor) {
77}
78
79void ImageWindowDelegate::OnWindowDestroying() {
80}
81
82void ImageWindowDelegate::OnWindowDestroyed() {
83  delete this;
84}
85
86void ImageWindowDelegate::OnWindowTargetVisibilityChanged(bool visible) {
87}
88
89bool ImageWindowDelegate::HasHitTestMask() const {
90  return false;
91}
92
93void ImageWindowDelegate::GetHitTestMask(gfx::Path* mask) const {
94}
95
96void ImageWindowDelegate::DidRecreateLayer(ui::Layer *old_layer,
97                                           ui::Layer *new_layer) {
98}
99
100}  // namespace content
101