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 "ui/aura/window.h" | 5 #include "ui/aura/window.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
12 #include "ui/aura/client/stacking_client.h" | 12 #include "ui/aura/client/stacking_client.h" |
13 #include "ui/aura/event.h" | 13 #include "ui/aura/event.h" |
14 #include "ui/aura/event_filter.h" | 14 #include "ui/aura/event_filter.h" |
15 #include "ui/aura/layout_manager.h" | 15 #include "ui/aura/layout_manager.h" |
16 #include "ui/aura/root_window.h" | 16 #include "ui/aura/root_window.h" |
17 #include "ui/aura/window_delegate.h" | 17 #include "ui/aura/window_delegate.h" |
18 #include "ui/aura/window_observer.h" | 18 #include "ui/aura/window_observer.h" |
19 #include "ui/aura/window_types.h" | 19 #include "ui/aura/window_types.h" |
20 #include "ui/base/animation/multi_animation.h" | 20 #include "ui/base/animation/multi_animation.h" |
21 #include "ui/gfx/canvas_skia.h" | 21 #include "ui/gfx/canvas_skia.h" |
22 #include "ui/gfx/compositor/compositor.h" | 22 #include "ui/gfx/compositor/compositor.h" |
23 #include "ui/gfx/screen.h" | 23 #include "ui/gfx/screen.h" |
24 | 24 |
25 namespace aura { | 25 namespace aura { |
26 | 26 |
| 27 namespace { |
| 28 |
| 29 Window* GetParentForWindow(Window* window, Window* suggested_parent) { |
| 30 if (suggested_parent) |
| 31 return suggested_parent; |
| 32 if (client::GetStackingClient()) |
| 33 return client::GetStackingClient()->GetDefaultParent(window); |
| 34 return RootWindow::GetInstance(); |
| 35 } |
| 36 |
| 37 } // namespace |
| 38 |
27 Window::Window(WindowDelegate* delegate) | 39 Window::Window(WindowDelegate* delegate) |
28 : type_(WINDOW_TYPE_UNKNOWN), | 40 : type_(WINDOW_TYPE_UNKNOWN), |
29 delegate_(delegate), | 41 delegate_(delegate), |
30 parent_(NULL), | 42 parent_(NULL), |
31 transient_parent_(NULL), | 43 transient_parent_(NULL), |
32 id_(-1), | 44 id_(-1), |
33 user_data_(NULL), | 45 user_data_(NULL), |
34 stops_event_propagation_(false), | 46 stops_event_propagation_(false), |
35 ignore_events_(false) { | 47 ignore_events_(false) { |
36 } | 48 } |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 | 158 |
147 void Window::SetCanvas(const SkCanvas& canvas, const gfx::Point& origin) { | 159 void Window::SetCanvas(const SkCanvas& canvas, const gfx::Point& origin) { |
148 // TODO: figure out how this is going to work when animating the layer. In | 160 // TODO: figure out how this is going to work when animating the layer. In |
149 // particular if we're animating the size then the underlying Texture is going | 161 // particular if we're animating the size then the underlying Texture is going |
150 // to be unhappy if we try to set a texture on a size bigger than the size of | 162 // to be unhappy if we try to set a texture on a size bigger than the size of |
151 // the texture. | 163 // the texture. |
152 layer_->SetCanvas(canvas, origin); | 164 layer_->SetCanvas(canvas, origin); |
153 } | 165 } |
154 | 166 |
155 void Window::SetParent(Window* parent) { | 167 void Window::SetParent(Window* parent) { |
156 if (parent) | 168 GetParentForWindow(this, parent)->AddChild(this); |
157 parent->AddChild(this); | |
158 else if (RootWindow::GetInstance()->stacking_client()) | |
159 RootWindow::GetInstance()->stacking_client()->AddChildToDefaultParent(this); | |
160 else | |
161 NOTREACHED(); | |
162 } | 169 } |
163 | 170 |
164 void Window::StackChildAtTop(Window* child) { | 171 void Window::StackChildAtTop(Window* child) { |
165 if (children_.size() <= 1 || child == children_.back()) | 172 if (children_.size() <= 1 || child == children_.back()) |
166 return; // In the front already. | 173 return; // In the front already. |
167 StackChildAbove(child, children_.back()); | 174 StackChildAbove(child, children_.back()); |
168 } | 175 } |
169 | 176 |
170 void Window::StackChildAbove(Window* child, Window* other) { | 177 void Window::StackChildAbove(Window* child, Window* other) { |
171 DCHECK_NE(child, other); | 178 DCHECK_NE(child, other); |
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
544 if (id_ != -1) { | 551 if (id_ != -1) { |
545 char id_buf[10]; | 552 char id_buf[10]; |
546 base::snprintf(id_buf, sizeof(id_buf), " %d", id_); | 553 base::snprintf(id_buf, sizeof(id_buf), " %d", id_); |
547 layer_name.append(id_buf); | 554 layer_name.append(id_buf); |
548 } | 555 } |
549 layer()->set_name(layer_name); | 556 layer()->set_name(layer_name); |
550 #endif | 557 #endif |
551 } | 558 } |
552 | 559 |
553 } // namespace aura | 560 } // namespace aura |
OLD | NEW |