1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
9 A package of routines shared by the XUL content code.
13 #include "mozilla/ArrayUtils.h"
14 #include "mozilla/intl/LocaleService.h"
15 #include "mozilla/intl/Collator.h"
18 #include "nsComponentManagerUtils.h"
19 #include "nsIContent.h"
20 #include "mozilla/dom/Document.h"
21 #include "mozilla/dom/Element.h"
22 #include "nsXULContentUtils.h"
24 #include "nsGkAtoms.h"
26 using namespace mozilla
;
28 //------------------------------------------------------------------------
30 const mozilla::intl::Collator
* nsXULContentUtils::gCollator
;
32 //------------------------------------------------------------------------
33 // Constructors n' stuff
36 nsresult
nsXULContentUtils::Finish() {
45 const mozilla::intl::Collator
* nsXULContentUtils::GetCollator() {
47 // Lazily initialize the Collator.
48 auto result
= mozilla::intl::LocaleService::TryCreateComponent
<
49 mozilla::intl::Collator
>();
51 NS_ERROR("couldn't create a mozilla::intl::Collator");
55 auto collator
= result
.unwrap();
57 // Sort in a case-insensitive way, where "base" letters are considered
58 // equal, e.g: a = á, a = A, a ≠ b.
59 mozilla::intl::Collator::Options options
{};
60 options
.sensitivity
= mozilla::intl::Collator::Sensitivity::Base
;
61 auto optResult
= collator
->SetOptions(options
);
62 if (optResult
.isErr()) {
63 NS_ERROR("couldn't set options for mozilla::intl::Collator");
66 gCollator
= collator
.release();
72 //------------------------------------------------------------------------
75 nsresult
nsXULContentUtils::FindChildByTag(nsIContent
* aElement
,
76 int32_t aNameSpaceID
, nsAtom
* aTag
,
77 mozilla::dom::Element
** aResult
) {
78 for (nsIContent
* child
= aElement
->GetFirstChild(); child
;
79 child
= child
->GetNextSibling()) {
80 if (child
->IsElement() && child
->NodeInfo()->Equals(aTag
, aNameSpaceID
)) {
81 NS_ADDREF(*aResult
= child
->AsElement());
87 return NS_RDF_NO_VALUE
; // not found