2015-05-03 22:32:37 +03: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 15:12:37 +04: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 09:50:08 +04:00
|
|
|
|
2012-12-21 18:06:50 +04:00
|
|
|
#include "HTMLBodyElement.h"
|
2019-05-31 17:33:33 +03:00
|
|
|
#include "mozilla/dom/BindContext.h"
|
2012-12-21 18:07:28 +04:00
|
|
|
#include "mozilla/dom/HTMLBodyElementBinding.h"
|
2018-06-22 19:48:42 +03:00
|
|
|
#include "mozilla/MappedDeclarations.h"
|
2017-08-07 10:53:59 +03:00
|
|
|
#include "mozilla/HTMLEditor.h"
|
2017-06-22 09:21:31 +03:00
|
|
|
#include "mozilla/TextEditor.h"
|
2012-09-30 20:40:24 +04:00
|
|
|
#include "nsAttrValueInlines.h"
|
2007-01-30 03:06:41 +03:00
|
|
|
#include "nsGkAtoms.h"
|
1998-09-01 23:07:50 +04:00
|
|
|
#include "nsStyleConsts.h"
|
2004-08-01 03:15:21 +04:00
|
|
|
#include "nsPresContext.h"
|
2019-01-02 16:05:23 +03:00
|
|
|
#include "mozilla/dom/Document.h"
|
|
|
|
#include "DocumentInlines.h"
|
2020-02-11 04:22:29 +03:00
|
|
|
#include "nsDocShell.h"
|
2004-04-13 01:56:09 +04:00
|
|
|
#include "nsHTMLStyleSheet.h"
|
2004-01-26 22:22:05 +03:00
|
|
|
#include "nsMappedAttributes.h"
|
2000-03-11 03:37:07 +03:00
|
|
|
#include "nsIDocShell.h"
|
2012-12-21 18:07:28 +04:00
|
|
|
#include "nsGlobalWindow.h"
|
1998-09-01 23:07:50 +04:00
|
|
|
|
2012-12-21 18:06:50 +04:00
|
|
|
NS_IMPL_NS_NEW_HTML_ELEMENT(Body)
|
2011-08-24 23:49:25 +04:00
|
|
|
|
2020-11-04 20:04:01 +03:00
|
|
|
namespace mozilla::dom {
|
1998-09-04 02:21:32 +04:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
2020-02-20 19:19:15 +03:00
|
|
|
HTMLBodyElement::~HTMLBodyElement() = default;
|
1998-09-01 23:07:50 +04: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 17:13:33 +03:00
|
|
|
JSObject* HTMLBodyElement::WrapNode(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) {
|
2018-06-26 00:20:54 +03:00
|
|
|
return HTMLBodyElement_Binding::Wrap(aCx, this, aGivenProto);
|
2012-12-21 18:07:28 +04:00
|
|
|
}
|
1998-09-01 23:07:50 +04:00
|
|
|
|
2012-12-21 18:06:50 +04:00
|
|
|
NS_IMPL_ELEMENT_CLONE(HTMLBodyElement)
|
1998-09-01 23:07:50 +04:00
|
|
|
|
2012-12-21 18:06:50 +04:00
|
|
|
bool HTMLBodyElement::ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute,
|
|
|
|
const nsAString& aValue,
|
2017-11-02 06:35:52 +03:00
|
|
|
nsIPrincipal* aMaybeScriptedPrincipal,
|
2012-12-21 18:06:50 +04:00
|
|
|
nsAttrValue& aResult) {
|
2005-11-29 19:37:15 +03:00
|
|
|
if (aNamespaceID == kNameSpaceID_None) {
|
2006-12-26 20:47:52 +03:00
|
|
|
if (aAttribute == nsGkAtoms::bgcolor || aAttribute == nsGkAtoms::text ||
|
|
|
|
aAttribute == nsGkAtoms::link || aAttribute == nsGkAtoms::alink ||
|
|
|
|
aAttribute == nsGkAtoms::vlink) {
|
2010-07-17 12:09:14 +04:00
|
|
|
return aResult.ParseColor(aValue);
|
2005-11-29 19:37:15 +03:00
|
|
|
}
|
2006-12-26 20:47:52 +03:00
|
|
|
if (aAttribute == nsGkAtoms::marginwidth ||
|
|
|
|
aAttribute == nsGkAtoms::marginheight ||
|
|
|
|
aAttribute == nsGkAtoms::topmargin ||
|
|
|
|
aAttribute == nsGkAtoms::bottommargin ||
|
|
|
|
aAttribute == nsGkAtoms::leftmargin ||
|
|
|
|
aAttribute == nsGkAtoms::rightmargin) {
|
2019-06-29 02:32:12 +03:00
|
|
|
return aResult.ParseNonNegativeIntValue(aValue);
|
2005-11-29 19:37:15 +03:00
|
|
|
}
|
1998-09-04 02:21:32 +04:00
|
|
|
}
|
1998-09-01 23:07:50 +04:00
|
|
|
|
2012-08-24 21:50:49 +04:00
|
|
|
return nsGenericHTMLElement::ParseBackgroundAttribute(
|
|
|
|
aNamespaceID, aAttribute, aValue, aResult) ||
|
|
|
|
nsGenericHTMLElement::ParseAttribute(aNamespaceID, aAttribute, aValue,
|
2017-11-02 06:35:52 +03:00
|
|
|
aMaybeScriptedPrincipal, aResult);
|
1998-09-01 23:07:50 +04:00
|
|
|
}
|
|
|
|
|
2013-11-19 23:21:29 +04:00
|
|
|
void HTMLBodyElement::MapAttributesIntoRule(
|
|
|
|
const nsMappedAttributes* aAttributes, MappedDeclarations& aDecls) {
|
2018-03-29 04:39:07 +03: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 19:48:42 +03:00
|
|
|
aDecls.SetPixelValueIfUnset(eCSSProperty_margin_left,
|
|
|
|
(float)bodyMarginWidth);
|
|
|
|
aDecls.SetPixelValueIfUnset(eCSSProperty_margin_right,
|
|
|
|
(float)bodyMarginWidth);
|
2018-03-29 04:39:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
value = aAttributes->GetAttr(nsGkAtoms::marginheight);
|
|
|
|
if (value && value->Type() == nsAttrValue::eInteger) {
|
|
|
|
bodyMarginHeight = value->GetIntegerValue();
|
|
|
|
if (bodyMarginHeight < 0) {
|
|
|
|
bodyMarginHeight = 0;
|
|
|
|
}
|
2018-06-22 19:48:42 +03:00
|
|
|
aDecls.SetPixelValueIfUnset(eCSSProperty_margin_top,
|
|
|
|
(float)bodyMarginHeight);
|
|
|
|
aDecls.SetPixelValueIfUnset(eCSSProperty_margin_bottom,
|
|
|
|
(float)bodyMarginHeight);
|
2018-03-29 04:39:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// topmargin (IE-attribute)
|
|
|
|
if (bodyMarginHeight == -1) {
|
|
|
|
value = aAttributes->GetAttr(nsGkAtoms::topmargin);
|
2017-03-29 22:10:00 +03:00
|
|
|
if (value && value->Type() == nsAttrValue::eInteger) {
|
2018-03-29 04:39:07 +03:00
|
|
|
bodyTopMargin = value->GetIntegerValue();
|
|
|
|
if (bodyTopMargin < 0) {
|
|
|
|
bodyTopMargin = 0;
|
2017-03-29 22:10:00 +03:00
|
|
|
}
|
2018-06-22 19:48:42 +03:00
|
|
|
aDecls.SetPixelValueIfUnset(eCSSProperty_margin_top,
|
|
|
|
(float)bodyTopMargin);
|
2017-03-29 22:10:00 +03:00
|
|
|
}
|
2018-03-29 04:39:07 +03:00
|
|
|
}
|
|
|
|
// bottommargin (IE-attribute)
|
2017-03-29 22:10:00 +03:00
|
|
|
|
2018-03-29 04:39:07 +03:00
|
|
|
if (bodyMarginHeight == -1) {
|
|
|
|
value = aAttributes->GetAttr(nsGkAtoms::bottommargin);
|
2017-03-29 22:10:00 +03:00
|
|
|
if (value && value->Type() == nsAttrValue::eInteger) {
|
2018-03-29 04:39:07 +03:00
|
|
|
bodyBottomMargin = value->GetIntegerValue();
|
|
|
|
if (bodyBottomMargin < 0) {
|
|
|
|
bodyBottomMargin = 0;
|
2017-03-29 22:10:00 +03:00
|
|
|
}
|
2018-06-22 19:48:42 +03:00
|
|
|
aDecls.SetPixelValueIfUnset(eCSSProperty_margin_bottom,
|
|
|
|
(float)bodyBottomMargin);
|
2017-03-29 22:10:00 +03:00
|
|
|
}
|
2018-03-29 04:39:07 +03:00
|
|
|
}
|
2017-03-29 22:10:00 +03:00
|
|
|
|
2018-03-29 04:39:07 +03: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 22:10:00 +03:00
|
|
|
}
|
2018-06-22 19:48:42 +03:00
|
|
|
aDecls.SetPixelValueIfUnset(eCSSProperty_margin_left,
|
|
|
|
(float)bodyLeftMargin);
|
2017-03-29 22:10:00 +03:00
|
|
|
}
|
2018-03-29 04:39:07 +03: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 22:10:00 +03:00
|
|
|
}
|
2018-06-22 19:48:42 +03:00
|
|
|
aDecls.SetPixelValueIfUnset(eCSSProperty_margin_right,
|
|
|
|
(float)bodyRightMargin);
|
2017-03-29 22:10:00 +03:00
|
|
|
}
|
2018-03-29 04:39:07 +03:00
|
|
|
}
|
2017-03-29 22:10:00 +03:00
|
|
|
|
2018-03-29 04:39:07 +03: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) {
|
2020-01-06 01:48:40 +03:00
|
|
|
if (nsDocShell* ds = nsDocShell::Cast(aDecls.Document()->GetDocShell())) {
|
|
|
|
CSSIntSize margins = ds->GetFrameMargins();
|
|
|
|
int32_t frameMarginWidth = margins.width;
|
|
|
|
int32_t frameMarginHeight = margins.height;
|
2018-03-29 04:39:07 +03:00
|
|
|
|
|
|
|
if (bodyMarginWidth == -1 && frameMarginWidth >= 0) {
|
|
|
|
if (bodyLeftMargin == -1) {
|
2018-06-22 19:48:42 +03:00
|
|
|
aDecls.SetPixelValueIfUnset(eCSSProperty_margin_left,
|
|
|
|
(float)frameMarginWidth);
|
2017-03-29 22:10:00 +03:00
|
|
|
}
|
2018-03-29 04:39:07 +03:00
|
|
|
if (bodyRightMargin == -1) {
|
2018-06-22 19:48:42 +03:00
|
|
|
aDecls.SetPixelValueIfUnset(eCSSProperty_margin_right,
|
|
|
|
(float)frameMarginWidth);
|
2017-03-29 22:10:00 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-29 04:39:07 +03:00
|
|
|
if (bodyMarginHeight == -1 && frameMarginHeight >= 0) {
|
|
|
|
if (bodyTopMargin == -1) {
|
2018-06-22 19:48:42 +03:00
|
|
|
aDecls.SetPixelValueIfUnset(eCSSProperty_margin_top,
|
|
|
|
(float)frameMarginHeight);
|
2017-03-29 22:10:00 +03:00
|
|
|
}
|
2018-03-29 04:39:07 +03:00
|
|
|
if (bodyBottomMargin == -1) {
|
2018-06-22 19:48:42 +03:00
|
|
|
aDecls.SetPixelValueIfUnset(eCSSProperty_margin_bottom,
|
|
|
|
(float)frameMarginHeight);
|
2017-03-29 22:10:00 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-29 04:39:07 +03:00
|
|
|
// When display if first asked for, go ahead and get our colors set up.
|
2018-06-22 19:48:42 +03:00
|
|
|
if (nsHTMLStyleSheet* styleSheet =
|
|
|
|
aDecls.Document()->GetAttributeStyleSheet()) {
|
2018-03-29 04:39:07 +03:00
|
|
|
nscolor color;
|
|
|
|
value = aAttributes->GetAttr(nsGkAtoms::link);
|
|
|
|
if (value && value->GetColorValue(color)) {
|
|
|
|
styleSheet->SetLinkColor(color);
|
|
|
|
}
|
2004-01-14 02:14:49 +03:00
|
|
|
|
2018-03-29 04:39:07 +03:00
|
|
|
value = aAttributes->GetAttr(nsGkAtoms::alink);
|
|
|
|
if (value && value->GetColorValue(color)) {
|
|
|
|
styleSheet->SetActiveLinkColor(color);
|
|
|
|
}
|
2004-01-14 02:14:49 +03:00
|
|
|
|
2018-03-29 04:39:07 +03:00
|
|
|
value = aAttributes->GetAttr(nsGkAtoms::vlink);
|
|
|
|
if (value && value->GetColorValue(color)) {
|
|
|
|
styleSheet->SetVisitedLinkColor(color);
|
1998-09-04 02:21:32 +04:00
|
|
|
}
|
2001-06-01 02:19:43 +04:00
|
|
|
}
|
1998-09-04 02:21:32 +04:00
|
|
|
|
2018-06-22 19:48:42 +03:00
|
|
|
if (!aDecls.PropertyIsSet(eCSSProperty_color)) {
|
2018-03-29 04:39:07 +03:00
|
|
|
// color: color
|
|
|
|
nscolor color;
|
|
|
|
value = aAttributes->GetAttr(nsGkAtoms::text);
|
|
|
|
if (value && value->GetColorValue(color)) {
|
2018-06-22 19:48:42 +03:00
|
|
|
aDecls.SetColorValue(eCSSProperty_color, color);
|
2001-06-01 02:19:43 +04:00
|
|
|
}
|
1998-09-04 02:21:32 +04:00
|
|
|
}
|
2001-06-01 02:19:43 +04:00
|
|
|
|
2018-06-22 19:48:42 +03:00
|
|
|
nsGenericHTMLElement::MapBackgroundAttributesInto(aAttributes, aDecls);
|
|
|
|
nsGenericHTMLElement::MapCommonAttributesInto(aAttributes, aDecls);
|
1998-09-01 23:07:50 +04:00
|
|
|
}
|
|
|
|
|
2012-12-21 18:06:50 +04:00
|
|
|
nsMapRuleToAttributesFunc HTMLBodyElement::GetAttributeMappingFunction() const {
|
2005-01-12 22:45:38 +03:00
|
|
|
return &MapAttributesIntoRule;
|
1998-09-05 08:00:06 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
NS_IMETHODIMP_(bool)
|
2017-10-03 01:05:19 +03:00
|
|
|
HTMLBodyElement::IsAttributeMapped(const nsAtom* aAttribute) const {
|
2004-02-26 00:04:50 +03:00
|
|
|
static const MappedAttributeEntry attributes[] = {
|
2018-04-03 06:21:06 +03:00
|
|
|
{nsGkAtoms::link},
|
|
|
|
{nsGkAtoms::vlink},
|
|
|
|
{nsGkAtoms::alink},
|
|
|
|
{nsGkAtoms::text},
|
|
|
|
{nsGkAtoms::marginwidth},
|
|
|
|
{nsGkAtoms::marginheight},
|
|
|
|
{nsGkAtoms::topmargin},
|
|
|
|
{nsGkAtoms::rightmargin},
|
|
|
|
{nsGkAtoms::bottommargin},
|
|
|
|
{nsGkAtoms::leftmargin},
|
2012-07-30 18:20:58 +04:00
|
|
|
{nullptr},
|
2003-04-17 00:54:20 +04:00
|
|
|
};
|
|
|
|
|
2004-02-26 00:04:50 +03:00
|
|
|
static const MappedAttributeEntry* const map[] = {
|
2003-04-17 00:54:20 +04:00
|
|
|
attributes,
|
|
|
|
sCommonAttributeMap,
|
|
|
|
sBackgroundAttributeMap,
|
|
|
|
};
|
|
|
|
|
2011-12-18 14:09:27 +04:00
|
|
|
return FindAttributeDependence(aAttribute, map);
|
1999-01-15 02:14:02 +03:00
|
|
|
}
|
2006-07-29 04:04:40 +04:00
|
|
|
|
2012-12-21 18:06:50 +04:00
|
|
|
already_AddRefed<TextEditor> HTMLBodyElement::GetAssociatedEditor() {
|
2017-06-22 09:21:31 +03:00
|
|
|
RefPtr<TextEditor> textEditor = GetTextEditorInternal();
|
|
|
|
if (textEditor) {
|
|
|
|
return textEditor.forget();
|
2006-07-29 04:04:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure this is the actual body of the document
|
2018-01-26 08:53:35 +03:00
|
|
|
if (this != OwnerDoc()->GetBodyElement()) {
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2006-07-29 04:04:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// For designmode, try to get document's editor
|
2014-08-23 00:11:27 +04:00
|
|
|
nsPresContext* presContext = GetPresContext(eForComposedDoc);
|
2006-07-29 04:04:40 +04:00
|
|
|
if (!presContext) {
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2006-07-29 04:04:40 +04:00
|
|
|
}
|
|
|
|
|
2013-11-20 23:18:25 +04:00
|
|
|
nsCOMPtr<nsIDocShell> docShell = presContext->GetDocShell();
|
2013-02-14 02:39:30 +04:00
|
|
|
if (!docShell) {
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2006-07-29 04:04:40 +04:00
|
|
|
}
|
|
|
|
|
2017-08-07 10:53:59 +03:00
|
|
|
RefPtr<HTMLEditor> htmlEditor = docShell->GetHTMLEditor();
|
|
|
|
return htmlEditor.forget();
|
2006-07-29 04:04:40 +04:00
|
|
|
}
|
2011-08-24 23:49:25 +04:00
|
|
|
|
2017-10-03 01:05:19 +03:00
|
|
|
bool HTMLBodyElement::IsEventAttributeNameInternal(nsAtom* aName) {
|
2013-01-03 00:24:07 +04: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 07:27:04 +03:00
|
|
|
nsresult HTMLBodyElement::BindToTree(BindContext& aContext, nsINode& aParent) {
|
|
|
|
nsresult rv = nsGenericHTMLElement::BindToTree(aContext, aParent);
|
2017-03-29 22:10:00 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2019-05-31 17:33:33 +03:00
|
|
|
return mAttrs.ForceMapped(this, &aContext.OwnerDoc());
|
2017-03-29 22:10:00 +03:00
|
|
|
}
|
|
|
|
|
2017-10-03 01:05:19 +03:00
|
|
|
nsresult HTMLBodyElement::AfterSetAttr(int32_t aNameSpaceID, nsAtom* aName,
|
2017-03-29 22:10:00 +03:00
|
|
|
const nsAttrValue* aValue,
|
2017-10-10 00:33:38 +03:00
|
|
|
const nsAttrValue* aOldValue,
|
|
|
|
nsIPrincipal* aSubjectPrincipal,
|
|
|
|
bool aNotify) {
|
2017-03-29 22:10:00 +03:00
|
|
|
nsresult rv = nsGenericHTMLElement::AfterSetAttr(
|
2017-10-10 00:33:38 +03:00
|
|
|
aNameSpaceID, aName, aValue, aOldValue, aSubjectPrincipal, aNotify);
|
2017-03-29 22:10:00 +03: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 22:07:26 +03:00
|
|
|
nsresult rv = mAttrs.ForceMapped(this, OwnerDoc());
|
2017-03-29 22:10:00 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-08-24 23:49:25 +04:00
|
|
|
#define EVENT(name_, id_, type_, \
|
|
|
|
struct_) /* nothing; handled by the superclass */
|
2012-11-26 18:19:02 +04:00
|
|
|
// nsGenericHTMLElement::GetOnError returns
|
|
|
|
// already_AddRefed<EventHandlerNonNull> while other getters return
|
|
|
|
// EventHandlerNonNull*, so allow passing in the type to use here.
|
2012-12-21 18:07:28 +04:00
|
|
|
#define WINDOW_EVENT_HELPER(name_, type_) \
|
|
|
|
type_* HTMLBodyElement::GetOn##name_() { \
|
2016-01-30 20:05:36 +03:00
|
|
|
if (nsPIDOMWindowInner* win = OwnerDoc()->GetInnerWindow()) { \
|
2017-11-04 01:25:38 +03:00
|
|
|
nsGlobalWindowInner* globalWin = nsGlobalWindowInner::Cast(win); \
|
2012-12-21 18:07:28 +04:00
|
|
|
return globalWin->GetOn##name_(); \
|
2012-12-21 18:06:50 +04:00
|
|
|
} \
|
2012-12-21 18:07:28 +04:00
|
|
|
return nullptr; \
|
2012-12-21 18:06:50 +04:00
|
|
|
} \
|
2013-09-17 15:01:28 +04:00
|
|
|
void HTMLBodyElement::SetOn##name_(type_* handler) { \
|
2016-01-30 20:05:36 +03:00
|
|
|
nsPIDOMWindowInner* win = OwnerDoc()->GetInnerWindow(); \
|
2013-04-29 19:34:16 +04:00
|
|
|
if (!win) { \
|
2012-12-21 18:07:28 +04:00
|
|
|
return; \
|
2012-12-21 18:06:50 +04:00
|
|
|
} \
|
2012-12-21 18:07:28 +04:00
|
|
|
\
|
2017-11-04 01:25:38 +03:00
|
|
|
nsGlobalWindowInner* globalWin = nsGlobalWindowInner::Cast(win); \
|
2013-09-17 15:01:28 +04:00
|
|
|
return globalWin->SetOn##name_(handler); \
|
2013-11-16 16:31:37 +04:00
|
|
|
}
|
2012-12-21 18:07:28 +04:00
|
|
|
#define WINDOW_EVENT(name_, id_, type_, struct_) \
|
|
|
|
WINDOW_EVENT_HELPER(name_, EventHandlerNonNull)
|
|
|
|
#define BEFOREUNLOAD_EVENT(name_, id_, type_, struct_) \
|
2013-10-08 19:51:15 +04:00
|
|
|
WINDOW_EVENT_HELPER(name_, OnBeforeUnloadEventHandlerNonNull)
|
2014-04-01 15:42:12 +04:00
|
|
|
#include "mozilla/EventNameList.h" // IWYU pragma: keep
|
2012-12-21 18:07:28 +04:00
|
|
|
#undef BEFOREUNLOAD_EVENT
|
2011-08-24 23:49:25 +04:00
|
|
|
#undef WINDOW_EVENT
|
2012-12-21 18:07:28 +04:00
|
|
|
#undef WINDOW_EVENT_HELPER
|
2011-08-24 23:49:25 +04:00
|
|
|
#undef EVENT
|
2012-12-21 18:06:50 +04:00
|
|
|
|
2020-11-04 20:04:01 +03:00
|
|
|
} // namespace mozilla::dom
|