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
|
|
|
|
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
|
|
|
|
2014-06-20 06:01:40 +04:00
|
|
|
HTMLHRElement::HTMLHRElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo)
|
2004-05-19 00:58:12 +04:00
|
|
|
: nsGenericHTMLElement(aNodeInfo)
|
1998-08-29 03:27:19 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-02-07 18:57:13 +04:00
|
|
|
HTMLHRElement::~HTMLHRElement()
|
1998-08-29 03:27:19 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-08-14 19:31:47 +03:00
|
|
|
NS_IMPL_ISUPPORTS_INHERITED0(HTMLHRElement, nsGenericHTMLElement)
|
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
|
|
|
|
2000-12-23 13:56:31 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2013-02-07 18:57:13 +04:00
|
|
|
HTMLHRElement::ParseAttribute(int32_t aNamespaceID,
|
2017-10-03 01:05:19 +03:00
|
|
|
nsAtom* aAttribute,
|
2013-02-07 18:57:13 +04:00
|
|
|
const nsAString& aValue,
|
|
|
|
nsAttrValue& aResult)
|
1998-08-29 03:27:19 +04:00
|
|
|
{
|
2013-11-19 23:21:29 +04:00
|
|
|
static const nsAttrValue::EnumTable kAlignTable[] = {
|
|
|
|
{ "left", NS_STYLE_TEXT_ALIGN_LEFT },
|
|
|
|
{ "right", NS_STYLE_TEXT_ALIGN_RIGHT },
|
|
|
|
{ "center", NS_STYLE_TEXT_ALIGN_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) {
|
2011-02-04 22:46:16 +03:00
|
|
|
return aResult.ParseSpecialIntValue(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,
|
|
|
|
aResult);
|
1998-08-29 03:27:19 +04:00
|
|
|
}
|
|
|
|
|
2013-11-19 23:21:29 +04:00
|
|
|
void
|
|
|
|
HTMLHRElement::MapAttributesIntoRule(const nsMappedAttributes* aAttributes,
|
2017-01-27 03:51:01 +03:00
|
|
|
GenericSpecifiedValues* aData)
|
1998-08-29 03:27:19 +04:00
|
|
|
{
|
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
|
|
|
|
2017-01-27 03:51:01 +03:00
|
|
|
if (aData->ShouldComputeStyleStruct(NS_STYLE_INHERIT_BIT(Position) |
|
|
|
|
NS_STYLE_INHERIT_BIT(Border))) {
|
2003-07-30 12:13:07 +04:00
|
|
|
if (colorIsSet) {
|
2011-10-17 18:59:28 +04:00
|
|
|
noshade = true;
|
2003-07-30 12:13:07 +04:00
|
|
|
} else {
|
2006-12-26 20:47:52 +03:00
|
|
|
noshade = !!aAttributes->GetAttr(nsGkAtoms::noshade);
|
2003-07-30 12:13:07 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-27 03:51:01 +03:00
|
|
|
if (aData->ShouldComputeStyleStruct(NS_STYLE_INHERIT_BIT(Margin))) {
|
1998-08-29 03:27:19 +04:00
|
|
|
// align: enum
|
2006-12-26 20:47:52 +03:00
|
|
|
const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::align);
|
2004-04-13 20:45:59 +04:00
|
|
|
if (value && value->Type() == nsAttrValue::eEnum) {
|
1999-03-05 07:20:07 +03:00
|
|
|
// Map align attribute into auto side margins
|
2004-04-13 20:45:59 +04:00
|
|
|
switch (value->GetEnumValue()) {
|
1999-03-05 07:20:07 +03:00
|
|
|
case NS_STYLE_TEXT_ALIGN_LEFT:
|
2017-01-27 03:51:01 +03:00
|
|
|
aData->SetPixelValueIfUnset(eCSSProperty_margin_left, 0.0f);
|
|
|
|
aData->SetAutoValueIfUnset(eCSSProperty_margin_right);
|
1999-03-05 07:20:07 +03:00
|
|
|
break;
|
|
|
|
case NS_STYLE_TEXT_ALIGN_RIGHT:
|
2017-01-27 03:51:01 +03:00
|
|
|
aData->SetAutoValueIfUnset(eCSSProperty_margin_left);
|
|
|
|
aData->SetPixelValueIfUnset(eCSSProperty_margin_right, 0.0f);
|
1999-03-05 07:20:07 +03:00
|
|
|
break;
|
|
|
|
case NS_STYLE_TEXT_ALIGN_CENTER:
|
2017-01-27 03:51:01 +03:00
|
|
|
aData->SetAutoValueIfUnset(eCSSProperty_margin_left);
|
|
|
|
aData->SetAutoValueIfUnset(eCSSProperty_margin_right);
|
1999-03-05 07:20:07 +03:00
|
|
|
break;
|
|
|
|
}
|
1998-08-29 03:27:19 +04:00
|
|
|
}
|
2001-06-01 02:19:43 +04:00
|
|
|
}
|
2017-01-27 03:51:01 +03:00
|
|
|
if (aData->ShouldComputeStyleStruct(NS_STYLE_INHERIT_BIT(Position))) {
|
|
|
|
if (!aData->PropertyIsSet(eCSSProperty_height)) {
|
2004-02-11 03:09:59 +03:00
|
|
|
// size: integer
|
2003-07-30 12:13:07 +04:00
|
|
|
if (noshade) {
|
|
|
|
// noshade case: size is set using the border
|
2017-01-27 03:51:01 +03:00
|
|
|
aData->SetAutoValue(eCSSProperty_height);
|
2003-07-30 12:13:07 +04: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.
|
2006-12-26 20:47:52 +03:00
|
|
|
const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::size);
|
2004-04-13 20:45:59 +04:00
|
|
|
if (value && value->Type() == nsAttrValue::eInteger) {
|
2017-01-27 03:51:01 +03:00
|
|
|
aData->SetPixelValue(eCSSProperty_height, (float)value->GetIntegerValue());
|
2003-07-30 12:13:07 +04: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
|
|
|
|
if (aData->ShouldComputeStyleStruct(NS_STYLE_INHERIT_BIT(Border)) && 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;
|
2006-12-26 20:47:52 +03:00
|
|
|
const nsAttrValue* 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
|
|
|
|
}
|
2017-01-27 03:51:01 +03:00
|
|
|
aData->SetPixelValueIfUnset(eCSSProperty_border_top_width, sizePerSide);
|
2003-07-30 12:13:07 +04:00
|
|
|
if (allSides) {
|
2017-01-27 03:51:01 +03:00
|
|
|
aData->SetPixelValueIfUnset(eCSSProperty_border_right_width, sizePerSide);
|
|
|
|
aData->SetPixelValueIfUnset(eCSSProperty_border_bottom_width, sizePerSide);
|
|
|
|
aData->SetPixelValueIfUnset(eCSSProperty_border_left_width, sizePerSide);
|
2003-07-30 12:13:07 +04:00
|
|
|
}
|
2001-06-01 02:19:43 +04:00
|
|
|
|
2017-01-27 03:51:01 +03:00
|
|
|
if (!aData->PropertyIsSet(eCSSProperty_border_top_style))
|
|
|
|
aData->SetKeywordValue(eCSSProperty_border_top_style,
|
|
|
|
NS_STYLE_BORDER_STYLE_SOLID);
|
2003-07-30 12:13:07 +04:00
|
|
|
if (allSides) {
|
2017-01-27 03:51:01 +03:00
|
|
|
aData->SetKeywordValueIfUnset(eCSSProperty_border_right_style,
|
|
|
|
NS_STYLE_BORDER_STYLE_SOLID);
|
|
|
|
aData->SetKeywordValueIfUnset(eCSSProperty_border_bottom_style,
|
|
|
|
NS_STYLE_BORDER_STYLE_SOLID);
|
|
|
|
aData->SetKeywordValueIfUnset(eCSSProperty_border_left_style,
|
|
|
|
NS_STYLE_BORDER_STYLE_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) {
|
2017-01-27 03:51:01 +03:00
|
|
|
aData->SetPixelValueIfUnset(*props, 10000.0f);
|
2003-07-30 12:13:07 +04:00
|
|
|
}
|
|
|
|
}
|
2003-07-12 01:16:12 +04:00
|
|
|
}
|
2017-01-27 03:51:01 +03:00
|
|
|
if (aData->ShouldComputeStyleStruct(NS_STYLE_INHERIT_BIT(Color))) {
|
2003-07-30 12:13:07 +04:00
|
|
|
// color: a color
|
|
|
|
// (we got the color attribute earlier)
|
|
|
|
if (colorIsSet &&
|
2017-01-27 03:51:01 +03:00
|
|
|
aData->PresContext()->UseDocumentColors()) {
|
|
|
|
aData->SetColorValueIfUnset(eCSSProperty_color, color);
|
2003-07-30 12:13:07 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-27 03:51:01 +03:00
|
|
|
nsGenericHTMLElement::MapWidthAttributeInto(aAttributes, aData);
|
|
|
|
nsGenericHTMLElement::MapCommonAttributesInto(aAttributes, aData);
|
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
|
2003-07-12 01:16:12 +04:00
|
|
|
{
|
2004-02-26 00:04:50 +03:00
|
|
|
static const MappedAttributeEntry attributes[] = {
|
2006-12-26 20:47:52 +03:00
|
|
|
{ &nsGkAtoms::align },
|
|
|
|
{ &nsGkAtoms::width },
|
|
|
|
{ &nsGkAtoms::size },
|
|
|
|
{ &nsGkAtoms::color },
|
|
|
|
{ &nsGkAtoms::noshade },
|
2012-07-30 18:20:58 +04:00
|
|
|
{ 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
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-01-12 22:45:38 +03:00
|
|
|
nsMapRuleToAttributesFunc
|
2013-02-07 18:57:13 +04:00
|
|
|
HTMLHRElement::GetAttributeMappingFunction() const
|
1998-09-05 08:00:06 +04:00
|
|
|
{
|
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
|
|
|
|
2013-02-07 18:57:59 +04:00
|
|
|
JSObject*
|
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
|
|
|
HTMLHRElement::WrapNode(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
2013-02-07 18:57:59 +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
|
|
|
return HTMLHRElementBinding::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
|