Adding new method to nsIDOMNSUIEvent to give event pos as range offset.

This commit is contained in:
joki%netscape.com 1999-06-08 02:19:26 +00:00
parent aa061f9788
commit 7e2352ba3a
16 changed files with 483 additions and 292 deletions

View File

@ -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!

View File

@ -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);

View File

@ -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); } \

View File

@ -177,18 +177,20 @@
const int EVENT_FORWARD = 0x08000000;
const int EVENT_HELP = 0x10000000;
const int EVENT_BACK = 0x20000000;
const int EVENT_TEXT = 0x40000000;
const int EVENT_TEXT = 0x40000000;
const int EVENT_ALT_MASK = 0x00000001;
const int EVENT_CONTROL_MASK = 0x00000002;
const int EVENT_SHIFT_MASK = 0x00000004;
const int EVENT_META_MASK = 0x00000008;
readonly attribute int layerX;
readonly attribute int layerY;
readonly attribute int pageX;
readonly attribute int pageY;
readonly attribute int layerX;
readonly attribute int layerY;
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;
};

View File

@ -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}
};

View File

@ -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;

View File

@ -417,7 +417,6 @@ public:
nsEventStatus& aEventStatus) = 0;
NS_IMETHOD GetPosition(nsIPresContext& aPresContext,
nsIRenderingContext * aRendContext,
nsGUIEvent* aEvent,
nsIFrame * aNewFrame,
nsIContent ** aNewContent,

View File

@ -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!

View File

@ -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);

View File

@ -878,30 +878,26 @@ 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)){
PRInt32 startPos = 0;
PRUint32 contentOffset = 0;
PRInt32 contentOffsetEnd = 0;
nsCOMPtr<nsIContent> newContent;
if (NS_SUCCEEDED(GetPosition(aPresContext, acx, aEvent, this, getter_AddRefs(newContent),
contentOffset, startPos, contentOffsetEnd))){
nsCOMPtr<nsIDOMSelection> selection;
if (NS_SUCCEEDED(shell->GetSelection(getter_AddRefs(selection)))){
nsCOMPtr<nsIFrameSelection> frameselection;
frameselection = do_QueryInterface(selection);
if (frameselection) {
if (NS_SUCCEEDED( rv )){
frameselection->SetMouseDownState(PR_TRUE);//not important if it fails here
frameselection->TakeFocus(newContent, startPos + contentOffset, contentOffsetEnd + contentOffset, inputEvent->isShift);
}
nsInputEvent *inputEvent = (nsInputEvent *)aEvent;
PRInt32 startPos = 0;
PRUint32 contentOffset = 0;
PRInt32 contentOffsetEnd = 0;
nsCOMPtr<nsIContent> 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)))){
nsCOMPtr<nsIFrameSelection> frameselection;
frameselection = do_QueryInterface(selection);
if (frameselection) {
if (NS_SUCCEEDED( rv )){
frameselection->SetMouseDownState(PR_TRUE);//not important if it fails here
frameselection->TakeFocus(newContent, startPos + contentOffset, contentOffsetEnd + contentOffset, inputEvent->isShift);
}
}
//no release
}
//no release
}
}
return NS_OK;
@ -930,28 +926,24 @@ 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),
contentOffset, startPos, contentOffsetEnd))){
nsIDOMSelection *selection = nsnull;
if (NS_SUCCEEDED(shell->GetSelection(&selection))){
nsIFrameSelection* frameselection;
if (NS_SUCCEEDED(selection->QueryInterface(kIFrameSelection, (void **)&frameselection))) {
if (NS_SUCCEEDED( rv )){
frameselection->TakeFocus(newContent, startPos + contentOffset, contentOffsetEnd + contentOffset, PR_TRUE); //TRUE IS THE DIFFERENCE
}
NS_RELEASE(frameselection);
PRInt32 startPos = 0;
PRUint32 contentOffset = 0;
PRInt32 contentOffsetEnd = 0;
nsCOMPtr<nsIContent> newContent;
if (NS_SUCCEEDED(GetPosition(aPresContext, aEvent, this, getter_AddRefs(newContent),
contentOffset, startPos, contentOffsetEnd))){
nsIDOMSelection *selection = nsnull;
if (NS_SUCCEEDED(shell->GetSelection(&selection))){
nsIFrameSelection* frameselection;
if (NS_SUCCEEDED(selection->QueryInterface(kIFrameSelection, (void **)&frameselection))) {
if (NS_SUCCEEDED( rv )){
frameselection->TakeFocus(newContent, startPos + contentOffset, contentOffsetEnd + contentOffset, PR_TRUE); //TRUE IS THE DIFFERENCE
}
NS_RELEASE(selection);
NS_RELEASE(frameselection);
}
//no release
NS_RELEASE(selection);
}
//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,

View File

@ -257,7 +257,6 @@ public:
nsEventStatus& aEventStatus);
NS_IMETHOD GetPosition(nsIPresContext& aPresContext,
nsIRenderingContext * aRendContext,
nsGUIEvent* aEvent,
nsIFrame * aNewFrame,
nsIContent ** aNewContent,

View File

@ -417,7 +417,6 @@ public:
nsEventStatus& aEventStatus) = 0;
NS_IMETHOD GetPosition(nsIPresContext& aPresContext,
nsIRenderingContext * aRendContext,
nsGUIEvent* aEvent,
nsIFrame * aNewFrame,
nsIContent ** aNewContent,

View File

@ -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,106 +1706,115 @@ nsTextFrame::GetPosition(nsIPresContext& aPresContext,
PRInt32& aOffset,
PRInt32& aOffsetEnd)
{
TextStyle ts(&aPresContext, *aRendContext, mStyleContext);
if (ts.mSmallCaps || ts.mWordSpacing || ts.mLetterSpacing) {
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,
aActualContentOffset, aOffset);
aOffsetEnd = aOffset;
return result;
}
PRUnichar wordBufMem[WORD_BUF_SIZE];
PRUnichar paintBufMem[TEXT_BUF_SIZE];
PRInt32 indicies[TEXT_BUF_SIZE];
PRInt32* ip = indicies;
PRUnichar* paintBuf = paintBufMem;
if (mContentLength >= TEXT_BUF_SIZE) {
ip = new PRInt32[mContentLength+1];
paintBuf = new PRUnichar[mContentLength];
}
PRInt32 textLength;
// Find the font metrics for this text
nsIStyleContext* styleContext;
aNewFrame->GetStyleContext(&styleContext);
const nsStyleFont *font = (const nsStyleFont*)
styleContext->GetStyleData(eStyleStruct_Font);
NS_RELEASE(styleContext);
nsCOMPtr<nsIFontMetrics> fm;
aPresContext.GetMetricsFor(font->mFont, getter_AddRefs(fm));
aRendContext->SetFont(fm);
// Get the document
nsCOMPtr<nsIDocument> doc(getter_AddRefs(GetDocument(&aPresContext)));
// Get the renderable form of the text
nsCOMPtr<nsILineBreaker> lb;
doc->GetLineBreaker(getter_AddRefs(lb));
nsCOMPtr<nsIWordBreaker> wb;
doc->GetWordBreaker(getter_AddRefs(wb));
nsTextTransformer tx(wordBufMem, WORD_BUF_SIZE,lb,wb);
PrepareUnicodeText(tx, ip, paintBuf, &textLength);
ip[mContentLength] = ip[mContentLength-1];
if ((ip[mContentLength]-mContentOffset) < textLength) {
//must set up last one for selection beyond edge if in boundary
ip[mContentLength]++;
}
PRInt32 index;
PRInt32 textWidth = 0;
PRUnichar* text = paintBuf;
nsPoint origin;
nsIView * view;
GetView(&view);
GetOffsetFromView(origin, &view);
PRBool found = BinarySearchForPosition(aRendContext, 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);
charWidth /= 2;
if (PRInt32(aEvent->point.x) - origin.x > textWidth+charWidth) {
index++;
}
/* offset = 0;
PRInt32 j;
PRInt32* ptr = ip;
for (j=0;j<=PRInt32(mContentLength);j++) {
if (*ptr == index+mContentOffset) {
offset = j;//+mContentOffset;
break;
nsresult result = GetPositionSlowly(aPresContext, acx, aEvent, aNewContent,
aActualContentOffset, aOffset);
aOffsetEnd = aOffset;
return result;
}
ptr++;
} */
}
if (ip != indicies) {
delete [] ip;
}
if (paintBuf != paintBufMem) {
delete [] paintBuf;
}
PRUnichar wordBufMem[WORD_BUF_SIZE];
PRUnichar paintBufMem[TEXT_BUF_SIZE];
PRInt32 indicies[TEXT_BUF_SIZE];
PRInt32* ip = indicies;
PRUnichar* paintBuf = paintBufMem;
if (mContentLength >= TEXT_BUF_SIZE) {
ip = new PRInt32[mContentLength+1];
paintBuf = new PRUnichar[mContentLength];
}
PRInt32 textLength;
aActualContentOffset = mContentOffset;//offset;//((nsTextFrame *)aNewFrame)->mContentOffset;
aOffset = index;
aOffsetEnd = aOffset;
//reusing wordBufMem
PRInt32 i;
for (i = 0;i <= mContentLength; i ++){
if (ip[i] == aOffset + mContentOffset){ //reverse mapping
aOffset = i;
break;
// Find the font metrics for this text
nsIStyleContext* styleContext;
aNewFrame->GetStyleContext(&styleContext);
const nsStyleFont *font = (const nsStyleFont*)
styleContext->GetStyleData(eStyleStruct_Font);
NS_RELEASE(styleContext);
nsCOMPtr<nsIFontMetrics> fm;
aPresContext.GetMetricsFor(font->mFont, getter_AddRefs(fm));
acx->SetFont(fm);
// Get the document
nsCOMPtr<nsIDocument> doc(getter_AddRefs(GetDocument(&aPresContext)));
// Get the renderable form of the text
nsCOMPtr<nsILineBreaker> lb;
doc->GetLineBreaker(getter_AddRefs(lb));
nsCOMPtr<nsIWordBreaker> wb;
doc->GetWordBreaker(getter_AddRefs(wb));
nsTextTransformer tx(wordBufMem, WORD_BUF_SIZE,lb,wb);
PrepareUnicodeText(tx, ip, paintBuf, &textLength);
ip[mContentLength] = ip[mContentLength-1];
if ((ip[mContentLength]-mContentOffset) < textLength) {
//must set up last one for selection beyond edge if in boundary
ip[mContentLength]++;
}
PRInt32 index;
PRInt32 textWidth = 0;
PRUnichar* text = paintBuf;
nsPoint origin;
nsIView * view;
GetView(&view);
GetOffsetFromView(origin, &view);
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;
acx->GetWidth(text[index], charWidth);
charWidth /= 2;
if (PRInt32(aEvent->point.x) - origin.x > textWidth+charWidth) {
index++;
}
/*offset = 0;
PRInt32 j;
PRInt32* ptr = ip;
for (j=0;j<=PRInt32(mContentLength);j++) {
if (*ptr == index+mContentOffset) {
offset = j;//+mContentOffset;
break;
}
ptr++;
} */
}
if (ip != indicies) {
delete [] ip;
}
if (paintBuf != paintBufMem) {
delete [] paintBuf;
}
aActualContentOffset = mContentOffset;//offset;//((nsTextFrame *)aNewFrame)->mContentOffset;
aOffset = index;
aOffsetEnd = aOffset;
//reusing wordBufMem
PRInt32 i;
for (i = 0;i <= mContentLength; i ++){
if (ip[i] == aOffset + mContentOffset){ //reverse mapping
aOffset = i;
break;
}
}
NS_ASSERTION(i<= mContentLength, "offset we got from binary search is messed up");
*aNewContent = mContent;
if (*aNewContent) {
(*aNewContent)->AddRef();
}
}
}
NS_ASSERTION(i<= mContentLength, "offset we got from binary search is messed up");
*aNewContent = mContent;
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;

View File

@ -878,30 +878,26 @@ 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)){
PRInt32 startPos = 0;
PRUint32 contentOffset = 0;
PRInt32 contentOffsetEnd = 0;
nsCOMPtr<nsIContent> newContent;
if (NS_SUCCEEDED(GetPosition(aPresContext, acx, aEvent, this, getter_AddRefs(newContent),
contentOffset, startPos, contentOffsetEnd))){
nsCOMPtr<nsIDOMSelection> selection;
if (NS_SUCCEEDED(shell->GetSelection(getter_AddRefs(selection)))){
nsCOMPtr<nsIFrameSelection> frameselection;
frameselection = do_QueryInterface(selection);
if (frameselection) {
if (NS_SUCCEEDED( rv )){
frameselection->SetMouseDownState(PR_TRUE);//not important if it fails here
frameselection->TakeFocus(newContent, startPos + contentOffset, contentOffsetEnd + contentOffset, inputEvent->isShift);
}
nsInputEvent *inputEvent = (nsInputEvent *)aEvent;
PRInt32 startPos = 0;
PRUint32 contentOffset = 0;
PRInt32 contentOffsetEnd = 0;
nsCOMPtr<nsIContent> 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)))){
nsCOMPtr<nsIFrameSelection> frameselection;
frameselection = do_QueryInterface(selection);
if (frameselection) {
if (NS_SUCCEEDED( rv )){
frameselection->SetMouseDownState(PR_TRUE);//not important if it fails here
frameselection->TakeFocus(newContent, startPos + contentOffset, contentOffsetEnd + contentOffset, inputEvent->isShift);
}
}
//no release
}
//no release
}
}
return NS_OK;
@ -930,28 +926,24 @@ 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),
contentOffset, startPos, contentOffsetEnd))){
nsIDOMSelection *selection = nsnull;
if (NS_SUCCEEDED(shell->GetSelection(&selection))){
nsIFrameSelection* frameselection;
if (NS_SUCCEEDED(selection->QueryInterface(kIFrameSelection, (void **)&frameselection))) {
if (NS_SUCCEEDED( rv )){
frameselection->TakeFocus(newContent, startPos + contentOffset, contentOffsetEnd + contentOffset, PR_TRUE); //TRUE IS THE DIFFERENCE
}
NS_RELEASE(frameselection);
PRInt32 startPos = 0;
PRUint32 contentOffset = 0;
PRInt32 contentOffsetEnd = 0;
nsCOMPtr<nsIContent> newContent;
if (NS_SUCCEEDED(GetPosition(aPresContext, aEvent, this, getter_AddRefs(newContent),
contentOffset, startPos, contentOffsetEnd))){
nsIDOMSelection *selection = nsnull;
if (NS_SUCCEEDED(shell->GetSelection(&selection))){
nsIFrameSelection* frameselection;
if (NS_SUCCEEDED(selection->QueryInterface(kIFrameSelection, (void **)&frameselection))) {
if (NS_SUCCEEDED( rv )){
frameselection->TakeFocus(newContent, startPos + contentOffset, contentOffsetEnd + contentOffset, PR_TRUE); //TRUE IS THE DIFFERENCE
}
NS_RELEASE(selection);
NS_RELEASE(frameselection);
}
//no release
NS_RELEASE(selection);
}
//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,

View File

@ -257,7 +257,6 @@ public:
nsEventStatus& aEventStatus);
NS_IMETHOD GetPosition(nsIPresContext& aPresContext,
nsIRenderingContext * aRendContext,
nsGUIEvent* aEvent,
nsIFrame * aNewFrame,
nsIContent ** aNewContent,

View File

@ -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,106 +1706,115 @@ nsTextFrame::GetPosition(nsIPresContext& aPresContext,
PRInt32& aOffset,
PRInt32& aOffsetEnd)
{
TextStyle ts(&aPresContext, *aRendContext, mStyleContext);
if (ts.mSmallCaps || ts.mWordSpacing || ts.mLetterSpacing) {
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,
aActualContentOffset, aOffset);
aOffsetEnd = aOffset;
return result;
}
PRUnichar wordBufMem[WORD_BUF_SIZE];
PRUnichar paintBufMem[TEXT_BUF_SIZE];
PRInt32 indicies[TEXT_BUF_SIZE];
PRInt32* ip = indicies;
PRUnichar* paintBuf = paintBufMem;
if (mContentLength >= TEXT_BUF_SIZE) {
ip = new PRInt32[mContentLength+1];
paintBuf = new PRUnichar[mContentLength];
}
PRInt32 textLength;
// Find the font metrics for this text
nsIStyleContext* styleContext;
aNewFrame->GetStyleContext(&styleContext);
const nsStyleFont *font = (const nsStyleFont*)
styleContext->GetStyleData(eStyleStruct_Font);
NS_RELEASE(styleContext);
nsCOMPtr<nsIFontMetrics> fm;
aPresContext.GetMetricsFor(font->mFont, getter_AddRefs(fm));
aRendContext->SetFont(fm);
// Get the document
nsCOMPtr<nsIDocument> doc(getter_AddRefs(GetDocument(&aPresContext)));
// Get the renderable form of the text
nsCOMPtr<nsILineBreaker> lb;
doc->GetLineBreaker(getter_AddRefs(lb));
nsCOMPtr<nsIWordBreaker> wb;
doc->GetWordBreaker(getter_AddRefs(wb));
nsTextTransformer tx(wordBufMem, WORD_BUF_SIZE,lb,wb);
PrepareUnicodeText(tx, ip, paintBuf, &textLength);
ip[mContentLength] = ip[mContentLength-1];
if ((ip[mContentLength]-mContentOffset) < textLength) {
//must set up last one for selection beyond edge if in boundary
ip[mContentLength]++;
}
PRInt32 index;
PRInt32 textWidth = 0;
PRUnichar* text = paintBuf;
nsPoint origin;
nsIView * view;
GetView(&view);
GetOffsetFromView(origin, &view);
PRBool found = BinarySearchForPosition(aRendContext, 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);
charWidth /= 2;
if (PRInt32(aEvent->point.x) - origin.x > textWidth+charWidth) {
index++;
}
/* offset = 0;
PRInt32 j;
PRInt32* ptr = ip;
for (j=0;j<=PRInt32(mContentLength);j++) {
if (*ptr == index+mContentOffset) {
offset = j;//+mContentOffset;
break;
nsresult result = GetPositionSlowly(aPresContext, acx, aEvent, aNewContent,
aActualContentOffset, aOffset);
aOffsetEnd = aOffset;
return result;
}
ptr++;
} */
}
if (ip != indicies) {
delete [] ip;
}
if (paintBuf != paintBufMem) {
delete [] paintBuf;
}
PRUnichar wordBufMem[WORD_BUF_SIZE];
PRUnichar paintBufMem[TEXT_BUF_SIZE];
PRInt32 indicies[TEXT_BUF_SIZE];
PRInt32* ip = indicies;
PRUnichar* paintBuf = paintBufMem;
if (mContentLength >= TEXT_BUF_SIZE) {
ip = new PRInt32[mContentLength+1];
paintBuf = new PRUnichar[mContentLength];
}
PRInt32 textLength;
aActualContentOffset = mContentOffset;//offset;//((nsTextFrame *)aNewFrame)->mContentOffset;
aOffset = index;
aOffsetEnd = aOffset;
//reusing wordBufMem
PRInt32 i;
for (i = 0;i <= mContentLength; i ++){
if (ip[i] == aOffset + mContentOffset){ //reverse mapping
aOffset = i;
break;
// Find the font metrics for this text
nsIStyleContext* styleContext;
aNewFrame->GetStyleContext(&styleContext);
const nsStyleFont *font = (const nsStyleFont*)
styleContext->GetStyleData(eStyleStruct_Font);
NS_RELEASE(styleContext);
nsCOMPtr<nsIFontMetrics> fm;
aPresContext.GetMetricsFor(font->mFont, getter_AddRefs(fm));
acx->SetFont(fm);
// Get the document
nsCOMPtr<nsIDocument> doc(getter_AddRefs(GetDocument(&aPresContext)));
// Get the renderable form of the text
nsCOMPtr<nsILineBreaker> lb;
doc->GetLineBreaker(getter_AddRefs(lb));
nsCOMPtr<nsIWordBreaker> wb;
doc->GetWordBreaker(getter_AddRefs(wb));
nsTextTransformer tx(wordBufMem, WORD_BUF_SIZE,lb,wb);
PrepareUnicodeText(tx, ip, paintBuf, &textLength);
ip[mContentLength] = ip[mContentLength-1];
if ((ip[mContentLength]-mContentOffset) < textLength) {
//must set up last one for selection beyond edge if in boundary
ip[mContentLength]++;
}
PRInt32 index;
PRInt32 textWidth = 0;
PRUnichar* text = paintBuf;
nsPoint origin;
nsIView * view;
GetView(&view);
GetOffsetFromView(origin, &view);
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;
acx->GetWidth(text[index], charWidth);
charWidth /= 2;
if (PRInt32(aEvent->point.x) - origin.x > textWidth+charWidth) {
index++;
}
/*offset = 0;
PRInt32 j;
PRInt32* ptr = ip;
for (j=0;j<=PRInt32(mContentLength);j++) {
if (*ptr == index+mContentOffset) {
offset = j;//+mContentOffset;
break;
}
ptr++;
} */
}
if (ip != indicies) {
delete [] ip;
}
if (paintBuf != paintBufMem) {
delete [] paintBuf;
}
aActualContentOffset = mContentOffset;//offset;//((nsTextFrame *)aNewFrame)->mContentOffset;
aOffset = index;
aOffsetEnd = aOffset;
//reusing wordBufMem
PRInt32 i;
for (i = 0;i <= mContentLength; i ++){
if (ip[i] == aOffset + mContentOffset){ //reverse mapping
aOffset = i;
break;
}
}
NS_ASSERTION(i<= mContentLength, "offset we got from binary search is messed up");
*aNewContent = mContent;
if (*aNewContent) {
(*aNewContent)->AddRef();
}
}
}
NS_ASSERTION(i<= mContentLength, "offset we got from binary search is messed up");
*aNewContent = mContent;
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;