Bug 847585 - Paris binding for UIEvent, r=peterv

--HG--
extra : rebase_source : 01c588b769f9a3fa0ed435b67b0e07dff4dda179
This commit is contained in:
Olli Pettay 2013-03-13 22:02:32 +02:00
parent e48730f81b
commit b7e2a4443f
7 changed files with 183 additions and 21 deletions

View File

@ -343,6 +343,24 @@ nsDOMEvent::InitFromCtor(const nsAString& aType,
return InitEvent(aType, d.bubbles, d.cancelable);
}
bool
nsDOMEvent::Init(mozilla::dom::EventTarget* aGlobal)
{
bool trusted = false;
nsCOMPtr<nsPIDOMWindow> w = do_QueryInterface(aGlobal);
if (w) {
nsCOMPtr<nsIDocument> d = do_QueryInterface(w->GetExtantDocument());
if (d) {
trusted = nsContentUtils::IsChromeDoc(d);
nsIPresShell* s = d->GetShell();
if (s) {
InitPresContextData(s->GetPresContext());
}
}
}
return trusted;
}
//static
already_AddRefed<nsDOMEvent>
nsDOMEvent::Constructor(const mozilla::dom::GlobalObject& aGlobal,
@ -352,19 +370,7 @@ nsDOMEvent::Constructor(const mozilla::dom::GlobalObject& aGlobal,
{
nsCOMPtr<mozilla::dom::EventTarget> t = do_QueryInterface(aGlobal.Get());
nsRefPtr<nsDOMEvent> e = nsDOMEvent::CreateEvent(t, nullptr, nullptr);
bool trusted = false;
nsCOMPtr<nsPIDOMWindow> w = do_QueryInterface(t);
if (w) {
nsCOMPtr<nsIDocument> d = do_QueryInterface(w->GetExtantDocument());
if (d) {
trusted = nsContentUtils::IsChromeDoc(d);
nsIPresShell* s = d->GetShell();
if (s) {
e->InitPresContextData(s->GetPresContext());
}
}
}
bool trusted = e->Init(t);
aRv = e->InitEvent(aType, aParam.mBubbles, aParam.mCancelable);
e->SetTrusted(trusted);
return e.forget();

View File

@ -96,6 +96,9 @@ public:
void InitPresContextData(nsPresContext* aPresContext);
// Returns true if the event should be trusted.
bool Init(mozilla::dom::EventTarget* aGlobal);
static PopupControlState GetEventPopupControlState(nsEvent *aEvent);
static void PopupAllowedEventsChanged();

View File

@ -76,6 +76,23 @@ nsDOMUIEvent::nsDOMUIEvent(mozilla::dom::EventTarget* aOwner,
}
}
//static
already_AddRefed<nsDOMUIEvent>
nsDOMUIEvent::Constructor(const mozilla::dom::GlobalObject& aGlobal,
const nsAString& aType,
const mozilla::dom::UIEventInit& aParam,
mozilla::ErrorResult& aRv)
{
nsCOMPtr<mozilla::dom::EventTarget> t = do_QueryInterface(aGlobal.Get());
nsRefPtr<nsDOMUIEvent> e = new nsDOMUIEvent(t, nullptr, nullptr);
e->SetIsDOMBinding();
bool trusted = e->Init(t);
aRv = e->InitUIEvent(aType, aParam.mBubbles, aParam.mCancelable, aParam.mView,
aParam.mDetail);
e->SetTrusted(trusted);
return e.forget();
}
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(nsDOMUIEvent, nsDOMEvent)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mView)
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
@ -239,18 +256,15 @@ nsDOMUIEvent::GetWhich(uint32_t* aWhich)
return Which(aWhich);
}
NS_IMETHODIMP
nsDOMUIEvent::GetRangeParent(nsIDOMNode** aRangeParent)
already_AddRefed<nsINode>
nsDOMUIEvent::GetRangeParent()
{
NS_ENSURE_ARG_POINTER(aRangeParent);
nsIFrame* targetFrame = nullptr;
if (mPresContext) {
targetFrame = mPresContext->EventStateManager()->GetEventTarget();
}
*aRangeParent = nullptr;
if (targetFrame) {
nsPoint pt = nsLayoutUtils::GetEventCoordinatesRelativeTo(mEvent,
targetFrame);
@ -258,12 +272,24 @@ nsDOMUIEvent::GetRangeParent(nsIDOMNode** aRangeParent)
if (parent) {
if (parent->ChromeOnlyAccess() &&
!nsContentUtils::CanAccessNativeAnon()) {
return NS_OK;
return nullptr;
}
return CallQueryInterface(parent, aRangeParent);
return parent.forget().get();
}
}
return nullptr;
}
NS_IMETHODIMP
nsDOMUIEvent::GetRangeParent(nsIDOMNode** aRangeParent)
{
NS_ENSURE_ARG_POINTER(aRangeParent);
*aRangeParent = nullptr;
nsCOMPtr<nsINode> n = GetRangeParent();
if (n) {
CallQueryInterface(n, aRangeParent);
}
return NS_OK;
}
@ -291,7 +317,7 @@ NS_IMETHODIMP
nsDOMUIEvent::GetCancelBubble(bool* aCancelBubble)
{
NS_ENSURE_ARG_POINTER(aCancelBubble);
*aCancelBubble = mEvent->mFlags.mPropagationStopped;
*aCancelBubble = CancelBubble();
return NS_OK;
}
@ -511,5 +537,6 @@ nsresult NS_NewDOMUIEvent(nsIDOMEvent** aInstancePtrResult,
nsGUIEvent *aEvent)
{
nsDOMUIEvent* it = new nsDOMUIEvent(aOwner, aPresContext, aEvent);
it->SetIsDOMBinding();
return CallQueryInterface(it, aInstancePtrResult);
}

View File

@ -10,6 +10,7 @@
#include "nsDOMEvent.h"
#include "nsLayoutUtils.h"
#include "nsEvent.h"
#include "mozilla/dom/UIEventBinding.h"
class nsDOMUIEvent : public nsDOMEvent,
public nsIDOMUIEvent
@ -86,6 +87,79 @@ public:
nsPresContext::AppUnitsToIntCSSPixels(pt.y));
}
static already_AddRefed<nsDOMUIEvent> Constructor(const mozilla::dom::GlobalObject& aGlobal,
const nsAString& aType,
const mozilla::dom::UIEventInit& aParam,
mozilla::ErrorResult& aRv);
virtual JSObject* WrapObject(JSContext* aCx, JSObject* aScope)
{
return mozilla::dom::UIEventBinding::Wrap(aCx, aScope, this);
}
already_AddRefed<nsIDOMWindow> GetView()
{
nsCOMPtr<nsIDOMWindow> view = mView;
return mView.forget();
}
int32_t Detail()
{
return mDetail;
}
int32_t LayerX()
{
return GetLayerPoint().x;
}
int32_t LayerY()
{
return GetLayerPoint().y;
}
int32_t PageX()
{
int32_t x;
GetPageX(&x);
return x;
}
int32_t PageY()
{
int32_t y;
GetPageY(&y);
return y;
}
uint32_t Which()
{
uint32_t w;
GetWhich(&w);
return w;
}
already_AddRefed<nsINode> GetRangeParent();
int32_t RangeOffset()
{
int32_t offset;
GetRangeOffset(&offset);
return offset;
}
bool CancelBubble()
{
return mEvent->mFlags.mPropagationStopped;
}
bool IsChar()
{
bool isChar;
GetIsChar(&isChar);
return isChar;
}
protected:
// Internal helper functions
nsIntPoint GetClientPoint();

View File

@ -868,6 +868,10 @@ DOMInterfaces = {
'resultNotAddRefed': [ 'root', 'currentNode' ],
},
'UIEvent': {
'nativeType': 'nsDOMUIEvent',
},
'URL' : [{
'concrete': False,
},

47
dom/webidl/UIEvent.webidl Normal file
View File

@ -0,0 +1,47 @@
/* -*- Mode: IDL; 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/.
*
* For more information on this interface please see
* http://dev.w3.org/2006/webapi/DOM-Level-3-Events/html/DOM3-Events.html
*
* Copyright © 2012 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C
* liability, trademark and document use rules apply.
*/
interface WindowProxy;
[Constructor(DOMString type, optional UIEventInit eventInitDict)]
interface UIEvent : Event
{
readonly attribute WindowProxy? view;
readonly attribute long detail;
void initUIEvent(DOMString aType,
boolean aCanBubble,
boolean aCancelable,
WindowProxy? aView,
long aDetail);
};
// Additional DOM0 properties.
partial interface UIEvent {
const long SCROLL_PAGE_UP = -32768;
const long SCROLL_PAGE_DOWN = 32768;
readonly attribute long layerX;
readonly attribute long layerY;
readonly attribute long pageX;
readonly attribute long pageY;
readonly attribute unsigned long which;
readonly attribute Node? rangeParent;
readonly attribute long rangeOffset;
attribute boolean cancelBubble;
readonly attribute boolean isChar;
};
dictionary UIEventInit : EventInit
{
WindowProxy? view = null;
long detail = 0;
};

View File

@ -226,6 +226,7 @@ webidl_files = \
TextEncoder.webidl \
TimeRanges.webidl \
TreeWalker.webidl \
UIEvent.webidl \
URL.webidl \
ValidityState.webidl \
WebComponents.webidl \