2013-03-14 19:42:59 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 11:12:37 +00: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 02:21:53 +00:00
|
|
|
|
|
|
|
#include "inDOMUtils.h"
|
|
|
|
#include "inLayoutUtils.h"
|
|
|
|
|
2006-05-17 02:33:55 +00:00
|
|
|
#include "nsIServiceManager.h"
|
2013-09-25 11:21:20 +00:00
|
|
|
#include "nsISupportsArray.h"
|
2006-05-17 02:21:53 +00:00
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsIDOMElement.h"
|
|
|
|
#include "nsIDocument.h"
|
2009-08-10 22:52:29 +00:00
|
|
|
#include "nsIPresShell.h"
|
2006-05-17 02:21:53 +00:00
|
|
|
#include "nsIDOMDocument.h"
|
2006-05-17 02:37:41 +00:00
|
|
|
#include "nsIDOMCharacterData.h"
|
2006-05-17 02:33:36 +00:00
|
|
|
#include "nsRuleNode.h"
|
2006-05-17 02:21:53 +00:00
|
|
|
#include "nsIStyleRule.h"
|
2011-03-11 02:48:57 +00:00
|
|
|
#include "mozilla/css/StyleRule.h"
|
2006-05-17 02:38:08 +00:00
|
|
|
#include "nsICSSStyleRuleDOMWrapper.h"
|
2011-07-15 10:31:34 +00:00
|
|
|
#include "nsIDOMWindow.h"
|
2009-08-10 22:52:29 +00:00
|
|
|
#include "nsXBLBinding.h"
|
|
|
|
#include "nsXBLPrototypeBinding.h"
|
|
|
|
#include "nsIMutableArray.h"
|
|
|
|
#include "nsBindingManager.h"
|
2013-05-01 22:50:08 +00:00
|
|
|
#include "ChildIterator.h"
|
2009-08-10 22:52:29 +00:00
|
|
|
#include "nsComputedDOMStyle.h"
|
2011-04-21 17:35:52 +00:00
|
|
|
#include "nsEventStateManager.h"
|
2011-05-05 21:12:04 +00:00
|
|
|
#include "nsIAtom.h"
|
2012-01-10 14:19:54 +00:00
|
|
|
#include "nsRange.h"
|
2013-05-01 22:50:08 +00:00
|
|
|
#include "nsContentList.h"
|
2011-07-20 19:18:54 +00:00
|
|
|
#include "mozilla/dom/Element.h"
|
2012-06-03 16:54:38 +00:00
|
|
|
#include "nsCSSStyleSheet.h"
|
2013-02-13 15:11:53 +00:00
|
|
|
#include "nsRuleWalker.h"
|
|
|
|
#include "nsRuleProcessorData.h"
|
|
|
|
#include "nsCSSRuleProcessor.h"
|
2013-03-14 19:43:00 +00:00
|
|
|
#include "mozilla/dom/InspectorUtilsBinding.h"
|
2013-07-15 21:28:49 +00:00
|
|
|
#include "nsCSSProps.h"
|
|
|
|
#include "nsColor.h"
|
2013-07-25 13:31:14 +00:00
|
|
|
#include "nsStyleSet.h"
|
2011-07-20 19:18:54 +00:00
|
|
|
|
2013-02-13 15:11:53 +00:00
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::css;
|
|
|
|
using namespace mozilla::dom;
|
2006-05-17 02:21:53 +00:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
inDOMUtils::inDOMUtils()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
inDOMUtils::~inDOMUtils()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2006-05-17 02:38:09 +00:00
|
|
|
NS_IMPL_ISUPPORTS1(inDOMUtils, inIDOMUtils)
|
2006-05-17 02:21:53 +00:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// inIDOMUtils
|
|
|
|
|
2013-07-25 13:31:14 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
inDOMUtils::GetAllStyleSheets(nsIDOMDocument *aDocument, uint32_t *aLength,
|
|
|
|
nsISupports ***aSheets)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aDocument);
|
|
|
|
|
|
|
|
nsCOMArray<nsISupports> sheets;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocument> document = do_QueryInterface(aDocument);
|
|
|
|
MOZ_ASSERT(document);
|
|
|
|
|
|
|
|
// Get the agent, then user sheets in the style set.
|
|
|
|
nsIPresShell* presShell = document->GetShell();
|
|
|
|
if (presShell) {
|
|
|
|
nsStyleSet* styleSet = presShell->StyleSet();
|
|
|
|
nsStyleSet::sheetType sheetType = nsStyleSet::eAgentSheet;
|
|
|
|
for (int32_t i = 0; i < styleSet->SheetCount(sheetType); i++) {
|
|
|
|
sheets.AppendElement(styleSet->StyleSheetAt(sheetType, i));
|
|
|
|
}
|
|
|
|
sheetType = nsStyleSet::eUserSheet;
|
|
|
|
for (int32_t i = 0; i < styleSet->SheetCount(sheetType); i++) {
|
|
|
|
sheets.AppendElement(styleSet->StyleSheetAt(sheetType, i));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the document sheets.
|
|
|
|
for (int32_t i = 0; i < document->GetNumberOfStyleSheets(); i++) {
|
|
|
|
sheets.AppendElement(document->GetStyleSheetAt(i));
|
|
|
|
}
|
|
|
|
|
|
|
|
nsISupports** ret = static_cast<nsISupports**>(NS_Alloc(sheets.Count() *
|
|
|
|
sizeof(nsISupports*)));
|
|
|
|
|
|
|
|
for (int32_t i = 0; i < sheets.Count(); i++) {
|
|
|
|
NS_ADDREF(ret[i] = sheets[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
*aLength = sheets.Count();
|
|
|
|
*aSheets = ret;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-05-17 02:37:41 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
inDOMUtils::IsIgnorableWhitespace(nsIDOMCharacterData *aDataNode,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool *aReturn)
|
2006-05-17 02:37:41 +00:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aReturn, "Must have an out parameter");
|
|
|
|
|
2008-12-16 11:26:42 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aDataNode);
|
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
*aReturn = false;
|
2006-05-17 02:37:41 +00:00
|
|
|
|
2006-07-19 04:36:36 +00:00
|
|
|
nsCOMPtr<nsIContent> content = do_QueryInterface(aDataNode);
|
|
|
|
NS_ASSERTION(content, "Does not implement nsIContent!");
|
2006-05-17 02:37:41 +00:00
|
|
|
|
2006-07-19 04:36:36 +00:00
|
|
|
if (!content->TextIsOnlyWhitespace()) {
|
2006-05-17 02:37:41 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Okay. We have only white space. Let's check the white-space
|
|
|
|
// property now and make sure that this isn't preformatted text...
|
2009-12-24 21:20:06 +00:00
|
|
|
nsIFrame* frame = content->GetPrimaryFrame();
|
2006-05-17 02:37:51 +00:00
|
|
|
if (frame) {
|
2013-02-16 21:51:02 +00:00
|
|
|
const nsStyleText* text = frame->StyleText();
|
2008-02-20 02:07:48 +00:00
|
|
|
*aReturn = !text->WhiteSpaceIsSignificant();
|
2006-05-17 02:37:41 +00:00
|
|
|
}
|
2006-05-17 02:37:52 +00:00
|
|
|
else {
|
|
|
|
// empty inter-tag text node without frame, e.g., in between <table>\n<tr>
|
2011-10-17 14:59:28 +00:00
|
|
|
*aReturn = true;
|
2006-05-17 02:37:52 +00:00
|
|
|
}
|
2006-05-17 02:37:41 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
2006-05-17 02:37:38 +00:00
|
|
|
}
|
|
|
|
|
2006-05-17 02:38:00 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
inDOMUtils::GetParentForNode(nsIDOMNode* aNode,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool aShowingAnonymousContent,
|
2006-05-17 02:38:00 +00:00
|
|
|
nsIDOMNode** aParent)
|
|
|
|
{
|
2008-12-16 11:26:42 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aNode);
|
|
|
|
|
|
|
|
// First do the special cases -- document nodes and anonymous content
|
2013-07-23 23:39:17 +00:00
|
|
|
nsCOMPtr<nsIDocument> doc(do_QueryInterface(aNode));
|
2006-05-17 02:38:00 +00:00
|
|
|
nsCOMPtr<nsIDOMNode> parent;
|
|
|
|
|
|
|
|
if (doc) {
|
2013-07-23 23:39:17 +00:00
|
|
|
parent = inLayoutUtils::GetContainerFor(*doc);
|
2006-05-17 02:38:00 +00:00
|
|
|
} else if (aShowingAnonymousContent) {
|
|
|
|
nsCOMPtr<nsIContent> content = do_QueryInterface(aNode);
|
2006-07-14 12:08:59 +00:00
|
|
|
if (content) {
|
2013-07-17 16:05:06 +00:00
|
|
|
nsIContent* bparent = content->GetXBLInsertionParent();
|
2006-07-14 12:08:59 +00:00
|
|
|
parent = do_QueryInterface(bparent);
|
|
|
|
}
|
2006-05-17 02:38:00 +00:00
|
|
|
}
|
2012-05-09 16:23:57 +00:00
|
|
|
|
2006-05-17 02:38:00 +00:00
|
|
|
if (!parent) {
|
|
|
|
// Ok, just get the normal DOM parent node
|
|
|
|
aNode->GetParentNode(getter_AddRefs(parent));
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IF_ADDREF(*aParent = parent);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-05-30 21:51:09 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
inDOMUtils::GetChildrenForNode(nsIDOMNode* aNode,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool aShowingAnonymousContent,
|
2011-05-30 21:51:09 +00:00
|
|
|
nsIDOMNodeList** aChildren)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aNode);
|
|
|
|
NS_PRECONDITION(aChildren, "Must have an out parameter");
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMNodeList> kids;
|
|
|
|
|
|
|
|
if (aShowingAnonymousContent) {
|
|
|
|
nsCOMPtr<nsIContent> content = do_QueryInterface(aNode);
|
|
|
|
if (content) {
|
2013-04-14 18:47:31 +00:00
|
|
|
kids = content->GetChildren(nsIContent::eAllChildren);
|
2011-05-30 21:51:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!kids) {
|
|
|
|
aNode->GetChildNodes(getter_AddRefs(kids));
|
|
|
|
}
|
|
|
|
|
|
|
|
kids.forget(aChildren);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-05-17 02:21:53 +00:00
|
|
|
NS_IMETHODIMP
|
2006-05-17 02:38:08 +00:00
|
|
|
inDOMUtils::GetCSSStyleRules(nsIDOMElement *aElement,
|
2011-05-05 21:12:04 +00:00
|
|
|
const nsAString& aPseudo,
|
2006-05-17 02:38:08 +00:00
|
|
|
nsISupportsArray **_retval)
|
2006-05-17 02:21:53 +00:00
|
|
|
{
|
2008-12-16 11:26:42 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aElement);
|
2006-05-17 02:37:51 +00:00
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
*_retval = nullptr;
|
2006-05-17 02:37:39 +00:00
|
|
|
|
2011-05-05 21:12:04 +00:00
|
|
|
nsCOMPtr<nsIAtom> pseudoElt;
|
|
|
|
if (!aPseudo.IsEmpty()) {
|
|
|
|
pseudoElt = do_GetAtom(aPseudo);
|
|
|
|
}
|
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
nsRuleNode* ruleNode = nullptr;
|
2013-11-11 08:00:41 +00:00
|
|
|
nsCOMPtr<Element> element = do_QueryInterface(aElement);
|
|
|
|
NS_ENSURE_STATE(element);
|
2009-11-25 05:35:55 +00:00
|
|
|
nsRefPtr<nsStyleContext> styleContext;
|
2013-11-11 08:00:41 +00:00
|
|
|
GetRuleNodeForElement(element, pseudoElt, getter_AddRefs(styleContext), &ruleNode);
|
2006-05-17 02:38:34 +00:00
|
|
|
if (!ruleNode) {
|
2013-11-11 08:00:41 +00:00
|
|
|
// This can fail for elements that are not in the document or
|
2006-05-17 02:38:34 +00:00
|
|
|
// if the document they're in doesn't have a presshell. Bail out.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsISupportsArray> rules;
|
|
|
|
NS_NewISupportsArray(getter_AddRefs(rules));
|
|
|
|
if (!rules) return NS_ERROR_OUT_OF_MEMORY;
|
2006-05-17 02:37:39 +00:00
|
|
|
|
2011-03-11 02:48:57 +00:00
|
|
|
nsRefPtr<mozilla::css::StyleRule> cssRule;
|
2009-08-10 22:52:29 +00:00
|
|
|
for ( ; !ruleNode->IsRoot(); ruleNode = ruleNode->GetParent()) {
|
2011-03-11 02:48:57 +00:00
|
|
|
cssRule = do_QueryObject(ruleNode->GetRule());
|
2006-05-17 02:38:08 +00:00
|
|
|
if (cssRule) {
|
2011-04-08 06:36:09 +00:00
|
|
|
nsCOMPtr<nsIDOMCSSRule> domRule = cssRule->GetDOMRule();
|
2006-05-17 02:38:13 +00:00
|
|
|
if (domRule)
|
|
|
|
rules->InsertElementAt(domRule, 0);
|
2006-05-17 02:38:08 +00:00
|
|
|
}
|
2006-05-17 02:34:02 +00:00
|
|
|
}
|
2006-05-17 02:21:53 +00:00
|
|
|
|
|
|
|
*_retval = rules;
|
2006-05-17 02:37:39 +00:00
|
|
|
NS_ADDREF(*_retval);
|
|
|
|
|
2006-05-17 02:21:53 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-02-13 15:11:53 +00:00
|
|
|
static already_AddRefed<StyleRule>
|
|
|
|
GetRuleFromDOMRule(nsIDOMCSSStyleRule *aRule, ErrorResult& rv)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsICSSStyleRuleDOMWrapper> rule = do_QueryInterface(aRule);
|
|
|
|
if (!rule) {
|
2013-02-13 16:32:40 +00:00
|
|
|
rv.Throw(NS_ERROR_INVALID_POINTER);
|
2013-02-13 15:11:53 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<StyleRule> cssrule;
|
|
|
|
rv = rule->GetCSSStyleRule(getter_AddRefs(cssrule));
|
|
|
|
if (rv.Failed()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!cssrule) {
|
|
|
|
rv.Throw(NS_ERROR_FAILURE);
|
|
|
|
}
|
|
|
|
return cssrule.forget();
|
|
|
|
}
|
|
|
|
|
2006-05-17 02:21:53 +00:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
inDOMUtils::GetRuleLine(nsIDOMCSSStyleRule *aRule, uint32_t *_retval)
|
2006-05-17 02:21:53 +00:00
|
|
|
{
|
2013-02-13 15:11:53 +00:00
|
|
|
ErrorResult rv;
|
|
|
|
nsRefPtr<StyleRule> rule = GetRuleFromDOMRule(aRule, rv);
|
|
|
|
if (rv.Failed()) {
|
|
|
|
return rv.ErrorCode();
|
|
|
|
}
|
2008-12-16 11:26:42 +00:00
|
|
|
|
2013-02-13 15:11:53 +00:00
|
|
|
*_retval = rule->GetLineNumber();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2008-12-16 11:26:42 +00:00
|
|
|
|
2013-04-06 17:38:56 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
inDOMUtils::GetRuleColumn(nsIDOMCSSStyleRule *aRule, uint32_t *_retval)
|
|
|
|
{
|
|
|
|
ErrorResult rv;
|
|
|
|
nsRefPtr<StyleRule> rule = GetRuleFromDOMRule(aRule, rv);
|
|
|
|
if (rv.Failed()) {
|
|
|
|
return rv.ErrorCode();
|
|
|
|
}
|
|
|
|
*_retval = rule->GetColumnNumber();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-02-13 15:11:53 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
inDOMUtils::GetSelectorCount(nsIDOMCSSStyleRule* aRule, uint32_t *aCount)
|
|
|
|
{
|
|
|
|
ErrorResult rv;
|
|
|
|
nsRefPtr<StyleRule> rule = GetRuleFromDOMRule(aRule, rv);
|
|
|
|
if (rv.Failed()) {
|
|
|
|
return rv.ErrorCode();
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t count = 0;
|
|
|
|
for (nsCSSSelectorList* sel = rule->Selector(); sel; sel = sel->mNext) {
|
|
|
|
++count;
|
|
|
|
}
|
|
|
|
*aCount = count;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static nsCSSSelectorList*
|
|
|
|
GetSelectorAtIndex(nsIDOMCSSStyleRule* aRule, uint32_t aIndex, ErrorResult& rv)
|
|
|
|
{
|
|
|
|
nsRefPtr<StyleRule> rule = GetRuleFromDOMRule(aRule, rv);
|
|
|
|
if (rv.Failed()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (nsCSSSelectorList* sel = rule->Selector(); sel;
|
|
|
|
sel = sel->mNext, --aIndex) {
|
|
|
|
if (aIndex == 0) {
|
|
|
|
return sel;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ran out of selectors
|
|
|
|
rv.Throw(NS_ERROR_INVALID_ARG);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
inDOMUtils::GetSelectorText(nsIDOMCSSStyleRule* aRule,
|
|
|
|
uint32_t aSelectorIndex,
|
|
|
|
nsAString& aText)
|
|
|
|
{
|
|
|
|
ErrorResult rv;
|
|
|
|
nsCSSSelectorList* sel = GetSelectorAtIndex(aRule, aSelectorIndex, rv);
|
|
|
|
if (rv.Failed()) {
|
|
|
|
return rv.ErrorCode();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<StyleRule> rule = GetRuleFromDOMRule(aRule, rv);
|
|
|
|
MOZ_ASSERT(!rv.Failed(), "How could we get a selector but not a rule?");
|
|
|
|
|
|
|
|
sel->mSelectors->ToString(aText, rule->GetStyleSheet(), false);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
inDOMUtils::GetSpecificity(nsIDOMCSSStyleRule* aRule,
|
|
|
|
uint32_t aSelectorIndex,
|
|
|
|
uint64_t* aSpecificity)
|
|
|
|
{
|
|
|
|
ErrorResult rv;
|
|
|
|
nsCSSSelectorList* sel = GetSelectorAtIndex(aRule, aSelectorIndex, rv);
|
|
|
|
if (rv.Failed()) {
|
|
|
|
return rv.ErrorCode();
|
|
|
|
}
|
|
|
|
|
|
|
|
*aSpecificity = sel->mWeight;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
inDOMUtils::SelectorMatchesElement(nsIDOMElement* aElement,
|
|
|
|
nsIDOMCSSStyleRule* aRule,
|
|
|
|
uint32_t aSelectorIndex,
|
|
|
|
bool* aMatches)
|
|
|
|
{
|
|
|
|
nsCOMPtr<Element> element = do_QueryInterface(aElement);
|
|
|
|
NS_ENSURE_ARG_POINTER(element);
|
|
|
|
|
|
|
|
ErrorResult rv;
|
|
|
|
nsCSSSelectorList* tail = GetSelectorAtIndex(aRule, aSelectorIndex, rv);
|
|
|
|
if (rv.Failed()) {
|
|
|
|
return rv.ErrorCode();
|
|
|
|
}
|
|
|
|
|
|
|
|
// We want just the one list item, not the whole list tail
|
|
|
|
nsAutoPtr<nsCSSSelectorList> sel(tail->Clone(false));
|
|
|
|
|
|
|
|
element->OwnerDoc()->FlushPendingLinkUpdates();
|
|
|
|
// XXXbz what exactly should we do with visited state here?
|
|
|
|
TreeMatchContext matchingContext(false,
|
|
|
|
nsRuleWalker::eRelevantLinkUnvisited,
|
|
|
|
element->OwnerDoc(),
|
|
|
|
TreeMatchContext::eNeverMatchVisited);
|
|
|
|
*aMatches = nsCSSRuleProcessor::SelectorListMatches(element, matchingContext,
|
|
|
|
sel);
|
2006-05-17 02:21:53 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-11-05 15:41:10 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
inDOMUtils::IsInheritedProperty(const nsAString &aPropertyName, bool *_retval)
|
|
|
|
{
|
2012-07-13 23:59:05 +00:00
|
|
|
nsCSSProperty prop = nsCSSProps::LookupProperty(aPropertyName,
|
|
|
|
nsCSSProps::eAny);
|
2011-11-05 15:41:10 +00:00
|
|
|
if (prop == eCSSProperty_UNKNOWN) {
|
|
|
|
*_retval = false;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nsCSSProps::IsShorthand(prop)) {
|
|
|
|
prop = nsCSSProps::SubpropertyEntryFor(prop)[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
nsStyleStructID sid = nsCSSProps::kSIDTable[prop];
|
|
|
|
*_retval = !nsCachedStyleData::IsReset(sid);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-03-14 19:42:59 +00:00
|
|
|
extern const char* const kCSSRawProperties[];
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
inDOMUtils::GetCSSPropertyNames(uint32_t aFlags, uint32_t* aCount,
|
|
|
|
PRUnichar*** aProps)
|
|
|
|
{
|
|
|
|
// maxCount is the largest number of properties we could have; our actual
|
|
|
|
// number might be smaller because properties might be disabled.
|
|
|
|
uint32_t maxCount;
|
|
|
|
if (aFlags & EXCLUDE_SHORTHANDS) {
|
|
|
|
maxCount = eCSSProperty_COUNT_no_shorthands;
|
|
|
|
} else {
|
|
|
|
maxCount = eCSSProperty_COUNT;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aFlags & INCLUDE_ALIASES) {
|
|
|
|
maxCount += (eCSSProperty_COUNT_with_aliases - eCSSProperty_COUNT);
|
|
|
|
}
|
|
|
|
|
|
|
|
PRUnichar** props =
|
|
|
|
static_cast<PRUnichar**>(nsMemory::Alloc(maxCount * sizeof(PRUnichar*)));
|
|
|
|
|
|
|
|
#define DO_PROP(_prop) \
|
|
|
|
PR_BEGIN_MACRO \
|
|
|
|
nsCSSProperty cssProp = nsCSSProperty(_prop); \
|
|
|
|
if (nsCSSProps::IsEnabled(cssProp)) { \
|
|
|
|
props[propCount] = \
|
|
|
|
ToNewUnicode(nsDependentCString(kCSSRawProperties[_prop])); \
|
|
|
|
++propCount; \
|
|
|
|
} \
|
|
|
|
PR_END_MACRO
|
|
|
|
|
|
|
|
// prop is the property id we're considering; propCount is how many properties
|
|
|
|
// we've put into props so far.
|
|
|
|
uint32_t prop = 0, propCount = 0;
|
|
|
|
for ( ; prop < eCSSProperty_COUNT_no_shorthands; ++prop) {
|
2013-05-14 18:20:58 +00:00
|
|
|
if (nsCSSProps::PropertyParseType(nsCSSProperty(prop)) !=
|
|
|
|
CSS_PROPERTY_PARSE_INACCESSIBLE) {
|
2013-03-14 19:42:59 +00:00
|
|
|
DO_PROP(prop);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(aFlags & EXCLUDE_SHORTHANDS)) {
|
|
|
|
for ( ; prop < eCSSProperty_COUNT; ++prop) {
|
|
|
|
// Some shorthands are also aliases
|
|
|
|
if ((aFlags & INCLUDE_ALIASES) ||
|
|
|
|
!nsCSSProps::PropHasFlags(nsCSSProperty(prop),
|
|
|
|
CSS_PROPERTY_IS_ALIAS)) {
|
|
|
|
DO_PROP(prop);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aFlags & INCLUDE_ALIASES) {
|
|
|
|
for (prop = eCSSProperty_COUNT; prop < eCSSProperty_COUNT_with_aliases; ++prop) {
|
|
|
|
DO_PROP(prop);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef DO_PROP
|
|
|
|
|
|
|
|
*aCount = propCount;
|
|
|
|
*aProps = props;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
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 14:32:52 +00: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);
|
|
|
|
}
|
|
|
|
|
2013-07-15 21:28:49 +00:00
|
|
|
static void GetKeywordsForProperty(const nsCSSProperty aProperty,
|
|
|
|
nsTArray<nsString>& aArray)
|
|
|
|
{
|
|
|
|
if (nsCSSProps::IsShorthand(aProperty)) {
|
|
|
|
// Shorthand props have no keywords.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const int32_t *keywordTable = nsCSSProps::kKeywordTableTable[aProperty];
|
2013-07-30 19:38:01 +00:00
|
|
|
if (keywordTable && keywordTable != nsCSSProps::kBoxPropSourceKTable) {
|
2013-07-15 21:28:49 +00:00
|
|
|
size_t i = 0;
|
|
|
|
while (nsCSSKeyword(keywordTable[i]) != eCSSKeyword_UNKNOWN) {
|
|
|
|
nsCSSKeyword word = nsCSSKeyword(keywordTable[i]);
|
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 14:32:52 +00:00
|
|
|
InsertNoDuplicates(aArray,
|
|
|
|
NS_ConvertASCIItoUTF16(nsCSSKeywords::GetStringValue(word)));
|
2013-07-15 21:28:49 +00:00
|
|
|
// Increment counter by 2, because in this table every second
|
|
|
|
// element is a nsCSSKeyword.
|
|
|
|
i += 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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 14:32:52 +00:00
|
|
|
static void GetColorsForProperty(const uint32_t aParserVariant,
|
2013-07-15 21:28:49 +00: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 14:32:52 +00:00
|
|
|
if (aParserVariant & VARIANT_COLOR) {
|
2013-07-29 12:42:51 +00: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-15 21:28:49 +00:00
|
|
|
size_t size;
|
|
|
|
const char * const *allColorNames = NS_AllColorNames(&size);
|
|
|
|
for (size_t i = 0; i < size; i++) {
|
|
|
|
CopyASCIItoUTF16(allColorNames[i], *aArray.AppendElement());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
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 14:32:52 +00: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"));
|
|
|
|
InsertNoDuplicates(aArray, NS_LITERAL_STRING("-moz-calc"));
|
|
|
|
}
|
2013-07-29 12:42:51 +00:00
|
|
|
if (aParserVariant & VARIANT_URL) {
|
|
|
|
InsertNoDuplicates(aArray, NS_LITERAL_STRING("url"));
|
|
|
|
}
|
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 14:32:52 +00:00
|
|
|
}
|
|
|
|
|
2013-07-15 21:28:49 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
inDOMUtils::GetCSSValuesForProperty(const nsAString& aProperty,
|
|
|
|
uint32_t* aLength,
|
|
|
|
PRUnichar*** aValues)
|
|
|
|
{
|
|
|
|
nsCSSProperty propertyID = nsCSSProps::LookupProperty(aProperty,
|
|
|
|
nsCSSProps::eEnabled);
|
|
|
|
if (propertyID == eCSSProperty_UNKNOWN) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsTArray<nsString> array;
|
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 14:32:52 +00:00
|
|
|
// We start collecting the values, BUT colors need to go in first, because array
|
|
|
|
// needs to stay sorted, and the colors are sorted, so we just append them.
|
2013-07-15 21:28:49 +00:00
|
|
|
if (!nsCSSProps::IsShorthand(propertyID)) {
|
|
|
|
// 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 14:32:52 +00:00
|
|
|
uint32_t propertyParserVariant = nsCSSProps::ParserVariant(propertyID);
|
|
|
|
// Get colors first.
|
|
|
|
GetColorsForProperty(propertyParserVariant, array);
|
2013-08-22 14:16:07 +00:00
|
|
|
if (propertyParserVariant & VARIANT_KEYWORD) {
|
|
|
|
GetKeywordsForProperty(propertyID, array);
|
|
|
|
}
|
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 14:32:52 +00:00
|
|
|
GetOtherValuesForProperty(propertyParserVariant, array);
|
2013-07-15 21:28:49 +00:00
|
|
|
} else {
|
|
|
|
// Property is shorthand.
|
2013-07-29 12:42:51 +00:00
|
|
|
CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(subproperty, propertyID) {
|
|
|
|
// Get colors (once) first.
|
|
|
|
uint32_t propertyParserVariant = nsCSSProps::ParserVariant(*subproperty);
|
|
|
|
if (propertyParserVariant & VARIANT_COLOR) {
|
|
|
|
GetColorsForProperty(propertyParserVariant, array);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-07-15 21:28:49 +00:00
|
|
|
CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(subproperty, propertyID) {
|
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 14:32:52 +00:00
|
|
|
uint32_t propertyParserVariant = nsCSSProps::ParserVariant(*subproperty);
|
2013-08-22 14:16:07 +00:00
|
|
|
if (propertyParserVariant & VARIANT_KEYWORD) {
|
|
|
|
GetKeywordsForProperty(*subproperty, array);
|
|
|
|
}
|
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 14:32:52 +00:00
|
|
|
GetOtherValuesForProperty(propertyParserVariant, array);
|
2013-07-15 21:28:49 +00:00
|
|
|
}
|
|
|
|
}
|
2013-10-10 00:47:40 +00:00
|
|
|
// All CSS properties take initial, inherit and unset.
|
2013-09-29 04:41:30 +00:00
|
|
|
InsertNoDuplicates(array, NS_LITERAL_STRING("initial"));
|
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 14:32:52 +00:00
|
|
|
InsertNoDuplicates(array, NS_LITERAL_STRING("inherit"));
|
2013-10-10 00:47:40 +00:00
|
|
|
InsertNoDuplicates(array, NS_LITERAL_STRING("unset"));
|
2013-07-15 21:28:49 +00:00
|
|
|
|
|
|
|
*aLength = array.Length();
|
|
|
|
PRUnichar** ret =
|
|
|
|
static_cast<PRUnichar**>(NS_Alloc(*aLength * sizeof(PRUnichar*)));
|
|
|
|
for (uint32_t i = 0; i < *aLength; ++i) {
|
|
|
|
ret[i] = ToNewUnicode(array[i]);
|
|
|
|
}
|
|
|
|
*aValues = ret;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-03-14 19:43:00 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
inDOMUtils::ColorNameToRGB(const nsAString& aColorName, JSContext* aCx,
|
|
|
|
JS::Value* aValue)
|
|
|
|
{
|
|
|
|
nscolor color;
|
|
|
|
if (!NS_ColorNameToRGB(aColorName, &color)) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
InspectorRGBTriple triple;
|
|
|
|
triple.mR = NS_GET_R(color);
|
|
|
|
triple.mG = NS_GET_G(color);
|
|
|
|
triple.mB = NS_GET_B(color);
|
|
|
|
|
2013-06-08 02:45:46 +00:00
|
|
|
if (!triple.ToObject(aCx, JS::NullPtr(),
|
|
|
|
JS::MutableHandle<JS::Value>::fromMarkedLocation(aValue))) {
|
2013-03-14 19:43:00 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-03-14 19:43:00 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
inDOMUtils::RgbToColorName(uint8_t aR, uint8_t aG, uint8_t aB,
|
|
|
|
nsAString& aColorName)
|
|
|
|
{
|
|
|
|
const char* color = NS_RGBToColorName(NS_RGB(aR, aG, aB));
|
|
|
|
if (!color) {
|
|
|
|
aColorName.Truncate();
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
aColorName.AssignASCII(color);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-05-09 16:23:57 +00:00
|
|
|
NS_IMETHODIMP
|
2006-05-17 02:38:48 +00:00
|
|
|
inDOMUtils::GetBindingURLs(nsIDOMElement *aElement, nsIArray **_retval)
|
2006-05-17 02:21:53 +00:00
|
|
|
{
|
2008-12-16 11:26:42 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aElement);
|
2009-08-10 22:52:29 +00:00
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
*_retval = nullptr;
|
2009-08-10 22:52:29 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIMutableArray> urls = do_CreateInstance(NS_ARRAY_CONTRACTID);
|
|
|
|
if (!urls)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> content = do_QueryInterface(aElement);
|
2012-11-16 23:35:06 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(content);
|
2009-08-10 22:52:29 +00:00
|
|
|
|
2013-07-17 16:05:03 +00:00
|
|
|
nsXBLBinding *binding = content->GetXBLBinding();
|
2009-08-10 22:52:29 +00:00
|
|
|
|
2011-10-18 11:19:44 +00:00
|
|
|
while (binding) {
|
|
|
|
urls->AppendElement(binding->PrototypeBinding()->BindingURI(), false);
|
|
|
|
binding = binding->GetBaseBinding();
|
2009-08-10 22:52:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_ADDREF(*_retval = urls);
|
|
|
|
return NS_OK;
|
2006-05-17 02:21:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2010-10-20 11:26:32 +00:00
|
|
|
inDOMUtils::SetContentState(nsIDOMElement *aElement, nsEventStates::InternalType aState)
|
2006-05-17 02:21:53 +00:00
|
|
|
{
|
2008-12-16 11:26:42 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aElement);
|
2012-05-09 16:23:57 +00:00
|
|
|
|
2011-04-21 17:35:52 +00:00
|
|
|
nsRefPtr<nsEventStateManager> esm = inLayoutUtils::GetEventStateManagerFor(aElement);
|
2006-05-17 02:21:53 +00:00
|
|
|
if (esm) {
|
|
|
|
nsCOMPtr<nsIContent> content;
|
|
|
|
content = do_QueryInterface(aElement);
|
2012-05-09 16:23:57 +00:00
|
|
|
|
2012-07-27 14:03:25 +00:00
|
|
|
// XXX Invalid cast of bool to nsresult (bug 778108)
|
|
|
|
return (nsresult)esm->SetContentState(content, nsEventStates(aState));
|
2006-05-17 02:21:53 +00:00
|
|
|
}
|
2012-05-09 16:23:57 +00:00
|
|
|
|
2006-05-17 02:33:42 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
2006-05-17 02:21:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2010-10-20 11:26:32 +00:00
|
|
|
inDOMUtils::GetContentState(nsIDOMElement *aElement, nsEventStates::InternalType* aState)
|
2006-05-17 02:21:53 +00:00
|
|
|
{
|
2006-05-17 02:38:49 +00:00
|
|
|
*aState = 0;
|
2011-06-01 01:46:56 +00:00
|
|
|
nsCOMPtr<nsIContent> content = do_QueryInterface(aElement);
|
|
|
|
NS_ENSURE_ARG_POINTER(content);
|
2006-05-17 02:33:42 +00:00
|
|
|
|
2011-06-01 01:46:56 +00:00
|
|
|
// NOTE: if this method is removed,
|
|
|
|
// please remove GetInternalValue from nsEventStates
|
|
|
|
*aState = content->AsElement()->State().GetInternalValue();
|
|
|
|
return NS_OK;
|
2006-05-17 02:21:53 +00:00
|
|
|
}
|
|
|
|
|
2009-08-10 22:52:29 +00:00
|
|
|
/* static */ nsresult
|
2013-11-11 08:00:41 +00:00
|
|
|
inDOMUtils::GetRuleNodeForElement(dom::Element* aElement,
|
2011-05-05 21:12:04 +00:00
|
|
|
nsIAtom* aPseudo,
|
2009-11-25 05:35:55 +00:00
|
|
|
nsStyleContext** aStyleContext,
|
|
|
|
nsRuleNode** aRuleNode)
|
2009-08-10 22:52:29 +00:00
|
|
|
{
|
2013-11-11 08:00:41 +00:00
|
|
|
MOZ_ASSERT(aElement);
|
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
*aRuleNode = nullptr;
|
|
|
|
*aStyleContext = nullptr;
|
2009-08-10 22:52:29 +00:00
|
|
|
|
2013-11-11 08:00:41 +00:00
|
|
|
nsIDocument* doc = aElement->GetDocument();
|
2009-08-10 22:52:29 +00:00
|
|
|
NS_ENSURE_TRUE(doc, NS_ERROR_UNEXPECTED);
|
|
|
|
|
2010-06-25 13:59:57 +00:00
|
|
|
nsIPresShell *presShell = doc->GetShell();
|
2009-08-10 22:52:29 +00:00
|
|
|
NS_ENSURE_TRUE(presShell, NS_ERROR_UNEXPECTED);
|
|
|
|
|
2009-12-31 15:56:33 +00:00
|
|
|
nsPresContext *presContext = presShell->GetPresContext();
|
|
|
|
NS_ENSURE_TRUE(presContext, NS_ERROR_UNEXPECTED);
|
|
|
|
|
2013-11-11 08:00:33 +00:00
|
|
|
presContext->EnsureSafeToHandOutCSSRules();
|
2009-12-31 15:56:33 +00:00
|
|
|
|
2009-08-10 22:52:29 +00:00
|
|
|
nsRefPtr<nsStyleContext> sContext =
|
2013-11-11 08:00:41 +00:00
|
|
|
nsComputedDOMStyle::GetStyleContextForElement(aElement, aPseudo, presShell);
|
2011-05-05 21:12:04 +00:00
|
|
|
if (sContext) {
|
2013-02-16 21:04:53 +00:00
|
|
|
*aRuleNode = sContext->RuleNode();
|
2011-05-05 21:12:04 +00:00
|
|
|
sContext.forget(aStyleContext);
|
|
|
|
}
|
2009-08-10 22:52:29 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2011-06-16 06:31:36 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
inDOMUtils::GetUsedFontFaces(nsIDOMRange* aRange,
|
|
|
|
nsIDOMFontFaceList** aFontFaceList)
|
|
|
|
{
|
2012-01-10 14:19:54 +00:00
|
|
|
return static_cast<nsRange*>(aRange)->GetUsedFontFaces(aFontFaceList);
|
2011-06-16 06:31:36 +00:00
|
|
|
}
|
2012-02-08 18:42:38 +00:00
|
|
|
|
|
|
|
static nsEventStates
|
|
|
|
GetStatesForPseudoClass(const nsAString& aStatePseudo)
|
|
|
|
{
|
|
|
|
// An array of the states that are relevant for various pseudoclasses.
|
|
|
|
// XXXbz this duplicates code in nsCSSRuleProcessor
|
|
|
|
static const nsEventStates sPseudoClassStates[] = {
|
2012-12-25 03:35:34 +00:00
|
|
|
#define CSS_PSEUDO_CLASS(_name, _value, _pref) \
|
2012-02-08 18:42:38 +00:00
|
|
|
nsEventStates(),
|
2012-12-25 03:35:34 +00:00
|
|
|
#define CSS_STATE_PSEUDO_CLASS(_name, _value, _pref, _states) \
|
2012-02-08 18:42:38 +00: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.
|
|
|
|
nsEventStates(),
|
|
|
|
nsEventStates()
|
|
|
|
};
|
2013-07-18 17:59:53 +00:00
|
|
|
static_assert(NS_ARRAY_LENGTH(sPseudoClassStates) ==
|
|
|
|
nsCSSPseudoClasses::ePseudoClass_NotPseudoClass + 1,
|
|
|
|
"Length of PseudoClassStates array is incorrect");
|
2012-02-08 18:42:38 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIAtom> atom = do_GetAtom(aStatePseudo);
|
|
|
|
|
|
|
|
// Ignore :moz-any-link so we don't give the element simultaneous
|
|
|
|
// visited and unvisited style state
|
|
|
|
if (nsCSSPseudoClasses::GetPseudoType(atom) ==
|
|
|
|
nsCSSPseudoClasses::ePseudoClass_mozAnyLink) {
|
|
|
|
return nsEventStates();
|
|
|
|
}
|
|
|
|
// Our array above is long enough that indexing into it with
|
|
|
|
// NotPseudoClass is ok.
|
|
|
|
return sPseudoClassStates[nsCSSPseudoClasses::GetPseudoType(atom)];
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
inDOMUtils::AddPseudoClassLock(nsIDOMElement *aElement,
|
|
|
|
const nsAString &aPseudoClass)
|
|
|
|
{
|
|
|
|
nsEventStates state = GetStatesForPseudoClass(aPseudoClass);
|
|
|
|
if (state.IsEmpty()) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<mozilla::dom::Element> element = do_QueryInterface(aElement);
|
2012-05-09 16:23:57 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(element);
|
|
|
|
|
2012-02-08 18:42:38 +00:00
|
|
|
element->LockStyleStates(state);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
inDOMUtils::RemovePseudoClassLock(nsIDOMElement *aElement,
|
|
|
|
const nsAString &aPseudoClass)
|
|
|
|
{
|
|
|
|
nsEventStates state = GetStatesForPseudoClass(aPseudoClass);
|
|
|
|
if (state.IsEmpty()) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<mozilla::dom::Element> element = do_QueryInterface(aElement);
|
2012-05-09 16:23:57 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(element);
|
|
|
|
|
2012-02-08 18:42:38 +00:00
|
|
|
element->UnlockStyleStates(state);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
inDOMUtils::HasPseudoClassLock(nsIDOMElement *aElement,
|
|
|
|
const nsAString &aPseudoClass,
|
|
|
|
bool *_retval)
|
|
|
|
{
|
|
|
|
nsEventStates state = GetStatesForPseudoClass(aPseudoClass);
|
|
|
|
if (state.IsEmpty()) {
|
|
|
|
*_retval = false;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<mozilla::dom::Element> element = do_QueryInterface(aElement);
|
2012-05-09 16:23:57 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(element);
|
|
|
|
|
2012-02-08 18:42:38 +00:00
|
|
|
nsEventStates locks = element->LockedStyleStates();
|
|
|
|
|
|
|
|
*_retval = locks.HasAllStates(state);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
inDOMUtils::ClearPseudoClassLocks(nsIDOMElement *aElement)
|
|
|
|
{
|
|
|
|
nsCOMPtr<mozilla::dom::Element> element = do_QueryInterface(aElement);
|
2012-05-09 16:23:57 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(element);
|
|
|
|
|
2012-02-08 18:42:38 +00:00
|
|
|
element->ClearStyleStateLocks();
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2012-06-03 16:54:38 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
inDOMUtils::ParseStyleSheet(nsIDOMCSSStyleSheet *aSheet,
|
|
|
|
const nsAString& aInput)
|
|
|
|
{
|
|
|
|
nsRefPtr<nsCSSStyleSheet> sheet = do_QueryObject(aSheet);
|
|
|
|
NS_ENSURE_ARG_POINTER(sheet);
|
|
|
|
|
|
|
|
return sheet->ParseSheet(aInput);
|
|
|
|
}
|