Home | History | Annotate | Download | only in qt
      1 /*
      2  * Copyright (C) 2010 Apple Inc. All rights reserved.
      3  * Copyright (C) 2010 University of Szeged. All rights reserved.
      4  *
      5  * Redistribution and use in source and binary forms, with or without
      6  * modification, are permitted provided that the following conditions
      7  * are met:
      8  * 1. Redistributions of source code must retain the above copyright
      9  *    notice, this list of conditions and the following disclaimer.
     10  * 2. Redistributions in binary form must reproduce the above copyright
     11  *    notice, this list of conditions and the following disclaimer in the
     12  *    documentation and/or other materials provided with the distribution.
     13  *
     14  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     15  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     16  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     17  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     18  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     19  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
     20  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     21  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     22  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     24  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     25  */
     26 
     27 #include "config.h"
     28 
     29 #include "PlatformWebView.h"
     30 #include "qgraphicswkview.h"
     31 #include "qwkcontext.h"
     32 #include <QtGui>
     33 
     34 namespace WTR {
     35 
     36 class WebView : public QGraphicsView {
     37 public:
     38     WebView(WKContextRef);
     39 
     40     QGraphicsWKView* wkView() const { return m_item; }
     41 
     42     virtual ~WebView() { delete m_item; }
     43 
     44 private:
     45     QGraphicsWKView* m_item;
     46 };
     47 
     48 WebView::WebView(WKContextRef contextRef)
     49     : QGraphicsView()
     50     , m_item(new QGraphicsWKView(new QWKContext(contextRef, this)))
     51 {
     52     setScene(new QGraphicsScene(this));
     53     scene()->addItem(m_item);
     54 }
     55 
     56 PlatformWebView::PlatformWebView(WKContextRef contextRef, WKPageGroupRef)
     57     : m_view(new WebView(contextRef))
     58     , m_window(new QMainWindow())
     59 {
     60     m_view->setParent(m_window);
     61     m_window->setCentralWidget(m_view);
     62     m_window->setGeometry(0, 0, 800, 600);
     63 }
     64 
     65 PlatformWebView::~PlatformWebView()
     66 {
     67     delete m_window;
     68 }
     69 
     70 void PlatformWebView::resizeTo(unsigned width, unsigned height)
     71 {
     72     m_window->resize(width, height);
     73 }
     74 
     75 WKPageRef PlatformWebView::page()
     76 {
     77     return m_view->wkView()->page()->pageRef();
     78 }
     79 
     80 void PlatformWebView::focus()
     81 {
     82     m_view->setFocus(Qt::OtherFocusReason);
     83 }
     84 
     85 WKRect PlatformWebView::windowFrame()
     86 {
     87     // Implement.
     88 
     89     WKRect wkFrame;
     90     wkFrame.origin.x = 0;
     91     wkFrame.origin.y = 0;
     92     wkFrame.size.width = 0;
     93     wkFrame.size.height = 0;
     94     return wkFrame;
     95 }
     96 
     97 void PlatformWebView::setWindowFrame(WKRect)
     98 {
     99     // Implement.
    100 }
    101 
    102 } // namespace WTR
    103