зеркало из https://github.com/mozilla/pjs.git
Wrote RemoveAllInlineProperties() to deal with clearing out inline style, and also fixed a bunch of IME bugs.
This commit is contained in:
Родитель
f13843ab50
Коммит
b7dd11f7bb
|
@ -96,7 +96,6 @@
|
|||
#include "nsEditor.h"
|
||||
#include "nsEditorUtils.h"
|
||||
|
||||
|
||||
#ifdef HACK_FORCE_REDRAW
|
||||
// INCLUDES FOR EVIL HACK TO FOR REDRAW
|
||||
// BEGIN
|
||||
|
@ -2491,7 +2490,7 @@ nsresult nsEditor::GetTextNodeTag(nsString& aOutString)
|
|||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsEditor::JoeInsertTextImpl(const nsString& aStringToInsert,
|
||||
NS_IMETHODIMP nsEditor::InsertTextImpl(const nsString& aStringToInsert,
|
||||
nsCOMPtr<nsIDOMNode> *aInOutNode,
|
||||
PRInt32 *aInOutOffset,
|
||||
nsIDOMDocument *aDoc)
|
||||
|
@ -2501,7 +2500,7 @@ NS_IMETHODIMP nsEditor::JoeInsertTextImpl(const nsString& aStringToInsert,
|
|||
// if desired.
|
||||
|
||||
if (!aInOutNode || !*aInOutNode || !aInOutOffset || !aDoc) return NS_ERROR_NULL_POINTER;
|
||||
if (aStringToInsert.IsEmpty()) return NS_OK;
|
||||
if (!mInIMEMode && aStringToInsert.IsEmpty()) return NS_OK;
|
||||
nsCOMPtr<nsIDOMText> nodeAsText = do_QueryInterface(*aInOutNode);
|
||||
PRInt32 offset = *aInOutOffset;
|
||||
nsresult res;
|
||||
|
@ -2520,7 +2519,7 @@ NS_IMETHODIMP nsEditor::JoeInsertTextImpl(const nsString& aStringToInsert,
|
|||
if (NS_FAILED(res)) return res;
|
||||
offset = 0;
|
||||
}
|
||||
res = JoeInsertTextIntoTextNodeImpl(aStringToInsert, nodeAsText, offset);
|
||||
res = InsertTextIntoTextNodeImpl(aStringToInsert, nodeAsText, offset);
|
||||
if (NS_FAILED(res)) return res;
|
||||
}
|
||||
else
|
||||
|
@ -2528,7 +2527,7 @@ NS_IMETHODIMP nsEditor::JoeInsertTextImpl(const nsString& aStringToInsert,
|
|||
if (nodeAsText)
|
||||
{
|
||||
// we are inserting text into an existing text node.
|
||||
res = JoeInsertTextIntoTextNodeImpl(aStringToInsert, nodeAsText, offset);
|
||||
res = InsertTextIntoTextNodeImpl(aStringToInsert, nodeAsText, offset);
|
||||
if (NS_FAILED(res)) return res;
|
||||
*aInOutOffset += aStringToInsert.Length();
|
||||
}
|
||||
|
@ -2552,7 +2551,7 @@ NS_IMETHODIMP nsEditor::JoeInsertTextImpl(const nsString& aStringToInsert,
|
|||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsEditor::JoeInsertTextIntoTextNodeImpl(const nsString& aStringToInsert,
|
||||
NS_IMETHODIMP nsEditor::InsertTextIntoTextNodeImpl(const nsString& aStringToInsert,
|
||||
nsIDOMCharacterData *aTextNode,
|
||||
PRInt32 aOffset)
|
||||
{
|
||||
|
|
|
@ -299,11 +299,11 @@ public:
|
|||
public:
|
||||
|
||||
|
||||
NS_IMETHOD JoeInsertTextImpl(const nsString& aStringToInsert,
|
||||
NS_IMETHOD InsertTextImpl(const nsString& aStringToInsert,
|
||||
nsCOMPtr<nsIDOMNode> *aInOutNode,
|
||||
PRInt32 *aInOutOffset,
|
||||
nsIDOMDocument *aDoc);
|
||||
NS_IMETHOD JoeInsertTextIntoTextNodeImpl(const nsString& aStringToInsert,
|
||||
NS_IMETHOD InsertTextIntoTextNodeImpl(const nsString& aStringToInsert,
|
||||
nsIDOMCharacterData *aTextNode,
|
||||
PRInt32 aOffset);
|
||||
NS_IMETHOD DeleteSelectionImpl(EDirection aAction);
|
||||
|
|
|
@ -854,17 +854,7 @@ nsEditorShell::RemoveOneProperty(const nsString& aProp, const nsString &aAttr)
|
|||
NS_IMETHODIMP
|
||||
nsEditorShell::RemoveTextProperty(const PRUnichar *prop, const PRUnichar *attr)
|
||||
{
|
||||
// OK, I'm really hacking now. This is just so that we can accept 'all' as input.
|
||||
// this logic should live elsewhere.
|
||||
//TODO: FIX THIS! IT IS WRONG! IT DOESN'T CONSIDER ALL THE
|
||||
// OTHER POSSIBLE TEXT ATTRIBUTES!
|
||||
static const char* sAllKnownStyles[] = {
|
||||
"b",
|
||||
"i",
|
||||
"u",
|
||||
nsnull // this null is important
|
||||
};
|
||||
|
||||
// OK, I'm really hacking now. This is just so that we can accept 'all' as input.
|
||||
nsAutoString allStr(prop);
|
||||
nsAutoString aAttr(attr);
|
||||
|
||||
|
@ -874,19 +864,7 @@ nsEditorShell::RemoveTextProperty(const PRUnichar *prop, const PRUnichar *attr)
|
|||
|
||||
if (doingAll)
|
||||
{
|
||||
nsAutoString thisAttr;
|
||||
const char **tagName = sAllKnownStyles;
|
||||
|
||||
while (*tagName)
|
||||
{
|
||||
thisAttr.Truncate(0);
|
||||
thisAttr += (char *)(*tagName);
|
||||
|
||||
err = RemoveOneProperty(thisAttr, aAttr);
|
||||
|
||||
tagName ++;
|
||||
}
|
||||
|
||||
err = mEditor->RemoveAllInlineProperties();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -210,9 +210,13 @@ nsHTMLEditRules::AfterEdit(PRInt32 action, nsIEditor::EDirection aDirection)
|
|||
if (NS_FAILED(res)) return res;
|
||||
|
||||
// merge any adjacent text nodes
|
||||
res = mEditor->CollapseAdjacentTextNodes(mDocChangeRange);
|
||||
if (NS_FAILED(res)) return res;
|
||||
|
||||
if ( (action != nsEditor::kOpInsertText &&
|
||||
action != nsEditor::kOpInsertIMEText) )
|
||||
{
|
||||
res = mEditor->CollapseAdjacentTextNodes(mDocChangeRange);
|
||||
if (NS_FAILED(res)) return res;
|
||||
}
|
||||
|
||||
// adjust whitespace for insert text and delete actions
|
||||
if ((action == nsEditor::kOpInsertText) ||
|
||||
(action == nsEditor::kOpInsertIMEText) ||
|
||||
|
@ -404,7 +408,7 @@ nsHTMLEditRules::WillInsertText(PRInt32 aAction,
|
|||
|
||||
if (aAction == kInsertTextIME)
|
||||
{
|
||||
res = mEditor->JoeInsertTextImpl(*inString, &selNode, &selOffset, doc);
|
||||
res = mEditor->InsertTextImpl(*inString, &selNode, &selOffset, doc);
|
||||
if (NS_FAILED(res)) return res;
|
||||
}
|
||||
else // aAction == kInsertText
|
||||
|
@ -462,12 +466,12 @@ nsHTMLEditRules::WillInsertText(PRInt32 aAction,
|
|||
// is it a return?
|
||||
if (subStr.Equals("\n"))
|
||||
{
|
||||
res = mEditor->JoeCreateBR(&curNode, &curOffset, &unused, nsIEditor::eNone);
|
||||
res = mEditor->CreateBRImpl(&curNode, &curOffset, &unused, nsIEditor::eNone);
|
||||
pos++;
|
||||
}
|
||||
else
|
||||
{
|
||||
res = mEditor->JoeInsertTextImpl(subStr, &curNode, &curOffset, doc);
|
||||
res = mEditor->InsertTextImpl(subStr, &curNode, &curOffset, doc);
|
||||
}
|
||||
if (NS_FAILED(res)) return res;
|
||||
}
|
||||
|
@ -500,18 +504,18 @@ nsHTMLEditRules::WillInsertText(PRInt32 aAction,
|
|||
// is it a tab?
|
||||
if (subStr.Equals("\t"))
|
||||
{
|
||||
res = mEditor->JoeInsertTextImpl(tabString, &curNode, &curOffset, doc);
|
||||
res = mEditor->InsertTextImpl(tabString, &curNode, &curOffset, doc);
|
||||
pos++;
|
||||
}
|
||||
// is it a return?
|
||||
else if (subStr.Equals("\n"))
|
||||
{
|
||||
res = mEditor->JoeCreateBR(&curNode, &curOffset, &unused, nsIEditor::eNone);
|
||||
res = mEditor->CreateBRImpl(&curNode, &curOffset, &unused, nsIEditor::eNone);
|
||||
pos++;
|
||||
}
|
||||
else
|
||||
{
|
||||
res = mEditor->JoeInsertTextImpl(subStr, &curNode, &curOffset, doc);
|
||||
res = mEditor->InsertTextImpl(subStr, &curNode, &curOffset, doc);
|
||||
}
|
||||
if (NS_FAILED(res)) return res;
|
||||
}
|
||||
|
|
|
@ -717,6 +717,12 @@ NS_IMETHODIMP nsHTMLEditor::EditorKeyPress(nsIDOMKeyEvent* aKeyEvent)
|
|||
return TypedText(empty, eTypedBreak); // uses rules to figure out what to insert
|
||||
}
|
||||
}
|
||||
else if (keyCode == nsIDOMKeyEvent::DOM_VK_ESCAPE)
|
||||
{
|
||||
// pass escape keypresses through as empty strings: needed forime support
|
||||
nsAutoString empty;
|
||||
return TypedText(empty, eTypedText);
|
||||
}
|
||||
|
||||
// if we got here we either fell out of the tab case or have a normal character.
|
||||
// Either way, treat as normal character.
|
||||
|
@ -810,7 +816,7 @@ NS_IMETHODIMP nsHTMLEditor::TabInTable(PRBool inIsShift, PRBool *outHandled)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsHTMLEditor::JoeCreateBR(nsCOMPtr<nsIDOMNode> *aInOutParent, PRInt32 *aInOutOffset, nsCOMPtr<nsIDOMNode> *outBRNode, EDirection aSelect)
|
||||
NS_IMETHODIMP nsHTMLEditor::CreateBRImpl(nsCOMPtr<nsIDOMNode> *aInOutParent, PRInt32 *aInOutOffset, nsCOMPtr<nsIDOMNode> *outBRNode, EDirection aSelect)
|
||||
{
|
||||
if (!aInOutParent || !*aInOutParent || !aInOutOffset || !outBRNode) return NS_ERROR_NULL_POINTER;
|
||||
*outBRNode = nsnull;
|
||||
|
@ -891,7 +897,7 @@ NS_IMETHODIMP nsHTMLEditor::CreateBR(nsIDOMNode *aNode, PRInt32 aOffset, nsCOMPt
|
|||
{
|
||||
nsCOMPtr<nsIDOMNode> parent = aNode;
|
||||
PRInt32 offset = aOffset;
|
||||
return JoeCreateBR(&parent, &offset, outBRNode, aSelect);
|
||||
return CreateBRImpl(&parent, &offset, outBRNode, aSelect);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsHTMLEditor::InsertBR(nsCOMPtr<nsIDOMNode> *outBRNode)
|
||||
|
@ -1255,7 +1261,7 @@ nsresult nsHTMLEditor::SplitStyleAboveRange(nsIDOMRange *inRange,
|
|||
nsIAtom *aProperty,
|
||||
const nsString *aAttribute)
|
||||
{
|
||||
if (!inRange || !aProperty) return NS_ERROR_NULL_POINTER;
|
||||
if (!inRange) return NS_ERROR_NULL_POINTER;
|
||||
nsresult res;
|
||||
nsCOMPtr<nsIDOMNode> startNode, endNode, origStartNode;
|
||||
PRInt32 startOffset, endOffset, origStartOffset;
|
||||
|
@ -1296,7 +1302,7 @@ nsresult nsHTMLEditor::SplitStyleAboveRange(nsIDOMRange *inRange,
|
|||
|
||||
nsresult nsHTMLEditor::SplitStyleAbovePoint(nsCOMPtr<nsIDOMNode> *aNode,
|
||||
PRInt32 *aOffset,
|
||||
nsIAtom *aProperty,
|
||||
nsIAtom *aProperty, // null here means we split all properties
|
||||
const nsString *aAttribute)
|
||||
{
|
||||
if (!aNode || !*aNode || !aOffset) return NS_ERROR_NULL_POINTER;
|
||||
|
@ -1305,7 +1311,8 @@ nsresult nsHTMLEditor::SplitStyleAbovePoint(nsCOMPtr<nsIDOMNode> *aNode,
|
|||
PRInt32 offset;
|
||||
while (tmp && !nsHTMLEditUtils::IsBody(tmp))
|
||||
{
|
||||
if (NodeIsType(tmp, aProperty))
|
||||
if ( (aProperty && NodeIsType(tmp, aProperty)) || // node is the correct inline prop
|
||||
(!aProperty && NodeIsProperty(tmp)) ) // or node is any prop, and we asked to split them all
|
||||
{
|
||||
// found a style node we need to split
|
||||
SplitNodeDeep(tmp, *aNode, *aOffset, &offset);
|
||||
|
@ -1318,13 +1325,23 @@ nsresult nsHTMLEditor::SplitStyleAbovePoint(nsCOMPtr<nsIDOMNode> *aNode,
|
|||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
PRBool nsHTMLEditor::NodeIsProperty(nsIDOMNode *aNode)
|
||||
{
|
||||
if (!aNode) return PR_FALSE;
|
||||
if (!IsContainer(aNode)) return PR_FALSE;
|
||||
if (!IsEditable(aNode)) return PR_FALSE;
|
||||
if (!IsInlineNode(aNode)) return PR_FALSE;
|
||||
if (NodeIsType(aNode, nsIEditProperty::a)) return PR_FALSE;
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
nsresult nsHTMLEditor::RemoveStyleInside(nsIDOMNode *aNode,
|
||||
nsIAtom *aProperty,
|
||||
nsIAtom *aProperty, // null here means remove all properties
|
||||
const nsString *aAttribute,
|
||||
PRBool aChildrenOnly)
|
||||
{
|
||||
if (!aNode || !aProperty) return NS_ERROR_NULL_POINTER;
|
||||
if (!aNode) return NS_ERROR_NULL_POINTER;
|
||||
if (IsTextNode(aNode)) return NS_OK;
|
||||
nsresult res = NS_OK;
|
||||
|
||||
|
@ -1341,7 +1358,9 @@ nsresult nsHTMLEditor::RemoveStyleInside(nsIDOMNode *aNode,
|
|||
}
|
||||
|
||||
// then process the node itself
|
||||
if (!aChildrenOnly && NodeIsType(aNode, aProperty))
|
||||
if ( !aChildrenOnly &&
|
||||
(aProperty && NodeIsType(aNode, aProperty)) || // node is prop we wasked for
|
||||
(!aProperty && NodeIsProperty(aNode)) ) // or node is any prop and we asked for that
|
||||
{
|
||||
// if we weren't passed an attribute, then we want to
|
||||
// remove any matching inlinestyles entirely
|
||||
|
@ -1773,9 +1792,19 @@ NS_IMETHODIMP nsHTMLEditor::GetInlineProperty(nsIAtom *aProperty,
|
|||
return result;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsHTMLEditor::RemoveAllInlineProperties()
|
||||
{
|
||||
return RemoveInlinePropertyImpl(nsnull, nsnull);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsHTMLEditor::RemoveInlineProperty(nsIAtom *aProperty, const nsString *aAttribute)
|
||||
{
|
||||
if (!aProperty) return NS_ERROR_NULL_POINTER;
|
||||
return RemoveInlinePropertyImpl(aProperty, aAttribute);
|
||||
}
|
||||
|
||||
nsresult nsHTMLEditor::RemoveInlinePropertyImpl(nsIAtom *aProperty, const nsString *aAttribute)
|
||||
{
|
||||
if (!mRules) return NS_ERROR_NOT_INITIALIZED;
|
||||
ForceCompositionEnd();
|
||||
|
||||
|
@ -1790,7 +1819,8 @@ NS_IMETHODIMP nsHTMLEditor::RemoveInlineProperty(nsIAtom *aProperty, const nsStr
|
|||
if (isCollapsed)
|
||||
{
|
||||
// manipulating text attributes on a collapsed selection only sets state for the next text insertion
|
||||
return mTypeInState->ClearProp(aProperty, *aAttribute);
|
||||
if (aProperty) return mTypeInState->ClearProp(aProperty, *aAttribute);
|
||||
// else return mTypeInState->ClearAllProps();
|
||||
}
|
||||
nsAutoEditBatch batchIt(this);
|
||||
nsAutoRules beginRulesSniffing(this, kOpRemoveTextProperty, nsIEditor::eNext);
|
||||
|
|
|
@ -103,6 +103,7 @@ public:
|
|||
const nsString *aValue,
|
||||
PRBool &aFirst, PRBool &aAny, PRBool &aAll);
|
||||
|
||||
NS_IMETHOD RemoveAllInlineProperties();
|
||||
NS_IMETHOD RemoveInlineProperty(nsIAtom *aProperty, const nsString *aAttribute);
|
||||
NS_IMETHOD IncreaseFontSize();
|
||||
NS_IMETHOD DecreaseFontSize();
|
||||
|
@ -356,7 +357,7 @@ protected:
|
|||
NS_IMETHOD TabInTable(PRBool inIsShift, PRBool *outHandled);
|
||||
NS_IMETHOD CreateBR(nsIDOMNode *aNode, PRInt32 aOffset,
|
||||
nsCOMPtr<nsIDOMNode> *outBRNode, EDirection aSelect = eNone);
|
||||
NS_IMETHOD JoeCreateBR(nsCOMPtr<nsIDOMNode> *aInOutParent,
|
||||
NS_IMETHOD CreateBRImpl(nsCOMPtr<nsIDOMNode> *aInOutParent,
|
||||
PRInt32 *aInOutOffset,
|
||||
nsCOMPtr<nsIDOMNode> *outBRNode,
|
||||
EDirection aSelect);
|
||||
|
@ -488,7 +489,9 @@ protected:
|
|||
nsIAtom *aProperty,
|
||||
const nsString *aAttribute,
|
||||
PRBool aChildrenOnly = PR_FALSE);
|
||||
|
||||
nsresult RemoveInlinePropertyImpl(nsIAtom *aProperty, const nsString *aAttribute);
|
||||
|
||||
PRBool NodeIsProperty(nsIDOMNode *aNode);
|
||||
PRBool HasAttr(nsIDOMNode *aNode, const nsString *aAttribute);
|
||||
PRBool HasAttrVal(nsIDOMNode *aNode, const nsString *aAttribute, const nsString *aValue);
|
||||
PRBool IsAtFrontOfNode(nsIDOMNode *aNode, PRInt32 aOffset);
|
||||
|
|
|
@ -610,7 +610,7 @@ nsTextEditRules::WillInsertText(PRInt32 aAction,
|
|||
|
||||
if (aAction == kInsertTextIME)
|
||||
{
|
||||
res = mEditor->JoeInsertTextImpl(*outString, &selNode, &selOffset, doc);
|
||||
res = mEditor->InsertTextImpl(*outString, &selNode, &selOffset, doc);
|
||||
if (NS_FAILED(res)) return res;
|
||||
}
|
||||
else // aAction == kInsertText
|
||||
|
@ -662,12 +662,12 @@ nsTextEditRules::WillInsertText(PRInt32 aAction,
|
|||
// is it a return?
|
||||
if (subStr.Equals("\n"))
|
||||
{
|
||||
res = mEditor->JoeCreateBR(&curNode, &curOffset, &unused, nsIEditor::eNone);
|
||||
res = mEditor->CreateBRImpl(&curNode, &curOffset, &unused, nsIEditor::eNone);
|
||||
pos++;
|
||||
}
|
||||
else
|
||||
{
|
||||
res = mEditor->JoeInsertTextImpl(subStr, &curNode, &curOffset, doc);
|
||||
res = mEditor->InsertTextImpl(subStr, &curNode, &curOffset, doc);
|
||||
}
|
||||
if (NS_FAILED(res)) return res;
|
||||
}
|
||||
|
@ -700,18 +700,18 @@ nsTextEditRules::WillInsertText(PRInt32 aAction,
|
|||
// is it a tab?
|
||||
if (subStr.Equals("\t"))
|
||||
{
|
||||
res = mEditor->JoeInsertTextImpl(tabString, &curNode, &curOffset, doc);
|
||||
res = mEditor->InsertTextImpl(tabString, &curNode, &curOffset, doc);
|
||||
pos++;
|
||||
}
|
||||
// is it a return?
|
||||
else if (subStr.Equals("\n"))
|
||||
{
|
||||
res = mEditor->JoeCreateBR(&curNode, &curOffset, &unused, nsIEditor::eNone);
|
||||
res = mEditor->CreateBRImpl(&curNode, &curOffset, &unused, nsIEditor::eNone);
|
||||
pos++;
|
||||
}
|
||||
else
|
||||
{
|
||||
res = mEditor->JoeInsertTextImpl(subStr, &curNode, &curOffset, doc);
|
||||
res = mEditor->InsertTextImpl(subStr, &curNode, &curOffset, doc);
|
||||
}
|
||||
if (NS_FAILED(res)) return res;
|
||||
}
|
||||
|
|
|
@ -854,17 +854,7 @@ nsEditorShell::RemoveOneProperty(const nsString& aProp, const nsString &aAttr)
|
|||
NS_IMETHODIMP
|
||||
nsEditorShell::RemoveTextProperty(const PRUnichar *prop, const PRUnichar *attr)
|
||||
{
|
||||
// OK, I'm really hacking now. This is just so that we can accept 'all' as input.
|
||||
// this logic should live elsewhere.
|
||||
//TODO: FIX THIS! IT IS WRONG! IT DOESN'T CONSIDER ALL THE
|
||||
// OTHER POSSIBLE TEXT ATTRIBUTES!
|
||||
static const char* sAllKnownStyles[] = {
|
||||
"b",
|
||||
"i",
|
||||
"u",
|
||||
nsnull // this null is important
|
||||
};
|
||||
|
||||
// OK, I'm really hacking now. This is just so that we can accept 'all' as input.
|
||||
nsAutoString allStr(prop);
|
||||
nsAutoString aAttr(attr);
|
||||
|
||||
|
@ -874,19 +864,7 @@ nsEditorShell::RemoveTextProperty(const PRUnichar *prop, const PRUnichar *attr)
|
|||
|
||||
if (doingAll)
|
||||
{
|
||||
nsAutoString thisAttr;
|
||||
const char **tagName = sAllKnownStyles;
|
||||
|
||||
while (*tagName)
|
||||
{
|
||||
thisAttr.Truncate(0);
|
||||
thisAttr += (char *)(*tagName);
|
||||
|
||||
err = RemoveOneProperty(thisAttr, aAttr);
|
||||
|
||||
tagName ++;
|
||||
}
|
||||
|
||||
err = mEditor->RemoveAllInlineProperties();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -96,7 +96,6 @@
|
|||
#include "nsEditor.h"
|
||||
#include "nsEditorUtils.h"
|
||||
|
||||
|
||||
#ifdef HACK_FORCE_REDRAW
|
||||
// INCLUDES FOR EVIL HACK TO FOR REDRAW
|
||||
// BEGIN
|
||||
|
@ -2491,7 +2490,7 @@ nsresult nsEditor::GetTextNodeTag(nsString& aOutString)
|
|||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsEditor::JoeInsertTextImpl(const nsString& aStringToInsert,
|
||||
NS_IMETHODIMP nsEditor::InsertTextImpl(const nsString& aStringToInsert,
|
||||
nsCOMPtr<nsIDOMNode> *aInOutNode,
|
||||
PRInt32 *aInOutOffset,
|
||||
nsIDOMDocument *aDoc)
|
||||
|
@ -2501,7 +2500,7 @@ NS_IMETHODIMP nsEditor::JoeInsertTextImpl(const nsString& aStringToInsert,
|
|||
// if desired.
|
||||
|
||||
if (!aInOutNode || !*aInOutNode || !aInOutOffset || !aDoc) return NS_ERROR_NULL_POINTER;
|
||||
if (aStringToInsert.IsEmpty()) return NS_OK;
|
||||
if (!mInIMEMode && aStringToInsert.IsEmpty()) return NS_OK;
|
||||
nsCOMPtr<nsIDOMText> nodeAsText = do_QueryInterface(*aInOutNode);
|
||||
PRInt32 offset = *aInOutOffset;
|
||||
nsresult res;
|
||||
|
@ -2520,7 +2519,7 @@ NS_IMETHODIMP nsEditor::JoeInsertTextImpl(const nsString& aStringToInsert,
|
|||
if (NS_FAILED(res)) return res;
|
||||
offset = 0;
|
||||
}
|
||||
res = JoeInsertTextIntoTextNodeImpl(aStringToInsert, nodeAsText, offset);
|
||||
res = InsertTextIntoTextNodeImpl(aStringToInsert, nodeAsText, offset);
|
||||
if (NS_FAILED(res)) return res;
|
||||
}
|
||||
else
|
||||
|
@ -2528,7 +2527,7 @@ NS_IMETHODIMP nsEditor::JoeInsertTextImpl(const nsString& aStringToInsert,
|
|||
if (nodeAsText)
|
||||
{
|
||||
// we are inserting text into an existing text node.
|
||||
res = JoeInsertTextIntoTextNodeImpl(aStringToInsert, nodeAsText, offset);
|
||||
res = InsertTextIntoTextNodeImpl(aStringToInsert, nodeAsText, offset);
|
||||
if (NS_FAILED(res)) return res;
|
||||
*aInOutOffset += aStringToInsert.Length();
|
||||
}
|
||||
|
@ -2552,7 +2551,7 @@ NS_IMETHODIMP nsEditor::JoeInsertTextImpl(const nsString& aStringToInsert,
|
|||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsEditor::JoeInsertTextIntoTextNodeImpl(const nsString& aStringToInsert,
|
||||
NS_IMETHODIMP nsEditor::InsertTextIntoTextNodeImpl(const nsString& aStringToInsert,
|
||||
nsIDOMCharacterData *aTextNode,
|
||||
PRInt32 aOffset)
|
||||
{
|
||||
|
|
|
@ -299,11 +299,11 @@ public:
|
|||
public:
|
||||
|
||||
|
||||
NS_IMETHOD JoeInsertTextImpl(const nsString& aStringToInsert,
|
||||
NS_IMETHOD InsertTextImpl(const nsString& aStringToInsert,
|
||||
nsCOMPtr<nsIDOMNode> *aInOutNode,
|
||||
PRInt32 *aInOutOffset,
|
||||
nsIDOMDocument *aDoc);
|
||||
NS_IMETHOD JoeInsertTextIntoTextNodeImpl(const nsString& aStringToInsert,
|
||||
NS_IMETHOD InsertTextIntoTextNodeImpl(const nsString& aStringToInsert,
|
||||
nsIDOMCharacterData *aTextNode,
|
||||
PRInt32 aOffset);
|
||||
NS_IMETHOD DeleteSelectionImpl(EDirection aAction);
|
||||
|
|
|
@ -210,9 +210,13 @@ nsHTMLEditRules::AfterEdit(PRInt32 action, nsIEditor::EDirection aDirection)
|
|||
if (NS_FAILED(res)) return res;
|
||||
|
||||
// merge any adjacent text nodes
|
||||
res = mEditor->CollapseAdjacentTextNodes(mDocChangeRange);
|
||||
if (NS_FAILED(res)) return res;
|
||||
|
||||
if ( (action != nsEditor::kOpInsertText &&
|
||||
action != nsEditor::kOpInsertIMEText) )
|
||||
{
|
||||
res = mEditor->CollapseAdjacentTextNodes(mDocChangeRange);
|
||||
if (NS_FAILED(res)) return res;
|
||||
}
|
||||
|
||||
// adjust whitespace for insert text and delete actions
|
||||
if ((action == nsEditor::kOpInsertText) ||
|
||||
(action == nsEditor::kOpInsertIMEText) ||
|
||||
|
@ -404,7 +408,7 @@ nsHTMLEditRules::WillInsertText(PRInt32 aAction,
|
|||
|
||||
if (aAction == kInsertTextIME)
|
||||
{
|
||||
res = mEditor->JoeInsertTextImpl(*inString, &selNode, &selOffset, doc);
|
||||
res = mEditor->InsertTextImpl(*inString, &selNode, &selOffset, doc);
|
||||
if (NS_FAILED(res)) return res;
|
||||
}
|
||||
else // aAction == kInsertText
|
||||
|
@ -462,12 +466,12 @@ nsHTMLEditRules::WillInsertText(PRInt32 aAction,
|
|||
// is it a return?
|
||||
if (subStr.Equals("\n"))
|
||||
{
|
||||
res = mEditor->JoeCreateBR(&curNode, &curOffset, &unused, nsIEditor::eNone);
|
||||
res = mEditor->CreateBRImpl(&curNode, &curOffset, &unused, nsIEditor::eNone);
|
||||
pos++;
|
||||
}
|
||||
else
|
||||
{
|
||||
res = mEditor->JoeInsertTextImpl(subStr, &curNode, &curOffset, doc);
|
||||
res = mEditor->InsertTextImpl(subStr, &curNode, &curOffset, doc);
|
||||
}
|
||||
if (NS_FAILED(res)) return res;
|
||||
}
|
||||
|
@ -500,18 +504,18 @@ nsHTMLEditRules::WillInsertText(PRInt32 aAction,
|
|||
// is it a tab?
|
||||
if (subStr.Equals("\t"))
|
||||
{
|
||||
res = mEditor->JoeInsertTextImpl(tabString, &curNode, &curOffset, doc);
|
||||
res = mEditor->InsertTextImpl(tabString, &curNode, &curOffset, doc);
|
||||
pos++;
|
||||
}
|
||||
// is it a return?
|
||||
else if (subStr.Equals("\n"))
|
||||
{
|
||||
res = mEditor->JoeCreateBR(&curNode, &curOffset, &unused, nsIEditor::eNone);
|
||||
res = mEditor->CreateBRImpl(&curNode, &curOffset, &unused, nsIEditor::eNone);
|
||||
pos++;
|
||||
}
|
||||
else
|
||||
{
|
||||
res = mEditor->JoeInsertTextImpl(subStr, &curNode, &curOffset, doc);
|
||||
res = mEditor->InsertTextImpl(subStr, &curNode, &curOffset, doc);
|
||||
}
|
||||
if (NS_FAILED(res)) return res;
|
||||
}
|
||||
|
|
|
@ -717,6 +717,12 @@ NS_IMETHODIMP nsHTMLEditor::EditorKeyPress(nsIDOMKeyEvent* aKeyEvent)
|
|||
return TypedText(empty, eTypedBreak); // uses rules to figure out what to insert
|
||||
}
|
||||
}
|
||||
else if (keyCode == nsIDOMKeyEvent::DOM_VK_ESCAPE)
|
||||
{
|
||||
// pass escape keypresses through as empty strings: needed forime support
|
||||
nsAutoString empty;
|
||||
return TypedText(empty, eTypedText);
|
||||
}
|
||||
|
||||
// if we got here we either fell out of the tab case or have a normal character.
|
||||
// Either way, treat as normal character.
|
||||
|
@ -810,7 +816,7 @@ NS_IMETHODIMP nsHTMLEditor::TabInTable(PRBool inIsShift, PRBool *outHandled)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsHTMLEditor::JoeCreateBR(nsCOMPtr<nsIDOMNode> *aInOutParent, PRInt32 *aInOutOffset, nsCOMPtr<nsIDOMNode> *outBRNode, EDirection aSelect)
|
||||
NS_IMETHODIMP nsHTMLEditor::CreateBRImpl(nsCOMPtr<nsIDOMNode> *aInOutParent, PRInt32 *aInOutOffset, nsCOMPtr<nsIDOMNode> *outBRNode, EDirection aSelect)
|
||||
{
|
||||
if (!aInOutParent || !*aInOutParent || !aInOutOffset || !outBRNode) return NS_ERROR_NULL_POINTER;
|
||||
*outBRNode = nsnull;
|
||||
|
@ -891,7 +897,7 @@ NS_IMETHODIMP nsHTMLEditor::CreateBR(nsIDOMNode *aNode, PRInt32 aOffset, nsCOMPt
|
|||
{
|
||||
nsCOMPtr<nsIDOMNode> parent = aNode;
|
||||
PRInt32 offset = aOffset;
|
||||
return JoeCreateBR(&parent, &offset, outBRNode, aSelect);
|
||||
return CreateBRImpl(&parent, &offset, outBRNode, aSelect);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsHTMLEditor::InsertBR(nsCOMPtr<nsIDOMNode> *outBRNode)
|
||||
|
@ -1255,7 +1261,7 @@ nsresult nsHTMLEditor::SplitStyleAboveRange(nsIDOMRange *inRange,
|
|||
nsIAtom *aProperty,
|
||||
const nsString *aAttribute)
|
||||
{
|
||||
if (!inRange || !aProperty) return NS_ERROR_NULL_POINTER;
|
||||
if (!inRange) return NS_ERROR_NULL_POINTER;
|
||||
nsresult res;
|
||||
nsCOMPtr<nsIDOMNode> startNode, endNode, origStartNode;
|
||||
PRInt32 startOffset, endOffset, origStartOffset;
|
||||
|
@ -1296,7 +1302,7 @@ nsresult nsHTMLEditor::SplitStyleAboveRange(nsIDOMRange *inRange,
|
|||
|
||||
nsresult nsHTMLEditor::SplitStyleAbovePoint(nsCOMPtr<nsIDOMNode> *aNode,
|
||||
PRInt32 *aOffset,
|
||||
nsIAtom *aProperty,
|
||||
nsIAtom *aProperty, // null here means we split all properties
|
||||
const nsString *aAttribute)
|
||||
{
|
||||
if (!aNode || !*aNode || !aOffset) return NS_ERROR_NULL_POINTER;
|
||||
|
@ -1305,7 +1311,8 @@ nsresult nsHTMLEditor::SplitStyleAbovePoint(nsCOMPtr<nsIDOMNode> *aNode,
|
|||
PRInt32 offset;
|
||||
while (tmp && !nsHTMLEditUtils::IsBody(tmp))
|
||||
{
|
||||
if (NodeIsType(tmp, aProperty))
|
||||
if ( (aProperty && NodeIsType(tmp, aProperty)) || // node is the correct inline prop
|
||||
(!aProperty && NodeIsProperty(tmp)) ) // or node is any prop, and we asked to split them all
|
||||
{
|
||||
// found a style node we need to split
|
||||
SplitNodeDeep(tmp, *aNode, *aOffset, &offset);
|
||||
|
@ -1318,13 +1325,23 @@ nsresult nsHTMLEditor::SplitStyleAbovePoint(nsCOMPtr<nsIDOMNode> *aNode,
|
|||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
PRBool nsHTMLEditor::NodeIsProperty(nsIDOMNode *aNode)
|
||||
{
|
||||
if (!aNode) return PR_FALSE;
|
||||
if (!IsContainer(aNode)) return PR_FALSE;
|
||||
if (!IsEditable(aNode)) return PR_FALSE;
|
||||
if (!IsInlineNode(aNode)) return PR_FALSE;
|
||||
if (NodeIsType(aNode, nsIEditProperty::a)) return PR_FALSE;
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
nsresult nsHTMLEditor::RemoveStyleInside(nsIDOMNode *aNode,
|
||||
nsIAtom *aProperty,
|
||||
nsIAtom *aProperty, // null here means remove all properties
|
||||
const nsString *aAttribute,
|
||||
PRBool aChildrenOnly)
|
||||
{
|
||||
if (!aNode || !aProperty) return NS_ERROR_NULL_POINTER;
|
||||
if (!aNode) return NS_ERROR_NULL_POINTER;
|
||||
if (IsTextNode(aNode)) return NS_OK;
|
||||
nsresult res = NS_OK;
|
||||
|
||||
|
@ -1341,7 +1358,9 @@ nsresult nsHTMLEditor::RemoveStyleInside(nsIDOMNode *aNode,
|
|||
}
|
||||
|
||||
// then process the node itself
|
||||
if (!aChildrenOnly && NodeIsType(aNode, aProperty))
|
||||
if ( !aChildrenOnly &&
|
||||
(aProperty && NodeIsType(aNode, aProperty)) || // node is prop we wasked for
|
||||
(!aProperty && NodeIsProperty(aNode)) ) // or node is any prop and we asked for that
|
||||
{
|
||||
// if we weren't passed an attribute, then we want to
|
||||
// remove any matching inlinestyles entirely
|
||||
|
@ -1773,9 +1792,19 @@ NS_IMETHODIMP nsHTMLEditor::GetInlineProperty(nsIAtom *aProperty,
|
|||
return result;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsHTMLEditor::RemoveAllInlineProperties()
|
||||
{
|
||||
return RemoveInlinePropertyImpl(nsnull, nsnull);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsHTMLEditor::RemoveInlineProperty(nsIAtom *aProperty, const nsString *aAttribute)
|
||||
{
|
||||
if (!aProperty) return NS_ERROR_NULL_POINTER;
|
||||
return RemoveInlinePropertyImpl(aProperty, aAttribute);
|
||||
}
|
||||
|
||||
nsresult nsHTMLEditor::RemoveInlinePropertyImpl(nsIAtom *aProperty, const nsString *aAttribute)
|
||||
{
|
||||
if (!mRules) return NS_ERROR_NOT_INITIALIZED;
|
||||
ForceCompositionEnd();
|
||||
|
||||
|
@ -1790,7 +1819,8 @@ NS_IMETHODIMP nsHTMLEditor::RemoveInlineProperty(nsIAtom *aProperty, const nsStr
|
|||
if (isCollapsed)
|
||||
{
|
||||
// manipulating text attributes on a collapsed selection only sets state for the next text insertion
|
||||
return mTypeInState->ClearProp(aProperty, *aAttribute);
|
||||
if (aProperty) return mTypeInState->ClearProp(aProperty, *aAttribute);
|
||||
// else return mTypeInState->ClearAllProps();
|
||||
}
|
||||
nsAutoEditBatch batchIt(this);
|
||||
nsAutoRules beginRulesSniffing(this, kOpRemoveTextProperty, nsIEditor::eNext);
|
||||
|
|
|
@ -103,6 +103,7 @@ public:
|
|||
const nsString *aValue,
|
||||
PRBool &aFirst, PRBool &aAny, PRBool &aAll);
|
||||
|
||||
NS_IMETHOD RemoveAllInlineProperties();
|
||||
NS_IMETHOD RemoveInlineProperty(nsIAtom *aProperty, const nsString *aAttribute);
|
||||
NS_IMETHOD IncreaseFontSize();
|
||||
NS_IMETHOD DecreaseFontSize();
|
||||
|
@ -356,7 +357,7 @@ protected:
|
|||
NS_IMETHOD TabInTable(PRBool inIsShift, PRBool *outHandled);
|
||||
NS_IMETHOD CreateBR(nsIDOMNode *aNode, PRInt32 aOffset,
|
||||
nsCOMPtr<nsIDOMNode> *outBRNode, EDirection aSelect = eNone);
|
||||
NS_IMETHOD JoeCreateBR(nsCOMPtr<nsIDOMNode> *aInOutParent,
|
||||
NS_IMETHOD CreateBRImpl(nsCOMPtr<nsIDOMNode> *aInOutParent,
|
||||
PRInt32 *aInOutOffset,
|
||||
nsCOMPtr<nsIDOMNode> *outBRNode,
|
||||
EDirection aSelect);
|
||||
|
@ -488,7 +489,9 @@ protected:
|
|||
nsIAtom *aProperty,
|
||||
const nsString *aAttribute,
|
||||
PRBool aChildrenOnly = PR_FALSE);
|
||||
|
||||
nsresult RemoveInlinePropertyImpl(nsIAtom *aProperty, const nsString *aAttribute);
|
||||
|
||||
PRBool NodeIsProperty(nsIDOMNode *aNode);
|
||||
PRBool HasAttr(nsIDOMNode *aNode, const nsString *aAttribute);
|
||||
PRBool HasAttrVal(nsIDOMNode *aNode, const nsString *aAttribute, const nsString *aValue);
|
||||
PRBool IsAtFrontOfNode(nsIDOMNode *aNode, PRInt32 aOffset);
|
||||
|
|
|
@ -610,7 +610,7 @@ nsTextEditRules::WillInsertText(PRInt32 aAction,
|
|||
|
||||
if (aAction == kInsertTextIME)
|
||||
{
|
||||
res = mEditor->JoeInsertTextImpl(*outString, &selNode, &selOffset, doc);
|
||||
res = mEditor->InsertTextImpl(*outString, &selNode, &selOffset, doc);
|
||||
if (NS_FAILED(res)) return res;
|
||||
}
|
||||
else // aAction == kInsertText
|
||||
|
@ -662,12 +662,12 @@ nsTextEditRules::WillInsertText(PRInt32 aAction,
|
|||
// is it a return?
|
||||
if (subStr.Equals("\n"))
|
||||
{
|
||||
res = mEditor->JoeCreateBR(&curNode, &curOffset, &unused, nsIEditor::eNone);
|
||||
res = mEditor->CreateBRImpl(&curNode, &curOffset, &unused, nsIEditor::eNone);
|
||||
pos++;
|
||||
}
|
||||
else
|
||||
{
|
||||
res = mEditor->JoeInsertTextImpl(subStr, &curNode, &curOffset, doc);
|
||||
res = mEditor->InsertTextImpl(subStr, &curNode, &curOffset, doc);
|
||||
}
|
||||
if (NS_FAILED(res)) return res;
|
||||
}
|
||||
|
@ -700,18 +700,18 @@ nsTextEditRules::WillInsertText(PRInt32 aAction,
|
|||
// is it a tab?
|
||||
if (subStr.Equals("\t"))
|
||||
{
|
||||
res = mEditor->JoeInsertTextImpl(tabString, &curNode, &curOffset, doc);
|
||||
res = mEditor->InsertTextImpl(tabString, &curNode, &curOffset, doc);
|
||||
pos++;
|
||||
}
|
||||
// is it a return?
|
||||
else if (subStr.Equals("\n"))
|
||||
{
|
||||
res = mEditor->JoeCreateBR(&curNode, &curOffset, &unused, nsIEditor::eNone);
|
||||
res = mEditor->CreateBRImpl(&curNode, &curOffset, &unused, nsIEditor::eNone);
|
||||
pos++;
|
||||
}
|
||||
else
|
||||
{
|
||||
res = mEditor->JoeInsertTextImpl(subStr, &curNode, &curOffset, doc);
|
||||
res = mEditor->InsertTextImpl(subStr, &curNode, &curOffset, doc);
|
||||
}
|
||||
if (NS_FAILED(res)) return res;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче