[haiku-webkit-commits] r244 - webkit/trunk/WebKit/haiku/WebPositive

  • From: webkit@xxxxxxxxxxxxxxx
  • To: haiku-webkit-commits@xxxxxxxxxxxxx
  • Date: Sun, 28 Feb 2010 13:32:39 +0000

Author: stippi
Date: Sun Feb 28 13:32:39 2010
New Revision: 244
URL: http://mmlr.dyndns.org/changeset/244

Log:
Implemented a neat new window management feature: When the app is asked to
open a new file or url, check if there is already a window open on the current
workspace, and if so, open a new tab in that window and bring it to front.
ArgReceived() now reuses RefsReceived(), which has been extended to handle
"url" string fields in the message, since ArgReceived() may also be asked to
open urls and not only local files. The LOAD_AT_STARTING mechanism, which
turned out to be broken for multiple args anyway, could be replaced, since
RefsReceived() already buffers the message when it has been called earlier
then ReadyToRun().

Modified:
   webkit/trunk/WebKit/haiku/WebPositive/BrowserApp.cpp
   webkit/trunk/WebKit/haiku/WebPositive/BrowserApp.h

Modified: webkit/trunk/WebKit/haiku/WebPositive/BrowserApp.cpp
==============================================================================
--- webkit/trunk/WebKit/haiku/WebPositive/BrowserApp.cpp        Sun Feb 28 
12:53:22 2010        (r243)
+++ webkit/trunk/WebKit/haiku/WebPositive/BrowserApp.cpp        Sun Feb 28 
13:32:39 2010        (r244)
@@ -49,11 +49,6 @@
 const char* kApplicationName = "WebPositive";
 
 
-enum {
-       LOAD_AT_STARTING = 'lost'
-};
-
-
 BrowserApp::BrowserApp()
        : BApplication(kApplicationSignature)
        , fWindowCount(0)
@@ -85,17 +80,18 @@
 void
 BrowserApp::ArgvReceived(int32 argc, char** argv)
 {
+       BMessage message(B_REFS_RECEIVED);
        for (int i = 1; i < argc; i++) {
                const char* url = argv[i];
                BEntry entry(argv[i], true);
                BPath path;
                if (entry.Exists() && entry.GetPath(&path) == B_OK)
                        url = path.Path();
-               BMessage message(LOAD_AT_STARTING);
                message.AddString("url", url);
-               message.AddBool("new window", fInitialized || i > 1);
-               PostMessage(&message);
        }
+       // Upon program launch, it will buffer a copy of the message, since
+       // ArgReceived() is called before ReadyToRun().
+       RefsReceived(&message);
 }
 
 
@@ -141,37 +137,8 @@
 BrowserApp::MessageReceived(BMessage* message)
 {
        switch (message->what) {
-       case LOAD_AT_STARTING: {
-               BString url;
-               if (message->FindString("url", &url) != B_OK)
-                       break;
-               bool openNewWindow = false;
-               message->FindBool("new window", &openNewWindow);
-               BrowserWindow* webWindow = NULL;
-               for (int i = 0; BWindow* window = WindowAt(i); i++) {
-                       webWindow = dynamic_cast<BrowserWindow*>(window);
-                       if (!webWindow)
-                               continue;
-                       if (!openNewWindow) {
-                               // stop at the first window
-                               break;
-                       }
-               }
-               if (webWindow) {
-                       // There should always be at least one window open. If 
not, maybe we are about
-                       // to quit anyway...
-                       if (openNewWindow) {
-                               // open a new window with an offset to the last 
window
-                               _CreateNewWindow(url);
-                       } else {
-                               // load the URL in the first window
-                               
webWindow->CurrentWebView()->LoadURL(url.String());
-                       }
-               }
-               break;
-       }
        case B_SILENT_RELAUNCH:
-               _CreateNewWindow("");
+               _CreateNewPage("");
                break;
        case NEW_WINDOW: {
                BString url;
@@ -238,8 +205,12 @@
                        continue;
                BString url;
                url << path.Path();
-               _CreateNewWindow(url);
+               _CreateNewPage(url);
        }
+
+       BString url;
+       for (int32 i = 0; message->FindString("url", i, &url) == B_OK; i++)
+               _CreateNewPage(url);
 }
 
 
@@ -294,6 +265,31 @@
 
 
 void
+BrowserApp::_CreateNewPage(const BString& url)
+{
+       uint32 workspace = 1 << current_workspace();
+
+       bool loadedInWindowOnCurrentWorkspace = false;
+       for (int i = 0; BWindow* window = WindowAt(i); i++) {
+               BrowserWindow* webWindow = dynamic_cast<BrowserWindow*>(window);
+               if (!webWindow)
+                       continue;
+               if (webWindow->Lock()) {
+                       if (webWindow->Workspaces() & workspace) {
+                               webWindow->CreateNewTab(url, true);
+                               webWindow->Activate();
+                               loadedInWindowOnCurrentWorkspace = true;
+                       }
+                       webWindow->Unlock();
+               }
+               if (loadedInWindowOnCurrentWorkspace)
+                       return;
+       }
+       _CreateNewWindow(url);
+}
+
+
+void
 BrowserApp::_CreateNewWindow(const BString& url)
 {
        fLastWindowFrame.OffsetBy(20, 20);

Modified: webkit/trunk/WebKit/haiku/WebPositive/BrowserApp.h
==============================================================================
--- webkit/trunk/WebKit/haiku/WebPositive/BrowserApp.h  Sun Feb 28 12:53:22 
2010        (r243)
+++ webkit/trunk/WebKit/haiku/WebPositive/BrowserApp.h  Sun Feb 28 13:32:39 
2010        (r244)
@@ -51,6 +51,7 @@
 
 private:
                        bool                            
_OpenSettingsFile(BFile& file, uint32 mode);
+                       void                            _CreateNewPage(const 
BString& url);
                        void                            _CreateNewWindow(const 
BString& url);
                        void                            
_CreateNewTab(BrowserWindow* window,
                                                                        const 
BString& url, bool select);

Other related posts:

  • » [haiku-webkit-commits] r244 - webkit/trunk/WebKit/haiku/WebPositive - webkit