1 // Copyright (c) 2011 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 "aura/window.h"
7 #include "aura/desktop.h"
8 #include "aura/window_delegate.h"
9 #include "third_party/skia/include/core/SkCanvas.h"
10 #include "ui/gfx/compositor/compositor.h"
11 #include "ui/gfx/compositor/layer.h"
15 // TODO: do we need to support child windows?
16 Window::Window(Desktop
* desktop
)
19 visibility_(VISIBILITY_HIDDEN
),
20 // TODO: Need to make layers lazily create the texture.
21 layer_(new ui::Layer(desktop
->compositor())),
22 needs_paint_all_(true) {
28 void Window::SetVisibility(Visibility visibility
) {
29 if (visibility_
== visibility
)
32 visibility_
= visibility
;
33 if (visibility_
== VISIBILITY_SHOWN
) {
34 // TODO: move to top of window stack?
35 desktop_
->AddWindow(this);
38 desktop_
->RemoveWindow(this);
42 void Window::SetBounds(const gfx::Rect
& bounds
, int anim_ms
) {
43 // TODO: support anim_ms
44 // TODO: funnel this through the Desktop.
46 layer_
->SetBounds(bounds
);
49 void Window::SchedulePaint(const gfx::Rect
& bounds
) {
50 if (dirty_rect_
.IsEmpty())
53 dirty_rect_
= dirty_rect_
.Union(bounds
);
56 void Window::SetCanvas(const SkCanvas
& canvas
, const gfx::Point
& origin
) {
57 // TODO: figure out how this is going to work when animating the layer. In
58 // particular if we're animating the size then the underyling Texture is going
59 // to be unhappy if we try to set a texture on a size bigger than the size of
61 layer_
->SetCanvas(canvas
, origin
);
65 if (visibility_
!= VISIBILITY_HIDDEN
)
69 void Window::UpdateLayerCanvas() {
70 if (needs_paint_all_
) {
71 needs_paint_all_
= false;
72 dirty_rect_
= gfx::Rect(0, 0, bounds().width(), bounds().height());
74 gfx::Rect dirty_rect
= dirty_rect_
.Intersect(
75 gfx::Rect(0, 0, bounds().width(), bounds().height()));
76 dirty_rect_
.SetRect(0, 0, 0, 0);
77 if (dirty_rect
.IsEmpty())
80 delegate_
->OnPaint(dirty_rect
);