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