⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 webframe.cpp

📁 linux下开源浏览器WebKit的源码,市面上的很多商用浏览器都是移植自WebKit
💻 CPP
📖 第 1 页 / 共 4 页
字号:
Widget* WebFrame::createJavaAppletWidget(const IntSize& pluginSize, HTMLAppletElement* element, const KURL& /*baseURL*/, const Vector<String>& paramNames, const Vector<String>& paramValues){    PluginView* pluginView = PluginView::create(core(this), pluginSize, element, KURL(), paramNames, paramValues, "application/x-java-applet", false);    // Check if the plugin can be loaded successfully    if (pluginView->plugin() && pluginView->plugin()->load())        return pluginView;    COMPtr<IWebResourceLoadDelegate> resourceLoadDelegate;    if (FAILED(d->webView->resourceLoadDelegate(&resourceLoadDelegate)))        return pluginView;    COMPtr<CFDictionaryPropertyBag> userInfoBag(AdoptCOM, CFDictionaryPropertyBag::createInstance());    ResourceError resourceError(String(WebKitErrorDomain), WebKitErrorJavaUnavailable, String(), String());    COMPtr<IWebError> error(AdoptCOM, WebError::createInstance(resourceError, userInfoBag.get()));         resourceLoadDelegate->plugInFailedWithError(d->webView, error.get(), getWebDataSource(d->frame->loader()->documentLoader()));    return pluginView;}ObjectContentType WebFrame::objectContentType(const KURL& url, const String& mimeTypeIn){    String mimeType = mimeTypeIn;    if (mimeType.isEmpty())        mimeType = MIMETypeRegistry::getMIMETypeForExtension(url.path().substring(url.path().reverseFind('.') + 1));    if (mimeType.isEmpty())        return ObjectContentFrame; // Go ahead and hope that we can display the content.    if (MIMETypeRegistry::isSupportedImageMIMEType(mimeType))        return WebCore::ObjectContentImage;    if (PluginDatabase::installedPlugins()->isMIMETypeRegistered(mimeType))        return WebCore::ObjectContentNetscapePlugin;    if (MIMETypeRegistry::isSupportedNonImageMIMEType(mimeType))        return WebCore::ObjectContentFrame;    return WebCore::ObjectContentNone;}String WebFrame::overrideMediaType() const{    notImplemented();    return String();}void WebFrame::windowObjectCleared(){    Frame* coreFrame = core(this);    ASSERT(coreFrame);    Settings* settings = coreFrame->settings();    if (!settings || !settings->isJavaScriptEnabled())        return;    COMPtr<IWebFrameLoadDelegate> frameLoadDelegate;    if (SUCCEEDED(d->webView->frameLoadDelegate(&frameLoadDelegate))) {        COMPtr<IWebFrameLoadDelegate2> frameLoadDelegate2(Query, frameLoadDelegate);        JSContextRef context = toRef(coreFrame->script()->globalObject()->globalExec());        JSObjectRef windowObject = toRef(coreFrame->script()->globalObject());        ASSERT(windowObject);        if (!frameLoadDelegate2 ||             FAILED(frameLoadDelegate2->didClearWindowObject(d->webView, context, windowObject, this)))            frameLoadDelegate->windowScriptObjectAvailable(d->webView, context, windowObject);    }}void WebFrame::documentElementAvailable(){}void WebFrame::didPerformFirstNavigation() const{    COMPtr<IWebPreferences> preferences;    if (FAILED(d->webView->preferences(&preferences)))        return;    COMPtr<IWebPreferencesPrivate> preferencesPrivate(Query, preferences);    if (!preferencesPrivate)        return;    BOOL automaticallyDetectsCacheModel;    if (FAILED(preferencesPrivate->automaticallyDetectsCacheModel(&automaticallyDetectsCacheModel)))        return;    WebCacheModel cacheModel;    if (FAILED(preferences->cacheModel(&cacheModel)))        return;    if (automaticallyDetectsCacheModel && cacheModel < WebCacheModelDocumentBrowser)        preferences->setCacheModel(WebCacheModelDocumentBrowser);}void WebFrame::registerForIconNotification(bool listen){    d->webView->registerForIconNotification(listen);}static IntRect printerRect(HDC printDC){    return IntRect(0, 0,                    GetDeviceCaps(printDC, PHYSICALWIDTH)  - 2 * GetDeviceCaps(printDC, PHYSICALOFFSETX),                   GetDeviceCaps(printDC, PHYSICALHEIGHT) - 2 * GetDeviceCaps(printDC, PHYSICALOFFSETY));}void WebFrame::setPrinting(bool printing, float minPageWidth, float maxPageWidth, bool adjustViewSize){    Frame* coreFrame = core(this);    ASSERT(coreFrame);    coreFrame->setPrinting(printing, minPageWidth, maxPageWidth, adjustViewSize);}HRESULT STDMETHODCALLTYPE WebFrame::setInPrintingMode(     /* [in] */ BOOL value,    /* [in] */ HDC printDC){    if (m_inPrintingMode == !!value)        return S_OK;    Frame* coreFrame = core(this);    if (!coreFrame || !coreFrame->document())        return E_FAIL;    m_inPrintingMode = !!value;    // If we are a frameset just print with the layout we have onscreen, otherwise relayout    // according to the paper size    float minLayoutWidth = 0.0f;    float maxLayoutWidth = 0.0f;    if (m_inPrintingMode && !coreFrame->document()->isFrameSet()) {        if (!printDC) {            ASSERT_NOT_REACHED();            return E_POINTER;        }        const int desiredHorizontalPixelsPerInch = 72;        int paperHorizontalPixelsPerInch = ::GetDeviceCaps(printDC, LOGPIXELSX);        int paperWidth = printerRect(printDC).width() * desiredHorizontalPixelsPerInch / paperHorizontalPixelsPerInch;        minLayoutWidth = paperWidth * PrintingMinimumShrinkFactor;        maxLayoutWidth = paperWidth * PrintingMaximumShrinkFactor;    }    setPrinting(m_inPrintingMode, minLayoutWidth, maxLayoutWidth, true);    if (!m_inPrintingMode)        m_pageRects.clear();    return S_OK;}void WebFrame::headerAndFooterHeights(float* headerHeight, float* footerHeight){    if (headerHeight)        *headerHeight = 0;    if (footerHeight)        *footerHeight = 0;    float height = 0;    COMPtr<IWebUIDelegate> ui;    if (FAILED(d->webView->uiDelegate(&ui)))        return;    COMPtr<IWebUIDelegate2> ui2;    if (FAILED(ui->QueryInterface(IID_IWebUIDelegate2, (void**) &ui2)))        return;    if (headerHeight && SUCCEEDED(ui2->webViewHeaderHeight(d->webView, &height)))        *headerHeight = height;    if (footerHeight && SUCCEEDED(ui2->webViewFooterHeight(d->webView, &height)))        *footerHeight = height;}IntRect WebFrame::printerMarginRect(HDC printDC){    IntRect emptyRect(0, 0, 0, 0);    COMPtr<IWebUIDelegate> ui;    if (FAILED(d->webView->uiDelegate(&ui)))        return emptyRect;    COMPtr<IWebUIDelegate2> ui2;    if (FAILED(ui->QueryInterface(IID_IWebUIDelegate2, (void**) &ui2)))        return emptyRect;    RECT rect;    if (FAILED(ui2->webViewPrintingMarginRect(d->webView, &rect)))        return emptyRect;    rect.left = MulDiv(rect.left, ::GetDeviceCaps(printDC, LOGPIXELSX), 1000);    rect.top = MulDiv(rect.top, ::GetDeviceCaps(printDC, LOGPIXELSY), 1000);    rect.right = MulDiv(rect.right, ::GetDeviceCaps(printDC, LOGPIXELSX), 1000);    rect.bottom = MulDiv(rect.bottom, ::GetDeviceCaps(printDC, LOGPIXELSY), 1000);    return IntRect(rect.left, rect.top, (rect.right - rect.left), rect.bottom - rect.top);}const Vector<WebCore::IntRect>& WebFrame::computePageRects(HDC printDC){    ASSERT(m_inPrintingMode);        Frame* coreFrame = core(this);    ASSERT(coreFrame);    ASSERT(coreFrame->document());    if (!printDC)        return m_pageRects;    // adjust the page rect by the header and footer    float headerHeight = 0, footerHeight = 0;    headerAndFooterHeights(&headerHeight, &footerHeight);    IntRect pageRect = printerRect(printDC);    IntRect marginRect = printerMarginRect(printDC);    IntRect adjustedRect = IntRect(        pageRect.x() + marginRect.x(),        pageRect.y() + marginRect.y(),        pageRect.width() - marginRect.x() - marginRect.right(),        pageRect.height() - marginRect.y() - marginRect.bottom());    computePageRectsForFrame(coreFrame, adjustedRect, headerHeight, footerHeight, 1.0,m_pageRects, m_pageHeight);        return m_pageRects;}HRESULT STDMETHODCALLTYPE WebFrame::getPrintedPageCount(     /* [in] */ HDC printDC,    /* [retval][out] */ UINT *pageCount){    if (!pageCount || !printDC) {        ASSERT_NOT_REACHED();        return E_POINTER;    }    *pageCount = 0;    if (!m_inPrintingMode) {        ASSERT_NOT_REACHED();        return E_FAIL;    }    Frame* coreFrame = core(this);    if (!coreFrame || !coreFrame->document())        return E_FAIL;    const Vector<IntRect>& pages = computePageRects(printDC);    *pageCount = (UINT) pages.size();        return S_OK;}HRESULT STDMETHODCALLTYPE WebFrame::spoolPages(     /* [in] */ HDC printDC,    /* [in] */ UINT startPage,    /* [in] */ UINT endPage,    /* [retval][out] */ void* ctx){    if (!printDC || !ctx) {        ASSERT_NOT_REACHED();        return E_POINTER;    }    if (!m_inPrintingMode) {        ASSERT_NOT_REACHED();        return E_FAIL;    }    Frame* coreFrame = core(this);    if (!coreFrame || !coreFrame->document())        return E_FAIL;    UINT pageCount = (UINT) m_pageRects.size();    PlatformGraphicsContext* pctx = (PlatformGraphicsContext*)ctx;    if (!pageCount || startPage > pageCount) {        ASSERT_NOT_REACHED();        return E_FAIL;    }    if (startPage > 0)        startPage--;    if (endPage == 0)        endPage = pageCount;    COMPtr<IWebUIDelegate> ui;    if (FAILED(d->webView->uiDelegate(&ui)))        return E_FAIL;    // FIXME: we can return early after the updated app is released    COMPtr<IWebUIDelegate2> ui2;    if (FAILED(ui->QueryInterface(IID_IWebUIDelegate2, (void**) &ui2)))        ui2 = 0;    float headerHeight = 0, footerHeight = 0;    headerAndFooterHeights(&headerHeight, &footerHeight);    GraphicsContext spoolCtx(pctx);    spoolCtx.setShouldIncludeChildWindows(true);    for (UINT ii = startPage; ii < endPage; ii++) {        IntRect pageRect = m_pageRects[ii];        CGContextSaveGState(pctx);        IntRect printRect = printerRect(printDC);        CGRect mediaBox = CGRectMake(CGFloat(0),                                     CGFloat(0),                                     CGFloat(printRect.width()),                                     CGFloat(printRect.height()));        CGContextBeginPage(pctx, &mediaBox);        CGFloat scale = (float)mediaBox.size.width/ (float)pageRect.width();        CGAffineTransform ctm = CGContextGetBaseCTM(pctx);        ctm = CGAffineTransformScale(ctm, -scale, -scale);        ctm = CGAffineTransformTranslate(ctm, CGFloat(-pageRect.x()), CGFloat(-pageRect.y()+headerHeight)); // reserves space for header        CGContextScaleCTM(pctx, scale, scale);        CGContextTranslateCTM(pctx, CGFloat(-pageRect.x()), CGFloat(-pageRect.y()+headerHeight));   // reserves space for header        CGContextSetBaseCTM(pctx, ctm);        coreFrame->view()->paintContents(&spoolCtx, pageRect);        if (ui2) {            CGContextTranslateCTM(pctx, CGFloat(pageRect.x()), CGFloat(pageRect.y())-headerHeight);            int x = pageRect.x();            int y = 0;            if (headerHeight) {                RECT headerRect = {x, y, x+pageRect.width(), y+(int)headerHeight};                ui2->drawHeaderInRect(d->webView, &headerRect, (OLE_HANDLE)(LONG64)pctx);            }            if (footerHeight) {                y = max((int)headerHeight+pageRect.height(), m_pageHeight-(int)footerHeight);                RECT footerRect = {x, y, x+pageRect.width(), y+(int)footerHeight};                ui2->drawFooterInRect(d->webView, &footerRect, (OLE_HANDLE)(LONG64)pctx, ii+1, pageCount);            }        }        CGContextEndPage(pctx);        CGContextRestoreGState(pctx);    }     return S_OK;}HRESULT STDMETHODCALLTYPE WebFrame::isFrameSet(     /* [retval][out] */ BOOL* result){    *result = FALSE;    Frame* coreFrame = core(this);    if (!coreFrame || !coreFrame->document())        return E_FAIL;    *result = coreFrame->document()->isFrameSet() ? TRUE : FALSE;    return S_OK;}HRESULT STDMETHODCALLTYPE WebFrame::string(     /* [retval][out] */ BSTR *result){    *result = 0;    Frame* coreFrame = core(this);    if (!coreFrame)        return E_FAIL;    RefPtr<Range> allRange(rangeOfContents(coreFrame->document()));    String allString = plainText(allRange.get());    *result = BString(allString).release();    return S_OK;}HRESULT STDMETHODCALLTYPE WebFrame::size(     /* [retval][out] */ SIZE *size){    if (!size)        return E_POINTER;    size->cx = size->cy = 0;    Frame* coreFrame = core(this);    if (!coreFrame)        return E_FAIL;    FrameView* view = coreFrame->view();    if (!view)        return E_FAIL;    size->cx = view->width();    size->cy = view->height();    return S_OK;}HRESULT STDMETHODCALLTYPE WebFrame::hasScrollBars(     /* [retval][out] */ BOOL *result){    if (!result)        return E_POINTER;    *result = FALSE;    Frame* coreFrame = core(this);    if (!coreFrame)        return E_FAIL;    FrameView* view = coreFrame->view();    if (!view)        return E_FAIL;    if (view->horizontalScrollbar() || view->verticalScrollbar())        *result = TRUE;    return S_OK;}HRESULT STDMETHODCALLTYPE WebFrame::contentBounds(     /* [retval][out] */ RECT *result){    if (!result)        return E_POINTER;    ::SetRectEmpty(result);    Frame* coreFrame = core(this);    if (!coreFrame)        return E_FAIL;    FrameView* view = coreFrame->view();    if (!view)        return E_FAIL;    result->bottom = view->contentsHeight();    result->right = view->contentsWidth();    return S_OK;}HRESULT STDMETHODCALLTYPE WebFrame::frameBounds(     /* [retval][out] */ RECT *result){    if (!result)        return E_POINTER;    ::SetRectEmpty(result);    Frame* coreFrame = core(this);    if (!coreFrame)        return E_FAIL;    FrameView* view = coreFrame->view();    if (!view)        return E_FAIL;    FloatRect bounds = view->visibleContentRect(true);    result->bottom = (LONG) bounds.height();    result->right = (LONG) bounds.width();    return S_OK;}HRESULT STDMETHODCALLTYPE WebFrame::isDescendantOfFrame(     /* [in] */ IWebFrame *ancestor,    /* [retval][out] */ BOOL *result){    if (!result)        return E_POINTER;    *result = FALSE;    Frame* coreFrame = core(this);    COMPtr<WebFrame> ancestorWebFrame(Query, ancestor);    if (!ancestorWebFrame)        return S_OK;    *result = (coreFrame && coreFrame->tree()->isDescendantOf(core(ancestorWebFrame.get()))) ? TRUE : FALSE;    return S_OK;}void WebFrame::unmarkAllMisspellings(){    Frame* coreFrame = core(this);    for (Frame* frame = coreFrame; frame; frame = frame->tree()->traverseNext(coreFrame)) {        Document *doc = frame->document();        if (!doc)            return;        doc->removeMarkers(DocumentMarker::Spelling);    }}void WebFrame::unmarkAllBadGrammar(){    Frame* coreFrame = core(this);    for (Frame* frame = coreFrame; frame; frame = frame->tree()->traverseNext(coreFrame)) {        Document *doc = frame->document();        if (!doc)            return;        doc->removeMarkers(DocumentMarker::Grammar);    }}WebView* WebFrame::webView() const{    return d->webView;}COMPtr<IAccessible> WebFrame::accessible() const{    Frame* coreFrame = core(this);    ASSERT(coreFrame);    Document* currentDocument = coreFrame->document();    if (!currentDocument)        m_accessible = 0;    else if (!m_accessible || m_accessible->document() != currentDocument) {        // Either we've never had a wrapper for this frame's top-level Document,        // the Document renderer was destroyed and its wrapper was detached, or        // the previous Document is in the page cache, and the current document        // needs to be wrapped.        m_accessible = new AccessibleDocument(currentDocument);    }    return m_accessible.get();}void WebFrame::updateBackground(){    Color backgroundColor = webView()->transparent() ? Color::transparent : Color::white;    Frame* coreFrame = core(this);    if (!coreFrame || !coreFrame->view())        return;    coreFrame->view()->updateBackgroundRecursively(backgroundColor, webView()->transparent());}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -