Chromium Code Reviews| 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 "ui/aura/desktop.h" | 10 #include "ui/aura/desktop.h" |
| 11 #include "ui/aura/event.h" | 11 #include "ui/aura/event.h" |
| 12 #include "ui/aura/event_filter.h" | 12 #include "ui/aura/event_filter.h" |
| 13 #include "ui/aura/focus_manager.h" | 13 #include "ui/aura/focus_manager.h" |
| 14 #include "ui/aura/layout_manager.h" | 14 #include "ui/aura/layout_manager.h" |
| 15 #include "ui/aura/window_delegate.h" | 15 #include "ui/aura/window_delegate.h" |
| 16 #include "ui/gfx/canvas_skia.h" | 16 #include "ui/gfx/canvas_skia.h" |
| 17 #include "ui/gfx/compositor/compositor.h" | 17 #include "ui/gfx/compositor/compositor.h" |
| 18 #include "ui/gfx/compositor/layer.h" | 18 #include "ui/gfx/compositor/layer.h" |
| 19 | 19 |
| 20 namespace aura { | 20 namespace aura { |
| 21 | 21 |
| 22 using internal::RootWindow; | |
| 23 | |
| 22 Window::Window(WindowDelegate* delegate) | 24 Window::Window(WindowDelegate* delegate) |
| 23 : delegate_(delegate), | 25 : is_root_(false), |
| 26 delegate_(delegate), | |
| 24 visibility_(VISIBILITY_HIDDEN), | 27 visibility_(VISIBILITY_HIDDEN), |
| 25 parent_(NULL), | 28 parent_(NULL), |
| 26 id_(-1), | 29 id_(-1), |
| 27 user_data_(NULL) { | 30 user_data_(NULL) { |
| 28 } | 31 } |
| 29 | 32 |
| 30 Window::~Window() { | 33 Window::~Window() { |
| 31 // Let the delegate know we're in the processing of destroying. | 34 // Let the delegate know we're in the processing of destroying. |
| 32 if (delegate_) | 35 if (delegate_) |
| 33 delegate_->OnWindowDestroying(); | 36 delegate_->OnWindowDestroying(); |
| 34 | 37 |
| 35 // Update the FocusManager in case we were focused. This must be done before | 38 // Update the FocusManager in case we were focused. This must be done before |
| 36 // we are removed from the hierarchy otherwise we won't be able to find the | 39 // we are removed from the hierarchy otherwise we won't be able to find the |
| 37 // FocusManager. | 40 // FocusManager. |
| 38 internal::FocusManager* focus_manager = GetFocusManager(); | 41 internal::FocusManager* focus_manager = GetFocusManager(); |
| 39 if (focus_manager && focus_manager->focused_window() == this) | 42 if (focus_manager && focus_manager->focused_window() == this) |
| 40 focus_manager->SetFocusedWindow(NULL); | 43 focus_manager->SetFocusedWindow(NULL); |
| 41 | 44 |
| 45 // Let the root know so that it can remove any references to us. | |
| 46 RootWindow* root = GetRoot(); | |
|
Ben Goodger (Google)
2011/09/21 04:15:21
Can you maybe move the FocusManager code above int
| |
| 47 if (root) | |
| 48 root->WindowDestroying(this); | |
| 49 | |
| 42 // Then destroy the children. | 50 // Then destroy the children. |
| 43 while (!children_.empty()) { | 51 while (!children_.empty()) { |
| 44 Window* child = children_[0]; | 52 Window* child = children_[0]; |
| 45 delete child; | 53 delete child; |
| 46 // Deleting the child so remove it from out children_ list. | 54 // Deleting the child so remove it from out children_ list. |
| 47 DCHECK(std::find(children_.begin(), children_.end(), child) == | 55 DCHECK(std::find(children_.begin(), children_.end(), child) == |
| 48 children_.end()); | 56 children_.end()); |
| 49 } | 57 } |
| 50 // And let the delegate do any post cleanup. | 58 // And let the delegate do any post cleanup. |
| 51 if (delegate_) | 59 if (delegate_) |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 63 } | 71 } |
| 64 | 72 |
| 65 void Window::SetVisibility(Visibility visibility) { | 73 void Window::SetVisibility(Visibility visibility) { |
| 66 if (visibility_ == visibility) | 74 if (visibility_ == visibility) |
| 67 return; | 75 return; |
| 68 | 76 |
| 69 visibility_ = visibility; | 77 visibility_ = visibility; |
| 70 layer_->set_visible(visibility_ != VISIBILITY_HIDDEN); | 78 layer_->set_visible(visibility_ != VISIBILITY_HIDDEN); |
| 71 if (layer_->visible()) | 79 if (layer_->visible()) |
| 72 SchedulePaint(); | 80 SchedulePaint(); |
| 81 if (visibility_ != VISIBILITY_SHOWN) | |
| 82 ReleaseCapture(); | |
| 73 } | 83 } |
| 74 | 84 |
| 75 void Window::SetLayoutManager(LayoutManager* layout_manager) { | 85 void Window::SetLayoutManager(LayoutManager* layout_manager) { |
| 76 layout_manager_.reset(layout_manager); | 86 layout_manager_.reset(layout_manager); |
| 77 } | 87 } |
| 78 | 88 |
| 79 void Window::SetBounds(const gfx::Rect& bounds, int anim_ms) { | 89 void Window::SetBounds(const gfx::Rect& bounds, int anim_ms) { |
| 80 // TODO: support anim_ms | 90 // TODO: support anim_ms |
| 81 // TODO: funnel this through the Desktop. | 91 // TODO: funnel this through the Desktop. |
| 82 bool was_move = bounds_.size() == bounds.size(); | 92 bool was_move = bounds_.size() == bounds.size(); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 128 SchedulePaintInRect(gfx::Rect()); | 138 SchedulePaintInRect(gfx::Rect()); |
| 129 | 139 |
| 130 ui::Layer* parent_layer = child->layer()->parent(); | 140 ui::Layer* parent_layer = child->layer()->parent(); |
| 131 parent_layer->Remove(child->layer()); | 141 parent_layer->Remove(child->layer()); |
| 132 parent_layer->Add(child->layer()); | 142 parent_layer->Add(child->layer()); |
| 133 } | 143 } |
| 134 | 144 |
| 135 void Window::AddChild(Window* child) { | 145 void Window::AddChild(Window* child) { |
| 136 DCHECK(std::find(children_.begin(), children_.end(), child) == | 146 DCHECK(std::find(children_.begin(), children_.end(), child) == |
| 137 children_.end()); | 147 children_.end()); |
| 148 DCHECK(!child->is_root_); | |
| 138 child->parent_ = this; | 149 child->parent_ = this; |
| 139 layer_->Add(child->layer_.get()); | 150 layer_->Add(child->layer_.get()); |
| 140 children_.push_back(child); | 151 children_.push_back(child); |
| 141 } | 152 } |
| 142 | 153 |
| 143 void Window::RemoveChild(Window* child) { | 154 void Window::RemoveChild(Window* child) { |
| 144 Windows::iterator i = std::find(children_.begin(), children_.end(), child); | 155 Windows::iterator i = std::find(children_.begin(), children_.end(), child); |
| 145 DCHECK(i != children_.end()); | 156 DCHECK(i != children_.end()); |
| 146 child->parent_ = NULL; | 157 child->parent_ = NULL; |
| 147 layer_->Remove(child->layer_.get()); | 158 layer_->Remove(child->layer_.get()); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 192 return handler; | 203 return handler; |
| 193 } | 204 } |
| 194 } | 205 } |
| 195 return delegate_ ? this : NULL; | 206 return delegate_ ? this : NULL; |
| 196 } | 207 } |
| 197 | 208 |
| 198 internal::FocusManager* Window::GetFocusManager() { | 209 internal::FocusManager* Window::GetFocusManager() { |
| 199 return parent_ ? parent_->GetFocusManager() : NULL; | 210 return parent_ ? parent_->GetFocusManager() : NULL; |
| 200 } | 211 } |
| 201 | 212 |
| 213 void Window::SetCapture() { | |
| 214 if (visibility_ != VISIBILITY_SHOWN) | |
| 215 return; | |
| 216 | |
| 217 RootWindow* root = GetRoot(); | |
| 218 if (!root) | |
| 219 return; | |
| 220 | |
| 221 root->SetCapture(this); | |
| 222 } | |
| 223 | |
| 224 void Window::ReleaseCapture() { | |
| 225 RootWindow* root = GetRoot(); | |
| 226 if (!root) | |
| 227 return; | |
| 228 | |
| 229 root->ReleaseCapture(this); | |
| 230 } | |
| 231 | |
| 232 bool Window::HasCapture() { | |
| 233 RootWindow* root = GetRoot(); | |
| 234 return root && root->capture_window() == this; | |
| 235 } | |
| 236 | |
| 237 Window::Window(WindowDelegate* delegate, bool is_root) | |
| 238 : is_root_(is_root), | |
| 239 delegate_(delegate), | |
| 240 visibility_(VISIBILITY_HIDDEN), | |
| 241 parent_(NULL), | |
| 242 id_(-1), | |
| 243 user_data_(NULL) { | |
| 244 } | |
| 245 | |
| 202 void Window::SchedulePaint() { | 246 void Window::SchedulePaint() { |
| 203 SchedulePaintInRect(gfx::Rect(0, 0, bounds_.width(), bounds_.height())); | 247 SchedulePaintInRect(gfx::Rect(0, 0, bounds_.width(), bounds_.height())); |
| 204 } | 248 } |
| 205 | 249 |
| 250 RootWindow* Window::GetRoot() { | |
|
Ben Goodger (Google)
2011/09/21 04:15:21
rather than adding this state, how about a virtual
| |
| 251 Window* parent = this; | |
| 252 while (parent && !parent->is_root_) | |
| 253 parent = parent->parent_; | |
| 254 return static_cast<RootWindow*>(parent); | |
| 255 } | |
| 256 | |
| 206 void Window::OnPaintLayer(gfx::Canvas* canvas) { | 257 void Window::OnPaintLayer(gfx::Canvas* canvas) { |
| 207 delegate_->OnPaint(canvas); | 258 delegate_->OnPaint(canvas); |
| 208 } | 259 } |
| 209 | 260 |
| 210 } // namespace aura | 261 } // namespace aura |
| OLD | NEW |