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-05-28 11:43:44 +04:00
|
|
|
|
2013-02-07 18:57:13 +04:00
|
|
|
#include "mozilla/dom/HTMLHRElement.h"
|
2013-02-07 18:57:59 +04:00
|
|
|
#include "mozilla/dom/HTMLHRElementBinding.h"
|
2000-12-23 13:56:31 +03:00
|
|
|
|
2020-02-24 16:32:57 +03:00
|
|
|
#include "nsStyleConsts.h"
|
|
|
|
#include "mozilla/MappedDeclarations.h"
|
2018-04-26 08:00:50 +03:00
|
|
|
|
2004-05-19 00:58:12 +04:00
|
|
|
NS_IMPL_NS_NEW_HTML_ELEMENT(HR)
|
2000-12-23 13:56:31 +03:00
|
|
|
|
2013-02-07 18:57:13 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2000-12-23 13:56:31 +03:00
|
|
|
|
2018-09-21 23:45:49 +03:00
|
|
|
HTMLHRElement::HTMLHRElement(
|
|
|
|
already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo)
|
|
|
|
: nsGenericHTMLElement(std::move(aNodeInfo)) {}
|
1998-08-29 03:27:19 +04:00
|
|
|
|
2020-02-20 19:19:15 +03:00
|
|
|
HTMLHRElement::~HTMLHRElement() = default;
|
1998-08-29 03:27:19 +04:00
|
|
|
|
2013-02-07 18:57:13 +04:00
|
|
|
NS_IMPL_ELEMENT_CLONE(HTMLHRElement)
|
1998-09-11 08:16:18 +04:00
|
|
|
|
2013-02-07 18:57:13 +04:00
|
|
|
bool HTMLHRElement::ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute,
|
|
|
|
const nsAString& aValue,
|
2017-11-02 06:35:52 +03:00
|
|
|
nsIPrincipal* aMaybeScriptedPrincipal,
|
2013-02-07 18:57:13 +04:00
|
|
|
nsAttrValue& aResult) {
|
2013-11-19 23:21:29 +04:00
|
|
|
static const nsAttrValue::EnumTable kAlignTable[] = {
|
2020-02-24 16:32:57 +03:00
|
|
|
{"left", StyleTextAlign::Left},
|
|
|
|
{"right", StyleTextAlign::Right},
|
|
|
|
{"center", StyleTextAlign::Center},
|
2016-09-07 05:20:17 +03:00
|
|
|
{nullptr, 0}};
|
2013-11-19 23:21:29 +04:00
|
|
|
|
2005-12-04 19:31:26 +03:00
|
|
|
if (aNamespaceID == kNameSpaceID_None) {
|
2006-12-26 20:47:52 +03:00
|
|
|
if (aAttribute == nsGkAtoms::width) {
|
2019-06-28 23:56:55 +03:00
|
|
|
return aResult.ParseHTMLDimension(aValue);
|
2005-11-29 19:37:15 +03:00
|
|
|
}
|
2006-12-26 20:47:52 +03:00
|
|
|
if (aAttribute == nsGkAtoms::size) {
|
2005-11-29 19:37:15 +03:00
|
|
|
return aResult.ParseIntWithBounds(aValue, 1, 1000);
|
|
|
|
}
|
2006-12-26 20:47:52 +03:00
|
|
|
if (aAttribute == nsGkAtoms::align) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return aResult.ParseEnumValue(aValue, kAlignTable, false);
|
2005-11-29 19:37:15 +03:00
|
|
|
}
|
2006-12-26 20:47:52 +03:00
|
|
|
if (aAttribute == nsGkAtoms::color) {
|
2010-07-17 12:09:14 +04:00
|
|
|
return aResult.ParseColor(aValue);
|
2005-11-29 19:37:15 +03:00
|
|
|
}
|
2003-07-30 12:13:07 +04:00
|
|
|
}
|
2000-12-23 13:56:31 +03:00
|
|
|
|
2005-11-29 19:37:15 +03:00
|
|
|
return nsGenericHTMLElement::ParseAttribute(aNamespaceID, aAttribute, aValue,
|
2017-11-02 06:35:52 +03:00
|
|
|
aMaybeScriptedPrincipal, aResult);
|
1998-08-29 03:27:19 +04:00
|
|
|
}
|
|
|
|
|
2013-11-19 23:21:29 +04:00
|
|
|
void HTMLHRElement::MapAttributesIntoRule(const nsMappedAttributes* aAttributes,
|
2018-06-22 19:48:42 +03:00
|
|
|
MappedDeclarations& aDecls) {
|
2011-09-29 10:19:26 +04:00
|
|
|
bool noshade = false;
|
2003-07-30 12:13:07 +04:00
|
|
|
|
2006-12-26 20:47:52 +03:00
|
|
|
const nsAttrValue* colorValue = aAttributes->GetAttr(nsGkAtoms::color);
|
2004-02-11 03:09:59 +03:00
|
|
|
nscolor color;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool colorIsSet = colorValue && colorValue->GetColorValue(color);
|
2003-07-30 12:13:07 +04:00
|
|
|
|
2018-03-29 04:39:07 +03:00
|
|
|
if (colorIsSet) {
|
|
|
|
noshade = true;
|
|
|
|
} else {
|
|
|
|
noshade = !!aAttributes->GetAttr(nsGkAtoms::noshade);
|
2003-07-30 12:13:07 +04:00
|
|
|
}
|
|
|
|
|
2018-03-29 04:39:07 +03:00
|
|
|
// align: enum
|
|
|
|
const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::align);
|
|
|
|
if (value && value->Type() == nsAttrValue::eEnum) {
|
|
|
|
// Map align attribute into auto side margins
|
2020-02-24 16:32:57 +03:00
|
|
|
switch (StyleTextAlign(value->GetEnumValue())) {
|
|
|
|
case StyleTextAlign::Left:
|
2018-06-22 19:48:42 +03:00
|
|
|
aDecls.SetPixelValueIfUnset(eCSSProperty_margin_left, 0.0f);
|
|
|
|
aDecls.SetAutoValueIfUnset(eCSSProperty_margin_right);
|
2018-03-29 04:39:07 +03:00
|
|
|
break;
|
2020-02-24 16:32:57 +03:00
|
|
|
case StyleTextAlign::Right:
|
2018-06-22 19:48:42 +03:00
|
|
|
aDecls.SetAutoValueIfUnset(eCSSProperty_margin_left);
|
|
|
|
aDecls.SetPixelValueIfUnset(eCSSProperty_margin_right, 0.0f);
|
2018-03-29 04:39:07 +03:00
|
|
|
break;
|
2020-02-24 16:32:57 +03:00
|
|
|
case StyleTextAlign::Center:
|
2018-06-22 19:48:42 +03:00
|
|
|
aDecls.SetAutoValueIfUnset(eCSSProperty_margin_left);
|
|
|
|
aDecls.SetAutoValueIfUnset(eCSSProperty_margin_right);
|
2018-03-29 04:39:07 +03:00
|
|
|
break;
|
2020-02-24 16:32:57 +03:00
|
|
|
default:
|
|
|
|
MOZ_ASSERT_UNREACHABLE("Unknown <hr align> value");
|
|
|
|
break;
|
1998-08-29 03:27:19 +04:00
|
|
|
}
|
2001-06-01 02:19:43 +04:00
|
|
|
}
|
2018-06-22 19:48:42 +03:00
|
|
|
if (!aDecls.PropertyIsSet(eCSSProperty_height)) {
|
2018-03-29 04:39:07 +03:00
|
|
|
// size: integer
|
|
|
|
if (noshade) {
|
|
|
|
// noshade case: size is set using the border
|
2018-06-22 19:48:42 +03:00
|
|
|
aDecls.SetAutoValue(eCSSProperty_height);
|
2018-03-29 04:39:07 +03:00
|
|
|
} else {
|
|
|
|
// normal case
|
|
|
|
// the height includes the top and bottom borders that are initially 1px.
|
|
|
|
// for size=1, html.css has a special case rule that makes this work by
|
|
|
|
// removing all but the top border.
|
|
|
|
const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::size);
|
|
|
|
if (value && value->Type() == nsAttrValue::eInteger) {
|
2018-06-22 19:48:42 +03:00
|
|
|
aDecls.SetPixelValue(eCSSProperty_height,
|
|
|
|
(float)value->GetIntegerValue());
|
2018-03-29 04:39:07 +03:00
|
|
|
} // else use default value from html.css
|
1999-03-05 07:20:07 +03:00
|
|
|
}
|
1998-08-29 03:27:19 +04:00
|
|
|
}
|
2017-01-27 03:51:01 +03:00
|
|
|
|
|
|
|
// if not noshade, border styles are dealt with by html.css
|
2018-03-29 04:39:07 +03:00
|
|
|
if (noshade) {
|
2004-02-11 03:09:59 +03:00
|
|
|
// size: integer
|
2003-07-30 12:13:07 +04:00
|
|
|
// if a size is set, use half of it per side, otherwise, use 1px per side
|
|
|
|
float sizePerSide;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool allSides = true;
|
2018-03-29 04:39:07 +03:00
|
|
|
value = aAttributes->GetAttr(nsGkAtoms::size);
|
2004-04-13 20:45:59 +04:00
|
|
|
if (value && value->Type() == nsAttrValue::eInteger) {
|
|
|
|
sizePerSide = (float)value->GetIntegerValue() / 2.0f;
|
2003-07-30 12:13:07 +04:00
|
|
|
if (sizePerSide < 1.0f) {
|
|
|
|
// XXX When the pixel bug is fixed, all the special casing for
|
|
|
|
// subpixel borders should be removed.
|
|
|
|
// In the meantime, this makes http://www.microsoft.com/ look right.
|
|
|
|
sizePerSide = 1.0f;
|
2011-10-17 18:59:28 +04:00
|
|
|
allSides = false;
|
2003-07-30 12:13:07 +04:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
sizePerSide = 1.0f; // default to a 2px high line
|
|
|
|
}
|
2018-06-22 19:48:42 +03:00
|
|
|
aDecls.SetPixelValueIfUnset(eCSSProperty_border_top_width, sizePerSide);
|
2003-07-30 12:13:07 +04:00
|
|
|
if (allSides) {
|
2018-06-22 19:48:42 +03:00
|
|
|
aDecls.SetPixelValueIfUnset(eCSSProperty_border_right_width, sizePerSide);
|
|
|
|
aDecls.SetPixelValueIfUnset(eCSSProperty_border_bottom_width,
|
|
|
|
sizePerSide);
|
|
|
|
aDecls.SetPixelValueIfUnset(eCSSProperty_border_left_width, sizePerSide);
|
2003-07-30 12:13:07 +04:00
|
|
|
}
|
2001-06-01 02:19:43 +04:00
|
|
|
|
2018-06-22 19:48:42 +03:00
|
|
|
if (!aDecls.PropertyIsSet(eCSSProperty_border_top_style))
|
|
|
|
aDecls.SetKeywordValue(eCSSProperty_border_top_style,
|
2018-11-07 22:56:17 +03:00
|
|
|
StyleBorderStyle::Solid);
|
2003-07-30 12:13:07 +04:00
|
|
|
if (allSides) {
|
2018-06-22 19:48:42 +03:00
|
|
|
aDecls.SetKeywordValueIfUnset(eCSSProperty_border_right_style,
|
2018-11-07 22:56:17 +03:00
|
|
|
StyleBorderStyle::Solid);
|
2018-06-22 19:48:42 +03:00
|
|
|
aDecls.SetKeywordValueIfUnset(eCSSProperty_border_bottom_style,
|
2018-11-07 22:56:17 +03:00
|
|
|
StyleBorderStyle::Solid);
|
2018-06-22 19:48:42 +03:00
|
|
|
aDecls.SetKeywordValueIfUnset(eCSSProperty_border_left_style,
|
2018-11-07 22:56:17 +03:00
|
|
|
StyleBorderStyle::Solid);
|
2003-07-30 12:13:07 +04:00
|
|
|
|
|
|
|
// If it would be noticeable, set the border radius to
|
2010-10-07 08:25:44 +04:00
|
|
|
// 10000px on all corners; this triggers the clamping to make
|
|
|
|
// circular ends. This assumes the <hr> isn't larger than
|
|
|
|
// that in *both* dimensions.
|
2016-08-17 04:37:48 +03:00
|
|
|
for (const nsCSSPropertyID* props =
|
2011-03-18 06:14:31 +03:00
|
|
|
nsCSSProps::SubpropertyEntryFor(eCSSProperty_border_radius);
|
|
|
|
*props != eCSSProperty_UNKNOWN; ++props) {
|
2018-06-22 19:48:42 +03:00
|
|
|
aDecls.SetPixelValueIfUnset(*props, 10000.0f);
|
2003-07-30 12:13:07 +04:00
|
|
|
}
|
|
|
|
}
|
2003-07-12 01:16:12 +04:00
|
|
|
}
|
2018-03-29 04:39:07 +03:00
|
|
|
// color: a color
|
|
|
|
// (we got the color attribute earlier)
|
|
|
|
if (colorIsSet) {
|
2018-06-22 19:48:42 +03:00
|
|
|
aDecls.SetColorValueIfUnset(eCSSProperty_color, color);
|
2003-07-30 12:13:07 +04:00
|
|
|
}
|
|
|
|
|
2018-06-22 19:48:42 +03:00
|
|
|
nsGenericHTMLElement::MapWidthAttributeInto(aAttributes, aDecls);
|
|
|
|
nsGenericHTMLElement::MapCommonAttributesInto(aAttributes, aDecls);
|
2003-07-12 01:16:12 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
NS_IMETHODIMP_(bool)
|
2017-10-03 01:05:19 +03:00
|
|
|
HTMLHRElement::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::align}, {nsGkAtoms::width}, {nsGkAtoms::size},
|
|
|
|
{nsGkAtoms::color}, {nsGkAtoms::noshade}, {nullptr},
|
2003-04-17 00:54:20 +04:00
|
|
|
};
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2004-02-26 00:04:50 +03:00
|
|
|
static const MappedAttributeEntry* const map[] = {
|
2003-04-17 00:54:20 +04:00
|
|
|
attributes,
|
|
|
|
sCommonAttributeMap,
|
|
|
|
};
|
|
|
|
|
2011-12-18 14:09:27 +04:00
|
|
|
return FindAttributeDependence(aAttribute, map);
|
1999-07-07 05:24:40 +04:00
|
|
|
}
|
|
|
|
|
2013-02-07 18:57:13 +04:00
|
|
|
nsMapRuleToAttributesFunc HTMLHRElement::GetAttributeMappingFunction() const {
|
2005-01-12 22:45:38 +03:00
|
|
|
return &MapAttributesIntoRule;
|
1998-08-29 03:27:19 +04:00
|
|
|
}
|
2013-02-07 18:57:13 +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* HTMLHRElement::WrapNode(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) {
|
2018-06-26 00:20:54 +03:00
|
|
|
return HTMLHRElement_Binding::Wrap(aCx, this, aGivenProto);
|
2013-02-07 18:57:59 +04:00
|
|
|
}
|
|
|
|
|
2013-02-07 18:57:13 +04:00
|
|
|
} // namespace dom
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace mozilla
|