コード例 #1
0
ファイル: nsViewManager.cpp プロジェクト: mozilla/pjs
void nsViewManager::ReparentChildWidgets(nsIView* aView, nsIWidget *aNewWidget)
{
  NS_PRECONDITION(aNewWidget, "");

  if (aView->HasWidget()) {
    // Check to see if the parent widget is the
    // same as the new parent. If not then reparent
    // the widget, otherwise there is nothing more
    // to do for the view and its descendants
    nsIWidget* widget = aView->GetWidget();
    nsIWidget* parentWidget = widget->GetParent();
    if (parentWidget) {
      // Child widget
      if (parentWidget != aNewWidget) {
#ifdef DEBUG
        nsresult rv =
#endif
          widget->SetParent(aNewWidget);
        NS_ASSERTION(NS_SUCCEEDED(rv), "SetParent failed!");
      }
    } else {
      // Toplevel widget (popup, dialog, etc)
      widget->ReparentNativeWidget(aNewWidget);
    }
    return;
  }

  // Need to check each of the views children to see
  // if they have a widget and reparent it.

  nsView* view = static_cast<nsView*>(aView);
  for (nsView *kid = view->GetFirstChild(); kid; kid = kid->GetNextSibling()) {
    ReparentChildWidgets(kid, aNewWidget);
  }
}
コード例 #2
0
void nsViewManager::ReparentWidgets(nsView* aView, nsView *aParent)
{
    NS_PRECONDITION(aParent, "Must have a parent");
    NS_PRECONDITION(aView, "Must have a view");

    // Quickly determine whether the view has pre-existing children or a
    // widget. In most cases the view will not have any pre-existing
    // children when this is called.  Only in the case
    // where a view has been reparented by removing it from
    // a reinserting it into a new location in the view hierarchy do we
    // have to consider reparenting the existing widgets for the view and
    // it's descendants.
    if (aView->HasWidget() || aView->GetFirstChild()) {
        nsIWidget* parentWidget = aParent->GetNearestWidget(nullptr);
        if (parentWidget) {
            ReparentChildWidgets(aView, parentWidget);
            return;
        }
        NS_WARNING("Can not find a widget for the parent view");
    }
}