Bug 989198, Patch 1: Implementation of InternalBeforeAfterKeyboardEvent, r=smaug,masayuki.

This commit is contained in:
Gina Yeh 2014-11-03 15:05:12 +08:00
Родитель 938aa11999
Коммит f4ea14c0b9
5 изменённых файлов: 111 добавлений и 2 удалений

Просмотреть файл

@ -41,6 +41,11 @@
// Key is pressed within a window
#define NS_KEY_DOWN (NS_WINDOW_START + 33)
#define NS_KEY_BEFORE_DOWN (NS_WINDOW_START + 34)
#define NS_KEY_AFTER_DOWN (NS_WINDOW_START + 35)
#define NS_KEY_BEFORE_UP (NS_WINDOW_START + 36)
#define NS_KEY_AFTER_UP (NS_WINDOW_START + 37)
#define NS_RESIZE_EVENT (NS_WINDOW_START + 60)
#define NS_SCROLL_EVENT (NS_WINDOW_START + 61)

Просмотреть файл

@ -26,6 +26,7 @@ NS_EVENT_CLASS(Widget, CompositionEvent)
NS_EVENT_CLASS(Widget, QueryContentEvent)
NS_EVENT_CLASS(Widget, SelectionEvent)
NS_EVENT_CLASS(Internal, EditorInputEvent)
NS_EVENT_CLASS(Internal, BeforeAfterKeyboardEvent)
// MouseEvents.h
NS_EVENT_CLASS(Widget, MouseEventBase)

Просмотреть файл

@ -75,6 +75,7 @@ private:
friend class dom::PBrowserParent;
friend class dom::PBrowserChild;
protected:
WidgetKeyboardEvent()
{
}
@ -82,8 +83,9 @@ private:
public:
virtual WidgetKeyboardEvent* AsKeyboardEvent() MOZ_OVERRIDE { return this; }
WidgetKeyboardEvent(bool aIsTrusted, uint32_t aMessage, nsIWidget* aWidget)
: WidgetInputEvent(aIsTrusted, aMessage, aWidget, eKeyboardEventClass)
WidgetKeyboardEvent(bool aIsTrusted, uint32_t aMessage, nsIWidget* aWidget,
EventClassID aEventClassID = eKeyboardEventClass)
: WidgetInputEvent(aIsTrusted, aMessage, aWidget, aEventClassID)
, keyCode(0)
, charCode(0)
, location(nsIDOMKeyEvent::DOM_KEY_LOCATION_STANDARD)
@ -194,6 +196,72 @@ public:
}
};
/******************************************************************************
* mozilla::InternalBeforeAfterKeyboardEvent
*
* This is extended from WidgetKeyboardEvent and is mapped to DOM event
* "BeforeAfterKeyboardEvent".
*
* Event message: NS_KEY_BEFORE_DOWN
* NS_KEY_BEFORE_UP
* NS_KEY_AFTER_DOWN
* NS_KEY_AFTER_UP
******************************************************************************/
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;
virtual InternalBeforeAfterKeyboardEvent* AsBeforeAfterKeyboardEvent() MOZ_OVERRIDE
{
return this;
}
InternalBeforeAfterKeyboardEvent(bool aIsTrusted, uint32_t aMessage,
nsIWidget* aWidget)
: WidgetKeyboardEvent(aIsTrusted, aMessage, aWidget, eBeforeAfterKeyboardEventClass)
{
}
virtual WidgetEvent* Duplicate() const MOZ_OVERRIDE
{
MOZ_ASSERT(mClass == eBeforeAfterKeyboardEventClass,
"Duplicate() must be overridden by sub class");
// Not copying widget, it is a weak reference.
InternalBeforeAfterKeyboardEvent* result =
new InternalBeforeAfterKeyboardEvent(false, message, nullptr);
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);
}
};
/******************************************************************************
* mozilla::WidgetCompositionEvent
******************************************************************************/

Просмотреть файл

@ -122,6 +122,10 @@ WidgetEvent::HasKeyEventMessage() const
case NS_KEY_DOWN:
case NS_KEY_PRESS:
case NS_KEY_UP:
case NS_KEY_BEFORE_DOWN:
case NS_KEY_BEFORE_UP:
case NS_KEY_AFTER_DOWN:
case NS_KEY_AFTER_UP:
return true;
default:
return false;

Просмотреть файл

@ -362,6 +362,37 @@ struct ParamTraits<mozilla::WidgetKeyboardEvent>
}
};
template<>
struct ParamTraits<mozilla::InternalBeforeAfterKeyboardEvent>
{
typedef mozilla::InternalBeforeAfterKeyboardEvent paramType;
static void Write(Message* aMsg, const paramType& aParam)
{
WriteParam(aMsg, static_cast<mozilla::WidgetKeyboardEvent>(aParam));
WriteParam(aMsg, aParam.mEmbeddedCancelled.IsNull());
WriteParam(aMsg, aParam.mEmbeddedCancelled.Value());
}
static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
{
bool isNull;
bool value;
bool rv =
ReadParam(aMsg, aIter,
static_cast<mozilla::WidgetKeyboardEvent*>(aResult)) &&
ReadParam(aMsg, aIter, &isNull) &&
ReadParam(aMsg, aIter, &value);
aResult->mEmbeddedCancelled = Nullable<bool>();
if (!isNull) {
aResult->mEmbeddedCancelled.SetValue(value);
}
return rv;
}
};
template<>
struct ParamTraits<mozilla::TextRangeStyle>
{