Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes
nsDeviceContextQt Class Reference

#include <nsDeviceContextQt.h>

List of all members.

Public Member Functions

 nsDeviceContextQt ()
virtual ~nsDeviceContextQt ()
NS_IMETHOD Init (nsNativeWidget aNativeWidget)
NS_IMETHOD CreateRenderingContext (nsIRenderingContext *&aContext)
NS_IMETHOD CreateRenderingContext (nsIView *aView, nsIRenderingContext *&aContext)
NS_IMETHOD CreateRenderingContext (nsIWidget *aWidget, nsIRenderingContext *&aContext)
NS_IMETHOD CreateRenderingContext (nsIDrawingSurface *aSurface, nsIRenderingContext *&aContext)
NS_IMETHOD CreateRenderingContextInstance (nsIRenderingContext *&aContext)
NS_IMETHOD SupportsNativeWidgets (PRBool &aSupportsWidgets)
NS_IMETHOD GetScrollBarDimensions (float &aWidth, float &aHeight) const
NS_IMETHOD GetSystemFont (nsSystemFontID anID, nsFont *aFont) const
NS_IMETHOD CheckFontExistence (const nsString &aFontName)
NS_IMETHOD GetDeviceSurfaceDimensions (PRInt32 &aWidth, PRInt32 &aHeight)
NS_IMETHOD GetClientRect (nsRect &aRect)
NS_IMETHOD GetRect (nsRect &aRect)
NS_IMETHOD GetDeviceContextFor (nsIDeviceContextSpec *aDevice, nsIDeviceContext *&aContext)
NS_IMETHOD BeginDocument (PRUnichar *aTitle, PRUnichar *aPrintToFileName, PRInt32 aStartPage, PRInt32 aEndPage)
NS_IMETHOD EndDocument (void)
NS_IMETHOD BeginPage (void)
NS_IMETHOD EndPage (void)
NS_IMETHOD GetDepth (PRUint32 &aDepth)
NS_IMETHOD Observe (nsISupports *aSubject, const char *aTopic, const PRUnichar *aData)
nsresult SetDPI (PRInt32 dpi)

Private Member Functions

nsresult GetSystemFontInfo (nsFont *aFont) const

Private Attributes

PRUint32 mDepth
PRInt16 mScrollbarHeight
PRInt16 mScrollbarWidth
QWidget * mWidget
PRInt32 mWidth
PRInt32 mHeight
float mWidthFloat
float mHeightFloat

Static Private Attributes

static nscoord mDpi = 0

Detailed Description

Definition at line 51 of file nsDeviceContextQt.h.


Constructor & Destructor Documentation

Definition at line 85 of file nsDeviceContextQt.cpp.

  : DeviceContextImpl()
{
  mTwipsToPixels = 1.0;
  mPixelsToTwips = 1.0;
  mDepth = 0 ;
  mWidthFloat = 0.0f;
  mHeightFloat = 0.0f;
  mWidth = -1;
  mHeight = -1;
}

Definition at line 97 of file nsDeviceContextQt.cpp.

{
  nsCOMPtr<nsIPrefBranch2> pbi = do_GetService(NS_PREFSERVICE_CONTRACTID);
  if (pbi) {
    pbi->RemoveObserver("layout.css.dpi", this);
  }
}

Here is the call graph for this function:


Member Function Documentation

NS_IMETHODIMP nsDeviceContextQt::BeginDocument ( PRUnichar aTitle,
PRUnichar aPrintToFileName,
PRInt32  aStartPage,
PRInt32  aEndPage 
)

Definition at line 383 of file nsDeviceContextQt.cpp.

{
  return NS_OK;
}

Definition at line 396 of file nsDeviceContextQt.cpp.

{
  return NS_OK;
}

Definition at line 278 of file nsDeviceContextQt.cpp.

{
  QString family = QString::fromUcs2(aFontName.get());
  QStringList families = QFontDatabase().families();
  return families.find(family) != families.end();
}

Here is the call graph for this function:

Definition at line 179 of file nsDeviceContextQt.cpp.

{
  nsresult rv;
  nsDrawingSurfaceQt *surf;
  QPaintDevice *pDev = nsnull;

  if (mWidget)
    pDev = (QPaintDevice*)mWidget;

  // to call init for this, we need to have a valid nsDrawingSurfaceQt created
  nsCOMPtr<nsRenderingContextQt> pContext( new nsRenderingContextQt() );

  // create the nsDrawingSurfaceQt
  surf = new nsDrawingSurfaceQt();

  if (surf) {
    //Handled by the nsDrawingSurfaceQt
    //FIXME: instead of passing it around
    //       create it in the nsDrawingSurface init method
    QPainter *gc = new QPainter();

    // init the nsDrawingSurfaceQt
    if (pDev)
      rv = surf->Init(pDev,gc);
    else
      rv = surf->Init(gc,10,10,0);

    if (NS_SUCCEEDED(rv))
      // Init the nsRenderingContextQt
      rv = pContext->Init(this,surf);
  }
  else
    rv = NS_ERROR_OUT_OF_MEMORY;

  if (NS_SUCCEEDED(rv)) {
    aContext = pContext;
    NS_ADDREF(aContext);
  }
  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 60 of file nsDeviceContextQt.h.

    {return (DeviceContextImpl::CreateRenderingContext(aView,aContext));}

Definition at line 62 of file nsDeviceContextQt.h.

    {return (DeviceContextImpl::CreateRenderingContext(aWidget,aContext));}

Definition at line 64 of file nsDeviceContextQt.h.

    {return (DeviceContextImpl::CreateRenderingContext(aSurface, aContext));}

Definition at line 221 of file nsDeviceContextQt.cpp.

{
  return CreateRenderingContext(aContext);
}

Here is the call graph for this function:

Definition at line 391 of file nsDeviceContextQt.cpp.

{
  return NS_OK;
}

Definition at line 401 of file nsDeviceContextQt.cpp.

{
  return NS_OK;
}

Definition at line 314 of file nsDeviceContextQt.cpp.

{
  return GetRect(aRect);
}

Here is the call graph for this function:

Definition at line 406 of file nsDeviceContextQt.cpp.

{
  aDepth = mDepth;
  return NS_OK;
}

Definition at line 319 of file nsDeviceContextQt.cpp.

{
  nsresult                 rv;
  PrintMethod              method;
  nsDeviceContextSpecQt   *spec = NS_STATIC_CAST(nsDeviceContextSpecQt *, aDevice);

  rv = spec->GetPrintMethod(method);
  if (NS_FAILED(rv))
    return rv;

#ifdef USE_XPRINT
  if (method == pmXprint) { // XPRINT
    static NS_DEFINE_CID(kCDeviceContextXp, NS_DEVICECONTEXTXP_CID);
    nsCOMPtr<nsIDeviceContextXp> dcxp(do_CreateInstance(kCDeviceContextXp, &rv));
    NS_ASSERTION(NS_SUCCEEDED(rv), "Couldn't create Xp Device context.");
    if (NS_FAILED(rv))
      return rv;

    rv = dcxp->SetSpec(aDevice);
    if (NS_FAILED(rv))
      return rv;

    rv = dcxp->InitDeviceContextXP((nsIDeviceContext*)aContext,
                                   (nsIDeviceContext*)this);
    if (NS_FAILED(rv))
      return rv;

    rv = dcxp->QueryInterface(NS_GET_IID(nsIDeviceContext),
                              (void **)&aContext);
    return rv;
  }
  else
#endif /* USE_XPRINT */
#ifdef USE_POSTSCRIPT
  if (method == pmPostScript) { // PostScript
    // default/PS
    static NS_DEFINE_CID(kCDeviceContextPS, NS_DEVICECONTEXTPS_CID);

    // Create a Postscript device context
    nsCOMPtr<nsIDeviceContextPS> dcps(do_CreateInstance(kCDeviceContextPS, &rv));
    NS_ASSERTION(NS_SUCCEEDED(rv), "Couldn't create PS Device context.");
    if (NS_FAILED(rv))
      return rv;

    rv = dcps->SetSpec(aDevice);
    if (NS_FAILED(rv))
      return rv;

    rv = dcps->InitDeviceContextPS((nsIDeviceContext*)aContext,
                                   (nsIDeviceContext*)this);
    if (NS_FAILED(rv))
      return rv;

    rv = dcps->QueryInterface(NS_GET_IID(nsIDeviceContext),
                              (void **)&aContext);
    return rv;
  }
#endif /* USE_POSTSCRIPT */

  NS_WARNING("no print module created.");
  return NS_ERROR_UNEXPECTED;
}

Here is the call graph for this function:

Definition at line 285 of file nsDeviceContextQt.cpp.

{
  if (-1 == mWidth)
    mWidth =  NSToIntRound(mWidthFloat * mDevUnitsToAppUnits);

  if (-1 == mHeight)
    mHeight =  NSToIntRound(mHeightFloat * mDevUnitsToAppUnits);

  aWidth = mWidth;
  aHeight = mHeight;

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 300 of file nsDeviceContextQt.cpp.

{
  PRInt32 width,height;
  nsresult rv;

  rv = GetDeviceSurfaceDimensions(width,height);
  aRect.x = 0;
  aRect.y = 0;
  aRect.width = width;
  aRect.height = height;

  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

NS_IMETHODIMP nsDeviceContextQt::GetScrollBarDimensions ( float &  aWidth,
float &  aHeight 
) const

Definition at line 237 of file nsDeviceContextQt.cpp.

{
  float scale;
  GetCanonicalPixelScale(scale);
  aWidth = mScrollbarWidth * mPixelsToTwips * scale;
  aHeight = mScrollbarHeight * mPixelsToTwips * scale;

  return NS_OK;
}

Definition at line 487 of file nsDeviceContextQt.cpp.

{
  nsresult status = NS_OK;
  int rawWeight;
  QFont theFont = QApplication::font();
  QFontInfo theFontInfo(theFont);

  aFont->style       = NS_FONT_STYLE_NORMAL;
  aFont->weight      = NS_FONT_WEIGHT_NORMAL;
  aFont->decorations = NS_FONT_DECORATION_NONE;
  aFont->name.Assign(theFontInfo.family().ucs2());
  if (theFontInfo.bold()) {
    aFont->weight = NS_FONT_WEIGHT_BOLD;
  }
  rawWeight = theFontInfo.pixelSize();
  aFont->size = NSIntPixelsToTwips(rawWeight,mPixelsToTwips);
  if (theFontInfo.italic()) {
    aFont->style = NS_FONT_STYLE_ITALIC;
  }
  if (theFontInfo.underline()) {
    aFont->decorations = NS_FONT_DECORATION_UNDERLINE;
  }

  return (status);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 105 of file nsDeviceContextQt.cpp.

{
  PRBool  bCleanUp = PR_FALSE;
  QWidget *pWidget  = nsnull;

  mWidget = (QWidget*)aNativeWidget;

  if (mWidget != nsnull)
    pWidget = mWidget;
  else {
    pWidget = new QWidget();
    bCleanUp = PR_TRUE;
  }

  nsresult ignore;
  nsCOMPtr<nsIScreenManager> sm(do_GetService("@mozilla.org/gfx/screenmanager;1",
                                              &ignore));
  if (sm) {
    nsCOMPtr<nsIScreen> screen;
    sm->GetPrimaryScreen(getter_AddRefs(screen));
    if (screen) {
      PRInt32 x,y,width,height,depth;

      screen->GetAvailRect(&x,&y,&width,&height);
      screen->GetPixelDepth(&depth);
      mWidthFloat = float(width);
      mHeightFloat = float(height);
      mDepth = NS_STATIC_CAST(PRUint32,depth);
    }
  }

  if (!mDpi) {
    // Set prefVal the value of the preference "layout.css.dpi"
    // or -1 if we can't get it.
    // If it's negative, we pretend it's not set.
    // If it's 0, it means force use of the operating system's logical resolution.
    // If it's positive, we use it as the logical resolution
    PRInt32 prefVal = -1;
    nsCOMPtr<nsIPrefBranch> prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID));
    if (prefBranch) {
      nsresult res = prefBranch->GetIntPref("layout.css.dpi",
                                            &prefVal);
      if (NS_FAILED(res)) {
        prefVal = -1;
      }
      nsCOMPtr<nsIPrefBranch2> pbi(do_QueryInterface(prefBranch));
      pbi->AddObserver("layout.css.dpi", this, PR_FALSE);
    }

    SetDPI(prefVal);
  } else {
    SetDPI(mDpi);
  }

#ifdef MOZ_LOGGING
  static PRBool once = PR_TRUE;
  if (once) {
    PR_LOG(gQtLogModule, QT_BASIC, ("GFX: dpi=%d t2p=%g p2t=%g depth=%d\n",
           mDpi,mTwipsToPixels,mPixelsToTwips,mDepth));
    once = PR_FALSE;
  }
#endif

  QStyle &style = pWidget->style();
  mScrollbarWidth = mScrollbarHeight = style.pixelMetric(QStyle::PM_ScrollBarExtent);

  DeviceContextImpl::CommonInit();

  if (bCleanUp)
    delete pWidget;
  return NS_OK;
}

Here is the call graph for this function:

NS_IMETHODIMP nsDeviceContextQt::Observe ( nsISupports *  aSubject,
const char *  aTopic,
const PRUnichar aData 
)

Definition at line 462 of file nsDeviceContextQt.cpp.

{
  if (nsCRT::strcmp(aTopic, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID) != 0) {
    // Our local observer only handles pref changes.
    // Forward everything else to our super class.
    return DeviceContextImpl::Observe(aSubject, aTopic, aData);
  }

  nsCOMPtr<nsIPrefBranch> prefBranch(do_QueryInterface(aSubject));
  NS_ASSERTION(prefBranch,
               "All pref change observer subjects implement nsIPrefBranch");
  nsCAutoString prefName(NS_LossyConvertUCS2toASCII(aData).get());

  if (prefName.Equals(NS_LITERAL_CSTRING("layout.css.dpi"))) {
    PRInt32 dpi;
    nsresult rv = prefBranch->GetIntPref(prefName.get(), &dpi);
    if (NS_SUCCEEDED(rv))
      SetDPI(dpi);
    return NS_OK;
  } else
    return DeviceContextImpl::Observe(aSubject, aTopic, aData);
}

Here is the call graph for this function:

Definition at line 412 of file nsDeviceContextQt.cpp.

{
  // Set OSVal to what the operating system thinks the logical resolution is.
  PRInt32 OSVal = 0;

  QWidget *pDev = mWidget;
  if (!pDev) {
    QWidgetList *wlist = QApplication::allWidgets();
    pDev = wlist->first();
    qDebug("number of widgets is %d", wlist->count() );
    delete wlist;
  }

  QPaintDeviceMetrics qPaintMetrics(pDev);
  OSVal = qPaintMetrics.logicalDpiX();


#ifdef DEBUG
  if (!pDev)
    qDebug("nsDeviceContextQt::SetDPI called without widget (find cleaner solution)");
#endif

  if (aDpi > 0) {
    // If there's a valid pref value for the logical resolution,
    // use it.
    mDpi = aDpi;
  }
  else if (aDpi == 0 || OSVal > 96) {
    // Either if the pref is 0 (force use of OS value) or the OS
    // value is bigger than 96, use the OS value.
    mDpi = OSVal;
  }
  else {
    // if we couldn't get the pref or it's negative, and the OS
    // value is under 96ppi, then use 96.
    mDpi = 96;
  }

  int pt2t = 72;

  // make p2t a nice round number - this prevents rounding problems
  mPixelsToTwips = float(NSToIntRound(float(NSIntPointsToTwips(pt2t)) / float(aDpi)));
  mTwipsToPixels = 1.0f / mPixelsToTwips;

  // XXX need to reflow all documents

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 227 of file nsDeviceContextQt.cpp.

{
  //XXX it is very critical that this not lie!! MMP
  // read the comments in the mac code for this
  // ##############
  aSupportsWidgets = PR_TRUE;

  return NS_OK;
}

Member Data Documentation

Definition at line 98 of file nsDeviceContextQt.h.

nscoord nsDeviceContextQt::mDpi = 0 [static, private]

Definition at line 107 of file nsDeviceContextQt.h.

Definition at line 103 of file nsDeviceContextQt.h.

Definition at line 105 of file nsDeviceContextQt.h.

Definition at line 99 of file nsDeviceContextQt.h.

Definition at line 100 of file nsDeviceContextQt.h.

QWidget* nsDeviceContextQt::mWidget [private]

Definition at line 101 of file nsDeviceContextQt.h.

Definition at line 102 of file nsDeviceContextQt.h.

Definition at line 104 of file nsDeviceContextQt.h.


The documentation for this class was generated from the following files: