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.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #include "mozilla/Assertions.h" |
michael@0 | 7 | #include "mozilla/dom/Element.h" |
michael@0 | 8 | #include "nsAString.h" |
michael@0 | 9 | #include "nsCOMPtr.h" |
michael@0 | 10 | #include "nsCaseTreatment.h" |
michael@0 | 11 | #include "nsDebug.h" |
michael@0 | 12 | #include "nsEditor.h" |
michael@0 | 13 | #include "nsError.h" |
michael@0 | 14 | #include "nsGkAtoms.h" |
michael@0 | 15 | #include "nsIDOMElement.h" |
michael@0 | 16 | #include "nsIDOMNode.h" |
michael@0 | 17 | #include "nsNameSpaceManager.h" |
michael@0 | 18 | #include "nsLiteralString.h" |
michael@0 | 19 | #include "nsPlaintextEditor.h" |
michael@0 | 20 | #include "nsString.h" |
michael@0 | 21 | #include "nsTextEditUtils.h" |
michael@0 | 22 | |
michael@0 | 23 | using namespace mozilla; |
michael@0 | 24 | |
michael@0 | 25 | /////////////////////////////////////////////////////////////////////////// |
michael@0 | 26 | // IsBody: true if node an html body node |
michael@0 | 27 | bool |
michael@0 | 28 | nsTextEditUtils::IsBody(nsIDOMNode *node) |
michael@0 | 29 | { |
michael@0 | 30 | return nsEditor::NodeIsType(node, nsGkAtoms::body); |
michael@0 | 31 | } |
michael@0 | 32 | |
michael@0 | 33 | |
michael@0 | 34 | /////////////////////////////////////////////////////////////////////////// |
michael@0 | 35 | // IsBreak: true if node an html break node |
michael@0 | 36 | bool |
michael@0 | 37 | nsTextEditUtils::IsBreak(nsIDOMNode *node) |
michael@0 | 38 | { |
michael@0 | 39 | return nsEditor::NodeIsType(node, nsGkAtoms::br); |
michael@0 | 40 | } |
michael@0 | 41 | |
michael@0 | 42 | |
michael@0 | 43 | /////////////////////////////////////////////////////////////////////////// |
michael@0 | 44 | // IsMozBR: true if node an html br node with type = _moz |
michael@0 | 45 | // |
michael@0 | 46 | bool |
michael@0 | 47 | nsTextEditUtils::IsMozBR(nsIDOMNode *node) |
michael@0 | 48 | { |
michael@0 | 49 | NS_PRECONDITION(node, "null node passed to nsHTMLEditUtils::IsMozBR"); |
michael@0 | 50 | return IsBreak(node) && HasMozAttr(node); |
michael@0 | 51 | } |
michael@0 | 52 | |
michael@0 | 53 | |
michael@0 | 54 | bool |
michael@0 | 55 | nsTextEditUtils::IsMozBR(nsINode* aNode) |
michael@0 | 56 | { |
michael@0 | 57 | MOZ_ASSERT(aNode); |
michael@0 | 58 | return aNode->IsElement() && |
michael@0 | 59 | aNode->AsElement()->IsHTML(nsGkAtoms::br) && |
michael@0 | 60 | aNode->AsElement()->AttrValueIs(kNameSpaceID_None, nsGkAtoms::type, |
michael@0 | 61 | NS_LITERAL_STRING("_moz"), |
michael@0 | 62 | eIgnoreCase); |
michael@0 | 63 | } |
michael@0 | 64 | |
michael@0 | 65 | /////////////////////////////////////////////////////////////////////////// |
michael@0 | 66 | // HasMozAttr: true if node has type attribute = _moz |
michael@0 | 67 | // (used to indicate the div's and br's we use in |
michael@0 | 68 | // mail compose rules) |
michael@0 | 69 | // |
michael@0 | 70 | bool |
michael@0 | 71 | nsTextEditUtils::HasMozAttr(nsIDOMNode *node) |
michael@0 | 72 | { |
michael@0 | 73 | NS_PRECONDITION(node, "null parent passed to nsHTMLEditUtils::HasMozAttr"); |
michael@0 | 74 | nsCOMPtr<nsIDOMElement> elem = do_QueryInterface(node); |
michael@0 | 75 | if (elem) |
michael@0 | 76 | { |
michael@0 | 77 | nsAutoString typeAttrVal; |
michael@0 | 78 | nsresult res = elem->GetAttribute(NS_LITERAL_STRING("type"), typeAttrVal); |
michael@0 | 79 | if (NS_SUCCEEDED(res) && (typeAttrVal.LowerCaseEqualsLiteral("_moz"))) |
michael@0 | 80 | return true; |
michael@0 | 81 | } |
michael@0 | 82 | return false; |
michael@0 | 83 | } |
michael@0 | 84 | |
michael@0 | 85 | |
michael@0 | 86 | /////////////////////////////////////////////////////////////////////////// |
michael@0 | 87 | // nsAutoEditInitRulesTrigger methods |
michael@0 | 88 | // |
michael@0 | 89 | nsAutoEditInitRulesTrigger::nsAutoEditInitRulesTrigger( nsPlaintextEditor *aEd, nsresult &aRes) : mEd(aEd), mRes(aRes) |
michael@0 | 90 | { |
michael@0 | 91 | if (mEd) mEd->BeginEditorInit(); |
michael@0 | 92 | } |
michael@0 | 93 | |
michael@0 | 94 | nsAutoEditInitRulesTrigger::~nsAutoEditInitRulesTrigger() |
michael@0 | 95 | { |
michael@0 | 96 | if (mEd) mRes = mEd->EndEditorInit(); |
michael@0 | 97 | } |
michael@0 | 98 |