Hi,
When I load a webpage using the embedding api, I'm attempting to resize
the client window to the extents of the webpage. 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.
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);
}