mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-10 20:05:49 +00:00
Adding new method to nsIDOMNSUIEvent to give event pos as range offset.
This commit is contained in:
parent
aa061f9788
commit
7e2352ba3a
@ -338,6 +338,67 @@ NS_METHOD nsDOMEvent::GetWhich(PRUint32* aWhich)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_METHOD nsDOMEvent::GetRangeParent(nsIDOMNode** aRangeParent)
|
||||
{
|
||||
nsIFrame* targetFrame;
|
||||
nsIEventStateManager* manager;
|
||||
|
||||
if (NS_OK == mPresContext->GetEventStateManager(&manager)) {
|
||||
manager->GetEventTarget(&targetFrame);
|
||||
NS_RELEASE(manager);
|
||||
}
|
||||
|
||||
if (targetFrame) {
|
||||
nsIContent* parent = nsnull;
|
||||
PRUint32 actualOffset;
|
||||
PRInt32 offset, endOffset;
|
||||
|
||||
if (NS_SUCCEEDED(targetFrame->GetPosition(*mPresContext,
|
||||
(nsGUIEvent*)mEvent,
|
||||
targetFrame,
|
||||
&parent,
|
||||
actualOffset,
|
||||
offset,
|
||||
endOffset))) {
|
||||
if (parent && NS_SUCCEEDED(parent->QueryInterface(kIDOMNodeIID, (void**)aRangeParent))) {
|
||||
NS_RELEASE(parent);
|
||||
return NS_OK;
|
||||
}
|
||||
NS_IF_RELEASE(parent);
|
||||
}
|
||||
}
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_METHOD nsDOMEvent::GetRangeOffset(PRInt32* aRangeOffset)
|
||||
{
|
||||
nsIFrame* targetFrame;
|
||||
nsIEventStateManager* manager;
|
||||
|
||||
if (NS_OK == mPresContext->GetEventStateManager(&manager)) {
|
||||
manager->GetEventTarget(&targetFrame);
|
||||
NS_RELEASE(manager);
|
||||
}
|
||||
|
||||
if (targetFrame) {
|
||||
nsIContent* parent = nsnull;
|
||||
PRUint32 actualOffset;
|
||||
PRInt32 offset, endOffset;
|
||||
|
||||
if (NS_SUCCEEDED(targetFrame->GetPosition(*mPresContext,
|
||||
(nsGUIEvent*)mEvent,
|
||||
targetFrame,
|
||||
&parent,
|
||||
actualOffset,
|
||||
*aRangeOffset,
|
||||
endOffset))) {
|
||||
NS_IF_RELEASE(parent);
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_METHOD nsDOMEvent::DuplicatePrivateData()
|
||||
{
|
||||
//XXX Write me!
|
||||
|
@ -119,6 +119,10 @@ public:
|
||||
|
||||
NS_IMETHOD GetRc(nsIDOMRenderingContext** aRc);
|
||||
|
||||
NS_IMETHOD GetRangeParent(nsIDOMNode** aRangeParent);
|
||||
|
||||
NS_IMETHOD GetRangeOffset(PRInt32* aRangeOffset);
|
||||
|
||||
// nsIPrivateDOMEvent interface
|
||||
NS_IMETHOD DuplicatePrivateData();
|
||||
NS_IMETHOD SetTarget(nsIDOMNode* aNode);
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include "nsString.h"
|
||||
#include "nsIScriptContext.h"
|
||||
|
||||
class nsIDOMNode;
|
||||
class nsIDOMRenderingContext;
|
||||
|
||||
#define NS_IDOMNSUIEVENT_IID \
|
||||
@ -81,6 +82,10 @@ public:
|
||||
|
||||
NS_IMETHOD GetWhich(PRUint32* aWhich)=0;
|
||||
|
||||
NS_IMETHOD GetRangeParent(nsIDOMNode** aRangeParent)=0;
|
||||
|
||||
NS_IMETHOD GetRangeOffset(PRInt32* aRangeOffset)=0;
|
||||
|
||||
NS_IMETHOD GetRc(nsIDOMRenderingContext** aRc)=0;
|
||||
};
|
||||
|
||||
@ -91,6 +96,8 @@ public:
|
||||
NS_IMETHOD GetPageX(PRInt32* aPageX); \
|
||||
NS_IMETHOD GetPageY(PRInt32* aPageY); \
|
||||
NS_IMETHOD GetWhich(PRUint32* aWhich); \
|
||||
NS_IMETHOD GetRangeParent(nsIDOMNode** aRangeParent); \
|
||||
NS_IMETHOD GetRangeOffset(PRInt32* aRangeOffset); \
|
||||
NS_IMETHOD GetRc(nsIDOMRenderingContext** aRc); \
|
||||
|
||||
|
||||
@ -101,6 +108,8 @@ public:
|
||||
NS_IMETHOD GetPageX(PRInt32* aPageX) { return _to GetPageX(aPageX); } \
|
||||
NS_IMETHOD GetPageY(PRInt32* aPageY) { return _to GetPageY(aPageY); } \
|
||||
NS_IMETHOD GetWhich(PRUint32* aWhich) { return _to GetWhich(aWhich); } \
|
||||
NS_IMETHOD GetRangeParent(nsIDOMNode** aRangeParent) { return _to GetRangeParent(aRangeParent); } \
|
||||
NS_IMETHOD GetRangeOffset(PRInt32* aRangeOffset) { return _to GetRangeOffset(aRangeOffset); } \
|
||||
NS_IMETHOD GetRc(nsIDOMRenderingContext** aRc) { return _to GetRc(aRc); } \
|
||||
|
||||
|
||||
|
@ -189,6 +189,8 @@
|
||||
readonly attribute int pageX;
|
||||
readonly attribute int pageY;
|
||||
readonly attribute unsigned long which;
|
||||
readonly attribute Node rangeParent;
|
||||
readonly attribute int rangeOffset;
|
||||
|
||||
readonly attribute RenderingContext rc;
|
||||
};
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include "nsIPtr.h"
|
||||
#include "nsString.h"
|
||||
#include "nsIDOMNSUIEvent.h"
|
||||
#include "nsIDOMNode.h"
|
||||
#include "nsIDOMUIEvent.h"
|
||||
#include "nsIDOMRenderingContext.h"
|
||||
|
||||
@ -36,10 +37,12 @@ static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
|
||||
static NS_DEFINE_IID(kIJSScriptObjectIID, NS_IJSSCRIPTOBJECT_IID);
|
||||
static NS_DEFINE_IID(kIScriptGlobalObjectIID, NS_ISCRIPTGLOBALOBJECT_IID);
|
||||
static NS_DEFINE_IID(kINSUIEventIID, NS_IDOMNSUIEVENT_IID);
|
||||
static NS_DEFINE_IID(kINodeIID, NS_IDOMNODE_IID);
|
||||
static NS_DEFINE_IID(kIUIEventIID, NS_IDOMUIEVENT_IID);
|
||||
static NS_DEFINE_IID(kIRenderingContextIID, NS_IDOMRENDERINGCONTEXT_IID);
|
||||
|
||||
NS_DEF_PTR(nsIDOMNSUIEvent);
|
||||
NS_DEF_PTR(nsIDOMNode);
|
||||
NS_DEF_PTR(nsIDOMUIEvent);
|
||||
NS_DEF_PTR(nsIDOMRenderingContext);
|
||||
|
||||
@ -65,7 +68,9 @@ enum UIEvent_slots {
|
||||
NSUIEVENT_PAGEX = -16,
|
||||
NSUIEVENT_PAGEY = -17,
|
||||
NSUIEVENT_WHICH = -18,
|
||||
NSUIEVENT_RC = -19
|
||||
NSUIEVENT_RANGEPARENT = -19,
|
||||
NSUIEVENT_RANGEOFFSET = -20,
|
||||
NSUIEVENT_RC = -21
|
||||
};
|
||||
|
||||
/***********************************************************************/
|
||||
@ -423,6 +428,57 @@ GetUIEventProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
||||
}
|
||||
break;
|
||||
}
|
||||
case NSUIEVENT_RANGEPARENT:
|
||||
{
|
||||
secMan->CheckScriptAccess(scriptCX, obj, "nsuievent.rangeparent", &ok);
|
||||
if (!ok) {
|
||||
//Need to throw error here
|
||||
return JS_FALSE;
|
||||
}
|
||||
nsIDOMNode* prop;
|
||||
nsIDOMNSUIEvent* b;
|
||||
if (NS_OK == a->QueryInterface(kINSUIEventIID, (void **)&b)) {
|
||||
if(NS_OK == b->GetRangeParent(&prop)) {
|
||||
// get the js object
|
||||
nsJSUtils::nsConvertObjectToJSVal((nsISupports *)prop, cx, vp);
|
||||
NS_RELEASE(b);
|
||||
}
|
||||
else {
|
||||
NS_RELEASE(b);
|
||||
return JS_FALSE;
|
||||
}
|
||||
}
|
||||
else {
|
||||
JS_ReportError(cx, "Object must be of type NSUIEvent");
|
||||
return JS_FALSE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case NSUIEVENT_RANGEOFFSET:
|
||||
{
|
||||
secMan->CheckScriptAccess(scriptCX, obj, "nsuievent.rangeoffset", &ok);
|
||||
if (!ok) {
|
||||
//Need to throw error here
|
||||
return JS_FALSE;
|
||||
}
|
||||
PRInt32 prop;
|
||||
nsIDOMNSUIEvent* b;
|
||||
if (NS_OK == a->QueryInterface(kINSUIEventIID, (void **)&b)) {
|
||||
if(NS_OK == b->GetRangeOffset(&prop)) {
|
||||
*vp = INT_TO_JSVAL(prop);
|
||||
NS_RELEASE(b);
|
||||
}
|
||||
else {
|
||||
NS_RELEASE(b);
|
||||
return JS_FALSE;
|
||||
}
|
||||
}
|
||||
else {
|
||||
JS_ReportError(cx, "Object must be of type NSUIEvent");
|
||||
return JS_FALSE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case NSUIEVENT_RC:
|
||||
{
|
||||
secMan->CheckScriptAccess(scriptCX, obj, "nsuievent.rc", &ok);
|
||||
@ -583,6 +639,8 @@ static JSPropertySpec UIEventProperties[] =
|
||||
{"pageX", NSUIEVENT_PAGEX, JSPROP_ENUMERATE | JSPROP_READONLY},
|
||||
{"pageY", NSUIEVENT_PAGEY, JSPROP_ENUMERATE | JSPROP_READONLY},
|
||||
{"which", NSUIEVENT_WHICH, JSPROP_ENUMERATE | JSPROP_READONLY},
|
||||
{"rangeParent", NSUIEVENT_RANGEPARENT, JSPROP_ENUMERATE | JSPROP_READONLY},
|
||||
{"rangeOffset", NSUIEVENT_RANGEOFFSET, JSPROP_ENUMERATE | JSPROP_READONLY},
|
||||
{"rc", NSUIEVENT_RC, JSPROP_ENUMERATE | JSPROP_READONLY},
|
||||
{0}
|
||||
};
|
||||
|
@ -797,7 +797,7 @@ HTMLDocumentClose(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *
|
||||
nsIScriptSecurityManager *secMan;
|
||||
if (NS_OK == scriptCX->GetSecurityManager(&secMan)) {
|
||||
PRBool ok;
|
||||
secMan->CheckScriptAccess(scriptCX, obj, "htmldocument.open", &ok);
|
||||
secMan->CheckScriptAccess(scriptCX, obj, "htmldocument.close", &ok);
|
||||
if (!ok) {
|
||||
//Need to throw error here
|
||||
return JS_FALSE;
|
||||
@ -847,7 +847,7 @@ HTMLDocumentGetElementById(JSContext *cx, JSObject *obj, uintN argc, jsval *argv
|
||||
nsIScriptSecurityManager *secMan;
|
||||
if (NS_OK == scriptCX->GetSecurityManager(&secMan)) {
|
||||
PRBool ok;
|
||||
secMan->CheckScriptAccess(scriptCX, obj, "htmldocument.close", &ok);
|
||||
secMan->CheckScriptAccess(scriptCX, obj, "htmldocument.getelementbyid", &ok);
|
||||
if (!ok) {
|
||||
//Need to throw error here
|
||||
return JS_FALSE;
|
||||
@ -899,7 +899,7 @@ HTMLDocumentGetElementsByName(JSContext *cx, JSObject *obj, uintN argc, jsval *a
|
||||
nsIScriptSecurityManager *secMan;
|
||||
if (NS_OK == scriptCX->GetSecurityManager(&secMan)) {
|
||||
PRBool ok;
|
||||
secMan->CheckScriptAccess(scriptCX, obj, "htmldocument.write", &ok);
|
||||
secMan->CheckScriptAccess(scriptCX, obj, "htmldocument.getelementsbyname", &ok);
|
||||
if (!ok) {
|
||||
//Need to throw error here
|
||||
return JS_FALSE;
|
||||
@ -956,7 +956,7 @@ NSHTMLDocumentGetSelection(JSContext *cx, JSObject *obj, uintN argc, jsval *argv
|
||||
nsIScriptSecurityManager *secMan;
|
||||
if (NS_OK == scriptCX->GetSecurityManager(&secMan)) {
|
||||
PRBool ok;
|
||||
secMan->CheckScriptAccess(scriptCX, obj, "htmldocument.writeln", &ok);
|
||||
secMan->CheckScriptAccess(scriptCX, obj, "nshtmldocument.getselection", &ok);
|
||||
if (!ok) {
|
||||
//Need to throw error here
|
||||
return JS_FALSE;
|
||||
@ -1012,7 +1012,7 @@ NSHTMLDocumentNamedItem(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, j
|
||||
nsIScriptSecurityManager *secMan;
|
||||
if (NS_OK == scriptCX->GetSecurityManager(&secMan)) {
|
||||
PRBool ok;
|
||||
secMan->CheckScriptAccess(scriptCX, obj, "htmldocument.getelementbyid", &ok);
|
||||
secMan->CheckScriptAccess(scriptCX, obj, "nshtmldocument.nameditem", &ok);
|
||||
if (!ok) {
|
||||
//Need to throw error here
|
||||
return JS_FALSE;
|
||||
@ -1068,7 +1068,7 @@ NSHTMLDocumentOpen(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval
|
||||
nsIScriptSecurityManager *secMan;
|
||||
if (NS_OK == scriptCX->GetSecurityManager(&secMan)) {
|
||||
PRBool ok;
|
||||
secMan->CheckScriptAccess(scriptCX, obj, "htmldocument.getelementsbyname", &ok);
|
||||
secMan->CheckScriptAccess(scriptCX, obj, "nshtmldocument.open", &ok);
|
||||
if (!ok) {
|
||||
//Need to throw error here
|
||||
return JS_FALSE;
|
||||
@ -1122,7 +1122,7 @@ NSHTMLDocumentWrite(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval
|
||||
nsIScriptSecurityManager *secMan;
|
||||
if (NS_OK == scriptCX->GetSecurityManager(&secMan)) {
|
||||
PRBool ok;
|
||||
secMan->CheckScriptAccess(scriptCX, obj, "nshtmldocument.getselection", &ok);
|
||||
secMan->CheckScriptAccess(scriptCX, obj, "nshtmldocument.write", &ok);
|
||||
if (!ok) {
|
||||
//Need to throw error here
|
||||
return JS_FALSE;
|
||||
@ -1176,7 +1176,7 @@ NSHTMLDocumentWriteln(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsv
|
||||
nsIScriptSecurityManager *secMan;
|
||||
if (NS_OK == scriptCX->GetSecurityManager(&secMan)) {
|
||||
PRBool ok;
|
||||
secMan->CheckScriptAccess(scriptCX, obj, "nshtmldocument.nameditem", &ok);
|
||||
secMan->CheckScriptAccess(scriptCX, obj, "nshtmldocument.writeln", &ok);
|
||||
if (!ok) {
|
||||
//Need to throw error here
|
||||
return JS_FALSE;
|
||||
|
@ -417,7 +417,6 @@ public:
|
||||
nsEventStatus& aEventStatus) = 0;
|
||||
|
||||
NS_IMETHOD GetPosition(nsIPresContext& aPresContext,
|
||||
nsIRenderingContext * aRendContext,
|
||||
nsGUIEvent* aEvent,
|
||||
nsIFrame * aNewFrame,
|
||||
nsIContent ** aNewContent,
|
||||
|
@ -338,6 +338,67 @@ NS_METHOD nsDOMEvent::GetWhich(PRUint32* aWhich)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_METHOD nsDOMEvent::GetRangeParent(nsIDOMNode** aRangeParent)
|
||||
{
|
||||
nsIFrame* targetFrame;
|
||||
nsIEventStateManager* manager;
|
||||
|
||||
if (NS_OK == mPresContext->GetEventStateManager(&manager)) {
|
||||
manager->GetEventTarget(&targetFrame);
|
||||
NS_RELEASE(manager);
|
||||
}
|
||||
|
||||
if (targetFrame) {
|
||||
nsIContent* parent = nsnull;
|
||||
PRUint32 actualOffset;
|
||||
PRInt32 offset, endOffset;
|
||||
|
||||
if (NS_SUCCEEDED(targetFrame->GetPosition(*mPresContext,
|
||||
(nsGUIEvent*)mEvent,
|
||||
targetFrame,
|
||||
&parent,
|
||||
actualOffset,
|
||||
offset,
|
||||
endOffset))) {
|
||||
if (parent && NS_SUCCEEDED(parent->QueryInterface(kIDOMNodeIID, (void**)aRangeParent))) {
|
||||
NS_RELEASE(parent);
|
||||
return NS_OK;
|
||||
}
|
||||
NS_IF_RELEASE(parent);
|
||||
}
|
||||
}
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_METHOD nsDOMEvent::GetRangeOffset(PRInt32* aRangeOffset)
|
||||
{
|
||||
nsIFrame* targetFrame;
|
||||
nsIEventStateManager* manager;
|
||||
|
||||
if (NS_OK == mPresContext->GetEventStateManager(&manager)) {
|
||||
manager->GetEventTarget(&targetFrame);
|
||||
NS_RELEASE(manager);
|
||||
}
|
||||
|
||||
if (targetFrame) {
|
||||
nsIContent* parent = nsnull;
|
||||
PRUint32 actualOffset;
|
||||
PRInt32 offset, endOffset;
|
||||
|
||||
if (NS_SUCCEEDED(targetFrame->GetPosition(*mPresContext,
|
||||
(nsGUIEvent*)mEvent,
|
||||
targetFrame,
|
||||
&parent,
|
||||
actualOffset,
|
||||
*aRangeOffset,
|
||||
endOffset))) {
|
||||
NS_IF_RELEASE(parent);
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_METHOD nsDOMEvent::DuplicatePrivateData()
|
||||
{
|
||||
//XXX Write me!
|
||||
|
@ -119,6 +119,10 @@ public:
|
||||
|
||||
NS_IMETHOD GetRc(nsIDOMRenderingContext** aRc);
|
||||
|
||||
NS_IMETHOD GetRangeParent(nsIDOMNode** aRangeParent);
|
||||
|
||||
NS_IMETHOD GetRangeOffset(PRInt32* aRangeOffset);
|
||||
|
||||
// nsIPrivateDOMEvent interface
|
||||
NS_IMETHOD DuplicatePrivateData();
|
||||
NS_IMETHOD SetTarget(nsIDOMNode* aNode);
|
||||
|
@ -878,16 +878,13 @@ nsFrame::HandlePress(nsIPresContext& aPresContext,
|
||||
|
||||
nsCOMPtr<nsIPresShell> shell;
|
||||
nsresult rv = aPresContext.GetShell(getter_AddRefs(shell));
|
||||
nsInputEvent *inputEvent = (nsInputEvent *)aEvent;
|
||||
if (NS_SUCCEEDED(rv) && shell) {
|
||||
nsCOMPtr<nsIRenderingContext> acx;
|
||||
rv = shell->CreateRenderingContext(this, getter_AddRefs(acx));
|
||||
if (NS_SUCCEEDED(rv)){
|
||||
nsInputEvent *inputEvent = (nsInputEvent *)aEvent;
|
||||
PRInt32 startPos = 0;
|
||||
PRUint32 contentOffset = 0;
|
||||
PRInt32 contentOffsetEnd = 0;
|
||||
nsCOMPtr<nsIContent> newContent;
|
||||
if (NS_SUCCEEDED(GetPosition(aPresContext, acx, aEvent, this, getter_AddRefs(newContent),
|
||||
if (NS_SUCCEEDED(GetPosition(aPresContext, aEvent, this, getter_AddRefs(newContent),
|
||||
contentOffset, startPos, contentOffsetEnd))){
|
||||
nsCOMPtr<nsIDOMSelection> selection;
|
||||
if (NS_SUCCEEDED(shell->GetSelection(getter_AddRefs(selection)))){
|
||||
@ -903,7 +900,6 @@ nsFrame::HandlePress(nsIPresContext& aPresContext,
|
||||
//no release
|
||||
}
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
|
||||
}
|
||||
@ -930,14 +926,11 @@ NS_IMETHODIMP nsFrame::HandleDrag(nsIPresContext& aPresContext,
|
||||
nsCOMPtr<nsIPresShell> shell;
|
||||
nsresult rv = aPresContext.GetShell(getter_AddRefs(shell));
|
||||
if (NS_SUCCEEDED(rv) && shell) {
|
||||
nsCOMPtr<nsIRenderingContext> acx;
|
||||
rv = shell->CreateRenderingContext(this, getter_AddRefs(acx));
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
PRInt32 startPos = 0;
|
||||
PRUint32 contentOffset = 0;
|
||||
PRInt32 contentOffsetEnd = 0;
|
||||
nsCOMPtr<nsIContent> newContent;
|
||||
if (NS_SUCCEEDED(GetPosition(aPresContext, acx, aEvent, this, getter_AddRefs(newContent),
|
||||
if (NS_SUCCEEDED(GetPosition(aPresContext, aEvent, this, getter_AddRefs(newContent),
|
||||
contentOffset, startPos, contentOffsetEnd))){
|
||||
nsIDOMSelection *selection = nsnull;
|
||||
if (NS_SUCCEEDED(shell->GetSelection(&selection))){
|
||||
@ -953,7 +946,6 @@ NS_IMETHODIMP nsFrame::HandleDrag(nsIPresContext& aPresContext,
|
||||
//no release
|
||||
}
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@ -968,7 +960,6 @@ NS_IMETHODIMP nsFrame::HandleRelease(nsIPresContext& aPresContext,
|
||||
//-- GetPosition
|
||||
//--------------------------------------------------------------------------
|
||||
NS_IMETHODIMP nsFrame::GetPosition(nsIPresContext& aPresContext,
|
||||
nsIRenderingContext * aRendContext,
|
||||
nsGUIEvent * aEvent,
|
||||
nsIFrame * aNewFrame,
|
||||
nsIContent ** aNewContent,
|
||||
|
@ -257,7 +257,6 @@ public:
|
||||
nsEventStatus& aEventStatus);
|
||||
|
||||
NS_IMETHOD GetPosition(nsIPresContext& aPresContext,
|
||||
nsIRenderingContext * aRendContext,
|
||||
nsGUIEvent* aEvent,
|
||||
nsIFrame * aNewFrame,
|
||||
nsIContent ** aNewContent,
|
||||
|
@ -417,7 +417,6 @@ public:
|
||||
nsEventStatus& aEventStatus) = 0;
|
||||
|
||||
NS_IMETHOD GetPosition(nsIPresContext& aPresContext,
|
||||
nsIRenderingContext * aRendContext,
|
||||
nsGUIEvent* aEvent,
|
||||
nsIFrame * aNewFrame,
|
||||
nsIContent ** aNewContent,
|
||||
|
@ -223,7 +223,6 @@ public:
|
||||
NS_IMETHOD GetFrameName(nsString& aResult) const;
|
||||
|
||||
NS_IMETHOD GetPosition(nsIPresContext& aCX,
|
||||
nsIRenderingContext * aRendContext,
|
||||
nsGUIEvent* aEvent,
|
||||
nsIFrame * aNewFrame,
|
||||
nsIContent ** aNewContent,
|
||||
@ -1700,7 +1699,6 @@ BinarySearchForPosition(nsIRenderingContext* acx,
|
||||
//---------------------------------------------------------------------------
|
||||
NS_IMETHODIMP
|
||||
nsTextFrame::GetPosition(nsIPresContext& aPresContext,
|
||||
nsIRenderingContext* aRendContext,
|
||||
nsGUIEvent* aEvent,
|
||||
nsIFrame* aNewFrame,
|
||||
nsIContent **aNewContent,
|
||||
@ -1708,10 +1706,16 @@ nsTextFrame::GetPosition(nsIPresContext& aPresContext,
|
||||
PRInt32& aOffset,
|
||||
PRInt32& aOffsetEnd)
|
||||
{
|
||||
TextStyle ts(&aPresContext, *aRendContext, mStyleContext);
|
||||
nsCOMPtr<nsIPresShell> shell;
|
||||
nsresult rv = aPresContext.GetShell(getter_AddRefs(shell));
|
||||
if (NS_SUCCEEDED(rv) && shell) {
|
||||
nsCOMPtr<nsIRenderingContext> acx;
|
||||
rv = shell->CreateRenderingContext(this, getter_AddRefs(acx));
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
TextStyle ts(&aPresContext, *acx, mStyleContext);
|
||||
if (ts.mSmallCaps || ts.mWordSpacing || ts.mLetterSpacing) {
|
||||
|
||||
nsresult result = GetPositionSlowly(aPresContext, aRendContext, aEvent, aNewContent,
|
||||
nsresult result = GetPositionSlowly(aPresContext, acx, aEvent, aNewContent,
|
||||
aActualContentOffset, aOffset);
|
||||
aOffsetEnd = aOffset;
|
||||
return result;
|
||||
@ -1736,7 +1740,7 @@ nsTextFrame::GetPosition(nsIPresContext& aPresContext,
|
||||
NS_RELEASE(styleContext);
|
||||
nsCOMPtr<nsIFontMetrics> fm;
|
||||
aPresContext.GetMetricsFor(font->mFont, getter_AddRefs(fm));
|
||||
aRendContext->SetFont(fm);
|
||||
acx->SetFont(fm);
|
||||
|
||||
// Get the document
|
||||
nsCOMPtr<nsIDocument> doc(getter_AddRefs(GetDocument(&aPresContext)));
|
||||
@ -1761,20 +1765,20 @@ nsTextFrame::GetPosition(nsIPresContext& aPresContext,
|
||||
nsIView * view;
|
||||
GetView(&view);
|
||||
GetOffsetFromView(origin, &view);
|
||||
PRBool found = BinarySearchForPosition(aRendContext, text, origin.x, 0, 0,
|
||||
PRBool found = BinarySearchForPosition(acx, text, origin.x, 0, 0,
|
||||
PRInt32(textLength),
|
||||
PRInt32(aEvent->point.x) , //go to local coordinates
|
||||
index, textWidth);
|
||||
if (found) {
|
||||
PRInt32 charWidth;
|
||||
aRendContext->GetWidth(text[index], charWidth);
|
||||
acx->GetWidth(text[index], charWidth);
|
||||
charWidth /= 2;
|
||||
|
||||
if (PRInt32(aEvent->point.x) - origin.x > textWidth+charWidth) {
|
||||
index++;
|
||||
}
|
||||
|
||||
/* offset = 0;
|
||||
/*offset = 0;
|
||||
PRInt32 j;
|
||||
PRInt32* ptr = ip;
|
||||
for (j=0;j<=PRInt32(mContentLength);j++) {
|
||||
@ -1806,8 +1810,11 @@ nsTextFrame::GetPosition(nsIPresContext& aPresContext,
|
||||
}
|
||||
NS_ASSERTION(i<= mContentLength, "offset we got from binary search is messed up");
|
||||
*aNewContent = mContent;
|
||||
if (*aNewContent)
|
||||
if (*aNewContent) {
|
||||
(*aNewContent)->AddRef();
|
||||
}
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@ -2256,7 +2263,7 @@ nsTextFrame::HandleMultiplePress(nsIPresContext& aPresContext,
|
||||
PRUint32 contentOffset = 0;
|
||||
PRInt32 contentOffsetEnd = 0;
|
||||
nsCOMPtr<nsIContent> newContent;
|
||||
if (NS_SUCCEEDED(GetPosition(aPresContext, acx, aEvent, this,
|
||||
if (NS_SUCCEEDED(GetPosition(aPresContext, aEvent, this,
|
||||
getter_AddRefs(newContent), contentOffset, startPos, contentOffsetEnd))){
|
||||
//find which word needs to be selected! use peek offset one way then the other
|
||||
nsCOMPtr<nsIContent> startContent;
|
||||
|
@ -878,16 +878,13 @@ nsFrame::HandlePress(nsIPresContext& aPresContext,
|
||||
|
||||
nsCOMPtr<nsIPresShell> shell;
|
||||
nsresult rv = aPresContext.GetShell(getter_AddRefs(shell));
|
||||
nsInputEvent *inputEvent = (nsInputEvent *)aEvent;
|
||||
if (NS_SUCCEEDED(rv) && shell) {
|
||||
nsCOMPtr<nsIRenderingContext> acx;
|
||||
rv = shell->CreateRenderingContext(this, getter_AddRefs(acx));
|
||||
if (NS_SUCCEEDED(rv)){
|
||||
nsInputEvent *inputEvent = (nsInputEvent *)aEvent;
|
||||
PRInt32 startPos = 0;
|
||||
PRUint32 contentOffset = 0;
|
||||
PRInt32 contentOffsetEnd = 0;
|
||||
nsCOMPtr<nsIContent> newContent;
|
||||
if (NS_SUCCEEDED(GetPosition(aPresContext, acx, aEvent, this, getter_AddRefs(newContent),
|
||||
if (NS_SUCCEEDED(GetPosition(aPresContext, aEvent, this, getter_AddRefs(newContent),
|
||||
contentOffset, startPos, contentOffsetEnd))){
|
||||
nsCOMPtr<nsIDOMSelection> selection;
|
||||
if (NS_SUCCEEDED(shell->GetSelection(getter_AddRefs(selection)))){
|
||||
@ -903,7 +900,6 @@ nsFrame::HandlePress(nsIPresContext& aPresContext,
|
||||
//no release
|
||||
}
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
|
||||
}
|
||||
@ -930,14 +926,11 @@ NS_IMETHODIMP nsFrame::HandleDrag(nsIPresContext& aPresContext,
|
||||
nsCOMPtr<nsIPresShell> shell;
|
||||
nsresult rv = aPresContext.GetShell(getter_AddRefs(shell));
|
||||
if (NS_SUCCEEDED(rv) && shell) {
|
||||
nsCOMPtr<nsIRenderingContext> acx;
|
||||
rv = shell->CreateRenderingContext(this, getter_AddRefs(acx));
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
PRInt32 startPos = 0;
|
||||
PRUint32 contentOffset = 0;
|
||||
PRInt32 contentOffsetEnd = 0;
|
||||
nsCOMPtr<nsIContent> newContent;
|
||||
if (NS_SUCCEEDED(GetPosition(aPresContext, acx, aEvent, this, getter_AddRefs(newContent),
|
||||
if (NS_SUCCEEDED(GetPosition(aPresContext, aEvent, this, getter_AddRefs(newContent),
|
||||
contentOffset, startPos, contentOffsetEnd))){
|
||||
nsIDOMSelection *selection = nsnull;
|
||||
if (NS_SUCCEEDED(shell->GetSelection(&selection))){
|
||||
@ -953,7 +946,6 @@ NS_IMETHODIMP nsFrame::HandleDrag(nsIPresContext& aPresContext,
|
||||
//no release
|
||||
}
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@ -968,7 +960,6 @@ NS_IMETHODIMP nsFrame::HandleRelease(nsIPresContext& aPresContext,
|
||||
//-- GetPosition
|
||||
//--------------------------------------------------------------------------
|
||||
NS_IMETHODIMP nsFrame::GetPosition(nsIPresContext& aPresContext,
|
||||
nsIRenderingContext * aRendContext,
|
||||
nsGUIEvent * aEvent,
|
||||
nsIFrame * aNewFrame,
|
||||
nsIContent ** aNewContent,
|
||||
|
@ -257,7 +257,6 @@ public:
|
||||
nsEventStatus& aEventStatus);
|
||||
|
||||
NS_IMETHOD GetPosition(nsIPresContext& aPresContext,
|
||||
nsIRenderingContext * aRendContext,
|
||||
nsGUIEvent* aEvent,
|
||||
nsIFrame * aNewFrame,
|
||||
nsIContent ** aNewContent,
|
||||
|
@ -223,7 +223,6 @@ public:
|
||||
NS_IMETHOD GetFrameName(nsString& aResult) const;
|
||||
|
||||
NS_IMETHOD GetPosition(nsIPresContext& aCX,
|
||||
nsIRenderingContext * aRendContext,
|
||||
nsGUIEvent* aEvent,
|
||||
nsIFrame * aNewFrame,
|
||||
nsIContent ** aNewContent,
|
||||
@ -1700,7 +1699,6 @@ BinarySearchForPosition(nsIRenderingContext* acx,
|
||||
//---------------------------------------------------------------------------
|
||||
NS_IMETHODIMP
|
||||
nsTextFrame::GetPosition(nsIPresContext& aPresContext,
|
||||
nsIRenderingContext* aRendContext,
|
||||
nsGUIEvent* aEvent,
|
||||
nsIFrame* aNewFrame,
|
||||
nsIContent **aNewContent,
|
||||
@ -1708,10 +1706,16 @@ nsTextFrame::GetPosition(nsIPresContext& aPresContext,
|
||||
PRInt32& aOffset,
|
||||
PRInt32& aOffsetEnd)
|
||||
{
|
||||
TextStyle ts(&aPresContext, *aRendContext, mStyleContext);
|
||||
nsCOMPtr<nsIPresShell> shell;
|
||||
nsresult rv = aPresContext.GetShell(getter_AddRefs(shell));
|
||||
if (NS_SUCCEEDED(rv) && shell) {
|
||||
nsCOMPtr<nsIRenderingContext> acx;
|
||||
rv = shell->CreateRenderingContext(this, getter_AddRefs(acx));
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
TextStyle ts(&aPresContext, *acx, mStyleContext);
|
||||
if (ts.mSmallCaps || ts.mWordSpacing || ts.mLetterSpacing) {
|
||||
|
||||
nsresult result = GetPositionSlowly(aPresContext, aRendContext, aEvent, aNewContent,
|
||||
nsresult result = GetPositionSlowly(aPresContext, acx, aEvent, aNewContent,
|
||||
aActualContentOffset, aOffset);
|
||||
aOffsetEnd = aOffset;
|
||||
return result;
|
||||
@ -1736,7 +1740,7 @@ nsTextFrame::GetPosition(nsIPresContext& aPresContext,
|
||||
NS_RELEASE(styleContext);
|
||||
nsCOMPtr<nsIFontMetrics> fm;
|
||||
aPresContext.GetMetricsFor(font->mFont, getter_AddRefs(fm));
|
||||
aRendContext->SetFont(fm);
|
||||
acx->SetFont(fm);
|
||||
|
||||
// Get the document
|
||||
nsCOMPtr<nsIDocument> doc(getter_AddRefs(GetDocument(&aPresContext)));
|
||||
@ -1761,20 +1765,20 @@ nsTextFrame::GetPosition(nsIPresContext& aPresContext,
|
||||
nsIView * view;
|
||||
GetView(&view);
|
||||
GetOffsetFromView(origin, &view);
|
||||
PRBool found = BinarySearchForPosition(aRendContext, text, origin.x, 0, 0,
|
||||
PRBool found = BinarySearchForPosition(acx, text, origin.x, 0, 0,
|
||||
PRInt32(textLength),
|
||||
PRInt32(aEvent->point.x) , //go to local coordinates
|
||||
index, textWidth);
|
||||
if (found) {
|
||||
PRInt32 charWidth;
|
||||
aRendContext->GetWidth(text[index], charWidth);
|
||||
acx->GetWidth(text[index], charWidth);
|
||||
charWidth /= 2;
|
||||
|
||||
if (PRInt32(aEvent->point.x) - origin.x > textWidth+charWidth) {
|
||||
index++;
|
||||
}
|
||||
|
||||
/* offset = 0;
|
||||
/*offset = 0;
|
||||
PRInt32 j;
|
||||
PRInt32* ptr = ip;
|
||||
for (j=0;j<=PRInt32(mContentLength);j++) {
|
||||
@ -1806,8 +1810,11 @@ nsTextFrame::GetPosition(nsIPresContext& aPresContext,
|
||||
}
|
||||
NS_ASSERTION(i<= mContentLength, "offset we got from binary search is messed up");
|
||||
*aNewContent = mContent;
|
||||
if (*aNewContent)
|
||||
if (*aNewContent) {
|
||||
(*aNewContent)->AddRef();
|
||||
}
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@ -2256,7 +2263,7 @@ nsTextFrame::HandleMultiplePress(nsIPresContext& aPresContext,
|
||||
PRUint32 contentOffset = 0;
|
||||
PRInt32 contentOffsetEnd = 0;
|
||||
nsCOMPtr<nsIContent> newContent;
|
||||
if (NS_SUCCEEDED(GetPosition(aPresContext, acx, aEvent, this,
|
||||
if (NS_SUCCEEDED(GetPosition(aPresContext, aEvent, this,
|
||||
getter_AddRefs(newContent), contentOffset, startPos, contentOffsetEnd))){
|
||||
//find which word needs to be selected! use peek offset one way then the other
|
||||
nsCOMPtr<nsIContent> startContent;
|
||||
|
Loading…
Reference in New Issue
Block a user