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), |
| 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 set_name(ASCIIToUTF16("RootWindow")); | 21 set_name(ASCIIToUTF16("RootWindow")); |
| 22 } | 22 } |
| 23 | 23 |
| 24 RootWindow::~RootWindow() { | 24 RootWindow::~RootWindow() { |
| 25 } | 25 } |
| 26 | 26 |
| 27 bool RootWindow::HandleMouseEvent(const MouseEvent& event) { | 27 bool RootWindow::HandleMouseEvent(const MouseEvent& event) { |
| 28 Window* target = mouse_pressed_handler_; | 28 Window* target = mouse_pressed_handler_; |
| 29 if (!target) | 29 if (!target) |
| 30 target = GetEventHandlerForPoint(event.location()); | 30 target = GetEventHandlerForPoint(event.location()); |
|
sadrul
2011/09/21 14:24:39
Or may be return early if target is NULL here?
| |
| 31 if (event.type() == ui::ET_MOUSE_PRESSED && !mouse_pressed_handler_) | 31 if (event.type() == ui::ET_MOUSE_PRESSED && !mouse_pressed_handler_) |
| 32 mouse_pressed_handler_ = target; | 32 mouse_pressed_handler_ = target; |
| 33 if (event.type() == ui::ET_MOUSE_RELEASED) | 33 if (event.type() == ui::ET_MOUSE_RELEASED) |
| 34 mouse_pressed_handler_ = NULL; | 34 mouse_pressed_handler_ = NULL; |
| 35 if (target->delegate()) { | 35 if (target && target->delegate()) { |
| 36 MouseEvent translated_event(event, this, target); | 36 MouseEvent translated_event(event, this, target); |
| 37 return target->OnMouseEvent(&translated_event); | 37 return target->OnMouseEvent(&translated_event); |
| 38 } | 38 } |
| 39 return false; | 39 return false; |
| 40 } | 40 } |
| 41 | 41 |
| 42 bool RootWindow::HandleKeyEvent(const KeyEvent& event) { | 42 bool RootWindow::HandleKeyEvent(const KeyEvent& event) { |
| 43 Window* focused_window = GetFocusManager()->focused_window(); | 43 Window* focused_window = GetFocusManager()->focused_window(); |
| 44 if (focused_window) { | 44 if (focused_window) { |
| 45 KeyEvent translated_event(event); | 45 KeyEvent translated_event(event); |
| 46 return GetFocusManager()->focused_window()->OnKeyEvent(&translated_event); | 46 return GetFocusManager()->focused_window()->OnKeyEvent(&translated_event); |
| 47 } | 47 } |
| 48 return false; | 48 return false; |
| 49 } | 49 } |
| 50 | 50 |
| 51 FocusManager* RootWindow::GetFocusManager() { | 51 FocusManager* RootWindow::GetFocusManager() { |
| 52 return focus_manager_.get(); | 52 return focus_manager_.get(); |
| 53 } | 53 } |
| 54 | 54 |
| 55 } // namespace internal | 55 } // namespace internal |
| 56 } // namespace aura | 56 } // namespace aura |
| OLD | NEW |