Example #1
0
void
nsMenuFrame::CreateMenuCommandEvent(WidgetGUIEvent* aEvent, bool aFlipChecked)
{
  // Create a trusted event if the triggering event was trusted, or if
  // we're called from chrome code (since at least one of our caller
  // passes in a null event).
  bool isTrusted = aEvent ? aEvent->IsTrusted() :
                              nsContentUtils::IsCallerChrome();

  bool shift = false, control = false, alt = false, meta = false;
  WidgetInputEvent* inputEvent = aEvent ? aEvent->AsInputEvent() : nullptr;
  if (inputEvent) {
    shift = inputEvent->IsShift();
    control = inputEvent->IsControl();
    alt = inputEvent->IsAlt();
    meta = inputEvent->IsMeta();
  }

  // Because the command event is firing asynchronously, a flag is needed to
  // indicate whether user input is being handled. This ensures that a popup
  // window won't get blocked.
  bool userinput = EventStateManager::IsHandlingUserInput();

  mDelayedMenuCommandEvent =
    new nsXULMenuCommandEvent(mContent, isTrusted, shift, control, alt, meta,
                              userinput, aFlipChecked);
}
void
nsButtonBoxFrame::DoMouseClick(WidgetGUIEvent* aEvent, bool aTrustEvent)
{
  // Don't execute if we're disabled.
  if (mContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::disabled,
                            nsGkAtoms::_true, eCaseMatters))
    return;

  // Execute the oncommand event handler.
  bool isShift = false;
  bool isControl = false;
  bool isAlt = false;
  bool isMeta = false;
  if(aEvent) {
    WidgetInputEvent* inputEvent = aEvent->AsInputEvent();
    isShift = inputEvent->IsShift();
    isControl = inputEvent->IsControl();
    isAlt = inputEvent->IsAlt();
    isMeta = inputEvent->IsMeta();
  }

  // Have the content handle the event, propagating it according to normal DOM rules.
  nsCOMPtr<nsIPresShell> shell = PresContext()->GetPresShell();
  if (shell) {
    nsContentUtils::DispatchXULCommand(mContent,
                                       aEvent ?
                                         aEvent->mFlags.mIsTrusted : aTrustEvent,
                                       nullptr, shell,
                                       isControl, isAlt, isShift, isMeta);
  }
}
uint32_t
nsMenuBarListener::GetModifiers(nsIDOMKeyEvent* aKeyEvent)
{
  uint32_t modifiers = 0;
  WidgetInputEvent* inputEvent =
    static_cast<WidgetInputEvent*>(aKeyEvent->GetInternalNSEvent());
  MOZ_ASSERT(inputEvent);

  if (inputEvent->IsShift()) {
    modifiers |= MODIFIER_SHIFT;
  }

  if (inputEvent->IsControl()) {
    modifiers |= MODIFIER_CONTROL;
  }

  if (inputEvent->IsAlt()) {
    modifiers |= MODIFIER_ALT;
  }

  if (inputEvent->IsMeta()) {
    modifiers |= MODIFIER_META;
  }

  if (inputEvent->IsOS()) {
    modifiers |= MODIFIER_OS;
  }

  return modifiers;
}
bool
nsDOMUIEvent::GetModifierStateInternal(const nsAString& aKey)
{
    WidgetInputEvent* inputEvent = mEvent->AsInputEvent();
    MOZ_ASSERT(inputEvent, "mEvent must be WidgetInputEvent or derived class");
    if (aKey.EqualsLiteral(NS_DOM_KEYNAME_SHIFT)) {
        return inputEvent->IsShift();
    }
    if (aKey.EqualsLiteral(NS_DOM_KEYNAME_CONTROL)) {
        return inputEvent->IsControl();
    }
    if (aKey.EqualsLiteral(NS_DOM_KEYNAME_META)) {
        return inputEvent->IsMeta();
    }
    if (aKey.EqualsLiteral(NS_DOM_KEYNAME_ALT)) {
        return inputEvent->IsAlt();
    }

    if (aKey.EqualsLiteral(NS_DOM_KEYNAME_ALTGRAPH)) {
        return inputEvent->IsAltGraph();
    }
    if (aKey.EqualsLiteral(NS_DOM_KEYNAME_OS)) {
        return inputEvent->IsOS();
    }

    if (aKey.EqualsLiteral(NS_DOM_KEYNAME_CAPSLOCK)) {
        return inputEvent->IsCapsLocked();
    }
    if (aKey.EqualsLiteral(NS_DOM_KEYNAME_NUMLOCK)) {
        return inputEvent->IsNumLocked();
    }

    if (aKey.EqualsLiteral(NS_DOM_KEYNAME_FN)) {
        return inputEvent->IsFn();
    }
    if (aKey.EqualsLiteral(NS_DOM_KEYNAME_SCROLLLOCK)) {
        return inputEvent->IsScrollLocked();
    }
    if (aKey.EqualsLiteral(NS_DOM_KEYNAME_SYMBOLLOCK)) {
        return inputEvent->IsSymbolLocked();
    }
    return false;
}
bool
nsXBLPrototypeHandler::ModifiersMatchMask(
                         nsIDOMUIEvent* aEvent,
                         const IgnoreModifierState& aIgnoreModifierState)
{
  WidgetInputEvent* inputEvent = aEvent->AsEvent()->WidgetEventPtr()->AsInputEvent();
  NS_ENSURE_TRUE(inputEvent, false);

  if (mKeyMask & cMetaMask) {
    if (inputEvent->IsMeta() != ((mKeyMask & cMeta) != 0)) {
      return false;
    }
  }

  if ((mKeyMask & cOSMask) && !aIgnoreModifierState.mOS) {
    if (inputEvent->IsOS() != ((mKeyMask & cOS) != 0)) {
      return false;
    }
  }

  if (mKeyMask & cShiftMask && !aIgnoreModifierState.mShift) {
    if (inputEvent->IsShift() != ((mKeyMask & cShift) != 0)) {
      return false;
    }
  }

  if (mKeyMask & cAltMask) {
    if (inputEvent->IsAlt() != ((mKeyMask & cAlt) != 0)) {
      return false;
    }
  }

  if (mKeyMask & cControlMask) {
    if (inputEvent->IsControl() != ((mKeyMask & cControl) != 0)) {
      return false;
    }
  }

  return true;
}
bool
nsXBLPrototypeHandler::ModifiersMatchMask(nsIDOMUIEvent* aEvent,
                                          bool aIgnoreShiftKey)
{
  WidgetInputEvent* inputEvent = aEvent->GetInternalNSEvent()->AsInputEvent();
  NS_ENSURE_TRUE(inputEvent, false);

  if (mKeyMask & cMetaMask) {
    if (inputEvent->IsMeta() != ((mKeyMask & cMeta) != 0)) {
      return false;
    }
  }

  if (mKeyMask & cOSMask) {
    if (inputEvent->IsOS() != ((mKeyMask & cOS) != 0)) {
      return false;
    }
  }

  if (mKeyMask & cShiftMask && !aIgnoreShiftKey) {
    if (inputEvent->IsShift() != ((mKeyMask & cShift) != 0)) {
      return false;
    }
  }

  if (mKeyMask & cAltMask) {
    if (inputEvent->IsAlt() != ((mKeyMask & cAlt) != 0)) {
      return false;
    }
  }

  if (mKeyMask & cControlMask) {
    if (inputEvent->IsControl() != ((mKeyMask & cControl) != 0)) {
      return false;
    }
  }

  return true;
}