nsComposeTxtSrvFilter.cpp (2190B)
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 "nsComposeTxtSrvFilter.h" 7 #include "nsError.h" // for NS_OK 8 #include "nsIContent.h" // for nsIContent 9 #include "nsLiteralString.h" // for NS_LITERAL_STRING 10 #include "mozilla/dom/Element.h" // for nsIContent 11 12 using namespace mozilla; 13 14 bool nsComposeTxtSrvFilter::Skip(nsINode* aNode) const { 15 if (NS_WARN_IF(!aNode)) { 16 return false; 17 } 18 19 // Check to see if we can skip this node 20 21 if (aNode->IsAnyOfHTMLElements(nsGkAtoms::script, nsGkAtoms::textarea, 22 nsGkAtoms::select, nsGkAtoms::style, 23 nsGkAtoms::map)) { 24 return true; 25 } 26 27 if (!mIsForMail) { 28 return false; 29 } 30 31 // For nodes that are blockquotes, we must make sure 32 // their type is "cite" 33 if (aNode->IsHTMLElement(nsGkAtoms::blockquote)) { 34 return aNode->AsElement()->AttrValueIs(kNameSpaceID_None, nsGkAtoms::type, 35 nsGkAtoms::cite, eIgnoreCase); 36 } 37 38 if (aNode->IsHTMLElement(nsGkAtoms::span)) { 39 if (aNode->AsElement()->AttrValueIs(kNameSpaceID_None, nsGkAtoms::mozquote, 40 nsGkAtoms::_true, eIgnoreCase)) { 41 return true; 42 } 43 44 return aNode->AsElement()->AttrValueIs(kNameSpaceID_None, nsGkAtoms::_class, 45 nsGkAtoms::mozsignature, 46 eCaseMatters); 47 } 48 49 if (aNode->IsHTMLElement(nsGkAtoms::table)) { 50 return aNode->AsElement()->AttrValueIs(kNameSpaceID_None, nsGkAtoms::_class, 51 u"moz-email-headers-table"_ns, 52 eCaseMatters); 53 } 54 55 return false; 56 } 57 58 // static 59 UniquePtr<nsComposeTxtSrvFilter> nsComposeTxtSrvFilter::CreateHelper( 60 bool aIsForMail) { 61 auto filter = MakeUnique<nsComposeTxtSrvFilter>(); 62 filter->Init(aIsForMail); 63 return filter; 64 }