2002-01-09 16:51:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-18 18:21:17 +04:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
2002-01-09 16:51:37 +03:00
|
|
|
*
|
2004-04-18 18:21:17 +04:00
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
2002-01-09 16:51:37 +03:00
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2004-04-18 18:21:17 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
2002-01-09 16:51:37 +03:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
2004-04-18 18:21:17 +04:00
|
|
|
* Original Author: Daniel Glazman <glazman@netscape.com>
|
2002-01-09 16:51:37 +03:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-18 18:21:17 +04:00
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
2002-01-09 16:51:37 +03:00
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
2004-04-18 18:21:17 +04:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2002-01-09 16:51:37 +03:00
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
2004-04-18 18:21:17 +04:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2002-01-09 16:51:37 +03:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
#include "nsHTMLEditor.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsHTMLEditUtils.h"
|
2002-11-23 04:26:58 +03:00
|
|
|
#include "nsIPrefBranch.h"
|
|
|
|
#include "nsIPrefService.h"
|
2002-01-09 16:51:37 +03:00
|
|
|
#include "nsIServiceManager.h"
|
2003-04-17 09:42:33 +04:00
|
|
|
#include "nsEditProperty.h"
|
2002-01-09 16:51:37 +03:00
|
|
|
#include "ChangeCSSInlineStyleTxn.h"
|
|
|
|
#include "nsIDOMElement.h"
|
|
|
|
#include "TransactionFactory.h"
|
|
|
|
#include "nsIDOMElementCSSInlineStyle.h"
|
|
|
|
#include "nsIDOMDocument.h"
|
|
|
|
#include "nsIDOMDocumentView.h"
|
|
|
|
#include "nsIContent.h"
|
2003-07-18 23:03:34 +04:00
|
|
|
#include "nsIAtom.h"
|
2002-01-09 16:51:37 +03:00
|
|
|
#include "nsTextEditUtils.h"
|
2003-07-14 11:37:39 +04:00
|
|
|
#include "nsReadableUtils.h"
|
2002-01-09 16:51:37 +03:00
|
|
|
#include "nsUnicharUtils.h"
|
|
|
|
#include "nsHTMLCSSUtils.h"
|
2002-12-13 11:56:21 +03:00
|
|
|
#include "nsColor.h"
|
2005-12-29 00:52:39 +03:00
|
|
|
#include "nsAttrName.h"
|
2007-07-02 18:01:27 +04:00
|
|
|
#include "nsAutoPtr.h"
|
2002-01-09 16:51:37 +03:00
|
|
|
|
|
|
|
static
|
2002-03-24 01:08:20 +03:00
|
|
|
void ProcessBValue(const nsAString * aInputString, nsAString & aOutputString,
|
2002-01-09 16:51:37 +03:00
|
|
|
const char * aDefaultValueString,
|
|
|
|
const char * aPrependString, const char* aAppendString)
|
|
|
|
{
|
2004-05-23 02:15:22 +04:00
|
|
|
if (aInputString && aInputString->EqualsLiteral("-moz-editor-invert-value")) {
|
2004-06-17 04:13:25 +04:00
|
|
|
aOutputString.AssignLiteral("normal");
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
else {
|
2004-06-17 04:13:25 +04:00
|
|
|
aOutputString.AssignLiteral("bold");
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
2002-03-24 01:08:20 +03:00
|
|
|
void ProcessDefaultValue(const nsAString * aInputString, nsAString & aOutputString,
|
2002-01-09 16:51:37 +03:00
|
|
|
const char * aDefaultValueString,
|
|
|
|
const char * aPrependString, const char* aAppendString)
|
|
|
|
{
|
2004-01-30 01:04:45 +03:00
|
|
|
CopyASCIItoUTF16(aDefaultValueString, aOutputString);
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static
|
2002-03-24 01:08:20 +03:00
|
|
|
void ProcessSameValue(const nsAString * aInputString, nsAString & aOutputString,
|
2002-01-09 16:51:37 +03:00
|
|
|
const char * aDefaultValueString,
|
|
|
|
const char * aPrependString, const char* aAppendString)
|
|
|
|
{
|
|
|
|
if (aInputString) {
|
|
|
|
aOutputString.Assign(*aInputString);
|
|
|
|
}
|
2003-09-03 17:54:36 +04:00
|
|
|
else
|
|
|
|
aOutputString.Truncate();
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static
|
2002-03-24 01:08:20 +03:00
|
|
|
void ProcessExtendedValue(const nsAString * aInputString, nsAString & aOutputString,
|
2002-01-09 16:51:37 +03:00
|
|
|
const char * aDefaultValueString,
|
|
|
|
const char * aPrependString, const char* aAppendString)
|
|
|
|
{
|
|
|
|
aOutputString.Truncate();
|
|
|
|
if (aInputString) {
|
|
|
|
if (aPrependString) {
|
2003-11-01 13:57:41 +03:00
|
|
|
AppendASCIItoUTF16(aPrependString, aOutputString);
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
2002-01-21 12:30:02 +03:00
|
|
|
aOutputString.Append(*aInputString);
|
2002-01-09 16:51:37 +03:00
|
|
|
if (aAppendString) {
|
2003-11-01 13:57:41 +03:00
|
|
|
AppendASCIItoUTF16(aAppendString, aOutputString);
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
2002-03-24 01:08:20 +03:00
|
|
|
void ProcessLengthValue(const nsAString * aInputString, nsAString & aOutputString,
|
2002-01-09 16:51:37 +03:00
|
|
|
const char * aDefaultValueString,
|
|
|
|
const char * aPrependString, const char* aAppendString)
|
|
|
|
{
|
|
|
|
aOutputString.Truncate();
|
|
|
|
if (aInputString) {
|
|
|
|
aOutputString.Append(*aInputString);
|
|
|
|
if (-1 == aOutputString.FindChar(PRUnichar('%'))) {
|
2004-06-17 04:13:25 +04:00
|
|
|
aOutputString.AppendLiteral("px");
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
2002-03-24 01:08:20 +03:00
|
|
|
void ProcessListStyleTypeValue(const nsAString * aInputString, nsAString & aOutputString,
|
2002-01-09 16:51:37 +03:00
|
|
|
const char * aDefaultValueString,
|
|
|
|
const char * aPrependString, const char* aAppendString)
|
|
|
|
{
|
|
|
|
aOutputString.Truncate();
|
|
|
|
if (aInputString) {
|
2004-05-23 02:15:22 +04:00
|
|
|
if (aInputString->EqualsLiteral("1")) {
|
2004-06-17 04:13:25 +04:00
|
|
|
aOutputString.AppendLiteral("decimal");
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
2004-05-23 02:15:22 +04:00
|
|
|
else if (aInputString->EqualsLiteral("a")) {
|
2004-06-17 04:13:25 +04:00
|
|
|
aOutputString.AppendLiteral("lower-alpha");
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
2004-05-23 02:15:22 +04:00
|
|
|
else if (aInputString->EqualsLiteral("A")) {
|
2004-06-17 04:13:25 +04:00
|
|
|
aOutputString.AppendLiteral("upper-alpha");
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
2004-05-23 02:15:22 +04:00
|
|
|
else if (aInputString->EqualsLiteral("i")) {
|
2004-06-17 04:13:25 +04:00
|
|
|
aOutputString.AppendLiteral("lower-roman");
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
2004-05-23 02:15:22 +04:00
|
|
|
else if (aInputString->EqualsLiteral("I")) {
|
2004-06-17 04:13:25 +04:00
|
|
|
aOutputString.AppendLiteral("upper-roman");
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
2004-05-23 02:15:22 +04:00
|
|
|
else if (aInputString->EqualsLiteral("square")
|
|
|
|
|| aInputString->EqualsLiteral("circle")
|
|
|
|
|| aInputString->EqualsLiteral("disc")) {
|
2002-01-09 16:51:37 +03:00
|
|
|
aOutputString.Append(*aInputString);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
2002-03-24 01:08:20 +03:00
|
|
|
void ProcessMarginLeftValue(const nsAString * aInputString, nsAString & aOutputString,
|
2002-01-09 16:51:37 +03:00
|
|
|
const char * aDefaultValueString,
|
|
|
|
const char * aPrependString, const char* aAppendString)
|
|
|
|
{
|
|
|
|
aOutputString.Truncate();
|
|
|
|
if (aInputString) {
|
2004-05-23 02:15:22 +04:00
|
|
|
if (aInputString->EqualsLiteral("center") ||
|
|
|
|
aInputString->EqualsLiteral("-moz-center")) {
|
2004-06-17 04:13:25 +04:00
|
|
|
aOutputString.AppendLiteral("auto");
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
2004-05-23 02:15:22 +04:00
|
|
|
else if (aInputString->EqualsLiteral("right") ||
|
|
|
|
aInputString->EqualsLiteral("-moz-right")) {
|
2004-06-17 04:13:25 +04:00
|
|
|
aOutputString.AppendLiteral("auto");
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
else {
|
2004-06-17 04:13:25 +04:00
|
|
|
aOutputString.AppendLiteral("0px");
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
2002-03-24 01:08:20 +03:00
|
|
|
void ProcessMarginRightValue(const nsAString * aInputString, nsAString & aOutputString,
|
2002-01-09 16:51:37 +03:00
|
|
|
const char * aDefaultValueString,
|
|
|
|
const char * aPrependString, const char* aAppendString)
|
|
|
|
{
|
|
|
|
aOutputString.Truncate();
|
|
|
|
if (aInputString) {
|
2004-05-23 02:15:22 +04:00
|
|
|
if (aInputString->EqualsLiteral("center") ||
|
|
|
|
aInputString->EqualsLiteral("-moz-center")) {
|
2004-06-17 04:13:25 +04:00
|
|
|
aOutputString.AppendLiteral("auto");
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
2004-05-23 02:15:22 +04:00
|
|
|
else if (aInputString->EqualsLiteral("left") ||
|
|
|
|
aInputString->EqualsLiteral("-moz-left")) {
|
2004-06-17 04:13:25 +04:00
|
|
|
aOutputString.AppendLiteral("auto");
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
else {
|
2004-06-17 04:13:25 +04:00
|
|
|
aOutputString.AppendLiteral("0px");
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const nsHTMLCSSUtils::CSSEquivTable boldEquivTable[] = {
|
2002-08-23 13:24:47 +04:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_font_weight, ProcessBValue, nsnull, nsnull, nsnull, PR_TRUE, PR_FALSE },
|
2002-01-09 16:51:37 +03:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_NONE, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
const nsHTMLCSSUtils::CSSEquivTable italicEquivTable[] = {
|
2002-08-23 13:24:47 +04:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_font_style, ProcessDefaultValue, "italic", nsnull, nsnull, PR_TRUE, PR_FALSE },
|
2002-01-09 16:51:37 +03:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_NONE, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
const nsHTMLCSSUtils::CSSEquivTable underlineEquivTable[] = {
|
2002-08-23 13:24:47 +04:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_text_decoration, ProcessDefaultValue, "underline", nsnull, nsnull, PR_TRUE, PR_FALSE },
|
2002-01-09 16:51:37 +03:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_NONE, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
const nsHTMLCSSUtils::CSSEquivTable strikeEquivTable[] = {
|
2002-08-23 13:24:47 +04:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_text_decoration, ProcessDefaultValue, "line-through", nsnull, nsnull, PR_TRUE, PR_FALSE },
|
2002-01-09 16:51:37 +03:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_NONE, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
const nsHTMLCSSUtils::CSSEquivTable ttEquivTable[] = {
|
2002-08-23 13:24:47 +04:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_font_family, ProcessDefaultValue, "monospace", nsnull, nsnull, PR_TRUE, PR_FALSE },
|
2002-01-09 16:51:37 +03:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_NONE, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
const nsHTMLCSSUtils::CSSEquivTable fontColorEquivTable[] = {
|
2002-08-23 13:24:47 +04:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_color, ProcessSameValue, nsnull, nsnull, nsnull, PR_TRUE, PR_FALSE },
|
2002-01-09 16:51:37 +03:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_NONE, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
const nsHTMLCSSUtils::CSSEquivTable fontFaceEquivTable[] = {
|
2002-08-23 13:24:47 +04:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_font_family, ProcessSameValue, nsnull, nsnull, nsnull, PR_TRUE, PR_FALSE },
|
2002-01-09 16:51:37 +03:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_NONE, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
const nsHTMLCSSUtils::CSSEquivTable bgcolorEquivTable[] = {
|
2002-08-23 13:24:47 +04:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_background_color, ProcessSameValue, nsnull, nsnull, nsnull, PR_TRUE, PR_FALSE },
|
2002-01-09 16:51:37 +03:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_NONE, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
const nsHTMLCSSUtils::CSSEquivTable backgroundImageEquivTable[] = {
|
2002-08-23 13:24:47 +04:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_background_image, ProcessExtendedValue, nsnull, "url(", ")", PR_TRUE, PR_TRUE },
|
2002-01-09 16:51:37 +03:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_NONE, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
const nsHTMLCSSUtils::CSSEquivTable textColorEquivTable[] = {
|
2002-08-23 13:24:47 +04:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_color, ProcessSameValue, nsnull, nsnull, nsnull, PR_TRUE, PR_FALSE },
|
2002-01-09 16:51:37 +03:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_NONE, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
const nsHTMLCSSUtils::CSSEquivTable borderEquivTable[] = {
|
2002-08-23 13:24:47 +04:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_border, ProcessExtendedValue, nsnull, nsnull, "px solid", PR_TRUE, PR_FALSE },
|
2002-01-09 16:51:37 +03:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_NONE, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
const nsHTMLCSSUtils::CSSEquivTable textAlignEquivTable[] = {
|
2002-08-23 13:24:47 +04:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_text_align, ProcessSameValue, nsnull, nsnull, nsnull, PR_TRUE, PR_FALSE },
|
2002-01-09 16:51:37 +03:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_NONE, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
const nsHTMLCSSUtils::CSSEquivTable captionAlignEquivTable[] = {
|
2002-08-23 13:24:47 +04:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_caption_side, ProcessSameValue, nsnull, nsnull, nsnull, PR_TRUE, PR_FALSE },
|
2002-01-09 16:51:37 +03:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_NONE, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
const nsHTMLCSSUtils::CSSEquivTable verticalAlignEquivTable[] = {
|
2002-08-23 13:24:47 +04:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_vertical_align, ProcessSameValue, nsnull, nsnull, nsnull, PR_TRUE, PR_FALSE },
|
2002-01-09 16:51:37 +03:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_NONE, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
const nsHTMLCSSUtils::CSSEquivTable nowrapEquivTable[] = {
|
2002-08-23 13:24:47 +04:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_whitespace, ProcessDefaultValue, "nowrap", nsnull, nsnull, PR_TRUE, PR_FALSE },
|
2002-01-09 16:51:37 +03:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_NONE, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
const nsHTMLCSSUtils::CSSEquivTable widthEquivTable[] = {
|
2002-08-23 13:24:47 +04:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_width, ProcessLengthValue, nsnull, nsnull, nsnull, PR_TRUE, PR_FALSE },
|
2002-01-09 16:51:37 +03:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_NONE, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
const nsHTMLCSSUtils::CSSEquivTable heightEquivTable[] = {
|
2002-08-23 13:24:47 +04:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_height, ProcessLengthValue, nsnull, nsnull, nsnull, PR_TRUE, PR_FALSE },
|
2002-01-09 16:51:37 +03:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_NONE, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
const nsHTMLCSSUtils::CSSEquivTable listStyleTypeEquivTable[] = {
|
2002-08-23 13:24:47 +04:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_list_style_type, ProcessListStyleTypeValue, nsnull, nsnull, nsnull, PR_TRUE, PR_TRUE },
|
2002-01-09 16:51:37 +03:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_NONE, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
const nsHTMLCSSUtils::CSSEquivTable tableAlignEquivTable[] = {
|
2002-08-23 13:24:47 +04:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_text_align, ProcessDefaultValue, "left", nsnull, nsnull, PR_FALSE, PR_FALSE },
|
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_margin_left, ProcessMarginLeftValue, nsnull, nsnull, nsnull, PR_TRUE, PR_FALSE },
|
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_margin_right, ProcessMarginRightValue, nsnull, nsnull, nsnull, PR_TRUE, PR_FALSE },
|
2002-01-09 16:51:37 +03:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_NONE, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
const nsHTMLCSSUtils::CSSEquivTable hrAlignEquivTable[] = {
|
2002-08-23 13:24:47 +04:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_margin_left, ProcessMarginLeftValue, nsnull, nsnull, nsnull, PR_TRUE, PR_FALSE },
|
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_margin_right, ProcessMarginRightValue, nsnull, nsnull, nsnull, PR_TRUE, PR_FALSE },
|
2002-01-09 16:51:37 +03:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_NONE, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
nsHTMLCSSUtils::nsHTMLCSSUtils()
|
|
|
|
: mIsCSSPrefChecked(PR_FALSE)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2002-08-07 04:02:10 +04:00
|
|
|
nsHTMLCSSUtils::~nsHTMLCSSUtils()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2002-01-09 16:51:37 +03:00
|
|
|
nsresult
|
|
|
|
nsHTMLCSSUtils::Init(nsHTMLEditor *aEditor)
|
|
|
|
{
|
|
|
|
nsresult result = NS_OK;
|
2007-07-08 11:08:04 +04:00
|
|
|
mHTMLEditor = static_cast<nsHTMLEditor*>(aEditor);
|
2002-01-09 16:51:37 +03:00
|
|
|
|
|
|
|
// let's retrieve the value of the "CSS editing" pref
|
2002-11-23 04:26:58 +03:00
|
|
|
nsCOMPtr<nsIPrefBranch> prefBranch =
|
|
|
|
do_GetService(NS_PREFSERVICE_CONTRACTID, &result);
|
|
|
|
if (NS_SUCCEEDED(result) && prefBranch) {
|
|
|
|
result = prefBranch->GetBoolPref("editor.use_css", &mIsCSSPrefChecked);
|
2002-01-09 16:51:37 +03:00
|
|
|
if (NS_FAILED(result)) return result;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Answers true if we have some CSS equivalence for the HTML style defined
|
|
|
|
// by aProperty and/or aAttribute for the node aNode
|
|
|
|
PRBool
|
|
|
|
nsHTMLCSSUtils::IsCSSEditableProperty(nsIDOMNode * aNode,
|
|
|
|
nsIAtom * aProperty,
|
2002-03-24 01:08:20 +03:00
|
|
|
const nsAString * aAttribute)
|
2002-01-09 16:51:37 +03:00
|
|
|
{
|
2003-07-29 18:48:44 +04:00
|
|
|
NS_ASSERTION(aNode, "Shouldn't you pass aNode? - Bug 214025");
|
|
|
|
|
2002-01-09 16:51:37 +03:00
|
|
|
nsCOMPtr<nsIDOMNode> node = aNode;
|
|
|
|
// we need an element node here
|
|
|
|
if (mHTMLEditor->IsTextNode(aNode)) {
|
|
|
|
aNode->GetParentNode(getter_AddRefs(node));
|
|
|
|
}
|
|
|
|
nsCOMPtr<nsIContent> content = do_QueryInterface(node);
|
2003-07-29 18:48:44 +04:00
|
|
|
if (!content) return PR_FALSE;
|
|
|
|
|
2003-11-19 04:20:56 +03:00
|
|
|
nsIAtom *tagName = content->Tag();
|
2003-09-03 17:54:36 +04:00
|
|
|
// brade: should the above use nsEditor::GetTag(aNode)?
|
|
|
|
// brade: shouldn't some of the above go below the next block?
|
2002-01-09 16:51:37 +03:00
|
|
|
|
|
|
|
// html inline styles B I TT U STRIKE and COLOR/FACE on FONT
|
2003-04-17 09:42:33 +04:00
|
|
|
if (nsEditProperty::b == aProperty
|
|
|
|
|| nsEditProperty::i == aProperty
|
|
|
|
|| nsEditProperty::tt == aProperty
|
|
|
|
|| nsEditProperty::u == aProperty
|
|
|
|
|| nsEditProperty::strike == aProperty
|
|
|
|
|| ((nsEditProperty::font == aProperty) && aAttribute &&
|
2004-05-23 02:15:22 +04:00
|
|
|
(aAttribute->EqualsLiteral("color") ||
|
|
|
|
aAttribute->EqualsLiteral("face")))) {
|
2002-01-09 16:51:37 +03:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ALIGN attribute on elements supporting it
|
2004-05-23 02:15:22 +04:00
|
|
|
if (aAttribute && (aAttribute->EqualsLiteral("align")) &&
|
2003-04-17 09:42:33 +04:00
|
|
|
(nsEditProperty::div == tagName
|
|
|
|
|| nsEditProperty::p == tagName
|
|
|
|
|| nsEditProperty::h1 == tagName
|
|
|
|
|| nsEditProperty::h2 == tagName
|
|
|
|
|| nsEditProperty::h3 == tagName
|
|
|
|
|| nsEditProperty::h4 == tagName
|
|
|
|
|| nsEditProperty::h5 == tagName
|
|
|
|
|| nsEditProperty::h6 == tagName
|
|
|
|
|| nsEditProperty::td == tagName
|
|
|
|
|| nsEditProperty::th == tagName
|
|
|
|
|| nsEditProperty::table == tagName
|
|
|
|
|| nsEditProperty::hr == tagName
|
2003-09-03 17:54:36 +04:00
|
|
|
// brade: for the above, why not use nsHTMLEditUtils::SupportsAlignAttr
|
|
|
|
// brade: but it also checks for tbody, tfoot, thead
|
2002-01-09 16:51:37 +03:00
|
|
|
// Let's add the following elements here even if ALIGN has not
|
|
|
|
// the same meaning for them
|
2003-04-17 09:42:33 +04:00
|
|
|
|| nsEditProperty::legend == tagName
|
|
|
|
|| nsEditProperty::caption == tagName)) {
|
2002-01-09 16:51:37 +03:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2004-05-23 02:15:22 +04:00
|
|
|
if (aAttribute && (aAttribute->EqualsLiteral("valign")) &&
|
2003-04-17 09:42:33 +04:00
|
|
|
(nsEditProperty::col == tagName
|
|
|
|
|| nsEditProperty::colgroup == tagName
|
|
|
|
|| nsEditProperty::tbody == tagName
|
|
|
|
|| nsEditProperty::td == tagName
|
|
|
|
|| nsEditProperty::th == tagName
|
|
|
|
|| nsEditProperty::tfoot == tagName
|
|
|
|
|| nsEditProperty::thead == tagName
|
|
|
|
|| nsEditProperty::tr == tagName)) {
|
2002-09-17 16:04:59 +04:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2002-01-09 16:51:37 +03:00
|
|
|
// attributes TEXT, BACKGROUND and BGCOLOR on BODY
|
2003-04-17 09:42:33 +04:00
|
|
|
if (aAttribute && (nsEditProperty::body == tagName) &&
|
2004-05-23 02:15:22 +04:00
|
|
|
(aAttribute->EqualsLiteral("text")
|
|
|
|
|| aAttribute->EqualsLiteral("background")
|
|
|
|
|| aAttribute->EqualsLiteral("bgcolor"))) {
|
2002-01-09 16:51:37 +03:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// attribute BGCOLOR on other elements
|
2004-05-23 02:15:22 +04:00
|
|
|
if (aAttribute && aAttribute->EqualsLiteral("bgcolor")) {
|
2002-01-09 16:51:37 +03:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// attributes HEIGHT, WIDTH and NOWRAP on TD and TH
|
2003-04-17 09:42:33 +04:00
|
|
|
if (aAttribute && ((nsEditProperty::td == tagName)
|
|
|
|
|| (nsEditProperty::th == tagName)) &&
|
2004-05-23 02:15:22 +04:00
|
|
|
(aAttribute->EqualsLiteral("height")
|
|
|
|
|| aAttribute->EqualsLiteral("width")
|
|
|
|
|| aAttribute->EqualsLiteral("nowrap"))) {
|
2002-01-09 16:51:37 +03:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// attributes HEIGHT and WIDTH on TABLE
|
2003-04-17 09:42:33 +04:00
|
|
|
if (aAttribute && (nsEditProperty::table == tagName) &&
|
2004-05-23 02:15:22 +04:00
|
|
|
(aAttribute->EqualsLiteral("height")
|
|
|
|
|| aAttribute->EqualsLiteral("width"))) {
|
2002-01-09 16:51:37 +03:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// attributes SIZE and WIDTH on HR
|
2003-04-17 09:42:33 +04:00
|
|
|
if (aAttribute && (nsEditProperty::hr == tagName) &&
|
2004-05-23 02:15:22 +04:00
|
|
|
(aAttribute->EqualsLiteral("size")
|
|
|
|
|| aAttribute->EqualsLiteral("width"))) {
|
2002-01-09 16:51:37 +03:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// attribute TYPE on OL UL LI
|
2003-04-17 09:42:33 +04:00
|
|
|
if (aAttribute && (nsEditProperty::ol == tagName
|
|
|
|
|| nsEditProperty::ul == tagName
|
|
|
|
|| nsEditProperty::li == tagName) &&
|
2004-05-23 02:15:22 +04:00
|
|
|
aAttribute->EqualsLiteral("type")) {
|
2002-01-09 16:51:37 +03:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2003-04-17 09:42:33 +04:00
|
|
|
if (aAttribute && nsEditProperty::img == tagName &&
|
2004-05-23 02:15:22 +04:00
|
|
|
(aAttribute->EqualsLiteral("border")
|
|
|
|
|| aAttribute->EqualsLiteral("width")
|
|
|
|
|| aAttribute->EqualsLiteral("height"))) {
|
2002-01-09 16:51:37 +03:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// other elements that we can align using CSS even if they
|
|
|
|
// can't carry the html ALIGN attribute
|
2004-05-23 02:15:22 +04:00
|
|
|
if (aAttribute && aAttribute->EqualsLiteral("align") &&
|
2003-04-17 09:42:33 +04:00
|
|
|
(nsEditProperty::ul == tagName
|
|
|
|
|| nsEditProperty::ol == tagName
|
|
|
|
|| nsEditProperty::dl == tagName
|
|
|
|
|| nsEditProperty::li == tagName
|
|
|
|
|| nsEditProperty::dd == tagName
|
|
|
|
|| nsEditProperty::dt == tagName
|
|
|
|
|| nsEditProperty::address == tagName
|
|
|
|
|| nsEditProperty::pre == tagName
|
|
|
|
|| nsEditProperty::ul == tagName)) {
|
2002-01-09 16:51:37 +03:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// the lowest level above the transaction; adds the css declaration "aProperty : aValue" to
|
|
|
|
// the inline styles carried by aElement
|
|
|
|
nsresult
|
2002-09-17 16:04:59 +04:00
|
|
|
nsHTMLCSSUtils::SetCSSProperty(nsIDOMElement *aElement, nsIAtom * aProperty, const nsAString & aValue,
|
|
|
|
PRBool aSuppressTransaction)
|
2002-01-09 16:51:37 +03:00
|
|
|
{
|
2007-07-02 18:01:27 +04:00
|
|
|
nsRefPtr<ChangeCSSInlineStyleTxn> txn;
|
|
|
|
nsresult result = CreateCSSPropertyTxn(aElement, aProperty, aValue,
|
|
|
|
getter_AddRefs(txn), PR_FALSE);
|
2002-01-09 16:51:37 +03:00
|
|
|
if (NS_SUCCEEDED(result)) {
|
2002-09-17 16:04:59 +04:00
|
|
|
if (aSuppressTransaction) {
|
|
|
|
result = txn->DoTransaction();
|
|
|
|
}
|
|
|
|
else {
|
2003-04-05 00:50:25 +04:00
|
|
|
result = mHTMLEditor->DoTransaction(txn);
|
2002-09-17 16:04:59 +04:00
|
|
|
}
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2003-09-03 17:54:36 +04:00
|
|
|
nsresult
|
|
|
|
nsHTMLCSSUtils::SetCSSPropertyPixels(nsIDOMElement *aElement,
|
|
|
|
nsIAtom *aProperty,
|
|
|
|
PRInt32 aIntValue,
|
|
|
|
PRBool aSuppressTransaction)
|
|
|
|
{
|
|
|
|
nsAutoString s;
|
|
|
|
s.AppendInt(aIntValue);
|
|
|
|
return SetCSSProperty(aElement, aProperty, s + NS_LITERAL_STRING("px"),
|
|
|
|
aSuppressTransaction);
|
|
|
|
}
|
|
|
|
|
2002-01-09 16:51:37 +03:00
|
|
|
// the lowest level above the transaction; removes the value aValue from the list of values
|
|
|
|
// specified for the CSS property aProperty, or totally remove the declaration if this
|
|
|
|
// property accepts only one value
|
|
|
|
nsresult
|
2002-09-17 16:04:59 +04:00
|
|
|
nsHTMLCSSUtils::RemoveCSSProperty(nsIDOMElement *aElement, nsIAtom * aProperty, const nsAString & aValue,
|
|
|
|
PRBool aSuppressTransaction)
|
2002-01-09 16:51:37 +03:00
|
|
|
{
|
2007-07-02 18:01:27 +04:00
|
|
|
nsRefPtr<ChangeCSSInlineStyleTxn> txn;
|
|
|
|
nsresult result = CreateCSSPropertyTxn(aElement, aProperty, aValue,
|
|
|
|
getter_AddRefs(txn), PR_TRUE);
|
2002-01-09 16:51:37 +03:00
|
|
|
if (NS_SUCCEEDED(result)) {
|
2002-09-17 16:04:59 +04:00
|
|
|
if (aSuppressTransaction) {
|
|
|
|
result = txn->DoTransaction();
|
|
|
|
}
|
|
|
|
else {
|
2003-04-05 00:50:25 +04:00
|
|
|
result = mHTMLEditor->DoTransaction(txn);
|
2002-09-17 16:04:59 +04:00
|
|
|
}
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsHTMLCSSUtils::CreateCSSPropertyTxn(nsIDOMElement *aElement,
|
|
|
|
nsIAtom * aAttribute,
|
2002-03-24 01:08:20 +03:00
|
|
|
const nsAString& aValue,
|
2002-01-09 16:51:37 +03:00
|
|
|
ChangeCSSInlineStyleTxn ** aTxn,
|
|
|
|
PRBool aRemoveProperty)
|
|
|
|
{
|
|
|
|
nsresult result = NS_ERROR_NULL_POINTER;
|
2003-09-03 17:54:36 +04:00
|
|
|
if (aElement)
|
2002-01-09 16:51:37 +03:00
|
|
|
{
|
|
|
|
result = TransactionFactory::GetNewTransaction(ChangeCSSInlineStyleTxn::GetCID(), (EditTxn **)aTxn);
|
|
|
|
if (NS_SUCCEEDED(result)) {
|
|
|
|
result = (*aTxn)->Init(mHTMLEditor, aElement, aAttribute, aValue, aRemoveProperty);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsHTMLCSSUtils::GetSpecifiedProperty(nsIDOMNode *aNode, nsIAtom *aProperty,
|
2002-03-24 01:08:20 +03:00
|
|
|
nsAString & aValue)
|
2002-01-09 16:51:37 +03:00
|
|
|
{
|
|
|
|
return GetCSSInlinePropertyBase(aNode, aProperty, aValue, nsnull, SPECIFIED_STYLE_TYPE);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsHTMLCSSUtils::GetComputedProperty(nsIDOMNode *aNode, nsIAtom *aProperty,
|
2002-03-24 01:08:20 +03:00
|
|
|
nsAString & aValue)
|
2002-01-09 16:51:37 +03:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMViewCSS> viewCSS = nsnull;
|
|
|
|
nsresult res = GetDefaultViewCSS(aNode, getter_AddRefs(viewCSS));
|
|
|
|
if (NS_FAILED(res)) return res;
|
|
|
|
|
|
|
|
return GetCSSInlinePropertyBase(aNode, aProperty, aValue, viewCSS, COMPUTED_STYLE_TYPE);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsHTMLCSSUtils::GetCSSInlinePropertyBase(nsIDOMNode *aNode, nsIAtom *aProperty,
|
2002-03-24 01:08:20 +03:00
|
|
|
nsAString &aValue,
|
2002-01-09 16:51:37 +03:00
|
|
|
nsIDOMViewCSS *aViewCSS,
|
|
|
|
PRUint8 aStyleType)
|
|
|
|
{
|
|
|
|
aValue.Truncate();
|
|
|
|
NS_ENSURE_TRUE(aProperty, NS_ERROR_NULL_POINTER);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMElement>element;
|
|
|
|
nsresult res = GetElementContainerOrSelf(aNode, getter_AddRefs(element));
|
|
|
|
if (NS_FAILED(res)) return res;
|
|
|
|
|
|
|
|
switch (aStyleType) {
|
|
|
|
case COMPUTED_STYLE_TYPE:
|
|
|
|
if (element && aViewCSS) {
|
2005-09-12 05:28:51 +04:00
|
|
|
nsAutoString value, propString;
|
2002-01-09 16:51:37 +03:00
|
|
|
nsCOMPtr<nsIDOMCSSStyleDeclaration> cssDecl;
|
|
|
|
aProperty->ToString(propString);
|
|
|
|
// Get the all the computed css styles attached to the element node
|
2005-09-12 05:28:51 +04:00
|
|
|
res = aViewCSS->GetComputedStyle(element, EmptyString(), getter_AddRefs(cssDecl));
|
2007-01-16 20:04:16 +03:00
|
|
|
if (NS_FAILED(res) || !cssDecl) return res;
|
2002-01-09 16:51:37 +03:00
|
|
|
// from these declarations, get the one we want and that one only
|
|
|
|
res = cssDecl->GetPropertyValue(propString, value);
|
|
|
|
if (NS_FAILED(res)) return res;
|
|
|
|
aValue.Assign(value);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SPECIFIED_STYLE_TYPE:
|
|
|
|
if (element) {
|
|
|
|
nsCOMPtr<nsIDOMCSSStyleDeclaration> cssDecl;
|
2003-09-03 17:54:36 +04:00
|
|
|
PRUint32 length;
|
2002-01-09 16:51:37 +03:00
|
|
|
res = GetInlineStyles(element, getter_AddRefs(cssDecl), &length);
|
2007-01-16 20:04:16 +03:00
|
|
|
if (NS_FAILED(res) || !cssDecl) return res;
|
2002-01-09 16:51:37 +03:00
|
|
|
nsAutoString value, propString;
|
|
|
|
aProperty->ToString(propString);
|
|
|
|
res = cssDecl->GetPropertyValue(propString, value);
|
|
|
|
if (NS_FAILED(res)) return res;
|
|
|
|
aValue.Assign(value);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsHTMLCSSUtils::GetDefaultViewCSS(nsIDOMNode *aNode, nsIDOMViewCSS **aViewCSS)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMElement>element;
|
|
|
|
nsresult res = GetElementContainerOrSelf(aNode, getter_AddRefs(element));
|
|
|
|
if (NS_FAILED(res)) return res;
|
|
|
|
|
|
|
|
// if we have an element node
|
|
|
|
if (element) {
|
|
|
|
// find the owner document
|
2002-03-18 13:40:58 +03:00
|
|
|
nsCOMPtr<nsIDOMDocument> doc;
|
2002-01-09 16:51:37 +03:00
|
|
|
nsCOMPtr<nsIDOMNode> node = do_QueryInterface(element);
|
2002-03-18 13:40:58 +03:00
|
|
|
res = node->GetOwnerDocument(getter_AddRefs(doc));
|
2002-01-09 16:51:37 +03:00
|
|
|
if (NS_FAILED(res)) return res;
|
|
|
|
if (doc) {
|
2003-09-03 17:54:36 +04:00
|
|
|
nsCOMPtr<nsIDOMDocumentView> documentView = do_QueryInterface(doc);
|
2002-03-18 13:40:58 +03:00
|
|
|
nsCOMPtr<nsIDOMAbstractView> abstractView;
|
2002-01-09 16:51:37 +03:00
|
|
|
// from the document, get the abtractView
|
2002-03-18 13:40:58 +03:00
|
|
|
res = documentView->GetDefaultView(getter_AddRefs(abstractView));
|
2002-01-09 16:51:37 +03:00
|
|
|
if (NS_FAILED(res)) return res;
|
2006-08-24 09:09:35 +04:00
|
|
|
if (abstractView) {
|
|
|
|
// from the abstractView, get the CSS view
|
|
|
|
CallQueryInterface(abstractView, aViewCSS);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
*aViewCSS = nsnull;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
NS_NewHTMLCSSUtils(nsHTMLCSSUtils** aInstancePtrResult)
|
|
|
|
{
|
|
|
|
nsHTMLCSSUtils * rules = new nsHTMLCSSUtils();
|
|
|
|
if (rules) {
|
|
|
|
*aInstancePtrResult = rules;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2003-09-03 17:54:36 +04:00
|
|
|
|
|
|
|
*aInstancePtrResult = nsnull;
|
2002-01-09 16:51:37 +03:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
// remove the CSS style "aProperty : aPropertyValue" and possibly remove the whole node
|
|
|
|
// if it is a span and if its only attribute is _moz_dirty
|
|
|
|
nsresult
|
2002-03-24 01:08:20 +03:00
|
|
|
nsHTMLCSSUtils::RemoveCSSInlineStyle(nsIDOMNode *aNode, nsIAtom *aProperty, const nsAString & aPropertyValue)
|
2002-01-09 16:51:37 +03:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMElement> elem = do_QueryInterface(aNode);
|
|
|
|
|
|
|
|
// remove the property from the style attribute
|
2002-09-17 16:04:59 +04:00
|
|
|
nsresult res = RemoveCSSProperty(elem, aProperty, aPropertyValue, PR_FALSE);
|
2002-01-09 16:51:37 +03:00
|
|
|
if (NS_FAILED(res)) return res;
|
|
|
|
|
2003-07-15 17:47:15 +04:00
|
|
|
if (nsEditor::NodeIsType(aNode, nsEditProperty::span)) {
|
2002-01-09 16:51:37 +03:00
|
|
|
nsCOMPtr<nsIContent> content = do_QueryInterface(aNode);
|
2003-09-27 08:18:26 +04:00
|
|
|
PRUint32 attrCount = content->GetAttrCount();
|
|
|
|
|
2002-01-09 16:51:37 +03:00
|
|
|
if (0 == attrCount) {
|
|
|
|
// no more attributes on this span, let's remove the element
|
|
|
|
res = mHTMLEditor->RemoveContainer(aNode);
|
|
|
|
if (NS_FAILED(res)) return res;
|
|
|
|
}
|
|
|
|
else if (1 == attrCount) {
|
|
|
|
// incredible hack in case the only remaining attribute is a _moz_dirty...
|
2005-12-29 00:52:39 +03:00
|
|
|
if (content->GetAttrNameAt(0)->Equals(nsEditProperty::mozdirty)) {
|
2002-01-09 16:51:37 +03:00
|
|
|
res = mHTMLEditor->RemoveContainer(aNode);
|
|
|
|
if (NS_FAILED(res)) return res;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Answers true is the property can be removed by setting a "none" CSS value
|
|
|
|
// on a node
|
|
|
|
PRBool
|
2002-03-24 01:08:20 +03:00
|
|
|
nsHTMLCSSUtils::IsCSSInvertable(nsIAtom *aProperty, const nsAString *aAttribute)
|
2002-01-09 16:51:37 +03:00
|
|
|
{
|
2003-04-17 09:42:33 +04:00
|
|
|
return PRBool(nsEditProperty::b == aProperty);
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Get the default browser background color if we need it for GetCSSBackgroundColorState
|
|
|
|
nsresult
|
2002-03-24 01:08:20 +03:00
|
|
|
nsHTMLCSSUtils::GetDefaultBackgroundColor(nsAString & aColor)
|
2002-01-09 16:51:37 +03:00
|
|
|
{
|
|
|
|
nsresult result;
|
2002-11-23 04:26:58 +03:00
|
|
|
nsCOMPtr<nsIPrefBranch> prefBranch =
|
|
|
|
do_GetService(NS_PREFSERVICE_CONTRACTID, &result);
|
2002-01-09 16:51:37 +03:00
|
|
|
if (NS_FAILED(result)) return result;
|
2004-06-17 04:13:25 +04:00
|
|
|
aColor.AssignLiteral("#ffffff");
|
2002-01-09 16:51:37 +03:00
|
|
|
nsXPIDLCString returnColor;
|
2002-11-23 04:26:58 +03:00
|
|
|
if (prefBranch) {
|
2002-01-09 16:51:37 +03:00
|
|
|
PRBool useCustomColors;
|
2002-11-23 04:26:58 +03:00
|
|
|
result = prefBranch->GetBoolPref("editor.use_custom_colors", &useCustomColors);
|
2002-01-09 16:51:37 +03:00
|
|
|
if (NS_FAILED(result)) return result;
|
|
|
|
if (useCustomColors) {
|
2002-11-23 04:26:58 +03:00
|
|
|
result = prefBranch->GetCharPref("editor.background_color",
|
|
|
|
getter_Copies(returnColor));
|
2002-01-09 16:51:37 +03:00
|
|
|
if (NS_FAILED(result)) return result;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
PRBool useSystemColors;
|
2002-11-23 04:26:58 +03:00
|
|
|
result = prefBranch->GetBoolPref("browser.display.use_system_colors", &useSystemColors);
|
2002-01-09 16:51:37 +03:00
|
|
|
if (NS_FAILED(result)) return result;
|
|
|
|
if (!useSystemColors) {
|
2002-11-23 04:26:58 +03:00
|
|
|
result = prefBranch->GetCharPref("browser.display.background_color",
|
|
|
|
getter_Copies(returnColor));
|
2002-01-09 16:51:37 +03:00
|
|
|
if (NS_FAILED(result)) return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (returnColor) {
|
2004-01-30 01:04:45 +03:00
|
|
|
CopyASCIItoUTF16(returnColor, aColor);
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the default length unit used for CSS Indent/Outdent
|
|
|
|
nsresult
|
2002-03-24 01:08:20 +03:00
|
|
|
nsHTMLCSSUtils::GetDefaultLengthUnit(nsAString & aLengthUnit)
|
2002-01-09 16:51:37 +03:00
|
|
|
{
|
|
|
|
nsresult result;
|
2002-11-23 04:26:58 +03:00
|
|
|
nsCOMPtr<nsIPrefBranch> prefBranch =
|
|
|
|
do_GetService(NS_PREFSERVICE_CONTRACTID, &result);
|
2002-01-09 16:51:37 +03:00
|
|
|
if (NS_FAILED(result)) return result;
|
2004-06-17 04:13:25 +04:00
|
|
|
aLengthUnit.AssignLiteral("px");
|
2002-11-23 04:26:58 +03:00
|
|
|
if (NS_SUCCEEDED(result) && prefBranch) {
|
2002-01-09 16:51:37 +03:00
|
|
|
nsXPIDLCString returnLengthUnit;
|
2002-11-23 04:26:58 +03:00
|
|
|
result = prefBranch->GetCharPref("editor.css.default_length_unit",
|
|
|
|
getter_Copies(returnLengthUnit));
|
2002-01-09 16:51:37 +03:00
|
|
|
if (NS_FAILED(result)) return result;
|
|
|
|
if (returnLengthUnit) {
|
2004-01-30 01:04:45 +03:00
|
|
|
CopyASCIItoUTF16(returnLengthUnit, aLengthUnit);
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Unfortunately, CSSStyleDeclaration::GetPropertyCSSValue is not yet implemented...
|
|
|
|
// We need then a way to determine the number part and the unit from aString, aString
|
|
|
|
// being the result of a GetPropertyValue query...
|
|
|
|
void
|
2002-03-24 01:08:20 +03:00
|
|
|
nsHTMLCSSUtils::ParseLength(const nsAString & aString, float * aValue, nsIAtom ** aUnit)
|
2002-01-09 16:51:37 +03:00
|
|
|
{
|
|
|
|
nsAString::const_iterator iter;
|
|
|
|
aString.BeginReading(iter);
|
|
|
|
|
|
|
|
float a = 10.0f , b = 1.0f, value = 0;
|
|
|
|
PRInt8 sign = 1;
|
|
|
|
PRInt32 i = 0, j = aString.Length();
|
|
|
|
PRUnichar c;
|
|
|
|
nsAutoString unit;
|
|
|
|
PRBool floatingPointFound = PR_FALSE;
|
|
|
|
c = *iter;
|
|
|
|
if (PRUnichar('-') == c) { sign = -1; iter++; i++; }
|
|
|
|
else if (PRUnichar('+') == c) { iter++; i++; }
|
|
|
|
while (i < j) {
|
|
|
|
c = *iter;
|
|
|
|
if ((PRUnichar('0') == c) ||
|
|
|
|
(PRUnichar('1') == c) ||
|
|
|
|
(PRUnichar('2') == c) ||
|
|
|
|
(PRUnichar('3') == c) ||
|
|
|
|
(PRUnichar('4') == c) ||
|
|
|
|
(PRUnichar('5') == c) ||
|
|
|
|
(PRUnichar('6') == c) ||
|
|
|
|
(PRUnichar('7') == c) ||
|
|
|
|
(PRUnichar('8') == c) ||
|
|
|
|
(PRUnichar('9') == c)) {
|
|
|
|
value = (value * a) + (b * (c - PRUnichar('0')));
|
|
|
|
b = b / 10 * a;
|
|
|
|
}
|
|
|
|
else if (!floatingPointFound && (PRUnichar('.') == c)) {
|
|
|
|
floatingPointFound = PR_TRUE;
|
|
|
|
a = 1.0f; b = 0.1f;
|
|
|
|
}
|
|
|
|
else break;
|
|
|
|
iter++;
|
|
|
|
i++;
|
|
|
|
}
|
2002-04-30 00:29:54 +04:00
|
|
|
unit = Substring(aString, aString.Length() - (j-i), j-i);
|
2002-01-09 16:51:37 +03:00
|
|
|
*aValue = value * sign;
|
|
|
|
*aUnit = NS_NewAtom(unit);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHTMLCSSUtils::GetCSSPropertyAtom(nsCSSEditableProperty aProperty, nsIAtom ** aAtom)
|
|
|
|
{
|
|
|
|
*aAtom = nsnull;
|
|
|
|
if (0 < aProperty) {
|
|
|
|
switch (aProperty) {
|
|
|
|
case eCSSEditableProperty_background_color:
|
2003-04-17 09:42:33 +04:00
|
|
|
*aAtom = nsEditProperty::cssBackgroundColor;
|
2002-01-09 16:51:37 +03:00
|
|
|
break;
|
|
|
|
case eCSSEditableProperty_background_image:
|
2003-04-17 09:42:33 +04:00
|
|
|
*aAtom = nsEditProperty::cssBackgroundImage;
|
2002-01-09 16:51:37 +03:00
|
|
|
break;
|
|
|
|
case eCSSEditableProperty_border:
|
2003-04-17 09:42:33 +04:00
|
|
|
*aAtom = nsEditProperty::cssBorder;
|
2002-01-09 16:51:37 +03:00
|
|
|
break;
|
|
|
|
case eCSSEditableProperty_caption_side:
|
2003-04-17 09:42:33 +04:00
|
|
|
*aAtom = nsEditProperty::cssCaptionSide;
|
2002-01-09 16:51:37 +03:00
|
|
|
break;
|
|
|
|
case eCSSEditableProperty_color:
|
2003-04-17 09:42:33 +04:00
|
|
|
*aAtom = nsEditProperty::cssColor;
|
2002-01-09 16:51:37 +03:00
|
|
|
break;
|
|
|
|
case eCSSEditableProperty_float:
|
2003-04-17 09:42:33 +04:00
|
|
|
*aAtom = nsEditProperty::cssFloat;
|
2002-01-09 16:51:37 +03:00
|
|
|
break;
|
|
|
|
case eCSSEditableProperty_font_family:
|
2003-04-17 09:42:33 +04:00
|
|
|
*aAtom = nsEditProperty::cssFontFamily;
|
2002-01-09 16:51:37 +03:00
|
|
|
break;
|
|
|
|
case eCSSEditableProperty_font_size:
|
2003-04-17 09:42:33 +04:00
|
|
|
*aAtom = nsEditProperty::cssFontSize;
|
2002-01-09 16:51:37 +03:00
|
|
|
break;
|
|
|
|
case eCSSEditableProperty_font_style:
|
2003-04-17 09:42:33 +04:00
|
|
|
*aAtom = nsEditProperty::cssFontStyle;
|
2002-01-09 16:51:37 +03:00
|
|
|
break;
|
|
|
|
case eCSSEditableProperty_font_weight:
|
2003-04-17 09:42:33 +04:00
|
|
|
*aAtom = nsEditProperty::cssFontWeight;
|
2002-01-09 16:51:37 +03:00
|
|
|
break;
|
|
|
|
case eCSSEditableProperty_height:
|
2003-04-17 09:42:33 +04:00
|
|
|
*aAtom = nsEditProperty::cssHeight;
|
2002-01-09 16:51:37 +03:00
|
|
|
break;
|
|
|
|
case eCSSEditableProperty_list_style_type:
|
2003-04-17 09:42:33 +04:00
|
|
|
*aAtom = nsEditProperty::cssListStyleType;
|
2002-01-09 16:51:37 +03:00
|
|
|
break;
|
|
|
|
case eCSSEditableProperty_margin_left:
|
2003-04-17 09:42:33 +04:00
|
|
|
*aAtom = nsEditProperty::cssMarginLeft;
|
2002-01-09 16:51:37 +03:00
|
|
|
break;
|
|
|
|
case eCSSEditableProperty_margin_right:
|
2003-04-17 09:42:33 +04:00
|
|
|
*aAtom = nsEditProperty::cssMarginRight;
|
2002-01-09 16:51:37 +03:00
|
|
|
break;
|
|
|
|
case eCSSEditableProperty_text_align:
|
2003-04-17 09:42:33 +04:00
|
|
|
*aAtom = nsEditProperty::cssTextAlign;
|
2002-01-09 16:51:37 +03:00
|
|
|
break;
|
|
|
|
case eCSSEditableProperty_text_decoration:
|
2003-04-17 09:42:33 +04:00
|
|
|
*aAtom = nsEditProperty::cssTextDecoration;
|
2002-01-09 16:51:37 +03:00
|
|
|
break;
|
|
|
|
case eCSSEditableProperty_vertical_align:
|
2003-04-17 09:42:33 +04:00
|
|
|
*aAtom = nsEditProperty::cssVerticalAlign;
|
2002-01-09 16:51:37 +03:00
|
|
|
break;
|
|
|
|
case eCSSEditableProperty_whitespace:
|
2003-04-17 09:42:33 +04:00
|
|
|
*aAtom = nsEditProperty::cssWhitespace;
|
2002-01-09 16:51:37 +03:00
|
|
|
break;
|
|
|
|
case eCSSEditableProperty_width:
|
2003-04-17 09:42:33 +04:00
|
|
|
*aAtom = nsEditProperty::cssWidth;
|
2002-01-09 16:51:37 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Populate aProperty and aValueArray with the CSS declarations equivalent to the
|
|
|
|
// value aValue according to the equivalence table aEquivTable
|
|
|
|
void
|
|
|
|
nsHTMLCSSUtils::BuildCSSDeclarations(nsVoidArray & aPropertyArray,
|
|
|
|
nsStringArray & aValueArray,
|
|
|
|
const CSSEquivTable * aEquivTable,
|
2002-03-24 01:08:20 +03:00
|
|
|
const nsAString * aValue,
|
2002-01-09 16:51:37 +03:00
|
|
|
PRBool aGetOrRemoveRequest)
|
|
|
|
{
|
|
|
|
// clear arrays
|
|
|
|
aPropertyArray.Clear();
|
|
|
|
aValueArray.Clear();
|
|
|
|
|
|
|
|
// if we have an input value, let's use it
|
2002-08-23 13:24:47 +04:00
|
|
|
nsAutoString value, lowerCasedValue;
|
2002-01-09 16:51:37 +03:00
|
|
|
if (aValue) {
|
|
|
|
value.Assign(*aValue);
|
2002-08-23 13:24:47 +04:00
|
|
|
lowerCasedValue.Assign(*aValue);
|
|
|
|
ToLowerCase(lowerCasedValue);
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
PRInt8 index = 0;
|
|
|
|
nsCSSEditableProperty cssProperty = aEquivTable[index].cssProperty;
|
|
|
|
while (cssProperty) {
|
|
|
|
if (!aGetOrRemoveRequest|| aEquivTable[index].gettable) {
|
|
|
|
nsAutoString cssValue, cssPropertyString;
|
|
|
|
nsIAtom * cssPropertyAtom;
|
|
|
|
// find the equivalent css value for the index-th property in
|
|
|
|
// the equivalence table
|
2004-06-28 16:43:49 +04:00
|
|
|
(*aEquivTable[index].processValueFunctor) ((!aGetOrRemoveRequest || aEquivTable[index].caseSensitiveValue) ? &value : &lowerCasedValue,
|
2002-08-23 13:24:47 +04:00
|
|
|
cssValue,
|
2002-01-09 16:51:37 +03:00
|
|
|
aEquivTable[index].defaultValue,
|
|
|
|
aEquivTable[index].prependValue,
|
|
|
|
aEquivTable[index].appendValue);
|
|
|
|
GetCSSPropertyAtom(cssProperty, &cssPropertyAtom);
|
|
|
|
aPropertyArray.AppendElement(cssPropertyAtom);
|
|
|
|
aValueArray.AppendString(cssValue);
|
|
|
|
}
|
|
|
|
index++;
|
|
|
|
cssProperty = aEquivTable[index].cssProperty;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Populate cssPropertyArray and cssValueArray with the declarations equivalent
|
|
|
|
// to aHTMLProperty/aAttribute/aValue for the node aNode
|
|
|
|
void
|
|
|
|
nsHTMLCSSUtils::GenerateCSSDeclarationsFromHTMLStyle(nsIDOMNode * aNode,
|
|
|
|
nsIAtom *aHTMLProperty,
|
2002-03-24 01:08:20 +03:00
|
|
|
const nsAString * aAttribute,
|
|
|
|
const nsAString * aValue,
|
2002-01-09 16:51:37 +03:00
|
|
|
nsVoidArray & cssPropertyArray,
|
|
|
|
nsStringArray & cssValueArray,
|
|
|
|
PRBool aGetOrRemoveRequest)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMNode> node = aNode;
|
|
|
|
if (mHTMLEditor->IsTextNode(aNode)) {
|
|
|
|
aNode->GetParentNode(getter_AddRefs(node));
|
|
|
|
}
|
|
|
|
if (!node) return;
|
|
|
|
|
2003-11-19 04:20:56 +03:00
|
|
|
nsIAtom *tagName = nsEditor::GetTag(node);
|
2002-01-09 16:51:37 +03:00
|
|
|
|
2003-04-17 09:42:33 +04:00
|
|
|
if (nsEditProperty::b == aHTMLProperty) {
|
2002-01-09 16:51:37 +03:00
|
|
|
BuildCSSDeclarations(cssPropertyArray, cssValueArray, boldEquivTable, aValue, aGetOrRemoveRequest);
|
|
|
|
}
|
2003-04-17 09:42:33 +04:00
|
|
|
else if (nsEditProperty::i == aHTMLProperty) {
|
2002-01-09 16:51:37 +03:00
|
|
|
BuildCSSDeclarations(cssPropertyArray, cssValueArray, italicEquivTable, aValue, aGetOrRemoveRequest);
|
|
|
|
}
|
2003-04-17 09:42:33 +04:00
|
|
|
else if (nsEditProperty::u == aHTMLProperty) {
|
2002-01-09 16:51:37 +03:00
|
|
|
BuildCSSDeclarations(cssPropertyArray, cssValueArray, underlineEquivTable, aValue, aGetOrRemoveRequest);
|
|
|
|
}
|
2003-04-17 09:42:33 +04:00
|
|
|
else if (nsEditProperty::strike == aHTMLProperty) {
|
2002-01-09 16:51:37 +03:00
|
|
|
BuildCSSDeclarations(cssPropertyArray, cssValueArray, strikeEquivTable, aValue, aGetOrRemoveRequest);
|
|
|
|
}
|
2003-04-17 09:42:33 +04:00
|
|
|
else if (nsEditProperty::tt == aHTMLProperty) {
|
2002-01-09 16:51:37 +03:00
|
|
|
BuildCSSDeclarations(cssPropertyArray, cssValueArray, ttEquivTable, aValue, aGetOrRemoveRequest);
|
|
|
|
}
|
|
|
|
else if (aAttribute) {
|
2003-04-17 09:42:33 +04:00
|
|
|
if (nsEditProperty::font == aHTMLProperty &&
|
2004-05-23 02:15:22 +04:00
|
|
|
aAttribute->EqualsLiteral("color")) {
|
2002-01-09 16:51:37 +03:00
|
|
|
BuildCSSDeclarations(cssPropertyArray, cssValueArray, fontColorEquivTable, aValue, aGetOrRemoveRequest);
|
|
|
|
}
|
2003-04-17 09:42:33 +04:00
|
|
|
else if (nsEditProperty::font == aHTMLProperty &&
|
2004-05-23 02:15:22 +04:00
|
|
|
aAttribute->EqualsLiteral("face")) {
|
2002-01-09 16:51:37 +03:00
|
|
|
BuildCSSDeclarations(cssPropertyArray, cssValueArray, fontFaceEquivTable, aValue, aGetOrRemoveRequest);
|
|
|
|
}
|
2004-05-23 02:15:22 +04:00
|
|
|
else if (aAttribute->EqualsLiteral("bgcolor")) {
|
2002-01-09 16:51:37 +03:00
|
|
|
BuildCSSDeclarations(cssPropertyArray, cssValueArray, bgcolorEquivTable, aValue, aGetOrRemoveRequest);
|
|
|
|
}
|
2004-05-23 02:15:22 +04:00
|
|
|
else if (aAttribute->EqualsLiteral("background")) {
|
2002-01-09 16:51:37 +03:00
|
|
|
BuildCSSDeclarations(cssPropertyArray, cssValueArray, backgroundImageEquivTable, aValue, aGetOrRemoveRequest);
|
|
|
|
}
|
2004-05-23 02:15:22 +04:00
|
|
|
else if (aAttribute->EqualsLiteral("text")) {
|
2002-01-09 16:51:37 +03:00
|
|
|
BuildCSSDeclarations(cssPropertyArray, cssValueArray, textColorEquivTable, aValue, aGetOrRemoveRequest);
|
|
|
|
}
|
2004-05-23 02:15:22 +04:00
|
|
|
else if (aAttribute->EqualsLiteral("border")) {
|
2002-01-09 16:51:37 +03:00
|
|
|
BuildCSSDeclarations(cssPropertyArray, cssValueArray, borderEquivTable, aValue, aGetOrRemoveRequest);
|
|
|
|
}
|
2004-05-23 02:15:22 +04:00
|
|
|
else if (aAttribute->EqualsLiteral("align")) {
|
2003-04-17 09:42:33 +04:00
|
|
|
if (nsEditProperty::table == tagName) {
|
2002-01-09 16:51:37 +03:00
|
|
|
BuildCSSDeclarations(cssPropertyArray, cssValueArray, tableAlignEquivTable, aValue, aGetOrRemoveRequest);
|
|
|
|
}
|
2003-04-17 09:42:33 +04:00
|
|
|
else if (nsEditProperty::hr == tagName) {
|
2002-01-09 16:51:37 +03:00
|
|
|
BuildCSSDeclarations(cssPropertyArray, cssValueArray, hrAlignEquivTable, aValue, aGetOrRemoveRequest);
|
|
|
|
}
|
2003-04-17 09:42:33 +04:00
|
|
|
else if (nsEditProperty::legend == tagName ||
|
|
|
|
nsEditProperty::caption == tagName) {
|
2002-01-09 16:51:37 +03:00
|
|
|
BuildCSSDeclarations(cssPropertyArray, cssValueArray, captionAlignEquivTable, aValue, aGetOrRemoveRequest);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
BuildCSSDeclarations(cssPropertyArray, cssValueArray, textAlignEquivTable, aValue, aGetOrRemoveRequest);
|
|
|
|
}
|
|
|
|
}
|
2004-05-23 02:15:22 +04:00
|
|
|
else if (aAttribute->EqualsLiteral("valign")) {
|
2002-01-09 16:51:37 +03:00
|
|
|
BuildCSSDeclarations(cssPropertyArray, cssValueArray, verticalAlignEquivTable, aValue, aGetOrRemoveRequest);
|
|
|
|
}
|
2004-05-23 02:15:22 +04:00
|
|
|
else if (aAttribute->EqualsLiteral("nowrap")) {
|
2002-01-09 16:51:37 +03:00
|
|
|
BuildCSSDeclarations(cssPropertyArray, cssValueArray, nowrapEquivTable, aValue, aGetOrRemoveRequest);
|
|
|
|
}
|
2004-05-23 02:15:22 +04:00
|
|
|
else if (aAttribute->EqualsLiteral("width")) {
|
2002-01-09 16:51:37 +03:00
|
|
|
BuildCSSDeclarations(cssPropertyArray, cssValueArray, widthEquivTable, aValue, aGetOrRemoveRequest);
|
|
|
|
}
|
2004-05-23 02:15:22 +04:00
|
|
|
else if (aAttribute->EqualsLiteral("height") ||
|
|
|
|
(nsEditProperty::hr == tagName && aAttribute->EqualsLiteral("size"))) {
|
2002-01-09 16:51:37 +03:00
|
|
|
BuildCSSDeclarations(cssPropertyArray, cssValueArray, heightEquivTable, aValue, aGetOrRemoveRequest);
|
|
|
|
}
|
2004-05-23 02:15:22 +04:00
|
|
|
else if (aAttribute->EqualsLiteral("type") &&
|
2003-04-17 09:42:33 +04:00
|
|
|
(nsEditProperty::ol == tagName
|
|
|
|
|| nsEditProperty::ul == tagName
|
|
|
|
|| nsEditProperty::li == tagName)) {
|
2002-01-09 16:51:37 +03:00
|
|
|
BuildCSSDeclarations(cssPropertyArray, cssValueArray, listStyleTypeEquivTable, aValue, aGetOrRemoveRequest);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add to aNode the CSS inline style equivalent to HTMLProperty/aAttribute/aValue for the node,
|
|
|
|
// and return in aCount the number of CSS properties set by the call
|
|
|
|
nsresult
|
|
|
|
nsHTMLCSSUtils::SetCSSEquivalentToHTMLStyle(nsIDOMNode * aNode,
|
|
|
|
nsIAtom *aHTMLProperty,
|
2002-03-24 01:08:20 +03:00
|
|
|
const nsAString *aAttribute,
|
|
|
|
const nsAString *aValue,
|
2002-09-17 16:04:59 +04:00
|
|
|
PRInt32 * aCount,
|
|
|
|
PRBool aSuppressTransaction)
|
2002-01-09 16:51:37 +03:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMElement> theElement = do_QueryInterface(aNode);
|
|
|
|
nsresult res = NS_OK;
|
|
|
|
*aCount = 0;
|
|
|
|
if (theElement && IsCSSEditableProperty(aNode, aHTMLProperty, aAttribute)) {
|
|
|
|
// we can apply the styles only if the node is an element and if we have
|
|
|
|
// an equivalence for the requested HTML style in this implementation
|
|
|
|
|
|
|
|
// Find the CSS equivalence to the HTML style
|
|
|
|
nsVoidArray cssPropertyArray;
|
|
|
|
nsStringArray cssValueArray;
|
|
|
|
GenerateCSSDeclarationsFromHTMLStyle(aNode, aHTMLProperty, aAttribute, aValue,
|
|
|
|
cssPropertyArray, cssValueArray, PR_FALSE);
|
|
|
|
|
|
|
|
// set the individual CSS inline styles
|
|
|
|
*aCount = cssPropertyArray.Count();
|
|
|
|
PRInt32 index;
|
|
|
|
for (index = 0; index < *aCount; index++) {
|
|
|
|
nsAutoString valueString;
|
|
|
|
cssValueArray.StringAt(index, valueString);
|
|
|
|
nsCOMPtr<nsIDOMElement> theElement = do_QueryInterface(aNode);
|
|
|
|
res = SetCSSProperty(theElement, (nsIAtom *)cssPropertyArray.ElementAt(index),
|
2002-09-17 16:04:59 +04:00
|
|
|
valueString, aSuppressTransaction);
|
2002-01-09 16:51:37 +03:00
|
|
|
if (NS_FAILED(res)) return res;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove from aNode the CSS inline style equivalent to HTMLProperty/aAttribute/aValue for the node
|
|
|
|
nsresult
|
|
|
|
nsHTMLCSSUtils::RemoveCSSEquivalentToHTMLStyle(nsIDOMNode * aNode,
|
2002-09-17 16:04:59 +04:00
|
|
|
nsIAtom *aHTMLProperty,
|
|
|
|
const nsAString *aAttribute,
|
|
|
|
const nsAString *aValue,
|
|
|
|
PRBool aSuppressTransaction)
|
2002-01-09 16:51:37 +03:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMElement> theElement = do_QueryInterface(aNode);
|
|
|
|
nsresult res = NS_OK;
|
|
|
|
PRInt32 count = 0;
|
|
|
|
if (theElement && IsCSSEditableProperty(aNode, aHTMLProperty, aAttribute)) {
|
|
|
|
// we can apply the styles only if the node is an element and if we have
|
|
|
|
// an equivalence for the requested HTML style in this implementation
|
|
|
|
|
|
|
|
// Find the CSS equivalence to the HTML style
|
|
|
|
nsVoidArray cssPropertyArray;
|
|
|
|
nsStringArray cssValueArray;
|
|
|
|
GenerateCSSDeclarationsFromHTMLStyle(aNode, aHTMLProperty, aAttribute, aValue,
|
|
|
|
cssPropertyArray, cssValueArray, PR_TRUE);
|
|
|
|
|
|
|
|
// remove the individual CSS inline styles
|
|
|
|
count = cssPropertyArray.Count();
|
|
|
|
PRInt32 index;
|
|
|
|
for (index = 0; index < count; index++) {
|
|
|
|
nsAutoString valueString;
|
|
|
|
cssValueArray.StringAt(index, valueString);
|
2002-09-17 16:04:59 +04:00
|
|
|
res = RemoveCSSProperty(theElement, (nsIAtom *)cssPropertyArray.ElementAt(index), valueString,
|
|
|
|
aSuppressTransaction);
|
2002-01-09 16:51:37 +03:00
|
|
|
if (NS_FAILED(res)) return res;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// aReturn is true if the element aElement carries an ID or a class.
|
|
|
|
nsresult
|
|
|
|
nsHTMLCSSUtils::HasClassOrID(nsIDOMElement * aElement, PRBool & aReturn)
|
|
|
|
{
|
|
|
|
nsAutoString classVal, idVal;
|
|
|
|
PRBool isClassSet, isIdSet;
|
|
|
|
aReturn = PR_FALSE;
|
|
|
|
|
|
|
|
nsresult res = mHTMLEditor->GetAttributeValue(aElement, NS_LITERAL_STRING("class"), classVal, &isClassSet);
|
|
|
|
if (NS_FAILED(res)) return res;
|
|
|
|
res = mHTMLEditor->GetAttributeValue(aElement, NS_LITERAL_STRING("id"), idVal, &isIdSet);
|
|
|
|
if (NS_FAILED(res)) return res;
|
|
|
|
|
|
|
|
// we need to make sure that if the element has an id or a class attribute,
|
|
|
|
// the attribute is not the empty string
|
2003-05-24 01:34:47 +04:00
|
|
|
aReturn = ((isClassSet && !classVal.IsEmpty()) ||
|
|
|
|
(isIdSet && !idVal.IsEmpty()));
|
2002-01-09 16:51:37 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// returns in aValueString the list of values for the CSS equivalences to
|
|
|
|
// the HTML style aHTMLProperty/aAttribute/aValueString for the node aNode;
|
|
|
|
// the value of aStyleType controls the styles we retrieve : specified or
|
|
|
|
// computed.
|
|
|
|
nsresult
|
|
|
|
nsHTMLCSSUtils::GetCSSEquivalentToHTMLInlineStyleSet(nsIDOMNode * aNode,
|
|
|
|
nsIAtom *aHTMLProperty,
|
2002-03-24 01:08:20 +03:00
|
|
|
const nsAString *aAttribute,
|
|
|
|
nsAString & aValueString,
|
2002-01-09 16:51:37 +03:00
|
|
|
PRUint8 aStyleType)
|
|
|
|
{
|
2003-09-03 17:54:36 +04:00
|
|
|
aValueString.Truncate();
|
2002-01-09 16:51:37 +03:00
|
|
|
nsCOMPtr<nsIDOMElement> theElement;
|
|
|
|
nsresult res = GetElementContainerOrSelf(aNode, getter_AddRefs(theElement));
|
|
|
|
if (NS_FAILED(res)) return res;
|
|
|
|
|
2003-09-03 17:54:36 +04:00
|
|
|
if (theElement && IsCSSEditableProperty(theElement, aHTMLProperty, aAttribute)) {
|
2002-01-09 16:51:37 +03:00
|
|
|
// Yes, the requested HTML style has a CSS equivalence in this implementation
|
|
|
|
// Retrieve the default ViewCSS if we are asked for computed styles
|
|
|
|
nsCOMPtr<nsIDOMViewCSS> viewCSS = nsnull;
|
|
|
|
if (COMPUTED_STYLE_TYPE == aStyleType) {
|
2003-09-03 17:54:36 +04:00
|
|
|
res = GetDefaultViewCSS(theElement, getter_AddRefs(viewCSS));
|
2002-01-09 16:51:37 +03:00
|
|
|
if (NS_FAILED(res)) return res;
|
|
|
|
}
|
|
|
|
nsVoidArray cssPropertyArray;
|
|
|
|
nsStringArray cssValueArray;
|
|
|
|
// get the CSS equivalence with last param PR_TRUE indicating we want only the
|
|
|
|
// "gettable" properties
|
2003-09-03 17:54:36 +04:00
|
|
|
GenerateCSSDeclarationsFromHTMLStyle(theElement, aHTMLProperty, aAttribute, nsnull,
|
2002-01-09 16:51:37 +03:00
|
|
|
cssPropertyArray, cssValueArray, PR_TRUE);
|
|
|
|
PRInt32 count = cssPropertyArray.Count();
|
|
|
|
PRInt32 index;
|
|
|
|
for (index = 0; index < count; index++) {
|
|
|
|
nsAutoString valueString;
|
|
|
|
// retrieve the specified/computed value of the property
|
2003-09-03 17:54:36 +04:00
|
|
|
res = GetCSSInlinePropertyBase(theElement, (nsIAtom *)cssPropertyArray.ElementAt(index),
|
2002-01-09 16:51:37 +03:00
|
|
|
valueString, viewCSS, aStyleType);
|
|
|
|
if (NS_FAILED(res)) return res;
|
|
|
|
// append the value to aValueString (possibly with a leading whitespace)
|
|
|
|
if (index) aValueString.Append(PRUnichar(' '));
|
|
|
|
aValueString.Append(valueString);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Does the node aNode (or his parent if it is not an element node) carries
|
|
|
|
// the CSS equivalent styles to the HTML style aHTMLProperty/aAttribute/
|
|
|
|
// aValueString for this node ?
|
|
|
|
// The value of aStyleType controls the styles we retrieve : specified or
|
|
|
|
// computed. The return value aIsSet is true is the CSS styles are set.
|
|
|
|
nsresult
|
|
|
|
nsHTMLCSSUtils::IsCSSEquivalentToHTMLInlineStyleSet(nsIDOMNode * aNode,
|
|
|
|
nsIAtom *aHTMLProperty,
|
2002-03-24 01:08:20 +03:00
|
|
|
const nsAString * aHTMLAttribute,
|
2002-01-09 16:51:37 +03:00
|
|
|
PRBool & aIsSet,
|
2002-03-24 01:08:20 +03:00
|
|
|
nsAString & valueString,
|
2002-01-09 16:51:37 +03:00
|
|
|
PRUint8 aStyleType)
|
|
|
|
{
|
|
|
|
NS_ENSURE_TRUE(aNode, NS_ERROR_NULL_POINTER);
|
|
|
|
|
|
|
|
nsAutoString htmlValueString(valueString);
|
|
|
|
aIsSet = PR_FALSE;
|
|
|
|
nsCOMPtr<nsIDOMNode> node = aNode;
|
2003-09-03 17:54:36 +04:00
|
|
|
NS_NAMED_LITERAL_STRING(boldStr, "bold");
|
2002-01-09 16:51:37 +03:00
|
|
|
do {
|
|
|
|
valueString.Assign(htmlValueString);
|
|
|
|
// get the value of the CSS equivalent styles
|
|
|
|
nsresult res = GetCSSEquivalentToHTMLInlineStyleSet(node, aHTMLProperty, aHTMLAttribute,
|
|
|
|
valueString, aStyleType);
|
|
|
|
if (NS_FAILED(res)) return res;
|
|
|
|
|
|
|
|
// early way out if we can
|
2003-04-17 11:35:55 +04:00
|
|
|
if (valueString.IsEmpty()) return NS_OK;
|
2002-01-09 16:51:37 +03:00
|
|
|
|
2003-04-17 09:42:33 +04:00
|
|
|
if (nsEditProperty::b == aHTMLProperty) {
|
2003-09-03 17:54:36 +04:00
|
|
|
if (valueString.Equals(boldStr)) {
|
2002-01-09 16:51:37 +03:00
|
|
|
aIsSet = PR_TRUE;
|
|
|
|
}
|
2004-05-23 02:15:22 +04:00
|
|
|
else if (valueString.EqualsLiteral("normal")) {
|
2002-01-09 16:51:37 +03:00
|
|
|
aIsSet = PR_FALSE;
|
|
|
|
}
|
2004-05-23 02:15:22 +04:00
|
|
|
else if (valueString.EqualsLiteral("bolder")) {
|
2002-01-09 16:51:37 +03:00
|
|
|
aIsSet = PR_TRUE;
|
2003-09-03 17:54:36 +04:00
|
|
|
valueString.Assign(boldStr);
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
PRInt32 weight = 0;
|
|
|
|
PRInt32 errorCode;
|
|
|
|
nsAutoString value(valueString);
|
|
|
|
weight = value.ToInteger(&errorCode, 10);
|
|
|
|
if (400 < weight) {
|
|
|
|
aIsSet = PR_TRUE;
|
2003-09-03 17:54:36 +04:00
|
|
|
valueString.Assign(boldStr);
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
aIsSet = PR_FALSE;
|
2004-06-17 04:13:25 +04:00
|
|
|
valueString.AssignLiteral("normal");
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-04-17 09:42:33 +04:00
|
|
|
else if (nsEditProperty::i == aHTMLProperty) {
|
2004-05-23 02:15:22 +04:00
|
|
|
if (valueString.EqualsLiteral("italic") ||
|
|
|
|
valueString.EqualsLiteral("oblique")) {
|
2002-01-09 16:51:37 +03:00
|
|
|
aIsSet= PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-04-17 09:42:33 +04:00
|
|
|
else if (nsEditProperty::u == aHTMLProperty) {
|
2002-01-09 16:51:37 +03:00
|
|
|
nsAutoString val;
|
2004-06-17 04:13:25 +04:00
|
|
|
val.AssignLiteral("underline");
|
2002-01-09 16:51:37 +03:00
|
|
|
aIsSet = PRBool(ChangeCSSInlineStyleTxn::ValueIncludes(valueString, val, PR_FALSE));
|
|
|
|
}
|
|
|
|
|
2003-04-17 09:42:33 +04:00
|
|
|
else if (nsEditProperty::strike == aHTMLProperty) {
|
2002-01-09 16:51:37 +03:00
|
|
|
nsAutoString val;
|
2004-06-17 04:13:25 +04:00
|
|
|
val.AssignLiteral("line-through");
|
2002-01-09 16:51:37 +03:00
|
|
|
aIsSet = PRBool(ChangeCSSInlineStyleTxn::ValueIncludes(valueString, val, PR_FALSE));
|
|
|
|
}
|
|
|
|
|
2002-12-13 11:56:21 +03:00
|
|
|
else if (aHTMLAttribute &&
|
2003-04-17 09:42:33 +04:00
|
|
|
( (nsEditProperty::font == aHTMLProperty &&
|
2004-05-23 02:15:22 +04:00
|
|
|
aHTMLAttribute->EqualsLiteral("color")) ||
|
|
|
|
aHTMLAttribute->EqualsLiteral("bgcolor"))) {
|
2002-12-13 11:56:21 +03:00
|
|
|
if (htmlValueString.IsEmpty())
|
|
|
|
aIsSet = PR_TRUE;
|
|
|
|
else {
|
|
|
|
nscolor rgba;
|
|
|
|
nsAutoString subStr;
|
|
|
|
htmlValueString.Right(subStr, htmlValueString.Length()-1);
|
|
|
|
if (NS_ColorNameToRGB(htmlValueString, &rgba) ||
|
|
|
|
NS_HexToRGB(subStr, &rgba)) {
|
|
|
|
nsAutoString htmlColor, tmpStr;
|
2004-06-17 04:13:25 +04:00
|
|
|
htmlColor.AppendLiteral("rgb(");
|
2002-12-13 11:56:21 +03:00
|
|
|
|
|
|
|
NS_NAMED_LITERAL_STRING(comma, ", ");
|
|
|
|
|
|
|
|
tmpStr.AppendInt(NS_GET_R(rgba), 10);
|
|
|
|
htmlColor.Append(tmpStr + comma);
|
|
|
|
|
|
|
|
tmpStr.Truncate();
|
|
|
|
tmpStr.AppendInt(NS_GET_G(rgba), 10);
|
|
|
|
htmlColor.Append(tmpStr + comma);
|
|
|
|
|
|
|
|
tmpStr.Truncate();
|
|
|
|
tmpStr.AppendInt(NS_GET_B(rgba), 10);
|
|
|
|
htmlColor.Append(tmpStr);
|
|
|
|
|
|
|
|
htmlColor.Append(PRUnichar(')'));
|
2002-12-13 13:17:42 +03:00
|
|
|
aIsSet = htmlColor.Equals(valueString,
|
|
|
|
nsCaseInsensitiveStringComparator());
|
2002-12-13 11:56:21 +03:00
|
|
|
}
|
|
|
|
else
|
2002-12-13 13:17:42 +03:00
|
|
|
aIsSet = htmlValueString.Equals(valueString,
|
|
|
|
nsCaseInsensitiveStringComparator());
|
2002-12-13 11:56:21 +03:00
|
|
|
}
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
|
2003-04-17 09:42:33 +04:00
|
|
|
else if (nsEditProperty::tt == aHTMLProperty) {
|
2003-07-14 11:37:39 +04:00
|
|
|
aIsSet = StringBeginsWith(valueString, NS_LITERAL_STRING("monospace"));
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
|
2003-04-17 09:42:33 +04:00
|
|
|
else if ((nsEditProperty::font == aHTMLProperty) && aHTMLAttribute
|
2004-05-23 02:15:22 +04:00
|
|
|
&& aHTMLAttribute->EqualsLiteral("face")) {
|
2003-04-17 11:35:55 +04:00
|
|
|
if (!htmlValueString.IsEmpty()) {
|
|
|
|
const PRUnichar commaSpace[] = { PRUnichar(','), PRUnichar(' '), 0 };
|
|
|
|
const PRUnichar comma[] = { PRUnichar(','), 0 };
|
|
|
|
htmlValueString.ReplaceSubstring(commaSpace, comma);
|
|
|
|
nsAutoString valueStringNorm(valueString);
|
|
|
|
valueStringNorm.ReplaceSubstring(commaSpace, comma);
|
|
|
|
aIsSet = htmlValueString.Equals(valueStringNorm,
|
|
|
|
nsCaseInsensitiveStringComparator());
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
else {
|
2003-04-17 11:35:55 +04:00
|
|
|
// ignore this, it's TT or our default
|
|
|
|
nsAutoString valueStringLower;
|
|
|
|
ToLowerCase(valueString, valueStringLower);
|
2004-05-23 02:15:22 +04:00
|
|
|
aIsSet = !valueStringLower.EqualsLiteral("monospace") &&
|
|
|
|
!valueStringLower.EqualsLiteral("serif");
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2003-04-17 11:35:55 +04:00
|
|
|
else if (aHTMLAttribute
|
2004-05-23 02:15:22 +04:00
|
|
|
&& aHTMLAttribute->EqualsLiteral("align")) {
|
2002-01-09 16:51:37 +03:00
|
|
|
aIsSet = PR_TRUE;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
aIsSet = PR_FALSE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-04-17 11:35:55 +04:00
|
|
|
if (!htmlValueString.IsEmpty()) {
|
2002-02-10 18:49:46 +03:00
|
|
|
if (htmlValueString.Equals(valueString,
|
|
|
|
nsCaseInsensitiveStringComparator())) {
|
2002-01-09 16:51:37 +03:00
|
|
|
aIsSet = PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-04-17 09:42:33 +04:00
|
|
|
if (nsEditProperty::u == aHTMLProperty || nsEditProperty::strike == aHTMLProperty) {
|
2002-01-09 16:51:37 +03:00
|
|
|
// unfortunately, the value of the text-decoration property is not inherited.
|
|
|
|
// that means that we have to look at ancestors of node to see if they are underlined
|
|
|
|
nsCOMPtr<nsIDOMNode> tmp;
|
|
|
|
res = node->GetParentNode(getter_AddRefs(tmp));
|
|
|
|
if (NS_FAILED(res)) return res;
|
|
|
|
nsCOMPtr<nsIDOMElement> element = do_QueryInterface(tmp);
|
2003-09-03 17:54:36 +04:00
|
|
|
node = element; // set to null if it's not a dom element
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
2003-04-17 09:42:33 +04:00
|
|
|
} while ((nsEditProperty::u == aHTMLProperty || nsEditProperty::strike == aHTMLProperty) &&
|
2002-01-09 16:51:37 +03:00
|
|
|
!aIsSet && node);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsHTMLCSSUtils::SetCSSEnabled(PRBool aIsCSSPrefChecked)
|
|
|
|
{
|
|
|
|
mIsCSSPrefChecked = aIsCSSPrefChecked;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsHTMLCSSUtils::IsCSSPrefChecked()
|
|
|
|
{
|
|
|
|
return mIsCSSPrefChecked ;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ElementsSameStyle compares two elements and checks if they have the same
|
|
|
|
// specified CSS declarations in the STYLE attribute
|
|
|
|
// The answer is always negative if at least one of them carries an ID or a class
|
|
|
|
PRBool
|
|
|
|
nsHTMLCSSUtils::ElementsSameStyle(nsIDOMNode *aFirstNode, nsIDOMNode *aSecondNode)
|
|
|
|
{
|
|
|
|
nsresult res;
|
|
|
|
nsCOMPtr<nsIDOMElement> firstElement = do_QueryInterface(aFirstNode);
|
|
|
|
nsCOMPtr<nsIDOMElement> secondElement = do_QueryInterface(aSecondNode);
|
|
|
|
|
|
|
|
NS_ASSERTION((firstElement && secondElement), "Non element nodes passed to ElementsSameStyle.");
|
|
|
|
|
|
|
|
nsAutoString firstID, secondID;
|
|
|
|
PRBool isFirstIDSet, isSecondIDSet;
|
|
|
|
res = mHTMLEditor->GetAttributeValue(firstElement, NS_LITERAL_STRING("id"), firstID, &isFirstIDSet);
|
|
|
|
res = mHTMLEditor->GetAttributeValue(secondElement, NS_LITERAL_STRING("id"), secondID, &isSecondIDSet);
|
|
|
|
if (isFirstIDSet || isSecondIDSet) {
|
|
|
|
// at least one of the spans carries an ID ; suspect a CSS rule applies to it and
|
|
|
|
// refuse to merge the nodes
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoString firstClass, secondClass;
|
|
|
|
PRBool isFirstClassSet, isSecondClassSet;
|
|
|
|
res = mHTMLEditor->GetAttributeValue(firstElement, NS_LITERAL_STRING("class"), firstClass, &isFirstClassSet);
|
|
|
|
res = mHTMLEditor->GetAttributeValue(secondElement, NS_LITERAL_STRING("class"), secondClass, &isSecondClassSet);
|
|
|
|
if (isFirstClassSet && isSecondClassSet) {
|
|
|
|
// both spans carry a class, let's compare them
|
|
|
|
if (!firstClass.Equals(secondClass)) {
|
|
|
|
// WARNING : technically, the comparison just above is questionable :
|
|
|
|
// from a pure HTML/CSS point of view class="a b" is NOT the same than
|
|
|
|
// class="b a" because a CSS rule could test the exact value of the class
|
|
|
|
// attribute to be "a b" for instance ; from a user's point of view, a
|
|
|
|
// wysiwyg editor should probably NOT make any difference. CSS people
|
|
|
|
// need to discuss this issue before any modification.
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (isFirstClassSet || isSecondClassSet) {
|
|
|
|
// one span only carries a class, early way out
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMCSSStyleDeclaration> firstCSSDecl, secondCSSDecl;
|
|
|
|
PRUint32 firstLength, secondLength;
|
|
|
|
res = GetInlineStyles(firstElement, getter_AddRefs(firstCSSDecl), &firstLength);
|
|
|
|
if (NS_FAILED(res) || !firstCSSDecl) return PR_FALSE;
|
|
|
|
res = GetInlineStyles(secondElement, getter_AddRefs(secondCSSDecl), &secondLength);
|
|
|
|
if (NS_FAILED(res) || !secondCSSDecl) return PR_FALSE;
|
|
|
|
|
|
|
|
if (firstLength != secondLength) {
|
|
|
|
// early way out if we can
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
else if (0 == firstLength) {
|
|
|
|
// no inline style !
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRUint32 i;
|
|
|
|
nsAutoString propertyNameString;
|
|
|
|
nsAutoString firstValue, secondValue;
|
|
|
|
for (i=0; i<firstLength; i++) {
|
|
|
|
firstCSSDecl->Item(i, propertyNameString);
|
|
|
|
firstCSSDecl->GetPropertyValue(propertyNameString, firstValue);
|
|
|
|
secondCSSDecl->GetPropertyValue(propertyNameString, secondValue);
|
|
|
|
if (!firstValue.Equals(secondValue)) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (i=0; i<secondLength; i++) {
|
|
|
|
secondCSSDecl->Item(i, propertyNameString);
|
|
|
|
secondCSSDecl->GetPropertyValue(propertyNameString, secondValue);
|
|
|
|
firstCSSDecl->GetPropertyValue(propertyNameString, firstValue);
|
|
|
|
if (!firstValue.Equals(secondValue)) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsHTMLCSSUtils::GetInlineStyles(nsIDOMElement *aElement,
|
|
|
|
nsIDOMCSSStyleDeclaration **aCssDecl,
|
|
|
|
PRUint32 *aLength)
|
|
|
|
{
|
|
|
|
if (!aElement || !aLength) return NS_ERROR_NULL_POINTER;
|
|
|
|
*aLength = 0;
|
|
|
|
nsCOMPtr<nsIDOMElementCSSInlineStyle> inlineStyles = do_QueryInterface(aElement);
|
|
|
|
if (!inlineStyles) return NS_ERROR_NULL_POINTER;
|
|
|
|
nsresult res = inlineStyles->GetStyle(aCssDecl);
|
|
|
|
if (NS_FAILED(res) || !aCssDecl) return NS_ERROR_NULL_POINTER;
|
|
|
|
(*aCssDecl)->GetLength(aLength);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsHTMLCSSUtils::GetElementContainerOrSelf(nsIDOMNode * aNode, nsIDOMElement ** aElement)
|
|
|
|
{
|
|
|
|
NS_ENSURE_TRUE(aNode, NS_ERROR_NULL_POINTER);
|
|
|
|
|
2003-09-03 17:54:36 +04:00
|
|
|
nsCOMPtr<nsIDOMNode> node=aNode, parentNode;
|
2002-01-09 16:51:37 +03:00
|
|
|
PRUint16 type;
|
|
|
|
nsresult res;
|
|
|
|
res = node->GetNodeType(&type);
|
|
|
|
if (NS_FAILED(res)) return res;
|
|
|
|
// loop until we find an element
|
|
|
|
while (node && nsIDOMNode::ELEMENT_NODE != type) {
|
|
|
|
parentNode = node;
|
2002-04-29 14:13:23 +04:00
|
|
|
res = parentNode->GetParentNode(getter_AddRefs(node));
|
2002-01-09 16:51:37 +03:00
|
|
|
if (NS_FAILED(res)) return res;
|
2002-04-29 14:13:23 +04:00
|
|
|
if (node) {
|
|
|
|
res = node->GetNodeType(&type);
|
|
|
|
if (NS_FAILED(res)) return res;
|
|
|
|
}
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
2002-04-29 14:13:23 +04:00
|
|
|
NS_ASSERTION(node, "we reached a null node ancestor !");
|
2002-01-09 16:51:37 +03:00
|
|
|
NS_ENSURE_TRUE(node, NS_ERROR_NULL_POINTER);
|
|
|
|
nsCOMPtr<nsIDOMElement> element = do_QueryInterface(node);
|
|
|
|
(*aElement) = element;
|
2002-04-29 14:13:23 +04:00
|
|
|
NS_IF_ADDREF(*aElement);
|
2002-01-09 16:51:37 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2003-06-25 12:50:48 +04:00
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsHTMLCSSUtils::SetCSSProperty(nsIDOMElement * aElement,
|
|
|
|
const nsAString & aProperty,
|
|
|
|
const nsAString & aValue)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMCSSStyleDeclaration> cssDecl;
|
2003-09-03 17:54:36 +04:00
|
|
|
PRUint32 length;
|
2003-06-25 12:50:48 +04:00
|
|
|
nsresult res = GetInlineStyles(aElement, getter_AddRefs(cssDecl), &length);
|
2007-01-16 20:04:16 +03:00
|
|
|
if (NS_FAILED(res) || !cssDecl) return res;
|
2003-06-25 12:50:48 +04:00
|
|
|
|
|
|
|
return cssDecl->SetProperty(aProperty,
|
|
|
|
aValue,
|
2004-01-30 01:04:45 +03:00
|
|
|
EmptyString());
|
2003-06-25 12:50:48 +04:00
|
|
|
}
|
2003-09-03 17:54:36 +04:00
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsHTMLCSSUtils::SetCSSPropertyPixels(nsIDOMElement * aElement,
|
|
|
|
const nsAString & aProperty,
|
|
|
|
PRInt32 aIntValue)
|
|
|
|
{
|
|
|
|
nsAutoString s;
|
|
|
|
s.AppendInt(aIntValue);
|
|
|
|
return SetCSSProperty(aElement, aProperty, s + NS_LITERAL_STRING("px"));
|
|
|
|
}
|
|
|
|
|
2003-06-25 12:50:48 +04:00
|
|
|
nsresult
|
|
|
|
nsHTMLCSSUtils::RemoveCSSProperty(nsIDOMElement * aElement,
|
|
|
|
const nsAString & aProperty)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMCSSStyleDeclaration> cssDecl;
|
2003-09-03 17:54:36 +04:00
|
|
|
PRUint32 length;
|
2003-06-25 12:50:48 +04:00
|
|
|
nsresult res = GetInlineStyles(aElement, getter_AddRefs(cssDecl), &length);
|
2007-01-16 20:04:16 +03:00
|
|
|
if (NS_FAILED(res) || !cssDecl) return res;
|
2003-06-25 12:50:48 +04:00
|
|
|
|
|
|
|
nsAutoString returnString;
|
|
|
|
return cssDecl->RemoveProperty(aProperty, returnString);
|
|
|
|
}
|
|
|
|
|