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/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, true), |
| 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->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 if (capture_window_ && capture_window_->delegate()) | |
| 61 capture_window_->delegate()->OnCaptureGained(); | |
| 62 | |
| 63 if (capture_window_ && mouse_pressed_handler_) { | |
| 64 // Make all subsequent mouse events go to the capture window. We shouldn't | |
| 65 // need to send an event here as OnCaptureLost should take care of that. | |
| 66 mouse_pressed_handler_ = capture_window_; | |
| 67 } | |
| 68 } | |
| 69 | |
| 70 void RootWindow::ReleaseCapture(Window* window) { | |
| 71 if (capture_window_ != window) | |
| 72 return; | |
| 73 | |
| 74 if (capture_window_ && capture_window_->delegate()) | |
| 75 capture_window_->delegate()->OnCaptureLost(); | |
| 76 capture_window_ = NULL; | |
| 77 } | |
| 78 | |
| 79 void RootWindow::WindowDestroying(Window* window) { | |
| 80 // 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
| |
| 81 // won't want events. | |
| 82 if (mouse_pressed_handler_ == window) | |
| 83 mouse_pressed_handler_ = NULL; | |
| 84 if (capture_window_ == window) | |
| 85 capture_window_ = NULL; | |
| 86 } | |
| 87 | |
| 51 FocusManager* RootWindow::GetFocusManager() { | 88 FocusManager* RootWindow::GetFocusManager() { |
| 52 return focus_manager_.get(); | 89 return focus_manager_.get(); |
| 53 } | 90 } |
| 54 | 91 |
| 55 } // namespace internal | 92 } // namespace internal |
| 56 } // namespace aura | 93 } // namespace aura |
| OLD | NEW |