2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2011-10-10 22:50:08 -07:00
|
|
|
|
|
|
|
#include "mozilla/Util.h"
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nscore.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsIDOMHTMLBodyElement.h"
|
|
|
|
#include "nsGenericHTMLElement.h"
|
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
#include "nsStyleConsts.h"
|
|
|
|
#include "nsPresContext.h"
|
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsHTMLStyleSheet.h"
|
|
|
|
#include "nsIMarkupDocumentViewer.h"
|
|
|
|
#include "nsMappedAttributes.h"
|
|
|
|
#include "nsRuleData.h"
|
|
|
|
#include "nsIFrame.h"
|
|
|
|
#include "nsIDocShell.h"
|
|
|
|
#include "nsIEditorDocShell.h"
|
|
|
|
#include "nsRuleWalker.h"
|
2011-08-24 12:49:25 -07:00
|
|
|
#include "jsapi.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
2011-10-10 22:50:08 -07:00
|
|
|
using namespace mozilla;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
class nsHTMLBodyElement;
|
|
|
|
|
|
|
|
class BodyRule: public nsIStyleRule {
|
|
|
|
public:
|
|
|
|
BodyRule(nsHTMLBodyElement* aPart);
|
|
|
|
virtual ~BodyRule();
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
// nsIStyleRule interface
|
2010-05-19 19:28:00 -07:00
|
|
|
virtual void MapRuleInfoInto(nsRuleData* aRuleData);
|
2007-03-22 10:30:00 -07:00
|
|
|
#ifdef DEBUG
|
2010-05-19 19:28:00 -07:00
|
|
|
virtual void List(FILE* out = stdout, PRInt32 aIndent = 0) const;
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
nsHTMLBodyElement* mPart; // not ref-counted, cleared by content
|
|
|
|
};
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
class nsHTMLBodyElement : public nsGenericHTMLElement,
|
|
|
|
public nsIDOMHTMLBodyElement
|
|
|
|
{
|
|
|
|
public:
|
2011-04-14 05:04:12 -07:00
|
|
|
using nsGenericElement::GetText;
|
|
|
|
using nsGenericElement::SetText;
|
|
|
|
|
2010-07-23 02:49:57 -07:00
|
|
|
nsHTMLBodyElement(already_AddRefed<nsINodeInfo> aNodeInfo);
|
2007-03-22 10:30:00 -07:00
|
|
|
virtual ~nsHTMLBodyElement();
|
|
|
|
|
|
|
|
// nsISupports
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
|
|
|
|
// nsIDOMNode
|
|
|
|
NS_FORWARD_NSIDOMNODE(nsGenericHTMLElement::)
|
|
|
|
|
|
|
|
// nsIDOMElement
|
|
|
|
NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLElement::)
|
|
|
|
|
|
|
|
// nsIDOMHTMLElement
|
|
|
|
NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLElement::)
|
|
|
|
|
|
|
|
// nsIDOMHTMLBodyElement
|
|
|
|
NS_DECL_NSIDOMHTMLBODYELEMENT
|
|
|
|
|
2011-08-24 12:49:25 -07:00
|
|
|
// Event listener stuff; we need to declare only the ones we need to
|
|
|
|
// forward to window that don't come from nsIDOMHTMLBodyElement.
|
|
|
|
#define EVENT(name_, id_, type_, struct_) /* nothing; handled by the shim */
|
|
|
|
#define FORWARDED_EVENT(name_, id_, type_, struct_) \
|
|
|
|
NS_IMETHOD GetOn##name_(JSContext *cx, jsval *vp); \
|
|
|
|
NS_IMETHOD SetOn##name_(JSContext *cx, const jsval &v);
|
|
|
|
#include "nsEventNameList.h"
|
|
|
|
#undef FORWARDED_EVENT
|
|
|
|
#undef EVENT
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
virtual bool ParseAttribute(PRInt32 aNamespaceID,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIAtom* aAttribute,
|
|
|
|
const nsAString& aValue,
|
|
|
|
nsAttrValue& aResult);
|
2011-09-28 23:19:26 -07:00
|
|
|
virtual void UnbindFromTree(bool aDeep = true,
|
|
|
|
bool aNullParent = true);
|
2007-03-22 10:30:00 -07:00
|
|
|
virtual nsMapRuleToAttributesFunc GetAttributeMappingFunction() const;
|
|
|
|
NS_IMETHOD WalkContentStyleRules(nsRuleWalker* aRuleWalker);
|
2011-09-28 23:19:26 -07:00
|
|
|
NS_IMETHOD_(bool) IsAttributeMapped(const nsIAtom* aAttribute) const;
|
2007-03-22 10:30:00 -07:00
|
|
|
virtual already_AddRefed<nsIEditor> GetAssociatedEditor();
|
|
|
|
virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
|
2010-07-23 02:49:57 -07:00
|
|
|
virtual nsXPCClassInfo* GetClassInfo();
|
2012-04-25 06:47:30 -07:00
|
|
|
virtual nsIDOMNode* AsDOMNode() { return this; }
|
2007-03-22 10:30:00 -07:00
|
|
|
private:
|
|
|
|
nsresult GetColorHelper(nsIAtom* aAtom, nsAString& aColor);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
BodyRule* mContentStyleRule;
|
|
|
|
};
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
BodyRule::BodyRule(nsHTMLBodyElement* aPart)
|
|
|
|
{
|
|
|
|
mPart = aPart;
|
|
|
|
}
|
|
|
|
|
|
|
|
BodyRule::~BodyRule()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS1(BodyRule, nsIStyleRule)
|
|
|
|
|
2010-05-19 19:28:00 -07:00
|
|
|
/* virtual */ void
|
2007-03-22 10:30:00 -07:00
|
|
|
BodyRule::MapRuleInfoInto(nsRuleData* aData)
|
|
|
|
{
|
2011-03-17 20:14:31 -07:00
|
|
|
if (!(aData->mSIDs & NS_STYLE_INHERIT_BIT(Margin)) || !mPart)
|
2010-05-19 19:28:00 -07:00
|
|
|
return; // We only care about margins.
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
PRInt32 bodyMarginWidth = -1;
|
|
|
|
PRInt32 bodyMarginHeight = -1;
|
|
|
|
PRInt32 bodyTopMargin = -1;
|
|
|
|
PRInt32 bodyBottomMargin = -1;
|
|
|
|
PRInt32 bodyLeftMargin = -1;
|
|
|
|
PRInt32 bodyRightMargin = -1;
|
|
|
|
|
|
|
|
// check the mode (fortunately, the ruleData has a presContext for us to use!)
|
|
|
|
NS_ASSERTION(aData->mPresContext, "null presContext in ruleNode was unexpected");
|
|
|
|
nsCompatibility mode = aData->mPresContext->CompatibilityMode();
|
|
|
|
|
|
|
|
|
|
|
|
const nsAttrValue* value;
|
|
|
|
if (mPart->GetAttrCount() > 0) {
|
|
|
|
// if marginwidth/marginheight are set, reflect them as 'margin'
|
|
|
|
value = mPart->GetParsedAttr(nsGkAtoms::marginwidth);
|
|
|
|
if (value && value->Type() == nsAttrValue::eInteger) {
|
|
|
|
bodyMarginWidth = value->GetIntegerValue();
|
|
|
|
if (bodyMarginWidth < 0) bodyMarginWidth = 0;
|
2011-03-17 20:14:31 -07:00
|
|
|
nsCSSValue* marginLeft = aData->ValueForMarginLeftValue();
|
|
|
|
if (marginLeft->GetUnit() == eCSSUnit_Null)
|
|
|
|
marginLeft->SetFloatValue((float)bodyMarginWidth, eCSSUnit_Pixel);
|
|
|
|
nsCSSValue* marginRight = aData->ValueForMarginRightValue();
|
|
|
|
if (marginRight->GetUnit() == eCSSUnit_Null)
|
|
|
|
marginRight->SetFloatValue((float)bodyMarginWidth, eCSSUnit_Pixel);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
value = mPart->GetParsedAttr(nsGkAtoms::marginheight);
|
|
|
|
if (value && value->Type() == nsAttrValue::eInteger) {
|
|
|
|
bodyMarginHeight = value->GetIntegerValue();
|
|
|
|
if (bodyMarginHeight < 0) bodyMarginHeight = 0;
|
2011-03-17 20:14:31 -07:00
|
|
|
nsCSSValue* marginTop = aData->ValueForMarginTop();
|
|
|
|
if (marginTop->GetUnit() == eCSSUnit_Null)
|
|
|
|
marginTop->SetFloatValue((float)bodyMarginHeight, eCSSUnit_Pixel);
|
|
|
|
nsCSSValue* marginBottom = aData->ValueForMarginBottom();
|
|
|
|
if (marginBottom->GetUnit() == eCSSUnit_Null)
|
|
|
|
marginBottom->SetFloatValue((float)bodyMarginHeight, eCSSUnit_Pixel);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (eCompatibility_NavQuirks == mode){
|
|
|
|
// topmargin (IE-attribute)
|
|
|
|
value = mPart->GetParsedAttr(nsGkAtoms::topmargin);
|
|
|
|
if (value && value->Type() == nsAttrValue::eInteger) {
|
|
|
|
bodyTopMargin = value->GetIntegerValue();
|
|
|
|
if (bodyTopMargin < 0) bodyTopMargin = 0;
|
2011-03-17 20:14:31 -07:00
|
|
|
nsCSSValue* marginTop = aData->ValueForMarginTop();
|
|
|
|
if (marginTop->GetUnit() == eCSSUnit_Null)
|
|
|
|
marginTop->SetFloatValue((float)bodyTopMargin, eCSSUnit_Pixel);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// bottommargin (IE-attribute)
|
|
|
|
value = mPart->GetParsedAttr(nsGkAtoms::bottommargin);
|
|
|
|
if (value && value->Type() == nsAttrValue::eInteger) {
|
|
|
|
bodyBottomMargin = value->GetIntegerValue();
|
|
|
|
if (bodyBottomMargin < 0) bodyBottomMargin = 0;
|
2011-03-17 20:14:31 -07:00
|
|
|
nsCSSValue* marginBottom = aData->ValueForMarginBottom();
|
|
|
|
if (marginBottom->GetUnit() == eCSSUnit_Null)
|
|
|
|
marginBottom->SetFloatValue((float)bodyBottomMargin, eCSSUnit_Pixel);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// leftmargin (IE-attribute)
|
|
|
|
value = mPart->GetParsedAttr(nsGkAtoms::leftmargin);
|
|
|
|
if (value && value->Type() == nsAttrValue::eInteger) {
|
|
|
|
bodyLeftMargin = value->GetIntegerValue();
|
|
|
|
if (bodyLeftMargin < 0) bodyLeftMargin = 0;
|
2011-03-17 20:14:31 -07:00
|
|
|
nsCSSValue* marginLeft = aData->ValueForMarginLeftValue();
|
|
|
|
if (marginLeft->GetUnit() == eCSSUnit_Null)
|
|
|
|
marginLeft->SetFloatValue((float)bodyLeftMargin, eCSSUnit_Pixel);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// rightmargin (IE-attribute)
|
|
|
|
value = mPart->GetParsedAttr(nsGkAtoms::rightmargin);
|
|
|
|
if (value && value->Type() == nsAttrValue::eInteger) {
|
|
|
|
bodyRightMargin = value->GetIntegerValue();
|
|
|
|
if (bodyRightMargin < 0) bodyRightMargin = 0;
|
2011-03-17 20:14:31 -07:00
|
|
|
nsCSSValue* marginRight = aData->ValueForMarginRightValue();
|
|
|
|
if (marginRight->GetUnit() == eCSSUnit_Null)
|
|
|
|
marginRight->SetFloatValue((float)bodyRightMargin, eCSSUnit_Pixel);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// if marginwidth or marginheight is set in the <frame> and not set in the <body>
|
|
|
|
// reflect them as margin in the <body>
|
|
|
|
if (bodyMarginWidth == -1 || bodyMarginHeight == -1) {
|
|
|
|
nsCOMPtr<nsISupports> container = aData->mPresContext->GetContainer();
|
|
|
|
if (container) {
|
|
|
|
nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(container));
|
|
|
|
if (docShell) {
|
|
|
|
nscoord frameMarginWidth=-1; // default value
|
|
|
|
nscoord frameMarginHeight=-1; // default value
|
|
|
|
docShell->GetMarginWidth(&frameMarginWidth); // -1 indicates not set
|
|
|
|
docShell->GetMarginHeight(&frameMarginHeight);
|
|
|
|
if ((frameMarginWidth >= 0) && (bodyMarginWidth == -1)) { // set in <frame> & not in <body>
|
|
|
|
if (eCompatibility_NavQuirks == mode) {
|
|
|
|
if ((bodyMarginHeight == -1) && (0 > frameMarginHeight)) // nav quirk
|
|
|
|
frameMarginHeight = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ((frameMarginHeight >= 0) && (bodyMarginHeight == -1)) { // set in <frame> & not in <body>
|
|
|
|
if (eCompatibility_NavQuirks == mode) {
|
|
|
|
if ((bodyMarginWidth == -1) && (0 > frameMarginWidth)) // nav quirk
|
|
|
|
frameMarginWidth = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((bodyMarginWidth == -1) && (frameMarginWidth >= 0)) {
|
2011-03-17 20:14:31 -07:00
|
|
|
nsCSSValue* marginLeft = aData->ValueForMarginLeftValue();
|
|
|
|
if (marginLeft->GetUnit() == eCSSUnit_Null)
|
|
|
|
marginLeft->SetFloatValue((float)frameMarginWidth, eCSSUnit_Pixel);
|
|
|
|
nsCSSValue* marginRight = aData->ValueForMarginRightValue();
|
|
|
|
if (marginRight->GetUnit() == eCSSUnit_Null)
|
|
|
|
marginRight->SetFloatValue((float)frameMarginWidth, eCSSUnit_Pixel);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((bodyMarginHeight == -1) && (frameMarginHeight >= 0)) {
|
2011-03-17 20:14:31 -07:00
|
|
|
nsCSSValue* marginTop = aData->ValueForMarginTop();
|
|
|
|
if (marginTop->GetUnit() == eCSSUnit_Null)
|
|
|
|
marginTop->SetFloatValue((float)frameMarginHeight, eCSSUnit_Pixel);
|
|
|
|
nsCSSValue* marginBottom = aData->ValueForMarginBottom();
|
|
|
|
if (marginBottom->GetUnit() == eCSSUnit_Null)
|
|
|
|
marginBottom->SetFloatValue((float)frameMarginHeight, eCSSUnit_Pixel);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
2010-05-19 19:28:00 -07:00
|
|
|
/* virtual */ void
|
2007-03-22 10:30:00 -07:00
|
|
|
BodyRule::List(FILE* out, PRInt32 aIndent) const
|
|
|
|
{
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMPL_NS_NEW_HTML_ELEMENT(Body)
|
|
|
|
|
|
|
|
|
2010-07-23 02:49:57 -07:00
|
|
|
nsHTMLBodyElement::nsHTMLBodyElement(already_AddRefed<nsINodeInfo> aNodeInfo)
|
2007-03-22 10:30:00 -07:00
|
|
|
: nsGenericHTMLElement(aNodeInfo),
|
|
|
|
mContentStyleRule(nsnull)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsHTMLBodyElement::~nsHTMLBodyElement()
|
|
|
|
{
|
|
|
|
if (mContentStyleRule) {
|
|
|
|
mContentStyleRule->mPart = nsnull;
|
|
|
|
NS_RELEASE(mContentStyleRule);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF_INHERITED(nsHTMLBodyElement, nsGenericElement)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(nsHTMLBodyElement, nsGenericElement)
|
|
|
|
|
2010-07-23 02:49:57 -07:00
|
|
|
DOMCI_NODE_DATA(HTMLBodyElement, nsHTMLBodyElement)
|
2010-01-12 05:08:43 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// QueryInterface implementation for nsHTMLBodyElement
|
2008-11-03 02:31:47 -08:00
|
|
|
NS_INTERFACE_TABLE_HEAD(nsHTMLBodyElement)
|
|
|
|
NS_HTML_CONTENT_INTERFACE_TABLE1(nsHTMLBodyElement, nsIDOMHTMLBodyElement)
|
|
|
|
NS_HTML_CONTENT_INTERFACE_TABLE_TO_MAP_SEGUE(nsHTMLBodyElement,
|
|
|
|
nsGenericHTMLElement)
|
2007-08-20 15:55:06 -07:00
|
|
|
NS_HTML_CONTENT_INTERFACE_TABLE_TAIL_CLASSINFO(HTMLBodyElement)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
NS_IMPL_ELEMENT_CLONE(nsHTMLBodyElement)
|
|
|
|
|
|
|
|
|
2011-06-03 23:57:23 -07:00
|
|
|
NS_IMPL_STRING_ATTR(nsHTMLBodyElement, Background, background)
|
2009-05-19 19:11:01 -07:00
|
|
|
NS_IMPL_STRING_ATTR(nsHTMLBodyElement, VLink, vlink)
|
|
|
|
NS_IMPL_STRING_ATTR(nsHTMLBodyElement, ALink, alink)
|
|
|
|
NS_IMPL_STRING_ATTR(nsHTMLBodyElement, Link, link)
|
|
|
|
NS_IMPL_STRING_ATTR(nsHTMLBodyElement, Text, text)
|
|
|
|
NS_IMPL_STRING_ATTR(nsHTMLBodyElement, BgColor, bgcolor)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2007-03-22 10:30:00 -07:00
|
|
|
nsHTMLBodyElement::ParseAttribute(PRInt32 aNamespaceID,
|
|
|
|
nsIAtom* aAttribute,
|
|
|
|
const nsAString& aValue,
|
|
|
|
nsAttrValue& aResult)
|
|
|
|
{
|
|
|
|
if (aNamespaceID == kNameSpaceID_None) {
|
|
|
|
if (aAttribute == nsGkAtoms::bgcolor ||
|
|
|
|
aAttribute == nsGkAtoms::text ||
|
|
|
|
aAttribute == nsGkAtoms::link ||
|
|
|
|
aAttribute == nsGkAtoms::alink ||
|
|
|
|
aAttribute == nsGkAtoms::vlink) {
|
2010-07-17 01:09:14 -07:00
|
|
|
return aResult.ParseColor(aValue);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
if (aAttribute == nsGkAtoms::marginwidth ||
|
|
|
|
aAttribute == nsGkAtoms::marginheight ||
|
|
|
|
aAttribute == nsGkAtoms::topmargin ||
|
|
|
|
aAttribute == nsGkAtoms::bottommargin ||
|
|
|
|
aAttribute == nsGkAtoms::leftmargin ||
|
|
|
|
aAttribute == nsGkAtoms::rightmargin) {
|
|
|
|
return aResult.ParseIntWithBounds(aValue, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsGenericHTMLElement::ParseAttribute(aNamespaceID, aAttribute, aValue,
|
|
|
|
aResult);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-09-28 23:19:26 -07:00
|
|
|
nsHTMLBodyElement::UnbindFromTree(bool aDeep, bool aNullParent)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (mContentStyleRule) {
|
|
|
|
mContentStyleRule->mPart = nsnull;
|
|
|
|
|
|
|
|
// destroy old style rule
|
|
|
|
NS_RELEASE(mContentStyleRule);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsGenericHTMLElement::UnbindFromTree(aDeep, aNullParent);
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
void MapAttributesIntoRule(const nsMappedAttributes* aAttributes, nsRuleData* aData)
|
|
|
|
{
|
2007-10-08 14:58:22 -07:00
|
|
|
if (aData->mSIDs & NS_STYLE_INHERIT_BIT(Display)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// When display if first asked for, go ahead and get our colors set up.
|
|
|
|
nsIPresShell *presShell = aData->mPresContext->GetPresShell();
|
|
|
|
if (presShell) {
|
|
|
|
nsIDocument *doc = presShell->GetDocument();
|
|
|
|
if (doc) {
|
|
|
|
nsHTMLStyleSheet* styleSheet = doc->GetAttributeStyleSheet();
|
|
|
|
if (styleSheet) {
|
|
|
|
const nsAttrValue* value;
|
|
|
|
nscolor color;
|
|
|
|
value = aAttributes->GetAttr(nsGkAtoms::link);
|
|
|
|
if (value && value->GetColorValue(color)) {
|
|
|
|
styleSheet->SetLinkColor(color);
|
|
|
|
}
|
|
|
|
|
|
|
|
value = aAttributes->GetAttr(nsGkAtoms::alink);
|
|
|
|
if (value && value->GetColorValue(color)) {
|
|
|
|
styleSheet->SetActiveLinkColor(color);
|
|
|
|
}
|
|
|
|
|
|
|
|
value = aAttributes->GetAttr(nsGkAtoms::vlink);
|
|
|
|
if (value && value->GetColorValue(color)) {
|
|
|
|
styleSheet->SetVisitedLinkColor(color);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-08 14:58:22 -07:00
|
|
|
if (aData->mSIDs & NS_STYLE_INHERIT_BIT(Color)) {
|
2011-03-17 20:14:31 -07:00
|
|
|
nsCSSValue *colorValue = aData->ValueForColor();
|
|
|
|
if (colorValue->GetUnit() == eCSSUnit_Null &&
|
2007-11-15 19:46:42 -08:00
|
|
|
aData->mPresContext->UseDocumentColors()) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// color: color
|
|
|
|
nscolor color;
|
|
|
|
const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::text);
|
|
|
|
if (value && value->GetColorValue(color))
|
2011-03-17 20:14:31 -07:00
|
|
|
colorValue->SetColorValue(color);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsGenericHTMLElement::MapBackgroundAttributesInto(aAttributes, aData);
|
|
|
|
nsGenericHTMLElement::MapCommonAttributesInto(aAttributes, aData);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsMapRuleToAttributesFunc
|
|
|
|
nsHTMLBodyElement::GetAttributeMappingFunction() const
|
|
|
|
{
|
|
|
|
return &MapAttributesIntoRule;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLBodyElement::WalkContentStyleRules(nsRuleWalker* aRuleWalker)
|
|
|
|
{
|
|
|
|
nsGenericHTMLElement::WalkContentStyleRules(aRuleWalker);
|
|
|
|
|
|
|
|
if (!mContentStyleRule && IsInDoc()) {
|
2011-10-18 03:53:36 -07:00
|
|
|
// XXXbz should this use OwnerDoc() or GetCurrentDoc()?
|
2007-03-22 10:30:00 -07:00
|
|
|
// sXBL/XBL2 issue!
|
|
|
|
mContentStyleRule = new BodyRule(this);
|
|
|
|
NS_IF_ADDREF(mContentStyleRule);
|
|
|
|
}
|
|
|
|
if (aRuleWalker && mContentStyleRule) {
|
|
|
|
aRuleWalker->Forward(mContentStyleRule);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
NS_IMETHODIMP_(bool)
|
2007-03-22 10:30:00 -07:00
|
|
|
nsHTMLBodyElement::IsAttributeMapped(const nsIAtom* aAttribute) const
|
|
|
|
{
|
|
|
|
static const MappedAttributeEntry attributes[] = {
|
|
|
|
{ &nsGkAtoms::link },
|
|
|
|
{ &nsGkAtoms::vlink },
|
|
|
|
{ &nsGkAtoms::alink },
|
|
|
|
{ &nsGkAtoms::text },
|
|
|
|
// These aren't mapped through attribute mapping, but they are
|
|
|
|
// mapped through a style rule, so it is attribute dependent style.
|
|
|
|
// XXXldb But we don't actually replace the body rule when we have
|
|
|
|
// dynamic changes...
|
|
|
|
{ &nsGkAtoms::marginwidth },
|
|
|
|
{ &nsGkAtoms::marginheight },
|
|
|
|
{ nsnull },
|
|
|
|
};
|
|
|
|
|
|
|
|
static const MappedAttributeEntry* const map[] = {
|
|
|
|
attributes,
|
|
|
|
sCommonAttributeMap,
|
|
|
|
sBackgroundAttributeMap,
|
|
|
|
};
|
|
|
|
|
2011-12-18 02:09:27 -08:00
|
|
|
return FindAttributeDependence(aAttribute, map);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<nsIEditor>
|
|
|
|
nsHTMLBodyElement::GetAssociatedEditor()
|
|
|
|
{
|
|
|
|
nsIEditor* editor = nsnull;
|
|
|
|
if (NS_SUCCEEDED(GetEditorInternal(&editor)) && editor) {
|
|
|
|
return editor;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure this is the actual body of the document
|
|
|
|
if (!IsCurrentBodyElement()) {
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
// For designmode, try to get document's editor
|
|
|
|
nsPresContext* presContext = GetPresContext();
|
|
|
|
if (!presContext) {
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsISupports> container = presContext->GetContainer();
|
|
|
|
nsCOMPtr<nsIEditorDocShell> editorDocShell = do_QueryInterface(container);
|
|
|
|
if (!editorDocShell) {
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
editorDocShell->GetEditor(&editor);
|
|
|
|
return editor;
|
|
|
|
}
|
2011-08-24 12:49:25 -07:00
|
|
|
|
|
|
|
// Event listener stuff
|
|
|
|
// FIXME (https://bugzilla.mozilla.org/show_bug.cgi?id=431767)
|
|
|
|
// nsDocument::GetInnerWindow can return an outer window in some
|
|
|
|
// cases. We don't want to stick an event listener on an outer
|
|
|
|
// window, so bail if it does. See also similar code in
|
|
|
|
// nsGenericHTMLElement::GetEventListenerManagerForAttr.
|
|
|
|
#define EVENT(name_, id_, type_, struct_) /* nothing; handled by the superclass */
|
|
|
|
#define FORWARDED_EVENT(name_, id_, type_, struct_) \
|
|
|
|
NS_IMETHODIMP nsHTMLBodyElement::GetOn##name_(JSContext *cx, \
|
|
|
|
jsval *vp) { \
|
|
|
|
/* XXXbz note to self: add tests for this! */ \
|
2011-10-18 03:53:36 -07:00
|
|
|
nsPIDOMWindow* win = OwnerDoc()->GetInnerWindow(); \
|
2011-08-24 12:49:25 -07:00
|
|
|
if (win && win->IsInnerWindow()) { \
|
|
|
|
nsCOMPtr<nsIInlineEventHandlers> ev = do_QueryInterface(win); \
|
|
|
|
return ev->GetOn##name_(cx, vp); \
|
|
|
|
} \
|
|
|
|
*vp = JSVAL_NULL; \
|
|
|
|
return NS_OK; \
|
|
|
|
} \
|
|
|
|
NS_IMETHODIMP nsHTMLBodyElement::SetOn##name_(JSContext *cx, \
|
|
|
|
const jsval &v) { \
|
2011-10-18 03:53:36 -07:00
|
|
|
nsPIDOMWindow* win = OwnerDoc()->GetInnerWindow(); \
|
2011-08-24 12:49:25 -07:00
|
|
|
if (win && win->IsInnerWindow()) { \
|
|
|
|
nsCOMPtr<nsIInlineEventHandlers> ev = do_QueryInterface(win); \
|
|
|
|
return ev->SetOn##name_(cx, v); \
|
|
|
|
} \
|
|
|
|
return NS_OK; \
|
|
|
|
}
|
|
|
|
#define WINDOW_EVENT(name_, id_, type_, struct_) \
|
|
|
|
NS_IMETHODIMP nsHTMLBodyElement::GetOn##name_(JSContext *cx, \
|
|
|
|
jsval *vp) { \
|
2011-10-18 03:53:36 -07:00
|
|
|
nsPIDOMWindow* win = OwnerDoc()->GetInnerWindow(); \
|
2011-08-24 12:49:25 -07:00
|
|
|
if (win && win->IsInnerWindow()) { \
|
|
|
|
return win->GetOn##name_(cx, vp); \
|
|
|
|
} \
|
|
|
|
*vp = JSVAL_NULL; \
|
|
|
|
return NS_OK; \
|
|
|
|
} \
|
|
|
|
NS_IMETHODIMP nsHTMLBodyElement::SetOn##name_(JSContext *cx, \
|
|
|
|
const jsval &v) { \
|
2011-10-18 03:53:36 -07:00
|
|
|
nsPIDOMWindow* win = OwnerDoc()->GetInnerWindow(); \
|
2011-08-24 12:49:25 -07:00
|
|
|
if (win && win->IsInnerWindow()) { \
|
|
|
|
return win->SetOn##name_(cx, v); \
|
|
|
|
} \
|
|
|
|
return NS_OK; \
|
|
|
|
}
|
|
|
|
#include "nsEventNameList.h"
|
|
|
|
#undef WINDOW_EVENT
|
|
|
|
#undef FORWARDED_EVENT
|
|
|
|
#undef EVENT
|