OLD | NEW |
---|---|
(Empty) | |
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. | |
4 | |
5 #include "aura/window.h" | |
6 | |
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" | |
12 | |
13 namespace aura { | |
14 | |
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) { | |
23 } | |
24 | |
25 Window::~Window() { | |
26 } | |
27 | |
28 void Window::SetVisibility(Visibility visibility) { | |
29 if (visibility_ == visibility) | |
30 return; | |
31 | |
32 visibility_ = visibility; | |
33 if (visibility_ == VISIBILITY_SHOWN) { | |
34 // TODO: move to top of window stack? | |
35 desktop_->Show(this); | |
36 } else { | |
37 // TODO: hide? | |
38 desktop_->Hide(this); | |
39 } | |
40 } | |
41 | |
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_->set_bounds(bounds); | |
47 } | |
48 | |
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); | |
54 } | |
55 | |
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); | |
62 } | |
63 | |
64 void Window::Draw() { | |
65 if (visibility_ != VISIBILITY_HIDDEN) | |
66 layer_->Draw(); | |
67 } | |
68 | |
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()); | |
73 } | |
74 gfx::Rect dirty_rect = dirty_rect_.Intersect( | |
Daniel Erat
2011/07/28 23:00:37
is this Intersect() here to handle a case where |d
sky
2011/07/29 15:42:23
Exactly.
| |
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); | |
81 } | |
82 | |
83 } // namespace aura | |
OLD | NEW |