This source file includes following definitions.
- create
- mapMouseEvent
- imageElement
- parseAttribute
- areas
- insertedInto
- removedFrom
#include "config.h"
#include "core/html/HTMLMapElement.h"
#include "HTMLNames.h"
#include "core/dom/Document.h"
#include "core/dom/ElementTraversal.h"
#include "core/html/HTMLAreaElement.h"
#include "core/html/HTMLCollection.h"
#include "core/html/HTMLImageElement.h"
#include "core/rendering/HitTestResult.h"
using namespace std;
namespace WebCore {
using namespace HTMLNames;
HTMLMapElement::HTMLMapElement(Document& document)
: HTMLElement(mapTag, document)
{
ScriptWrappable::init(this);
}
PassRefPtr<HTMLMapElement> HTMLMapElement::create(Document& document)
{
return adoptRef(new HTMLMapElement(document));
}
HTMLMapElement::~HTMLMapElement()
{
}
bool HTMLMapElement::mapMouseEvent(LayoutPoint location, const LayoutSize& size, HitTestResult& result)
{
HTMLAreaElement* defaultArea = 0;
for (HTMLAreaElement* area = Traversal<HTMLAreaElement>::firstWithin(*this); area; area = Traversal<HTMLAreaElement>::next(*area, this)) {
if (area->isDefault()) {
if (!defaultArea)
defaultArea = area;
} else if (area->mapMouseEvent(location, size, result)) {
return true;
}
}
if (defaultArea) {
result.setInnerNode(defaultArea);
result.setURLElement(defaultArea);
}
return defaultArea;
}
HTMLImageElement* HTMLMapElement::imageElement()
{
RefPtr<HTMLCollection> images = document().images();
for (unsigned i = 0; Element* curr = images->item(i); i++) {
ASSERT(isHTMLImageElement(curr));
HTMLImageElement& imageElement = toHTMLImageElement(*curr);
String useMapName = imageElement.getAttribute(usemapAttr).string().substring(1);
if (equalIgnoringCase(useMapName, m_name))
return &imageElement;
}
return 0;
}
void HTMLMapElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
{
if (isIdAttributeName(name) || name == nameAttr) {
if (isIdAttributeName(name)) {
HTMLElement::parseAttribute(name, value);
if (document().isHTMLDocument())
return;
}
if (inDocument())
treeScope().removeImageMap(this);
String mapName = value;
if (mapName[0] == '#')
mapName = mapName.substring(1);
m_name = AtomicString(document().isHTMLDocument() ? mapName.lower() : mapName);
if (inDocument())
treeScope().addImageMap(this);
return;
}
HTMLElement::parseAttribute(name, value);
}
PassRefPtr<HTMLCollection> HTMLMapElement::areas()
{
return ensureCachedHTMLCollection(MapAreas);
}
Node::InsertionNotificationRequest HTMLMapElement::insertedInto(ContainerNode* insertionPoint)
{
if (insertionPoint->inDocument())
treeScope().addImageMap(this);
return HTMLElement::insertedInto(insertionPoint);
}
void HTMLMapElement::removedFrom(ContainerNode* insertionPoint)
{
if (insertionPoint->inDocument())
treeScope().removeImageMap(this);
HTMLElement::removedFrom(insertionPoint);
}
}