Add support for 9 new smilies, and clean up code a bit (part of multiple checkins)

r/sr = sspitzer, r=brade


git-svn-id: svn://10.0.0.236/trunk@140043 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
syd%netscape.com
2003-03-22 04:55:45 +00:00
parent 2d532b4c3c
commit afaa8ff67d
6 changed files with 339 additions and 143 deletions

View File

@@ -667,14 +667,19 @@ mozTXTToHTMLConv::StructPhraseHit(const PRUnichar * aInString, PRInt32 aInString
return PR_FALSE;
}
PRBool
mozTXTToHTMLConv::SmilyHit(const PRUnichar * aInString, PRInt32 aLength, PRBool col0,
const PRUnichar* tagTXT, PRInt32 aTagTxtLength, const char* tagHTML,
const char* tagTXT, const char* imageName,
nsString& outputHTML, PRInt32& glyphTextLen)
{
PRInt32 tagLen = nsCRT::strlen(tagTXT);
if ( !aInString || !tagTXT || !imageName )
return PR_FALSE;
PRInt32 tagLen = nsCRT::strlen(tagTXT);
PRUint32 delim = (col0 ? 0 : 1) + tagLen;
if
(
(col0 || IsSpace(aInString[0]))
@@ -688,31 +693,34 @@ mozTXTToHTMLConv::SmilyHit(const PRUnichar * aInString, PRInt32 aLength, PRBool
aInString[delim] == '.' ||
aInString[delim] == ',' ||
aInString[delim] == ';' ||
aInString[delim] == '8' ||
aInString[delim] == '>' ||
aInString[delim] == '!' ||
aInString[delim] == '?'
)
&& IsSpace(aInString[delim + 1])
)
&& ItMatchesDelimited(aInString, aLength, tagTXT, aTagTxtLength,
&& ItMatchesDelimited(aInString, aLength, NS_ConvertASCIItoUCS2(tagTXT).get(), tagLen,
col0 ? LT_IGNORE : LT_DELIMITER, LT_IGNORE)
// Note: tests at different pos for LT_IGNORE and LT_DELIMITER
)
{
if (col0)
{
outputHTML.AssignWithConversion(tagHTML);
}
else
if (!col0)
{
outputHTML.Truncate();
outputHTML.Append(PRUnichar(' '));
outputHTML.AppendWithConversion(tagHTML);
}
outputHTML += NS_LITERAL_STRING("<img src=\"chrome://editor/content/images/")
+ NS_ConvertASCIItoUCS2(imageName)
+ NS_LITERAL_STRING("\" alt=\"")
+ NS_ConvertASCIItoUCS2(tagTXT)
+ NS_LITERAL_STRING("\" class=\"moz-txt-smily\"height=19 width=19 align=ABSCENTER>");
glyphTextLen = (col0 ? 0 : 1) + tagLen;
return PR_TRUE;
}
else
return PR_FALSE;
return PR_FALSE;
}
// the glyph is appended to aOutputString instead of the original string...
@@ -724,144 +732,144 @@ mozTXTToHTMLConv::GlyphHit(const PRUnichar * aInString, PRInt32 aInLength, PRBoo
PRUnichar text0 = aInString[0];
PRUnichar text1 = aInString[1];
PRUnichar firstChar = (col0 ? text0 : text1);
// temporary variable used to store the glyph html text
nsAutoString outputHTML;
PRBool bTestSmilie;
PRBool bArg;
int i;
if
(
( // Performance increase
(col0 ? text0 : text1) == ':' ||
(col0 ? text0 : text1) == ';'
)
&&
(
SmilyHit(aInString, aInLength, col0,
NS_LITERAL_STRING(":-)").get(), 3,
"<img src=\"chrome://editor/content/images/smile_n.gif\" alt=\":-)\" class=\"moz-txt-smily\" height=19 width=19 align=ABSCENTER>",
outputHTML, glyphTextLen) ||
SmilyHit(aInString, aInLength, col0,
NS_LITERAL_STRING(":)").get(), 2,
"<img src=\"chrome://editor/content/images/smile_n.gif\" alt=\":)\" class=\"moz-txt-smily\" height=19 width=19 align=ABSCENTER>",
outputHTML, glyphTextLen) ||
SmilyHit(aInString, aInLength, col0,
NS_LITERAL_STRING(":-D").get(), 3,
"<img src=\"chrome://editor/content/images/laughing_n.gif\" alt=\":-D\" class=\"moz-txt-smily\" height=19 width=19 align=ABSCENTER>",
outputHTML, glyphTextLen) ||
SmilyHit(aInString, aInLength, col0,
NS_LITERAL_STRING(":-(").get(), 3,
"<img src=\"chrome://editor/content/images/frown_n.gif\" alt=\":-(\" class=\"moz-txt-smily\" height=19 width=19 align=ABSCENTER>",
outputHTML, glyphTextLen) ||
SmilyHit(aInString, aInLength, col0,
NS_LITERAL_STRING(":(").get(), 2,
"<img src=\"chrome://editor/content/images/frown_n.gif\" alt=\":(\" class=\"moz-txt-smily\" height=19 width=19 align=ABSCENTER>",
outputHTML, glyphTextLen) ||
SmilyHit(aInString, aInLength, col0,
NS_LITERAL_STRING(":-[").get(), 3,
"<img src=\"chrome://editor/content/images/embarrassed_n.gif\" alt=\":-[\" class=\"moz-txt-smily\" height=19 width=19 align=ABSCENTER>",
// refactor some of this mess to avoid code duplication and speed execution a bit
// there are two cases that need to be tried one after another. To avoid a lot of
// duplicate code, rolling into a loop
i = 0;
while ( i < 2 )
{
bTestSmilie = PR_FALSE;
if ( !i && (firstChar == ':' || firstChar == ';' || firstChar == '=' || firstChar == '>' || firstChar == '8' || firstChar == 'O'))
{
// first test passed
bTestSmilie = PR_TRUE;
bArg = col0;
}
if ( i && col0 && ( text1 == ':' || text1 == ';' || text1 == '=' || text1 == '>' || text1 == '8' || text1 == 'O' ) )
{
// second test passed
bTestSmilie = PR_TRUE;
bArg = PR_FALSE;
}
if ( bTestSmilie && (
SmilyHit(aInString, aInLength, bArg,
":-)",
"smile_n.gif",
outputHTML, glyphTextLen) ||
SmilyHit(aInString, aInLength, bArg,
":)",
"smile_n.gif",
outputHTML, glyphTextLen) ||
SmilyHit(aInString, aInLength, col0,
NS_LITERAL_STRING(";-)").get(), 3,
"<img src=\"chrome://editor/content/images/wink_n.gif\" alt=\";-)\" class=\"moz-txt-smily\" height=19 width=19 align=ABSCENTER>",
outputHTML, glyphTextLen) ||
SmilyHit(aInString, aInLength, col0,
NS_LITERAL_STRING(";)").get(), 2,
"<img src=\"chrome://editor/content/images/wink_n.gif\" alt=\";)\" class=\"moz-txt-smily\" height=19 width=19 align=ABSCENTER>",
outputHTML, glyphTextLen) ||
SmilyHit(aInString, aInLength, col0,
NS_LITERAL_STRING(":-\\").get(), 3,
"<img src=\"chrome://editor/content/images/undecided_n.gif\" alt=\":-\\\" class=\"moz-txt-smily\" height=19 width=19 align=ABSCENTER>",
outputHTML, glyphTextLen) ||
SmilyHit(aInString, aInLength, col0,
NS_LITERAL_STRING(":-P").get(), 3,
"<img src=\"chrome://editor/content/images/tongue_n.gif\" alt=\":-P\" class=\"moz-txt-smily\" height=19 width=19 align=ABSCENTER>",
outputHTML, glyphTextLen)
)
)
{
aOutputString.Append(outputHTML);
MOZ_TIMER_STOP(mGlyphHitTimer);
return PR_TRUE;
}
if // XXX Hotfix
(
( // Performance increase
col0
&&
(
text1 == ':' ||
text1 == ';'
)
)
&&
(
SmilyHit(aInString, aInLength, PR_FALSE,
NS_LITERAL_STRING(":-)").get(), 3,
"<img src=\"chrome://editor/content/images/smile_n.gif\" alt=\":-)\" class=\"moz-txt-smily\" height=19 width=19 align=ABSCENTER>",
outputHTML, glyphTextLen) ||
SmilyHit(aInString, aInLength, PR_FALSE,
NS_LITERAL_STRING(":)").get(), 2,
"<img src=\"chrome://editor/content/images/smile_n.gif\" alt=\":)\" class=\"moz-txt-smily\" height=19 width=19 align=ABSCENTER>",
outputHTML, glyphTextLen) ||
SmilyHit(aInString, aInLength, PR_FALSE,
NS_LITERAL_STRING(":-D").get(), 3,
"<img src=\"chrome://editor/content/images/laughing_n.gif\" alt=\":-D\" class=\"moz-txt-smily\" height=19 width=19 align=ABSCENTER>",
outputHTML, glyphTextLen) ||
SmilyHit(aInString, aInLength, PR_FALSE,
NS_LITERAL_STRING(":-(").get(), 3,
"<img src=\"chrome://editor/content/images/frown_n.gif\" alt=\":-(\" class=\"moz-txt-smily\" height=19 width=19 align=ABSCENTER>",
outputHTML, glyphTextLen) ||
SmilyHit(aInString, aInLength, PR_FALSE,
NS_LITERAL_STRING(":(").get(), 2,
"<img src=\"chrome://editor/content/images/frown_n.gif\" alt=\":(\" class=\"moz-txt-smily\" height=19 width=19 align=ABSCENTER>",
outputHTML, glyphTextLen) ||
SmilyHit(aInString, aInLength, PR_FALSE,
NS_LITERAL_STRING(":-[").get(), 3,
"<img src=\"chrome://editor/content/images/embarrassed_n.gif\" alt=\":-[\" class=\"moz-txt-smily\" height=19 width=19 align=ABSCENTER>",
SmilyHit(aInString, aInLength, bArg,
":-D",
"laughing_n.gif",
outputHTML, glyphTextLen) ||
SmilyHit(aInString, aInLength, PR_FALSE,
NS_LITERAL_STRING(";-)").get(), 3,
"<img src=\"chrome://editor/content/images/wink_n.gif\" alt=\";-)\" class=\"moz-txt-smily\" height=19 width=19 align=ABSCENTER>",
outputHTML, glyphTextLen) ||
SmilyHit(aInString, aInLength, bArg,
":-(",
"frown_n.gif",
outputHTML, glyphTextLen) ||
SmilyHit(aInString, aInLength, PR_FALSE,
NS_LITERAL_STRING(";)").get(), 2,
"<img src=\"chrome://editor/content/images/wink_n.gif\" alt=\";)\" class=\"moz-txt-smily\" height=19 width=19 align=ABSCENTER>",
outputHTML, glyphTextLen) ||
SmilyHit(aInString, aInLength, bArg,
":(",
"frown_n.gif",
outputHTML, glyphTextLen) ||
SmilyHit(aInString, aInLength, PR_FALSE,
NS_LITERAL_STRING(":-\\").get(), 3,
"<img src=\"chrome://editor/content/images/undecided_n.gif\" alt=\":-\\\" class=\"moz-txt-smily\" height=19 width=19 align=ABSCENTER>",
outputHTML, glyphTextLen) ||
SmilyHit(aInString, aInLength, PR_FALSE,
NS_LITERAL_STRING(":-P").get(), 3,
"<img src=\"chrome://editor/content/images/tongue_n.gif\" alt=\":-P\" class=\"moz-txt-smily\" height=19 width=19 align=ABSCENTER>",
outputHTML, glyphTextLen)
SmilyHit(aInString, aInLength, bArg,
":-[",
"embarrassed_n.gif",
outputHTML, glyphTextLen) ||
SmilyHit(aInString, aInLength, bArg,
";-)",
"wink_n.gif",
outputHTML, glyphTextLen) ||
SmilyHit(aInString, aInLength, col0,
";)",
"wink_n.gif",
outputHTML, glyphTextLen) ||
SmilyHit(aInString, aInLength, bArg,
":-\\",
"undecided_n.gif",
outputHTML, glyphTextLen) ||
SmilyHit(aInString, aInLength, bArg,
":-P",
"tongue_n.gif",
outputHTML, glyphTextLen) ||
SmilyHit(aInString, aInLength, bArg,
"=-O",
"surprise_n.gif",
outputHTML, glyphTextLen) ||
SmilyHit(aInString, aInLength, bArg,
":-*",
"kiss_n.gif",
outputHTML, glyphTextLen) ||
SmilyHit(aInString, aInLength, bArg,
">:o",
"yell_n.gif",
outputHTML, glyphTextLen) ||
SmilyHit(aInString, aInLength, bArg,
">:-o",
"yell_n.gif",
outputHTML, glyphTextLen) ||
SmilyHit(aInString, aInLength, bArg,
"8-)",
"cool_n.gif",
outputHTML, glyphTextLen) ||
SmilyHit(aInString, aInLength, bArg,
":-$",
"money_n.gif",
outputHTML, glyphTextLen) ||
SmilyHit(aInString, aInLength, bArg,
":-!",
"foot_n.gif",
outputHTML, glyphTextLen) ||
SmilyHit(aInString, aInLength, bArg,
"O:-)",
"innocent_n.gif",
outputHTML, glyphTextLen) ||
SmilyHit(aInString, aInLength, bArg,
":'(",
"cry_n.gif",
outputHTML, glyphTextLen) ||
SmilyHit(aInString, aInLength, bArg,
":-X",
"sealed_n.gif",
outputHTML, glyphTextLen)
)
)
{
aOutputString.Append(outputHTML);
MOZ_TIMER_STOP(mGlyphHitTimer);
return PR_TRUE;
{
aOutputString.Append(outputHTML);
MOZ_TIMER_STOP(mGlyphHitTimer);
return PR_TRUE;
}
i++;
}
if (text0 == '+' || text1 == '+')
{

View File

@@ -289,13 +289,13 @@ private:
/**
@param text (in), col0 (in): see GlyphHit
@param tagTXT (in): Smily, see also StructPhraseHit
@param aTagTxtLen (in): length of tagTXT
@param tagHTML (in): see StructPhraseHit
@param imageName (in): the basename of the file that contains the image for this smilie
@param outputHTML (out): new string containing the html for the smily
@param glyphTextLen (out): see GlyphHit
*/
PRBool SmilyHit(const PRUnichar * aInString, PRInt32 aLength, PRBool col0,
const PRUnichar* tagTXT, PRInt32 aTagTxtLen, const char* tagHTML,
PRBool
SmilyHit(const PRUnichar * aInString, PRInt32 aLength, PRBool col0,
const char* tagTXT, const char* imageName,
nsString& outputHTML, PRInt32& glyphTextLen);
/**

View File

@@ -445,6 +445,44 @@
list-style-image: url("chrome://editor/content/images/undecided_n.gif");
}
.insert-surprise > .menu-iconic-left {
list-style-image: url("chrome://editor/content/images/surprise_n.gif");
}
.insert-kiss > .menu-iconic-left {
list-style-image: url("chrome://editor/content/images/kiss_n.gif");
}
.insert-yell > .menu-iconic-left {
list-style-image: url("chrome://editor/content/images/yell_n.gif");
}
.insert-cool > .menu-iconic-left {
list-style-image: url("chrome://editor/content/images/cool_n.gif");
}
.insert-undecided > .menu-iconic-left {
list-style-image: url("chrome://editor/content/images/undecided_n.gif");
}
.insert-money > .menu-iconic-left {
list-style-image: url("chrome://editor/content/images/money_n.gif");
}
.insert-foot > .menu-iconic-left {
list-style-image: url("chrome://editor/content/images/foot_n.gif");
}
.insert-innocent > .menu-iconic-left {
list-style-image: url("chrome://editor/content/images/innocent_n.gif");
}
.insert-sealed > .menu-iconic-left {
list-style-image: url("chrome://editor/content/images/sealed_n.gif");
}
/* ::::: fg/bg color picker ::::: */
.ColorPickerLabel {

View File

@@ -150,7 +150,18 @@ span.moz-smiley-s3,
span.moz-smiley-s4,
span.moz-smiley-s5,
span.moz-smiley-s6,
span.moz-smiley-s7 {
span.moz-smiley-s7,
span.moz-smiley-s8,
span.moz-smiley-s9,
span.moz-smiley-s10,
span.moz-smiley-s11,
span.moz-smiley-s12,
span.moz-smiley-s13,
span.moz-smiley-s14,
span.moz-smiley-s15,
span.moz-smiley-s16
{
min-height: 17px; margin-left: 2px; margin-top: 2px;
padding-left: 20px;
background-repeat: no-repeat;
@@ -163,7 +174,17 @@ span.moz-smiley-s3 > span,
span.moz-smiley-s4 > span,
span.moz-smiley-s5 > span,
span.moz-smiley-s6 > span,
span.moz-smiley-s7 > span {
span.moz-smiley-s7 > span,
span.moz-smiley-s8 > span,
span.moz-smiley-s9 > span,
span.moz-smiley-s10 > span,
span.moz-smiley-s11 > span,
span.moz-smiley-s12 > span,
span.moz-smiley-s13 > span,
span.moz-smiley-s14 > span,
span.moz-smiley-s15 > span,
span.moz-smiley-s16 > span
{
display: none;
}
@@ -194,3 +215,39 @@ span.moz-smiley-s6 {
span.moz-smiley-s7 {
background-image: url("chrome://editor/content/images/undecided_n.gif");
}
span.moz-smiley-s8 {
background-image: url("chrome://editor/content/images/surprise_n.gif");
}
span.moz-smiley-s9 {
background-image: url("chrome://editor/content/images/kiss_n.gif");
}
span.moz-smiley-s10 {
background-image: url("chrome://editor/content/images/yell_n.gif");
}
span.moz-smiley-s11 {
background-image: url("chrome://editor/content/images/cool_n.gif");
}
span.moz-smiley-s12 {
background-image: url("chrome://editor/content/images/money_n.gif");
}
span.moz-smiley-s13 {
background-image: url("chrome://editor/content/images/foot_n.gif");
}
span.moz-smiley-s14 {
background-image: url("chrome://editor/content/images/innocent_n.gif");
}
span.moz-smiley-s15 {
background-image: url("chrome://editor/content/images/cry_n.gif");
}
span.moz-smiley-s16 {
background-image: url("chrome://editor/content/images/sealed_n.gif");
}

View File

@@ -472,6 +472,43 @@
list-style-image: url("chrome://editor/content/images/undecided_n.gif");
}
.insert-surprise > .menu-iconic-left {
list-style-image: url("chrome://editor/content/images/surprise_n.gif");
}
.insert-kiss > .menu-iconic-left {
list-style-image: url("chrome://editor/content/images/kiss_n.gif");
}
.insert-yell > .menu-iconic-left {
list-style-image: url("chrome://editor/content/images/yell_n.gif");
}
.insert-cool > .menu-iconic-left {
list-style-image: url("chrome://editor/content/images/cool_n.gif");
}
.insert-money > .menu-iconic-left {
list-style-image: url("chrome://editor/content/images/money_n.gif");
}
.insert-foot > .menu-iconic-left {
list-style-image: url("chrome://editor/content/images/foot_n.gif");
}
.insert-innocent > .menu-iconic-left {
list-style-image: url("chrome://editor/content/images/innocent_n.gif");
}
.insert-cry > .menu-iconic-left {
list-style-image: url("chrome://editor/content/images/cry_n.gif");
}
.insert-sealed > .menu-iconic-left {
list-style-image: url("chrome://editor/content/images/sealed_n.gif");
}
/* ::::: fg/bg color picker ::::: */
.color-button {

View File

@@ -150,7 +150,17 @@ span.moz-smiley-s3,
span.moz-smiley-s4,
span.moz-smiley-s5,
span.moz-smiley-s6,
span.moz-smiley-s7 {
span.moz-smiley-s7,
span.moz-smiley-s8,
span.moz-smiley-s9,
span.moz-smiley-s10,
span.moz-smiley-s11,
span.moz-smiley-s12,
span.moz-smiley-s13,
span.moz-smiley-s14,
span.moz-smiley-s15,
span.moz-smiley-s16
{
min-height: 17px; margin-left: 2px; margin-top: 2px;
padding-left: 20px;
background-repeat: no-repeat;
@@ -163,7 +173,17 @@ span.moz-smiley-s3 > span,
span.moz-smiley-s4 > span,
span.moz-smiley-s5 > span,
span.moz-smiley-s6 > span,
span.moz-smiley-s7 > span {
span.moz-smiley-s7 > span,
span.moz-smiley-s8 > span,
span.moz-smiley-s9 > span,
span.moz-smiley-s10 > span,
span.moz-smiley-s11 > span,
span.moz-smiley-s12 > span,
span.moz-smiley-s13 > span,
span.moz-smiley-s14 > span,
span.moz-smiley-s15 > span,
span.moz-smiley-s16 > span
{
display: none;
}
@@ -194,3 +214,39 @@ span.moz-smiley-s6 {
span.moz-smiley-s7 {
background-image: url("chrome://editor/content/images/undecided_n.gif");
}
span.moz-smiley-s8 {
background-image: url("chrome://editor/content/images/surprise_n.gif");
}
span.moz-smiley-s9 {
background-image: url("chrome://editor/content/images/kiss_n.gif");
}
span.moz-smiley-s10 {
background-image: url("chrome://editor/content/images/yell_n.gif");
}
span.moz-smiley-s11 {
background-image: url("chrome://editor/content/images/cool_n.gif");
}
span.moz-smiley-s12 {
background-image: url("chrome://editor/content/images/money_n.gif");
}
span.moz-smiley-s13 {
background-image: url("chrome://editor/content/images/foot_n.gif");
}
span.moz-smiley-s14 {
background-image: url("chrome://editor/content/images/innocent_n.gif");
}
span.moz-smiley-s15 {
background-image: url("chrome://editor/content/images/cry_n.gif");
}
span.moz-smiley-s16 {
background-image: url("chrome://editor/content/images/sealed_n.gif");
}