2017-10-27 20:33:53 +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: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* 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/. */
|
2006-05-17 06:21:53 +04:00
|
|
|
|
2014-01-30 22:26:54 +04:00
|
|
|
#include "mozilla/ArrayUtils.h"
|
2014-04-03 08:18:36 +04:00
|
|
|
#include "mozilla/EventStates.h"
|
2014-01-30 22:26:54 +04:00
|
|
|
|
2006-05-17 06:21:53 +04:00
|
|
|
#include "inLayoutUtils.h"
|
|
|
|
|
2016-10-24 23:24:28 +03:00
|
|
|
#include "nsArray.h"
|
2016-06-07 23:10:18 +03:00
|
|
|
#include "nsAutoPtr.h"
|
2018-01-11 07:38:00 +03:00
|
|
|
#include "nsGenericDOMDataNode.h"
|
2006-05-17 06:33:55 +04:00
|
|
|
#include "nsIServiceManager.h"
|
2006-05-17 06:21:53 +04:00
|
|
|
#include "nsString.h"
|
2015-08-18 01:19:21 +03:00
|
|
|
#include "nsIStyleSheetLinkingElement.h"
|
2016-08-19 03:03:49 +03:00
|
|
|
#include "nsIContentInlines.h"
|
2006-05-17 06:21:53 +04:00
|
|
|
#include "nsIDOMElement.h"
|
|
|
|
#include "nsIDocument.h"
|
2009-08-11 02:52:29 +04:00
|
|
|
#include "nsIPresShell.h"
|
2006-05-17 06:21:53 +04:00
|
|
|
#include "nsIDOMDocument.h"
|
2006-05-17 06:37:41 +04:00
|
|
|
#include "nsIDOMCharacterData.h"
|
2018-02-01 07:04:04 +03:00
|
|
|
#ifdef MOZ_OLD_STYLE
|
2006-05-17 06:33:36 +04:00
|
|
|
#include "nsRuleNode.h"
|
2006-05-17 06:21:53 +04:00
|
|
|
#include "nsIStyleRule.h"
|
2011-03-11 05:48:57 +03:00
|
|
|
#include "mozilla/css/StyleRule.h"
|
2018-02-01 07:04:04 +03:00
|
|
|
#endif
|
2011-07-15 14:31:34 +04:00
|
|
|
#include "nsIDOMWindow.h"
|
2009-08-11 02:52:29 +04:00
|
|
|
#include "nsXBLBinding.h"
|
|
|
|
#include "nsXBLPrototypeBinding.h"
|
|
|
|
#include "nsIMutableArray.h"
|
|
|
|
#include "nsBindingManager.h"
|
2013-05-02 02:50:08 +04:00
|
|
|
#include "ChildIterator.h"
|
2009-08-11 02:52:29 +04:00
|
|
|
#include "nsComputedDOMStyle.h"
|
2014-04-01 08:09:23 +04:00
|
|
|
#include "mozilla/EventStateManager.h"
|
2017-10-03 01:05:19 +03:00
|
|
|
#include "nsAtom.h"
|
2012-01-10 18:19:54 +04:00
|
|
|
#include "nsRange.h"
|
2016-09-26 15:03:25 +03:00
|
|
|
#include "mozilla/StyleSheetInlines.h"
|
2011-07-20 23:18:54 +04:00
|
|
|
#include "mozilla/dom/Element.h"
|
2018-02-01 07:04:04 +03:00
|
|
|
#ifdef MOZ_OLD_STYLE
|
2013-02-13 19:11:53 +04:00
|
|
|
#include "nsRuleWalker.h"
|
2018-02-01 07:04:04 +03:00
|
|
|
#endif
|
2016-04-22 16:38:46 +03:00
|
|
|
#include "nsCSSPseudoClasses.h"
|
2018-02-01 07:04:04 +03:00
|
|
|
#ifdef MOZ_OLD_STYLE
|
2013-02-13 19:11:53 +04:00
|
|
|
#include "nsCSSRuleProcessor.h"
|
2018-02-01 07:04:04 +03:00
|
|
|
#endif
|
2015-05-04 17:28:00 +03:00
|
|
|
#include "mozilla/dom/CSSLexer.h"
|
2013-03-14 23:43:00 +04:00
|
|
|
#include "mozilla/dom/InspectorUtilsBinding.h"
|
2014-06-11 23:38:55 +04:00
|
|
|
#include "mozilla/dom/ToJSValue.h"
|
2014-07-17 18:08:07 +04:00
|
|
|
#include "nsCSSParser.h"
|
2013-07-16 01:28:49 +04:00
|
|
|
#include "nsCSSProps.h"
|
2014-07-17 18:08:07 +04:00
|
|
|
#include "nsCSSValue.h"
|
2013-07-16 01:28:49 +04:00
|
|
|
#include "nsColor.h"
|
2016-12-09 21:27:32 +03:00
|
|
|
#include "mozilla/StyleSetHandleInlines.h"
|
2014-07-17 18:08:07 +04:00
|
|
|
#include "nsStyleUtil.h"
|
2015-04-15 19:47:03 +03:00
|
|
|
#include "nsQueryObject.h"
|
2017-04-08 01:21:36 +03:00
|
|
|
#include "mozilla/ServoBindings.h"
|
|
|
|
#include "mozilla/ServoStyleRule.h"
|
2017-06-19 08:45:43 +03:00
|
|
|
#include "mozilla/ServoStyleRuleMap.h"
|
2017-10-16 04:02:35 +03:00
|
|
|
#include "mozilla/ServoCSSParser.h"
|
2018-01-11 07:37:59 +03:00
|
|
|
#include "mozilla/dom/InspectorUtils.h"
|
2018-01-11 07:38:01 +03:00
|
|
|
#include "mozilla/dom/InspectorFontFace.h"
|
2011-07-20 23:18:54 +04:00
|
|
|
|
2013-02-13 19:11:53 +04:00
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::css;
|
|
|
|
using namespace mozilla::dom;
|
2006-05-17 06:21:53 +04:00
|
|
|
|
2018-01-11 07:37:59 +03:00
|
|
|
extern const char* const kCSSRawProperties[];
|
|
|
|
|
2018-01-11 07:37:59 +03:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2013-07-25 17:31:14 +04:00
|
|
|
|
2018-01-11 07:37:59 +03:00
|
|
|
/* static */ void
|
|
|
|
InspectorUtils::GetAllStyleSheets(GlobalObject& aGlobalObject,
|
|
|
|
nsIDocument& aDocument,
|
|
|
|
nsTArray<RefPtr<StyleSheet>>& aResult)
|
|
|
|
{
|
2015-08-12 15:43:39 +03:00
|
|
|
// Get the agent, then user and finally xbl sheets in the style set.
|
2018-01-11 07:37:59 +03:00
|
|
|
nsIPresShell* presShell = aDocument.GetShell();
|
2016-02-24 10:01:11 +03:00
|
|
|
|
2013-07-25 17:31:14 +04:00
|
|
|
if (presShell) {
|
2016-12-09 21:27:32 +03:00
|
|
|
StyleSetHandle styleSet = presShell->StyleSet();
|
2015-10-20 02:16:20 +03:00
|
|
|
SheetType sheetType = SheetType::Agent;
|
2013-07-25 17:31:14 +04:00
|
|
|
for (int32_t i = 0; i < styleSet->SheetCount(sheetType); i++) {
|
2018-01-11 07:37:59 +03:00
|
|
|
aResult.AppendElement(styleSet->StyleSheetAt(sheetType, i));
|
2013-07-25 17:31:14 +04:00
|
|
|
}
|
2015-10-20 02:16:20 +03:00
|
|
|
sheetType = SheetType::User;
|
2013-07-25 17:31:14 +04:00
|
|
|
for (int32_t i = 0; i < styleSet->SheetCount(sheetType); i++) {
|
2018-01-11 07:37:59 +03:00
|
|
|
aResult.AppendElement(styleSet->StyleSheetAt(sheetType, i));
|
2013-07-25 17:31:14 +04:00
|
|
|
}
|
2017-06-30 02:09:22 +03:00
|
|
|
|
|
|
|
AutoTArray<StyleSheet*, 32> xblSheetArray;
|
2017-07-05 12:11:54 +03:00
|
|
|
styleSet->AppendAllXBLStyleSheets(xblSheetArray);
|
2017-06-30 02:09:22 +03:00
|
|
|
|
|
|
|
// The XBL stylesheet array will quite often be full of duplicates. Cope:
|
|
|
|
nsTHashtable<nsPtrHashKey<StyleSheet>> sheetSet;
|
|
|
|
for (StyleSheet* sheet : xblSheetArray) {
|
|
|
|
if (!sheetSet.Contains(sheet)) {
|
|
|
|
sheetSet.PutEntry(sheet);
|
2018-01-11 07:37:59 +03:00
|
|
|
aResult.AppendElement(sheet);
|
2015-08-12 15:43:39 +03:00
|
|
|
}
|
|
|
|
}
|
2013-07-25 17:31:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Get the document sheets.
|
2018-01-11 07:37:59 +03:00
|
|
|
for (size_t i = 0; i < aDocument.SheetCount(); i++) {
|
|
|
|
aResult.AppendElement(aDocument.SheetAt(i));
|
2013-07-25 17:31:14 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-11 07:38:00 +03:00
|
|
|
bool
|
|
|
|
InspectorUtils::IsIgnorableWhitespace(nsGenericDOMDataNode& aDataNode)
|
2006-05-17 06:37:41 +04:00
|
|
|
{
|
2018-01-11 07:38:00 +03:00
|
|
|
if (!aDataNode.TextIsOnlyWhitespace()) {
|
|
|
|
return false;
|
2006-05-17 06:37:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Okay. We have only white space. Let's check the white-space
|
|
|
|
// property now and make sure that this isn't preformatted text...
|
2018-01-11 07:38:00 +03:00
|
|
|
if (nsIFrame* frame = aDataNode.GetPrimaryFrame()) {
|
|
|
|
return !frame->StyleText()->WhiteSpaceIsSignificant();
|
2006-05-17 06:37:52 +04:00
|
|
|
}
|
2006-05-17 06:37:41 +04:00
|
|
|
|
2018-01-11 07:38:00 +03:00
|
|
|
// empty inter-tag text node without frame, e.g., in between <table>\n<tr>
|
|
|
|
return true;
|
2006-05-17 06:37:38 +04:00
|
|
|
}
|
|
|
|
|
2018-01-11 07:38:00 +03:00
|
|
|
/* static */ nsINode*
|
|
|
|
InspectorUtils::GetParentForNode(nsINode& aNode,
|
|
|
|
bool aShowingAnonymousContent)
|
2006-05-17 06:38:00 +04:00
|
|
|
{
|
2008-12-16 14:26:42 +03:00
|
|
|
// First do the special cases -- document nodes and anonymous content
|
2018-01-11 07:38:00 +03:00
|
|
|
nsINode* parent = nullptr;
|
2006-05-17 06:38:00 +04:00
|
|
|
|
2018-01-11 07:38:00 +03:00
|
|
|
if (aNode.IsNodeOfType(nsINode::eDOCUMENT)) {
|
|
|
|
auto& doc = static_cast<nsIDocument&>(aNode);
|
|
|
|
parent = inLayoutUtils::GetContainerFor(doc);
|
2006-05-17 06:38:00 +04:00
|
|
|
} else if (aShowingAnonymousContent) {
|
2018-01-11 07:38:00 +03:00
|
|
|
if (aNode.IsContent()) {
|
|
|
|
parent = aNode.AsContent()->GetFlattenedTreeParent();
|
2006-07-14 16:08:59 +04:00
|
|
|
}
|
2006-05-17 06:38:00 +04:00
|
|
|
}
|
2012-05-09 20:23:57 +04:00
|
|
|
|
2006-05-17 06:38:00 +04:00
|
|
|
if (!parent) {
|
|
|
|
// Ok, just get the normal DOM parent node
|
2018-01-11 07:38:00 +03:00
|
|
|
return aNode.GetParentNode();
|
2006-05-17 06:38:00 +04:00
|
|
|
}
|
|
|
|
|
2018-01-11 07:38:00 +03:00
|
|
|
return parent;
|
2006-05-17 06:38:00 +04:00
|
|
|
}
|
|
|
|
|
2018-01-11 07:38:00 +03:00
|
|
|
/* static */ already_AddRefed<nsINodeList>
|
|
|
|
InspectorUtils::GetChildrenForNode(nsINode& aNode,
|
|
|
|
bool aShowingAnonymousContent)
|
2011-05-31 01:51:09 +04:00
|
|
|
{
|
2018-01-11 07:38:00 +03:00
|
|
|
nsCOMPtr<nsINodeList> kids;
|
2011-05-31 01:51:09 +04:00
|
|
|
|
|
|
|
if (aShowingAnonymousContent) {
|
2018-01-11 07:38:00 +03:00
|
|
|
if (aNode.IsContent()) {
|
|
|
|
kids = aNode.AsContent()->GetChildren(nsIContent::eAllChildren);
|
2011-05-31 01:51:09 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!kids) {
|
2018-01-11 07:38:00 +03:00
|
|
|
kids = aNode.ChildNodes();
|
2011-05-31 01:51:09 +04:00
|
|
|
}
|
|
|
|
|
2018-01-11 07:38:00 +03:00
|
|
|
return kids.forget();
|
2011-05-31 01:51:09 +04:00
|
|
|
}
|
|
|
|
|
2018-01-11 07:37:59 +03:00
|
|
|
/* static */ void
|
|
|
|
InspectorUtils::GetCSSStyleRules(GlobalObject& aGlobalObject,
|
|
|
|
Element& aElement,
|
|
|
|
const nsAString& aPseudo,
|
|
|
|
nsTArray<RefPtr<css::Rule>>& aResult)
|
|
|
|
{
|
2017-10-03 01:05:19 +03:00
|
|
|
RefPtr<nsAtom> pseudoElt;
|
2011-05-06 01:12:04 +04:00
|
|
|
if (!aPseudo.IsEmpty()) {
|
2016-03-29 02:09:43 +03:00
|
|
|
pseudoElt = NS_Atomize(aPseudo);
|
2011-05-06 01:12:04 +04:00
|
|
|
}
|
|
|
|
|
2017-03-14 03:23:17 +03:00
|
|
|
RefPtr<nsStyleContext> styleContext =
|
2018-01-11 07:37:59 +03:00
|
|
|
GetCleanStyleContextForElement(&aElement, pseudoElt);
|
2017-03-14 03:23:17 +03:00
|
|
|
if (!styleContext) {
|
2013-11-11 12:00:41 +04:00
|
|
|
// This can fail for elements that are not in the document or
|
2006-05-17 06:38:34 +04:00
|
|
|
// if the document they're in doesn't have a presshell. Bail out.
|
2018-01-11 07:37:59 +03:00
|
|
|
return;
|
2006-05-17 06:38:34 +04:00
|
|
|
}
|
|
|
|
|
2017-04-08 01:21:36 +03:00
|
|
|
|
2018-02-01 07:04:04 +03:00
|
|
|
if (styleContext->IsGecko()) {
|
|
|
|
#ifdef MOZ_OLD_STYLE
|
|
|
|
auto gecko = styleContext->AsGecko();
|
2017-06-11 08:27:45 +03:00
|
|
|
nsRuleNode* ruleNode = gecko->RuleNode();
|
|
|
|
if (!ruleNode) {
|
2018-01-11 07:37:59 +03:00
|
|
|
return;
|
2017-06-11 08:27:45 +03:00
|
|
|
}
|
2017-03-14 03:24:38 +03:00
|
|
|
|
|
|
|
AutoTArray<nsRuleNode*, 16> ruleNodes;
|
|
|
|
while (!ruleNode->IsRoot()) {
|
|
|
|
ruleNodes.AppendElement(ruleNode);
|
|
|
|
ruleNode = ruleNode->GetParent();
|
|
|
|
}
|
2016-10-24 03:59:00 +03:00
|
|
|
|
2017-03-14 03:24:38 +03:00
|
|
|
for (nsRuleNode* ruleNode : Reversed(ruleNodes)) {
|
|
|
|
RefPtr<Declaration> decl = do_QueryObject(ruleNode->GetRule());
|
|
|
|
if (decl) {
|
|
|
|
css::Rule* owningRule = decl->GetOwningRule();
|
|
|
|
if (owningRule) {
|
2018-01-11 07:37:59 +03:00
|
|
|
aResult.AppendElement(owningRule);
|
2017-03-14 03:24:38 +03:00
|
|
|
}
|
2015-11-05 11:44:10 +03:00
|
|
|
}
|
2006-05-17 06:38:08 +04:00
|
|
|
}
|
2018-02-01 07:04:04 +03:00
|
|
|
#else
|
|
|
|
MOZ_CRASH("old style system disabled");
|
|
|
|
#endif
|
2017-04-08 01:21:36 +03:00
|
|
|
} else {
|
2018-01-11 07:37:59 +03:00
|
|
|
nsIDocument* doc = aElement.OwnerDoc();
|
2017-06-19 08:45:43 +03:00
|
|
|
nsIPresShell* shell = doc->GetShell();
|
|
|
|
if (!shell) {
|
2018-01-11 07:37:59 +03:00
|
|
|
return;
|
2017-04-08 01:21:36 +03:00
|
|
|
}
|
2006-05-17 06:21:53 +04:00
|
|
|
|
2017-07-10 02:38:58 +03:00
|
|
|
ServoStyleContext* servo = styleContext->AsServo();
|
|
|
|
nsTArray<const RawServoStyleRule*> rawRuleList;
|
2017-07-19 09:17:34 +03:00
|
|
|
Servo_ComputedValues_GetStyleRuleList(servo, &rawRuleList);
|
2017-07-10 02:38:58 +03:00
|
|
|
|
2017-08-03 09:59:17 +03:00
|
|
|
AutoTArray<ServoStyleRuleMap*, 1> maps;
|
|
|
|
{
|
|
|
|
ServoStyleSet* styleSet = shell->StyleSet()->AsServo();
|
|
|
|
ServoStyleRuleMap* map = styleSet->StyleRuleMap();
|
|
|
|
map->EnsureTable();
|
|
|
|
maps.AppendElement(map);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Collect style rule maps for bindings.
|
2018-01-11 07:37:59 +03:00
|
|
|
for (nsIContent* bindingContent = &aElement; bindingContent;
|
2017-08-03 09:59:17 +03:00
|
|
|
bindingContent = bindingContent->GetBindingParent()) {
|
2017-10-12 09:41:13 +03:00
|
|
|
for (nsXBLBinding* binding = bindingContent->GetXBLBinding();
|
|
|
|
binding; binding = binding->GetBaseBinding()) {
|
2017-08-03 09:59:17 +03:00
|
|
|
if (ServoStyleSet* styleSet = binding->GetServoStyleSet()) {
|
|
|
|
ServoStyleRuleMap* map = styleSet->StyleRuleMap();
|
|
|
|
map->EnsureTable();
|
|
|
|
maps.AppendElement(map);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Note that we intentionally don't cut off here, unlike when we
|
|
|
|
// do styling, because even if style rules from parent binding
|
|
|
|
// do not apply to the element directly in those cases, their
|
|
|
|
// rules may still show up in the list we get above due to the
|
|
|
|
// inheritance in cascading.
|
|
|
|
}
|
2017-06-19 08:45:43 +03:00
|
|
|
|
2017-04-08 01:21:36 +03:00
|
|
|
// Find matching rules in the table.
|
2017-06-19 08:45:43 +03:00
|
|
|
for (const RawServoStyleRule* rawRule : Reversed(rawRuleList)) {
|
2017-08-03 09:59:17 +03:00
|
|
|
ServoStyleRule* rule = nullptr;
|
|
|
|
for (ServoStyleRuleMap* map : maps) {
|
|
|
|
rule = map->Lookup(rawRule);
|
|
|
|
if (rule) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (rule) {
|
2018-01-11 07:37:59 +03:00
|
|
|
aResult.AppendElement(rule);
|
2017-05-19 00:50:05 +03:00
|
|
|
} else {
|
2017-06-19 08:45:43 +03:00
|
|
|
MOZ_ASSERT_UNREACHABLE("We should be able to map a raw rule to a rule");
|
2017-05-19 00:50:05 +03:00
|
|
|
}
|
2017-04-08 01:21:36 +03:00
|
|
|
}
|
2017-03-14 03:24:38 +03:00
|
|
|
}
|
2006-05-17 06:21:53 +04:00
|
|
|
}
|
|
|
|
|
2018-01-11 07:37:59 +03:00
|
|
|
/* static */ uint32_t
|
|
|
|
InspectorUtils::GetRuleLine(GlobalObject& aGlobal, css::Rule& aRule)
|
|
|
|
{
|
|
|
|
return aRule.GetLineNumber();
|
2013-02-13 19:11:53 +04:00
|
|
|
}
|
2008-12-16 14:26:42 +03:00
|
|
|
|
2018-01-11 07:37:59 +03:00
|
|
|
/* static */ uint32_t
|
|
|
|
InspectorUtils::GetRuleColumn(GlobalObject& aGlobal, css::Rule& aRule)
|
2013-04-06 21:38:56 +04:00
|
|
|
{
|
2018-01-11 07:37:59 +03:00
|
|
|
return aRule.GetColumnNumber();
|
2013-04-06 21:38:56 +04:00
|
|
|
}
|
|
|
|
|
2018-01-11 07:37:59 +03:00
|
|
|
/* static */ uint32_t
|
|
|
|
InspectorUtils::GetRelativeRuleLine(GlobalObject& aGlobal, css::Rule& aRule)
|
2015-08-18 01:19:21 +03:00
|
|
|
{
|
2018-01-11 07:37:59 +03:00
|
|
|
uint32_t lineNumber = aRule.GetLineNumber();
|
2018-01-18 01:40:45 +03:00
|
|
|
|
|
|
|
// If aRule was parsed along with its stylesheet, then it will
|
|
|
|
// have an absolute lineNumber that we need to remap to its
|
|
|
|
// containing node. But if aRule was added via CSSOM after parsing,
|
|
|
|
// then it has a sort-of relative line number already:
|
|
|
|
// Gecko gives all rules a 0 lineNumber.
|
|
|
|
// Servo gives the first line of a rule a 0 lineNumber, and then
|
|
|
|
// counts up from there.
|
|
|
|
|
|
|
|
// The Servo behavior is arguably more correct, but harder to
|
|
|
|
// interpret for purposes of deciding whether a lineNumber is
|
|
|
|
// relative or absolute.
|
|
|
|
|
|
|
|
// Since most of the time, inserted rules are single line and
|
|
|
|
// therefore have 0 lineNumbers in both Gecko and Servo, we use
|
|
|
|
// that to detect that a lineNumber is already relative.
|
|
|
|
|
|
|
|
// There is one ugly edge case that we avoid: if an inserted rule
|
|
|
|
// is multi-line, then Servo will give it 0+ lineNumbers. If we
|
|
|
|
// do relative number mapping on those line numbers, we could get
|
|
|
|
// negative underflow. So we check for underflow and instead report
|
|
|
|
// a 0 lineNumber.
|
2018-01-11 07:37:59 +03:00
|
|
|
StyleSheet* sheet = aRule.GetStyleSheet();
|
2015-11-17 19:02:34 +03:00
|
|
|
if (sheet && lineNumber != 0) {
|
2015-08-18 01:19:21 +03:00
|
|
|
nsINode* owningNode = sheet->GetOwnerNode();
|
|
|
|
if (owningNode) {
|
|
|
|
nsCOMPtr<nsIStyleSheetLinkingElement> link =
|
|
|
|
do_QueryInterface(owningNode);
|
|
|
|
if (link) {
|
2018-01-18 01:40:45 +03:00
|
|
|
// Check for underflow, which is one indication that we're
|
|
|
|
// trying to remap an already relative lineNumber.
|
|
|
|
uint32_t linkLineIndex0 = link->GetLineNumber() - 1;
|
|
|
|
if (linkLineIndex0 > lineNumber ) {
|
|
|
|
lineNumber = 0;
|
|
|
|
} else {
|
|
|
|
lineNumber -= linkLineIndex0;
|
|
|
|
}
|
2015-08-18 01:19:21 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-11 07:37:59 +03:00
|
|
|
return lineNumber;
|
2015-08-18 01:19:21 +03:00
|
|
|
}
|
|
|
|
|
2018-01-06 00:38:56 +03:00
|
|
|
/* static */ bool
|
|
|
|
InspectorUtils::HasRulesModifiedByCSSOM(GlobalObject& aGlobal, StyleSheet& aSheet)
|
|
|
|
{
|
|
|
|
return aSheet.HasModifiedRules();
|
|
|
|
}
|
|
|
|
|
2018-01-11 07:37:59 +03:00
|
|
|
/* static */ CSSLexer*
|
|
|
|
InspectorUtils::GetCSSLexer(GlobalObject& aGlobal, const nsAString& aText)
|
2015-05-04 17:28:00 +03:00
|
|
|
{
|
2018-01-11 07:37:59 +03:00
|
|
|
return new CSSLexer(aText);
|
2015-05-04 17:28:00 +03:00
|
|
|
}
|
|
|
|
|
2018-01-11 07:37:59 +03:00
|
|
|
/* static */ uint32_t
|
|
|
|
InspectorUtils::GetSelectorCount(GlobalObject& aGlobal,
|
|
|
|
BindingStyleRule& aRule)
|
2013-02-13 19:11:53 +04:00
|
|
|
{
|
2018-01-11 07:37:59 +03:00
|
|
|
return aRule.GetSelectorCount();
|
2013-02-13 19:11:53 +04:00
|
|
|
}
|
|
|
|
|
2018-01-11 07:37:59 +03:00
|
|
|
/* static */ void
|
|
|
|
InspectorUtils::GetSelectorText(GlobalObject& aGlobal,
|
|
|
|
BindingStyleRule& aRule,
|
|
|
|
uint32_t aSelectorIndex,
|
|
|
|
nsString& aText,
|
|
|
|
ErrorResult& aRv)
|
2013-02-13 19:11:53 +04:00
|
|
|
{
|
2018-01-11 07:37:59 +03:00
|
|
|
aRv = aRule.GetSelectorText(aSelectorIndex, aText);
|
2013-02-13 19:11:53 +04:00
|
|
|
}
|
|
|
|
|
2018-01-11 07:37:59 +03:00
|
|
|
/* static */ uint64_t
|
|
|
|
InspectorUtils::GetSpecificity(GlobalObject& aGlobal,
|
|
|
|
BindingStyleRule& aRule,
|
|
|
|
uint32_t aSelectorIndex,
|
|
|
|
ErrorResult& aRv)
|
2013-02-13 19:11:53 +04:00
|
|
|
{
|
2018-01-11 07:37:59 +03:00
|
|
|
uint64_t s;
|
|
|
|
aRv = aRule.GetSpecificity(aSelectorIndex, &s);
|
|
|
|
return s;
|
2013-02-13 19:11:53 +04:00
|
|
|
}
|
|
|
|
|
2018-01-11 07:37:59 +03:00
|
|
|
/* static */ bool
|
|
|
|
InspectorUtils::SelectorMatchesElement(GlobalObject& aGlobalObject,
|
|
|
|
Element& aElement,
|
|
|
|
BindingStyleRule& aRule,
|
|
|
|
uint32_t aSelectorIndex,
|
|
|
|
const nsAString& aPseudo,
|
|
|
|
ErrorResult& aRv)
|
2013-02-13 19:11:53 +04:00
|
|
|
{
|
2018-01-11 07:37:59 +03:00
|
|
|
bool result = false;
|
|
|
|
aRv = aRule.SelectorMatchesElement(&aElement, aSelectorIndex, aPseudo,
|
|
|
|
&result);
|
|
|
|
return result;
|
2006-05-17 06:21:53 +04:00
|
|
|
}
|
|
|
|
|
2018-01-11 07:37:59 +03:00
|
|
|
/* static */ bool
|
|
|
|
InspectorUtils::IsInheritedProperty(GlobalObject& aGlobalObject,
|
|
|
|
const nsAString& aPropertyName)
|
2011-11-05 19:41:10 +04:00
|
|
|
{
|
2016-08-10 02:28:19 +03:00
|
|
|
nsCSSPropertyID prop = nsCSSProps::
|
2016-05-10 11:44:05 +03:00
|
|
|
LookupProperty(aPropertyName, CSSEnabledState::eIgnoreEnabledState);
|
2011-11-05 19:41:10 +04:00
|
|
|
if (prop == eCSSProperty_UNKNOWN) {
|
2018-01-11 07:37:59 +03:00
|
|
|
return false;
|
2011-11-05 19:41:10 +04:00
|
|
|
}
|
|
|
|
|
2013-12-12 06:09:47 +04:00
|
|
|
if (prop == eCSSPropertyExtra_variable) {
|
2018-01-11 07:37:59 +03:00
|
|
|
return true;
|
2013-12-12 06:09:47 +04:00
|
|
|
}
|
|
|
|
|
2011-11-05 19:41:10 +04:00
|
|
|
if (nsCSSProps::IsShorthand(prop)) {
|
|
|
|
prop = nsCSSProps::SubpropertyEntryFor(prop)[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
nsStyleStructID sid = nsCSSProps::kSIDTable[prop];
|
2018-01-11 07:37:59 +03:00
|
|
|
return !nsStyleContext::IsReset(sid);
|
2011-11-05 19:41:10 +04:00
|
|
|
}
|
|
|
|
|
2018-01-11 07:37:59 +03:00
|
|
|
/* static */ void
|
|
|
|
InspectorUtils::GetCSSPropertyNames(GlobalObject& aGlobalObject,
|
|
|
|
const PropertyNamesOptions& aOptions,
|
|
|
|
nsTArray<nsString>& aResult)
|
2013-03-14 23:42:59 +04:00
|
|
|
{
|
2016-05-10 11:44:05 +03:00
|
|
|
#define DO_PROP(_prop) \
|
|
|
|
PR_BEGIN_MACRO \
|
2018-01-11 07:37:59 +03:00
|
|
|
nsCSSPropertyID cssProp = nsCSSPropertyID(_prop); \
|
2016-05-10 11:44:05 +03:00
|
|
|
if (nsCSSProps::IsEnabled(cssProp, CSSEnabledState::eForAllContent)) { \
|
2018-01-11 07:37:59 +03:00
|
|
|
nsDependentCString name(kCSSRawProperties[_prop]); \
|
|
|
|
aResult.AppendElement(NS_ConvertASCIItoUTF16(name)); \
|
2016-05-10 11:44:05 +03:00
|
|
|
} \
|
2013-03-14 23:42:59 +04:00
|
|
|
PR_END_MACRO
|
|
|
|
|
2018-01-11 07:37:59 +03:00
|
|
|
uint32_t prop = 0;
|
2013-03-14 23:42:59 +04:00
|
|
|
for ( ; prop < eCSSProperty_COUNT_no_shorthands; ++prop) {
|
2016-08-10 02:28:19 +03:00
|
|
|
if (nsCSSProps::PropertyParseType(nsCSSPropertyID(prop)) !=
|
2013-05-14 22:20:58 +04:00
|
|
|
CSS_PROPERTY_PARSE_INACCESSIBLE) {
|
2013-03-14 23:42:59 +04:00
|
|
|
DO_PROP(prop);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-11 07:37:59 +03:00
|
|
|
for ( ; prop < eCSSProperty_COUNT; ++prop) {
|
|
|
|
// Some shorthands are also aliases
|
|
|
|
if (aOptions.mIncludeAliases ||
|
|
|
|
!nsCSSProps::PropHasFlags(nsCSSPropertyID(prop),
|
|
|
|
CSS_PROPERTY_IS_ALIAS)) {
|
|
|
|
DO_PROP(prop);
|
2013-03-14 23:42:59 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-11 07:37:59 +03:00
|
|
|
if (aOptions.mIncludeAliases) {
|
2013-03-14 23:42:59 +04:00
|
|
|
for (prop = eCSSProperty_COUNT; prop < eCSSProperty_COUNT_with_aliases; ++prop) {
|
|
|
|
DO_PROP(prop);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef DO_PROP
|
|
|
|
}
|
|
|
|
|
Bug 895076 - domUtils.getCSSValuesForProperty now returns non keyword values. r=bz
This patch makes getCSSValuesForProperty return some none keyword values: auto,
normal, none, all, calc, -moz-calc, -moz-element, -moz-element-rect, rgb, hsl, -moz-rgba, -moz-hsla, rgba, hsla, cubic-bezer, and steps.
2013-07-19 18:32:52 +04:00
|
|
|
static void InsertNoDuplicates(nsTArray<nsString>& aArray,
|
|
|
|
const nsAString& aString)
|
|
|
|
{
|
|
|
|
size_t i = aArray.IndexOfFirstElementGt(aString);
|
|
|
|
if (i > 0 && aArray[i-1].Equals(aString)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
aArray.InsertElementAt(i, aString);
|
|
|
|
}
|
|
|
|
|
2016-08-10 02:28:19 +03:00
|
|
|
static void GetKeywordsForProperty(const nsCSSPropertyID aProperty,
|
2013-07-16 01:28:49 +04:00
|
|
|
nsTArray<nsString>& aArray)
|
|
|
|
{
|
|
|
|
if (nsCSSProps::IsShorthand(aProperty)) {
|
|
|
|
// Shorthand props have no keywords.
|
|
|
|
return;
|
|
|
|
}
|
2015-11-20 05:09:07 +03:00
|
|
|
const nsCSSProps::KTableEntry* keywordTable =
|
2014-02-05 15:10:44 +04:00
|
|
|
nsCSSProps::kKeywordTableTable[aProperty];
|
2018-01-22 23:26:14 +03:00
|
|
|
|
|
|
|
// Special cases where nsCSSPropList.h doesn't hold the table.
|
|
|
|
if (keywordTable == nullptr) {
|
|
|
|
if (aProperty == eCSSProperty_clip_path) {
|
|
|
|
keywordTable = nsCSSProps::kClipPathGeometryBoxKTable;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-17 07:16:02 +03:00
|
|
|
if (keywordTable) {
|
2018-01-15 19:14:55 +03:00
|
|
|
for (size_t i = 0; !keywordTable[i].IsSentinel(); ++i) {
|
2015-11-20 05:08:57 +03:00
|
|
|
nsCSSKeyword word = keywordTable[i].mKeyword;
|
2017-04-07 18:01:00 +03:00
|
|
|
|
|
|
|
// These are extra -moz values which are added while rebuilding
|
|
|
|
// the properties db. These values are not relevant and are not
|
|
|
|
// documented on MDN, so filter these out
|
2018-01-15 19:14:55 +03:00
|
|
|
// eCSSKeyword_UNKNOWN is ignored because it indicates an
|
|
|
|
// invalid entry; but can still be seen in a table, see bug 1430616.
|
2017-04-07 18:01:00 +03:00
|
|
|
if (word != eCSSKeyword__moz_zoom_in && word != eCSSKeyword__moz_zoom_out &&
|
2018-01-15 19:14:55 +03:00
|
|
|
word != eCSSKeyword__moz_grab && word != eCSSKeyword__moz_grabbing &&
|
|
|
|
word != eCSSKeyword_UNKNOWN) {
|
2017-04-07 18:01:00 +03:00
|
|
|
InsertNoDuplicates(aArray,
|
|
|
|
NS_ConvertASCIItoUTF16(nsCSSKeywords::GetStringValue(word)));
|
|
|
|
}
|
2013-07-16 01:28:49 +04:00
|
|
|
}
|
|
|
|
}
|
2018-01-22 23:26:14 +03:00
|
|
|
|
|
|
|
// More special cases.
|
|
|
|
if (aProperty == eCSSProperty_clip_path) {
|
|
|
|
InsertNoDuplicates(aArray, NS_LITERAL_STRING("circle"));
|
|
|
|
InsertNoDuplicates(aArray, NS_LITERAL_STRING("ellipse"));
|
|
|
|
InsertNoDuplicates(aArray, NS_LITERAL_STRING("inset"));
|
|
|
|
InsertNoDuplicates(aArray, NS_LITERAL_STRING("polygon"));
|
|
|
|
} else if (aProperty == eCSSProperty_clip) {
|
|
|
|
InsertNoDuplicates(aArray, NS_LITERAL_STRING("rect"));
|
2018-01-31 18:50:27 +03:00
|
|
|
} else if (aProperty == eCSSProperty_list_style_type) {
|
|
|
|
int32_t length;
|
|
|
|
const char* const* values = nsCSSProps::GetListStyleTypes(&length);
|
|
|
|
for (int32_t i = 0; i < length; ++i) {
|
|
|
|
InsertNoDuplicates(aArray, NS_ConvertASCIItoUTF16(values[i]));
|
|
|
|
}
|
|
|
|
InsertNoDuplicates(aArray, NS_LITERAL_STRING("symbols"));
|
2018-01-22 23:26:14 +03:00
|
|
|
}
|
2013-07-16 01:28:49 +04:00
|
|
|
}
|
|
|
|
|
Bug 895076 - domUtils.getCSSValuesForProperty now returns non keyword values. r=bz
This patch makes getCSSValuesForProperty return some none keyword values: auto,
normal, none, all, calc, -moz-calc, -moz-element, -moz-element-rect, rgb, hsl, -moz-rgba, -moz-hsla, rgba, hsla, cubic-bezer, and steps.
2013-07-19 18:32:52 +04:00
|
|
|
static void GetColorsForProperty(const uint32_t aParserVariant,
|
2013-07-16 01:28:49 +04:00
|
|
|
nsTArray<nsString>& aArray)
|
|
|
|
{
|
Bug 895076 - domUtils.getCSSValuesForProperty now returns non keyword values. r=bz
This patch makes getCSSValuesForProperty return some none keyword values: auto,
normal, none, all, calc, -moz-calc, -moz-element, -moz-element-rect, rgb, hsl, -moz-rgba, -moz-hsla, rgba, hsla, cubic-bezer, and steps.
2013-07-19 18:32:52 +04:00
|
|
|
if (aParserVariant & VARIANT_COLOR) {
|
2013-07-29 16:42:51 +04:00
|
|
|
// GetKeywordsForProperty and GetOtherValuesForProperty assume aArray is sorted,
|
|
|
|
// and if aArray is not empty here, then it's not going to be sorted coming out.
|
|
|
|
MOZ_ASSERT(aArray.Length() == 0);
|
2013-07-16 01:28:49 +04:00
|
|
|
size_t size;
|
|
|
|
const char * const *allColorNames = NS_AllColorNames(&size);
|
2016-05-20 04:48:59 +03:00
|
|
|
nsString* utf16Names = aArray.AppendElements(size);
|
2013-07-16 01:28:49 +04:00
|
|
|
for (size_t i = 0; i < size; i++) {
|
2016-05-20 04:48:59 +03:00
|
|
|
CopyASCIItoUTF16(allColorNames[i], utf16Names[i]);
|
2013-07-16 01:28:49 +04:00
|
|
|
}
|
2015-09-02 12:53:00 +03:00
|
|
|
InsertNoDuplicates(aArray, NS_LITERAL_STRING("currentColor"));
|
2013-07-16 01:28:49 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Bug 895076 - domUtils.getCSSValuesForProperty now returns non keyword values. r=bz
This patch makes getCSSValuesForProperty return some none keyword values: auto,
normal, none, all, calc, -moz-calc, -moz-element, -moz-element-rect, rgb, hsl, -moz-rgba, -moz-hsla, rgba, hsla, cubic-bezer, and steps.
2013-07-19 18:32:52 +04:00
|
|
|
static void GetOtherValuesForProperty(const uint32_t aParserVariant,
|
|
|
|
nsTArray<nsString>& aArray)
|
|
|
|
{
|
|
|
|
if (aParserVariant & VARIANT_AUTO) {
|
|
|
|
InsertNoDuplicates(aArray, NS_LITERAL_STRING("auto"));
|
|
|
|
}
|
|
|
|
if (aParserVariant & VARIANT_NORMAL) {
|
|
|
|
InsertNoDuplicates(aArray, NS_LITERAL_STRING("normal"));
|
|
|
|
}
|
|
|
|
if(aParserVariant & VARIANT_ALL) {
|
|
|
|
InsertNoDuplicates(aArray, NS_LITERAL_STRING("all"));
|
|
|
|
}
|
|
|
|
if (aParserVariant & VARIANT_NONE) {
|
|
|
|
InsertNoDuplicates(aArray, NS_LITERAL_STRING("none"));
|
|
|
|
}
|
|
|
|
if (aParserVariant & VARIANT_ELEMENT) {
|
|
|
|
InsertNoDuplicates(aArray, NS_LITERAL_STRING("-moz-element"));
|
|
|
|
}
|
|
|
|
if (aParserVariant & VARIANT_IMAGE_RECT) {
|
|
|
|
InsertNoDuplicates(aArray, NS_LITERAL_STRING("-moz-image-rect"));
|
|
|
|
}
|
|
|
|
if (aParserVariant & VARIANT_COLOR) {
|
|
|
|
InsertNoDuplicates(aArray, NS_LITERAL_STRING("rgb"));
|
|
|
|
InsertNoDuplicates(aArray, NS_LITERAL_STRING("hsl"));
|
|
|
|
InsertNoDuplicates(aArray, NS_LITERAL_STRING("rgba"));
|
|
|
|
InsertNoDuplicates(aArray, NS_LITERAL_STRING("hsla"));
|
|
|
|
}
|
|
|
|
if (aParserVariant & VARIANT_TIMING_FUNCTION) {
|
|
|
|
InsertNoDuplicates(aArray, NS_LITERAL_STRING("cubic-bezier"));
|
|
|
|
InsertNoDuplicates(aArray, NS_LITERAL_STRING("steps"));
|
|
|
|
}
|
|
|
|
if (aParserVariant & VARIANT_CALC) {
|
|
|
|
InsertNoDuplicates(aArray, NS_LITERAL_STRING("calc"));
|
|
|
|
}
|
2013-07-29 16:42:51 +04:00
|
|
|
if (aParserVariant & VARIANT_URL) {
|
|
|
|
InsertNoDuplicates(aArray, NS_LITERAL_STRING("url"));
|
|
|
|
}
|
2014-03-25 19:36:48 +04:00
|
|
|
if (aParserVariant & VARIANT_GRADIENT) {
|
|
|
|
InsertNoDuplicates(aArray, NS_LITERAL_STRING("linear-gradient"));
|
|
|
|
InsertNoDuplicates(aArray, NS_LITERAL_STRING("radial-gradient"));
|
|
|
|
InsertNoDuplicates(aArray, NS_LITERAL_STRING("repeating-linear-gradient"));
|
|
|
|
InsertNoDuplicates(aArray, NS_LITERAL_STRING("repeating-radial-gradient"));
|
2015-07-15 17:37:22 +03:00
|
|
|
InsertNoDuplicates(aArray, NS_LITERAL_STRING("-moz-linear-gradient"));
|
|
|
|
InsertNoDuplicates(aArray, NS_LITERAL_STRING("-moz-radial-gradient"));
|
|
|
|
InsertNoDuplicates(aArray, NS_LITERAL_STRING("-moz-repeating-linear-gradient"));
|
|
|
|
InsertNoDuplicates(aArray, NS_LITERAL_STRING("-moz-repeating-radial-gradient"));
|
2014-03-25 19:36:48 +04:00
|
|
|
}
|
2018-01-26 02:55:28 +03:00
|
|
|
if (aParserVariant & VARIANT_ATTR) {
|
|
|
|
InsertNoDuplicates(aArray, NS_LITERAL_STRING("attr"));
|
|
|
|
}
|
|
|
|
if (aParserVariant & VARIANT_COUNTER) {
|
|
|
|
InsertNoDuplicates(aArray, NS_LITERAL_STRING("counter"));
|
|
|
|
InsertNoDuplicates(aArray, NS_LITERAL_STRING("counters"));
|
|
|
|
}
|
Bug 895076 - domUtils.getCSSValuesForProperty now returns non keyword values. r=bz
This patch makes getCSSValuesForProperty return some none keyword values: auto,
normal, none, all, calc, -moz-calc, -moz-element, -moz-element-rect, rgb, hsl, -moz-rgba, -moz-hsla, rgba, hsla, cubic-bezer, and steps.
2013-07-19 18:32:52 +04:00
|
|
|
}
|
|
|
|
|
2018-01-11 07:38:00 +03:00
|
|
|
/* static */ void
|
|
|
|
InspectorUtils::GetSubpropertiesForCSSProperty(GlobalObject& aGlobal,
|
|
|
|
const nsAString& aProperty,
|
|
|
|
nsTArray<nsString>& aResult,
|
|
|
|
ErrorResult& aRv)
|
2014-05-06 19:46:34 +04:00
|
|
|
{
|
2016-08-10 02:28:19 +03:00
|
|
|
nsCSSPropertyID propertyID =
|
2016-05-10 11:44:05 +03:00
|
|
|
nsCSSProps::LookupProperty(aProperty, CSSEnabledState::eForAllContent);
|
2014-05-06 19:46:34 +04:00
|
|
|
|
2015-07-20 23:25:00 +03:00
|
|
|
if (propertyID == eCSSProperty_UNKNOWN) {
|
2018-01-11 07:38:00 +03:00
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return;
|
2014-05-06 19:46:34 +04:00
|
|
|
}
|
|
|
|
|
2015-07-20 23:25:00 +03:00
|
|
|
if (propertyID == eCSSPropertyExtra_variable) {
|
2018-01-11 07:38:00 +03:00
|
|
|
aResult.AppendElement(aProperty);
|
|
|
|
return;
|
2015-07-20 23:25:00 +03:00
|
|
|
}
|
|
|
|
|
2014-05-06 19:46:34 +04:00
|
|
|
if (!nsCSSProps::IsShorthand(propertyID)) {
|
2018-01-11 07:38:00 +03:00
|
|
|
nsString* name = aResult.AppendElement();
|
|
|
|
CopyASCIItoUTF16(nsCSSProps::GetStringValue(propertyID), *name);
|
|
|
|
return;
|
2014-05-06 19:46:34 +04:00
|
|
|
}
|
|
|
|
|
2018-01-11 07:38:00 +03:00
|
|
|
for (const nsCSSPropertyID* props = nsCSSProps::SubpropertyEntryFor(propertyID);
|
2014-05-06 19:46:34 +04:00
|
|
|
*props != eCSSProperty_UNKNOWN; ++props) {
|
2018-01-11 07:38:00 +03:00
|
|
|
nsString* name = aResult.AppendElement();
|
|
|
|
CopyASCIItoUTF16(nsCSSProps::GetStringValue(*props), *name);
|
2014-05-06 19:46:34 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-11 07:38:00 +03:00
|
|
|
/* static */ bool
|
|
|
|
InspectorUtils::CssPropertyIsShorthand(GlobalObject& aGlobalObject,
|
|
|
|
const nsAString& aProperty,
|
|
|
|
ErrorResult& aRv)
|
2014-05-06 19:46:34 +04:00
|
|
|
{
|
2016-08-10 02:28:19 +03:00
|
|
|
nsCSSPropertyID propertyID =
|
2016-05-10 11:44:05 +03:00
|
|
|
nsCSSProps::LookupProperty(aProperty, CSSEnabledState::eForAllContent);
|
2014-05-06 19:46:34 +04:00
|
|
|
if (propertyID == eCSSProperty_UNKNOWN) {
|
2018-01-11 07:38:00 +03:00
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return false;
|
2014-05-06 19:46:34 +04:00
|
|
|
}
|
|
|
|
|
2015-08-20 00:48:55 +03:00
|
|
|
if (propertyID == eCSSPropertyExtra_variable) {
|
2018-01-11 07:38:00 +03:00
|
|
|
return false;
|
2015-08-20 00:48:55 +03:00
|
|
|
}
|
2018-01-11 07:38:00 +03:00
|
|
|
|
|
|
|
return nsCSSProps::IsShorthand(propertyID);
|
2014-05-06 19:46:34 +04:00
|
|
|
}
|
|
|
|
|
2015-05-04 14:39:00 +03:00
|
|
|
// A helper function that determines whether the given property
|
|
|
|
// supports the given type.
|
|
|
|
static bool
|
2016-08-10 02:28:19 +03:00
|
|
|
PropertySupportsVariant(nsCSSPropertyID aPropertyID, uint32_t aVariant)
|
2015-05-04 14:39:00 +03:00
|
|
|
{
|
|
|
|
if (nsCSSProps::IsShorthand(aPropertyID)) {
|
|
|
|
// We need a special case for border here, because while it resets
|
|
|
|
// border-image, it can't actually parse an image.
|
|
|
|
if (aPropertyID == eCSSProperty_border) {
|
|
|
|
return (aVariant & (VARIANT_COLOR | VARIANT_LENGTH)) != 0;
|
|
|
|
}
|
|
|
|
|
2016-08-10 02:28:19 +03:00
|
|
|
for (const nsCSSPropertyID* props = nsCSSProps::SubpropertyEntryFor(aPropertyID);
|
2015-05-04 14:39:00 +03:00
|
|
|
*props != eCSSProperty_UNKNOWN; ++props) {
|
|
|
|
if (PropertySupportsVariant(*props, aVariant)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-01-17 20:34:34 +03:00
|
|
|
uint32_t supported = nsCSSProps::ParserVariant(aPropertyID);
|
|
|
|
|
|
|
|
// For the time being, properties that are parsed by functions must
|
|
|
|
// have some of their attributes hand-maintained here.
|
2015-05-04 14:39:00 +03:00
|
|
|
if (nsCSSProps::PropHasFlags(aPropertyID, CSS_PROPERTY_VALUE_PARSER_FUNCTION) ||
|
|
|
|
nsCSSProps::PropertyParseType(aPropertyID) == CSS_PROPERTY_PARSE_FUNCTION) {
|
|
|
|
// These must all be special-cased.
|
|
|
|
switch (aPropertyID) {
|
|
|
|
case eCSSProperty_border_image_slice:
|
2016-04-21 17:18:34 +03:00
|
|
|
case eCSSProperty_grid_template:
|
2015-05-04 14:39:00 +03:00
|
|
|
case eCSSProperty_grid:
|
2018-01-17 20:34:34 +03:00
|
|
|
supported |= VARIANT_PN;
|
2015-05-04 14:39:00 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case eCSSProperty_border_image_outset:
|
2018-01-17 20:34:34 +03:00
|
|
|
supported |= VARIANT_LN;
|
2015-05-04 14:39:00 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case eCSSProperty_border_image_width:
|
|
|
|
case eCSSProperty_stroke_dasharray:
|
2018-01-17 20:34:34 +03:00
|
|
|
supported |= VARIANT_LPN;
|
2015-05-04 14:39:00 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case eCSSProperty_border_top_left_radius:
|
|
|
|
case eCSSProperty_border_top_right_radius:
|
|
|
|
case eCSSProperty_border_bottom_left_radius:
|
|
|
|
case eCSSProperty_border_bottom_right_radius:
|
|
|
|
case eCSSProperty_background_position:
|
2016-04-22 03:22:46 +03:00
|
|
|
case eCSSProperty_background_position_x:
|
|
|
|
case eCSSProperty_background_position_y:
|
2015-05-04 14:39:00 +03:00
|
|
|
case eCSSProperty_background_size:
|
2016-01-28 08:28:00 +03:00
|
|
|
case eCSSProperty_mask_position:
|
2016-04-22 03:22:46 +03:00
|
|
|
case eCSSProperty_mask_position_x:
|
|
|
|
case eCSSProperty_mask_position_y:
|
2016-01-28 08:28:00 +03:00
|
|
|
case eCSSProperty_mask_size:
|
2015-05-04 14:39:00 +03:00
|
|
|
case eCSSProperty_grid_auto_columns:
|
|
|
|
case eCSSProperty_grid_auto_rows:
|
|
|
|
case eCSSProperty_grid_template_columns:
|
|
|
|
case eCSSProperty_grid_template_rows:
|
|
|
|
case eCSSProperty_object_position:
|
|
|
|
case eCSSProperty_scroll_snap_coordinate:
|
|
|
|
case eCSSProperty_scroll_snap_destination:
|
|
|
|
case eCSSProperty_transform_origin:
|
2018-01-25 03:18:44 +03:00
|
|
|
case eCSSProperty_translate:
|
2015-05-04 14:39:00 +03:00
|
|
|
case eCSSProperty_perspective_origin:
|
2016-12-21 10:16:50 +03:00
|
|
|
case eCSSProperty__moz_outline_radius_topleft:
|
|
|
|
case eCSSProperty__moz_outline_radius_topright:
|
|
|
|
case eCSSProperty__moz_outline_radius_bottomleft:
|
|
|
|
case eCSSProperty__moz_outline_radius_bottomright:
|
2017-06-19 08:44:22 +03:00
|
|
|
case eCSSProperty__moz_window_transform_origin:
|
2018-01-17 20:34:34 +03:00
|
|
|
supported |= VARIANT_LP;
|
2015-05-04 14:39:00 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case eCSSProperty_text_shadow:
|
|
|
|
case eCSSProperty_box_shadow:
|
2018-01-17 20:34:34 +03:00
|
|
|
supported |= VARIANT_LENGTH | VARIANT_COLOR;
|
2015-05-04 14:39:00 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case eCSSProperty_border_spacing:
|
2018-01-17 20:34:34 +03:00
|
|
|
supported |= VARIANT_LENGTH;
|
2015-05-04 14:39:00 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case eCSSProperty_cursor:
|
2018-01-17 20:34:34 +03:00
|
|
|
supported |= VARIANT_URL;
|
2017-11-17 11:34:37 +03:00
|
|
|
break;
|
|
|
|
|
2017-11-17 11:34:37 +03:00
|
|
|
case eCSSProperty_shape_outside:
|
2018-01-17 20:34:34 +03:00
|
|
|
supported |= VARIANT_IMAGE;
|
2017-11-17 11:34:37 +03:00
|
|
|
break;
|
|
|
|
|
2015-05-04 14:39:00 +03:00
|
|
|
case eCSSProperty_fill:
|
|
|
|
case eCSSProperty_stroke:
|
2018-01-17 20:34:34 +03:00
|
|
|
supported |= VARIANT_COLOR | VARIANT_URL;
|
2015-05-04 14:39:00 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case eCSSProperty_image_orientation:
|
2018-01-25 03:18:44 +03:00
|
|
|
case eCSSProperty_rotate:
|
2018-01-17 20:34:34 +03:00
|
|
|
supported |= VARIANT_ANGLE;
|
2015-05-04 14:39:00 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case eCSSProperty_filter:
|
2018-01-17 20:34:34 +03:00
|
|
|
supported |= VARIANT_URL;
|
2015-05-04 14:39:00 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case eCSSProperty_grid_column_start:
|
|
|
|
case eCSSProperty_grid_column_end:
|
|
|
|
case eCSSProperty_grid_row_start:
|
|
|
|
case eCSSProperty_grid_row_end:
|
|
|
|
case eCSSProperty_font_weight:
|
2016-07-28 10:23:36 +03:00
|
|
|
case eCSSProperty_initial_letter:
|
2018-01-25 03:18:44 +03:00
|
|
|
case eCSSProperty_scale:
|
2018-01-17 20:34:34 +03:00
|
|
|
supported |= VARIANT_NUMBER;
|
2015-05-04 14:39:00 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-17 20:34:34 +03:00
|
|
|
return (supported & aVariant) != 0;
|
2015-05-04 14:39:00 +03:00
|
|
|
}
|
|
|
|
|
2018-01-11 07:38:00 +03:00
|
|
|
bool
|
|
|
|
InspectorUtils::CssPropertySupportsType(GlobalObject& aGlobalObject,
|
|
|
|
const nsAString& aProperty,
|
|
|
|
uint32_t aType,
|
|
|
|
ErrorResult& aRv)
|
2014-05-06 19:46:34 +04:00
|
|
|
{
|
2016-08-10 02:28:19 +03:00
|
|
|
nsCSSPropertyID propertyID =
|
2016-05-10 11:44:05 +03:00
|
|
|
nsCSSProps::LookupProperty(aProperty, CSSEnabledState::eForAllContent);
|
2014-05-06 19:46:34 +04:00
|
|
|
if (propertyID == eCSSProperty_UNKNOWN) {
|
2018-01-11 07:38:00 +03:00
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return false;
|
2014-05-06 19:46:34 +04:00
|
|
|
}
|
|
|
|
|
2015-05-04 14:39:00 +03:00
|
|
|
if (propertyID >= eCSSProperty_COUNT) {
|
2018-01-11 07:38:00 +03:00
|
|
|
return false;
|
2015-05-04 14:39:00 +03:00
|
|
|
}
|
|
|
|
|
2014-05-06 19:46:34 +04:00
|
|
|
uint32_t variant;
|
|
|
|
switch (aType) {
|
2018-01-11 07:38:00 +03:00
|
|
|
case InspectorUtilsBinding::TYPE_LENGTH:
|
2014-05-06 19:46:34 +04:00
|
|
|
variant = VARIANT_LENGTH;
|
|
|
|
break;
|
2018-01-11 07:38:00 +03:00
|
|
|
case InspectorUtilsBinding::TYPE_PERCENTAGE:
|
2014-05-06 19:46:34 +04:00
|
|
|
variant = VARIANT_PERCENT;
|
|
|
|
break;
|
2018-01-11 07:38:00 +03:00
|
|
|
case InspectorUtilsBinding::TYPE_COLOR:
|
2014-05-06 19:46:34 +04:00
|
|
|
variant = VARIANT_COLOR;
|
|
|
|
break;
|
2018-01-11 07:38:00 +03:00
|
|
|
case InspectorUtilsBinding::TYPE_URL:
|
2014-05-06 19:46:34 +04:00
|
|
|
variant = VARIANT_URL;
|
|
|
|
break;
|
2018-01-11 07:38:00 +03:00
|
|
|
case InspectorUtilsBinding::TYPE_ANGLE:
|
2014-05-06 19:46:34 +04:00
|
|
|
variant = VARIANT_ANGLE;
|
|
|
|
break;
|
2018-01-11 07:38:00 +03:00
|
|
|
case InspectorUtilsBinding::TYPE_FREQUENCY:
|
2014-05-06 19:46:34 +04:00
|
|
|
variant = VARIANT_FREQUENCY;
|
|
|
|
break;
|
2018-01-11 07:38:00 +03:00
|
|
|
case InspectorUtilsBinding::TYPE_TIME:
|
2014-05-06 19:46:34 +04:00
|
|
|
variant = VARIANT_TIME;
|
|
|
|
break;
|
2018-01-11 07:38:00 +03:00
|
|
|
case InspectorUtilsBinding::TYPE_GRADIENT:
|
2014-05-06 19:46:34 +04:00
|
|
|
variant = VARIANT_GRADIENT;
|
|
|
|
break;
|
2018-01-11 07:38:00 +03:00
|
|
|
case InspectorUtilsBinding::TYPE_TIMING_FUNCTION:
|
2014-05-06 19:46:34 +04:00
|
|
|
variant = VARIANT_TIMING_FUNCTION;
|
|
|
|
break;
|
2018-01-11 07:38:00 +03:00
|
|
|
case InspectorUtilsBinding::TYPE_IMAGE_RECT:
|
2014-05-06 19:46:34 +04:00
|
|
|
variant = VARIANT_IMAGE_RECT;
|
|
|
|
break;
|
2018-01-11 07:38:00 +03:00
|
|
|
case InspectorUtilsBinding::TYPE_NUMBER:
|
2014-05-06 19:46:34 +04:00
|
|
|
// Include integers under "number"?
|
|
|
|
variant = VARIANT_NUMBER | VARIANT_INTEGER;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
// Unknown type
|
2018-01-11 07:38:00 +03:00
|
|
|
aRv.Throw(NS_ERROR_NOT_AVAILABLE);
|
|
|
|
return false;
|
2014-05-06 19:46:34 +04:00
|
|
|
}
|
|
|
|
|
2018-01-11 07:38:00 +03:00
|
|
|
return PropertySupportsVariant(propertyID, variant);
|
2014-05-06 19:46:34 +04:00
|
|
|
}
|
|
|
|
|
2018-01-11 07:38:00 +03:00
|
|
|
/* static */ void
|
|
|
|
InspectorUtils::GetCSSValuesForProperty(GlobalObject& aGlobalObject,
|
|
|
|
const nsAString& aProperty,
|
|
|
|
nsTArray<nsString>& aResult,
|
|
|
|
ErrorResult& aRv)
|
2013-07-16 01:28:49 +04:00
|
|
|
{
|
2016-08-10 02:28:19 +03:00
|
|
|
nsCSSPropertyID propertyID = nsCSSProps::
|
2016-05-10 11:44:05 +03:00
|
|
|
LookupProperty(aProperty, CSSEnabledState::eForAllContent);
|
2013-07-16 01:28:49 +04:00
|
|
|
if (propertyID == eCSSProperty_UNKNOWN) {
|
2018-01-11 07:38:00 +03:00
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return;
|
2013-07-16 01:28:49 +04:00
|
|
|
}
|
|
|
|
|
2018-01-11 07:38:00 +03:00
|
|
|
// We start collecting the values, BUT colors need to go in first, because aResult
|
Bug 895076 - domUtils.getCSSValuesForProperty now returns non keyword values. r=bz
This patch makes getCSSValuesForProperty return some none keyword values: auto,
normal, none, all, calc, -moz-calc, -moz-element, -moz-element-rect, rgb, hsl, -moz-rgba, -moz-hsla, rgba, hsla, cubic-bezer, and steps.
2013-07-19 18:32:52 +04:00
|
|
|
// needs to stay sorted, and the colors are sorted, so we just append them.
|
2013-12-12 06:09:47 +04:00
|
|
|
if (propertyID == eCSSPropertyExtra_variable) {
|
|
|
|
// No other values we can report.
|
|
|
|
} else if (!nsCSSProps::IsShorthand(propertyID)) {
|
2013-07-16 01:28:49 +04:00
|
|
|
// Property is longhand.
|
Bug 895076 - domUtils.getCSSValuesForProperty now returns non keyword values. r=bz
This patch makes getCSSValuesForProperty return some none keyword values: auto,
normal, none, all, calc, -moz-calc, -moz-element, -moz-element-rect, rgb, hsl, -moz-rgba, -moz-hsla, rgba, hsla, cubic-bezer, and steps.
2013-07-19 18:32:52 +04:00
|
|
|
uint32_t propertyParserVariant = nsCSSProps::ParserVariant(propertyID);
|
|
|
|
// Get colors first.
|
2018-01-11 07:38:00 +03:00
|
|
|
GetColorsForProperty(propertyParserVariant, aResult);
|
|
|
|
GetKeywordsForProperty(propertyID, aResult);
|
|
|
|
GetOtherValuesForProperty(propertyParserVariant, aResult);
|
2018-01-10 21:48:28 +03:00
|
|
|
} else if (propertyID == eCSSProperty_all) {
|
|
|
|
// We don't want to pick up everything from gAllSubpropTable, so
|
|
|
|
// special-case this here.
|
2013-07-16 01:28:49 +04:00
|
|
|
} else {
|
|
|
|
// Property is shorthand.
|
2015-01-17 07:55:07 +03:00
|
|
|
CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(subproperty, propertyID,
|
2016-05-10 11:44:05 +03:00
|
|
|
CSSEnabledState::eForAllContent) {
|
2013-07-29 16:42:51 +04:00
|
|
|
// Get colors (once) first.
|
|
|
|
uint32_t propertyParserVariant = nsCSSProps::ParserVariant(*subproperty);
|
|
|
|
if (propertyParserVariant & VARIANT_COLOR) {
|
2018-01-11 07:38:00 +03:00
|
|
|
GetColorsForProperty(propertyParserVariant, aResult);
|
2013-07-29 16:42:51 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2015-01-17 07:55:07 +03:00
|
|
|
CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(subproperty, propertyID,
|
2016-05-10 11:44:05 +03:00
|
|
|
CSSEnabledState::eForAllContent) {
|
Bug 895076 - domUtils.getCSSValuesForProperty now returns non keyword values. r=bz
This patch makes getCSSValuesForProperty return some none keyword values: auto,
normal, none, all, calc, -moz-calc, -moz-element, -moz-element-rect, rgb, hsl, -moz-rgba, -moz-hsla, rgba, hsla, cubic-bezer, and steps.
2013-07-19 18:32:52 +04:00
|
|
|
uint32_t propertyParserVariant = nsCSSProps::ParserVariant(*subproperty);
|
2018-01-11 07:38:00 +03:00
|
|
|
GetKeywordsForProperty(*subproperty, aResult);
|
|
|
|
GetOtherValuesForProperty(propertyParserVariant, aResult);
|
2013-07-16 01:28:49 +04:00
|
|
|
}
|
|
|
|
}
|
2013-10-10 04:47:40 +04:00
|
|
|
// All CSS properties take initial, inherit and unset.
|
2018-01-11 07:38:00 +03:00
|
|
|
InsertNoDuplicates(aResult, NS_LITERAL_STRING("initial"));
|
|
|
|
InsertNoDuplicates(aResult, NS_LITERAL_STRING("inherit"));
|
|
|
|
InsertNoDuplicates(aResult, NS_LITERAL_STRING("unset"));
|
2013-07-16 01:28:49 +04:00
|
|
|
}
|
|
|
|
|
2018-01-11 07:38:00 +03:00
|
|
|
/* static */ void
|
|
|
|
InspectorUtils::RgbToColorName(GlobalObject& aGlobalObject,
|
|
|
|
uint8_t aR, uint8_t aG, uint8_t aB,
|
|
|
|
nsAString& aColorName,
|
|
|
|
ErrorResult& aRv)
|
2013-03-14 23:43:00 +04:00
|
|
|
{
|
|
|
|
const char* color = NS_RGBToColorName(NS_RGB(aR, aG, aB));
|
|
|
|
if (!color) {
|
|
|
|
aColorName.Truncate();
|
2018-01-11 07:38:00 +03:00
|
|
|
aRv.Throw(NS_ERROR_INVALID_ARG);
|
|
|
|
return;
|
2013-03-14 23:43:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
aColorName.AssignASCII(color);
|
|
|
|
}
|
|
|
|
|
2018-01-11 07:38:00 +03:00
|
|
|
/* static */ void
|
|
|
|
InspectorUtils::ColorToRGBA(GlobalObject& aGlobalObject,
|
|
|
|
const nsAString& aColorString,
|
|
|
|
Nullable<InspectorRGBATuple>& aResult)
|
2014-07-17 18:08:07 +04:00
|
|
|
{
|
2017-10-16 04:06:39 +03:00
|
|
|
nscolor color = NS_RGB(0, 0, 0);
|
|
|
|
|
|
|
|
#ifdef MOZ_STYLO
|
|
|
|
if (!ServoCSSParser::ComputeColor(nullptr, NS_RGB(0, 0, 0), aColorString,
|
|
|
|
&color)) {
|
2018-01-11 07:38:00 +03:00
|
|
|
aResult.SetNull();
|
|
|
|
return;
|
2017-10-16 04:06:39 +03:00
|
|
|
}
|
|
|
|
#else
|
2014-07-17 18:08:07 +04:00
|
|
|
nsCSSParser cssParser;
|
|
|
|
nsCSSValue cssValue;
|
|
|
|
|
2017-10-16 04:06:39 +03:00
|
|
|
if (!cssParser.ParseColorString(aColorString, nullptr, 0, cssValue, true)) {
|
2018-01-11 07:38:00 +03:00
|
|
|
aResult.SetNull();
|
|
|
|
return;
|
2014-07-17 18:08:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsRuleNode::ComputeColor(cssValue, nullptr, nullptr, color);
|
2017-10-16 04:06:39 +03:00
|
|
|
#endif
|
2014-07-17 18:08:07 +04:00
|
|
|
|
2018-01-11 07:38:00 +03:00
|
|
|
InspectorRGBATuple& tuple = aResult.SetValue();
|
2014-07-17 18:08:07 +04:00
|
|
|
tuple.mR = NS_GET_R(color);
|
|
|
|
tuple.mG = NS_GET_G(color);
|
|
|
|
tuple.mB = NS_GET_B(color);
|
|
|
|
tuple.mA = nsStyleUtil::ColorComponentToFloat(NS_GET_A(color));
|
|
|
|
}
|
|
|
|
|
2018-01-11 07:38:00 +03:00
|
|
|
/* static */ bool
|
|
|
|
InspectorUtils::IsValidCSSColor(GlobalObject& aGlobalObject,
|
|
|
|
const nsAString& aColorString)
|
2014-07-17 18:08:07 +04:00
|
|
|
{
|
2017-10-16 04:02:35 +03:00
|
|
|
#ifdef MOZ_STYLO
|
2018-01-11 07:38:00 +03:00
|
|
|
return ServoCSSParser::IsValidCSSColor(aColorString);
|
2017-10-16 04:02:35 +03:00
|
|
|
#else
|
2014-07-17 18:08:07 +04:00
|
|
|
nsCSSParser cssParser;
|
|
|
|
nsCSSValue cssValue;
|
2018-01-11 07:38:00 +03:00
|
|
|
return cssParser.ParseColorString(aColorString, nullptr, 0, cssValue, true);
|
2017-10-16 04:02:35 +03:00
|
|
|
#endif
|
2014-07-17 18:08:07 +04:00
|
|
|
}
|
|
|
|
|
2018-01-11 07:38:01 +03:00
|
|
|
void
|
|
|
|
InspectorUtils::GetBindingURLs(GlobalObject& aGlobalObject,
|
|
|
|
Element& aElement,
|
|
|
|
nsTArray<nsString>& aResult)
|
2006-05-17 06:21:53 +04:00
|
|
|
{
|
2018-01-11 07:38:01 +03:00
|
|
|
nsXBLBinding* binding = aElement.GetXBLBinding();
|
2009-08-11 02:52:29 +04:00
|
|
|
|
2011-10-18 15:19:44 +04:00
|
|
|
while (binding) {
|
2018-01-11 07:38:01 +03:00
|
|
|
nsCString spec;
|
|
|
|
nsCOMPtr<nsIURI> bindingURI = binding->PrototypeBinding()->BindingURI();
|
|
|
|
bindingURI->GetSpec(spec);
|
|
|
|
nsString* resultURI = aResult.AppendElement();
|
|
|
|
CopyASCIItoUTF16(spec, *resultURI);
|
2011-10-18 15:19:44 +04:00
|
|
|
binding = binding->GetBaseBinding();
|
2009-08-11 02:52:29 +04:00
|
|
|
}
|
2006-05-17 06:21:53 +04:00
|
|
|
}
|
|
|
|
|
2018-01-11 07:38:01 +03:00
|
|
|
/* static */ bool
|
|
|
|
InspectorUtils::SetContentState(GlobalObject& aGlobalObject,
|
|
|
|
Element& aElement,
|
|
|
|
uint64_t aState,
|
|
|
|
ErrorResult& aRv)
|
2006-05-17 06:21:53 +04:00
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<EventStateManager> esm =
|
2014-04-01 08:09:23 +04:00
|
|
|
inLayoutUtils::GetEventStateManagerFor(aElement);
|
2018-01-11 07:38:01 +03:00
|
|
|
if (!esm) {
|
|
|
|
aRv.Throw(NS_ERROR_INVALID_ARG);
|
|
|
|
return false;
|
|
|
|
}
|
2016-03-30 12:54:27 +03:00
|
|
|
|
2018-01-11 07:38:01 +03:00
|
|
|
return esm->SetContentState(&aElement, EventStates(aState));
|
2016-03-30 12:54:27 +03:00
|
|
|
}
|
|
|
|
|
2018-01-11 07:38:01 +03:00
|
|
|
/* static */ bool
|
|
|
|
InspectorUtils::RemoveContentState(GlobalObject& aGlobalObject,
|
|
|
|
Element& aElement,
|
|
|
|
uint64_t aState,
|
|
|
|
bool aClearActiveDocument,
|
|
|
|
ErrorResult& aRv)
|
2016-03-30 12:54:27 +03:00
|
|
|
{
|
|
|
|
RefPtr<EventStateManager> esm =
|
|
|
|
inLayoutUtils::GetEventStateManagerFor(aElement);
|
2018-01-11 07:38:01 +03:00
|
|
|
if (!esm) {
|
|
|
|
aRv.Throw(NS_ERROR_INVALID_ARG);
|
|
|
|
return false;
|
|
|
|
}
|
2012-05-09 20:23:57 +04:00
|
|
|
|
2018-01-11 07:38:01 +03:00
|
|
|
bool result = esm->SetContentState(nullptr, EventStates(aState));
|
2017-06-14 08:42:03 +03:00
|
|
|
|
|
|
|
if (aClearActiveDocument && EventStates(aState) == NS_EVENT_STATE_ACTIVE) {
|
|
|
|
EventStateManager* activeESM = static_cast<EventStateManager*>(
|
|
|
|
EventStateManager::GetActiveEventStateManager());
|
|
|
|
if (activeESM == esm) {
|
|
|
|
EventStateManager::ClearGlobalActiveContent(nullptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-11 07:38:01 +03:00
|
|
|
return result;
|
2006-05-17 06:21:53 +04:00
|
|
|
}
|
|
|
|
|
2018-01-11 07:38:01 +03:00
|
|
|
/* static */ uint64_t
|
|
|
|
InspectorUtils::GetContentState(GlobalObject& aGlobalObject,
|
|
|
|
Element& aElement)
|
2006-05-17 06:21:53 +04:00
|
|
|
{
|
2011-06-01 05:46:56 +04:00
|
|
|
// NOTE: if this method is removed,
|
2014-04-03 08:18:36 +04:00
|
|
|
// please remove GetInternalValue from EventStates
|
2018-01-11 07:38:01 +03:00
|
|
|
return aElement.State().GetInternalValue();
|
2006-05-17 06:21:53 +04:00
|
|
|
}
|
|
|
|
|
2017-03-14 03:23:17 +03:00
|
|
|
/* static */ already_AddRefed<nsStyleContext>
|
2018-01-11 07:37:59 +03:00
|
|
|
InspectorUtils::GetCleanStyleContextForElement(dom::Element* aElement,
|
|
|
|
nsAtom* aPseudo)
|
2009-08-11 02:52:29 +04:00
|
|
|
{
|
2013-11-11 12:00:41 +04:00
|
|
|
MOZ_ASSERT(aElement);
|
|
|
|
|
2014-08-23 00:11:27 +04:00
|
|
|
nsIDocument* doc = aElement->GetComposedDoc();
|
2017-03-14 03:23:17 +03:00
|
|
|
if (!doc) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2009-08-11 02:52:29 +04:00
|
|
|
|
2010-06-25 17:59:57 +04:00
|
|
|
nsIPresShell *presShell = doc->GetShell();
|
2017-03-14 03:23:17 +03:00
|
|
|
if (!presShell) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2009-08-11 02:52:29 +04:00
|
|
|
|
2009-12-31 18:56:33 +03:00
|
|
|
nsPresContext *presContext = presShell->GetPresContext();
|
2017-03-14 03:23:17 +03:00
|
|
|
if (!presContext) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2009-12-31 18:56:33 +03:00
|
|
|
|
2013-11-11 12:00:33 +04:00
|
|
|
presContext->EnsureSafeToHandOutCSSRules();
|
2009-12-31 18:56:33 +03:00
|
|
|
|
2017-03-14 03:23:17 +03:00
|
|
|
RefPtr<nsStyleContext> styleContext =
|
2017-04-05 08:39:23 +03:00
|
|
|
nsComputedDOMStyle::GetStyleContext(aElement, aPseudo, presShell);
|
2017-03-14 03:23:17 +03:00
|
|
|
return styleContext.forget();
|
2009-08-11 02:52:29 +04:00
|
|
|
}
|
2011-06-16 10:31:36 +04:00
|
|
|
|
2018-01-11 07:38:01 +03:00
|
|
|
/* static */ void
|
|
|
|
InspectorUtils::GetUsedFontFaces(GlobalObject& aGlobalObject,
|
|
|
|
nsRange& aRange,
|
|
|
|
nsTArray<nsAutoPtr<InspectorFontFace>>& aResult,
|
|
|
|
ErrorResult& aRv)
|
2011-06-16 10:31:36 +04:00
|
|
|
{
|
2018-01-11 07:38:01 +03:00
|
|
|
nsresult rv = aRange.GetUsedFontFaces(aResult);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
}
|
2011-06-16 10:31:36 +04:00
|
|
|
}
|
2012-02-08 22:42:38 +04:00
|
|
|
|
2014-04-03 08:18:36 +04:00
|
|
|
static EventStates
|
2012-02-08 22:42:38 +04:00
|
|
|
GetStatesForPseudoClass(const nsAString& aStatePseudo)
|
|
|
|
{
|
|
|
|
// An array of the states that are relevant for various pseudoclasses.
|
|
|
|
// XXXbz this duplicates code in nsCSSRuleProcessor
|
2014-04-03 08:18:36 +04:00
|
|
|
static const EventStates sPseudoClassStates[] = {
|
2014-10-23 20:57:27 +04:00
|
|
|
#define CSS_PSEUDO_CLASS(_name, _value, _flags, _pref) \
|
2014-04-03 08:18:36 +04:00
|
|
|
EventStates(),
|
2014-10-23 20:57:27 +04:00
|
|
|
#define CSS_STATE_PSEUDO_CLASS(_name, _value, _flags, _pref, _states) \
|
2012-02-08 22:42:38 +04:00
|
|
|
_states,
|
|
|
|
#include "nsCSSPseudoClassList.h"
|
|
|
|
#undef CSS_STATE_PSEUDO_CLASS
|
|
|
|
#undef CSS_PSEUDO_CLASS
|
|
|
|
|
|
|
|
// Add more entries for our fake values to make sure we can't
|
|
|
|
// index out of bounds into this array no matter what.
|
2014-04-03 08:18:36 +04:00
|
|
|
EventStates(),
|
|
|
|
EventStates()
|
2012-02-08 22:42:38 +04:00
|
|
|
};
|
2014-01-30 22:26:54 +04:00
|
|
|
static_assert(MOZ_ARRAY_LENGTH(sPseudoClassStates) ==
|
2016-04-22 17:18:21 +03:00
|
|
|
static_cast<size_t>(CSSPseudoClassType::MAX),
|
2013-07-18 21:59:53 +04:00
|
|
|
"Length of PseudoClassStates array is incorrect");
|
2012-02-08 22:42:38 +04:00
|
|
|
|
2017-10-03 01:05:19 +03:00
|
|
|
RefPtr<nsAtom> atom = NS_Atomize(aStatePseudo);
|
2016-05-10 11:44:05 +03:00
|
|
|
CSSPseudoClassType type = nsCSSPseudoClasses::
|
|
|
|
GetPseudoType(atom, CSSEnabledState::eIgnoreEnabledState);
|
2012-02-08 22:42:38 +04:00
|
|
|
|
2016-07-20 06:13:13 +03:00
|
|
|
// Ignore :any-link so we don't give the element simultaneous
|
2012-02-08 22:42:38 +04:00
|
|
|
// visited and unvisited style state
|
2016-07-20 06:13:13 +03:00
|
|
|
if (type == CSSPseudoClassType::anyLink ||
|
|
|
|
type == CSSPseudoClassType::mozAnyLink) {
|
2014-04-03 08:18:36 +04:00
|
|
|
return EventStates();
|
2012-02-08 22:42:38 +04:00
|
|
|
}
|
|
|
|
// Our array above is long enough that indexing into it with
|
2016-04-22 15:40:45 +03:00
|
|
|
// NotPseudo is ok.
|
|
|
|
return sPseudoClassStates[static_cast<CSSPseudoClassTypeBase>(type)];
|
2012-02-08 22:42:38 +04:00
|
|
|
}
|
|
|
|
|
2018-01-11 07:38:01 +03:00
|
|
|
/* static */ void
|
|
|
|
InspectorUtils::GetCSSPseudoElementNames(GlobalObject& aGlobalObject,
|
|
|
|
nsTArray<nsString>& aResult)
|
|
|
|
{
|
2016-02-18 21:18:00 +03:00
|
|
|
const CSSPseudoElementTypeBase pseudoCount =
|
|
|
|
static_cast<CSSPseudoElementTypeBase>(CSSPseudoElementType::Count);
|
|
|
|
for (CSSPseudoElementTypeBase i = 0; i < pseudoCount; ++i) {
|
2016-02-17 23:37:00 +03:00
|
|
|
CSSPseudoElementType type = static_cast<CSSPseudoElementType>(i);
|
2016-05-10 11:44:05 +03:00
|
|
|
if (nsCSSPseudoElements::IsEnabled(type, CSSEnabledState::eForAllContent)) {
|
2017-10-03 01:05:19 +03:00
|
|
|
nsAtom* atom = nsCSSPseudoElements::GetPseudoAtom(type);
|
2018-01-11 07:38:01 +03:00
|
|
|
aResult.AppendElement(nsDependentAtomString(atom));
|
2015-11-02 18:55:26 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-11 07:38:01 +03:00
|
|
|
/* static */ void
|
|
|
|
InspectorUtils::AddPseudoClassLock(GlobalObject& aGlobalObject,
|
|
|
|
Element& aElement,
|
|
|
|
const nsAString& aPseudoClass,
|
|
|
|
bool aEnabled)
|
2012-02-08 22:42:38 +04:00
|
|
|
{
|
2014-04-03 08:18:36 +04:00
|
|
|
EventStates state = GetStatesForPseudoClass(aPseudoClass);
|
2012-02-08 22:42:38 +04:00
|
|
|
if (state.IsEmpty()) {
|
2018-01-11 07:38:01 +03:00
|
|
|
return;
|
2012-02-08 22:42:38 +04:00
|
|
|
}
|
|
|
|
|
2018-01-11 07:38:01 +03:00
|
|
|
aElement.LockStyleStates(state, aEnabled);
|
2012-02-08 22:42:38 +04:00
|
|
|
}
|
|
|
|
|
2018-01-11 07:38:01 +03:00
|
|
|
/* static */ void
|
|
|
|
InspectorUtils::RemovePseudoClassLock(GlobalObject& aGlobal,
|
|
|
|
Element& aElement,
|
|
|
|
const nsAString& aPseudoClass)
|
2012-02-08 22:42:38 +04:00
|
|
|
{
|
2014-04-03 08:18:36 +04:00
|
|
|
EventStates state = GetStatesForPseudoClass(aPseudoClass);
|
2012-02-08 22:42:38 +04:00
|
|
|
if (state.IsEmpty()) {
|
2018-01-11 07:38:01 +03:00
|
|
|
return;
|
2012-02-08 22:42:38 +04:00
|
|
|
}
|
|
|
|
|
2018-01-11 07:38:01 +03:00
|
|
|
aElement.UnlockStyleStates(state);
|
2012-02-08 22:42:38 +04:00
|
|
|
}
|
|
|
|
|
2018-01-11 07:38:01 +03:00
|
|
|
/* static */ bool
|
|
|
|
InspectorUtils::HasPseudoClassLock(GlobalObject& aGlobalObject,
|
|
|
|
Element& aElement,
|
|
|
|
const nsAString& aPseudoClass)
|
2012-02-08 22:42:38 +04:00
|
|
|
{
|
2014-04-03 08:18:36 +04:00
|
|
|
EventStates state = GetStatesForPseudoClass(aPseudoClass);
|
2012-02-08 22:42:38 +04:00
|
|
|
if (state.IsEmpty()) {
|
2018-01-11 07:38:01 +03:00
|
|
|
return false;
|
2012-02-08 22:42:38 +04:00
|
|
|
}
|
|
|
|
|
2018-01-11 07:38:01 +03:00
|
|
|
EventStates locks = aElement.LockedStyleStates().mLocks;
|
|
|
|
return locks.HasAllStates(state);
|
2012-02-08 22:42:38 +04:00
|
|
|
}
|
|
|
|
|
2018-01-11 07:38:01 +03:00
|
|
|
/* static */ void
|
|
|
|
InspectorUtils::ClearPseudoClassLocks(GlobalObject& aGlobalObject,
|
|
|
|
Element& aElement)
|
2012-02-08 22:42:38 +04:00
|
|
|
{
|
2018-01-11 07:38:01 +03:00
|
|
|
aElement.ClearStyleStateLocks();
|
2012-02-08 22:42:38 +04:00
|
|
|
}
|
2012-06-03 20:54:38 +04:00
|
|
|
|
2018-01-11 07:38:01 +03:00
|
|
|
/* static */ void
|
|
|
|
InspectorUtils::ParseStyleSheet(GlobalObject& aGlobalObject,
|
|
|
|
StyleSheet& aSheet,
|
|
|
|
const nsAString& aInput,
|
|
|
|
ErrorResult& aRv)
|
2012-06-03 20:54:38 +04:00
|
|
|
{
|
2018-02-01 07:04:04 +03:00
|
|
|
#ifdef MOZ_OLD_STYLE
|
2018-01-11 07:38:01 +03:00
|
|
|
RefPtr<CSSStyleSheet> geckoSheet = do_QueryObject(&aSheet);
|
2017-05-25 05:55:57 +03:00
|
|
|
if (geckoSheet) {
|
2018-01-11 07:38:01 +03:00
|
|
|
nsresult rv = geckoSheet->ReparseSheet(aInput);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
}
|
|
|
|
return;
|
2017-05-25 05:55:57 +03:00
|
|
|
}
|
2018-02-01 07:04:04 +03:00
|
|
|
#endif
|
2017-05-25 05:55:57 +03:00
|
|
|
|
2018-01-11 07:38:01 +03:00
|
|
|
RefPtr<ServoStyleSheet> servoSheet = do_QueryObject(&aSheet);
|
2017-05-25 05:55:57 +03:00
|
|
|
if (servoSheet) {
|
2018-01-11 07:38:01 +03:00
|
|
|
nsresult rv = servoSheet->ReparseSheet(aInput);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
}
|
|
|
|
return;
|
2017-05-25 05:55:57 +03:00
|
|
|
}
|
2012-06-03 20:54:38 +04:00
|
|
|
|
2018-01-11 07:38:01 +03:00
|
|
|
aRv.Throw(NS_ERROR_INVALID_POINTER);
|
2012-06-03 20:54:38 +04:00
|
|
|
}
|
2014-06-09 11:35:13 +04:00
|
|
|
|
2018-01-11 07:38:01 +03:00
|
|
|
void
|
|
|
|
InspectorUtils::ScrollElementIntoView(GlobalObject& aGlobalObject,
|
|
|
|
Element& aElement)
|
2014-06-09 11:35:13 +04:00
|
|
|
{
|
2018-01-11 07:38:01 +03:00
|
|
|
nsIPresShell* presShell = aElement.OwnerDoc()->GetShell();
|
2014-06-09 11:35:13 +04:00
|
|
|
if (!presShell) {
|
2018-01-11 07:38:01 +03:00
|
|
|
return;
|
2014-06-09 11:35:13 +04:00
|
|
|
}
|
|
|
|
|
2018-01-11 07:38:01 +03:00
|
|
|
presShell->ScrollContentIntoView(&aElement,
|
2014-06-09 11:35:13 +04:00
|
|
|
nsIPresShell::ScrollAxis(),
|
|
|
|
nsIPresShell::ScrollAxis(),
|
|
|
|
nsIPresShell::SCROLL_OVERFLOW_HIDDEN);
|
|
|
|
}
|
2018-01-11 07:38:01 +03:00
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|