MouseRelatedEvent.cpp [plain text]
#include "config.h"
#include "MouseRelatedEvent.h"
#include "DOMWindow.h"
#include "Document.h"
#include "Frame.h"
#include "FrameView.h"
#include "Node.h"
#include "RenderLayer.h"
#include "RenderObject.h"
namespace WebCore {
MouseRelatedEvent::MouseRelatedEvent()
: m_screenX(0)
, m_screenY(0)
, m_clientX(0)
, m_clientY(0)
, m_pageX(0)
, m_pageY(0)
, m_layerX(0)
, m_layerY(0)
, m_offsetX(0)
, m_offsetY(0)
, m_isSimulated(false)
{
}
static int contentsX(AbstractView* abstractView)
{
if (!abstractView)
return 0;
Frame* frame = abstractView->frame();
if (!frame)
return 0;
FrameView* frameView = frame->view();
if (!frameView)
return 0;
return frameView->contentsX();
}
static int contentsY(AbstractView* abstractView)
{
if (!abstractView)
return 0;
Frame* frame = abstractView->frame();
if (!frame)
return 0;
FrameView* frameView = frame->view();
if (!frameView)
return 0;
return frameView->contentsY();
}
MouseRelatedEvent::MouseRelatedEvent(const AtomicString& eventType, bool canBubble, bool cancelable, AbstractView* view,
int detail, int screenX, int screenY, int pageX, int pageY,
bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, bool isSimulated)
: UIEventWithKeyState(eventType, canBubble, cancelable, view, detail, ctrlKey, altKey, shiftKey, metaKey)
, m_screenX(screenX)
, m_screenY(screenY)
, m_clientX(pageX - contentsX(view))
, m_clientY(pageY - contentsY(view))
, m_pageX(pageX)
, m_pageY(pageY)
, m_isSimulated(isSimulated)
{
initCoordinates();
}
void MouseRelatedEvent::initCoordinates()
{
m_layerX = m_pageX;
m_layerY = m_pageY;
m_offsetX = m_pageX;
m_offsetY = m_pageY;
}
void MouseRelatedEvent::initCoordinates(int clientX, int clientY)
{
m_clientX = clientX;
m_clientY = clientY;
m_pageX = clientX + contentsX(view());
m_pageY = clientY + contentsY(view());
m_layerX = m_pageX;
m_layerY = m_pageY;
m_offsetX = m_pageX;
m_offsetY = m_pageY;
}
void MouseRelatedEvent::receivedTarget()
{
ASSERT(target());
Node* targ = target()->toNode();
if (!targ)
return;
m_layerX = m_pageX;
m_layerY = m_pageY;
m_offsetX = m_pageX;
m_offsetY = m_pageY;
targ->document()->updateRendering();
if (!isSimulated()) {
if (RenderObject* r = targ->renderer()) {
int rx, ry;
if (r->absolutePosition(rx, ry)) {
m_offsetX -= rx;
m_offsetY -= ry;
}
}
}
Node* n = targ;
while (n && !n->renderer())
n = n->parent();
if (n) {
RenderLayer* layer = n->renderer()->enclosingLayer();
layer->updateLayerPosition();
for (; layer; layer = layer->parent()) {
m_layerX -= layer->xPos();
m_layerY -= layer->yPos();
}
}
}
int MouseRelatedEvent::pageX() const
{
return m_pageX;
}
int MouseRelatedEvent::pageY() const
{
return m_pageY;
}
int MouseRelatedEvent::x() const
{
return m_clientX;
}
int MouseRelatedEvent::y() const
{
return m_clientY;
}
}