Updating trunk VERSION from 848.0 to 849.0
[chromium-blink-merge.git] / aura / window.cc
blob7725ffcbabf653b5b1c5aae7def208cb594d7209
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"
13 namespace aura {
15 // TODO: do we need to support child windows?
16 Window::Window(Desktop* desktop)
17 : desktop_(desktop),
18 delegate_(NULL),
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) {
25 Window::~Window() {
28 void Window::SetVisibility(Visibility visibility) {
29 if (visibility_ == visibility)
30 return;
32 visibility_ = visibility;
33 if (visibility_ == VISIBILITY_SHOWN) {
34 // TODO: move to top of window stack?
35 desktop_->AddWindow(this);
36 } else {
37 // TODO: hide?
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.
45 bounds_ = bounds;
46 layer_->SetBounds(bounds);
49 void Window::SchedulePaint(const gfx::Rect& bounds) {
50 if (dirty_rect_.IsEmpty())
51 dirty_rect_ = bounds;
52 else
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
60 // the texture.
61 layer_->SetCanvas(canvas, origin);
64 void Window::Draw() {
65 if (visibility_ != VISIBILITY_HIDDEN)
66 layer_->Draw();
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())
78 return;
79 if (delegate_)
80 delegate_->OnPaint(dirty_rect);
83 } // namespace aura