OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "aura/window.h" | 5 #include "aura/window.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "aura/desktop.h" | 9 #include "aura/desktop.h" |
10 #include "aura/window_delegate.h" | 10 #include "aura/window_delegate.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "third_party/skia/include/core/SkCanvas.h" | 12 #include "ui/gfx/canvas_skia.h" |
13 #include "ui/gfx/compositor/compositor.h" | 13 #include "ui/gfx/compositor/compositor.h" |
14 #include "ui/gfx/compositor/layer.h" | 14 #include "ui/gfx/compositor/layer.h" |
15 | 15 |
16 namespace aura { | 16 namespace aura { |
17 | 17 |
18 // TODO: do we need to support child windows? | 18 Window::Window(WindowDelegate* delegate) |
19 Window::Window(Desktop* desktop) | 19 : delegate_(delegate), |
20 : delegate_(NULL), | |
21 visibility_(VISIBILITY_HIDDEN), | 20 visibility_(VISIBILITY_HIDDEN), |
22 layer_(new ui::Layer(desktop->compositor())), | |
23 needs_paint_all_(true), | 21 needs_paint_all_(true), |
24 parent_(NULL), | 22 parent_(NULL), |
25 id_(-1) { | 23 id_(-1) { |
26 } | 24 } |
27 | 25 |
28 Window::~Window() { | 26 Window::~Window() { |
29 } | 27 } |
30 | 28 |
| 29 void Window::Init() { |
| 30 layer_.reset(new ui::Layer(Desktop::GetInstance()->compositor())); |
| 31 } |
| 32 |
31 void Window::SetVisibility(Visibility visibility) { | 33 void Window::SetVisibility(Visibility visibility) { |
32 if (visibility_ == visibility) | 34 if (visibility_ == visibility) |
33 return; | 35 return; |
34 | 36 |
35 visibility_ = visibility; | 37 visibility_ = visibility; |
36 } | 38 } |
37 | 39 |
38 void Window::SetBounds(const gfx::Rect& bounds, int anim_ms) { | 40 void Window::SetBounds(const gfx::Rect& bounds, int anim_ms) { |
39 // TODO: support anim_ms | 41 // TODO: support anim_ms |
40 // TODO: funnel this through the Desktop. | 42 // TODO: funnel this through the Desktop. |
41 bounds_ = bounds; | 43 bounds_ = bounds; |
42 layer_->SetBounds(bounds); | 44 layer_->SetBounds(bounds); |
43 } | 45 } |
44 | 46 |
45 void Window::SchedulePaint(const gfx::Rect& bounds) { | 47 void Window::SchedulePaint(const gfx::Rect& bounds) { |
46 if (dirty_rect_.IsEmpty()) | 48 if (dirty_rect_.IsEmpty()) |
47 dirty_rect_ = bounds; | 49 dirty_rect_ = bounds; |
48 else | 50 else |
49 dirty_rect_ = dirty_rect_.Union(bounds); | 51 dirty_rect_ = dirty_rect_.Union(bounds); |
50 } | 52 } |
51 | 53 |
52 void Window::SetCanvas(const SkCanvas& canvas, const gfx::Point& origin) { | 54 void Window::SetCanvas(const SkCanvas& canvas, const gfx::Point& origin) { |
53 // TODO: figure out how this is going to work when animating the layer. In | 55 // TODO: figure out how this is going to work when animating the layer. In |
54 // particular if we're animating the size then the underyling Texture is going | 56 // particular if we're animating the size then the underlying Texture is going |
55 // to be unhappy if we try to set a texture on a size bigger than the size of | 57 // to be unhappy if we try to set a texture on a size bigger than the size of |
56 // the texture. | 58 // the texture. |
57 layer_->SetCanvas(canvas, origin); | 59 layer_->SetCanvas(canvas, origin); |
58 } | 60 } |
59 | 61 |
| 62 void Window::SetParent(Window* parent) { |
| 63 if (parent) |
| 64 parent->AddChild(this); |
| 65 else |
| 66 Desktop::GetInstance()->window()->AddChild(this); |
| 67 } |
| 68 |
60 void Window::DrawTree() { | 69 void Window::DrawTree() { |
61 UpdateLayerCanvas(); | 70 UpdateLayerCanvas(); |
62 Draw(); | 71 Draw(); |
63 | 72 |
64 // First pass updates the layer bitmaps. | 73 // First pass updates the layer bitmaps. |
65 for (Windows::iterator i = children_.begin(); i != children_.end(); ++i) | 74 for (Windows::iterator i = children_.begin(); i != children_.end(); ++i) |
66 (*i)->DrawTree(); | 75 (*i)->DrawTree(); |
67 } | 76 } |
68 | 77 |
69 void Window::AddChild(Window* child) { | 78 void Window::AddChild(Window* child) { |
(...skipping 19 matching lines...) Expand all Loading... |
89 void Window::UpdateLayerCanvas() { | 98 void Window::UpdateLayerCanvas() { |
90 if (needs_paint_all_) { | 99 if (needs_paint_all_) { |
91 needs_paint_all_ = false; | 100 needs_paint_all_ = false; |
92 dirty_rect_ = gfx::Rect(0, 0, bounds().width(), bounds().height()); | 101 dirty_rect_ = gfx::Rect(0, 0, bounds().width(), bounds().height()); |
93 } | 102 } |
94 gfx::Rect dirty_rect = dirty_rect_.Intersect( | 103 gfx::Rect dirty_rect = dirty_rect_.Intersect( |
95 gfx::Rect(0, 0, bounds().width(), bounds().height())); | 104 gfx::Rect(0, 0, bounds().width(), bounds().height())); |
96 dirty_rect_.SetRect(0, 0, 0, 0); | 105 dirty_rect_.SetRect(0, 0, 0, 0); |
97 if (dirty_rect.IsEmpty()) | 106 if (dirty_rect.IsEmpty()) |
98 return; | 107 return; |
99 if (delegate_) | 108 if (delegate_) { |
100 delegate_->OnPaint(dirty_rect); | 109 scoped_ptr<gfx::Canvas> canvas(gfx::Canvas::CreateCanvas( |
| 110 dirty_rect.width(), dirty_rect.height(), false)); |
| 111 canvas->TranslateInt(dirty_rect.x(), dirty_rect.y()); |
| 112 delegate_->OnPaint(canvas.get()); |
| 113 SetCanvas(*canvas->AsCanvasSkia(), bounds().origin()); |
| 114 } |
101 } | 115 } |
102 | 116 |
103 void Window::Draw() { | 117 void Window::Draw() { |
104 if (visibility_ != VISIBILITY_HIDDEN) | 118 if (visibility_ != VISIBILITY_HIDDEN) |
105 layer_->Draw(); | 119 layer_->Draw(); |
106 } | 120 } |
107 | 121 |
108 } // namespace aura | 122 } // namespace aura |
OLD | NEW |