[haiku-webkit-commits] r289 - in webkit/trunk: WebCore/platform WebCore/platform/haiku WebKit/haiku/API WebKit/haiku/WebCoreSupport

  • From: webkit@xxxxxxxxxxxxxxx
  • To: haiku-webkit-commits@xxxxxxxxxxxxx
  • Date: Fri, 05 Mar 2010 18:05:56 +0000

Author: stippi
Date: Fri Mar  5 18:05:56 2010
New Revision: 289
URL: http://mmlr.dyndns.org/changeset/289

Log:
Should be two separate commits, but has changes in BWebPage for both:
 * Moved page creation from both ChromeClientHaiku and FrameLoaderClientHaiku
   into BWebPage. This resolves sub-frames being unable to create new pages,
   since they are not directly connected to a listener messenger. And creating
   new pages via the ChromeClient now also uses the respective implementation
   for embedding the new views, i.e. into new tabs in WebPositive.
 * Completed the ContextMenu implementation. BWebPage is supposed to look for
   secondary clicks, and forward this as context menu event. Custom context 
menus
   like on maps.google.com are also supported. Changed the ContextMenuReceiver
   class to become useful, in the form of a BHandler that is attached to the
   application. Beware: Generating context menus for editable context currently
   crashes WebPositive. Other stuff like opening links in new tabs, or copying
   the link target to the clipboard works as expected.

Modified:
   webkit/trunk/WebCore/platform/ContextMenu.h
   webkit/trunk/WebCore/platform/haiku/ContextMenuHaiku.cpp
   webkit/trunk/WebKit/haiku/API/WebPage.cpp
   webkit/trunk/WebKit/haiku/API/WebPage.h
   webkit/trunk/WebKit/haiku/WebCoreSupport/ChromeClientHaiku.cpp
   webkit/trunk/WebKit/haiku/WebCoreSupport/ContextMenuClientHaiku.cpp
   webkit/trunk/WebKit/haiku/WebCoreSupport/FrameLoaderClientHaiku.cpp

Modified: webkit/trunk/WebCore/platform/ContextMenu.h
==============================================================================
--- webkit/trunk/WebCore/platform/ContextMenu.h Fri Mar  5 17:59:09 2010        
(r288)
+++ webkit/trunk/WebCore/platform/ContextMenu.h Fri Mar  5 18:05:56 2010        
(r289)
@@ -83,6 +83,10 @@
 #else
         PlatformMenuDescription m_platformDescription;
 #endif
+#if PLATFORM(HAIKU)
+        class ContextMenuHandler;
+        ContextMenuHandler* m_menuHandler;
+#endif
     };
 
 }

Modified: webkit/trunk/WebCore/platform/haiku/ContextMenuHaiku.cpp
==============================================================================
--- webkit/trunk/WebCore/platform/haiku/ContextMenuHaiku.cpp    Fri Mar  5 
17:59:09 2010        (r288)
+++ webkit/trunk/WebCore/platform/haiku/ContextMenuHaiku.cpp    Fri Mar  5 
18:05:56 2010        (r289)
@@ -32,31 +32,32 @@
 #include "Document.h"
 #include "Frame.h"
 #include "FrameView.h"
-#include <Looper.h>
-#include <Menu.h>
+#include <Application.h>
+#include <Handler.h>
+#include <MenuItem.h>
 #include <Message.h>
+#include <Messenger.h>
+#include <PopUpMenu.h>
 #include <wtf/Assertions.h>
-
+#include <stdio.h>
 
 namespace WebCore {
 
-// FIXME: This class isn't used yet
-class ContextMenuReceiver : public BLooper {
+class ContextMenu::ContextMenuHandler : public BHandler {
 public:
-    ContextMenuReceiver(ContextMenu* menu)
-        : BLooper("context_menu_receiver")
+    ContextMenuHandler(ContextMenu* menu)
+        : BHandler("context menu handler")
         , m_menu(menu)
-        , m_result(-1)
     {
     }
 
-    void HandleMessage(BMessage* msg)
+    virtual void MessageReceived(BMessage* message)
     {
-        m_result = msg->what;
-        if (m_result != -1) {
-            BMenuItem* item = 
m_menu->platformDescription()->FindItem(m_result);
+        int result = message->what;
+        if (result != -1) {
+            BMenuItem* item = m_menu->platformDescription()->FindItem(result);
             if (!item) {
-                printf("Error: Context menu item with code %i not found!\n", 
m_result);
+                printf("Error: Context menu item with code %i not found!\n", 
result);
                 return;
             }
             ContextMenuItem cmItem(item);
@@ -65,34 +66,34 @@
         }
     }
 
-    int Result()
-    {
-        return m_result;
-    }
-
 private:
     ContextMenu* m_menu;
-    int m_result;
 };
 
 ContextMenu::ContextMenu(const HitTestResult& result)
     : m_hitTestResult(result)
-    , m_platformDescription(new BMenu("context_menu"))
+    , m_platformDescription(new BPopUpMenu("context_menu"))
+    , m_menuHandler(new ContextMenuHandler(this))
 {
+       if (be_app->Lock()) {
+               be_app->AddHandler(m_menuHandler);
+               be_app->Unlock();
+       }
 }
 
 ContextMenu::~ContextMenu()
 {
+       if (be_app->Lock()) {
+               be_app->RemoveHandler(m_menuHandler);
+               be_app->Unlock();
+       }
+       delete m_menuHandler;
     delete m_platformDescription;
 }
 
 void ContextMenu::appendItem(ContextMenuItem& item)
 {
-    checkOrEnableIfNeeded(item);
-
-    BMenuItem* menuItem = item.releasePlatformDescription();
-    if (menuItem)
-        m_platformDescription->AddItem(menuItem);
+       insertItem(itemCount(), item);
 }
 
 unsigned ContextMenu::itemCount() const
@@ -105,8 +106,10 @@
     checkOrEnableIfNeeded(item);
 
     BMenuItem* menuItem = item.releasePlatformDescription();
-    if (menuItem)
+    if (menuItem) {
         m_platformDescription->AddItem(menuItem, position);
+        menuItem->SetTarget(BMessenger(m_menuHandler));
+    }
 }
 
 PlatformMenuDescription ContextMenu::platformDescription() const
@@ -116,11 +119,19 @@
 
 void ContextMenu::setPlatformDescription(PlatformMenuDescription menu)
 {
-    if (static_cast<BMenu*>(menu) == m_platformDescription)
+    if (menu == m_platformDescription)
         return;
 
     delete m_platformDescription;
-    m_platformDescription = static_cast<BMenu*>(menu);
+    m_platformDescription = menu;
+}
+
+PlatformMenuDescription ContextMenu::releasePlatformDescription()
+{
+    PlatformMenuDescription description = m_platformDescription;
+    m_platformDescription = 0;
+
+    return description;
 }
 
 } // namespace WebCore

Modified: webkit/trunk/WebKit/haiku/API/WebPage.cpp
==============================================================================
--- webkit/trunk/WebKit/haiku/API/WebPage.cpp   Fri Mar  5 17:59:09 2010        
(r288)
+++ webkit/trunk/WebKit/haiku/API/WebPage.cpp   Fri Mar  5 18:05:56 2010        
(r289)
@@ -33,7 +33,9 @@
 #include "AtomicString.h"
 #include "Cache.h"
 #include "ChromeClientHaiku.h"
+#include "ContextMenu.h"
 #include "ContextMenuClientHaiku.h"
+#include "ContextMenuController.h"
 #include "Cursor.h"
 #include "DOMTimer.h"
 #include "DragClientHaiku.h"
@@ -71,6 +73,7 @@
 #include <Message.h>
 #include <MessageQueue.h>
 #include <Messenger.h>
+#include <PopUpMenu.h>
 #include <Region.h>
 #include <Window.h>
 
@@ -402,6 +405,28 @@
     return m_page;
 }
 
+WebCore::Page* BWebPage::createNewPage(BRect frame, bool modalDialog, bool 
resizable)
+{
+    // Creating the BWebView in the application thread is exactly what we need 
anyway.
+       BWebView* view = new BWebView("web view");
+       BWebPage* page = view->WebPage();
+
+    BMessage message(NEW_PAGE_CREATED);
+    message.AddPointer("view", view);
+    if (frame.IsValid())
+        message.AddRect("frame", frame);
+    if (modalDialog)
+        message.AddBool("modal", modalDialog);
+    if (!resizable)
+        message.AddBool("resizable", resizable);
+
+    // Block until some window has embedded this view.
+    BMessage reply;
+    m_listener.SendMessage(&message, &reply);
+
+    return page->page();
+}
+
 BRect BWebPage::windowBounds()
 {
     BRect bounds;
@@ -911,6 +936,28 @@
     PlatformMouseEvent event(message);
     switch (message->what) {
     case B_MOUSE_DOWN:
+        // Handle context menus, if necessary.
+        if (event.button() == RightButton) {
+            m_page->contextMenuController()->clearContextMenu();
+
+            WebCore::Frame* focusedFrame = 
m_page->focusController()->focusedOrMainFrame();
+            focusedFrame->eventHandler()->sendContextMenuEvent(event);
+            // If the web page implements it's own context menu handling, then
+            // the contextMenu() pointer will be zero. In this case, we should
+            // also swallow the event.
+            ContextMenu* contextMenu = 
m_page->contextMenuController()->contextMenu();
+            if (contextMenu) {
+               // ContextMenuHaiku really creates BPopUpMenu instances.
+               BPopUpMenu* popupMenu = static_cast<BPopUpMenu*>(
+                       contextMenu->platformDescription());
+               if (popupMenu) {
+                       BPoint screenLocation(event.globalX(), event.globalY());
+                   popupMenu->Go(screenLocation, true, true, true);
+               }
+            }
+            break;
+       }
+       // Handle regular mouse events.
         frame->eventHandler()->handleMousePressEvent(event);
         break;
     case B_MOUSE_UP:

Modified: webkit/trunk/WebKit/haiku/API/WebPage.h
==============================================================================
--- webkit/trunk/WebKit/haiku/API/WebPage.h     Fri Mar  5 17:59:09 2010        
(r288)
+++ webkit/trunk/WebKit/haiku/API/WebPage.h     Fri Mar  5 18:05:56 2010        
(r289)
@@ -138,6 +138,9 @@
 
        WebCore::Page* page() const;
 
+       WebCore::Page* createNewPage(BRect frame = BRect(),
+               bool modalDialog = false, bool resizable = true);
+
        BRect windowBounds();
        void setWindowBounds(const BRect& bounds);
        BRect viewBounds();

Modified: webkit/trunk/WebKit/haiku/WebCoreSupport/ChromeClientHaiku.cpp
==============================================================================
--- webkit/trunk/WebKit/haiku/WebCoreSupport/ChromeClientHaiku.cpp      Fri Mar 
 5 17:59:09 2010        (r288)
+++ webkit/trunk/WebKit/haiku/WebCoreSupport/ChromeClientHaiku.cpp      Fri Mar 
 5 18:05:56 2010        (r289)
@@ -130,28 +130,13 @@
         frame.top = features.y;
         frame.right = features.x + features.width - 1;
         frame.bottom = features.y + features.height - 1;
-    } else
-        frame.Set(50, 50, 449, 449);
-
-    window_look look = B_TITLED_WINDOW_LOOK;
-    window_feel feel = B_NORMAL_WINDOW_FEEL;
-    if (features.dialog) {
-        look = B_MODAL_WINDOW_LOOK;
-        feel = B_MODAL_APP_WINDOW_FEEL;
     }
-    uint32 flags = B_ASYNCHRONOUS_CONTROLS | B_AUTO_UPDATE_SIZE_LIMITS;
-    if (!features.resizable)
-        flags |= B_NOT_ZOOMABLE | B_NOT_RESIZABLE;
-
-    BWebWindow* window = new BWebWindow(frame, "WebKit", look, feel, flags);
-    BWebView* view = new BWebView("web view");
-    window->AddChild(view);
-    window->SetCurrentWebView(view);
-    window->Show();
 
-    view->LoadURL(BString(request.resourceRequest().url().string()));
+       WebCore::Page* page = m_webPage->createNewPage(frame, features.dialog, 
features.resizable);
+    if (page)
+        page->mainFrame()->loader()->load(request.resourceRequest(), false);
 
-    return view->WebPage()->page();
+    return page;
 }
 
 void ChromeClientHaiku::show()

Modified: webkit/trunk/WebKit/haiku/WebCoreSupport/ContextMenuClientHaiku.cpp
==============================================================================
--- webkit/trunk/WebKit/haiku/WebCoreSupport/ContextMenuClientHaiku.cpp Fri Mar 
 5 17:59:09 2010        (r288)
+++ webkit/trunk/WebKit/haiku/WebCoreSupport/ContextMenuClientHaiku.cpp Fri Mar 
 5 18:05:56 2010        (r289)
@@ -41,6 +41,11 @@
 
 PlatformMenuDescription 
ContextMenuClientHaiku::getCustomMenuFromDefaultItems(ContextMenu* menu)
 {
+       // This method appears to allow some form of filtering. I.e. we get the
+       // current platform menu, have the chance to mess with it, including
+       // the addition of some items, and return the changed menu. In
+       // ContextMenuController, what we return here is immediately passed back
+       // into menu->setPlatformDescription().
     return menu->platformDescription();
 }
 

Modified: webkit/trunk/WebKit/haiku/WebCoreSupport/FrameLoaderClientHaiku.cpp
==============================================================================
--- webkit/trunk/WebKit/haiku/WebCoreSupport/FrameLoaderClientHaiku.cpp Fri Mar 
 5 17:59:09 2010        (r288)
+++ webkit/trunk/WebKit/haiku/WebCoreSupport/FrameLoaderClientHaiku.cpp Fri Mar 
 5 18:05:56 2010        (r289)
@@ -412,24 +412,11 @@
 
 Frame* FrameLoaderClientHaiku::dispatchCreatePage()
 {
-if (!m_messenger.IsValid()) {
-printf("FrameLoaderClientHaiku::dispatchCreatePage() - can't embed new 
page!!\n");
-return 0;
-}
-    // TODO: This doesn't work for sub-frames without valid BMessenger!
-
-    // Creating the BWebView in the application thread is exactly what we need 
anyway.
-       BWebView* view = new BWebView("web view");
-       BWebPage* page = view->WebPage();
-
-    BMessage message(NEW_PAGE_CREATED);
-    message.AddPointer("view", view);
+       WebCore::Page* page = m_webPage->createNewPage();
+       if (page)
+               return page->mainFrame();
 
-    // Block until some window has embedded this view.
-    BMessage reply;
-    m_messenger.SendMessage(&message, &reply);
-
-    return page->page()->mainFrame();
+    return 0;
 }
 
 void FrameLoaderClientHaiku::dispatchShow()

Other related posts:

  • » [haiku-webkit-commits] r289 - in webkit/trunk: WebCore/platform WebCore/platform/haiku WebKit/haiku/API WebKit/haiku/WebCoreSupport - webkit