OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
209 host_->Hide(); | 209 host_->Hide(); |
210 } | 210 } |
211 | 211 |
212 void RootWindow::PrepareForShutdown() { | 212 void RootWindow::PrepareForShutdown() { |
213 host_->PrepareForShutdown(); | 213 host_->PrepareForShutdown(); |
214 // discard synthesize event request as well. | 214 // discard synthesize event request as well. |
215 synthesize_mouse_move_ = false; | 215 synthesize_mouse_move_ = false; |
216 } | 216 } |
217 | 217 |
218 void RootWindow::RepostEvent(const ui::LocatedEvent& event) { | 218 void RootWindow::RepostEvent(const ui::LocatedEvent& event) { |
219 if (event.type() != ui::ET_MOUSE_PRESSED && | |
sky
2013/08/22 22:07:16
I think this should just be a DCHECK. Also, docume
ananta
2013/08/22 22:48:15
Done.
| |
220 event.type() != ui::ET_GESTURE_TAP_DOWN) { | |
221 NOTREACHED() << "Invalid event type: " << event.type(); | |
222 return; | |
223 } | |
219 // We allow for only one outstanding repostable event. This is used | 224 // We allow for only one outstanding repostable event. This is used |
220 // in exiting context menus. A dropped repost request is allowed. | 225 // in exiting context menus. A dropped repost request is allowed. |
221 if (event.type() == ui::ET_MOUSE_PRESSED) { | 226 if (event.type() == ui::ET_MOUSE_PRESSED) { |
222 held_repostable_event_.reset( | 227 held_repostable_event_.reset( |
223 new ui::MouseEvent( | 228 new ui::MouseEvent( |
224 static_cast<const ui::MouseEvent&>(event), | 229 static_cast<const ui::MouseEvent&>(event), |
225 static_cast<aura::Window*>(event.target()), | 230 static_cast<aura::Window*>(event.target()), |
226 static_cast<aura::Window*>(this))); | 231 static_cast<aura::Window*>(this))); |
227 base::MessageLoop::current()->PostTask( | |
228 FROM_HERE, | |
229 base::Bind(&RootWindow::DispatchHeldEvents, | |
230 repostable_event_factory_.GetWeakPtr())); | |
231 } else { | 232 } else { |
232 DCHECK(event.type() == ui::ET_GESTURE_TAP_DOWN); | 233 const ui::GestureEvent* gesture_event = |
233 held_repostable_event_.reset(); | 234 static_cast<const ui::GestureEvent*>(&event); |
234 // TODO(sschmitz): add similar code for gesture events. | 235 held_repostable_event_.reset(new ui::GestureEvent( |
236 gesture_event->type(), | |
237 gesture_event->root_location().x(), | |
238 gesture_event->root_location().y(), | |
239 gesture_event->flags(), | |
240 gesture_event->time_stamp(), | |
241 gesture_event->details(), | |
242 gesture_event->touch_ids_bitfield())); | |
235 } | 243 } |
244 base::MessageLoop::current()->PostTask( | |
245 FROM_HERE, | |
246 base::Bind(&RootWindow::DispatchHeldEvents, | |
247 repostable_event_factory_.GetWeakPtr())); | |
236 } | 248 } |
237 | 249 |
238 RootWindowHostDelegate* RootWindow::AsRootWindowHostDelegate() { | 250 RootWindowHostDelegate* RootWindow::AsRootWindowHostDelegate() { |
239 return this; | 251 return this; |
240 } | 252 } |
241 | 253 |
242 void RootWindow::SetHostSize(const gfx::Size& size_in_pixel) { | 254 void RootWindow::SetHostSize(const gfx::Size& size_in_pixel) { |
243 DispatchHeldEvents(); | 255 DispatchHeldEvents(); |
244 gfx::Rect bounds = host_->GetBounds(); | 256 gfx::Rect bounds = host_->GetBounds(); |
245 bounds.set_size(size_in_pixel); | 257 bounds.set_size(size_in_pixel); |
(...skipping 764 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1010 } | 1022 } |
1011 | 1023 |
1012 bool RootWindow::DispatchMouseEventRepost(ui::MouseEvent* event) { | 1024 bool RootWindow::DispatchMouseEventRepost(ui::MouseEvent* event) { |
1013 if (event->type() != ui::ET_MOUSE_PRESSED) | 1025 if (event->type() != ui::ET_MOUSE_PRESSED) |
1014 return false; | 1026 return false; |
1015 mouse_pressed_handler_ = NULL; | 1027 mouse_pressed_handler_ = NULL; |
1016 Window* target = GetEventHandlerForPoint(event->location()); | 1028 Window* target = GetEventHandlerForPoint(event->location()); |
1017 return DispatchMouseEventToTarget(event, target); | 1029 return DispatchMouseEventToTarget(event, target); |
1018 } | 1030 } |
1019 | 1031 |
1032 bool RootWindow::DispatchGestureEventRepost(ui::GestureEvent* event) { | |
1033 if (event->type() != ui::ET_GESTURE_TAP_DOWN) | |
1034 return false; | |
1035 | |
1036 // Cleanup stale gesture events for the old gesture target. | |
1037 GestureConsumer* old_consumer = GetGestureTarget(event); | |
1038 if (old_consumer) { | |
sky
2013/08/22 22:07:16
nit: no {}
ananta
2013/08/22 22:48:15
Done.
| |
1039 CleanupGestureRecognizerState(static_cast<aura::Window*>(old_consumer)); | |
1040 } | |
1041 | |
1042 Window* new_consumer = GetEventHandlerForPoint(event->root_location()); | |
1043 if (new_consumer) { | |
1044 ProcessEvent(new_consumer, event); | |
1045 return event->handled(); | |
1046 } | |
1047 return false; | |
1048 } | |
1049 | |
1020 bool RootWindow::DispatchMouseEventToTarget(ui::MouseEvent* event, | 1050 bool RootWindow::DispatchMouseEventToTarget(ui::MouseEvent* event, |
1021 Window* target) { | 1051 Window* target) { |
1022 client::CursorClient* cursor_client = client::GetCursorClient(this); | 1052 client::CursorClient* cursor_client = client::GetCursorClient(this); |
1023 if (cursor_client && | 1053 if (cursor_client && |
1024 !cursor_client->IsMouseEventsEnabled() && | 1054 !cursor_client->IsMouseEventsEnabled() && |
1025 (event->flags() & ui::EF_IS_SYNTHESIZED)) | 1055 (event->flags() & ui::EF_IS_SYNTHESIZED)) |
1026 return false; | 1056 return false; |
1027 | 1057 |
1028 static const int kMouseButtonFlagMask = | 1058 static const int kMouseButtonFlagMask = |
1029 ui::EF_LEFT_MOUSE_BUTTON | | 1059 ui::EF_LEFT_MOUSE_BUTTON | |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1137 event_for_gr, result, target)); | 1167 event_for_gr, result, target)); |
1138 | 1168 |
1139 return ProcessGestures(gestures.get()) ? true : handled; | 1169 return ProcessGestures(gestures.get()) ? true : handled; |
1140 } | 1170 } |
1141 | 1171 |
1142 void RootWindow::DispatchHeldEvents() { | 1172 void RootWindow::DispatchHeldEvents() { |
1143 if (held_repostable_event_) { | 1173 if (held_repostable_event_) { |
1144 if (held_repostable_event_->type() == ui::ET_MOUSE_PRESSED) { | 1174 if (held_repostable_event_->type() == ui::ET_MOUSE_PRESSED) { |
1145 ui::MouseEvent mouse_event( | 1175 ui::MouseEvent mouse_event( |
1146 static_cast<const ui::MouseEvent&>(*held_repostable_event_.get())); | 1176 static_cast<const ui::MouseEvent&>(*held_repostable_event_.get())); |
1147 held_repostable_event_.reset(); // must be reset before dispatch | 1177 held_repostable_event_.reset(); // must be reset before dispatch |
1148 DispatchMouseEventRepost(&mouse_event); | 1178 DispatchMouseEventRepost(&mouse_event); |
1149 } else { | 1179 } else { |
1150 DCHECK(held_repostable_event_->type() == ui::ET_GESTURE_TAP_DOWN); | 1180 DCHECK(held_repostable_event_->type() == ui::ET_GESTURE_TAP_DOWN); |
1151 // TODO(sschmitz): add similar code for gesture events | 1181 ui::GestureEvent gesture_event( |
1182 static_cast<const ui::GestureEvent&>(*held_repostable_event_.get())); | |
1183 held_repostable_event_.reset(); // must be reset before dispatch | |
1184 DispatchGestureEventRepost(&gesture_event); | |
1152 } | 1185 } |
1153 held_repostable_event_.reset(); | 1186 held_repostable_event_.reset(); |
1154 } | 1187 } |
1155 if (held_move_event_ && held_move_event_->IsMouseEvent()) { | 1188 if (held_move_event_ && held_move_event_->IsMouseEvent()) { |
1156 // If a mouse move has been synthesized, the target location is suspect, | 1189 // If a mouse move has been synthesized, the target location is suspect, |
1157 // so drop the held event. | 1190 // so drop the held event. |
1158 if (!synthesize_mouse_move_) | 1191 if (!synthesize_mouse_move_) |
1159 DispatchMouseEventImpl( | 1192 DispatchMouseEventImpl( |
1160 static_cast<ui::MouseEvent*>(held_move_event_.get())); | 1193 static_cast<ui::MouseEvent*>(held_move_event_.get())); |
1161 held_move_event_.reset(); | 1194 held_move_event_.reset(); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1194 } | 1227 } |
1195 | 1228 |
1196 gfx::Transform RootWindow::GetInverseRootTransform() const { | 1229 gfx::Transform RootWindow::GetInverseRootTransform() const { |
1197 float scale = ui::GetDeviceScaleFactor(layer()); | 1230 float scale = ui::GetDeviceScaleFactor(layer()); |
1198 gfx::Transform transform; | 1231 gfx::Transform transform; |
1199 transform.Scale(1.0f / scale, 1.0f / scale); | 1232 transform.Scale(1.0f / scale, 1.0f / scale); |
1200 return transformer_->GetInverseTransform() * transform; | 1233 return transformer_->GetInverseTransform() * transform; |
1201 } | 1234 } |
1202 | 1235 |
1203 } // namespace aura | 1236 } // namespace aura |
OLD | NEW |