pjs/layout/style/nsHTMLCSSStyleSheet.cpp

263 строки
6.7 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
1998-05-14 03:42:18 +04:00
*
* 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/
1998-05-14 03:42:18 +04:00
*
* 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.
1998-05-14 03:42:18 +04:00
*
* 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"
1998-05-14 03:42:18 +04:00
#include "nsCRT.h"
#include "nsIAtom.h"
#include "nsIURL.h"
#include "nsCSSPseudoElements.h"
1998-05-14 03:42:18 +04:00
#include "nsIStyleRule.h"
1998-05-19 01:11:08 +04:00
#include "nsIFrame.h"
#include "mozilla/css/StyleRule.h"
#include "nsIStyleRuleProcessor.h"
#include "nsPresContext.h"
1998-11-26 04:34:53 +03:00
#include "nsIDocument.h"
#include "nsCOMPtr.h"
#include "nsRuleWalker.h"
#include "nsRuleData.h"
#include "nsRuleProcessorData.h"
#include "mozilla/dom/Element.h"
using namespace mozilla::dom;
namespace css = mozilla::css;
nsHTMLCSSStyleSheet::nsHTMLCSSStyleSheet()
: mDocument(nsnull)
1998-05-14 03:42:18 +04:00
{
}
NS_IMPL_ISUPPORTS2(nsHTMLCSSStyleSheet,
nsIStyleSheet,
nsIStyleRuleProcessor)
1998-05-14 03:42:18 +04:00
/* virtual */ void
nsHTMLCSSStyleSheet::RulesMatching(ElementRuleProcessorData* aData)
1998-05-14 03:42:18 +04:00
{
Element* element = aData->mElement;
// just get the one and only style rule from the content's STYLE attribute
css::StyleRule* rule = element->GetInlineStyleRule();
if (rule) {
rule->RuleMatched();
aData->mRuleWalker->Forward(rule);
}
#ifdef MOZ_SMIL
rule = element->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(element,
eRestyle_Self);
} 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
1998-05-14 03:42:18 +04:00
}
/* virtual */ void
nsHTMLCSSStyleSheet::RulesMatching(PseudoElementRuleProcessorData* aData)
{
}
/* virtual */ void
nsHTMLCSSStyleSheet::RulesMatching(AnonBoxRuleProcessorData* aData)
{
}
#ifdef MOZ_XUL
/* virtual */ void
nsHTMLCSSStyleSheet::RulesMatching(XULTreeRuleProcessorData* aData)
1998-05-19 01:11:08 +04:00
{
}
#endif
1998-05-19 01:11:08 +04:00
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;
return NS_OK;
}
1999-04-20 04:05:54 +04:00
// Test if style is dependent on content state
/* virtual */ nsRestyleHint
nsHTMLCSSStyleSheet::HasStateDependentStyle(StateRuleProcessorData* aData)
1999-04-20 04:05:54 +04:00
{
return nsRestyleHint(0);
1999-04-20 04:05:54 +04:00
}
/* virtual */ PRBool
nsHTMLCSSStyleSheet::HasDocumentStateDependentStyle(StateRuleProcessorData* aData)
{
return PR_FALSE;
}
// Test if style is dependent on attribute
/* virtual */ nsRestyleHint
nsHTMLCSSStyleSheet::HasAttributeDependentStyle(AttributeRuleProcessorData* aData)
{
// Perhaps should check that it's XUL, SVG, (or HTML) namespace, but
// it doesn't really matter.
if (aData->mAttrHasChanged && aData->mAttribute == nsGkAtoms::style) {
return eRestyle_Self;
}
return nsRestyleHint(0);
}
/* virtual */ PRBool
nsHTMLCSSStyleSheet::MediumFeaturesChanged(nsPresContext* aPresContext)
{
return PR_FALSE;
}
1999-04-20 04:05:54 +04:00
void
nsHTMLCSSStyleSheet::Reset(nsIURI* aURL)
{
mURL = aURL;
}
/* virtual */ nsIURI*
nsHTMLCSSStyleSheet::GetSheetURI() const
1998-05-14 03:42:18 +04:00
{
return mURL;
}
/* virtual */ nsIURI*
nsHTMLCSSStyleSheet::GetBaseURI() const
{
return mURL;
1998-11-26 04:34:53 +03:00
}
/* virtual */ void
nsHTMLCSSStyleSheet::GetTitle(nsString& aTitle) const
1998-11-26 04:34:53 +03:00
{
aTitle.AssignLiteral("Internal HTML/CSS Style Sheet");
1998-11-26 04:34:53 +03:00
}
/* virtual */ void
nsHTMLCSSStyleSheet::GetType(nsString& aType) const
1998-11-26 04:34:53 +03:00
{
aType.AssignLiteral("text/html");
1998-11-26 04:34:53 +03:00
}
/* virtual */ PRBool
nsHTMLCSSStyleSheet::HasRules() const
{
// Say we always have rules, since we don't know.
return PR_TRUE;
}
/* virtual */ PRBool
nsHTMLCSSStyleSheet::IsApplicable() const
1998-11-26 04:34:53 +03:00
{
return PR_TRUE;
1998-11-26 04:34:53 +03:00
}
/* virtual */ void
nsHTMLCSSStyleSheet::SetEnabled(PRBool aEnabled)
1998-11-26 04:34:53 +03:00
{ // these can't be disabled
}
/* virtual */ PRBool
nsHTMLCSSStyleSheet::IsComplete() const
{
return PR_TRUE;
}
/* virtual */ void
nsHTMLCSSStyleSheet::SetComplete()
{
}
1998-11-26 04:34:53 +03:00
// style sheet owner info
/* virtual */ nsIStyleSheet*
nsHTMLCSSStyleSheet::GetParentSheet() const
1998-11-26 04:34:53 +03:00
{
return nsnull;
1998-11-26 04:34:53 +03:00
}
/* virtual */ nsIDocument*
nsHTMLCSSStyleSheet::GetOwningDocument() const
1998-11-26 04:34:53 +03:00
{
return mDocument;
1998-11-26 04:34:53 +03:00
}
/* virtual */ void
nsHTMLCSSStyleSheet::SetOwningDocument(nsIDocument* aDocument)
1998-11-26 04:34:53 +03:00
{
mDocument = aDocument;
1998-05-14 03:42:18 +04:00
}
#ifdef DEBUG
/* virtual */ void
nsHTMLCSSStyleSheet::List(FILE* out, PRInt32 aIndent) const
1998-05-14 03:42:18 +04:00
{
// 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);
}
1998-05-14 03:42:18 +04:00
fputs("\n", out);
}
#endif