Bug 912956 part.7 Create mozilla/ContentEvents.h r=roc

This commit is contained in:
Masayuki Nakano 2013-09-24 19:04:15 +09:00
parent 4d620ef251
commit 22c5f0a4eb
5 changed files with 296 additions and 227 deletions

View File

@ -47,25 +47,23 @@ enum nsEventStructType
NS_SIMPLE_GESTURE_EVENT, // WidgetSimpleGestureEvent
NS_TOUCH_EVENT, // WidgetTouchEvent
// Scroll related events
NS_SCROLLPORT_EVENT, // nsScrollPortEvent
NS_SCROLLAREA_EVENT, // nsScrollAreaEvent
// ContentEvents.h
NS_SCRIPT_ERROR_EVENT, // InternalScriptErrorEvent
NS_SCROLLPORT_EVENT, // InternalScrollPortEvent
NS_SCROLLAREA_EVENT, // InternalScrollAreaEvent
NS_FORM_EVENT, // InternalFormEvent
NS_FOCUS_EVENT, // InternalFocusEvent
NS_CLIPBOARD_EVENT, // InternalClipboardEvent
NS_TRANSITION_EVENT, // InternalTransitionEvent
NS_ANIMATION_EVENT, // InternalAnimationEvent
// DOM events
NS_SCRIPT_ERROR_EVENT, // nsScriptErrorEvent
NS_MUTATION_EVENT, // nsMutationEvent
NS_FORM_EVENT, // nsFormEvent
NS_FOCUS_EVENT, // nsFocusEvent
NS_CLIPBOARD_EVENT, // nsClipboardEvent
// SVG events
NS_SVGZOOM_EVENT, // GUIEvent
NS_SMIL_TIME_EVENT, // UIEvent
// CSS events
NS_TRANSITION_EVENT, // nsTransitionEvent
NS_ANIMATION_EVENT, // nsAnimationEvent
// Command events
NS_COMMAND_EVENT, // nsCommandEvent
NS_CONTENT_COMMAND_EVENT, // nsContentCommandEvent
@ -874,6 +872,14 @@ public:
class InternalUIEvent : public WidgetGUIEvent
{
protected:
InternalUIEvent(bool aIsTrusted, uint32_t aMessage,
nsEventStructType aStructType, int32_t aDetail) :
WidgetGUIEvent(aIsTrusted, aMessage, nullptr, aStructType),
detail(aDetail)
{
}
public:
InternalUIEvent(bool aIsTrusted, uint32_t aMessage, int32_t aDetail) :
WidgetGUIEvent(aIsTrusted, aMessage, nullptr, NS_UI_EVENT),

260
widget/ContentEvents.h Normal file
View File

@ -0,0 +1,260 @@
/* -*- 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_ContentEvents_h__
#define mozilla_ContentEvents_h__
#include <stdint.h>
#include "mozilla/BasicEvents.h"
#include "mozilla/dom/EventTarget.h"
#include "nsCOMPtr.h"
#include "nsIDOMDataTransfer.h"
#include "nsRect.h"
#include "nsStringGlue.h"
class nsIContent;
namespace mozilla {
/******************************************************************************
* mozilla::InternalScriptErrorEvent
******************************************************************************/
class InternalScriptErrorEvent : public WidgetEvent
{
public:
InternalScriptErrorEvent(bool aIsTrusted, uint32_t aMessage) :
WidgetEvent(aIsTrusted, aMessage, NS_SCRIPT_ERROR_EVENT),
lineNr(0), errorMsg(nullptr), fileName(nullptr)
{
}
int32_t lineNr;
const PRUnichar* errorMsg;
const PRUnichar* fileName;
// XXX Not tested by test_assign_event_data.html
void AssignScriptErrorEventData(const InternalScriptErrorEvent& aEvent,
bool aCopyTargets)
{
AssignEventData(aEvent, aCopyTargets);
lineNr = aEvent.lineNr;
// We don't copy errorMsg and fileName. If it's necessary, perhaps, this
// should duplicate the characters and free them at destructing.
errorMsg = nullptr;
fileName = nullptr;
}
};
/******************************************************************************
* mozilla::InternalScrollPortEvent
******************************************************************************/
class InternalScrollPortEvent : public WidgetGUIEvent
{
public:
enum orientType
{
vertical = 0,
horizontal = 1,
both = 2
};
InternalScrollPortEvent(bool aIsTrusted, uint32_t aMessage,
nsIWidget* aWidget) :
WidgetGUIEvent(aIsTrusted, aMessage, aWidget, NS_SCROLLPORT_EVENT),
orient(vertical)
{
}
orientType orient;
void AssignScrollPortEventData(const InternalScrollPortEvent& aEvent,
bool aCopyTargets)
{
AssignGUIEventData(aEvent, aCopyTargets);
orient = aEvent.orient;
}
};
/******************************************************************************
* mozilla::InternalScrollPortEvent
******************************************************************************/
class InternalScrollAreaEvent : public WidgetGUIEvent
{
public:
InternalScrollAreaEvent(bool aIsTrusted, uint32_t aMessage,
nsIWidget* aWidget) :
WidgetGUIEvent(aIsTrusted, aMessage, aWidget, NS_SCROLLAREA_EVENT)
{
}
nsRect mArea;
void AssignScrollAreaEventData(const InternalScrollAreaEvent& aEvent,
bool aCopyTargets)
{
AssignGUIEventData(aEvent, aCopyTargets);
mArea = aEvent.mArea;
}
};
/******************************************************************************
* mozilla::InternalFormEvent
*
* We hold the originating form control for form submit and reset events.
* originator is a weak pointer (does not hold a strong reference).
******************************************************************************/
class InternalFormEvent : public WidgetEvent
{
public:
InternalFormEvent(bool aIsTrusted, uint32_t aMessage) :
WidgetEvent(aIsTrusted, aMessage, NS_FORM_EVENT),
originator(nullptr)
{
}
nsIContent *originator;
void AssignFormEventData(const InternalFormEvent& aEvent, bool aCopyTargets)
{
AssignEventData(aEvent, aCopyTargets);
// Don't copy originator due to a weak pointer.
}
};
/******************************************************************************
* mozilla::InternalClipboardEvent
******************************************************************************/
class InternalClipboardEvent : public WidgetEvent
{
public:
InternalClipboardEvent(bool aIsTrusted, uint32_t aMessage) :
WidgetEvent(aIsTrusted, aMessage, NS_CLIPBOARD_EVENT)
{
}
nsCOMPtr<nsIDOMDataTransfer> clipboardData;
void AssignClipboardEventData(const InternalClipboardEvent& aEvent,
bool aCopyTargets)
{
AssignEventData(aEvent, aCopyTargets);
clipboardData = aEvent.clipboardData;
}
};
/******************************************************************************
* mozilla::InternalFocusEvent
******************************************************************************/
class InternalFocusEvent : public InternalUIEvent
{
public:
InternalFocusEvent(bool aIsTrusted, uint32_t aMessage) :
InternalUIEvent(aIsTrusted, aMessage, NS_FOCUS_EVENT, 0),
fromRaise(false), isRefocus(false)
{
}
/// The possible related target
nsCOMPtr<dom::EventTarget> relatedTarget;
bool fromRaise;
bool isRefocus;
void AssignFocusEventData(const InternalFocusEvent& aEvent, bool aCopyTargets)
{
AssignUIEventData(aEvent, aCopyTargets);
relatedTarget = aCopyTargets ? aEvent.relatedTarget : nullptr;
fromRaise = aEvent.fromRaise;
isRefocus = aEvent.isRefocus;
}
};
/******************************************************************************
* mozilla::InternalTransitionEvent
******************************************************************************/
class InternalTransitionEvent : public WidgetEvent
{
public:
InternalTransitionEvent(bool aIsTrusted, uint32_t aMessage,
const nsAString& aPropertyName, float aElapsedTime,
const nsAString& aPseudoElement) :
nsEvent(aIsTrusted, aMessage, NS_TRANSITION_EVENT),
propertyName(aPropertyName), elapsedTime(aElapsedTime),
pseudoElement(aPseudoElement)
{
}
nsString propertyName;
float elapsedTime;
nsString pseudoElement;
void AssignTransitionEventData(const InternalTransitionEvent& aEvent,
bool aCopyTargets)
{
AssignEventData(aEvent, aCopyTargets);
// propertyName, elapsedTime and pseudoElement must have been initialized
// with the constructor.
}
};
/******************************************************************************
* mozilla::InternalAnimationEvent
******************************************************************************/
class InternalAnimationEvent : public WidgetEvent
{
public:
InternalAnimationEvent(bool aIsTrusted, uint32_t aMessage,
const nsAString& aAnimationName, float aElapsedTime,
const nsAString& aPseudoElement) :
WidgetEvent(aIsTrusted, aMessage, NS_ANIMATION_EVENT),
animationName(aAnimationName), elapsedTime(aElapsedTime),
pseudoElement(aPseudoElement)
{
}
nsString animationName;
float elapsedTime;
nsString pseudoElement;
void AssignAnimationEventData(const InternalAnimationEvent& aEvent,
bool aCopyTargets)
{
AssignEventData(aEvent, aCopyTargets);
// animationName, elapsedTime and pseudoElement must have been initialized
// with the constructor.
}
};
} // namespace mozilla
// TODO: Remove following typedefs
typedef mozilla::InternalScriptErrorEvent nsScriptErrorEvent;
typedef mozilla::InternalScrollPortEvent nsScrollPortEvent;
typedef mozilla::InternalScrollAreaEvent nsScrollAreaEvent;
typedef mozilla::InternalFormEvent nsFormEvent;
typedef mozilla::InternalClipboardEvent nsClipboardEvent;
typedef mozilla::InternalFocusEvent nsFocusEvent;
typedef mozilla::InternalTransitionEvent nsTransitionEvent;
typedef mozilla::InternalAnimationEvent nsAnimationEvent;
#endif // mozilla_ContentEvents_h__

View File

@ -82,17 +82,17 @@ class WidgetWheelEvent;
class WidgetGestureNotifyEvent;
class WidgetSimpleGestureEvent;
class WidgetTouchEvent;
} // namespace mozilla
// ContentEvents.h
class nsScriptErrorEvent;
class nsScrollPortEvent;
class nsScrollAreaEvent;
class nsFormEvent;
class nsClipboardEvent;
class nsFocusEvent;
class nsTransitionEvent;
class nsAnimationEvent;
class InternalScriptErrorEvent;
class InternalScrollPortEvent;
class InternalScrollAreaEvent;
class InternalFormEvent;
class InternalClipboardEvent;
class InternalFocusEvent;
class InternalTransitionEvent;
class InternalAnimationEvent;
} // namespace mozilla
// MiscEvents.h
class nsCommandEvent;
@ -128,5 +128,13 @@ typedef WidgetWheelEvent WheelEvent;
typedef mozilla::WidgetGestureNotifyEvent nsGestureNotifyEvent;
typedef mozilla::WidgetSimpleGestureEvent nsSimpleGestureEvent;
typedef mozilla::WidgetTouchEvent nsTouchEvent;
typedef mozilla::InternalScriptErrorEvent nsScriptErrorEvent;
typedef mozilla::InternalScrollPortEvent nsScrollPortEvent;
typedef mozilla::InternalScrollAreaEvent nsScrollAreaEvent;
typedef mozilla::InternalFormEvent nsFormEvent;
typedef mozilla::InternalClipboardEvent nsClipboardEvent;
typedef mozilla::InternalFocusEvent nsFocusEvent;
typedef mozilla::InternalTransitionEvent nsTransitionEvent;
typedef mozilla::InternalAnimationEvent nsAnimationEvent;
#endif // mozilla_EventForwards_h__

View File

@ -112,6 +112,7 @@ EXPORTS += [
EXPORTS.mozilla += [
'BasicEvents.h',
'ContentEvents.h',
'EventForwards.h',
'LookAndFeel.h',
'MouseEvents.h',

View File

@ -7,98 +7,19 @@
#define nsGUIEvent_h__
#include "mozilla/BasicEvents.h"
#include "mozilla/ContentEvents.h"
#include "mozilla/MouseEvents.h"
#include "mozilla/TextEvents.h"
#include "mozilla/TouchEvents.h"
#include "nsPoint.h"
#include "nsRect.h"
#include "nsIDOMDataTransfer.h"
#include "nsWeakPtr.h"
#include "nsITransferable.h"
class nsIContent;
#define NS_EVENT_TYPE_NULL 0
#define NS_EVENT_TYPE_ALL 1 // Not a real event type
/**
* Script error event
*/
class nsScriptErrorEvent : public nsEvent
{
public:
nsScriptErrorEvent(bool isTrusted, uint32_t msg)
: nsEvent(isTrusted, msg, NS_SCRIPT_ERROR_EVENT),
lineNr(0), errorMsg(nullptr), fileName(nullptr)
{
}
int32_t lineNr;
const PRUnichar* errorMsg;
const PRUnichar* fileName;
// XXX Not tested by test_assign_event_data.html
void AssignScriptErrorEventData(const nsScriptErrorEvent& aEvent,
bool aCopyTargets)
{
AssignEventData(aEvent, aCopyTargets);
lineNr = aEvent.lineNr;
// We don't copy errorMsg and fileName. If it's necessary, perhaps, this
// should duplicate the characters and free them at destructing.
errorMsg = nullptr;
fileName = nullptr;
}
};
class nsScrollPortEvent : public nsGUIEvent
{
public:
enum orientType {
vertical = 0,
horizontal = 1,
both = 2
};
nsScrollPortEvent(bool isTrusted, uint32_t msg, nsIWidget *w)
: nsGUIEvent(isTrusted, msg, w, NS_SCROLLPORT_EVENT),
orient(vertical)
{
}
orientType orient;
void AssignScrollPortEventData(const nsScrollPortEvent& aEvent,
bool aCopyTargets)
{
AssignGUIEventData(aEvent, aCopyTargets);
orient = aEvent.orient;
}
};
class nsScrollAreaEvent : public nsGUIEvent
{
public:
nsScrollAreaEvent(bool isTrusted, uint32_t msg, nsIWidget *w)
: nsGUIEvent(isTrusted, msg, w, NS_SCROLLAREA_EVENT)
{
}
nsRect mArea;
void AssignScrollAreaEventData(const nsScrollAreaEvent& aEvent,
bool aCopyTargets)
{
AssignGUIEventData(aEvent, aCopyTargets);
mArea = aEvent.mArea;
}
};
class nsContentCommandEvent : public nsGUIEvent
{
public:
@ -138,32 +59,6 @@ public:
bool mIsEnabled; // [out]
};
/**
* Form event
*
* We hold the originating form control for form submit and reset events.
* originator is a weak pointer (does not hold a strong reference).
*/
class nsFormEvent : public nsEvent
{
public:
nsFormEvent(bool isTrusted, uint32_t msg)
: nsEvent(isTrusted, msg, NS_FORM_EVENT),
originator(nullptr)
{
}
nsIContent *originator;
void AssignFormEventData(const nsFormEvent& aEvent, bool aCopyTargets)
{
AssignEventData(aEvent, aCopyTargets);
// Don't copy originator due to a weak pointer.
}
};
/**
* Command event
*
@ -192,107 +87,6 @@ public:
}
};
/**
* Clipboard event
*/
class nsClipboardEvent : public nsEvent
{
public:
nsClipboardEvent(bool isTrusted, uint32_t msg)
: nsEvent(isTrusted, msg, NS_CLIPBOARD_EVENT)
{
}
nsCOMPtr<nsIDOMDataTransfer> clipboardData;
void AssignClipboardEventData(const nsClipboardEvent& aEvent,
bool aCopyTargets)
{
AssignEventData(aEvent, aCopyTargets);
clipboardData = aEvent.clipboardData;
}
};
class nsFocusEvent : public nsUIEvent
{
public:
nsFocusEvent(bool isTrusted, uint32_t msg)
: nsUIEvent(isTrusted, msg, 0),
fromRaise(false),
isRefocus(false)
{
eventStructType = NS_FOCUS_EVENT;
}
/// The possible related target
nsCOMPtr<mozilla::dom::EventTarget> relatedTarget;
bool fromRaise;
bool isRefocus;
void AssignFocusEventData(const nsFocusEvent& aEvent, bool aCopyTargets)
{
AssignUIEventData(aEvent, aCopyTargets);
relatedTarget = aCopyTargets ? aEvent.relatedTarget : nullptr;
fromRaise = aEvent.fromRaise;
isRefocus = aEvent.isRefocus;
}
};
class nsTransitionEvent : public nsEvent
{
public:
nsTransitionEvent(bool isTrusted, uint32_t msg,
const nsAString& propertyNameArg, float elapsedTimeArg,
const nsAString& pseudoElementArg)
: nsEvent(isTrusted, msg, NS_TRANSITION_EVENT),
propertyName(propertyNameArg), elapsedTime(elapsedTimeArg),
pseudoElement(pseudoElementArg)
{
}
nsString propertyName;
float elapsedTime;
nsString pseudoElement;
void AssignTransitionEventData(const nsTransitionEvent& aEvent,
bool aCopyTargets)
{
AssignEventData(aEvent, aCopyTargets);
// propertyName, elapsedTime and pseudoElement must have been initialized
// with the constructor.
}
};
class nsAnimationEvent : public nsEvent
{
public:
nsAnimationEvent(bool isTrusted, uint32_t msg,
const nsAString &animationNameArg, float elapsedTimeArg,
const nsAString &pseudoElementArg)
: nsEvent(isTrusted, msg, NS_ANIMATION_EVENT),
animationName(animationNameArg), elapsedTime(elapsedTimeArg),
pseudoElement(pseudoElementArg)
{
}
nsString animationName;
float elapsedTime;
nsString pseudoElement;
void AssignAnimationEventData(const nsAnimationEvent& aEvent,
bool aCopyTargets)
{
AssignEventData(aEvent, aCopyTargets);
// animationName, elapsedTime and pseudoElement must have been initialized
// with the constructor.
}
};
/**
* Native event pluginEvent for plugins.
*/