Index: ui/aura/window.cc |
diff --git a/ui/aura/window.cc b/ui/aura/window.cc |
index 6ccf808d8a7c93106a8c7afc6c8213a6a65ac8a0..9704d281f7f81a9fb7f24eb79b9356e93afd80b3 100644 |
--- a/ui/aura/window.cc |
+++ b/ui/aura/window.cc |
@@ -19,8 +19,11 @@ |
namespace aura { |
+using internal::RootWindow; |
+ |
Window::Window(WindowDelegate* delegate) |
- : delegate_(delegate), |
+ : is_root_(false), |
+ delegate_(delegate), |
visibility_(VISIBILITY_HIDDEN), |
parent_(NULL), |
id_(-1), |
@@ -39,6 +42,11 @@ Window::~Window() { |
if (focus_manager && focus_manager->focused_window() == this) |
focus_manager->SetFocusedWindow(NULL); |
+ // Let the root know so that it can remove any references to us. |
+ RootWindow* root = GetRoot(); |
Ben Goodger (Google)
2011/09/21 04:15:21
Can you maybe move the FocusManager code above int
|
+ if (root) |
+ root->WindowDestroying(this); |
+ |
// Then destroy the children. |
while (!children_.empty()) { |
Window* child = children_[0]; |
@@ -70,6 +78,8 @@ void Window::SetVisibility(Visibility visibility) { |
layer_->set_visible(visibility_ != VISIBILITY_HIDDEN); |
if (layer_->visible()) |
SchedulePaint(); |
+ if (visibility_ != VISIBILITY_SHOWN) |
+ ReleaseCapture(); |
} |
void Window::SetLayoutManager(LayoutManager* layout_manager) { |
@@ -135,6 +145,7 @@ void Window::MoveChildToFront(Window* child) { |
void Window::AddChild(Window* child) { |
DCHECK(std::find(children_.begin(), children_.end(), child) == |
children_.end()); |
+ DCHECK(!child->is_root_); |
child->parent_ = this; |
layer_->Add(child->layer_.get()); |
children_.push_back(child); |
@@ -199,10 +210,50 @@ internal::FocusManager* Window::GetFocusManager() { |
return parent_ ? parent_->GetFocusManager() : NULL; |
} |
+void Window::SetCapture() { |
+ if (visibility_ != VISIBILITY_SHOWN) |
+ return; |
+ |
+ RootWindow* root = GetRoot(); |
+ if (!root) |
+ return; |
+ |
+ root->SetCapture(this); |
+} |
+ |
+void Window::ReleaseCapture() { |
+ RootWindow* root = GetRoot(); |
+ if (!root) |
+ return; |
+ |
+ root->ReleaseCapture(this); |
+} |
+ |
+bool Window::HasCapture() { |
+ RootWindow* root = GetRoot(); |
+ return root && root->capture_window() == this; |
+} |
+ |
+Window::Window(WindowDelegate* delegate, bool is_root) |
+ : is_root_(is_root), |
+ delegate_(delegate), |
+ visibility_(VISIBILITY_HIDDEN), |
+ parent_(NULL), |
+ id_(-1), |
+ user_data_(NULL) { |
+} |
+ |
void Window::SchedulePaint() { |
SchedulePaintInRect(gfx::Rect(0, 0, bounds_.width(), bounds_.height())); |
} |
+RootWindow* Window::GetRoot() { |
Ben Goodger (Google)
2011/09/21 04:15:21
rather than adding this state, how about a virtual
|
+ Window* parent = this; |
+ while (parent && !parent->is_root_) |
+ parent = parent->parent_; |
+ return static_cast<RootWindow*>(parent); |
+} |
+ |
void Window::OnPaintLayer(gfx::Canvas* canvas) { |
delegate_->OnPaint(canvas); |
} |