📄 html_imageimpl.cpp
字号:
/** * This file is part of the DOM implementation for KDE. * * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */#include "html/html_imageimpl.h"#include "html/html_formimpl.h"#include "html/html_documentimpl.h"#include "misc/htmlhashes.h"#include "khtmlview.h"#include "khtml_part.h"#include <kstringhandler.h>#include <kglobal.h>#include <kdebug.h>#include "rendering/render_image.h"#include "rendering/render_flow.h"#include "css/cssstyleselector.h"#include "css/cssproperties.h"#include "css/cssvalues.h"#include "css/csshelper.h"#include "xml/dom2_eventsimpl.h"#include <qstring.h>#include <qpoint.h>#include <qregion.h>#include <qptrstack.h>#include <qimage.h>#include <qpointarray.h>using namespace DOM;using namespace khtml;// -------------------------------------------------------------------------HTMLImageElementImpl::HTMLImageElementImpl(DocumentPtr *doc, HTMLFormElementImpl *f) : HTMLElementImpl(doc), ismap(false), loadEventSent(true), m_image(0), m_form(f){ if (m_form) m_form->registerImgElement(this);}HTMLImageElementImpl::~HTMLImageElementImpl(){ if (getDocument()) getDocument()->removeImage(this); if (m_image) m_image->deref(this); if (m_form) m_form->removeImgElement(this);}NodeImpl::Id HTMLImageElementImpl::id() const{ return ID_IMG;}void HTMLImageElementImpl::parseAttribute(AttributeImpl *attr){ switch (attr->id()) { case ATTR_ALT: setChanged(); break; case ATTR_SRC: { setChanged(); //Start loading the image already, to generate events DOMString url = attr->value(); if (!url.isEmpty()) { //### why do we not hide or something when setting this? CachedImage* newImage = getDocument()->docLoader()->requestImage(khtml::parseURL(url)); if (newImage && newImage != m_image) { loadEventSent = false; if (m_image) m_image->deref(this); m_image = newImage; m_image->ref(this); } } } break; case ATTR_WIDTH: if (!attr->value().isEmpty()) addCSSLength(CSS_PROP_WIDTH, attr->value()); else removeCSSProperty(CSS_PROP_WIDTH); break; case ATTR_HEIGHT: if (!attr->value().isEmpty()) addCSSLength(CSS_PROP_HEIGHT, attr->value()); else removeCSSProperty(CSS_PROP_HEIGHT); break; case ATTR_BORDER: // border="noborder" -> border="0" if(attr->value().toInt()) { addCSSLength(CSS_PROP_BORDER_WIDTH, attr->value()); addCSSProperty( CSS_PROP_BORDER_TOP_STYLE, CSS_VAL_SOLID ); addCSSProperty( CSS_PROP_BORDER_RIGHT_STYLE, CSS_VAL_SOLID ); addCSSProperty( CSS_PROP_BORDER_BOTTOM_STYLE, CSS_VAL_SOLID ); addCSSProperty( CSS_PROP_BORDER_LEFT_STYLE, CSS_VAL_SOLID ); } else { removeCSSProperty( CSS_PROP_BORDER_WIDTH ); removeCSSProperty( CSS_PROP_BORDER_TOP_STYLE ); removeCSSProperty( CSS_PROP_BORDER_RIGHT_STYLE ); removeCSSProperty( CSS_PROP_BORDER_BOTTOM_STYLE ); removeCSSProperty( CSS_PROP_BORDER_LEFT_STYLE ); } break; case ATTR_VSPACE: addCSSLength(CSS_PROP_MARGIN_TOP, attr->value()); addCSSLength(CSS_PROP_MARGIN_BOTTOM, attr->value()); break; case ATTR_HSPACE: addCSSLength(CSS_PROP_MARGIN_LEFT, attr->value()); addCSSLength(CSS_PROP_MARGIN_RIGHT, attr->value()); break; case ATTR_ALIGN: addHTMLAlignment( attr->value() ); break; case ATTR_VALIGN: addCSSProperty(CSS_PROP_VERTICAL_ALIGN, attr->value().lower()); break; case ATTR_USEMAP: if ( attr->value()[0] == '#' ) usemap = attr->value(); else { QString url = getDocument()->completeURL( khtml::parseURL( attr->value() ).string() ); // ### we remove the part before the anchor and hope // the map is on the same html page.... usemap = url; } m_hasAnchor = attr->val() != 0; case ATTR_ISMAP: ismap = true; break; case ATTR_ONABORT: // ### add support for this setHTMLEventListener(EventImpl::ABORT_EVENT, getDocument()->createHTMLEventListener(attr->value().string(), "onabort", this)); break; case ATTR_ONERROR: setHTMLEventListener(EventImpl::ERROR_EVENT, getDocument()->createHTMLEventListener(attr->value().string(), "onerror", this)); break; case ATTR_ONLOAD: setHTMLEventListener(EventImpl::LOAD_EVENT, getDocument()->createHTMLEventListener(attr->value().string(), "onload", this)); break; case ATTR_NOSAVE: break; case ATTR_NAME: if (inDocument() && m_name != attr->value()) { getDocument()->underDocNamedCache().remove(m_name.string(), this); getDocument()->underDocNamedCache().add (attr->value().string(), this); } m_name = attr->value(); //fallthrough default: HTMLElementImpl::parseAttribute(attr); }}void HTMLImageElementImpl::notifyFinished(CachedObject *finishedObj){ if (m_image == finishedObj) { getDocument()->dispatchImageLoadEventSoon(this); }}void HTMLImageElementImpl::dispatchLoadEvent(){ if (!loadEventSent) { loadEventSent = true; if (m_image->isErrorImage()) { dispatchHTMLEvent(EventImpl::ERROR_EVENT, false, false); } else { dispatchHTMLEvent(EventImpl::LOAD_EVENT, false, false); } }}DOMString HTMLImageElementImpl::altText() const{ // lets figure out the alt text.. magic stuff // http://www.w3.org/TR/1998/REC-html40-19980424/appendix/notes.html#altgen // also heavily discussed by Hixie on bugzilla DOMString alt( getAttribute( ATTR_ALT ) ); // fall back to title attribute if ( alt.isNull() ) alt = getAttribute( ATTR_TITLE );#if 0 if ( alt.isNull() ) { QString p = KURL( getDocument()->completeURL( getAttribute(ATTR_SRC).string() ) ).prettyURL(); int pos; if ( ( pos = p.findRev( '.' ) ) > 0 ) p.truncate( pos ); alt = DOMString( KStringHandler::csqueeze( p ) ); }#endif return alt;}void HTMLImageElementImpl::attach(){ assert(!attached()); assert(!m_render); assert(parentNode()); RenderStyle* _style = getDocument()->styleSelector()->styleForElement(this); _style->ref(); if (parentNode()->renderer() && parentNode()->renderer()->childAllowed() && _style->display() != NONE) { m_render = new (getDocument()->renderArena()) RenderImage(this); m_render->setStyle(_style); parentNode()->renderer()->addChild(m_render, nextRenderer()); } _style->deref(); NodeBaseImpl::attach(); if (m_render) m_render->updateFromElement();}void HTMLImageElementImpl::removedFromDocument(){ getDocument()->underDocNamedCache().remove(m_name.string(), this); HTMLElementImpl::removedFromDocument();}void HTMLImageElementImpl::insertedIntoDocument(){ getDocument()->underDocNamedCache().add(m_name.string(), this); HTMLElementImpl::insertedIntoDocument();}void HTMLImageElementImpl::removeId(const QString& id){ getDocument()->underDocNamedCache().remove(id, this); HTMLElementImpl::removeId(id);}void HTMLImageElementImpl::addId (const QString& id){ getDocument()->underDocNamedCache().add(id, this); HTMLElementImpl::addId(id);}long HTMLImageElementImpl::width() const{ if (!m_render) { DOMString widthAttr = getAttribute(ATTR_WIDTH); if (!widthAttr.isNull()) return widthAttr.toInt();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -