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/desktop.h" | |
14 #include "ui/aura/event.h" | 13 #include "ui/aura/event.h" |
15 #include "ui/aura/event_filter.h" | 14 #include "ui/aura/event_filter.h" |
16 #include "ui/aura/layout_manager.h" | 15 #include "ui/aura/layout_manager.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 Window::Window(WindowDelegate* delegate) | 27 Window::Window(WindowDelegate* delegate) |
28 : type_(WINDOW_TYPE_UNKNOWN), | 28 : type_(WINDOW_TYPE_UNKNOWN), |
29 delegate_(delegate), | 29 delegate_(delegate), |
30 parent_(NULL), | 30 parent_(NULL), |
31 transient_parent_(NULL), | 31 transient_parent_(NULL), |
32 id_(-1), | 32 id_(-1), |
33 user_data_(NULL), | 33 user_data_(NULL), |
34 stops_event_propagation_(false), | 34 stops_event_propagation_(false), |
35 ignore_events_(false) { | 35 ignore_events_(false) { |
36 } | 36 } |
37 | 37 |
38 Window::~Window() { | 38 Window::~Window() { |
39 // Let the delegate know we're in the processing of destroying. | 39 // Let the delegate know we're in the processing of destroying. |
40 if (delegate_) | 40 if (delegate_) |
41 delegate_->OnWindowDestroying(); | 41 delegate_->OnWindowDestroying(); |
42 | 42 |
43 // Let the root know so that it can remove any references to us. | 43 // Let the root know so that it can remove any references to us. |
44 Desktop* desktop = GetDesktop(); | 44 RootWindow* root_window = GetRootWindow(); |
45 if (desktop) | 45 if (root_window) |
46 desktop->WindowDestroying(this); | 46 root_window->WindowDestroying(this); |
47 | 47 |
48 // Then destroy the children. | 48 // Then destroy the children. |
49 while (!children_.empty()) { | 49 while (!children_.empty()) { |
50 Window* child = children_[0]; | 50 Window* child = children_[0]; |
51 delete child; | 51 delete child; |
52 // Deleting the child so remove it from out children_ list. | 52 // Deleting the child so remove it from out children_ list. |
53 DCHECK(std::find(children_.begin(), children_.end(), child) == | 53 DCHECK(std::find(children_.begin(), children_.end(), child) == |
54 children_.end()); | 54 children_.end()); |
55 } | 55 } |
56 | 56 |
(...skipping 16 matching lines...) Expand all Loading... |
73 | 73 |
74 FOR_EACH_OBSERVER(WindowObserver, observers_, OnWindowDestroyed(this)); | 74 FOR_EACH_OBSERVER(WindowObserver, observers_, OnWindowDestroyed(this)); |
75 } | 75 } |
76 | 76 |
77 void Window::Init(ui::Layer::LayerType layer_type) { | 77 void Window::Init(ui::Layer::LayerType layer_type) { |
78 layer_.reset(new ui::Layer(layer_type)); | 78 layer_.reset(new ui::Layer(layer_type)); |
79 layer_->SetVisible(false); | 79 layer_->SetVisible(false); |
80 layer_->set_delegate(this); | 80 layer_->set_delegate(this); |
81 UpdateLayerName(name_); | 81 UpdateLayerName(name_); |
82 | 82 |
83 Desktop::GetInstance()->WindowInitialized(this); | 83 RootWindow::GetInstance()->WindowInitialized(this); |
84 } | 84 } |
85 | 85 |
86 void Window::SetType(WindowType type) { | 86 void Window::SetType(WindowType type) { |
87 // Cannot change type after the window is initialized. | 87 // Cannot change type after the window is initialized. |
88 DCHECK(!layer()); | 88 DCHECK(!layer()); |
89 type_ = type; | 89 type_ = type; |
90 } | 90 } |
91 | 91 |
92 void Window::SetName(const std::string& name) { | 92 void Window::SetName(const std::string& name) { |
93 name_ = name; | 93 name_ = name; |
94 | 94 |
95 if (layer()) | 95 if (layer()) |
96 UpdateLayerName(name_); | 96 UpdateLayerName(name_); |
97 } | 97 } |
98 | 98 |
99 void Window::Show() { | 99 void Window::Show() { |
100 SetVisible(true); | 100 SetVisible(true); |
101 } | 101 } |
102 | 102 |
103 void Window::Hide() { | 103 void Window::Hide() { |
104 SetVisible(false); | 104 SetVisible(false); |
105 ReleaseCapture(); | 105 ReleaseCapture(); |
106 if (Desktop::GetInstance()->active_window() == this || | 106 if (RootWindow::GetInstance()->active_window() == this || |
107 !Desktop::GetInstance()->active_window()) { | 107 !RootWindow::GetInstance()->active_window()) { |
108 Desktop::GetInstance()->ActivateTopmostWindow(); | 108 RootWindow::GetInstance()->ActivateTopmostWindow(); |
109 } | 109 } |
110 } | 110 } |
111 | 111 |
112 bool Window::IsVisible() const { | 112 bool Window::IsVisible() const { |
113 return layer_->IsDrawn(); | 113 return layer_->IsDrawn(); |
114 } | 114 } |
115 | 115 |
116 gfx::Rect Window::GetScreenBounds() const { | 116 gfx::Rect Window::GetScreenBounds() const { |
117 gfx::Point origin = bounds().origin(); | 117 gfx::Point origin = bounds().origin(); |
118 Window::ConvertPointToWindow(parent_, | 118 Window::ConvertPointToWindow(parent_, |
119 aura::Desktop::GetInstance(), | 119 aura::RootWindow::GetInstance(), |
120 &origin); | 120 &origin); |
121 return gfx::Rect(origin, bounds().size()); | 121 return gfx::Rect(origin, bounds().size()); |
122 } | 122 } |
123 | 123 |
124 void Window::Activate() { | 124 void Window::Activate() { |
125 // If we support minimization need to ensure this restores the window first. | 125 // If we support minimization need to ensure this restores the window first. |
126 aura::Desktop::GetInstance()->SetActiveWindow(this, this); | 126 aura::RootWindow::GetInstance()->SetActiveWindow(this, this); |
127 } | 127 } |
128 | 128 |
129 void Window::Deactivate() { | 129 void Window::Deactivate() { |
130 aura::Desktop::GetInstance()->Deactivate(this); | 130 aura::RootWindow::GetInstance()->Deactivate(this); |
131 } | 131 } |
132 | 132 |
133 bool Window::IsActive() const { | 133 bool Window::IsActive() const { |
134 return aura::Desktop::GetInstance()->active_window() == this; | 134 return aura::RootWindow::GetInstance()->active_window() == this; |
135 } | 135 } |
136 | 136 |
137 void Window::SetTransform(const ui::Transform& transform) { | 137 void Window::SetTransform(const ui::Transform& transform) { |
138 layer()->SetTransform(transform); | 138 layer()->SetTransform(transform); |
139 } | 139 } |
140 | 140 |
141 void Window::SetLayoutManager(LayoutManager* layout_manager) { | 141 void Window::SetLayoutManager(LayoutManager* layout_manager) { |
142 layout_manager_.reset(layout_manager); | 142 layout_manager_.reset(layout_manager); |
143 } | 143 } |
144 | 144 |
(...skipping 20 matching lines...) Expand all Loading... |
165 // TODO: figure out how this is going to work when animating the layer. In | 165 // TODO: figure out how this is going to work when animating the layer. In |
166 // particular if we're animating the size then the underlying Texture is going | 166 // particular if we're animating the size then the underlying Texture is going |
167 // to be unhappy if we try to set a texture on a size bigger than the size of | 167 // to be unhappy if we try to set a texture on a size bigger than the size of |
168 // the texture. | 168 // the texture. |
169 layer_->SetCanvas(canvas, origin); | 169 layer_->SetCanvas(canvas, origin); |
170 } | 170 } |
171 | 171 |
172 void Window::SetParent(Window* parent) { | 172 void Window::SetParent(Window* parent) { |
173 if (parent) | 173 if (parent) |
174 parent->AddChild(this); | 174 parent->AddChild(this); |
175 else if (Desktop::GetInstance()->stacking_client()) | 175 else if (RootWindow::GetInstance()->stacking_client()) |
176 Desktop::GetInstance()->stacking_client()->AddChildToDefaultParent(this); | 176 RootWindow::GetInstance()->stacking_client()->AddChildToDefaultParent(this); |
177 else | 177 else |
178 NOTREACHED(); | 178 NOTREACHED(); |
179 } | 179 } |
180 | 180 |
181 void Window::StackChildAtTop(Window* child) { | 181 void Window::StackChildAtTop(Window* child) { |
182 if (children_.size() <= 1 || child == children_.back()) | 182 if (children_.size() <= 1 || child == children_.back()) |
183 return; // In the front already. | 183 return; // In the front already. |
184 StackChildAbove(child, children_.back()); | 184 StackChildAbove(child, children_.back()); |
185 } | 185 } |
186 | 186 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 if (child->transient_parent_ == this) | 256 if (child->transient_parent_ == this) |
257 child->transient_parent_ = NULL; | 257 child->transient_parent_ = NULL; |
258 } | 258 } |
259 | 259 |
260 void Window::RemoveChild(Window* child) { | 260 void Window::RemoveChild(Window* child) { |
261 Windows::iterator i = std::find(children_.begin(), children_.end(), child); | 261 Windows::iterator i = std::find(children_.begin(), children_.end(), child); |
262 DCHECK(i != children_.end()); | 262 DCHECK(i != children_.end()); |
263 if (layout_manager_.get()) | 263 if (layout_manager_.get()) |
264 layout_manager_->OnWillRemoveWindowFromLayout(child); | 264 layout_manager_->OnWillRemoveWindowFromLayout(child); |
265 FOR_EACH_OBSERVER(WindowObserver, observers_, OnWillRemoveWindow(child)); | 265 FOR_EACH_OBSERVER(WindowObserver, observers_, OnWillRemoveWindow(child)); |
266 aura::Window* desktop = child->GetDesktop(); | 266 aura::Window* root_window = child->GetRootWindow(); |
267 child->parent_ = NULL; | 267 child->parent_ = NULL; |
268 if (desktop) | 268 if (root_window) |
269 desktop->WindowDetachedFromDesktop(child); | 269 root_window->WindowDetachedFromRootWindow(child); |
270 layer_->Remove(child->layer_.get()); | 270 layer_->Remove(child->layer_.get()); |
271 children_.erase(i); | 271 children_.erase(i); |
272 child->OnParentChanged(); | 272 child->OnParentChanged(); |
273 } | 273 } |
274 | 274 |
275 bool Window::Contains(const Window* other) const { | 275 bool Window::Contains(const Window* other) const { |
276 for (const Window* parent = other; parent; parent = parent->parent_) { | 276 for (const Window* parent = other; parent; parent = parent->parent_) { |
277 if (parent == this) | 277 if (parent == this) |
278 return true; | 278 return true; |
279 } | 279 } |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
387 } | 387 } |
388 | 388 |
389 const internal::FocusManager* Window::GetFocusManager() const { | 389 const internal::FocusManager* Window::GetFocusManager() const { |
390 return parent_ ? parent_->GetFocusManager() : NULL; | 390 return parent_ ? parent_->GetFocusManager() : NULL; |
391 } | 391 } |
392 | 392 |
393 void Window::SetCapture() { | 393 void Window::SetCapture() { |
394 if (!IsVisible()) | 394 if (!IsVisible()) |
395 return; | 395 return; |
396 | 396 |
397 Desktop* desktop = GetDesktop(); | 397 RootWindow* root_window = GetRootWindow(); |
398 if (!desktop) | 398 if (!root_window) |
399 return; | 399 return; |
400 | 400 |
401 desktop->SetCapture(this); | 401 root_window->SetCapture(this); |
402 } | 402 } |
403 | 403 |
404 void Window::ReleaseCapture() { | 404 void Window::ReleaseCapture() { |
405 Desktop* desktop = GetDesktop(); | 405 RootWindow* root_window = GetRootWindow(); |
406 if (!desktop) | 406 if (!root_window) |
407 return; | 407 return; |
408 | 408 |
409 desktop->ReleaseCapture(this); | 409 root_window->ReleaseCapture(this); |
410 } | 410 } |
411 | 411 |
412 bool Window::HasCapture() { | 412 bool Window::HasCapture() { |
413 Desktop* desktop = GetDesktop(); | 413 RootWindow* root_window = GetRootWindow(); |
414 return desktop && desktop->capture_window() == this; | 414 return root_window && root_window->capture_window() == this; |
415 } | 415 } |
416 | 416 |
417 void Window::SetProperty(const char* name, void* value) { | 417 void Window::SetProperty(const char* name, void* value) { |
418 void* old = GetProperty(name); | 418 void* old = GetProperty(name); |
419 if (value) | 419 if (value) |
420 prop_map_[name] = value; | 420 prop_map_[name] = value; |
421 else | 421 else |
422 prop_map_.erase(name); | 422 prop_map_.erase(name); |
423 FOR_EACH_OBSERVER( | 423 FOR_EACH_OBSERVER( |
424 WindowObserver, observers_, OnWindowPropertyChanged(this, name, old)); | 424 WindowObserver, observers_, OnWindowPropertyChanged(this, name, old)); |
425 } | 425 } |
426 | 426 |
427 void Window::SetIntProperty(const char* name, int value) { | 427 void Window::SetIntProperty(const char* name, int value) { |
428 SetProperty(name, reinterpret_cast<void*>(value)); | 428 SetProperty(name, reinterpret_cast<void*>(value)); |
429 } | 429 } |
430 | 430 |
431 void* Window::GetProperty(const char* name) const { | 431 void* Window::GetProperty(const char* name) const { |
432 std::map<const char*, void*>::const_iterator iter = prop_map_.find(name); | 432 std::map<const char*, void*>::const_iterator iter = prop_map_.find(name); |
433 if (iter == prop_map_.end()) | 433 if (iter == prop_map_.end()) |
434 return NULL; | 434 return NULL; |
435 return iter->second; | 435 return iter->second; |
436 } | 436 } |
437 | 437 |
438 int Window::GetIntProperty(const char* name) const { | 438 int Window::GetIntProperty(const char* name) const { |
439 return static_cast<int>(reinterpret_cast<intptr_t>( | 439 return static_cast<int>(reinterpret_cast<intptr_t>( |
440 GetProperty(name))); | 440 GetProperty(name))); |
441 } | 441 } |
442 | 442 |
443 Desktop* Window::GetDesktop() { | 443 RootWindow* Window::GetRootWindow() { |
444 return parent_ ? parent_->GetDesktop() : NULL; | 444 return parent_ ? parent_->GetRootWindow() : NULL; |
445 } | 445 } |
446 | 446 |
447 void Window::WindowDetachedFromDesktop(aura::Window* window) { | 447 void Window::WindowDetachedFromRootWindow(aura::Window* window) { |
448 } | 448 } |
449 | 449 |
450 void Window::SetBoundsInternal(const gfx::Rect& new_bounds) { | 450 void Window::SetBoundsInternal(const gfx::Rect& new_bounds) { |
451 gfx::Rect actual_new_bounds(new_bounds); | 451 gfx::Rect actual_new_bounds(new_bounds); |
452 | 452 |
453 // Ensure we don't go smaller than our minimum bounds. | 453 // Ensure we don't go smaller than our minimum bounds. |
454 if (delegate_) { | 454 if (delegate_) { |
455 const gfx::Size& min_size = delegate_->GetMinimumSize(); | 455 const gfx::Size& min_size = delegate_->GetMinimumSize(); |
456 actual_new_bounds.set_width( | 456 actual_new_bounds.set_width( |
457 std::max(min_size.width(), actual_new_bounds.width())); | 457 std::max(min_size.width(), actual_new_bounds.width())); |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
565 if (id_ != -1) { | 565 if (id_ != -1) { |
566 char id_buf[10]; | 566 char id_buf[10]; |
567 base::snprintf(id_buf, sizeof(id_buf), " %d", id_); | 567 base::snprintf(id_buf, sizeof(id_buf), " %d", id_); |
568 layer_name.append(id_buf); | 568 layer_name.append(id_buf); |
569 } | 569 } |
570 layer()->set_name(layer_name); | 570 layer()->set_name(layer_name); |
571 #endif | 571 #endif |
572 } | 572 } |
573 | 573 |
574 } // namespace aura | 574 } // namespace aura |
OLD | NEW |