⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 kwqkhtmlpart.cpp

📁 手机浏览器源码程序,功能强大
💻 CPP
📖 第 1 页 / 共 5 页
字号:
 /*
 * Copyright (C) 2003 Apple Computer, Inc.  All rights reserved.
 * Portions Copyright (c) 2005 Nokia Corporation, Inc. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
#include "KWQKHTMLPart.h"
#include "KWQClipboard.h"
#include "KWQDOMNode.h"
#include "BrCtlDefs.h"
//#define __NAVIGATION_DEBUG__
//#include "KWQDummyView.h"
//#include "KWQEditCommand.h"
//#include "KWQExceptions.h"
#include "KWQKJobClasses.h"
#include "KWQLogging.h"
//#include "KWQPageState.h"
#include "KWQPrinter.h"
#include "KWQScrollBar.h"
#include "KWQWindowWidget.h"
#include "KWQObjectWidget.h"
#include "KWQFormData.h"
//#include "KWQFoundationExtras.h"
#include "WebCoreBridge.h"
//#include "WebCoreViewFactory.h"
#include "csshelper.h"
#include "dom2_eventsimpl.h"
#include "dom2_rangeimpl.h"
#include "dom_position.h"
#include "dom_textimpl.h"
#include "html_formimpl.h"
#include "html_documentimpl.h"
#include "html_misc.h"
#include "htmlattrs.h"
#include "htmltokenizer.h"
#include "khtmlpart_p.h"
#include "khtmlview.h"

#if !KHTML_NO_SCRIPTING
#include "kjs_binding.h"
#include "kjs_window.h"
#endif

#include "render_canvas.h"
#include "render_frames.h"
#include "render_image.h"
#include "render_list.h"
#include "render_style.h"
#include "render_table.h"
#include "render_text.h"
#include "visible_text.h"

#undef _KWQ_TIMING

using DOM::AtomicString;
using DOM::ClipboardEventImpl;
using DOM::DocumentImpl;
using DOM::DOMString;
using DOM::ElementImpl;
using DOM::EventImpl;
using DOM::HTMLDocumentImpl;
using DOM::HTMLElementImpl;
using DOM::HTMLFormElementImpl;
using DOM::HTMLFrameElementImpl;
using DOM::HTMLGenericFormElementImpl;
using DOM::HTMLTableCellElementImpl;
using DOM::Node;
using DOM::NodeImpl;
using DOM::Position;
using DOM::Range;
using DOM::RangeImpl;
using DOM::TextImpl;

using khtml::Cache;
using khtml::ChildFrame;
using khtml::Decoder;
using khtml::InlineTextBox;
using khtml::MouseDoubleClickEvent;
using khtml::MouseMoveEvent;
using khtml::MousePressEvent;
using khtml::MouseReleaseEvent;
using khtml::parseURL;
using khtml::PRE;
using khtml::RenderCanvas;
using khtml::RenderImage;
using khtml::RenderLayer;
using khtml::RenderListItem;
using khtml::RenderObject;
using khtml::RenderPart;
using khtml::RenderStyle;
using khtml::RenderTableCell;
using khtml::RenderText;
using khtml::RenderWidget;
using khtml::VISIBLE;

using KIO::Job;

#if !KHTML_NO_SCRIPTING
using KJS::Interpreter;
using KJS::Location;
using KJS::SavedBuiltins;
using KJS::SavedProperties;
using KJS::ScheduledAction;
using KJS::Window;

// ### NOT IMPLEMENTED plugin scripting
//using KJS::Bindings::Instance;
#endif

using KParts::ReadOnlyPart;
using KParts::URLArgs;

using namespace DOM;


struct CurrentEvent
OOM_MODIFIED
{
	enum TEventType { EKey, EPointer };

	TEventType iType;
	TKeyEvent iKey;
	TPointerEvent iPointer;
};

CurrentEvent *KWQKHTMLPart::_currentEvent = 0;

bool KWQKHTMLPart::isFrameSet() const
{
    DocumentImpl *document = d->m_doc;
    if (!document || !document->isHTMLDocument())
        return false;
    NodeImpl *body = static_cast<HTMLDocumentImpl *>(document)->body();
    return body && body->renderer() && body->id() == ID_FRAMESET;
}


void KHTMLPart::completed()
{
    KWQ(this)->_completed.call();
}

void KHTMLPart::completed(bool arg)
{
    KWQ(this)->_completed.call(arg);
}

void KHTMLPart::nodeActivated(const Node &)
{
}

bool KHTMLPart::openURL(const KURL &URL)
{
    ASSERT_NOT_REACHED();
    return true;
}

void KHTMLPart::onURL(const QString &)
{
}

void KHTMLPart::setStatusBarText(const QString &status)
{
    KWQ(this)->setStatusBarText(status);
}

void KHTMLPart::started(Job *j)
{
    KWQ(this)->_started.call(j);
}

bool KHTMLView::isKHTMLView() const
{
    return true;
}

static void redirectionTimerMonitor(void *context)
{
    KWQKHTMLPart *kwq = static_cast<KWQKHTMLPart *>(context);
    kwq->redirectionTimerStartedOrStopped();
}

KWQKHTMLPart::KWQKHTMLPart()
    : _started(this, SIGNAL(started(KIO::Job *)))
    , _completed(this, SIGNAL(completed()))
    , _completedWithBool(this, SIGNAL(completed(bool)))
//    , _mouseDownView(0)
    , _sendingEventToSubview(false)
    , _mouseDownMayStartDrag(false)
    , _mouseDownMayStartSelect(false)
    , _formValuesAboutToBeSubmitted(0)
//    , _formAboutToBeSubmitted(0)
    , _windowWidget(NULL)
    , _usesInactiveTextBackgroundColor(false)
    , _showsFirstResponder(true)
    , _drawSelectionOnly(false)
#if !KHTML_NO_SCRIPTING
//    , _bindingRoot(0)
    , _windowScriptObject(0)
#endif
//    , _dragSrc(0)
//    , _dragClipboard(0)
    , _elementToDraw(0)
    , m_markedTextUsesUnderlines(false)
    , _focusableNodeList(0)
{
    // Must init the cache before connecting to any signals
    Cache::init();

    // The widget is made outside this class in our case.
    KHTMLPart::init( 0, DefaultGUI );

    mutableInstances().prepend(this);
    d->m_redirectionTimer.setMonitor(redirectionTimerMonitor, this);

}

KWQKHTMLPart::~KWQKHTMLPart()
{
    cleanupPluginRootObjects();

    mutableInstances().remove(this);
    if (d->m_view) {
	d->m_view->deref();
    }
    freeClipboard();
    // these are all basic Foundation classes and our own classes - we
    // know they will not raise in dealloc, so no need to block
    // exceptions.
    delete _formValuesAboutToBeSubmitted;
    //KWQRelease(_formAboutToBeSubmitted);

    //KWQRelease(_windowScriptObject);

    delete _windowWidget;

    delete _focusableNodeList;
}

void KWQKHTMLPart::freeClipboard()
{
// ### NOT IMPLEMENTED clipboard
/*    if (_dragClipboard) {
        _dragClipboard->setAccessPolicy(KWQClipboard::Numb);
	_dragClipboard->deref();
        _dragClipboard = 0;
    }
*/
}

void KWQKHTMLPart::setSettings (KHTMLSettings *settings)
{
    d->m_settings = settings;
}

QString KWQKHTMLPart::generateFrameName()
{
	HBufC* frameName = _bridge->Client().GenerateFrameName();
	if(frameName){
		QString qframeName= QString::FromDes(frameName->Des());
		delete frameName;
		return qframeName;
	}
	return QString("");
}

void KWQKHTMLPart::provisionalLoadStarted()
{
    // we don't want to wait until we get an actual http response back
    // to cancel pending redirects, otherwise they might fire before
    // that happens.
    cancelRedirection(true);
}

bool KWQKHTMLPart::openURL(const KURL &url)
{
    bool userGesture = true;

    if (jScript() && jScript()->interpreter()) {
        KHTMLPart *rootPart = this;
        while (rootPart->parentPart() != 0)
            rootPart = rootPart->parentPart();
        KJS::ScriptInterpreter *interpreter = static_cast<KJS::ScriptInterpreter *>(KJSProxy::proxy(rootPart)->interpreter());
        userGesture = interpreter->wasRunByUserGesture();
    }

    // FIXME: The lack of args here to get the reload flag from
    // indicates a problem in how we use KHTMLPart::processObjectRequest,
    // where we are opening the URL before the args are set up.
    _bridge->Client().LoadUrl(url.Des(),
            _bridge->Referrer(), // referrer
              EFalse, // reload
              userGesture, //userGesture
              KNullDesC, //target
     		  EEventNull); //triggeringEvent

    return true;
}

void KWQKHTMLPart::openURLRequest(const KURL &url, const URLArgs &args)
{

    _bridge->Client().LoadUrl(url.Des(),
            _bridge->Referrer(), // referrer
              args.reload, // reload
              ETrue, //userGesture
              args.frameName.Des(), //target
     		  EEventNull); //triggeringEvent

}

void KWQKHTMLPart::didNotOpenURL(const KURL &URL)
{
    if (_submittedFormURL == URL) {
        _submittedFormURL = KURL();
    }
}

// Scans logically forward from "start", including any child frames
static HTMLFormElementImpl *scanForForm(NodeImpl *start)
{
    NodeImpl *n;
    for (n = start; n; n = n->traverseNextNode()) {
        NodeImpl::Id nodeID = idFromNode(n);
        if (nodeID == ID_FORM) {
            return static_cast<HTMLFormElementImpl *>(n);
        } else if (n->isHTMLElement()
                   && static_cast<HTMLElementImpl *>(n)->isGenericFormElement()) {
            return static_cast<HTMLGenericFormElementImpl *>(n)->form();
        } else if (nodeID == ID_FRAME || nodeID == ID_IFRAME) {
            NodeImpl *childDoc = static_cast<HTMLFrameElementImpl *>(n)->contentDocument();
            HTMLFormElementImpl *frameResult = scanForForm(childDoc);
            if (frameResult) {
                return frameResult;
            }
        }
    }
    return 0;
}

// We look for either the form containing the current focus, or for one immediately after it
HTMLFormElementImpl *KWQKHTMLPart::currentForm() const
{
    // start looking either at the active (first responder) node, or where the selection is
    NodeImpl *start = activeNode().handle();
    if (!start) {
        start = selectionStart();
    }

    // try walking up the node tree to find a form element
    NodeImpl *n;
    for (n = start; n; n = n->parentNode()) {
        if (idFromNode(n) == ID_FORM) {
            return static_cast<HTMLFormElementImpl *>(n);
        } else if (n->isHTMLElement()
                   && static_cast<HTMLElementImpl *>(n)->isGenericFormElement()) {
            return static_cast<HTMLGenericFormElementImpl *>(n)->form();
        }
    }

    // try walking forward in the node tree to find a form element
    if (!start) {
        start = xmlDocImpl();
    }
    return scanForForm(start);
}


// ### NOT IMPLEMENTED search stuff
#if 0
// Either get cached regexp or build one that matches any of the labels.
// The regexp we build is of the form:  (STR1|STR2|STRN)
QRegExp *regExpForLabels(NSArray *labels)
{
    // All the ObjC calls in this method are simple array and string
    // calls which we can assume do not raise exceptions

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -