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 "nsIDocument.h"
|
2009-08-11 02:52:29 +04:00
|
|
|
#include "nsIPresShell.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"
|
2018-06-04 16:35:50 +03:00
|
|
|
#include "mozilla/dom/CSSStyleRule.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"
|
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
|
|
|
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)) {
|
2018-06-04 16:35:50 +03:00
|
|
|
CSSStyleRule* rule = nullptr;
|
2018-03-22 21:20:41 +03:00
|
|
|
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 {
|
2018-07-14 13:40:59 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
nsAutoCString str;
|
|
|
|
fprintf(stderr, "%s\n", str.get());
|
|
|
|
Servo_StyleRule_Debug(rawRule, &str);
|
|
|
|
MOZ_CRASH_UNSAFE_PRINTF(
|
|
|
|
"We should be able to map a raw rule to a rule: %s\n",
|
|
|
|
str.get()
|
|
|
|
);
|
|
|
|
#endif
|
2018-03-22 21:20:41 +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 */ 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)) {
|
2018-07-30 19:04:05 +03:00
|
|
|
aResult.AppendElement(NS_ConvertASCIItoUTF16(
|
|
|
|
nsCSSProps::GetStringValue(cssProp)));
|
2018-04-20 06:42:14 +03:00
|
|
|
}
|
|
|
|
};
|
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) {
|
2018-04-26 08:00:50 +03:00
|
|
|
if (!nsCSSProps::PropHasFlags(nsCSSPropertyID(prop),
|
2018-04-26 08:00:50 +03:00
|
|
|
CSSPropFlags::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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-31 07:11:01 +03:00
|
|
|
/* static */ void
|
|
|
|
InspectorUtils::GetCSSPropertyPrefs(GlobalObject& aGlobalObject,
|
|
|
|
nsTArray<PropertyPref>& aResult)
|
|
|
|
{
|
|
|
|
for (const auto* src = nsCSSProps::kPropertyPrefTable;
|
|
|
|
src->mPropID != eCSSProperty_UNKNOWN; src++) {
|
|
|
|
PropertyPref& dest = *aResult.AppendElement();
|
2018-07-30 19:04:05 +03:00
|
|
|
dest.mName.Assign(NS_ConvertASCIItoUTF16(nsCSSProps::GetStringValue(src->mPropID)));
|
2018-05-31 07:11:01 +03:00
|
|
|
dest.mPref.AssignASCII(src->mPref);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2018-07-30 18:32:17 +03:00
|
|
|
nsCSSPropertyID propertyID = nsCSSProps::LookupProperty(aProperty);
|
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
|
|
|
{
|
Bug 1434130 part 13 - Use Servo code to back GetCSSValuesForProperty. r=emilio,gl
This causes various changes to properties-db.js and also many devtools
tests get updated.
There are two changes affect multiple tests:
* `calc` gets removed from everywhere. We never have it listed in all
properties which deserve it, and doing so without much false positive
(i.e. properties don't deserve but get it) can be pretty tricky.
So they are just removed for now.
* The complete color keyword list is no longer included, and instead,
"COLOR" is prepended to the list directly. We can probably remove
the related code which replaces color keywords with "COLOR" from
devtools. Note that, with stylo enabled, the list is already unrelated
to what the parsing code uses. We should eventually re-enable the
disabled test here after we can get the color list from cssparser
in bug 1456715.
Other changes to properties-db.js seem to be valid, some of them also
affect tests:
* `{-webkit-,}align-{content,items,self}` get `first baseline`, `safe`,
`unsafe`, and lose `left` and `right`.
* `{-moz-,-webkit-,}{animation,transition}{,-timing-function}` has a
new `frame` keyword which is a function value in `<timing-function>`.
* `{background,{-webkit-,}mask}-position-x` lose `top` and `bottom`, and
correspondingly `{background,{-webkit-,}mask}-position-y` lose `left`
and `right`. They don't deserve those values.
* `{background,{-webkit-,}mask}{,-size}` get `auto`.
* `border` shorthand loses `<image>` values as well as other keyword
values for `border-image-*` subproperties, because they aren't parsed
on the shorthand.
* `{-moz-,}border-image{,-width}` get `auto`.
* `-moz-context-properties` gets `none`.
* `cursor` get some -moz-prefixed values as well as `url`.
* `fill` and `stroke` get the color keywords.
* `{-webkit-,}filter` get the keywords and function names.
* `font` shorthand loses values from many of `font-variant-*` properties
because they are not parsed there.
* `font-variant` and `font-variant-alternates` get function values of
the longhand.
* `font-variant-{east-asian,ligatures,numeric}` get `normal`, and
`font-variant-ligatures` in addition gets `none`.
`font-{feature,variation}-settings` also get `normal`.
* `grid` and `grid-template-{areas,columns,rows}` get `none`.
* `grid`, `grid-template`, and `grid-template-{columns,rows}` get
`auto`, `fit-content`, `minmax`, and `repeat`.
* `grid-auto-{columns,rows}` get `auto`, `fit-content` and `minmax`.
* `-moz-image-region` gets `auto` and `rect`.
* `{-webkit-,}justify-content` lose `baseline`, `last baseline`, and
get `safe` and `unsafe`.
* `{justify,place}-items` get `first baseline`, `legacy`, `safe`,
`unsafe` and lose `auto`.
* `{justify,place}-self` and `place-content` get `first baseline`,
`safe`, and `unsafe`.
* `outline{,-style}` get `hidden`.
* `scroll-snap-coordinate` gets `none`, and `scroll-snap-points-{x,y}`
gets `none` and `repeat`.
* `shape-outside`, `text-emphasis{,-style}` get all the keyword values
and function names they deserve.
* `stroke-dasharray` gets `none`.
* `text-combine-upright` drops `digits` which we never implemented.
* `{-moz-,-webkit-,}transform` and `-moz-window-transform` get their
transform function list. `accumulatematrix` and `interpolatematrix`
aren't real CSS value but they have `#[css(function)]` specified.
We should probably remove them at some point.
* `will-change` gets `auto`.
* All properties accept `<image>` value now gets -webkit-prefixed
gradient function names, including
* `background{,-image}`,
* `{-moz-,-webkit-,}border-image{,-source}`, and
* `{-webkit-,}mask{,-image}`.
MozReview-Commit-ID: E7Y0CFUFYgW
--HG--
extra : source : bab732c8c531cfca1bcd233f769c25bb2e373773
2018-04-29 02:03:31 +03:00
|
|
|
NS_ConvertUTF16toUTF8 property(aProperty);
|
|
|
|
bool found;
|
|
|
|
Servo_Property_GetCSSValuesForProperty(&property, &found, &aResult);
|
|
|
|
if (!found) {
|
2018-01-11 07:38:00 +03:00
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
2013-07-16 01:28:49 +04:00
|
|
|
}
|
Bug 1434130 part 13 - Use Servo code to back GetCSSValuesForProperty. r=emilio,gl
This causes various changes to properties-db.js and also many devtools
tests get updated.
There are two changes affect multiple tests:
* `calc` gets removed from everywhere. We never have it listed in all
properties which deserve it, and doing so without much false positive
(i.e. properties don't deserve but get it) can be pretty tricky.
So they are just removed for now.
* The complete color keyword list is no longer included, and instead,
"COLOR" is prepended to the list directly. We can probably remove
the related code which replaces color keywords with "COLOR" from
devtools. Note that, with stylo enabled, the list is already unrelated
to what the parsing code uses. We should eventually re-enable the
disabled test here after we can get the color list from cssparser
in bug 1456715.
Other changes to properties-db.js seem to be valid, some of them also
affect tests:
* `{-webkit-,}align-{content,items,self}` get `first baseline`, `safe`,
`unsafe`, and lose `left` and `right`.
* `{-moz-,-webkit-,}{animation,transition}{,-timing-function}` has a
new `frame` keyword which is a function value in `<timing-function>`.
* `{background,{-webkit-,}mask}-position-x` lose `top` and `bottom`, and
correspondingly `{background,{-webkit-,}mask}-position-y` lose `left`
and `right`. They don't deserve those values.
* `{background,{-webkit-,}mask}{,-size}` get `auto`.
* `border` shorthand loses `<image>` values as well as other keyword
values for `border-image-*` subproperties, because they aren't parsed
on the shorthand.
* `{-moz-,}border-image{,-width}` get `auto`.
* `-moz-context-properties` gets `none`.
* `cursor` get some -moz-prefixed values as well as `url`.
* `fill` and `stroke` get the color keywords.
* `{-webkit-,}filter` get the keywords and function names.
* `font` shorthand loses values from many of `font-variant-*` properties
because they are not parsed there.
* `font-variant` and `font-variant-alternates` get function values of
the longhand.
* `font-variant-{east-asian,ligatures,numeric}` get `normal`, and
`font-variant-ligatures` in addition gets `none`.
`font-{feature,variation}-settings` also get `normal`.
* `grid` and `grid-template-{areas,columns,rows}` get `none`.
* `grid`, `grid-template`, and `grid-template-{columns,rows}` get
`auto`, `fit-content`, `minmax`, and `repeat`.
* `grid-auto-{columns,rows}` get `auto`, `fit-content` and `minmax`.
* `-moz-image-region` gets `auto` and `rect`.
* `{-webkit-,}justify-content` lose `baseline`, `last baseline`, and
get `safe` and `unsafe`.
* `{justify,place}-items` get `first baseline`, `legacy`, `safe`,
`unsafe` and lose `auto`.
* `{justify,place}-self` and `place-content` get `first baseline`,
`safe`, and `unsafe`.
* `outline{,-style}` get `hidden`.
* `scroll-snap-coordinate` gets `none`, and `scroll-snap-points-{x,y}`
gets `none` and `repeat`.
* `shape-outside`, `text-emphasis{,-style}` get all the keyword values
and function names they deserve.
* `stroke-dasharray` gets `none`.
* `text-combine-upright` drops `digits` which we never implemented.
* `{-moz-,-webkit-,}transform` and `-moz-window-transform` get their
transform function list. `accumulatematrix` and `interpolatematrix`
aren't real CSS value but they have `#[css(function)]` specified.
We should probably remove them at some point.
* `will-change` gets `auto`.
* All properties accept `<image>` value now gets -webkit-prefixed
gradient function names, including
* `background{,-image}`,
* `{-moz-,-webkit-,}border-image{,-source}`, and
* `{-webkit-,}mask{,-image}`.
MozReview-Commit-ID: E7Y0CFUFYgW
--HG--
extra : source : bab732c8c531cfca1bcd233f769c25bb2e373773
2018-04-29 02:03:31 +03:00
|
|
|
return;
|
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-05-24 16:44:09 +03:00
|
|
|
bool aSkipCollapsedWhitespace,
|
2018-01-11 07:38:01 +03:00
|
|
|
nsTArray<nsAutoPtr<InspectorFontFace>>& aResult,
|
|
|
|
ErrorResult& aRv)
|
2011-06-16 10:31:36 +04:00
|
|
|
{
|
2018-05-24 16:44:09 +03:00
|
|
|
nsresult rv = aRange.GetUsedFontFaces(aResult, aMaxRanges,
|
|
|
|
aSkipCollapsedWhitespace);
|
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-30 19:19:44 +03:00
|
|
|
aRv = aSheet.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
|
|
|
|
2018-07-19 14:59:05 +03:00
|
|
|
|
|
|
|
bool
|
|
|
|
InspectorUtils::IsCustomElementName(GlobalObject&,
|
|
|
|
const nsAString& aName,
|
|
|
|
const nsAString& aNamespaceURI)
|
|
|
|
{
|
|
|
|
if (aName.IsEmpty()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t namespaceID;
|
|
|
|
nsContentUtils::NameSpaceManager()->RegisterNameSpace(
|
|
|
|
aNamespaceURI,
|
|
|
|
namespaceID);
|
|
|
|
|
|
|
|
RefPtr<nsAtom> nameElt = NS_Atomize(aName);
|
|
|
|
return nsContentUtils::IsCustomElementName(
|
|
|
|
nameElt,
|
|
|
|
namespaceID);
|
|
|
|
}
|
|
|
|
|
2018-01-11 07:38:01 +03:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|