html_inlineimpl.cpp Source File (khtml Library)

| # khtml Library API Documentation
Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Source Files

# html_inlineimpl.cpp

    00001
    00023 // -------------------------------------------------------------------------
    00024
    00025 #include "html/html_inlineimpl.h"
    00026 #include "html/html_imageimpl.h"
    00027 #include "html/html_documentimpl.h"
    00028
    00029 #include "misc/htmlhashes.h"
    00030 #include "khtmlview.h"
    00031 #include "khtml_part.h"
    00032 #include "css/csshelper.h"
    00033 #include "css/cssproperties.h"
    00034 #include "css/cssvalues.h"
    00035 #include "css/cssstyleselector.h"
    00036 #include "xml/dom2_eventsimpl.h"
    00037 #include "rendering/render_br.h"
    00038 #include "rendering/render_image.h"
    00039
    00040 #include <kdebug.h>
    00041
    00042 using namespace khtml;
    00043 using namespace DOM;
    00044
    00045 NodeImpl::Id HTMLAnchorElementImpl::id() const
    00046 {
    00047     return ID_A;
    00048 }
    00049
    00050 void HTMLAnchorElementImpl::defaultEventHandler(EventImpl *evt)
    00051 {
    00052     bool keydown = evt->id() == EventImpl::KHTML_KEYPRESS_EVENT ||
    00053                    evt->id() == EventImpl::KHTML_KEYDOWN_EVENT;
    00054
    00055     // React on clicks and on keypresses.
    00056     // Don't make this KEYUP_EVENT again, it makes khtml follow links
    00057     // it shouldn't, when pressing Enter in the combo.
    00058     if ( ( (evt->id() == EventImpl::CLICK_EVENT && static_cast<MouseEventImpl*>(evt)->detail() == 1) ||
    00059          ( keydown && m_focused)) && m_hasAnchor) {
    00060
    00061         MouseEventImpl *e = 0;
    00062         if ( evt->id() == EventImpl::CLICK_EVENT )
    00063             e = static_cast<MouseEventImpl*>( evt );
    00064
    00065         TextEventImpl *k = 0;
    00066         if (keydown)
    00067             k = static_cast<TextEventImpl *>( evt );
    00068
    00069         QString utarget;
    00070         QString url;
    00071         if ( e && e->button() == 2 ) {
    00072             HTMLElementImpl::defaultEventHandler(evt);
    00073             return;
    00074         }
    00075
    00076         if ( k ) {
    00077             if (k->virtKeyVal() != TextEventImpl::DOM_VK_ENTER) {
    00078                 if (k->qKeyEvent)
    00079                     k->qKeyEvent->ignore();
    00080                 HTMLElementImpl::defaultEventHandler(evt);
    00081                 return;
    00082             }
    00083             if (k->qKeyEvent) k->qKeyEvent->accept();
    00084         }
    00085
    00086         url = khtml::parseURL(getAttribute(ATTR_HREF)).string();
    00087
    00088         utarget = getAttribute(ATTR_TARGET).string();
    00089
    00090         if ( e && e->button() == 1 )
    00091             utarget = "_blank";
    00092
    00093         if ( evt->target()->id() == ID_IMG ) {
    00094             HTMLImageElementImpl* img = static_cast<HTMLImageElementImpl*>( evt->target() );
    00095             if ( img && img->isServerMap() )
    00096             {
    00097                 khtml::RenderImage *r = static_cast<khtml::RenderImage *>(img->renderer());
    00098                 if(r && e)
    00099                 {
    00100                     int absx, absy;
    00101                     r->absolutePosition(absx, absy);
    00102                     int x(e->clientX() - absx), y(e->clientY() - absy);
    00103                     url += QString("?%1,%2").arg( x ).arg( y );
    00104                 }
    00105                 else {
    00106                     evt->setDefaultHandled();
    00107                     HTMLElementImpl::defaultEventHandler(evt);
    00108                     return;
    00109                 }
    00110             }
    00111         }
    00112         if ( !evt->defaultPrevented() ) {
    00113             int state = 0;
    00114             int button = 0;
    00115
    00116             if ( e ) {
    00117                 if ( e->ctrlKey() )
    00118                     state |= Qt::ControlButton;
    00119                 if ( e->shiftKey() )
    00120                     state |= Qt::ShiftButton;
    00121                 if ( e->altKey() )
    00122                     state |= Qt::AltButton;
    00123                 if (  e->metaKey() )
    00124                     state |= Qt::MetaButton;
    00125
    00126                 if ( e->button() == 0 )
    00127                     button = Qt::LeftButton;
    00128                 else if ( e->button() == 1 )
    00129                     button = Qt::MidButton;
    00130                 else if ( e->button() == 2 )
    00131                     button = Qt::RightButton;
    00132             }
    00133             else if ( k )
    00134             {
    00135               if ( k->checkModifier(Qt::ShiftButton) )
    00136                 state |= Qt::ShiftButton;
    00137               if ( k->checkModifier(Qt::AltButton) )
    00138                 state |= Qt::AltButton;
    00139               if ( k->checkModifier(Qt::ControlButton) )
    00140                 state |= Qt::ControlButton;
    00141             }
    00142
    00143             getDocument()->view()->part()->
    00144                 urlSelected( url, button, state, utarget );
    00145         }
    00146         evt->setDefaultHandled();
    00147     }
    00148     HTMLElementImpl::defaultEventHandler(evt);
    00149 }
    00150
    00151
    00152 void HTMLAnchorElementImpl::parseAttribute(AttributeImpl *attr)
    00153 {
    00154     switch(attr->id())
    00155     {
    00156     case ATTR_HREF:
    00157         m_hasAnchor = attr->val() != 0;
    00158         break;
    00159     case ATTR_TARGET:
    00160         m_hasTarget = attr->val() != 0;
    00161         break;
    00162     case ATTR_NAME:
    00163     case ATTR_TITLE:
    00164     case ATTR_REL:
    00165         break;
    00166     default:
    00167         HTMLElementImpl::parseAttribute(attr);
    00168     }
    00169 }
    00170
    00171 // -------------------------------------------------------------------------
    00172
    00173 NodeImpl::Id HTMLBRElementImpl::id() const
    00174 {
    00175     return ID_BR;
    00176 }
    00177
    00178 void HTMLBRElementImpl::parseAttribute(AttributeImpl *attr)
    00179 {
    00180     switch(attr->id())
    00181     {
    00182     case ATTR_CLEAR:
    00183     {
    00184         DOMString str = attr->value();
    00185         if( str.isEmpty() ) str = "none";
    00186         else if( strcasecmp (str,"all")==0 ) str = "both";
    00187         addCSSProperty(CSS_PROP_CLEAR, str);
    00188         break;
    00189     }
    00190     default:
    00191         HTMLElementImpl::parseAttribute(attr);
    00192     }
    00193 }
    00194
    00195 void HTMLBRElementImpl::attach()
    00196 {
    00197     assert(!attached());
    00198     assert(!m_render);
    00199     assert(parentNode());
    00200
    00201     if (parentNode()->renderer()) {
    00202         RenderStyle* style = getDocument()->styleSelector()->styleForElement(  this );
    00203         style->ref();
    00204         if(  style->display() != NONE ) {
    00205           m_render = new RenderBR( this );
    00206           m_render->setStyle( style );
    00207           parentNode()->renderer()->addChild( m_render, nextRenderer() );
    00208         }
    00209         style->deref();
    00210     }
    00211     NodeImpl::attach();
    00212 }
    00213
    00214 // -------------------------------------------------------------------------
    00215
    00216 NodeImpl::Id HTMLFontElementImpl::id() const
    00217 {
    00218     return ID_FONT;
    00219 }
    00220
    00221 void HTMLFontElementImpl::parseAttribute(AttributeImpl *attr)
    00222 {
    00223     switch(attr->id())
    00224     {
    00225     case ATTR_SIZE:
    00226     {
    00227         DOMString s = attr->value();
    00228         if(!s.isNull()) {
    00229             int num = s.toInt();
    00230             if ( *s.unicode() == '+' || *s.unicode() == '-' ) {
    00231                 num += 3;
    00232             }
    00233             int size = 0;
    00234             switch (num)
    00235             {
    00236             case 1: size = CSS_VAL_X_SMALL; break;
    00237             case 2: size = CSS_VAL_SMALL;   break;
    00238             case 3: size = CSS_VAL_MEDIUM;  break;
    00239             case 4: size = CSS_VAL_LARGE;   break;
    00240             case 5: size = CSS_VAL_X_LARGE; break;
    00241             case 6: size = CSS_VAL_XX_LARGE;break;
    00242             default:
    00243                 if (num >= 6)
    00244                     size = CSS_VAL__KONQ_XXX_LARGE;
    00245                 else if (num < 1)
    00246                     size = CSS_VAL_XX_SMALL;
    00247             }
    00248             if ( size )
    00249                 addCSSProperty(CSS_PROP_FONT_SIZE, size);
    00250         }
    00251         break;
    00252     }
    00253     case ATTR_COLOR:
    00254         addCSSProperty(CSS_PROP_COLOR, attr->value());
    00255         // HTML4 compatibility hack
    00256         addCSSProperty(CSS_PROP_TEXT_DECORATION_COLOR, attr->value());
    00257         break;
    00258     case ATTR_FACE:
    00259         addCSSProperty(CSS_PROP_FONT_FAMILY, attr->value());
    00260         break;
    00261     default:
    00262         HTMLElementImpl::parseAttribute(attr);
    00263     }
    00264 }
    00265
    00266

This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Jan 28 13:33:55 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001