Author: stippi Date: Sat Apr 3 16:46:54 2010 New Revision: 380 URL: http://mmlr.dyndns.org/changeset/380 Log: * Added optional BWebView parameter passed to BrowserWindow constructor, which will be passed to CreateNewTab(), so that BrowserWindows can be created to embed a view which already exists. * Extended NewPageCreated() hook with the additional information that BWebPage::createPage() already provides. It can be used to decide if new windows shall be created instead of creating another tab for the new page. * Reworked BrowserWindow constructor with regards to the "DoNotHaveToolbar" policy. All views are always created, BLayoutItems are remembered for the various groups and are being turned invisible depending on policy. This way each BrowserWindow is fully valid and can be reconfigured easily during runtime. (Settings could be exposed as well now.) * Changed ChromeClientHaiku::createWindow() implementation to not disregard the "window features" properties if only some of them are not set. All this combined makes the Haiku User Guide translation page open a separate window for editing the translations just like BeZillaBrowser. What does not work (but apparently also not in BeZillaBrowser) is clicking another block and having the editing window update to show that block instead. Don't know if this is actually supposed to work that way, it just seems like it should. Modified: webkit/trunk/WebKit/haiku/API/WebWindow.cpp webkit/trunk/WebKit/haiku/API/WebWindow.h webkit/trunk/WebKit/haiku/WebCoreSupport/ChromeClientHaiku.cpp webkit/trunk/WebKit/haiku/WebPositive/BrowserWindow.cpp webkit/trunk/WebKit/haiku/WebPositive/BrowserWindow.h Modified: webkit/trunk/WebKit/haiku/API/WebWindow.cpp ============================================================================== --- webkit/trunk/WebKit/haiku/API/WebWindow.cpp Sat Apr 3 16:38:50 2010 (r379) +++ webkit/trunk/WebKit/haiku/API/WebWindow.cpp Sat Apr 3 16:46:54 2010 (r380) @@ -115,8 +115,19 @@ // and sent a default reply. That's why the pointer is guaranteed // to be still valid. BWebView* view; - if (message->FindPointer("view", reinterpret_cast<void**>(&view)) == B_OK) - NewPageCreated(view); + if (message->FindPointer("view", reinterpret_cast<void**>(&view)) != B_OK) + break; + BRect windowFrame; + if (message->FindRect("frame", &windowFrame) != B_OK) + windowFrame = BRect(); + bool modalDialog; + if (message->FindBool("modal", &modalDialog) != B_OK) + modalDialog = false; + bool resizable; + if (message->FindBool("resizable", &resizable) != B_OK) + resizable = true; + + NewPageCreated(view, windowFrame, modalDialog, resizable); break; } case CLOSE_WINDOW_REQUESTED: @@ -291,11 +302,32 @@ { } -void BWebWindow::NewPageCreated(BWebView* view) +void BWebWindow::NewPageCreated(BWebView* view, BRect windowFrame, + bool modalDialog, bool resizable) { - BWebWindow* window = new BWebWindow(Frame().OffsetByCopy(10, 10), - "WebKit window", B_TITLED_WINDOW_LOOK, Feel(), Flags()); + if (!windowFrame.IsValid()) + windowFrame = Frame().OffsetByCopy(10, 10); + + uint32 flags = Flags(); + + window_look look; + window_feel feel; + if (modalDialog) { + feel = B_MODAL_APP_WINDOW_FEEL; + look = B_BORDERED_WINDOW_LOOK; + } else { + look = B_TITLED_WINDOW_LOOK; + feel = B_NORMAL_WINDOW_FEEL; + } + if (!resizable) + flags |= B_NOT_RESIZABLE; + + BWebWindow* window = new BWebWindow(windowFrame, "WebKit window", + look, feel, flags); + window->AddChild(view); + window->SetCurrentWebView(view); + window->Show(); } Modified: webkit/trunk/WebKit/haiku/API/WebWindow.h ============================================================================== --- webkit/trunk/WebKit/haiku/API/WebWindow.h Sat Apr 3 16:38:50 2010 (r379) +++ webkit/trunk/WebKit/haiku/API/WebWindow.h Sat Apr 3 16:46:54 2010 (r380) @@ -58,7 +58,9 @@ virtual void NewWindowRequested(const BString& url, bool primaryAction); virtual void CloseWindowRequested(BWebView* view); - virtual void NewPageCreated(BWebView* view); + virtual void NewPageCreated(BWebView* view, + BRect windowFrame, bool modalDialog, + bool resizable); virtual void LoadNegotiating(const BString& url, BWebView* view); virtual void LoadCommitted(const BString& url, Modified: webkit/trunk/WebKit/haiku/WebCoreSupport/ChromeClientHaiku.cpp ============================================================================== --- webkit/trunk/WebKit/haiku/WebCoreSupport/ChromeClientHaiku.cpp Sat Apr 3 16:38:50 2010 (r379) +++ webkit/trunk/WebKit/haiku/WebCoreSupport/ChromeClientHaiku.cpp Sat Apr 3 16:46:54 2010 (r380) @@ -138,13 +138,24 @@ // implement themselves, so this method is not implemented in the Chromium // WebKit code.) +//printf("createWindow() - dialog: %d, resizable: %d\n", features.dialog, features.resizable); + BRect windowFrame; - if (features.xSet && features.ySet && features.widthSet && features.heightSet) { - windowFrame.left = features.x; - windowFrame.top = features.y; - windowFrame.right = features.x + features.width - 1; - windowFrame.bottom = features.y + features.height - 1; - } + // If any frame property of the features is set, the windowFrame will be valid and + // starts of as an offseted copy of the window frame where this page is embedded. + if (features.xSet || features.ySet || features.widthSet || features.heightSet) + windowFrame = m_webPage->windowFrame().OffsetByCopy(10, 10); + + if (features.xSet) + windowFrame.OffsetTo(features.x, windowFrame.top); + if (features.ySet) + windowFrame.OffsetTo(windowFrame.left, features.y); + if (features.widthSet) + windowFrame.right = windowFrame.left + features.width - 1; + if (features.heightSet) + windowFrame.bottom = windowFrame.top + features.height - 1; + +//printf(" frame: "); windowFrame.PrintToStream(); WebCore::Page* page = m_webPage->createNewPage(windowFrame, features.dialog, features.resizable); if (!page) Modified: webkit/trunk/WebKit/haiku/WebPositive/BrowserWindow.cpp ============================================================================== --- webkit/trunk/WebKit/haiku/WebPositive/BrowserWindow.cpp Sat Apr 3 16:38:50 2010 (r379) +++ webkit/trunk/WebKit/haiku/WebPositive/BrowserWindow.cpp Sat Apr 3 16:46:54 2010 (r380) @@ -238,7 +238,8 @@ // #pragma mark - BrowserWindow -BrowserWindow::BrowserWindow(BRect frame, ToolbarPolicy toolbarPolicy) +BrowserWindow::BrowserWindow(BRect frame, ToolbarPolicy toolbarPolicy, + BWebView* webView) : BWebWindow(frame, kApplicationName, B_DOCUMENT_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL, @@ -250,162 +251,165 @@ newTabMessage->AddBool("select", true); fTabManager = new TabManager(BMessenger(this), newTabMessage); - if (toolbarPolicy == HaveToolbar) { - // Menu + // Menu #if INTEGRATE_MENU_INTO_TAB_BAR - BMenu* mainMenu = fTabManager->Menu(); + BMenu* mainMenu = fTabManager->Menu(); #else - BMenu* mainMenu = new BMenuBar("Main menu"); + BMenu* mainMenu = new BMenuBar("Main menu"); #endif - BMenu* menu = new BMenu("Window"); - BMessage* newWindowMessage = new BMessage(NEW_WINDOW); - newWindowMessage->AddString("url", ""); - BMenuItem* newItem = new BMenuItem("New window", newWindowMessage, 'N'); - menu->AddItem(newItem); - newItem->SetTarget(be_app); - newItem = new BMenuItem("New tab", new BMessage(*newTabMessage), 'T'); - menu->AddItem(newItem); - newItem->SetTarget(be_app); - menu->AddItem(new BMenuItem("Open location", new BMessage(OPEN_LOCATION), 'L')); - menu->AddSeparatorItem(); - menu->AddItem(new BMenuItem("Close window", new BMessage(B_QUIT_REQUESTED), 'W', B_SHIFT_KEY)); - menu->AddItem(new BMenuItem("Close tab", new BMessage(CLOSE_TAB), 'W')); - menu->AddSeparatorItem(); - menu->AddItem(new BMenuItem("Show downloads", new BMessage(SHOW_DOWNLOAD_WINDOW), 'J')); - menu->AddItem(new BMenuItem("Show settings", new BMessage(SHOW_SETTINGS_WINDOW))); - menu->AddSeparatorItem(); - BMenuItem* quitItem = new BMenuItem("Quit", new BMessage(B_QUIT_REQUESTED), 'Q'); - menu->AddItem(quitItem); - quitItem->SetTarget(be_app); - mainMenu->AddItem(menu); - - menu = new BMenu("Text"); - menu->AddItem(new BMenuItem("Find", new BMessage(TEXT_SHOW_FIND_GROUP), 'F')); - menu->AddSeparatorItem(); - menu->AddItem(new BMenuItem("Increase size", new BMessage(TEXT_SIZE_INCREASE), '+')); - menu->AddItem(new BMenuItem("Decrease size", new BMessage(TEXT_SIZE_DECREASE), '-')); - menu->AddItem(new BMenuItem("Reset size", new BMessage(TEXT_SIZE_RESET), '0')); - mainMenu->AddItem(menu); - - fGoMenu = new BMenu("Go"); - mainMenu->AddItem(fGoMenu); - - BPath bookmarkPath; - entry_ref bookmarkRef; - if (_BookmarkPath(bookmarkPath) == B_OK - && get_ref_for_path(bookmarkPath.Path(), &bookmarkRef) == B_OK) { - BMenu* bookmarkMenu - = new BookmarkMenu("Bookmarks", this, &bookmarkRef); - mainMenu->AddItem(bookmarkMenu); - } - - // Back, Forward & Stop - fBackButton = new IconButton("Back", 0, NULL, new BMessage(GO_BACK)); - fBackButton->SetIcon(201); - fBackButton->TrimIcon(); - - fForwardButton = new IconButton("Forward", 0, NULL, new BMessage(GO_FORWARD)); - fForwardButton->SetIcon(202); - fForwardButton->TrimIcon(); - - fStopButton = new IconButton("Stop", 0, NULL, new BMessage(STOP)); - fStopButton->SetIcon(204); - fStopButton->TrimIcon(); - - // URL - fURLTextControl = new BTextControl("url", "", "", NULL); - fURLTextControl->SetDivider(50.0); - - // Go - fGoButton = new BButton("", "Go", new BMessage(GOTO_URL)); - - // Status Bar - fStatusText = new BStringView("status", ""); - fStatusText->SetAlignment(B_ALIGN_LEFT); - fStatusText->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET)); - fStatusText->SetExplicitMinSize(BSize(150, 12)); - // Prevent the window from growing to fit a long status message... - BFont font(be_plain_font); - font.SetSize(ceilf(font.Size() * 0.8)); - fStatusText->SetFont(&font, B_FONT_SIZE); - - // Loading progress bar - fLoadingProgressBar = new BStatusBar("progress"); - fLoadingProgressBar->SetMaxValue(100); - fLoadingProgressBar->Hide(); - fLoadingProgressBar->SetBarHeight(12); - - const float kInsetSpacing = 3; - const float kElementSpacing = 5; + BMenu* menu = new BMenu("Window"); + BMessage* newWindowMessage = new BMessage(NEW_WINDOW); + newWindowMessage->AddString("url", ""); + BMenuItem* newItem = new BMenuItem("New window", newWindowMessage, 'N'); + menu->AddItem(newItem); + newItem->SetTarget(be_app); + newItem = new BMenuItem("New tab", new BMessage(*newTabMessage), 'T'); + menu->AddItem(newItem); + newItem->SetTarget(be_app); + menu->AddItem(new BMenuItem("Open location", new BMessage(OPEN_LOCATION), 'L')); + menu->AddSeparatorItem(); + menu->AddItem(new BMenuItem("Close window", new BMessage(B_QUIT_REQUESTED), 'W', B_SHIFT_KEY)); + menu->AddItem(new BMenuItem("Close tab", new BMessage(CLOSE_TAB), 'W')); + menu->AddSeparatorItem(); + menu->AddItem(new BMenuItem("Show downloads", new BMessage(SHOW_DOWNLOAD_WINDOW), 'J')); + menu->AddItem(new BMenuItem("Show settings", new BMessage(SHOW_SETTINGS_WINDOW))); + menu->AddSeparatorItem(); + BMenuItem* quitItem = new BMenuItem("Quit", new BMessage(B_QUIT_REQUESTED), 'Q'); + menu->AddItem(quitItem); + quitItem->SetTarget(be_app); + mainMenu->AddItem(menu); + + menu = new BMenu("Text"); + menu->AddItem(new BMenuItem("Find", new BMessage(TEXT_SHOW_FIND_GROUP), 'F')); + menu->AddSeparatorItem(); + menu->AddItem(new BMenuItem("Increase size", new BMessage(TEXT_SIZE_INCREASE), '+')); + menu->AddItem(new BMenuItem("Decrease size", new BMessage(TEXT_SIZE_DECREASE), '-')); + menu->AddItem(new BMenuItem("Reset size", new BMessage(TEXT_SIZE_RESET), '0')); + mainMenu->AddItem(menu); + + fGoMenu = new BMenu("Go"); + mainMenu->AddItem(fGoMenu); + + BPath bookmarkPath; + entry_ref bookmarkRef; + if (_BookmarkPath(bookmarkPath) == B_OK + && get_ref_for_path(bookmarkPath.Path(), &bookmarkRef) == B_OK) { + BMenu* bookmarkMenu + = new BookmarkMenu("Bookmarks", this, &bookmarkRef); + mainMenu->AddItem(bookmarkMenu); + } + + // Back, Forward & Stop + fBackButton = new IconButton("Back", 0, NULL, new BMessage(GO_BACK)); + fBackButton->SetIcon(201); + fBackButton->TrimIcon(); + + fForwardButton = new IconButton("Forward", 0, NULL, new BMessage(GO_FORWARD)); + fForwardButton->SetIcon(202); + fForwardButton->TrimIcon(); + + fStopButton = new IconButton("Stop", 0, NULL, new BMessage(STOP)); + fStopButton->SetIcon(204); + fStopButton->TrimIcon(); + + // URL + fURLTextControl = new BTextControl("url", "", "", NULL); + fURLTextControl->SetDivider(50.0); + + // Go + fGoButton = new BButton("", "Go", new BMessage(GOTO_URL)); + + // Status Bar + fStatusText = new BStringView("status", ""); + fStatusText->SetAlignment(B_ALIGN_LEFT); + fStatusText->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET)); + fStatusText->SetExplicitMinSize(BSize(150, 12)); + // Prevent the window from growing to fit a long status message... + BFont font(be_plain_font); + font.SetSize(ceilf(font.Size() * 0.8)); + fStatusText->SetFont(&font, B_FONT_SIZE); + + // Loading progress bar + fLoadingProgressBar = new BStatusBar("progress"); + fLoadingProgressBar->SetMaxValue(100); + fLoadingProgressBar->Hide(); + fLoadingProgressBar->SetBarHeight(12); + + const float kInsetSpacing = 3; + const float kElementSpacing = 5; + + fFindTextControl = new BTextControl("find", "Find:", "", + new BMessage(TEXT_FIND_NEXT)); + fFindCaseSensitiveCheckBox = new BCheckBox("Match case"); + BView* findGroup = BGroupLayoutBuilder(B_VERTICAL) + .Add(new BSeparatorView(B_HORIZONTAL, B_PLAIN_BORDER)) + .Add(BGroupLayoutBuilder(B_HORIZONTAL, kElementSpacing) + .Add(fFindTextControl) + .Add(new BButton("Previous", new BMessage(TEXT_FIND_PREVIOUS))) + .Add(new BButton("Next", new BMessage(TEXT_FIND_NEXT))) + .Add(fFindCaseSensitiveCheckBox) + .Add(BSpaceLayoutItem::CreateGlue()) + .Add(new BButton("Close", new BMessage(TEXT_HIDE_FIND_GROUP))) + .SetInsets(kInsetSpacing, kInsetSpacing, + kInsetSpacing, kInsetSpacing) + ) + ; + + BView* navigationGroup = BGroupLayoutBuilder(B_VERTICAL) + .Add(BGridLayoutBuilder(kElementSpacing, kElementSpacing) + .Add(fBackButton, 0, 0) + .Add(fForwardButton, 1, 0) + .Add(fStopButton, 2, 0) + .Add(fURLTextControl, 3, 0) + .Add(fGoButton, 4, 0) + .SetInsets(kInsetSpacing, kInsetSpacing, kInsetSpacing, kInsetSpacing) + ) + .Add(new BSeparatorView(B_HORIZONTAL, B_PLAIN_BORDER)) + ; + + BView* statusGroup = BGroupLayoutBuilder(B_HORIZONTAL, kElementSpacing) + .Add(fStatusText) + .Add(fLoadingProgressBar, 0.2) + .AddStrut(12 - kElementSpacing) + .SetInsets(kInsetSpacing, 0, kInsetSpacing, 0) + ; - fFindTextControl = new BTextControl("find", "Find:", "", - new BMessage(TEXT_FIND_NEXT)); - fFindCaseSensitiveCheckBox = new BCheckBox("Match case"); - BView* findGroup = BGroupLayoutBuilder(B_VERTICAL) - .Add(new BSeparatorView(B_HORIZONTAL, B_PLAIN_BORDER)) - .Add(BGroupLayoutBuilder(B_HORIZONTAL, kElementSpacing) - .Add(fFindTextControl) - .Add(new BButton("Previous", new BMessage(TEXT_FIND_PREVIOUS))) - .Add(new BButton("Next", new BMessage(TEXT_FIND_NEXT))) - .Add(fFindCaseSensitiveCheckBox) - .Add(BSpaceLayoutItem::CreateGlue()) - .Add(new BButton("Close", new BMessage(TEXT_HIDE_FIND_GROUP))) - .SetInsets(kInsetSpacing, kInsetSpacing, - kInsetSpacing, kInsetSpacing) - ) - ; - // Layout - AddChild(BGroupLayoutBuilder(B_VERTICAL) + // Layout + AddChild(BGroupLayoutBuilder(B_VERTICAL) #if !INTEGRATE_MENU_INTO_TAB_BAR - .Add(mainMenu) + .Add(mainMenu) #endif - .Add(fTabManager->TabGroup()) - .Add(BGridLayoutBuilder(kElementSpacing, kElementSpacing) - .Add(fBackButton, 0, 0) - .Add(fForwardButton, 1, 0) - .Add(fStopButton, 2, 0) - .Add(fURLTextControl, 3, 0) - .Add(fGoButton, 4, 0) - .SetInsets(kInsetSpacing, kInsetSpacing, kInsetSpacing, kInsetSpacing) - ) - .Add(new BSeparatorView(B_HORIZONTAL, B_PLAIN_BORDER)) - .Add(fTabManager->ContainerView()) - .Add(findGroup) - .Add(new BSeparatorView(B_HORIZONTAL, B_PLAIN_BORDER)) - .Add(BGroupLayoutBuilder(B_HORIZONTAL, kElementSpacing) - .Add(fStatusText) - .Add(fLoadingProgressBar, 0.2) - .AddStrut(12 - kElementSpacing) - .SetInsets(kInsetSpacing, 0, kInsetSpacing, 0) - ) - ); - - fURLTextControl->MakeFocus(true); - - fURLAutoCompleter = new TextControlCompleter(fURLTextControl, - new BrowsingHistoryChoiceModel()); - - fFindGroup = layoutItemFor(findGroup); - fTabGroup = layoutItemFor(fTabManager->TabGroup()); - } else { - fBackButton = 0; - fForwardButton = 0; - fStopButton = 0; - fGoButton = 0; - fURLTextControl = 0; - fURLAutoCompleter = 0; - fStatusText = 0; - fLoadingProgressBar = 0; - - AddChild(BGroupLayoutBuilder(B_VERTICAL) - .Add(fTabManager->ContainerView()) - ); - } + .Add(fTabManager->TabGroup()) + .Add(navigationGroup) + .Add(fTabManager->ContainerView()) + .Add(findGroup) + .Add(new BSeparatorView(B_HORIZONTAL, B_PLAIN_BORDER)) + .Add(statusGroup) + ); + + fURLTextControl->MakeFocus(true); + + fURLAutoCompleter = new TextControlCompleter(fURLTextControl, + new BrowsingHistoryChoiceModel()); + + fMenuGroup = layoutItemFor(mainMenu); + fTabGroup = layoutItemFor(fTabManager->TabGroup()); + fNavigationGroup = layoutItemFor(navigationGroup); + fFindGroup = layoutItemFor(findGroup); + fStatusGroup = layoutItemFor(statusGroup); - CreateNewTab("", true); + CreateNewTab("", true, webView); fFindGroup->SetVisible(false); + if (toolbarPolicy == DoNotHaveToolbar) { +#if !INTEGRATE_MENU_INTO_TAB_BAR + fMenuGroup->SetVisible(false); +#endif + fTabGroup->SetVisible(false); + fNavigationGroup->SetVisible(false); + } + AddShortcut('G', B_COMMAND_KEY, new BMessage(TEXT_FIND_NEXT)); AddShortcut('G', B_COMMAND_KEY | B_SHIFT_KEY, new BMessage(TEXT_FIND_PREVIOUS)); AddShortcut('F', B_COMMAND_KEY, new BMessage(TEXT_SHOW_FIND_GROUP)); @@ -857,9 +861,15 @@ void -BrowserWindow::NewPageCreated(BWebView* view) +BrowserWindow::NewPageCreated(BWebView* view, BRect windowFrame, + bool modalDialog, bool resizable) { - CreateNewTab(BString(), true, view); + if (windowFrame.IsValid()) { + BrowserWindow* window = new BrowserWindow(windowFrame, + DoNotHaveToolbar, view); + window->Show(); + } else + CreateNewTab(BString(), true, view); } Modified: webkit/trunk/WebKit/haiku/WebPositive/BrowserWindow.h ============================================================================== --- webkit/trunk/WebKit/haiku/WebPositive/BrowserWindow.h Sat Apr 3 16:38:50 2010 (r379) +++ webkit/trunk/WebKit/haiku/WebPositive/BrowserWindow.h Sat Apr 3 16:46:54 2010 (r380) @@ -69,7 +69,8 @@ class BrowserWindow : public BWebWindow { public: BrowserWindow(BRect frame, - ToolbarPolicy = HaveToolbar); + ToolbarPolicy = HaveToolbar, + BWebView* webView = NULL); virtual ~BrowserWindow(); virtual void DispatchMessage(BMessage* message, @@ -88,7 +89,9 @@ virtual void NewWindowRequested(const BString& url, bool primaryAction); virtual void CloseWindowRequested(BWebView* view); - virtual void NewPageCreated(BWebView* view); + virtual void NewPageCreated(BWebView* view, + BRect windowFrame, bool modalDialog, + bool resizable); virtual void LoadNegotiating(const BString& url, BWebView* view); virtual void LoadCommitted(const BString& url, @@ -147,8 +150,13 @@ TextControlCompleter* fURLAutoCompleter; BStringView* fStatusText; BStatusBar* fLoadingProgressBar; - BLayoutItem* fFindGroup; + + BLayoutItem* fMenuGroup; BLayoutItem* fTabGroup; + BLayoutItem* fNavigationGroup; + BLayoutItem* fFindGroup; + BLayoutItem* fStatusGroup; + BTextControl* fFindTextControl; BCheckBox* fFindCaseSensitiveCheckBox; TabManager* fTabManager;