/src/mozilla-central/editor/libeditor/TextEditUtils.cpp
Line | Count | Source (jump to first uncovered line) |
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/. */ |
5 | | |
6 | | #include "TextEditUtils.h" |
7 | | |
8 | | #include "mozilla/Assertions.h" |
9 | | #include "mozilla/TextEditor.h" |
10 | | #include "mozilla/dom/Element.h" |
11 | | #include "nsAString.h" |
12 | | #include "nsCOMPtr.h" |
13 | | #include "nsCaseTreatment.h" |
14 | | #include "nsDebug.h" |
15 | | #include "nsError.h" |
16 | | #include "nsGkAtoms.h" |
17 | | #include "nsNameSpaceManager.h" |
18 | | #include "nsLiteralString.h" |
19 | | #include "nsString.h" |
20 | | |
21 | | namespace mozilla { |
22 | | |
23 | | /****************************************************************************** |
24 | | * TextEditUtils |
25 | | ******************************************************************************/ |
26 | | |
27 | | /** |
28 | | * IsBody() returns true if aNode is an html body node. |
29 | | */ |
30 | | bool |
31 | | TextEditUtils::IsBody(nsINode* aNode) |
32 | 0 | { |
33 | 0 | MOZ_ASSERT(aNode); |
34 | 0 | return aNode->IsHTMLElement(nsGkAtoms::body); |
35 | 0 | } |
36 | | |
37 | | /** |
38 | | * IsBreak() returns true if aNode is an html break node. |
39 | | */ |
40 | | bool |
41 | | TextEditUtils::IsBreak(nsINode* aNode) |
42 | 0 | { |
43 | 0 | MOZ_ASSERT(aNode); |
44 | 0 | return aNode->IsHTMLElement(nsGkAtoms::br); |
45 | 0 | } |
46 | | |
47 | | |
48 | | /** |
49 | | * IsMozBR() returns true if aNode is an html br node with |type = _moz|. |
50 | | */ |
51 | | bool |
52 | | TextEditUtils::IsMozBR(nsINode* aNode) |
53 | 0 | { |
54 | 0 | MOZ_ASSERT(aNode); |
55 | 0 | return aNode->IsHTMLElement(nsGkAtoms::br) && |
56 | 0 | aNode->AsElement()->AttrValueIs(kNameSpaceID_None, nsGkAtoms::type, |
57 | 0 | NS_LITERAL_STRING("_moz"), |
58 | 0 | eIgnoreCase); |
59 | 0 | } |
60 | | |
61 | | /** |
62 | | * HasMozAttr() returns true if aNode has type attribute and its value is |
63 | | * |_moz|. (Used to indicate div's and br's we use in mail compose rules) |
64 | | */ |
65 | | bool |
66 | | TextEditUtils::HasMozAttr(nsINode* aNode) |
67 | 0 | { |
68 | 0 | MOZ_ASSERT(aNode); |
69 | 0 | return aNode->IsElement() && |
70 | 0 | aNode->AsElement()->AttrValueIs(kNameSpaceID_None, |
71 | 0 | nsGkAtoms::type, |
72 | 0 | NS_LITERAL_STRING("_moz"), |
73 | 0 | eIgnoreCase); |
74 | 0 | } |
75 | | |
76 | | /****************************************************************************** |
77 | | * AutoEditInitRulesTrigger |
78 | | ******************************************************************************/ |
79 | | |
80 | | AutoEditInitRulesTrigger::AutoEditInitRulesTrigger(TextEditor* aTextEditor, |
81 | | nsresult& aResult) |
82 | | : mTextEditor(aTextEditor) |
83 | | , mResult(aResult) |
84 | 0 | { |
85 | 0 | if (mTextEditor) { |
86 | 0 | mTextEditor->BeginEditorInit(); |
87 | 0 | } |
88 | 0 | } |
89 | | |
90 | | AutoEditInitRulesTrigger::~AutoEditInitRulesTrigger() |
91 | 0 | { |
92 | 0 | if (mTextEditor) { |
93 | 0 | mResult = mTextEditor->EndEditorInit(); |
94 | 0 | } |
95 | 0 | } |
96 | | |
97 | | } // namespace mozilla |