2002-02-19 05:09:06 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
// vim:cindent:ts=8:et:sw=4:
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2002
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
2003-01-02 02:53:20 +03:00
|
|
|
* L. David Baron <dbaron@dbaron.org> (original author)
|
2002-02-19 05:09:06 +03:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
2006-03-25 08:47:31 +03:00
|
|
|
/* XPCOM interface to provide some internal information to DOM inspector */
|
|
|
|
|
2002-02-19 05:09:06 +03:00
|
|
|
#include "nsInspectorCSSUtils.h"
|
2004-07-20 10:11:27 +04:00
|
|
|
#include "nsIStyleRule.h"
|
2002-02-19 05:09:06 +03:00
|
|
|
#include "nsRuleNode.h"
|
|
|
|
#include "nsString.h"
|
2007-01-30 03:06:41 +03:00
|
|
|
#include "nsGkAtoms.h"
|
2003-01-09 09:49:07 +03:00
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIPresShell.h"
|
2003-02-22 03:32:13 +03:00
|
|
|
#include "nsAutoPtr.h"
|
|
|
|
#include "nsIFrame.h"
|
2004-01-28 03:18:22 +03:00
|
|
|
#include "nsStyleSet.h"
|
2005-02-26 01:07:01 +03:00
|
|
|
#include "nsXBLBinding.h"
|
|
|
|
#include "nsXBLPrototypeBinding.h"
|
|
|
|
#include "nsIDOMElement.h"
|
2006-04-12 19:43:32 +04:00
|
|
|
#include "nsIMutableArray.h"
|
2007-02-17 02:02:08 +03:00
|
|
|
#include "nsBindingManager.h"
|
2002-02-19 05:09:06 +03:00
|
|
|
|
|
|
|
nsInspectorCSSUtils::nsInspectorCSSUtils()
|
|
|
|
{
|
|
|
|
nsCSSProps::AddRefTable();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsInspectorCSSUtils::~nsInspectorCSSUtils()
|
|
|
|
{
|
|
|
|
nsCSSProps::ReleaseTable();
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS1(nsInspectorCSSUtils, nsIInspectorCSSUtils)
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsInspectorCSSUtils::LookupCSSProperty(const nsAString& aName, nsCSSProperty *aProp)
|
|
|
|
{
|
|
|
|
*aProp = nsCSSProps::LookupProperty(aName);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsInspectorCSSUtils::GetRuleNodeParent(nsRuleNode *aNode, nsRuleNode **aParent)
|
|
|
|
{
|
|
|
|
*aParent = aNode->GetParent();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsInspectorCSSUtils::GetRuleNodeRule(nsRuleNode *aNode, nsIStyleRule **aRule)
|
|
|
|
{
|
2003-06-20 05:22:44 +04:00
|
|
|
*aRule = aNode->GetRule();
|
2003-06-28 01:06:45 +04:00
|
|
|
NS_IF_ADDREF(*aRule);
|
2003-06-20 05:22:44 +04:00
|
|
|
return NS_OK;
|
2002-02-19 05:09:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsInspectorCSSUtils::IsRuleNodeRoot(nsRuleNode *aNode, PRBool *aIsRoot)
|
|
|
|
{
|
|
|
|
*aIsRoot = aNode->IsRoot();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2004-03-29 20:00:38 +04:00
|
|
|
/* static */
|
2003-02-22 03:32:13 +03:00
|
|
|
nsStyleContext*
|
|
|
|
nsInspectorCSSUtils::GetStyleContextForFrame(nsIFrame* aFrame)
|
2002-04-20 02:29:24 +04:00
|
|
|
{
|
2003-02-22 03:32:13 +03:00
|
|
|
nsStyleContext* styleContext = aFrame->GetStyleContext();
|
|
|
|
if (!styleContext)
|
|
|
|
return nsnull;
|
2002-04-20 02:29:24 +04:00
|
|
|
|
|
|
|
/* For tables the primary frame is the "outer frame" but the style
|
|
|
|
* rules are applied to the "inner frame". Luckily, the "outer
|
|
|
|
* frame" actually inherits style from the "inner frame" so we can
|
2002-07-03 04:18:33 +04:00
|
|
|
* just move one level up in the style context hierarchy....
|
2002-04-20 02:29:24 +04:00
|
|
|
*/
|
2006-12-26 20:47:52 +03:00
|
|
|
if (aFrame->GetType() == nsGkAtoms::tableOuterFrame)
|
2003-02-22 03:32:13 +03:00
|
|
|
return styleContext->GetParent();
|
|
|
|
|
|
|
|
return styleContext;
|
2002-04-20 02:29:24 +04:00
|
|
|
}
|
2002-11-19 10:41:07 +03:00
|
|
|
|
2004-03-29 20:00:38 +04:00
|
|
|
/* static */
|
2003-02-22 03:32:13 +03:00
|
|
|
already_AddRefed<nsStyleContext>
|
2003-01-09 09:49:07 +03:00
|
|
|
nsInspectorCSSUtils::GetStyleContextForContent(nsIContent* aContent,
|
2004-03-29 20:00:38 +04:00
|
|
|
nsIAtom* aPseudo,
|
2003-02-22 03:32:13 +03:00
|
|
|
nsIPresShell* aPresShell)
|
2003-01-09 09:49:07 +03:00
|
|
|
{
|
2004-03-29 20:00:38 +04:00
|
|
|
if (!aPseudo) {
|
2007-03-23 02:01:14 +03:00
|
|
|
aPresShell->FlushPendingNotifications(Flush_StyleReresolves);
|
2005-08-23 02:24:29 +04:00
|
|
|
nsIFrame* frame = aPresShell->GetPrimaryFrameFor(aContent);
|
2004-03-29 20:00:38 +04:00
|
|
|
if (frame) {
|
|
|
|
nsStyleContext* result = GetStyleContextForFrame(frame);
|
|
|
|
// this function returns an addrefed style context
|
|
|
|
if (result)
|
|
|
|
result->AddRef();
|
|
|
|
return result;
|
|
|
|
}
|
2003-02-22 03:32:13 +03:00
|
|
|
}
|
2003-01-09 09:49:07 +03:00
|
|
|
|
2004-03-29 20:00:38 +04:00
|
|
|
// No frame has been created or we have a pseudo, so resolve the
|
|
|
|
// style ourselves
|
2003-02-22 03:32:13 +03:00
|
|
|
nsRefPtr<nsStyleContext> parentContext;
|
2004-03-29 20:00:38 +04:00
|
|
|
nsIContent* parent = aPseudo ? aContent : aContent->GetParent();
|
2003-02-22 03:32:13 +03:00
|
|
|
if (parent)
|
2004-03-29 20:00:38 +04:00
|
|
|
parentContext = GetStyleContextForContent(parent, nsnull, aPresShell);
|
2003-01-09 09:49:07 +03:00
|
|
|
|
2004-08-21 00:34:37 +04:00
|
|
|
nsPresContext *presContext = aPresShell->GetPresContext();
|
2003-02-22 03:32:13 +03:00
|
|
|
if (!presContext)
|
|
|
|
return nsnull;
|
2003-01-09 09:49:07 +03:00
|
|
|
|
2004-01-28 03:18:22 +03:00
|
|
|
nsStyleSet *styleSet = aPresShell->StyleSet();
|
|
|
|
|
2006-05-05 10:52:21 +04:00
|
|
|
if (!aContent->IsNodeOfType(nsINode::eELEMENT)) {
|
2004-03-29 20:00:38 +04:00
|
|
|
NS_ASSERTION(!aPseudo, "Shouldn't have a pseudo for a non-element!");
|
|
|
|
return styleSet->ResolveStyleForNonElement(parentContext);
|
|
|
|
}
|
2003-01-09 09:49:07 +03:00
|
|
|
|
2004-03-29 20:00:38 +04:00
|
|
|
if (aPseudo) {
|
|
|
|
return styleSet->ResolvePseudoStyleFor(aContent, aPseudo, parentContext);
|
|
|
|
}
|
|
|
|
|
|
|
|
return styleSet->ResolveStyleFor(aContent, parentContext);
|
2003-01-09 09:49:07 +03:00
|
|
|
}
|
|
|
|
|
2002-11-19 10:41:07 +03:00
|
|
|
NS_IMETHODIMP
|
2003-01-09 09:49:07 +03:00
|
|
|
nsInspectorCSSUtils::GetRuleNodeForContent(nsIContent* aContent,
|
|
|
|
nsRuleNode** aRuleNode)
|
2002-11-19 10:41:07 +03:00
|
|
|
{
|
2003-01-09 09:49:07 +03:00
|
|
|
*aRuleNode = nsnull;
|
2002-11-19 10:41:07 +03:00
|
|
|
|
2003-07-29 01:17:26 +04:00
|
|
|
nsIDocument* doc = aContent->GetDocument();
|
2003-01-09 09:49:07 +03:00
|
|
|
NS_ENSURE_TRUE(doc, NS_ERROR_UNEXPECTED);
|
2002-11-19 10:41:07 +03:00
|
|
|
|
2007-05-02 02:24:20 +04:00
|
|
|
nsIPresShell *presShell = doc->GetPrimaryShell();
|
2003-01-09 09:49:07 +03:00
|
|
|
NS_ENSURE_TRUE(presShell, NS_ERROR_UNEXPECTED);
|
|
|
|
|
2003-09-27 08:18:26 +04:00
|
|
|
nsRefPtr<nsStyleContext> sContext =
|
2004-03-29 20:00:38 +04:00
|
|
|
GetStyleContextForContent(aContent, nsnull, presShell);
|
2003-06-20 05:22:44 +04:00
|
|
|
*aRuleNode = sContext->GetRuleNode();
|
2003-02-22 03:32:13 +03:00
|
|
|
return NS_OK;
|
2002-11-19 10:41:07 +03:00
|
|
|
}
|
2005-02-26 01:07:01 +03:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsInspectorCSSUtils::GetBindingURLs(nsIDOMElement *aElement,
|
|
|
|
nsIArray **aResult)
|
|
|
|
{
|
|
|
|
*aResult = nsnull;
|
|
|
|
|
2006-04-12 19:43:32 +04:00
|
|
|
nsCOMPtr<nsIMutableArray> urls = do_CreateInstance(NS_ARRAY_CONTRACTID);
|
|
|
|
if (!urls)
|
|
|
|
return NS_ERROR_FAILURE;
|
2005-02-26 01:07:01 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> content = do_QueryInterface(aElement);
|
|
|
|
NS_ASSERTION(content, "elements must implement nsIContent");
|
|
|
|
|
|
|
|
nsIDocument *ownerDoc = content->GetOwnerDoc();
|
|
|
|
if (ownerDoc) {
|
|
|
|
nsXBLBinding *binding =
|
|
|
|
ownerDoc->BindingManager()->GetBinding(content);
|
|
|
|
|
|
|
|
while (binding) {
|
2006-04-12 19:43:32 +04:00
|
|
|
urls->AppendElement(binding->PrototypeBinding()->BindingURI(),
|
|
|
|
PR_FALSE);
|
2005-02-26 01:07:01 +03:00
|
|
|
binding = binding->GetBaseBinding();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-04-12 19:43:32 +04:00
|
|
|
NS_ADDREF(*aResult = urls);
|
|
|
|
return NS_OK;
|
2005-02-26 01:07:01 +03:00
|
|
|
}
|