nsresult
nsFilteredContentIterator::PositionAt(nsINode* aCurNode)
{
  NS_ENSURE_TRUE(mCurrentIterator, NS_ERROR_FAILURE);
  mIsOutOfRange = false;
  return mCurrentIterator->PositionAt(aCurNode);
}
bool
WheelScrollAnimation::DoSample(FrameMetrics& aFrameMetrics, const TimeDuration& aDelta)
{
  TimeStamp now = AsyncPanZoomController::GetFrameTime();
  CSSToParentLayerScale2D zoom = aFrameMetrics.GetZoom();

  // If the animation is finished, make sure the final position is correct by
  // using one last displacement. Otherwise, compute the delta via the timing
  // function as normal.
  bool finished = IsFinished(now);
  nsPoint sampledDest = finished
                        ? mDestination
                        : PositionAt(now);
  ParentLayerPoint displacement =
    (CSSPoint::FromAppUnits(sampledDest) - aFrameMetrics.GetScrollOffset()) * zoom;

  // Note: we ignore overscroll for wheel animations.
  ParentLayerPoint adjustedOffset, overscroll;
  mApzc.mX.AdjustDisplacement(displacement.x, adjustedOffset.x, overscroll.x);
  mApzc.mY.AdjustDisplacement(displacement.y, adjustedOffset.y, overscroll.y,
                              !aFrameMetrics.AllowVerticalScrollWithWheel());
  if (IsZero(adjustedOffset)) {
    // Nothing more to do - end the animation.
    return false;
  }

  aFrameMetrics.ScrollBy(adjustedOffset / zoom);
  return !finished;
}
//------------------------------------------------------------
// Helper function to see if the next/prev node should be skipped
void
nsFilteredContentIterator::CheckAdvNode(nsIDOMNode* aNode, bool& aDidSkip, eDirectionType aDir)
{
  aDidSkip      = false;
  mIsOutOfRange = false;

  if (aNode && mFilter) {
    nsCOMPtr<nsIDOMNode> currentNode = aNode;
    bool skipIt;
    while (1) {
      nsresult rv = mFilter->Skip(aNode, &skipIt);
      if (NS_SUCCEEDED(rv) && skipIt) {
        aDidSkip = true;
        // Get the next/prev node and then 
        // see if we should skip that
        nsCOMPtr<nsIDOMNode> advNode;
        rv = AdvanceNode(aNode, *getter_AddRefs(advNode), aDir);
        if (NS_SUCCEEDED(rv) && advNode) {
          aNode = advNode;
        } else {
          return; // fell out of range
        }
      } else {
        if (aNode != currentNode) {
          nsCOMPtr<nsIContent> content(do_QueryInterface(aNode));
          mCurrentIterator->PositionAt(content);
        }
        return; // found something
      }
    }
  }
}
bool
WheelScrollAnimation::DoSample(FrameMetrics& aFrameMetrics, const TimeDuration& aDelta)
{
  TimeStamp now = AsyncPanZoomController::GetFrameTime();
  CSSToParentLayerScale2D zoom = aFrameMetrics.GetZoom();

  // If the animation is finished, make sure the final position is correct by
  // using one last displacement. Otherwise, compute the delta via the timing
  // function as normal.
  bool finished = IsFinished(now);
  nsPoint sampledDest = finished
                        ? mDestination
                        : PositionAt(now);
  ParentLayerPoint displacement =
    (CSSPoint::FromAppUnits(sampledDest) - aFrameMetrics.GetScrollOffset()) * zoom;

  // Note: we ignore overscroll for wheel animations.
  ParentLayerPoint adjustedOffset, overscroll;
  mApzc.mX.AdjustDisplacement(displacement.x, adjustedOffset.x, overscroll.x);
  mApzc.mY.AdjustDisplacement(displacement.y, adjustedOffset.y, overscroll.y,
                              !aFrameMetrics.AllowVerticalScrollWithWheel());

  // If we expected to scroll, but there's no more scroll range on either axis,
  // then end the animation early. Note that the initial displacement could be 0
  // if the compositor ran very quickly (<1ms) after the animation was created.
  // When that happens we want to make sure the animation continues.
  if (!IsZero(displacement) && IsZero(adjustedOffset)) {
    // Nothing more to do - end the animation.
    return false;
  }

  aFrameMetrics.ScrollBy(adjustedOffset / zoom);
  return !finished;
}
Example #5
0
void
DataView::MouseMoved(BPoint where, uint32 transit, const BMessage *dragMessage)
{
	if (transit == B_EXITED_VIEW && fDragMessageSize > 0) {
		SetSelection(fStoredStart, fStoredEnd);
		fDragMessageSize = -1;
	}

	if (dragMessage && AcceptsDrop(dragMessage)) {
		// handle drag message and tracking

		if (transit == B_ENTERED_VIEW) {
			fStoredStart = fStart;
			fStoredEnd = fEnd;

			const void *data;
			ssize_t size;
			if (dragMessage->FindData("text/plain", B_MIME_TYPE, &data, &size) == B_OK
				|| dragMessage->FindData("text/plain", B_MIME_TYPE, &data, &size) == B_OK)
				fDragMessageSize = size;
		} else if (fDragMessageSize > 0) {
			view_focus newFocus;
			int32 start = PositionAt(kNoFocus, where, &newFocus);
			int32 end = start + fDragMessageSize - 1;

			SetSelection(start, end);
			MakeVisible(start);
		}
		return;
	}

	if (fMouseSelectionStart == -1)
		return;

	int32 end = PositionAt(fFocus, where);
	if (end == -1)
		return;

	SetSelection(fMouseSelectionStart, end);
	MakeVisible(end);
}
void
nsContentIterator::Last()
{
  NS_ASSERTION(mLast, "No last node!");

  if (mLast) {
#ifdef DEBUG
    nsresult rv =
#endif
    PositionAt(mLast);

    NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to position iterator!");
  }

  mIsDone = mLast == nsnull;
}
bool
GenericScrollAnimation::DoSample(FrameMetrics& aFrameMetrics, const TimeDuration& aDelta)
{
  TimeStamp now = mApzc.GetFrameTime();
  CSSToParentLayerScale2D zoom = aFrameMetrics.GetZoom();

  // If the animation is finished, make sure the final position is correct by
  // using one last displacement. Otherwise, compute the delta via the timing
  // function as normal.
  bool finished = IsFinished(now);
  nsPoint sampledDest = finished
                        ? mDestination
                        : PositionAt(now);
  ParentLayerPoint displacement =
    (CSSPoint::FromAppUnits(sampledDest) - aFrameMetrics.GetScrollOffset()) * zoom;

  if (finished) {
    mApzc.mX.SetVelocity(0);
    mApzc.mY.SetVelocity(0);
  } else if (!IsZero(displacement)) {
    // Velocity is measured in ParentLayerCoords / Milliseconds
    float xVelocity = displacement.x / aDelta.ToMilliseconds();
    float yVelocity = displacement.y / aDelta.ToMilliseconds();
    mApzc.mX.SetVelocity(xVelocity);
    mApzc.mY.SetVelocity(yVelocity);
  }

  // Note: we ignore overscroll for generic animations.
  ParentLayerPoint adjustedOffset, overscroll;
  mApzc.mX.AdjustDisplacement(displacement.x, adjustedOffset.x, overscroll.x);
  mApzc.mY.AdjustDisplacement(displacement.y, adjustedOffset.y, overscroll.y,
                              mForceVerticalOverscroll);

  // If we expected to scroll, but there's no more scroll range on either axis,
  // then end the animation early. Note that the initial displacement could be 0
  // if the compositor ran very quickly (<1ms) after the animation was created.
  // When that happens we want to make sure the animation continues.
  if (!IsZero(displacement) && IsZero(adjustedOffset)) {
    // Nothing more to do - end the animation.
    return false;
  }

  aFrameMetrics.ScrollBy(adjustedOffset / zoom);
  return !finished;
}
Example #8
0
void
DataView::MouseDown(BPoint where)
{
	MakeFocus(true);

	BMessage *message = Looper()->CurrentMessage();
	int32 buttons;
	if (message == NULL || message->FindInt32("buttons", &buttons) != B_OK)
		return;

	view_focus newFocus;
	int32 position = PositionAt(kNoFocus, where, &newFocus);

	if ((buttons & B_SECONDARY_MOUSE_BUTTON) != 0
		&& position >= fStart && position <= fEnd) {
		InitiateDrag(newFocus);
		return;
	}

	if ((buttons & B_PRIMARY_MOUSE_BUTTON) == 0)
		return;

	int32 modifiers = message->FindInt32("modifiers");

	fMouseSelectionStart = position;
	if (fMouseSelectionStart == -1) {
		// "where" is outside the valid frame
		return;
	}

	int32 selectionEnd = fMouseSelectionStart;
	if (modifiers & B_SHIFT_KEY) {
		// enlarge the current selection
		if (fStart < selectionEnd)
			fMouseSelectionStart = fStart;
		else if (fEnd > selectionEnd)
			fMouseSelectionStart = fEnd;
	}
	SetSelection(fMouseSelectionStart, selectionEnd, newFocus);

	SetMouseEventMask(B_POINTER_EVENTS,
		B_NO_POINTER_HISTORY | B_SUSPEND_VIEW_FOCUS | B_LOCK_WINDOW_FOCUS);
}
//------------------------------------------------------------
nsresult 
nsFilteredContentIterator::SwitchDirections(bool aChangeToForward)
{
  nsINode *node = mCurrentIterator->GetCurrentNode();

  if (aChangeToForward) {
    mCurrentIterator = mPreIterator;
    mDirection       = eForward;
  } else {
    mCurrentIterator = mIterator;
    mDirection       = eBackward;
  }

  if (node) {
    nsresult rv = mCurrentIterator->PositionAt(node);
    if (NS_FAILED(rv)) {
      mIsOutOfRange = true;
      return rv;
    }
  }
  return NS_OK;
}
bool Mesh::Load(const GLfloat* positions,
                const GLfloat* colors, 
                const GLfloat* normals,
                const GLfloat* texCoords,
                const GLuint* indices,
                int numVertices, 
                int numIndices,
                GLenum drawMode, 
                StorageType storageType
              ) 
{ 
  if (!positions || numVertices <= 0)
  {
    return false;
  }

  mDrawMode = drawMode;
  mStorageType = storageType;
  mNumVertices = numVertices;
  mNumIndices  = (numIndices <= 0 || indices == nullptr) ? numVertices : numIndices;

  mHasColors   = (colors    != nullptr);
  mHasNormals  = (normals   != nullptr);
  mHasTexCoord = (texCoords != nullptr);
  mVertexSize  = 3 + 3*mHasColors + 3*mHasNormals + 2*mHasTexCoord;

  mVertices = new GLfloat [mVertexSize * mNumVertices];
  mIndices  = new GLuint  [mNumIndices];

  if (mStorageType == kTightlyPacked)
  {
    // Initialize vertices buffer array. 
    for (int i = 0; i < mNumVertices; i++)
    {
      float* position = PositionAt(i);
      float* texCoord = TexCoordAt(i);
      float* normal   = NormalAt(i); 
      float* color    = ColorAt(i);

      memcpy(position, positions + 3*i, sizeof(GLfloat)*3);
      if (HasColors())
      {
        memcpy(color, colors + 3*i, sizeof(GLfloat)*3);
      }
      if (HasNormals())
      {
        memcpy(normal, normals + 3*i, sizeof(GLfloat)*3);
      }
      if (HasTexCoord())
      {
        memcpy(texCoord, texCoords + 2*i, sizeof(GLfloat)*2);
      }
    }
  }
  else
  {
    GLfloat* dest = mVertices;
    memcpy(dest, positions, 3*sizeof(GLfloat)*mNumVertices);
    dest += 3*mNumVertices;
    if (HasColors())
    {
      memcpy(dest, colors, 3*sizeof(GLfloat)*mNumVertices);
      dest += 3*mNumVertices;
    }
    if (HasNormals())
    {
      memcpy(dest, normals, 3*sizeof(GLfloat)*mNumVertices);
      dest += 3*mNumVertices;
    }
    if (HasTexCoord())
    {
      memcpy(dest, texCoords, 2*sizeof(GLfloat)*mNumVertices);
      dest += 2*mNumVertices;
    }
  }

  // Initialize element array (indices array).
  if (indices)  // Element array provided.
  {
    memcpy(mIndices, indices, sizeof(GLuint)*mNumIndices);
  }
  else  // Element array wasn't provided -- build it up.
  {
    for (int i = 0; i < mNumIndices; i++)
    {
      mIndices[i] = i;
    }
  }

  mInitialized = true;
  Mesh::Upload();
  return true;
}
// Reloads the geometry. To keep some data constant, just specify nullptr.
void Mesh::Reload(const GLfloat* positions,
                  const GLfloat* colors,   
                  const GLfloat* normals,  
                  const GLfloat* texCoords 
                )
{
  if (!mInitialized)
  {
    std::cerr << "ERROR The mesh must be initialized before creating buffer objects.\n";
    return;
  }

  if (mStorageType == kTightlyPacked)
  {
    for (int i = 0; i < mNumVertices; i++)
    {
      float* position = PositionAt(i);
      float* texCoord = TexCoordAt(i);
      float* normal   = NormalAt(i); 
      float* color    = ColorAt(i);

      if (positions)
      {
        memcpy(position, positions + 3*i, sizeof(GLfloat)*3);
      }
      if (colors && HasColors())
      {
        memcpy(color, colors + 3*i, sizeof(GLfloat)*3);
      }
      if (normals && HasNormals())
      {
        memcpy(normal, normals + 3*i, sizeof(GLfloat)*3);
      }
      if (texCoords && HasTexCoord())
      {
        memcpy(texCoord, texCoords + 2*i, sizeof(GLfloat)*2);
      }
    }
  }
  else  // Sub-buffered.
  {
    GLfloat* dest = mVertices;
    if (positions)
    {
      memcpy(dest, positions, 3*sizeof(GLfloat)*mNumVertices);
      dest += 3*mNumVertices;
    }
    if (colors && HasColors())
    {
      memcpy(dest, colors, 3*sizeof(GLfloat)*mNumVertices);
      dest += 3*mNumVertices;
    }
    if (normals && HasNormals())
    {
      memcpy(dest, normals, 3*sizeof(GLfloat)*mNumVertices);
      dest += 3*mNumVertices;
    }
    if (texCoords && HasTexCoord())
    {
      memcpy(dest, texCoords, 2*sizeof(GLfloat)*mNumVertices);
      dest += 2*mNumVertices;
    }
  }

  Mesh::Upload();
}
Example #12
0
void
DataView::KeyDown(const char *bytes, int32 numBytes)
{
	int32 modifiers;
	if (Looper()->CurrentMessage() == NULL
		|| Looper()->CurrentMessage()->FindInt32("modifiers", &modifiers) != B_OK)
		modifiers = ::modifiers();

	// check if the selection is going to be changed
	switch (bytes[0]) {
		case B_LEFT_ARROW:
		case B_RIGHT_ARROW:
		case B_UP_ARROW:
		case B_DOWN_ARROW:
			if (modifiers & B_SHIFT_KEY) {
				if (fKeySelectionStart == -1)
					fKeySelectionStart = fStart;
			} else
				fKeySelectionStart = -1;
			break;
	}

	switch (bytes[0]) {
		case B_LEFT_ARROW:
		{
			int32 position = fStart - 1;

			if (modifiers & B_SHIFT_KEY) {
				if (fKeySelectionStart == fEnd)
					SetSelection(fStart - 1, fEnd);
				else {
					SetSelection(fStart, fEnd - 1);
					position = fEnd;
				}
			} else
				SetSelection(fStart - 1, fStart - 1);

			MakeVisible(position);
			break;
		}
		case B_RIGHT_ARROW:
		{
			int32 position = fEnd + 1;

			if (modifiers & B_SHIFT_KEY) {
				if (fKeySelectionStart == fStart)
					SetSelection(fStart, fEnd + 1);
				else
					SetSelection(fStart + 1, fEnd);
			} else
				SetSelection(fEnd + 1, fEnd + 1);

			MakeVisible(position);
			break;
		}
		case B_UP_ARROW:
		{
			int32 start, end;
			if (modifiers & B_SHIFT_KEY) {
				if (fKeySelectionStart == fStart) {
					start = fEnd - int32(kBlockSize);
					end = fStart;
				} else {
					start = fStart - int32(kBlockSize);
					end = fEnd;
				}
				if (start < 0)
					start = 0;
			} else {
				start = fStart - int32(kBlockSize);
				if (start < 0)
					start = fStart;

				end = start;
			}

			SetSelection(start, end);
			MakeVisible(start);
			break;
		}
		case B_DOWN_ARROW:
		{
			int32 start, end;
			if (modifiers & B_SHIFT_KEY) {
				if (fKeySelectionStart == fEnd) {
					start = fEnd;
					end = fStart + int32(kBlockSize);
				} else {
					start = fStart;
					end = fEnd + int32(kBlockSize);
				}
				if (end >= int32(fSizeInView))
					end = int32(fSizeInView) - 1;
			} else {
				end = fEnd + int32(kBlockSize);
				if (end >= int32(fSizeInView))
					start = fEnd;

				start = end;
			}

			SetSelection(start, end);
			MakeVisible(end);
			break;
		}

		case B_PAGE_UP:
		{
			// scroll one page up, but keep the same cursor column

			BRect frame = SelectionFrame(fFocus, fStart, fStart);
			frame.OffsetBy(0, -Bounds().Height());
			if (frame.top <= kVerticalSpace)
				frame.top = kVerticalSpace + 1;
			ScrollBy(0, -Bounds().Height());

			int32 position = PositionAt(fFocus, frame.LeftTop());
			SetSelection(position, position);
			break;
		}
		case B_PAGE_DOWN:
		{
			// scroll one page down, but keep the same cursor column

			BRect frame = SelectionFrame(fFocus, fStart, fStart);
			frame.OffsetBy(0, Bounds().Height());

			float lastLine = DataBounds().Height() - 1 - kVerticalSpace;
			if (frame.top > lastLine)
				frame.top = lastLine;
			ScrollBy(0, Bounds().Height());

			int32 position = PositionAt(fFocus, frame.LeftTop());
			SetSelection(position, position);
			break;
		}
		case B_HOME:
			SetSelection(0, 0);
			MakeVisible(fStart);
			break;
		case B_END:
			SetSelection(fDataSize - 1, fDataSize - 1);
			MakeVisible(fStart);
			break;
		case B_TAB:
			SetFocus(fFocus == kHexFocus ? kAsciiFocus : kHexFocus);
			MakeVisible(fStart);
			break;

		case B_FUNCTION_KEY:
			// this is ignored
			break;

		case B_BACKSPACE:
			if (fBitPosition == 0)
				SetSelection(fStart - 1, fStart - 1);

			if (fFocus == kHexFocus)
				fBitPosition = (fBitPosition + 4) % 8;

			// supposed to fall through
		case B_DELETE:
			SetSelection(fStart, fStart);
				// to make sure only the cursor is selected

			if (fFocus == kHexFocus) {
				const uint8 *data = DataAt(fStart);
				if (data == NULL)
					break;

				uint8 c = data[0] & (fBitPosition == 0 ? 0x0f : 0xf0);
					// mask out region to be cleared

				fEditor.Replace(fOffset + fStart, &c, 1);
			} else
				fEditor.Replace(fOffset + fStart, (const uint8 *)"", 1);
			break;

		default:
			if (fFocus == kHexFocus) {
				// only hexadecimal characters are allowed to be entered
				const uint8 *data = DataAt(fStart);
				uint8 c = bytes[0];
				if (c >= 'A' && c <= 'F')
					c += 'A' - 'a';
				const char *hexNumbers = "0123456789abcdef";
				addr_t number;
				if (data == NULL || (number = (addr_t)strchr(hexNumbers, c)) == 0)
					break;

				SetSelection(fStart, fStart);
					// to make sure only the cursor is selected

				number -= (addr_t)hexNumbers;
				fBitPosition = (fBitPosition + 4) % 8;

				c = (data[0] & (fBitPosition ? 0x0f : 0xf0)) | (number << fBitPosition);
					// mask out overwritten region and bit-wise or the number to be inserted

				if (fEditor.Replace(fOffset + fStart, &c, 1) == B_OK && fBitPosition == 0)
					SetSelection(fStart + 1, fStart + 1);
			} else {
				if (fEditor.Replace(fOffset + fStart, (const uint8 *)bytes, numBytes) == B_OK)
					SetSelection(fStart + 1, fStart + 1);
			}
			break;
	}
}