Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(293)

Side by Side Diff: ui/aura/desktop.cc

Issue 8194004: change the way windows are parented when their parent is set to NULL. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/aura/desktop.h ('k') | ui/aura/desktop_delegate.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/desktop.h" 5 #include "ui/aura/desktop.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "ui/aura/desktop_delegate.h"
9 #include "ui/aura/desktop_host.h" 10 #include "ui/aura/desktop_host.h"
10 #include "ui/aura/focus_manager.h" 11 #include "ui/aura/focus_manager.h"
11 #include "ui/aura/root_window.h" 12 #include "ui/aura/root_window.h"
12 #include "ui/aura/toplevel_window_container.h" 13 #include "ui/aura/toplevel_window_container.h"
13 #include "ui/aura/window.h" 14 #include "ui/aura/window.h"
14 #include "ui/aura/window_delegate.h" 15 #include "ui/aura/window_delegate.h"
15 #include "ui/gfx/compositor/compositor.h" 16 #include "ui/gfx/compositor/compositor.h"
16 #include "ui/gfx/compositor/layer.h" 17 #include "ui/gfx/compositor/layer.h"
17 18
18 namespace aura { 19 namespace aura {
19 20
20 // static 21 // static
21 Desktop* Desktop::instance_ = NULL; 22 Desktop* Desktop::instance_ = NULL;
22 23
23 // static 24 // static
24 ui::Compositor*(*Desktop::compositor_factory_)() = NULL; 25 ui::Compositor*(*Desktop::compositor_factory_)() = NULL;
25 26
26 Desktop::Desktop() 27 Desktop::Desktop()
27 : default_parent_(NULL), 28 : delegate_(NULL),
28 host_(aura::DesktopHost::Create(gfx::Rect(200, 200, 1280, 1024))), 29 host_(aura::DesktopHost::Create(gfx::Rect(200, 200, 1280, 1024))),
29 ALLOW_THIS_IN_INITIALIZER_LIST(schedule_paint_(this)), 30 ALLOW_THIS_IN_INITIALIZER_LIST(schedule_paint_(this)),
30 active_window_(NULL), 31 active_window_(NULL),
31 in_destructor_(false) { 32 in_destructor_(false) {
32 DCHECK(MessageLoopForUI::current())
33 << "The UI message loop must be initialized first.";
34 if (compositor_factory_) { 33 if (compositor_factory_) {
35 compositor_ = (*Desktop::compositor_factory())(); 34 compositor_ = (*Desktop::compositor_factory())();
36 } else { 35 } else {
37 compositor_ = ui::Compositor::Create(this, host_->GetAcceleratedWidget(), 36 compositor_ = ui::Compositor::Create(this, host_->GetAcceleratedWidget(),
38 host_->GetSize()); 37 host_->GetSize());
39 } 38 }
40 host_->SetDesktop(this); 39 host_->SetDesktop(this);
41 DCHECK(compositor_.get()); 40 DCHECK(compositor_.get());
42 window_.reset(new internal::RootWindow); 41 window_.reset(new internal::RootWindow);
43 } 42 }
44 43
45 Desktop::~Desktop() { 44 Desktop::~Desktop() {
46 in_destructor_ = true; 45 in_destructor_ = true;
47 if (instance_ == this) 46 if (instance_ == this)
48 instance_ = NULL; 47 instance_ = NULL;
49 } 48 }
50 49
51 void Desktop::Init() { 50 void Desktop::Init() {
52 window_->Init(); 51 window_->Init();
53 window_->SetBounds(gfx::Rect(gfx::Point(), host_->GetSize())); 52 window_->SetBounds(gfx::Rect(gfx::Point(), host_->GetSize()));
54 window_->Show(); 53 window_->Show();
55 compositor()->SetRootLayer(window_->layer()); 54 compositor()->SetRootLayer(window_->layer());
56 } 55 }
57 56
58 void Desktop::CreateDefaultParentForTesting() {
59 Window* default_parent = new internal::ToplevelWindowContainer;
60 default_parent->Init();
61 default_parent->SetBounds(window_->bounds());
62 default_parent->Show();
63 window_->AddChild(default_parent);
64 set_default_parent(default_parent);
65 }
66
67 void Desktop::Show() { 57 void Desktop::Show() {
68 host_->Show(); 58 host_->Show();
69 } 59 }
70 60
71 void Desktop::SetSize(const gfx::Size& size) { 61 void Desktop::SetSize(const gfx::Size& size) {
72 host_->SetSize(size); 62 host_->SetSize(size);
73 } 63 }
74 64
75 gfx::Size Desktop::GetSize() const { 65 gfx::Size Desktop::GetSize() const {
76 return host_->GetSize(); 66 return host_->GetSize();
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 active_window_ = window; 108 active_window_ = window;
119 if (active_window_) { 109 if (active_window_) {
120 active_window_->parent()->MoveChildToFront(active_window_); 110 active_window_->parent()->MoveChildToFront(active_window_);
121 active_window_->delegate()->OnActivated(); 111 active_window_->delegate()->OnActivated();
122 active_window_->GetFocusManager()->SetFocusedWindow( 112 active_window_->GetFocusManager()->SetFocusedWindow(
123 to_focus ? to_focus : active_window_); 113 to_focus ? to_focus : active_window_);
124 } 114 }
125 } 115 }
126 116
127 void Desktop::ActivateTopmostWindow() { 117 void Desktop::ActivateTopmostWindow() {
128 SetActiveWindow(GetTopmostWindowToActivate(NULL), NULL); 118 SetActiveWindow(delegate_->GetTopmostWindowToActivate(NULL), NULL);
129 } 119 }
130 120
131 void Desktop::WindowDestroying(Window* window) { 121 void Desktop::WindowDestroying(Window* window) {
132 if (in_destructor_ || window != active_window_) 122 if (in_destructor_ || window != active_window_)
133 return; 123 return;
134 124
135 // Reset active_window_ before invoking SetActiveWindow so that we don't 125 // Reset active_window_ before invoking SetActiveWindow so that we don't
136 // attempt to notify it while running its destructor. 126 // attempt to notify it while running its destructor.
137 active_window_ = NULL; 127 active_window_ = NULL;
138 SetActiveWindow(GetTopmostWindowToActivate(window), NULL); 128 SetActiveWindow(delegate_->GetTopmostWindowToActivate(window), NULL);
139 } 129 }
140 130
141 MessageLoop::Dispatcher* Desktop::GetDispatcher() { 131 MessageLoop::Dispatcher* Desktop::GetDispatcher() {
142 return host_.get(); 132 return host_.get();
143 } 133 }
144 134
145 135
146 Window* Desktop::GetTopmostWindowToActivate(Window* ignore) {
147 Window::Windows windows(default_parent_->children());
148 for (Window::Windows::const_reverse_iterator i = windows.rbegin();
149 i != windows.rend(); ++i) {
150 if (*i != ignore && (*i)->IsVisible() &&
151 (*i)->delegate()->ShouldActivate(NULL))
152 return *i;
153 }
154 return NULL;
155 }
156
157 // static 136 // static
158 Desktop* Desktop::GetInstance() { 137 Desktop* Desktop::GetInstance() {
159 if (!instance_) { 138 if (!instance_) {
160 instance_ = new Desktop; 139 instance_ = new Desktop;
161 instance_->Init(); 140 instance_->Init();
162 } 141 }
163 return instance_; 142 return instance_;
164 } 143 }
165 144
166 } // namespace aura 145 } // namespace aura
OLDNEW
« no previous file with comments | « ui/aura/desktop.h ('k') | ui/aura/desktop_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698