[haiku-webkit-commits] r436 - in webkit/trunk/WebKit/haiku: API WebPositive

  • From: webkit@xxxxxxxxxxxxxxx
  • To: haiku-webkit-commits@xxxxxxxxxxxxx
  • Date: Tue, 20 Apr 2010 12:32:27 +0000

Author: stippi
Date: Tue Apr 20 12:32:26 2010
New Revision: 436
URL: http://mmlr.dyndns.org/changeset/436

Log:
* Implemented a mechanism to ask the BWebPage about it's editing capabilities.
  This needs to be asynchronous, as always. BrowserWindow asks when menus are
  opened, but the result arrives so fast, that the user never sees invalid
  items. The Cut/Copy/Paste items are now always enabled according to what's
  currently really possible.
* Enable and disable the Back/Forward History menu items along with the buttons.

Modified:
   webkit/trunk/WebKit/haiku/API/WebPage.cpp
   webkit/trunk/WebKit/haiku/API/WebPage.h
   webkit/trunk/WebKit/haiku/WebPositive/BrowserWindow.cpp
   webkit/trunk/WebKit/haiku/WebPositive/BrowserWindow.h

Modified: webkit/trunk/WebKit/haiku/API/WebPage.cpp
==============================================================================
--- webkit/trunk/WebKit/haiku/API/WebPage.cpp   Tue Apr 20 11:26:15 2010        
(r435)
+++ webkit/trunk/WebKit/haiku/API/WebPage.cpp   Tue Apr 20 12:32:26 2010        
(r436)
@@ -115,7 +115,8 @@
     HANDLE_FIND_STRING = 'find',
 
     HANDLE_SET_STATUS_MESSAGE = 'stsm',
-    HANDLE_RESEND_NOTIFICATIONS = 'rsnt'
+    HANDLE_RESEND_NOTIFICATIONS = 'rsnt',
+    HANDLE_SEND_EDITING_CAPABILITIES = 'sedc'
 };
 
 using namespace WebCore;
@@ -241,8 +242,7 @@
 
 void BWebPage::Shutdown()
 {
-    BMessage message(HANDLE_SHUTDOWN);
-    Looper()->PostMessage(&message, this);
+    Looper()->PostMessage(HANDLE_SHUTDOWN, this);
 }
 
 void BWebPage::SetListener(const BMessenger& listener)
@@ -271,26 +271,22 @@
 
 void BWebPage::Reload()
 {
-    BMessage message(HANDLE_RELOAD);
-    Looper()->PostMessage(&message, this);
+    Looper()->PostMessage(HANDLE_RELOAD, this);
 }
 
 void BWebPage::GoBack()
 {
-    BMessage message(HANDLE_GO_BACK);
-    Looper()->PostMessage(&message, this);
+    Looper()->PostMessage(HANDLE_GO_BACK, this);
 }
 
 void BWebPage::GoForward()
 {
-    BMessage message(HANDLE_GO_FORWARD);
-    Looper()->PostMessage(&message, this);
+    Looper()->PostMessage(HANDLE_GO_FORWARD, this);
 }
 
 void BWebPage::StopLoading()
 {
-    BMessage message(HANDLE_STOP_LOADING);
-    Looper()->PostMessage(&message, this);
+    Looper()->PostMessage(HANDLE_STOP_LOADING, this);
 }
 
 void BWebPage::ChangeZoomFactor(float increment, bool textOnly)
@@ -322,8 +318,12 @@
 
 void BWebPage::ResendNotifications()
 {
-    BMessage message(HANDLE_RESEND_NOTIFICATIONS);
-    Looper()->PostMessage(&message, this);
+    Looper()->PostMessage(HANDLE_RESEND_NOTIFICATIONS, this);
+}
+
+void BWebPage::SendEditingCapabilities()
+{
+    Looper()->PostMessage(HANDLE_SEND_EDITING_CAPABILITIES, this);
 }
 
 /*static*/ void BWebPage::RequestDownload(const BString& url)
@@ -923,6 +923,9 @@
     case HANDLE_RESEND_NOTIFICATIONS:
         handleResendNotifications(message);
         break;
+    case HANDLE_SEND_EDITING_CAPABILITIES:
+        handleSendEditingCapabilities(message);
+        break;
 
     case B_REFS_RECEIVED: {
                RefPtr<FileChooser>* chooser;
@@ -1220,6 +1223,29 @@
     // TODO: Other notifications...
 }
 
+void BWebPage::handleSendEditingCapabilities(BMessage*)
+{
+    bool canCut = false;
+    bool canCopy = false;
+    bool canPaste = false;
+
+    WebCore::Frame* frame = fPage->focusController()->focusedOrMainFrame();
+    if (frame && frame->editor()) {
+        WebCore::Editor* editor = frame->editor();
+
+        canCut = editor->canCut() || editor->canDHTMLCut();
+        canCopy = editor->canCopy() || editor->canDHTMLCopy();
+        canPaste = editor->canPaste() || editor->canDHTMLPaste();
+    }
+
+    BMessage message(B_EDITING_CAPABILITIES_RESULT);
+    message.AddBool("can cut", canCut);
+    message.AddBool("can copy", canCopy);
+    message.AddBool("can paste", canPaste);
+
+    dispatchMessage(message);
+}
+
 // #pragma mark -
 
 status_t BWebPage::dispatchMessage(BMessage& message) const

Modified: webkit/trunk/WebKit/haiku/API/WebPage.h
==============================================================================
--- webkit/trunk/WebKit/haiku/API/WebPage.h     Tue Apr 20 11:26:15 2010        
(r435)
+++ webkit/trunk/WebKit/haiku/API/WebPage.h     Tue Apr 20 12:32:26 2010        
(r436)
@@ -61,9 +61,10 @@
 };
 
 enum {
-       B_FIND_STRING_RESULT    = 'fsrs',
-       B_DOWNLOAD_ADDED                = 'dwna',
-       B_DOWNLOAD_REMOVED              = 'dwnr'
+       B_FIND_STRING_RESULT                    = 'fsrs',
+       B_DOWNLOAD_ADDED                                = 'dwna',
+       B_DOWNLOAD_REMOVED                              = 'dwnr',
+       B_EDITING_CAPABILITIES_RESULT   = 'cedr'
 };
 
 typedef enum {
@@ -111,6 +112,8 @@
                        void                            SetStatusMessage(const 
BString& status);
                        void                            ResendNotifications();
 
+                       void                            
SendEditingCapabilities();
+
        static  void                            RequestDownload(const BString& 
url);
 
 private:
@@ -211,6 +214,7 @@
        void handleChangeZoomFactor(BMessage* message);
        void handleFindString(BMessage* message);
        void handleResendNotifications(BMessage* message);
+       void handleSendEditingCapabilities(BMessage* message);
 
     status_t dispatchMessage(BMessage& message) const;
 

Modified: webkit/trunk/WebKit/haiku/WebPositive/BrowserWindow.cpp
==============================================================================
--- webkit/trunk/WebKit/haiku/WebPositive/BrowserWindow.cpp     Tue Apr 20 
11:26:15 2010        (r435)
+++ webkit/trunk/WebKit/haiku/WebPositive/BrowserWindow.cpp     Tue Apr 20 
12:32:26 2010        (r436)
@@ -239,8 +239,10 @@
        mainMenu->AddItem(menu);
 
        fHistoryMenu = new BMenu("History");
-       fHistoryMenu->AddItem(new BMenuItem("Back", new BMessage(GO_BACK), 
B_LEFT_ARROW));
-       fHistoryMenu->AddItem(new BMenuItem("Forward", new 
BMessage(GO_FORWARD), B_RIGHT_ARROW));
+       fHistoryMenu->AddItem(fBackMenuItem = new BMenuItem("Back",
+               new BMessage(GO_BACK), B_LEFT_ARROW));
+       fHistoryMenu->AddItem(fForwardMenuItem = new BMenuItem("Forward",
+               new BMessage(GO_FORWARD), B_RIGHT_ARROW));
        fHistoryMenu->AddSeparatorItem();
        fHistoryMenuFixedItemCount = fHistoryMenu->CountItems();
        mainMenu->AddItem(fHistoryMenu);
@@ -594,6 +596,29 @@
                        break;
                }
 
+               case B_EDITING_CAPABILITIES_RESULT:
+               {
+                       BWebView* webView;
+                       if (message->FindPointer("view",
+                                       reinterpret_cast<void**>(&webView)) != 
B_OK
+                               || webView != CurrentWebView()) {
+                               break;
+                       }
+                       bool canCut;
+                       bool canCopy;
+                       bool canPaste;
+                       if (message->FindBool("can cut", &canCut) != B_OK)
+                               canCut = false;
+                       if (message->FindBool("can copy", &canCopy) != B_OK)
+                               canCopy = false;
+                       if (message->FindBool("can paste", &canPaste) != B_OK)
+                               canPaste = false;
+                       fCutMenuItem->SetEnabled(canCut);
+                       fCopyMenuItem->SetEnabled(canCopy);
+                       fPasteMenuItem->SetEnabled(canPaste);
+                       break;
+               }
+
                case SHOW_DOWNLOAD_WINDOW:
                case SHOW_SETTINGS_WINDOW:
                        message->AddUInt32("workspaces", Workspaces());
@@ -684,6 +709,19 @@
 
 
 void
+BrowserWindow::MenusEnded()
+{
+       // Reenabled the clipboard items, since we don't update them when
+       // the capabilities really change, but only when the menu is opened.
+       // The shortcuts need to work when the capabilities change without
+       // the Edit menu being opened meanwhile.
+       fCutMenuItem->SetEnabled(true);
+       fCopyMenuItem->SetEnabled(true);
+       fPasteMenuItem->SetEnabled(true);
+}
+
+
+void
 BrowserWindow::CreateNewTab(const BString& url, bool select, BWebView* webView)
 {
        // Executed in app thread (new BWebPage needs to be created in app 
thread).
@@ -957,12 +995,12 @@
        if (view != CurrentWebView())
                return;
 
-       if (fBackButton)
-               fBackButton->SetEnabled(canGoBackward);
-       if (fForwardButton)
-               fForwardButton->SetEnabled(canGoForward);
-       if (fStopButton)
-               fStopButton->SetEnabled(canStop);
+       fBackButton->SetEnabled(canGoBackward);
+       fForwardButton->SetEnabled(canGoForward);
+       fStopButton->SetEnabled(canStop);
+
+       fBackMenuItem->SetEnabled(canGoBackward);
+       fForwardMenuItem->SetEnabled(canGoForward);
 }
 
 
@@ -1405,9 +1443,16 @@
                fCutMenuItem->SetEnabled(hasSelection);
                fCopyMenuItem->SetEnabled(hasSelection);
                fPasteMenuItem->SetEnabled(canPaste);
-       } else if (CurrentFocus() != CurrentWebView()) {
+       } else if (CurrentWebView() != NULL) {
+               // Trigger update of the clipboard items, even if the
+               // BWebView doesn't have focus, we'll dispatch these message
+               // there anyway. This works so fast that the user can never see
+               // the wrong enabled state when the menu opens until the result
+               // message arrives.
                fCutMenuItem->SetEnabled(false);
                fCopyMenuItem->SetEnabled(false);
                fPasteMenuItem->SetEnabled(false);
+
+               CurrentWebView()->WebPage()->SendEditingCapabilities();
        }
 }

Modified: webkit/trunk/WebKit/haiku/WebPositive/BrowserWindow.h
==============================================================================
--- webkit/trunk/WebKit/haiku/WebPositive/BrowserWindow.h       Tue Apr 20 
11:26:15 2010        (r435)
+++ webkit/trunk/WebKit/haiku/WebPositive/BrowserWindow.h       Tue Apr 20 
12:32:26 2010        (r436)
@@ -81,6 +81,7 @@
        virtual void                            MessageReceived(BMessage* 
message);
        virtual bool                            QuitRequested();
        virtual void                            MenusBeginning();
+       virtual void                            MenusEnded();
 
                        void                            CreateNewTab(const 
BString& url, bool select,
                                                                        
BWebView* webView = 0);
@@ -156,6 +157,8 @@
                        BMenuItem*                      fFindPreviousMenuItem;
                        BMenuItem*                      fFindNextMenuItem;
                        BMenuItem*                      fZoomTextOnlyMenuItem;
+                       BMenuItem*                      fBackMenuItem;
+                       BMenuItem*                      fForwardMenuItem;
 
                        IconButton*                     fBackButton;
                        IconButton*                     fForwardButton;

Other related posts:

  • » [haiku-webkit-commits] r436 - in webkit/trunk/WebKit/haiku: API WebPositive - webkit