зеркало из https://github.com/mozilla/gecko-dev.git
XPCOM'ed the Selection and Search methods
This commit is contained in:
Родитель
934caea51d
Коммит
4a4b4a34b2
|
@ -184,23 +184,18 @@ public:
|
|||
/**
|
||||
* Returns the Selection Object
|
||||
*/
|
||||
virtual nsISelection * GetSelection() = 0;
|
||||
NS_IMETHOD GetSelection(nsISelection *& aSelection) = 0;
|
||||
|
||||
/**
|
||||
* Selects all the Content
|
||||
*/
|
||||
virtual void SelectAll() = 0;
|
||||
NS_IMETHOD SelectAll() = 0;
|
||||
|
||||
/**
|
||||
* Finds text in content
|
||||
*/
|
||||
NS_IMETHOD FindNext(const nsString &aSearchStr, PRBool aMatchCase, PRBool aSearchDown, PRBool &aIsFound) = 0;
|
||||
|
||||
/**
|
||||
* Copies all text from the selection
|
||||
*/
|
||||
virtual void GetSelectionText(nsString & aText) = 0;
|
||||
|
||||
/**
|
||||
* Converts the document or a selection of the
|
||||
* document to XIF (XML Interchange Format)
|
||||
|
|
|
@ -1112,11 +1112,15 @@ nsDocument::Construct(JSContext *cx, JSObject *obj, uintN argc,
|
|||
/**
|
||||
* Returns the Selection Object
|
||||
*/
|
||||
nsISelection * nsDocument::GetSelection() {
|
||||
NS_IMETHODIMP nsDocument::GetSelection(nsISelection *& aSelection) {
|
||||
if (mSelection != nsnull) {
|
||||
NS_ADDREF(mSelection);
|
||||
aSelection = mSelection;
|
||||
return NS_OK;
|
||||
} else {
|
||||
aSelection = nsnull;
|
||||
}
|
||||
return mSelection;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
|
||||
|
@ -1152,7 +1156,8 @@ static void TraverseBlockContent(nsIContent * aContent, nsString & aStr)
|
|||
/**
|
||||
* Selects all the Content
|
||||
*/
|
||||
void nsDocument::SelectAll() {
|
||||
NS_IMETHODIMP nsDocument::SelectAll() {
|
||||
|
||||
nsIContent * start = nsnull;
|
||||
nsIContent * end = nsnull;
|
||||
nsIContent * body = nsnull;
|
||||
|
@ -1178,7 +1183,7 @@ void nsDocument::SelectAll() {
|
|||
}
|
||||
|
||||
if (body == nsnull) {
|
||||
return;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
start = body;
|
||||
|
@ -1215,6 +1220,7 @@ void nsDocument::SelectAll() {
|
|||
endPnt->SetPoint(end, -1, PR_FALSE);
|
||||
SetDisplaySelection(PR_TRUE);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1223,82 +1229,9 @@ void nsDocument::SelectAll() {
|
|||
NS_IMETHODIMP nsDocument::FindNext(const nsString &aSearchStr, PRBool aMatchCase, PRBool aSearchDown, PRBool &aIsFound)
|
||||
{
|
||||
aIsFound = PR_FALSE;
|
||||
return NS_OK;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
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(atom);
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PRInt32 n;
|
||||
aContent->ChildCount(n);
|
||||
for (PRInt32 i=0;i<n;i++) {
|
||||
nsIContent* kid;
|
||||
aContent->ChildAt(i, kid);
|
||||
TraverseTree(aText, kid, 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;
|
||||
nsIContent * startContent = startPnt->GetContent();
|
||||
nsIContent * endContent = endPnt->GetContent();
|
||||
TraverseTree(aText, mRootContent, startContent, endContent, inRange);
|
||||
NS_IF_RELEASE(startContent);
|
||||
NS_IF_RELEASE(endContent);
|
||||
}
|
||||
|
||||
|
||||
void nsDocument::BeginConvertToXIF(nsXIFConverter& aConverter, nsIDOMNode* aNode)
|
||||
|
|
|
@ -162,29 +162,18 @@ public:
|
|||
/**
|
||||
* Returns the Selection Object
|
||||
*/
|
||||
virtual nsISelection * GetSelection();
|
||||
NS_IMETHOD GetSelection(nsISelection *& aSelection);
|
||||
|
||||
/**
|
||||
* Selects all the Content
|
||||
*/
|
||||
virtual void SelectAll();
|
||||
NS_IMETHOD SelectAll();
|
||||
|
||||
/**
|
||||
* Finds text in content
|
||||
*/
|
||||
NS_IMETHOD FindNext(const nsString &aSearchStr, PRBool aMatchCase, PRBool aSearchDown, PRBool &aIsFound);
|
||||
|
||||
/**
|
||||
* Copies all text from the selection
|
||||
*/
|
||||
virtual void GetSelectionText(nsString & aText);
|
||||
|
||||
void TraverseTree(nsString & aText,
|
||||
nsIContent * aContent,
|
||||
nsIContent * aStart,
|
||||
nsIContent * aEnd,
|
||||
PRBool & aInRange);
|
||||
|
||||
/**
|
||||
* Converts the document or a selection of the
|
||||
* document to XIF (XML Interchange Format)
|
||||
|
|
|
@ -184,23 +184,18 @@ public:
|
|||
/**
|
||||
* Returns the Selection Object
|
||||
*/
|
||||
virtual nsISelection * GetSelection() = 0;
|
||||
NS_IMETHOD GetSelection(nsISelection *& aSelection) = 0;
|
||||
|
||||
/**
|
||||
* Selects all the Content
|
||||
*/
|
||||
virtual void SelectAll() = 0;
|
||||
NS_IMETHOD SelectAll() = 0;
|
||||
|
||||
/**
|
||||
* Finds text in content
|
||||
*/
|
||||
NS_IMETHOD FindNext(const nsString &aSearchStr, PRBool aMatchCase, PRBool aSearchDown, PRBool &aIsFound) = 0;
|
||||
|
||||
/**
|
||||
* Copies all text from the selection
|
||||
*/
|
||||
virtual void GetSelectionText(nsString & aText) = 0;
|
||||
|
||||
/**
|
||||
* Converts the document or a selection of the
|
||||
* document to XIF (XML Interchange Format)
|
||||
|
|
|
@ -1112,11 +1112,15 @@ nsDocument::Construct(JSContext *cx, JSObject *obj, uintN argc,
|
|||
/**
|
||||
* Returns the Selection Object
|
||||
*/
|
||||
nsISelection * nsDocument::GetSelection() {
|
||||
NS_IMETHODIMP nsDocument::GetSelection(nsISelection *& aSelection) {
|
||||
if (mSelection != nsnull) {
|
||||
NS_ADDREF(mSelection);
|
||||
aSelection = mSelection;
|
||||
return NS_OK;
|
||||
} else {
|
||||
aSelection = nsnull;
|
||||
}
|
||||
return mSelection;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
|
||||
|
@ -1152,7 +1156,8 @@ static void TraverseBlockContent(nsIContent * aContent, nsString & aStr)
|
|||
/**
|
||||
* Selects all the Content
|
||||
*/
|
||||
void nsDocument::SelectAll() {
|
||||
NS_IMETHODIMP nsDocument::SelectAll() {
|
||||
|
||||
nsIContent * start = nsnull;
|
||||
nsIContent * end = nsnull;
|
||||
nsIContent * body = nsnull;
|
||||
|
@ -1178,7 +1183,7 @@ void nsDocument::SelectAll() {
|
|||
}
|
||||
|
||||
if (body == nsnull) {
|
||||
return;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
start = body;
|
||||
|
@ -1215,6 +1220,7 @@ void nsDocument::SelectAll() {
|
|||
endPnt->SetPoint(end, -1, PR_FALSE);
|
||||
SetDisplaySelection(PR_TRUE);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1223,82 +1229,9 @@ void nsDocument::SelectAll() {
|
|||
NS_IMETHODIMP nsDocument::FindNext(const nsString &aSearchStr, PRBool aMatchCase, PRBool aSearchDown, PRBool &aIsFound)
|
||||
{
|
||||
aIsFound = PR_FALSE;
|
||||
return NS_OK;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
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(atom);
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PRInt32 n;
|
||||
aContent->ChildCount(n);
|
||||
for (PRInt32 i=0;i<n;i++) {
|
||||
nsIContent* kid;
|
||||
aContent->ChildAt(i, kid);
|
||||
TraverseTree(aText, kid, 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;
|
||||
nsIContent * startContent = startPnt->GetContent();
|
||||
nsIContent * endContent = endPnt->GetContent();
|
||||
TraverseTree(aText, mRootContent, startContent, endContent, inRange);
|
||||
NS_IF_RELEASE(startContent);
|
||||
NS_IF_RELEASE(endContent);
|
||||
}
|
||||
|
||||
|
||||
void nsDocument::BeginConvertToXIF(nsXIFConverter& aConverter, nsIDOMNode* aNode)
|
||||
|
|
|
@ -162,29 +162,18 @@ public:
|
|||
/**
|
||||
* Returns the Selection Object
|
||||
*/
|
||||
virtual nsISelection * GetSelection();
|
||||
NS_IMETHOD GetSelection(nsISelection *& aSelection);
|
||||
|
||||
/**
|
||||
* Selects all the Content
|
||||
*/
|
||||
virtual void SelectAll();
|
||||
NS_IMETHOD SelectAll();
|
||||
|
||||
/**
|
||||
* Finds text in content
|
||||
*/
|
||||
NS_IMETHOD FindNext(const nsString &aSearchStr, PRBool aMatchCase, PRBool aSearchDown, PRBool &aIsFound);
|
||||
|
||||
/**
|
||||
* Copies all text from the selection
|
||||
*/
|
||||
virtual void GetSelectionText(nsString & aText);
|
||||
|
||||
void TraverseTree(nsString & aText,
|
||||
nsIContent * aContent,
|
||||
nsIContent * aStart,
|
||||
nsIContent * aEnd,
|
||||
PRBool & aInRange);
|
||||
|
||||
/**
|
||||
* Converts the document or a selection of the
|
||||
* document to XIF (XML Interchange Format)
|
||||
|
|
|
@ -574,7 +574,8 @@ NS_METHOD nsFrame::Paint(nsIPresContext& aPresContext,
|
|||
nsIPresShell * shell = aPresContext.GetShell();
|
||||
nsIDocument * doc = shell->GetDocument();
|
||||
if (mSelectionRange == nsnull) { // Get Selection Object
|
||||
nsISelection * selection = doc->GetSelection();
|
||||
nsISelection * selection;
|
||||
doc->GetSelection(selection);
|
||||
|
||||
mSelectionRange = selection->GetRange();
|
||||
|
||||
|
@ -670,11 +671,13 @@ NS_METHOD nsFrame::HandlePress(nsIPresContext& aPresContext,
|
|||
|
||||
nsFrame * currentFrame = this;
|
||||
nsIPresShell * shell = aPresContext.GetShell();
|
||||
nsMouseEvent * mouseEvent = (nsMouseEvent *)aEvent;
|
||||
|
||||
gDoc = shell->GetDocument();
|
||||
|
||||
nsISelection * selection = gDoc->GetSelection();
|
||||
nsMouseEvent * mouseEvent = (nsMouseEvent *)aEvent;
|
||||
nsISelection * selection;
|
||||
gDoc->GetSelection(selection);
|
||||
|
||||
|
||||
mSelectionRange = selection->GetRange();
|
||||
|
||||
|
|
|
@ -512,7 +512,9 @@ TextFrame::ComputeSelectionInfo(nsIRenderingContext& aRenderingContext,
|
|||
aResult.mEndOffset = aTextLength;
|
||||
aResult.mEmptySelection = PR_FALSE;
|
||||
|
||||
nsISelection * selection = aDocument->GetSelection();
|
||||
nsISelection * selection;
|
||||
aDocument->GetSelection(selection);
|
||||
|
||||
nsSelectionRange * range = selection->GetRange();
|
||||
nsSelectionPoint * startPnt = range->GetStartPoint();
|
||||
nsSelectionPoint * endPnt = range->GetEndPoint();
|
||||
|
|
|
@ -512,7 +512,9 @@ TextFrame::ComputeSelectionInfo(nsIRenderingContext& aRenderingContext,
|
|||
aResult.mEndOffset = aTextLength;
|
||||
aResult.mEmptySelection = PR_FALSE;
|
||||
|
||||
nsISelection * selection = aDocument->GetSelection();
|
||||
nsISelection * selection;
|
||||
aDocument->GetSelection(selection);
|
||||
|
||||
nsSelectionRange * range = selection->GetRange();
|
||||
nsSelectionPoint * startPnt = range->GetStartPoint();
|
||||
nsSelectionPoint * endPnt = range->GetEndPoint();
|
||||
|
|
|
@ -498,7 +498,8 @@ nsGenericDOMDataNode::ConvertContentToXIF(nsXIFConverter& aConverter) const
|
|||
|
||||
if (aConverter.GetUseSelection() == PR_TRUE && mDocument->IsInSelection(content))
|
||||
{
|
||||
nsISelection* sel = mDocument->GetSelection();
|
||||
nsISelection* sel;
|
||||
mDocument->GetSelection(sel);
|
||||
if (sel != nsnull)
|
||||
{
|
||||
nsSelectionRange* range = sel->GetRange();
|
||||
|
|
Загрузка…
Ссылка в новой задаче