diff options
-rw-r--r-- | lib/blinqpage.cpp | 107 | ||||
-rw-r--r-- | lib/lib.pro | 3 | ||||
-rw-r--r-- | lib/shell_qt.cpp | 204 | ||||
-rw-r--r-- | patches/0001-Temporary-patch-add-some-Qt-member-functions-to-Rend.patch | 150 |
4 files changed, 448 insertions, 16 deletions
diff --git a/lib/blinqpage.cpp b/lib/blinqpage.cpp index 2b921adb1..5c1011514 100644 --- a/lib/blinqpage.cpp +++ b/lib/blinqpage.cpp @@ -42,6 +42,7 @@ #include "skia/ext/platform_canvas.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebScreenInfo.h" +#include <QBackingStore> #include <QByteArray> #include <QWindow> #include <QCoreApplication> @@ -50,6 +51,7 @@ #include <QLabel> #include <QPainter> #include <QScreen> +#include <QResizeEvent> #include <qpa/qplatformnativeinterface.h> #include <X11/Xutil.h> @@ -181,6 +183,70 @@ inline net::URLRequestContext* ResourceContext::GetRequestContext() return context->GetRequestContext()->GetURLRequestContext(); } +class RasterWindow : public QWindow +{ +public: + RasterWindow(QWindow *parent = 0) + : QWindow(parent) + , m_update_pending(false) + { + m_backingStore = new QBackingStore(this); + create(); + } + + void blitPixmap(const QRect& rect, const QPixmap& pixmap) + { + if (!isExposed()) + return; + + m_backingStore->beginPaint(rect); + QPaintDevice *device = m_backingStore->paintDevice(); + if (device) { + QPainter painter(device); + + painter.drawPixmap(0, 0, width(), height(), pixmap); + } + m_backingStore->endPaint(); + m_backingStore->flush(rect); + } + + void renderNow() + { + if (!isExposed()) + return; + + } + +protected: + bool event(QEvent *event) + { + if (event->type() == QEvent::UpdateRequest) { + m_update_pending = false; + renderNow(); + return true; + } + return QWindow::event(event); + } + + void resizeEvent(QResizeEvent *resizeEvent) + { + m_backingStore->resize(resizeEvent->size()); + if (isExposed()) + renderNow(); + } + + void exposeEvent(QExposeEvent *) + { + if (isExposed()) { + renderNow(); + } + } +private: + QPixmap m_pixmap; + QBackingStore *m_backingStore; + bool m_update_pending; +}; + class BackingStoreQt : public QLabel , public content::BackingStore { @@ -191,7 +257,7 @@ public: { // FIXME: remove QLabel inheritance resize(size.width(), size.height()); - show(); + // show(); setWindowTitle(QStringLiteral("BackingStoreQt")); // FISME: remove QLabel inheritance } @@ -279,6 +345,18 @@ public: return true; } + void paintToQWindow(const gfx::Rect& r, QWindow* surface) + { + // OpenGL painting is currently not supported. + if (surface->surfaceType() != QSurface::RasterSurface) { + fprintf(stderr, "OpenGL painting is currently NOT supported."); + return; + } + + RasterWindow* rasterWindow = static_cast<RasterWindow*>(surface); + rasterWindow->blitPixmap(QRect(r.x(), r.y(), r.width(), r.height()), m_pixelBuffer); + } + private: QPainter m_painter; QPixmap m_pixelBuffer; @@ -306,27 +384,17 @@ public: virtual void InitAsChild(gfx::NativeView parent_view) { - m_view = new QWindow; - // FIXME: should this have backing store size? - m_view->resize(200, 200); - m_view->show(); + m_view = new RasterWindow; } virtual void InitAsPopup(content::RenderWidgetHostView*, const gfx::Rect&) { - m_view = new QWindow; - // FIXME: should this have backing store size? - m_view->resize(200, 200); - m_view->show(); + m_view = new RasterWindow; } virtual void InitAsFullscreen(content::RenderWidgetHostView*) { - m_view = new QWindow; - // FIXME: should this have backing store size? - m_view->resize(200, 200); - m_view->setWindowState(Qt::WindowFullScreen); - m_view->show(); + m_view = new RasterWindow; } virtual content::RenderWidgetHost* GetRenderWidgetHost() const @@ -369,6 +437,12 @@ public: // return m_view; return gfx::NativeView(); } + + virtual QWindow* GetNativeViewQt() const OVERRIDE + { + return m_view; + } + virtual gfx::NativeViewId GetNativeViewId() const { QT_NOT_YET_IMPLEMENTED @@ -636,7 +710,10 @@ public: private: void Paint(const gfx::Rect& scroll_rect) { - // FIXME: implement painting. + bool force_create = !m_host->empty(); + BackingStoreQt* backing_store = static_cast<BackingStoreQt*>(m_host->GetBackingStore(force_create)); + if (backing_store && m_view) + backing_store->paintToQWindow(scroll_rect, m_view); } bool IsPopup() const diff --git a/lib/lib.pro b/lib/lib.pro index 56a67244e..3c6a6e951 100644 --- a/lib/lib.pro +++ b/lib/lib.pro @@ -17,7 +17,8 @@ CONFIG(release, debug|release): DEFINES += NDEBUG QT += gui-private widgets SOURCES = \ - blinqpage.cpp + blinqpage.cpp \ + shell_qt.cpp HEADERS = \ blinqpage.h diff --git a/lib/shell_qt.cpp b/lib/shell_qt.cpp new file mode 100644 index 000000000..af1164591 --- /dev/null +++ b/lib/shell_qt.cpp @@ -0,0 +1,204 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "content/shell/shell.h" + +#include <gdk/gdkkeysyms.h> +#include <gtk/gtk.h> + +#include "base/logging.h" +#include "base/strings/string_piece.h" +#include "base/utf_string_conversions.h" +#include "content/public/browser/browser_context.h" +#include "content/public/browser/native_web_keyboard_event.h" +#include "content/public/browser/web_contents.h" +#include "content/public/browser/web_contents_view.h" +#include "content/public/common/renderer_preferences.h" +#include "content/shell/shell_browser_context.h" +#include "content/shell/shell_content_browser_client.h" + +#include <QWindow> +#include <QLineEdit> +#include <QWidget> +#include <QVBoxLayout> + +namespace content { + +void Shell::PlatformInitialize(const gfx::Size& default_window_size) +{ +} + +void Shell::PlatformCleanUp() +{ + // Nothing to clean up; GTK will clean up the widgets shortly after. +} + +void Shell::PlatformEnableUIControl(UIControl control, bool is_enabled) +{ + // if (headless_) + // return; + + // GtkToolItem* item = NULL; + // switch (control) { + // case BACK_BUTTON: + // item = back_button_; + // break; + // case FORWARD_BUTTON: + // item = forward_button_; + // break; + // case STOP_BUTTON: + // item = stop_button_; + // break; + // default: + // NOTREACHED() << "Unknown UI control"; + // return; + // } + // gtk_widget_set_sensitive(GTK_WIDGET(item), is_enabled); +} + +void Shell::PlatformSetAddressBarURL(const GURL& url) +{ + if (headless_) + return; + + gtk_entry_set_text(GTK_ENTRY(url_edit_view_), url.spec().c_str()); +} + + +void Shell::PlatformSetIsLoading(bool loading) +{ + if (headless_) + return; + + if (loading) + gtk_spinner_start(GTK_SPINNER(spinner_)); + else + gtk_spinner_stop(GTK_SPINNER(spinner_)); +} + +void Shell::PlatformCreateWindow(int width, int height) { + SizeTo(width, height); + + if (headless_) + return; + + if (!m_window) { + m_window = new QWidget; + m_window->setGeometry(100,100, width, height); + + QVBoxLayout* layout = new QVBoxLayout; + + // Create a widget based address bar. + QLineEdit* lineEdit = new QLineEdit; + layout->addWidget(lineEdit); + + m_window->setLayout(layout); + m_window->show(); + } +} + +void Shell::PlatformSetContents() +{ + if (headless_) + return; + + WebContentsView* content_view = web_contents_->GetView(); + + QWidget* container = QWidget::createWindowContainer(content_view->GetNativeViewQt()); + m_window->layout()->addWidget(container); +} + +void Shell::SizeTo(int width, int height) { + content_width_ = width; + content_height_ = height; + if (web_contents_) { + gtk_widget_set_size_request(web_contents_->GetView()->GetNativeView(), + width, height); + } +} + +void Shell::PlatformResizeSubViews() +{ + SizeTo(content_width_, content_height_); +} + +void Shell::Close() +{ + if (headless_) { + delete this; + return; + } + + gtk_widget_destroy(GTK_WIDGET(window_)); +} + +void Shell::OnBackButtonClicked(GtkWidget* widget) +{ + GoBackOrForward(-1); +} + +void Shell::OnForwardButtonClicked(GtkWidget* widget) +{ + GoBackOrForward(1); +} + +void Shell::OnReloadButtonClicked(GtkWidget* widget) +{ + Reload(); +} + +void Shell::OnStopButtonClicked(GtkWidget* widget) +{ + Stop(); +} + +void Shell::OnURLEntryActivate(GtkWidget* entry) +{ + const gchar* str = gtk_entry_get_text(GTK_ENTRY(entry)); + GURL url(str); + if (!url.has_scheme()) + url = GURL(std::string("http://") + std::string(str)); + LoadURL(GURL(url)); +} + +// Callback for when the main window is destroyed. +gboolean Shell::OnWindowDestroyed(GtkWidget* window) +{ + delete this; + return FALSE; // Don't stop this message. +} + +gboolean Shell::OnCloseWindowKeyPressed(GtkAccelGroup* accel_group, GObject* acceleratable, guint keyval, GdkModifierType modifier) +{ + gtk_widget_destroy(GTK_WIDGET(window_)); + return TRUE; +} + +gboolean Shell::OnNewWindowKeyPressed(GtkAccelGroup* accel_group, GObject* acceleratable, guint keyval, GdkModifierType modifier) +{ + ShellBrowserContext* browser_context = ShellContentBrowserClient::Get()->browser_context(); + Shell::CreateNewWindow(browser_context, + GURL(), + NULL, + MSG_ROUTING_NONE, + gfx::Size()); + return TRUE; +} + +gboolean Shell::OnHighlightURLView(GtkAccelGroup* accel_group, GObject* acceleratable, guint keyval, GdkModifierType modifier) +{ + gtk_widget_grab_focus(GTK_WIDGET(url_edit_view_)); + return TRUE; +} + +void Shell::PlatformSetTitle(const string16& title) +{ + if (headless_) + return; + + std::string title_utf8 = UTF16ToUTF8(title); + gtk_window_set_title(GTK_WINDOW(window_), title_utf8.c_str()); +} + +} // namespace content diff --git a/patches/0001-Temporary-patch-add-some-Qt-member-functions-to-Rend.patch b/patches/0001-Temporary-patch-add-some-Qt-member-functions-to-Rend.patch new file mode 100644 index 000000000..8ab997e13 --- /dev/null +++ b/patches/0001-Temporary-patch-add-some-Qt-member-functions-to-Rend.patch @@ -0,0 +1,150 @@ +From 30b08c80f4b17fada28703f2e15c98207875e771 Mon Sep 17 00:00:00 2001 +From: Zeno Albisser <zeno@webkit.org> +Date: Tue, 14 May 2013 10:52:58 +0200 +Subject: [PATCH] Temporary patch: add some Qt member functions to + RenderWidgetHostView. + +This patch should be removed again, once we manage to avoid the use of +GetNativeView() or we manage to make gfx::NativeView a QWindow.w +--- + content/browser/renderer_host/render_widget_host_view_gtk.h | 1 + + content/browser/web_contents/web_contents_view_gtk.cc | 7 +++++++ + content/browser/web_contents/web_contents_view_gtk.h | 1 + + content/content_shell.gypi | 1 - + content/public/browser/render_widget_host_view.h | 3 +++ + content/public/browser/web_contents_view.h | 2 ++ + content/shell/shell.cc | 1 + + content/shell/shell.h | 2 ++ + 8 files changed, 17 insertions(+), 1 deletion(-) + +diff --git a/content/browser/renderer_host/render_widget_host_view_gtk.h b/content/browser/renderer_host/render_widget_host_view_gtk.h +index 46daaac..271ad19 100644 +--- a/content/browser/renderer_host/render_widget_host_view_gtk.h ++++ b/content/browser/renderer_host/render_widget_host_view_gtk.h +@@ -55,6 +55,7 @@ class CONTENT_EXPORT RenderWidgetHostViewGtk + virtual RenderWidgetHost* GetRenderWidgetHost() const OVERRIDE; + virtual void SetSize(const gfx::Size& size) OVERRIDE; + virtual void SetBounds(const gfx::Rect& rect) OVERRIDE; ++ virtual gfx::NativeView GetNativeViewGTK() const { return gfx::NativeView(); }; + virtual gfx::NativeView GetNativeView() const OVERRIDE; + virtual gfx::NativeViewId GetNativeViewId() const OVERRIDE; + virtual gfx::NativeViewAccessible GetNativeViewAccessible() OVERRIDE; +diff --git a/content/browser/web_contents/web_contents_view_gtk.cc b/content/browser/web_contents/web_contents_view_gtk.cc +index 9cb9212..8202258 100644 +--- a/content/browser/web_contents/web_contents_view_gtk.cc ++++ b/content/browser/web_contents/web_contents_view_gtk.cc +@@ -115,6 +115,13 @@ gfx::NativeView WebContentsViewGtk::GetNativeView() const { + return expanded_.get(); + } + ++QWindow* WebContentsViewGtk::GetNativeViewQt() const { ++ RenderWidgetHostView* rwhv = web_contents_->GetRenderWidgetHostView(); ++ if (!rwhv) ++ return NULL; ++ return rwhv->GetNativeViewQt(); ++} ++ + gfx::NativeView WebContentsViewGtk::GetContentNativeView() const { + RenderWidgetHostView* rwhv = web_contents_->GetRenderWidgetHostView(); + if (!rwhv) +diff --git a/content/browser/web_contents/web_contents_view_gtk.h b/content/browser/web_contents/web_contents_view_gtk.h +index a5a15a2..f4a5a93 100644 +--- a/content/browser/web_contents/web_contents_view_gtk.h ++++ b/content/browser/web_contents/web_contents_view_gtk.h +@@ -46,6 +46,7 @@ class CONTENT_EXPORT WebContentsViewGtk + // WebContentsView implementation -------------------------------------------- + + virtual gfx::NativeView GetNativeView() const OVERRIDE; ++ virtual QWindow* GetNativeViewQt() const OVERRIDE; + virtual gfx::NativeView GetContentNativeView() const OVERRIDE; + virtual gfx::NativeWindow GetTopLevelNativeWindow() const OVERRIDE; + virtual void GetContainerBounds(gfx::Rect* out) const OVERRIDE; +diff --git a/content/content_shell.gypi b/content/content_shell.gypi +index 1bf233b..fc6bf96 100644 +--- a/content/content_shell.gypi ++++ b/content/content_shell.gypi +@@ -82,7 +82,6 @@ + 'shell/shell.h', + 'shell/shell_android.cc', + 'shell/shell_aura.cc', +- 'shell/shell_gtk.cc', + 'shell/shell_mac.mm', + 'shell/shell_win.cc', + 'shell/shell_application_mac.h', +diff --git a/content/public/browser/render_widget_host_view.h b/content/public/browser/render_widget_host_view.h +index b881748..3eccb42 100644 +--- a/content/public/browser/render_widget_host_view.h ++++ b/content/public/browser/render_widget_host_view.h +@@ -18,6 +18,7 @@ + #endif + + class GURL; ++class QWindow; + + namespace gfx { + class Rect; +@@ -76,7 +77,9 @@ class CONTENT_EXPORT RenderWidgetHostView { + + // Retrieves the native view used to contain plugins and identify the + // renderer in IPC messages. ++ virtual gfx::NativeView GetNativeViewGTK() const { return 0; }; + virtual gfx::NativeView GetNativeView() const = 0; ++ virtual QWindow* GetNativeViewQt() const { return 0; } + virtual gfx::NativeViewId GetNativeViewId() const = 0; + virtual gfx::NativeViewAccessible GetNativeViewAccessible() = 0; + +diff --git a/content/public/browser/web_contents_view.h b/content/public/browser/web_contents_view.h +index d0a7309..9cfddb4 100644 +--- a/content/public/browser/web_contents_view.h ++++ b/content/public/browser/web_contents_view.h +@@ -15,6 +15,7 @@ + #include "ui/gfx/size.h" + + struct WebDropData; ++class QWindow; + + namespace content { + +@@ -27,6 +28,7 @@ class CONTENT_EXPORT WebContentsView { + + // Returns the native widget that contains the contents of the tab. + virtual gfx::NativeView GetNativeView() const = 0; ++ virtual QWindow* GetNativeViewQt() const { return 0; } + + // Returns the native widget with the main content of the tab (i.e. the main + // render view host, though there may be many popups in the tab as children of +diff --git a/content/shell/shell.cc b/content/shell/shell.cc +index 5eac7af..3e4bd60 100644 +--- a/content/shell/shell.cc ++++ b/content/shell/shell.cc +@@ -46,6 +46,7 @@ Shell::Shell(WebContents* web_contents) + : devtools_frontend_(NULL), + is_fullscreen_(false), + window_(NULL), ++ m_window(NULL), + url_edit_view_(NULL), + #if defined(OS_WIN) && !defined(USE_AURA) + default_edit_wnd_proc_(0), +diff --git a/content/shell/shell.h b/content/shell/shell.h +index 736bd3f..4d028cf 100644 +--- a/content/shell/shell.h ++++ b/content/shell/shell.h +@@ -37,6 +37,7 @@ class ViewsDelegate; + } + #endif + ++class QWidget; + class GURL; + namespace content { + +@@ -219,6 +220,7 @@ class Shell : public WebContentsDelegate, + bool is_fullscreen_; + + gfx::NativeWindow window_; ++ QWidget* m_window; + gfx::NativeEditView url_edit_view_; + + // Notification manager +-- +1.8.1.2 + |