зеркало из https://github.com/mozilla/pjs.git
Bug 718170 - Part b: Use nsINode in IsVisTextNode; r=ehsan
This commit is contained in:
Родитель
9acebd55d1
Коммит
60f6c34d94
|
@ -1,6 +1,5 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* ***** BEGIN LICENSE BLOCK *****
|
||||
/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
|
@ -47,11 +46,12 @@ typedef short SelectionType;
|
|||
typedef short SelectionRegion;
|
||||
%}
|
||||
|
||||
interface nsIContent;
|
||||
interface nsIDOMNode;
|
||||
interface nsISelection;
|
||||
interface nsISelectionDisplay;
|
||||
|
||||
[scriptable, uuid(cf30315f-b65d-44c3-8c57-557e36d18fd2)]
|
||||
[scriptable, uuid(b1ff7faa-8097-431d-b7f1-b0615e3cd596)]
|
||||
interface nsISelectionController : nsISelectionDisplay
|
||||
{
|
||||
const short SELECTION_NONE=0;
|
||||
|
@ -276,6 +276,7 @@ interface nsISelectionController : nsISelectionDisplay
|
|||
* @param aReturnBool boolean returned TRUE if visible FALSE if not
|
||||
*/
|
||||
boolean checkVisibility(in nsIDOMNode node, in short startOffset, in short endOffset);
|
||||
[noscript,nostdcall] boolean checkVisibilityContent(in nsIContent node, in short startOffset, in short endOffset);
|
||||
|
||||
};
|
||||
%{ C++
|
||||
|
|
|
@ -217,6 +217,7 @@ public:
|
|||
NS_IMETHOD ScrollCharacter(bool aRight);
|
||||
NS_IMETHOD SelectAll(void);
|
||||
NS_IMETHOD CheckVisibility(nsIDOMNode *node, PRInt16 startOffset, PRInt16 EndOffset, bool *_retval);
|
||||
virtual nsresult CheckVisibilityContent(nsIContent* aNode, PRInt16 aStartOffset, PRInt16 aEndOffset, bool* aRetval);
|
||||
|
||||
private:
|
||||
nsRefPtr<nsFrameSelection> mFrameSelection;
|
||||
|
@ -606,6 +607,22 @@ nsTextInputSelectionImpl::CheckVisibility(nsIDOMNode *node, PRInt16 startOffset,
|
|||
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsTextInputSelectionImpl::CheckVisibilityContent(nsIContent* aNode,
|
||||
PRInt16 aStartOffset,
|
||||
PRInt16 aEndOffset,
|
||||
bool* aRetval)
|
||||
{
|
||||
if (!mPresShellWeak) {
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsISelectionController> shell = do_QueryReferent(mPresShellWeak);
|
||||
NS_ENSURE_TRUE(shell, NS_ERROR_FAILURE);
|
||||
|
||||
return shell->CheckVisibilityContent(aNode, aStartOffset, aEndOffset, aRetval);
|
||||
}
|
||||
|
||||
class nsTextInputListener : public nsISelectionListener,
|
||||
public nsIDOMEventListener,
|
||||
public nsIEditorObserver,
|
||||
|
|
|
@ -2437,21 +2437,20 @@ nsHTMLEditRules::WillDeleteSelection(nsISelection *aSelection,
|
|||
|
||||
// now that we have the list, delete non table elements
|
||||
PRInt32 listCount = arrayOfNodes.Count();
|
||||
PRInt32 j;
|
||||
|
||||
for (j = 0; j < listCount; j++)
|
||||
{
|
||||
for (PRInt32 j = 0; j < listCount; j++) {
|
||||
nsIDOMNode* somenode = arrayOfNodes[0];
|
||||
res = DeleteNonTableElements(somenode);
|
||||
arrayOfNodes.RemoveObjectAt(0);
|
||||
// If something visible is deleted, no need to join.
|
||||
// Visible means all nodes except non-visible textnodes and breaks.
|
||||
if (join && origCollapsed) {
|
||||
if (mHTMLEditor->IsTextNode(somenode)) {
|
||||
mHTMLEditor->IsVisTextNode(somenode, &join, true);
|
||||
}
|
||||
else {
|
||||
join = nsTextEditUtils::IsBreak(somenode) &&
|
||||
nsCOMPtr<nsIContent> content = do_QueryInterface(somenode);
|
||||
if (!content) {
|
||||
join = false;
|
||||
} else if (content->NodeType() == nsIDOMNode::TEXT_NODE) {
|
||||
mHTMLEditor->IsVisTextNode(content, &join, true);
|
||||
} else {
|
||||
join = content->IsHTML(nsGkAtoms::br) &&
|
||||
!mHTMLEditor->IsVisBreak(somenode);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4798,29 +4798,20 @@ nsresult
|
|||
nsHTMLEditor::IsVisTextNode(nsIContent* aNode,
|
||||
bool* outIsEmptyNode,
|
||||
bool aSafeToAskFrames)
|
||||
{
|
||||
nsCOMPtr<nsIDOMNode> node = do_QueryInterface(aNode);
|
||||
return IsVisTextNode(node);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsHTMLEditor::IsVisTextNode( nsIDOMNode* aNode,
|
||||
bool *outIsEmptyNode,
|
||||
bool aSafeToAskFrames)
|
||||
{
|
||||
NS_ENSURE_TRUE(aNode && outIsEmptyNode, NS_ERROR_NULL_POINTER);
|
||||
*outIsEmptyNode = true;
|
||||
nsresult res = NS_OK;
|
||||
|
||||
nsCOMPtr<nsIContent> textContent = do_QueryInterface(aNode);
|
||||
// callers job to only call us with text nodes
|
||||
if (!textContent || !textContent->IsNodeOfType(nsINode::eTEXT))
|
||||
if (!aNode->IsNodeOfType(nsINode::eTEXT)) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
PRUint32 length = textContent->TextLength();
|
||||
}
|
||||
|
||||
PRUint32 length = aNode->TextLength();
|
||||
if (aSafeToAskFrames)
|
||||
{
|
||||
nsCOMPtr<nsISelectionController> selCon;
|
||||
res = GetSelectionController(getter_AddRefs(selCon));
|
||||
nsresult res = GetSelectionController(getter_AddRefs(selCon));
|
||||
NS_ENSURE_SUCCESS(res, res);
|
||||
NS_ENSURE_TRUE(selCon, NS_ERROR_FAILURE);
|
||||
bool isVisible = false;
|
||||
|
@ -4830,7 +4821,7 @@ nsHTMLEditor::IsVisTextNode( nsIDOMNode* aNode,
|
|||
// So we put a call in the selection controller interface, since it's already
|
||||
// in bed with frames anyway. (this is a fix for bug 22227, and a
|
||||
// partial fix for bug 46209)
|
||||
res = selCon->CheckVisibility(aNode, 0, length, &isVisible);
|
||||
res = selCon->CheckVisibilityContent(aNode, 0, length, &isVisible);
|
||||
NS_ENSURE_SUCCESS(res, res);
|
||||
if (isVisible)
|
||||
{
|
||||
|
@ -4839,18 +4830,20 @@ nsHTMLEditor::IsVisTextNode( nsIDOMNode* aNode,
|
|||
}
|
||||
else if (length)
|
||||
{
|
||||
if (textContent->TextIsOnlyWhitespace())
|
||||
if (aNode->TextIsOnlyWhitespace())
|
||||
{
|
||||
nsWSRunObject wsRunObj(this, aNode, 0);
|
||||
nsCOMPtr<nsIDOMNode> node = do_QueryInterface(aNode);
|
||||
nsWSRunObject wsRunObj(this, node, 0);
|
||||
nsCOMPtr<nsIDOMNode> visNode;
|
||||
PRInt32 outVisOffset=0;
|
||||
PRInt16 visType=0;
|
||||
res = wsRunObj.NextVisibleNode(aNode, 0, address_of(visNode), &outVisOffset, &visType);
|
||||
nsresult res = wsRunObj.NextVisibleNode(node, 0, address_of(visNode),
|
||||
&outVisOffset, &visType);
|
||||
NS_ENSURE_SUCCESS(res, res);
|
||||
if ( (visType == nsWSRunObject::eNormalWS) ||
|
||||
(visType == nsWSRunObject::eText) )
|
||||
{
|
||||
*outIsEmptyNode = (aNode != visNode);
|
||||
*outIsEmptyNode = (node != visNode);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
|
@ -391,9 +391,6 @@ public:
|
|||
nsresult IsVisTextNode(nsIContent* aNode,
|
||||
bool* outIsEmptyNode,
|
||||
bool aSafeToAskFrames);
|
||||
nsresult IsVisTextNode( nsIDOMNode *aNode,
|
||||
bool *outIsEmptyNode,
|
||||
bool aSafeToAskFrames);
|
||||
nsresult IsEmptyNode(nsIDOMNode *aNode, bool *outIsEmptyBlock,
|
||||
bool aMozBRDoesntCount = false,
|
||||
bool aListOrCellNotEmpty = false,
|
||||
|
|
|
@ -2531,6 +2531,27 @@ PresShell::SelectAll()
|
|||
return mSelection->SelectAll();
|
||||
}
|
||||
|
||||
static void
|
||||
DoCheckVisibility(nsPresContext* aPresContext,
|
||||
nsIContent* aNode,
|
||||
PRInt16 aStartOffset,
|
||||
PRInt16 aEndOffset,
|
||||
bool* aRetval)
|
||||
{
|
||||
nsIFrame* frame = aNode->GetPrimaryFrame();
|
||||
if (!frame) {
|
||||
// No frame to look at so it must not be visible.
|
||||
return;
|
||||
}
|
||||
|
||||
// Start process now to go through all frames to find startOffset. Then check
|
||||
// chars after that to see if anything until EndOffset is visible.
|
||||
bool finished = false;
|
||||
frame->CheckVisibility(aPresContext, aStartOffset, aEndOffset, true,
|
||||
&finished, aRetval);
|
||||
// Don't worry about other return value.
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
PresShell::CheckVisibility(nsIDOMNode *node, PRInt16 startOffset, PRInt16 EndOffset, bool *_retval)
|
||||
{
|
||||
|
@ -2540,14 +2561,23 @@ PresShell::CheckVisibility(nsIDOMNode *node, PRInt16 startOffset, PRInt16 EndOff
|
|||
nsCOMPtr<nsIContent> content(do_QueryInterface(node));
|
||||
if (!content)
|
||||
return NS_ERROR_FAILURE;
|
||||
nsIFrame *frame = content->GetPrimaryFrame();
|
||||
if (!frame) //no frame to look at so it must not be visible
|
||||
return NS_OK;
|
||||
//start process now to go through all frames to find startOffset. then check chars after that to see
|
||||
//if anything until EndOffset is visible.
|
||||
bool finished = false;
|
||||
frame->CheckVisibility(mPresContext,startOffset,EndOffset,true,&finished, _retval);
|
||||
return NS_OK;//dont worry about other return val
|
||||
|
||||
DoCheckVisibility(mPresContext, content, startOffset, EndOffset, _retval);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
PresShell::CheckVisibilityContent(nsIContent* aNode, PRInt16 aStartOffset,
|
||||
PRInt16 aEndOffset, bool* aRetval)
|
||||
{
|
||||
if (!aNode || aStartOffset > aEndOffset || !aRetval ||
|
||||
aStartOffset < 0 || aEndOffset < 0) {
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
|
||||
*aRetval = false;
|
||||
DoCheckVisibility(mPresContext, aNode, aStartOffset, aEndOffset, aRetval);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//end implementations nsISelectionController
|
||||
|
|
|
@ -366,6 +366,8 @@ public:
|
|||
NS_IMETHOD CompleteMove(bool aForward, bool aExtend);
|
||||
NS_IMETHOD SelectAll();
|
||||
NS_IMETHOD CheckVisibility(nsIDOMNode *node, PRInt16 startOffset, PRInt16 EndOffset, bool *_retval);
|
||||
virtual nsresult CheckVisibilityContent(nsIContent* aNode, PRInt16 aStartOffset,
|
||||
PRInt16 aEndOffset, bool* aRetval);
|
||||
|
||||
// nsIDocumentObserver
|
||||
NS_DECL_NSIDOCUMENTOBSERVER_BEGINUPDATE
|
||||
|
|
Загрузка…
Ссылка в новой задаче