1998-04-14 00:24:54 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Netscape Public License
|
|
|
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
|
|
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
|
|
|
* http://www.mozilla.org/NPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* NPL.
|
|
|
|
*
|
|
|
|
* The Initial Developer of this code under the NPL is Netscape
|
|
|
|
* Communications Corporation. Portions created by Netscape are
|
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
|
|
|
* Reserved.
|
|
|
|
*/
|
|
|
|
#include "nsIHTMLStyleSheet.h"
|
|
|
|
#include "nsIArena.h"
|
|
|
|
#include "nsCRT.h"
|
|
|
|
#include "nsIAtom.h"
|
|
|
|
#include "nsIURL.h"
|
|
|
|
#include "nsISupportsArray.h"
|
1998-09-02 06:10:44 +04:00
|
|
|
#include "nsHashtable.h"
|
1998-04-14 00:24:54 +04:00
|
|
|
#include "nsIHTMLContent.h"
|
1998-09-02 06:10:44 +04:00
|
|
|
#include "nsIHTMLAttributes.h"
|
1998-04-14 00:24:54 +04:00
|
|
|
#include "nsIStyleRule.h"
|
1998-05-19 01:11:08 +04:00
|
|
|
#include "nsIFrame.h"
|
1998-07-25 05:20:48 +04:00
|
|
|
#include "nsIStyleContext.h"
|
|
|
|
#include "nsHTMLAtoms.h"
|
|
|
|
#include "nsIPresContext.h"
|
|
|
|
#include "nsILinkHandler.h"
|
|
|
|
#include "nsIDocument.h"
|
1998-09-15 21:58:24 +04:00
|
|
|
#include "nsIHTMLTableCellElement.h"
|
1998-08-27 04:50:52 +04:00
|
|
|
#include "nsTableColFrame.h"
|
1998-09-05 08:00:06 +04:00
|
|
|
#include "nsHTMLIIDs.h"
|
1998-09-10 23:32:14 +04:00
|
|
|
#include "nsIStyleFrameConstruction.h"
|
|
|
|
#include "nsHTMLParts.h"
|
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsIViewManager.h"
|
|
|
|
#include "nsStyleConsts.h"
|
|
|
|
#include "nsTableOuterFrame.h"
|
1998-11-12 01:06:16 +03:00
|
|
|
#include "nsIXMLDocument.h"
|
1998-11-10 02:30:16 +03:00
|
|
|
#include "nsIWebShell.h"
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
static NS_DEFINE_IID(kIHTMLStyleSheetIID, NS_IHTML_STYLE_SHEET_IID);
|
|
|
|
static NS_DEFINE_IID(kIStyleSheetIID, NS_ISTYLE_SHEET_IID);
|
1998-07-25 05:20:48 +04:00
|
|
|
static NS_DEFINE_IID(kIStyleRuleIID, NS_ISTYLE_RULE_IID);
|
1998-09-10 23:32:14 +04:00
|
|
|
static NS_DEFINE_IID(kIStyleFrameConstructionIID, NS_ISTYLE_FRAME_CONSTRUCTION_IID);
|
1998-09-15 21:58:24 +04:00
|
|
|
static NS_DEFINE_IID(kIHTMLTableCellElementIID, NS_IHTMLTABLECELLELEMENT_IID);
|
1998-11-12 01:06:16 +03:00
|
|
|
static NS_DEFINE_IID(kIXMLDocumentIID, NS_IXMLDOCUMENT_IID);
|
1998-11-10 02:30:16 +03:00
|
|
|
static NS_DEFINE_IID(kIWebShellIID, NS_IWEB_SHELL_IID);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-07-25 05:20:48 +04:00
|
|
|
class HTMLAnchorRule : public nsIStyleRule {
|
|
|
|
public:
|
1998-11-26 04:34:53 +03:00
|
|
|
HTMLAnchorRule(nsIHTMLStyleSheet* aSheet);
|
1998-08-05 03:06:39 +04:00
|
|
|
~HTMLAnchorRule();
|
|
|
|
|
1998-07-25 05:20:48 +04:00
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
1998-09-02 06:10:44 +04:00
|
|
|
NS_IMETHOD Equals(const nsIStyleRule* aRule, PRBool& aValue) const;
|
|
|
|
NS_IMETHOD HashValue(PRUint32& aValue) const;
|
1998-11-26 04:34:53 +03:00
|
|
|
NS_IMETHOD GetStyleSheet(nsIStyleSheet*& aSheet) const;
|
1998-09-11 06:07:58 +04:00
|
|
|
// Strength is an out-of-band weighting, always 0 here
|
|
|
|
NS_IMETHOD GetStrength(PRInt32& aStrength);
|
1998-07-25 05:20:48 +04:00
|
|
|
|
1998-09-05 08:00:06 +04:00
|
|
|
NS_IMETHOD MapStyleInto(nsIStyleContext* aContext, nsIPresContext* aPresContext);
|
1998-07-25 05:20:48 +04:00
|
|
|
|
1998-08-30 00:20:38 +04:00
|
|
|
NS_IMETHOD List(FILE* out = stdout, PRInt32 aIndent = 0) const;
|
1998-07-25 05:20:48 +04:00
|
|
|
|
1998-11-26 04:34:53 +03:00
|
|
|
nscolor mColor;
|
|
|
|
nsIHTMLStyleSheet* mSheet;
|
1998-07-25 05:20:48 +04:00
|
|
|
};
|
|
|
|
|
1998-11-26 04:34:53 +03:00
|
|
|
HTMLAnchorRule::HTMLAnchorRule(nsIHTMLStyleSheet* aSheet)
|
|
|
|
: mSheet(aSheet)
|
1998-08-05 03:06:39 +04:00
|
|
|
{
|
|
|
|
NS_INIT_REFCNT();
|
|
|
|
}
|
|
|
|
|
|
|
|
HTMLAnchorRule::~HTMLAnchorRule()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
1998-07-25 05:20:48 +04:00
|
|
|
NS_IMPL_ISUPPORTS(HTMLAnchorRule, kIStyleRuleIID);
|
|
|
|
|
1998-09-02 06:10:44 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLAnchorRule::Equals(const nsIStyleRule* aRule, PRBool& aResult) const
|
1998-07-25 05:20:48 +04:00
|
|
|
{
|
1998-09-02 06:10:44 +04:00
|
|
|
aResult = PRBool(this == aRule);
|
|
|
|
return NS_OK;
|
1998-07-25 05:20:48 +04:00
|
|
|
}
|
|
|
|
|
1998-09-02 06:10:44 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLAnchorRule::HashValue(PRUint32& aValue) const
|
1998-07-25 05:20:48 +04:00
|
|
|
{
|
1998-09-02 06:10:44 +04:00
|
|
|
aValue = (PRUint32)(mColor);
|
|
|
|
return NS_OK;
|
1998-07-25 05:20:48 +04:00
|
|
|
}
|
|
|
|
|
1998-11-26 04:34:53 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLAnchorRule::GetStyleSheet(nsIStyleSheet*& aSheet) const
|
|
|
|
{
|
|
|
|
NS_IF_ADDREF(mSheet);
|
|
|
|
aSheet = mSheet;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-09-11 06:07:58 +04:00
|
|
|
// Strength is an out-of-band weighting, always 0 here
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLAnchorRule::GetStrength(PRInt32& aStrength)
|
|
|
|
{
|
|
|
|
aStrength = 0;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-09-02 06:10:44 +04:00
|
|
|
NS_IMETHODIMP
|
1998-09-05 08:00:06 +04:00
|
|
|
HTMLAnchorRule::MapStyleInto(nsIStyleContext* aContext, nsIPresContext* aPresContext)
|
1998-07-25 05:20:48 +04:00
|
|
|
{
|
|
|
|
nsStyleColor* styleColor = (nsStyleColor*)(aContext->GetMutableStyleData(eStyleStruct_Color));
|
|
|
|
|
|
|
|
if (nsnull != styleColor) {
|
|
|
|
styleColor->mColor = mColor;
|
|
|
|
}
|
1998-09-02 06:10:44 +04:00
|
|
|
return NS_OK;
|
1998-07-25 05:20:48 +04:00
|
|
|
}
|
|
|
|
|
1998-08-30 00:20:38 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLAnchorRule::List(FILE* out, PRInt32 aIndent) const
|
1998-07-25 05:20:48 +04:00
|
|
|
{
|
1998-08-30 00:20:38 +04:00
|
|
|
return NS_OK;
|
1998-07-25 05:20:48 +04:00
|
|
|
}
|
|
|
|
|
1998-08-27 04:50:52 +04:00
|
|
|
// -----------------------------------------------------------
|
1998-07-25 05:20:48 +04:00
|
|
|
|
1998-09-02 06:10:44 +04:00
|
|
|
class AttributeKey: public nsHashKey
|
|
|
|
{
|
|
|
|
public:
|
1998-09-05 08:00:06 +04:00
|
|
|
AttributeKey(nsMapAttributesFunc aMapFunc, nsIHTMLAttributes* aAttributes);
|
1998-09-02 06:10:44 +04:00
|
|
|
virtual ~AttributeKey(void);
|
|
|
|
|
|
|
|
PRBool Equals(const nsHashKey* aOther) const;
|
|
|
|
PRUint32 HashValue(void) const;
|
|
|
|
nsHashKey* Clone(void) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
AttributeKey(void);
|
|
|
|
AttributeKey(const AttributeKey& aCopy);
|
|
|
|
AttributeKey& operator=(const AttributeKey& aCopy);
|
|
|
|
|
|
|
|
public:
|
1998-09-05 08:00:06 +04:00
|
|
|
nsMapAttributesFunc mMapFunc;
|
1998-09-02 06:10:44 +04:00
|
|
|
nsIHTMLAttributes* mAttributes;
|
|
|
|
PRUint32 mHashSet: 1;
|
|
|
|
PRUint32 mHashCode: 31;
|
|
|
|
};
|
|
|
|
|
1998-09-05 08:00:06 +04:00
|
|
|
AttributeKey::AttributeKey(nsMapAttributesFunc aMapFunc, nsIHTMLAttributes* aAttributes)
|
|
|
|
: mMapFunc(aMapFunc),
|
1998-09-02 06:10:44 +04:00
|
|
|
mAttributes(aAttributes)
|
|
|
|
{
|
|
|
|
NS_ADDREF(mAttributes);
|
|
|
|
mHashSet = 0;
|
1998-10-08 05:32:41 +04:00
|
|
|
mHashCode = 0;
|
1998-09-02 06:10:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
AttributeKey::~AttributeKey(void)
|
|
|
|
{
|
|
|
|
NS_RELEASE(mAttributes);
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool AttributeKey::Equals(const nsHashKey* aOther) const
|
|
|
|
{
|
|
|
|
const AttributeKey* other = (const AttributeKey*)aOther;
|
1998-09-05 08:00:06 +04:00
|
|
|
if (mMapFunc == other->mMapFunc) {
|
1998-09-02 06:10:44 +04:00
|
|
|
PRBool equals;
|
|
|
|
mAttributes->Equals(other->mAttributes, equals);
|
|
|
|
return equals;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRUint32 AttributeKey::HashValue(void) const
|
|
|
|
{
|
|
|
|
if (0 == mHashSet) {
|
|
|
|
AttributeKey* self = (AttributeKey*)this; // break const
|
|
|
|
PRUint32 hash;
|
|
|
|
mAttributes->HashValue(hash);
|
|
|
|
self->mHashCode = (0x7FFFFFFF & hash);
|
1998-09-05 08:00:06 +04:00
|
|
|
self->mHashCode |= (0x7FFFFFFF & PRUint32(mMapFunc));
|
1998-09-02 06:10:44 +04:00
|
|
|
self->mHashSet = 1;
|
|
|
|
}
|
|
|
|
return mHashCode;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsHashKey* AttributeKey::Clone(void) const
|
|
|
|
{
|
1998-09-05 08:00:06 +04:00
|
|
|
AttributeKey* clown = new AttributeKey(mMapFunc, mAttributes);
|
1998-09-02 06:10:44 +04:00
|
|
|
if (nsnull != clown) {
|
|
|
|
clown->mHashSet = mHashSet;
|
|
|
|
clown->mHashCode = mHashCode;
|
|
|
|
}
|
|
|
|
return clown;
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------
|
|
|
|
|
1998-09-10 23:32:14 +04:00
|
|
|
class HTMLStyleSheetImpl : public nsIHTMLStyleSheet,
|
|
|
|
public nsIStyleFrameConstruction {
|
1998-04-14 00:24:54 +04:00
|
|
|
public:
|
|
|
|
void* operator new(size_t size);
|
|
|
|
void* operator new(size_t size, nsIArena* aArena);
|
|
|
|
void operator delete(void* ptr);
|
|
|
|
|
1998-11-26 04:34:53 +03:00
|
|
|
HTMLStyleSheetImpl(nsIURL* aURL, nsIDocument* aDocument);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr);
|
|
|
|
NS_IMETHOD_(nsrefcnt) AddRef();
|
|
|
|
NS_IMETHOD_(nsrefcnt) Release();
|
|
|
|
|
1998-11-26 04:34:53 +03:00
|
|
|
// nsIStyleSheet api
|
|
|
|
NS_IMETHOD GetURL(nsIURL*& aURL) const;
|
|
|
|
NS_IMETHOD GetTitle(nsString& aTitle) const;
|
|
|
|
NS_IMETHOD GetType(nsString& aType) const;
|
|
|
|
NS_IMETHOD GetMediumCount(PRInt32& aCount) const;
|
1998-12-02 03:38:14 +03:00
|
|
|
NS_IMETHOD GetMediumAt(PRInt32 aIndex, nsIAtom*& aMedium) const;
|
1998-11-26 04:34:53 +03:00
|
|
|
|
|
|
|
NS_IMETHOD GetEnabled(PRBool& aEnabled) const;
|
|
|
|
NS_IMETHOD SetEnabled(PRBool aEnabled);
|
|
|
|
|
|
|
|
// style sheet owner info
|
|
|
|
NS_IMETHOD GetParentSheet(nsIStyleSheet*& aParent) const; // will be null
|
|
|
|
NS_IMETHOD GetOwningDocument(nsIDocument*& aDocument) const;
|
|
|
|
|
|
|
|
NS_IMETHOD SetOwningDocument(nsIDocument* aDocumemt);
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
virtual PRInt32 RulesMatching(nsIPresContext* aPresContext,
|
|
|
|
nsIContent* aContent,
|
1998-11-03 23:33:23 +03:00
|
|
|
nsIStyleContext* aParentContext,
|
1998-04-14 00:24:54 +04:00
|
|
|
nsISupportsArray* aResults);
|
|
|
|
|
1998-05-19 01:11:08 +04:00
|
|
|
virtual PRInt32 RulesMatching(nsIPresContext* aPresContext,
|
1998-11-03 23:33:23 +03:00
|
|
|
nsIContent* aParentContent,
|
1998-05-19 01:11:08 +04:00
|
|
|
nsIAtom* aPseudoTag,
|
1998-11-03 23:33:23 +03:00
|
|
|
nsIStyleContext* aParentContext,
|
1998-05-19 01:11:08 +04:00
|
|
|
nsISupportsArray* aResults);
|
|
|
|
|
1998-07-25 05:20:48 +04:00
|
|
|
NS_IMETHOD SetLinkColor(nscolor aColor);
|
|
|
|
NS_IMETHOD SetActiveLinkColor(nscolor aColor);
|
|
|
|
NS_IMETHOD SetVisitedLinkColor(nscolor aColor);
|
|
|
|
|
1998-09-02 06:10:44 +04:00
|
|
|
// Attribute management methods, aAttributes is an in/out param
|
1998-09-05 08:00:06 +04:00
|
|
|
NS_IMETHOD SetAttributesFor(nsIHTMLContent* aContent,
|
|
|
|
nsIHTMLAttributes*& aAttributes);
|
|
|
|
NS_IMETHOD SetIDFor(nsIAtom* aID, nsIHTMLContent* aContent,
|
|
|
|
nsIHTMLAttributes*& aAttributes);
|
|
|
|
NS_IMETHOD SetClassFor(nsIAtom* aClass, nsIHTMLContent* aContent,
|
|
|
|
nsIHTMLAttributes*& aAttributes);
|
|
|
|
NS_IMETHOD SetAttributeFor(nsIAtom* aAttribute, const nsString& aValue,
|
|
|
|
nsIHTMLContent* aContent,
|
1998-09-02 06:10:44 +04:00
|
|
|
nsIHTMLAttributes*& aAttributes);
|
1998-09-05 08:00:06 +04:00
|
|
|
NS_IMETHOD SetAttributeFor(nsIAtom* aAttribute, const nsHTMLValue& aValue,
|
|
|
|
nsIHTMLContent* aContent,
|
1998-09-02 06:10:44 +04:00
|
|
|
nsIHTMLAttributes*& aAttributes);
|
1998-09-05 08:00:06 +04:00
|
|
|
NS_IMETHOD UnsetAttributeFor(nsIAtom* aAttribute, nsIHTMLContent* aContent,
|
1998-09-02 06:10:44 +04:00
|
|
|
nsIHTMLAttributes*& aAttributes);
|
|
|
|
|
1998-09-10 23:32:14 +04:00
|
|
|
NS_IMETHOD ConstructFrame(nsIPresContext* aPresContext,
|
|
|
|
nsIContent* aContent,
|
|
|
|
nsIFrame* aParentFrame,
|
|
|
|
nsIFrame*& aFrameSubTree);
|
|
|
|
|
1998-11-17 05:14:38 +03:00
|
|
|
NS_IMETHODIMP ReconstructFrames(nsIPresContext* aPresContext,
|
|
|
|
nsIContent* aContent,
|
|
|
|
nsIFrame* aParentFrame,
|
|
|
|
nsIFrame* aFrameSubTree);
|
|
|
|
|
1998-09-10 23:32:14 +04:00
|
|
|
NS_IMETHOD ContentAppended(nsIPresContext* aPresContext,
|
|
|
|
nsIContent* aContainer,
|
|
|
|
PRInt32 aNewIndexInContainer);
|
1998-09-02 06:10:44 +04:00
|
|
|
|
1998-09-18 21:18:37 +04:00
|
|
|
NS_IMETHOD ContentInserted(nsIPresContext* aPresContext,
|
|
|
|
nsIContent* aContainer,
|
|
|
|
nsIContent* aChild,
|
|
|
|
PRInt32 aIndexInContainer);
|
|
|
|
|
1998-09-26 02:47:00 +04:00
|
|
|
NS_IMETHOD ContentReplaced(nsIPresContext* aPresContext,
|
|
|
|
nsIContent* aContainer,
|
|
|
|
nsIContent* aOldChild,
|
|
|
|
nsIContent* aNewChild,
|
|
|
|
PRInt32 aIndexInContainer);
|
|
|
|
|
1998-09-25 09:13:06 +04:00
|
|
|
NS_IMETHOD ContentRemoved(nsIPresContext* aPresContext,
|
|
|
|
nsIContent* aContainer,
|
|
|
|
nsIContent* aChild,
|
|
|
|
PRInt32 aIndexInContainer);
|
|
|
|
|
1998-09-30 03:51:28 +04:00
|
|
|
NS_IMETHOD ContentChanged(nsIPresContext* aPresContext,
|
|
|
|
nsIContent* aContent,
|
|
|
|
nsISupports* aSubContent);
|
|
|
|
NS_IMETHOD AttributeChanged(nsIPresContext* aPresContext,
|
|
|
|
nsIContent* aContent,
|
|
|
|
nsIAtom* aAttribute,
|
|
|
|
PRInt32 aHint);
|
|
|
|
|
1998-11-26 04:34:53 +03:00
|
|
|
// Style change notifications
|
|
|
|
NS_IMETHOD StyleRuleChanged(nsIPresContext* aPresContext,
|
|
|
|
nsIStyleSheet* aStyleSheet,
|
|
|
|
nsIStyleRule* aStyleRule,
|
|
|
|
PRInt32 aHint); // See nsStyleConsts fot hint values
|
|
|
|
NS_IMETHOD StyleRuleAdded(nsIPresContext* aPresContext,
|
|
|
|
nsIStyleSheet* aStyleSheet,
|
|
|
|
nsIStyleRule* aStyleRule);
|
|
|
|
NS_IMETHOD StyleRuleRemoved(nsIPresContext* aPresContext,
|
|
|
|
nsIStyleSheet* aStyleSheet,
|
|
|
|
nsIStyleRule* aStyleRule);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
virtual void List(FILE* out = stdout, PRInt32 aIndent = 0) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
// These are not supported and are not implemented!
|
|
|
|
HTMLStyleSheetImpl(const HTMLStyleSheetImpl& aCopy);
|
|
|
|
HTMLStyleSheetImpl& operator=(const HTMLStyleSheetImpl& aCopy);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual ~HTMLStyleSheetImpl();
|
|
|
|
|
1998-09-02 06:10:44 +04:00
|
|
|
NS_IMETHOD EnsureSingleAttributes(nsIHTMLAttributes*& aAttributes,
|
1998-09-05 08:00:06 +04:00
|
|
|
nsMapAttributesFunc aMapFunc,
|
1998-09-02 06:10:44 +04:00
|
|
|
PRBool aCreate,
|
|
|
|
nsIHTMLAttributes*& aSingleAttrs);
|
|
|
|
NS_IMETHOD UniqueAttributes(nsIHTMLAttributes*& aSingleAttrs,
|
1998-09-05 08:00:06 +04:00
|
|
|
nsMapAttributesFunc aMapFunc,
|
1998-09-02 06:10:44 +04:00
|
|
|
PRInt32 aAttrCount,
|
|
|
|
nsIHTMLAttributes*& aAttributes);
|
|
|
|
|
1998-09-17 08:07:58 +04:00
|
|
|
nsresult ConstructRootFrame(nsIPresContext* aPresContext,
|
|
|
|
nsIContent* aContent,
|
|
|
|
nsIStyleContext* aStyleContext,
|
|
|
|
nsIFrame*& aNewFrame);
|
|
|
|
|
1998-11-17 05:14:38 +03:00
|
|
|
nsresult ConstructXMLRootDescendants(nsIPresContext* aPresContext,
|
|
|
|
nsIContent* aContent,
|
|
|
|
nsIStyleContext* aRootPseudoStyle,
|
|
|
|
nsIFrame* aParentFrame,
|
|
|
|
nsIFrame*& aNewFrame);
|
|
|
|
|
1998-11-13 02:03:35 +03:00
|
|
|
nsresult ConstructXMLRootFrame(nsIPresContext* aPresContext,
|
|
|
|
nsIContent* aContent,
|
|
|
|
nsIStyleContext* aStyleContext,
|
|
|
|
nsIFrame*& aNewFrame);
|
1998-11-12 01:06:16 +03:00
|
|
|
|
1998-09-17 08:07:58 +04:00
|
|
|
nsresult ConstructTableFrame(nsIPresContext* aPresContext,
|
|
|
|
nsIContent* aContent,
|
|
|
|
nsIFrame* aParentFrame,
|
|
|
|
nsIStyleContext* aStyleContext,
|
|
|
|
nsIFrame*& aNewFrame);
|
|
|
|
|
|
|
|
nsresult ConstructFrameByTag(nsIPresContext* aPresContext,
|
|
|
|
nsIContent* aContent,
|
|
|
|
nsIFrame* aParentFrame,
|
|
|
|
nsIAtom* aTag,
|
|
|
|
nsIStyleContext* aStyleContext,
|
|
|
|
nsIFrame*& aNewFrame);
|
|
|
|
|
|
|
|
nsresult ConstructFrameByDisplayType(nsIPresContext* aPresContext,
|
1998-10-06 04:43:48 +04:00
|
|
|
const nsStyleDisplay* aDisplay,
|
1998-09-17 08:07:58 +04:00
|
|
|
nsIContent* aContent,
|
|
|
|
nsIFrame* aParentFrame,
|
|
|
|
nsIStyleContext* aStyleContext,
|
|
|
|
nsIFrame*& aNewFrame);
|
1998-09-15 01:16:01 +04:00
|
|
|
|
1998-10-22 02:24:59 +04:00
|
|
|
nsresult GetAdjustedParentFrame(nsIFrame* aCurrentParentFrame,
|
|
|
|
PRUint8 aChildDisplayType,
|
|
|
|
nsIFrame*& aNewParentFrame);
|
|
|
|
|
|
|
|
|
1998-09-10 23:32:14 +04:00
|
|
|
nsresult ProcessChildren(nsIPresContext* aPresContext,
|
|
|
|
nsIFrame* aFrame,
|
1998-09-13 03:51:57 +04:00
|
|
|
nsIContent* aContent,
|
|
|
|
nsIFrame*& aChildList);
|
1998-09-10 23:32:14 +04:00
|
|
|
|
1998-12-03 09:31:43 +03:00
|
|
|
nsresult CreateInputFrame(nsIContent* aContent, nsIFrame*& aFrame);
|
1998-09-10 23:32:14 +04:00
|
|
|
|
1998-11-25 19:41:06 +03:00
|
|
|
PRBool IsScrollable(nsIPresContext* aPresContext, nsIAtom* aTag, const nsStyleDisplay* aDisplay);
|
1998-10-13 02:13:23 +04:00
|
|
|
|
1998-11-10 02:30:16 +03:00
|
|
|
nsIFrame* GetFrameFor(nsIPresShell* aPresShell, nsIPresContext* aPresContext,
|
|
|
|
nsIContent* aContent);
|
1998-10-30 02:25:02 +03:00
|
|
|
|
1998-10-31 02:06:14 +03:00
|
|
|
PRBool AttributeRequiresRepaint(nsIAtom* aAttribute);
|
|
|
|
PRBool AttributeRequiresReflow (nsIAtom* aAttribute);
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
protected:
|
|
|
|
PRUint32 mInHeap : 1;
|
|
|
|
PRUint32 mRefCnt : 31;
|
|
|
|
|
1998-11-26 04:34:53 +03:00
|
|
|
nsIURL* mURL;
|
|
|
|
nsIDocument* mDocument;
|
|
|
|
HTMLAnchorRule* mLinkRule;
|
|
|
|
HTMLAnchorRule* mVisitedRule;
|
|
|
|
HTMLAnchorRule* mActiveRule;
|
|
|
|
nsHashtable mAttrTable;
|
1998-09-02 06:10:44 +04:00
|
|
|
nsIHTMLAttributes* mRecycledAttrs;
|
1998-04-14 00:24:54 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
void* HTMLStyleSheetImpl::operator new(size_t size)
|
|
|
|
{
|
|
|
|
HTMLStyleSheetImpl* rv = (HTMLStyleSheetImpl*) ::operator new(size);
|
|
|
|
#ifdef NS_DEBUG
|
|
|
|
if (nsnull != rv) {
|
|
|
|
nsCRT::memset(rv, 0xEE, size);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
rv->mInHeap = 1;
|
|
|
|
return (void*) rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
void* HTMLStyleSheetImpl::operator new(size_t size, nsIArena* aArena)
|
|
|
|
{
|
|
|
|
HTMLStyleSheetImpl* rv = (HTMLStyleSheetImpl*) aArena->Alloc(PRInt32(size));
|
|
|
|
#ifdef NS_DEBUG
|
|
|
|
if (nsnull != rv) {
|
|
|
|
nsCRT::memset(rv, 0xEE, size);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
rv->mInHeap = 0;
|
|
|
|
return (void*) rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
void HTMLStyleSheetImpl::operator delete(void* ptr)
|
|
|
|
{
|
|
|
|
HTMLStyleSheetImpl* sheet = (HTMLStyleSheetImpl*) ptr;
|
|
|
|
if (nsnull != sheet) {
|
|
|
|
if (sheet->mInHeap) {
|
|
|
|
::delete ptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
1998-11-26 04:34:53 +03:00
|
|
|
HTMLStyleSheetImpl::HTMLStyleSheetImpl(nsIURL* aURL, nsIDocument* aDocument)
|
1998-04-14 00:24:54 +04:00
|
|
|
: nsIHTMLStyleSheet(),
|
1998-07-25 05:20:48 +04:00
|
|
|
mURL(aURL),
|
1998-11-26 04:34:53 +03:00
|
|
|
mDocument(aDocument),
|
1998-07-25 05:20:48 +04:00
|
|
|
mLinkRule(nsnull),
|
|
|
|
mVisitedRule(nsnull),
|
1998-09-02 06:10:44 +04:00
|
|
|
mActiveRule(nsnull),
|
|
|
|
mRecycledAttrs(nsnull)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
NS_INIT_REFCNT();
|
|
|
|
NS_ADDREF(mURL);
|
|
|
|
}
|
|
|
|
|
|
|
|
HTMLStyleSheetImpl::~HTMLStyleSheetImpl()
|
|
|
|
{
|
|
|
|
NS_RELEASE(mURL);
|
1998-11-26 04:34:53 +03:00
|
|
|
if (nsnull != mLinkRule) {
|
|
|
|
mLinkRule->mSheet = nsnull;
|
|
|
|
NS_RELEASE(mLinkRule);
|
|
|
|
}
|
|
|
|
if (nsnull != mVisitedRule) {
|
|
|
|
mVisitedRule->mSheet = nsnull;
|
|
|
|
NS_RELEASE(mVisitedRule);
|
|
|
|
}
|
|
|
|
if (nsnull != mActiveRule) {
|
|
|
|
mActiveRule->mSheet = nsnull;
|
|
|
|
NS_RELEASE(mActiveRule);
|
|
|
|
}
|
1998-09-02 06:10:44 +04:00
|
|
|
NS_IF_RELEASE(mRecycledAttrs);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF(HTMLStyleSheetImpl)
|
|
|
|
NS_IMPL_RELEASE(HTMLStyleSheetImpl)
|
|
|
|
|
|
|
|
nsresult HTMLStyleSheetImpl::QueryInterface(const nsIID& aIID,
|
|
|
|
void** aInstancePtrResult)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aInstancePtrResult, "null pointer");
|
|
|
|
if (nsnull == aInstancePtrResult) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
|
|
|
if (aIID.Equals(kIHTMLStyleSheetIID)) {
|
|
|
|
*aInstancePtrResult = (void*) ((nsIHTMLStyleSheet*)this);
|
1998-10-05 09:11:18 +04:00
|
|
|
NS_ADDREF_THIS();
|
1998-04-14 00:24:54 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
if (aIID.Equals(kIStyleSheetIID)) {
|
|
|
|
*aInstancePtrResult = (void*) ((nsIStyleSheet*)this);
|
1998-10-05 09:11:18 +04:00
|
|
|
NS_ADDREF_THIS();
|
1998-04-14 00:24:54 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-09-10 23:32:14 +04:00
|
|
|
if (aIID.Equals(kIStyleFrameConstructionIID)) {
|
|
|
|
*aInstancePtrResult = (void*) ((nsIStyleFrameConstruction*)this);
|
1998-10-05 09:11:18 +04:00
|
|
|
NS_ADDREF_THIS();
|
1998-09-10 23:32:14 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
if (aIID.Equals(kISupportsIID)) {
|
1998-09-10 23:32:14 +04:00
|
|
|
*aInstancePtrResult = (void*) this;
|
1998-10-05 09:11:18 +04:00
|
|
|
NS_ADDREF_THIS();
|
1998-04-14 00:24:54 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return NS_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32 HTMLStyleSheetImpl::RulesMatching(nsIPresContext* aPresContext,
|
|
|
|
nsIContent* aContent,
|
1998-11-03 23:33:23 +03:00
|
|
|
nsIStyleContext* aParentContext,
|
1998-04-14 00:24:54 +04:00
|
|
|
nsISupportsArray* aResults)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aPresContext, "null arg");
|
|
|
|
NS_PRECONDITION(nsnull != aContent, "null arg");
|
|
|
|
NS_PRECONDITION(nsnull != aResults, "null arg");
|
|
|
|
|
|
|
|
PRInt32 matchCount = 0;
|
|
|
|
|
1998-11-03 23:33:23 +03:00
|
|
|
nsIHTMLContent* htmlContent;
|
|
|
|
if (NS_OK == aContent->QueryInterface(kIHTMLContentIID, (void**)&htmlContent)) {
|
|
|
|
nsIAtom* tag;
|
|
|
|
htmlContent->GetTag(tag);
|
|
|
|
// if we have anchor colors, check if this is an anchor with an href
|
|
|
|
if (tag == nsHTMLAtoms::a) {
|
|
|
|
if ((nsnull != mLinkRule) || (nsnull != mVisitedRule) || (nsnull != mActiveRule)) {
|
|
|
|
// test link state
|
|
|
|
nsILinkHandler* linkHandler;
|
|
|
|
|
|
|
|
if ((NS_OK == aPresContext->GetLinkHandler(&linkHandler)) &&
|
|
|
|
(nsnull != linkHandler)) {
|
|
|
|
nsAutoString base, href; // XXX base??
|
|
|
|
nsresult attrState = htmlContent->GetAttribute("href", href);
|
|
|
|
|
|
|
|
if (NS_CONTENT_ATTR_HAS_VALUE == attrState) {
|
|
|
|
nsIURL* docURL = nsnull;
|
|
|
|
nsIDocument* doc = nsnull;
|
|
|
|
aContent->GetDocument(doc);
|
|
|
|
if (nsnull != doc) {
|
|
|
|
docURL = doc->GetDocumentURL();
|
|
|
|
NS_RELEASE(doc);
|
|
|
|
}
|
1998-07-25 05:20:48 +04:00
|
|
|
|
1998-11-03 23:33:23 +03:00
|
|
|
nsAutoString absURLSpec;
|
|
|
|
nsresult rv = NS_MakeAbsoluteURL(docURL, base, href, absURLSpec);
|
|
|
|
NS_IF_RELEASE(docURL);
|
|
|
|
|
|
|
|
nsLinkState state;
|
|
|
|
if (NS_OK == linkHandler->GetLinkState(absURLSpec, state)) {
|
|
|
|
switch (state) {
|
|
|
|
case eLinkState_Unvisited:
|
|
|
|
if (nsnull != mLinkRule) {
|
|
|
|
aResults->AppendElement(mLinkRule);
|
|
|
|
matchCount++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case eLinkState_Visited:
|
|
|
|
if (nsnull != mVisitedRule) {
|
|
|
|
aResults->AppendElement(mVisitedRule);
|
|
|
|
matchCount++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case eLinkState_Active:
|
|
|
|
if (nsnull != mActiveRule) {
|
|
|
|
aResults->AppendElement(mActiveRule);
|
|
|
|
matchCount++;
|
|
|
|
}
|
|
|
|
break;
|
1998-07-25 05:20:48 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1998-11-03 23:33:23 +03:00
|
|
|
NS_RELEASE(linkHandler);
|
1998-07-25 05:20:48 +04:00
|
|
|
}
|
1998-05-19 01:11:08 +04:00
|
|
|
}
|
1998-11-03 23:33:23 +03:00
|
|
|
} // end A tag
|
|
|
|
|
|
|
|
// just get the one and only style rule from the content
|
|
|
|
nsIStyleRule* rule;
|
1998-12-02 03:38:14 +03:00
|
|
|
htmlContent->GetContentStyleRule(rule);
|
1998-11-03 23:33:23 +03:00
|
|
|
if (nsnull != rule) {
|
|
|
|
aResults->AppendElement(rule);
|
|
|
|
NS_RELEASE(rule);
|
|
|
|
matchCount++;
|
1998-05-19 01:11:08 +04:00
|
|
|
}
|
1998-11-03 23:33:23 +03:00
|
|
|
|
|
|
|
NS_IF_RELEASE(tag);
|
|
|
|
NS_RELEASE(htmlContent);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return matchCount;
|
|
|
|
}
|
|
|
|
|
1998-05-19 01:11:08 +04:00
|
|
|
PRInt32 HTMLStyleSheetImpl::RulesMatching(nsIPresContext* aPresContext,
|
1998-11-03 23:33:23 +03:00
|
|
|
nsIContent* aParentContent,
|
1998-05-19 01:11:08 +04:00
|
|
|
nsIAtom* aPseudoTag,
|
1998-11-03 23:33:23 +03:00
|
|
|
nsIStyleContext* aParentContext,
|
1998-05-19 01:11:08 +04:00
|
|
|
nsISupportsArray* aResults)
|
|
|
|
{
|
|
|
|
// no pseudo frame style
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-11-26 04:34:53 +03:00
|
|
|
// nsIStyleSheet api
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLStyleSheetImpl::GetURL(nsIURL*& aURL) const
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1998-11-26 04:34:53 +03:00
|
|
|
NS_IF_ADDREF(mURL);
|
|
|
|
aURL = mURL;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLStyleSheetImpl::GetTitle(nsString& aTitle) const
|
|
|
|
{
|
|
|
|
aTitle.Truncate();
|
|
|
|
aTitle.Append("Internal HTML Style Sheet");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLStyleSheetImpl::GetType(nsString& aType) const
|
|
|
|
{
|
|
|
|
aType.Truncate();
|
|
|
|
aType.Append("text/html");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLStyleSheetImpl::GetMediumCount(PRInt32& aCount) const
|
|
|
|
{
|
|
|
|
aCount = 0;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1998-12-02 03:38:14 +03:00
|
|
|
HTMLStyleSheetImpl::GetMediumAt(PRInt32 aIndex, nsIAtom*& aMedium) const
|
1998-11-26 04:34:53 +03:00
|
|
|
{
|
1998-12-02 03:38:14 +03:00
|
|
|
aMedium = nsnull;
|
1998-11-26 04:34:53 +03:00
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLStyleSheetImpl::GetEnabled(PRBool& aEnabled) const
|
|
|
|
{
|
|
|
|
aEnabled = PR_TRUE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLStyleSheetImpl::SetEnabled(PRBool aEnabled)
|
|
|
|
{ // these can't be disabled
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLStyleSheetImpl::GetParentSheet(nsIStyleSheet*& aParent) const
|
|
|
|
{
|
|
|
|
aParent = nsnull;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLStyleSheetImpl::GetOwningDocument(nsIDocument*& aDocument) const
|
|
|
|
{
|
|
|
|
NS_IF_ADDREF(mDocument);
|
|
|
|
aDocument = mDocument;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLStyleSheetImpl::SetOwningDocument(nsIDocument* aDocument)
|
|
|
|
{
|
|
|
|
mDocument = aDocument;
|
|
|
|
return NS_OK;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1998-07-25 05:20:48 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP HTMLStyleSheetImpl::SetLinkColor(nscolor aColor)
|
|
|
|
{
|
|
|
|
if (nsnull == mLinkRule) {
|
1998-11-26 04:34:53 +03:00
|
|
|
mLinkRule = new HTMLAnchorRule(this);
|
1998-07-25 05:20:48 +04:00
|
|
|
if (nsnull == mLinkRule) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
NS_ADDREF(mLinkRule);
|
|
|
|
}
|
|
|
|
mLinkRule->mColor = aColor;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP HTMLStyleSheetImpl::SetActiveLinkColor(nscolor aColor)
|
|
|
|
{
|
|
|
|
if (nsnull == mActiveRule) {
|
1998-11-26 04:34:53 +03:00
|
|
|
mActiveRule = new HTMLAnchorRule(this);
|
1998-07-25 05:20:48 +04:00
|
|
|
if (nsnull == mActiveRule) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
NS_ADDREF(mActiveRule);
|
|
|
|
}
|
|
|
|
mActiveRule->mColor = aColor;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP HTMLStyleSheetImpl::SetVisitedLinkColor(nscolor aColor)
|
|
|
|
{
|
|
|
|
if (nsnull == mVisitedRule) {
|
1998-11-26 04:34:53 +03:00
|
|
|
mVisitedRule = new HTMLAnchorRule(this);
|
1998-07-25 05:20:48 +04:00
|
|
|
if (nsnull == mVisitedRule) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
NS_ADDREF(mVisitedRule);
|
|
|
|
}
|
|
|
|
mVisitedRule->mColor = aColor;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-09-05 08:00:06 +04:00
|
|
|
NS_IMETHODIMP HTMLStyleSheetImpl::SetAttributesFor(nsIHTMLContent* aContent, nsIHTMLAttributes*& aAttributes)
|
1998-09-02 06:10:44 +04:00
|
|
|
{
|
|
|
|
nsIHTMLAttributes* attrs = aAttributes;
|
|
|
|
|
|
|
|
if (nsnull != attrs) {
|
1998-09-05 08:00:06 +04:00
|
|
|
nsMapAttributesFunc mapFunc;
|
|
|
|
aContent->GetAttributeMappingFunction(mapFunc);
|
|
|
|
AttributeKey key(mapFunc, attrs);
|
1998-09-02 06:10:44 +04:00
|
|
|
nsIHTMLAttributes* sharedAttrs = (nsIHTMLAttributes*)mAttrTable.Get(&key);
|
|
|
|
if (nsnull == sharedAttrs) { // we have a new unique set
|
|
|
|
mAttrTable.Put(&key, attrs);
|
|
|
|
}
|
|
|
|
else { // found existing set
|
|
|
|
if (sharedAttrs != aAttributes) {
|
|
|
|
aAttributes->ReleaseContentRef();
|
|
|
|
NS_RELEASE(aAttributes); // release content's ref
|
|
|
|
|
|
|
|
aAttributes = sharedAttrs;
|
|
|
|
aAttributes->AddContentRef();
|
|
|
|
NS_ADDREF(aAttributes); // add ref for content
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-09-05 08:00:06 +04:00
|
|
|
NS_IMETHODIMP HTMLStyleSheetImpl::SetIDFor(nsIAtom* aID, nsIHTMLContent* aContent, nsIHTMLAttributes*& aAttributes)
|
1998-09-02 06:10:44 +04:00
|
|
|
{
|
|
|
|
nsresult result = NS_OK;
|
|
|
|
nsIHTMLAttributes* attrs;
|
|
|
|
PRBool hasValue = PRBool(nsnull != aID);
|
1998-09-05 08:00:06 +04:00
|
|
|
nsMapAttributesFunc mapFunc;
|
|
|
|
|
|
|
|
aContent->GetAttributeMappingFunction(mapFunc);
|
1998-09-02 06:10:44 +04:00
|
|
|
|
1998-09-05 08:00:06 +04:00
|
|
|
result = EnsureSingleAttributes(aAttributes, mapFunc, hasValue, attrs);
|
1998-09-02 06:10:44 +04:00
|
|
|
|
|
|
|
if ((NS_OK == result) && (nsnull != attrs)) {
|
|
|
|
PRInt32 count;
|
|
|
|
attrs->SetID(aID, count);
|
|
|
|
|
1998-09-05 08:00:06 +04:00
|
|
|
result = UniqueAttributes(attrs, mapFunc, count, aAttributes);
|
1998-09-02 06:10:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1998-09-05 08:00:06 +04:00
|
|
|
NS_IMETHODIMP HTMLStyleSheetImpl::SetClassFor(nsIAtom* aClass, nsIHTMLContent* aContent, nsIHTMLAttributes*& aAttributes)
|
1998-09-02 06:10:44 +04:00
|
|
|
{
|
|
|
|
nsresult result = NS_OK;
|
|
|
|
nsIHTMLAttributes* attrs;
|
|
|
|
PRBool hasValue = PRBool(nsnull != aClass);
|
1998-09-05 08:00:06 +04:00
|
|
|
nsMapAttributesFunc mapFunc;
|
|
|
|
|
|
|
|
aContent->GetAttributeMappingFunction(mapFunc);
|
1998-09-02 06:10:44 +04:00
|
|
|
|
1998-09-05 08:00:06 +04:00
|
|
|
result = EnsureSingleAttributes(aAttributes, mapFunc, hasValue, attrs);
|
1998-09-02 06:10:44 +04:00
|
|
|
|
|
|
|
if ((NS_OK == result) && (nsnull != attrs)) {
|
|
|
|
PRInt32 count;
|
|
|
|
attrs->SetClass(aClass, count);
|
|
|
|
|
1998-09-05 08:00:06 +04:00
|
|
|
result = UniqueAttributes(attrs, mapFunc, count, aAttributes);
|
1998-09-02 06:10:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP HTMLStyleSheetImpl::SetAttributeFor(nsIAtom* aAttribute,
|
|
|
|
const nsString& aValue,
|
1998-09-05 08:00:06 +04:00
|
|
|
nsIHTMLContent* aContent,
|
1998-09-02 06:10:44 +04:00
|
|
|
nsIHTMLAttributes*& aAttributes)
|
|
|
|
{
|
|
|
|
nsresult result = NS_OK;
|
|
|
|
nsIHTMLAttributes* attrs;
|
1998-09-05 08:00:06 +04:00
|
|
|
nsMapAttributesFunc mapFunc;
|
1998-09-02 06:10:44 +04:00
|
|
|
|
1998-09-05 08:00:06 +04:00
|
|
|
aContent->GetAttributeMappingFunction(mapFunc);
|
|
|
|
|
|
|
|
result = EnsureSingleAttributes(aAttributes, mapFunc, PR_TRUE, attrs);
|
1998-09-02 06:10:44 +04:00
|
|
|
|
|
|
|
if ((NS_OK == result) && (nsnull != attrs)) {
|
|
|
|
PRInt32 count;
|
|
|
|
attrs->SetAttribute(aAttribute, aValue, count);
|
|
|
|
|
1998-09-05 08:00:06 +04:00
|
|
|
result = UniqueAttributes(attrs, mapFunc, count, aAttributes);
|
1998-09-02 06:10:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLStyleSheetImpl::EnsureSingleAttributes(nsIHTMLAttributes*& aAttributes,
|
1998-09-05 08:00:06 +04:00
|
|
|
nsMapAttributesFunc aMapFunc,
|
1998-09-02 06:10:44 +04:00
|
|
|
PRBool aCreate,
|
|
|
|
nsIHTMLAttributes*& aSingleAttrs)
|
|
|
|
{
|
|
|
|
nsresult result = NS_OK;
|
|
|
|
PRInt32 contentRefCount;
|
|
|
|
|
|
|
|
if (nsnull == aAttributes) {
|
|
|
|
if (PR_TRUE == aCreate) {
|
|
|
|
if (nsnull != mRecycledAttrs) {
|
|
|
|
aSingleAttrs = mRecycledAttrs;
|
|
|
|
mRecycledAttrs = nsnull;
|
1998-09-05 08:00:06 +04:00
|
|
|
aSingleAttrs->SetMappingFunction(aMapFunc);
|
1998-09-02 06:10:44 +04:00
|
|
|
}
|
|
|
|
else {
|
1998-11-26 04:34:53 +03:00
|
|
|
result = NS_NewHTMLAttributes(&aSingleAttrs, this, aMapFunc);
|
1998-09-02 06:10:44 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
aSingleAttrs = nsnull;
|
|
|
|
}
|
|
|
|
contentRefCount = 0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
aSingleAttrs = aAttributes;
|
|
|
|
aSingleAttrs->GetContentRefCount(contentRefCount);
|
|
|
|
NS_ASSERTION(0 < contentRefCount, "bad content ref count");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_OK == result) {
|
|
|
|
if (1 < contentRefCount) { // already shared, copy it
|
|
|
|
result = aSingleAttrs->Clone(&aSingleAttrs);
|
|
|
|
if (NS_OK != result) {
|
|
|
|
aSingleAttrs = nsnull;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
contentRefCount = 0;
|
|
|
|
aAttributes->ReleaseContentRef();
|
|
|
|
NS_RELEASE(aAttributes);
|
|
|
|
}
|
|
|
|
else { // one content ref, ok to use, remove from table because hash may change
|
|
|
|
if (1 == contentRefCount) {
|
1998-09-05 08:00:06 +04:00
|
|
|
AttributeKey key(aMapFunc, aSingleAttrs);
|
1998-09-02 06:10:44 +04:00
|
|
|
mAttrTable.Remove(&key);
|
|
|
|
NS_ADDREF(aSingleAttrs); // add a local ref so we match up
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// at this point, content ref count is 0 or 1, and we hold a local ref
|
|
|
|
// attrs is also unique and not in the table
|
|
|
|
NS_ASSERTION(((0 == contentRefCount) && (nsnull == aAttributes)) ||
|
|
|
|
((1 == contentRefCount) && (aSingleAttrs == aAttributes)), "this is broken");
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLStyleSheetImpl::UniqueAttributes(nsIHTMLAttributes*& aSingleAttrs,
|
1998-09-05 08:00:06 +04:00
|
|
|
nsMapAttributesFunc aMapFunc,
|
1998-09-02 06:10:44 +04:00
|
|
|
PRInt32 aAttrCount,
|
|
|
|
nsIHTMLAttributes*& aAttributes)
|
|
|
|
{
|
|
|
|
nsresult result = NS_OK;
|
|
|
|
|
|
|
|
if (0 < aAttrCount) {
|
1998-09-05 08:00:06 +04:00
|
|
|
AttributeKey key(aMapFunc, aSingleAttrs);
|
1998-09-02 06:10:44 +04:00
|
|
|
nsIHTMLAttributes* sharedAttrs = (nsIHTMLAttributes*)mAttrTable.Get(&key);
|
|
|
|
if (nsnull == sharedAttrs) { // we have a new unique set
|
|
|
|
mAttrTable.Put(&key, aSingleAttrs);
|
|
|
|
if (aSingleAttrs != aAttributes) {
|
|
|
|
NS_ASSERTION(nsnull == aAttributes, "this is broken");
|
|
|
|
aAttributes = aSingleAttrs;
|
|
|
|
aAttributes->AddContentRef();
|
|
|
|
NS_ADDREF(aAttributes); // add ref for content
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else { // found existing set
|
|
|
|
NS_ASSERTION (sharedAttrs != aAttributes, "should never happen");
|
|
|
|
if (nsnull != aAttributes) {
|
|
|
|
aAttributes->ReleaseContentRef();
|
|
|
|
NS_RELEASE(aAttributes); // release content's ref
|
|
|
|
}
|
|
|
|
aAttributes = sharedAttrs;
|
|
|
|
aAttributes->AddContentRef();
|
|
|
|
NS_ADDREF(aAttributes); // add ref for content
|
|
|
|
|
|
|
|
if (nsnull == mRecycledAttrs) {
|
|
|
|
mRecycledAttrs = aSingleAttrs;
|
|
|
|
NS_ADDREF(mRecycledAttrs);
|
|
|
|
mRecycledAttrs->Reset();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else { // no attributes to store
|
|
|
|
if (nsnull != aAttributes) {
|
|
|
|
aAttributes->ReleaseContentRef();
|
|
|
|
NS_RELEASE(aAttributes);
|
|
|
|
}
|
|
|
|
if ((nsnull != aSingleAttrs) && (nsnull == mRecycledAttrs)) {
|
|
|
|
mRecycledAttrs = aSingleAttrs;
|
|
|
|
NS_ADDREF(mRecycledAttrs);
|
|
|
|
mRecycledAttrs->Reset();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
NS_IF_RELEASE(aSingleAttrs);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP HTMLStyleSheetImpl::SetAttributeFor(nsIAtom* aAttribute,
|
|
|
|
const nsHTMLValue& aValue,
|
1998-09-05 08:00:06 +04:00
|
|
|
nsIHTMLContent* aContent,
|
1998-09-02 06:10:44 +04:00
|
|
|
nsIHTMLAttributes*& aAttributes)
|
|
|
|
{
|
|
|
|
nsresult result = NS_OK;
|
|
|
|
nsIHTMLAttributes* attrs;
|
|
|
|
PRBool hasValue = PRBool(eHTMLUnit_Null != aValue.GetUnit());
|
1998-09-05 08:00:06 +04:00
|
|
|
nsMapAttributesFunc mapFunc;
|
|
|
|
|
|
|
|
aContent->GetAttributeMappingFunction(mapFunc);
|
1998-09-02 06:10:44 +04:00
|
|
|
|
1998-09-05 08:00:06 +04:00
|
|
|
result = EnsureSingleAttributes(aAttributes, mapFunc, hasValue, attrs);
|
1998-09-02 06:10:44 +04:00
|
|
|
|
|
|
|
if ((NS_OK == result) && (nsnull != attrs)) {
|
|
|
|
PRInt32 count;
|
|
|
|
attrs->SetAttribute(aAttribute, aValue, count);
|
|
|
|
|
1998-09-05 08:00:06 +04:00
|
|
|
result = UniqueAttributes(attrs, mapFunc, count, aAttributes);
|
1998-09-02 06:10:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP HTMLStyleSheetImpl::UnsetAttributeFor(nsIAtom* aAttribute,
|
1998-09-05 08:00:06 +04:00
|
|
|
nsIHTMLContent* aContent,
|
1998-09-02 06:10:44 +04:00
|
|
|
nsIHTMLAttributes*& aAttributes)
|
|
|
|
{
|
|
|
|
nsresult result = NS_OK;
|
|
|
|
nsIHTMLAttributes* attrs;
|
1998-09-05 08:00:06 +04:00
|
|
|
nsMapAttributesFunc mapFunc;
|
|
|
|
|
|
|
|
aContent->GetAttributeMappingFunction(mapFunc);
|
1998-09-02 06:10:44 +04:00
|
|
|
|
1998-09-05 08:00:06 +04:00
|
|
|
result = EnsureSingleAttributes(aAttributes, mapFunc, PR_FALSE, attrs);
|
1998-09-02 06:10:44 +04:00
|
|
|
|
|
|
|
if ((NS_OK == result) && (nsnull != attrs)) {
|
|
|
|
PRInt32 count;
|
|
|
|
attrs->UnsetAttribute(aAttribute, count);
|
|
|
|
|
1998-09-05 08:00:06 +04:00
|
|
|
result = UniqueAttributes(attrs, mapFunc, count, aAttributes);
|
1998-09-02 06:10:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
1998-09-17 08:07:58 +04:00
|
|
|
nsresult
|
|
|
|
HTMLStyleSheetImpl::ProcessChildren(nsIPresContext* aPresContext,
|
|
|
|
nsIFrame* aFrame,
|
|
|
|
nsIContent* aContent,
|
|
|
|
nsIFrame*& aChildList)
|
1998-09-10 23:32:14 +04:00
|
|
|
{
|
1998-09-13 03:51:57 +04:00
|
|
|
// Initialize OUT parameter
|
|
|
|
aChildList = nsnull;
|
|
|
|
|
|
|
|
// Iterate the child content objects and construct a frame
|
1998-09-10 23:32:14 +04:00
|
|
|
nsIFrame* lastChildFrame = nsnull;
|
|
|
|
PRInt32 count;
|
|
|
|
aContent->ChildCount(count);
|
|
|
|
for (PRInt32 i = 0; i < count; i++) {
|
|
|
|
nsIContent* childContent;
|
|
|
|
aContent->ChildAt(i, childContent);
|
|
|
|
|
|
|
|
if (nsnull != childContent) {
|
|
|
|
nsIFrame* childFrame;
|
|
|
|
|
|
|
|
// Construct a child frame
|
|
|
|
ConstructFrame(aPresContext, childContent, aFrame, childFrame);
|
|
|
|
|
|
|
|
if (nsnull != childFrame) {
|
|
|
|
// Link the frame into the child list
|
|
|
|
if (nsnull == lastChildFrame) {
|
1998-09-13 03:51:57 +04:00
|
|
|
aChildList = childFrame;
|
1998-09-10 23:32:14 +04:00
|
|
|
} else {
|
|
|
|
lastChildFrame->SetNextSibling(childFrame);
|
|
|
|
}
|
|
|
|
lastChildFrame = childFrame;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_RELEASE(childContent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
1998-12-03 09:31:43 +03:00
|
|
|
HTMLStyleSheetImpl::CreateInputFrame(nsIContent* aContent, nsIFrame*& aFrame)
|
1998-09-10 23:32:14 +04:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
// Figure out which type of input frame to create
|
|
|
|
nsAutoString val;
|
|
|
|
if (NS_OK == aContent->GetAttribute(nsAutoString("type"), val)) {
|
|
|
|
if (val.EqualsIgnoreCase("submit")) {
|
1998-12-03 09:31:43 +03:00
|
|
|
rv = NS_NewButtonControlFrame(aFrame);
|
1998-09-10 23:32:14 +04:00
|
|
|
}
|
|
|
|
else if (val.EqualsIgnoreCase("reset")) {
|
1998-12-03 09:31:43 +03:00
|
|
|
rv = NS_NewButtonControlFrame(aFrame);
|
1998-09-10 23:32:14 +04:00
|
|
|
}
|
|
|
|
else if (val.EqualsIgnoreCase("button")) {
|
1998-12-03 09:31:43 +03:00
|
|
|
rv = NS_NewButtonControlFrame(aFrame);
|
1998-09-10 23:32:14 +04:00
|
|
|
}
|
|
|
|
else if (val.EqualsIgnoreCase("checkbox")) {
|
1998-12-03 09:31:43 +03:00
|
|
|
rv = NS_NewCheckboxControlFrame(aFrame);
|
1998-09-10 23:32:14 +04:00
|
|
|
}
|
|
|
|
else if (val.EqualsIgnoreCase("file")) {
|
1998-12-03 09:31:43 +03:00
|
|
|
rv = NS_NewFileControlFrame(aFrame);
|
1998-09-10 23:32:14 +04:00
|
|
|
}
|
|
|
|
else if (val.EqualsIgnoreCase("hidden")) {
|
1998-12-03 09:31:43 +03:00
|
|
|
rv = NS_NewButtonControlFrame(aFrame);
|
1998-09-10 23:32:14 +04:00
|
|
|
}
|
|
|
|
else if (val.EqualsIgnoreCase("image")) {
|
1998-12-03 09:31:43 +03:00
|
|
|
rv = NS_NewImageControlFrame(aFrame);
|
1998-09-10 23:32:14 +04:00
|
|
|
}
|
|
|
|
else if (val.EqualsIgnoreCase("password")) {
|
1998-12-03 09:31:43 +03:00
|
|
|
rv = NS_NewTextControlFrame(aFrame);
|
1998-09-10 23:32:14 +04:00
|
|
|
}
|
|
|
|
else if (val.EqualsIgnoreCase("radio")) {
|
1998-12-03 09:31:43 +03:00
|
|
|
rv = NS_NewRadioControlFrame(aFrame);
|
1998-09-10 23:32:14 +04:00
|
|
|
}
|
|
|
|
else if (val.EqualsIgnoreCase("text")) {
|
1998-12-03 09:31:43 +03:00
|
|
|
rv = NS_NewTextControlFrame(aFrame);
|
1998-09-10 23:32:14 +04:00
|
|
|
}
|
|
|
|
else {
|
1998-12-03 09:31:43 +03:00
|
|
|
rv = NS_NewTextControlFrame(aFrame);
|
1998-09-10 23:32:14 +04:00
|
|
|
}
|
|
|
|
} else {
|
1998-12-03 09:31:43 +03:00
|
|
|
rv = NS_NewTextControlFrame(aFrame);
|
1998-09-10 23:32:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1998-09-17 08:07:58 +04:00
|
|
|
nsresult
|
1998-09-16 21:19:20 +04:00
|
|
|
HTMLStyleSheetImpl::ConstructTableFrame(nsIPresContext* aPresContext,
|
|
|
|
nsIContent* aContent,
|
|
|
|
nsIFrame* aParentFrame,
|
|
|
|
nsIStyleContext* aStyleContext,
|
1998-09-17 08:07:58 +04:00
|
|
|
nsIFrame*& aNewFrame)
|
1998-09-16 21:19:20 +04:00
|
|
|
{
|
1998-09-17 08:07:58 +04:00
|
|
|
nsIFrame* childList;
|
1998-09-16 21:19:20 +04:00
|
|
|
nsIFrame* innerFrame;
|
|
|
|
nsIFrame* innerChildList = nsnull;
|
|
|
|
nsIFrame* captionFrame = nsnull;
|
|
|
|
|
|
|
|
// Create an anonymous table outer frame which holds the caption and the
|
|
|
|
// table frame
|
1998-12-03 09:31:43 +03:00
|
|
|
NS_NewTableOuterFrame(aNewFrame);
|
|
|
|
aNewFrame->Init(*aPresContext, aContent, aParentFrame, aStyleContext);
|
1998-09-16 21:19:20 +04:00
|
|
|
|
|
|
|
// Create the inner table frame
|
1998-12-03 09:31:43 +03:00
|
|
|
NS_NewTableFrame(innerFrame);
|
1998-09-17 08:07:58 +04:00
|
|
|
childList = innerFrame;
|
1998-09-16 21:19:20 +04:00
|
|
|
|
1998-11-21 00:08:06 +03:00
|
|
|
// Have the inner table frame use a pseudo style context based on the outer table frame's
|
1998-11-21 03:53:03 +03:00
|
|
|
/* XXX: comment this back in and use this as the inner table's p-style asap
|
1998-11-21 00:08:06 +03:00
|
|
|
nsIStyleContext *innerTableStyleContext =
|
|
|
|
aPresContext->ResolvePseudoStyleContextFor (aContent,
|
|
|
|
nsHTMLAtoms::tablePseudo,
|
|
|
|
aStyleContext);
|
1998-11-21 03:53:03 +03:00
|
|
|
*/
|
1998-12-03 09:31:43 +03:00
|
|
|
innerFrame->Init(*aPresContext, aContent, aNewFrame, aStyleContext);
|
1998-11-21 00:09:54 +03:00
|
|
|
// this should be "innerTableStyleContext" but I haven't tested that thoroughly yet
|
1998-09-16 21:19:20 +04:00
|
|
|
|
|
|
|
// Iterate the child content
|
|
|
|
nsIFrame* lastChildFrame = nsnull;
|
|
|
|
PRInt32 count;
|
|
|
|
aContent->ChildCount(count);
|
|
|
|
for (PRInt32 i = 0; i < count; i++) {
|
1998-11-12 21:37:28 +03:00
|
|
|
nsIFrame* grandChildList=nsnull; // to be used only when pseudoframes need to be created
|
1998-09-16 21:19:20 +04:00
|
|
|
nsIContent* childContent;
|
|
|
|
aContent->ChildAt(i, childContent);
|
|
|
|
|
|
|
|
if (nsnull != childContent) {
|
|
|
|
nsIFrame* frame = nsnull;
|
|
|
|
nsIStyleContext* childStyleContext;
|
|
|
|
|
|
|
|
// Resolve the style context
|
1998-11-03 23:33:23 +03:00
|
|
|
childStyleContext = aPresContext->ResolveStyleContextFor(childContent, aStyleContext);
|
1998-09-16 21:19:20 +04:00
|
|
|
|
|
|
|
// See how it should be displayed
|
|
|
|
const nsStyleDisplay* styleDisplay = (const nsStyleDisplay*)
|
|
|
|
childStyleContext->GetStyleData(eStyleStruct_Display);
|
|
|
|
|
|
|
|
switch (styleDisplay->mDisplay) {
|
|
|
|
case NS_STYLE_DISPLAY_TABLE_CAPTION:
|
|
|
|
// Have we already created a caption? If so, ignore this caption
|
|
|
|
if (nsnull == captionFrame) {
|
1998-12-03 09:31:43 +03:00
|
|
|
NS_NewBodyFrame(captionFrame, NS_BODY_NO_AUTO_MARGINS);
|
|
|
|
captionFrame->Init(*aPresContext, childContent, aNewFrame, childStyleContext);
|
1998-11-10 09:05:32 +03:00
|
|
|
// Process the caption's child content and set the initial child list
|
1998-09-16 21:19:20 +04:00
|
|
|
nsIFrame* captionChildList;
|
|
|
|
ProcessChildren(aPresContext, captionFrame, childContent, captionChildList);
|
1998-11-10 09:05:32 +03:00
|
|
|
captionFrame->SetInitialChildList(*aPresContext, nsnull, captionChildList);
|
1998-09-16 21:19:20 +04:00
|
|
|
|
|
|
|
// Prepend the caption frame to the outer frame's child list
|
1998-09-20 08:50:08 +04:00
|
|
|
innerFrame->SetNextSibling(captionFrame);
|
1998-09-16 21:19:20 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_STYLE_DISPLAY_TABLE_HEADER_GROUP:
|
|
|
|
case NS_STYLE_DISPLAY_TABLE_FOOTER_GROUP:
|
|
|
|
case NS_STYLE_DISPLAY_TABLE_ROW_GROUP:
|
1998-12-03 09:31:43 +03:00
|
|
|
NS_NewTableRowGroupFrame(frame);
|
|
|
|
frame->Init(*aPresContext, childContent, innerFrame, childStyleContext);
|
1998-09-16 21:19:20 +04:00
|
|
|
break;
|
|
|
|
|
1998-11-12 23:45:28 +03:00
|
|
|
case NS_STYLE_DISPLAY_TABLE_ROW:
|
|
|
|
{
|
|
|
|
// When we're done here, "frame" will be the pseudo rowgroup frame and will be dealt with normally after the swtich.
|
|
|
|
// The row itself will have already been dealt with
|
|
|
|
nsIStyleContext* rowStyleContext;
|
|
|
|
nsIStyleContext* rowGroupStyleContext;
|
|
|
|
rowGroupStyleContext = aPresContext->ResolvePseudoStyleContextFor (childContent,
|
|
|
|
nsHTMLAtoms::columnPseudo,
|
|
|
|
aStyleContext);
|
|
|
|
nsStyleDisplay *rowGroupDisplay = (nsStyleDisplay *)rowGroupStyleContext->GetMutableStyleData(eStyleStruct_Display);
|
|
|
|
rowGroupDisplay->mDisplay = NS_STYLE_DISPLAY_TABLE_ROW_GROUP;
|
1998-12-03 09:31:43 +03:00
|
|
|
NS_NewTableRowGroupFrame(frame);
|
1998-11-12 23:45:28 +03:00
|
|
|
NS_RELEASE(childStyleContext); // we can't use this resolved style, so get rid of it
|
|
|
|
childStyleContext = rowGroupStyleContext; // the row group style context will get set to childStyleContext after the switch ends.
|
1998-12-03 09:31:43 +03:00
|
|
|
frame->Init(*aPresContext, childContent, innerFrame, childStyleContext);
|
1998-11-12 23:45:28 +03:00
|
|
|
// need to resolve the style context for the column again to be sure it's a child of the colgroup style context
|
|
|
|
rowStyleContext = aPresContext->ResolveStyleContextFor(childContent, rowGroupStyleContext);
|
|
|
|
nsIFrame *rowFrame;
|
1998-12-03 09:31:43 +03:00
|
|
|
NS_NewTableRowFrame(rowFrame);
|
|
|
|
rowFrame->Init(*aPresContext, childContent, frame, rowStyleContext);
|
1998-11-12 23:45:28 +03:00
|
|
|
rowFrame->SetInitialChildList(*aPresContext, nsnull, nsnull);
|
|
|
|
grandChildList = rowFrame;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
case NS_STYLE_DISPLAY_TABLE_CELL:
|
|
|
|
{
|
|
|
|
// When we're done here, "frame" will be the pseudo rowgroup frame and will be dealt with normally after the swtich.
|
|
|
|
// The row itself will have already been dealt with
|
|
|
|
nsIStyleContext* cellStyleContext;
|
|
|
|
nsIStyleContext* rowStyleContext;
|
|
|
|
nsIStyleContext* rowGroupStyleContext;
|
|
|
|
rowGroupStyleContext = aPresContext->ResolvePseudoStyleContextFor (childContent,
|
|
|
|
nsHTMLAtoms::columnPseudo,
|
|
|
|
aStyleContext);
|
|
|
|
nsStyleDisplay *rowGroupDisplay = (nsStyleDisplay *)rowGroupStyleContext->GetMutableStyleData(eStyleStruct_Display);
|
|
|
|
rowGroupDisplay->mDisplay = NS_STYLE_DISPLAY_TABLE_ROW_GROUP;
|
|
|
|
NS_NewTableRowGroupFrame(childContent, innerFrame, frame);
|
|
|
|
NS_RELEASE(childStyleContext); // we can't use this resolved style, so get rid of it
|
|
|
|
childStyleContext = rowGroupStyleContext; // the row group style context will get set to childStyleContext after the switch ends.
|
|
|
|
// need to resolve the style context for the column again to be sure it's a child of the colgroup style context
|
|
|
|
rowStyleContext = aPresContext->ResolveStyleContextFor(childContent, rowGroupStyleContext);
|
|
|
|
nsIFrame *rowFrame;
|
|
|
|
NS_NewTableRowFrame(childContent, frame, rowFrame);
|
|
|
|
rowFrame->SetInitialChildList(*aPresContext, nsnull, nsnull);
|
|
|
|
rowFrame->SetStyleContext(aPresContext, rowStyleContext);
|
|
|
|
grandChildList = rowFrame;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
*/
|
1998-09-16 21:19:20 +04:00
|
|
|
case NS_STYLE_DISPLAY_TABLE_COLUMN:
|
1998-11-12 21:37:28 +03:00
|
|
|
{
|
|
|
|
//XXX: Peter - please code review and remove this comment when all is well.
|
|
|
|
// When we're done here, "frame" will be the pseudo colgroup frame and will be dealt with normally after the swtich.
|
1998-11-12 23:45:28 +03:00
|
|
|
// The column itself will have already been dealt with
|
1998-11-12 21:37:28 +03:00
|
|
|
nsIStyleContext* colStyleContext;
|
|
|
|
nsIStyleContext* colGroupStyleContext;
|
|
|
|
colGroupStyleContext = aPresContext->ResolvePseudoStyleContextFor (childContent,
|
|
|
|
nsHTMLAtoms::columnPseudo,
|
|
|
|
aStyleContext);
|
|
|
|
nsStyleDisplay *colGroupDisplay = (nsStyleDisplay *)colGroupStyleContext->GetMutableStyleData(eStyleStruct_Display);
|
|
|
|
colGroupDisplay->mDisplay = NS_STYLE_DISPLAY_TABLE_COLUMN_GROUP;
|
1998-12-03 09:31:43 +03:00
|
|
|
NS_NewTableColGroupFrame(frame);
|
1998-11-12 23:45:28 +03:00
|
|
|
NS_RELEASE(childStyleContext); // we can't use this resolved style, so get rid of it
|
1998-11-12 21:37:28 +03:00
|
|
|
childStyleContext = colGroupStyleContext; // the col group style context will get set to childStyleContext after the switch ends.
|
1998-12-03 09:31:43 +03:00
|
|
|
frame->Init(*aPresContext, childContent, innerFrame, childStyleContext);
|
1998-11-12 21:37:28 +03:00
|
|
|
// need to resolve the style context for the column again to be sure it's a child of the colgroup style context
|
|
|
|
colStyleContext = aPresContext->ResolveStyleContextFor(childContent, colGroupStyleContext);
|
|
|
|
nsIFrame *colFrame;
|
1998-12-03 09:31:43 +03:00
|
|
|
NS_NewTableColFrame(colFrame);
|
|
|
|
colFrame->Init(*aPresContext, childContent, frame, colStyleContext);
|
1998-11-12 21:37:28 +03:00
|
|
|
colFrame->SetInitialChildList(*aPresContext, nsnull, nsnull);
|
|
|
|
grandChildList = colFrame;
|
1998-09-16 21:19:20 +04:00
|
|
|
break;
|
1998-11-12 21:37:28 +03:00
|
|
|
}
|
1998-09-16 21:19:20 +04:00
|
|
|
|
|
|
|
case NS_STYLE_DISPLAY_TABLE_COLUMN_GROUP:
|
1998-12-03 09:31:43 +03:00
|
|
|
NS_NewTableColGroupFrame(frame);
|
|
|
|
frame->Init(*aPresContext, childContent, innerFrame, childStyleContext);
|
1998-09-16 21:19:20 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
// XXX For the time being ignore everything else. We should deal with
|
|
|
|
// things like table cells and create anonymous frames...
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
1998-12-03 09:31:43 +03:00
|
|
|
// If it's not a caption frame, then link the frame into the inner
|
|
|
|
// frame's child list
|
1998-09-16 21:19:20 +04:00
|
|
|
if (nsnull != frame) {
|
1998-11-10 09:05:32 +03:00
|
|
|
// Process the children, and set the frame's initial child list
|
1998-11-12 23:45:28 +03:00
|
|
|
nsIFrame* childChildList;
|
1998-11-12 21:37:28 +03:00
|
|
|
if (nsnull==grandChildList)
|
|
|
|
{
|
|
|
|
ProcessChildren(aPresContext, frame, childContent, childChildList);
|
|
|
|
grandChildList = childChildList;
|
|
|
|
}
|
1998-11-12 23:45:28 +03:00
|
|
|
else
|
|
|
|
{
|
|
|
|
ProcessChildren(aPresContext, grandChildList, childContent, childChildList);
|
|
|
|
grandChildList->SetInitialChildList(*aPresContext, nsnull, childChildList);
|
|
|
|
}
|
1998-11-12 21:37:28 +03:00
|
|
|
frame->SetInitialChildList(*aPresContext, nsnull, grandChildList);
|
1998-09-16 21:19:20 +04:00
|
|
|
|
|
|
|
// Link the frame into the child list
|
|
|
|
if (nsnull == lastChildFrame) {
|
|
|
|
innerChildList = frame;
|
|
|
|
} else {
|
|
|
|
lastChildFrame->SetNextSibling(frame);
|
|
|
|
}
|
|
|
|
lastChildFrame = frame;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_RELEASE(childStyleContext);
|
|
|
|
NS_RELEASE(childContent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-11-10 09:05:32 +03:00
|
|
|
// Set the inner table frame's list of initial child frames
|
|
|
|
innerFrame->SetInitialChildList(*aPresContext, nsnull, innerChildList);
|
1998-09-16 21:19:20 +04:00
|
|
|
|
1998-11-10 09:05:32 +03:00
|
|
|
// Set the anonymous table outer frame's initial child list
|
|
|
|
aNewFrame->SetInitialChildList(*aPresContext, nsnull, childList);
|
1998-09-17 08:07:58 +04:00
|
|
|
return NS_OK;
|
1998-09-15 01:16:01 +04:00
|
|
|
}
|
1998-09-10 23:32:14 +04:00
|
|
|
|
1998-09-17 08:07:58 +04:00
|
|
|
nsresult
|
|
|
|
HTMLStyleSheetImpl::ConstructRootFrame(nsIPresContext* aPresContext,
|
|
|
|
nsIContent* aContent,
|
|
|
|
nsIStyleContext* aStyleContext,
|
|
|
|
nsIFrame*& aNewFrame)
|
1998-09-15 01:16:01 +04:00
|
|
|
{
|
|
|
|
#ifdef NS_DEBUG
|
|
|
|
nsIDocument* doc;
|
|
|
|
nsIContent* rootContent;
|
|
|
|
|
|
|
|
// Verify it's the root content object
|
|
|
|
aContent->GetDocument(doc);
|
|
|
|
rootContent = doc->GetRootContent();
|
|
|
|
NS_RELEASE(doc);
|
1998-09-24 01:55:41 +04:00
|
|
|
NS_ASSERTION(rootContent == aContent, "unexpected content");
|
1998-09-15 01:16:01 +04:00
|
|
|
NS_RELEASE(rootContent);
|
|
|
|
#endif
|
1998-09-10 23:32:14 +04:00
|
|
|
|
1998-09-17 08:07:58 +04:00
|
|
|
// Create the root frame
|
1998-12-03 09:31:43 +03:00
|
|
|
nsresult rv = NS_NewHTMLFrame(aNewFrame);
|
1998-09-16 21:19:20 +04:00
|
|
|
|
1998-09-17 08:07:58 +04:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
// Bind root frame to root view (and root window)
|
|
|
|
nsIPresShell* presShell = aPresContext->GetShell();
|
|
|
|
nsIViewManager* viewManager = presShell->GetViewManager();
|
|
|
|
nsIView* rootView;
|
|
|
|
|
|
|
|
NS_RELEASE(presShell);
|
|
|
|
viewManager->GetRootView(rootView);
|
|
|
|
aNewFrame->SetView(rootView);
|
|
|
|
NS_RELEASE(viewManager);
|
|
|
|
|
1998-12-03 09:31:43 +03:00
|
|
|
// Initialize the frame
|
|
|
|
aNewFrame->Init(*aPresContext, aContent, nsnull, aStyleContext);
|
1998-09-17 08:07:58 +04:00
|
|
|
|
1998-11-05 09:13:55 +03:00
|
|
|
// See if we're paginated
|
|
|
|
if (aPresContext->IsPaginated()) {
|
1998-11-13 07:22:23 +03:00
|
|
|
nsIFrame* scrollFrame;
|
|
|
|
nsIFrame* pageSequenceFrame;
|
|
|
|
|
|
|
|
// XXX This isn't the correct style context pseudo element to use...
|
|
|
|
nsIStyleContext* pseudoStyle;
|
|
|
|
pseudoStyle = aPresContext->ResolvePseudoStyleContextFor(aContent,
|
|
|
|
nsHTMLAtoms::columnPseudo, aStyleContext);
|
1998-11-05 09:13:55 +03:00
|
|
|
|
1998-11-09 22:40:27 +03:00
|
|
|
// Wrap the simple page sequence frame in a scroll frame
|
1998-11-13 07:22:23 +03:00
|
|
|
// XXX Only do this if it's print preview
|
1998-12-03 09:31:43 +03:00
|
|
|
if NS_SUCCEEDED(NS_NewScrollFrame(scrollFrame)) {
|
|
|
|
// Initialize the frame
|
|
|
|
scrollFrame->Init(*aPresContext, aContent, aNewFrame, pseudoStyle);
|
1998-11-09 22:40:27 +03:00
|
|
|
|
1998-11-13 07:22:23 +03:00
|
|
|
// Create a simple page sequence frame
|
1998-12-03 09:31:43 +03:00
|
|
|
rv = NS_NewSimplePageSequenceFrame(pageSequenceFrame);
|
1998-11-05 09:13:55 +03:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
1998-11-13 07:22:23 +03:00
|
|
|
nsIFrame* childList;
|
1998-09-17 08:07:58 +04:00
|
|
|
|
1998-12-03 09:31:43 +03:00
|
|
|
// Initialize the frame
|
|
|
|
pageSequenceFrame->Init(*aPresContext, aContent, scrollFrame, pseudoStyle);
|
1998-11-13 07:22:23 +03:00
|
|
|
NS_RELEASE(pseudoStyle);
|
|
|
|
|
|
|
|
// Process the child content, and set the page sequence frame's initial
|
|
|
|
// child list
|
|
|
|
rv = ProcessChildren(aPresContext, pageSequenceFrame, aContent, childList);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
pageSequenceFrame->SetInitialChildList(*aPresContext, nsnull, childList);
|
|
|
|
|
|
|
|
// Set the scroll frame's initial child list
|
|
|
|
scrollFrame->SetInitialChildList(*aPresContext, nsnull, pageSequenceFrame);
|
|
|
|
}
|
|
|
|
|
1998-11-05 09:13:55 +03:00
|
|
|
// Set the root frame's initial child list
|
1998-11-13 07:22:23 +03:00
|
|
|
aNewFrame->SetInitialChildList(*aPresContext, nsnull, scrollFrame);
|
1998-11-05 09:13:55 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
nsIFrame* childList;
|
|
|
|
|
1998-11-10 09:05:32 +03:00
|
|
|
// Process the child content, and set the frame's initial child list
|
1998-11-05 09:13:55 +03:00
|
|
|
rv = ProcessChildren(aPresContext, aNewFrame, aContent, childList);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
1998-11-10 09:05:32 +03:00
|
|
|
aNewFrame->SetInitialChildList(*aPresContext, nsnull, childList);
|
1998-11-05 09:13:55 +03:00
|
|
|
}
|
|
|
|
}
|
1998-09-17 08:07:58 +04:00
|
|
|
}
|
1998-09-17 04:19:47 +04:00
|
|
|
|
1998-11-12 01:06:16 +03:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1998-11-17 05:14:38 +03:00
|
|
|
nsresult
|
|
|
|
HTMLStyleSheetImpl::ConstructXMLRootDescendants(nsIPresContext* aPresContext,
|
|
|
|
nsIContent* aContent,
|
|
|
|
nsIStyleContext* aRootPseudoStyle,
|
|
|
|
nsIFrame* aParentFrame,
|
|
|
|
nsIFrame*& aNewFrame)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
// Create a scroll frame.
|
|
|
|
// XXX Use the rootPseudoStyle overflow style information to decide whether
|
|
|
|
// we create a scroll frame or just a body wrapper frame...
|
|
|
|
nsIFrame* scrollFrame = nsnull;
|
|
|
|
|
1998-12-03 09:31:43 +03:00
|
|
|
rv = NS_NewScrollFrame(scrollFrame);
|
1998-11-17 05:14:38 +03:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
// The scroll frame gets the root pseudo style context, and the scrolled
|
|
|
|
// frame gets a SCROLLED-CONTENT pseudo element style context.
|
|
|
|
// XXX We should probably use a different pseudo style context...
|
1998-12-03 09:31:43 +03:00
|
|
|
scrollFrame->Init(*aPresContext, nsnull, aParentFrame, aRootPseudoStyle);
|
1998-11-17 05:14:38 +03:00
|
|
|
|
|
|
|
nsIStyleContext* scrolledPseudoStyle;
|
|
|
|
nsIFrame* wrapperFrame;
|
|
|
|
|
|
|
|
scrolledPseudoStyle = aPresContext->ResolvePseudoStyleContextFor
|
|
|
|
(nsnull, nsHTMLAtoms::scrolledContentPseudo,
|
|
|
|
aRootPseudoStyle);
|
|
|
|
|
|
|
|
// Create a body frame to wrap the document element
|
1998-12-03 09:31:43 +03:00
|
|
|
NS_NewBodyFrame(wrapperFrame, NS_BODY_THE_BODY|NS_BODY_SHRINK_WRAP);
|
|
|
|
wrapperFrame->Init(*aPresContext, nsnull, scrollFrame, scrolledPseudoStyle);
|
1998-11-17 05:14:38 +03:00
|
|
|
|
|
|
|
// Construct a frame for the document element and process its children
|
|
|
|
nsIFrame* docElementFrame;
|
|
|
|
ConstructFrame(aPresContext, aContent, wrapperFrame, docElementFrame);
|
|
|
|
wrapperFrame->SetInitialChildList(*aPresContext, nsnull, docElementFrame);
|
|
|
|
|
|
|
|
// Set the scroll frame's initial child list
|
|
|
|
scrollFrame->SetInitialChildList(*aPresContext, nsnull, wrapperFrame);
|
|
|
|
}
|
|
|
|
|
|
|
|
aNewFrame = scrollFrame;
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1998-11-12 01:06:16 +03:00
|
|
|
nsresult
|
1998-11-13 02:03:35 +03:00
|
|
|
HTMLStyleSheetImpl::ConstructXMLRootFrame(nsIPresContext* aPresContext,
|
|
|
|
nsIContent* aContent,
|
|
|
|
nsIStyleContext* aStyleContext,
|
|
|
|
nsIFrame*& aNewFrame)
|
1998-11-12 01:06:16 +03:00
|
|
|
{
|
1998-11-13 06:43:15 +03:00
|
|
|
// Create the root frame. It gets a special pseudo element style.
|
|
|
|
// XXX It's wrong that the document element's style context (which is
|
|
|
|
// passed in) isn't based on the xml-root pseudo element style context
|
|
|
|
// we create below. That means that things like font information defined
|
|
|
|
// in the ua.css don't get properly inherited. We could re-resolve the
|
|
|
|
// style context, or change the flow of control so we create the style
|
|
|
|
// context rather than pass it in...
|
1998-11-13 02:03:35 +03:00
|
|
|
nsIStyleContext* rootPseudoStyle;
|
|
|
|
rootPseudoStyle = aPresContext->ResolvePseudoStyleContextFor(nsnull,
|
|
|
|
nsHTMLAtoms::xmlRootPseudo, nsnull);
|
|
|
|
|
1998-11-13 06:43:15 +03:00
|
|
|
// XXX It would be nice if we didn't need this and we made the scroll
|
|
|
|
// frame (or the body wrapper frame) the root of the frame hierarchy
|
1998-12-03 09:31:43 +03:00
|
|
|
nsresult rv = NS_NewHTMLFrame(aNewFrame);
|
1998-11-12 01:06:16 +03:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
// Bind root frame to root view (and root window)
|
|
|
|
nsIPresShell* presShell = aPresContext->GetShell();
|
|
|
|
nsIViewManager* viewManager = presShell->GetViewManager();
|
|
|
|
nsIView* rootView;
|
|
|
|
|
|
|
|
NS_RELEASE(presShell);
|
|
|
|
viewManager->GetRootView(rootView);
|
|
|
|
aNewFrame->SetView(rootView);
|
|
|
|
NS_RELEASE(viewManager);
|
|
|
|
|
1998-12-03 09:31:43 +03:00
|
|
|
// Initialize the frame
|
|
|
|
aNewFrame->Init(*aPresContext, nsnull, nsnull, rootPseudoStyle);
|
1998-11-12 01:06:16 +03:00
|
|
|
|
1998-11-13 06:43:15 +03:00
|
|
|
// Create a scroll frame.
|
|
|
|
// XXX Use the rootPseudoStyle overflow style information to decide whether
|
|
|
|
// we create a scroll frame or just a body wrapper frame...
|
1998-11-12 01:06:16 +03:00
|
|
|
nsIFrame* scrollFrame;
|
|
|
|
|
1998-11-17 05:14:38 +03:00
|
|
|
rv = ConstructXMLRootDescendants(aPresContext, aContent, rootPseudoStyle,
|
|
|
|
aNewFrame, scrollFrame);
|
1998-11-12 01:06:16 +03:00
|
|
|
|
|
|
|
// initialize the root frame
|
1998-11-17 05:14:38 +03:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
aNewFrame->SetInitialChildList(*aPresContext, nsnull, scrollFrame);
|
|
|
|
}
|
1998-11-12 01:06:16 +03:00
|
|
|
}
|
|
|
|
|
1998-11-17 05:14:38 +03:00
|
|
|
NS_IF_RELEASE(rootPseudoStyle);
|
1998-09-17 08:07:58 +04:00
|
|
|
return rv;
|
|
|
|
}
|
1998-09-10 23:32:14 +04:00
|
|
|
|
1998-09-17 08:07:58 +04:00
|
|
|
nsresult
|
|
|
|
HTMLStyleSheetImpl::ConstructFrameByTag(nsIPresContext* aPresContext,
|
|
|
|
nsIContent* aContent,
|
|
|
|
nsIFrame* aParentFrame,
|
|
|
|
nsIAtom* aTag,
|
|
|
|
nsIStyleContext* aStyleContext,
|
|
|
|
nsIFrame*& aNewFrame)
|
|
|
|
{
|
|
|
|
PRBool processChildren = PR_FALSE; // whether we should process child content
|
|
|
|
nsresult rv = NS_OK;
|
1998-09-10 23:32:14 +04:00
|
|
|
|
1998-09-17 08:07:58 +04:00
|
|
|
// Initialize OUT parameter
|
|
|
|
aNewFrame = nsnull;
|
1998-09-16 21:19:20 +04:00
|
|
|
|
1998-09-17 08:07:58 +04:00
|
|
|
if (nsnull == aTag) {
|
1998-12-03 09:31:43 +03:00
|
|
|
rv = NS_NewTextFrame(aNewFrame);
|
1998-09-17 08:07:58 +04:00
|
|
|
}
|
1998-11-13 02:55:47 +03:00
|
|
|
else {
|
|
|
|
nsIHTMLContent *htmlContent;
|
|
|
|
rv = aContent->QueryInterface(kIHTMLContentIID, (void **)&htmlContent);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
if (nsHTMLAtoms::img == aTag) {
|
1998-12-03 09:31:43 +03:00
|
|
|
rv = NS_NewImageFrame(aNewFrame);
|
1998-11-13 02:55:47 +03:00
|
|
|
}
|
|
|
|
else if (nsHTMLAtoms::hr == aTag) {
|
1998-12-03 09:31:43 +03:00
|
|
|
rv = NS_NewHRFrame(aNewFrame);
|
1998-11-13 02:55:47 +03:00
|
|
|
}
|
|
|
|
else if (nsHTMLAtoms::br == aTag) {
|
1998-12-03 09:31:43 +03:00
|
|
|
rv = NS_NewBRFrame(aNewFrame);
|
1998-11-13 02:55:47 +03:00
|
|
|
}
|
|
|
|
else if (nsHTMLAtoms::wbr == aTag) {
|
1998-12-03 09:31:43 +03:00
|
|
|
rv = NS_NewWBRFrame(aNewFrame);
|
1998-11-13 02:55:47 +03:00
|
|
|
}
|
|
|
|
else if (nsHTMLAtoms::input == aTag) {
|
1998-12-03 09:31:43 +03:00
|
|
|
rv = CreateInputFrame(aContent, aNewFrame);
|
1998-11-13 02:55:47 +03:00
|
|
|
}
|
|
|
|
else if (nsHTMLAtoms::textarea == aTag) {
|
1998-12-03 09:31:43 +03:00
|
|
|
rv = NS_NewTextControlFrame(aNewFrame);
|
1998-11-13 02:55:47 +03:00
|
|
|
}
|
|
|
|
else if (nsHTMLAtoms::select == aTag) {
|
1998-12-03 09:31:43 +03:00
|
|
|
rv = NS_NewSelectControlFrame(aNewFrame);
|
1998-11-13 02:55:47 +03:00
|
|
|
}
|
|
|
|
else if (nsHTMLAtoms::applet == aTag) {
|
1998-12-03 09:31:43 +03:00
|
|
|
rv = NS_NewObjectFrame(aNewFrame);
|
1998-11-13 02:55:47 +03:00
|
|
|
}
|
|
|
|
else if (nsHTMLAtoms::embed == aTag) {
|
1998-12-03 09:31:43 +03:00
|
|
|
rv = NS_NewObjectFrame(aNewFrame);
|
1998-11-13 02:55:47 +03:00
|
|
|
}
|
|
|
|
else if (nsHTMLAtoms::fieldset == aTag) {
|
1998-12-03 09:31:43 +03:00
|
|
|
rv = NS_NewFieldSetFrame(aNewFrame);
|
1998-11-13 02:55:47 +03:00
|
|
|
processChildren = PR_TRUE;
|
|
|
|
}
|
|
|
|
else if (nsHTMLAtoms::legend == aTag) {
|
1998-12-03 09:31:43 +03:00
|
|
|
rv = NS_NewLegendFrame(aNewFrame);
|
1998-11-13 02:55:47 +03:00
|
|
|
processChildren = PR_TRUE;
|
|
|
|
}
|
|
|
|
else if (nsHTMLAtoms::object == aTag) {
|
1998-12-03 09:31:43 +03:00
|
|
|
rv = NS_NewObjectFrame(aNewFrame);
|
1998-11-13 02:55:47 +03:00
|
|
|
}
|
|
|
|
else if (nsHTMLAtoms::body == aTag) {
|
1998-12-03 09:31:43 +03:00
|
|
|
rv = NS_NewBodyFrame(aNewFrame, NS_BODY_THE_BODY|NS_BODY_NO_AUTO_MARGINS);
|
1998-11-13 02:55:47 +03:00
|
|
|
processChildren = PR_TRUE;
|
|
|
|
}
|
|
|
|
else if (nsHTMLAtoms::form == aTag) {
|
1998-12-03 09:31:43 +03:00
|
|
|
rv = NS_NewFormFrame(aNewFrame);
|
1998-11-13 02:55:47 +03:00
|
|
|
}
|
|
|
|
else if (nsHTMLAtoms::frameset == aTag) {
|
1998-12-03 09:31:43 +03:00
|
|
|
rv = NS_NewHTMLFramesetFrame(aNewFrame);
|
1998-11-13 02:55:47 +03:00
|
|
|
}
|
|
|
|
else if (nsHTMLAtoms::iframe == aTag) {
|
1998-12-03 09:31:43 +03:00
|
|
|
rv = NS_NewHTMLFrameOuterFrame(aNewFrame);
|
1998-11-13 02:55:47 +03:00
|
|
|
}
|
|
|
|
else if (nsHTMLAtoms::spacer == aTag) {
|
1998-12-03 09:31:43 +03:00
|
|
|
rv = NS_NewSpacerFrame(aNewFrame);
|
1998-11-13 02:55:47 +03:00
|
|
|
}
|
|
|
|
else if (nsHTMLAtoms::button == aTag) {
|
1998-12-03 09:31:43 +03:00
|
|
|
rv = NS_NewHTMLButtonControlFrame(aNewFrame);
|
1998-11-13 02:55:47 +03:00
|
|
|
processChildren = PR_TRUE;
|
|
|
|
}
|
|
|
|
else if (nsHTMLAtoms::label == aTag) {
|
1998-12-03 09:31:43 +03:00
|
|
|
rv = NS_NewLabelFrame(aNewFrame);
|
1998-11-13 02:55:47 +03:00
|
|
|
processChildren = PR_TRUE;
|
|
|
|
}
|
|
|
|
NS_RELEASE(htmlContent);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
aNewFrame = nsnull;
|
|
|
|
rv = NS_OK;
|
|
|
|
}
|
1998-10-23 03:00:37 +04:00
|
|
|
}
|
1998-09-15 21:58:24 +04:00
|
|
|
|
1998-12-03 09:31:43 +03:00
|
|
|
// If we succeeded in creating a frame then initialize it, process its
|
|
|
|
// children (if requested), and set the initial child list
|
1998-09-17 08:07:58 +04:00
|
|
|
if (NS_SUCCEEDED(rv) && (nsnull != aNewFrame)) {
|
1998-12-03 09:31:43 +03:00
|
|
|
aNewFrame->Init(*aPresContext, aContent, aParentFrame, aStyleContext);
|
1998-09-17 08:07:58 +04:00
|
|
|
|
|
|
|
// Process the child content if requested
|
|
|
|
nsIFrame* childList = nsnull;
|
|
|
|
if (processChildren) {
|
|
|
|
rv = ProcessChildren(aPresContext, aNewFrame, aContent, childList);
|
1998-09-10 23:32:14 +04:00
|
|
|
}
|
1998-09-15 01:16:01 +04:00
|
|
|
|
1998-11-10 09:05:32 +03:00
|
|
|
// Set the frame's initial child list
|
|
|
|
aNewFrame->SetInitialChildList(*aPresContext, nsnull, childList);
|
1998-09-17 08:07:58 +04:00
|
|
|
}
|
1998-09-15 01:16:01 +04:00
|
|
|
|
1998-09-17 08:07:58 +04:00
|
|
|
return rv;
|
|
|
|
}
|
1998-09-16 21:19:20 +04:00
|
|
|
|
1998-09-17 08:07:58 +04:00
|
|
|
nsresult
|
1998-12-03 09:31:43 +03:00
|
|
|
HTMLStyleSheetImpl::ConstructFrameByDisplayType(nsIPresContext* aPresContext,
|
1998-10-06 04:43:48 +04:00
|
|
|
const nsStyleDisplay* aDisplay,
|
1998-12-03 09:31:43 +03:00
|
|
|
nsIContent* aContent,
|
|
|
|
nsIFrame* aParentFrame,
|
|
|
|
nsIStyleContext* aStyleContext,
|
|
|
|
nsIFrame*& aNewFrame)
|
1998-09-17 08:07:58 +04:00
|
|
|
{
|
|
|
|
PRBool processChildren = PR_FALSE; // whether we should process child content
|
|
|
|
nsresult rv = NS_OK;
|
1998-09-16 21:19:20 +04:00
|
|
|
|
1998-09-17 08:07:58 +04:00
|
|
|
// Initialize OUT parameter
|
|
|
|
aNewFrame = nsnull;
|
|
|
|
|
1998-10-06 04:43:48 +04:00
|
|
|
switch (aDisplay->mDisplay) {
|
1998-09-17 08:07:58 +04:00
|
|
|
case NS_STYLE_DISPLAY_BLOCK:
|
|
|
|
case NS_STYLE_DISPLAY_LIST_ITEM:
|
1998-11-10 02:35:44 +03:00
|
|
|
case NS_STYLE_DISPLAY_RUN_IN:
|
|
|
|
case NS_STYLE_DISPLAY_COMPACT:
|
1998-12-03 09:31:43 +03:00
|
|
|
rv = NS_NewBlockFrame(aNewFrame, 0);
|
1998-09-17 08:07:58 +04:00
|
|
|
processChildren = PR_TRUE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_STYLE_DISPLAY_INLINE:
|
1998-12-03 09:31:43 +03:00
|
|
|
rv = NS_NewInlineFrame(aNewFrame);
|
1998-09-17 08:07:58 +04:00
|
|
|
processChildren = PR_TRUE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_STYLE_DISPLAY_TABLE:
|
|
|
|
rv = ConstructTableFrame(aPresContext, aContent, aParentFrame,
|
|
|
|
aStyleContext, aNewFrame);
|
1998-12-03 09:31:43 +03:00
|
|
|
// Note: table construction function takes care of initializing the frame,
|
1998-11-10 09:05:32 +03:00
|
|
|
// processing children, and setting the initial child list
|
1998-09-17 08:07:58 +04:00
|
|
|
return rv;
|
|
|
|
|
|
|
|
case NS_STYLE_DISPLAY_TABLE_ROW_GROUP:
|
|
|
|
case NS_STYLE_DISPLAY_TABLE_HEADER_GROUP:
|
|
|
|
case NS_STYLE_DISPLAY_TABLE_FOOTER_GROUP:
|
|
|
|
// XXX We should check for being inside of a table. If there's a missing
|
|
|
|
// table then create an anonynmous table frame
|
1998-11-12 21:37:28 +03:00
|
|
|
// XXX: see ConstructTableFrame for a prototype of how this should be done,
|
|
|
|
// and propagate similar logic to other table elements
|
1998-10-22 02:24:59 +04:00
|
|
|
{
|
|
|
|
nsIFrame *parentFrame;
|
|
|
|
rv = GetAdjustedParentFrame(aParentFrame, aDisplay->mDisplay, parentFrame);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
{
|
1998-12-03 09:31:43 +03:00
|
|
|
rv = NS_NewTableRowGroupFrame(aNewFrame);
|
1998-10-22 02:24:59 +04:00
|
|
|
processChildren = PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
1998-09-17 08:07:58 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_STYLE_DISPLAY_TABLE_COLUMN:
|
|
|
|
// XXX We should check for being inside of a table column group...
|
1998-12-03 09:31:43 +03:00
|
|
|
rv = NS_NewTableColFrame(aNewFrame);
|
1998-09-17 08:07:58 +04:00
|
|
|
processChildren = PR_TRUE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_STYLE_DISPLAY_TABLE_COLUMN_GROUP:
|
|
|
|
// XXX We should check for being inside of a table...
|
1998-10-22 02:24:59 +04:00
|
|
|
{
|
|
|
|
nsIFrame *parentFrame;
|
|
|
|
rv = GetAdjustedParentFrame(aParentFrame, aDisplay->mDisplay, parentFrame);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
{
|
1998-12-03 09:31:43 +03:00
|
|
|
rv = NS_NewTableColGroupFrame(aNewFrame);
|
1998-10-22 02:24:59 +04:00
|
|
|
processChildren = PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
1998-09-17 08:07:58 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_STYLE_DISPLAY_TABLE_ROW:
|
|
|
|
// XXX We should check for being inside of a table row group...
|
1998-12-03 09:31:43 +03:00
|
|
|
rv = NS_NewTableRowFrame(aNewFrame);
|
1998-09-17 08:07:58 +04:00
|
|
|
processChildren = PR_TRUE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_STYLE_DISPLAY_TABLE_CELL:
|
|
|
|
// XXX We should check for being inside of a table row frame...
|
1998-12-03 09:31:43 +03:00
|
|
|
rv = NS_NewTableCellFrame(aNewFrame);
|
1998-09-17 08:07:58 +04:00
|
|
|
processChildren = PR_TRUE;
|
1998-10-09 23:59:45 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_STYLE_DISPLAY_TABLE_CAPTION:
|
|
|
|
// XXX We should check for being inside of a table row frame...
|
1998-12-03 09:31:43 +03:00
|
|
|
rv = NS_NewBodyFrame(aNewFrame, NS_BODY_NO_AUTO_MARGINS);
|
1998-10-09 23:59:45 +04:00
|
|
|
processChildren = PR_TRUE;
|
1998-09-17 08:07:58 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
// Don't create any frame for content that's not displayed...
|
|
|
|
break;
|
|
|
|
}
|
1998-09-16 21:19:20 +04:00
|
|
|
|
1998-12-03 09:31:43 +03:00
|
|
|
// If we succeeded in creating a frame then initialize the frame,
|
1998-09-17 08:07:58 +04:00
|
|
|
// process children (if requested), and initialize the frame
|
|
|
|
if (NS_SUCCEEDED(rv) && (nsnull != aNewFrame)) {
|
1998-12-03 09:31:43 +03:00
|
|
|
aNewFrame->Init(*aPresContext, aContent, aParentFrame, aStyleContext);
|
1998-09-16 21:19:20 +04:00
|
|
|
|
1998-09-17 08:07:58 +04:00
|
|
|
// Process the child content if requested
|
|
|
|
nsIFrame* childList = nsnull;
|
|
|
|
if (processChildren) {
|
|
|
|
rv = ProcessChildren(aPresContext, aNewFrame, aContent, childList);
|
|
|
|
}
|
1998-09-16 21:19:20 +04:00
|
|
|
|
1998-11-10 09:05:32 +03:00
|
|
|
// Set the frame's initial child list
|
|
|
|
aNewFrame->SetInitialChildList(*aPresContext, nsnull, childList);
|
1998-09-17 08:07:58 +04:00
|
|
|
}
|
1998-09-16 21:19:20 +04:00
|
|
|
|
1998-09-17 08:07:58 +04:00
|
|
|
return rv;
|
|
|
|
}
|
1998-09-16 21:19:20 +04:00
|
|
|
|
1998-10-22 02:24:59 +04:00
|
|
|
nsresult
|
|
|
|
HTMLStyleSheetImpl::GetAdjustedParentFrame(nsIFrame* aCurrentParentFrame,
|
|
|
|
PRUint8 aChildDisplayType,
|
|
|
|
nsIFrame*& aNewParentFrame)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull!=aCurrentParentFrame, "bad arg aCurrentParentFrame");
|
|
|
|
|
|
|
|
nsresult rv=NS_OK;
|
|
|
|
// by default, the new parent frame is the given current parent frame
|
|
|
|
aNewParentFrame=aCurrentParentFrame;
|
|
|
|
if (nsnull!=aCurrentParentFrame)
|
|
|
|
{
|
|
|
|
const nsStyleDisplay* currentParentDisplay;
|
|
|
|
aCurrentParentFrame->GetStyleData(eStyleStruct_Display, (const nsStyleStruct *&)currentParentDisplay);
|
|
|
|
if (NS_STYLE_DISPLAY_TABLE==currentParentDisplay->mDisplay)
|
|
|
|
{
|
|
|
|
if (NS_STYLE_DISPLAY_TABLE_CAPTION!=aChildDisplayType)
|
|
|
|
{
|
|
|
|
nsIFrame *innerTableFrame=nsnull;
|
1998-11-09 22:40:27 +03:00
|
|
|
aCurrentParentFrame->FirstChild(nsnull, innerTableFrame);
|
1998-10-22 02:24:59 +04:00
|
|
|
if (nsnull!=innerTableFrame)
|
|
|
|
{
|
|
|
|
const nsStyleDisplay* innerTableDisplay;
|
|
|
|
innerTableFrame->GetStyleData(eStyleStruct_Display, (const nsStyleStruct *&)innerTableDisplay);
|
|
|
|
if (NS_STYLE_DISPLAY_TABLE==innerTableDisplay->mDisplay)
|
|
|
|
{ // we were given the outer table frame, use the inner table frame
|
|
|
|
aNewParentFrame=innerTableFrame;
|
|
|
|
}
|
|
|
|
// else we were already given the inner table frame
|
|
|
|
}
|
|
|
|
// else the current parent has no children and cannot be an outer table frame
|
|
|
|
}
|
|
|
|
// else the child is a caption and really belongs to the outer table frame
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (NS_STYLE_DISPLAY_TABLE_CAPTION ==aChildDisplayType ||
|
|
|
|
NS_STYLE_DISPLAY_TABLE_ROW_GROUP ==aChildDisplayType ||
|
|
|
|
NS_STYLE_DISPLAY_TABLE_HEADER_GROUP==aChildDisplayType ||
|
|
|
|
NS_STYLE_DISPLAY_TABLE_FOOTER_GROUP==aChildDisplayType ||
|
|
|
|
NS_STYLE_DISPLAY_TABLE_COLUMN_GROUP==aChildDisplayType)
|
|
|
|
{ // we need to create an anonymous table frame (outer and inner) around the new frame
|
|
|
|
NS_NOTYETIMPLEMENTED("anonymous table frame as parent of table content not yet implemented.");
|
|
|
|
rv = NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
rv = NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
NS_POSTCONDITION(nsnull!=aNewParentFrame, "bad result null aNewParentFrame");
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1998-10-13 02:13:23 +04:00
|
|
|
PRBool
|
1998-11-25 19:41:06 +03:00
|
|
|
HTMLStyleSheetImpl::IsScrollable(nsIPresContext* aPresContext,
|
|
|
|
nsIAtom* aTag,
|
|
|
|
const nsStyleDisplay* aDisplay)
|
1998-10-13 02:13:23 +04:00
|
|
|
{
|
1998-11-01 04:29:00 +03:00
|
|
|
// For the time being it's scrollable if the overflow property is auto or
|
1998-11-11 09:37:30 +03:00
|
|
|
// scroll, regardless of whether the width or height is fixed in size
|
|
|
|
PRInt32 scrolling = -1;
|
1998-11-25 19:41:06 +03:00
|
|
|
|
|
|
|
if (nsHTMLAtoms::body == aTag) {
|
|
|
|
// XXX temporary hack: For body tags we check our webshell and see
|
|
|
|
// if scrolling is enabled there. This needs to go away!
|
|
|
|
nsISupports* container;
|
|
|
|
if (nsnull != aPresContext) {
|
|
|
|
aPresContext->GetContainer(&container);
|
|
|
|
if (nsnull != container) {
|
|
|
|
nsIWebShell* webShell = nsnull;
|
|
|
|
container->QueryInterface(kIWebShellIID, (void**) &webShell);
|
|
|
|
if (nsnull != webShell) {
|
|
|
|
webShell->GetScrolling(scrolling);
|
|
|
|
NS_RELEASE(webShell);
|
|
|
|
}
|
|
|
|
NS_RELEASE(container);
|
1998-11-10 02:30:16 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (-1 == scrolling) {
|
|
|
|
scrolling = aDisplay->mOverflow;
|
|
|
|
}
|
|
|
|
if ((NS_STYLE_OVERFLOW_SCROLL == scrolling) ||
|
|
|
|
(NS_STYLE_OVERFLOW_AUTO == scrolling)) {
|
1998-10-13 02:13:23 +04:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
1998-09-18 21:18:37 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLStyleSheetImpl::ConstructFrame(nsIPresContext* aPresContext,
|
|
|
|
nsIContent* aContent,
|
|
|
|
nsIFrame* aParentFrame,
|
|
|
|
nsIFrame*& aFrameSubTree)
|
1998-09-17 08:07:58 +04:00
|
|
|
{
|
|
|
|
nsresult rv;
|
1998-09-16 21:19:20 +04:00
|
|
|
|
1998-09-17 08:07:58 +04:00
|
|
|
// Get the tag
|
|
|
|
nsIAtom* tag;
|
|
|
|
aContent->GetTag(tag);
|
1998-09-16 21:19:20 +04:00
|
|
|
|
1998-09-17 08:07:58 +04:00
|
|
|
// Resolve the style context.
|
|
|
|
// XXX Cheesy hack for text
|
1998-11-03 23:33:23 +03:00
|
|
|
nsIStyleContext* parentStyleContext = nsnull;
|
|
|
|
if (nsnull != aParentFrame) {
|
|
|
|
aParentFrame->GetStyleContext(parentStyleContext);
|
|
|
|
}
|
1998-09-17 08:07:58 +04:00
|
|
|
nsIStyleContext* styleContext;
|
|
|
|
if (nsnull == tag) {
|
1998-11-03 23:33:23 +03:00
|
|
|
nsIContent* parentContent = nsnull;
|
|
|
|
if (nsnull != aParentFrame) {
|
|
|
|
aParentFrame->GetContent(parentContent);
|
|
|
|
}
|
|
|
|
styleContext = aPresContext->ResolvePseudoStyleContextFor(parentContent,
|
1998-11-18 05:11:27 +03:00
|
|
|
nsHTMLAtoms::textPseudo,
|
1998-11-03 23:33:23 +03:00
|
|
|
parentStyleContext);
|
|
|
|
NS_IF_RELEASE(parentContent);
|
1998-09-17 08:07:58 +04:00
|
|
|
} else {
|
1998-11-03 23:33:23 +03:00
|
|
|
styleContext = aPresContext->ResolveStyleContextFor(aContent, parentStyleContext);
|
1998-09-17 08:07:58 +04:00
|
|
|
}
|
1998-11-03 23:33:23 +03:00
|
|
|
NS_IF_RELEASE(parentStyleContext);
|
1998-10-06 04:43:48 +04:00
|
|
|
// XXX bad api - no nsresult returned!
|
|
|
|
if (nsnull == styleContext) {
|
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Pre-check for display "none" - if we find that, don't create
|
|
|
|
// any frame at all.
|
|
|
|
const nsStyleDisplay* display = (const nsStyleDisplay*)
|
|
|
|
styleContext->GetStyleData(eStyleStruct_Display);
|
|
|
|
if (NS_STYLE_DISPLAY_NONE == display->mDisplay) {
|
|
|
|
aFrameSubTree = nsnull;
|
|
|
|
rv = NS_OK;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Create a frame.
|
|
|
|
if (nsnull == aParentFrame) {
|
1998-11-12 01:06:16 +03:00
|
|
|
nsIDocument* document;
|
|
|
|
rv = aContent->GetDocument(document);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_RELEASE(styleContext);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
if (nsnull != document) {
|
|
|
|
nsIXMLDocument* xmlDocument;
|
|
|
|
rv = document->QueryInterface(kIXMLDocumentIID, (void **)&xmlDocument);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
// Construct the root frame object
|
|
|
|
rv = ConstructRootFrame(aPresContext, aContent, styleContext,
|
|
|
|
aFrameSubTree);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Construct the root frame object for XML
|
1998-11-13 02:03:35 +03:00
|
|
|
rv = ConstructXMLRootFrame(aPresContext, aContent, styleContext,
|
|
|
|
aFrameSubTree);
|
1998-11-12 01:06:16 +03:00
|
|
|
NS_RELEASE(xmlDocument);
|
|
|
|
}
|
|
|
|
NS_RELEASE(document);
|
|
|
|
}
|
1998-10-06 04:43:48 +04:00
|
|
|
} else {
|
1998-11-06 20:57:24 +03:00
|
|
|
// If the frame is a block-level frame and is scrollable then wrap it
|
|
|
|
// in a scroll frame.
|
|
|
|
// XXX Applies to replaced elements, too, but how to tell if the element
|
|
|
|
// is replaced?
|
|
|
|
nsIFrame* scrollFrame = nsnull;
|
1998-11-11 07:43:13 +03:00
|
|
|
nsIFrame* wrapperFrame = nsnull;
|
1998-11-06 20:57:24 +03:00
|
|
|
|
|
|
|
// If we're paginated then don't ever make the BODY scrollable
|
1998-11-11 07:43:13 +03:00
|
|
|
// XXX Use a special BODY rule for paged media...
|
1998-11-06 20:57:24 +03:00
|
|
|
if (!(aPresContext->IsPaginated() && (nsHTMLAtoms::body == tag))) {
|
1998-11-25 19:41:06 +03:00
|
|
|
if ((display->mDisplay!=NS_STYLE_DISPLAY_TABLE) && display->IsBlockLevel() && IsScrollable(aPresContext, tag, display)) {
|
1998-11-06 20:57:24 +03:00
|
|
|
// Create a scroll frame which will wrap the frame that needs to
|
|
|
|
// be scrolled
|
1998-12-03 09:31:43 +03:00
|
|
|
if (NS_SUCCEEDED(NS_NewScrollFrame(scrollFrame))) {
|
1998-11-11 07:43:13 +03:00
|
|
|
nsIStyleContext* scrolledPseudoStyle;
|
|
|
|
|
1998-11-06 20:57:24 +03:00
|
|
|
// The scroll frame gets the original style context, and the scrolled
|
1998-11-11 07:43:13 +03:00
|
|
|
// frame gets a SCROLLED-CONTENT pseudo element style context that
|
|
|
|
// inherits the background properties
|
1998-12-03 09:31:43 +03:00
|
|
|
scrollFrame->Init(*aPresContext, aContent, aParentFrame, styleContext);
|
1998-11-11 07:43:13 +03:00
|
|
|
scrolledPseudoStyle = aPresContext->ResolvePseudoStyleContextFor
|
|
|
|
(aContent, nsHTMLAtoms::scrolledContentPseudo,
|
|
|
|
styleContext);
|
1998-11-06 20:57:24 +03:00
|
|
|
NS_RELEASE(styleContext);
|
1998-11-11 07:43:13 +03:00
|
|
|
|
|
|
|
// If the content element can contain children then wrap it in a
|
|
|
|
// BODY frame. Don't do this for the BODY element, though...
|
|
|
|
PRBool isContainer;
|
|
|
|
aContent->CanContainChildren(isContainer);
|
|
|
|
if (isContainer && (tag != nsHTMLAtoms::body)) {
|
1998-12-03 09:31:43 +03:00
|
|
|
NS_NewBodyFrame(wrapperFrame, NS_BODY_SHRINK_WRAP);
|
|
|
|
wrapperFrame->Init(*aPresContext, aContent, scrollFrame, scrolledPseudoStyle);
|
1998-11-11 07:43:13 +03:00
|
|
|
|
|
|
|
// The wrapped frame also gets a pseudo style context, but it doesn't
|
1998-11-21 02:27:59 +03:00
|
|
|
// inherit any background properties. It does inherit the 'display'
|
|
|
|
// property (very important that it does)
|
1998-11-11 07:43:13 +03:00
|
|
|
nsIStyleContext* wrappedPseudoStyle;
|
|
|
|
wrappedPseudoStyle = aPresContext->ResolvePseudoStyleContextFor
|
1998-11-21 02:27:59 +03:00
|
|
|
(aContent, nsHTMLAtoms::wrappedFramePseudo,
|
1998-11-11 07:43:13 +03:00
|
|
|
scrolledPseudoStyle);
|
|
|
|
NS_RELEASE(scrolledPseudoStyle);
|
|
|
|
aParentFrame = wrapperFrame;
|
|
|
|
styleContext = wrappedPseudoStyle;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
aParentFrame = scrollFrame;
|
|
|
|
styleContext = scrolledPseudoStyle;
|
|
|
|
}
|
1998-11-06 20:57:24 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-10-06 04:43:48 +04:00
|
|
|
// Handle specific frame types
|
|
|
|
rv = ConstructFrameByTag(aPresContext, aContent, aParentFrame,
|
|
|
|
tag, styleContext, aFrameSubTree);
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv) && (nsnull == aFrameSubTree)) {
|
|
|
|
// When there is no explicit frame to create, assume it's a
|
|
|
|
// container and let display style dictate the rest
|
|
|
|
rv = ConstructFrameByDisplayType(aPresContext, display,
|
|
|
|
aContent, aParentFrame,
|
|
|
|
styleContext, aFrameSubTree);
|
|
|
|
}
|
1998-10-09 00:35:16 +04:00
|
|
|
|
1998-11-06 20:57:24 +03:00
|
|
|
// Set the scroll frame's initial child list and return the scroll frame
|
|
|
|
// as the frame sub-tree
|
|
|
|
if (nsnull != scrollFrame) {
|
1998-11-11 07:43:13 +03:00
|
|
|
if (nsnull != wrapperFrame) {
|
|
|
|
wrapperFrame->SetInitialChildList(*aPresContext, nsnull, aFrameSubTree);
|
|
|
|
scrollFrame->SetInitialChildList(*aPresContext, nsnull, wrapperFrame);
|
|
|
|
} else {
|
|
|
|
scrollFrame->SetInitialChildList(*aPresContext, nsnull, aFrameSubTree);
|
|
|
|
}
|
1998-11-06 20:57:24 +03:00
|
|
|
aFrameSubTree = scrollFrame;
|
1998-10-09 00:35:16 +04:00
|
|
|
}
|
1998-10-06 04:43:48 +04:00
|
|
|
}
|
1998-09-10 23:32:14 +04:00
|
|
|
}
|
1998-10-06 04:43:48 +04:00
|
|
|
NS_RELEASE(styleContext);
|
1998-09-10 23:32:14 +04:00
|
|
|
}
|
1998-09-16 21:19:20 +04:00
|
|
|
|
1998-09-10 23:32:14 +04:00
|
|
|
NS_IF_RELEASE(tag);
|
1998-09-17 08:07:58 +04:00
|
|
|
return rv;
|
1998-09-10 23:32:14 +04:00
|
|
|
}
|
|
|
|
|
1998-11-17 05:14:38 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLStyleSheetImpl::ReconstructFrames(nsIPresContext* aPresContext,
|
|
|
|
nsIContent* aContent,
|
|
|
|
nsIFrame* aParentFrame,
|
|
|
|
nsIFrame* aFrameSubTree)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
nsIDocument* document;
|
|
|
|
rv = aContent->GetDocument(document);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
// XXX Currently we only know how to do this for XML documents
|
|
|
|
if (nsnull != document) {
|
|
|
|
nsIPresShell* shell = aPresContext->GetShell();
|
|
|
|
nsIXMLDocument* xmlDocument;
|
|
|
|
rv = document->QueryInterface(kIXMLDocumentIID, (void **)&xmlDocument);
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
nsIReflowCommand* reflowCmd;
|
|
|
|
|
|
|
|
rv = NS_NewHTMLReflowCommand(&reflowCmd, aParentFrame,
|
|
|
|
nsIReflowCommand::FrameRemoved,
|
|
|
|
aFrameSubTree);
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
shell->AppendReflowCommand(reflowCmd);
|
|
|
|
NS_RELEASE(reflowCmd);
|
|
|
|
|
|
|
|
nsIFrame *newChild;
|
|
|
|
// XXX See ConstructXMLContents for an explanation of why
|
|
|
|
// we create this pseudostyle
|
|
|
|
nsIStyleContext* rootPseudoStyle;
|
|
|
|
rootPseudoStyle = aPresContext->ResolvePseudoStyleContextFor(nsnull,
|
|
|
|
nsHTMLAtoms::xmlRootPseudo, nsnull);
|
|
|
|
|
|
|
|
rv = ConstructXMLRootDescendants(aPresContext, aContent,
|
|
|
|
rootPseudoStyle, aParentFrame,
|
|
|
|
newChild);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
rv = NS_NewHTMLReflowCommand(&reflowCmd, aParentFrame,
|
|
|
|
nsIReflowCommand::FrameInserted,
|
|
|
|
newChild);
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
shell->AppendReflowCommand(reflowCmd);
|
|
|
|
NS_RELEASE(reflowCmd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
NS_IF_RELEASE(rootPseudoStyle);
|
|
|
|
}
|
|
|
|
NS_RELEASE(xmlDocument);
|
|
|
|
}
|
|
|
|
NS_RELEASE(document);
|
|
|
|
NS_RELEASE(shell);
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
1998-10-30 02:25:02 +03:00
|
|
|
nsIFrame*
|
1998-11-10 02:30:16 +03:00
|
|
|
HTMLStyleSheetImpl::GetFrameFor(nsIPresShell* aPresShell, nsIPresContext* aPresContext,
|
|
|
|
nsIContent* aContent)
|
1998-10-30 02:25:02 +03:00
|
|
|
{
|
|
|
|
nsIFrame* frame = aPresShell->FindFrameWithContent(aContent);
|
|
|
|
|
|
|
|
if (nsnull != frame) {
|
|
|
|
// If the primary frame is a scroll frame, then get the scrolled frame.
|
|
|
|
// That's the frame that gets the reflow command
|
|
|
|
const nsStyleDisplay* display;
|
|
|
|
frame->GetStyleData(eStyleStruct_Display, (const nsStyleStruct*&)display);
|
|
|
|
|
1998-11-25 19:41:06 +03:00
|
|
|
nsIAtom* tag;
|
|
|
|
aContent->GetTag(tag);
|
|
|
|
if (display->IsBlockLevel() && IsScrollable(aPresContext, tag, display)) {
|
1998-11-09 22:40:27 +03:00
|
|
|
frame->FirstChild(nsnull, frame);
|
1998-10-30 02:25:02 +03:00
|
|
|
}
|
1998-11-25 19:41:06 +03:00
|
|
|
NS_IF_RELEASE(tag);
|
1998-10-30 02:25:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return frame;
|
|
|
|
}
|
|
|
|
|
1998-09-18 21:18:37 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLStyleSheetImpl::ContentAppended(nsIPresContext* aPresContext,
|
|
|
|
nsIContent* aContainer,
|
|
|
|
PRInt32 aNewIndexInContainer)
|
1998-09-10 23:32:14 +04:00
|
|
|
{
|
|
|
|
nsIPresShell* shell = aPresContext->GetShell();
|
1998-11-10 02:30:16 +03:00
|
|
|
nsIFrame* parentFrame = GetFrameFor(shell, aPresContext, aContainer);
|
1998-09-17 04:06:46 +04:00
|
|
|
|
|
|
|
#ifdef NS_DEBUG
|
|
|
|
if (nsnull == parentFrame) {
|
|
|
|
NS_WARNING("Ignoring content-appended notification with no matching frame...");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if (nsnull != parentFrame) {
|
|
|
|
// Get the parent frame's last-in-flow
|
|
|
|
nsIFrame* nextInFlow = parentFrame;
|
|
|
|
while (nsnull != nextInFlow) {
|
|
|
|
parentFrame->GetNextInFlow(nextInFlow);
|
|
|
|
if (nsnull != nextInFlow) {
|
|
|
|
parentFrame = nextInFlow;
|
1998-09-10 23:32:14 +04:00
|
|
|
}
|
1998-09-17 04:06:46 +04:00
|
|
|
}
|
1998-09-10 23:32:14 +04:00
|
|
|
|
1998-09-17 04:06:46 +04:00
|
|
|
// Create some new frames
|
|
|
|
PRInt32 count;
|
|
|
|
nsIFrame* lastChildFrame = nsnull;
|
|
|
|
nsIFrame* firstAppendedFrame = nsnull;
|
1998-09-10 23:32:14 +04:00
|
|
|
|
1998-09-17 04:06:46 +04:00
|
|
|
aContainer->ChildCount(count);
|
1998-09-10 23:32:14 +04:00
|
|
|
|
1998-09-17 04:06:46 +04:00
|
|
|
for (PRInt32 i = aNewIndexInContainer; i < count; i++) {
|
|
|
|
nsIContent* child;
|
|
|
|
nsIFrame* frame;
|
1998-09-10 23:32:14 +04:00
|
|
|
|
1998-09-17 04:06:46 +04:00
|
|
|
aContainer->ChildAt(i, child);
|
|
|
|
ConstructFrame(aPresContext, child, parentFrame, frame);
|
1998-09-10 23:32:14 +04:00
|
|
|
|
1998-09-30 03:51:28 +04:00
|
|
|
if (nsnull != frame) {
|
|
|
|
// Link the frame into the child frame list
|
|
|
|
if (nsnull == lastChildFrame) {
|
|
|
|
firstAppendedFrame = frame;
|
|
|
|
} else {
|
|
|
|
lastChildFrame->SetNextSibling(frame);
|
|
|
|
}
|
1998-09-10 23:32:14 +04:00
|
|
|
|
1998-09-30 03:51:28 +04:00
|
|
|
lastChildFrame = frame;
|
|
|
|
}
|
1998-09-17 04:06:46 +04:00
|
|
|
NS_RELEASE(child);
|
|
|
|
}
|
|
|
|
|
1998-10-30 02:25:02 +03:00
|
|
|
// Adjust parent frame for table inner/outer frame
|
1998-10-22 02:24:59 +04:00
|
|
|
// we need to do this here because we need both the parent frame and the constructed frame
|
|
|
|
nsresult result = NS_OK;
|
|
|
|
nsIFrame *adjustedParentFrame=parentFrame;
|
|
|
|
if (nsnull!=firstAppendedFrame)
|
|
|
|
{
|
|
|
|
const nsStyleDisplay* firstAppendedFrameDisplay;
|
|
|
|
firstAppendedFrame->GetStyleData(eStyleStruct_Display, (const nsStyleStruct *&)firstAppendedFrameDisplay);
|
|
|
|
result = GetAdjustedParentFrame(parentFrame, firstAppendedFrameDisplay->mDisplay, adjustedParentFrame);
|
|
|
|
}
|
|
|
|
|
1998-09-17 04:06:46 +04:00
|
|
|
// Notify the parent frame with a reflow command, passing it the list of
|
|
|
|
// new frames.
|
|
|
|
if (NS_SUCCEEDED(result)) {
|
1998-10-22 02:24:59 +04:00
|
|
|
nsIReflowCommand* reflowCmd;
|
|
|
|
result = NS_NewHTMLReflowCommand(&reflowCmd, adjustedParentFrame,
|
|
|
|
nsIReflowCommand::FrameAppended,
|
|
|
|
firstAppendedFrame);
|
|
|
|
if (NS_SUCCEEDED(result)) {
|
|
|
|
shell->AppendReflowCommand(reflowCmd);
|
|
|
|
NS_RELEASE(reflowCmd);
|
|
|
|
}
|
1998-09-10 23:32:14 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_RELEASE(shell);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-09-02 06:10:44 +04:00
|
|
|
|
1998-09-19 01:28:21 +04:00
|
|
|
static nsIFrame*
|
|
|
|
FindPreviousSibling(nsIPresShell* aPresShell,
|
|
|
|
nsIContent* aContainer,
|
|
|
|
PRInt32 aIndexInContainer)
|
1998-09-18 21:18:37 +04:00
|
|
|
{
|
|
|
|
nsIFrame* prevSibling = nsnull;
|
|
|
|
|
|
|
|
// Note: not all content objects are associated with a frame so
|
|
|
|
// keep looking until we find a previous frame
|
1998-09-23 08:25:49 +04:00
|
|
|
for (PRInt32 index = aIndexInContainer - 1; index >= 0; index--) {
|
1998-09-18 21:18:37 +04:00
|
|
|
nsIContent* precedingContent;
|
1998-09-19 01:28:21 +04:00
|
|
|
aContainer->ChildAt(index, precedingContent);
|
|
|
|
prevSibling = aPresShell->FindFrameWithContent(precedingContent);
|
1998-09-18 21:18:37 +04:00
|
|
|
NS_RELEASE(precedingContent);
|
|
|
|
|
|
|
|
if (nsnull != prevSibling) {
|
|
|
|
// The frame may have a next-in-flow. Get the last-in-flow
|
|
|
|
nsIFrame* nextInFlow;
|
|
|
|
do {
|
|
|
|
prevSibling->GetNextInFlow(nextInFlow);
|
|
|
|
if (nsnull != nextInFlow) {
|
|
|
|
prevSibling = nextInFlow;
|
|
|
|
}
|
|
|
|
} while (nsnull != nextInFlow);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-09-19 01:28:21 +04:00
|
|
|
return prevSibling;
|
|
|
|
}
|
|
|
|
|
|
|
|
static nsIFrame*
|
|
|
|
FindNextSibling(nsIPresShell* aPresShell,
|
|
|
|
nsIContent* aContainer,
|
|
|
|
PRInt32 aIndexInContainer)
|
|
|
|
{
|
|
|
|
nsIFrame* nextSibling = nsnull;
|
|
|
|
|
|
|
|
// Note: not all content objects are associated with a frame so
|
|
|
|
// keep looking until we find a next frame
|
|
|
|
PRInt32 count;
|
|
|
|
aContainer->ChildCount(count);
|
|
|
|
for (PRInt32 index = aIndexInContainer + 1; index < count; index++) {
|
|
|
|
nsIContent* nextContent;
|
|
|
|
aContainer->ChildAt(index, nextContent);
|
|
|
|
nextSibling = aPresShell->FindFrameWithContent(nextContent);
|
|
|
|
NS_RELEASE(nextContent);
|
|
|
|
|
|
|
|
if (nsnull != nextSibling) {
|
|
|
|
// The frame may have a next-in-flow. Get the last-in-flow
|
|
|
|
nsIFrame* nextInFlow;
|
|
|
|
do {
|
|
|
|
nextSibling->GetNextInFlow(nextInFlow);
|
|
|
|
if (nsnull != nextInFlow) {
|
|
|
|
nextSibling = nextInFlow;
|
|
|
|
}
|
|
|
|
} while (nsnull != nextInFlow);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nextSibling;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLStyleSheetImpl::ContentInserted(nsIPresContext* aPresContext,
|
|
|
|
nsIContent* aContainer,
|
|
|
|
nsIContent* aChild,
|
|
|
|
PRInt32 aIndexInContainer)
|
|
|
|
{
|
|
|
|
nsIPresShell* shell = aPresContext->GetShell();
|
|
|
|
|
|
|
|
// Find the frame that precedes the insertion point.
|
|
|
|
nsIFrame* prevSibling = FindPreviousSibling(shell, aContainer, aIndexInContainer);
|
|
|
|
nsIFrame* nextSibling = nsnull;
|
|
|
|
PRBool isAppend = PR_FALSE;
|
|
|
|
|
|
|
|
// If there is no previous sibling, then find the frame that follows
|
|
|
|
if (nsnull == prevSibling) {
|
|
|
|
nextSibling = FindNextSibling(shell, aContainer, aIndexInContainer);
|
|
|
|
}
|
|
|
|
|
1998-09-18 21:18:37 +04:00
|
|
|
// Get the geometric parent.
|
|
|
|
nsIFrame* parentFrame;
|
1998-09-19 01:28:21 +04:00
|
|
|
if ((nsnull == prevSibling) && (nsnull == nextSibling)) {
|
|
|
|
// No previous or next sibling so treat this like an appended frame.
|
|
|
|
// XXX This won't always be true if there's auto-generated before/after
|
|
|
|
// content
|
|
|
|
isAppend = PR_TRUE;
|
1998-09-18 21:18:37 +04:00
|
|
|
parentFrame = shell->FindFrameWithContent(aContainer);
|
1998-09-19 01:28:21 +04:00
|
|
|
|
1998-09-18 21:18:37 +04:00
|
|
|
} else {
|
1998-09-19 01:28:21 +04:00
|
|
|
// Use the prev sibling if we have it; otherwise use the next sibling.
|
|
|
|
// Note that we use the content parent, and not the geometric parent,
|
|
|
|
// in case the frame has been moved out of the flow...
|
|
|
|
if (nsnull != prevSibling) {
|
|
|
|
prevSibling->GetContentParent(parentFrame);
|
|
|
|
} else {
|
|
|
|
nextSibling->GetContentParent(parentFrame);
|
|
|
|
}
|
1998-09-18 21:18:37 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Construct a new frame
|
1998-09-19 01:28:21 +04:00
|
|
|
nsresult rv = NS_OK;
|
1998-09-18 21:18:37 +04:00
|
|
|
if (nsnull != parentFrame) {
|
|
|
|
nsIFrame* newFrame;
|
|
|
|
rv = ConstructFrame(aPresContext, aChild, parentFrame, newFrame);
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv) && (nsnull != newFrame)) {
|
1998-09-19 01:28:21 +04:00
|
|
|
nsIReflowCommand* reflowCmd = nsnull;
|
|
|
|
|
|
|
|
// Notify the parent frame with a reflow command.
|
|
|
|
if (isAppend) {
|
|
|
|
// Generate a FrameAppended reflow command
|
|
|
|
rv = NS_NewHTMLReflowCommand(&reflowCmd, parentFrame,
|
|
|
|
nsIReflowCommand::FrameAppended, newFrame);
|
|
|
|
} else {
|
|
|
|
// Generate a FrameInserted reflow command
|
|
|
|
rv = NS_NewHTMLReflowCommand(&reflowCmd, parentFrame, newFrame, prevSibling);
|
|
|
|
}
|
1998-09-18 21:18:37 +04:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
shell->AppendReflowCommand(reflowCmd);
|
|
|
|
NS_RELEASE(reflowCmd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_RELEASE(shell);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1998-09-26 02:47:00 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLStyleSheetImpl::ContentReplaced(nsIPresContext* aPresContext,
|
|
|
|
nsIContent* aContainer,
|
|
|
|
nsIContent* aOldChild,
|
|
|
|
nsIContent* aNewChild,
|
|
|
|
PRInt32 aIndexInContainer)
|
|
|
|
{
|
1998-11-30 10:59:11 +03:00
|
|
|
// XXX For now, do a brute force remove and insert.
|
|
|
|
nsresult res = ContentRemoved(aPresContext, aContainer,
|
|
|
|
aOldChild, aIndexInContainer);
|
|
|
|
if (NS_OK == res) {
|
|
|
|
res = ContentInserted(aPresContext, aContainer,
|
|
|
|
aNewChild, aIndexInContainer);
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
1998-09-26 02:47:00 +04:00
|
|
|
}
|
|
|
|
|
1998-09-25 09:13:06 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLStyleSheetImpl::ContentRemoved(nsIPresContext* aPresContext,
|
|
|
|
nsIContent* aContainer,
|
|
|
|
nsIContent* aChild,
|
|
|
|
PRInt32 aIndexInContainer)
|
|
|
|
{
|
|
|
|
nsIPresShell* shell = aPresContext->GetShell();
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
// Find the child frame
|
|
|
|
nsIFrame* childFrame = shell->FindFrameWithContent(aChild);
|
|
|
|
|
|
|
|
if (nsnull != childFrame) {
|
|
|
|
// Get the parent frame.
|
|
|
|
// Note that we use the content parent, and not the geometric parent,
|
|
|
|
// in case the frame has been moved out of the flow...
|
|
|
|
nsIFrame* parentFrame;
|
|
|
|
childFrame->GetContentParent(parentFrame);
|
|
|
|
NS_ASSERTION(nsnull != parentFrame, "null content parent frame");
|
|
|
|
|
|
|
|
// Notify the parent frame with a reflow command.
|
|
|
|
nsIReflowCommand* reflowCmd;
|
|
|
|
rv = NS_NewHTMLReflowCommand(&reflowCmd, parentFrame,
|
1998-09-25 20:12:13 +04:00
|
|
|
nsIReflowCommand::FrameRemoved, childFrame);
|
1998-09-25 09:13:06 +04:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
shell->AppendReflowCommand(reflowCmd);
|
|
|
|
NS_RELEASE(reflowCmd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_RELEASE(shell);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1998-09-30 03:51:28 +04:00
|
|
|
|
|
|
|
static void
|
|
|
|
ApplyRenderingChangeToTree(nsIPresContext* aPresContext,
|
|
|
|
nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
nsIViewManager* viewManager = nsnull;
|
|
|
|
|
|
|
|
// Trigger rendering updates by damaging this frame and any
|
|
|
|
// continuations of this frame.
|
|
|
|
while (nsnull != aFrame) {
|
|
|
|
// Get the frame's bounding rect
|
|
|
|
nsRect r;
|
|
|
|
aFrame->GetRect(r);
|
|
|
|
r.x = 0;
|
|
|
|
r.y = 0;
|
|
|
|
|
|
|
|
// Get view if this frame has one and trigger an update. If the
|
|
|
|
// frame doesn't have a view, find the nearest containing view
|
|
|
|
// (adjusting r's coordinate system to reflect the nesting) and
|
|
|
|
// update there.
|
|
|
|
nsIView* view;
|
|
|
|
aFrame->GetView(view);
|
|
|
|
if (nsnull != view) {
|
|
|
|
} else {
|
|
|
|
nsPoint offset;
|
|
|
|
aFrame->GetOffsetFromView(offset, view);
|
|
|
|
NS_ASSERTION(nsnull != view, "no view");
|
|
|
|
r += offset;
|
|
|
|
}
|
|
|
|
if (nsnull == viewManager) {
|
|
|
|
view->GetViewManager(viewManager);
|
|
|
|
}
|
1998-10-28 05:05:05 +03:00
|
|
|
const nsStyleColor* color;
|
|
|
|
aFrame->GetStyleData(eStyleStruct_Color, (const nsStyleStruct*&) color);
|
|
|
|
viewManager->SetViewOpacity(view, color->mOpacity);
|
1998-09-30 03:51:28 +04:00
|
|
|
viewManager->UpdateView(view, r, NS_VMREFRESH_NO_SYNC);
|
|
|
|
|
|
|
|
aFrame->GetNextInFlow(aFrame);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nsnull != viewManager) {
|
|
|
|
viewManager->Composite();
|
|
|
|
NS_RELEASE(viewManager);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
StyleChangeReflow(nsIPresContext* aPresContext,
|
1998-11-04 22:34:34 +03:00
|
|
|
nsIFrame* aFrame,
|
|
|
|
nsIAtom * aAttribute)
|
1998-09-30 03:51:28 +04:00
|
|
|
{
|
|
|
|
nsIPresShell* shell;
|
|
|
|
shell = aPresContext->GetShell();
|
|
|
|
|
|
|
|
nsIReflowCommand* reflowCmd;
|
|
|
|
nsresult rv = NS_NewHTMLReflowCommand(&reflowCmd, aFrame,
|
1998-11-04 22:34:34 +03:00
|
|
|
nsIReflowCommand::StyleChanged,
|
|
|
|
nsnull,
|
|
|
|
aAttribute);
|
1998-09-30 03:51:28 +04:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
shell->AppendReflowCommand(reflowCmd);
|
|
|
|
NS_RELEASE(reflowCmd);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_RELEASE(shell);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLStyleSheetImpl::ContentChanged(nsIPresContext* aPresContext,
|
|
|
|
nsIContent* aContent,
|
|
|
|
nsISupports* aSubContent)
|
|
|
|
{
|
|
|
|
nsIPresShell* shell = aPresContext->GetShell();
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
// Find the child frame
|
|
|
|
nsIFrame* frame = shell->FindFrameWithContent(aContent);
|
|
|
|
|
|
|
|
// Notify the first frame that maps the content. It will generate a reflow
|
|
|
|
// command
|
|
|
|
|
|
|
|
// It's possible the frame whose content changed isn't inserted into the
|
|
|
|
// frame hierarchy yet, or that there is no frame that maps the content
|
|
|
|
if (nsnull != frame) {
|
|
|
|
#if 0
|
|
|
|
NS_FRAME_LOG(NS_FRAME_TRACE_CALLS,
|
|
|
|
("nsHTMLStyleSheet::ContentChanged: content=%p[%s] subcontent=%p frame=%p",
|
|
|
|
aContent, ContentTag(aContent, 0),
|
|
|
|
aSubContent, frame));
|
|
|
|
#endif
|
|
|
|
frame->ContentChanged(aPresContext, aContent, aSubContent);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_RELEASE(shell);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1998-10-31 02:06:14 +03:00
|
|
|
PRBool HTMLStyleSheetImpl::AttributeRequiresReflow(nsIAtom* aAttribute)
|
|
|
|
{
|
|
|
|
// these are attributes that always require a restyle and reflow
|
|
|
|
// regardless of the tag they are associated with
|
|
|
|
return (PRBool)
|
|
|
|
(aAttribute==nsHTMLAtoms::align ||
|
|
|
|
aAttribute==nsHTMLAtoms::border ||
|
|
|
|
aAttribute==nsHTMLAtoms::cellpadding ||
|
|
|
|
aAttribute==nsHTMLAtoms::cellspacing ||
|
|
|
|
aAttribute==nsHTMLAtoms::ch ||
|
|
|
|
aAttribute==nsHTMLAtoms::choff ||
|
|
|
|
aAttribute==nsHTMLAtoms::colspan ||
|
|
|
|
aAttribute==nsHTMLAtoms::face ||
|
|
|
|
aAttribute==nsHTMLAtoms::frame ||
|
|
|
|
aAttribute==nsHTMLAtoms::height ||
|
|
|
|
aAttribute==nsHTMLAtoms::nowrap ||
|
|
|
|
aAttribute==nsHTMLAtoms::rowspan ||
|
|
|
|
aAttribute==nsHTMLAtoms::rules ||
|
|
|
|
aAttribute==nsHTMLAtoms::span ||
|
|
|
|
aAttribute==nsHTMLAtoms::valign ||
|
|
|
|
aAttribute==nsHTMLAtoms::width);
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool HTMLStyleSheetImpl::AttributeRequiresRepaint(nsIAtom* aAttribute)
|
|
|
|
{
|
1998-11-04 22:34:34 +03:00
|
|
|
// these are attributes that always require a restyle and a repaint, but not a reflow
|
1998-10-31 02:06:14 +03:00
|
|
|
// regardless of the tag they are associated with
|
|
|
|
return (PRBool)
|
|
|
|
(aAttribute==nsHTMLAtoms::bgcolor ||
|
|
|
|
aAttribute==nsHTMLAtoms::color);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-09-30 03:51:28 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLStyleSheetImpl::AttributeChanged(nsIPresContext* aPresContext,
|
|
|
|
nsIContent* aContent,
|
|
|
|
nsIAtom* aAttribute,
|
|
|
|
PRInt32 aHint)
|
|
|
|
{
|
|
|
|
nsresult result = NS_OK;
|
|
|
|
|
|
|
|
nsIPresShell* shell = aPresContext->GetShell();
|
|
|
|
nsIFrame* frame = shell->FindFrameWithContent(aContent);
|
|
|
|
|
|
|
|
if (nsnull != frame) {
|
|
|
|
PRBool restyle = PR_FALSE;
|
|
|
|
PRBool reflow = PR_FALSE;
|
|
|
|
PRBool reframe = PR_FALSE;
|
|
|
|
PRBool render = PR_FALSE;
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
NS_FRAME_LOG(NS_FRAME_TRACE_CALLS,
|
|
|
|
("HTMLStyleSheet::AttributeChanged: content=%p[%s] frame=%p",
|
|
|
|
aContent, ContentTag(aContent, 0), frame));
|
|
|
|
#endif
|
|
|
|
|
1998-10-31 02:06:14 +03:00
|
|
|
if (PR_TRUE==AttributeRequiresReflow(aAttribute)) {
|
|
|
|
restyle = PR_TRUE;
|
|
|
|
reflow = PR_TRUE;
|
|
|
|
}
|
|
|
|
else if (PR_TRUE==AttributeRequiresRepaint(aAttribute)) {
|
|
|
|
restyle = PR_TRUE;
|
|
|
|
render = PR_TRUE;
|
|
|
|
}
|
|
|
|
// the style tag has its own interpretation based on aHint
|
|
|
|
else if (nsHTMLAtoms::style==aAttribute) {
|
|
|
|
switch (aHint) {
|
|
|
|
default:
|
|
|
|
case NS_STYLE_HINT_UNKNOWN:
|
|
|
|
case NS_STYLE_HINT_FRAMECHANGE:
|
|
|
|
reframe = PR_TRUE;
|
|
|
|
case NS_STYLE_HINT_REFLOW:
|
1998-09-30 03:51:28 +04:00
|
|
|
reflow = PR_TRUE;
|
1998-10-31 02:06:14 +03:00
|
|
|
case NS_STYLE_HINT_VISUAL:
|
1998-09-30 03:51:28 +04:00
|
|
|
render = PR_TRUE;
|
1998-10-31 02:06:14 +03:00
|
|
|
case NS_STYLE_HINT_CONTENT:
|
|
|
|
restyle = PR_TRUE;
|
|
|
|
break;
|
|
|
|
case NS_STYLE_HINT_AURAL:
|
|
|
|
break;
|
1998-09-30 03:51:28 +04:00
|
|
|
}
|
1998-10-31 02:06:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// this is the hook for specifying behavior of an attribute based on the tag
|
|
|
|
else
|
|
|
|
{
|
|
|
|
nsIHTMLContent* htmlContent;
|
|
|
|
result = aContent->QueryInterface(kIHTMLContentIID, (void**)&htmlContent);
|
|
|
|
|
|
|
|
if (NS_OK == result) {
|
|
|
|
nsIAtom* tag;
|
|
|
|
htmlContent->GetTag(tag);
|
1998-09-30 03:51:28 +04:00
|
|
|
|
1998-10-31 02:06:14 +03:00
|
|
|
// handle specific attributes by tag
|
|
|
|
if (nsHTMLAtoms::table==tag)
|
|
|
|
{
|
|
|
|
if (nsHTMLAtoms::summary!=aAttribute)
|
|
|
|
{
|
|
|
|
restyle = PR_TRUE;
|
1998-09-30 03:51:28 +04:00
|
|
|
reflow = PR_TRUE;
|
1998-10-31 02:06:14 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (nsHTMLAtoms::col==tag ||
|
|
|
|
nsHTMLAtoms::colgroup==tag ||
|
|
|
|
nsHTMLAtoms::tr==tag ||
|
|
|
|
nsHTMLAtoms::tbody==tag ||
|
|
|
|
nsHTMLAtoms::thead==tag ||
|
|
|
|
nsHTMLAtoms::tfoot==tag)
|
|
|
|
{
|
|
|
|
restyle = PR_TRUE;
|
|
|
|
reflow = PR_TRUE;
|
|
|
|
}
|
|
|
|
else if (nsHTMLAtoms::td==tag ||
|
|
|
|
nsHTMLAtoms::th==tag)
|
|
|
|
{
|
|
|
|
if (nsHTMLAtoms::abbr!=aAttribute &&
|
|
|
|
nsHTMLAtoms::axis!=aAttribute &&
|
|
|
|
nsHTMLAtoms::headers!=aAttribute &&
|
|
|
|
nsHTMLAtoms::scope!=aAttribute)
|
|
|
|
{
|
1998-09-30 03:51:28 +04:00
|
|
|
restyle = PR_TRUE;
|
1998-10-31 02:06:14 +03:00
|
|
|
reflow = PR_TRUE;
|
|
|
|
}
|
1998-09-30 03:51:28 +04:00
|
|
|
}
|
|
|
|
|
1998-10-31 02:06:14 +03:00
|
|
|
NS_IF_RELEASE(tag);
|
|
|
|
NS_RELEASE(htmlContent);
|
|
|
|
}
|
1998-09-30 03:51:28 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// apply changes
|
|
|
|
if (PR_TRUE == restyle) {
|
1998-11-04 00:29:14 +03:00
|
|
|
nsIStyleContext* frameContext;
|
|
|
|
frame->GetStyleContext(frameContext);
|
|
|
|
NS_ASSERTION(nsnull != frameContext, "frame must have style context");
|
|
|
|
if (nsnull != frameContext) {
|
|
|
|
nsIStyleContext* parentContext = frameContext->GetParent();
|
|
|
|
frame->ReResolveStyleContext(aPresContext, parentContext);
|
|
|
|
NS_IF_RELEASE(parentContext);
|
|
|
|
NS_RELEASE(frameContext);
|
|
|
|
}
|
1998-09-30 03:51:28 +04:00
|
|
|
}
|
|
|
|
if (PR_TRUE == reframe) {
|
|
|
|
NS_NOTYETIMPLEMENTED("frame change reflow");
|
|
|
|
}
|
|
|
|
else if (PR_TRUE == reflow) {
|
1998-11-04 22:34:34 +03:00
|
|
|
StyleChangeReflow(aPresContext, frame, aAttribute);
|
1998-09-30 03:51:28 +04:00
|
|
|
}
|
|
|
|
else if (PR_TRUE == render) {
|
|
|
|
ApplyRenderingChangeToTree(aPresContext, frame);
|
|
|
|
}
|
|
|
|
else { // let the frame deal with it, since we don't know how to
|
|
|
|
frame->AttributeChanged(aPresContext, aContent, aAttribute, aHint);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_RELEASE(shell);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1998-11-26 04:34:53 +03:00
|
|
|
// Style change notifications
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLStyleSheetImpl::StyleRuleChanged(nsIPresContext* aPresContext,
|
|
|
|
nsIStyleSheet* aStyleSheet,
|
|
|
|
nsIStyleRule* aStyleRule,
|
|
|
|
PRInt32 aHint)
|
|
|
|
{
|
|
|
|
nsIPresShell* shell = aPresContext->GetShell();
|
|
|
|
nsIFrame* frame = shell->GetRootFrame();
|
|
|
|
|
|
|
|
PRBool reframe = PR_FALSE;
|
|
|
|
PRBool reflow = PR_FALSE;
|
|
|
|
PRBool render = PR_FALSE;
|
|
|
|
PRBool restyle = PR_FALSE;
|
|
|
|
switch (aHint) {
|
|
|
|
default:
|
|
|
|
case NS_STYLE_HINT_UNKNOWN:
|
|
|
|
case NS_STYLE_HINT_FRAMECHANGE:
|
|
|
|
reframe = PR_TRUE;
|
|
|
|
case NS_STYLE_HINT_REFLOW:
|
|
|
|
reflow = PR_TRUE;
|
|
|
|
case NS_STYLE_HINT_VISUAL:
|
|
|
|
render = PR_TRUE;
|
|
|
|
case NS_STYLE_HINT_CONTENT:
|
|
|
|
restyle = PR_TRUE;
|
|
|
|
break;
|
|
|
|
case NS_STYLE_HINT_AURAL:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (restyle) {
|
|
|
|
nsIStyleContext* sc;
|
|
|
|
frame->GetStyleContext(sc);
|
|
|
|
sc->RemapStyle(aPresContext);
|
|
|
|
NS_RELEASE(sc);
|
|
|
|
}
|
|
|
|
|
|
|
|
// XXX hack, skip the root and scrolling frames
|
|
|
|
frame->FirstChild(nsnull, frame);
|
|
|
|
frame->FirstChild(nsnull, frame);
|
|
|
|
if (reframe) {
|
|
|
|
NS_NOTYETIMPLEMENTED("frame change reflow");
|
|
|
|
}
|
|
|
|
else if (reflow) {
|
|
|
|
StyleChangeReflow(aPresContext, frame, nsnull);
|
|
|
|
}
|
|
|
|
else if (render) {
|
|
|
|
ApplyRenderingChangeToTree(aPresContext, frame);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_RELEASE(shell);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLStyleSheetImpl::StyleRuleAdded(nsIPresContext* aPresContext,
|
|
|
|
nsIStyleSheet* aStyleSheet,
|
|
|
|
nsIStyleRule* aStyleRule)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLStyleSheetImpl::StyleRuleRemoved(nsIPresContext* aPresContext,
|
|
|
|
nsIStyleSheet* aStyleSheet,
|
|
|
|
nsIStyleRule* aStyleRule)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-09-30 03:51:28 +04:00
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
void HTMLStyleSheetImpl::List(FILE* out, PRInt32 aIndent) const
|
|
|
|
{
|
|
|
|
nsAutoString buffer;
|
|
|
|
|
|
|
|
// Indent
|
|
|
|
for (PRInt32 index = aIndent; --index >= 0; ) fputs(" ", out);
|
|
|
|
|
|
|
|
fputs("HTML Style Sheet: ", out);
|
|
|
|
mURL->ToString(buffer);
|
|
|
|
fputs(buffer, out);
|
|
|
|
fputs("\n", out);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_HTML nsresult
|
1998-11-26 04:34:53 +03:00
|
|
|
NS_NewHTMLStyleSheet(nsIHTMLStyleSheet** aInstancePtrResult, nsIURL* aURL,
|
|
|
|
nsIDocument* aDocument)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
if (aInstancePtrResult == nsnull) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
|
1998-11-26 04:34:53 +03:00
|
|
|
HTMLStyleSheetImpl *it = new HTMLStyleSheetImpl(aURL, aDocument);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
if (nsnull == it) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
return it->QueryInterface(kIHTMLStyleSheetIID, (void **) aInstancePtrResult);
|
|
|
|
}
|