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 mouse_moved_handler_(NULL), | |
20 ALLOW_THIS_IN_INITIALIZER_LIST(focus_manager_(new FocusManager(this))), | 21 ALLOW_THIS_IN_INITIALIZER_LIST(focus_manager_(new FocusManager(this))), |
21 capture_window_(NULL) { | 22 capture_window_(NULL) { |
22 set_name(ASCIIToUTF16("RootWindow")); | 23 set_name(ASCIIToUTF16("RootWindow")); |
23 } | 24 } |
24 | 25 |
25 RootWindow::~RootWindow() { | 26 RootWindow::~RootWindow() { |
26 } | 27 } |
27 | 28 |
28 bool RootWindow::HandleMouseEvent(const MouseEvent& event) { | 29 bool RootWindow::HandleMouseEvent(const MouseEvent& event) { |
29 Window* target = | 30 Window* target = |
30 mouse_pressed_handler_ ? mouse_pressed_handler_ : capture_window_; | 31 mouse_pressed_handler_ ? mouse_pressed_handler_ : capture_window_; |
31 if (!target) | 32 if (!target) |
32 target = GetEventHandlerForPoint(event.location()); | 33 target = GetEventHandlerForPoint(event.location()); |
33 if (event.type() == ui::ET_MOUSE_PRESSED && !mouse_pressed_handler_) | 34 if (event.type() == ui::ET_MOUSE_PRESSED && !mouse_pressed_handler_) |
sky
2011/09/21 20:30:54
I think it's time for a switch.
| |
34 mouse_pressed_handler_ = target; | 35 mouse_pressed_handler_ = target; |
35 if (event.type() == ui::ET_MOUSE_RELEASED) | 36 if (event.type() == ui::ET_MOUSE_RELEASED) |
36 mouse_pressed_handler_ = NULL; | 37 mouse_pressed_handler_ = NULL; |
38 if (event.type() == ui::ET_MOUSE_MOVED) | |
39 HandleMouseMoved(event, target); | |
37 if (target && target->delegate()) { | 40 if (target && target->delegate()) { |
38 MouseEvent translated_event(event, this, target); | 41 MouseEvent translated_event(event, this, target); |
39 return target->OnMouseEvent(&translated_event); | 42 return target->OnMouseEvent(&translated_event); |
40 } | 43 } |
41 return false; | 44 return false; |
42 } | 45 } |
43 | 46 |
44 bool RootWindow::HandleKeyEvent(const KeyEvent& event) { | 47 bool RootWindow::HandleKeyEvent(const KeyEvent& event) { |
45 Window* focused_window = GetFocusManager()->focused_window(); | 48 Window* focused_window = GetFocusManager()->focused_window(); |
46 if (focused_window) { | 49 if (focused_window) { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
78 // Update the FocusManager if the window was focused. | 81 // Update the FocusManager if the window was focused. |
79 internal::FocusManager* focus_manager = GetFocusManager(); | 82 internal::FocusManager* focus_manager = GetFocusManager(); |
80 if (focus_manager && focus_manager->focused_window() == window) | 83 if (focus_manager && focus_manager->focused_window() == window) |
81 focus_manager->SetFocusedWindow(NULL); | 84 focus_manager->SetFocusedWindow(NULL); |
82 | 85 |
83 // When a window is being destroyed it's likely that the WindowDelegate won't | 86 // 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 | 87 // want events, so we reset the mouse_pressed_handler_ and capture_window_ and |
85 // don't sent it release/capture lost events. | 88 // don't sent it release/capture lost events. |
86 if (mouse_pressed_handler_ == window) | 89 if (mouse_pressed_handler_ == window) |
87 mouse_pressed_handler_ = NULL; | 90 mouse_pressed_handler_ = NULL; |
91 if (mouse_moved_handler_ == window) | |
92 mouse_moved_handler_ = NULL; | |
88 if (capture_window_ == window) | 93 if (capture_window_ == window) |
89 capture_window_ = NULL; | 94 capture_window_ = NULL; |
90 } | 95 } |
91 | 96 |
92 FocusManager* RootWindow::GetFocusManager() { | 97 FocusManager* RootWindow::GetFocusManager() { |
93 return focus_manager_.get(); | 98 return focus_manager_.get(); |
94 } | 99 } |
95 | 100 |
96 internal::RootWindow* RootWindow::GetRoot() { | 101 internal::RootWindow* RootWindow::GetRoot() { |
97 return this; | 102 return this; |
98 } | 103 } |
99 | 104 |
105 void RootWindow::HandleMouseMoved(const MouseEvent& event, Window* target) { | |
106 if (target == mouse_moved_handler_) | |
107 return; | |
108 | |
109 // Send an exited event. | |
110 if (mouse_moved_handler_) { | |
sky
2011/09/21 20:30:54
Do you need to make sure mouse_moved_handler_ has
| |
111 MouseEvent translated_event(event, this, mouse_moved_handler_, | |
112 ui::ET_MOUSE_EXITED); | |
113 mouse_moved_handler_->OnMouseEvent(&translated_event); | |
114 } | |
115 mouse_moved_handler_ = target; | |
116 // Send an entered event. | |
117 if (mouse_moved_handler_) { | |
118 MouseEvent translated_event(event, this, mouse_moved_handler_, | |
119 ui::ET_MOUSE_ENTERED); | |
120 mouse_moved_handler_->OnMouseEvent(&translated_event); | |
121 } | |
122 } | |
123 | |
100 } // namespace internal | 124 } // namespace internal |
101 } // namespace aura | 125 } // namespace aura |
OLD | NEW |