1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "mozilla/Assertions.h"
7 #include "mozilla/dom/Element.h"
10 #include "nsCaseTreatment.h"
14 #include "nsGkAtoms.h"
15 #include "nsIDOMElement.h"
16 #include "nsIDOMNode.h"
17 #include "nsINameSpaceManager.h"
18 #include "nsLiteralString.h"
19 #include "nsPlaintextEditor.h"
21 #include "nsTextEditUtils.h"
23 using namespace mozilla
;
25 ///////////////////////////////////////////////////////////////////////////
26 // IsBody: true if node an html body node
28 nsTextEditUtils::IsBody(nsIDOMNode
*node
)
30 return nsEditor::NodeIsType(node
, nsGkAtoms::body
);
34 ///////////////////////////////////////////////////////////////////////////
35 // IsBreak: true if node an html break node
37 nsTextEditUtils::IsBreak(nsIDOMNode
*node
)
39 return nsEditor::NodeIsType(node
, nsGkAtoms::br
);
43 ///////////////////////////////////////////////////////////////////////////
44 // IsMozBR: true if node an html br node with type = _moz
47 nsTextEditUtils::IsMozBR(nsIDOMNode
*node
)
49 NS_PRECONDITION(node
, "null node passed to nsHTMLEditUtils::IsMozBR");
50 return IsBreak(node
) && HasMozAttr(node
);
55 nsTextEditUtils::IsMozBR(dom::Element
* aNode
)
58 return aNode
->IsHTML(nsGkAtoms::br
) &&
59 aNode
->AttrValueIs(kNameSpaceID_None
, nsGkAtoms::type
,
60 NS_LITERAL_STRING("_moz"), eIgnoreCase
);
63 ///////////////////////////////////////////////////////////////////////////
64 // HasMozAttr: true if node has type attribute = _moz
65 // (used to indicate the div's and br's we use in
66 // mail compose rules)
69 nsTextEditUtils::HasMozAttr(nsIDOMNode
*node
)
71 NS_PRECONDITION(node
, "null parent passed to nsHTMLEditUtils::HasMozAttr");
72 nsCOMPtr
<nsIDOMElement
> elem
= do_QueryInterface(node
);
75 nsAutoString typeAttrVal
;
76 nsresult res
= elem
->GetAttribute(NS_LITERAL_STRING("type"), typeAttrVal
);
77 if (NS_SUCCEEDED(res
) && (typeAttrVal
.LowerCaseEqualsLiteral("_moz")))
84 ///////////////////////////////////////////////////////////////////////////
85 // nsAutoEditInitRulesTrigger methods
87 nsAutoEditInitRulesTrigger::nsAutoEditInitRulesTrigger( nsPlaintextEditor
*aEd
, nsresult
&aRes
) : mEd(aEd
), mRes(aRes
)
89 if (mEd
) mEd
->BeginEditorInit();
92 nsAutoEditInitRulesTrigger::~nsAutoEditInitRulesTrigger()
94 if (mEd
) mRes
= mEd
->EndEditorInit();