html_inlineimpl.cpp [plain text]
#include "html/html_inlineimpl.h"
#include "html/html_imageimpl.h"
#include "html/html_documentimpl.h"
#include "misc/htmlhashes.h"
#include "khtmlview.h"
#include "khtml_part.h"
#include "css/csshelper.h"
#include "css/cssproperties.h"
#include "css/cssvalues.h"
#include "css/cssstyleselector.h"
#include "xml/dom2_eventsimpl.h"
#include "rendering/render_br.h"
#include "rendering/render_image.h"
#include <kdebug.h>
using namespace khtml;
using namespace DOM;
HTMLAnchorElementImpl::HTMLAnchorElementImpl(DocumentPtr *doc)
: HTMLElementImpl(doc)
{
m_hasTarget = false;
}
HTMLAnchorElementImpl::~HTMLAnchorElementImpl()
{
}
bool HTMLAnchorElementImpl::isFocusable() const
{
if (isContentEditable())
return HTMLElementImpl::isFocusable();
if (!(m_hasAnchor && m_render && m_render->style()->visibility() == VISIBLE))
return false;
for (RenderObject *r = m_render; r; r = r->continuation()) {
if (r->width() > 0 && r->height() > 0)
return true;
}
QValueList<QRect> rects;
int x = 0, y = 0;
m_render->absolutePosition(x, y);
m_render->absoluteRects(rects, x, y);
for (QValueList<QRect>::ConstIterator it = rects.begin(); it != rects.end(); ++it) {
if ((*it).isValid())
return true;
}
return false;
}
bool HTMLAnchorElementImpl::isMouseFocusable() const
{
#if APPLE_CHANGES
return false;
#else
return isFocusable();
#endif
}
bool HTMLAnchorElementImpl::isKeyboardFocusable() const
{
if (!isFocusable())
return false;
if (!getDocument()->part())
return false;
return getDocument()->part()->tabsToLinks();
}
NodeImpl::Id HTMLAnchorElementImpl::id() const
{
return ID_A;
}
void HTMLAnchorElementImpl::defaultEventHandler(EventImpl *evt)
{
if ( ( evt->id() == EventImpl::KHTML_CLICK_EVENT ||
( evt->id() == EventImpl::KEYDOWN_EVENT && m_focused)) && m_hasAnchor) {
MouseEventImpl *e = 0;
if ( evt->id() == EventImpl::KHTML_CLICK_EVENT )
e = static_cast<MouseEventImpl*>( evt );
KeyboardEventImpl *k = 0;
if (evt->id() == EventImpl::KEYDOWN_EVENT)
k = static_cast<KeyboardEventImpl *>( evt );
QString utarget;
QString url;
if ( e && e->button() == 2 ) {
HTMLElementImpl::defaultEventHandler(evt);
return;
}
if ( k ) {
if (k->keyIdentifier() != "Enter") {
HTMLElementImpl::defaultEventHandler(evt);
return;
}
if (k->qKeyEvent()) {
k->qKeyEvent()->accept();
evt->setDefaultHandled();
click(false);
return;
}
}
url = khtml::parseURL(getAttribute(ATTR_HREF)).string();
utarget = getAttribute(ATTR_TARGET).string();
if ( e && e->button() == 1 )
utarget = "_blank";
if ( evt->target()->id() == ID_IMG ) {
HTMLImageElementImpl* img = static_cast<HTMLImageElementImpl*>( evt->target() );
if ( img && img->isServerMap() )
{
khtml::RenderImage *r = static_cast<khtml::RenderImage *>(img->renderer());
if(r && e)
{
int absx, absy;
r->absolutePosition(absx, absy);
int x(e->clientX() - absx), y(e->clientY() - absy);
url += QString("?%1,%2").arg( x ).arg( y );
}
else {
evt->setDefaultHandled();
HTMLElementImpl::defaultEventHandler(evt);
return;
}
}
}
if ( !evt->defaultPrevented() ) {
int state = 0;
int button = 0;
if ( e ) {
if ( e->ctrlKey() )
state |= Qt::ControlButton;
if ( e->shiftKey() )
state |= Qt::ShiftButton;
if ( e->altKey() )
state |= Qt::AltButton;
if ( e->metaKey() )
state |= Qt::MetaButton;
if ( e->button() == 0 )
button = Qt::LeftButton;
else if ( e->button() == 1 )
button = Qt::MidButton;
else if ( e->button() == 2 )
button = Qt::RightButton;
}
else if ( k )
{
if ( k->shiftKey() )
state |= Qt::ShiftButton;
if ( k->altKey() )
state |= Qt::AltButton;
if ( k->ctrlKey() )
state |= Qt::ControlButton;
}
if (getDocument() && getDocument()->view() && getDocument()->part()) {
getDocument()->view()->resetCursor();
getDocument()->part()->
urlSelected( url, button, state, utarget );
}
}
evt->setDefaultHandled();
}
HTMLElementImpl::defaultEventHandler(evt);
}
void HTMLAnchorElementImpl::parseHTMLAttribute(HTMLAttributeImpl *attr)
{
switch(attr->id())
{
case ATTR_HREF:
m_hasAnchor = !attr->isNull();
break;
case ATTR_TARGET:
m_hasTarget = !attr->isNull();
break;
case ATTR_NAME:
case ATTR_TITLE:
case ATTR_REL:
break;
default:
HTMLElementImpl::parseHTMLAttribute(attr);
}
}
void HTMLAnchorElementImpl::accessKeyAction(bool sendToAnyElement)
{
click(sendToAnyElement);
}
bool HTMLAnchorElementImpl::isURLAttribute(AttributeImpl *attr) const
{
return attr->id() == ATTR_HREF;
}
HTMLBRElementImpl::HTMLBRElementImpl(DocumentPtr *doc) : HTMLElementImpl(doc)
{
}
HTMLBRElementImpl::~HTMLBRElementImpl()
{
}
NodeImpl::Id HTMLBRElementImpl::id() const
{
return ID_BR;
}
bool HTMLBRElementImpl::mapToEntry(NodeImpl::Id attr, MappedAttributeEntry& result) const
{
if (attr == ATTR_CLEAR) {
result = eUniversal;
return false;
}
return HTMLElementImpl::mapToEntry(attr, result);
}
void HTMLBRElementImpl::parseHTMLAttribute(HTMLAttributeImpl *attr)
{
switch (attr->id())
{
case ATTR_CLEAR:
{
DOMString str = attr->value();
if (!str.isEmpty()) {
if (strcasecmp(str,"all") == 0)
str = "both";
addCSSProperty(attr, CSS_PROP_CLEAR, str);
}
break;
}
default:
HTMLElementImpl::parseHTMLAttribute(attr);
}
}
RenderObject *HTMLBRElementImpl::createRenderer(RenderArena *arena, RenderStyle *style)
{
return new (arena) RenderBR(this);
}
HTMLFontElementImpl::HTMLFontElementImpl(DocumentPtr *doc)
: HTMLElementImpl(doc)
{
}
HTMLFontElementImpl::~HTMLFontElementImpl()
{
}
NodeImpl::Id HTMLFontElementImpl::id() const
{
return ID_FONT;
}
static bool parseFontSizeNumber(const DOMString &s, int &size)
{
unsigned pos = 0;
while (pos < s.length() && s[pos].isSpace())
++pos;
bool sawPlus = false;
bool sawMinus = false;
if (pos < s.length() && s[pos] == '+') {
++pos;
sawPlus = true;
} else if (pos < s.length() && s[pos] == '-') {
++pos;
sawMinus = true;
}
if (pos >= s.length() || !s[pos].isNumber())
return false;
int num = s[pos++].digitValue();
if (pos < s.length() && s[pos].isNumber())
num = 10;
if (sawPlus) {
size = num + 3;
return true;
}
if (sawMinus) {
size = num == 1 ? 2 : 1;
return true;
}
size = num;
return true;
}
bool HTMLFontElementImpl::mapToEntry(NodeImpl::Id attr, MappedAttributeEntry& result) const
{
switch(attr)
{
case ATTR_SIZE:
case ATTR_COLOR:
case ATTR_FACE:
result = eUniversal;
return false;
default:
break;
}
return HTMLElementImpl::mapToEntry(attr, result);
}
void HTMLFontElementImpl::parseHTMLAttribute(HTMLAttributeImpl *attr)
{
switch(attr->id())
{
case ATTR_SIZE:
{
int num;
if (parseFontSizeNumber(attr->value(), num)) {
int size;
switch (num)
{
case 2: size = CSS_VAL_SMALL; break;
case 0: case 3: size = CSS_VAL_MEDIUM; break;
case 4: size = CSS_VAL_LARGE; break;
case 5: size = CSS_VAL_X_LARGE; break;
case 6: size = CSS_VAL_XX_LARGE; break;
default:
if (num > 6)
size = CSS_VAL__KHTML_XXX_LARGE;
else
size = CSS_VAL_X_SMALL;
}
addCSSProperty(attr, CSS_PROP_FONT_SIZE, size);
}
break;
}
case ATTR_COLOR:
addHTMLColor(attr, CSS_PROP_COLOR, attr->value());
break;
case ATTR_FACE:
addCSSProperty(attr, CSS_PROP_FONT_FAMILY, attr->value());
break;
default:
HTMLElementImpl::parseHTMLAttribute(attr);
}
}