Bug 827007: Implement Stop for UserMediaStreams; add NotifyRemoved for MediaStream...
[gecko.git] / editor / libeditor / text / nsTextEditUtils.cpp
blob408de26d2810471e811975e2f034cabe6a27f61d
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 "nsINameSpaceManager.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)
30 return nsEditor::NodeIsType(node, nsGkAtoms::body);
34 ///////////////////////////////////////////////////////////////////////////
35 // IsBreak: true if node an html break node
36 bool
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
45 //
46 bool
47 nsTextEditUtils::IsMozBR(nsIDOMNode *node)
49 NS_PRECONDITION(node, "null node passed to nsHTMLEditUtils::IsMozBR");
50 return IsBreak(node) && HasMozAttr(node);
54 bool
55 nsTextEditUtils::IsMozBR(dom::Element* aNode)
57 MOZ_ASSERT(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)
67 //
68 bool
69 nsTextEditUtils::HasMozAttr(nsIDOMNode *node)
71 NS_PRECONDITION(node, "null parent passed to nsHTMLEditUtils::HasMozAttr");
72 nsCOMPtr<nsIDOMElement> elem = do_QueryInterface(node);
73 if (elem)
75 nsAutoString typeAttrVal;
76 nsresult res = elem->GetAttribute(NS_LITERAL_STRING("type"), typeAttrVal);
77 if (NS_SUCCEEDED(res) && (typeAttrVal.LowerCaseEqualsLiteral("_moz")))
78 return true;
80 return false;
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();