blob: 6dc285802ff617e7e8909734b05ca452bdd59fec [file] [log] [blame]
/*
* Copyright (C) 1999 Lars Knoll (knoll@kde.org)
* (C) 1999 Antti Koivisto (koivisto@kde.org)
* Copyright (C) 2003, 2010 Apple Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
*/
#include "third_party/blink/renderer/core/html/html_hr_element.h"
#include "third_party/blink/renderer/core/css/css_color_value.h"
#include "third_party/blink/renderer/core/css/css_property_names.h"
#include "third_party/blink/renderer/core/css/css_property_value_set.h"
#include "third_party/blink/renderer/core/css_value_keywords.h"
#include "third_party/blink/renderer/core/html/forms/html_opt_group_element.h"
#include "third_party/blink/renderer/core/html/forms/html_select_element.h"
#include "third_party/blink/renderer/core/html_names.h"
namespace blink {
using namespace cssvalue;
using namespace html_names;
HTMLHRElement::HTMLHRElement(Document& document)
: HTMLElement(kHrTag, document) {}
DEFINE_NODE_FACTORY(HTMLHRElement)
bool HTMLHRElement::IsPresentationAttribute(const QualifiedName& name) const {
if (name == kAlignAttr || name == kWidthAttr || name == kColorAttr ||
name == kNoshadeAttr || name == kSizeAttr)
return true;
return HTMLElement::IsPresentationAttribute(name);
}
void HTMLHRElement::CollectStyleForPresentationAttribute(
const QualifiedName& name,
const AtomicString& value,
MutableCSSPropertyValueSet* style) {
if (name == kAlignAttr) {
if (DeprecatedEqualIgnoringCase(value, "left")) {
AddPropertyToPresentationAttributeStyle(
style, CSSPropertyID::kMarginLeft, 0,
CSSPrimitiveValue::UnitType::kPixels);
AddPropertyToPresentationAttributeStyle(
style, CSSPropertyID::kMarginRight, CSSValueID::kAuto);
} else if (DeprecatedEqualIgnoringCase(value, "right")) {
AddPropertyToPresentationAttributeStyle(style, CSSPropertyID::kMarginLeft,
CSSValueID::kAuto);
AddPropertyToPresentationAttributeStyle(
style, CSSPropertyID::kMarginRight, 0,
CSSPrimitiveValue::UnitType::kPixels);
} else {
AddPropertyToPresentationAttributeStyle(style, CSSPropertyID::kMarginLeft,
CSSValueID::kAuto);
AddPropertyToPresentationAttributeStyle(
style, CSSPropertyID::kMarginRight, CSSValueID::kAuto);
}
} else if (name == kWidthAttr) {
bool ok;
int v = value.ToInt(&ok);
if (ok && !v) {
AddPropertyToPresentationAttributeStyle(
style, CSSPropertyID::kWidth, 1,
CSSPrimitiveValue::UnitType::kPixels);
} else {
AddHTMLLengthToStyle(style, CSSPropertyID::kWidth, value);
}
} else if (name == kColorAttr) {
AddPropertyToPresentationAttributeStyle(style, CSSPropertyID::kBorderStyle,
CSSValueID::kSolid);
AddHTMLColorToStyle(style, CSSPropertyID::kBorderColor, value);
AddHTMLColorToStyle(style, CSSPropertyID::kBackgroundColor, value);
} else if (name == kNoshadeAttr) {
if (!hasAttribute(kColorAttr)) {
AddPropertyToPresentationAttributeStyle(
style, CSSPropertyID::kBorderStyle, CSSValueID::kSolid);
const CSSColorValue& dark_gray_value =
*CSSColorValue::Create(Color::kDarkGray);
style->SetProperty(CSSPropertyID::kBorderColor, dark_gray_value);
style->SetProperty(CSSPropertyID::kBackgroundColor, dark_gray_value);
}
} else if (name == kSizeAttr) {
int size = value.ToInt();
if (size <= 1) {
AddPropertyToPresentationAttributeStyle(
style, CSSPropertyID::kBorderBottomWidth, 0,
CSSPrimitiveValue::UnitType::kPixels);
} else {
AddPropertyToPresentationAttributeStyle(
style, CSSPropertyID::kHeight, size - 2,
CSSPrimitiveValue::UnitType::kPixels);
}
} else {
HTMLElement::CollectStyleForPresentationAttribute(name, value, style);
}
}
HTMLSelectElement* HTMLHRElement::OwnerSelectElement() const {
if (!parentNode())
return nullptr;
if (auto* select = ToHTMLSelectElementOrNull(*parentNode()))
return select;
if (!IsHTMLOptGroupElement(*parentNode()))
return nullptr;
return ToHTMLSelectElementOrNull(parentNode()->parentNode());
}
Node::InsertionNotificationRequest HTMLHRElement::InsertedInto(
ContainerNode& insertion_point) {
HTMLElement::InsertedInto(insertion_point);
if (HTMLSelectElement* select = OwnerSelectElement()) {
if (&insertion_point == select || (IsHTMLOptGroupElement(insertion_point) &&
insertion_point.parentNode() == select))
select->HrInsertedOrRemoved(*this);
}
return kInsertionDone;
}
void HTMLHRElement::RemovedFrom(ContainerNode& insertion_point) {
if (auto* select = ToHTMLSelectElementOrNull(insertion_point)) {
if (!parentNode() || IsHTMLOptGroupElement(*parentNode()))
select->HrInsertedOrRemoved(*this);
} else if (IsHTMLOptGroupElement(insertion_point)) {
Node* parent = insertion_point.parentNode();
select = ToHTMLSelectElementOrNull(parent);
if (select)
select->HrInsertedOrRemoved(*this);
}
HTMLElement::RemovedFrom(insertion_point);
}
} // namespace blink