2015-05-03 19:32:37 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 11:12:37 +00: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-11 05:50:08 +00:00
|
|
|
|
2012-12-21 14:06:50 +00:00
|
|
|
#include "HTMLBodyElement.h"
|
2019-05-31 14:33:33 +00:00
|
|
|
#include "mozilla/dom/BindContext.h"
|
2012-12-21 14:07:28 +00:00
|
|
|
#include "mozilla/dom/HTMLBodyElementBinding.h"
|
2018-06-22 16:48:42 +00:00
|
|
|
#include "mozilla/MappedDeclarations.h"
|
2017-08-07 07:53:59 +00:00
|
|
|
#include "mozilla/HTMLEditor.h"
|
2017-06-22 06:21:31 +00:00
|
|
|
#include "mozilla/TextEditor.h"
|
2012-09-30 16:40:24 +00:00
|
|
|
#include "nsAttrValueInlines.h"
|
2007-01-30 00:06:41 +00:00
|
|
|
#include "nsGkAtoms.h"
|
1998-09-01 19:07:50 +00:00
|
|
|
#include "nsStyleConsts.h"
|
2004-07-31 23:15:21 +00:00
|
|
|
#include "nsPresContext.h"
|
2019-01-02 13:05:23 +00:00
|
|
|
#include "mozilla/dom/Document.h"
|
|
|
|
#include "DocumentInlines.h"
|
2004-04-12 21:56:09 +00:00
|
|
|
#include "nsHTMLStyleSheet.h"
|
2004-01-26 19:22:05 +00:00
|
|
|
#include "nsMappedAttributes.h"
|
2000-03-11 00:37:07 +00:00
|
|
|
#include "nsIDocShell.h"
|
2012-12-21 14:07:28 +00:00
|
|
|
#include "nsGlobalWindow.h"
|
1998-09-01 19:07:50 +00:00
|
|
|
|
2012-12-21 14:06:50 +00:00
|
|
|
NS_IMPL_NS_NEW_HTML_ELEMENT(Body)
|
2011-08-24 19:49:25 +00:00
|
|
|
|
2012-12-21 14:06:50 +00:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
1998-09-03 22:21:32 +00:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
2012-12-21 14:06:50 +00:00
|
|
|
HTMLBodyElement::~HTMLBodyElement() {}
|
1998-09-01 19:07:50 +00:00
|
|
|
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 14:13:33 +00:00
|
|
|
JSObject* HTMLBodyElement::WrapNode(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) {
|
2018-06-25 21:20:54 +00:00
|
|
|
return HTMLBodyElement_Binding::Wrap(aCx, this, aGivenProto);
|
2012-12-21 14:07:28 +00:00
|
|
|
}
|
1998-09-01 19:07:50 +00:00
|
|
|
|
2012-12-21 14:06:50 +00:00
|
|
|
NS_IMPL_ELEMENT_CLONE(HTMLBodyElement)
|
1998-09-01 19:07:50 +00:00
|
|
|
|
2012-12-21 14:06:50 +00:00
|
|
|
bool HTMLBodyElement::ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute,
|
|
|
|
const nsAString& aValue,
|
2017-11-02 03:35:52 +00:00
|
|
|
nsIPrincipal* aMaybeScriptedPrincipal,
|
2012-12-21 14:06:50 +00:00
|
|
|
nsAttrValue& aResult) {
|
2005-11-29 16:37:15 +00:00
|
|
|
if (aNamespaceID == kNameSpaceID_None) {
|
2006-12-26 17:47:52 +00:00
|
|
|
if (aAttribute == nsGkAtoms::bgcolor || aAttribute == nsGkAtoms::text ||
|
|
|
|
aAttribute == nsGkAtoms::link || aAttribute == nsGkAtoms::alink ||
|
|
|
|
aAttribute == nsGkAtoms::vlink) {
|
2010-07-17 08:09:14 +00:00
|
|
|
return aResult.ParseColor(aValue);
|
2005-11-29 16:37:15 +00:00
|
|
|
}
|
2006-12-26 17:47:52 +00:00
|
|
|
if (aAttribute == nsGkAtoms::marginwidth ||
|
|
|
|
aAttribute == nsGkAtoms::marginheight ||
|
|
|
|
aAttribute == nsGkAtoms::topmargin ||
|
|
|
|
aAttribute == nsGkAtoms::bottommargin ||
|
|
|
|
aAttribute == nsGkAtoms::leftmargin ||
|
|
|
|
aAttribute == nsGkAtoms::rightmargin) {
|
2019-06-28 23:32:12 +00:00
|
|
|
return aResult.ParseNonNegativeIntValue(aValue);
|
2005-11-29 16:37:15 +00:00
|
|
|
}
|
1998-09-03 22:21:32 +00:00
|
|
|
}
|
1998-09-01 19:07:50 +00:00
|
|
|
|
2012-08-24 17:50:49 +00:00
|
|
|
return nsGenericHTMLElement::ParseBackgroundAttribute(
|
|
|
|
aNamespaceID, aAttribute, aValue, aResult) ||
|
|
|
|
nsGenericHTMLElement::ParseAttribute(aNamespaceID, aAttribute, aValue,
|
2017-11-02 03:35:52 +00:00
|
|
|
aMaybeScriptedPrincipal, aResult);
|
1998-09-01 19:07:50 +00:00
|
|
|
}
|
|
|
|
|
2013-11-19 19:21:29 +00:00
|
|
|
void HTMLBodyElement::MapAttributesIntoRule(
|
|
|
|
const nsMappedAttributes* aAttributes, MappedDeclarations& aDecls) {
|
2018-03-29 01:39:07 +00:00
|
|
|
// This is the one place where we try to set the same property
|
|
|
|
// multiple times in presentation attributes. Servo does not support
|
|
|
|
// querying if a property is set (because that is O(n) behavior
|
|
|
|
// in ServoSpecifiedValues). Instead, we use the below values to keep
|
|
|
|
// track of whether we have already set a property, and if so, what value
|
|
|
|
// we set it to (which is used when handling margin
|
|
|
|
// attributes from the containing frame element)
|
|
|
|
|
|
|
|
int32_t bodyMarginWidth = -1;
|
|
|
|
int32_t bodyMarginHeight = -1;
|
|
|
|
int32_t bodyTopMargin = -1;
|
|
|
|
int32_t bodyBottomMargin = -1;
|
|
|
|
int32_t bodyLeftMargin = -1;
|
|
|
|
int32_t bodyRightMargin = -1;
|
|
|
|
|
|
|
|
const nsAttrValue* value;
|
|
|
|
// if marginwidth/marginheight are set, reflect them as 'margin'
|
|
|
|
value = aAttributes->GetAttr(nsGkAtoms::marginwidth);
|
|
|
|
if (value && value->Type() == nsAttrValue::eInteger) {
|
|
|
|
bodyMarginWidth = value->GetIntegerValue();
|
|
|
|
if (bodyMarginWidth < 0) {
|
|
|
|
bodyMarginWidth = 0;
|
|
|
|
}
|
2018-06-22 16:48:42 +00:00
|
|
|
aDecls.SetPixelValueIfUnset(eCSSProperty_margin_left,
|
|
|
|
(float)bodyMarginWidth);
|
|
|
|
aDecls.SetPixelValueIfUnset(eCSSProperty_margin_right,
|
|
|
|
(float)bodyMarginWidth);
|
2018-03-29 01:39:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
value = aAttributes->GetAttr(nsGkAtoms::marginheight);
|
|
|
|
if (value && value->Type() == nsAttrValue::eInteger) {
|
|
|
|
bodyMarginHeight = value->GetIntegerValue();
|
|
|
|
if (bodyMarginHeight < 0) {
|
|
|
|
bodyMarginHeight = 0;
|
|
|
|
}
|
2018-06-22 16:48:42 +00:00
|
|
|
aDecls.SetPixelValueIfUnset(eCSSProperty_margin_top,
|
|
|
|
(float)bodyMarginHeight);
|
|
|
|
aDecls.SetPixelValueIfUnset(eCSSProperty_margin_bottom,
|
|
|
|
(float)bodyMarginHeight);
|
2018-03-29 01:39:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// topmargin (IE-attribute)
|
|
|
|
if (bodyMarginHeight == -1) {
|
|
|
|
value = aAttributes->GetAttr(nsGkAtoms::topmargin);
|
2017-03-29 19:10:00 +00:00
|
|
|
if (value && value->Type() == nsAttrValue::eInteger) {
|
2018-03-29 01:39:07 +00:00
|
|
|
bodyTopMargin = value->GetIntegerValue();
|
|
|
|
if (bodyTopMargin < 0) {
|
|
|
|
bodyTopMargin = 0;
|
2017-03-29 19:10:00 +00:00
|
|
|
}
|
2018-06-22 16:48:42 +00:00
|
|
|
aDecls.SetPixelValueIfUnset(eCSSProperty_margin_top,
|
|
|
|
(float)bodyTopMargin);
|
2017-03-29 19:10:00 +00:00
|
|
|
}
|
2018-03-29 01:39:07 +00:00
|
|
|
}
|
|
|
|
// bottommargin (IE-attribute)
|
2017-03-29 19:10:00 +00:00
|
|
|
|
2018-03-29 01:39:07 +00:00
|
|
|
if (bodyMarginHeight == -1) {
|
|
|
|
value = aAttributes->GetAttr(nsGkAtoms::bottommargin);
|
2017-03-29 19:10:00 +00:00
|
|
|
if (value && value->Type() == nsAttrValue::eInteger) {
|
2018-03-29 01:39:07 +00:00
|
|
|
bodyBottomMargin = value->GetIntegerValue();
|
|
|
|
if (bodyBottomMargin < 0) {
|
|
|
|
bodyBottomMargin = 0;
|
2017-03-29 19:10:00 +00:00
|
|
|
}
|
2018-06-22 16:48:42 +00:00
|
|
|
aDecls.SetPixelValueIfUnset(eCSSProperty_margin_bottom,
|
|
|
|
(float)bodyBottomMargin);
|
2017-03-29 19:10:00 +00:00
|
|
|
}
|
2018-03-29 01:39:07 +00:00
|
|
|
}
|
2017-03-29 19:10:00 +00:00
|
|
|
|
2018-03-29 01:39:07 +00:00
|
|
|
// leftmargin (IE-attribute)
|
|
|
|
if (bodyMarginWidth == -1) {
|
|
|
|
value = aAttributes->GetAttr(nsGkAtoms::leftmargin);
|
|
|
|
if (value && value->Type() == nsAttrValue::eInteger) {
|
|
|
|
bodyLeftMargin = value->GetIntegerValue();
|
|
|
|
if (bodyLeftMargin < 0) {
|
|
|
|
bodyLeftMargin = 0;
|
2017-03-29 19:10:00 +00:00
|
|
|
}
|
2018-06-22 16:48:42 +00:00
|
|
|
aDecls.SetPixelValueIfUnset(eCSSProperty_margin_left,
|
|
|
|
(float)bodyLeftMargin);
|
2017-03-29 19:10:00 +00:00
|
|
|
}
|
2018-03-29 01:39:07 +00:00
|
|
|
}
|
|
|
|
// rightmargin (IE-attribute)
|
|
|
|
if (bodyMarginWidth == -1) {
|
|
|
|
value = aAttributes->GetAttr(nsGkAtoms::rightmargin);
|
|
|
|
if (value && value->Type() == nsAttrValue::eInteger) {
|
|
|
|
bodyRightMargin = value->GetIntegerValue();
|
|
|
|
if (bodyRightMargin < 0) {
|
|
|
|
bodyRightMargin = 0;
|
2017-03-29 19:10:00 +00:00
|
|
|
}
|
2018-06-22 16:48:42 +00:00
|
|
|
aDecls.SetPixelValueIfUnset(eCSSProperty_margin_right,
|
|
|
|
(float)bodyRightMargin);
|
2017-03-29 19:10:00 +00:00
|
|
|
}
|
2018-03-29 01:39:07 +00:00
|
|
|
}
|
2017-03-29 19:10:00 +00:00
|
|
|
|
2018-03-29 01:39:07 +00: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) {
|
2018-06-22 16:48:42 +00:00
|
|
|
nsCOMPtr<nsIDocShell> docShell(aDecls.Document()->GetDocShell());
|
2018-03-29 01:39:07 +00:00
|
|
|
if (docShell) {
|
|
|
|
nscoord frameMarginWidth = -1; // default value
|
|
|
|
nscoord frameMarginHeight = -1; // default value
|
|
|
|
docShell->GetMarginWidth(&frameMarginWidth); // -1 indicates not set
|
|
|
|
docShell->GetMarginHeight(&frameMarginHeight);
|
|
|
|
|
|
|
|
if (bodyMarginWidth == -1 && frameMarginWidth >= 0) {
|
|
|
|
if (bodyLeftMargin == -1) {
|
2018-06-22 16:48:42 +00:00
|
|
|
aDecls.SetPixelValueIfUnset(eCSSProperty_margin_left,
|
|
|
|
(float)frameMarginWidth);
|
2017-03-29 19:10:00 +00:00
|
|
|
}
|
2018-03-29 01:39:07 +00:00
|
|
|
if (bodyRightMargin == -1) {
|
2018-06-22 16:48:42 +00:00
|
|
|
aDecls.SetPixelValueIfUnset(eCSSProperty_margin_right,
|
|
|
|
(float)frameMarginWidth);
|
2017-03-29 19:10:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-29 01:39:07 +00:00
|
|
|
if (bodyMarginHeight == -1 && frameMarginHeight >= 0) {
|
|
|
|
if (bodyTopMargin == -1) {
|
2018-06-22 16:48:42 +00:00
|
|
|
aDecls.SetPixelValueIfUnset(eCSSProperty_margin_top,
|
|
|
|
(float)frameMarginHeight);
|
2017-03-29 19:10:00 +00:00
|
|
|
}
|
2018-03-29 01:39:07 +00:00
|
|
|
if (bodyBottomMargin == -1) {
|
2018-06-22 16:48:42 +00:00
|
|
|
aDecls.SetPixelValueIfUnset(eCSSProperty_margin_bottom,
|
|
|
|
(float)frameMarginHeight);
|
2017-03-29 19:10:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-29 01:39:07 +00:00
|
|
|
// When display if first asked for, go ahead and get our colors set up.
|
2018-06-22 16:48:42 +00:00
|
|
|
if (nsHTMLStyleSheet* styleSheet =
|
|
|
|
aDecls.Document()->GetAttributeStyleSheet()) {
|
2018-03-29 01:39:07 +00:00
|
|
|
nscolor color;
|
|
|
|
value = aAttributes->GetAttr(nsGkAtoms::link);
|
|
|
|
if (value && value->GetColorValue(color)) {
|
|
|
|
styleSheet->SetLinkColor(color);
|
|
|
|
}
|
2004-01-13 23:14:49 +00:00
|
|
|
|
2018-03-29 01:39:07 +00:00
|
|
|
value = aAttributes->GetAttr(nsGkAtoms::alink);
|
|
|
|
if (value && value->GetColorValue(color)) {
|
|
|
|
styleSheet->SetActiveLinkColor(color);
|
|
|
|
}
|
2004-01-13 23:14:49 +00:00
|
|
|
|
2018-03-29 01:39:07 +00:00
|
|
|
value = aAttributes->GetAttr(nsGkAtoms::vlink);
|
|
|
|
if (value && value->GetColorValue(color)) {
|
|
|
|
styleSheet->SetVisitedLinkColor(color);
|
1998-09-03 22:21:32 +00:00
|
|
|
}
|
2001-05-31 22:19:43 +00:00
|
|
|
}
|
1998-09-03 22:21:32 +00:00
|
|
|
|
2018-06-22 16:48:42 +00:00
|
|
|
if (!aDecls.PropertyIsSet(eCSSProperty_color)) {
|
2018-03-29 01:39:07 +00:00
|
|
|
// color: color
|
|
|
|
nscolor color;
|
|
|
|
value = aAttributes->GetAttr(nsGkAtoms::text);
|
|
|
|
if (value && value->GetColorValue(color)) {
|
2018-06-22 16:48:42 +00:00
|
|
|
aDecls.SetColorValue(eCSSProperty_color, color);
|
2001-05-31 22:19:43 +00:00
|
|
|
}
|
1998-09-03 22:21:32 +00:00
|
|
|
}
|
2001-05-31 22:19:43 +00:00
|
|
|
|
2018-06-22 16:48:42 +00:00
|
|
|
nsGenericHTMLElement::MapBackgroundAttributesInto(aAttributes, aDecls);
|
|
|
|
nsGenericHTMLElement::MapCommonAttributesInto(aAttributes, aDecls);
|
1998-09-01 19:07:50 +00:00
|
|
|
}
|
|
|
|
|
2012-12-21 14:06:50 +00:00
|
|
|
nsMapRuleToAttributesFunc HTMLBodyElement::GetAttributeMappingFunction() const {
|
2005-01-12 19:45:38 +00:00
|
|
|
return &MapAttributesIntoRule;
|
1998-09-05 04:00:06 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
NS_IMETHODIMP_(bool)
|
2017-10-02 22:05:19 +00:00
|
|
|
HTMLBodyElement::IsAttributeMapped(const nsAtom* aAttribute) const {
|
2004-02-25 21:04:50 +00:00
|
|
|
static const MappedAttributeEntry attributes[] = {
|
2018-04-03 03:21:06 +00:00
|
|
|
{nsGkAtoms::link},
|
|
|
|
{nsGkAtoms::vlink},
|
|
|
|
{nsGkAtoms::alink},
|
|
|
|
{nsGkAtoms::text},
|
|
|
|
{nsGkAtoms::marginwidth},
|
|
|
|
{nsGkAtoms::marginheight},
|
|
|
|
{nsGkAtoms::topmargin},
|
|
|
|
{nsGkAtoms::rightmargin},
|
|
|
|
{nsGkAtoms::bottommargin},
|
|
|
|
{nsGkAtoms::leftmargin},
|
2012-07-30 14:20:58 +00:00
|
|
|
{nullptr},
|
2003-04-16 20:54:20 +00:00
|
|
|
};
|
|
|
|
|
2004-02-25 21:04:50 +00:00
|
|
|
static const MappedAttributeEntry* const map[] = {
|
2003-04-16 20:54:20 +00:00
|
|
|
attributes,
|
|
|
|
sCommonAttributeMap,
|
|
|
|
sBackgroundAttributeMap,
|
|
|
|
};
|
|
|
|
|
2011-12-18 10:09:27 +00:00
|
|
|
return FindAttributeDependence(aAttribute, map);
|
1999-01-14 23:14:02 +00:00
|
|
|
}
|
2006-07-29 00:04:40 +00:00
|
|
|
|
2012-12-21 14:06:50 +00:00
|
|
|
already_AddRefed<TextEditor> HTMLBodyElement::GetAssociatedEditor() {
|
2017-06-22 06:21:31 +00:00
|
|
|
RefPtr<TextEditor> textEditor = GetTextEditorInternal();
|
|
|
|
if (textEditor) {
|
|
|
|
return textEditor.forget();
|
2006-07-29 00:04:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure this is the actual body of the document
|
2018-01-26 05:53:35 +00:00
|
|
|
if (this != OwnerDoc()->GetBodyElement()) {
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2006-07-29 00:04:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// For designmode, try to get document's editor
|
2014-08-22 20:11:27 +00:00
|
|
|
nsPresContext* presContext = GetPresContext(eForComposedDoc);
|
2006-07-29 00:04:40 +00:00
|
|
|
if (!presContext) {
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2006-07-29 00:04:40 +00:00
|
|
|
}
|
|
|
|
|
2013-11-20 19:18:25 +00:00
|
|
|
nsCOMPtr<nsIDocShell> docShell = presContext->GetDocShell();
|
2013-02-13 22:39:30 +00:00
|
|
|
if (!docShell) {
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2006-07-29 00:04:40 +00:00
|
|
|
}
|
|
|
|
|
2017-08-07 07:53:59 +00:00
|
|
|
RefPtr<HTMLEditor> htmlEditor = docShell->GetHTMLEditor();
|
|
|
|
return htmlEditor.forget();
|
2006-07-29 00:04:40 +00:00
|
|
|
}
|
2011-08-24 19:49:25 +00:00
|
|
|
|
2017-10-02 22:05:19 +00:00
|
|
|
bool HTMLBodyElement::IsEventAttributeNameInternal(nsAtom* aName) {
|
2013-01-02 20:24:07 +00:00
|
|
|
return nsContentUtils::IsEventAttributeName(
|
|
|
|
aName, EventNameType_HTML | EventNameType_HTMLBodyOrFramesetOnly);
|
|
|
|
}
|
|
|
|
|
Bug 1555216 - Change the signature of BindToTree to be (BindContext&, nsINode& aParentNode). r=bzbarsky
BindContext was going to have way more information at first, but then I realized
that most of the things I wanted to know were basically a flag away using the
parent node.
Still I think it's worth it, now experimenting with BindToTree will only mean
adding a field to a struct that's included from a couple cpp files, instead of a
massive pain.
I also think this is clearer, and doing this highlights quite a few
inconsistencies in our code which I've left untouched, but commented with
FIXMEs.
Steps are:
$ for file in $(rg 'nsresult BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#nsresult BindToTree(Document\* aDocument, nsIContent\* aParent,#nsresult BindToTree(BindContext\&, nsINode\& aParent)#g' $file; done
$ for file in $(rg 'nsresult BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's# nsIContent\* aBindingParent) override#override#g' $file; done
$ for file in $(rg '::BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#::BindToTree(Document\* aDocument, nsIContent\* aParent,#::BindToTree(BindContext\& aContext, nsINode\& aParent)#g' $file; done
$ for file in $(rg '::BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#nsIContent\* aBindingParent)##g' $file; done
$ for file in $(rg '::BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#::BindToTree(aDocument, aParent, aBindingParent)#::BindToTree(aContext, aParent)#g' $file; done
$ ./mach clang-format
Then manual fixups.
Depends on D32948
Differential Revision: https://phabricator.services.mozilla.com/D32949
2019-05-29 04:27:04 +00:00
|
|
|
nsresult HTMLBodyElement::BindToTree(BindContext& aContext, nsINode& aParent) {
|
|
|
|
nsresult rv = nsGenericHTMLElement::BindToTree(aContext, aParent);
|
2017-03-29 19:10:00 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2019-05-31 14:33:33 +00:00
|
|
|
return mAttrs.ForceMapped(this, &aContext.OwnerDoc());
|
2017-03-29 19:10:00 +00:00
|
|
|
}
|
|
|
|
|
2017-10-02 22:05:19 +00:00
|
|
|
nsresult HTMLBodyElement::AfterSetAttr(int32_t aNameSpaceID, nsAtom* aName,
|
2017-03-29 19:10:00 +00:00
|
|
|
const nsAttrValue* aValue,
|
2017-10-09 21:33:38 +00:00
|
|
|
const nsAttrValue* aOldValue,
|
|
|
|
nsIPrincipal* aSubjectPrincipal,
|
|
|
|
bool aNotify) {
|
2017-03-29 19:10:00 +00:00
|
|
|
nsresult rv = nsGenericHTMLElement::AfterSetAttr(
|
2017-10-09 21:33:38 +00:00
|
|
|
aNameSpaceID, aName, aValue, aOldValue, aSubjectPrincipal, aNotify);
|
2017-03-29 19:10:00 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
// if the last mapped attribute was removed, don't clear the
|
|
|
|
// nsMappedAttributes, our style can still depend on the containing frame
|
|
|
|
// element
|
|
|
|
if (!aValue && IsAttributeMapped(aName)) {
|
2018-08-07 19:07:26 +00:00
|
|
|
nsresult rv = mAttrs.ForceMapped(this, OwnerDoc());
|
2017-03-29 19:10:00 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-08-24 19:49:25 +00:00
|
|
|
#define EVENT(name_, id_, type_, \
|
|
|
|
struct_) /* nothing; handled by the superclass */
|
2012-11-26 14:19:02 +00:00
|
|
|
// nsGenericHTMLElement::GetOnError returns
|
|
|
|
// already_AddRefed<EventHandlerNonNull> while other getters return
|
|
|
|
// EventHandlerNonNull*, so allow passing in the type to use here.
|
2012-12-21 14:07:28 +00:00
|
|
|
#define WINDOW_EVENT_HELPER(name_, type_) \
|
|
|
|
type_* HTMLBodyElement::GetOn##name_() { \
|
2016-01-30 17:05:36 +00:00
|
|
|
if (nsPIDOMWindowInner* win = OwnerDoc()->GetInnerWindow()) { \
|
2017-11-03 22:25:38 +00:00
|
|
|
nsGlobalWindowInner* globalWin = nsGlobalWindowInner::Cast(win); \
|
2012-12-21 14:07:28 +00:00
|
|
|
return globalWin->GetOn##name_(); \
|
2012-12-21 14:06:50 +00:00
|
|
|
} \
|
2012-12-21 14:07:28 +00:00
|
|
|
return nullptr; \
|
2012-12-21 14:06:50 +00:00
|
|
|
} \
|
2013-09-17 11:01:28 +00:00
|
|
|
void HTMLBodyElement::SetOn##name_(type_* handler) { \
|
2016-01-30 17:05:36 +00:00
|
|
|
nsPIDOMWindowInner* win = OwnerDoc()->GetInnerWindow(); \
|
2013-04-29 15:34:16 +00:00
|
|
|
if (!win) { \
|
2012-12-21 14:07:28 +00:00
|
|
|
return; \
|
2012-12-21 14:06:50 +00:00
|
|
|
} \
|
2012-12-21 14:07:28 +00:00
|
|
|
\
|
2017-11-03 22:25:38 +00:00
|
|
|
nsGlobalWindowInner* globalWin = nsGlobalWindowInner::Cast(win); \
|
2013-09-17 11:01:28 +00:00
|
|
|
return globalWin->SetOn##name_(handler); \
|
2013-11-16 12:31:37 +00:00
|
|
|
}
|
2012-12-21 14:07:28 +00:00
|
|
|
#define WINDOW_EVENT(name_, id_, type_, struct_) \
|
|
|
|
WINDOW_EVENT_HELPER(name_, EventHandlerNonNull)
|
|
|
|
#define BEFOREUNLOAD_EVENT(name_, id_, type_, struct_) \
|
2013-10-08 15:51:15 +00:00
|
|
|
WINDOW_EVENT_HELPER(name_, OnBeforeUnloadEventHandlerNonNull)
|
2014-04-01 11:42:12 +00:00
|
|
|
#include "mozilla/EventNameList.h" // IWYU pragma: keep
|
2012-12-21 14:07:28 +00:00
|
|
|
#undef BEFOREUNLOAD_EVENT
|
2011-08-24 19:49:25 +00:00
|
|
|
#undef WINDOW_EVENT
|
2012-12-21 14:07:28 +00:00
|
|
|
#undef WINDOW_EVENT_HELPER
|
2011-08-24 19:49:25 +00:00
|
|
|
#undef EVENT
|
2012-12-21 14:06:50 +00:00
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|