2018-01-11 07:37:59 +03:00
|
|
|
/* -*- 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
|
|
|
|
|
2018-01-11 07:37:59 +03:00
|
|
|
#include "mozilla/dom/BindingDeclarations.h"
|
|
|
|
|
2018-01-11 07:37:59 +03:00
|
|
|
class nsAtom;
|
2018-01-11 07:37:59 +03:00
|
|
|
class nsIDocument;
|
2018-01-11 07:37:59 +03:00
|
|
|
class nsStyleContext;
|
2018-01-11 07:37:59 +03:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
class StyleSheet;
|
2018-01-11 07:37:59 +03:00
|
|
|
namespace css {
|
|
|
|
class Rule;
|
|
|
|
} // namespace css
|
|
|
|
namespace dom {
|
|
|
|
class Element;
|
|
|
|
} // namespace dom
|
2018-01-11 07:37:59 +03:00
|
|
|
} // namespace mozilla
|
|
|
|
|
2018-01-11 07:37:59 +03:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A collection of utility methods for use by devtools.
|
|
|
|
*/
|
|
|
|
class InspectorUtils
|
|
|
|
{
|
2018-01-11 07:37:59 +03:00
|
|
|
public:
|
|
|
|
static void GetAllStyleSheets(GlobalObject& aGlobal,
|
|
|
|
nsIDocument& aDocument,
|
|
|
|
nsTArray<RefPtr<StyleSheet>>& aResult);
|
2018-01-11 07:37:59 +03:00
|
|
|
static void GetCSSStyleRules(GlobalObject& aGlobal,
|
|
|
|
Element& aElement,
|
|
|
|
const nsAString& aPseudo,
|
|
|
|
nsTArray<RefPtr<css::Rule>>& aResult);
|
|
|
|
|
2018-01-11 07:37:59 +03:00
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
|
2018-01-11 07:37:59 +03:00
|
|
|
static CSSLexer* GetCSSLexer(GlobalObject& aGlobal, const nsAString& aText);
|
|
|
|
|
2018-01-11 07:37:59 +03:00
|
|
|
// 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);
|
|
|
|
|
2018-01-11 07:37:59 +03:00
|
|
|
private:
|
|
|
|
static already_AddRefed<nsStyleContext>
|
|
|
|
GetCleanStyleContextForElement(Element* aElement, nsAtom* aPseudo);
|
2018-01-11 07:37:59 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_dom_InspectorUtils_h
|