HTMLMapElement.cpp [plain text]
#include "config.h"
#include "HTMLMapElement.h"
#include "Document.h"
#include "HTMLAreaElement.h"
#include "HTMLCollection.h"
#include "HTMLNames.h"
#include "IntSize.h"
#include "HitTestResult.h"
using namespace std;
namespace WebCore {
using namespace HTMLNames;
HTMLMapElement::HTMLMapElement(Document *doc)
: HTMLElement(mapTag, doc)
{
}
HTMLMapElement::~HTMLMapElement()
{
document()->removeImageMap(this);
}
bool HTMLMapElement::checkDTD(const Node* newChild)
{
return inBlockTagList(newChild) || newChild->hasTagName(areaTag) || newChild->hasTagName(scriptTag) || newChild->hasTagName(imgTag); }
bool HTMLMapElement::mapMouseEvent(int x, int y, const IntSize& size, HitTestResult& result)
{
HTMLAreaElement* defaultArea = 0;
Node *node = this;
while ((node = node->traverseNextNode(this))) {
if (node->hasTagName(areaTag)) {
HTMLAreaElement* areaElt = static_cast<HTMLAreaElement*>(node);
if (areaElt->isDefault()) {
if (!defaultArea)
defaultArea = areaElt;
} else if (areaElt->mapMouseEvent(x, y, size, result))
return true;
}
}
if (defaultArea) {
result.setInnerNode(defaultArea);
result.setURLElement(defaultArea);
}
return defaultArea;
}
void HTMLMapElement::parseMappedAttribute(MappedAttribute* attr)
{
const QualifiedName& attrName = attr->name();
if (attrName == idAttr || attrName == nameAttr) {
Document* doc = document();
if (attrName == idAttr) {
HTMLElement::parseMappedAttribute(attr);
if (doc->htmlMode() != Document::XHtml)
return;
}
doc->removeImageMap(this);
String mapName = attr->value();
if (mapName[0] == '#')
mapName = mapName.substring(1);
m_name = doc->htmlMode() == Document::XHtml ? mapName : mapName.lower();
doc->addImageMap(this);
} else
HTMLElement::parseMappedAttribute(attr);
}
PassRefPtr<HTMLCollection> HTMLMapElement::areas()
{
return new HTMLCollection(this, HTMLCollection::MapAreas);
}
String HTMLMapElement::name() const
{
return getAttribute(nameAttr);
}
void HTMLMapElement::setName(const String& value)
{
setAttribute(nameAttr, value);
}
}