Author: stippi Date: Sun Mar 14 10:27:39 2010 New Revision: 310 URL: http://mmlr.dyndns.org/changeset/310 Log: * Made BWebPage download related methods and listener member static. * Introduced BWebPage::RequestDownload() public API (expected to run synchronous). * Added necessary wiring for "Download this link" in context menus. * Restarting downloads works in principle, although with some quirks. (Sometimes it appears the "Desktop" is being downloaded...) Modified: webkit/trunk/WebCore/platform/graphics/haiku/GraphicsContextHaiku.cpp webkit/trunk/WebKit/haiku/API/WebPage.cpp webkit/trunk/WebKit/haiku/API/WebPage.h webkit/trunk/WebKit/haiku/WebCoreSupport/ContextMenuClientHaiku.cpp webkit/trunk/WebKit/haiku/WebCoreSupport/ContextMenuClientHaiku.h webkit/trunk/WebKit/haiku/WebPositive/BrowserApp.cpp webkit/trunk/WebKit/haiku/WebPositive/BrowserWindow.cpp webkit/trunk/WebKit/haiku/WebPositive/BrowserWindow.h webkit/trunk/WebKit/haiku/WebPositive/DownloadWindow.cpp Modified: webkit/trunk/WebCore/platform/graphics/haiku/GraphicsContextHaiku.cpp ============================================================================== --- webkit/trunk/WebCore/platform/graphics/haiku/GraphicsContextHaiku.cpp Sat Mar 13 14:10:14 2010 (r309) +++ webkit/trunk/WebCore/platform/graphics/haiku/GraphicsContextHaiku.cpp Sun Mar 14 10:27:39 2010 (r310) @@ -135,6 +135,11 @@ return m_currentLayer->view; } + uint8 globalAlpha() const + { + return m_currentLayer->globalAlpha; + } + void setClipping(const BRegion& region) { // If we are supposed to set an empty region, but never @@ -406,8 +411,14 @@ // BGradient* gradient = m_common->state.strokeGradient->platformGradient(); // gradient->SetTransform(m_common->state.fillGradient->gradientSpaceTransform()); // m_data->view()->StrokeShape(m_data->shape(), *gradient); - } else + } else { + drawing_mode mode = m_data->view()->DrawingMode(); + if (m_data->view()->HighColor().alpha < 255) + m_data->view()->SetDrawingMode(B_OP_ALPHA); + m_data->view()->StrokeShape(m_data->shape()); + m_data->view()->SetDrawingMode(mode); + } } // m_data->view()->SetFlags(flags); @@ -545,8 +556,15 @@ BGradient* gradient = m_common->state.fillGradient->platformGradient(); // gradient->SetTransform(m_common->state.fillGradient->gradientSpaceTransform()); m_data->view()->FillShape(m_data->shape(), *gradient); - } else + } else { + drawing_mode mode = m_data->view()->DrawingMode(); + if (m_data->view()->HighColor().alpha < 255) + m_data->view()->SetDrawingMode(B_OP_ALPHA); + m_data->view()->FillShape(m_data->shape()); + + m_data->view()->SetDrawingMode(mode); + } } m_data->setShape(0); } @@ -637,7 +655,7 @@ return; // NOTE: Used by RenderBoxModelObject to clip out the inner part of an arc when rending box corners... - + notImplemented(); } Modified: webkit/trunk/WebKit/haiku/API/WebPage.cpp ============================================================================== --- webkit/trunk/WebKit/haiku/API/WebPage.cpp Sat Mar 13 14:10:14 2010 (r309) +++ webkit/trunk/WebKit/haiku/API/WebPage.cpp Sun Mar 14 10:27:39 2010 (r310) @@ -23,7 +23,7 @@ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ @@ -115,6 +115,8 @@ using namespace WebCore; +BMessenger BWebPage::sDownloadListener; + /*static*/ void BWebPage::InitializeOnce() { // NOTE: This needs to be called when the BApplication is ready. @@ -178,7 +180,7 @@ , m_menubarVisible(true) { m_page = new WebCore::Page(new WebCore::ChromeClientHaiku(this, webView), - new WebCore::ContextMenuClientHaiku(), + new WebCore::ContextMenuClientHaiku(this), new WebCore::EditorClientHaiku(this), new WebCore::DragClientHaiku(webView), new WebCore::InspectorClientHaiku(), @@ -236,7 +238,7 @@ void BWebPage::SetDownloadListener(const BMessenger& listener) { - m_downloadListener = listener; + sDownloadListener = listener; } /*static*/ void BWebPage::SetCookieJar(BNetworkCookieJar* cookieJar) @@ -301,6 +303,12 @@ Looper()->PostMessage(&message, this); } +/*static*/ void BWebPage::RequestDownload(const BString& url) +{ + ResourceRequest request(url); + requestDownload(request, false); +} + BWebFrame* BWebPage::MainFrame() const { return m_mainFrame; @@ -545,28 +553,35 @@ printf("BWebPage::linkHovered()\n"); } -void BWebPage::requestDownload(const WebCore::ResourceRequest& request) +/*static*/ void BWebPage::requestDownload(const WebCore::ResourceRequest& request, + bool isAsynchronousRequest) { BWebDownload* download = new BWebDownload(new BPrivate::WebDownloadPrivate(request)); - downloadCreated(download); + downloadCreated(download, isAsynchronousRequest); } -void BWebPage::requestDownload(WebCore::ResourceHandle* handle, - const WebCore::ResourceRequest& request, const WebCore::ResourceResponse& response) +/*static*/ void BWebPage::requestDownload(WebCore::ResourceHandle* handle, + const WebCore::ResourceRequest& request, + const WebCore::ResourceResponse& response, bool isAsynchronousRequest) { BWebDownload* download = new BWebDownload(new BPrivate::WebDownloadPrivate(handle, request, response)); - downloadCreated(download); + downloadCreated(download, isAsynchronousRequest); } -void BWebPage::downloadCreated(BWebDownload* download) +/*static*/ void BWebPage::downloadCreated(BWebDownload* download, + bool isAsynchronousRequest) { download->Start(); - if (m_downloadListener.IsValid()) { + if (sDownloadListener.IsValid()) { BMessage message(B_DOWNLOAD_ADDED); message.AddPointer("download", download); - // Block until the listener has pulled all the information... - BMessage reply; - m_downloadListener.SendMessage(&message, &reply); + if (isAsynchronousRequest) { + // Block until the listener has pulled all the information... + BMessage reply; + sDownloadListener.SendMessage(&message, &reply); + } else { + sDownloadListener.SendMessage(&message); + } } } @@ -672,7 +687,7 @@ int32 xIncrement; int32 yIncrement; - + if (yOffset == 0 && xOffset > 0) { // copy from right to left xIncrement = -1; @@ -681,7 +696,7 @@ // copy from left to right xIncrement = 1; } - + if (yOffset > 0) { // copy from bottom to top yIncrement = -bytesPerRow; @@ -690,9 +705,9 @@ // copy from top to bottom yIncrement = bytesPerRow; } - + uint8* dst = src + yOffset * bytesPerRow + xOffset * 4; - + if (xIncrement == 1) { for (uint32 y = 0; y < height; y++) { memcpy(dst, src, width * 4); @@ -788,7 +803,7 @@ delete message; first = false; } - + message = nextMessage; queue->RemoveMessage(message); Modified: webkit/trunk/WebKit/haiku/API/WebPage.h ============================================================================== --- webkit/trunk/WebKit/haiku/API/WebPage.h Sat Mar 13 14:10:14 2010 (r309) +++ webkit/trunk/WebKit/haiku/API/WebPage.h Sun Mar 14 10:27:39 2010 (r310) @@ -80,7 +80,7 @@ void Shutdown(); void SetListener(const BMessenger& listener); - void SetDownloadListener(const BMessenger& listener); + static void SetDownloadListener(const BMessenger& listener); static void SetCookieJar(BNetworkCookieJar* cookieJar); @@ -108,6 +108,8 @@ void ResendNotifications(); + static void RequestDownload(const BString& url); + private: friend class BWebFrame; friend class BWebView; @@ -165,10 +167,14 @@ friend class BWebDownload; - void requestDownload(const WebCore::ResourceRequest& request); - void requestDownload(WebCore::ResourceHandle* handle, - const WebCore::ResourceRequest& request, const WebCore::ResourceResponse& response); - void downloadCreated(BWebDownload* download); + static void requestDownload(const WebCore::ResourceRequest& request, + bool isAsynchronousRequest = false); + static void requestDownload(WebCore::ResourceHandle* handle, + const WebCore::ResourceRequest& request, + const WebCore::ResourceResponse& response, + bool isAsynchronousRequest = false); + static void downloadCreated(BWebDownload* download, + bool isAsynchronousRequest); void paint(BRect rect, bool contentChanged, bool immediate, bool repaintContentOnly); @@ -202,7 +208,7 @@ private: BMessenger m_listener; - BMessenger m_downloadListener; + static BMessenger sDownloadListener; BWebView* m_webView; BWebFrame* m_mainFrame; BWebSettings* m_settings; Modified: webkit/trunk/WebKit/haiku/WebCoreSupport/ContextMenuClientHaiku.cpp ============================================================================== --- webkit/trunk/WebKit/haiku/WebCoreSupport/ContextMenuClientHaiku.cpp Sat Mar 13 14:10:14 2010 (r309) +++ webkit/trunk/WebKit/haiku/WebCoreSupport/ContextMenuClientHaiku.cpp Sun Mar 14 10:27:39 2010 (r310) @@ -1,6 +1,7 @@ /* * Copyright (C) 2006 Zack Rusin <zack@xxxxxxx> * Copyright (C) 2007 Ryan Leavengood <leavengood@xxxxxxxxx> + * Copyright (C) 2010 Stephan Aßmus <superstippi@xxxxxx> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -30,10 +31,17 @@ #include "HitTestResult.h" #include "KURL.h" #include "NotImplemented.h" +#include "ResourceRequest.h" +#include "WebPage.h" namespace WebCore { +ContextMenuClientHaiku::ContextMenuClientHaiku(BWebPage* webPage) + : m_webPage(webPage) +{ +} + void ContextMenuClientHaiku::contextMenuDestroyed() { delete this; @@ -56,7 +64,8 @@ void ContextMenuClientHaiku::downloadURL(const KURL& url) { - notImplemented(); + ResourceRequest request(url); + BWebPage::requestDownload(request); } void ContextMenuClientHaiku::lookUpInDictionary(Frame*) Modified: webkit/trunk/WebKit/haiku/WebCoreSupport/ContextMenuClientHaiku.h ============================================================================== --- webkit/trunk/WebKit/haiku/WebCoreSupport/ContextMenuClientHaiku.h Sat Mar 13 14:10:14 2010 (r309) +++ webkit/trunk/WebKit/haiku/WebCoreSupport/ContextMenuClientHaiku.h Sun Mar 14 10:27:39 2010 (r310) @@ -1,6 +1,7 @@ /* * Copyright (C) 2006 Zack Rusin <zack@xxxxxxx> * Copyright (C) 2007 Ryan Leavengood <leavengood@xxxxxxxxx> + * Copyright (C) 2010 Stephan Aßmus <superstippi@xxxxxx> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -29,23 +30,32 @@ #include "ContextMenuClient.h" +class BWebPage; + namespace WebCore { - class ContextMenu; - class ContextMenuClientHaiku : public ContextMenuClient { - public: - virtual void contextMenuDestroyed(); - - virtual PlatformMenuDescription getCustomMenuFromDefaultItems(ContextMenu*); - virtual void contextMenuItemSelected(ContextMenuItem*, const ContextMenu*); - - virtual void downloadURL(const KURL& url); - virtual void lookUpInDictionary(Frame*); - virtual void speak(const String&); - virtual bool isSpeaking(); - virtual void stopSpeaking(); - virtual void searchWithGoogle(const Frame*); - }; +class ContextMenu; + +class ContextMenuClientHaiku : public ContextMenuClient { +public: + ContextMenuClientHaiku(BWebPage*); + + virtual void contextMenuDestroyed(); + + virtual PlatformMenuDescription getCustomMenuFromDefaultItems(ContextMenu*); + virtual void contextMenuItemSelected(ContextMenuItem*, const ContextMenu*); + + virtual void downloadURL(const KURL& url); + virtual void lookUpInDictionary(Frame*); + virtual void speak(const String&); + virtual bool isSpeaking(); + virtual void stopSpeaking(); + virtual void searchWithGoogle(const Frame*); + +private: + BWebPage* m_webPage; +}; + } // namespace WebCore #endif // ContextMenuClientHaiku_h Modified: webkit/trunk/WebKit/haiku/WebPositive/BrowserApp.cpp ============================================================================== --- webkit/trunk/WebKit/haiku/WebPositive/BrowserApp.cpp Sat Mar 13 14:10:14 2010 (r309) +++ webkit/trunk/WebKit/haiku/WebPositive/BrowserApp.cpp Sun Mar 14 10:27:39 2010 (r310) @@ -124,7 +124,7 @@ BWebSettings::SetPersistentStoragePath(path.Path()); } - + BString mainSettingsPath(kApplicationName); mainSettingsPath << "/Application"; fSettings = new SettingsMessage(B_USER_SETTINGS_DIRECTORY, @@ -148,6 +148,8 @@ fDownloadWindow = new DownloadWindow(downloadWindowFrame, showDownloads); fSettingsWindow = new SettingsWindow(settingsWindowFrame, fSettings); + BWebPage::SetDownloadListener(BMessenger(fDownloadWindow)); + fInitialized = true; if (fLaunchRefsMessage) { @@ -155,8 +157,7 @@ delete fLaunchRefsMessage; fLaunchRefsMessage = 0; } else { - BrowserWindow* window = new BrowserWindow(fLastWindowFrame, - BMessenger(fDownloadWindow)); + BrowserWindow* window = new BrowserWindow(fLastWindowFrame); window->Show(); } PostMessage(PRELOAD_BROWSING_HISTORY); @@ -313,8 +314,7 @@ if (!BScreen().Frame().Contains(fLastWindowFrame)) fLastWindowFrame.OffsetTo(50, 50); - BrowserWindow* window = new BrowserWindow(fLastWindowFrame, - BMessenger(fDownloadWindow)); + BrowserWindow* window = new BrowserWindow(fLastWindowFrame); window->Show(); if (url.Length()) window->CurrentWebView()->LoadURL(url.String()); Modified: webkit/trunk/WebKit/haiku/WebPositive/BrowserWindow.cpp ============================================================================== --- webkit/trunk/WebKit/haiku/WebPositive/BrowserWindow.cpp Sat Mar 13 14:10:14 2010 (r309) +++ webkit/trunk/WebKit/haiku/WebPositive/BrowserWindow.cpp Sun Mar 14 10:27:39 2010 (r310) @@ -195,13 +195,11 @@ // #pragma mark - BrowserWindow -BrowserWindow::BrowserWindow(BRect frame, const BMessenger& downloadListener, - ToolbarPolicy toolbarPolicy) +BrowserWindow::BrowserWindow(BRect frame, ToolbarPolicy toolbarPolicy) : BWebWindow(frame, kApplicationName, B_DOCUMENT_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL, - B_AUTO_UPDATE_SIZE_LIMITS | B_ASYNCHRONOUS_CONTROLS), - fDownloadListener(downloadListener) + B_AUTO_UPDATE_SIZE_LIMITS | B_ASYNCHRONOUS_CONTROLS) { BMessage* newTabMessage = new BMessage(NEW_TAB); newTabMessage->AddString("url", ""); @@ -373,7 +371,7 @@ snprintf(numStr, sizeof(numStr), "%d", (int) i); AddShortcut(numStr[0], B_COMMAND_KEY, selectTab); } - + be_app->PostMessage(WINDOW_OPENED); } @@ -538,7 +536,7 @@ && fTabManager->CountTabs() > index) { fTabManager->SelectTab(index); } - + break; } @@ -629,7 +627,6 @@ // Executed in app thread (new BWebPage needs to be created in app thread). if (!webView) webView = new BWebView("web view"); - webView->WebPage()->SetDownloadListener(fDownloadListener); fTabManager->AddTab(webView, "New tab"); @@ -675,7 +672,7 @@ } -void +void BrowserWindow::NewPageCreated(BWebView* view) { CreateNewTab(BString(), true, view); Modified: webkit/trunk/WebKit/haiku/WebPositive/BrowserWindow.h ============================================================================== --- webkit/trunk/WebKit/haiku/WebPositive/BrowserWindow.h Sat Mar 13 14:10:14 2010 (r309) +++ webkit/trunk/WebKit/haiku/WebPositive/BrowserWindow.h Sun Mar 14 10:27:39 2010 (r310) @@ -66,7 +66,6 @@ class BrowserWindow : public BWebWindow { public: BrowserWindow(BRect frame, - const BMessenger& downloadListener, ToolbarPolicy = HaveToolbar); virtual ~BrowserWindow(); @@ -121,7 +120,6 @@ void _ShutdownTab(int32 index); private: - BMessenger fDownloadListener; BMenu* fGoMenu; IconButton* fBackButton; IconButton* fForwardButton; Modified: webkit/trunk/WebKit/haiku/WebPositive/DownloadWindow.cpp ============================================================================== --- webkit/trunk/WebKit/haiku/WebPositive/DownloadWindow.cpp Sat Mar 13 14:10:14 2010 (r309) +++ webkit/trunk/WebKit/haiku/WebPositive/DownloadWindow.cpp Sun Mar 14 10:27:39 2010 (r310) @@ -257,7 +257,7 @@ break; } case RESTART_DOWNLOAD: - // TODO: + BWebPage::RequestDownload(m_url); break; case CANCEL_DOWNLOAD: