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 "win8/metro_driver/stdafx.h" | 5 #include "win8/metro_driver/stdafx.h" |
6 #include "win8/metro_driver/chrome_app_view_ash.h" | 6 #include "win8/metro_driver/chrome_app_view_ash.h" |
7 | 7 |
8 #include <windows.foundation.h> | 8 #include <windows.foundation.h> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
13 #include "base/path_service.h" | 13 #include "base/path_service.h" |
14 #include "base/process_util.h" | 14 #include "base/process_util.h" |
15 #include "base/threading/thread.h" | 15 #include "base/threading/thread.h" |
16 #include "base/win/metro.h" | 16 #include "base/win/metro.h" |
17 #include "base/win/win_util.h" | 17 #include "base/win/win_util.h" |
18 #include "chrome/common/chrome_switches.h" | 18 #include "chrome/common/chrome_switches.h" |
19 #include "ipc/ipc_channel.h" | 19 #include "ipc/ipc_channel.h" |
20 #include "ipc/ipc_channel_proxy.h" | 20 #include "ipc/ipc_channel_proxy.h" |
21 #include "ipc/ipc_sender.h" | 21 #include "ipc/ipc_sender.h" |
| 22 #include "ui/base/gestures/gesture_sequence.h" |
22 #include "ui/metro_viewer/metro_viewer_messages.h" | 23 #include "ui/metro_viewer/metro_viewer_messages.h" |
23 #include "win8/metro_driver/file_picker_ash.h" | 24 #include "win8/metro_driver/file_picker_ash.h" |
24 #include "win8/metro_driver/metro_driver.h" | 25 #include "win8/metro_driver/metro_driver.h" |
25 #include "win8/metro_driver/winrt_utils.h" | 26 #include "win8/metro_driver/winrt_utils.h" |
26 | 27 |
27 typedef winfoundtn::ITypedEventHandler< | 28 typedef winfoundtn::ITypedEventHandler< |
28 winapp::Core::CoreApplicationView*, | 29 winapp::Core::CoreApplicationView*, |
29 winapp::Activation::IActivatedEventArgs*> ActivatedHandler; | 30 winapp::Activation::IActivatedEventArgs*> ActivatedHandler; |
30 | 31 |
31 typedef winfoundtn::ITypedEventHandler< | 32 typedef winfoundtn::ITypedEventHandler< |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 } | 139 } |
139 | 140 |
140 // This class helps decoding the pointer properties of an event. | 141 // This class helps decoding the pointer properties of an event. |
141 class PointerInfoHandler { | 142 class PointerInfoHandler { |
142 public: | 143 public: |
143 PointerInfoHandler() : | 144 PointerInfoHandler() : |
144 x_(0), | 145 x_(0), |
145 y_(0), | 146 y_(0), |
146 wheel_delta_(0), | 147 wheel_delta_(0), |
147 update_kind_(winui::Input::PointerUpdateKind_Other), | 148 update_kind_(winui::Input::PointerUpdateKind_Other), |
148 timestamp_(0) {} | 149 timestamp_(0), |
| 150 pointer_id_(0) {} |
149 | 151 |
150 HRESULT Init(winui::Core::IPointerEventArgs* args) { | 152 HRESULT Init(winui::Core::IPointerEventArgs* args) { |
151 HRESULT hr = args->get_CurrentPoint(&pointer_point_); | 153 HRESULT hr = args->get_CurrentPoint(&pointer_point_); |
152 if (FAILED(hr)) | 154 if (FAILED(hr)) |
153 return hr; | 155 return hr; |
154 | 156 |
155 winfoundtn::Point point; | 157 winfoundtn::Point point; |
156 hr = pointer_point_->get_Position(&point); | 158 hr = pointer_point_->get_Position(&point); |
157 if (FAILED(hr)) | 159 if (FAILED(hr)) |
158 return hr; | 160 return hr; |
159 | 161 |
160 mswr::ComPtr<winui::Input::IPointerPointProperties> properties; | 162 mswr::ComPtr<winui::Input::IPointerPointProperties> properties; |
161 hr = pointer_point_->get_Properties(&properties); | 163 hr = pointer_point_->get_Properties(&properties); |
162 if (FAILED(hr)) | 164 if (FAILED(hr)) |
163 return hr; | 165 return hr; |
164 | 166 |
165 hr = properties->get_PointerUpdateKind(&update_kind_); | 167 hr = properties->get_PointerUpdateKind(&update_kind_); |
166 if (FAILED(hr)) | 168 if (FAILED(hr)) |
167 return hr; | 169 return hr; |
168 | 170 |
169 hr = properties->get_MouseWheelDelta(&wheel_delta_); | 171 hr = properties->get_MouseWheelDelta(&wheel_delta_); |
170 if (FAILED(hr)) | 172 if (FAILED(hr)) |
171 return hr; | 173 return hr; |
172 | |
173 x_ = point.X; | 174 x_ = point.X; |
174 y_ = point.Y; | 175 y_ = point.Y; |
175 pointer_point_->get_Timestamp(×tamp_); | 176 pointer_point_->get_Timestamp(×tamp_); |
| 177 pointer_point_->get_PointerId(&pointer_id_); |
| 178 // Map the OS touch event id to a range allowed by the gesture recognizer. |
| 179 if (IsTouch()) |
| 180 pointer_id_ %= ui::GestureSequence::kMaxGesturePoints; |
176 return S_OK; | 181 return S_OK; |
177 } | 182 } |
178 | 183 |
179 bool IsType(windevs::Input::PointerDeviceType type) const { | 184 bool IsType(windevs::Input::PointerDeviceType type) const { |
180 mswr::ComPtr<windevs::Input::IPointerDevice> pointer_device; | 185 mswr::ComPtr<windevs::Input::IPointerDevice> pointer_device; |
181 CheckHR(pointer_point_->get_PointerDevice(&pointer_device)); | 186 CheckHR(pointer_point_->get_PointerDevice(&pointer_device)); |
182 windevs::Input::PointerDeviceType device_type; | 187 windevs::Input::PointerDeviceType device_type; |
183 CheckHR(pointer_device->get_PointerDeviceType(&device_type)); | 188 CheckHR(pointer_device->get_PointerDeviceType(&device_type)); |
184 return (device_type == type); | 189 return (device_type == type); |
185 } | 190 } |
(...skipping 25 matching lines...) Expand all Loading... |
211 case winui::Input::PointerUpdateKind_MiddleButtonReleased: | 216 case winui::Input::PointerUpdateKind_MiddleButtonReleased: |
212 return ui::EF_MIDDLE_MOUSE_BUTTON; | 217 return ui::EF_MIDDLE_MOUSE_BUTTON; |
213 default: | 218 default: |
214 return ui::EF_NONE; | 219 return ui::EF_NONE; |
215 }; | 220 }; |
216 } | 221 } |
217 | 222 |
218 int x() const { return x_; } | 223 int x() const { return x_; } |
219 int y() const { return y_; } | 224 int y() const { return y_; } |
220 | 225 |
| 226 uint32 pointer_id() const { |
| 227 return pointer_id_; |
| 228 } |
| 229 |
221 uint64 timestamp() const { return timestamp_; } | 230 uint64 timestamp() const { return timestamp_; } |
222 | 231 |
223 private: | 232 private: |
224 int x_; | 233 int x_; |
225 int y_; | 234 int y_; |
226 int wheel_delta_; | 235 int wheel_delta_; |
| 236 uint32 pointer_id_; |
227 winui::Input::PointerUpdateKind update_kind_; | 237 winui::Input::PointerUpdateKind update_kind_; |
228 mswr::ComPtr<winui::Input::IPointerPoint> pointer_point_; | 238 mswr::ComPtr<winui::Input::IPointerPoint> pointer_point_; |
229 uint64 timestamp_; | 239 uint64 timestamp_; |
230 }; | 240 }; |
231 | 241 |
232 void RunMessageLoop(winui::Core::ICoreDispatcher* dispatcher) { | 242 void RunMessageLoop(winui::Core::ICoreDispatcher* dispatcher) { |
233 // We're entering a nested message loop, let's allow dispatching | 243 // We're entering a nested message loop, let's allow dispatching |
234 // tasks while we're in there. | 244 // tasks while we're in there. |
235 MessageLoop::current()->SetNestableTasksAllowed(true); | 245 MessageLoop::current()->SetNestableTasksAllowed(true); |
236 | 246 |
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
541 return hr; | 551 return hr; |
542 | 552 |
543 if (pointer.IsMouse()) { | 553 if (pointer.IsMouse()) { |
544 ui_channel_->Send(new MetroViewerHostMsg_MouseMoved(pointer.x(), | 554 ui_channel_->Send(new MetroViewerHostMsg_MouseMoved(pointer.x(), |
545 pointer.y(), | 555 pointer.y(), |
546 mouse_down_flags_)); | 556 mouse_down_flags_)); |
547 } else { | 557 } else { |
548 DCHECK(pointer.IsTouch()); | 558 DCHECK(pointer.IsTouch()); |
549 ui_channel_->Send(new MetroViewerHostMsg_TouchMoved(pointer.x(), | 559 ui_channel_->Send(new MetroViewerHostMsg_TouchMoved(pointer.x(), |
550 pointer.y(), | 560 pointer.y(), |
551 pointer.timestamp())); | 561 pointer.timestamp(), |
| 562 pointer.pointer_id())); |
552 } | 563 } |
553 return S_OK; | 564 return S_OK; |
554 } | 565 } |
555 | 566 |
556 // NOTE: From experimentation, it seems like Metro only sends a PointerPressed | 567 // NOTE: From experimentation, it seems like Metro only sends a PointerPressed |
557 // event for the first button pressed and the last button released in a sequence | 568 // event for the first button pressed and the last button released in a sequence |
558 // of mouse events. | 569 // of mouse events. |
559 // For example, a sequence of LEFT_DOWN, RIGHT_DOWN, LEFT_UP, RIGHT_UP results | 570 // For example, a sequence of LEFT_DOWN, RIGHT_DOWN, LEFT_UP, RIGHT_UP results |
560 // only in PointerPressed(LEFT)/PointerReleased(RIGHT) events. | 571 // only in PointerPressed(LEFT)/PointerReleased(RIGHT) events. |
561 HRESULT ChromeAppViewAsh::OnPointerPressed( | 572 HRESULT ChromeAppViewAsh::OnPointerPressed( |
562 winui::Core::ICoreWindow* sender, | 573 winui::Core::ICoreWindow* sender, |
563 winui::Core::IPointerEventArgs* args) { | 574 winui::Core::IPointerEventArgs* args) { |
564 PointerInfoHandler pointer; | 575 PointerInfoHandler pointer; |
565 HRESULT hr = pointer.Init(args); | 576 HRESULT hr = pointer.Init(args); |
566 if (FAILED(hr)) | 577 if (FAILED(hr)) |
567 return hr; | 578 return hr; |
568 | 579 |
569 if (pointer.IsMouse()) { | 580 if (pointer.IsMouse()) { |
570 mouse_down_flags_ = pointer.flags(); | 581 mouse_down_flags_ = pointer.flags(); |
571 ui_channel_->Send(new MetroViewerHostMsg_MouseButton(pointer.x(), | 582 ui_channel_->Send(new MetroViewerHostMsg_MouseButton(pointer.x(), |
572 pointer.y(), | 583 pointer.y(), |
573 0, | 584 0, |
574 ui::ET_MOUSE_PRESSED, | 585 ui::ET_MOUSE_PRESSED, |
575 mouse_down_flags_)); | 586 mouse_down_flags_)); |
576 } else { | 587 } else { |
577 DCHECK(pointer.IsTouch()); | 588 DCHECK(pointer.IsTouch()); |
578 ui_channel_->Send(new MetroViewerHostMsg_TouchDown(pointer.x(), | 589 ui_channel_->Send(new MetroViewerHostMsg_TouchDown(pointer.x(), |
579 pointer.y(), | 590 pointer.y(), |
580 pointer.timestamp())); | 591 pointer.timestamp(), |
| 592 pointer.pointer_id())); |
581 } | 593 } |
582 return S_OK; | 594 return S_OK; |
583 } | 595 } |
584 | 596 |
585 HRESULT ChromeAppViewAsh::OnPointerReleased( | 597 HRESULT ChromeAppViewAsh::OnPointerReleased( |
586 winui::Core::ICoreWindow* sender, | 598 winui::Core::ICoreWindow* sender, |
587 winui::Core::IPointerEventArgs* args) { | 599 winui::Core::IPointerEventArgs* args) { |
588 PointerInfoHandler pointer; | 600 PointerInfoHandler pointer; |
589 HRESULT hr = pointer.Init(args); | 601 HRESULT hr = pointer.Init(args); |
590 if (FAILED(hr)) | 602 if (FAILED(hr)) |
591 return hr; | 603 return hr; |
592 | 604 |
593 if (pointer.IsMouse()) { | 605 if (pointer.IsMouse()) { |
594 mouse_down_flags_ = ui::EF_NONE; | 606 mouse_down_flags_ = ui::EF_NONE; |
595 ui_channel_->Send(new MetroViewerHostMsg_MouseButton(pointer.x(), | 607 ui_channel_->Send(new MetroViewerHostMsg_MouseButton(pointer.x(), |
596 pointer.y(), | 608 pointer.y(), |
597 0, | 609 0, |
598 ui::ET_MOUSE_RELEASED, | 610 ui::ET_MOUSE_RELEASED, |
599 pointer.flags())); | 611 pointer.flags())); |
600 } else { | 612 } else { |
601 DCHECK(pointer.IsTouch()); | 613 DCHECK(pointer.IsTouch()); |
602 ui_channel_->Send(new MetroViewerHostMsg_TouchUp(pointer.x(), | 614 ui_channel_->Send(new MetroViewerHostMsg_TouchUp(pointer.x(), |
603 pointer.y(), | 615 pointer.y(), |
604 pointer.timestamp())); | 616 pointer.timestamp(), |
| 617 pointer.pointer_id())); |
605 } | 618 } |
606 return S_OK; | 619 return S_OK; |
607 } | 620 } |
608 | 621 |
609 HRESULT ChromeAppViewAsh::OnWheel( | 622 HRESULT ChromeAppViewAsh::OnWheel( |
610 winui::Core::ICoreWindow* sender, | 623 winui::Core::ICoreWindow* sender, |
611 winui::Core::IPointerEventArgs* args) { | 624 winui::Core::IPointerEventArgs* args) { |
612 PointerInfoHandler pointer; | 625 PointerInfoHandler pointer; |
613 HRESULT hr = pointer.Init(args); | 626 HRESULT hr = pointer.Init(args); |
614 if (FAILED(hr)) | 627 if (FAILED(hr)) |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
751 mswr::ComPtr<winapp::Core::ICoreApplicationExit> app_exit; | 764 mswr::ComPtr<winapp::Core::ICoreApplicationExit> app_exit; |
752 CheckHR(core_app.As(&app_exit)); | 765 CheckHR(core_app.As(&app_exit)); |
753 globals.app_exit = app_exit.Detach(); | 766 globals.app_exit = app_exit.Detach(); |
754 } | 767 } |
755 | 768 |
756 IFACEMETHODIMP | 769 IFACEMETHODIMP |
757 ChromeAppViewFactory::CreateView(winapp::Core::IFrameworkView** view) { | 770 ChromeAppViewFactory::CreateView(winapp::Core::IFrameworkView** view) { |
758 *view = mswr::Make<ChromeAppViewAsh>().Detach(); | 771 *view = mswr::Make<ChromeAppViewAsh>().Detach(); |
759 return (*view) ? S_OK : E_OUTOFMEMORY; | 772 return (*view) ? S_OK : E_OUTOFMEMORY; |
760 } | 773 } |
OLD | NEW |