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.
5 #include "ui/aura_extra/image_window_delegate.h"
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/geometry/rect.h"
12 #include "ui/gfx/geometry/size.h"
13 #include "ui/gfx/image/image.h"
14 #include "ui/gfx/image/image_skia.h"
16 namespace aura_extra
{
18 ImageWindowDelegate::ImageWindowDelegate()
19 : background_color_(SK_ColorWHITE
),
20 size_mismatch_(false) {
23 ImageWindowDelegate::~ImageWindowDelegate() {
26 void ImageWindowDelegate::SetImage(const gfx::Image
& image
) {
28 if (!window_size_
.IsEmpty() && !image_
.IsEmpty())
29 size_mismatch_
= window_size_
!= image_
.AsImageSkia().size();
32 gfx::Size
ImageWindowDelegate::GetMinimumSize() const {
36 gfx::Size
ImageWindowDelegate::GetMaximumSize() const {
40 void ImageWindowDelegate::OnBoundsChanged(const gfx::Rect
& old_bounds
,
41 const gfx::Rect
& new_bounds
) {
42 window_size_
= new_bounds
.size();
43 if (!image_
.IsEmpty())
44 size_mismatch_
= window_size_
!= image_
.AsImageSkia().size();
47 ui::TextInputClient
* ImageWindowDelegate::GetFocusedTextInputClient() {
51 gfx::NativeCursor
ImageWindowDelegate::GetCursor(const gfx::Point
& point
) {
52 return gfx::kNullCursor
;
55 int ImageWindowDelegate::GetNonClientComponent(const gfx::Point
& point
) const {
59 bool ImageWindowDelegate::ShouldDescendIntoChildForEventHandling(
61 const gfx::Point
& location
) {
65 bool ImageWindowDelegate::CanFocus() {
69 void ImageWindowDelegate::OnCaptureLost() {
72 void ImageWindowDelegate::OnPaint(gfx::Canvas
* canvas
) {
73 if (background_color_
!= SK_ColorTRANSPARENT
&&
74 (image_
.IsEmpty() || size_mismatch_
|| !offset_
.IsZero())) {
75 canvas
->DrawColor(background_color_
);
77 if (!image_
.IsEmpty())
78 canvas
->DrawImageInt(image_
.AsImageSkia(), offset_
.x(), offset_
.y());
81 void ImageWindowDelegate::OnDeviceScaleFactorChanged(float scale_factor
) {
84 void ImageWindowDelegate::OnWindowDestroying(aura::Window
* window
) {
87 void ImageWindowDelegate::OnWindowDestroyed(aura::Window
* window
) {
91 void ImageWindowDelegate::OnWindowTargetVisibilityChanged(bool visible
) {
94 bool ImageWindowDelegate::HasHitTestMask() const {
98 void ImageWindowDelegate::GetHitTestMask(gfx::Path
* mask
) const {
101 } // namespace aura_extra