📄 html_documentimpl.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., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. * * $Id: html_documentimpl.cpp,v 1.3 2002/03/07 07:21:55 ymwei Exp $ */#include <stdlib.h>#include <qstack.h>#include "render_interface.h"#include "html_documentimpl.h"#include "dom_node.h"#include "mghtmlview.h"#include "mghtml_part.h"#include "mghtml_settings.h"#include "htmlattrs.h"#include "htmlparser.h"#include "htmltokenizer.h"#include "htmlhashes.h"#include "html_imageimpl.h"#include "kdebug.h"#include "kurl.h"#include "kcharsets.h"#include "cssstyleselector.h"#include "css_stylesheetimpl.h"#include "render_style.h"#include "render_root.h"#define DEBUG_BY_XHTANG 0using namespace DOM;using namespace khtml;template class QStack<DOM::NodeImpl>;HTMLDocumentImpl::HTMLDocumentImpl() : DocumentImpl(){ parser = 0; tokenizer = 0; bodyElement = 0; htmlElement = 0; m_loadingSheet = false; m_elemSheet=0; m_sheet = 0; m_docLoader = new MGDocLoader(); visuallyOrdered = false;}HTMLDocumentImpl::HTMLDocumentImpl(MGHTMLView *v) : DocumentImpl(v){ parser = 0; tokenizer = 0; bodyElement = 0; htmlElement = 0; m_styleSelector = new CSSStyleSelector(this); m_loadingSheet = false; m_elemSheet=0; m_sheet = 0; m_docLoader = new MGDocLoader(); m_docLoader->setHwnd(v->getHwnd()); visuallyOrdered = false;}HTMLDocumentImpl::~HTMLDocumentImpl(){ delete m_docLoader; if (m_elemSheet ) m_elemSheet->deref(); delete m_sheet;}DOMString HTMLDocumentImpl::referrer() const{ // ### should we fix that? I vote against for privacy reasons return DOMString();}DOMString HTMLDocumentImpl::domain() const{ // ### do they want the host or the domain???? KURL u(url.string()); return u.host();}DOMString HTMLDocumentImpl::baseURL() const{ if(!view()->part()->baseURL().isEmpty()) return view()->part()->baseURL().url(); return url;}HTMLElementImpl *HTMLDocumentImpl::body(){ if(bodyElement) return bodyElement; if(!_first) return 0; if(!htmlElement) html(); if(!htmlElement) return 0; NodeImpl *test = htmlElement->firstChild(); while(test && (test->id() != ID_BODY && test->id() != ID_FRAMESET)) test = test->nextSibling(); if(!test) return 0; bodyElement = static_cast<HTMLElementImpl *>(test); return bodyElement;}HTMLElementImpl *HTMLDocumentImpl::html(){ if (htmlElement) return htmlElement; NodeImpl *n = _first; while (n && n->id() != ID_HTML) n = n->nextSibling(); if (n) { htmlElement = static_cast<HTMLElementImpl*>(n); return htmlElement; } else return 0;}void HTMLDocumentImpl::setBody(const HTMLElement &/*_body*/){ // ###}void HTMLDocumentImpl::open(){ ////kdDebug( 6030 ) << "HTMLDocumentImpl::open()" << endl; clear(); parser = new KHTMLParser(m_view, this); tokenizer = new HTMLTokenizer(parser, m_view); connect(tokenizer,SIGNAL(finishedParsing()),this,SLOT(slotFinishedParsing())); tokenizer->begin();}void HTMLDocumentImpl::close(){ if (m_render) m_render->close(); if(parser) delete parser; parser = 0; if(tokenizer) delete tokenizer; tokenizer = 0;}void HTMLDocumentImpl::write( const DOMString &text ){ if(tokenizer){ tokenizer->write(text.string()); //save string between <script> and </script> //but it seems useless now 2001_05_11// m_script=tokenizer->m_script; }}void HTMLDocumentImpl::write( const QString &text ){ if(tokenizer){ tokenizer->write(text); //save string between <script> and </script> //but it seems useless now 2001_05_11,so it should deleted later.// m_script=tokenizer->m_script; }#if 0 //create a new html document to write. else { open(); if(tokenizer)tokenizer->write("<html><body>"+text+"</body></html>"); myClose(); }#endif}void HTMLDocumentImpl::writeln( const DOMString &text ){ write(text); write(DOMString("\n"));}void HTMLDocumentImpl::finishParsing(){ if(tokenizer) tokenizer->finish();}bool HTMLDocumentImpl::myClose(){ if(!tokenizer)return 0; tokenizer->notifyFinished(); if(tokenizer->CanFinishParsing()) { finishParsing(); close(); } return 1;} ElementImpl *HTMLDocumentImpl::getElementById( const DOMString &elementId ){ QStack<NodeImpl> nodeStack; NodeImpl *current = _first; while(1) { if(!current) { if(nodeStack.isEmpty()) break; current = nodeStack.pop(); current = current->nextSibling(); } else { if(current->isElementNode()) { ElementImpl *e = static_cast<ElementImpl *>(current); if(e->getAttribute(ATTR_ID) == elementId) return e; } NodeImpl *child = current->firstChild(); if(child) { nodeStack.push(current); current = child; } else { current = current->nextSibling(); } } } return 0;}NodeListImpl *HTMLDocumentImpl::getElementsByName( const DOMString &elementName ){ return new NameNodeListImpl( documentElement(), elementName );}// Please see if there`s a possibility to merge that code// with the next function and getElementByID().NodeImpl *HTMLDocumentImpl::findElement( int id ){ QStack<NodeImpl> nodeStack; NodeImpl *current = _first; while(1) { if(!current) { if(nodeStack.isEmpty()) break; current = nodeStack.pop(); current = current->nextSibling(); } else { if(current->id() == id) return current; NodeImpl *child = current->firstChild(); if(child) { nodeStack.push(current); current = child; } else { current = current->nextSibling(); } } } return 0;}HTMLElementImpl *HTMLDocumentImpl::findSelectableElement(NodeImpl *start, bool forward){ if (!start) start = forward?_first:_last; if (!start) return 0; if (forward) while(1) { if (start->firstChild()) start = start->firstChild(); else if (start->nextSibling()) start = start->nextSibling(); else // find the next sibling of the first parent that has a nextSibling { NodeImpl *pa = start; while (pa) { pa = pa->parentNode(); if (!pa) return 0; if (pa->nextSibling()) { start = pa->nextSibling(); pa = 0; } } } if (start->isElementNode() && static_cast<HTMLElementImpl *>(start)->isSelectable())
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -