зеркало из https://github.com/mozilla/gecko-dev.git
284 строки
6.9 KiB
C++
284 строки
6.9 KiB
C++
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
/* ***** 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) 1998
|
|
* the Initial Developer. All Rights Reserved.
|
|
*
|
|
* Contributor(s):
|
|
* Pierre Phaneuf <pp@ludusdesign.com>
|
|
*
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
* either of 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 ***** */
|
|
|
|
/*
|
|
* style sheet and style rule processor representing style attributes
|
|
*/
|
|
|
|
#include "nsHTMLCSSStyleSheet.h"
|
|
#include "nsCRT.h"
|
|
#include "nsIAtom.h"
|
|
#include "nsIURL.h"
|
|
#include "nsCSSPseudoElements.h"
|
|
#include "nsIStyleRule.h"
|
|
#include "nsIFrame.h"
|
|
#include "nsICSSStyleRule.h"
|
|
#include "nsIStyleRuleProcessor.h"
|
|
#include "nsPresContext.h"
|
|
#include "nsIDocument.h"
|
|
#include "nsCOMPtr.h"
|
|
#include "nsRuleWalker.h"
|
|
#include "nsRuleData.h"
|
|
#include "nsRuleProcessorData.h"
|
|
|
|
nsHTMLCSSStyleSheet::nsHTMLCSSStyleSheet()
|
|
: mRefCnt(0),
|
|
mURL(nsnull),
|
|
mDocument(nsnull)
|
|
{
|
|
}
|
|
|
|
nsHTMLCSSStyleSheet::~nsHTMLCSSStyleSheet()
|
|
{
|
|
NS_RELEASE(mURL);
|
|
}
|
|
|
|
NS_IMPL_ISUPPORTS2(nsHTMLCSSStyleSheet,
|
|
nsIStyleSheet,
|
|
nsIStyleRuleProcessor)
|
|
|
|
NS_IMETHODIMP
|
|
nsHTMLCSSStyleSheet::RulesMatching(ElementRuleProcessorData* aData)
|
|
{
|
|
nsIContent* content = aData->mContent;
|
|
|
|
// just get the one and only style rule from the content's STYLE attribute
|
|
nsICSSStyleRule* rule = content->GetInlineStyleRule();
|
|
if (rule) {
|
|
rule->RuleMatched();
|
|
aData->mRuleWalker->Forward(rule);
|
|
}
|
|
|
|
#ifdef MOZ_SMIL
|
|
rule = content->GetSMILOverrideStyleRule();
|
|
if (rule) {
|
|
if (aData->mPresContext->IsProcessingRestyles() &&
|
|
!aData->mPresContext->IsProcessingAnimationStyleChange()) {
|
|
// Non-animation restyle -- don't process SMIL override style, because we
|
|
// don't want SMIL animation to trigger new CSS transitions. Instead,
|
|
// request an Animation restyle, so we still get noticed.
|
|
aData->mPresContext->PresShell()->RestyleForAnimation(aData->mContent);
|
|
} else {
|
|
// Animation restyle (or non-restyle traversal of rules)
|
|
// Now we can walk SMIL overrride style, without triggering transitions.
|
|
rule->RuleMatched();
|
|
aData->mRuleWalker->Forward(rule);
|
|
}
|
|
}
|
|
#endif // MOZ_SMIL
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
nsHTMLCSSStyleSheet::RulesMatching(PseudoElementRuleProcessorData* aData)
|
|
{
|
|
return NS_OK;
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
nsHTMLCSSStyleSheet::RulesMatching(AnonBoxRuleProcessorData* aData)
|
|
{
|
|
return NS_OK;
|
|
}
|
|
|
|
#ifdef MOZ_XUL
|
|
NS_IMETHODIMP
|
|
nsHTMLCSSStyleSheet::RulesMatching(XULTreeRuleProcessorData* aData)
|
|
{
|
|
return NS_OK;
|
|
}
|
|
#endif
|
|
|
|
nsresult
|
|
nsHTMLCSSStyleSheet::Init(nsIURI* aURL, nsIDocument* aDocument)
|
|
{
|
|
NS_PRECONDITION(aURL && aDocument, "null ptr");
|
|
if (! aURL || ! aDocument)
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
if (mURL || mDocument)
|
|
return NS_ERROR_ALREADY_INITIALIZED;
|
|
|
|
mDocument = aDocument; // not refcounted!
|
|
mURL = aURL;
|
|
NS_ADDREF(mURL);
|
|
return NS_OK;
|
|
}
|
|
|
|
// Test if style is dependent on content state
|
|
nsRestyleHint
|
|
nsHTMLCSSStyleSheet::HasStateDependentStyle(StateRuleProcessorData* aData)
|
|
{
|
|
return nsRestyleHint(0);
|
|
}
|
|
|
|
PRBool
|
|
nsHTMLCSSStyleSheet::HasDocumentStateDependentStyle(StateRuleProcessorData* aData)
|
|
{
|
|
return PR_FALSE;
|
|
}
|
|
|
|
// Test if style is dependent on attribute
|
|
nsRestyleHint
|
|
nsHTMLCSSStyleSheet::HasAttributeDependentStyle(AttributeRuleProcessorData* aData)
|
|
{
|
|
return nsRestyleHint(0);
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
nsHTMLCSSStyleSheet::MediumFeaturesChanged(nsPresContext* aPresContext,
|
|
PRBool* aRulesChanged)
|
|
{
|
|
*aRulesChanged = PR_FALSE;
|
|
return NS_OK;
|
|
}
|
|
|
|
|
|
nsresult
|
|
nsHTMLCSSStyleSheet::Reset(nsIURI* aURL)
|
|
{
|
|
NS_IF_RELEASE(mURL);
|
|
mURL = aURL;
|
|
NS_ADDREF(mURL);
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
nsHTMLCSSStyleSheet::GetSheetURI(nsIURI** aSheetURL) const
|
|
{
|
|
NS_IF_ADDREF(mURL);
|
|
*aSheetURL = mURL;
|
|
return NS_OK;
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
nsHTMLCSSStyleSheet::GetBaseURI(nsIURI** aBaseURL) const
|
|
{
|
|
NS_IF_ADDREF(mURL);
|
|
*aBaseURL = mURL;
|
|
return NS_OK;
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
nsHTMLCSSStyleSheet::GetTitle(nsString& aTitle) const
|
|
{
|
|
aTitle.AssignLiteral("Internal HTML/CSS Style Sheet");
|
|
return NS_OK;
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
nsHTMLCSSStyleSheet::GetType(nsString& aType) const
|
|
{
|
|
aType.AssignLiteral("text/html");
|
|
return NS_OK;
|
|
}
|
|
|
|
NS_IMETHODIMP_(PRBool)
|
|
nsHTMLCSSStyleSheet::HasRules() const
|
|
{
|
|
// Say we always have rules, since we don't know.
|
|
return PR_TRUE;
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
nsHTMLCSSStyleSheet::GetApplicable(PRBool& aApplicable) const
|
|
{
|
|
aApplicable = PR_TRUE;
|
|
return NS_OK;
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
nsHTMLCSSStyleSheet::SetEnabled(PRBool aEnabled)
|
|
{ // these can't be disabled
|
|
return NS_OK;
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
nsHTMLCSSStyleSheet::GetComplete(PRBool& aComplete) const
|
|
{
|
|
aComplete = PR_TRUE;
|
|
return NS_OK;
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
nsHTMLCSSStyleSheet::SetComplete()
|
|
{
|
|
return NS_OK;
|
|
}
|
|
|
|
// style sheet owner info
|
|
NS_IMETHODIMP
|
|
nsHTMLCSSStyleSheet::GetParentSheet(nsIStyleSheet*& aParent) const
|
|
{
|
|
aParent = nsnull;
|
|
return NS_OK;
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
nsHTMLCSSStyleSheet::GetOwningDocument(nsIDocument*& aDocument) const
|
|
{
|
|
NS_IF_ADDREF(mDocument);
|
|
aDocument = mDocument;
|
|
return NS_OK;
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
nsHTMLCSSStyleSheet::SetOwningDocument(nsIDocument* aDocument)
|
|
{
|
|
mDocument = aDocument;
|
|
return NS_OK;
|
|
}
|
|
|
|
#ifdef DEBUG
|
|
void nsHTMLCSSStyleSheet::List(FILE* out, PRInt32 aIndent) const
|
|
{
|
|
// Indent
|
|
for (PRInt32 index = aIndent; --index >= 0; ) fputs(" ", out);
|
|
|
|
fputs("HTML CSS Style Sheet: ", out);
|
|
nsCAutoString urlSpec;
|
|
mURL->GetSpec(urlSpec);
|
|
if (!urlSpec.IsEmpty()) {
|
|
fputs(urlSpec.get(), out);
|
|
}
|
|
fputs("\n", out);
|
|
}
|
|
#endif
|