Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/xul/nsXULContentUtils.cpp
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
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/. */
6
7
8
/*
9
10
  A package of routines shared by the XUL content code.
11
12
 */
13
14
#include "mozilla/ArrayUtils.h"
15
16
#include "nsCollationCID.h"
17
#include "nsCOMPtr.h"
18
#include "nsIContent.h"
19
#include "nsICollation.h"
20
#include "nsIDocument.h"
21
#include "nsIDOMXULCommandDispatcher.h"
22
#include "nsIServiceManager.h"
23
#include "nsXULContentUtils.h"
24
#include "nsLayoutCID.h"
25
#include "nsString.h"
26
#include "nsGkAtoms.h"
27
#include "XULDocument.h"
28
29
using namespace mozilla;
30
using dom::XULDocument;
31
32
//------------------------------------------------------------------------
33
34
nsICollation *nsXULContentUtils::gCollation;
35
36
//------------------------------------------------------------------------
37
// Constructors n' stuff
38
//
39
40
nsresult
41
nsXULContentUtils::Finish()
42
0
{
43
0
    NS_IF_RELEASE(gCollation);
44
0
45
0
    return NS_OK;
46
0
}
47
48
nsICollation*
49
nsXULContentUtils::GetCollation()
50
0
{
51
0
    if (!gCollation) {
52
0
        nsCOMPtr<nsICollationFactory> colFactory =
53
0
            do_CreateInstance(NS_COLLATIONFACTORY_CONTRACTID);
54
0
        if (colFactory) {
55
0
            DebugOnly<nsresult> rv = colFactory->CreateCollation(&gCollation);
56
0
            NS_ASSERTION(NS_SUCCEEDED(rv),
57
0
                         "couldn't create collation instance");
58
0
        } else
59
0
            NS_ERROR("couldn't create instance of collation factory");
60
0
    }
61
0
62
0
    return gCollation;
63
0
}
64
65
66
//------------------------------------------------------------------------
67
//
68
69
nsresult
70
nsXULContentUtils::FindChildByTag(nsIContent* aElement,
71
                                  int32_t aNameSpaceID,
72
                                  nsAtom* aTag,
73
                                  Element** aResult)
74
0
{
75
0
    for (nsIContent* child = aElement->GetFirstChild();
76
0
         child;
77
0
         child = child->GetNextSibling()) {
78
0
79
0
        if (child->IsElement() &&
80
0
            child->NodeInfo()->Equals(aTag, aNameSpaceID)) {
81
0
            NS_ADDREF(*aResult = child->AsElement());
82
0
            return NS_OK;
83
0
        }
84
0
    }
85
0
86
0
    *aResult = nullptr;
87
0
    return NS_RDF_NO_VALUE; // not found
88
0
}