| 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/root_window.h" | 5 #include "ui/aura/root_window.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "ui/aura/event.h" | 9 #include "ui/aura/event.h" |
| 10 #include "ui/aura/focus_manager.h" | 10 #include "ui/aura/focus_manager.h" |
| 11 #include "ui/aura/window_delegate.h" | 11 #include "ui/aura/window_delegate.h" |
| 12 #include "ui/base/events.h" | 12 #include "ui/base/events.h" |
| 13 | 13 |
| 14 namespace aura { | 14 namespace aura { |
| 15 namespace internal { | 15 namespace internal { |
| 16 | 16 |
| 17 RootWindow::RootWindow() | 17 RootWindow::RootWindow() |
| 18 : Window(NULL), | 18 : Window(NULL), |
| 19 mouse_pressed_handler_(NULL), | 19 mouse_pressed_handler_(NULL), |
| 20 ALLOW_THIS_IN_INITIALIZER_LIST(focus_manager_(new FocusManager(this))) { | 20 ALLOW_THIS_IN_INITIALIZER_LIST(focus_manager_(new FocusManager(this))), |
| 21 capture_window_(NULL) { |
| 21 set_name(ASCIIToUTF16("RootWindow")); | 22 set_name(ASCIIToUTF16("RootWindow")); |
| 22 } | 23 } |
| 23 | 24 |
| 24 RootWindow::~RootWindow() { | 25 RootWindow::~RootWindow() { |
| 25 } | 26 } |
| 26 | 27 |
| 27 bool RootWindow::HandleMouseEvent(const MouseEvent& event) { | 28 bool RootWindow::HandleMouseEvent(const MouseEvent& event) { |
| 28 Window* target = mouse_pressed_handler_; | 29 Window* target = |
| 30 mouse_pressed_handler_ ? mouse_pressed_handler_ : capture_window_; |
| 29 if (!target) | 31 if (!target) |
| 30 target = GetEventHandlerForPoint(event.location()); | 32 target = GetEventHandlerForPoint(event.location()); |
| 31 if (event.type() == ui::ET_MOUSE_PRESSED && !mouse_pressed_handler_) | 33 if (event.type() == ui::ET_MOUSE_PRESSED && !mouse_pressed_handler_) |
| 32 mouse_pressed_handler_ = target; | 34 mouse_pressed_handler_ = target; |
| 33 if (event.type() == ui::ET_MOUSE_RELEASED) | 35 if (event.type() == ui::ET_MOUSE_RELEASED) |
| 34 mouse_pressed_handler_ = NULL; | 36 mouse_pressed_handler_ = NULL; |
| 35 if (target && target->delegate()) { | 37 if (target && target->delegate()) { |
| 36 MouseEvent translated_event(event, this, target); | 38 MouseEvent translated_event(event, this, target); |
| 37 return target->OnMouseEvent(&translated_event); | 39 return target->OnMouseEvent(&translated_event); |
| 38 } | 40 } |
| 39 return false; | 41 return false; |
| 40 } | 42 } |
| 41 | 43 |
| 42 bool RootWindow::HandleKeyEvent(const KeyEvent& event) { | 44 bool RootWindow::HandleKeyEvent(const KeyEvent& event) { |
| 43 Window* focused_window = GetFocusManager()->focused_window(); | 45 Window* focused_window = GetFocusManager()->focused_window(); |
| 44 if (focused_window) { | 46 if (focused_window) { |
| 45 KeyEvent translated_event(event); | 47 KeyEvent translated_event(event); |
| 46 return GetFocusManager()->focused_window()->OnKeyEvent(&translated_event); | 48 return GetFocusManager()->focused_window()->OnKeyEvent(&translated_event); |
| 47 } | 49 } |
| 48 return false; | 50 return false; |
| 49 } | 51 } |
| 50 | 52 |
| 53 void RootWindow::SetCapture(Window* window) { |
| 54 if (capture_window_ == window) |
| 55 return; |
| 56 |
| 57 if (capture_window_ && capture_window_->delegate()) |
| 58 capture_window_->delegate()->OnCaptureLost(); |
| 59 capture_window_ = window; |
| 60 |
| 61 if (capture_window_ && mouse_pressed_handler_) { |
| 62 // Make all subsequent mouse events go to the capture window. We shouldn't |
| 63 // need to send an event here as OnCaptureLost should take care of that. |
| 64 mouse_pressed_handler_ = capture_window_; |
| 65 } |
| 66 } |
| 67 |
| 68 void RootWindow::ReleaseCapture(Window* window) { |
| 69 if (capture_window_ != window) |
| 70 return; |
| 71 |
| 72 if (capture_window_ && capture_window_->delegate()) |
| 73 capture_window_->delegate()->OnCaptureLost(); |
| 74 capture_window_ = NULL; |
| 75 } |
| 76 |
| 77 void RootWindow::WindowDestroying(Window* window) { |
| 78 // Update the FocusManager if the window was focused. |
| 79 internal::FocusManager* focus_manager = GetFocusManager(); |
| 80 if (focus_manager && focus_manager->focused_window() == window) |
| 81 focus_manager->SetFocusedWindow(NULL); |
| 82 |
| 83 // When a window is being destroyed it's likely that the WindowDelegate won't |
| 84 // want events, so we reset the mouse_pressed_handler_ and capture_window_ and |
| 85 // don't sent it release/capture lost events. |
| 86 if (mouse_pressed_handler_ == window) |
| 87 mouse_pressed_handler_ = NULL; |
| 88 if (capture_window_ == window) |
| 89 capture_window_ = NULL; |
| 90 } |
| 91 |
| 51 FocusManager* RootWindow::GetFocusManager() { | 92 FocusManager* RootWindow::GetFocusManager() { |
| 52 return focus_manager_.get(); | 93 return focus_manager_.get(); |
| 53 } | 94 } |
| 54 | 95 |
| 96 internal::RootWindow* RootWindow::GetRoot() { |
| 97 return this; |
| 98 } |
| 99 |
| 55 } // namespace internal | 100 } // namespace internal |
| 56 } // namespace aura | 101 } // namespace aura |
| OLD | NEW |