Chromium Code Reviews| Index: ui/aura/root_window.cc |
| diff --git a/ui/aura/root_window.cc b/ui/aura/root_window.cc |
| index 9c50a2cf801ca0b2bb1b779fdf28aa3e29316363..2a0d74f5b2a66d7087e0f907177e43fe869d8a21 100644 |
| --- a/ui/aura/root_window.cc |
| +++ b/ui/aura/root_window.cc |
| @@ -15,9 +15,10 @@ namespace aura { |
| namespace internal { |
| RootWindow::RootWindow() |
| - : Window(NULL), |
| + : Window(NULL, true), |
| mouse_pressed_handler_(NULL), |
| - ALLOW_THIS_IN_INITIALIZER_LIST(focus_manager_(new FocusManager(this))) { |
| + ALLOW_THIS_IN_INITIALIZER_LIST(focus_manager_(new FocusManager(this))), |
| + capture_window_(NULL) { |
| set_name(ASCIIToUTF16("RootWindow")); |
| } |
| @@ -25,14 +26,15 @@ RootWindow::~RootWindow() { |
| } |
| bool RootWindow::HandleMouseEvent(const MouseEvent& event) { |
| - Window* target = mouse_pressed_handler_; |
| + Window* target = |
| + mouse_pressed_handler_ ? mouse_pressed_handler_ : capture_window_; |
| if (!target) |
| target = GetEventHandlerForPoint(event.location()); |
| if (event.type() == ui::ET_MOUSE_PRESSED && !mouse_pressed_handler_) |
| mouse_pressed_handler_ = target; |
| if (event.type() == ui::ET_MOUSE_RELEASED) |
| mouse_pressed_handler_ = NULL; |
| - if (target->delegate()) { |
| + if (target && target->delegate()) { |
| MouseEvent translated_event(event, this, target); |
| return target->OnMouseEvent(&translated_event); |
| } |
| @@ -48,6 +50,41 @@ bool RootWindow::HandleKeyEvent(const KeyEvent& event) { |
| return false; |
| } |
| +void RootWindow::SetCapture(Window* window) { |
| + if (capture_window_ == window) |
| + return; |
| + |
| + if (capture_window_ && capture_window_->delegate()) |
| + capture_window_->delegate()->OnCaptureLost(); |
| + capture_window_ = window; |
| + if (capture_window_ && capture_window_->delegate()) |
| + capture_window_->delegate()->OnCaptureGained(); |
| + |
| + if (capture_window_ && mouse_pressed_handler_) { |
| + // Make all subsequent mouse events go to the capture window. We shouldn't |
| + // need to send an event here as OnCaptureLost should take care of that. |
| + mouse_pressed_handler_ = capture_window_; |
| + } |
| +} |
| + |
| +void RootWindow::ReleaseCapture(Window* window) { |
| + if (capture_window_ != window) |
| + return; |
| + |
| + if (capture_window_ && capture_window_->delegate()) |
| + capture_window_->delegate()->OnCaptureLost(); |
| + capture_window_ = NULL; |
| +} |
| + |
| +void RootWindow::WindowDestroying(Window* window) { |
| + // When a window is being destroyed it's likely that the windows delegate |
|
Ben Goodger (Google)
2011/09/21 04:15:21
window's
WindowDelegate
delegate
|
| + // won't want events. |
| + if (mouse_pressed_handler_ == window) |
| + mouse_pressed_handler_ = NULL; |
| + if (capture_window_ == window) |
| + capture_window_ = NULL; |
| +} |
| + |
| FocusManager* RootWindow::GetFocusManager() { |
| return focus_manager_.get(); |
| } |