darin | 6b7950a | 2007-08-11 17:18:57 +0000 | [diff] [blame] | 1 | /* |
eseidel | 8494362 | 2006-05-15 23:23:42 +0000 | [diff] [blame] | 2 | * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
| 3 | * (C) 1999 Antti Koivisto (koivisto@kde.org) |
darin@apple.com | 877ce5b | 2010-05-28 15:38:58 +0000 | [diff] [blame] | 4 | * Copyright (C) 2004, 2005, 2006, 2007, 2010 Apple Inc. All rights reserved. |
eseidel | 8494362 | 2006-05-15 23:23:42 +0000 | [diff] [blame] | 5 | * |
| 6 | * This library is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU Library General Public |
| 8 | * License as published by the Free Software Foundation; either |
| 9 | * version 2 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * This library is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | * Library General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU Library General Public License |
| 17 | * along with this library; see the file COPYING.LIB. If not, write to |
ddkilzer | c8eccec | 2007-09-26 02:29:57 +0000 | [diff] [blame] | 18 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 19 | * Boston, MA 02110-1301, USA. |
eseidel | 8494362 | 2006-05-15 23:23:42 +0000 | [diff] [blame] | 20 | */ |
darin@apple.com | 9a925fa | 2009-05-04 18:00:34 +0000 | [diff] [blame] | 21 | |
eseidel | 8494362 | 2006-05-15 23:23:42 +0000 | [diff] [blame] | 22 | #include "config.h" |
| 23 | #include "HTMLMapElement.h" |
| 24 | |
weinig@apple.com | c360893 | 2010-05-19 17:48:06 +0000 | [diff] [blame] | 25 | #include "Attribute.h" |
eseidel | 8494362 | 2006-05-15 23:23:42 +0000 | [diff] [blame] | 26 | #include "Document.h" |
antti@apple.com | 0494cf8 | 2013-08-31 14:12:00 +0000 | [diff] [blame] | 27 | #include "ElementIterator.h" |
eseidel | 8494362 | 2006-05-15 23:23:42 +0000 | [diff] [blame] | 28 | #include "HTMLAreaElement.h" |
| 29 | #include "HTMLCollection.h" |
cfleizach@apple.com | bc08890 | 2010-01-26 18:06:41 +0000 | [diff] [blame] | 30 | #include "HTMLImageElement.h" |
bdakin | c1a5a83 | 2006-10-28 18:28:00 +0000 | [diff] [blame] | 31 | #include "HitTestResult.h" |
darin@apple.com | 9a925fa | 2009-05-04 18:00:34 +0000 | [diff] [blame] | 32 | #include "IntSize.h" |
eseidel | 8494362 | 2006-05-15 23:23:42 +0000 | [diff] [blame] | 33 | |
eseidel | 8494362 | 2006-05-15 23:23:42 +0000 | [diff] [blame] | 34 | namespace WebCore { |
| 35 | |
| 36 | using namespace HTMLNames; |
| 37 | |
weinig@apple.com | 4917883 | 2013-09-15 00:39:29 +0000 | [diff] [blame] | 38 | HTMLMapElement::HTMLMapElement(const QualifiedName& tagName, Document& document) |
weinig@apple.com | dedf67e | 2013-09-15 05:23:01 +0000 | [diff] [blame] | 39 | : HTMLElement(tagName, document) |
eseidel | 8494362 | 2006-05-15 23:23:42 +0000 | [diff] [blame] | 40 | { |
jchaffraix@webkit.org | 94d95b0 | 2008-12-04 22:39:05 +0000 | [diff] [blame] | 41 | ASSERT(hasTagName(mapTag)); |
eseidel | 8494362 | 2006-05-15 23:23:42 +0000 | [diff] [blame] | 42 | } |
| 43 | |
weinig@apple.com | 4917883 | 2013-09-15 00:39:29 +0000 | [diff] [blame] | 44 | PassRefPtr<HTMLMapElement> HTMLMapElement::create(Document& document) |
darin@apple.com | 877ce5b | 2010-05-28 15:38:58 +0000 | [diff] [blame] | 45 | { |
darin@apple.com | f190b3d | 2010-06-16 23:07:32 +0000 | [diff] [blame] | 46 | return adoptRef(new HTMLMapElement(mapTag, document)); |
darin@apple.com | 877ce5b | 2010-05-28 15:38:58 +0000 | [diff] [blame] | 47 | } |
| 48 | |
weinig@apple.com | 4917883 | 2013-09-15 00:39:29 +0000 | [diff] [blame] | 49 | PassRefPtr<HTMLMapElement> HTMLMapElement::create(const QualifiedName& tagName, Document& document) |
darin@apple.com | 877ce5b | 2010-05-28 15:38:58 +0000 | [diff] [blame] | 50 | { |
darin@apple.com | f190b3d | 2010-06-16 23:07:32 +0000 | [diff] [blame] | 51 | return adoptRef(new HTMLMapElement(tagName, document)); |
darin@apple.com | 877ce5b | 2010-05-28 15:38:58 +0000 | [diff] [blame] | 52 | } |
| 53 | |
eseidel | 8494362 | 2006-05-15 23:23:42 +0000 | [diff] [blame] | 54 | HTMLMapElement::~HTMLMapElement() |
| 55 | { |
eseidel | 8494362 | 2006-05-15 23:23:42 +0000 | [diff] [blame] | 56 | } |
| 57 | |
eae@chromium.org | 020f587 | 2011-08-18 03:38:05 +0000 | [diff] [blame] | 58 | bool HTMLMapElement::mapMouseEvent(LayoutPoint location, const LayoutSize& size, HitTestResult& result) |
eseidel | 8494362 | 2006-05-15 23:23:42 +0000 | [diff] [blame] | 59 | { |
hyatt | 00af680d | 2006-09-19 21:31:59 +0000 | [diff] [blame] | 60 | HTMLAreaElement* defaultArea = 0; |
antti@apple.com | b8a9576 | 2013-08-25 21:30:10 +0000 | [diff] [blame] | 61 | |
weinig@apple.com | c77041e | 2013-12-14 18:05:45 +0000 | [diff] [blame] | 62 | for (auto& area : descendantsOfType<HTMLAreaElement>(*this)) { |
| 63 | if (area.isDefault()) { |
antti@apple.com | ecdc7b0 | 2013-08-23 12:40:49 +0000 | [diff] [blame] | 64 | if (!defaultArea) |
weinig@apple.com | c77041e | 2013-12-14 18:05:45 +0000 | [diff] [blame] | 65 | defaultArea = &area; |
| 66 | } else if (area.mapMouseEvent(location, size, result)) |
antti@apple.com | ecdc7b0 | 2013-08-23 12:40:49 +0000 | [diff] [blame] | 67 | return true; |
hyatt | 00af680d | 2006-09-19 21:31:59 +0000 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | if (defaultArea) { |
bdakin | 1c628c0 | 2006-10-29 22:07:47 +0000 | [diff] [blame] | 71 | result.setInnerNode(defaultArea); |
| 72 | result.setURLElement(defaultArea); |
hyatt | 00af680d | 2006-09-19 21:31:59 +0000 | [diff] [blame] | 73 | } |
| 74 | return defaultArea; |
eseidel | 8494362 | 2006-05-15 23:23:42 +0000 | [diff] [blame] | 75 | } |
| 76 | |
commit-queue@webkit.org | 7e978e1 | 2011-07-20 21:12:30 +0000 | [diff] [blame] | 77 | HTMLImageElement* HTMLMapElement::imageElement() |
cfleizach@apple.com | bc08890 | 2010-01-26 18:06:41 +0000 | [diff] [blame] | 78 | { |
rniwa@webkit.org | 01ebac5 | 2013-10-05 02:59:02 +0000 | [diff] [blame] | 79 | if (m_name.isEmpty()) |
| 80 | return 0; |
| 81 | AtomicString lowercasedName = m_name.lower(); |
| 82 | ASSERT(lowercasedName.impl()); |
| 83 | return document().imageElementByLowercasedUsemap(*lowercasedName.impl()); |
cfleizach@apple.com | bc08890 | 2010-01-26 18:06:41 +0000 | [diff] [blame] | 84 | } |
darin@apple.com | f5247d1 | 2010-06-13 17:29:10 +0000 | [diff] [blame] | 85 | |
akling@apple.com | 43e9d04 | 2012-11-18 16:55:06 +0000 | [diff] [blame] | 86 | void HTMLMapElement::parseAttribute(const QualifiedName& name, const AtomicString& value) |
eseidel | 8494362 | 2006-05-15 23:23:42 +0000 | [diff] [blame] | 87 | { |
darin@apple.com | f5247d1 | 2010-06-13 17:29:10 +0000 | [diff] [blame] | 88 | // FIXME: This logic seems wrong for XML documents. |
| 89 | // Either the id or name will be used depending on the order the attributes are parsed. |
| 90 | |
akling@apple.com | a1ed58f | 2014-03-04 10:28:38 +0000 | [diff] [blame] | 91 | if (name == HTMLNames::idAttr || name == HTMLNames::nameAttr) { |
| 92 | if (name == HTMLNames::idAttr) { |
eseidel | 8494362 | 2006-05-15 23:23:42 +0000 | [diff] [blame] | 93 | // Call base class so that hasID bit gets set. |
akling@apple.com | 43e9d04 | 2012-11-18 16:55:06 +0000 | [diff] [blame] | 94 | HTMLElement::parseAttribute(name, value); |
akling@apple.com | 622b1a4 | 2013-08-30 14:30:12 +0000 | [diff] [blame] | 95 | if (document().isHTMLDocument()) |
eseidel | 8494362 | 2006-05-15 23:23:42 +0000 | [diff] [blame] | 96 | return; |
| 97 | } |
ap@apple.com | 115b70a | 2010-06-10 05:33:00 +0000 | [diff] [blame] | 98 | if (inDocument()) |
akling@apple.com | 3eb4c41 | 2013-10-06 02:30:52 +0000 | [diff] [blame] | 99 | treeScope().removeImageMap(*this); |
akling@apple.com | 43e9d04 | 2012-11-18 16:55:06 +0000 | [diff] [blame] | 100 | String mapName = value; |
antti | 614703a | 2007-02-12 18:07:26 +0000 | [diff] [blame] | 101 | if (mapName[0] == '#') |
antti | 2330871 | 2007-02-12 20:28:52 +0000 | [diff] [blame] | 102 | mapName = mapName.substring(1); |
akling@apple.com | 622b1a4 | 2013-08-30 14:30:12 +0000 | [diff] [blame] | 103 | m_name = document().isHTMLDocument() ? mapName.lower() : mapName; |
ap@apple.com | 115b70a | 2010-06-10 05:33:00 +0000 | [diff] [blame] | 104 | if (inDocument()) |
akling@apple.com | 3eb4c41 | 2013-10-06 02:30:52 +0000 | [diff] [blame] | 105 | treeScope().addImageMap(*this); |
commit-queue@webkit.org | caca49d | 2011-12-10 02:29:51 +0000 | [diff] [blame] | 106 | |
darin@apple.com | f5247d1 | 2010-06-13 17:29:10 +0000 | [diff] [blame] | 107 | return; |
| 108 | } |
| 109 | |
akling@apple.com | 43e9d04 | 2012-11-18 16:55:06 +0000 | [diff] [blame] | 110 | HTMLElement::parseAttribute(name, value); |
eseidel | 8494362 | 2006-05-15 23:23:42 +0000 | [diff] [blame] | 111 | } |
| 112 | |
rniwa@webkit.org | 4823cc1 | 2012-07-09 17:40:09 +0000 | [diff] [blame] | 113 | PassRefPtr<HTMLCollection> HTMLMapElement::areas() |
eseidel | 8494362 | 2006-05-15 23:23:42 +0000 | [diff] [blame] | 114 | { |
kling@webkit.org | a3a65e3 | 2012-01-01 21:05:42 +0000 | [diff] [blame] | 115 | return ensureCachedHTMLCollection(MapAreas); |
eseidel | 8494362 | 2006-05-15 23:23:42 +0000 | [diff] [blame] | 116 | } |
| 117 | |
akling@apple.com | 2e55ebf | 2013-10-04 18:51:32 +0000 | [diff] [blame] | 118 | Node::InsertionNotificationRequest HTMLMapElement::insertedInto(ContainerNode& insertionPoint) |
ap@apple.com | 115b70a | 2010-06-10 05:33:00 +0000 | [diff] [blame] | 119 | { |
rniwa@webkit.org | 21186e9 | 2013-11-19 09:43:22 +0000 | [diff] [blame] | 120 | Node::InsertionNotificationRequest request = HTMLElement::insertedInto(insertionPoint); |
akling@apple.com | 2e55ebf | 2013-10-04 18:51:32 +0000 | [diff] [blame] | 121 | if (insertionPoint.inDocument()) |
akling@apple.com | 3eb4c41 | 2013-10-06 02:30:52 +0000 | [diff] [blame] | 122 | treeScope().addImageMap(*this); |
rniwa@webkit.org | 21186e9 | 2013-11-19 09:43:22 +0000 | [diff] [blame] | 123 | return request; |
ap@apple.com | 115b70a | 2010-06-10 05:33:00 +0000 | [diff] [blame] | 124 | } |
| 125 | |
akling@apple.com | 2e55ebf | 2013-10-04 18:51:32 +0000 | [diff] [blame] | 126 | void HTMLMapElement::removedFrom(ContainerNode& insertionPoint) |
ap@apple.com | 115b70a | 2010-06-10 05:33:00 +0000 | [diff] [blame] | 127 | { |
akling@apple.com | 2e55ebf | 2013-10-04 18:51:32 +0000 | [diff] [blame] | 128 | if (insertionPoint.inDocument()) |
akling@apple.com | 3eb4c41 | 2013-10-06 02:30:52 +0000 | [diff] [blame] | 129 | treeScope().removeImageMap(*this); |
commit-queue@webkit.org | 9ea0080 | 2012-04-17 06:40:55 +0000 | [diff] [blame] | 130 | HTMLElement::removedFrom(insertionPoint); |
ap@apple.com | 115b70a | 2010-06-10 05:33:00 +0000 | [diff] [blame] | 131 | } |
| 132 | |
eseidel | 8494362 | 2006-05-15 23:23:42 +0000 | [diff] [blame] | 133 | } |