| 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 <corewindow.h> | 8 #include <corewindow.h> |
| 9 #include <shellapi.h> | 9 #include <shellapi.h> |
| 10 #include <windows.foundation.h> | 10 #include <windows.foundation.h> |
| (...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 // This class helps decoding the pointer properties of an event. | 366 // This class helps decoding the pointer properties of an event. |
| 367 class ChromeAppViewAsh::PointerInfoHandler { | 367 class ChromeAppViewAsh::PointerInfoHandler { |
| 368 public: | 368 public: |
| 369 PointerInfoHandler() | 369 PointerInfoHandler() |
| 370 : x_(0), | 370 : x_(0), |
| 371 y_(0), | 371 y_(0), |
| 372 wheel_delta_(0), | 372 wheel_delta_(0), |
| 373 update_kind_(winui::Input::PointerUpdateKind_Other), | 373 update_kind_(winui::Input::PointerUpdateKind_Other), |
| 374 timestamp_(0), | 374 timestamp_(0), |
| 375 pointer_id_(0), | 375 pointer_id_(0), |
| 376 mouse_down_flags_(0) {} | 376 mouse_down_flags_(0), |
| 377 is_horizontal_wheel_(0) {} |
| 377 | 378 |
| 378 HRESULT Init(winui::Core::IPointerEventArgs* args) { | 379 HRESULT Init(winui::Core::IPointerEventArgs* args) { |
| 379 HRESULT hr = args->get_CurrentPoint(&pointer_point_); | 380 HRESULT hr = args->get_CurrentPoint(&pointer_point_); |
| 380 if (FAILED(hr)) | 381 if (FAILED(hr)) |
| 381 return hr; | 382 return hr; |
| 382 | 383 |
| 383 winfoundtn::Point point; | 384 winfoundtn::Point point; |
| 384 hr = pointer_point_->get_Position(&point); | 385 hr = pointer_point_->get_Position(&point); |
| 385 if (FAILED(hr)) | 386 if (FAILED(hr)) |
| 386 return hr; | 387 return hr; |
| 387 | 388 |
| 388 mswr::ComPtr<winui::Input::IPointerPointProperties> properties; | 389 mswr::ComPtr<winui::Input::IPointerPointProperties> properties; |
| 389 hr = pointer_point_->get_Properties(&properties); | 390 hr = pointer_point_->get_Properties(&properties); |
| 390 if (FAILED(hr)) | 391 if (FAILED(hr)) |
| 391 return hr; | 392 return hr; |
| 392 | 393 |
| 393 hr = properties->get_PointerUpdateKind(&update_kind_); | 394 hr = properties->get_PointerUpdateKind(&update_kind_); |
| 394 if (FAILED(hr)) | 395 if (FAILED(hr)) |
| 395 return hr; | 396 return hr; |
| 396 | 397 |
| 397 hr = properties->get_MouseWheelDelta(&wheel_delta_); | 398 hr = properties->get_MouseWheelDelta(&wheel_delta_); |
| 398 if (FAILED(hr)) | 399 if (FAILED(hr)) |
| 399 return hr; | 400 return hr; |
| 400 | 401 |
| 402 is_horizontal_wheel_ = 0; |
| 403 properties->get_IsHorizontalMouseWheel(&is_horizontal_wheel_); |
| 404 |
| 401 x_ = point.X; | 405 x_ = point.X; |
| 402 y_ = point.Y; | 406 y_ = point.Y; |
| 407 |
| 403 pointer_point_->get_Timestamp(×tamp_); | 408 pointer_point_->get_Timestamp(×tamp_); |
| 404 pointer_point_->get_PointerId(&pointer_id_); | 409 pointer_point_->get_PointerId(&pointer_id_); |
| 405 // Map the OS touch event id to a range allowed by the gesture recognizer. | 410 // Map the OS touch event id to a range allowed by the gesture recognizer. |
| 406 if (IsTouch()) | 411 if (IsTouch()) |
| 407 pointer_id_ %= ui::GestureSequence::kMaxGesturePoints; | 412 pointer_id_ %= ui::GestureSequence::kMaxGesturePoints; |
| 408 | 413 |
| 409 boolean left_button_state; | 414 boolean left_button_state; |
| 410 hr = properties->get_IsLeftButtonPressed(&left_button_state); | 415 hr = properties->get_IsLeftButtonPressed(&left_button_state); |
| 411 if (FAILED(hr)) | 416 if (FAILED(hr)) |
| 412 return hr; | 417 return hr; |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 476 int y() const { return y_; } | 481 int y() const { return y_; } |
| 477 | 482 |
| 478 uint32 pointer_id() const { | 483 uint32 pointer_id() const { |
| 479 return pointer_id_; | 484 return pointer_id_; |
| 480 } | 485 } |
| 481 | 486 |
| 482 uint64 timestamp() const { return timestamp_; } | 487 uint64 timestamp() const { return timestamp_; } |
| 483 | 488 |
| 484 winui::Input::PointerUpdateKind update_kind() const { return update_kind_; } | 489 winui::Input::PointerUpdateKind update_kind() const { return update_kind_; } |
| 485 | 490 |
| 491 bool is_horizontal_wheel() const { return !!is_horizontal_wheel_; } |
| 492 |
| 486 private: | 493 private: |
| 487 int x_; | 494 int x_; |
| 488 int y_; | 495 int y_; |
| 489 int wheel_delta_; | 496 int wheel_delta_; |
| 490 uint32 pointer_id_; | 497 uint32 pointer_id_; |
| 491 winui::Input::PointerUpdateKind update_kind_; | 498 winui::Input::PointerUpdateKind update_kind_; |
| 492 mswr::ComPtr<winui::Input::IPointerPoint> pointer_point_; | 499 mswr::ComPtr<winui::Input::IPointerPoint> pointer_point_; |
| 493 uint64 timestamp_; | 500 uint64 timestamp_; |
| 494 | 501 |
| 495 // Bitmask of ui::EventFlags corresponding to the buttons that are currently | 502 // Bitmask of ui::EventFlags corresponding to the buttons that are currently |
| 496 // down. | 503 // down. |
| 497 uint32 mouse_down_flags_; | 504 uint32 mouse_down_flags_; |
| 498 | 505 |
| 506 // Set to true for a horizontal wheel message. |
| 507 boolean is_horizontal_wheel_; |
| 508 |
| 499 DISALLOW_COPY_AND_ASSIGN(PointerInfoHandler); | 509 DISALLOW_COPY_AND_ASSIGN(PointerInfoHandler); |
| 500 }; | 510 }; |
| 501 | 511 |
| 502 ChromeAppViewAsh::ChromeAppViewAsh() | 512 ChromeAppViewAsh::ChromeAppViewAsh() |
| 503 : mouse_down_flags_(ui::EF_NONE), | 513 : mouse_down_flags_(ui::EF_NONE), |
| 504 ui_channel_(nullptr), | 514 ui_channel_(nullptr), |
| 505 core_window_hwnd_(NULL) { | 515 core_window_hwnd_(NULL) { |
| 506 DVLOG(1) << __FUNCTION__; | 516 DVLOG(1) << __FUNCTION__; |
| 507 globals.previous_state = | 517 globals.previous_state = |
| 508 winapp::Activation::ApplicationExecutionState_NotRunning; | 518 winapp::Activation::ApplicationExecutionState_NotRunning; |
| (...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 935 | 945 |
| 936 void ChromeAppViewAsh::OnTextCommitted(const base::string16& text) { | 946 void ChromeAppViewAsh::OnTextCommitted(const base::string16& text) { |
| 937 ui_channel_->Send(new MetroViewerHostMsg_ImeTextCommitted(text)); | 947 ui_channel_->Send(new MetroViewerHostMsg_ImeTextCommitted(text)); |
| 938 } | 948 } |
| 939 | 949 |
| 940 void ChromeAppViewAsh::SendMouseButton(int x, | 950 void ChromeAppViewAsh::SendMouseButton(int x, |
| 941 int y, | 951 int y, |
| 942 int extra, | 952 int extra, |
| 943 ui::EventType event_type, | 953 ui::EventType event_type, |
| 944 uint32 flags, | 954 uint32 flags, |
| 945 ui::EventFlags changed_button) { | 955 ui::EventFlags changed_button, |
| 956 bool is_horizontal_wheel) { |
| 946 MetroViewerHostMsg_MouseButtonParams params; | 957 MetroViewerHostMsg_MouseButtonParams params; |
| 947 params.x = static_cast<int32>(x); | 958 params.x = static_cast<int32>(x); |
| 948 params.y = static_cast<int32>(y); | 959 params.y = static_cast<int32>(y); |
| 949 params.extra = static_cast<int32>(extra); | 960 params.extra = static_cast<int32>(extra); |
| 950 params.event_type = event_type; | 961 params.event_type = event_type; |
| 951 params.flags = static_cast<int32>(flags); | 962 params.flags = static_cast<int32>(flags); |
| 952 params.changed_button = changed_button; | 963 params.changed_button = changed_button; |
| 964 params.is_horizontal_wheel = is_horizontal_wheel; |
| 953 ui_channel_->Send(new MetroViewerHostMsg_MouseButton(params)); | 965 ui_channel_->Send(new MetroViewerHostMsg_MouseButton(params)); |
| 954 } | 966 } |
| 955 | 967 |
| 956 void ChromeAppViewAsh::GenerateMouseEventFromMoveIfNecessary( | 968 void ChromeAppViewAsh::GenerateMouseEventFromMoveIfNecessary( |
| 957 const PointerInfoHandler& pointer) { | 969 const PointerInfoHandler& pointer) { |
| 958 ui::EventType event_type; | 970 ui::EventType event_type; |
| 959 // For aura we want the flags to include the button that was released, thus | 971 // For aura we want the flags to include the button that was released, thus |
| 960 // we or the old and new. | 972 // we or the old and new. |
| 961 uint32 mouse_down_flags = pointer.mouse_down_flags() | mouse_down_flags_; | 973 uint32 mouse_down_flags = pointer.mouse_down_flags() | mouse_down_flags_; |
| 962 mouse_down_flags_ = pointer.mouse_down_flags(); | 974 mouse_down_flags_ = pointer.mouse_down_flags(); |
| 963 switch (pointer.update_kind()) { | 975 switch (pointer.update_kind()) { |
| 964 case winui::Input::PointerUpdateKind_LeftButtonPressed: | 976 case winui::Input::PointerUpdateKind_LeftButtonPressed: |
| 965 case winui::Input::PointerUpdateKind_RightButtonPressed: | 977 case winui::Input::PointerUpdateKind_RightButtonPressed: |
| 966 case winui::Input::PointerUpdateKind_MiddleButtonPressed: | 978 case winui::Input::PointerUpdateKind_MiddleButtonPressed: |
| 967 event_type = ui::ET_MOUSE_PRESSED; | 979 event_type = ui::ET_MOUSE_PRESSED; |
| 968 break; | 980 break; |
| 969 case winui::Input::PointerUpdateKind_LeftButtonReleased: | 981 case winui::Input::PointerUpdateKind_LeftButtonReleased: |
| 970 case winui::Input::PointerUpdateKind_RightButtonReleased: | 982 case winui::Input::PointerUpdateKind_RightButtonReleased: |
| 971 case winui::Input::PointerUpdateKind_MiddleButtonReleased: | 983 case winui::Input::PointerUpdateKind_MiddleButtonReleased: |
| 972 event_type = ui::ET_MOUSE_RELEASED; | 984 event_type = ui::ET_MOUSE_RELEASED; |
| 973 break; | 985 break; |
| 974 default: | 986 default: |
| 975 return; | 987 return; |
| 976 } | 988 } |
| 977 SendMouseButton(pointer.x(), pointer.y(), 0, event_type, | 989 SendMouseButton(pointer.x(), pointer.y(), 0, event_type, |
| 978 mouse_down_flags | GetKeyboardEventFlags(), | 990 mouse_down_flags | GetKeyboardEventFlags(), |
| 979 pointer.changed_button()); | 991 pointer.changed_button(), pointer.is_horizontal_wheel()); |
| 980 } | 992 } |
| 981 | 993 |
| 982 HRESULT ChromeAppViewAsh::OnActivate( | 994 HRESULT ChromeAppViewAsh::OnActivate( |
| 983 winapp::Core::ICoreApplicationView*, | 995 winapp::Core::ICoreApplicationView*, |
| 984 winapp::Activation::IActivatedEventArgs* args) { | 996 winapp::Activation::IActivatedEventArgs* args) { |
| 985 DVLOG(1) << __FUNCTION__; | 997 DVLOG(1) << __FUNCTION__; |
| 986 // Note: If doing more work in this function, you migth need to call | 998 // Note: If doing more work in this function, you migth need to call |
| 987 // get_PreviousExecutionState() and skip the work if the result is | 999 // get_PreviousExecutionState() and skip the work if the result is |
| 988 // ApplicationExecutionState_Running and globals.previous_state is too. | 1000 // ApplicationExecutionState_Running and globals.previous_state is too. |
| 989 args->get_PreviousExecutionState(&globals.previous_state); | 1001 args->get_PreviousExecutionState(&globals.previous_state); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1043 winui::Core::IPointerEventArgs* args) { | 1055 winui::Core::IPointerEventArgs* args) { |
| 1044 PointerInfoHandler pointer; | 1056 PointerInfoHandler pointer; |
| 1045 HRESULT hr = pointer.Init(args); | 1057 HRESULT hr = pointer.Init(args); |
| 1046 if (FAILED(hr)) | 1058 if (FAILED(hr)) |
| 1047 return hr; | 1059 return hr; |
| 1048 | 1060 |
| 1049 if (pointer.IsMouse()) { | 1061 if (pointer.IsMouse()) { |
| 1050 mouse_down_flags_ = pointer.mouse_down_flags(); | 1062 mouse_down_flags_ = pointer.mouse_down_flags(); |
| 1051 SendMouseButton(pointer.x(), pointer.y(), 0, ui::ET_MOUSE_PRESSED, | 1063 SendMouseButton(pointer.x(), pointer.y(), 0, ui::ET_MOUSE_PRESSED, |
| 1052 mouse_down_flags_ | GetKeyboardEventFlags(), | 1064 mouse_down_flags_ | GetKeyboardEventFlags(), |
| 1053 pointer.changed_button()); | 1065 pointer.changed_button(), pointer.is_horizontal_wheel()); |
| 1054 } else { | 1066 } else { |
| 1055 DCHECK(pointer.IsTouch()); | 1067 DCHECK(pointer.IsTouch()); |
| 1056 ui_channel_->Send(new MetroViewerHostMsg_TouchDown(pointer.x(), | 1068 ui_channel_->Send(new MetroViewerHostMsg_TouchDown(pointer.x(), |
| 1057 pointer.y(), | 1069 pointer.y(), |
| 1058 pointer.timestamp(), | 1070 pointer.timestamp(), |
| 1059 pointer.pointer_id())); | 1071 pointer.pointer_id())); |
| 1060 } | 1072 } |
| 1061 return S_OK; | 1073 return S_OK; |
| 1062 } | 1074 } |
| 1063 | 1075 |
| 1064 HRESULT ChromeAppViewAsh::OnPointerReleased( | 1076 HRESULT ChromeAppViewAsh::OnPointerReleased( |
| 1065 winui::Core::ICoreWindow* sender, | 1077 winui::Core::ICoreWindow* sender, |
| 1066 winui::Core::IPointerEventArgs* args) { | 1078 winui::Core::IPointerEventArgs* args) { |
| 1067 PointerInfoHandler pointer; | 1079 PointerInfoHandler pointer; |
| 1068 HRESULT hr = pointer.Init(args); | 1080 HRESULT hr = pointer.Init(args); |
| 1069 if (FAILED(hr)) | 1081 if (FAILED(hr)) |
| 1070 return hr; | 1082 return hr; |
| 1071 | 1083 |
| 1072 if (pointer.IsMouse()) { | 1084 if (pointer.IsMouse()) { |
| 1073 mouse_down_flags_ = ui::EF_NONE; | 1085 mouse_down_flags_ = ui::EF_NONE; |
| 1074 SendMouseButton(pointer.x(), pointer.y(), 0, ui::ET_MOUSE_RELEASED, | 1086 SendMouseButton(pointer.x(), pointer.y(), 0, ui::ET_MOUSE_RELEASED, |
| 1075 static_cast<uint32>(pointer.changed_button()) | | 1087 static_cast<uint32>(pointer.changed_button()) | |
| 1076 GetKeyboardEventFlags(), | 1088 GetKeyboardEventFlags(), |
| 1077 pointer.changed_button()); | 1089 pointer.changed_button(), |
| 1090 pointer.is_horizontal_wheel()); |
| 1078 } else { | 1091 } else { |
| 1079 DCHECK(pointer.IsTouch()); | 1092 DCHECK(pointer.IsTouch()); |
| 1080 ui_channel_->Send(new MetroViewerHostMsg_TouchUp(pointer.x(), | 1093 ui_channel_->Send(new MetroViewerHostMsg_TouchUp(pointer.x(), |
| 1081 pointer.y(), | 1094 pointer.y(), |
| 1082 pointer.timestamp(), | 1095 pointer.timestamp(), |
| 1083 pointer.pointer_id())); | 1096 pointer.pointer_id())); |
| 1084 } | 1097 } |
| 1085 return S_OK; | 1098 return S_OK; |
| 1086 } | 1099 } |
| 1087 | 1100 |
| 1088 HRESULT ChromeAppViewAsh::OnWheel( | 1101 HRESULT ChromeAppViewAsh::OnWheel( |
| 1089 winui::Core::ICoreWindow* sender, | 1102 winui::Core::ICoreWindow* sender, |
| 1090 winui::Core::IPointerEventArgs* args) { | 1103 winui::Core::IPointerEventArgs* args) { |
| 1091 PointerInfoHandler pointer; | 1104 PointerInfoHandler pointer; |
| 1092 HRESULT hr = pointer.Init(args); | 1105 HRESULT hr = pointer.Init(args); |
| 1093 if (FAILED(hr)) | 1106 if (FAILED(hr)) |
| 1094 return hr; | 1107 return hr; |
| 1095 DCHECK(pointer.IsMouse()); | 1108 DCHECK(pointer.IsMouse()); |
| 1096 SendMouseButton(pointer.x(), pointer.y(), pointer.wheel_delta(), | 1109 SendMouseButton(pointer.x(), pointer.y(), pointer.wheel_delta(), |
| 1097 ui::ET_MOUSEWHEEL, ui::EF_NONE, ui::EF_NONE); | 1110 ui::ET_MOUSEWHEEL, ui::EF_NONE, ui::EF_NONE, |
| 1111 pointer.is_horizontal_wheel()); |
| 1098 return S_OK; | 1112 return S_OK; |
| 1099 } | 1113 } |
| 1100 | 1114 |
| 1101 HRESULT ChromeAppViewAsh::OnKeyDown( | 1115 HRESULT ChromeAppViewAsh::OnKeyDown( |
| 1102 winui::Core::ICoreWindow* sender, | 1116 winui::Core::ICoreWindow* sender, |
| 1103 winui::Core::IKeyEventArgs* args) { | 1117 winui::Core::IKeyEventArgs* args) { |
| 1104 winsys::VirtualKey virtual_key; | 1118 winsys::VirtualKey virtual_key; |
| 1105 HRESULT hr = args->get_VirtualKey(&virtual_key); | 1119 HRESULT hr = args->get_VirtualKey(&virtual_key); |
| 1106 if (FAILED(hr)) | 1120 if (FAILED(hr)) |
| 1107 return hr; | 1121 return hr; |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1321 mswr::ComPtr<winapp::Core::ICoreApplicationExit> app_exit; | 1335 mswr::ComPtr<winapp::Core::ICoreApplicationExit> app_exit; |
| 1322 CheckHR(core_app.As(&app_exit)); | 1336 CheckHR(core_app.As(&app_exit)); |
| 1323 globals.app_exit = app_exit.Detach(); | 1337 globals.app_exit = app_exit.Detach(); |
| 1324 } | 1338 } |
| 1325 | 1339 |
| 1326 IFACEMETHODIMP | 1340 IFACEMETHODIMP |
| 1327 ChromeAppViewFactory::CreateView(winapp::Core::IFrameworkView** view) { | 1341 ChromeAppViewFactory::CreateView(winapp::Core::IFrameworkView** view) { |
| 1328 *view = mswr::Make<ChromeAppViewAsh>().Detach(); | 1342 *view = mswr::Make<ChromeAppViewAsh>().Detach(); |
| 1329 return (*view) ? S_OK : E_OUTOFMEMORY; | 1343 return (*view) ? S_OK : E_OUTOFMEMORY; |
| 1330 } | 1344 } |
| OLD | NEW |