Opera 12.15 Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

scope_system_input.cpp 6.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. /* -*- Mode: c++; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*-
  2. **
  3. ** Copyright (C) 2010 Opera Software AS. All rights reserved.
  4. **
  5. ** This file is part of the Opera web browser. It may not be distributed
  6. ** under any circumstances.
  7. */
  8. #include "core/pch.h"
  9. #include "modules/scope/src/scope_transport.h"
  10. #include "adjunct/desktop_scope/src/scope_system_input.h"
  11. #include "adjunct/desktop_pi/system_input_pi.h"
  12. ///////////////////////////////////////////////////////////////////////////////////////////////////
  13. /* OpScopeSystemInput */
  14. OpScopeSystemInput::OpScopeSystemInput()
  15. : m_system_input_pi(0)
  16. {
  17. // Create the system input object
  18. OpStatus::Ignore(SystemInputPI::Create(&m_system_input_pi));
  19. }
  20. /* virtual */
  21. OpScopeSystemInput::~OpScopeSystemInput()
  22. {
  23. OP_DELETE(m_system_input_pi);
  24. }
  25. /* virtual */ OP_STATUS
  26. OpScopeSystemInput::OnServiceEnabled()
  27. {
  28. // Init the System Input when scope actually connects
  29. if (m_system_input_pi)
  30. {
  31. OpStatus::Ignore(m_system_input_pi->Init());
  32. }
  33. return OpStatus::OK;
  34. }
  35. ///////////////////////////////////////////////////////////////////////////////////////////////////
  36. MouseButton OpScopeSystemInput::GetOperaButton(OpScopeSystemInput_SI::MouseInfo::MouseButton button)
  37. {
  38. switch (button)
  39. {
  40. case MouseInfo::MOUSEBUTTON_LEFT:
  41. return MOUSE_BUTTON_1;
  42. case MouseInfo::MOUSEBUTTON_RIGHT:
  43. return MOUSE_BUTTON_2;
  44. case MouseInfo::MOUSEBUTTON_MIDDLE:
  45. return MOUSE_BUTTON_3;
  46. default:
  47. OP_ASSERT(!"Mouse button not supported");
  48. break;
  49. }
  50. return MOUSE_BUTTON_1;
  51. }
  52. ///////////////////////////////////////////////////////////////////////////////////////////////////
  53. ShiftKeyState OpScopeSystemInput::GetOperaModifier(UINT32 modifiers)
  54. {
  55. ShiftKeyState opera_modifiers = 0;
  56. if ((modifiers & MODIFIERPRESSED_CTRL) == MODIFIERPRESSED_CTRL)
  57. opera_modifiers |= SHIFTKEY_CTRL;
  58. if ((modifiers & MODIFIERPRESSED_SHIFT) == MODIFIERPRESSED_SHIFT)
  59. opera_modifiers |= SHIFTKEY_SHIFT;
  60. if ((modifiers & MODIFIERPRESSED_ALT) == MODIFIERPRESSED_ALT)
  61. opera_modifiers |= SHIFTKEY_ALT;
  62. if ((modifiers & MODIFIERPRESSED_META) == MODIFIERPRESSED_META)
  63. opera_modifiers |= SHIFTKEY_META;
  64. if ((modifiers & MODIFIERPRESSED_SUPER) == MODIFIERPRESSED_SUPER)
  65. opera_modifiers |= SHIFTKEY_SUPER;
  66. return opera_modifiers;
  67. }
  68. ///////////////////////////////////////////////////////////////////////////////////////////////////
  69. OP_STATUS OpScopeSystemInput::DoClick(const MouseInfo &in)
  70. {
  71. if (m_system_input_pi)
  72. m_system_input_pi->Click(in.GetX(), in.GetY(), GetOperaButton(in.GetButton()), in.GetNumClicks(), GetOperaModifier(in.GetModifier()));
  73. else
  74. return SetCommandError(OpScopeTPHeader::InternalError, UNI_L("System input service could not be initialized"));
  75. return OpStatus::OK;
  76. }
  77. ///////////////////////////////////////////////////////////////////////////////////////////////////
  78. OP_STATUS OpScopeSystemInput::DoKeyPress(const KeyPressInfo &in)
  79. {
  80. // Convert the string e.g. "Control", "escape" to the OP_KEY
  81. const uni_char* key_string = in.GetKey().CStr();
  82. if (!key_string || !*key_string)
  83. return SetCommandError(OpScopeTPHeader::InternalError, UNI_L("KeyPress misses information about key"));;
  84. if (m_system_input_pi)
  85. {
  86. if (uni_strlen(key_string) > 1)
  87. {
  88. OpVirtualKey key = OpKey::FromString(key_string);
  89. m_system_input_pi->PressKey(key, key, GetOperaModifier(in.GetModifier()));
  90. }
  91. else
  92. {
  93. uni_char key = key_string[0];
  94. m_system_input_pi->PressKey(key, OP_KEY_INVALID, GetOperaModifier(in.GetModifier()));
  95. }
  96. }
  97. else
  98. {
  99. return SetCommandError(OpScopeTPHeader::InternalError, UNI_L("System input service could not be initialized"));
  100. }
  101. return OpStatus::OK;
  102. }
  103. OP_STATUS OpScopeSystemInput::DoKeyUp(const KeyPressInfo &in)
  104. {
  105. // Convert the string e.g. "Control", "escape" to the OP_KEY
  106. const uni_char* key_string = in.GetKey().CStr();
  107. if (!key_string || !*key_string)
  108. return SetCommandError(OpScopeTPHeader::InternalError, UNI_L("KeyUp misses information about key"));;
  109. if (!m_system_input_pi)
  110. return SetCommandError(OpScopeTPHeader::InternalError, UNI_L("System input service could not be initialized"));
  111. if (uni_strlen(key_string) > 1)
  112. {
  113. OpVirtualKey key = OpKey::FromString(key_string);
  114. m_system_input_pi->KeyUp(key, key, GetOperaModifier(in.GetModifier()));
  115. }
  116. else
  117. {
  118. uni_char key = key_string[0];
  119. m_system_input_pi->KeyUp(key, OP_KEY_INVALID, GetOperaModifier(in.GetModifier()));
  120. }
  121. return OpStatus::OK;
  122. }
  123. OP_STATUS OpScopeSystemInput::DoKeyDown(const KeyPressInfo &in)
  124. {
  125. // Convert the string e.g. "Control", "escape" to the OP_KEY
  126. const uni_char* key_string = in.GetKey().CStr();
  127. if (!key_string || !*key_string)
  128. return SetCommandError(OpScopeTPHeader::InternalError, UNI_L("KeyDown misses information about key"));;
  129. if (!m_system_input_pi)
  130. return SetCommandError(OpScopeTPHeader::InternalError, UNI_L("System input service could not be initialized"));
  131. if (uni_strlen(key_string) > 1)
  132. {
  133. OpVirtualKey key = OpKey::FromString(key_string);
  134. m_system_input_pi->KeyDown(key, key, GetOperaModifier(in.GetModifier()));
  135. }
  136. else
  137. {
  138. uni_char key = key_string[0];
  139. m_system_input_pi->KeyDown(key, OP_KEY_INVALID, GetOperaModifier(in.GetModifier()));
  140. }
  141. return OpStatus::OK;
  142. }
  143. OP_STATUS OpScopeSystemInput::DoMouseDown(const MouseInfo &in)
  144. {
  145. if (m_system_input_pi)
  146. m_system_input_pi->MouseDown(in.GetX(), in.GetY(), GetOperaButton(in.GetButton()), GetOperaModifier(in.GetModifier()));
  147. else
  148. return SetCommandError(OpScopeTPHeader::InternalError, UNI_L("System input service could not be initialized"));
  149. return OpStatus::OK;
  150. }
  151. OP_STATUS OpScopeSystemInput::DoMouseUp(const MouseInfo &in)
  152. {
  153. if (m_system_input_pi)
  154. m_system_input_pi->MouseUp(in.GetX(), in.GetY(), GetOperaButton(in.GetButton()), GetOperaModifier(in.GetModifier()));
  155. else
  156. return SetCommandError(OpScopeTPHeader::InternalError, UNI_L("System input service could not be initialized"));
  157. return OpStatus::OK;
  158. }
  159. OP_STATUS OpScopeSystemInput::DoMouseMove(const MouseInfo &in)
  160. {
  161. if (m_system_input_pi)
  162. m_system_input_pi->MouseMove(in.GetX(), in.GetY(), GetOperaButton(in.GetButton()), GetOperaModifier(in.GetModifier()));
  163. else
  164. return SetCommandError(OpScopeTPHeader::InternalError, UNI_L("System input service could not be initialized"));
  165. return OpStatus::OK;
  166. }