Index: ui/aura/desktop.cc |
diff --git a/ui/aura/desktop.cc b/ui/aura/desktop.cc |
index 90ee1716fc309bb76a50e7dfeace8cd369d75bda..53e08fd6cb7b714b4b60bd72d91d4664e14c61c3 100644 |
--- a/ui/aura/desktop.cc |
+++ b/ui/aura/desktop.cc |
@@ -100,6 +100,13 @@ void GetEventFiltersToNotify(Window* target, EventFilters* filters) { |
} |
} |
+// Returns true if |descendant| is a descendant of |ancestor|. |
+bool IsAncestor(Window* ancestor, Window* descendant) { |
+ while (descendant && descendant != ancestor) |
+ descendant = descendant->parent(); |
+ return descendant == ancestor; |
Ben Goodger (Google)
2011/11/28 17:50:19
Rather than defining this here, can you add a Cont
flackr
2011/11/28 20:36:35
Done.
|
+} |
+ |
} // namespace |
Desktop* Desktop::instance_ = NULL; |
@@ -533,19 +540,22 @@ void Desktop::WindowDetachedFromDesktop(Window* detached) { |
// If the ancestor of the capture window is detached, |
// release the capture. |
- aura::Window* window = capture_window_; |
- while (window && window != detached) |
- window = window->parent(); |
- if (window && window != this) |
+ if (IsAncestor(detached, capture_window_) && capture_window_ != this) |
sky
2011/11/28 17:20:22
Is the capture_window_ condition necessary? Also,
flackr
2011/11/28 20:36:35
Oops, seems like I converted the old statement inc
|
ReleaseCapture(capture_window_); |
- // If the ancestor of the capture window is detached, |
+ // If the ancestor of the focused window is detached, |
// release the focus. |
- window = focused_window_; |
- while (window && window != detached) |
- window = window->parent(); |
- if (window) |
+ if (IsAncestor(detached, focused_window_)) |
SetFocusedWindow(NULL); |
+ |
+ // If the ancestor of any event handler windows are detached, release the |
+ // pointer to those windows. |
+ if (IsAncestor(detached, mouse_pressed_handler_)) |
+ mouse_pressed_handler_ = NULL; |
+ if (IsAncestor(detached, mouse_moved_handler_)) |
+ mouse_moved_handler_ = NULL; |
+ if (IsAncestor(detached, touch_event_handler_)) |
+ touch_event_handler_ = NULL; |
} |
void Desktop::OnLayerAnimationEnded( |