diff options
author | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
---|---|---|
committer | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
commit | 1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch) | |
tree | 46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/WebCore/html/HTMLAreaElement.cpp | |
parent | 32761a6cee1d0dee366b885b7b9c777e67885688 (diff) | |
download | WebKitGtk-tarball-master.tar.gz |
webkitgtk-2.16.5HEADwebkitgtk-2.16.5master
Diffstat (limited to 'Source/WebCore/html/HTMLAreaElement.cpp')
-rw-r--r-- | Source/WebCore/html/HTMLAreaElement.cpp | 81 |
1 files changed, 43 insertions, 38 deletions
diff --git a/Source/WebCore/html/HTMLAreaElement.cpp b/Source/WebCore/html/HTMLAreaElement.cpp index 5eeb31e46..3a51f25f4 100644 --- a/Source/WebCore/html/HTMLAreaElement.cpp +++ b/Source/WebCore/html/HTMLAreaElement.cpp @@ -23,10 +23,10 @@ #include "HTMLAreaElement.h" #include "AffineTransform.h" -#include "Attribute.h" #include "Frame.h" #include "HTMLImageElement.h" #include "HTMLMapElement.h" +#include "HTMLParserIdioms.h" #include "HitTestResult.h" #include "Path.h" #include "RenderImage.h" @@ -38,32 +38,33 @@ using namespace HTMLNames; inline HTMLAreaElement::HTMLAreaElement(const QualifiedName& tagName, Document& document) : HTMLAnchorElement(tagName, document) - , m_coordsLen(0) , m_lastSize(-1, -1) , m_shape(Unknown) { ASSERT(hasTagName(areaTag)); } -PassRefPtr<HTMLAreaElement> HTMLAreaElement::create(const QualifiedName& tagName, Document& document) +Ref<HTMLAreaElement> HTMLAreaElement::create(const QualifiedName& tagName, Document& document) { - return adoptRef(new HTMLAreaElement(tagName, document)); + return adoptRef(*new HTMLAreaElement(tagName, document)); } void HTMLAreaElement::parseAttribute(const QualifiedName& name, const AtomicString& value) { if (name == shapeAttr) { - if (equalIgnoringCase(value, "default")) + if (equalLettersIgnoringASCIICase(value, "default")) m_shape = Default; - else if (equalIgnoringCase(value, "circle")) + else if (equalLettersIgnoringASCIICase(value, "circle") || equalLettersIgnoringASCIICase(value, "circ")) m_shape = Circle; - else if (equalIgnoringCase(value, "poly")) + else if (equalLettersIgnoringASCIICase(value, "poly") || equalLettersIgnoringASCIICase(value, "polygon")) m_shape = Poly; - else if (equalIgnoringCase(value, "rect")) + else { + // The missing value default is the rectangle state. m_shape = Rect; + } invalidateCachedRegion(); } else if (name == coordsAttr) { - m_coords = newCoordsArray(value.string(), m_coordsLen); + m_coords = parseHTMLListOfOfFloatingPointNumberValues(value.string()); invalidateCachedRegion(); } else if (name == altAttr || name == accesskeyAttr) { // Do nothing. @@ -79,7 +80,7 @@ void HTMLAreaElement::invalidateCachedRegion() bool HTMLAreaElement::mapMouseEvent(LayoutPoint location, const LayoutSize& size, HitTestResult& result) { if (m_lastSize != size) { - m_region = adoptPtr(new Path(getRegion(size))); + m_region = std::make_unique<Path>(getRegion(size)); m_lastSize = size; } @@ -117,6 +118,11 @@ Path HTMLAreaElement::computePath(RenderObject* obj) const return p; } +Path HTMLAreaElement::computePathForFocusRing(const LayoutSize& elementSize) const +{ + return getRegion(m_shape == Default ? elementSize : m_lastSize); +} + // FIXME: Use RenderElement* instead of RenderObject* once we upstream iOS's DOMUIKitExtensions.{h, mm}. LayoutRect HTMLAreaElement::computeRect(RenderObject* obj) const { @@ -125,7 +131,7 @@ LayoutRect HTMLAreaElement::computeRect(RenderObject* obj) const Path HTMLAreaElement::getRegion(const LayoutSize& size) const { - if (!m_coords && m_shape != Default) + if (m_coords.isEmpty() && m_shape != Default) return Path(); LayoutUnit width = size.width(); @@ -134,39 +140,38 @@ Path HTMLAreaElement::getRegion(const LayoutSize& size) const // If element omits the shape attribute, select shape based on number of coordinates. Shape shape = m_shape; if (shape == Unknown) { - if (m_coordsLen == 3) + if (m_coords.size() == 3) shape = Circle; - else if (m_coordsLen == 4) + else if (m_coords.size() == 4) shape = Rect; - else if (m_coordsLen >= 6) + else if (m_coords.size() >= 6) shape = Poly; } Path path; - RenderView* renderView = document().renderView(); switch (shape) { case Poly: - if (m_coordsLen >= 6) { - int numPoints = m_coordsLen / 2; - path.moveTo(FloatPoint(minimumValueForLength(m_coords[0], width, renderView), minimumValueForLength(m_coords[1], height, renderView))); + if (m_coords.size() >= 6) { + int numPoints = m_coords.size() / 2; + path.moveTo(FloatPoint(m_coords[0], m_coords[1])); for (int i = 1; i < numPoints; ++i) - path.addLineTo(FloatPoint(minimumValueForLength(m_coords[i * 2], width, renderView), minimumValueForLength(m_coords[i * 2 + 1], height, renderView))); + path.addLineTo(FloatPoint(m_coords[i * 2], m_coords[i * 2 + 1])); path.closeSubpath(); } break; case Circle: - if (m_coordsLen >= 3) { - Length radius = m_coords[2]; - int r = std::min(minimumValueForLength(radius, width, renderView), minimumValueForLength(radius, height, renderView)); - path.addEllipse(FloatRect(minimumValueForLength(m_coords[0], width, renderView) - r, minimumValueForLength(m_coords[1], height, renderView) - r, 2 * r, 2 * r)); + if (m_coords.size() >= 3) { + double radius = m_coords[2]; + if (radius > 0) + path.addEllipse(FloatRect(m_coords[0] - radius, m_coords[1] - radius, 2 * radius, 2 * radius)); } break; case Rect: - if (m_coordsLen >= 4) { - int x0 = minimumValueForLength(m_coords[0], width, renderView); - int y0 = minimumValueForLength(m_coords[1], height, renderView); - int x1 = minimumValueForLength(m_coords[2], width, renderView); - int y1 = minimumValueForLength(m_coords[3], height, renderView); + if (m_coords.size() >= 4) { + double x0 = m_coords[0]; + double y0 = m_coords[1]; + double x1 = m_coords[2]; + double y1 = m_coords[3]; path.addRect(FloatRect(x0, y0, x1 - x0, y1 - y0)); } break; @@ -183,13 +188,13 @@ Path HTMLAreaElement::getRegion(const LayoutSize& size) const HTMLImageElement* HTMLAreaElement::imageElement() const { Node* mapElement = parentNode(); - if (!mapElement || !isHTMLMapElement(mapElement)) - return 0; + if (!is<HTMLMapElement>(mapElement)) + return nullptr; - return toHTMLMapElement(mapElement)->imageElement(); + return downcast<HTMLMapElement>(*mapElement).imageElement(); } -bool HTMLAreaElement::isKeyboardFocusable(KeyboardEvent*) const +bool HTMLAreaElement::isKeyboardFocusable(KeyboardEvent&) const { return isFocusable(); } @@ -219,14 +224,14 @@ void HTMLAreaElement::setFocus(bool shouldBeFocused) if (!imageElement) return; - auto renderer = imageElement->renderer(); - if (!renderer || !renderer->isRenderImage()) + auto* renderer = imageElement->renderer(); + if (!is<RenderImage>(renderer)) return; - toRenderImage(renderer)->areaElementFocusChanged(this); + downcast<RenderImage>(*renderer).areaElementFocusChanged(this); } -void HTMLAreaElement::updateFocusAppearance(bool restorePreviousSelection) +void HTMLAreaElement::updateFocusAppearance(SelectionRestorationMode restorationMode, SelectionRevealMode revealMode) { if (!isFocusable()) return; @@ -235,7 +240,7 @@ void HTMLAreaElement::updateFocusAppearance(bool restorePreviousSelection) if (!imageElement) return; - imageElement->updateFocusAppearance(restorePreviousSelection); + imageElement->updateFocusAppearance(restorationMode, revealMode); } bool HTMLAreaElement::supportsFocus() const @@ -248,7 +253,7 @@ bool HTMLAreaElement::supportsFocus() const String HTMLAreaElement::target() const { - return getAttribute(targetAttr); + return attributeWithoutSynchronization(targetAttr); } } |