[WebKit-devel] [Patch] Add the "Frame" menu like Konqueror

Alain Laporte alain_laporte123 at yahoo.fr
Wed Oct 28 03:45:31 CET 2009


Hello,

I have patched WebKitKDE for to add the Frame menu like in Konqueror (the code for add the entries is an adaptation of this : http://websvn.kde.org/trunk/KDE/kdelibs/khtml/khtml_ext.cpp?view=markup ).

The entry to show the informations on the page isn't active because the window doesn't exists (i think...).

For reloading entry, i'm not sure of the code. I do a load() with the frame's URL, but the cache is maybe used.

Alain Laporte

Index: /mnt/sata_500_450_1/Dev/webkitkde/part/webkitpart_ext.h
===================================================================
--- /mnt/sata_500_450_1/Dev/webkitkde/part/webkitpart_ext.h (révision 1041446)
+++ /mnt/sata_500_450_1/Dev/webkitkde/part/webkitpart_ext.h (copie de travail)
@@ -63,7 +63,8 @@
     void slotFrameInWindow();
     void slotFrameInTab();
     void slotFrameInTop();
-
+    void slotReloadFrame();
+    
     void slotSaveImageAs();
     void slotSendImage();
     void slotCopyImage();
@@ -73,6 +74,7 @@
     void slotSaveLinkAs();
 
     void slotViewDocumentSource();
+    void slotViewFrameSource();
 
     void updateEditActions();
 
Index: /mnt/sata_500_450_1/Dev/webkitkde/part/webview.cpp
===================================================================
--- /mnt/sata_500_450_1/Dev/webkitkde/part/webview.cpp  (révision 1041446)
+++ /mnt/sata_500_450_1/Dev/webkitkde/part/webview.cpp  (copie de travail)
@@ -151,6 +151,63 @@
 void WebView::partActionPopupMenu(KParts::BrowserExtension::ActionGroupMap &partGroupMap)
 {
     QList<QAction *>partActions;
+    
+    if (d->result.frame()->parentFrame()) {
+        KActionMenu * menu = new KActionMenu(i18nc("@title:menu HTML frame/iframe", "Frame"), this);
+        
+        KAction * action = new KAction(i18n("Open in New &Window"), this);
+        d->actionCollection->addAction("frameinwindow", action);
+        action->setIcon(KIcon("window-new"));
+        connect(action, SIGNAL(triggered(bool)), d->part->browserExtension(), SLOT(slotFrameInWindow()));
+        menu->addAction(action);
+
+        action = new KAction(i18n("Open in &This Window"), this);
+        d->actionCollection->addAction("frameintop", action);
+        connect(action, SIGNAL(triggered(bool)), d->part->browserExtension(), SLOT(slotFrameInTop()));
+        menu->addAction(action);
+
+        action = new KAction(i18n("Open in &New Tab"), this);
+        d->actionCollection->addAction("frameintab", action);
+        action->setIcon(KIcon("tab-new"));
+        connect(action, SIGNAL(triggered(bool)), d->part->browserExtension(), SLOT(slotFrameInTab()));
+        menu->addAction(action);
+
+        action = new KAction(d->actionCollection);
+        action->setSeparator(true);
+        menu->addAction(action);
+        
+        action = new KAction(i18n("Reload Frame"), this);
+        d->actionCollection->addAction("reloadframe", action);
+        connect(action, SIGNAL(triggered(bool)), d->part->browserExtension(), SLOT(slotReloadFrame()));
+        menu->addAction(action);
+        
+        action = new KAction(i18n("Print Frame..."), this);
+        d->actionCollection->addAction("printFrame", action);
+        action->setIcon(KIcon("document-print-frame"));
+        connect(action, SIGNAL(triggered(bool)), d->part->browserExtension(), SLOT(print()));
+        menu->addAction(action);
+
+        action = new KAction(i18n("Save &Frame As..."), this);
+        d->actionCollection->addAction("saveFrame", action);
+        connect(action, SIGNAL(triggered(bool)), d->part->browserExtension(), SLOT(slotSaveFrame()));
+        menu->addAction(action);
+
+        action = new KAction(i18n("View Frame Source"), this);
+        d->actionCollection->addAction("viewFrameSource", action);
+        connect(action, SIGNAL(triggered(bool)), d->part->browserExtension(), SLOT(slotViewFrameSource()));
+        menu->addAction(action);
+///TODO Slot not implemented yet
+//         action = new KAction(i18n("View Frame Information"), this);
+//         d->actionCollection->addAction("viewFrameInfo", action);
+//         connect(action, SIGNAL(triggered(bool)), d->part->browserExtension(), SLOT(slotViewPageInfo()));
+        
+        action = new KAction(d->actionCollection);
+        action->setSeparator(true);
+        menu->addAction(action);
+    
+        partActions.append(menu);
+    }
+ 
     if (!d->result.imageUrl().isEmpty()) {
         QAction *action;
         if (!d->actionCollection->action("saveimageas")) {
Index: /mnt/sata_500_450_1/Dev/webkitkde/part/webkitpart_ext.cpp
===================================================================
--- /mnt/sata_500_450_1/Dev/webkitkde/part/webkitpart_ext.cpp   (révision 1041446)
+++ /mnt/sata_500_450_1/Dev/webkitkde/part/webkitpart_ext.cpp   (copie de travail)
@@ -237,35 +237,42 @@
 void WebKitBrowserExtension::slotFrameInWindow()
 {
     if (d->view) {
-        KParts::OpenUrlArguments args;// = d->m_khtml->arguments();
-        args.metaData()["referrer"] = d->view->contextMenuResult().linkText();
+        KParts::OpenUrlArguments args;
+        args.metaData()["referrer"] = d->view->url().toString();
         args.metaData()["forcenewwindow"] = "true";
-        emit createNewWindow(d->view->contextMenuResult().linkUrl(), args);
+        emit createNewWindow(d->view->page()->currentFrame()->url(), args);
     }
 }
 
 void WebKitBrowserExtension::slotFrameInTab()
 {
     if (d->view) {
-        KParts::OpenUrlArguments args;// = d->m_khtml->arguments();
-        args.metaData()["referrer"] = d->view->contextMenuResult().linkText();
-        KParts::BrowserArguments browserArgs;//( d->m_khtml->browserExtension()->browserArguments() );
+        KParts::OpenUrlArguments args;
+        args.metaData()["referrer"] = d->view->url().toString();
+        KParts::BrowserArguments browserArgs;
         browserArgs.setNewTab(true);
-        emit createNewWindow(d->view->contextMenuResult().linkUrl(), args, browserArgs);
+        emit createNewWindow(d->view->page()->currentFrame()->url(), args, browserArgs);
     }
 }
 
 void WebKitBrowserExtension::slotFrameInTop()
 {
     if (d->view) {
-        KParts::OpenUrlArguments args;// = d->m_khtml->arguments();
-        args.metaData()["referrer"] = d->view->contextMenuResult().linkText();
-        KParts::BrowserArguments browserArgs;//( d->m_khtml->browserExtension()->browserArguments() );
+        KParts::OpenUrlArguments args;
+        args.metaData()["referrer"] = d->view->url().toString();
+        KParts::BrowserArguments browserArgs;
         browserArgs.frameName = "_top";
-        emit openUrlRequest(d->view->contextMenuResult().linkUrl(), args, browserArgs);
+        emit openUrlRequest(d->view->page()->currentFrame()->url(), args, browserArgs);
     }
 }
 
+void WebKitBrowserExtension::slotReloadFrame()
+{
+    if (d->view) {
+        d->view->page()->currentFrame()->load(d->view->page()->currentFrame()->url()); ///NOTE I'm not sure this is the right way for releading correctly a frame...
+    }
+}
+
 void WebKitBrowserExtension::slotSaveImageAs()
 {
     if (d->view) {
@@ -367,4 +374,11 @@
     }
 }
 
+void WebKitBrowserExtension::slotViewFrameSource()
+{
+    if (d->view) {
+        KRun::runUrl(KUrl(d->view->page()->currentFrame()->url()), QLatin1String("text/plain"), d->view, false);
+    }
+}
+
 #include "webkitpart_ext.moc"



      


More information about the WebKit-devel mailing list