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"
|
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"
|
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"
|
2018-03-19 22:18:07 +03:00
|
|
|
#include "mozilla/dom/CharacterData.h"
|
2011-07-20 23:18:54 +04:00
|
|
|
#include "mozilla/dom/Element.h"
|
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"
|
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"
|
2018-03-29 14:15:46 +03:00
|
|
|
#include "mozilla/ServoStyleSet.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,
|
2018-04-16 20:10:57 +03:00
|
|
|
bool aDocumentOnly,
|
2018-01-11 07:37:59 +03:00
|
|
|
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) {
|
2018-03-29 14:15:46 +03:00
|
|
|
ServoStyleSet* styleSet = presShell->StyleSet();
|
2018-04-16 20:10:57 +03:00
|
|
|
|
|
|
|
if (!aDocumentOnly) {
|
|
|
|
SheetType sheetType = SheetType::Agent;
|
|
|
|
for (int32_t i = 0; i < styleSet->SheetCount(sheetType); i++) {
|
|
|
|
aResult.AppendElement(styleSet->StyleSheetAt(sheetType, i));
|
|
|
|
}
|
|
|
|
sheetType = SheetType::User;
|
|
|
|
for (int32_t i = 0; i < styleSet->SheetCount(sheetType); i++) {
|
|
|
|
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;
|
2018-04-16 20:10:57 +03:00
|
|
|
styleSet->AppendAllNonDocumentAuthorSheets(xblSheetArray);
|
2017-06-30 02:09:22 +03:00
|
|
|
|
|
|
|
// The XBL stylesheet array will quite often be full of duplicates. Cope:
|
2018-04-16 20:10:57 +03:00
|
|
|
//
|
|
|
|
// FIXME(emilio, bug 1454467): I think this is not true since bug 1452525.
|
2017-06-30 02:09:22 +03:00
|
|
|
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
|
2018-03-19 22:18:06 +03:00
|
|
|
InspectorUtils::IsIgnorableWhitespace(CharacterData& 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-04-15 12:43:15 +03:00
|
|
|
if (aNode.IsDocument()) {
|
|
|
|
parent = inLayoutUtils::GetContainerFor(*aNode.AsDocument());
|
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
|
|
|
}
|
|
|
|
|
2018-03-22 16:49:21 +03:00
|
|
|
RefPtr<ComputedStyle> computedStyle =
|
2018-03-22 21:20:41 +03:00
|
|
|
GetCleanComputedStyleForElement(&aElement, pseudoElt);
|
2018-03-22 16:49:21 +03:00
|
|
|
if (!computedStyle) {
|
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-03-22 21:20:41 +03:00
|
|
|
nsIDocument* doc = aElement.OwnerDoc();
|
|
|
|
nsIPresShell* shell = doc->GetShell();
|
|
|
|
if (!shell) {
|
|
|
|
return;
|
|
|
|
}
|
2006-05-17 06:21:53 +04:00
|
|
|
|
2018-03-22 21:20:41 +03:00
|
|
|
nsTArray<const RawServoStyleRule*> rawRuleList;
|
2018-03-25 20:16:39 +03:00
|
|
|
Servo_ComputedValues_GetStyleRuleList(computedStyle, &rawRuleList);
|
2017-07-10 02:38:58 +03:00
|
|
|
|
2018-03-22 21:20:41 +03:00
|
|
|
AutoTArray<ServoStyleRuleMap*, 1> maps;
|
|
|
|
{
|
2018-03-29 14:15:46 +03:00
|
|
|
ServoStyleSet* styleSet = shell->StyleSet();
|
2018-03-22 21:20:41 +03:00
|
|
|
ServoStyleRuleMap* map = styleSet->StyleRuleMap();
|
|
|
|
maps.AppendElement(map);
|
|
|
|
}
|
2017-08-03 09:59:17 +03:00
|
|
|
|
2018-03-22 21:20:41 +03:00
|
|
|
// Collect style rule maps for bindings.
|
|
|
|
for (nsIContent* bindingContent = &aElement; bindingContent;
|
|
|
|
bindingContent = bindingContent->GetBindingParent()) {
|
|
|
|
for (nsXBLBinding* binding = bindingContent->GetXBLBinding();
|
|
|
|
binding; binding = binding->GetBaseBinding()) {
|
|
|
|
if (auto* map = binding->PrototypeBinding()->GetServoStyleRuleMap()) {
|
|
|
|
maps.AppendElement(map);
|
2017-08-03 09:59:17 +03:00
|
|
|
}
|
|
|
|
}
|
2018-03-22 21:20:41 +03:00
|
|
|
// 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
|
|
|
|
2018-03-22 21:20:41 +03:00
|
|
|
// Now shadow DOM stuff...
|
|
|
|
if (auto* shadow = aElement.GetShadowRoot()) {
|
|
|
|
maps.AppendElement(&shadow->ServoStyleRuleMap());
|
|
|
|
}
|
2018-02-25 20:01:42 +03:00
|
|
|
|
2018-03-22 21:20:41 +03:00
|
|
|
for (auto* shadow = aElement.GetContainingShadow();
|
|
|
|
shadow;
|
|
|
|
shadow = shadow->Host()->GetContainingShadow()) {
|
|
|
|
maps.AppendElement(&shadow->ServoStyleRuleMap());
|
|
|
|
}
|
2018-02-25 20:01:42 +03:00
|
|
|
|
2018-03-22 21:20:41 +03:00
|
|
|
// Find matching rules in the table.
|
|
|
|
for (const RawServoStyleRule* rawRule : Reversed(rawRuleList)) {
|
|
|
|
ServoStyleRule* rule = nullptr;
|
|
|
|
for (ServoStyleRuleMap* map : maps) {
|
|
|
|
rule = map->Lookup(rawRule);
|
2017-08-03 09:59:17 +03:00
|
|
|
if (rule) {
|
2018-03-22 21:20:41 +03:00
|
|
|
break;
|
2017-05-19 00:50:05 +03:00
|
|
|
}
|
2017-04-08 01:21:36 +03:00
|
|
|
}
|
2018-03-22 21:20:41 +03:00
|
|
|
if (rule) {
|
|
|
|
aResult.AppendElement(rule);
|
|
|
|
} else {
|
|
|
|
MOZ_ASSERT_UNREACHABLE("We should be able to map a raw rule to a rule");
|
|
|
|
}
|
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
|
|
|
{
|
2018-04-09 07:33:30 +03:00
|
|
|
NS_ConvertUTF16toUTF8 propName(aPropertyName);
|
|
|
|
return Servo_Property_IsInherited(&propName);
|
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
|
|
|
{
|
2018-04-20 06:42:14 +03:00
|
|
|
CSSEnabledState enabledState = aOptions.mIncludeExperimentals
|
|
|
|
? CSSEnabledState::eIgnoreEnabledState
|
|
|
|
: CSSEnabledState::eForAllContent;
|
|
|
|
|
|
|
|
auto appendProperty = [enabledState, &aResult](uint32_t prop) {
|
|
|
|
nsCSSPropertyID cssProp = nsCSSPropertyID(prop);
|
|
|
|
if (nsCSSProps::IsEnabled(cssProp, enabledState)) {
|
|
|
|
nsDependentCString name(kCSSRawProperties[prop]);
|
|
|
|
aResult.AppendElement(NS_ConvertASCIItoUTF16(name));
|
|
|
|
}
|
|
|
|
};
|
2013-03-14 23:42:59 +04:00
|
|
|
|
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) {
|
2018-04-20 06:42:14 +03:00
|
|
|
appendProperty(prop);
|
2013-03-14 23:42:59 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-20 06:42:14 +03:00
|
|
|
if (aOptions.mIncludeShorthands) {
|
|
|
|
for ( ; prop < eCSSProperty_COUNT; ++prop) {
|
|
|
|
appendProperty(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) {
|
2018-04-20 06:42:14 +03:00
|
|
|
appendProperty(prop);
|
2013-03-14 23:42:59 +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 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)
|
|
|
|
{
|
2018-04-11 03:12:16 +03:00
|
|
|
const nsCSSProps::KTableEntry* keywordTable;
|
2013-07-16 01:28:49 +04:00
|
|
|
if (nsCSSProps::IsShorthand(aProperty)) {
|
2018-04-11 03:12:16 +03:00
|
|
|
if (aProperty == eCSSProperty_font) {
|
|
|
|
keywordTable = nsCSSProps::kFontKTable;
|
|
|
|
} else {
|
|
|
|
// Other shorthand props have no keywords.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
keywordTable = nsCSSProps::kKeywordTableTable[aProperty];
|
|
|
|
// Special cases where nsCSSPropList.h doesn't hold the table.
|
|
|
|
if (keywordTable == nullptr) {
|
|
|
|
if (aProperty == eCSSProperty_clip_path) {
|
|
|
|
keywordTable = nsCSSProps::kClipPathGeometryBoxKTable;
|
|
|
|
}
|
2018-01-22 23:26:14 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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++) {
|
2018-03-24 22:31:19 +03:00
|
|
|
utf16Names[i].AssignASCII(allColorNames[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
|
|
|
{
|
2018-03-18 15:56:09 +03:00
|
|
|
NS_ConvertUTF16toUTF8 prop(aProperty);
|
|
|
|
bool found;
|
|
|
|
bool isShorthand = Servo_Property_IsShorthand(&prop, &found);
|
|
|
|
if (!found) {
|
2018-01-11 07:38:00 +03:00
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
2014-05-06 19:46:34 +04:00
|
|
|
}
|
2018-03-18 15:56:09 +03:00
|
|
|
return isShorthand;
|
2014-05-06 19:46:34 +04: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
|
|
|
{
|
2018-04-26 02:01:02 +03:00
|
|
|
NS_ConvertUTF16toUTF8 property(aProperty);
|
|
|
|
bool found;
|
|
|
|
bool result = Servo_Property_SupportsType(&property, aType, &found);
|
|
|
|
if (!found) {
|
2018-01-11 07:38:00 +03:00
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return false;
|
2014-05-06 19:46:34 +04:00
|
|
|
}
|
2018-04-26 02:01:02 +03:00
|
|
|
return result;
|
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;
|
|
|
|
}
|
|
|
|
}
|
2018-04-11 03:12:16 +03:00
|
|
|
// Some shorthands may have keywords not available in subproperties.
|
|
|
|
GetKeywordsForProperty(propertyID, aResult);
|
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);
|
|
|
|
|
|
|
|
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
|
|
|
}
|
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
|
|
|
{
|
2018-01-11 07:38:00 +03:00
|
|
|
return ServoCSSParser::IsValidCSSColor(aColorString);
|
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
|
|
|
}
|
|
|
|
|
2018-03-22 21:20:41 +03:00
|
|
|
/* static */ already_AddRefed<ComputedStyle>
|
|
|
|
InspectorUtils::GetCleanComputedStyleForElement(dom::Element* aElement,
|
2018-01-11 07:37:59 +03:00
|
|
|
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
|
|
|
|
2018-03-22 16:49:21 +03:00
|
|
|
return nsComputedDOMStyle::GetComputedStyle(aElement, aPseudo);
|
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,
|
2018-02-15 21:48:22 +03:00
|
|
|
uint32_t aMaxRanges,
|
2018-01-11 07:38:01 +03:00
|
|
|
nsTArray<nsAutoPtr<InspectorFontFace>>& aResult,
|
|
|
|
ErrorResult& aRv)
|
2011-06-16 10:31:36 +04:00
|
|
|
{
|
2018-02-15 21:48:22 +03:00
|
|
|
nsresult rv = aRange.GetUsedFontFaces(aResult, aMaxRanges);
|
2018-01-11 07:38:01 +03:00
|
|
|
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)
|
|
|
|
{
|
2018-03-28 01:41:04 +03:00
|
|
|
if (aStatePseudo.IsEmpty() || aStatePseudo[0] != u':') {
|
2014-04-03 08:18:36 +04:00
|
|
|
return EventStates();
|
2012-02-08 22:42:38 +04:00
|
|
|
}
|
2018-03-28 01:41:04 +03:00
|
|
|
NS_ConvertUTF16toUTF8 statePseudo(Substring(aStatePseudo, 1));
|
|
|
|
return EventStates(Servo_PseudoClass_GetStates(&statePseudo));
|
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
|
|
|
{
|
2017-05-25 05:55:57 +03:00
|
|
|
|
2018-04-16 20:10:57 +03:00
|
|
|
RefPtr<ServoStyleSheet> servoSheet = aSheet.AsServo();
|
|
|
|
aRv = servoSheet->ReparseSheet(aInput);
|
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
|