nsContentTestNode.cpp 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
  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. #include "nsContentTestNode.h"
  6. #include "nsIRDFResource.h"
  7. #include "nsIAtom.h"
  8. #include "nsIDOMElement.h"
  9. #include "nsXULContentUtils.h"
  10. #include "nsIXULTemplateResult.h"
  11. #include "nsIXULTemplateBuilder.h"
  12. #include "nsXULTemplateQueryProcessorRDF.h"
  13. #include "mozilla/Logging.h"
  14. using mozilla::LogLevel;
  15. extern mozilla::LazyLogModule gXULTemplateLog;
  16. nsContentTestNode::nsContentTestNode(nsXULTemplateQueryProcessorRDF* aProcessor,
  17. nsIAtom* aRefVariable)
  18. : TestNode(nullptr),
  19. mProcessor(aProcessor),
  20. mDocument(nullptr),
  21. mRefVariable(aRefVariable),
  22. mTag(nullptr)
  23. {
  24. if (MOZ_LOG_TEST(gXULTemplateLog, LogLevel::Debug)) {
  25. nsAutoString tag(NS_LITERAL_STRING("(none)"));
  26. if (mTag)
  27. mTag->ToString(tag);
  28. nsAutoString refvar(NS_LITERAL_STRING("(none)"));
  29. if (aRefVariable)
  30. aRefVariable->ToString(refvar);
  31. MOZ_LOG(gXULTemplateLog, LogLevel::Debug,
  32. ("nsContentTestNode[%p]: ref-var=%s tag=%s",
  33. this, NS_ConvertUTF16toUTF8(refvar).get(),
  34. NS_ConvertUTF16toUTF8(tag).get()));
  35. }
  36. }
  37. nsresult
  38. nsContentTestNode::FilterInstantiations(InstantiationSet& aInstantiations,
  39. bool* aCantHandleYet) const
  40. {
  41. if (aCantHandleYet)
  42. *aCantHandleYet = false;
  43. return NS_OK;
  44. }
  45. nsresult
  46. nsContentTestNode::Constrain(InstantiationSet& aInstantiations)
  47. {
  48. // contrain the matches to those that have matched in the template builder
  49. nsIXULTemplateBuilder* builder = mProcessor->GetBuilder();
  50. if (!builder) {
  51. aInstantiations.Clear();
  52. return NS_OK;
  53. }
  54. nsresult rv;
  55. InstantiationSet::Iterator last = aInstantiations.Last();
  56. for (InstantiationSet::Iterator inst = aInstantiations.First(); inst != last; ++inst) {
  57. nsCOMPtr<nsIRDFNode> refValue;
  58. bool hasRefBinding = inst->mAssignments.GetAssignmentFor(mRefVariable,
  59. getter_AddRefs(refValue));
  60. if (hasRefBinding) {
  61. nsCOMPtr<nsIRDFResource> refResource = do_QueryInterface(refValue);
  62. if (refResource) {
  63. bool generated;
  64. rv = builder->HasGeneratedContent(refResource, mTag, &generated);
  65. if (NS_FAILED(rv)) return rv;
  66. if (generated)
  67. continue;
  68. }
  69. }
  70. aInstantiations.Erase(inst--);
  71. }
  72. return NS_OK;
  73. }