2001-09-25 22:53:13 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 11:12:37 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2001-04-05 23:34:08 +00:00
|
|
|
|
2014-12-02 05:07:42 +00:00
|
|
|
#include "nsTextEditUtils.h"
|
|
|
|
|
2012-07-13 06:33:42 +00:00
|
|
|
#include "mozilla/Assertions.h"
|
2012-01-11 08:23:07 +00:00
|
|
|
#include "mozilla/dom/Element.h"
|
2012-07-13 06:33:42 +00:00
|
|
|
#include "nsAString.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsCaseTreatment.h"
|
|
|
|
#include "nsDebug.h"
|
2001-04-05 23:34:08 +00:00
|
|
|
#include "nsEditor.h"
|
2012-07-13 06:33:42 +00:00
|
|
|
#include "nsError.h"
|
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
#include "nsIDOMElement.h"
|
|
|
|
#include "nsIDOMNode.h"
|
2014-02-27 23:04:46 +00:00
|
|
|
#include "nsNameSpaceManager.h"
|
2012-07-13 06:33:42 +00:00
|
|
|
#include "nsLiteralString.h"
|
2001-04-05 23:34:08 +00:00
|
|
|
#include "nsPlaintextEditor.h"
|
2012-07-13 06:33:42 +00:00
|
|
|
#include "nsString.h"
|
2001-04-05 23:34:08 +00:00
|
|
|
|
2012-01-11 08:23:07 +00:00
|
|
|
using namespace mozilla;
|
|
|
|
|
2001-04-05 23:34:08 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// IsBody: true if node an html body node
|
2015-05-28 15:58:42 +00:00
|
|
|
bool
|
2001-04-05 23:34:08 +00:00
|
|
|
nsTextEditUtils::IsBody(nsIDOMNode *node)
|
|
|
|
{
|
2012-05-09 09:45:23 +00:00
|
|
|
return nsEditor::NodeIsType(node, nsGkAtoms::body);
|
2001-04-05 23:34:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// IsBreak: true if node an html break node
|
2015-05-28 15:58:42 +00:00
|
|
|
bool
|
2001-04-05 23:34:08 +00:00
|
|
|
nsTextEditUtils::IsBreak(nsIDOMNode *node)
|
|
|
|
{
|
2012-05-09 09:45:23 +00:00
|
|
|
return nsEditor::NodeIsType(node, nsGkAtoms::br);
|
2001-04-05 23:34:08 +00:00
|
|
|
}
|
2015-05-28 15:58:42 +00:00
|
|
|
|
|
|
|
bool
|
2014-04-25 10:34:42 +00:00
|
|
|
nsTextEditUtils::IsBreak(nsINode* aNode)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aNode);
|
2015-03-03 11:08:59 +00:00
|
|
|
return aNode->IsHTMLElement(nsGkAtoms::br);
|
2014-04-25 10:34:42 +00:00
|
|
|
}
|
2001-04-05 23:34:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// IsMozBR: true if node an html br node with type = _moz
|
2015-05-28 15:58:42 +00:00
|
|
|
//
|
|
|
|
bool
|
2001-04-05 23:34:08 +00:00
|
|
|
nsTextEditUtils::IsMozBR(nsIDOMNode *node)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(node, "null node passed to nsHTMLEditUtils::IsMozBR");
|
2012-01-11 08:23:07 +00:00
|
|
|
return IsBreak(node) && HasMozAttr(node);
|
2001-04-05 23:34:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-01-11 08:23:07 +00:00
|
|
|
bool
|
2013-04-04 12:02:24 +00:00
|
|
|
nsTextEditUtils::IsMozBR(nsINode* aNode)
|
2012-01-11 08:23:07 +00:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(aNode);
|
2015-03-03 11:08:59 +00:00
|
|
|
return aNode->IsHTMLElement(nsGkAtoms::br) &&
|
2013-04-04 12:02:24 +00:00
|
|
|
aNode->AsElement()->AttrValueIs(kNameSpaceID_None, nsGkAtoms::type,
|
|
|
|
NS_LITERAL_STRING("_moz"),
|
|
|
|
eIgnoreCase);
|
2012-01-11 08:23:07 +00:00
|
|
|
}
|
|
|
|
|
2001-04-05 23:34:08 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// HasMozAttr: true if node has type attribute = _moz
|
|
|
|
// (used to indicate the div's and br's we use in
|
|
|
|
// mail compose rules)
|
2015-05-28 15:58:42 +00:00
|
|
|
//
|
|
|
|
bool
|
2001-04-05 23:34:08 +00:00
|
|
|
nsTextEditUtils::HasMozAttr(nsIDOMNode *node)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(node, "null parent passed to nsHTMLEditUtils::HasMozAttr");
|
|
|
|
nsCOMPtr<nsIDOMElement> elem = do_QueryInterface(node);
|
|
|
|
if (elem)
|
|
|
|
{
|
|
|
|
nsAutoString typeAttrVal;
|
2003-07-18 14:12:51 +00:00
|
|
|
nsresult res = elem->GetAttribute(NS_LITERAL_STRING("type"), typeAttrVal);
|
2004-06-17 00:13:25 +00:00
|
|
|
if (NS_SUCCEEDED(res) && (typeAttrVal.LowerCaseEqualsLiteral("_moz")))
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2001-04-05 23:34:08 +00:00
|
|
|
}
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2001-04-05 23:34:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsAutoEditInitRulesTrigger methods
|
|
|
|
//
|
|
|
|
nsAutoEditInitRulesTrigger::nsAutoEditInitRulesTrigger( nsPlaintextEditor *aEd, nsresult &aRes) : mEd(aEd), mRes(aRes)
|
|
|
|
{
|
|
|
|
if (mEd) mEd->BeginEditorInit();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoEditInitRulesTrigger::~nsAutoEditInitRulesTrigger()
|
|
|
|
{
|
|
|
|
if (mEd) mRes = mEd->EndEditorInit();
|
|
|
|
}
|
|
|
|
|