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"
23 #include "nsLayoutCID.h"
25 #include "nsGkAtoms.h"
27 using namespace mozilla
;
29 //------------------------------------------------------------------------
31 const mozilla::intl::Collator
* nsXULContentUtils::gCollator
;
33 //------------------------------------------------------------------------
34 // Constructors n' stuff
37 nsresult
nsXULContentUtils::Finish() {
46 const mozilla::intl::Collator
* nsXULContentUtils::GetCollator() {
48 // Lazily initialize the Collator.
49 auto result
= mozilla::intl::LocaleService::TryCreateComponent
<
50 mozilla::intl::Collator
>();
52 NS_ERROR("couldn't create a mozilla::intl::Collator");
56 auto collator
= result
.unwrap();
58 // Sort in a case-insensitive way, where "base" letters are considered
59 // equal, e.g: a = á, a = A, a ≠ b.
60 mozilla::intl::Collator::Options options
{};
61 options
.sensitivity
= mozilla::intl::Collator::Sensitivity::Base
;
62 auto optResult
= collator
->SetOptions(options
);
63 if (optResult
.isErr()) {
64 NS_ERROR("couldn't set options for mozilla::intl::Collator");
67 gCollator
= collator
.release();
73 //------------------------------------------------------------------------
76 nsresult
nsXULContentUtils::FindChildByTag(nsIContent
* aElement
,
77 int32_t aNameSpaceID
, nsAtom
* aTag
,
78 mozilla::dom::Element
** aResult
) {
79 for (nsIContent
* child
= aElement
->GetFirstChild(); child
;
80 child
= child
->GetNextSibling()) {
81 if (child
->IsElement() && child
->NodeInfo()->Equals(aTag
, aNameSpaceID
)) {
82 NS_ADDREF(*aResult
= child
->AsElement());
88 return NS_RDF_NO_VALUE
; // not found