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>
|
2011-05-15 14:07:30 +04:00
|
|
|
* Ms2ger <ms2ger@gmail.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"
|
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 "nsIDOMElementCSSInlineStyle.h"
|
|
|
|
#include "nsIDOMDocument.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"
|
2011-06-17 04:59:29 +04:00
|
|
|
#include "mozilla/Preferences.h"
|
2012-04-24 14:57:49 +04:00
|
|
|
#include "nsContentUtils.h"
|
2011-06-17 04:59:29 +04:00
|
|
|
|
|
|
|
using namespace mozilla;
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-24 14:57:49 +04:00
|
|
|
static
|
|
|
|
void ProcessFontSizeValue(const nsAString* aInputString, nsAString& aOutputString,
|
|
|
|
const char* aDefaultValueString,
|
|
|
|
const char* aPrependString, const char* aAppendString)
|
|
|
|
{
|
|
|
|
aOutputString.Truncate();
|
|
|
|
if (aInputString) {
|
|
|
|
PRInt32 size = nsContentUtils::ParseLegacyFontSize(*aInputString);
|
|
|
|
switch (size) {
|
|
|
|
case 0:
|
|
|
|
// Didn't parse
|
|
|
|
return;
|
|
|
|
case 1:
|
|
|
|
aOutputString.AssignLiteral("x-small");
|
|
|
|
return;
|
|
|
|
case 2:
|
|
|
|
aOutputString.AssignLiteral("small");
|
|
|
|
return;
|
|
|
|
case 3:
|
|
|
|
aOutputString.AssignLiteral("medium");
|
|
|
|
return;
|
|
|
|
case 4:
|
|
|
|
aOutputString.AssignLiteral("large");
|
|
|
|
return;
|
|
|
|
case 5:
|
|
|
|
aOutputString.AssignLiteral("x-large");
|
|
|
|
return;
|
|
|
|
case 6:
|
|
|
|
aOutputString.AssignLiteral("xx-large");
|
|
|
|
return;
|
|
|
|
case 7:
|
|
|
|
// No corresponding CSS size
|
|
|
|
return;
|
|
|
|
default:
|
|
|
|
NS_NOTREACHED("Unexpected return value from ParseLegacyFontSize");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-01-09 16:51:37 +03:00
|
|
|
const nsHTMLCSSUtils::CSSEquivTable boldEquivTable[] = {
|
2011-10-17 18:59:28 +04:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_font_weight, ProcessBValue, nsnull, nsnull, nsnull, true, false },
|
2002-01-09 16:51:37 +03:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_NONE, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
const nsHTMLCSSUtils::CSSEquivTable italicEquivTable[] = {
|
2011-10-17 18:59:28 +04:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_font_style, ProcessDefaultValue, "italic", nsnull, nsnull, true, false },
|
2002-01-09 16:51:37 +03:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_NONE, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
const nsHTMLCSSUtils::CSSEquivTable underlineEquivTable[] = {
|
2011-10-17 18:59:28 +04:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_text_decoration, ProcessDefaultValue, "underline", nsnull, nsnull, true, false },
|
2002-01-09 16:51:37 +03:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_NONE, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
const nsHTMLCSSUtils::CSSEquivTable strikeEquivTable[] = {
|
2011-10-17 18:59:28 +04:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_text_decoration, ProcessDefaultValue, "line-through", nsnull, nsnull, true, false },
|
2002-01-09 16:51:37 +03:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_NONE, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
const nsHTMLCSSUtils::CSSEquivTable ttEquivTable[] = {
|
2011-10-17 18:59:28 +04:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_font_family, ProcessDefaultValue, "monospace", nsnull, nsnull, true, false },
|
2002-01-09 16:51:37 +03:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_NONE, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
const nsHTMLCSSUtils::CSSEquivTable fontColorEquivTable[] = {
|
2011-10-17 18:59:28 +04:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_color, ProcessSameValue, nsnull, nsnull, nsnull, true, false },
|
2002-01-09 16:51:37 +03:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_NONE, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
const nsHTMLCSSUtils::CSSEquivTable fontFaceEquivTable[] = {
|
2011-10-17 18:59:28 +04:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_font_family, ProcessSameValue, nsnull, nsnull, nsnull, true, false },
|
2002-01-09 16:51:37 +03:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_NONE, 0 }
|
|
|
|
};
|
|
|
|
|
2012-04-24 14:57:49 +04:00
|
|
|
const nsHTMLCSSUtils::CSSEquivTable fontSizeEquivTable[] = {
|
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_font_size, ProcessFontSizeValue, nsnull, nsnull, nsnull, true, false },
|
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_NONE, 0 }
|
|
|
|
};
|
|
|
|
|
2002-01-09 16:51:37 +03:00
|
|
|
const nsHTMLCSSUtils::CSSEquivTable bgcolorEquivTable[] = {
|
2011-10-17 18:59:28 +04:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_background_color, ProcessSameValue, nsnull, nsnull, nsnull, true, false },
|
2002-01-09 16:51:37 +03:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_NONE, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
const nsHTMLCSSUtils::CSSEquivTable backgroundImageEquivTable[] = {
|
2011-10-17 18:59:28 +04:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_background_image, ProcessExtendedValue, nsnull, "url(", ")", true, true },
|
2002-01-09 16:51:37 +03:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_NONE, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
const nsHTMLCSSUtils::CSSEquivTable textColorEquivTable[] = {
|
2011-10-17 18:59:28 +04:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_color, ProcessSameValue, nsnull, nsnull, nsnull, true, false },
|
2002-01-09 16:51:37 +03:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_NONE, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
const nsHTMLCSSUtils::CSSEquivTable borderEquivTable[] = {
|
2011-10-17 18:59:28 +04:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_border, ProcessExtendedValue, nsnull, nsnull, "px solid", true, false },
|
2002-01-09 16:51:37 +03:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_NONE, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
const nsHTMLCSSUtils::CSSEquivTable textAlignEquivTable[] = {
|
2011-10-17 18:59:28 +04:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_text_align, ProcessSameValue, nsnull, nsnull, nsnull, true, false },
|
2002-01-09 16:51:37 +03:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_NONE, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
const nsHTMLCSSUtils::CSSEquivTable captionAlignEquivTable[] = {
|
2011-10-17 18:59:28 +04:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_caption_side, ProcessSameValue, nsnull, nsnull, nsnull, true, false },
|
2002-01-09 16:51:37 +03:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_NONE, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
const nsHTMLCSSUtils::CSSEquivTable verticalAlignEquivTable[] = {
|
2011-10-17 18:59:28 +04:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_vertical_align, ProcessSameValue, nsnull, nsnull, nsnull, true, false },
|
2002-01-09 16:51:37 +03:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_NONE, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
const nsHTMLCSSUtils::CSSEquivTable nowrapEquivTable[] = {
|
2011-10-17 18:59:28 +04:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_whitespace, ProcessDefaultValue, "nowrap", nsnull, nsnull, true, false },
|
2002-01-09 16:51:37 +03:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_NONE, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
const nsHTMLCSSUtils::CSSEquivTable widthEquivTable[] = {
|
2011-10-17 18:59:28 +04:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_width, ProcessLengthValue, nsnull, nsnull, nsnull, true, false },
|
2002-01-09 16:51:37 +03:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_NONE, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
const nsHTMLCSSUtils::CSSEquivTable heightEquivTable[] = {
|
2011-10-17 18:59:28 +04:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_height, ProcessLengthValue, nsnull, nsnull, nsnull, true, false },
|
2002-01-09 16:51:37 +03:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_NONE, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
const nsHTMLCSSUtils::CSSEquivTable listStyleTypeEquivTable[] = {
|
2011-10-17 18:59:28 +04:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_list_style_type, ProcessListStyleTypeValue, nsnull, nsnull, nsnull, true, true },
|
2002-01-09 16:51:37 +03:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_NONE, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
const nsHTMLCSSUtils::CSSEquivTable tableAlignEquivTable[] = {
|
2011-10-17 18:59:28 +04:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_text_align, ProcessDefaultValue, "left", nsnull, nsnull, false, false },
|
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_margin_left, ProcessMarginLeftValue, nsnull, nsnull, nsnull, true, false },
|
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_margin_right, ProcessMarginRightValue, nsnull, nsnull, nsnull, true, false },
|
2002-01-09 16:51:37 +03:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_NONE, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
const nsHTMLCSSUtils::CSSEquivTable hrAlignEquivTable[] = {
|
2011-10-17 18:59:28 +04:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_margin_left, ProcessMarginLeftValue, nsnull, nsnull, nsnull, true, false },
|
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_margin_right, ProcessMarginRightValue, nsnull, nsnull, nsnull, true, false },
|
2002-01-09 16:51:37 +03:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_NONE, 0 }
|
|
|
|
};
|
|
|
|
|
2011-05-15 14:07:30 +04:00
|
|
|
nsHTMLCSSUtils::nsHTMLCSSUtils(nsHTMLEditor* aEditor)
|
|
|
|
: mHTMLEditor(aEditor)
|
2012-04-03 18:16:05 +04:00
|
|
|
, mIsCSSPrefChecked(true)
|
2002-01-09 16:51:37 +03:00
|
|
|
{
|
|
|
|
// let's retrieve the value of the "CSS editing" pref
|
2011-06-17 04:59:29 +04:00
|
|
|
mIsCSSPrefChecked = Preferences::GetBool("editor.use_css", mIsCSSPrefChecked);
|
2011-05-15 14:07:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsHTMLCSSUtils::~nsHTMLCSSUtils()
|
|
|
|
{
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Answers true if we have some CSS equivalence for the HTML style defined
|
|
|
|
// by aProperty and/or aAttribute for the node aNode
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2012-04-24 14:57:49 +04:00
|
|
|
nsHTMLCSSUtils::IsCSSEditableProperty(nsIDOMNode* aNode,
|
|
|
|
nsIAtom* aProperty,
|
|
|
|
const nsAString* aAttribute,
|
|
|
|
const nsAString* aValue)
|
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");
|
|
|
|
|
2012-02-10 14:04:47 +04:00
|
|
|
nsCOMPtr<nsIContent> content = do_QueryInterface(aNode);
|
|
|
|
NS_ENSURE_TRUE(content, false);
|
2012-04-24 14:57:49 +04:00
|
|
|
return IsCSSEditableProperty(content, aProperty, aAttribute, aValue);
|
2012-02-10 14:04:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsHTMLCSSUtils::IsCSSEditableProperty(nsIContent* aNode,
|
|
|
|
nsIAtom* aProperty,
|
2012-04-24 14:57:49 +04:00
|
|
|
const nsAString* aAttribute,
|
|
|
|
const nsAString* aValue)
|
2012-02-10 14:04:47 +04:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(aNode);
|
|
|
|
|
|
|
|
nsIContent* content = aNode;
|
2002-01-09 16:51:37 +03:00
|
|
|
// we need an element node here
|
2012-02-10 14:04:47 +04:00
|
|
|
if (content->NodeType() == nsIDOMNode::TEXT_NODE) {
|
|
|
|
content = content->GetParent();
|
|
|
|
NS_ENSURE_TRUE(content, false);
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
2003-07-29 18:48:44 +04:00
|
|
|
|
2003-11-19 04:20:56 +03:00
|
|
|
nsIAtom *tagName = content->Tag();
|
2003-09-03 17:54:36 +04:00
|
|
|
// 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")))) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
|
2012-04-24 14:57:49 +04:00
|
|
|
// FONT SIZE doesn't work if the value is 7
|
|
|
|
if (nsEditProperty::font == aProperty && aAttribute &&
|
|
|
|
aAttribute->EqualsLiteral("size")) {
|
|
|
|
if (!aValue || aValue->IsEmpty()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
PRInt32 size = nsContentUtils::ParseLegacyFontSize(*aValue);
|
|
|
|
return size && size != 7;
|
|
|
|
}
|
|
|
|
|
2002-01-09 16:51:37 +03:00
|
|
|
// 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)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
|
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)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2002-09-17 16:04:59 +04:00
|
|
|
}
|
|
|
|
|
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"))) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// attribute BGCOLOR on other elements
|
2004-05-23 02:15:22 +04:00
|
|
|
if (aAttribute && aAttribute->EqualsLiteral("bgcolor")) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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"))) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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"))) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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"))) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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")) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
|
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"))) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool 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,
|
2011-10-17 18:59:28 +04:00
|
|
|
getter_AddRefs(txn), 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,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aSuppressTransaction)
|
2003-09-03 17:54:36 +04:00
|
|
|
{
|
|
|
|
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,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool 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,
|
2011-10-17 18:59:28 +04:00
|
|
|
getter_AddRefs(txn), 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,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aRemoveProperty)
|
2002-01-09 16:51:37 +03:00
|
|
|
{
|
2010-06-18 00:40:48 +04:00
|
|
|
NS_ENSURE_TRUE(aElement, NS_ERROR_NULL_POINTER);
|
2009-04-25 02:45:34 +04:00
|
|
|
|
|
|
|
*aTxn = new ChangeCSSInlineStyleTxn();
|
2010-06-18 00:40:48 +04:00
|
|
|
NS_ENSURE_TRUE(*aTxn, NS_ERROR_OUT_OF_MEMORY);
|
2009-04-25 02:45:34 +04:00
|
|
|
NS_ADDREF(*aTxn);
|
|
|
|
return (*aTxn)->Init(mHTMLEditor, aElement, aAttribute, aValue, aRemoveProperty);
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2011-04-24 10:54:25 +04:00
|
|
|
nsCOMPtr<nsIDOMWindow> window;
|
|
|
|
nsresult res = GetDefaultViewCSS(aNode, getter_AddRefs(window));
|
2010-06-17 23:27:24 +04:00
|
|
|
NS_ENSURE_SUCCESS(res, res);
|
2002-01-09 16:51:37 +03:00
|
|
|
|
2011-04-24 10:54:25 +04:00
|
|
|
return GetCSSInlinePropertyBase(aNode, aProperty, aValue, window, COMPUTED_STYLE_TYPE);
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
|
2012-02-10 14:04:47 +04:00
|
|
|
nsresult
|
|
|
|
nsHTMLCSSUtils::GetCSSInlinePropertyBase(nsINode* aNode, nsIAtom* aProperty,
|
|
|
|
nsAString& aValue,
|
|
|
|
nsIDOMWindow* aWindow,
|
|
|
|
PRUint8 aStyleType)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMNode> node = do_QueryInterface(aNode);
|
|
|
|
return GetCSSInlinePropertyBase(node, aProperty, aValue, aWindow, aStyleType);
|
|
|
|
}
|
|
|
|
|
2002-01-09 16:51:37 +03:00
|
|
|
nsresult
|
|
|
|
nsHTMLCSSUtils::GetCSSInlinePropertyBase(nsIDOMNode *aNode, nsIAtom *aProperty,
|
2011-04-24 10:54:25 +04:00
|
|
|
nsAString& aValue,
|
|
|
|
nsIDOMWindow* aWindow,
|
|
|
|
PRUint8 aStyleType)
|
2002-01-09 16:51:37 +03:00
|
|
|
{
|
|
|
|
aValue.Truncate();
|
|
|
|
NS_ENSURE_TRUE(aProperty, NS_ERROR_NULL_POINTER);
|
|
|
|
|
2012-02-01 14:54:22 +04:00
|
|
|
nsCOMPtr<nsIDOMElement> element = GetElementContainerOrSelf(aNode);
|
|
|
|
NS_ENSURE_TRUE(element, NS_ERROR_NULL_POINTER);
|
2002-01-09 16:51:37 +03:00
|
|
|
|
|
|
|
switch (aStyleType) {
|
|
|
|
case COMPUTED_STYLE_TYPE:
|
2011-04-24 10:54:25 +04:00
|
|
|
if (element && aWindow) {
|
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
|
2012-02-01 14:54:22 +04:00
|
|
|
nsresult res = aWindow->GetComputedStyle(element, EmptyString(), getter_AddRefs(cssDecl));
|
2011-04-24 10:54:25 +04: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);
|
2010-06-17 23:27:24 +04:00
|
|
|
NS_ENSURE_SUCCESS(res, res);
|
2002-01-09 16:51:37 +03:00
|
|
|
aValue.Assign(value);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SPECIFIED_STYLE_TYPE:
|
|
|
|
if (element) {
|
|
|
|
nsCOMPtr<nsIDOMCSSStyleDeclaration> cssDecl;
|
2003-09-03 17:54:36 +04:00
|
|
|
PRUint32 length;
|
2012-02-01 14:54:22 +04:00
|
|
|
nsresult 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);
|
2010-06-17 23:27:24 +04:00
|
|
|
NS_ENSURE_SUCCESS(res, res);
|
2002-01-09 16:51:37 +03:00
|
|
|
aValue.Assign(value);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2011-04-24 10:54:25 +04:00
|
|
|
nsHTMLCSSUtils::GetDefaultViewCSS(nsIDOMNode *aNode, nsIDOMWindow **aViewCSS)
|
2002-01-09 16:51:37 +03:00
|
|
|
{
|
2012-02-10 14:04:47 +04:00
|
|
|
nsCOMPtr<nsINode> node = do_QueryInterface(aNode);
|
|
|
|
NS_ENSURE_TRUE(node, NS_ERROR_NULL_POINTER);
|
|
|
|
return GetDefaultViewCSS(node, aViewCSS);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsHTMLCSSUtils::GetDefaultViewCSS(nsINode* aNode, nsIDOMWindow** aViewCSS)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aNode);
|
|
|
|
dom::Element* element = GetElementContainerOrSelf(aNode);
|
2012-02-01 14:54:22 +04:00
|
|
|
NS_ENSURE_TRUE(element, NS_ERROR_NULL_POINTER);
|
2002-01-09 16:51:37 +03:00
|
|
|
|
2012-02-10 14:04:47 +04:00
|
|
|
nsCOMPtr<nsIDOMWindow> window = element->OwnerDoc()->GetWindow();
|
|
|
|
NS_ENSURE_TRUE(window, NS_ERROR_FAILURE);
|
2011-04-24 10:54:25 +04:00
|
|
|
window.forget(aViewCSS);
|
2002-01-09 16:51:37 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
2011-10-17 18:59:28 +04:00
|
|
|
nsresult res = RemoveCSSProperty(elem, aProperty, aPropertyValue, false);
|
2010-06-17 23:27:24 +04:00
|
|
|
NS_ENSURE_SUCCESS(res, res);
|
2002-01-09 16:51:37 +03:00
|
|
|
|
2012-02-10 14:04:46 +04:00
|
|
|
nsCOMPtr<dom::Element> element = do_QueryInterface(aNode);
|
|
|
|
if (!element || !element->IsHTML(nsGkAtoms::span) ||
|
|
|
|
nsHTMLEditor::HasAttributes(element)) {
|
|
|
|
return NS_OK;
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
2012-02-10 14:04:46 +04:00
|
|
|
|
|
|
|
return mHTMLEditor->RemoveContainer(aNode);
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Answers true is the property can be removed by setting a "none" CSS value
|
|
|
|
// on a node
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2002-03-24 01:08:20 +03:00
|
|
|
nsHTMLCSSUtils::IsCSSInvertable(nsIAtom *aProperty, const nsAString *aAttribute)
|
2002-01-09 16:51:37 +03:00
|
|
|
{
|
2011-09-29 10:19:26 +04:00
|
|
|
return bool(nsEditProperty::b == aProperty);
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Get the default browser background color if we need it for GetCSSBackgroundColorState
|
2011-06-17 04:59:29 +04:00
|
|
|
void
|
2002-03-24 01:08:20 +03:00
|
|
|
nsHTMLCSSUtils::GetDefaultBackgroundColor(nsAString & aColor)
|
2002-01-09 16:51:37 +03:00
|
|
|
{
|
2011-09-29 10:19:26 +04:00
|
|
|
if (Preferences::GetBool("editor.use_custom_colors", false)) {
|
2011-06-17 04:59:29 +04:00
|
|
|
nsresult rv = Preferences::GetString("editor.background_color", &aColor);
|
|
|
|
// XXX Why don't you validate the pref value?
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_WARNING("failed to get editor.background_color");
|
|
|
|
aColor.AssignLiteral("#ffffff"); // Default to white
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
2011-06-17 04:59:29 +04:00
|
|
|
return;
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
2011-06-17 04:59:29 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
if (Preferences::GetBool("browser.display.use_system_colors", false)) {
|
2011-06-17 04:59:29 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv =
|
|
|
|
Preferences::GetString("browser.display.background_color", &aColor);
|
|
|
|
// XXX Why don't you validate the pref value?
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_WARNING("failed to get browser.display.background_color");
|
|
|
|
aColor.AssignLiteral("#ffffff"); // Default to white
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the default length unit used for CSS Indent/Outdent
|
2011-06-17 04:59:29 +04:00
|
|
|
void
|
2002-03-24 01:08:20 +03:00
|
|
|
nsHTMLCSSUtils::GetDefaultLengthUnit(nsAString & aLengthUnit)
|
2002-01-09 16:51:37 +03:00
|
|
|
{
|
2011-06-17 04:59:29 +04:00
|
|
|
nsresult rv =
|
|
|
|
Preferences::GetString("editor.css.default_length_unit", &aLengthUnit);
|
|
|
|
// XXX Why don't you validate the pref value?
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aLengthUnit.AssignLiteral("px");
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool floatingPointFound = false;
|
2002-01-09 16:51:37 +03:00
|
|
|
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)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
floatingPointFound = true;
|
2002-01-09 16:51:37 +03:00
|
|
|
a = 1.0f; b = 0.1f;
|
|
|
|
}
|
|
|
|
else break;
|
|
|
|
iter++;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
*aValue = value * sign;
|
2010-06-09 03:25:27 +04:00
|
|
|
*aUnit = NS_NewAtom(StringTail(aString, j-i));
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHTMLCSSUtils::GetCSSPropertyAtom(nsCSSEditableProperty aProperty, nsIAtom ** aAtom)
|
|
|
|
{
|
|
|
|
*aAtom = nsnull;
|
2009-07-23 02:31:01 +04:00
|
|
|
switch (aProperty) {
|
|
|
|
case eCSSEditableProperty_background_color:
|
|
|
|
*aAtom = nsEditProperty::cssBackgroundColor;
|
|
|
|
break;
|
|
|
|
case eCSSEditableProperty_background_image:
|
|
|
|
*aAtom = nsEditProperty::cssBackgroundImage;
|
|
|
|
break;
|
|
|
|
case eCSSEditableProperty_border:
|
|
|
|
*aAtom = nsEditProperty::cssBorder;
|
|
|
|
break;
|
|
|
|
case eCSSEditableProperty_caption_side:
|
|
|
|
*aAtom = nsEditProperty::cssCaptionSide;
|
|
|
|
break;
|
|
|
|
case eCSSEditableProperty_color:
|
|
|
|
*aAtom = nsEditProperty::cssColor;
|
|
|
|
break;
|
|
|
|
case eCSSEditableProperty_float:
|
|
|
|
*aAtom = nsEditProperty::cssFloat;
|
|
|
|
break;
|
|
|
|
case eCSSEditableProperty_font_family:
|
|
|
|
*aAtom = nsEditProperty::cssFontFamily;
|
|
|
|
break;
|
|
|
|
case eCSSEditableProperty_font_size:
|
|
|
|
*aAtom = nsEditProperty::cssFontSize;
|
|
|
|
break;
|
|
|
|
case eCSSEditableProperty_font_style:
|
|
|
|
*aAtom = nsEditProperty::cssFontStyle;
|
|
|
|
break;
|
|
|
|
case eCSSEditableProperty_font_weight:
|
|
|
|
*aAtom = nsEditProperty::cssFontWeight;
|
|
|
|
break;
|
|
|
|
case eCSSEditableProperty_height:
|
|
|
|
*aAtom = nsEditProperty::cssHeight;
|
|
|
|
break;
|
|
|
|
case eCSSEditableProperty_list_style_type:
|
|
|
|
*aAtom = nsEditProperty::cssListStyleType;
|
|
|
|
break;
|
|
|
|
case eCSSEditableProperty_margin_left:
|
|
|
|
*aAtom = nsEditProperty::cssMarginLeft;
|
|
|
|
break;
|
|
|
|
case eCSSEditableProperty_margin_right:
|
|
|
|
*aAtom = nsEditProperty::cssMarginRight;
|
|
|
|
break;
|
|
|
|
case eCSSEditableProperty_text_align:
|
|
|
|
*aAtom = nsEditProperty::cssTextAlign;
|
|
|
|
break;
|
|
|
|
case eCSSEditableProperty_text_decoration:
|
|
|
|
*aAtom = nsEditProperty::cssTextDecoration;
|
|
|
|
break;
|
|
|
|
case eCSSEditableProperty_vertical_align:
|
|
|
|
*aAtom = nsEditProperty::cssVerticalAlign;
|
|
|
|
break;
|
|
|
|
case eCSSEditableProperty_whitespace:
|
|
|
|
*aAtom = nsEditProperty::cssWhitespace;
|
|
|
|
break;
|
|
|
|
case eCSSEditableProperty_width:
|
|
|
|
*aAtom = nsEditProperty::cssWidth;
|
|
|
|
break;
|
|
|
|
case eCSSEditableProperty_NONE:
|
|
|
|
// intentionally empty
|
|
|
|
break;
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Populate aProperty and aValueArray with the CSS declarations equivalent to the
|
|
|
|
// value aValue according to the equivalence table aEquivTable
|
|
|
|
void
|
2009-04-22 12:43:15 +04:00
|
|
|
nsHTMLCSSUtils::BuildCSSDeclarations(nsTArray<nsIAtom*> & aPropertyArray,
|
2009-01-18 23:14:14 +03:00
|
|
|
nsTArray<nsString> & aValueArray,
|
2002-01-09 16:51:37 +03:00
|
|
|
const CSSEquivTable * aEquivTable,
|
2002-03-24 01:08:20 +03:00
|
|
|
const nsAString * aValue,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aGetOrRemoveRequest)
|
2002-01-09 16:51:37 +03:00
|
|
|
{
|
|
|
|
// 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);
|
2009-01-18 23:14:14 +03:00
|
|
|
aValueArray.AppendElement(cssValue);
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
index++;
|
|
|
|
cssProperty = aEquivTable[index].cssProperty;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Populate cssPropertyArray and cssValueArray with the declarations equivalent
|
|
|
|
// to aHTMLProperty/aAttribute/aValue for the node aNode
|
|
|
|
void
|
2012-02-10 14:04:47 +04:00
|
|
|
nsHTMLCSSUtils::GenerateCSSDeclarationsFromHTMLStyle(dom::Element* aElement,
|
|
|
|
nsIAtom* aHTMLProperty,
|
|
|
|
const nsAString* aAttribute,
|
|
|
|
const nsAString* aValue,
|
|
|
|
nsTArray<nsIAtom*>& cssPropertyArray,
|
|
|
|
nsTArray<nsString>& cssValueArray,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aGetOrRemoveRequest)
|
2002-01-09 16:51:37 +03:00
|
|
|
{
|
2012-02-10 14:04:47 +04:00
|
|
|
MOZ_ASSERT(aElement);
|
|
|
|
nsIAtom* tagName = aElement->Tag();
|
2012-04-24 14:57:23 +04:00
|
|
|
const nsHTMLCSSUtils::CSSEquivTable* equivTable = nsnull;
|
2002-01-09 16:51:37 +03:00
|
|
|
|
2003-04-17 09:42:33 +04:00
|
|
|
if (nsEditProperty::b == aHTMLProperty) {
|
2012-04-24 14:57:23 +04:00
|
|
|
equivTable = boldEquivTable;
|
|
|
|
} else if (nsEditProperty::i == aHTMLProperty) {
|
|
|
|
equivTable = italicEquivTable;
|
|
|
|
} else if (nsEditProperty::u == aHTMLProperty) {
|
|
|
|
equivTable = underlineEquivTable;
|
|
|
|
} else if (nsEditProperty::strike == aHTMLProperty) {
|
|
|
|
equivTable = strikeEquivTable;
|
|
|
|
} else if (nsEditProperty::tt == aHTMLProperty) {
|
|
|
|
equivTable = ttEquivTable;
|
|
|
|
} 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")) {
|
2012-04-24 14:57:23 +04:00
|
|
|
equivTable = fontColorEquivTable;
|
|
|
|
} else if (nsEditProperty::font == aHTMLProperty &&
|
|
|
|
aAttribute->EqualsLiteral("face")) {
|
|
|
|
equivTable = fontFaceEquivTable;
|
2012-04-24 14:57:49 +04:00
|
|
|
} else if (nsEditProperty::font == aHTMLProperty &&
|
|
|
|
aAttribute->EqualsLiteral("size")) {
|
|
|
|
equivTable = fontSizeEquivTable;
|
2012-04-24 14:57:23 +04:00
|
|
|
} else if (aAttribute->EqualsLiteral("bgcolor")) {
|
|
|
|
equivTable = bgcolorEquivTable;
|
|
|
|
} else if (aAttribute->EqualsLiteral("background")) {
|
|
|
|
equivTable = backgroundImageEquivTable;
|
|
|
|
} else if (aAttribute->EqualsLiteral("text")) {
|
|
|
|
equivTable = textColorEquivTable;
|
|
|
|
} else if (aAttribute->EqualsLiteral("border")) {
|
|
|
|
equivTable = borderEquivTable;
|
|
|
|
} else if (aAttribute->EqualsLiteral("align")) {
|
2003-04-17 09:42:33 +04:00
|
|
|
if (nsEditProperty::table == tagName) {
|
2012-04-24 14:57:23 +04:00
|
|
|
equivTable = tableAlignEquivTable;
|
|
|
|
} else if (nsEditProperty::hr == tagName) {
|
|
|
|
equivTable = hrAlignEquivTable;
|
|
|
|
} else if (nsEditProperty::legend == tagName ||
|
2003-04-17 09:42:33 +04:00
|
|
|
nsEditProperty::caption == tagName) {
|
2012-04-24 14:57:23 +04:00
|
|
|
equivTable = captionAlignEquivTable;
|
|
|
|
} else {
|
|
|
|
equivTable = textAlignEquivTable;
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
2012-04-24 14:57:23 +04:00
|
|
|
} else if (aAttribute->EqualsLiteral("valign")) {
|
|
|
|
equivTable = verticalAlignEquivTable;
|
|
|
|
} else if (aAttribute->EqualsLiteral("nowrap")) {
|
|
|
|
equivTable = nowrapEquivTable;
|
|
|
|
} else if (aAttribute->EqualsLiteral("width")) {
|
|
|
|
equivTable = widthEquivTable;
|
|
|
|
} else if (aAttribute->EqualsLiteral("height") ||
|
|
|
|
(nsEditProperty::hr == tagName &&
|
|
|
|
aAttribute->EqualsLiteral("size"))) {
|
|
|
|
equivTable = heightEquivTable;
|
|
|
|
} else if (aAttribute->EqualsLiteral("type") &&
|
|
|
|
(nsEditProperty::ol == tagName
|
|
|
|
|| nsEditProperty::ul == tagName
|
|
|
|
|| nsEditProperty::li == tagName)) {
|
|
|
|
equivTable = listStyleTypeEquivTable;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (equivTable) {
|
|
|
|
BuildCSSDeclarations(cssPropertyArray, cssValueArray, equivTable,
|
|
|
|
aValue, aGetOrRemoveRequest);
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aSuppressTransaction)
|
2002-01-09 16:51:37 +03:00
|
|
|
{
|
2012-02-10 14:04:47 +04:00
|
|
|
nsCOMPtr<dom::Element> element = do_QueryInterface(aNode);
|
2002-01-09 16:51:37 +03:00
|
|
|
*aCount = 0;
|
2012-04-24 14:57:49 +04:00
|
|
|
if (!element || !IsCSSEditableProperty(element, aHTMLProperty,
|
|
|
|
aAttribute, aValue)) {
|
2012-02-10 14:04:47 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
|
nsTArray<nsIAtom*> cssPropertyArray;
|
|
|
|
nsTArray<nsString> cssValueArray;
|
|
|
|
GenerateCSSDeclarationsFromHTMLStyle(element, aHTMLProperty, aAttribute,
|
|
|
|
aValue, cssPropertyArray, cssValueArray,
|
|
|
|
false);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMElement> domElement = do_QueryInterface(element);
|
|
|
|
// set the individual CSS inline styles
|
|
|
|
*aCount = cssPropertyArray.Length();
|
|
|
|
for (PRInt32 index = 0; index < *aCount; index++) {
|
|
|
|
nsresult res = SetCSSProperty(domElement, cssPropertyArray[index],
|
|
|
|
cssValueArray[index], aSuppressTransaction);
|
|
|
|
NS_ENSURE_SUCCESS(res, res);
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
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,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aSuppressTransaction)
|
2002-01-09 16:51:37 +03:00
|
|
|
{
|
2012-02-10 14:04:47 +04:00
|
|
|
nsCOMPtr<dom::Element> element = do_QueryInterface(aNode);
|
|
|
|
if (!element || !IsCSSEditableProperty(element, aHTMLProperty, aAttribute)) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
|
nsTArray<nsIAtom*> cssPropertyArray;
|
|
|
|
nsTArray<nsString> cssValueArray;
|
|
|
|
GenerateCSSDeclarationsFromHTMLStyle(element, aHTMLProperty, aAttribute,
|
|
|
|
aValue, cssPropertyArray, cssValueArray,
|
|
|
|
true);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMElement> domElement = do_QueryInterface(element);
|
|
|
|
// remove the individual CSS inline styles
|
|
|
|
PRInt32 count = cssPropertyArray.Length();
|
|
|
|
for (PRInt32 index = 0; index < count; index++) {
|
|
|
|
nsresult res = RemoveCSSProperty(domElement,
|
|
|
|
cssPropertyArray[index],
|
|
|
|
cssValueArray[index],
|
|
|
|
aSuppressTransaction);
|
|
|
|
NS_ENSURE_SUCCESS(res, res);
|
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
|
2012-02-10 14:04:47 +04:00
|
|
|
nsHTMLCSSUtils::GetCSSEquivalentToHTMLInlineStyleSet(nsINode* aNode,
|
2002-01-09 16:51:37 +03:00
|
|
|
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();
|
2012-02-10 14:04:47 +04:00
|
|
|
nsCOMPtr<dom::Element> theElement = GetElementContainerOrSelf(aNode);
|
2012-02-01 14:54:22 +04:00
|
|
|
NS_ENSURE_TRUE(theElement, NS_ERROR_NULL_POINTER);
|
2002-01-09 16:51:37 +03:00
|
|
|
|
2012-04-24 14:57:49 +04:00
|
|
|
if (!theElement || !IsCSSEditableProperty(theElement, aHTMLProperty,
|
|
|
|
aAttribute, &aValueString)) {
|
2012-02-10 14:04:47 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Yes, the requested HTML style has a CSS equivalence in this implementation
|
|
|
|
// Retrieve the default ViewCSS if we are asked for computed styles
|
|
|
|
nsCOMPtr<nsIDOMWindow> window;
|
|
|
|
if (COMPUTED_STYLE_TYPE == aStyleType) {
|
|
|
|
nsresult res = GetDefaultViewCSS(theElement, getter_AddRefs(window));
|
|
|
|
NS_ENSURE_SUCCESS(res, res);
|
|
|
|
}
|
|
|
|
nsTArray<nsIAtom*> cssPropertyArray;
|
|
|
|
nsTArray<nsString> cssValueArray;
|
|
|
|
// get the CSS equivalence with last param true indicating we want only the
|
|
|
|
// "gettable" properties
|
|
|
|
GenerateCSSDeclarationsFromHTMLStyle(theElement, aHTMLProperty, aAttribute, nsnull,
|
|
|
|
cssPropertyArray, cssValueArray, true);
|
|
|
|
PRInt32 count = cssPropertyArray.Length();
|
|
|
|
for (PRInt32 index = 0; index < count; index++) {
|
|
|
|
nsAutoString valueString;
|
|
|
|
// retrieve the specified/computed value of the property
|
|
|
|
nsresult res = GetCSSInlinePropertyBase(theElement, cssPropertyArray[index],
|
|
|
|
valueString, window, aStyleType);
|
|
|
|
NS_ENSURE_SUCCESS(res, res);
|
|
|
|
// append the value to aValueString (possibly with a leading whitespace)
|
|
|
|
if (index) {
|
|
|
|
aValueString.Append(PRUnichar(' '));
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
2012-02-10 14:04:47 +04:00
|
|
|
aValueString.Append(valueString);
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-04-17 21:50:19 +04:00
|
|
|
// Does the node aNode (or its parent, if it's not an element node) have a CSS
|
|
|
|
// style equivalent to the HTML style aHTMLProperty/aHTMLAttribute/valueString?
|
|
|
|
// The value of aStyleType controls the styles we retrieve: specified or
|
|
|
|
// computed. The return value aIsSet is true if the CSS styles are set.
|
2002-01-09 16:51:37 +03:00
|
|
|
nsresult
|
2012-04-17 21:50:19 +04:00
|
|
|
nsHTMLCSSUtils::IsCSSEquivalentToHTMLInlineStyleSet(nsIDOMNode *aNode,
|
2002-01-09 16:51:37 +03:00
|
|
|
nsIAtom *aHTMLProperty,
|
2012-04-17 21:50:19 +04:00
|
|
|
const nsAString *aHTMLAttribute,
|
|
|
|
bool& aIsSet,
|
|
|
|
nsAString& valueString,
|
2002-01-09 16:51:37 +03:00
|
|
|
PRUint8 aStyleType)
|
|
|
|
{
|
|
|
|
NS_ENSURE_TRUE(aNode, NS_ERROR_NULL_POINTER);
|
|
|
|
|
|
|
|
nsAutoString htmlValueString(valueString);
|
2011-10-17 18:59:28 +04:00
|
|
|
aIsSet = false;
|
2012-02-10 14:04:47 +04:00
|
|
|
nsCOMPtr<nsINode> node = do_QueryInterface(aNode);
|
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);
|
2010-06-17 23:27:24 +04:00
|
|
|
NS_ENSURE_SUCCESS(res, res);
|
2002-01-09 16:51:37 +03:00
|
|
|
|
|
|
|
// early way out if we can
|
2012-04-17 21:50:19 +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) {
|
2012-04-17 21:50:19 +04:00
|
|
|
if (valueString.EqualsLiteral("bold")) {
|
2011-10-17 18:59:28 +04:00
|
|
|
aIsSet = true;
|
2012-04-17 21:50:19 +04:00
|
|
|
} else if (valueString.EqualsLiteral("normal")) {
|
2011-10-17 18:59:28 +04:00
|
|
|
aIsSet = false;
|
2012-04-17 21:50:19 +04:00
|
|
|
} else if (valueString.EqualsLiteral("bolder")) {
|
2011-10-17 18:59:28 +04:00
|
|
|
aIsSet = true;
|
2012-04-17 21:50:19 +04:00
|
|
|
valueString.AssignLiteral("bold");
|
|
|
|
} else {
|
2002-01-09 16:51:37 +03:00
|
|
|
PRInt32 weight = 0;
|
|
|
|
PRInt32 errorCode;
|
|
|
|
nsAutoString value(valueString);
|
|
|
|
weight = value.ToInteger(&errorCode, 10);
|
|
|
|
if (400 < weight) {
|
2011-10-17 18:59:28 +04:00
|
|
|
aIsSet = true;
|
2012-04-17 21:50:19 +04:00
|
|
|
valueString.AssignLiteral("bold");
|
|
|
|
} else {
|
2011-10-17 18:59:28 +04:00
|
|
|
aIsSet = false;
|
2004-06-17 04:13:25 +04:00
|
|
|
valueString.AssignLiteral("normal");
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
}
|
2012-04-17 21:50:19 +04:00
|
|
|
} else if (nsEditProperty::i == aHTMLProperty) {
|
2004-05-23 02:15:22 +04:00
|
|
|
if (valueString.EqualsLiteral("italic") ||
|
|
|
|
valueString.EqualsLiteral("oblique")) {
|
2012-04-17 21:50:19 +04:00
|
|
|
aIsSet = true;
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
2012-04-17 21:50:19 +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");
|
2011-09-29 10:19:26 +04:00
|
|
|
aIsSet = bool(ChangeCSSInlineStyleTxn::ValueIncludes(valueString, val, false));
|
2012-04-17 21:50:19 +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");
|
2011-09-29 10:19:26 +04:00
|
|
|
aIsSet = bool(ChangeCSSInlineStyleTxn::ValueIncludes(valueString, val, false));
|
2012-04-17 21:50:19 +04:00
|
|
|
} else if (aHTMLAttribute &&
|
|
|
|
((nsEditProperty::font == aHTMLProperty &&
|
|
|
|
aHTMLAttribute->EqualsLiteral("color")) ||
|
|
|
|
aHTMLAttribute->EqualsLiteral("bgcolor"))) {
|
|
|
|
if (htmlValueString.IsEmpty()) {
|
2011-10-17 18:59:28 +04:00
|
|
|
aIsSet = true;
|
2012-04-17 21:50:19 +04:00
|
|
|
} else {
|
2002-12-13 11:56:21 +03:00
|
|
|
nscolor rgba;
|
|
|
|
nsAutoString subStr;
|
2012-04-17 21:50:19 +04:00
|
|
|
htmlValueString.Right(subStr, htmlValueString.Length() - 1);
|
2002-12-13 11:56:21 +03:00
|
|
|
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());
|
2012-04-17 21:50:19 +04:00
|
|
|
} else {
|
2002-12-13 13:17:42 +03:00
|
|
|
aIsSet = htmlValueString.Equals(valueString,
|
|
|
|
nsCaseInsensitiveStringComparator());
|
2012-04-17 21:50:19 +04:00
|
|
|
}
|
2002-12-13 11:56:21 +03:00
|
|
|
}
|
2012-04-17 21:50:19 +04:00
|
|
|
} else if (nsEditProperty::tt == aHTMLProperty) {
|
2003-07-14 11:37:39 +04:00
|
|
|
aIsSet = StringBeginsWith(valueString, NS_LITERAL_STRING("monospace"));
|
2012-04-17 21:50:19 +04:00
|
|
|
} else if (nsEditProperty::font == aHTMLProperty && aHTMLAttribute &&
|
|
|
|
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());
|
2012-04-17 21:50:19 +04: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;
|
2012-04-24 14:57:49 +04:00
|
|
|
} else if (nsEditProperty::font == aHTMLProperty && aHTMLAttribute &&
|
|
|
|
aHTMLAttribute->EqualsLiteral("size")) {
|
|
|
|
if (htmlValueString.IsEmpty()) {
|
|
|
|
aIsSet = true;
|
|
|
|
} else {
|
|
|
|
PRInt32 size = nsContentUtils::ParseLegacyFontSize(htmlValueString);
|
|
|
|
aIsSet = (size == 1 && valueString.EqualsLiteral("x-small")) ||
|
|
|
|
(size == 2 && valueString.EqualsLiteral("small")) ||
|
|
|
|
(size == 3 && valueString.EqualsLiteral("medium")) ||
|
|
|
|
(size == 4 && valueString.EqualsLiteral("large")) ||
|
|
|
|
(size == 5 && valueString.EqualsLiteral("x-large")) ||
|
|
|
|
(size == 6 && valueString.EqualsLiteral("xx-large"));
|
|
|
|
}
|
2012-04-17 21:50:19 +04:00
|
|
|
} else if (aHTMLAttribute && aHTMLAttribute->EqualsLiteral("align")) {
|
2011-10-17 18:59:28 +04:00
|
|
|
aIsSet = true;
|
2012-04-17 21:50:19 +04:00
|
|
|
} else {
|
2011-10-17 18:59:28 +04:00
|
|
|
aIsSet = false;
|
2002-01-09 16:51:37 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-04-17 21:50:19 +04:00
|
|
|
if (!htmlValueString.IsEmpty() &&
|
|
|
|
htmlValueString.Equals(valueString,
|
|
|
|
nsCaseInsensitiveStringComparator())) {
|
|
|
|
aIsSet = true;
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
|
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
|
2012-02-10 14:04:47 +04:00
|
|
|
node = node->GetElementParent(); // 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
|
2011-09-29 10:19:26 +04:00
|
|
|
nsHTMLCSSUtils::SetCSSEnabled(bool aIsCSSPrefChecked)
|
2002-01-09 16:51:37 +03:00
|
|
|
{
|
|
|
|
mIsCSSPrefChecked = aIsCSSPrefChecked;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2002-01-09 16:51:37 +03:00
|
|
|
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
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2002-01-09 16:51:37 +03:00
|
|
|
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;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isFirstIDSet, isSecondIDSet;
|
2002-01-09 16:51:37 +03:00
|
|
|
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
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoString firstClass, secondClass;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isFirstClassSet, isSecondClassSet;
|
2002-01-09 16:51:37 +03:00
|
|
|
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.
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (isFirstClassSet || isSecondClassSet) {
|
|
|
|
// one span only carries a class, early way out
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMCSSStyleDeclaration> firstCSSDecl, secondCSSDecl;
|
|
|
|
PRUint32 firstLength, secondLength;
|
|
|
|
res = GetInlineStyles(firstElement, getter_AddRefs(firstCSSDecl), &firstLength);
|
2011-10-17 18:59:28 +04:00
|
|
|
if (NS_FAILED(res) || !firstCSSDecl) return false;
|
2002-01-09 16:51:37 +03:00
|
|
|
res = GetInlineStyles(secondElement, getter_AddRefs(secondCSSDecl), &secondLength);
|
2011-10-17 18:59:28 +04:00
|
|
|
if (NS_FAILED(res) || !secondCSSDecl) return false;
|
2002-01-09 16:51:37 +03:00
|
|
|
|
|
|
|
if (firstLength != secondLength) {
|
|
|
|
// early way out if we can
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
else if (0 == firstLength) {
|
|
|
|
// no inline style !
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
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)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
for (i=0; i<secondLength; i++) {
|
|
|
|
secondCSSDecl->Item(i, propertyNameString);
|
|
|
|
secondCSSDecl->GetPropertyValue(propertyNameString, secondValue);
|
|
|
|
firstCSSDecl->GetPropertyValue(propertyNameString, firstValue);
|
|
|
|
if (!firstValue.Equals(secondValue)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsHTMLCSSUtils::GetInlineStyles(nsIDOMElement *aElement,
|
|
|
|
nsIDOMCSSStyleDeclaration **aCssDecl,
|
|
|
|
PRUint32 *aLength)
|
|
|
|
{
|
2010-06-17 23:41:16 +04:00
|
|
|
NS_ENSURE_TRUE(aElement && aLength, NS_ERROR_NULL_POINTER);
|
2002-01-09 16:51:37 +03:00
|
|
|
*aLength = 0;
|
|
|
|
nsCOMPtr<nsIDOMElementCSSInlineStyle> inlineStyles = do_QueryInterface(aElement);
|
2010-06-17 23:41:16 +04:00
|
|
|
NS_ENSURE_TRUE(inlineStyles, NS_ERROR_NULL_POINTER);
|
2002-01-09 16:51:37 +03:00
|
|
|
nsresult res = inlineStyles->GetStyle(aCssDecl);
|
|
|
|
if (NS_FAILED(res) || !aCssDecl) return NS_ERROR_NULL_POINTER;
|
|
|
|
(*aCssDecl)->GetLength(aLength);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-02-01 14:54:22 +04:00
|
|
|
already_AddRefed<nsIDOMElement>
|
|
|
|
nsHTMLCSSUtils::GetElementContainerOrSelf(nsIDOMNode* aNode)
|
2002-01-09 16:51:37 +03:00
|
|
|
{
|
2012-02-01 14:54:22 +04:00
|
|
|
nsCOMPtr<nsINode> node = do_QueryInterface(aNode);
|
|
|
|
NS_ENSURE_TRUE(node, nsnull);
|
2012-02-10 14:04:46 +04:00
|
|
|
nsCOMPtr<nsIDOMElement> element =
|
|
|
|
do_QueryInterface(GetElementContainerOrSelf(node));
|
|
|
|
return element.forget();
|
|
|
|
}
|
2009-02-19 10:55:40 +03:00
|
|
|
|
2012-02-10 14:04:46 +04:00
|
|
|
dom::Element*
|
|
|
|
nsHTMLCSSUtils::GetElementContainerOrSelf(nsINode* aNode)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aNode);
|
|
|
|
if (nsIDOMNode::DOCUMENT_NODE == aNode->NodeType()) {
|
2012-02-01 14:54:22 +04:00
|
|
|
return nsnull;
|
2009-02-19 10:55:40 +03:00
|
|
|
}
|
|
|
|
|
2012-02-10 14:04:46 +04:00
|
|
|
nsINode* node = aNode;
|
2012-02-01 14:54:22 +04:00
|
|
|
// Loop until we find an element.
|
|
|
|
while (node && !node->IsElement()) {
|
|
|
|
node = node->GetNodeParent();
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
2012-02-01 14:54:22 +04:00
|
|
|
|
|
|
|
NS_ENSURE_TRUE(node, nsnull);
|
2012-02-10 14:04:46 +04:00
|
|
|
return node->AsElement();
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
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"));
|
|
|
|
}
|