Commit 2750082a authored by rjw's avatar rjw

First pass at events, very messy.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@468 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 8a43743b
......@@ -323,7 +323,11 @@ void KHTMLView::drawContents( QPainter *p, int ex, int ey, int ew, int eh )
}
khtml::DrawContentsEvent event( p, ex, ey, ew, eh );
#ifdef _KWQ_
m_part->event (&event);
#else
QApplication::sendEvent( m_part, &event );
#endif
}
void KHTMLView::layout(bool)
......@@ -403,7 +407,11 @@ void KHTMLView::viewportMousePressEvent( QMouseEvent *_mouse )
khtml::MousePressEvent event( _mouse, xm, ym, mev.url, mev.innerNode );
event.setNodePos( mev.nodeAbsX, mev.nodeAbsY );
#ifdef _KWQ_
m_part->event (&event);
#else
QApplication::sendEvent( m_part, &event );
#endif
emit m_part->nodeActivated(mev.innerNode);
}
......@@ -441,7 +449,12 @@ void KHTMLView::viewportMouseDoubleClickEvent( QMouseEvent *_mouse )
khtml::MouseDoubleClickEvent event( _mouse, xm, ym, mev.url, mev.innerNode );
event.setNodePos( mev.nodeAbsX, mev.nodeAbsY );
#ifdef _KWQ_
m_part->event (&event);
#else
QApplication::sendEvent( m_part, &event );
#endif
// ###
//if ( url.length() )
......@@ -531,7 +544,12 @@ void KHTMLView::viewportMouseMoveEvent( QMouseEvent * _mouse )
khtml::MouseMoveEvent event( _mouse, xm, ym, mev.url, mev.innerNode );
event.setNodePos( mev.nodeAbsX, mev.nodeAbsY );
#ifdef _KWQ_
m_part->event (&event);
#else
QApplication::sendEvent( m_part, &event );
#endif
}
void KHTMLView::viewportMouseReleaseEvent( QMouseEvent * _mouse )
......@@ -559,7 +577,12 @@ void KHTMLView::viewportMouseReleaseEvent( QMouseEvent * _mouse )
khtml::MouseReleaseEvent event( _mouse, xm, ym, mev.url, mev.innerNode );
event.setNodePos( mev.nodeAbsX, mev.nodeAbsY );
#ifdef _KWQ_
m_part->event (&event);
#else
QApplication::sendEvent( m_part, &event );
#endif
}
void KHTMLView::keyPressEvent( QKeyEvent *_ke )
......
......@@ -174,12 +174,6 @@ public:
virtual void drawContents ( QPainter * p, int clipx, int clipy, int clipw, int cliph );
signals:
void cleared();
protected:
void clear();
virtual void resizeEvent ( QResizeEvent * event );
virtual void showEvent ( QShowEvent * );
virtual void hideEvent ( QHideEvent *);
......@@ -214,6 +208,13 @@ protected:
*/
void doAutoScroll();
signals:
void cleared();
void clear();
protected:
protected slots:
void slotPaletteChanged();
......
......@@ -76,7 +76,10 @@ void QApplication::restoreOverrideCursor()
bool QApplication::sendEvent(QObject *o, QEvent *e)
{
// _logNotYetImplemented();
QEvent::Type type = e->type();
KWQDEBUG1 ("received %d\n", type);
return FALSE;
}
......
......@@ -64,7 +64,7 @@ public:
QEvent() {}
#endif
QEvent(Type);
QEvent( Type t ) : _type(t) {}
virtual ~QEvent();
// member functions --------------------------------------------------------
......@@ -89,7 +89,7 @@ private:
#ifdef _KWQ_PEDANTIC_
QEvent &operator=(const QEvent &);
#endif
Type _type;
}; // class QEvent =============================================================
......@@ -146,6 +146,9 @@ private:
#ifdef _KWQ_PEDANTIC_
QMouseEvent &operator=(const QMouseEvent &);
#endif
QPoint _position;
int _button; // ### Make ushort in 3.0? Here it's an int...
ushort _state; // ### ...and here an ushort. But both are ButtonState!
}; // class QMouseEvent ========================================================
......@@ -492,20 +495,11 @@ private:
class QCustomEvent : public QEvent {
public:
// typedefs ----------------------------------------------------------------
// enums -------------------------------------------------------------------
// constants ---------------------------------------------------------------
// static member functions -------------------------------------------------
// constructors, copy constructors, and destructors ------------------------
// add no-arg constructor
#ifdef _KWQ_PEDANTIC_
QCustomEvent() {}
#endif
QCustomEvent(Type);
QCustomEvent( int type );
QCustomEvent( Type type, void *data )
: QEvent(type), d(data) {};
void *data() const { return d; }
void setData( void* data ) { d = data; }
// add no-op destructor
#ifdef _KWQ_PEDANTIC_
......@@ -519,6 +513,7 @@ public:
// private ---------------------------------------------------------------------
private:
void *d;
// add copy constructor
// this private declaration prevents copying
......
......@@ -31,11 +31,6 @@ static const QPoint ORIGIN(0,0);
// class QEvent ================================================================
QEvent::QEvent(Type)
{
//_logNotYetImplemented();
}
QEvent::~QEvent()
{
......@@ -45,30 +40,25 @@ QEvent::~QEvent()
QEvent::Type QEvent::type() const
{
_logNotYetImplemented();
return MouseButtonPress;
return _type;
}
// class QMouseEvent ===========================================================
QMouseEvent::QMouseEvent(Type type, const QPoint &pos, int button, int state)
{
_logNotYetImplemented();
QMouseEvent::QMouseEvent( Type t, const QPoint &pos, int b, int s )
: QEvent(t), _position(pos), _button(b), _state((ushort)s){
}
int QMouseEvent::x()
{
_logNotYetImplemented();
return 0;
return (int)_position.x();
}
int QMouseEvent::y()
{
_logNotYetImplemented();
return 0;
return (int)_position.y();
}
......@@ -88,30 +78,25 @@ int QMouseEvent::globalY()
const QPoint &QMouseEvent::pos() const
{
_logNotYetImplemented();
// FIXME: replace this hack
return ORIGIN;
return _position;
}
Qt::ButtonState QMouseEvent::button()
{
_logNotYetImplemented();
return Qt::NoButton;
return Qt::ButtonState(_button);
}
Qt::ButtonState QMouseEvent::state()
{
_logNotYetImplemented();
return Qt::NoButton;
return Qt::ButtonState(_state);
}
Qt::ButtonState QMouseEvent::stateAfter()
{
_logNotYetImplemented();
return Qt::NoButton;
return Qt::ButtonState(_state);
}
......@@ -224,7 +209,7 @@ void QWheelEvent::ignore()
// class QCustomEvent ===========================================================
QCustomEvent::QCustomEvent(Type)
QCustomEvent::QCustomEvent( int type )
: QEvent( (QEvent::Type)type ), d( 0 )
{
_logNotYetImplemented();
}
......@@ -78,36 +78,45 @@ const float LargeNumberForText = 1.0e7;
static NSMutableDictionary *metricsCache = nil;
@implementation KWQMetricsInfo
/*
*/
@implementation KWQLayoutInfo
+ (void)drawString: (NSString *)string atPoint: (NSPoint)p withFont: (NSFont *)font color: (NSColor *)color
{
KWQMetricsInfo *metricsCache = [KWQMetricsInfo getMetricsForFont: font];
KWQLayoutInfo *metricsCache = [KWQLayoutInfo getMetricsForFont: font];
NSLayoutManager *layoutManager = [metricsCache layoutManagerForString: string];
if (layoutManager != nil){
unsigned numberOfGlyphs = [layoutManager numberOfGlyphs];
[metricsCache setColor: color];
[metricsCache setFont: font];
[KWQTextStorage setString: string attributes: attributes];
[layoutManager drawGlyphsForGlyphRange:NSMakeRange (0, numberOfGlyphs) atPoint:p];
}
}
+ (KWQMetricsInfo *)getMetricsForFont: (NSFont *)aFont
+ (KWQLayoutInfo *)getMetricsForFont: (NSFont *)aFont
{
KWQMetricsInfo *info = (KWQMetricsInfo *)[metricsCache objectForKey: aFont];
KWQLayoutInfo *info = (KWQLayoutInfo *)[metricsCache objectForKey: aFont];
if (info == nil){
info = [[KWQMetricsInfo alloc] initWithFont: aFont];
[KWQMetricsInfo setMetric: info forFont: aFont];
info = [[KWQLayoutInfo alloc] initWithFont: aFont];
[KWQLayoutInfo setMetric: info forFont: aFont];
[info release];
}
return info;
}
+ (void)setMetric: (KWQMetricsInfo *)info forFont: (NSFont *)aFont
+ (void)setMetric: (KWQLayoutInfo *)info forFont: (NSFont *)aFont
{
if (metricsCache == nil)
metricsCache = [[NSMutableDictionary alloc] init];
[metricsCache setObject: info forKey: aFont];
}
- initWithFont: (NSFont *)aFont
{
[super init];
......@@ -158,6 +167,11 @@ static NSMutableDictionary *metricsCache = nil;
[attributes setObject: color forKey: NSForegroundColorAttributeName];
}
- (void)setFont: (NSFont *)aFont
{
[attributes setObject: aFont forKey: NSFontAttributeName];
}
- (void)dealloc
{
[attributes release];
......@@ -173,7 +187,7 @@ public:
QFontMetricsPrivate(NSFont *aFont)
{
font = [aFont retain];
info = [[KWQMetricsInfo getMetricsForFont: aFont] retain];
info = [[KWQLayoutInfo getMetricsForFont: aFont] retain];
}
~QFontMetricsPrivate()
......@@ -189,7 +203,7 @@ public:
}
private:
KWQMetricsInfo *info;
KWQLayoutInfo *info;
NSFont *font;
};
......
......@@ -37,8 +37,10 @@
#include <kcharsets.h>
#include <kglobal.h>
#include <html/htmltokenizer.h>
#include <html/html_imageimpl.h>
#include <xml/dom_docimpl.h>
#include <html/html_documentimpl.h>
#include <rendering/render_image.h>
#include <loader.h>
#include <kjs.h>
#include <kjs_dom.h>
......@@ -113,10 +115,27 @@ public:
bool m_haveEncoding:1;
bool m_haveCharset:1;
bool m_onlyLocalReferences:1;
bool m_startBeforeEnd:1;
KJSProxy *m_jscript;
int m_runningScripts;
QString m_strSelectedURL;
QString m_referrer;
bool m_bMousePressed;
DOM::Node m_mousePressNode; //node under the mouse when the mouse was pressed (set in the mouse handler)
DOM::Node m_selectionStart;
long m_startOffset;
DOM::Node m_selectionEnd;
long m_endOffset;
QString m_overURL;
QPoint m_dragStartPos;
#ifdef KHTML_NO_SELECTION
QPoint m_dragLastPos;
#endif
KHTMLPartPrivate(KHTMLPart *part)
{
if (!cache_init) {
......@@ -732,6 +751,385 @@ const KHTMLSettings *KHTMLPart::settings() const
}
bool KHTMLPart::event( QEvent *event )
{
if ( khtml::MousePressEvent::test( event ) )
{
khtmlMousePressEvent( static_cast<khtml::MousePressEvent *>( event ) );
return true;
}
if ( khtml::MouseDoubleClickEvent::test( event ) )
{
khtmlMouseDoubleClickEvent( static_cast<khtml::MouseDoubleClickEvent *>( event ) );
return true;
}
if ( khtml::MouseMoveEvent::test( event ) )
{
khtmlMouseMoveEvent( static_cast<khtml::MouseMoveEvent *>( event ) );
return true;
}
if ( khtml::MouseReleaseEvent::test( event ) )
{
khtmlMouseReleaseEvent( static_cast<khtml::MouseReleaseEvent *>( event ) );
return true;
}
if ( khtml::DrawContentsEvent::test( event ) )
{
khtmlDrawContentsEvent( static_cast<khtml::DrawContentsEvent *>( event ) );
return true;
}
return false;
}
void KHTMLPart::khtmlMousePressEvent( khtml::MousePressEvent *event )
{
DOM::DOMString url = event->url();
QMouseEvent *_mouse = event->qmouseEvent();
DOM::Node innerNode = event->innerNode();
d->m_mousePressNode = innerNode;
d->m_dragStartPos = _mouse->pos();
if ( event->url() != 0 )
d->m_strSelectedURL = event->url().string();
else
d->m_strSelectedURL = QString::null;
if ( _mouse->button() == LeftButton ||
_mouse->button() == MidButton )
{
d->m_bMousePressed = true;
#ifndef KHTML_NO_SELECTION
if ( _mouse->button() == LeftButton )
{
if ( !innerNode.isNull() )
{
int offset;
DOM::Node node;
innerNode.handle()->findSelectionNode( event->x(), event->y(),
event->nodeAbsX(), event->nodeAbsY(),
node, offset );
if ( node.isNull() || !node.handle() )
{
//kdDebug( 6000 ) << "Hmm, findSelectionNode returned no node" << endl;
d->m_selectionStart = innerNode;
d->m_startOffset = 0; //?
} else {
d->m_selectionStart = node;
d->m_startOffset = offset;
}
//kdDebug(6005) << "KHTMLPart::khtmlMousePressEvent selectionStart=" << d->m_selectionStart.handle()->renderer()
// << " offset=" << d->m_startOffset << endl;
d->m_selectionEnd = d->m_selectionStart;
d->m_endOffset = d->m_startOffset;
d->m_doc->clearSelection();
}
else
{
d->m_selectionStart = DOM::Node();
d->m_selectionEnd = DOM::Node();
}
//emitSelectionChanged();
//startAutoScroll();
}
#else
d->m_dragLastPos = _mouse->globalPos();
#endif
}
if ( _mouse->button() == RightButton )
{
//popupMenu( splitUrlTarget(d->m_strSelectedURL) );
d->m_strSelectedURL = QString::null;
}
}
void KHTMLPart::khtmlMouseDoubleClickEvent( khtml::MouseDoubleClickEvent * )
{
}
static QString splitUrlTarget(const QString &url, QString *target=0)
{
QString result = url;
if(url.left(7) == "target:")
{
KURL u(url);
result = u.ref();
if (target)
*target = u.host();
}
return result;
}
void KHTMLPart::khtmlMouseMoveEvent( khtml::MouseMoveEvent *event )
{
QMouseEvent *_mouse = event->qmouseEvent();
DOM::DOMString url = event->url();
DOM::Node innerNode = event->innerNode();
#define QT_NO_DRAGANDDROP 1
#ifndef QT_NO_DRAGANDDROP
if( d->m_bMousePressed && (!d->m_strSelectedURL.isEmpty() || (!innerNode.isNull() && innerNode.elementId() == ID_IMG) ) &&
( d->m_dragStartPos - _mouse->pos() ).manhattanLength() > KGlobalSettings::dndEventDelay() &&
d->m_bDnd && d->m_mousePressNode == innerNode ) {
QPixmap p;
QDragObject *drag = 0;
if( !d->m_strSelectedURL.isEmpty() ) {
KURL u( completeURL( splitUrlTarget(d->m_strSelectedURL)) );
KURL::List uris;
uris.append(u);
drag = KURLDrag::newDrag( uris, d->m_view->viewport() );
p = KMimeType::pixmapForURL(u, 0, KIcon::SizeMedium);
} else {
HTMLImageElementImpl *i = static_cast<HTMLImageElementImpl *>(innerNode.handle());
if( i ) {
drag = new QImageDrag( i->currentImage() , d->m_view->viewport() );
p = KMimeType::mimeType("image/*")->pixmap(KIcon::Desktop);
}
}
if ( !p.isNull() )
drag->setPixmap(p);
stopAutoScroll();
if(drag)
drag->drag();
// when we finish our drag, we need to undo our mouse press
d->m_bMousePressed = false;
d->m_strSelectedURL = "";
return;
}
#endif
QString target;
QString surl = splitUrlTarget(url.string(), &target);
// Not clicked -> mouse over stuff
if ( !d->m_bMousePressed )
{
// The mouse is over something
if ( url.length() )
{
bool shiftPressed = ( _mouse->state() & ShiftButton );
// Image map
if ( !innerNode.isNull() && innerNode.elementId() == ID_IMG )
{
HTMLImageElementImpl *i = static_cast<HTMLImageElementImpl *>(innerNode.handle());
if ( i && i->isServerMap() )
{
khtml::RenderImage *r = static_cast<khtml::RenderImage *>(i->renderer());
if(r)
{
int absx, absy, vx, vy;
r->absolutePosition(absx, absy);
//view()->contentsToViewport( absx, absy, vx, vy );
int x(_mouse->x() - vx), y(_mouse->y() - vy);
d->m_overURL = surl + QString("?%1,%2").arg(x).arg(y);
//overURL( d->m_overURL, target, shiftPressed );
return;
}
}
}
// normal link
QString target;
QString surl = splitUrlTarget(url.string(), &target);
if ( d->m_overURL.isEmpty() || d->m_overURL != surl )
{
d->m_overURL = surl;
//overURL( d->m_overURL, target, shiftPressed );
}
}
else // Not over a link...
{
if( !d->m_overURL.isEmpty() ) // and we were over a link -> reset to "default statusbar text"
{
d->m_overURL = QString::null;
//emit onURL( QString::null );
// Default statusbar text can be set from javascript. Otherwise it's empty.
//emit setStatusBarText( d->m_kjsDefaultStatusBarText );
}
}
}
else {
#ifndef KHTML_NO_SELECTION
// selection stuff
if( d->m_bMousePressed && !innerNode.isNull() && ( _mouse->state() == LeftButton )) {
int offset;
DOM::Node node;
//kdDebug(6000) << "KHTMLPart::khtmlMouseMoveEvent x=" << event->x() << " y=" << event->y()
// << " nodeAbsX=" << event->nodeAbsX() << " nodeAbsY=" << event->nodeAbsY()
// << endl;
innerNode.handle()->findSelectionNode( event->x(), event->y(),
event->nodeAbsX(), event->nodeAbsY(),
node, offset );
// When this stuff is finished, this should never happen.
// But currently....
if ( node.isNull() || !node.handle() )
{
//kdWarning( 6000 ) << "findSelectionNode returned no node" << endl;
d->m_selectionEnd = innerNode;
d->m_endOffset = 0; //?
}
else
{
d->m_selectionEnd = node;
d->m_endOffset = offset;
}
//kdDebug( 6000 ) << "setting end of selection to " << d->m_selectionEnd.handle()->renderer() << "/"
// << d->m_endOffset << endl;
// we have to get to know if end is before start or not...
DOM::Node n = d->m_selectionStart;
d->m_startBeforeEnd = false;
while(!n.isNull()) {
if(n == d->m_selectionEnd) {
d->m_startBeforeEnd = true;
break;
}
DOM::Node next = n.firstChild();
if(next.isNull()) next = n.nextSibling();
while( next.isNull() && !n.parentNode().isNull() ) {
n = n.parentNode();
next = n.nextSibling();
}
n = next;