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

Side by Side Diff: ui/aura/window.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/window.h ('k') | ui/aura/window_types.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/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 "ui/aura/desktop.h" 10 #include "ui/aura/desktop.h"
11 #include "ui/aura/desktop_delegate.h"
11 #include "ui/aura/event.h" 12 #include "ui/aura/event.h"
12 #include "ui/aura/event_filter.h" 13 #include "ui/aura/event_filter.h"
13 #include "ui/aura/layout_manager.h" 14 #include "ui/aura/layout_manager.h"
14 #include "ui/aura/window_delegate.h" 15 #include "ui/aura/window_delegate.h"
16 #include "ui/aura/window_types.h"
15 #include "ui/base/animation/multi_animation.h" 17 #include "ui/base/animation/multi_animation.h"
16 #include "ui/gfx/canvas_skia.h" 18 #include "ui/gfx/canvas_skia.h"
17 #include "ui/gfx/compositor/compositor.h" 19 #include "ui/gfx/compositor/compositor.h"
18 #include "ui/gfx/compositor/layer.h" 20 #include "ui/gfx/compositor/layer.h"
19 #include "ui/gfx/screen.h" 21 #include "ui/gfx/screen.h"
20 22
21 namespace aura { 23 namespace aura {
22 24
23 using internal::RootWindow; 25 using internal::RootWindow;
24 26
25 Window::Window(WindowDelegate* delegate) 27 Window::Window(WindowDelegate* delegate)
26 : delegate_(delegate), 28 : type_(kWindowType_Toplevel),
29 delegate_(delegate),
27 show_state_(ui::SHOW_STATE_NORMAL), 30 show_state_(ui::SHOW_STATE_NORMAL),
28 parent_(NULL), 31 parent_(NULL),
29 id_(-1), 32 id_(-1),
30 user_data_(NULL), 33 user_data_(NULL),
31 stops_event_propagation_(false) { 34 stops_event_propagation_(false) {
32 } 35 }
33 36
34 Window::~Window() { 37 Window::~Window() {
35 // Let the delegate know we're in the processing of destroying. 38 // Let the delegate know we're in the processing of destroying.
36 if (delegate_) 39 if (delegate_)
(...skipping 24 matching lines...) Expand all
61 if (delegate_) 64 if (delegate_)
62 type = ui::Layer::LAYER_HAS_TEXTURE; 65 type = ui::Layer::LAYER_HAS_TEXTURE;
63 layer_.reset(new ui::Layer(Desktop::GetInstance()->compositor(), type)); 66 layer_.reset(new ui::Layer(Desktop::GetInstance()->compositor(), type));
64 // Windows (and therefore the layer) should initially be hidden. 67 // Windows (and therefore the layer) should initially be hidden.
65 // TODO: when we distinguish control (child) windows, they should be initially 68 // TODO: when we distinguish control (child) windows, they should be initially
66 // visible. 69 // visible.
67 layer_->SetVisible(false); 70 layer_->SetVisible(false);
68 layer_->set_delegate(this); 71 layer_->set_delegate(this);
69 } 72 }
70 73
74 void Window::SetType(int type) {
75 // Cannot change type after the window is initialized.
76 DCHECK(!layer());
77 type_ = type;
78 }
79
71 void Window::Show() { 80 void Window::Show() {
72 SetVisible(true); 81 SetVisible(true);
73 } 82 }
74 83
75 void Window::Hide() { 84 void Window::Hide() {
76 SetVisible(false); 85 SetVisible(false);
77 ReleaseCapture(); 86 ReleaseCapture();
78 if (Desktop::GetInstance()->active_window() == this || 87 if (Desktop::GetInstance()->active_window() == this ||
79 !Desktop::GetInstance()->active_window()) { 88 !Desktop::GetInstance()->active_window()) {
80 Desktop::GetInstance()->ActivateTopmostWindow(); 89 Desktop::GetInstance()->ActivateTopmostWindow();
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 // TODO: figure out how this is going to work when animating the layer. In 128 // TODO: figure out how this is going to work when animating the layer. In
120 // particular if we're animating the size then the underlying Texture is going 129 // particular if we're animating the size then the underlying Texture is going
121 // to be unhappy if we try to set a texture on a size bigger than the size of 130 // to be unhappy if we try to set a texture on a size bigger than the size of
122 // the texture. 131 // the texture.
123 layer_->SetCanvas(canvas, origin); 132 layer_->SetCanvas(canvas, origin);
124 } 133 }
125 134
126 void Window::SetParent(Window* parent) { 135 void Window::SetParent(Window* parent) {
127 if (parent) 136 if (parent)
128 parent->AddChild(this); 137 parent->AddChild(this);
138 else if (Desktop::GetInstance()->delegate())
139 Desktop::GetInstance()->delegate()->AddChildToDefaultParent(this);
129 else 140 else
130 Desktop::GetInstance()->default_parent()->AddChild(this); 141 NOTREACHED();
131 } 142 }
132 143
133 void Window::Restore() { 144 void Window::Restore() {
134 if (show_state_ != ui::SHOW_STATE_NORMAL) { 145 if (show_state_ != ui::SHOW_STATE_NORMAL) {
135 show_state_ = ui::SHOW_STATE_NORMAL; 146 show_state_ = ui::SHOW_STATE_NORMAL;
136 SetBounds(restore_bounds_); 147 SetBounds(restore_bounds_);
137 restore_bounds_.SetRect(0, 0, 0, 0); 148 restore_bounds_.SetRect(0, 0, 0, 0);
138 } 149 }
139 } 150 }
140 151
141 void Window::Maximize() { 152 void Window::Maximize() {
142 if (UpdateShowStateAndRestoreBounds(ui::SHOW_STATE_MAXIMIZED)) 153 if (UpdateShowStateAndRestoreBounds(ui::SHOW_STATE_MAXIMIZED))
143 SetBounds(gfx::Screen::GetMonitorWorkAreaNearestWindow(this)); 154 SetBounds(gfx::Screen::GetMonitorWorkAreaNearestWindow(this));
144 } 155 }
145 156
146 void Window::Fullscreen() { 157 void Window::Fullscreen() {
147 if (UpdateShowStateAndRestoreBounds(ui::SHOW_STATE_FULLSCREEN)) 158 if (UpdateShowStateAndRestoreBounds(ui::SHOW_STATE_FULLSCREEN))
148 SetBounds(gfx::Screen::GetMonitorAreaNearestWindow(this)); 159 SetBounds(gfx::Screen::GetMonitorAreaNearestWindow(this));
149 } 160 }
150 161
151 bool Window::IsToplevelWindowContainer() const { 162 ToplevelWindowContainer* Window::AsToplevelWindowContainer() {
152 return false; 163 return NULL;
164 }
165
166 const ToplevelWindowContainer* Window::AsToplevelWindowContainer() const {
167 return NULL;
153 } 168 }
154 169
155 void Window::MoveChildToFront(Window* child) { 170 void Window::MoveChildToFront(Window* child) {
156 DCHECK_EQ(child->parent(), this); 171 DCHECK_EQ(child->parent(), this);
157 const Windows::iterator i(std::find(children_.begin(), children_.end(), 172 const Windows::iterator i(std::find(children_.begin(), children_.end(),
158 child)); 173 child));
159 DCHECK(i != children_.end()); 174 DCHECK(i != children_.end());
160 children_.erase(i); 175 children_.erase(i);
161 176
162 // TODO(beng): this obviously has to handle different window types. 177 // TODO(beng): this obviously has to handle different window types.
163 children_.insert(children_.begin() + children_.size(), child); 178 children_.insert(children_.begin() + children_.size(), child);
164 SchedulePaintInRect(gfx::Rect()); 179 SchedulePaintInRect(gfx::Rect());
165 180
166 child->layer()->parent()->MoveToFront(child->layer()); 181 child->layer()->parent()->MoveToFront(child->layer());
167 } 182 }
168 183
184 bool Window::CanActivate() const {
185 return IsVisible() && delegate_ && delegate_->ShouldActivate(NULL);
186 }
187
169 void Window::AddChild(Window* child) { 188 void Window::AddChild(Window* child) {
170 DCHECK(std::find(children_.begin(), children_.end(), child) == 189 DCHECK(std::find(children_.begin(), children_.end(), child) ==
171 children_.end()); 190 children_.end());
172 if (child->parent()) 191 if (child->parent())
173 child->parent()->RemoveChild(child); 192 child->parent()->RemoveChild(child);
174 child->parent_ = this; 193 child->parent_ = this;
175 layer_->Add(child->layer_.get()); 194 layer_->Add(child->layer_.get());
176 children_.push_back(child); 195 children_.push_back(child);
177 } 196 }
178 197
179 void Window::RemoveChild(Window* child) { 198 void Window::RemoveChild(Window* child) {
180 Windows::iterator i = std::find(children_.begin(), children_.end(), child); 199 Windows::iterator i = std::find(children_.begin(), children_.end(), child);
181 DCHECK(i != children_.end()); 200 DCHECK(i != children_.end());
182 child->parent_ = NULL; 201 child->parent_ = NULL;
183 layer_->Remove(child->layer_.get()); 202 layer_->Remove(child->layer_.get());
184 children_.erase(i); 203 children_.erase(i);
185 } 204 }
186 205
187 Window* Window::GetChildById(int id) { 206 Window* Window::GetChildById(int id) {
207 return const_cast<Window*>(const_cast<const Window*>(this)->GetChildById(id));
208 }
209
210 const Window* Window::GetChildById(int id) const {
188 Windows::const_iterator i; 211 Windows::const_iterator i;
189 for (i = children_.begin(); i != children_.end(); ++i) { 212 for (i = children_.begin(); i != children_.end(); ++i) {
190 if ((*i)->id() == id) 213 if ((*i)->id() == id)
191 return *i; 214 return *i;
192 Window* result = (*i)->GetChildById(id); 215 const Window* result = (*i)->GetChildById(id);
193 if (result) 216 if (result)
194 return result; 217 return result;
195 } 218 }
196 return NULL; 219 return NULL;
197 } 220 }
198 221
199 // static 222 // static
200 void Window::ConvertPointToWindow(Window* source, 223 void Window::ConvertPointToWindow(Window* source,
201 Window* target, 224 Window* target,
202 gfx::Point* point) { 225 gfx::Point* point) {
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 ui::WindowShowState new_show_state) { 366 ui::WindowShowState new_show_state) {
344 if (show_state_ == new_show_state) 367 if (show_state_ == new_show_state)
345 return false; 368 return false;
346 show_state_ = new_show_state; 369 show_state_ = new_show_state;
347 if (restore_bounds_.IsEmpty()) 370 if (restore_bounds_.IsEmpty())
348 restore_bounds_ = bounds(); 371 restore_bounds_ = bounds();
349 return true; 372 return true;
350 } 373 }
351 374
352 } // namespace aura 375 } // namespace aura
OLDNEW
« no previous file with comments | « ui/aura/window.h ('k') | ui/aura/window_types.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698