Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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"
8 #include "nsAString.h"
9 #include "nsCOMPtr.h"
10 #include "nsCaseTreatment.h"
11 #include "nsDebug.h"
12 #include "nsEditor.h"
13 #include "nsError.h"
14 #include "nsGkAtoms.h"
15 #include "nsIDOMElement.h"
16 #include "nsIDOMNode.h"
17 #include "nsNameSpaceManager.h"
18 #include "nsLiteralString.h"
19 #include "nsPlaintextEditor.h"
20 #include "nsString.h"
21 #include "nsTextEditUtils.h"
23 using namespace mozilla;
25 ///////////////////////////////////////////////////////////////////////////
26 // IsBody: true if node an html body node
27 bool
28 nsTextEditUtils::IsBody(nsIDOMNode *node)
29 {
30 return nsEditor::NodeIsType(node, nsGkAtoms::body);
31 }
34 ///////////////////////////////////////////////////////////////////////////
35 // IsBreak: true if node an html break node
36 bool
37 nsTextEditUtils::IsBreak(nsIDOMNode *node)
38 {
39 return nsEditor::NodeIsType(node, nsGkAtoms::br);
40 }
43 ///////////////////////////////////////////////////////////////////////////
44 // IsMozBR: true if node an html br node with type = _moz
45 //
46 bool
47 nsTextEditUtils::IsMozBR(nsIDOMNode *node)
48 {
49 NS_PRECONDITION(node, "null node passed to nsHTMLEditUtils::IsMozBR");
50 return IsBreak(node) && HasMozAttr(node);
51 }
54 bool
55 nsTextEditUtils::IsMozBR(nsINode* aNode)
56 {
57 MOZ_ASSERT(aNode);
58 return aNode->IsElement() &&
59 aNode->AsElement()->IsHTML(nsGkAtoms::br) &&
60 aNode->AsElement()->AttrValueIs(kNameSpaceID_None, nsGkAtoms::type,
61 NS_LITERAL_STRING("_moz"),
62 eIgnoreCase);
63 }
65 ///////////////////////////////////////////////////////////////////////////
66 // HasMozAttr: true if node has type attribute = _moz
67 // (used to indicate the div's and br's we use in
68 // mail compose rules)
69 //
70 bool
71 nsTextEditUtils::HasMozAttr(nsIDOMNode *node)
72 {
73 NS_PRECONDITION(node, "null parent passed to nsHTMLEditUtils::HasMozAttr");
74 nsCOMPtr<nsIDOMElement> elem = do_QueryInterface(node);
75 if (elem)
76 {
77 nsAutoString typeAttrVal;
78 nsresult res = elem->GetAttribute(NS_LITERAL_STRING("type"), typeAttrVal);
79 if (NS_SUCCEEDED(res) && (typeAttrVal.LowerCaseEqualsLiteral("_moz")))
80 return true;
81 }
82 return false;
83 }
86 ///////////////////////////////////////////////////////////////////////////
87 // nsAutoEditInitRulesTrigger methods
88 //
89 nsAutoEditInitRulesTrigger::nsAutoEditInitRulesTrigger( nsPlaintextEditor *aEd, nsresult &aRes) : mEd(aEd), mRes(aRes)
90 {
91 if (mEd) mEd->BeginEditorInit();
92 }
94 nsAutoEditInitRulesTrigger::~nsAutoEditInitRulesTrigger()
95 {
96 if (mEd) mRes = mEd->EndEditorInit();
97 }