added Selection methods to nsICodment, nsDocument, nsiSplittableFRame
This commit is contained in:
Родитель
48b1d62af3
Коммит
1205850979
|
@ -154,6 +154,16 @@ public:
|
|||
* Returns the Selection Object
|
||||
*/
|
||||
virtual nsISelection * GetSelection() = 0;
|
||||
|
||||
/**
|
||||
* Selects all the Content
|
||||
*/
|
||||
virtual void SelectAll() = 0;
|
||||
|
||||
/**
|
||||
* Copies all text from the selection
|
||||
*/
|
||||
virtual void GetSelectionText(nsString & aText) = 0;
|
||||
};
|
||||
|
||||
// XXX Belongs somewhere else
|
||||
|
|
|
@ -26,6 +26,8 @@
|
|||
#include "nsIDocumentObserver.h"
|
||||
|
||||
#include "nsSelection.h"
|
||||
#include "nsIDOMText.h"
|
||||
static NS_DEFINE_IID(kIDOMTextIID, NS_IDOMTEXT_IID);
|
||||
|
||||
static NS_DEFINE_IID(kIDocumentIID, NS_IDOCUMENT_IID);
|
||||
|
||||
|
@ -638,8 +640,103 @@ nsresult nsDocument::GetElementsByTagName(nsString &aTagname, nsIDOMNodeIterator
|
|||
* Returns the Selection Object
|
||||
*/
|
||||
nsISelection * nsDocument::GetSelection() {
|
||||
if (mSelection != nsnull) {
|
||||
NS_ADDREF(mSelection);
|
||||
}
|
||||
return mSelection;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Selects all the Content
|
||||
*/
|
||||
void nsDocument::SelectAll() {
|
||||
nsIContent * start = mRootContent;
|
||||
nsIContent * end = mRootContent;
|
||||
|
||||
// Find Very first Piece of Content
|
||||
while (start->ChildCount() > 0) {
|
||||
start = start->ChildAt(0);
|
||||
}
|
||||
|
||||
// Last piece of Content
|
||||
PRInt32 count = end->ChildCount();
|
||||
while (count > 0) {
|
||||
end = end->ChildAt(count-1);
|
||||
count = end->ChildCount();
|
||||
}
|
||||
nsSelectionRange * range = mSelection->GetRange();
|
||||
nsSelectionPoint * startPnt = range->GetStartPoint();
|
||||
nsSelectionPoint * endPnt = range->GetEndPoint();
|
||||
startPnt->SetPoint(start, -1, PR_TRUE);
|
||||
endPnt->SetPoint(end, -1, PR_FALSE);
|
||||
|
||||
}
|
||||
|
||||
void nsDocument::TraverseTree(nsString & aText,
|
||||
nsIContent * aContent,
|
||||
nsIContent * aStart,
|
||||
nsIContent * aEnd,
|
||||
PRBool & aInRange) {
|
||||
|
||||
if (aContent == aStart) {
|
||||
aInRange = PR_TRUE;
|
||||
}
|
||||
|
||||
PRBool addReturn = PR_FALSE;
|
||||
if (aInRange) {
|
||||
nsIDOMText * textContent;
|
||||
nsresult status = aContent->QueryInterface(kIDOMTextIID, (void**) &textContent);
|
||||
if (NS_OK == status) {
|
||||
nsString text;
|
||||
textContent->GetData(text);
|
||||
aText.Append(text);
|
||||
//NS_IF_RELEASE(textContent);
|
||||
} else {
|
||||
nsIAtom * atom = aContent->GetTag();
|
||||
if (atom != nsnull) {
|
||||
nsString str;
|
||||
atom->ToString(str);
|
||||
//char * s = str.ToNewCString();
|
||||
if (str.Equals("P") ||
|
||||
str.Equals("OL") ||
|
||||
str.Equals("LI") ||
|
||||
str.Equals("TD") ||
|
||||
str.Equals("H1") ||
|
||||
str.Equals("H2") ||
|
||||
str.Equals("H3") ||
|
||||
str.Equals("H4") ||
|
||||
str.Equals("H5") ||
|
||||
str.Equals("H6") ||
|
||||
str.Equals("TABLE")) {
|
||||
addReturn = PR_TRUE;
|
||||
}
|
||||
//printf("[%s]\n", s);
|
||||
//delete s;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (PRInt32 i=0;i<aContent->ChildCount();i++) {
|
||||
TraverseTree(aText, aContent->ChildAt(i), aStart, aEnd, aInRange);
|
||||
}
|
||||
if (addReturn) {
|
||||
aText.Append("\n");
|
||||
}
|
||||
if (aContent == aEnd) {
|
||||
aInRange = PR_FALSE;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void nsDocument::GetSelectionText(nsString & aText) {
|
||||
nsSelectionRange * range = mSelection->GetRange();
|
||||
nsSelectionPoint * startPnt = range->GetStartPoint();
|
||||
nsSelectionPoint * endPnt = range->GetEndPoint();
|
||||
|
||||
PRBool inRange = PR_FALSE;
|
||||
TraverseTree(aText, mRootContent, startPnt->GetContent(), endPnt->GetContent(), inRange);
|
||||
}
|
||||
|
||||
|
||||
NS_LAYOUT nsresult
|
||||
NS_NewSelection(nsISelection** aInstancePtrResult)
|
||||
|
|
|
@ -133,6 +133,23 @@ public:
|
|||
*/
|
||||
virtual nsISelection * GetSelection();
|
||||
|
||||
/**
|
||||
* Selects all the Content
|
||||
*/
|
||||
virtual void SelectAll();
|
||||
|
||||
/**
|
||||
* Copies all text from the selection
|
||||
*/
|
||||
virtual void GetSelectionText(nsString & aText);
|
||||
|
||||
void TraverseTree(nsString & aText,
|
||||
nsIContent * aContent,
|
||||
nsIContent * aStart,
|
||||
nsIContent * aEnd,
|
||||
PRBool & aInRange);
|
||||
|
||||
|
||||
public:
|
||||
|
||||
virtual nsresult GetScriptObject(JSContext *aContext, void** aScriptObject);
|
||||
|
|
|
@ -154,6 +154,16 @@ public:
|
|||
* Returns the Selection Object
|
||||
*/
|
||||
virtual nsISelection * GetSelection() = 0;
|
||||
|
||||
/**
|
||||
* Selects all the Content
|
||||
*/
|
||||
virtual void SelectAll() = 0;
|
||||
|
||||
/**
|
||||
* Copies all text from the selection
|
||||
*/
|
||||
virtual void GetSelectionText(nsString & aText) = 0;
|
||||
};
|
||||
|
||||
// XXX Belongs somewhere else
|
||||
|
|
|
@ -26,6 +26,8 @@
|
|||
#include "nsIDocumentObserver.h"
|
||||
|
||||
#include "nsSelection.h"
|
||||
#include "nsIDOMText.h"
|
||||
static NS_DEFINE_IID(kIDOMTextIID, NS_IDOMTEXT_IID);
|
||||
|
||||
static NS_DEFINE_IID(kIDocumentIID, NS_IDOCUMENT_IID);
|
||||
|
||||
|
@ -638,8 +640,103 @@ nsresult nsDocument::GetElementsByTagName(nsString &aTagname, nsIDOMNodeIterator
|
|||
* Returns the Selection Object
|
||||
*/
|
||||
nsISelection * nsDocument::GetSelection() {
|
||||
if (mSelection != nsnull) {
|
||||
NS_ADDREF(mSelection);
|
||||
}
|
||||
return mSelection;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Selects all the Content
|
||||
*/
|
||||
void nsDocument::SelectAll() {
|
||||
nsIContent * start = mRootContent;
|
||||
nsIContent * end = mRootContent;
|
||||
|
||||
// Find Very first Piece of Content
|
||||
while (start->ChildCount() > 0) {
|
||||
start = start->ChildAt(0);
|
||||
}
|
||||
|
||||
// Last piece of Content
|
||||
PRInt32 count = end->ChildCount();
|
||||
while (count > 0) {
|
||||
end = end->ChildAt(count-1);
|
||||
count = end->ChildCount();
|
||||
}
|
||||
nsSelectionRange * range = mSelection->GetRange();
|
||||
nsSelectionPoint * startPnt = range->GetStartPoint();
|
||||
nsSelectionPoint * endPnt = range->GetEndPoint();
|
||||
startPnt->SetPoint(start, -1, PR_TRUE);
|
||||
endPnt->SetPoint(end, -1, PR_FALSE);
|
||||
|
||||
}
|
||||
|
||||
void nsDocument::TraverseTree(nsString & aText,
|
||||
nsIContent * aContent,
|
||||
nsIContent * aStart,
|
||||
nsIContent * aEnd,
|
||||
PRBool & aInRange) {
|
||||
|
||||
if (aContent == aStart) {
|
||||
aInRange = PR_TRUE;
|
||||
}
|
||||
|
||||
PRBool addReturn = PR_FALSE;
|
||||
if (aInRange) {
|
||||
nsIDOMText * textContent;
|
||||
nsresult status = aContent->QueryInterface(kIDOMTextIID, (void**) &textContent);
|
||||
if (NS_OK == status) {
|
||||
nsString text;
|
||||
textContent->GetData(text);
|
||||
aText.Append(text);
|
||||
//NS_IF_RELEASE(textContent);
|
||||
} else {
|
||||
nsIAtom * atom = aContent->GetTag();
|
||||
if (atom != nsnull) {
|
||||
nsString str;
|
||||
atom->ToString(str);
|
||||
//char * s = str.ToNewCString();
|
||||
if (str.Equals("P") ||
|
||||
str.Equals("OL") ||
|
||||
str.Equals("LI") ||
|
||||
str.Equals("TD") ||
|
||||
str.Equals("H1") ||
|
||||
str.Equals("H2") ||
|
||||
str.Equals("H3") ||
|
||||
str.Equals("H4") ||
|
||||
str.Equals("H5") ||
|
||||
str.Equals("H6") ||
|
||||
str.Equals("TABLE")) {
|
||||
addReturn = PR_TRUE;
|
||||
}
|
||||
//printf("[%s]\n", s);
|
||||
//delete s;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (PRInt32 i=0;i<aContent->ChildCount();i++) {
|
||||
TraverseTree(aText, aContent->ChildAt(i), aStart, aEnd, aInRange);
|
||||
}
|
||||
if (addReturn) {
|
||||
aText.Append("\n");
|
||||
}
|
||||
if (aContent == aEnd) {
|
||||
aInRange = PR_FALSE;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void nsDocument::GetSelectionText(nsString & aText) {
|
||||
nsSelectionRange * range = mSelection->GetRange();
|
||||
nsSelectionPoint * startPnt = range->GetStartPoint();
|
||||
nsSelectionPoint * endPnt = range->GetEndPoint();
|
||||
|
||||
PRBool inRange = PR_FALSE;
|
||||
TraverseTree(aText, mRootContent, startPnt->GetContent(), endPnt->GetContent(), inRange);
|
||||
}
|
||||
|
||||
|
||||
NS_LAYOUT nsresult
|
||||
NS_NewSelection(nsISelection** aInstancePtrResult)
|
||||
|
|
|
@ -133,6 +133,23 @@ public:
|
|||
*/
|
||||
virtual nsISelection * GetSelection();
|
||||
|
||||
/**
|
||||
* Selects all the Content
|
||||
*/
|
||||
virtual void SelectAll();
|
||||
|
||||
/**
|
||||
* Copies all text from the selection
|
||||
*/
|
||||
virtual void GetSelectionText(nsString & aText);
|
||||
|
||||
void TraverseTree(nsString & aText,
|
||||
nsIContent * aContent,
|
||||
nsIContent * aStart,
|
||||
nsIContent * aEnd,
|
||||
PRBool & aInRange);
|
||||
|
||||
|
||||
public:
|
||||
|
||||
virtual nsresult GetScriptObject(JSContext *aContext, void** aScriptObject);
|
||||
|
|
|
@ -186,3 +186,12 @@ NS_METHOD nsSplittableFrame::BreakFromNextFlow()
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
nsIFrame * nsSplittableFrame::GetPrevInFlow()
|
||||
{
|
||||
return mPrevInFlow;
|
||||
}
|
||||
|
||||
nsIFrame * nsSplittableFrame::GetNextInFlow()
|
||||
{
|
||||
return mNextInFlow;
|
||||
}
|
||||
|
|
|
@ -54,6 +54,10 @@ public:
|
|||
NS_IMETHOD BreakFromPrevFlow();
|
||||
NS_IMETHOD BreakFromNextFlow();
|
||||
|
||||
nsIFrame * GetPrevInFlow();
|
||||
nsIFrame * GetNextInFlow();
|
||||
|
||||
|
||||
protected:
|
||||
// Constructor. Takes as arguments the content object, the index in parent,
|
||||
// and the Frame for the content parent
|
||||
|
|
Загрузка…
Ссылка в новой задаче