gecko-dev/layout/inspector/InspectorUtils.h

109 строки
3.7 KiB
C
Исходник Обычный вид История

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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/.
*/
#ifndef mozilla_dom_InspectorUtils_h
#define mozilla_dom_InspectorUtils_h
#include "mozilla/dom/BindingDeclarations.h"
class nsAtom;
class nsIDocument;
class nsStyleContext;
namespace mozilla {
class StyleSheet;
namespace css {
class Rule;
} // namespace css
namespace dom {
class Element;
} // namespace dom
} // namespace mozilla
namespace mozilla {
namespace dom {
/**
* A collection of utility methods for use by devtools.
*/
class InspectorUtils
{
public:
static void GetAllStyleSheets(GlobalObject& aGlobal,
nsIDocument& aDocument,
nsTArray<RefPtr<StyleSheet>>& aResult);
static void GetCSSStyleRules(GlobalObject& aGlobal,
Element& aElement,
const nsAString& aPseudo,
nsTArray<RefPtr<css::Rule>>& aResult);
/**
* Get the line number of a rule.
*
* @param aRule The rule.
* @return The rule's line number. Line numbers are 1-based.
*/
static uint32_t GetRuleLine(GlobalObject& aGlobal, css::Rule& aRule);
/**
* Get the column number of a rule.
*
* @param aRule The rule.
* @return The rule's column number. Column numbers are 1-based.
*/
static uint32_t GetRuleColumn(GlobalObject& aGlobal, css::Rule& aRule);
/**
* Like getRuleLine, but if the rule is in a <style> element,
* returns a line number relative to the start of the element.
*
* @param aRule the rule to examine
* @return the line number of the rule, possibly relative to the
* <style> element
*/
static uint32_t GetRelativeRuleLine(GlobalObject& aGlobal, css::Rule& aRule);
static CSSLexer* GetCSSLexer(GlobalObject& aGlobal, const nsAString& aText);
// Utilities for working with selectors. We don't have a JS OM representation
// of a single selector or a selector list yet, but given a rule we can index
// into the selector list.
//
// These methods would probably make more sense being [ChromeOnly] APIs on
// CSSStyleRule itself (bug 1428245).
static uint32_t GetSelectorCount(GlobalObject& aGlobal,
BindingStyleRule& aRule);
// For all three functions below, aSelectorIndex is 0-based
static void GetSelectorText(GlobalObject& aGlobal,
BindingStyleRule& aRule,
uint32_t aSelectorIndex,
nsString& aText,
ErrorResult& aRv);
static uint64_t GetSpecificity(GlobalObject& aGlobal,
BindingStyleRule& aRule,
uint32_t aSelectorIndex,
ErrorResult& aRv);
// Note: This does not handle scoped selectors correctly, because it has no
// idea what the right scope is.
static bool SelectorMatchesElement(GlobalObject& aGlobal,
Element& aElement,
BindingStyleRule& aRule,
uint32_t aSelectorIndex,
const nsAString& aPseudo,
ErrorResult& aRv);
private:
static already_AddRefed<nsStyleContext>
GetCleanStyleContextForElement(Element* aElement, nsAtom* aPseudo);
};
} // namespace dom
} // namespace mozilla
#endif // mozilla_dom_InspectorUtils_h