|
|
|
Lines 2285-2347
DocumentViewerImpl::MakeWindow(nsIWidget
|
Link Here
|
|---|
|
| 2285 |
if (NS_FAILED(rv)) |
2285 |
if (NS_FAILED(rv)) |
| 2286 |
return rv; |
2286 |
return rv; |
| 2287 |
|
2287 |
|
| 2288 |
// Reset the bounds offset so the root view is set to 0,0. The |
2288 |
// Reset the bounds offset so the root view is set to 0,0. The |
| 2289 |
// offset is specified in nsIViewManager::Init above. |
2289 |
// offset is specified in nsIViewManager::Init above. |
| 2290 |
// Besides, layout will reset the root view to (0,0) during reflow, |
2290 |
// Besides, layout will reset the root view to (0,0) during reflow, |
| 2291 |
// so changing it to 0,0 eliminates placing the root view in the |
2291 |
// so changing it to 0,0 eliminates placing the root view in the |
| 2292 |
// wrong place initially. |
2292 |
// wrong place initially. |
| 2293 |
tbounds.x = 0; |
2293 |
tbounds.x = 0; |
| 2294 |
tbounds.y = 0; |
2294 |
tbounds.y = 0; |
| 2295 |
|
2295 |
|
| 2296 |
// Create a child window of the parent that is our "root view/window" |
2296 |
// Create a child window of the parent that is our "root view/window" |
| 2297 |
// if aParentWidget has a view, we'll hook our view manager up to its view tree |
|
|
| 2298 |
nsIView* containerView = nsView::GetViewFor(aParentWidget); |
2297 |
nsIView* containerView = nsView::GetViewFor(aParentWidget); |
| 2299 |
|
2298 |
|
| 2300 |
if (containerView) { |
|
|
| 2301 |
// see if the containerView has already been hooked into a foreign view manager hierarchy |
| 2302 |
// if it has, then we have to hook into the hierarchy too otherwise bad things will happen. |
| 2303 |
nsIViewManager* containerVM = containerView->GetViewManager(); |
| 2304 |
nsIView* pView = containerView; |
| 2305 |
do { |
| 2306 |
pView = pView->GetParent(); |
| 2307 |
} while (pView && pView->GetViewManager() == containerVM); |
| 2308 |
|
| 2309 |
if (!pView) { |
| 2310 |
// OK, so the container is not already hooked up into a foreign view manager hierarchy. |
| 2311 |
// That means we can choose not to hook ourselves up. |
| 2312 |
// |
| 2313 |
// If the parent container is a chrome shell then we won't hook into its view |
| 2314 |
// tree. This will improve performance a little bit (especially given scrolling/painting perf bugs) |
| 2315 |
// but is really just for peace of mind. This check can be removed if we want to support fancy |
| 2316 |
// chrome effects like transparent controls floating over content, transparent Web browsers, and |
| 2317 |
// things like that, and the perf bugs are fixed. |
| 2318 |
nsCOMPtr<nsIDocShellTreeItem> container(do_QueryReferent(mContainer)); |
| 2319 |
nsCOMPtr<nsIDocShellTreeItem> parentContainer; |
| 2320 |
PRInt32 itemType; |
| 2321 |
if (nsnull == container |
| 2322 |
|| NS_FAILED(container->GetParent(getter_AddRefs(parentContainer))) |
| 2323 |
|| nsnull == parentContainer |
| 2324 |
|| NS_FAILED(parentContainer->GetItemType(&itemType)) |
| 2325 |
|| itemType != nsIDocShellTreeItem::typeContent) { |
| 2326 |
containerView = nsnull; |
| 2327 |
} |
| 2328 |
} |
| 2329 |
} |
| 2330 |
|
| 2331 |
// Create a view |
2299 |
// Create a view |
| 2332 |
nsIView* view = mViewManager->CreateView(tbounds, containerView); |
2300 |
nsIView* view = mViewManager->CreateView(tbounds, containerView); |
| 2333 |
if (!view) |
2301 |
if (!view) |
| 2334 |
return NS_ERROR_OUT_OF_MEMORY; |
2302 |
return NS_ERROR_OUT_OF_MEMORY; |
| 2335 |
|
2303 |
|
|
|
2304 |
if (containerView) { |
| 2305 |
nsCOMPtr<nsIDocShellTreeItem> container(do_QueryReferent(mContainer)); |
| 2306 |
nsCOMPtr<nsIDocShellTreeItem> parentContainer; |
| 2307 |
PRInt32 itemType; |
| 2308 |
PRInt32 parentItemType; |
| 2309 |
if (container |
| 2310 |
&& NS_SUCCEEDED(container->GetItemType(&itemType)) |
| 2311 |
&& itemType == nsIDocShellTreeItem::typeContent |
| 2312 |
&& NS_SUCCEEDED(container->GetParent(getter_AddRefs(parentContainer))) |
| 2313 |
&& parentContainer |
| 2314 |
&& NS_SUCCEEDED(parentContainer->GetItemType(&parentItemType)) |
| 2315 |
&& parentItemType != nsIDocShellTreeItem::typeContent) { |
| 2316 |
view->SetUseDefaultBackgroundColor(PR_TRUE); |
| 2317 |
} |
| 2318 |
} |
| 2319 |
|
| 2336 |
// pass in a native widget to be the parent widget ONLY if the view hierarchy will stand alone. |
2320 |
// pass in a native widget to be the parent widget ONLY if the view hierarchy will stand alone. |
| 2337 |
// otherwise the view will find its own parent widget and "do the right thing" to |
2321 |
// otherwise the view will find its own parent widget and "do the right thing" to |
| 2338 |
// establish a parent/child widget relationship |
2322 |
// establish a parent/child widget relationship |
| 2339 |
rv = view->CreateWidget(kWidgetCID, nsnull, |
2323 |
rv = view->CreateWidget(kWidgetCID, nsnull, |
| 2340 |
containerView != nsnull ? nsnull : aParentWidget->GetNativeData(NS_NATIVE_WIDGET), |
2324 |
containerView != nsnull ? nsnull : aParentWidget->GetNativeData(NS_NATIVE_WIDGET), |
| 2341 |
PR_TRUE, PR_FALSE); |
2325 |
PR_TRUE, PR_FALSE); |
| 2342 |
if (NS_FAILED(rv)) |
2326 |
if (NS_FAILED(rv)) |
| 2343 |
return rv; |
2327 |
return rv; |
| 2344 |
|
2328 |
|
| 2345 |
// Setup hierarchical relationship in view manager |
2329 |
// Setup hierarchical relationship in view manager |
| 2346 |
mViewManager->SetRootView(view); |
2330 |
mViewManager->SetRootView(view); |
| 2347 |
|
2331 |
|