📄 kwqkhtmlpart.cpp
字号:
}
#endif
if (renderer()) {
// _elementToDraw is used to draw only one element
RenderObject *eltRenderer = (_elementToDraw != 0) ? _elementToDraw.handle()->renderer() : 0;
renderer()->layer()->paint(p, rect, _drawSelectionOnly, eltRenderer);
#ifdef __NAVIGATION_DEBUG__
// paint the dot as red circle
DocumentImpl *doc = xmlDocImpl();
if (doc) {
QPtrList<khtml::BoxInfo> *boxInfoList = new QPtrList<khtml::BoxInfo>;
QRect rt(0,0,view()->contentsWidth(),view()->contentsHeight());
doc->renderer()->getRenderersInRect(*boxInfoList,0,0,rt);
for(khtml::BoxInfo *sel = boxInfoList->first();sel;sel = boxInfoList->next()){
NodeImpl* n = sel->renderObject->node();
QRect nr = n->getRect();
if(n->isFocusable() || sel->area
|| n->getHTMLEventListener(EventImpl::MOUSEOVER_EVENT)
|| n->getHTMLEventListener(EventImpl::KHTML_CLICK_EVENT)
|| n->getHTMLEventListener(EventImpl::MOUSEUP_EVENT)) {
p->setPen(qRgb(255,0,0));
p->setBrush(NoBrush);
p->drawRect(sel->absoluteXPos,sel->absoluteYPos,sel->width,sel->height);
//p->drawEllipse(sel->absoluteXPos,sel->absoluteYPos,10,10);
}
}
boxInfoList->clear();
delete boxInfoList;
NodeImpl *node = doc->focusNode();
if (node)
{
QRect nr = node->getRect();
p->setPen(qRgb(255,0,0));
p->drawEllipse(d->m_view->getDot().x() + nr.left(), d->m_view->getDot().y() + nr.top(), 5,5);
}
}
#endif
} else {
ERROR("called KWQKHTMLPart::paint with nil renderer",0);
}
}
void KWQKHTMLPart::adjustPageHeight(int *newBottom, int oldTop, int oldBottom, int bottomLimit)
{
RenderCanvas *root = static_cast<RenderCanvas *>(xmlDocImpl()->renderer());
if (root) {
// Use a printer device, with painting disabled for the pagination phase
QPainter painter(true);
painter.setPaintingDisabled(true);
root->setTruncatedAt(oldBottom);
QRect dirtyRect(0,oldTop,
root->docWidth(), oldBottom-oldTop);
root->layer()->paint(&painter, dirtyRect);
*newBottom = root->bestTruncatedAt();
if (*newBottom == 0) {
*newBottom = oldBottom;
}
} else {
*newBottom = oldBottom;
}
}
RenderObject *KWQKHTMLPart::renderer() const
{
DocumentImpl *doc = xmlDocImpl();
return doc ? doc->renderer() : 0;
}
QString KWQKHTMLPart::userAgent() const
{
return QString::FromDes(_bridge->Client().UserAgentForURL(m_url.Des()));
//return QString("Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en-us) AppleWebKit/179 (KHTML, like Gecko) Safari/179");
}
QString KWQKHTMLPart::mimeTypeForFileName(const QString &fileName) const
{
HBufC* _mimeType = _bridge->Client().MimeTypeForFileName(fileName.Des());
if(_mimeType) {
QString mimeType =QString::FromDes(*_mimeType);
delete _mimeType;
return mimeType ;
}
else{
return QString("");
}
}
#if !KHTML_NO_SCRIPTING
/*KJS::Bindings::RootObject *KWQKHTMLPart::bindingRootObject()
{
if (!_bindingRoot) {
_bindingRoot = new KJS::Bindings::RootObject(0); // The root gets deleted by JavaScriptCore.
KJS::ObjectImp *win = static_cast<KJS::ObjectImp *>(KJS::Window::retrieveWindow(this));
_bindingRoot->setRootObjectImp (win);
_bindingRoot->setInterpreter (KJSProxy::proxy(this)->interpreter());
addPluginRootObject (_bindingRoot);
}
return _bindingRoot;
}
WebScriptObject *KWQKHTMLPart::windowScriptObject()
{
if (!_windowScriptObject) {
KJS::ObjectImp *win = static_cast<KJS::ObjectImp *>(KJS::Window::retrieveWindow(this));
_windowScriptObject = KWQRetainNSRelease([[WebScriptObject alloc] _initWithObjectImp:win root:bindingRootObject()]);
}
return _windowScriptObject;
}*/
#endif
void KWQKHTMLPart::partClearedInBegin()
{
_bridge->Client().WindowObjectCleared();
}
#if !KHTML_NO_SCRIPTING
QMap<int, ScheduledAction*> *KWQKHTMLPart::pauseActions(const void *key)
{
if (d->m_doc && d->m_jscript) {
Window *w = Window::retrieveWindow(this);
if (w && w->hasTimeouts()) {
return w->pauseTimeouts(key);
}
}
return 0;
}
void KWQKHTMLPart::resumeActions(QMap<int, ScheduledAction*> *actions, const void *key)
{
if (d->m_doc && d->m_jscript && d->m_bJScriptEnabled) {
Window *w = Window::retrieveWindow(this);
if (w) {
w->resumeTimeouts(actions, key);
}
}
}
#endif
bool KWQKHTMLPart::canCachePage()
{
// Only save page state if:
// 1. We're not a frame or frameset.
// 2. The page has no unload handler.
// 3. The page has no password fields.
// 4. The URL for the page is not https.
// 5. The page has no applets.
if (d->m_frames.count() ||
parentPart() ||
m_url.protocol().startsWith("https") ||
(d->m_doc && ( //htmlDocument().applets().length() != 0 ||
d->m_doc->hasWindowEventListener(EventImpl::UNLOAD_EVENT) ||
d->m_doc->hasPasswordField()))) {
return false;
}
return true;
}
#if !KHTML_NO_SCRIPTING
void KWQKHTMLPart::saveWindowProperties(SavedProperties *windowProperties)
{
Window *window = Window::retrieveWindow(this);
if (window)
window->saveProperties(*windowProperties);
}
void KWQKHTMLPart::saveLocationProperties(SavedProperties *locationProperties)
{
Window *window = Window::retrieveWindow(this);
if (window) {
Interpreter::lock();
Location *location = window->location();
Interpreter::unlock();
location->saveProperties(*locationProperties);
}
}
void KWQKHTMLPart::restoreWindowProperties(SavedProperties *windowProperties)
{
Window *window = Window::retrieveWindow(this);
if (window)
window->restoreProperties(*windowProperties);
}
void KWQKHTMLPart::restoreLocationProperties(SavedProperties *locationProperties)
{
Window *window = Window::retrieveWindow(this);
if (window) {
Interpreter::lock();
Location *location = window->location();
Interpreter::unlock();
location->restoreProperties(*locationProperties);
}
}
void KWQKHTMLPart::saveInterpreterBuiltins(SavedBuiltins &interpreterBuiltins)
{
if (jScript() && jScript()->interpreter()) {
jScript()->interpreter()->saveBuiltins(interpreterBuiltins);
}
}
void KWQKHTMLPart::restoreInterpreterBuiltins(const SavedBuiltins &interpreterBuiltins)
{
if (jScript() && jScript()->interpreter()) {
jScript()->interpreter()->restoreBuiltins(interpreterBuiltins);
}
}
#endif
// ### NOT IMPLEMENTED page cache
#if 0
void KWQKHTMLPart::openURLFromPageCache(KWQPageState *state)
{
// It's safe to assume none of the KWQPageState methods will raise
// exceptions, since KWQPageState is implemented by WebCore and
// does not throw
DocumentImpl *doc = [state document];
KURL *url = [state URL];
SavedProperties *windowProperties = [state windowProperties];
SavedProperties *locationProperties = [state locationProperties];
SavedBuiltins *interpreterBuiltins = [state interpreterBuiltins];
QMap<int, ScheduledAction*> *actions = [state pausedActions];
cancelRedirection();
// We still have to close the previous part page.
if (!d->m_restored){
closeURL();
}
d->m_bComplete = false;
// Don't re-emit the load event.
d->m_bLoadEventEmitted = true;
// delete old status bar msg's from kjs (if it _was_ activated on last URL)
if( d->m_bJScriptEnabled )
{
d->m_kjsStatusBarText = QString::null;
d->m_kjsDefaultStatusBarText = QString::null;
}
ASSERT (url);
m_url = *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)
if(m_url.protocol().startsWith( "http" ) && !m_url.host().isEmpty() && m_url.path().isEmpty()) {
m_url.setPath("/");
emit d->m_extension->setLocationBarURL( m_url.prettyURL() );
}
// copy to m_workingURL after fixing m_url above
d->m_workingURL = m_url;
emit started( 0L );
// -----------begin-----------
clear();
doc->setInPageCache(NO);
d->m_bCleared = false;
d->m_cacheId = 0;
d->m_bComplete = false;
d->m_bLoadEventEmitted = false;
d->m_referrer = m_url.url();
setView(doc->view());
d->m_doc = doc;
d->m_doc->ref();
Decoder *decoder = doc->decoder();
if (decoder) {
decoder->ref();
}
if (d->m_decoder) {
d->m_decoder->deref();
}
d->m_decoder = decoder;
updatePolicyBaseURL();
restoreWindowProperties (windowProperties);
restoreLocationProperties (locationProperties);
restoreInterpreterBuiltins (*interpreterBuiltins);
if (actions)
resumeActions (actions, state);
checkCompleted();
}
#endif
KWQKHTMLPart *KWQKHTMLPart::partForWidget(const QWidget *widget)
{
ASSERT_ARG(widget, widget);
NodeImpl *node = nodeForWidget(widget);
if (node) {
return partForNode(node);
}
// Assume all widgets are either form controls, or KHTMLViews.
const KHTMLView *view = static_cast<const KHTMLView *>(widget);
return KWQ(view->part());
}
CWebCoreBridge *KWQKHTMLPart::bridgeForWidget(const QWidget *widget)
{
ASSERT_ARG(widget, widget);
KWQKHTMLPart *part = partForWidget(widget);
ASSERT(part);
return part->bridge();
}
KWQKHTMLPart *KWQKHTMLPart::partForNode(NodeImpl *node)
{
ASSERT_ARG(node, node);
return KWQ(node->getDocument()->part());
}
// ### NOT IMPLEMENTED views
/*
NSView *KWQKHTMLPart::documentViewForNode(DOM::NodeImpl *node)
{
WebCoreBridge *bridge = partForNode(node)->bridge();
return [bridge documentView];
}
*/
NodeImpl *KWQKHTMLPart::nodeForWidget(const QWidget *widget)
{
ASSERT_ARG(widget, widget);
const QObject *o = widget->eventFilterObject();
return o ? static_cast<const RenderWidget *>(o)->element() : 0;
}
void KWQKHTMLPart::setDocumentFocus(QWidget *widget)
{
NodeImpl *node = nodeForWidget(widget);
if (node) {
node->getDocument()->setFocusNode(node);
} else {
ERROR("unable to clear focus because widget had no corresponding node",0);
}
}
void KWQKHTMLPart::clearDocumentFocus(QWidget *widget)
{
NodeImpl *node = nodeForWidget(widget);
if (node) {
node->getDocument()->setFocusNode(0);
} else {
ERROR("unable to clear focus because widget had no corresponding node",0);
}
}
void KWQKHTMLPart::saveDocumentState()
{
if (_bridge)
_bridge->SaveDocumentState();
}
void KWQKHTMLPart::restoreDocumentState()
{
// ### NOT IMPLEMENTED document state save
/*
KWQ_BLOCK_EXCEPTIONS;
[_bridge restoreDocumentState];
KWQ_UNBLOCK_EXCEPTIONS;
*/
}
QPtrList<KWQKHTMLPart> &KWQKHTMLPart::mutableInstances()
{
static QPtrList<KWQKHTMLPart> instancesList;
return instancesList;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -