2003-02-22 03:32:13 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-18 01:52:36 +04:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
2003-02-22 03:32:13 +03:00
|
|
|
*
|
2004-04-18 01:52:36 +04:00
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
2003-02-22 03:32:13 +03:00
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2004-04-18 01:52:36 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
2003-02-22 03:32:13 +03:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* David Hyatt <hyatt@netscape.com>
|
|
|
|
* Pierre Phaneuf <pp@ludusdesign.com>
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-18 01:52:36 +04:00
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
2003-02-22 03:32:13 +03:00
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
2004-04-18 01:52:36 +04:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2003-02-22 03:32:13 +03:00
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
2004-04-18 01:52:36 +04:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2003-02-22 03:32:13 +03:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
2006-03-25 08:47:31 +03:00
|
|
|
/* the interface (to internal code) for retrieving computed style data */
|
|
|
|
|
2003-02-22 03:32:13 +03:00
|
|
|
#ifndef _nsStyleContext_h_
|
|
|
|
#define _nsStyleContext_h_
|
|
|
|
|
|
|
|
#include "nsRuleNode.h"
|
2004-06-09 03:53:59 +04:00
|
|
|
#include "nsIAtom.h"
|
2003-02-22 03:32:13 +03:00
|
|
|
|
2004-08-01 03:15:21 +04:00
|
|
|
class nsPresContext;
|
2003-02-22 03:32:13 +03:00
|
|
|
|
2005-02-04 23:11:00 +03:00
|
|
|
/**
|
|
|
|
* An nsStyleContext represents the computed style data for an element.
|
|
|
|
* The computed style data are stored in a set of structs (see
|
|
|
|
* nsStyleStruct.h) that are cached either on the style context or in
|
|
|
|
* the rule tree (see nsRuleNode.h for a description of this caching and
|
|
|
|
* how the cached structs are shared).
|
|
|
|
*
|
|
|
|
* Since the data in |nsIStyleRule|s and |nsRuleNode|s are immutable
|
|
|
|
* (with a few exceptions, like system color changes), the data in an
|
2005-02-05 08:24:21 +03:00
|
|
|
* nsStyleContext are also immutable (with the additional exception of
|
|
|
|
* GetUniqueStyleData). When style data change,
|
2005-02-04 23:11:00 +03:00
|
|
|
* nsFrameManager::ReResolveStyleContext creates a new style context.
|
2005-02-05 08:24:21 +03:00
|
|
|
*
|
|
|
|
* Style contexts are reference counted. References are generally held
|
|
|
|
* by:
|
|
|
|
* 1. the |nsIFrame|s that are using the style context and
|
|
|
|
* 2. any *child* style contexts (this might be the reverse of
|
|
|
|
* expectation, but it makes sense in this case)
|
|
|
|
* Style contexts participate in the mark phase of rule node garbage
|
|
|
|
* collection.
|
2005-02-04 23:11:00 +03:00
|
|
|
*/
|
|
|
|
|
2003-02-22 03:32:13 +03:00
|
|
|
class nsStyleContext
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsStyleContext(nsStyleContext* aParent, nsIAtom* aPseudoTag,
|
2004-08-01 03:15:21 +04:00
|
|
|
nsRuleNode* aRuleNode, nsPresContext* aPresContext) NS_HIDDEN;
|
2004-05-13 01:20:09 +04:00
|
|
|
~nsStyleContext() NS_HIDDEN;
|
2003-02-22 03:32:13 +03:00
|
|
|
|
2004-08-01 03:15:21 +04:00
|
|
|
NS_HIDDEN_(void*) operator new(size_t sz, nsPresContext* aPresContext) CPP_THROW_NEW;
|
2004-05-13 01:20:09 +04:00
|
|
|
NS_HIDDEN_(void) Destroy();
|
2003-02-22 03:32:13 +03:00
|
|
|
|
2003-02-22 07:05:05 +03:00
|
|
|
nsrefcnt AddRef() {
|
2003-02-22 03:32:13 +03:00
|
|
|
++mRefCnt;
|
|
|
|
NS_LOG_ADDREF(this, mRefCnt, "nsStyleContext", sizeof(nsStyleContext));
|
2003-02-22 07:05:05 +03:00
|
|
|
return mRefCnt;
|
2003-02-22 03:32:13 +03:00
|
|
|
}
|
|
|
|
|
2003-02-22 07:05:05 +03:00
|
|
|
nsrefcnt Release() {
|
2003-02-22 03:32:13 +03:00
|
|
|
--mRefCnt;
|
|
|
|
NS_LOG_RELEASE(this, mRefCnt, "nsStyleContext");
|
|
|
|
if (mRefCnt == 0) {
|
|
|
|
Destroy();
|
2003-02-22 07:05:05 +03:00
|
|
|
return 0;
|
2003-02-22 03:32:13 +03:00
|
|
|
}
|
2003-02-22 07:05:05 +03:00
|
|
|
return mRefCnt;
|
2003-02-22 03:32:13 +03:00
|
|
|
}
|
|
|
|
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext* PresContext() const { return mRuleNode->GetPresContext(); }
|
2004-02-09 09:55:14 +03:00
|
|
|
|
2003-02-22 03:32:13 +03:00
|
|
|
nsStyleContext* GetParent() const { return mParent; }
|
|
|
|
|
|
|
|
nsStyleContext* GetFirstChild() const { return mChild; }
|
|
|
|
|
2003-10-17 06:38:37 +04:00
|
|
|
nsIAtom* GetPseudoType() const { return mPseudoTag; }
|
2003-02-22 03:32:13 +03:00
|
|
|
|
2004-05-13 01:20:09 +04:00
|
|
|
NS_HIDDEN_(already_AddRefed<nsStyleContext>)
|
2003-02-22 03:32:13 +03:00
|
|
|
FindChildWithRules(const nsIAtom* aPseudoTag, nsRuleNode* aRules);
|
|
|
|
|
2004-05-13 01:20:09 +04:00
|
|
|
NS_HIDDEN_(PRBool) Equals(const nsStyleContext* aOther) const;
|
2007-10-10 04:00:06 +04:00
|
|
|
PRBool HasTextDecorations() { return !!(mBits & NS_STYLE_HAS_TEXT_DECORATIONS); }
|
2003-02-22 03:32:13 +03:00
|
|
|
|
2008-01-10 23:56:50 +03:00
|
|
|
NS_HIDDEN_(void) SetStyle(nsStyleStructID aSID, void* aStruct);
|
2003-02-22 03:32:13 +03:00
|
|
|
|
2003-06-20 05:22:44 +04:00
|
|
|
nsRuleNode* GetRuleNode() { return mRuleNode; }
|
2003-02-22 03:32:13 +03:00
|
|
|
void AddStyleBit(const PRUint32& aBit) { mBits |= aBit; }
|
|
|
|
|
2003-03-06 22:14:17 +03:00
|
|
|
/*
|
|
|
|
* Mark this style context's rule node (and its ancestors) to prevent
|
|
|
|
* it from being garbage collected.
|
|
|
|
*/
|
2004-05-13 01:20:09 +04:00
|
|
|
NS_HIDDEN_(void) Mark();
|
2003-03-06 22:14:17 +03:00
|
|
|
|
2003-03-13 18:29:36 +03:00
|
|
|
/*
|
|
|
|
* Get the style data for a style struct. This is the most important
|
|
|
|
* member function of nsIStyleContext. It fills in a const pointer
|
|
|
|
* to a style data struct that is appropriate for the style context's
|
|
|
|
* frame. This struct may be shared with other contexts (either in
|
|
|
|
* the rule tree or the style context tree), so it should not be
|
|
|
|
* modified.
|
|
|
|
*
|
|
|
|
* This function will NOT return null (even when out of memory) when
|
|
|
|
* given a valid style struct ID, so the result does not need to be
|
|
|
|
* null-checked.
|
|
|
|
*
|
2003-05-15 07:42:21 +04:00
|
|
|
* The typesafe functions below are preferred to the use of this
|
|
|
|
* function.
|
2003-03-13 18:29:36 +03:00
|
|
|
*/
|
2008-01-10 23:56:50 +03:00
|
|
|
NS_HIDDEN_(const void*) NS_FASTCALL GetStyleData(nsStyleStructID aSID);
|
2003-03-13 18:29:36 +03:00
|
|
|
|
2003-05-15 07:42:21 +04:00
|
|
|
/**
|
|
|
|
* Define typesafe getter functions for each style struct by
|
|
|
|
* preprocessing the list of style structs. These functions are the
|
|
|
|
* preferred way to get style data. The macro creates functions like:
|
|
|
|
* const nsStyleBorder* GetStyleBorder();
|
|
|
|
* const nsStyleColor* GetStyleColor();
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define STYLE_STRUCT(name_, checkdata_cb_, ctor_args_) \
|
2006-12-12 20:44:45 +03:00
|
|
|
NS_HIDDEN_(const nsStyle##name_ *) NS_FASTCALL GetStyle##name_();
|
2003-05-15 07:42:21 +04:00
|
|
|
#include "nsStyleStructList.h"
|
|
|
|
#undef STYLE_STRUCT
|
|
|
|
|
|
|
|
|
2008-01-10 23:56:50 +03:00
|
|
|
NS_HIDDEN_(const void*) PeekStyleData(nsStyleStructID aSID);
|
2003-02-22 03:32:13 +03:00
|
|
|
|
2008-01-10 23:56:50 +03:00
|
|
|
NS_HIDDEN_(void*) GetUniqueStyleData(const nsStyleStructID& aSID);
|
2003-02-22 03:32:13 +03:00
|
|
|
|
2004-05-13 01:20:09 +04:00
|
|
|
NS_HIDDEN_(nsChangeHint) CalcStyleDifference(nsStyleContext* aOther);
|
2003-02-22 03:32:13 +03:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
2004-08-01 03:15:21 +04:00
|
|
|
NS_HIDDEN_(void) DumpRegressionData(nsPresContext* aPresContext, FILE* out,
|
2004-05-13 01:20:09 +04:00
|
|
|
PRInt32 aIndent);
|
2003-02-22 03:32:13 +03:00
|
|
|
|
2004-05-13 01:20:09 +04:00
|
|
|
NS_HIDDEN_(void) List(FILE* out, PRInt32 aIndent);
|
2003-02-22 03:32:13 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
protected:
|
2006-04-28 04:09:05 +04:00
|
|
|
NS_HIDDEN_(void) AddChild(nsStyleContext* aChild);
|
2004-05-13 01:20:09 +04:00
|
|
|
NS_HIDDEN_(void) RemoveChild(nsStyleContext* aChild);
|
2003-02-22 03:32:13 +03:00
|
|
|
|
2004-08-01 03:15:21 +04:00
|
|
|
NS_HIDDEN_(void) ApplyStyleFixups(nsPresContext* aPresContext);
|
2003-02-22 03:32:13 +03:00
|
|
|
|
|
|
|
nsStyleContext* mParent;
|
2005-02-05 08:24:21 +03:00
|
|
|
|
2006-04-28 04:09:05 +04:00
|
|
|
// Children are kept in two circularly-linked lists. The list anchor
|
|
|
|
// is not part of the list (null for empty), and we point to the first
|
|
|
|
// child.
|
2005-02-05 08:24:21 +03:00
|
|
|
// mEmptyChild for children whose rule node is the root rule node, and
|
|
|
|
// mChild for other children. The order of children is not
|
|
|
|
// meaningful.
|
2003-02-22 03:32:13 +03:00
|
|
|
nsStyleContext* mChild;
|
|
|
|
nsStyleContext* mEmptyChild;
|
|
|
|
nsStyleContext* mPrevSibling;
|
|
|
|
nsStyleContext* mNextSibling;
|
|
|
|
|
|
|
|
// If this style context is for a pseudo-element, the pseudo-element
|
|
|
|
// atom. Otherwise, null.
|
|
|
|
nsCOMPtr<nsIAtom> mPseudoTag;
|
|
|
|
|
2005-02-04 23:11:00 +03:00
|
|
|
// The rule node is the node in the lexicographic tree of rule nodes
|
|
|
|
// (the "rule tree") that indicates which style rules are used to
|
|
|
|
// compute the style data, and in what cascading order. The least
|
|
|
|
// specific rule matched is the one whose rule node is a child of the
|
|
|
|
// root of the rule tree, and the most specific rule matched is the
|
|
|
|
// |mRule| member of |mRuleNode|.
|
2005-02-05 08:24:21 +03:00
|
|
|
nsRuleNode* const mRuleNode;
|
2003-02-22 03:32:13 +03:00
|
|
|
|
|
|
|
// |mCachedStyleData| points to both structs that are owned by this
|
|
|
|
// style context and structs that are owned by one of this style
|
|
|
|
// context's ancestors (which are indirectly owned since this style
|
|
|
|
// context owns a reference to its parent). If the bit in |mBits| is
|
|
|
|
// set for a struct, that means that the pointer for that struct is
|
|
|
|
// owned by an ancestor rather than by this style context.
|
|
|
|
nsCachedStyleData mCachedStyleData; // Our cached style data.
|
|
|
|
PRUint32 mBits; // Which structs are inherited from the
|
|
|
|
// parent context.
|
|
|
|
PRUint32 mRefCnt;
|
|
|
|
};
|
|
|
|
|
2004-05-13 01:20:09 +04:00
|
|
|
NS_HIDDEN_(already_AddRefed<nsStyleContext>)
|
2003-02-22 03:32:13 +03:00
|
|
|
NS_NewStyleContext(nsStyleContext* aParentContext,
|
|
|
|
nsIAtom* aPseudoTag,
|
|
|
|
nsRuleNode* aRuleNode,
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext* aPresContext);
|
2003-02-22 03:32:13 +03:00
|
|
|
#endif
|