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-05-28 00:43:44 -07:00
|
|
|
|
2013-02-07 06:57:13 -08:00
|
|
|
#include "mozilla/dom/HTMLHRElement.h"
|
2013-02-07 06:57:59 -08:00
|
|
|
#include "mozilla/dom/HTMLHRElementBinding.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
NS_IMPL_NS_NEW_HTML_ELEMENT(HR)
|
|
|
|
|
2013-02-07 06:57:13 -08:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-06-19 19:01:40 -07:00
|
|
|
HTMLHRElement::HTMLHRElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo)
|
2007-03-22 10:30:00 -07:00
|
|
|
: nsGenericHTMLElement(aNodeInfo)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-02-07 06:57:13 -08:00
|
|
|
HTMLHRElement::~HTMLHRElement()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-04-27 00:06:00 -07:00
|
|
|
NS_IMPL_ISUPPORTS_INHERITED(HTMLHRElement, nsGenericHTMLElement,
|
|
|
|
nsIDOMHTMLHRElement)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-02-07 06:57:13 -08:00
|
|
|
NS_IMPL_ELEMENT_CLONE(HTMLHRElement)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
|
2013-02-07 06:57:13 -08:00
|
|
|
NS_IMPL_STRING_ATTR(HTMLHRElement, Align, align)
|
|
|
|
NS_IMPL_BOOL_ATTR(HTMLHRElement, NoShade, noshade)
|
|
|
|
NS_IMPL_STRING_ATTR(HTMLHRElement, Size, size)
|
|
|
|
NS_IMPL_STRING_ATTR(HTMLHRElement, Width, width)
|
|
|
|
NS_IMPL_STRING_ATTR(HTMLHRElement, Color, color)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2013-02-07 06:57:13 -08:00
|
|
|
HTMLHRElement::ParseAttribute(int32_t aNamespaceID,
|
|
|
|
nsIAtom* aAttribute,
|
|
|
|
const nsAString& aValue,
|
|
|
|
nsAttrValue& aResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-11-19 11:21:29 -08:00
|
|
|
static const nsAttrValue::EnumTable kAlignTable[] = {
|
|
|
|
{ "left", NS_STYLE_TEXT_ALIGN_LEFT },
|
|
|
|
{ "right", NS_STYLE_TEXT_ALIGN_RIGHT },
|
|
|
|
{ "center", NS_STYLE_TEXT_ALIGN_CENTER },
|
|
|
|
{ 0 }
|
|
|
|
};
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (aNamespaceID == kNameSpaceID_None) {
|
|
|
|
if (aAttribute == nsGkAtoms::width) {
|
2011-02-04 11:46:16 -08:00
|
|
|
return aResult.ParseSpecialIntValue(aValue);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
if (aAttribute == nsGkAtoms::size) {
|
|
|
|
return aResult.ParseIntWithBounds(aValue, 1, 1000);
|
|
|
|
}
|
|
|
|
if (aAttribute == nsGkAtoms::align) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return aResult.ParseEnumValue(aValue, kAlignTable, false);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
if (aAttribute == nsGkAtoms::color) {
|
2010-07-17 01:09:14 -07:00
|
|
|
return aResult.ParseColor(aValue);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsGenericHTMLElement::ParseAttribute(aNamespaceID, aAttribute, aValue,
|
|
|
|
aResult);
|
|
|
|
}
|
|
|
|
|
2013-11-19 11:21:29 -08:00
|
|
|
void
|
|
|
|
HTMLHRElement::MapAttributesIntoRule(const nsMappedAttributes* aAttributes,
|
|
|
|
nsRuleData* aData)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-09-28 23:19:26 -07:00
|
|
|
bool noshade = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
const nsAttrValue* colorValue = aAttributes->GetAttr(nsGkAtoms::color);
|
|
|
|
nscolor color;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool colorIsSet = colorValue && colorValue->GetColorValue(color);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-10-08 14:58:22 -07:00
|
|
|
if (aData->mSIDs & (NS_STYLE_INHERIT_BIT(Position) |
|
|
|
|
NS_STYLE_INHERIT_BIT(Border))) {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (colorIsSet) {
|
2011-10-17 07:59:28 -07:00
|
|
|
noshade = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
} else {
|
|
|
|
noshade = !!aAttributes->GetAttr(nsGkAtoms::noshade);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-08 14:58:22 -07:00
|
|
|
if (aData->mSIDs & NS_STYLE_INHERIT_BIT(Margin)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// align: enum
|
|
|
|
const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::align);
|
|
|
|
if (value && value->Type() == nsAttrValue::eEnum) {
|
|
|
|
// Map align attribute into auto side margins
|
2011-03-17 20:14:31 -07:00
|
|
|
nsCSSValue* marginLeft = aData->ValueForMarginLeftValue();
|
|
|
|
nsCSSValue* marginRight = aData->ValueForMarginRightValue();
|
2007-03-22 10:30:00 -07:00
|
|
|
switch (value->GetEnumValue()) {
|
|
|
|
case NS_STYLE_TEXT_ALIGN_LEFT:
|
2011-03-17 20:14:31 -07:00
|
|
|
if (marginLeft->GetUnit() == eCSSUnit_Null)
|
|
|
|
marginLeft->SetFloatValue(0.0f, eCSSUnit_Pixel);
|
|
|
|
if (marginRight->GetUnit() == eCSSUnit_Null)
|
|
|
|
marginRight->SetAutoValue();
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
case NS_STYLE_TEXT_ALIGN_RIGHT:
|
2011-03-17 20:14:31 -07:00
|
|
|
if (marginLeft->GetUnit() == eCSSUnit_Null)
|
|
|
|
marginLeft->SetAutoValue();
|
|
|
|
if (marginRight->GetUnit() == eCSSUnit_Null)
|
|
|
|
marginRight->SetFloatValue(0.0f, eCSSUnit_Pixel);
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
case NS_STYLE_TEXT_ALIGN_CENTER:
|
2011-03-17 20:14:31 -07:00
|
|
|
if (marginLeft->GetUnit() == eCSSUnit_Null)
|
|
|
|
marginLeft->SetAutoValue();
|
|
|
|
if (marginRight->GetUnit() == eCSSUnit_Null)
|
|
|
|
marginRight->SetAutoValue();
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-10-08 14:58:22 -07:00
|
|
|
if (aData->mSIDs & NS_STYLE_INHERIT_BIT(Position)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// width: integer, percent
|
2011-03-17 20:14:31 -07:00
|
|
|
nsCSSValue* width = aData->ValueForWidth();
|
|
|
|
if (width->GetUnit() == eCSSUnit_Null) {
|
2007-03-22 10:30:00 -07:00
|
|
|
const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::width);
|
|
|
|
if (value && value->Type() == nsAttrValue::eInteger) {
|
2011-03-17 20:14:31 -07:00
|
|
|
width->SetFloatValue((float)value->GetIntegerValue(), eCSSUnit_Pixel);
|
2007-03-22 10:30:00 -07:00
|
|
|
} else if (value && value->Type() == nsAttrValue::ePercent) {
|
2011-03-17 20:14:31 -07:00
|
|
|
width->SetPercentValue(value->GetPercentValue());
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-17 20:14:31 -07:00
|
|
|
nsCSSValue* height = aData->ValueForHeight();
|
|
|
|
if (height->GetUnit() == eCSSUnit_Null) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// size: integer
|
|
|
|
if (noshade) {
|
|
|
|
// noshade case: size is set using the border
|
2011-03-17 20:14:31 -07:00
|
|
|
height->SetAutoValue();
|
2007-03-22 10:30:00 -07: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) {
|
2011-03-17 20:14:31 -07:00
|
|
|
height->SetFloatValue((float)value->GetIntegerValue(), eCSSUnit_Pixel);
|
2007-03-22 10:30:00 -07:00
|
|
|
} // else use default value from html.css
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-10-08 14:58:22 -07:00
|
|
|
if ((aData->mSIDs & NS_STYLE_INHERIT_BIT(Border)) && noshade) { // if not noshade, border styles are dealt with by html.css
|
2007-03-22 10:30:00 -07:00
|
|
|
// size: integer
|
|
|
|
// if a size is set, use half of it per side, otherwise, use 1px per side
|
|
|
|
float sizePerSide;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool allSides = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::size);
|
|
|
|
if (value && value->Type() == nsAttrValue::eInteger) {
|
|
|
|
sizePerSide = (float)value->GetIntegerValue() / 2.0f;
|
|
|
|
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 07:59:28 -07:00
|
|
|
allSides = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
sizePerSide = 1.0f; // default to a 2px high line
|
|
|
|
}
|
2011-03-17 20:14:31 -07:00
|
|
|
nsCSSValue* borderTopWidth = aData->ValueForBorderTopWidth();
|
|
|
|
if (borderTopWidth->GetUnit() == eCSSUnit_Null) {
|
|
|
|
borderTopWidth->SetFloatValue(sizePerSide, eCSSUnit_Pixel);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
if (allSides) {
|
2011-03-17 20:14:31 -07:00
|
|
|
nsCSSValue* borderRightWidth = aData->ValueForBorderRightWidthValue();
|
|
|
|
if (borderRightWidth->GetUnit() == eCSSUnit_Null) {
|
|
|
|
borderRightWidth->SetFloatValue(sizePerSide, eCSSUnit_Pixel);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2011-03-17 20:14:31 -07:00
|
|
|
nsCSSValue* borderBottomWidth = aData->ValueForBorderBottomWidth();
|
|
|
|
if (borderBottomWidth->GetUnit() == eCSSUnit_Null) {
|
|
|
|
borderBottomWidth->SetFloatValue(sizePerSide, eCSSUnit_Pixel);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2011-03-17 20:14:31 -07:00
|
|
|
nsCSSValue* borderLeftWidth = aData->ValueForBorderLeftWidthValue();
|
|
|
|
if (borderLeftWidth->GetUnit() == eCSSUnit_Null) {
|
|
|
|
borderLeftWidth->SetFloatValue(sizePerSide, eCSSUnit_Pixel);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-17 20:14:31 -07:00
|
|
|
nsCSSValue* borderTopStyle = aData->ValueForBorderTopStyle();
|
|
|
|
if (borderTopStyle->GetUnit() == eCSSUnit_Null) {
|
|
|
|
borderTopStyle->SetIntValue(NS_STYLE_BORDER_STYLE_SOLID,
|
|
|
|
eCSSUnit_Enumerated);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
if (allSides) {
|
2011-03-17 20:14:31 -07:00
|
|
|
nsCSSValue* borderRightStyle = aData->ValueForBorderRightStyleValue();
|
|
|
|
if (borderRightStyle->GetUnit() == eCSSUnit_Null) {
|
|
|
|
borderRightStyle->SetIntValue(NS_STYLE_BORDER_STYLE_SOLID,
|
|
|
|
eCSSUnit_Enumerated);
|
|
|
|
}
|
|
|
|
nsCSSValue* borderBottomStyle = aData->ValueForBorderBottomStyle();
|
|
|
|
if (borderBottomStyle->GetUnit() == eCSSUnit_Null) {
|
|
|
|
borderBottomStyle->SetIntValue(NS_STYLE_BORDER_STYLE_SOLID,
|
2007-03-22 10:30:00 -07:00
|
|
|
eCSSUnit_Enumerated);
|
|
|
|
}
|
2011-03-17 20:14:31 -07:00
|
|
|
nsCSSValue* borderLeftStyle = aData->ValueForBorderLeftStyleValue();
|
|
|
|
if (borderLeftStyle->GetUnit() == eCSSUnit_Null) {
|
|
|
|
borderLeftStyle->SetIntValue(NS_STYLE_BORDER_STYLE_SOLID,
|
|
|
|
eCSSUnit_Enumerated);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// If it would be noticeable, set the border radius to
|
2010-10-06 21:25:44 -07: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.
|
2011-03-17 20:14:31 -07:00
|
|
|
for (const nsCSSProperty* props =
|
|
|
|
nsCSSProps::SubpropertyEntryFor(eCSSProperty_border_radius);
|
|
|
|
*props != eCSSProperty_UNKNOWN; ++props) {
|
|
|
|
nsCSSValue* dimen = aData->ValueFor(*props);
|
|
|
|
if (dimen->GetUnit() == eCSSUnit_Null) {
|
|
|
|
dimen->SetFloatValue(10000.0f, eCSSUnit_Pixel);
|
2008-09-30 22:50:52 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-10-08 14:58:22 -07:00
|
|
|
if (aData->mSIDs & NS_STYLE_INHERIT_BIT(Color)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// color: a color
|
|
|
|
// (we got the color attribute earlier)
|
2011-03-17 20:14:31 -07:00
|
|
|
nsCSSValue* colorValue = aData->ValueForColor();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (colorIsSet &&
|
2011-03-17 20:14:31 -07:00
|
|
|
colorValue->GetUnit() == eCSSUnit_Null &&
|
2007-11-15 19:46:42 -08:00
|
|
|
aData->mPresContext->UseDocumentColors()) {
|
2011-03-17 20:14:31 -07:00
|
|
|
colorValue->SetColorValue(color);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsGenericHTMLElement::MapCommonAttributesInto(aAttributes, aData);
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
NS_IMETHODIMP_(bool)
|
2013-02-07 06:57:13 -08:00
|
|
|
HTMLHRElement::IsAttributeMapped(const nsIAtom* aAttribute) const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
static const MappedAttributeEntry attributes[] = {
|
|
|
|
{ &nsGkAtoms::align },
|
|
|
|
{ &nsGkAtoms::width },
|
|
|
|
{ &nsGkAtoms::size },
|
|
|
|
{ &nsGkAtoms::color },
|
|
|
|
{ &nsGkAtoms::noshade },
|
2012-07-30 07:20:58 -07:00
|
|
|
{ nullptr },
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
static const MappedAttributeEntry* const map[] = {
|
|
|
|
attributes,
|
|
|
|
sCommonAttributeMap,
|
|
|
|
};
|
|
|
|
|
2011-12-18 02:09:27 -08:00
|
|
|
return FindAttributeDependence(aAttribute, map);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsMapRuleToAttributesFunc
|
2013-02-07 06:57:13 -08:00
|
|
|
HTMLHRElement::GetAttributeMappingFunction() const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return &MapAttributesIntoRule;
|
|
|
|
}
|
2013-02-07 06:57:13 -08:00
|
|
|
|
2013-02-07 06:57:59 -08:00
|
|
|
JSObject*
|
2014-04-08 15:27:17 -07:00
|
|
|
HTMLHRElement::WrapNode(JSContext* aCx)
|
2013-02-07 06:57:59 -08:00
|
|
|
{
|
Bug 991742 part 6. Remove the "aScope" argument of binding Wrap() methods. r=bholley
This patch was mostly generated with this command:
find . -name "*.h" -o -name "*.cpp" | xargs sed -e 's/Binding::Wrap(aCx, aScope, this/Binding::Wrap(aCx, this/' -e 's/Binding_workers::Wrap(aCx, aScope, this/Binding_workers::Wrap(aCx, this/' -e 's/Binding::Wrap(cx, scope, this/Binding::Wrap(cx, this/' -i ""
plus a few manual fixes to dom/bindings/Codegen.py, js/xpconnect/src/event_impl_gen.py, and a few C++ files that were not caught in the search-and-replace above.
2014-04-08 15:27:17 -07:00
|
|
|
return HTMLHRElementBinding::Wrap(aCx, this);
|
2013-02-07 06:57:59 -08:00
|
|
|
}
|
|
|
|
|
2013-02-07 06:57:13 -08:00
|
|
|
} // namespace mozilla
|
|
|
|
} // namespace dom
|