зеркало из https://github.com/mozilla/pjs.git
vastly improved type-in state handling. smaller and faster
This commit is contained in:
Родитель
9acac7c2ed
Коммит
d00b8638a3
|
@ -20,6 +20,7 @@
|
|||
#define ChangeAttributeTxn_h__
|
||||
|
||||
#include "nsIDOMSelectionListener.h"
|
||||
#include "nsIEditProperty.h"
|
||||
|
||||
class TypeInState : public nsIDOMSelectionListener
|
||||
{
|
||||
|
@ -33,6 +34,12 @@ public:
|
|||
|
||||
NS_IMETHOD NotifySelectionChanged();
|
||||
|
||||
void GetEnumForName(nsIAtom *aPropName, PRUint32 &aEnum);
|
||||
|
||||
void SetProp(PRUint32 aProp, PRBool aSet);
|
||||
|
||||
void SetPropValue(PRUint32 aProp, const nsString &aValue);
|
||||
|
||||
PRBool IsSet(PRUint32 aStyle);
|
||||
PRBool IsAnySet();
|
||||
void UnSet(PRUint32 aStyle);
|
||||
|
@ -46,14 +53,14 @@ public:
|
|||
void SetUnderline(PRBool aIsSet);
|
||||
PRBool GetUnderline();
|
||||
|
||||
void SetFontFace(nsString aFace);
|
||||
nsString GetFontFace();
|
||||
void SetFontFace(const nsString &aFace);
|
||||
void GetFontFace(nsString &aFace);
|
||||
|
||||
void SetFontColor(nsString aColor);
|
||||
nsString GetFontColor();
|
||||
void SetFontColor(const nsString &aColor);
|
||||
void GetFontColor(nsString &aColor);
|
||||
|
||||
void SetFontSize(nsString aFontSize);
|
||||
nsString GetFontSize();
|
||||
void SetFontSize(const nsString &aSize);
|
||||
void GetFontSize(nsString &aSize);
|
||||
|
||||
protected:
|
||||
PRBool mBold;
|
||||
|
@ -65,6 +72,7 @@ protected:
|
|||
PRUint32 mIsSet;
|
||||
};
|
||||
|
||||
#define NS_TYPEINSTATE_UNKNOWN 0x00000000
|
||||
#define NS_TYPEINSTATE_BOLD 0x00000001
|
||||
#define NS_TYPEINSTATE_ITALIC 0x00000002
|
||||
#define NS_TYPEINSTATE_UNDERLINE 0x00000004
|
||||
|
@ -88,6 +96,51 @@ TypeInState::TypeInState()
|
|||
NS_INIT_REFCNT();
|
||||
Reset();
|
||||
};
|
||||
|
||||
inline
|
||||
void TypeInState::GetEnumForName(nsIAtom *aPropName, PRUint32 &aEnum)
|
||||
{
|
||||
aEnum = NS_TYPEINSTATE_UNKNOWN;
|
||||
if (nsIEditProperty::b==aPropName) { aEnum = NS_TYPEINSTATE_BOLD; }
|
||||
else if (nsIEditProperty::i==aPropName) { aEnum = NS_TYPEINSTATE_ITALIC; }
|
||||
else if (nsIEditProperty::u==aPropName) { aEnum = NS_TYPEINSTATE_UNDERLINE; }
|
||||
else if (nsIEditProperty::face==aPropName) { aEnum = NS_TYPEINSTATE_FONTFACE; }
|
||||
else if (nsIEditProperty::color==aPropName) { aEnum = NS_TYPEINSTATE_FONTCOLOR; }
|
||||
else if (nsIEditProperty::size==aPropName) { aEnum = NS_TYPEINSTATE_FONTSIZE; }
|
||||
}
|
||||
|
||||
inline void TypeInState::SetProp(PRUint32 aProp, PRBool aSet)
|
||||
{
|
||||
switch (aProp)
|
||||
{
|
||||
case NS_TYPEINSTATE_BOLD:
|
||||
SetBold(aSet);
|
||||
break;
|
||||
case NS_TYPEINSTATE_ITALIC:
|
||||
SetItalic(aSet);
|
||||
break;
|
||||
case NS_TYPEINSTATE_UNDERLINE:
|
||||
SetUnderline(aSet);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
inline void TypeInState::SetPropValue(PRUint32 aProp, const nsString &aValue)
|
||||
{
|
||||
switch (aProp)
|
||||
{
|
||||
case NS_TYPEINSTATE_FONTFACE:
|
||||
SetFontFace(aValue);
|
||||
break;
|
||||
case NS_TYPEINSTATE_FONTCOLOR:
|
||||
SetFontColor(aValue);
|
||||
break;
|
||||
case NS_TYPEINSTATE_FONTSIZE:
|
||||
SetFontSize(aValue);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
inline
|
||||
PRBool TypeInState::IsSet(PRUint32 aStyle)
|
||||
|
@ -144,37 +197,37 @@ PRBool TypeInState::GetUnderline()
|
|||
{ return mUnderline; };
|
||||
|
||||
inline
|
||||
void TypeInState::SetFontFace(nsString aFace)
|
||||
void TypeInState::SetFontFace(const nsString &aFace)
|
||||
{
|
||||
mFontFace = aFace;
|
||||
mIsSet |= NS_TYPEINSTATE_FONTFACE;
|
||||
};
|
||||
|
||||
inline
|
||||
nsString TypeInState::GetFontFace()
|
||||
{ return mFontFace; };
|
||||
void TypeInState::GetFontFace(nsString &aFace)
|
||||
{ aFace = mFontFace; };
|
||||
|
||||
inline
|
||||
void TypeInState::SetFontColor(nsString aColor)
|
||||
void TypeInState::SetFontColor(const nsString &aColor)
|
||||
{
|
||||
mFontColor = aColor;
|
||||
mIsSet |= NS_TYPEINSTATE_FONTCOLOR;
|
||||
};
|
||||
|
||||
inline
|
||||
nsString TypeInState::GetFontColor()
|
||||
{ return mFontColor; };
|
||||
void TypeInState::GetFontColor(nsString &aColor)
|
||||
{ aColor = mFontColor; };
|
||||
|
||||
inline
|
||||
void TypeInState::SetFontSize(nsString aSize)
|
||||
void TypeInState::SetFontSize(const nsString &aSize)
|
||||
{
|
||||
mFontSize = aSize;
|
||||
mIsSet |= NS_TYPEINSTATE_FONTSIZE;
|
||||
};
|
||||
|
||||
inline
|
||||
nsString TypeInState::GetFontSize()
|
||||
{ return mFontSize; };
|
||||
void TypeInState::GetFontSize(nsString &aSize)
|
||||
{ aSize = mFontSize; };
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -42,6 +42,7 @@ nsIAtom * nsIEditProperty::sup;
|
|||
nsIAtom * nsIEditProperty::tt;
|
||||
nsIAtom * nsIEditProperty::u;
|
||||
// block tags
|
||||
nsIAtom * nsIEditProperty::blockquote;
|
||||
nsIAtom * nsIEditProperty::h1;
|
||||
nsIAtom * nsIEditProperty::h2;
|
||||
// properties
|
||||
|
@ -68,6 +69,7 @@ nsEditProperty::InstanceInit()
|
|||
nsIEditProperty::tt = NS_NewAtom("TT");
|
||||
nsIEditProperty::u = NS_NewAtom("U");
|
||||
// tags
|
||||
nsIEditProperty::blockquote = NS_NewAtom("BLOCKQUOTE");
|
||||
nsIEditProperty::h1 = NS_NewAtom("H1");
|
||||
nsIEditProperty::h2 = NS_NewAtom("H2");
|
||||
// properties
|
||||
|
@ -95,6 +97,7 @@ nsEditProperty::InstanceShutdown()
|
|||
NS_IF_RELEASE(nsIEditProperty::tt);
|
||||
NS_IF_RELEASE(nsIEditProperty::u);
|
||||
// tags
|
||||
NS_IF_RELEASE(nsIEditProperty::blockquote);
|
||||
NS_IF_RELEASE(nsIEditProperty::h1);
|
||||
NS_IF_RELEASE(nsIEditProperty::h2);
|
||||
// properties
|
||||
|
|
|
@ -434,13 +434,20 @@ nsTextEditorKeyListener::ProcessShortCutKeys(nsIDOMEvent* aKeyEvent, PRBool& aPr
|
|||
PRBool first = PR_FALSE;
|
||||
nsAutoString color = "COLOR";
|
||||
nsAutoString value = "red";
|
||||
mEditor->SetTextProperty(nsIEditProperty::font, &color, &value);
|
||||
mEditor->GetTextProperty(nsIEditProperty::font, &color, &value, first, any, all);
|
||||
if (!all) {
|
||||
mEditor->SetTextProperty(nsIEditProperty::font, &color, &value);
|
||||
}
|
||||
else {
|
||||
printf("NOOP: all selected text is already red\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
// hard-coded ChangeTextAttributes test -- font color green
|
||||
// hard-coded ChangeTextAttributes test -- remove font color
|
||||
case nsIDOMEvent::VK_2:
|
||||
case nsIDOMEvent::VK_R:
|
||||
if (PR_TRUE==ctrlKey)
|
||||
{
|
||||
aProcessed=PR_TRUE;
|
||||
|
@ -452,8 +459,13 @@ nsTextEditorKeyListener::ProcessShortCutKeys(nsIDOMEvent* aKeyEvent, PRBool& aPr
|
|||
PRBool all = PR_FALSE;
|
||||
PRBool first = PR_FALSE;
|
||||
nsAutoString color = "COLOR";
|
||||
nsAutoString value = "green";
|
||||
mEditor->SetTextProperty(nsIEditProperty::font, &color, &value);
|
||||
mEditor->GetTextProperty(nsIEditProperty::font, &color, nsnull, first, any, all);
|
||||
if (any) {
|
||||
mEditor->RemoveTextProperty(nsIEditProperty::font, &color);
|
||||
}
|
||||
else {
|
||||
printf("NOOP: no color set\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -496,7 +508,7 @@ nsTextEditorKeyListener::ProcessShortCutKeys(nsIDOMEvent* aKeyEvent, PRBool& aPr
|
|||
}
|
||||
break;
|
||||
|
||||
// hard-coded ChangeTextAttributes test -- font face helvetica
|
||||
// hard-coded ChangeTextAttributes test -- font face helvetica
|
||||
case nsIDOMEvent::VK_5:
|
||||
if (PR_TRUE==ctrlKey)
|
||||
{
|
||||
|
@ -554,7 +566,7 @@ nsTextEditorKeyListener::ProcessShortCutKeys(nsIDOMEvent* aKeyEvent, PRBool& aPr
|
|||
}
|
||||
break;
|
||||
|
||||
// hard-coded change structure test -- block H2
|
||||
// hard-coded change structure test -- block blockquote (indent)
|
||||
case nsIDOMEvent::VK_8:
|
||||
case nsIDOMEvent::VK_W:
|
||||
if (PR_TRUE==ctrlKey)
|
||||
|
@ -567,7 +579,7 @@ nsTextEditorKeyListener::ProcessShortCutKeys(nsIDOMEvent* aKeyEvent, PRBool& aPr
|
|||
if (htmlEditor)
|
||||
{
|
||||
nsAutoString tag;
|
||||
nsIEditProperty::h2->ToString(tag);
|
||||
nsIEditProperty::blockquote->ToString(tag);
|
||||
htmlEditor->AddBlockParent(tag);
|
||||
}
|
||||
}
|
||||
|
@ -591,6 +603,26 @@ nsTextEditorKeyListener::ProcessShortCutKeys(nsIDOMEvent* aKeyEvent, PRBool& aPr
|
|||
}
|
||||
break;
|
||||
|
||||
// hard-coded change structure test -- un-BlockQuote
|
||||
case nsIDOMEvent::VK_0:
|
||||
case nsIDOMEvent::VK_G:
|
||||
if (PR_TRUE==ctrlKey)
|
||||
{
|
||||
aProcessed=PR_TRUE;
|
||||
if (mEditor)
|
||||
{
|
||||
nsCOMPtr<nsIHTMLEditor>htmlEditor;
|
||||
htmlEditor = do_QueryInterface(mEditor);
|
||||
if (htmlEditor)
|
||||
{
|
||||
nsAutoString tag;
|
||||
nsIEditProperty::blockquote->ToString(tag);
|
||||
htmlEditor->RemoveParent(tag);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
#ifdef NS_DEBUG
|
||||
// hard-coded Text Editor Unit Test
|
||||
|
|
|
@ -72,6 +72,7 @@ SUP places text in superscript style
|
|||
*/
|
||||
|
||||
// block tags
|
||||
static nsIAtom *blockquote;
|
||||
static nsIAtom *h1;
|
||||
static nsIAtom *h2;
|
||||
|
||||
|
|
|
@ -330,7 +330,7 @@ nsTextEditRules::CreateStyleForInsertText(nsIDOMSelection *aSelection, TypeInSta
|
|||
if (aTypeInState.IsSet(NS_TYPEINSTATE_FONTCOLOR))
|
||||
{
|
||||
nsAutoString value;
|
||||
value = aTypeInState.GetFontColor();
|
||||
aTypeInState.GetFontColor(value);
|
||||
nsAutoString attr;
|
||||
nsIEditProperty::color->ToString(attr);
|
||||
result = CreateFontStyleForInsertText(newTextNode, attr, value, aSelection);
|
||||
|
@ -338,7 +338,7 @@ nsTextEditRules::CreateStyleForInsertText(nsIDOMSelection *aSelection, TypeInSta
|
|||
if (aTypeInState.IsSet(NS_TYPEINSTATE_FONTFACE))
|
||||
{
|
||||
nsAutoString value;
|
||||
value = aTypeInState.GetFontFace();
|
||||
aTypeInState.GetFontFace(value);
|
||||
nsAutoString attr;
|
||||
nsIEditProperty::face->ToString(attr);
|
||||
result = CreateFontStyleForInsertText(newTextNode, attr, value, aSelection);
|
||||
|
@ -346,7 +346,7 @@ nsTextEditRules::CreateStyleForInsertText(nsIDOMSelection *aSelection, TypeInSta
|
|||
if (aTypeInState.IsSet(NS_TYPEINSTATE_FONTSIZE))
|
||||
{
|
||||
nsAutoString value;
|
||||
value = aTypeInState.GetFontSize();
|
||||
aTypeInState.GetFontSize(value);
|
||||
nsAutoString attr;
|
||||
nsIEditProperty::size->ToString(attr);
|
||||
result = CreateFontStyleForInsertText(newTextNode, attr, value, aSelection);
|
||||
|
|
|
@ -1845,7 +1845,7 @@ NS_IMETHODIMP nsTextEditor::RemoveTextPropertiesForNode(nsIDOMNode *aNode,
|
|||
}
|
||||
}
|
||||
// else we've found the style tag (referred to by "parent")
|
||||
// nwMiddleNode is the node that is an ancestor to the selection
|
||||
// newMiddleNode is the node that is an ancestor to the selection
|
||||
else
|
||||
{
|
||||
if (gNoisy) { printf("* this is the style node\n");}
|
||||
|
@ -2227,11 +2227,13 @@ nsTextEditor::SetTypeInStateForProperty(TypeInState &aTypeInState,
|
|||
if (!aPropName) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
if (nsIEditProperty::b==aPropName)
|
||||
PRUint32 propEnum;
|
||||
aTypeInState.GetEnumForName(aPropName, propEnum);
|
||||
if (nsIEditProperty::b==aPropName || nsIEditProperty::i==aPropName || nsIEditProperty::u==aPropName)
|
||||
{
|
||||
if (PR_TRUE==aTypeInState.IsSet(NS_TYPEINSTATE_BOLD))
|
||||
if (PR_TRUE==aTypeInState.IsSet(propEnum))
|
||||
{ // toggle currently set boldness
|
||||
aTypeInState.UnSet(NS_TYPEINSTATE_BOLD);
|
||||
aTypeInState.UnSet(propEnum);
|
||||
}
|
||||
else
|
||||
{ // get the current style and set boldness to the opposite of the current state
|
||||
|
@ -2239,53 +2241,25 @@ nsTextEditor::SetTypeInStateForProperty(TypeInState &aTypeInState,
|
|||
PRBool all = PR_FALSE;
|
||||
PRBool first = PR_FALSE;
|
||||
GetTextProperty(aPropName, aAttribute, nsnull, first, any, all); // operates on current selection
|
||||
aTypeInState.SetBold(!any);
|
||||
aTypeInState.SetProp(propEnum, !any);
|
||||
}
|
||||
}
|
||||
else if (nsIEditProperty::i==aPropName)
|
||||
{
|
||||
if (PR_TRUE==aTypeInState.IsSet(NS_TYPEINSTATE_ITALIC))
|
||||
{ // toggle currently set italicness
|
||||
aTypeInState.UnSet(NS_TYPEINSTATE_ITALIC);
|
||||
}
|
||||
else
|
||||
{ // get the current style and set italic proper to the opposite of the current state
|
||||
PRBool any = PR_FALSE;
|
||||
PRBool all = PR_FALSE;
|
||||
PRBool first = PR_FALSE;
|
||||
GetTextProperty(aPropName, aAttribute, nsnull, first, any, all); // operates on current selection
|
||||
aTypeInState.SetItalic(!any);
|
||||
}
|
||||
}
|
||||
else if (nsIEditProperty::u==aPropName)
|
||||
{
|
||||
if (PR_TRUE==aTypeInState.IsSet(NS_TYPEINSTATE_UNDERLINE))
|
||||
{ // toggle currently set italicness
|
||||
aTypeInState.UnSet(NS_TYPEINSTATE_UNDERLINE);
|
||||
}
|
||||
else
|
||||
{ // get the current style and set underline prop to the opposite of the current state
|
||||
PRBool any = PR_FALSE;
|
||||
PRBool all = PR_FALSE;
|
||||
PRBool first = PR_FALSE;
|
||||
GetTextProperty(aPropName, aAttribute, nsnull, first, any, all); // operates on current selection
|
||||
aTypeInState.SetUnderline(!any);
|
||||
}
|
||||
}
|
||||
else if (nsIEditProperty::font==aPropName)
|
||||
{
|
||||
if (!aAttribute) { return NS_ERROR_NULL_POINTER; }
|
||||
nsIAtom *attribute = NS_NewAtom(*aAttribute);
|
||||
if (!attribute) { return NS_ERROR_NULL_POINTER; }
|
||||
if (nsIEditProperty::color==attribute)
|
||||
PRUint32 attrEnum;
|
||||
aTypeInState.GetEnumForName(attribute, attrEnum);
|
||||
if (nsIEditProperty::color==attribute || nsIEditProperty::face==attribute || nsIEditProperty::size==attribute)
|
||||
{
|
||||
if (PR_TRUE==aTypeInState.IsSet(NS_TYPEINSTATE_FONTCOLOR))
|
||||
if (PR_TRUE==aTypeInState.IsSet(attrEnum))
|
||||
{
|
||||
if (nsnull==aValue) {
|
||||
aTypeInState.UnSet(NS_TYPEINSTATE_FONTCOLOR);
|
||||
aTypeInState.UnSet(attrEnum);
|
||||
}
|
||||
else { // we're just changing the value of color
|
||||
aTypeInState.SetFontColor(*aValue);
|
||||
aTypeInState.SetPropValue(attrEnum, *aValue);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -2296,56 +2270,10 @@ nsTextEditor::SetTypeInStateForProperty(TypeInState &aTypeInState,
|
|||
PRBool first = PR_FALSE;
|
||||
GetTextProperty(aPropName, aAttribute, aValue, first, any, all); // operates on current selection
|
||||
if (PR_FALSE==all) {
|
||||
aTypeInState.SetFontColor(*aValue);
|
||||
aTypeInState.SetPropValue(attrEnum, *aValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (nsIEditProperty::face==attribute)
|
||||
{
|
||||
if (PR_TRUE==aTypeInState.IsSet(NS_TYPEINSTATE_FONTFACE))
|
||||
{
|
||||
if (nsnull==aValue) {
|
||||
aTypeInState.UnSet(NS_TYPEINSTATE_FONTFACE);
|
||||
}
|
||||
else { // we're just changing the value of color
|
||||
aTypeInState.SetFontFace(*aValue);
|
||||
}
|
||||
}
|
||||
else
|
||||
{ // get the current style and set font color if it's needed
|
||||
if (!aValue) { return NS_ERROR_NULL_POINTER; }
|
||||
PRBool any = PR_FALSE;
|
||||
PRBool all = PR_FALSE;
|
||||
PRBool first = PR_FALSE;
|
||||
GetTextProperty(aPropName, aAttribute, aValue, first, any, all); // operates on current selection
|
||||
if (PR_FALSE==all) {
|
||||
aTypeInState.SetFontFace(*aValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (nsIEditProperty::size==attribute)
|
||||
{
|
||||
if (PR_TRUE==aTypeInState.IsSet(NS_TYPEINSTATE_FONTSIZE))
|
||||
{
|
||||
if (nsnull==aValue) {
|
||||
aTypeInState.UnSet(NS_TYPEINSTATE_FONTSIZE);
|
||||
}
|
||||
else { // we're just changing the value of size
|
||||
aTypeInState.SetFontSize(*aValue);
|
||||
}
|
||||
}
|
||||
else
|
||||
{ // get the current style and set font color if it's needed
|
||||
if (!aValue) { return NS_ERROR_NULL_POINTER; }
|
||||
PRBool any = PR_FALSE;
|
||||
PRBool all = PR_FALSE;
|
||||
PRBool first = PR_FALSE;
|
||||
GetTextProperty(aPropName, aAttribute, aValue, first, any, all); // operates on current selection
|
||||
if (PR_FALSE==all) {
|
||||
aTypeInState.SetFontSize(*aValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
else { return NS_ERROR_FAILURE; }
|
||||
}
|
||||
else { return NS_ERROR_FAILURE; }
|
||||
|
|
|
@ -72,6 +72,7 @@ SUP places text in superscript style
|
|||
*/
|
||||
|
||||
// block tags
|
||||
static nsIAtom *blockquote;
|
||||
static nsIAtom *h1;
|
||||
static nsIAtom *h2;
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#define ChangeAttributeTxn_h__
|
||||
|
||||
#include "nsIDOMSelectionListener.h"
|
||||
#include "nsIEditProperty.h"
|
||||
|
||||
class TypeInState : public nsIDOMSelectionListener
|
||||
{
|
||||
|
@ -33,6 +34,12 @@ public:
|
|||
|
||||
NS_IMETHOD NotifySelectionChanged();
|
||||
|
||||
void GetEnumForName(nsIAtom *aPropName, PRUint32 &aEnum);
|
||||
|
||||
void SetProp(PRUint32 aProp, PRBool aSet);
|
||||
|
||||
void SetPropValue(PRUint32 aProp, const nsString &aValue);
|
||||
|
||||
PRBool IsSet(PRUint32 aStyle);
|
||||
PRBool IsAnySet();
|
||||
void UnSet(PRUint32 aStyle);
|
||||
|
@ -46,14 +53,14 @@ public:
|
|||
void SetUnderline(PRBool aIsSet);
|
||||
PRBool GetUnderline();
|
||||
|
||||
void SetFontFace(nsString aFace);
|
||||
nsString GetFontFace();
|
||||
void SetFontFace(const nsString &aFace);
|
||||
void GetFontFace(nsString &aFace);
|
||||
|
||||
void SetFontColor(nsString aColor);
|
||||
nsString GetFontColor();
|
||||
void SetFontColor(const nsString &aColor);
|
||||
void GetFontColor(nsString &aColor);
|
||||
|
||||
void SetFontSize(nsString aFontSize);
|
||||
nsString GetFontSize();
|
||||
void SetFontSize(const nsString &aSize);
|
||||
void GetFontSize(nsString &aSize);
|
||||
|
||||
protected:
|
||||
PRBool mBold;
|
||||
|
@ -65,6 +72,7 @@ protected:
|
|||
PRUint32 mIsSet;
|
||||
};
|
||||
|
||||
#define NS_TYPEINSTATE_UNKNOWN 0x00000000
|
||||
#define NS_TYPEINSTATE_BOLD 0x00000001
|
||||
#define NS_TYPEINSTATE_ITALIC 0x00000002
|
||||
#define NS_TYPEINSTATE_UNDERLINE 0x00000004
|
||||
|
@ -88,6 +96,51 @@ TypeInState::TypeInState()
|
|||
NS_INIT_REFCNT();
|
||||
Reset();
|
||||
};
|
||||
|
||||
inline
|
||||
void TypeInState::GetEnumForName(nsIAtom *aPropName, PRUint32 &aEnum)
|
||||
{
|
||||
aEnum = NS_TYPEINSTATE_UNKNOWN;
|
||||
if (nsIEditProperty::b==aPropName) { aEnum = NS_TYPEINSTATE_BOLD; }
|
||||
else if (nsIEditProperty::i==aPropName) { aEnum = NS_TYPEINSTATE_ITALIC; }
|
||||
else if (nsIEditProperty::u==aPropName) { aEnum = NS_TYPEINSTATE_UNDERLINE; }
|
||||
else if (nsIEditProperty::face==aPropName) { aEnum = NS_TYPEINSTATE_FONTFACE; }
|
||||
else if (nsIEditProperty::color==aPropName) { aEnum = NS_TYPEINSTATE_FONTCOLOR; }
|
||||
else if (nsIEditProperty::size==aPropName) { aEnum = NS_TYPEINSTATE_FONTSIZE; }
|
||||
}
|
||||
|
||||
inline void TypeInState::SetProp(PRUint32 aProp, PRBool aSet)
|
||||
{
|
||||
switch (aProp)
|
||||
{
|
||||
case NS_TYPEINSTATE_BOLD:
|
||||
SetBold(aSet);
|
||||
break;
|
||||
case NS_TYPEINSTATE_ITALIC:
|
||||
SetItalic(aSet);
|
||||
break;
|
||||
case NS_TYPEINSTATE_UNDERLINE:
|
||||
SetUnderline(aSet);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
inline void TypeInState::SetPropValue(PRUint32 aProp, const nsString &aValue)
|
||||
{
|
||||
switch (aProp)
|
||||
{
|
||||
case NS_TYPEINSTATE_FONTFACE:
|
||||
SetFontFace(aValue);
|
||||
break;
|
||||
case NS_TYPEINSTATE_FONTCOLOR:
|
||||
SetFontColor(aValue);
|
||||
break;
|
||||
case NS_TYPEINSTATE_FONTSIZE:
|
||||
SetFontSize(aValue);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
inline
|
||||
PRBool TypeInState::IsSet(PRUint32 aStyle)
|
||||
|
@ -144,37 +197,37 @@ PRBool TypeInState::GetUnderline()
|
|||
{ return mUnderline; };
|
||||
|
||||
inline
|
||||
void TypeInState::SetFontFace(nsString aFace)
|
||||
void TypeInState::SetFontFace(const nsString &aFace)
|
||||
{
|
||||
mFontFace = aFace;
|
||||
mIsSet |= NS_TYPEINSTATE_FONTFACE;
|
||||
};
|
||||
|
||||
inline
|
||||
nsString TypeInState::GetFontFace()
|
||||
{ return mFontFace; };
|
||||
void TypeInState::GetFontFace(nsString &aFace)
|
||||
{ aFace = mFontFace; };
|
||||
|
||||
inline
|
||||
void TypeInState::SetFontColor(nsString aColor)
|
||||
void TypeInState::SetFontColor(const nsString &aColor)
|
||||
{
|
||||
mFontColor = aColor;
|
||||
mIsSet |= NS_TYPEINSTATE_FONTCOLOR;
|
||||
};
|
||||
|
||||
inline
|
||||
nsString TypeInState::GetFontColor()
|
||||
{ return mFontColor; };
|
||||
void TypeInState::GetFontColor(nsString &aColor)
|
||||
{ aColor = mFontColor; };
|
||||
|
||||
inline
|
||||
void TypeInState::SetFontSize(nsString aSize)
|
||||
void TypeInState::SetFontSize(const nsString &aSize)
|
||||
{
|
||||
mFontSize = aSize;
|
||||
mIsSet |= NS_TYPEINSTATE_FONTSIZE;
|
||||
};
|
||||
|
||||
inline
|
||||
nsString TypeInState::GetFontSize()
|
||||
{ return mFontSize; };
|
||||
void TypeInState::GetFontSize(nsString &aSize)
|
||||
{ aSize = mFontSize; };
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -42,6 +42,7 @@ nsIAtom * nsIEditProperty::sup;
|
|||
nsIAtom * nsIEditProperty::tt;
|
||||
nsIAtom * nsIEditProperty::u;
|
||||
// block tags
|
||||
nsIAtom * nsIEditProperty::blockquote;
|
||||
nsIAtom * nsIEditProperty::h1;
|
||||
nsIAtom * nsIEditProperty::h2;
|
||||
// properties
|
||||
|
@ -68,6 +69,7 @@ nsEditProperty::InstanceInit()
|
|||
nsIEditProperty::tt = NS_NewAtom("TT");
|
||||
nsIEditProperty::u = NS_NewAtom("U");
|
||||
// tags
|
||||
nsIEditProperty::blockquote = NS_NewAtom("BLOCKQUOTE");
|
||||
nsIEditProperty::h1 = NS_NewAtom("H1");
|
||||
nsIEditProperty::h2 = NS_NewAtom("H2");
|
||||
// properties
|
||||
|
@ -95,6 +97,7 @@ nsEditProperty::InstanceShutdown()
|
|||
NS_IF_RELEASE(nsIEditProperty::tt);
|
||||
NS_IF_RELEASE(nsIEditProperty::u);
|
||||
// tags
|
||||
NS_IF_RELEASE(nsIEditProperty::blockquote);
|
||||
NS_IF_RELEASE(nsIEditProperty::h1);
|
||||
NS_IF_RELEASE(nsIEditProperty::h2);
|
||||
// properties
|
||||
|
|
|
@ -434,13 +434,20 @@ nsTextEditorKeyListener::ProcessShortCutKeys(nsIDOMEvent* aKeyEvent, PRBool& aPr
|
|||
PRBool first = PR_FALSE;
|
||||
nsAutoString color = "COLOR";
|
||||
nsAutoString value = "red";
|
||||
mEditor->SetTextProperty(nsIEditProperty::font, &color, &value);
|
||||
mEditor->GetTextProperty(nsIEditProperty::font, &color, &value, first, any, all);
|
||||
if (!all) {
|
||||
mEditor->SetTextProperty(nsIEditProperty::font, &color, &value);
|
||||
}
|
||||
else {
|
||||
printf("NOOP: all selected text is already red\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
// hard-coded ChangeTextAttributes test -- font color green
|
||||
// hard-coded ChangeTextAttributes test -- remove font color
|
||||
case nsIDOMEvent::VK_2:
|
||||
case nsIDOMEvent::VK_R:
|
||||
if (PR_TRUE==ctrlKey)
|
||||
{
|
||||
aProcessed=PR_TRUE;
|
||||
|
@ -452,8 +459,13 @@ nsTextEditorKeyListener::ProcessShortCutKeys(nsIDOMEvent* aKeyEvent, PRBool& aPr
|
|||
PRBool all = PR_FALSE;
|
||||
PRBool first = PR_FALSE;
|
||||
nsAutoString color = "COLOR";
|
||||
nsAutoString value = "green";
|
||||
mEditor->SetTextProperty(nsIEditProperty::font, &color, &value);
|
||||
mEditor->GetTextProperty(nsIEditProperty::font, &color, nsnull, first, any, all);
|
||||
if (any) {
|
||||
mEditor->RemoveTextProperty(nsIEditProperty::font, &color);
|
||||
}
|
||||
else {
|
||||
printf("NOOP: no color set\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -496,7 +508,7 @@ nsTextEditorKeyListener::ProcessShortCutKeys(nsIDOMEvent* aKeyEvent, PRBool& aPr
|
|||
}
|
||||
break;
|
||||
|
||||
// hard-coded ChangeTextAttributes test -- font face helvetica
|
||||
// hard-coded ChangeTextAttributes test -- font face helvetica
|
||||
case nsIDOMEvent::VK_5:
|
||||
if (PR_TRUE==ctrlKey)
|
||||
{
|
||||
|
@ -554,7 +566,7 @@ nsTextEditorKeyListener::ProcessShortCutKeys(nsIDOMEvent* aKeyEvent, PRBool& aPr
|
|||
}
|
||||
break;
|
||||
|
||||
// hard-coded change structure test -- block H2
|
||||
// hard-coded change structure test -- block blockquote (indent)
|
||||
case nsIDOMEvent::VK_8:
|
||||
case nsIDOMEvent::VK_W:
|
||||
if (PR_TRUE==ctrlKey)
|
||||
|
@ -567,7 +579,7 @@ nsTextEditorKeyListener::ProcessShortCutKeys(nsIDOMEvent* aKeyEvent, PRBool& aPr
|
|||
if (htmlEditor)
|
||||
{
|
||||
nsAutoString tag;
|
||||
nsIEditProperty::h2->ToString(tag);
|
||||
nsIEditProperty::blockquote->ToString(tag);
|
||||
htmlEditor->AddBlockParent(tag);
|
||||
}
|
||||
}
|
||||
|
@ -591,6 +603,26 @@ nsTextEditorKeyListener::ProcessShortCutKeys(nsIDOMEvent* aKeyEvent, PRBool& aPr
|
|||
}
|
||||
break;
|
||||
|
||||
// hard-coded change structure test -- un-BlockQuote
|
||||
case nsIDOMEvent::VK_0:
|
||||
case nsIDOMEvent::VK_G:
|
||||
if (PR_TRUE==ctrlKey)
|
||||
{
|
||||
aProcessed=PR_TRUE;
|
||||
if (mEditor)
|
||||
{
|
||||
nsCOMPtr<nsIHTMLEditor>htmlEditor;
|
||||
htmlEditor = do_QueryInterface(mEditor);
|
||||
if (htmlEditor)
|
||||
{
|
||||
nsAutoString tag;
|
||||
nsIEditProperty::blockquote->ToString(tag);
|
||||
htmlEditor->RemoveParent(tag);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
#ifdef NS_DEBUG
|
||||
// hard-coded Text Editor Unit Test
|
||||
|
|
|
@ -330,7 +330,7 @@ nsTextEditRules::CreateStyleForInsertText(nsIDOMSelection *aSelection, TypeInSta
|
|||
if (aTypeInState.IsSet(NS_TYPEINSTATE_FONTCOLOR))
|
||||
{
|
||||
nsAutoString value;
|
||||
value = aTypeInState.GetFontColor();
|
||||
aTypeInState.GetFontColor(value);
|
||||
nsAutoString attr;
|
||||
nsIEditProperty::color->ToString(attr);
|
||||
result = CreateFontStyleForInsertText(newTextNode, attr, value, aSelection);
|
||||
|
@ -338,7 +338,7 @@ nsTextEditRules::CreateStyleForInsertText(nsIDOMSelection *aSelection, TypeInSta
|
|||
if (aTypeInState.IsSet(NS_TYPEINSTATE_FONTFACE))
|
||||
{
|
||||
nsAutoString value;
|
||||
value = aTypeInState.GetFontFace();
|
||||
aTypeInState.GetFontFace(value);
|
||||
nsAutoString attr;
|
||||
nsIEditProperty::face->ToString(attr);
|
||||
result = CreateFontStyleForInsertText(newTextNode, attr, value, aSelection);
|
||||
|
@ -346,7 +346,7 @@ nsTextEditRules::CreateStyleForInsertText(nsIDOMSelection *aSelection, TypeInSta
|
|||
if (aTypeInState.IsSet(NS_TYPEINSTATE_FONTSIZE))
|
||||
{
|
||||
nsAutoString value;
|
||||
value = aTypeInState.GetFontSize();
|
||||
aTypeInState.GetFontSize(value);
|
||||
nsAutoString attr;
|
||||
nsIEditProperty::size->ToString(attr);
|
||||
result = CreateFontStyleForInsertText(newTextNode, attr, value, aSelection);
|
||||
|
|
Загрузка…
Ссылка в новой задаче