Commit d1d2586f authored by Dirk Mueller's avatar Dirk Mueller

first step of an API cleanup in khtml.

- moved internal methods to the private section in KHTMLPart
- merging methods with similiar argument list
- some const fixes etc.
- removed deprecated/outdated methods, added compatibility methods
  (inline) for commonly used ones.
- fix baseURL mess for real (move the handling to DocumentImpl)
- fix empty path on http-servered documents
- added "destruction mode" to khtml. when unloading a webpage, do no
  longer recalculate the stylesheet or apply global dynamic changes.
- fix handling of relative stylesheet-urls

svn path=/trunk/kdelibs/; revision=109953
parent ff266d61
......@@ -105,7 +105,7 @@ DOMString StyleBaseImpl::baseURL()
DocumentImpl *doc = static_cast<DocumentImpl*>(sheet->ownerNode()->nodeType() == Node::DOCUMENT_NODE ? sheet->ownerNode() : sheet->ownerNode()->ownerDocument());
return doc->view()->part()->baseURL().url();
return doc->baseURL();
}
/*
......
......@@ -96,11 +96,7 @@ CSSStyleSelector::CSSStyleSelector(DocumentImpl * doc)
//kdDebug( 6080 ) << "number of style sheets in document " << authorStyleSheets.count() << endl;
//kdDebug( 6080 ) << "CSSStyleSelector: author style has " << authorStyle->count() << " elements"<< endl;
KURL u;
if ( doc->view() )
u = doc->view()->part()->completeURL( doc->URL().string() );
else
u = doc->URL().string();
KURL u = doc->url();
u.setQuery( QString::null );
u.setRef( QString::null );
......
......@@ -116,6 +116,12 @@ DOMString HTMLDocument::referrer() const
return ((HTMLDocumentImpl *)impl)->referrer();
}
DOMString HTMLDocument::completeURL(const DOMString& str) const
{
if(!impl) return str;
return ((HTMLDocumentImpl *)impl)->completeURL(str.string());
}
DOMString HTMLDocument::domain() const
{
if(!impl) return DOMString();
......@@ -125,7 +131,7 @@ DOMString HTMLDocument::domain() const
DOMString HTMLDocument::URL() const
{
if(!impl) return DOMString();
return ((HTMLDocumentImpl *)impl)->URL();
return ((HTMLDocumentImpl *)impl)->url();
}
HTMLElement HTMLDocument::body() const
......
......@@ -283,6 +283,15 @@ public:
*
*/
NodeList getElementsByName ( const DOMString &elementName );
/**
* not part of the DOM
*
* converts the given (potentially relative) URL in a
* full-qualified one, using the baseURL / document URL for
* the missing parts.
*/
DOMString completeURL( const DOMString& url) const;
};
}; //namespace
......
......@@ -251,7 +251,7 @@ KJSO KJS::HTMLDocument::tryGet(const UString &p) const
else if (p == "bgColor")
return String(body.bgColor());
else if (p == "fgColor")
return String(body.text());
return String(body.text());
else if (p == "alinkColor")
return String(body.aLink());
else if (p == "linkColor")
......@@ -260,9 +260,9 @@ KJSO KJS::HTMLDocument::tryGet(const UString &p) const
return String(body.vLink());
// potentially obsolete properties
// else if (p == "embeds")
// return Undefined();
// return Undefined();
// else if (p == "ids")
// return Undefined();
// return Undefined();
// else if (p == "lastModified")
// return Undefined();
else if (p == "height")
......@@ -1197,7 +1197,7 @@ void KJS::HTMLElement::tryPut(const UString &p, const KJSO& v)
if (p == "name") { form.setName(str); return; }
else if (p == "acceptCharset") { form.setAcceptCharset(str); return; }
else if (p == "action") {
form.setAction(Window::retrieveActive()->part()->completeURL( str.string() ).url());
form.setAction(str.string());
return;
}
else if (p == "enctype") { form.setEnctype(str); return; }
......
......@@ -384,11 +384,13 @@ KJSO Window::get(const UString &p) const
else if (p == "frames")
return KJSO(frames ? frames :
(const_cast<Window*>(this)->frames = new FrameArray(m_part)));
else if (p == "history")
else if (p == "history") {
return KJSO(history ? history :
(const_cast<Window*>(this)->history = new History(m_part)));
// else if (p == "event")
// return getDOMEvent(static_cast<DOM::Event>(m_part->view()->lastDOMMouseEvent()));
}
else if (p == "innerHeight")
return Number(m_part->view()->visibleHeight());
else if (p == "innerWidth")
......@@ -667,8 +669,10 @@ void Window::put(const UString &p, const KJSO &v)
}
else if (p == "location") {
QString str = v.toString().value().qstring();
m_part->scheduleRedirection(0, Window::retrieveActive()->m_part->
completeURL(str).url().prepend( "target://_self/#" ));
KHTMLPart* p = Window::retrieveActive()->m_part;
if ( p )
m_part->scheduleRedirection(0, p->htmlDocument().
completeURL(str).string().prepend( "target://_self/#" ));
}
else if (p == "onabort") {
if (isSafeScript())
......@@ -959,13 +963,8 @@ Completion WindowFunc::tryExecute(const List &args)
}
// prepare arguments
KURL url;
if (!str.isEmpty()) {
if (part->baseURL().isEmpty())
url = KURL(part->url(), str);
else
url = KURL(part->baseURL(), str);
}
KURL url = part->htmlDocument().completeURL(str).string();
KParts::URLArgs uargs;
uargs.frameName = args[1].isDefined() ?
args[1].toString().value().qstring()
......@@ -1071,7 +1070,7 @@ Completion WindowFunc::tryExecute(const List &args)
(const_cast<Window*>(window))->clearTimeout(v.toInt32());
break;
case Focus:
if (widget)
if (widget)
widget->setActiveWindow();
result = Undefined();
break;
......@@ -1260,8 +1259,13 @@ void Location::put(const UString &p, const KJSO &v)
QString str = v.toString().value().qstring();
KURL url;
if (p == "href")
url = Window::retrieveActive()->part()->completeURL(str);
if (p == "href") {
KHTMLPart* p = Window::retrieveActive()->part();
if ( p )
url = p->htmlDocument().completeURL( str ).string();
else
url = str;
}
else {
url = m_part->url();
if (p == "hash") url.setRef(str);
......@@ -1376,7 +1380,7 @@ Completion HistoryFunc::tryExecute(const List &args)
KParts::BrowserInterface *iface = ext->browserInterface();
if ( !iface )
return Completion(Normal);
return Completion(Normal);
switch (id) {
case Back:
......
......@@ -79,8 +79,7 @@ void HTMLBodyElementImpl::parseAttribute(AttrImpl *attr)
case ATTR_BACKGROUND:
{
QString url = khtml::parseURL( attr->value() ).string();
if ( ownerDocument() && ownerDocument()->view() )
url = ownerDocument()->view()->part()->completeURL( url ).url();
url = getDocument()->completeURL( url );
addCSSProperty(CSS_PROP_BACKGROUND_IMAGE, "url('"+url+"')" );
m_bgSet = !attr->value().isNull();
break;
......
......@@ -105,8 +105,7 @@ DOMString HTMLDocumentImpl::referrer() const
DOMString HTMLDocumentImpl::domain() const
{
// ### do they want the host or the domain????
KURL u(url.string());
return u.host();
return KURL( url() ).host();
}
HTMLElementImpl *HTMLDocumentImpl::body()
......
......@@ -149,8 +149,8 @@ void HTMLElementImpl::parseAttribute(AttrImpl *attr)
break;
// other misc attributes
default:
#ifdef UNSUPPORTED_ATTR
kdDebug(6030) << "UATTR: <" << this->nodeName().string() << "> ["
#ifdef UNSUPPORTED_ATTR
kdDebug(6030) << "UATTR: <" << this->nodeName().string() << "> ["
<< attr->name().string() << "]=[" << attr->value().string() << "]" << endl;
#endif
break;
......
......@@ -81,16 +81,14 @@ void HTMLBaseElementImpl::parseAttribute(AttrImpl *attr)
void HTMLBaseElementImpl::attach()
{
KHTMLView* v = ownerDocument()->view();
setStyle(ownerDocument()->styleSelector()->styleForElement(this));
if(_href.length())
{
v->part()->setBaseURL( KURL( v->part()->url(), _href.string() ) );
}
if(_target.length())
{
v->part()->setBaseTarget(_target.string());
}
if(!_href.isEmpty())
ownerDocument()->setBaseURL( KURL( ownerDocument()->view()->part()->url(), _href.string() ).url() );
if(!_target.isEmpty())
ownerDocument()->setBaseTarget( _target.string() );
HTMLElementImpl::attach();
}
......@@ -160,15 +158,20 @@ void HTMLLinkElementImpl::parseAttribute(AttrImpl *attr)
switch (attr->attrId)
{
case ATTR_REL:
m_rel = attr->value(); break;
m_rel = attr->value();
break;
case ATTR_HREF:
m_url = khtml::parseURL(attr->value()); break;
m_url = getDocument()->completeURL( khtml::parseURL(attr->value()).string() );
break;
case ATTR_TYPE:
m_type = attr->value(); break;
m_type = attr->value();
break;
case ATTR_MEDIA:
m_media = attr->value().string().lower(); break;
m_media = attr->value().string().lower();
break;
case ATTR_DISABLED:
// ###
break;
default:
HTMLElementImpl::parseAttribute(attr);
}
......@@ -290,7 +293,7 @@ void HTMLMetaElementImpl::attach()
if ( str.length() && str[0] == '=' ) str = str.mid( 1 ).stripWhiteSpace();
str = parseURL( DOMString(str) ).string();
if ( ok )
v->part()->scheduleRedirection(delay, v->part()->completeURL( str ).url());
v->part()->scheduleRedirection(delay, ownerDocument()->completeURL( str ));
}
}
else if(strcasecmp(_equiv, "expires") == 0 && !_content.isNull())
......
......@@ -151,10 +151,7 @@ void HTMLImageElementImpl::parseAttribute(AttrImpl *attr)
if ( attr->value()[0] == '#' )
usemap = attr->value();
else {
QString url = khtml::parseURL( attr->value() ).string();
if ( ownerDocument() && ownerDocument()->view() )
url = ownerDocument()->view()->part()->completeURL( url ).url();
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;
......
......@@ -90,55 +90,63 @@ bool HTMLAnchorElementImpl::prepareMouseEvent( int _x, int _y,
void HTMLAnchorElementImpl::defaultEventHandler(EventImpl *evt)
{
// ### KHTML_CLICK_EVENT??? why that?
// port to DOMACTIVATE
if (evt->id() == EventImpl::KHTML_CLICK_EVENT && evt->isMouseEvent() && href) {
MouseEventImpl* e = static_cast<MouseEventImpl*>( evt );
if ( ( evt->id() == EventImpl::KHTML_CLICK_EVENT ||
evt->id() == EventImpl::DOMACTIVATE_EVENT ) && href ) {
MouseEventImpl* e = 0;
if ( evt->id() == EventImpl::KHTML_CLICK_EVENT )
e = static_cast<MouseEventImpl*>( evt );
QString utarget;
QString url;
if ( e->button() == 2 ) return;
if ( e && e->button() == 2 ) return;
url = QConstString( href->s, href->l ).string();
if ( target )
utarget = QConstString( target->s, target->l ).string();
if ( e->button() == 1 )
if ( e && e->button() == 1 )
utarget = "_blank";
if ( e->target()->id() == ID_IMG ) {
HTMLImageElementImpl* img = static_cast<HTMLImageElementImpl*>( e->target() );
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)
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();
return;
}
}
}
if ( !evt->defaultPrevented() ) {
int state = 0;
if ( e->ctrlKey() )
state |= Qt::ControlButton;
if ( e->shiftKey() )
state |= Qt::ShiftButton;
if ( e->altKey() )
state |= Qt::AltButton;
int button = 0;
if ( e->button() == 0 )
button = Qt::LeftButton;
else if ( e->button() == 1 )
button = Qt::MidButton;
else if ( e->button() == 2 )
button = Qt::RightButton;
if ( e ) {
if ( e->ctrlKey() )
state |= Qt::ControlButton;
if ( e->shiftKey() )
state |= Qt::ShiftButton;
if ( e->altKey() )
state |= Qt::AltButton;
if ( e->button() == 0 )
button = Qt::LeftButton;
else if ( e->button() == 1 )
button = Qt::MidButton;
else if ( e->button() == 2 )
button = Qt::RightButton;
}
ownerDocument()->view()->part()->
urlSelected( url, button, state, utarget );
......
......@@ -135,11 +135,7 @@ void HTMLAppletElementImpl::attach()
if(archive)
args.insert( "archive", QString(archive->s, archive->l) );
if(!view->part()->baseURL().isEmpty())
args.insert( "baseURL", view->part()->baseURL().url() );
else
args.insert( "baseURL", view->part()->url().url() );
args.insert( "baseURL", ownerDocument()->baseURL() );
f = new RenderApplet(view, args, this);
}
else
......
......@@ -314,9 +314,8 @@ void HTMLTableElementImpl::parseAttribute(AttrImpl *attr)
if (!attr->value().isEmpty()) {
HTMLDocumentImpl *doc = static_cast<HTMLDocumentImpl *>(ownerDocument());
QString url = khtml::parseURL( attr->value() ).string();
if ( doc->view() )
url = doc->view()->part()->completeURL( url ).url();
addCSSProperty(CSS_PROP_BACKGROUND_IMAGE, "url('"+url+"')" );
url = doc->completeURL( url );
addCSSProperty(CSS_PROP_BACKGROUND_IMAGE, url );
}
else
removeCSSProperty(CSS_PROP_BACKGROUND_IMAGE);
......@@ -401,7 +400,7 @@ void HTMLTableElementImpl::parseAttribute(AttrImpl *attr)
removeCSSProperty(CSS_PROP_VERTICAL_ALIGN);
break;
case ATTR_NOSAVE:
break;
break;
default:
HTMLElementImpl::parseAttribute(attr);
}
......@@ -427,11 +426,8 @@ void HTMLTablePartElementImpl::parseAttribute(AttrImpl *attr)
case ATTR_BACKGROUND:
{
if (attr->val()) {
HTMLDocumentImpl *doc = static_cast<HTMLDocumentImpl *>(ownerDocument());
QString url = khtml::parseURL( attr->value() ).string();
if ( doc->view() )
url = doc->view()->part()->completeURL( url ).url();
addCSSProperty(CSS_PROP_BACKGROUND_IMAGE, "url('"+url+"')" );
addCSSProperty(CSS_PROP_BACKGROUND_IMAGE,
ownerDocument()->completeURL( khtml::parseURL( attr->value() ).string() ) );
}
else
removeCSSProperty(CSS_PROP_BACKGROUND_IMAGE);
......@@ -457,7 +453,7 @@ void HTMLTablePartElementImpl::parseAttribute(AttrImpl *attr)
break;
}
case ATTR_NOSAVE:
break;
break;
default:
HTMLElementImpl::parseAttribute(attr);
}
......@@ -680,7 +676,7 @@ void HTMLTableCellElementImpl::parseAttribute(AttrImpl *attr)
removeCSSProperty(CSS_PROP_HEIGHT);
break;
case ATTR_NOSAVE:
break;
break;
default:
HTMLTablePartElementImpl::parseAttribute(attr);
}
......
......@@ -388,8 +388,6 @@ void HTMLTokenizer::parseListing( DOMStringIt &src)
else if ( searchCount > 0 )
{
const QChar& cmp = *src;
kdDebug(6050) << "KHTMLPart::checkEmitLoadEvent " << this << endl;
if (!escaped && !src.escaped() &&
( cmp <= ' ' || cmp == '>' ) && searchFor[ searchCount ] == ' ') {
searchBuffer[ searchCount++] = cmp;
......@@ -1079,7 +1077,7 @@ void HTMLTokenizer::parseTag(DOMStringIt &src)
scriptSrc = scriptSrcCharset = "";
if ( currToken.attrs && !parser->doc()->view()->part()->onlyLocalReferences()) {
if ( ( a = currToken.attrs->getIdItem( ATTR_SRC ) ) )
scriptSrc = parser->doc()->view()->part()->completeURL(khtml::parseURL( a->value() ).string() ).url();
scriptSrc = parser->doc()->completeURL(khtml::parseURL( a->value() ).string() );
if ( ( a = currToken.attrs->getIdItem( ATTR_CHARSET ) ) )
scriptSrcCharset = a->value().string().stripWhiteSpace();
a = currToken.attrs->getIdItem( ATTR_LANGUAGE );
......
......@@ -279,8 +279,6 @@ public:
bool m_onlyLocalReferences :1;
KURL m_workingURL;
KURL m_baseURL;
QString m_baseTarget;
QTimer m_redirectionTimer;
#ifdef SPEED_DEBUG
......@@ -703,11 +701,12 @@ bool KHTMLPart::openURL( const KURL &url )
// initializing m_url to the new url breaks relative links when opening such a link after this call and _before_ begin() is called (when the first
// data arrives) (Simon)
// That has been fixed by calling setBaseURL() in begin(). (Waldo)
m_url = url;
if(m_url.protocol().startsWith( "http" ) && !m_url.host().isEmpty() &&
m_url.path().isEmpty())
m_url.path().isEmpty()) {
m_url.setPath("/");
emit d->m_extension->setLocationBarURL( m_url.prettyURL() );
}
kdDebug( 6050 ) << "KHTMLPart::openURL now (before started) m_url = " << m_url.url() << endl;
......@@ -796,11 +795,6 @@ KHTMLView *KHTMLPart::view() const
return d->m_view;
}
void KHTMLPart::enableJScript( bool enable )
{
setJScriptEnabled( enable );
}
void KHTMLPart::setJScriptEnabled( bool enable )
{
d->m_bJScriptForce = enable;
......@@ -814,7 +808,7 @@ bool KHTMLPart::jScriptEnabled() const
return d->m_bJScriptEnabled;
}
void KHTMLPart::enableMetaRefresh( bool enable )
void KHTMLPart::setMetaRefreshEnabled( bool enable )
{
d->m_metaRefreshEnabled = enable;
}
......@@ -860,6 +854,8 @@ QVariant KHTMLPart::executeScript( const DOM::Node &n, const QString &script )
//kdDebug(6050) << "KHTMLPart::executeScript n=" << n.nodeName().string().latin1() << "(" << n.nodeType() << ") " << script << endl;
KJSProxy *proxy = jScript();
qDebug( "executeScript: %s", script.latin1() );
if (!proxy)
return QVariant();
d->m_runningScripts++;
......@@ -898,12 +894,6 @@ QVariant KHTMLPart::executeScheduledScript()
return ret;
}
void KHTMLPart::enableJava( bool enable )
{
setJavaEnabled( enable );
}
void KHTMLPart::setJavaEnabled( bool enable )
{
d->m_bJavaForce = enable;
......@@ -935,11 +925,6 @@ KJavaAppletContext *KHTMLPart::createJavaContext()
return d->m_javaContext;
}
void KHTMLPart::enablePlugins( bool enable )
{
setPluginsEnabled( enable );
}
void KHTMLPart::setPluginsEnabled( bool enable )
{
d->m_bPluginsForce = enable;
......@@ -1024,11 +1009,6 @@ void KHTMLPart::slotDebugRenderTree()
d->m_doc->renderer()->printTree();
}
void KHTMLPart::autoloadImages( bool enable )
{
setAutoloadImages( enable );
}
void KHTMLPart::setAutoloadImages( bool enable )
{
if ( d->m_doc && d->m_doc->docLoader()->autoloadImages() == enable )
......@@ -1141,8 +1121,6 @@ void KHTMLPart::clear()
delete d->m_javaContext;
d->m_javaContext = 0;
d->m_baseURL = KURL();
d->m_baseTarget = QString::null;
d->m_delayRedirect = 0;
d->m_redirectURL = QString::null;
d->m_bHTTPRefresh = false;
......@@ -1278,8 +1256,7 @@ void KHTMLPart::slotData( KIO::Job* kio_job, const QByteArray &data )
end_pos = index;
}
}
qData = KURL( d->m_baseURL, qData.mid(pos, end_pos) ).url();
scheduleRedirection( delay, qData );
scheduleRedirection( delay, d->m_doc->completeURL( qData.mid( pos, end_pos ) ) );
}
d->m_bHTTPRefresh = true;
}
......@@ -1367,17 +1344,13 @@ void KHTMLPart::begin( const KURL &url, int xOffset, int yOffset )
d->m_referrer = url.url();
m_url = url;
KURL baseurl;
if ( !m_url.isEmpty() )
{
KURL::List lst = KURL::split( m_url );
KURL baseurl;
if ( !lst.isEmpty() )
baseurl = *lst.begin();
// Use this for relative links.
// We prefer m_baseURL over m_url because m_url changes when we are
// about to load a new page.
setBaseURL(baseurl);
KURL title( baseurl );
title.setRef( QString::null );
......@@ -1393,11 +1366,12 @@ void KHTMLPart::begin( const KURL &url, int xOffset, int yOffset )
else
d->m_doc = new HTMLDocumentImpl( d->m_view );
d->m_doc->ref();
d->m_doc->attach( d->m_view );
d->m_doc->setURL( m_url.url() );
// We prefer m_baseURL over m_url because m_url changes when we are
// about to load a new page.
d->m_doc->setBaseURL( baseurl.url() );
setAutoloadImages( KHTMLFactory::defaultHTMLSettings()->autoLoadImages() );
......@@ -1565,8 +1539,6 @@ void KHTMLPart::slotProgressUpdate()
void KHTMLPart::slotJobSpeed( KIO::Job* /*job*/, unsigned long speed )
{
qDebug( "slotJobSpeed: %d", speed );
emit d->m_extension->speedProgress( speed );
}
......@@ -1633,24 +1605,21 @@ void KHTMLPart::checkCompleted()
// check for a <link rel="SHORTCUT ICON" href="url to icon">,
// IE extension to set an icon for this page to use in
// bookmarks and the locationbar
if (!parentPart() && d->m_doc && d->m_doc->isHTMLDocument())
{
DOM::TagNodeListImpl links(d->m_doc, "LINK");
for (unsigned long i = 0; i < links.length(); ++i)
if (links.item(i)->isElementNode())
{
DOM::ElementImpl *link = static_cast<DOM::ElementImpl *>(links.item(i));
kdDebug(6005) << "Checking..." << endl;