From de48295467098599ab1d80cb04a2de5236599b31 Mon Sep 17 00:00:00 2001
From: Jocelyn Turcotte <jocelyn.turcotte@digia.com>
Date: Wed, 19 Jun 2013 14:54:59 +0200
Subject: [PATCH] Use Q_PRIVATE_SLOT for QWebContentsViewPrivate.

Fix the gyp generator to allow including the moc file directly
in qwebcontentsview.cpp to be able to use Q_PRIVATE_SLOT
instead of having the private object deriving from QObject.

This also removes the use of MOCABLE_SOURCES whose entries were
added to 'sources' without moc being run on them first.
---
 build/qmake/mkspecs/features/functions.prf     |  7 +++++++
 build/qmake/mkspecs/features/gyp_generator.prf | 17 +++++++++++++----
 build/scripts/find-included-moc-files          | 13 +++++++++++++
 lib/qwebcontentsview.cpp                       |  6 ++++--
 lib/qwebcontentsview.h                         |  2 ++
 lib/qwebcontentsview_p.h                       |  8 ++------
 6 files changed, 41 insertions(+), 12 deletions(-)
 create mode 100755 build/scripts/find-included-moc-files

diff --git a/build/qmake/mkspecs/features/functions.prf b/build/qmake/mkspecs/features/functions.prf
index 40a125f14..48c23a7f4 100644
--- a/build/qmake/mkspecs/features/functions.prf
+++ b/build/qmake/mkspecs/features/functions.prf
@@ -27,6 +27,13 @@ defineReplace(findMocables) {
   return($$mocables)
 }
 
+defineReplace(findIncludedMocFiles) {
+  input = $$1
+  for (file, input): \
+      infiles += $$absolute_path($$file, $$_PRO_FILE_PWD_)
+  return($$system("$$QTWEBENGINE_ROOT/build/scripts/find-included-moc-files $$infiles"))
+}
+
 defineReplace(mocOutput) {
   out = $$1
   # The order is important, since the output of the second replace would end up accidentaly transformed by the first one
diff --git a/build/qmake/mkspecs/features/gyp_generator.prf b/build/qmake/mkspecs/features/gyp_generator.prf
index 2cb652331..b01a9bb6c 100644
--- a/build/qmake/mkspecs/features/gyp_generator.prf
+++ b/build/qmake/mkspecs/features/gyp_generator.prf
@@ -34,7 +34,7 @@ GYPI_FILE = $$replace(_PRO_FILE_, .pro$, .gyp)
 
 TARGET_TYPE = $$toGypTargetType()
 MOCABLE_HEADERS = $$findMocables($$HEADERS)
-MOCABLE_SOURCES = $$findMocables($$SOURCES)
+INCLUDED_MOC_FILES = $$findIncludedMocFiles($$SOURCES)
 
 GYPI_CONTENTS =  "{" \
                  "  'targets': [" \
@@ -74,20 +74,29 @@ GYPI_CONTENTS += "    ],"
                    "      }," \
                    "    },"
 }
+
+# Source files to compile
 GYPI_CONTENTS += "    'sources': ["
 for (sourcefile, SOURCES): GYPI_CONTENTS += "      '$$sourcefile',"
 for (headerfile, HEADERS): GYPI_CONTENTS += "      '$$headerfile',"
+
+# Add moc output files to compile that aren't included at the end of any other source
 MOC_OUT_PATH = $$absolute_path($$MOC_DIR, $$OUT_PWD)$${QMAKE_DIR_SEP}
-for (mocable_header, MOCABLE_HEADERS): GYPI_CONTENTS += "       '$$MOC_OUT_PATH$$mocOutput($$mocable_header)',"
-for (mocable_source, MOCABLE_SOURCES): GYPI_CONTENTS += "       '$$MOC_OUT_PATH$$mocOutput($$mocable_source)',"
+for (mocable_header, MOCABLE_HEADERS) {
+    !contains(INCLUDED_MOC_FILES, $$mocOutput($$mocable_header)) {
+        GYPI_CONTENTS += "       '$$MOC_OUT_PATH$$mocOutput($$mocable_header)',"
+    }
+}
+
 GYPI_CONTENTS += "    ],"
 !isEmpty(INCLUDEPATH) {
   GYPI_CONTENTS += "    'include_dirs': ["
   for (path, INCLUDEPATH): GYPI_CONTENTS += "      '$$path',"
   GYPI_CONTENTS += "    ],"
 }
+
 # Generate the actions for moc
-!isEmpty(MOCABLE_HEADERS)|!isEmpty(MOCABLE_SOURCES) {
+!isEmpty(MOCABLE_HEADERS) {
     GYPI_CONTENTS += "    'actions': ["
     for(header, MOCABLE_HEADERS): GYPI_CONTENTS += $$mocAction($$header)
     GYPI_CONTENTS += "    ],"
diff --git a/build/scripts/find-included-moc-files b/build/scripts/find-included-moc-files
new file mode 100755
index 000000000..e55f3824c
--- /dev/null
+++ b/build/scripts/find-included-moc-files
@@ -0,0 +1,13 @@
+#!/usr/bin/env python
+
+import re, sys, os
+
+includedMocs = set()
+for f in filter(os.path.isfile, sys.argv[1:]):
+    inBlockComment = False
+    for line in open(f).readlines():
+        m = re.search('#include "(moc_\w+.cpp)"', line)
+        if m:
+            includedMocs.add(m.group(1))
+for moc in includedMocs:
+    print moc
diff --git a/lib/qwebcontentsview.cpp b/lib/qwebcontentsview.cpp
index c8f5535dd..0920a5d7d 100644
--- a/lib/qwebcontentsview.cpp
+++ b/lib/qwebcontentsview.cpp
@@ -68,7 +68,7 @@ QWebContentsView::QWebContentsView()
     WebContentsDelegateQt* delegate = d->webContentsDelegate.get();
     connect(delegate, SIGNAL(titleChanged(const QString&)), this, SIGNAL(titleChanged(const QString&)));
     connect(delegate, SIGNAL(urlChanged(const QUrl&)), this, SIGNAL(urlChanged(const QUrl&)));
-    connect(delegate, SIGNAL(loadingStateChanged()), d, SLOT(loadingStateChanged()));
+    connect(delegate, SIGNAL(loadingStateChanged()), this, SLOT(_q_onLoadingStateChanged()));
 }
 
 QWebContentsView::~QWebContentsView()
@@ -147,7 +147,7 @@ QWebContentsViewPrivate::QWebContentsViewPrivate()
     contents_view->SetClient(this);
 }
 
-void QWebContentsViewPrivate::loadingStateChanged()
+void QWebContentsViewPrivate::_q_onLoadingStateChanged()
 {
     Q_Q(QWebContentsView);
     bool isLoading = webContentsDelegate->web_contents()->IsLoading();
@@ -168,3 +168,5 @@ RenderWidgetHostViewQtDelegate *QWebContentsViewPrivate::CreateRenderWidgetHostV
     q->layout()->addWidget(viewDelegate);
     return viewDelegate;
 }
+
+#include "moc_qwebcontentsview.cpp"
diff --git a/lib/qwebcontentsview.h b/lib/qwebcontentsview.h
index 2bea89a14..b9753c719 100644
--- a/lib/qwebcontentsview.h
+++ b/lib/qwebcontentsview.h
@@ -71,6 +71,8 @@ Q_SIGNALS:
 
 private:
     Q_DECLARE_PRIVATE(QWebContentsView)
+    Q_PRIVATE_SLOT(d_func(), void _q_onLoadingStateChanged());
+
     // Hides QObject::d_ptr allowing us to use the convenience macros.
     QScopedPointer<QWebContentsViewPrivate> d_ptr;
 };
diff --git a/lib/qwebcontentsview_p.h b/lib/qwebcontentsview_p.h
index c2009c7ac..20049587d 100644
--- a/lib/qwebcontentsview_p.h
+++ b/lib/qwebcontentsview_p.h
@@ -47,22 +47,18 @@
 #include "web_contents_view_qt.h"
 #include "web_engine_context.h"
 
-
 #include <QScopedPointer>
-#include <QObject>
 
-class QWebContentsViewPrivate : public QObject, public WebContentsViewQtClient
+class QWebContentsViewPrivate : public WebContentsViewQtClient
 {
     QWebContentsView *q_ptr;
     Q_DECLARE_PUBLIC(QWebContentsView)
-    Q_OBJECT
 public:
     QWebContentsViewPrivate();
 
     RenderWidgetHostViewQtDelegate* CreateRenderWidgetHostViewQtDelegate(content::RenderWidgetHostViewQt *view) Q_DECL_OVERRIDE;
 
-public Q_SLOTS:
-    void loadingStateChanged();
+    void _q_onLoadingStateChanged();
 
 public:
     scoped_refptr<WebEngineContext> context;
-- 
GitLab