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"
|
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"
|
|
|
|
#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"
|
2011-07-20 19:18:54 +00:00
|
|
|
#include "mozilla/dom/Element.h"
|
2012-06-03 16:54:38 +00:00
|
|
|
#include "nsCSSStyleSheet.h"
|
2011-07-20 19:18:54 +00:00
|
|
|
|
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
|
|
|
|
|
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) {
|
2006-05-17 02:37:54 +00:00
|
|
|
const nsStyleText* text = frame->GetStyleText();
|
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
|
2006-05-17 02:38:00 +00:00
|
|
|
nsCOMPtr<nsIDOMDocument> doc(do_QueryInterface(aNode));
|
|
|
|
nsCOMPtr<nsIDOMNode> parent;
|
|
|
|
|
|
|
|
if (doc) {
|
|
|
|
parent = inLayoutUtils::GetContainerFor(doc);
|
|
|
|
} else if (aShowingAnonymousContent) {
|
|
|
|
nsCOMPtr<nsIContent> content = do_QueryInterface(aNode);
|
2006-07-14 12:08:59 +00:00
|
|
|
if (content) {
|
2012-07-30 14:20:58 +00:00
|
|
|
nsIContent* bparent = nullptr;
|
2007-02-16 23:02:08 +00:00
|
|
|
nsRefPtr<nsBindingManager> bindingManager = inLayoutUtils::GetBindingManagerFor(aNode);
|
2006-07-14 12:08:59 +00:00
|
|
|
if (bindingManager) {
|
2007-02-27 00:14:01 +00:00
|
|
|
bparent = bindingManager->GetInsertionParent(content);
|
2006-07-14 12:08:59 +00:00
|
|
|
}
|
2012-05-09 16:23:57 +00:00
|
|
|
|
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) {
|
|
|
|
nsRefPtr<nsBindingManager> bindingManager =
|
|
|
|
inLayoutUtils::GetBindingManagerFor(aNode);
|
|
|
|
if (bindingManager) {
|
|
|
|
bindingManager->GetAnonymousNodesFor(content, getter_AddRefs(kids));
|
|
|
|
if (!kids) {
|
|
|
|
bindingManager->GetContentListFor(content, getter_AddRefs(kids));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2006-05-17 02:37:51 +00:00
|
|
|
nsCOMPtr<nsIContent> content = do_QueryInterface(aElement);
|
2012-06-06 19:59:57 +00:00
|
|
|
NS_ENSURE_STATE(content);
|
2009-11-25 05:35:55 +00:00
|
|
|
nsRefPtr<nsStyleContext> styleContext;
|
2011-05-05 21:12:04 +00:00
|
|
|
GetRuleNodeForContent(content, pseudoElt, getter_AddRefs(styleContext), &ruleNode);
|
2006-05-17 02:38:34 +00:00
|
|
|
if (!ruleNode) {
|
|
|
|
// This can fail for content nodes that are not in the document or
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2006-05-17 02:38:08 +00:00
|
|
|
*_retval = 0;
|
2008-12-16 11:26:42 +00:00
|
|
|
|
|
|
|
NS_ENSURE_ARG_POINTER(aRule);
|
|
|
|
|
2006-05-17 02:38:08 +00:00
|
|
|
nsCOMPtr<nsICSSStyleRuleDOMWrapper> rule = do_QueryInterface(aRule);
|
2011-03-11 02:48:57 +00:00
|
|
|
nsRefPtr<mozilla::css::StyleRule> cssrule;
|
2008-12-16 11:26:42 +00:00
|
|
|
nsresult rv = rule->GetCSSStyleRule(getter_AddRefs(cssrule));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2012-07-30 14:20:58 +00:00
|
|
|
NS_ENSURE_TRUE(cssrule != nullptr, NS_ERROR_FAILURE);
|
2008-12-16 11:26:42 +00:00
|
|
|
*_retval = cssrule->GetLineNumber();
|
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;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2011-10-18 10:53:36 +00:00
|
|
|
nsIDocument *ownerDoc = content->OwnerDoc();
|
2011-10-18 11:19:44 +00:00
|
|
|
nsXBLBinding *binding = ownerDoc->BindingManager()->GetBinding(content);
|
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
|
2009-11-25 05:35:55 +00:00
|
|
|
inDOMUtils::GetRuleNodeForContent(nsIContent* aContent,
|
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
|
|
|
{
|
2012-07-30 14:20:58 +00:00
|
|
|
*aRuleNode = nullptr;
|
|
|
|
*aStyleContext = nullptr;
|
2009-08-10 22:52:29 +00:00
|
|
|
|
2010-04-30 13:12:06 +00:00
|
|
|
if (!aContent->IsElement()) {
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
2009-08-10 22:52:29 +00:00
|
|
|
nsIDocument* doc = aContent->GetDocument();
|
|
|
|
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);
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool safe = presContext->EnsureSafeToHandOutCSSRules();
|
2009-12-31 15:56:33 +00:00
|
|
|
NS_ENSURE_TRUE(safe, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
2009-08-10 22:52:29 +00:00
|
|
|
nsRefPtr<nsStyleContext> sContext =
|
2011-05-05 21:12:04 +00:00
|
|
|
nsComputedDOMStyle::GetStyleContextForElement(aContent->AsElement(), aPseudo, presShell);
|
|
|
|
if (sContext) {
|
|
|
|
*aRuleNode = sContext->GetRuleNode();
|
|
|
|
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()
|
|
|
|
};
|
2012-04-03 00:21:24 +00:00
|
|
|
MOZ_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);
|
|
|
|
}
|