Back to index

lightning-sunbird  0.9+nobinonly
Classes | Defines | Functions
nsScrollPortView.cpp File Reference
#include "nsScrollPortView.h"
#include "nsIWidget.h"
#include "nsUnitConversion.h"
#include "nsIDeviceContext.h"
#include "nsGUIEvent.h"
#include "nsWidgetsCID.h"
#include "nsViewsCID.h"
#include "nsIScrollableView.h"
#include "nsILookAndFeel.h"
#include "nsISupportsArray.h"
#include "nsIScrollPositionListener.h"
#include "nsIRegion.h"
#include "nsViewManager.h"
#include "nsIPrefBranch.h"
#include "nsIPrefService.h"
#include "nsCOMPtr.h"
#include "nsServiceManagerUtils.h"
#include <math.h>

Go to the source code of this file.


class  SmoothScroll


#define SMOOTH_SCROLL_PREF_NAME   "general.smoothScroll"


 NS_IMETHODIMP_ (nsIView *) nsScrollPortView
static void ComputeVelocities (PRInt32 aCurVelocity, nscoord aCurPos, nscoord aDstPos, PRInt32 *aVelocities, float aT2P, float aP2T)
static nsresult ClampScrollValues (nscoord &aX, nscoord &aY, nsScrollPortView *aThis)
static void AdjustChildWidgets (nsView *aView, nsPoint aWidgetToParentViewOrigin, float aScale, PRBool aInvalidate)

Define Documentation

Definition at line 62 of file nsScrollPortView.cpp.

Definition at line 61 of file nsScrollPortView.cpp.

#define SMOOTH_SCROLL_PREF_NAME   "general.smoothScroll"

Definition at line 64 of file nsScrollPortView.cpp.

Function Documentation

static void AdjustChildWidgets ( nsView aView,
nsPoint  aWidgetToParentViewOrigin,
float  aScale,
PRBool  aInvalidate 
) [static]

Definition at line 335 of file nsScrollPortView.cpp.

  if (aView->HasWidget()) {
    nsIWidget* widget = aView->GetWidget();
    nsWindowType type;
    if (type != eWindowType_popup) {
      nsRect bounds = aView->GetBounds();
      nsPoint widgetOrigin = aWidgetToParentViewOrigin
        + nsPoint(bounds.x, bounds.y);
      widget->Move(NSTwipsToIntPixels(widgetOrigin.x, aScale),
                   NSTwipsToIntPixels(widgetOrigin.y, aScale));
      if (aInvalidate) {
        // Force the widget and everything in it to repaint. We can't
        // just use Invalidate because the widget might have child
        // widgets and they wouldn't get updated. We can't call
        // UpdateView(aView) because the area to be repainted might be
        // outside aView's clipped bounds. This isn't the greatest way
        // to achieve this, perhaps, but it works.
  } else {
    // Don't recurse if the view has a widget, because we adjusted the view's
    // widget position, and its child widgets are relative to its positon
    nsPoint widgetToViewOrigin = aWidgetToParentViewOrigin
      + aView->GetPosition();

    for (nsView* kid = aView->GetFirstChild(); kid; kid = kid->GetNextSibling())
      AdjustChildWidgets(kid, widgetToViewOrigin, aScale, aInvalidate);

Here is the call graph for this function:

Here is the caller graph for this function:

static nsresult ClampScrollValues ( nscoord aX,
nscoord aY,
nsScrollPortView aThis 
) [static]

Definition at line 225 of file nsScrollPortView.cpp.

  // make sure the new position in in bounds
  nsView* scrolledView = aThis->GetScrolledView();
  if (!scrolledView) return NS_ERROR_FAILURE;
  nsSize scrolledSize;
  nsSize portSize;
  nscoord maxX = scrolledSize.width - portSize.width;
  nscoord maxY = scrolledSize.height - portSize.height;
  if (aX > maxX)
    aX = maxX;
  if (aY > maxY)
    aY = maxY;
  if (aX < 0)
    aX = 0;
  if (aY < 0)
    aY = 0;
  return NS_OK;

Here is the call graph for this function:

Here is the caller graph for this function:

static void ComputeVelocities ( PRInt32  aCurVelocity,
nscoord  aCurPos,
nscoord  aDstPos,
PRInt32 aVelocities,
float  aT2P,
float  aP2T 
) [static]

Definition at line 193 of file nsScrollPortView.cpp.

  // scrolling always works in units of whole pixels. So compute velocities
  // in pixels and then scale them up. This ensures, for example, that
  // a 1-pixel scroll isn't broken into N frames of 1/N pixels each, each
  // frame increment being rounded to 0 whole pixels.
  aCurPos = NSTwipsToIntPixels(aCurPos, aT2P);
  aDstPos = NSTwipsToIntPixels(aDstPos, aT2P);

  PRInt32 i;
  PRInt32 direction = (aCurPos < aDstPos ? 1 : -1);
  PRInt32 absDelta = (aDstPos - aCurPos)*direction;
  PRInt32 baseVelocity = absDelta/SMOOTH_SCROLL_FRAMES;

  for (i = 0; i < SMOOTH_SCROLL_FRAMES; i++) {
    aVelocities[i*2] = baseVelocity;
  nscoord total = baseVelocity*SMOOTH_SCROLL_FRAMES;
  for (i = 0; i < SMOOTH_SCROLL_FRAMES; i++) {
    if (total < absDelta) {
  NS_ASSERTION(total == absDelta, "Invalid velocity sum");

  PRInt32 scale = direction*((PRInt32)aP2T);
  for (i = 0; i < SMOOTH_SCROLL_FRAMES; i++) {
    aVelocities[i*2] *= scale;

Here is the call graph for this function:

Here is the caller graph for this function:

static NS_DEFINE_IID ( kWidgetCID  ,
) [static]

Definition at line 129 of file nsScrollPortView.cpp.

  return this;