1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved.
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
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20 */
21
22 #include "config.h"
23 #include "HTMLMapElement.h"
24
25 #include "Document.h"
26 #include "HTMLAreaElement.h"
27 #include "HTMLCollection.h"
28 #include "HTMLNames.h"
29 #include "HitTestResult.h"
30 #include "IntSize.h"
31 #include "MappedAttribute.h"
32
33 using namespace std;
34
35 namespace WebCore {
36
37 using namespace HTMLNames;
38
HTMLMapElement(const QualifiedName & tagName,Document * doc)39 HTMLMapElement::HTMLMapElement(const QualifiedName& tagName, Document* doc)
40 : HTMLElement(tagName, doc)
41 {
42 ASSERT(hasTagName(mapTag));
43 }
44
~HTMLMapElement()45 HTMLMapElement::~HTMLMapElement()
46 {
47 document()->removeImageMap(this);
48 }
49
checkDTD(const Node * newChild)50 bool HTMLMapElement::checkDTD(const Node* newChild)
51 {
52 return inEitherTagList(newChild) || newChild->hasTagName(areaTag) // HTML 4 DTD
53 || newChild->hasTagName(scriptTag); // extensions
54 }
55
mapMouseEvent(int x,int y,const IntSize & size,HitTestResult & result)56 bool HTMLMapElement::mapMouseEvent(int x, int y, const IntSize& size, HitTestResult& result)
57 {
58 HTMLAreaElement* defaultArea = 0;
59 Node *node = this;
60 while ((node = node->traverseNextNode(this))) {
61 if (node->hasTagName(areaTag)) {
62 HTMLAreaElement* areaElt = static_cast<HTMLAreaElement*>(node);
63 if (areaElt->isDefault()) {
64 if (!defaultArea)
65 defaultArea = areaElt;
66 } else if (areaElt->mapMouseEvent(x, y, size, result))
67 return true;
68 }
69 }
70
71 if (defaultArea) {
72 result.setInnerNode(defaultArea);
73 result.setURLElement(defaultArea);
74 }
75 return defaultArea;
76 }
77
parseMappedAttribute(MappedAttribute * attr)78 void HTMLMapElement::parseMappedAttribute(MappedAttribute* attr)
79 {
80 const QualifiedName& attrName = attr->name();
81 if (attrName == idAttr || attrName == nameAttr) {
82 Document* doc = document();
83 if (attrName == idAttr) {
84 // Call base class so that hasID bit gets set.
85 HTMLElement::parseMappedAttribute(attr);
86 if (doc->isHTMLDocument())
87 return;
88 }
89 doc->removeImageMap(this);
90 String mapName = attr->value();
91 if (mapName[0] == '#')
92 mapName = mapName.substring(1);
93 m_name = doc->isHTMLDocument() ? mapName.lower() : mapName;
94 doc->addImageMap(this);
95 } else
96 HTMLElement::parseMappedAttribute(attr);
97 }
98
areas()99 PassRefPtr<HTMLCollection> HTMLMapElement::areas()
100 {
101 return HTMLCollection::create(this, MapAreas);
102 }
103
name() const104 String HTMLMapElement::name() const
105 {
106 return getAttribute(nameAttr);
107 }
108
setName(const String & value)109 void HTMLMapElement::setName(const String& value)
110 {
111 setAttribute(nameAttr, value);
112 }
113
114 }
115