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 DCHECK(event.type() == ui::ET_MOUSE_PRESSED || | |
220 event.type() == ui::ET_GESTURE_TAP_DOWN); | |
219 // We allow for only one outstanding repostable event. This is used | 221 // We allow for only one outstanding repostable event. This is used |
220 // in exiting context menus. A dropped repost request is allowed. | 222 // in exiting context menus. A dropped repost request is allowed. |
221 if (event.type() == ui::ET_MOUSE_PRESSED) { | 223 if (event.type() == ui::ET_MOUSE_PRESSED) { |
222 held_repostable_event_.reset( | 224 held_repostable_event_.reset( |
223 new ui::MouseEvent( | 225 new ui::MouseEvent( |
224 static_cast<const ui::MouseEvent&>(event), | 226 static_cast<const ui::MouseEvent&>(event), |
225 static_cast<aura::Window*>(event.target()), | 227 static_cast<aura::Window*>(event.target()), |
226 static_cast<aura::Window*>(this))); | 228 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 { | 229 } else { |
232 DCHECK(event.type() == ui::ET_GESTURE_TAP_DOWN); | 230 const ui::GestureEvent* gesture_event = |
233 held_repostable_event_.reset(); | 231 static_cast<const ui::GestureEvent*>(&event); |
234 // TODO(sschmitz): add similar code for gesture events. | 232 held_repostable_event_.reset(new ui::GestureEvent( |
sadrul
2013/08/23 03:16:03
Can you use 'new ui::GestureEvent(event, event.tar
| |
233 gesture_event->type(), | |
234 gesture_event->root_location().x(), | |
235 gesture_event->root_location().y(), | |
236 gesture_event->flags(), | |
237 gesture_event->time_stamp(), | |
238 gesture_event->details(), | |
239 gesture_event->touch_ids_bitfield())); | |
235 } | 240 } |
241 base::MessageLoop::current()->PostTask( | |
242 FROM_HERE, | |
243 base::Bind(&RootWindow::DispatchHeldEvents, | |
244 repostable_event_factory_.GetWeakPtr())); | |
236 } | 245 } |
237 | 246 |
238 RootWindowHostDelegate* RootWindow::AsRootWindowHostDelegate() { | 247 RootWindowHostDelegate* RootWindow::AsRootWindowHostDelegate() { |
239 return this; | 248 return this; |
240 } | 249 } |
241 | 250 |
242 void RootWindow::SetHostSize(const gfx::Size& size_in_pixel) { | 251 void RootWindow::SetHostSize(const gfx::Size& size_in_pixel) { |
243 DispatchHeldEvents(); | 252 DispatchHeldEvents(); |
244 gfx::Rect bounds = host_->GetBounds(); | 253 gfx::Rect bounds = host_->GetBounds(); |
245 bounds.set_size(size_in_pixel); | 254 bounds.set_size(size_in_pixel); |
(...skipping 764 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1010 } | 1019 } |
1011 | 1020 |
1012 bool RootWindow::DispatchMouseEventRepost(ui::MouseEvent* event) { | 1021 bool RootWindow::DispatchMouseEventRepost(ui::MouseEvent* event) { |
1013 if (event->type() != ui::ET_MOUSE_PRESSED) | 1022 if (event->type() != ui::ET_MOUSE_PRESSED) |
1014 return false; | 1023 return false; |
1015 mouse_pressed_handler_ = NULL; | 1024 mouse_pressed_handler_ = NULL; |
1016 Window* target = GetEventHandlerForPoint(event->location()); | 1025 Window* target = GetEventHandlerForPoint(event->location()); |
1017 return DispatchMouseEventToTarget(event, target); | 1026 return DispatchMouseEventToTarget(event, target); |
1018 } | 1027 } |
1019 | 1028 |
1029 bool RootWindow::DispatchGestureEventRepost(ui::GestureEvent* event) { | |
1030 if (event->type() != ui::ET_GESTURE_TAP_DOWN) | |
1031 return false; | |
1032 | |
1033 // Cleanup stale gesture events for the old gesture target. | |
1034 GestureConsumer* old_consumer = GetGestureTarget(event); | |
1035 if (old_consumer) | |
1036 CleanupGestureRecognizerState(static_cast<aura::Window*>(old_consumer)); | |
1037 | |
1038 Window* new_consumer = GetEventHandlerForPoint(event->root_location()); | |
sadrul
2013/08/23 03:16:03
This code should dispatch a GESTURE_BEGIN event be
| |
1039 if (new_consumer) { | |
1040 ProcessEvent(new_consumer, event); | |
1041 return event->handled(); | |
1042 } | |
1043 return false; | |
1044 } | |
1045 | |
1020 bool RootWindow::DispatchMouseEventToTarget(ui::MouseEvent* event, | 1046 bool RootWindow::DispatchMouseEventToTarget(ui::MouseEvent* event, |
1021 Window* target) { | 1047 Window* target) { |
1022 client::CursorClient* cursor_client = client::GetCursorClient(this); | 1048 client::CursorClient* cursor_client = client::GetCursorClient(this); |
1023 if (cursor_client && | 1049 if (cursor_client && |
1024 !cursor_client->IsMouseEventsEnabled() && | 1050 !cursor_client->IsMouseEventsEnabled() && |
1025 (event->flags() & ui::EF_IS_SYNTHESIZED)) | 1051 (event->flags() & ui::EF_IS_SYNTHESIZED)) |
1026 return false; | 1052 return false; |
1027 | 1053 |
1028 static const int kMouseButtonFlagMask = | 1054 static const int kMouseButtonFlagMask = |
1029 ui::EF_LEFT_MOUSE_BUTTON | | 1055 ui::EF_LEFT_MOUSE_BUTTON | |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1137 event_for_gr, result, target)); | 1163 event_for_gr, result, target)); |
1138 | 1164 |
1139 return ProcessGestures(gestures.get()) ? true : handled; | 1165 return ProcessGestures(gestures.get()) ? true : handled; |
1140 } | 1166 } |
1141 | 1167 |
1142 void RootWindow::DispatchHeldEvents() { | 1168 void RootWindow::DispatchHeldEvents() { |
1143 if (held_repostable_event_) { | 1169 if (held_repostable_event_) { |
1144 if (held_repostable_event_->type() == ui::ET_MOUSE_PRESSED) { | 1170 if (held_repostable_event_->type() == ui::ET_MOUSE_PRESSED) { |
1145 ui::MouseEvent mouse_event( | 1171 ui::MouseEvent mouse_event( |
1146 static_cast<const ui::MouseEvent&>(*held_repostable_event_.get())); | 1172 static_cast<const ui::MouseEvent&>(*held_repostable_event_.get())); |
1147 held_repostable_event_.reset(); // must be reset before dispatch | 1173 held_repostable_event_.reset(); // must be reset before dispatch |
1148 DispatchMouseEventRepost(&mouse_event); | 1174 DispatchMouseEventRepost(&mouse_event); |
1149 } else { | 1175 } else { |
1150 DCHECK(held_repostable_event_->type() == ui::ET_GESTURE_TAP_DOWN); | 1176 DCHECK(held_repostable_event_->type() == ui::ET_GESTURE_TAP_DOWN); |
1151 // TODO(sschmitz): add similar code for gesture events | 1177 ui::GestureEvent gesture_event( |
1178 static_cast<const ui::GestureEvent&>(*held_repostable_event_.get())); | |
1179 held_repostable_event_.reset(); // must be reset before dispatch | |
1180 DispatchGestureEventRepost(&gesture_event); | |
1152 } | 1181 } |
1153 held_repostable_event_.reset(); | 1182 held_repostable_event_.reset(); |
1154 } | 1183 } |
1155 if (held_move_event_ && held_move_event_->IsMouseEvent()) { | 1184 if (held_move_event_ && held_move_event_->IsMouseEvent()) { |
1156 // If a mouse move has been synthesized, the target location is suspect, | 1185 // If a mouse move has been synthesized, the target location is suspect, |
1157 // so drop the held event. | 1186 // so drop the held event. |
1158 if (!synthesize_mouse_move_) | 1187 if (!synthesize_mouse_move_) |
1159 DispatchMouseEventImpl( | 1188 DispatchMouseEventImpl( |
1160 static_cast<ui::MouseEvent*>(held_move_event_.get())); | 1189 static_cast<ui::MouseEvent*>(held_move_event_.get())); |
1161 held_move_event_.reset(); | 1190 held_move_event_.reset(); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1194 } | 1223 } |
1195 | 1224 |
1196 gfx::Transform RootWindow::GetInverseRootTransform() const { | 1225 gfx::Transform RootWindow::GetInverseRootTransform() const { |
1197 float scale = ui::GetDeviceScaleFactor(layer()); | 1226 float scale = ui::GetDeviceScaleFactor(layer()); |
1198 gfx::Transform transform; | 1227 gfx::Transform transform; |
1199 transform.Scale(1.0f / scale, 1.0f / scale); | 1228 transform.Scale(1.0f / scale, 1.0f / scale); |
1200 return transformer_->GetInverseTransform() * transform; | 1229 return transformer_->GetInverseTransform() * transform; |
1201 } | 1230 } |
1202 | 1231 |
1203 } // namespace aura | 1232 } // namespace aura |
OLD | NEW |