blob: 97c5fe24d6f8be17737cb20c62754bcf0e4b2025 [file] [log] [blame]
darin6b7950a2007-08-11 17:18:57 +00001/*
eseidel84943622006-05-15 23:23:42 +00002 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
darin@apple.com877ce5b2010-05-28 15:38:58 +00004 * Copyright (C) 2004, 2005, 2006, 2007, 2010 Apple Inc. All rights reserved.
eseidel84943622006-05-15 23:23:42 +00005 *
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
ddkilzerc8eccec2007-09-26 02:29:57 +000018 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
eseidel84943622006-05-15 23:23:42 +000020 */
darin@apple.com9a925fa2009-05-04 18:00:34 +000021
eseidel84943622006-05-15 23:23:42 +000022#include "config.h"
23#include "HTMLMapElement.h"
24
weinig@apple.comc3608932010-05-19 17:48:06 +000025#include "Attribute.h"
eseidel84943622006-05-15 23:23:42 +000026#include "Document.h"
antti@apple.com0494cf82013-08-31 14:12:00 +000027#include "ElementIterator.h"
eseidel84943622006-05-15 23:23:42 +000028#include "HTMLAreaElement.h"
29#include "HTMLCollection.h"
cfleizach@apple.combc088902010-01-26 18:06:41 +000030#include "HTMLImageElement.h"
bdakinc1a5a832006-10-28 18:28:00 +000031#include "HitTestResult.h"
darin@apple.com9a925fa2009-05-04 18:00:34 +000032#include "IntSize.h"
eseidel84943622006-05-15 23:23:42 +000033
eseidel84943622006-05-15 23:23:42 +000034namespace WebCore {
35
36using namespace HTMLNames;
37
weinig@apple.com49178832013-09-15 00:39:29 +000038HTMLMapElement::HTMLMapElement(const QualifiedName& tagName, Document& document)
weinig@apple.comdedf67e2013-09-15 05:23:01 +000039 : HTMLElement(tagName, document)
eseidel84943622006-05-15 23:23:42 +000040{
jchaffraix@webkit.org94d95b02008-12-04 22:39:05 +000041 ASSERT(hasTagName(mapTag));
eseidel84943622006-05-15 23:23:42 +000042}
43
weinig@apple.com49178832013-09-15 00:39:29 +000044PassRefPtr<HTMLMapElement> HTMLMapElement::create(Document& document)
darin@apple.com877ce5b2010-05-28 15:38:58 +000045{
darin@apple.comf190b3d2010-06-16 23:07:32 +000046 return adoptRef(new HTMLMapElement(mapTag, document));
darin@apple.com877ce5b2010-05-28 15:38:58 +000047}
48
weinig@apple.com49178832013-09-15 00:39:29 +000049PassRefPtr<HTMLMapElement> HTMLMapElement::create(const QualifiedName& tagName, Document& document)
darin@apple.com877ce5b2010-05-28 15:38:58 +000050{
darin@apple.comf190b3d2010-06-16 23:07:32 +000051 return adoptRef(new HTMLMapElement(tagName, document));
darin@apple.com877ce5b2010-05-28 15:38:58 +000052}
53
eseidel84943622006-05-15 23:23:42 +000054HTMLMapElement::~HTMLMapElement()
55{
eseidel84943622006-05-15 23:23:42 +000056}
57
eae@chromium.org020f5872011-08-18 03:38:05 +000058bool HTMLMapElement::mapMouseEvent(LayoutPoint location, const LayoutSize& size, HitTestResult& result)
eseidel84943622006-05-15 23:23:42 +000059{
hyatt00af680d2006-09-19 21:31:59 +000060 HTMLAreaElement* defaultArea = 0;
antti@apple.comb8a95762013-08-25 21:30:10 +000061
weinig@apple.comc77041e2013-12-14 18:05:45 +000062 for (auto& area : descendantsOfType<HTMLAreaElement>(*this)) {
63 if (area.isDefault()) {
antti@apple.comecdc7b02013-08-23 12:40:49 +000064 if (!defaultArea)
weinig@apple.comc77041e2013-12-14 18:05:45 +000065 defaultArea = &area;
66 } else if (area.mapMouseEvent(location, size, result))
antti@apple.comecdc7b02013-08-23 12:40:49 +000067 return true;
hyatt00af680d2006-09-19 21:31:59 +000068 }
69
70 if (defaultArea) {
bdakin1c628c02006-10-29 22:07:47 +000071 result.setInnerNode(defaultArea);
72 result.setURLElement(defaultArea);
hyatt00af680d2006-09-19 21:31:59 +000073 }
74 return defaultArea;
eseidel84943622006-05-15 23:23:42 +000075}
76
commit-queue@webkit.org7e978e12011-07-20 21:12:30 +000077HTMLImageElement* HTMLMapElement::imageElement()
cfleizach@apple.combc088902010-01-26 18:06:41 +000078{
rniwa@webkit.org01ebac52013-10-05 02:59:02 +000079 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.combc088902010-01-26 18:06:41 +000084}
darin@apple.comf5247d12010-06-13 17:29:10 +000085
akling@apple.com43e9d042012-11-18 16:55:06 +000086void HTMLMapElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
eseidel84943622006-05-15 23:23:42 +000087{
darin@apple.comf5247d12010-06-13 17:29:10 +000088 // 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.coma1ed58f2014-03-04 10:28:38 +000091 if (name == HTMLNames::idAttr || name == HTMLNames::nameAttr) {
92 if (name == HTMLNames::idAttr) {
eseidel84943622006-05-15 23:23:42 +000093 // Call base class so that hasID bit gets set.
akling@apple.com43e9d042012-11-18 16:55:06 +000094 HTMLElement::parseAttribute(name, value);
akling@apple.com622b1a42013-08-30 14:30:12 +000095 if (document().isHTMLDocument())
eseidel84943622006-05-15 23:23:42 +000096 return;
97 }
ap@apple.com115b70a2010-06-10 05:33:00 +000098 if (inDocument())
akling@apple.com3eb4c412013-10-06 02:30:52 +000099 treeScope().removeImageMap(*this);
akling@apple.com43e9d042012-11-18 16:55:06 +0000100 String mapName = value;
antti614703a2007-02-12 18:07:26 +0000101 if (mapName[0] == '#')
antti23308712007-02-12 20:28:52 +0000102 mapName = mapName.substring(1);
akling@apple.com622b1a42013-08-30 14:30:12 +0000103 m_name = document().isHTMLDocument() ? mapName.lower() : mapName;
ap@apple.com115b70a2010-06-10 05:33:00 +0000104 if (inDocument())
akling@apple.com3eb4c412013-10-06 02:30:52 +0000105 treeScope().addImageMap(*this);
commit-queue@webkit.orgcaca49d2011-12-10 02:29:51 +0000106
darin@apple.comf5247d12010-06-13 17:29:10 +0000107 return;
108 }
109
akling@apple.com43e9d042012-11-18 16:55:06 +0000110 HTMLElement::parseAttribute(name, value);
eseidel84943622006-05-15 23:23:42 +0000111}
112
rniwa@webkit.org4823cc12012-07-09 17:40:09 +0000113PassRefPtr<HTMLCollection> HTMLMapElement::areas()
eseidel84943622006-05-15 23:23:42 +0000114{
kling@webkit.orga3a65e32012-01-01 21:05:42 +0000115 return ensureCachedHTMLCollection(MapAreas);
eseidel84943622006-05-15 23:23:42 +0000116}
117
akling@apple.com2e55ebf2013-10-04 18:51:32 +0000118Node::InsertionNotificationRequest HTMLMapElement::insertedInto(ContainerNode& insertionPoint)
ap@apple.com115b70a2010-06-10 05:33:00 +0000119{
rniwa@webkit.org21186e92013-11-19 09:43:22 +0000120 Node::InsertionNotificationRequest request = HTMLElement::insertedInto(insertionPoint);
akling@apple.com2e55ebf2013-10-04 18:51:32 +0000121 if (insertionPoint.inDocument())
akling@apple.com3eb4c412013-10-06 02:30:52 +0000122 treeScope().addImageMap(*this);
rniwa@webkit.org21186e92013-11-19 09:43:22 +0000123 return request;
ap@apple.com115b70a2010-06-10 05:33:00 +0000124}
125
akling@apple.com2e55ebf2013-10-04 18:51:32 +0000126void HTMLMapElement::removedFrom(ContainerNode& insertionPoint)
ap@apple.com115b70a2010-06-10 05:33:00 +0000127{
akling@apple.com2e55ebf2013-10-04 18:51:32 +0000128 if (insertionPoint.inDocument())
akling@apple.com3eb4c412013-10-06 02:30:52 +0000129 treeScope().removeImageMap(*this);
commit-queue@webkit.org9ea00802012-04-17 06:40:55 +0000130 HTMLElement::removedFrom(insertionPoint);
ap@apple.com115b70a2010-06-10 05:33:00 +0000131}
132
eseidel84943622006-05-15 23:23:42 +0000133}