nsresult
TextInputProcessor::PrepareKeyboardEventToDispatch(
                      WidgetKeyboardEvent& aKeyboardEvent,
                      uint32_t aKeyFlags)
{
  if (NS_WARN_IF(aKeyboardEvent.mCodeNameIndex == CODE_NAME_INDEX_USE_STRING)) {
    return NS_ERROR_INVALID_ARG;
  }
  if ((aKeyFlags & KEY_NON_PRINTABLE_KEY) &&
      NS_WARN_IF(aKeyboardEvent.mKeyNameIndex == KEY_NAME_INDEX_USE_STRING)) {
    return NS_ERROR_INVALID_ARG;
  }
  if ((aKeyFlags & KEY_FORCE_PRINTABLE_KEY) &&
      aKeyboardEvent.mKeyNameIndex != KEY_NAME_INDEX_USE_STRING) {
    aKeyboardEvent.GetDOMKeyName(aKeyboardEvent.mKeyValue);
    aKeyboardEvent.mKeyNameIndex = KEY_NAME_INDEX_USE_STRING;
  }
  if (aKeyFlags & KEY_KEEP_KEY_LOCATION_STANDARD) {
    // If .location is initialized with specific value, using
    // KEY_KEEP_KEY_LOCATION_STANDARD must be a bug of the caller.
    // Let's throw an exception for notifying the developer of this bug.
    if (NS_WARN_IF(aKeyboardEvent.mLocation)) {
      return NS_ERROR_INVALID_ARG;
    }
  } else if (!aKeyboardEvent.mLocation) {
    // If KeyboardEvent.mLocation is 0, it may be uninitialized.  If so, we
    // should compute proper mLocation value from its .code value.
    aKeyboardEvent.mLocation =
      WidgetKeyboardEvent::ComputeLocationFromCodeValue(
        aKeyboardEvent.mCodeNameIndex);
  }

  if (aKeyFlags & KEY_KEEP_KEYCODE_ZERO) {
    // If .keyCode is initialized with specific value, using
    // KEY_KEEP_KEYCODE_ZERO must be a bug of the caller.  Let's throw an
    // exception for notifying the developer of such bug.
    if (NS_WARN_IF(aKeyboardEvent.mKeyCode)) {
      return NS_ERROR_INVALID_ARG;
    }
  } else if (!aKeyboardEvent.mKeyCode &&
             aKeyboardEvent.mKeyNameIndex > KEY_NAME_INDEX_Unidentified &&
             aKeyboardEvent.mKeyNameIndex < KEY_NAME_INDEX_USE_STRING) {
    // If KeyboardEvent.keyCode is 0, it may be uninitialized.  If so, we may
    // be able to decide a good .keyCode value if the .key value is a
    // non-printable key.
    aKeyboardEvent.mKeyCode =
      WidgetKeyboardEvent::ComputeKeyCodeFromKeyNameIndex(
        aKeyboardEvent.mKeyNameIndex);
  }

  aKeyboardEvent.mIsSynthesizedByTIP = (mForTests)? false : true;

  return NS_OK;
}
Exemplo n.º 2
0
NS_IMETHODIMP
KeyboardEvent::GetKey(nsAString& aKeyName)
{
  WidgetKeyboardEvent* keyboardEvent = mEvent->AsKeyboardEvent();
  keyboardEvent->GetDOMKeyName(aKeyName);

  nsIDocument::DeprecatedOperations deprecatedOperation;
  switch (keyboardEvent->mKeyNameIndex) {
    case KEY_NAME_INDEX_Down:
      deprecatedOperation = nsIDocument::eKeyNameDown;
      break;
    case KEY_NAME_INDEX_Left:
      deprecatedOperation = nsIDocument::eKeyNameLeft;
      break;
    case KEY_NAME_INDEX_Right:
      deprecatedOperation = nsIDocument::eKeyNameRight;
      break;
    case KEY_NAME_INDEX_Up:
      deprecatedOperation = nsIDocument::eKeyNameUp;
      break;
    case KEY_NAME_INDEX_Crsel:
      deprecatedOperation = nsIDocument::eKeyNameCrsel;
      break;
    case KEY_NAME_INDEX_Del:
      deprecatedOperation = nsIDocument::eKeyNameDel;
      break;
    case KEY_NAME_INDEX_Exsel:
      deprecatedOperation = nsIDocument::eKeyNameExsel;
      break;
    case KEY_NAME_INDEX_Menu:
      deprecatedOperation = nsIDocument::eKeyNameMenu;
      break;
    case KEY_NAME_INDEX_Esc:
      deprecatedOperation = nsIDocument::eKeyNameEsc;
      break;
    case KEY_NAME_INDEX_Nonconvert:
      deprecatedOperation = nsIDocument::eKeyNameNonconvert;
      break;
    case KEY_NAME_INDEX_HalfWidth:
      deprecatedOperation = nsIDocument::eKeyNameHalfWidth;
      break;
    case KEY_NAME_INDEX_RomanCharacters:
      deprecatedOperation = nsIDocument::eKeyNameRomanCharacters;
      break;
    case KEY_NAME_INDEX_FullWidth:
      deprecatedOperation = nsIDocument::eKeyNameFullWidth;
      break;
    case KEY_NAME_INDEX_SelectMedia:
      deprecatedOperation = nsIDocument::eKeyNameSelectMedia;
      break;
    case KEY_NAME_INDEX_MediaNextTrack:
      deprecatedOperation = nsIDocument::eKeyNameMediaNextTrack;
      break;
    case KEY_NAME_INDEX_MediaPreviousTrack:
      deprecatedOperation = nsIDocument::eKeyNameMediaPreviousTrack;
      break;
    case KEY_NAME_INDEX_Red:
      deprecatedOperation = nsIDocument::eKeyNameRed;
      break;
    case KEY_NAME_INDEX_Green:
      deprecatedOperation = nsIDocument::eKeyNameGreen;
      break;
    case KEY_NAME_INDEX_Yellow:
      deprecatedOperation = nsIDocument::eKeyNameYellow;
      break;
    case KEY_NAME_INDEX_Blue:
      deprecatedOperation = nsIDocument::eKeyNameBlue;
      break;
    case KEY_NAME_INDEX_Live:
      deprecatedOperation = nsIDocument::eKeyNameLive;
      break;
    case KEY_NAME_INDEX_Apps:
      deprecatedOperation = nsIDocument::eKeyNameApps;
      break;
    case KEY_NAME_INDEX_FastFwd:
      deprecatedOperation = nsIDocument::eKeyNameFastFwd;
      break;
    case KEY_NAME_INDEX_Zoom:
      deprecatedOperation = nsIDocument::eKeyNameZoom;
      break;
    case KEY_NAME_INDEX_DeadGrave:
    case KEY_NAME_INDEX_DeadAcute:
    case KEY_NAME_INDEX_DeadCircumflex:
    case KEY_NAME_INDEX_DeadTilde:
    case KEY_NAME_INDEX_DeadMacron:
    case KEY_NAME_INDEX_DeadBreve:
    case KEY_NAME_INDEX_DeadAboveDot:
    case KEY_NAME_INDEX_DeadUmlaut:
    case KEY_NAME_INDEX_DeadAboveRing:
    case KEY_NAME_INDEX_DeadDoubleacute:
    case KEY_NAME_INDEX_DeadCaron:
    case KEY_NAME_INDEX_DeadCedilla:
    case KEY_NAME_INDEX_DeadOgonek:
    case KEY_NAME_INDEX_DeadIota:
    case KEY_NAME_INDEX_DeadVoicedSound:
    case KEY_NAME_INDEX_DeadSemivoicedSound:
      deprecatedOperation = nsIDocument::eKeyNameDeadKeys;
      break;
    default:
      return NS_OK;
  }

  nsIDocument* doc = mOwner ? mOwner->GetExtantDoc() : nullptr;
  if (NS_WARN_IF(!doc)) {
    return NS_OK;
  }
  doc->WarnOnceAbout(deprecatedOperation);
  return NS_OK;
}