Hi guys,

I'm attempting to determine the extents of a webpage in native device window
coordinates. I have been unable
to find a function that does this (I'm still pretty green with the codebase,
so I've probably missed it). The code
below should illustrate what I'm trying to do - it's based very closely on
the page loading code in the winembed sample.
My current thinking is to write a function that iterates through all views,
grabbing the mRect field from each associated
nsIFrame and form a union to generate a total bounding rectangle, then
convert to the appropriate coord system.
Will this work ? Is it overkill - ie. does a method exist somewhere already
that will achieve what I'm attempting to do ?

Thanks in advance for any help,
Steve.


class MyClass
{
 public:
     void LoadWebPage(const char *url);

private:
      nsCOMPtr<nsIWebBrowser> m_web_browser;
      nsCOMPtr<nsIWebBrowserChrome> m_chrome;

      // Rest of class definition ...
};

void MyClass::LoadWebPage(const char *url)
{
    nsresult  rv;

     // Create the chrome object. Note that it leaves this function
     // with an extra reference so that it can released correctly during
     // destruction (via Win32UI::Destroy)

     rv =
AppCallbacks::CreateBrowserWindow(nsIWebBrowserChrome::CHROME_DEFAULT,
nsnull, getter_AddRefs(m_chrome));

    if (!m_chrome || !NS_SUCCEEDED(rv))
       return;

     // Start loading a page
     m_chrome->GetWebBrowser(getter_AddRefs(m_web_browser));
     nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(m_web_browser));

     rv = webNav->LoadURI(NS_ConvertASCIItoUCS2(url).get(),
nsIWebNavigation::LOAD_FLAGS_NONE);

    if (!NS_SUCCEEDED(rv))
      return;

     nsCOMPtr<nsIBaseWindow> webBrowserAsWin =
do_QueryInterface(m_web_browser);


    // [PSEUDO CODE]  Get webpage extents ...

    nsRect rect;
    m_web_browser->GetExtents(rect);  // How do I do this using the
embedding API ???

   // [END PSEUDO CODE]



  // Resize window so it's exactly large enough to display the web page
without the need for scrollbars ...
    if (webBrowserAsWin)
         webBrowserAsWin->SetPositionAndSize(rect.x, rect.y, rect.width,
rect.height, PR_TRUE);
}





Reply via email to