Commit 3b62c939 authored by sharparrow1%yahoo.com's avatar sharparrow1%yahoo.com
Browse files

Bug 332927: Cleanup iframe/frame printing code (and a couple other misc. cleanups)

parent 198842fd
Loading
Loading
Loading
Loading
+15 −56
Original line number Diff line number Diff line
@@ -1633,12 +1633,6 @@ nsEventStateManager::DoScrollTextsize(nsIFrame *aTargetFrame,
    }
}

inline PRBool
ShouldScrollRootView(nsPresContext* aPresContext)
{
  return (aPresContext->Type() == nsPresContext::eContext_PrintPreview);
}

static nsIFrame*
GetParentFrameToScroll(nsPresContext* aPresContext, nsIFrame* aFrame)
{
@@ -1659,38 +1653,6 @@ nsEventStateManager::DoScrollText(nsPresContext* aPresContext,
                                  PRBool aScrollHorizontal,
                                  PRBool aScrollPage)
{
  nsIScrollableView* scrollView = nsnull;
  PRBool scrollRootView = ShouldScrollRootView(aPresContext);

  if (scrollRootView) {
    // Get root scroll view
    nsIViewManager* vm = aPresContext->GetViewManager();
    NS_ENSURE_TRUE(vm, NS_ERROR_FAILURE);
    vm->GetRootScrollableView(&scrollView);
    if (!scrollView) {
      // We don't have root scrollable view in current document.
      // Maybe, this is sub frame on Print Preview.
      // Let's pass to parent document.
      nsIFrame* newFrame = nsnull;
      nsCOMPtr<nsPresContext> newPresContext = nsnull;
      nsresult rv = GetParentScrollingView(aEvent, aPresContext, newFrame,
                                           *getter_AddRefs(newPresContext));
      NS_ENSURE_SUCCESS(rv, rv);
      NS_ENSURE_TRUE(newFrame && newPresContext, NS_ERROR_FAILURE);
      return DoScrollText(newPresContext, newFrame, aEvent, aNumLines,
                          aScrollHorizontal, aScrollPage);
    }
    // find target frame that is root scrollable content
    nsIFrame* targetFrame = aTargetFrame;
    for ( ;targetFrame; targetFrame = targetFrame->GetParent()) {
      nsCOMPtr<nsIScrollableViewProvider> svp = do_QueryInterface(targetFrame);
      if (svp && scrollView == svp->GetScrollableView())
        break;
    }
    NS_ENSURE_TRUE(targetFrame, NS_ERROR_FAILURE);
    aTargetFrame = targetFrame;
  }

  nsCOMPtr<nsIContent> targetContent = aTargetFrame->GetContent();
  if (!targetContent)
    GetFocusedContent(getter_AddRefs(targetContent));
@@ -1738,7 +1700,6 @@ nsEventStateManager::DoScrollText(nsPresContext* aPresContext,
      target->DispatchEvent(event, &defaultActionEnabled);
      if (!defaultActionEnabled)
        return NS_OK;
      if (!scrollRootView) {
      // Re-resolve |aTargetFrame| in case it was destroyed by the
      // DOM event handler above, bug 257998.
      aTargetFrame =
@@ -1752,10 +1713,10 @@ nsEventStateManager::DoScrollText(nsPresContext* aPresContext,
      }
    }
  }
  }

  nsIScrollableView* scrollView;
  nsIFrame* scrollFrame = aTargetFrame;
  PRBool passToParent = !scrollRootView;
  PRBool passToParent = PR_TRUE;

  for (; scrollFrame && passToParent;
       scrollFrame = GetParentFrameToScroll(aPresContext, scrollFrame)) {
@@ -1828,14 +1789,11 @@ nsEventStateManager::DoScrollText(nsPresContext* aPresContext,
    nsresult rv;
    nsIFrame* newFrame = nsnull;
    nsCOMPtr<nsPresContext> newPresContext;

    rv = GetParentScrollingView(aEvent, aPresContext, newFrame,
                                *getter_AddRefs(newPresContext));
    if (NS_SUCCEEDED(rv) && newFrame)
      return DoScrollText(newPresContext, newFrame, aEvent, aNumLines,
                          aScrollHorizontal, aScrollPage);
    else
      return NS_ERROR_FAILURE;
  }

  return NS_OK;
@@ -1871,7 +1829,8 @@ nsEventStateManager::GetParentScrollingView(nsInputEvent *aEvent,
      break;
    }
  }
  NS_ENSURE_TRUE(pPresShell, NS_ERROR_FAILURE);
  if (!pPresShell)
    return NS_ERROR_FAILURE;

  /* now find the content node in our parent docshell's document that
     corresponds to our docshell */
+2 −10
Original line number Diff line number Diff line
@@ -4775,11 +4775,7 @@ nsCSSFrameConstructor::ConstructRootFrame(nsIContent* aDocElement,
  // - renders the document element's background. This ensures the background covers
  //   the entire canvas as specified by the CSS2 spec

  PRBool isPaginated = presContext->IsPaginated();
  PRBool isPrintPreview =
    presContext->Type() == nsPresContext::eContext_PrintPreview;
  PRBool isPageLayout =
    presContext->Type() == nsPresContext::eContext_PageLayout;
  PRBool isPaginated = presContext->IsRootPaginatedDocument();

  nsIFrame* rootFrame = nsnull;
  nsIAtom* rootPseudo;
@@ -4842,11 +4838,7 @@ nsCSSFrameConstructor::ConstructRootFrame(nsIContent* aDocElement,
  }

  if (isPaginated) {
    if (isPrintPreview || isPageLayout) {
    isScrollable = presContext->HasPaginatedScrolling();
    } else {
      isScrollable = PR_FALSE; // we are printing
    }
  }

  // We no longer need to do overflow propagation here. It's taken care of
+1 −1
Original line number Diff line number Diff line
@@ -157,7 +157,7 @@ static NS_DEFINE_CID(kSelectionImageService, NS_SELECTIONIMAGESERVICE_CID);
nsPresContext::nsPresContext(nsPresContextType aType)
  : mType(aType), mTextZoom(1.0),
    mPageSize(-1, -1), mIsRootPaginatedDocument(PR_FALSE),
    mCanPaginatedScroll(PR_TRUE),
    mCanPaginatedScroll(PR_FALSE),
    mViewportStyleOverflow(NS_STYLE_OVERFLOW_AUTO, NS_STYLE_OVERFLOW_AUTO),
    mCompatibilityMode(eCompatibility_FullStandards),
    mImageAnimationModePref(imgIContainer::kNormalAnimMode),
+11 −28
Original line number Diff line number Diff line
@@ -91,9 +91,6 @@
#include "nsDisplayList.h"
#include "nsUnicharUtils.h"

#ifdef NS_PRINTING
#include "nsIWebBrowserPrint.h"
#endif
// For Accessibility
#ifdef ACCESSIBILITY
#include "nsIAccessibilityService.h"
@@ -255,33 +252,22 @@ nsSubDocumentFrame::Init(nsIContent* aContent,
          contentParent = (nsIFrame*)value;
    }

    nsHTMLContainerFrame::CreateViewForFrame(this, contentParent, PR_TRUE);
    rv = nsHTMLContainerFrame::CreateViewForFrame(this, contentParent, PR_TRUE);
    NS_ENSURE_SUCCESS(rv, rv);
  }
  nsIView* view = GetView();
  NS_ASSERTION(view, "We should always have a view now");

  if (aParent->GetStyleDisplay()->mDisplay == NS_STYLE_DISPLAY_DECK
      && !view->HasWidget()) {
    view->CreateWidget(kCChildCID);
  }

  // determine if we are a printcontext
  PRBool shouldCreateDoc;

  if (aPresContext->Medium() == nsLayoutAtoms::print) {
    if (aPresContext->Type() == nsPresContext::eContext_PrintPreview) {
      // for print preview we want to create the view and widget but
      // we do not want to load the document, it is already loaded.
  if (!aPresContext->IsDynamic()) {
    // We let the printing code take care of loading the document; just
    // create a widget for it to use
    rv = CreateViewAndWidget(eContentTypeContent);
    NS_ENSURE_SUCCESS(rv,rv);
    }

    shouldCreateDoc = PR_FALSE;
  } else {
    shouldCreateDoc = PR_TRUE;
  }

  if (shouldCreateDoc) {
    rv = ShowDocShell();
    NS_ENSURE_SUCCESS(rv,rv);
    mDidCreateDoc = PR_TRUE;
@@ -397,12 +383,9 @@ nsSubDocumentFrame::Reflow(nsPresContext* aPresContext,
    aDesiredSize.height += border.top + border.bottom;
  }

  // might not have an inner view yet during printing
  if (mInnerView) {
  nsIViewManager* vm = mInnerView->GetViewManager();
  vm->MoveViewTo(mInnerView, offset.x, offset.y);
    vm->ResizeView(mInnerView, nsRect(0, 0, innerSize.width, innerSize.height), PR_TRUE);
  }
  vm->ResizeView(mInnerView, nsRect(nsPoint(0, 0), innerSize), PR_TRUE);

  if (aDesiredSize.mComputeMEW) {   
    nscoord defaultAutoWidth = NSIntPixelsToTwips(300, aPresContext->ScaledPixelsToTwips());
+7 −2
Original line number Diff line number Diff line
@@ -1468,6 +1468,11 @@ nsGfxScrollFrameInner::ScrollbarStyles
nsGfxScrollFrameInner::GetScrollbarStylesFromFrame() const
{
  ScrollbarStyles result;

  if (mNeverHasVerticalScrollbar && mNeverHasHorizontalScrollbar) {
    return ScrollbarStyles(NS_STYLE_OVERFLOW_HIDDEN, NS_STYLE_OVERFLOW_HIDDEN);
  }

  if (mIsRoot) {
    nsPresContext *presContext = mOuter->GetPresContext();
    result = presContext->GetViewportOverflowOverride();
@@ -1609,10 +1614,10 @@ nsGfxScrollFrameInner::CreateAnonymousContent(nsISupportsArray& aAnonymousChildr

  // Don't create scrollbars if we're printing/print previewing
  // Get rid of this code when printing moves to its own presentation
  if (presContext->IsPaginated()) {
  if (!presContext->IsDynamic()) {
    // allow scrollbars if this is the child of the viewport, because
    // we must be the scrollbars for the print preview window
    if (!mIsRoot) {
    if (!(mIsRoot && presContext->HasPaginatedScrolling())) {
      mNeverHasVerticalScrollbar = mNeverHasHorizontalScrollbar = PR_TRUE;
      return;
    }
Loading