michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "mozilla/Assertions.h" michael@0: #include "mozilla/dom/Element.h" michael@0: #include "nsAString.h" michael@0: #include "nsCOMPtr.h" michael@0: #include "nsCaseTreatment.h" michael@0: #include "nsDebug.h" michael@0: #include "nsEditor.h" michael@0: #include "nsError.h" michael@0: #include "nsGkAtoms.h" michael@0: #include "nsIDOMElement.h" michael@0: #include "nsIDOMNode.h" michael@0: #include "nsNameSpaceManager.h" michael@0: #include "nsLiteralString.h" michael@0: #include "nsPlaintextEditor.h" michael@0: #include "nsString.h" michael@0: #include "nsTextEditUtils.h" michael@0: michael@0: using namespace mozilla; michael@0: michael@0: /////////////////////////////////////////////////////////////////////////// michael@0: // IsBody: true if node an html body node michael@0: bool michael@0: nsTextEditUtils::IsBody(nsIDOMNode *node) michael@0: { michael@0: return nsEditor::NodeIsType(node, nsGkAtoms::body); michael@0: } michael@0: michael@0: michael@0: /////////////////////////////////////////////////////////////////////////// michael@0: // IsBreak: true if node an html break node michael@0: bool michael@0: nsTextEditUtils::IsBreak(nsIDOMNode *node) michael@0: { michael@0: return nsEditor::NodeIsType(node, nsGkAtoms::br); michael@0: } michael@0: michael@0: michael@0: /////////////////////////////////////////////////////////////////////////// michael@0: // IsMozBR: true if node an html br node with type = _moz michael@0: // michael@0: bool michael@0: nsTextEditUtils::IsMozBR(nsIDOMNode *node) michael@0: { michael@0: NS_PRECONDITION(node, "null node passed to nsHTMLEditUtils::IsMozBR"); michael@0: return IsBreak(node) && HasMozAttr(node); michael@0: } michael@0: michael@0: michael@0: bool michael@0: nsTextEditUtils::IsMozBR(nsINode* aNode) michael@0: { michael@0: MOZ_ASSERT(aNode); michael@0: return aNode->IsElement() && michael@0: aNode->AsElement()->IsHTML(nsGkAtoms::br) && michael@0: aNode->AsElement()->AttrValueIs(kNameSpaceID_None, nsGkAtoms::type, michael@0: NS_LITERAL_STRING("_moz"), michael@0: eIgnoreCase); michael@0: } michael@0: michael@0: /////////////////////////////////////////////////////////////////////////// michael@0: // HasMozAttr: true if node has type attribute = _moz michael@0: // (used to indicate the div's and br's we use in michael@0: // mail compose rules) michael@0: // michael@0: bool michael@0: nsTextEditUtils::HasMozAttr(nsIDOMNode *node) michael@0: { michael@0: NS_PRECONDITION(node, "null parent passed to nsHTMLEditUtils::HasMozAttr"); michael@0: nsCOMPtr elem = do_QueryInterface(node); michael@0: if (elem) michael@0: { michael@0: nsAutoString typeAttrVal; michael@0: nsresult res = elem->GetAttribute(NS_LITERAL_STRING("type"), typeAttrVal); michael@0: if (NS_SUCCEEDED(res) && (typeAttrVal.LowerCaseEqualsLiteral("_moz"))) michael@0: return true; michael@0: } michael@0: return false; michael@0: } michael@0: michael@0: michael@0: /////////////////////////////////////////////////////////////////////////// michael@0: // nsAutoEditInitRulesTrigger methods michael@0: // michael@0: nsAutoEditInitRulesTrigger::nsAutoEditInitRulesTrigger( nsPlaintextEditor *aEd, nsresult &aRes) : mEd(aEd), mRes(aRes) michael@0: { michael@0: if (mEd) mEd->BeginEditorInit(); michael@0: } michael@0: michael@0: nsAutoEditInitRulesTrigger::~nsAutoEditInitRulesTrigger() michael@0: { michael@0: if (mEd) mRes = mEd->EndEditorInit(); michael@0: } michael@0: