2013-09-24 10:04:15 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef mozilla_TextEvents_h__
|
|
|
|
#define mozilla_TextEvents_h__
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#include "mozilla/Assertions.h"
|
|
|
|
#include "mozilla/BasicEvents.h"
|
2015-06-05 09:28:21 +00:00
|
|
|
#include "mozilla/CheckedInt.h"
|
2013-09-24 10:04:15 +00:00
|
|
|
#include "mozilla/EventForwards.h" // for KeyNameIndex, temporarily
|
2013-10-22 13:27:36 +00:00
|
|
|
#include "mozilla/TextRange.h"
|
2015-01-31 07:17:12 +00:00
|
|
|
#include "mozilla/FontRange.h"
|
2013-09-24 10:04:15 +00:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsIDOMKeyEvent.h"
|
2015-12-01 20:25:06 +00:00
|
|
|
#include "nsISelectionListener.h"
|
2013-09-24 10:04:15 +00:00
|
|
|
#include "nsITransferable.h"
|
|
|
|
#include "nsRect.h"
|
|
|
|
#include "nsStringGlue.h"
|
|
|
|
#include "nsTArray.h"
|
2014-11-22 14:39:03 +00:00
|
|
|
#include "WritingModes.h"
|
2013-09-24 10:04:15 +00:00
|
|
|
|
2015-02-19 06:50:19 +00:00
|
|
|
class nsStringHashKey;
|
|
|
|
template<class, class> class nsDataHashtable;
|
|
|
|
|
2013-09-24 10:04:15 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* virtual keycode values
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
#define NS_DEFINE_VK(aDOMKeyName, aDOMKeyCode) NS_##aDOMKeyName = aDOMKeyCode
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
2014-04-01 11:42:16 +00:00
|
|
|
#include "mozilla/VirtualKeyCodeList.h"
|
2013-09-24 10:04:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#undef NS_DEFINE_VK
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
namespace dom {
|
|
|
|
class PBrowserParent;
|
|
|
|
class PBrowserChild;
|
|
|
|
} // namespace dom
|
|
|
|
namespace plugins {
|
|
|
|
class PPluginInstanceChild;
|
|
|
|
} // namespace plugins
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* mozilla::AlternativeCharCode
|
|
|
|
*
|
|
|
|
* This stores alternative charCode values of a key event with some modifiers.
|
|
|
|
* The stored values proper for testing shortcut key or access key.
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
struct AlternativeCharCode
|
|
|
|
{
|
2014-07-23 11:05:45 +00:00
|
|
|
AlternativeCharCode() :
|
|
|
|
mUnshiftedCharCode(0), mShiftedCharCode(0)
|
|
|
|
{
|
|
|
|
}
|
2013-09-24 10:04:15 +00:00
|
|
|
AlternativeCharCode(uint32_t aUnshiftedCharCode, uint32_t aShiftedCharCode) :
|
|
|
|
mUnshiftedCharCode(aUnshiftedCharCode), mShiftedCharCode(aShiftedCharCode)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
uint32_t mUnshiftedCharCode;
|
|
|
|
uint32_t mShiftedCharCode;
|
|
|
|
};
|
|
|
|
|
2016-03-18 02:22:37 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* mozilla::ShortcutKeyCandidate
|
|
|
|
*
|
|
|
|
* This stores a candidate of shortcut key combination.
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
struct ShortcutKeyCandidate
|
|
|
|
{
|
|
|
|
ShortcutKeyCandidate(uint32_t aCharCode, bool aIgnoreShift)
|
|
|
|
: mCharCode(aCharCode)
|
|
|
|
, mIgnoreShift(aIgnoreShift)
|
|
|
|
{
|
|
|
|
}
|
2016-05-13 07:06:18 +00:00
|
|
|
// The mCharCode value which must match keyboard shortcut definition.
|
2016-03-18 02:22:37 +00:00
|
|
|
uint32_t mCharCode;
|
|
|
|
// true if Shift state can be ignored. Otherwise, Shift key state must
|
|
|
|
// match keyboard shortcut definition.
|
|
|
|
bool mIgnoreShift;
|
|
|
|
};
|
|
|
|
|
2013-09-24 10:04:15 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* mozilla::WidgetKeyboardEvent
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
class WidgetKeyboardEvent : public WidgetInputEvent
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
friend class dom::PBrowserParent;
|
|
|
|
friend class dom::PBrowserChild;
|
|
|
|
|
2014-11-03 07:05:12 +00:00
|
|
|
protected:
|
2013-09-24 10:04:15 +00:00
|
|
|
WidgetKeyboardEvent()
|
2016-05-12 10:18:36 +00:00
|
|
|
: mNativeKeyEvent(nullptr)
|
|
|
|
, mKeyCode(0)
|
2016-05-13 07:06:18 +00:00
|
|
|
, mCharCode(0)
|
2016-03-19 11:57:11 +00:00
|
|
|
, mPseudoCharCode(0)
|
2016-05-12 09:17:22 +00:00
|
|
|
, mLocation(nsIDOMKeyEvent::DOM_KEY_LOCATION_STANDARD)
|
2016-05-11 12:56:42 +00:00
|
|
|
, mAccessKeyForwardedToChild(false)
|
2016-01-12 18:16:59 +00:00
|
|
|
, mUniqueId(0)
|
|
|
|
#ifdef XP_MACOSX
|
|
|
|
, mNativeModifierFlags(0)
|
2016-05-12 10:18:36 +00:00
|
|
|
, mNativeKeyCode(0)
|
|
|
|
#endif // #ifdef XP_MACOSX
|
|
|
|
, mKeyNameIndex(mozilla::KEY_NAME_INDEX_Unidentified)
|
|
|
|
, mCodeNameIndex(CODE_NAME_INDEX_UNKNOWN)
|
2016-03-15 05:50:16 +00:00
|
|
|
, mInputMethodAppState(eNotHandled)
|
2016-05-12 10:18:36 +00:00
|
|
|
, mIsChar(false)
|
|
|
|
, mIsRepeat(false)
|
|
|
|
, mIsComposing(false)
|
|
|
|
, mIsReserved(false)
|
2016-03-15 05:50:16 +00:00
|
|
|
, mIsSynthesizedByTIP(false)
|
2013-09-24 10:04:15 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-10-18 06:10:20 +00:00
|
|
|
public:
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual WidgetKeyboardEvent* AsKeyboardEvent() override { return this; }
|
2013-10-18 06:10:20 +00:00
|
|
|
|
2015-08-26 12:56:59 +00:00
|
|
|
WidgetKeyboardEvent(bool aIsTrusted, EventMessage aMessage,
|
|
|
|
nsIWidget* aWidget,
|
2014-11-03 07:05:12 +00:00
|
|
|
EventClassID aEventClassID = eKeyboardEventClass)
|
|
|
|
: WidgetInputEvent(aIsTrusted, aMessage, aWidget, aEventClassID)
|
2016-05-12 10:18:36 +00:00
|
|
|
, mNativeKeyEvent(nullptr)
|
2016-05-12 08:13:49 +00:00
|
|
|
, mKeyCode(0)
|
2016-05-13 07:06:18 +00:00
|
|
|
, mCharCode(0)
|
2016-03-19 11:57:11 +00:00
|
|
|
, mPseudoCharCode(0)
|
2016-05-12 09:17:22 +00:00
|
|
|
, mLocation(nsIDOMKeyEvent::DOM_KEY_LOCATION_STANDARD)
|
2016-05-11 12:56:42 +00:00
|
|
|
, mAccessKeyForwardedToChild(false)
|
2014-04-10 07:11:36 +00:00
|
|
|
, mUniqueId(0)
|
2014-12-11 14:44:07 +00:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
, mNativeModifierFlags(0)
|
2016-05-12 10:18:36 +00:00
|
|
|
, mNativeKeyCode(0)
|
|
|
|
#endif // #ifdef XP_MACOSX
|
|
|
|
, mKeyNameIndex(mozilla::KEY_NAME_INDEX_Unidentified)
|
|
|
|
, mCodeNameIndex(CODE_NAME_INDEX_UNKNOWN)
|
2016-03-15 05:50:16 +00:00
|
|
|
, mInputMethodAppState(eNotHandled)
|
2016-05-12 10:18:36 +00:00
|
|
|
, mIsChar(false)
|
|
|
|
, mIsRepeat(false)
|
|
|
|
, mIsComposing(false)
|
|
|
|
, mIsReserved(false)
|
2016-03-15 05:50:16 +00:00
|
|
|
, mIsSynthesizedByTIP(false)
|
2013-09-24 10:04:15 +00:00
|
|
|
{
|
2016-04-22 16:22:49 +00:00
|
|
|
// If this is a keyboard event on a plugin, it shouldn't fired on content.
|
|
|
|
mFlags.mOnlySystemGroupDispatchInContent =
|
|
|
|
mFlags.mNoCrossProcessBoundaryForwarding = IsKeyEventOnPlugin();
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool IsKeyDownOrKeyDownOnPlugin(EventMessage aMessage)
|
|
|
|
{
|
|
|
|
return aMessage == eKeyDown || aMessage == eKeyDownOnPlugin;
|
|
|
|
}
|
|
|
|
bool IsKeyDownOrKeyDownOnPlugin() const
|
|
|
|
{
|
|
|
|
return IsKeyDownOrKeyDownOnPlugin(mMessage);
|
|
|
|
}
|
|
|
|
static bool IsKeyUpOrKeyUpOnPlugin(EventMessage aMessage)
|
|
|
|
{
|
|
|
|
return aMessage == eKeyUp || aMessage == eKeyUpOnPlugin;
|
|
|
|
}
|
|
|
|
bool IsKeyUpOrKeyUpOnPlugin() const
|
|
|
|
{
|
|
|
|
return IsKeyUpOrKeyUpOnPlugin(mMessage);
|
|
|
|
}
|
|
|
|
static bool IsKeyEventOnPlugin(EventMessage aMessage)
|
|
|
|
{
|
|
|
|
return aMessage == eKeyDownOnPlugin || aMessage == eKeyUpOnPlugin;
|
|
|
|
}
|
|
|
|
bool IsKeyEventOnPlugin() const
|
|
|
|
{
|
|
|
|
return IsKeyEventOnPlugin(mMessage);
|
2013-09-24 10:04:15 +00:00
|
|
|
}
|
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual WidgetEvent* Duplicate() const override
|
2014-01-27 06:10:44 +00:00
|
|
|
{
|
2014-08-04 05:28:48 +00:00
|
|
|
MOZ_ASSERT(mClass == eKeyboardEventClass,
|
2014-01-27 06:10:44 +00:00
|
|
|
"Duplicate() must be overridden by sub class");
|
|
|
|
// Not copying widget, it is a weak reference.
|
|
|
|
WidgetKeyboardEvent* result =
|
2015-08-22 01:34:51 +00:00
|
|
|
new WidgetKeyboardEvent(false, mMessage, nullptr);
|
2014-01-27 06:10:44 +00:00
|
|
|
result->AssignKeyEventData(*this, true);
|
|
|
|
result->mFlags = mFlags;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-05-12 10:18:36 +00:00
|
|
|
// OS translated Unicode chars which are used for accesskey and accelkey
|
|
|
|
// handling. The handlers will try from first character to last character.
|
|
|
|
nsTArray<AlternativeCharCode> mAlternativeCharCodes;
|
|
|
|
// DOM KeyboardEvent.key only when mKeyNameIndex is KEY_NAME_INDEX_USE_STRING.
|
|
|
|
nsString mKeyValue;
|
|
|
|
// DOM KeyboardEvent.code only when mCodeNameIndex is
|
|
|
|
// CODE_NAME_INDEX_USE_STRING.
|
|
|
|
nsString mCodeValue;
|
|
|
|
|
|
|
|
#ifdef XP_MACOSX
|
|
|
|
// Values given by a native NSEvent, for use with Cocoa NPAPI plugins.
|
|
|
|
nsString mNativeCharacters;
|
|
|
|
nsString mNativeCharactersIgnoringModifiers;
|
|
|
|
// If this is non-empty, create a text event for plugins instead of a
|
|
|
|
// keyboard event.
|
|
|
|
nsString mPluginTextEventString;
|
|
|
|
#endif // #ifdef XP_MACOSX
|
|
|
|
|
|
|
|
// OS-specific native event can optionally be preserved
|
|
|
|
void* mNativeKeyEvent;
|
2016-05-13 07:06:18 +00:00
|
|
|
// A DOM keyCode value or 0. If a keypress event whose mCharCode is 0, this
|
2013-09-24 10:04:15 +00:00
|
|
|
// should be 0.
|
2016-05-12 08:13:49 +00:00
|
|
|
uint32_t mKeyCode;
|
2013-09-24 10:04:15 +00:00
|
|
|
// If the instance is a keypress event of a printable key, this is a UTF-16
|
|
|
|
// value of the key. Otherwise, 0. This value must not be a control
|
|
|
|
// character when some modifiers are active. Then, this value should be an
|
|
|
|
// unmodified value except Shift and AltGr.
|
2016-05-13 07:06:18 +00:00
|
|
|
uint32_t mCharCode;
|
2016-03-19 11:57:11 +00:00
|
|
|
// mPseudoCharCode is valid only when mMessage is an eKeyDown event.
|
2016-05-13 07:06:18 +00:00
|
|
|
// This stores mCharCode value of keypress event which is fired with same
|
2016-03-19 11:57:11 +00:00
|
|
|
// key value and same modifier state.
|
|
|
|
uint32_t mPseudoCharCode;
|
2013-09-24 10:04:15 +00:00
|
|
|
// One of nsIDOMKeyEvent::DOM_KEY_LOCATION_*
|
2016-05-12 09:17:22 +00:00
|
|
|
uint32_t mLocation;
|
2016-05-11 12:56:42 +00:00
|
|
|
// True if accesskey handling was forwarded to the child via
|
|
|
|
// TabParent::HandleAccessKey. In this case, parent process menu access key
|
|
|
|
// handling should be delayed until it is determined that there exists no
|
|
|
|
// overriding access key in the content process.
|
|
|
|
bool mAccessKeyForwardedToChild;
|
2013-09-24 10:04:15 +00:00
|
|
|
// Unique id associated with a keydown / keypress event. Used in identifing
|
|
|
|
// keypress events for removal from async event dispatch queue in metrofx
|
|
|
|
// after preventDefault is called on keydown events. It's ok if this wraps
|
|
|
|
// over long periods.
|
|
|
|
uint32_t mUniqueId;
|
|
|
|
|
2014-12-11 14:44:07 +00:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
// Values given by a native NSEvent, for use with Cocoa NPAPI plugins.
|
|
|
|
uint32_t mNativeModifierFlags;
|
2016-05-12 10:18:36 +00:00
|
|
|
uint16_t mNativeKeyCode;
|
|
|
|
#endif // #ifdef XP_MACOSX
|
2014-12-11 14:44:07 +00:00
|
|
|
|
2016-05-12 10:18:36 +00:00
|
|
|
// DOM KeyboardEvent.key
|
|
|
|
KeyNameIndex mKeyNameIndex;
|
|
|
|
// DOM KeyboardEvent.code
|
|
|
|
CodeNameIndex mCodeNameIndex;
|
2016-03-15 05:50:16 +00:00
|
|
|
// Indicates that the event is being handled by input method app
|
|
|
|
typedef uint8_t InputMethodAppStateType;
|
|
|
|
enum InputMethodAppState : InputMethodAppStateType
|
|
|
|
{
|
|
|
|
eNotHandled, // not yet handled by intput method app
|
|
|
|
eHandling, // being handled by intput method app
|
|
|
|
eHandled // handled by input method app
|
|
|
|
};
|
|
|
|
InputMethodAppState mInputMethodAppState;
|
|
|
|
|
2016-05-12 10:18:36 +00:00
|
|
|
// Indicates whether the event signifies a printable character
|
|
|
|
bool mIsChar;
|
|
|
|
// Indicates whether the event is generated by auto repeat or not.
|
|
|
|
// if this is keyup event, always false.
|
|
|
|
bool mIsRepeat;
|
|
|
|
// Indicates whether the event is generated during IME (or deadkey)
|
|
|
|
// composition. This is initialized by EventStateManager. So, key event
|
|
|
|
// dispatchers don't need to initialize this.
|
|
|
|
bool mIsComposing;
|
|
|
|
// Indicates if the key combination is reserved by chrome. This is set by
|
|
|
|
// nsXBLWindowKeyHandler at capturing phase of the default event group.
|
|
|
|
bool mIsReserved;
|
2016-03-15 05:50:16 +00:00
|
|
|
// Indicates whether the event is synthesized from Text Input Processor
|
|
|
|
// or an actual event from nsAppShell.
|
|
|
|
bool mIsSynthesizedByTIP;
|
|
|
|
|
2015-02-19 06:50:18 +00:00
|
|
|
// If the key should cause keypress events, this returns true.
|
|
|
|
// Otherwise, false.
|
|
|
|
bool ShouldCauseKeypressEvents() const;
|
|
|
|
|
2016-05-13 07:06:18 +00:00
|
|
|
// mCharCode value of non-eKeyPress events is always 0. However, if
|
2016-03-19 11:57:11 +00:00
|
|
|
// non-eKeyPress event has one or more alternative char code values,
|
2016-05-13 07:06:18 +00:00
|
|
|
// its first item should be the mCharCode value of following eKeyPress event.
|
|
|
|
// PseudoCharCode() returns mCharCode value for eKeyPress event,
|
2016-03-19 11:57:11 +00:00
|
|
|
// the first alternative char code value of non-eKeyPress event or 0.
|
|
|
|
uint32_t PseudoCharCode() const
|
|
|
|
{
|
2016-05-13 07:06:18 +00:00
|
|
|
return mMessage == eKeyPress ? mCharCode : mPseudoCharCode;
|
2016-03-19 11:57:11 +00:00
|
|
|
}
|
|
|
|
void SetCharCode(uint32_t aCharCode)
|
|
|
|
{
|
|
|
|
if (mMessage == eKeyPress) {
|
2016-05-13 07:06:18 +00:00
|
|
|
mCharCode = aCharCode;
|
2016-03-19 11:57:11 +00:00
|
|
|
} else {
|
|
|
|
mPseudoCharCode = aCharCode;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-24 10:04:15 +00:00
|
|
|
void GetDOMKeyName(nsAString& aKeyName)
|
|
|
|
{
|
2013-12-10 16:14:53 +00:00
|
|
|
if (mKeyNameIndex == KEY_NAME_INDEX_USE_STRING) {
|
|
|
|
aKeyName = mKeyValue;
|
|
|
|
return;
|
|
|
|
}
|
2013-09-24 10:04:15 +00:00
|
|
|
GetDOMKeyName(mKeyNameIndex, aKeyName);
|
|
|
|
}
|
2014-05-25 02:08:58 +00:00
|
|
|
void GetDOMCodeName(nsAString& aCodeName)
|
|
|
|
{
|
|
|
|
if (mCodeNameIndex == CODE_NAME_INDEX_USE_STRING) {
|
|
|
|
aCodeName = mCodeValue;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
GetDOMCodeName(mCodeNameIndex, aCodeName);
|
|
|
|
}
|
2013-09-24 10:04:15 +00:00
|
|
|
|
2015-02-19 06:50:20 +00:00
|
|
|
bool IsModifierKeyEvent() const
|
|
|
|
{
|
|
|
|
return GetModifierForKeyName(mKeyNameIndex) != MODIFIER_NONE;
|
|
|
|
}
|
|
|
|
|
2016-03-18 02:22:37 +00:00
|
|
|
/**
|
|
|
|
* Get the candidates for shortcut key.
|
|
|
|
*
|
|
|
|
* @param aCandidates [out] the candidate shortcut key combination list.
|
|
|
|
* the first item is most preferred.
|
|
|
|
*/
|
|
|
|
void GetShortcutKeyCandidates(ShortcutKeyCandidateArray& aCandidates);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the candidates for access key.
|
|
|
|
*
|
|
|
|
* @param aCandidates [out] the candidate access key list.
|
|
|
|
* the first item is most preferred.
|
|
|
|
*/
|
|
|
|
void GetAccessKeyCandidates(nsTArray<uint32_t>& aCandidates);
|
|
|
|
|
2015-02-19 06:50:19 +00:00
|
|
|
static void Shutdown();
|
|
|
|
|
2015-02-19 06:50:19 +00:00
|
|
|
/**
|
2016-05-12 09:17:22 +00:00
|
|
|
* ComputeLocationFromCodeValue() returns one of .mLocation value
|
2015-02-19 06:50:19 +00:00
|
|
|
* (nsIDOMKeyEvent::DOM_KEY_LOCATION_*) which is the most preferred value
|
|
|
|
* for the specified specified code value.
|
|
|
|
*/
|
2015-01-28 13:36:53 +00:00
|
|
|
static uint32_t ComputeLocationFromCodeValue(CodeNameIndex aCodeNameIndex);
|
|
|
|
|
2015-02-19 06:50:19 +00:00
|
|
|
/**
|
2016-05-12 08:13:49 +00:00
|
|
|
* ComputeKeyCodeFromKeyNameIndex() return a .mKeyCode value which can be
|
2015-02-19 06:50:19 +00:00
|
|
|
* mapped from the specified key value. Note that this returns 0 if the
|
|
|
|
* key name index is KEY_NAME_INDEX_Unidentified or KEY_NAME_INDEX_USE_STRING.
|
|
|
|
* This means that this method is useful only for non-printable keys.
|
|
|
|
*/
|
|
|
|
static uint32_t ComputeKeyCodeFromKeyNameIndex(KeyNameIndex aKeyNameIndex);
|
|
|
|
|
2015-02-19 06:50:19 +00:00
|
|
|
/**
|
|
|
|
* GetModifierForKeyName() returns a value of Modifier which is activated
|
|
|
|
* by the aKeyNameIndex.
|
|
|
|
*/
|
|
|
|
static Modifier GetModifierForKeyName(KeyNameIndex aKeyNameIndex);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* IsLockableModifier() returns true if aKeyNameIndex is a lockable modifier
|
|
|
|
* key such as CapsLock and NumLock.
|
|
|
|
*/
|
|
|
|
static bool IsLockableModifier(KeyNameIndex aKeyNameIndex);
|
|
|
|
|
2014-05-25 02:08:58 +00:00
|
|
|
static void GetDOMKeyName(KeyNameIndex aKeyNameIndex,
|
2014-01-08 16:45:30 +00:00
|
|
|
nsAString& aKeyName);
|
2014-05-25 02:08:58 +00:00
|
|
|
static void GetDOMCodeName(CodeNameIndex aCodeNameIndex,
|
|
|
|
nsAString& aCodeName);
|
2013-09-24 10:04:15 +00:00
|
|
|
|
2015-02-19 06:50:19 +00:00
|
|
|
static KeyNameIndex GetKeyNameIndex(const nsAString& aKeyValue);
|
|
|
|
static CodeNameIndex GetCodeNameIndex(const nsAString& aCodeValue);
|
|
|
|
|
2014-03-14 13:13:30 +00:00
|
|
|
static const char* GetCommandStr(Command aCommand);
|
|
|
|
|
2013-09-24 10:04:15 +00:00
|
|
|
void AssignKeyEventData(const WidgetKeyboardEvent& aEvent, bool aCopyTargets)
|
|
|
|
{
|
|
|
|
AssignInputEventData(aEvent, aCopyTargets);
|
|
|
|
|
2016-05-12 08:13:49 +00:00
|
|
|
mKeyCode = aEvent.mKeyCode;
|
2016-05-13 07:06:18 +00:00
|
|
|
mCharCode = aEvent.mCharCode;
|
2016-03-19 11:57:11 +00:00
|
|
|
mPseudoCharCode = aEvent.mPseudoCharCode;
|
2016-05-12 09:17:22 +00:00
|
|
|
mLocation = aEvent.mLocation;
|
2016-05-12 08:57:21 +00:00
|
|
|
mAlternativeCharCodes = aEvent.mAlternativeCharCodes;
|
2016-05-12 09:31:05 +00:00
|
|
|
mIsChar = aEvent.mIsChar;
|
2013-11-07 11:17:32 +00:00
|
|
|
mIsRepeat = aEvent.mIsRepeat;
|
2014-04-10 07:11:36 +00:00
|
|
|
mIsComposing = aEvent.mIsComposing;
|
2016-04-22 16:22:49 +00:00
|
|
|
mIsReserved = aEvent.mIsReserved;
|
2016-05-11 12:56:42 +00:00
|
|
|
mAccessKeyForwardedToChild = aEvent.mAccessKeyForwardedToChild;
|
2013-09-24 10:04:15 +00:00
|
|
|
mKeyNameIndex = aEvent.mKeyNameIndex;
|
2014-05-25 02:08:58 +00:00
|
|
|
mCodeNameIndex = aEvent.mCodeNameIndex;
|
2013-12-10 16:14:53 +00:00
|
|
|
mKeyValue = aEvent.mKeyValue;
|
2014-05-25 02:08:58 +00:00
|
|
|
mCodeValue = aEvent.mCodeValue;
|
2013-09-24 10:04:15 +00:00
|
|
|
// Don't copy mNativeKeyEvent because it may be referred after its instance
|
|
|
|
// is destroyed.
|
|
|
|
mNativeKeyEvent = nullptr;
|
|
|
|
mUniqueId = aEvent.mUniqueId;
|
2015-02-20 16:37:02 +00:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
mNativeKeyCode = aEvent.mNativeKeyCode;
|
|
|
|
mNativeModifierFlags = aEvent.mNativeModifierFlags;
|
|
|
|
mNativeCharacters.Assign(aEvent.mNativeCharacters);
|
|
|
|
mNativeCharactersIgnoringModifiers.
|
|
|
|
Assign(aEvent.mNativeCharactersIgnoringModifiers);
|
|
|
|
mPluginTextEventString.Assign(aEvent.mPluginTextEventString);
|
|
|
|
#endif
|
2016-03-15 05:50:16 +00:00
|
|
|
mInputMethodAppState = aEvent.mInputMethodAppState;
|
|
|
|
mIsSynthesizedByTIP = aEvent.mIsSynthesizedByTIP;
|
2013-09-24 10:04:15 +00:00
|
|
|
}
|
2015-02-19 06:50:19 +00:00
|
|
|
|
|
|
|
private:
|
2016-03-11 02:18:39 +00:00
|
|
|
static const char16_t* const kKeyNames[];
|
|
|
|
static const char16_t* const kCodeNames[];
|
2015-02-19 06:50:19 +00:00
|
|
|
typedef nsDataHashtable<nsStringHashKey,
|
|
|
|
KeyNameIndex> KeyNameIndexHashtable;
|
|
|
|
typedef nsDataHashtable<nsStringHashKey,
|
|
|
|
CodeNameIndex> CodeNameIndexHashtable;
|
|
|
|
static KeyNameIndexHashtable* sKeyNameIndexHashtable;
|
|
|
|
static CodeNameIndexHashtable* sCodeNameIndexHashtable;
|
2013-09-24 10:04:15 +00:00
|
|
|
};
|
|
|
|
|
2014-11-03 07:05:12 +00:00
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* mozilla::InternalBeforeAfterKeyboardEvent
|
|
|
|
*
|
|
|
|
* This is extended from WidgetKeyboardEvent and is mapped to DOM event
|
|
|
|
* "BeforeAfterKeyboardEvent".
|
|
|
|
*
|
2015-08-28 23:58:27 +00:00
|
|
|
* Event mMessage: eBeforeKeyDown
|
2015-08-28 23:58:28 +00:00
|
|
|
* eBeforeKeyUp
|
2015-08-28 23:58:28 +00:00
|
|
|
* eAfterKeyDown
|
2015-08-28 23:58:28 +00:00
|
|
|
* eAfterKeyUp
|
2014-11-03 07:05:12 +00:00
|
|
|
******************************************************************************/
|
|
|
|
class InternalBeforeAfterKeyboardEvent : public WidgetKeyboardEvent
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
friend class dom::PBrowserParent;
|
|
|
|
friend class dom::PBrowserChild;
|
|
|
|
|
|
|
|
InternalBeforeAfterKeyboardEvent()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
// Extra member for InternalBeforeAfterKeyboardEvent. Indicates whether
|
|
|
|
// default actions of keydown/keyup event is prevented.
|
|
|
|
Nullable<bool> mEmbeddedCancelled;
|
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual InternalBeforeAfterKeyboardEvent* AsBeforeAfterKeyboardEvent() override
|
2014-11-03 07:05:12 +00:00
|
|
|
{
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2015-08-26 12:56:59 +00:00
|
|
|
InternalBeforeAfterKeyboardEvent(bool aIsTrusted, EventMessage aMessage,
|
2014-11-03 07:05:12 +00:00
|
|
|
nsIWidget* aWidget)
|
2015-08-26 12:56:59 +00:00
|
|
|
: WidgetKeyboardEvent(aIsTrusted, aMessage, aWidget,
|
|
|
|
eBeforeAfterKeyboardEventClass)
|
2014-11-03 07:05:12 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual WidgetEvent* Duplicate() const override
|
2014-11-03 07:05:12 +00:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(mClass == eBeforeAfterKeyboardEventClass,
|
|
|
|
"Duplicate() must be overridden by sub class");
|
|
|
|
// Not copying widget, it is a weak reference.
|
|
|
|
InternalBeforeAfterKeyboardEvent* result =
|
2015-08-22 01:34:51 +00:00
|
|
|
new InternalBeforeAfterKeyboardEvent(false, mMessage, nullptr);
|
2014-11-03 07:05:12 +00:00
|
|
|
result->AssignBeforeAfterKeyEventData(*this, true);
|
|
|
|
result->mFlags = mFlags;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AssignBeforeAfterKeyEventData(
|
|
|
|
const InternalBeforeAfterKeyboardEvent& aEvent,
|
|
|
|
bool aCopyTargets)
|
|
|
|
{
|
|
|
|
AssignKeyEventData(aEvent, aCopyTargets);
|
|
|
|
mEmbeddedCancelled = aEvent.mEmbeddedCancelled;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AssignBeforeAfterKeyEventData(
|
|
|
|
const WidgetKeyboardEvent& aEvent,
|
|
|
|
bool aCopyTargets)
|
|
|
|
{
|
|
|
|
AssignKeyEventData(aEvent, aCopyTargets);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-09-24 10:04:15 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* mozilla::WidgetCompositionEvent
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
class WidgetCompositionEvent : public WidgetGUIEvent
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
friend class mozilla::dom::PBrowserParent;
|
|
|
|
friend class mozilla::dom::PBrowserChild;
|
|
|
|
|
|
|
|
WidgetCompositionEvent()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual WidgetCompositionEvent* AsCompositionEvent() override
|
2013-10-18 06:10:20 +00:00
|
|
|
{
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2015-08-26 12:56:59 +00:00
|
|
|
WidgetCompositionEvent(bool aIsTrusted, EventMessage aMessage,
|
2014-01-15 14:41:39 +00:00
|
|
|
nsIWidget* aWidget)
|
2014-08-04 05:28:48 +00:00
|
|
|
: WidgetGUIEvent(aIsTrusted, aMessage, aWidget, eCompositionEventClass)
|
2015-12-11 06:15:57 +00:00
|
|
|
, mNativeIMEContext(aWidget)
|
2015-09-08 03:54:14 +00:00
|
|
|
, mOriginalMessage(eVoidEvent)
|
2013-09-24 10:04:15 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual WidgetEvent* Duplicate() const override
|
2014-01-27 06:10:44 +00:00
|
|
|
{
|
2014-08-04 05:28:48 +00:00
|
|
|
MOZ_ASSERT(mClass == eCompositionEventClass,
|
2014-01-27 06:10:44 +00:00
|
|
|
"Duplicate() must be overridden by sub class");
|
|
|
|
// Not copying widget, it is a weak reference.
|
|
|
|
WidgetCompositionEvent* result =
|
2015-08-22 01:34:51 +00:00
|
|
|
new WidgetCompositionEvent(false, mMessage, nullptr);
|
2014-01-27 06:10:44 +00:00
|
|
|
result->AssignCompositionEventData(*this, true);
|
|
|
|
result->mFlags = mFlags;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2013-09-24 10:04:15 +00:00
|
|
|
// The composition string or the commit string. If the instance is a
|
|
|
|
// compositionstart event, this is initialized with selected text by
|
|
|
|
// TextComposition automatically.
|
2014-10-07 10:01:46 +00:00
|
|
|
nsString mData;
|
2013-09-24 10:04:15 +00:00
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<TextRangeArray> mRanges;
|
2014-10-07 10:01:47 +00:00
|
|
|
|
2015-12-11 06:15:57 +00:00
|
|
|
// mNativeIMEContext stores the native IME context which causes the
|
|
|
|
// composition event.
|
|
|
|
widget::NativeIMEContext mNativeIMEContext;
|
|
|
|
|
2015-09-08 03:54:14 +00:00
|
|
|
// If the instance is a clone of another event, mOriginalMessage stores
|
|
|
|
// the another event's mMessage.
|
|
|
|
EventMessage mOriginalMessage;
|
|
|
|
|
2013-09-24 10:04:15 +00:00
|
|
|
void AssignCompositionEventData(const WidgetCompositionEvent& aEvent,
|
|
|
|
bool aCopyTargets)
|
|
|
|
{
|
|
|
|
AssignGUIEventData(aEvent, aCopyTargets);
|
|
|
|
|
2014-10-07 10:01:46 +00:00
|
|
|
mData = aEvent.mData;
|
2015-09-08 03:54:14 +00:00
|
|
|
mOriginalMessage = aEvent.mOriginalMessage;
|
2014-10-07 10:01:47 +00:00
|
|
|
|
|
|
|
// Currently, we don't need to copy the other members because they are
|
|
|
|
// for internal use only (not available from JS).
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsComposing() const
|
|
|
|
{
|
|
|
|
return mRanges && mRanges->IsComposing();
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t TargetClauseOffset() const
|
|
|
|
{
|
|
|
|
return mRanges ? mRanges->TargetClauseOffset() : 0;
|
|
|
|
}
|
|
|
|
|
2015-06-11 10:50:15 +00:00
|
|
|
uint32_t TargetClauseLength() const
|
|
|
|
{
|
|
|
|
uint32_t length = UINT32_MAX;
|
|
|
|
if (mRanges) {
|
|
|
|
length = mRanges->TargetClauseLength();
|
|
|
|
}
|
|
|
|
return length == UINT32_MAX ? mData.Length() : length;
|
|
|
|
}
|
|
|
|
|
2014-10-07 10:01:47 +00:00
|
|
|
uint32_t RangeCount() const
|
|
|
|
{
|
|
|
|
return mRanges ? mRanges->Length() : 0;
|
2013-09-24 10:04:15 +00:00
|
|
|
}
|
2014-11-25 05:02:30 +00:00
|
|
|
|
|
|
|
bool CausesDOMTextEvent() const
|
|
|
|
{
|
2015-09-11 12:21:27 +00:00
|
|
|
return mMessage == eCompositionChange ||
|
2015-09-11 12:21:27 +00:00
|
|
|
mMessage == eCompositionCommit ||
|
2015-09-11 12:21:26 +00:00
|
|
|
mMessage == eCompositionCommitAsIs;
|
2014-11-25 05:02:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CausesDOMCompositionEndEvent() const
|
|
|
|
{
|
2015-09-11 12:21:27 +00:00
|
|
|
return mMessage == eCompositionEnd ||
|
2015-09-11 12:21:27 +00:00
|
|
|
mMessage == eCompositionCommit ||
|
2015-09-11 12:21:26 +00:00
|
|
|
mMessage == eCompositionCommitAsIs;
|
2014-11-25 05:02:30 +00:00
|
|
|
}
|
2015-09-08 03:54:14 +00:00
|
|
|
|
|
|
|
bool IsFollowedByCompositionEnd() const
|
|
|
|
{
|
2015-09-11 12:21:27 +00:00
|
|
|
return mOriginalMessage == eCompositionCommit ||
|
2015-09-11 12:21:26 +00:00
|
|
|
mOriginalMessage == eCompositionCommitAsIs;
|
2015-09-08 03:54:14 +00:00
|
|
|
}
|
2013-09-24 10:04:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* mozilla::WidgetQueryContentEvent
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
class WidgetQueryContentEvent : public WidgetGUIEvent
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
friend class dom::PBrowserParent;
|
|
|
|
friend class dom::PBrowserChild;
|
|
|
|
|
|
|
|
WidgetQueryContentEvent()
|
2016-01-12 18:16:59 +00:00
|
|
|
: mSucceeded(false)
|
|
|
|
, mUseNativeLineBreak(true)
|
|
|
|
, mWithFontRanges(false)
|
2013-09-24 10:04:15 +00:00
|
|
|
{
|
|
|
|
MOZ_CRASH("WidgetQueryContentEvent is created without proper arguments");
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual WidgetQueryContentEvent* AsQueryContentEvent() override
|
2013-10-18 06:10:20 +00:00
|
|
|
{
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2015-08-26 12:56:59 +00:00
|
|
|
WidgetQueryContentEvent(bool aIsTrusted, EventMessage aMessage,
|
2014-04-25 23:52:12 +00:00
|
|
|
nsIWidget* aWidget)
|
2014-08-04 05:28:49 +00:00
|
|
|
: WidgetGUIEvent(aIsTrusted, aMessage, aWidget, eQueryContentEventClass)
|
2014-04-25 23:52:12 +00:00
|
|
|
, mSucceeded(false)
|
|
|
|
, mUseNativeLineBreak(true)
|
2015-01-31 07:17:12 +00:00
|
|
|
, mWithFontRanges(false)
|
2013-09-24 10:04:15 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual WidgetEvent* Duplicate() const override
|
2014-01-27 06:10:44 +00:00
|
|
|
{
|
|
|
|
// This event isn't an internal event of any DOM event.
|
2014-03-27 13:53:19 +00:00
|
|
|
NS_ASSERTION(!IsAllowedToDispatchDOMEvent(),
|
|
|
|
"WidgetQueryContentEvent needs to support Duplicate()");
|
2014-01-27 06:10:44 +00:00
|
|
|
MOZ_CRASH("WidgetQueryContentEvent doesn't support Duplicate()");
|
|
|
|
}
|
|
|
|
|
2014-04-25 23:52:12 +00:00
|
|
|
void InitForQueryTextContent(uint32_t aOffset, uint32_t aLength,
|
|
|
|
bool aUseNativeLineBreak = true)
|
2013-09-24 10:04:15 +00:00
|
|
|
{
|
2015-09-10 01:40:05 +00:00
|
|
|
NS_ASSERTION(mMessage == eQueryTextContent,
|
2013-09-24 10:04:15 +00:00
|
|
|
"wrong initializer is called");
|
|
|
|
mInput.mOffset = aOffset;
|
|
|
|
mInput.mLength = aLength;
|
2014-04-25 23:52:12 +00:00
|
|
|
mUseNativeLineBreak = aUseNativeLineBreak;
|
2013-09-24 10:04:15 +00:00
|
|
|
}
|
|
|
|
|
2014-04-25 23:52:12 +00:00
|
|
|
void InitForQueryCaretRect(uint32_t aOffset,
|
|
|
|
bool aUseNativeLineBreak = true)
|
2013-09-24 10:04:15 +00:00
|
|
|
{
|
2015-09-10 01:40:06 +00:00
|
|
|
NS_ASSERTION(mMessage == eQueryCaretRect,
|
2013-09-24 10:04:15 +00:00
|
|
|
"wrong initializer is called");
|
|
|
|
mInput.mOffset = aOffset;
|
2014-04-25 23:52:12 +00:00
|
|
|
mUseNativeLineBreak = aUseNativeLineBreak;
|
2013-09-24 10:04:15 +00:00
|
|
|
}
|
|
|
|
|
2014-04-25 23:52:12 +00:00
|
|
|
void InitForQueryTextRect(uint32_t aOffset, uint32_t aLength,
|
|
|
|
bool aUseNativeLineBreak = true)
|
2013-09-24 10:04:15 +00:00
|
|
|
{
|
2015-09-11 12:21:26 +00:00
|
|
|
NS_ASSERTION(mMessage == eQueryTextRect,
|
2013-09-24 10:04:15 +00:00
|
|
|
"wrong initializer is called");
|
|
|
|
mInput.mOffset = aOffset;
|
|
|
|
mInput.mLength = aLength;
|
2014-04-25 23:52:12 +00:00
|
|
|
mUseNativeLineBreak = aUseNativeLineBreak;
|
2013-09-24 10:04:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void InitForQueryDOMWidgetHittest(const mozilla::LayoutDeviceIntPoint& aPoint)
|
|
|
|
{
|
2015-09-10 01:40:06 +00:00
|
|
|
NS_ASSERTION(mMessage == eQueryDOMWidgetHittest,
|
2013-09-24 10:04:15 +00:00
|
|
|
"wrong initializer is called");
|
2016-04-18 14:09:02 +00:00
|
|
|
mRefPoint = aPoint;
|
2013-09-24 10:04:15 +00:00
|
|
|
}
|
|
|
|
|
2015-01-31 07:17:12 +00:00
|
|
|
void RequestFontRanges()
|
|
|
|
{
|
2015-09-10 01:40:05 +00:00
|
|
|
NS_ASSERTION(mMessage == eQueryTextContent,
|
2015-01-31 07:17:12 +00:00
|
|
|
"not querying text content");
|
|
|
|
mWithFontRanges = true;
|
|
|
|
}
|
|
|
|
|
2013-09-24 10:04:15 +00:00
|
|
|
uint32_t GetSelectionStart(void) const
|
|
|
|
{
|
2015-09-10 01:40:05 +00:00
|
|
|
NS_ASSERTION(mMessage == eQuerySelectedText,
|
2013-09-24 10:04:15 +00:00
|
|
|
"not querying selection");
|
|
|
|
return mReply.mOffset + (mReply.mReversed ? mReply.mString.Length() : 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t GetSelectionEnd(void) const
|
|
|
|
{
|
2015-09-10 01:40:05 +00:00
|
|
|
NS_ASSERTION(mMessage == eQuerySelectedText,
|
2013-09-24 10:04:15 +00:00
|
|
|
"not querying selection");
|
|
|
|
return mReply.mOffset + (mReply.mReversed ? 0 : mReply.mString.Length());
|
|
|
|
}
|
|
|
|
|
2014-12-05 02:15:43 +00:00
|
|
|
mozilla::WritingMode GetWritingMode(void) const
|
|
|
|
{
|
2015-09-10 01:40:05 +00:00
|
|
|
NS_ASSERTION(mMessage == eQuerySelectedText ||
|
2015-09-10 01:40:06 +00:00
|
|
|
mMessage == eQueryCaretRect ||
|
2015-09-11 12:21:26 +00:00
|
|
|
mMessage == eQueryTextRect,
|
2015-02-10 15:28:05 +00:00
|
|
|
"not querying selection or text rect");
|
2014-12-05 02:15:43 +00:00
|
|
|
return mReply.mWritingMode;
|
|
|
|
}
|
|
|
|
|
2013-09-24 10:04:15 +00:00
|
|
|
bool mSucceeded;
|
2014-04-25 23:52:12 +00:00
|
|
|
bool mUseNativeLineBreak;
|
2015-01-31 07:17:12 +00:00
|
|
|
bool mWithFontRanges;
|
2013-09-24 10:04:15 +00:00
|
|
|
struct
|
|
|
|
{
|
2015-05-26 08:14:35 +00:00
|
|
|
uint32_t EndOffset() const
|
|
|
|
{
|
2015-06-05 09:28:21 +00:00
|
|
|
CheckedInt<uint32_t> endOffset =
|
|
|
|
CheckedInt<uint32_t>(mOffset) + mLength;
|
|
|
|
return NS_WARN_IF(!endOffset.isValid()) ? UINT32_MAX : endOffset.value();
|
2015-05-26 08:14:35 +00:00
|
|
|
}
|
|
|
|
|
2013-09-24 10:04:15 +00:00
|
|
|
uint32_t mOffset;
|
|
|
|
uint32_t mLength;
|
|
|
|
} mInput;
|
2015-04-14 10:46:51 +00:00
|
|
|
|
|
|
|
struct Reply
|
2013-09-24 10:04:15 +00:00
|
|
|
{
|
|
|
|
void* mContentsRoot;
|
|
|
|
uint32_t mOffset;
|
2015-09-10 01:40:06 +00:00
|
|
|
// mTentativeCaretOffset is used by only eQueryCharacterAtPoint.
|
2016-04-18 14:09:02 +00:00
|
|
|
// This is the offset where caret would be if user clicked at the mRefPoint.
|
2015-04-14 05:27:37 +00:00
|
|
|
uint32_t mTentativeCaretOffset;
|
2013-09-24 10:04:15 +00:00
|
|
|
nsString mString;
|
2015-10-05 05:46:39 +00:00
|
|
|
// mRect is used by eQueryTextRect, eQueryCaretRect, eQueryCharacterAtPoint
|
|
|
|
// and eQueryEditorRect. The coordinates is system coordinates relative to
|
|
|
|
// the top level widget of mFocusedWidget. E.g., if a <xul:panel> which
|
|
|
|
// is owned by a window has focused editor, the offset of mRect is relative
|
|
|
|
// to the owner window, not the <xul:panel>.
|
2015-02-04 20:21:03 +00:00
|
|
|
mozilla::LayoutDeviceIntRect mRect;
|
2013-09-24 10:04:15 +00:00
|
|
|
// The return widget has the caret. This is set at all query events.
|
|
|
|
nsIWidget* mFocusedWidget;
|
2014-11-22 14:39:03 +00:00
|
|
|
// mozilla::WritingMode value at the end (focus) of the selection
|
|
|
|
mozilla::WritingMode mWritingMode;
|
2015-09-10 01:40:05 +00:00
|
|
|
// Used by eQuerySelectionAsTransferable
|
2013-09-24 10:04:15 +00:00
|
|
|
nsCOMPtr<nsITransferable> mTransferable;
|
2015-09-10 01:40:05 +00:00
|
|
|
// Used by eQueryTextContent with font ranges requested
|
2016-02-02 15:36:30 +00:00
|
|
|
AutoTArray<mozilla::FontRange, 1> mFontRanges;
|
2015-04-14 10:46:51 +00:00
|
|
|
// true if selection is reversed (end < start)
|
|
|
|
bool mReversed;
|
|
|
|
// true if the selection exists
|
|
|
|
bool mHasSelection;
|
|
|
|
// true if DOM element under mouse belongs to widget
|
|
|
|
bool mWidgetIsHit;
|
|
|
|
|
|
|
|
Reply()
|
|
|
|
: mContentsRoot(nullptr)
|
|
|
|
, mOffset(NOT_FOUND)
|
|
|
|
, mTentativeCaretOffset(NOT_FOUND)
|
|
|
|
, mFocusedWidget(nullptr)
|
|
|
|
, mReversed(false)
|
|
|
|
, mHasSelection(false)
|
|
|
|
, mWidgetIsHit(false)
|
|
|
|
{
|
|
|
|
}
|
2013-09-24 10:04:15 +00:00
|
|
|
} mReply;
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
NOT_FOUND = UINT32_MAX
|
|
|
|
};
|
|
|
|
|
|
|
|
// values of mComputedScrollAction
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
SCROLL_ACTION_NONE,
|
|
|
|
SCROLL_ACTION_LINE,
|
|
|
|
SCROLL_ACTION_PAGE
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* mozilla::WidgetSelectionEvent
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
class WidgetSelectionEvent : public WidgetGUIEvent
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
friend class mozilla::dom::PBrowserParent;
|
|
|
|
friend class mozilla::dom::PBrowserChild;
|
|
|
|
|
|
|
|
WidgetSelectionEvent()
|
2015-05-28 04:51:40 +00:00
|
|
|
: mOffset(0)
|
2014-01-15 14:41:39 +00:00
|
|
|
, mLength(0)
|
|
|
|
, mReversed(false)
|
|
|
|
, mExpandToClusterBoundary(true)
|
|
|
|
, mSucceeded(false)
|
2016-01-12 18:16:59 +00:00
|
|
|
, mUseNativeLineBreak(true)
|
2013-09-24 10:04:15 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual WidgetSelectionEvent* AsSelectionEvent() override
|
2013-10-18 06:10:20 +00:00
|
|
|
{
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2015-08-26 12:56:59 +00:00
|
|
|
WidgetSelectionEvent(bool aIsTrusted, EventMessage aMessage,
|
|
|
|
nsIWidget* aWidget)
|
2014-08-04 05:28:49 +00:00
|
|
|
: WidgetGUIEvent(aIsTrusted, aMessage, aWidget, eSelectionEventClass)
|
2014-01-15 14:41:39 +00:00
|
|
|
, mOffset(0)
|
|
|
|
, mLength(0)
|
|
|
|
, mReversed(false)
|
|
|
|
, mExpandToClusterBoundary(true)
|
|
|
|
, mSucceeded(false)
|
2014-04-25 23:52:12 +00:00
|
|
|
, mUseNativeLineBreak(true)
|
2015-12-01 20:25:06 +00:00
|
|
|
, mReason(nsISelectionListener::NO_REASON)
|
2013-09-24 10:04:15 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual WidgetEvent* Duplicate() const override
|
2014-01-27 06:10:44 +00:00
|
|
|
{
|
|
|
|
// This event isn't an internal event of any DOM event.
|
2014-03-27 13:53:19 +00:00
|
|
|
NS_ASSERTION(!IsAllowedToDispatchDOMEvent(),
|
|
|
|
"WidgetSelectionEvent needs to support Duplicate()");
|
2014-01-27 06:10:44 +00:00
|
|
|
MOZ_CRASH("WidgetSelectionEvent doesn't support Duplicate()");
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2013-09-24 10:04:15 +00:00
|
|
|
// Start offset of selection
|
|
|
|
uint32_t mOffset;
|
|
|
|
// Length of selection
|
|
|
|
uint32_t mLength;
|
|
|
|
// Selection "anchor" should be in front
|
|
|
|
bool mReversed;
|
|
|
|
// Cluster-based or character-based
|
|
|
|
bool mExpandToClusterBoundary;
|
|
|
|
// true if setting selection succeeded.
|
|
|
|
bool mSucceeded;
|
2014-04-25 23:52:12 +00:00
|
|
|
// true if native line breaks are used for mOffset and mLength
|
|
|
|
bool mUseNativeLineBreak;
|
2015-12-01 20:25:06 +00:00
|
|
|
// Fennec provides eSetSelection reason codes for downstream
|
|
|
|
// use in AccessibleCaret visibility logic.
|
|
|
|
int16_t mReason;
|
2013-09-24 10:04:15 +00:00
|
|
|
};
|
|
|
|
|
2014-04-10 07:11:37 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* mozilla::InternalEditorInputEvent
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
class InternalEditorInputEvent : public InternalUIEvent
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
InternalEditorInputEvent()
|
|
|
|
: mIsComposing(false)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual InternalEditorInputEvent* AsEditorInputEvent() override
|
2014-04-10 07:11:37 +00:00
|
|
|
{
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2015-08-26 12:56:59 +00:00
|
|
|
InternalEditorInputEvent(bool aIsTrusted, EventMessage aMessage,
|
2014-04-10 07:11:37 +00:00
|
|
|
nsIWidget* aWidget)
|
2014-08-04 05:28:49 +00:00
|
|
|
: InternalUIEvent(aIsTrusted, aMessage, aWidget, eEditorInputEventClass)
|
2014-04-10 07:11:37 +00:00
|
|
|
, mIsComposing(false)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual WidgetEvent* Duplicate() const override
|
2014-04-10 07:11:37 +00:00
|
|
|
{
|
2014-08-04 05:28:49 +00:00
|
|
|
MOZ_ASSERT(mClass == eEditorInputEventClass,
|
2014-04-10 07:11:37 +00:00
|
|
|
"Duplicate() must be overridden by sub class");
|
|
|
|
// Not copying widget, it is a weak reference.
|
|
|
|
InternalEditorInputEvent* result =
|
2015-08-22 01:34:51 +00:00
|
|
|
new InternalEditorInputEvent(false, mMessage, nullptr);
|
2014-04-10 07:11:37 +00:00
|
|
|
result->AssignEditorInputEventData(*this, true);
|
|
|
|
result->mFlags = mFlags;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool mIsComposing;
|
|
|
|
|
|
|
|
void AssignEditorInputEventData(const InternalEditorInputEvent& aEvent,
|
|
|
|
bool aCopyTargets)
|
|
|
|
{
|
|
|
|
AssignUIEventData(aEvent, aCopyTargets);
|
|
|
|
|
|
|
|
mIsComposing = aEvent.mIsComposing;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-09-24 10:04:15 +00:00
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_TextEvents_h__
|