diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:47:29 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:47:29 +0000 |
commit | 0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d (patch) | |
tree | a31f07c9bcca9d56ce61e9a1ffd30ef350d513aa /dom/xul/nsXULContentUtils.cpp | |
parent | Initial commit. (diff) | |
download | firefox-esr-upstream/115.8.0esr.tar.xz firefox-esr-upstream/115.8.0esr.zip |
Adding upstream version 115.8.0esr.upstream/115.8.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | dom/xul/nsXULContentUtils.cpp | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/dom/xul/nsXULContentUtils.cpp b/dom/xul/nsXULContentUtils.cpp new file mode 100644 index 0000000000..109aa1975a --- /dev/null +++ b/dom/xul/nsXULContentUtils.cpp @@ -0,0 +1,89 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * 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/. */ + +/* + + A package of routines shared by the XUL content code. + + */ + +#include "mozilla/ArrayUtils.h" +#include "mozilla/intl/LocaleService.h" +#include "mozilla/intl/Collator.h" + +#include "nsCOMPtr.h" +#include "nsComponentManagerUtils.h" +#include "nsIContent.h" +#include "mozilla/dom/Document.h" +#include "mozilla/dom/Element.h" +#include "nsXULContentUtils.h" +#include "nsLayoutCID.h" +#include "nsString.h" +#include "nsGkAtoms.h" + +using namespace mozilla; + +//------------------------------------------------------------------------ + +const mozilla::intl::Collator* nsXULContentUtils::gCollator; + +//------------------------------------------------------------------------ +// Constructors n' stuff +// + +nsresult nsXULContentUtils::Finish() { + if (gCollator) { + delete gCollator; + gCollator = nullptr; + } + + return NS_OK; +} + +const mozilla::intl::Collator* nsXULContentUtils::GetCollator() { + if (!gCollator) { + // Lazily initialize the Collator. + auto result = mozilla::intl::LocaleService::TryCreateComponent< + mozilla::intl::Collator>(); + if (result.isErr()) { + NS_ERROR("couldn't create a mozilla::intl::Collator"); + return nullptr; + } + + auto collator = result.unwrap(); + + // Sort in a case-insensitive way, where "base" letters are considered + // equal, e.g: a = á, a = A, a ≠ b. + mozilla::intl::Collator::Options options{}; + options.sensitivity = mozilla::intl::Collator::Sensitivity::Base; + auto optResult = collator->SetOptions(options); + if (optResult.isErr()) { + NS_ERROR("couldn't set options for mozilla::intl::Collator"); + return nullptr; + } + gCollator = collator.release(); + } + + return gCollator; +} + +//------------------------------------------------------------------------ +// + +nsresult nsXULContentUtils::FindChildByTag(nsIContent* aElement, + int32_t aNameSpaceID, nsAtom* aTag, + mozilla::dom::Element** aResult) { + for (nsIContent* child = aElement->GetFirstChild(); child; + child = child->GetNextSibling()) { + if (child->IsElement() && child->NodeInfo()->Equals(aTag, aNameSpaceID)) { + NS_ADDREF(*aResult = child->AsElement()); + return NS_OK; + } + } + + *aResult = nullptr; + return NS_RDF_NO_VALUE; // not found +} |