📄 kwqkhtmlpart.cpp
字号:
_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()
{
// ### NOT IMPLEMENTED document state save
/*
// Do not save doc state if the page has a password field and a form that would be submitted
// via https
if (!(d->m_doc && d->m_doc->hasPasswordField() && d->m_doc->hasSecureForm())) {
KWQ_BLOCK_EXCEPTIONS;
[_bridge saveDocumentState];
KWQ_UNBLOCK_EXCEPTIONS;
}
*/
}
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;
}
void KWQKHTMLPart::updatePolicyBaseURL()
{
// FIXME: docImpl() returns null for everything other than HTML documents; is this causing problems? -dwh
if (parentPart() && parentPart()->xmlDocImpl()) {
setPolicyBaseURL(parentPart()->xmlDocImpl()->policyBaseURL());
} else {
setPolicyBaseURL(m_url.url());
}
}
void KWQKHTMLPart::setPolicyBaseURL(const DOMString &s)
{
// FIXME: XML documents will cause this to return null. docImpl() is
// an HTMLdocument only. -dwh
if (xmlDocImpl())
xmlDocImpl()->setPolicyBaseURL(s);
ConstFrameIt end = d->m_frames.end();
for (ConstFrameIt it = d->m_frames.begin(); it != end; ++it) {
ReadOnlyPart *subpart = (*it).m_part;
static_cast<KWQKHTMLPart *>(subpart)->setPolicyBaseURL(s);
}
}
QString KWQKHTMLPart::requestedURLString() const
{
return QString::FromDes(_bridge->Client().RequestedURLString());
}
QString KWQKHTMLPart::incomingReferrer() const
{
return QString::FromDes(_bridge->Client().IncomingReferrer());
}
void KWQKHTMLPart::forceLayout()
{
KHTMLView *v = d->m_view;
if (v) {
v->layout();
// We cannot unschedule a pending relayout, since the force can be called with
// a tiny rectangle from a drawRect update. By unscheduling we in effect
// "validate" and stop the necessary full repaint from occurring. Basically any basic
// append/remove DHTML is broken by this call. For now, I have removed the optimization
// until we have a better invalidation stategy. -dwh
//v->unscheduleRelayout();
}
}
void KWQKHTMLPart::forceLayoutWithPageWidthRange(int minPageWidth, int maxPageWidth)
{
// Dumping externalRepresentation(_part->renderer()).ascii() is a good trick to see
// the state of things before and after the layout
RenderCanvas *root = static_cast<RenderCanvas *>(xmlDocImpl()->renderer());
if (root) {
// This magic is basically copied from khtmlview::print
int pageW = minPageWidth;
root->setWidth(pageW);
root->setNeedsLayoutAndMinMaxRecalc();
forceLayout();
// If we don't fit in the minimum page width, we'll lay out again. If we don't fit in the
// maximum page width, we will lay out to the maximum page width and clip extra content.
// FIXME: We are assuming a shrink-to-fit printing implementation. A cropping
// implementation should not do this!
int rightmostPos = root->rightmostPosition();
if (rightmostPos > minPageWidth) {
pageW = kMin(rightmostPos, maxPageWidth);
root->setWidth(pageW);
root->setNeedsLayoutAndMinMaxRecalc();
forceLayout();
}
}
}
void KWQKHTMLPart::sendResizeEvent()
{
KHTMLView *v = d->m_view;
if (v) {
// Sending an event can result in the destruction of the view and part.
// We ref so that happens after we return from the KHTMLView function.
v->ref();
QResizeEvent e;
v->resizeEvent(&e);
v->deref();
}
}
void KWQKHTMLPart::sendScrollEvent()
{
KHTMLView *v = d->m_view;
if (v) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -