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

📄 browserfrm.cpp

📁 JDesktop Integration Components (JDIC)
💻 CPP
📖 第 1 页 / 共 2 页
字号:
{    // Check to see if the mouse click was within the    // padlock icon pane(at pane index 2) of the status bar...    RECT rc;    GetItemRect(2, &rc );    if (PtInRect(&rc, point))     {        CBrowserFrame *pFrame = (CBrowserFrame *)GetParent();        if (pFrame != NULL)            pFrame->ShowSecurityInfo();    }            CStatusBar::OnLButtonDown(nFlags, point);}/////////////////////////////////////////////////////////////////////////////// CBrowserFrame helpersvoid CBrowserFrame::UpdateStatusBarText(const PRUnichar *aMessage){    nsCString strStatus;    if (aMessage)        strStatus.AssignWithConversion(aMessage);    m_wndStatusBar.SetPaneText(0, strStatus.get());}void CBrowserFrame::UpdateProgress(PRInt32 aCurrent, PRInt32 aMax){    m_wndProgressBar.SetRange32(0, aMax);    m_wndProgressBar.SetPos(aCurrent);}void CBrowserFrame::UpdateBusyState(PRBool aBusy){    // Just notify the view of the busy state    // There's code in there which will take care of    // updating the STOP toolbar btn. etc    m_wndBrowserView.UpdateBusyState(aBusy);}// Called from the OnLocationChange() method in the nsIWebProgressListener// interface implementation in CBrowserImpl to update the current URI// Will get called after a URI is successfully loaded in the browser// We use this info to update the URL bar's edit box//void CBrowserFrame::UpdateCurrentURI(nsIURI *aLocation){    if (aLocation)    {        nsCAutoString uriString;        aLocation->GetSpec(uriString);        m_wndUrlBar.SetCurrentURL(uriString.get());    }}void CBrowserFrame::GetBrowserFrameTitle(PRUnichar **aTitle){    CString title;    GetWindowText(title);    if (!title.IsEmpty())    {        nsString nsTitle;        nsTitle.AssignWithConversion(title.GetBuffer(0));        *aTitle = ToNewUnicode(nsTitle);    }}void CBrowserFrame::SetBrowserFrameTitle(const PRUnichar *aTitle){    USES_CONVERSION;    if (W2T(aTitle))    {        SetWindowText(W2T(aTitle));    }    else    {        // Use the AppName i.e. mfcembed as the title if we        // do not get one from GetBrowserWindowTitle()        //        CString cs;        cs.LoadString(AFX_IDS_APP_TITLE);        SetWindowText(cs);    }}void CBrowserFrame::SetBrowserFrameSize(PRInt32 aCX, PRInt32 aCY){    SetWindowPos(NULL, 0, 0, aCX, aCY,                SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER);}void CBrowserFrame::GetBrowserFrameSize(PRInt32 *aCX, PRInt32 *aCY){    RECT wndRect;    GetWindowRect(&wndRect);    if (aCX)        *aCX = wndRect.right - wndRect.left;    if (aCY)        *aCY = wndRect.bottom - wndRect.top;}void CBrowserFrame::SetBrowserFramePosition(PRInt32 aX, PRInt32 aY){    SetWindowPos(NULL, aX, aY, 0, 0,                SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOZORDER);}void CBrowserFrame::GetBrowserFramePosition(PRInt32 *aX, PRInt32 *aY){    RECT wndRect;    GetWindowRect(&wndRect);    if (aX)        *aX = wndRect.left;    if (aY)        *aY = wndRect.top;}void CBrowserFrame::GetBrowserFramePositionAndSize(PRInt32 *aX, PRInt32 *aY, PRInt32 *aCX, PRInt32 *aCY){    RECT wndRect;    GetWindowRect(&wndRect);    if (aX)        *aX = wndRect.left;    if (aY)        *aY = wndRect.top;    if (aCX)        *aCX = wndRect.right - wndRect.left;    if (aCY)        *aCY = wndRect.bottom - wndRect.top;}void CBrowserFrame::SetBrowserFramePositionAndSize(PRInt32 aX, PRInt32 aY, PRInt32 aCX, PRInt32 aCY, PRBool fRepaint){    SetWindowPos(NULL, aX, aY, aCX, aCY,                SWP_NOACTIVATE | SWP_NOZORDER);}void CBrowserFrame::FocusAvailable(PRBool *aFocusAvail){    HWND focusWnd = GetFocus()->m_hWnd;    if ((focusWnd == m_hWnd) || ::IsChild(m_hWnd, focusWnd))        *aFocusAvail = PR_TRUE;    else        *aFocusAvail = PR_FALSE;}void CBrowserFrame::ShowBrowserFrame(PRBool aShow){    if (aShow)    {        ShowWindow(SW_SHOW);        SetActiveWindow();        UpdateWindow();    }    else    {        ShowWindow(SW_HIDE);    }}void CBrowserFrame::GetBrowserFrameVisibility(PRBool *aVisible){    // Is the current BrowserFrame the active one?    if (GetActiveWindow()->m_hWnd != m_hWnd)    {        *aVisible = PR_FALSE;        return;    }    // We're the active one    //Return FALSE if we're minimized    WINDOWPLACEMENT wpl;    GetWindowPlacement(&wpl);    if ((wpl.showCmd == SW_RESTORE) || (wpl.showCmd == SW_MAXIMIZE))        *aVisible = PR_TRUE;    else        *aVisible = PR_FALSE;}PRBool CBrowserFrame::CreateNewBrowserFrame(                            PRUint32 chromeMask,                            PRInt32 x, PRInt32 y,                            PRInt32 cx, PRInt32 cy,                            nsIWebBrowser** aWebBrowser){    NS_ENSURE_ARG_POINTER(aWebBrowser);   *aWebBrowser = nsnull;    MozEmbedApp *pApp = (MozEmbedApp *)AfxGetApp();    if (!pApp)        return PR_FALSE;    // Note that we're calling with the last param set to "false" i.e.    // this instructs not to show the frame window    // This is mainly needed when the window size is specified in the window.open()    // JS call. In those cases Gecko calls us to create the browser with a default    // size (all are -1) and then it calls the SizeBrowserTo() method to set    // the proper window size. If this window were to be visible then you'll see    // the window size changes on the screen causing an unappealing flicker    //    CBrowserFrame* pFrm = pApp->CreateNewBrowserFrame(        chromeMask, NULL, x, y, cx, cy, PR_FALSE);    if (!pFrm)        return PR_FALSE;    // At this stage we have a new CBrowserFrame and a new CBrowserView    // objects. The CBrowserView also would have an embedded browser    // object created. Get the mWebBrowser member from the CBrowserView    // and return it. (See CBrowserView's CreateBrowser() on how the    // embedded browser gets created and how it's mWebBrowser member    // gets initialized)    NS_IF_ADDREF(*aWebBrowser = pFrm->m_wndBrowserView.mWebBrowser);    return PR_TRUE;}void CBrowserFrame::DestroyBrowserFrame(){    PostMessage(WM_CLOSE);}#define GOTO_BUILD_CTX_MENU { bContentHasFrames = FALSE; goto BUILD_CTX_MENU; }void CBrowserFrame::ShowContextMenu(PRUint32 aContextFlags, nsIContextMenuInfo *aInfo){    BOOL bContentHasFrames = FALSE;    UINT nIDResource = IDR_CTXMENU_DOCUMENT;    // Reset the values from the last invocation    // Clear image src & link url    nsAutoString empty;    m_wndBrowserView.SetCtxMenuImageSrc(empty);    m_wndBrowserView.SetCtxMenuLinkUrl(empty);    m_wndBrowserView.SetCurrentFrameURL(empty);    if (aContextFlags & nsIContextMenuListener2::CONTEXT_DOCUMENT)    {        nIDResource = IDR_CTXMENU_DOCUMENT;        // Background image?        if (aContextFlags & nsIContextMenuListener2::CONTEXT_BACKGROUND_IMAGE)        {            // Get the IMG SRC            nsCOMPtr<nsIURI> imgURI;            aInfo->GetBackgroundImageSrc(getter_AddRefs(imgURI));            if (!imgURI)                return;            nsCAutoString uri;            imgURI->GetSpec(uri);            m_wndBrowserView.SetCtxMenuImageSrc(NS_ConvertUTF8toUCS2(uri)); // Set the new Img Src        }    }    else if (aContextFlags & nsIContextMenuListener2::CONTEXT_TEXT)        nIDResource = IDR_CTXMENU_TEXT;    else if (aContextFlags & nsIContextMenuListener2::CONTEXT_LINK)    {        nIDResource = IDR_CTXMENU_LINK;        // Since we handle all the browser menu/toolbar commands        // in the View, we basically setup the Link's URL in the        // BrowserView object. When a menu selection in the context        // menu is made, the appropriate command handler in the        // BrowserView will be invoked and the value of the URL        // will be accesible in the view        nsAutoString strUrlUcs2;        nsresult rv = aInfo->GetAssociatedLink(strUrlUcs2);        if (NS_FAILED(rv))            return;        // Update the view with the new LinkUrl        // Note that this string is in UCS2 format        m_wndBrowserView.SetCtxMenuLinkUrl(strUrlUcs2);    }    else if (aContextFlags & nsIContextMenuListener2::CONTEXT_IMAGE)    {        nIDResource = IDR_CTXMENU_IMAGE;        // Get the IMG SRC        nsCOMPtr<nsIURI> imgURI;        aInfo->GetImageSrc(getter_AddRefs(imgURI));        if (!imgURI)            return;        nsCAutoString strImgSrcUtf8;        imgURI->GetSpec(strImgSrcUtf8);        if (strImgSrcUtf8.IsEmpty())            return;        // Set the new Img Src        m_wndBrowserView.SetCtxMenuImageSrc(NS_ConvertUTF8toUCS2(strImgSrcUtf8));    }    // Determine if we need to add the Frame related context menu items    // such as "View Frame Source" etc.    //    if (m_wndBrowserView.ViewContentContainsFrames())    {        bContentHasFrames = TRUE;        //Determine the current Frame URL        //        nsresult rv = NS_OK;        nsCOMPtr<nsIDOMNode> node;        aInfo->GetTargetNode(getter_AddRefs(node));        if (!node)            GOTO_BUILD_CTX_MENU;        nsCOMPtr<nsIDOMDocument> domDoc;        rv = node->GetOwnerDocument(getter_AddRefs(domDoc));        if (NS_FAILED(rv))            GOTO_BUILD_CTX_MENU;        nsCOMPtr<nsIDOMHTMLDocument> htmlDoc(do_QueryInterface(domDoc, &rv));        if (NS_FAILED(rv))            GOTO_BUILD_CTX_MENU;        nsAutoString strFrameURL;        rv = htmlDoc->GetURL(strFrameURL);        if (NS_FAILED(rv))            GOTO_BUILD_CTX_MENU;        m_wndBrowserView.SetCurrentFrameURL(strFrameURL); //Set it to the new URL    }BUILD_CTX_MENU:    CMenu ctxMenu;    if (ctxMenu.LoadMenu(nIDResource))    {        //Append the Frame related menu items if content has frames        if (bContentHasFrames)        {            CMenu* pCtxMenu = ctxMenu.GetSubMenu(0);            if (pCtxMenu)            {                pCtxMenu->AppendMenu(MF_SEPARATOR);                CString strMenuItem;                strMenuItem.LoadString(IDS_VIEW_FRAME_SOURCE);                pCtxMenu->AppendMenu(MF_STRING, ID_VIEW_FRAME_SOURCE, strMenuItem);                strMenuItem.LoadString(IDS_OPEN_FRAME_IN_NEW_WINDOW);                pCtxMenu->AppendMenu(MF_STRING, ID_OPEN_FRAME_IN_NEW_WINDOW, strMenuItem);            }        }        POINT cursorPos;        GetCursorPos(&cursorPos);        (ctxMenu.GetSubMenu(0))->TrackPopupMenu(TPM_LEFTALIGN, cursorPos.x, cursorPos.y, this);    }}void CBrowserFrame::ShowTooltip(PRInt32 aXCoords, PRInt32 aYCoords, const PRUnichar *aTipText){    m_wndTooltip.SetTipText(CString(aTipText));    m_wndTooltip.Show(&m_wndBrowserView, aXCoords, aYCoords);}void CBrowserFrame::HideTooltip(){    m_wndTooltip.Hide();}

⌨️ 快捷键说明

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