txBooleanResult.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. /*
  6. * Boolean Expression result
  7. */
  8. #include "txExprResult.h"
  9. /**
  10. * Creates a new BooleanResult with the value of the given bool parameter
  11. * @param boolean the bool to use for initialization of this BooleanResult's value
  12. **/
  13. BooleanResult::BooleanResult(bool boolean)
  14. : txAExprResult(nullptr)
  15. {
  16. this->value = boolean;
  17. } //-- BooleanResult
  18. /*
  19. * Virtual Methods from ExprResult
  20. */
  21. short BooleanResult::getResultType() {
  22. return txAExprResult::BOOLEAN;
  23. } //-- getResultType
  24. void
  25. BooleanResult::stringValue(nsString& aResult)
  26. {
  27. if (value) {
  28. aResult.AppendLiteral("true");
  29. }
  30. else {
  31. aResult.AppendLiteral("false");
  32. }
  33. }
  34. const nsString*
  35. BooleanResult::stringValuePointer()
  36. {
  37. // In theory we could set strings containing "true" and "false" somewhere,
  38. // but most stylesheets never get the stringvalue of a bool so that won't
  39. // really buy us anything.
  40. return nullptr;
  41. }
  42. bool BooleanResult::booleanValue() {
  43. return this->value;
  44. } //-- toBoolean
  45. double BooleanResult::numberValue() {
  46. return ( value ) ? 1.0 : 0.0;
  47. } //-- toNumber