webengine/osswebengine/WebKit/qt/WebKitPart/WebKitPart.cpp
changeset 0 dd21522fd290
equal deleted inserted replaced
-1:000000000000 0:dd21522fd290
       
     1 /*
       
     2  * Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org>
       
     3  * Copyright (C) 2006 Zack Rusin <zack@kde.org>
       
     4  *
       
     5  * All rights reserved.
       
     6  *
       
     7  * Redistribution and use in source and binary forms, with or without
       
     8  * modification, are permitted provided that the following conditions
       
     9  * are met:
       
    10  * 1. Redistributions of source code must retain the above copyright
       
    11  *    notice, this list of conditions and the following disclaimer.
       
    12  * 2. Redistributions in binary form must reproduce the above copyright
       
    13  *    notice, this list of conditions and the following disclaimer in the
       
    14  *    documentation and/or other materials provided with the distribution.
       
    15  *
       
    16  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
       
    17  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
       
    18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
       
    19  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
       
    20  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
       
    21  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
       
    22  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
       
    23  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
       
    24  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
       
    25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
       
    26  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
       
    27  */
       
    28 
       
    29 #include "config.h"
       
    30 #include "WebKitPart.h"
       
    31 
       
    32 #include "FrameLoader.h"
       
    33 #include "FrameView.h"
       
    34 #include "ChromeClientQt.h"
       
    35 #include "ContextMenuClientQt.h"
       
    36 #include "DragClientQt.h"
       
    37 #include "EditorClientQt.h"
       
    38 #include "InspectorClientQt.h"
       
    39 #include "KURL.h"
       
    40 
       
    41 #include <QDebug>
       
    42 
       
    43 #include "Page.h"
       
    44 #include "FrameQt.h"
       
    45 #include "WebKitFactory.h"
       
    46 #include "WebKitPartClient.h"
       
    47 #include "WebKitPartBrowserExtension.h"
       
    48 
       
    49 using namespace WebCore;
       
    50 
       
    51 WebKitPart::WebKitPart(QWidget* parentWidget, QObject* parentObject, GUIProfile prof)
       
    52     : KParts::ReadOnlyPart(parentObject)
       
    53     , m_frame(0)
       
    54     , m_frameView(0)
       
    55     , m_client(0)
       
    56 {
       
    57     setInstance(WebKitFactory::instance(), prof == BrowserViewGUI && !parentPart());
       
    58     initView(parentWidget, prof);
       
    59 
       
    60     m_extension = new WebKitPartBrowserExtension(this);
       
    61 }
       
    62 
       
    63 WebKitPart::~WebKitPart()
       
    64 {
       
    65     if (m_frame)
       
    66         delete m_frame->page();
       
    67 
       
    68     delete m_client;
       
    69     delete m_extension;
       
    70 }
       
    71 
       
    72 bool WebKitPart::openFile()
       
    73 {
       
    74     return true;
       
    75 }
       
    76 
       
    77 bool WebKitPart::openUrl(const KUrl& url)
       
    78 {
       
    79     if (!m_client)
       
    80         return false;
       
    81 
       
    82     emit started(0);
       
    83     m_client->openURL(KURL(url.toEncoded()));
       
    84     return true;
       
    85 }
       
    86 
       
    87 bool WebKitPart::closeUrl()
       
    88 {
       
    89     return m_frame->loader()->closeURL();
       
    90 }
       
    91 
       
    92 WebKitPart* WebKitPart::parentPart()
       
    93 {
       
    94     return qobject_cast<WebKitPart*>(parent());
       
    95 }
       
    96 
       
    97 Frame* WebKitPart::frame()
       
    98 {
       
    99     return m_frame.get();
       
   100 }
       
   101 
       
   102 void WebKitPart::initView(QWidget* parentWidget, GUIProfile prof)
       
   103 {
       
   104     if (prof == DefaultGUI)
       
   105         setXMLFile("WebKitPart.rc");
       
   106     else if (prof == BrowserViewGUI)
       
   107         setXMLFile("WebKitPartBrowser.rc");
       
   108 
       
   109     m_client = new WebKitPartClient(this);
       
   110  
       
   111     // Initialize WebCore in Qt platform mode...
       
   112     Page* page = new Page(new ChromeClientQt(), new ContextMenuClientQt(), new EditorClientQt(), new DragClientQt(), new InspectorClientQt());
       
   113     Frame* frame = new FrameQt(page, 0, m_client);
       
   114 
       
   115     m_frame = frame;
       
   116     frame->deref(); // Frames are created with a refcount of 1.  Release this ref, since we've assigned it to a RefPtr
       
   117 
       
   118     page->setMainFrame(frame);
       
   119 
       
   120     FrameView* frameView = new FrameView(frame);
       
   121     m_frameView = frameView;
       
   122     frameView->deref(); // FrameViews are created with a refcount of 1.  Release this ref, since we've assigned it to a RefPtr
       
   123 
       
   124     m_frame->setView(frameView);
       
   125     m_frameView->setParentWidget(parentWidget);
       
   126 
       
   127     m_frame->init();
       
   128 
       
   129     // Initialize KParts widget...
       
   130     setWidget(m_frame->view()->qwidget());
       
   131 }
       
   132 
       
   133 #include "WebKitPart.moc"