示例#1
0
bool SjColumnMixer::GetSelectionAnchor(long& colIndex__, long& rowIndex__)
{
	SjCol* currCol;

	// verify stored anchor
	if( m_selAnchorColIndex != -1 )
	{
		currCol = GetMaskedCol(m_selAnchorColIndex);
		if( currCol == NULL )
		{
			m_selAnchorColIndex = -1; // recalculate anchor - this is no error!
		}
		else
		{
			if(  m_selAnchorRowIndex<0 || m_selAnchorRowIndex>=currCol->m_rowCount
			        || !currCol->m_rows[m_selAnchorRowIndex]->IsSelected() )
			{
				m_selAnchorColIndex = -1; // recalculate anchor - this is no error!
			}
			delete currCol;
		}
	}

	// recalculate anchor if needed
	if( m_selAnchorColIndex == -1 || GetSelectedUrlCount() == 1 )
	{
		GetSelectionRange(m_selAnchorColIndex, m_selAnchorRowIndex);
	}

	// done
	colIndex__ = m_selAnchorColIndex;
	rowIndex__ = m_selAnchorRowIndex;

	return m_selAnchorColIndex!=-1;
}
void
HTMLTextAreaElement::SetSelectionEnd(uint32_t aSelectionEnd, ErrorResult& aError)
{
  if (mState.IsSelectionCached()) {
    mState.GetSelectionProperties().mEnd = aSelectionEnd;
    return;
  }

  nsAutoString direction;
  nsresult rv = GetSelectionDirection(direction);
  if (NS_FAILED(rv)) {
    aError.Throw(rv);
    return;
  }
  int32_t start, end;
  rv = GetSelectionRange(&start, &end);
  if (NS_FAILED(rv)) {
    aError.Throw(rv);
    return;
  }
  end = aSelectionEnd;
  if (start > end) {
    start = end;
  }
  rv = SetSelectionRange(start, end, direction);
  if (NS_FAILED(rv)) {
    aError.Throw(rv);
  }
}
void
HTMLTextAreaElement::SetSelectionEnd(const Nullable<uint32_t>& aSelectionEnd,
                                     ErrorResult& aError)
{
  int32_t selEnd = 0;
  if (!aSelectionEnd.IsNull()) {
    selEnd = aSelectionEnd.Value();
  }

  if (mState.IsSelectionCached()) {
    mState.GetSelectionProperties().SetEnd(selEnd);
    return;
  }

  nsAutoString direction;
  nsresult rv = GetSelectionDirection(direction);
  if (NS_FAILED(rv)) {
    aError.Throw(rv);
    return;
  }
  int32_t start, end;
  rv = GetSelectionRange(&start, &end);
  if (NS_FAILED(rv)) {
    aError.Throw(rv);
    return;
  }
  end = selEnd;
  if (start > end) {
    start = end;
  }
  rv = SetSelectionRange(start, end, direction);
  if (NS_FAILED(rv)) {
    aError.Throw(rv);
  }
}
NS_IMETHODIMP
nsHTMLTextAreaElement::GetSelectionEnd(PRInt32 *aSelectionEnd)
{
  NS_ENSURE_ARG_POINTER(aSelectionEnd);
  
  PRInt32 selStart;
  return GetSelectionRange(&selStart, aSelectionEnd);
}
NS_IMETHODIMP
nsHTMLTextAreaElement::GetSelectionStart(PRInt32 *aSelectionStart)
{
  NS_ENSURE_ARG_POINTER(aSelectionStart);
  
  PRInt32 selEnd;
  return GetSelectionRange(aSelectionStart, &selEnd);
}
uint32_t
HTMLTextAreaElement::GetSelectionEnd(ErrorResult& aError)
{
  int32_t selStart, selEnd;
  nsresult rv = GetSelectionRange(&selStart, &selEnd);

  if (NS_FAILED(rv) && mState.IsSelectionCached()) {
    return mState.GetSelectionProperties().mEnd;
  }
  if (NS_FAILED(rv)) {
    aError.Throw(rv);
  }
  return selEnd;
}
Nullable<uint32_t>
HTMLTextAreaElement::GetSelectionStart(ErrorResult& aError)
{
  int32_t selStart, selEnd;
  nsresult rv = GetSelectionRange(&selStart, &selEnd);

  if (NS_FAILED(rv) && mState.IsSelectionCached()) {
    return Nullable<uint32_t>(mState.GetSelectionProperties().GetStart());
  }
  if (NS_FAILED(rv)) {
    aError.Throw(rv);
  }
  return Nullable<uint32_t>(selStart);
}
void
HTMLTextAreaElement::SetRangeText(const nsAString& aReplacement,
                                  ErrorResult& aRv)
{
  int32_t start, end;
  aRv = GetSelectionRange(&start, &end);
  if (aRv.Failed()) {
    if (mState.IsSelectionCached()) {
      start = mState.GetSelectionProperties().mStart;
      end = mState.GetSelectionProperties().mEnd;
      aRv = NS_OK;
    }
  }

  SetRangeText(aReplacement, start, end, mozilla::dom::SelectionMode::Preserve,
               aRv, start, end);
}
示例#9
0
NS_IMETHODIMP
nsTextControlFrame::SetSelectionEnd(PRInt32 aSelectionEnd)
{
  nsresult rv = EnsureEditorInitialized();
  NS_ENSURE_SUCCESS(rv, rv);

  PRInt32 selStart = 0, selEnd = 0; 

  rv = GetSelectionRange(&selStart, &selEnd);
  NS_ENSURE_SUCCESS(rv, rv);

  if (aSelectionEnd < selStart) {
    // Collapse to the new end point.
    selStart = aSelectionEnd; 
  }

  selEnd = aSelectionEnd;
  
  return SetSelectionEndPoints(selStart, selEnd);
}
void
HTMLTextAreaElement::SetSelectionDirection(const nsAString& aDirection, ErrorResult& aError)
{
  if (mState.IsSelectionCached()) {
    nsITextControlFrame::SelectionDirection dir = nsITextControlFrame::eNone;
    if (aDirection.EqualsLiteral("forward")) {
      dir = nsITextControlFrame::eForward;
    } else if (aDirection.EqualsLiteral("backward")) {
      dir = nsITextControlFrame::eBackward;
    }
    mState.GetSelectionProperties().mDirection = dir;
    return;
  }

  int32_t start, end;
  nsresult rv = GetSelectionRange(&start, &end);
  if (NS_SUCCEEDED(rv)) {
    rv = SetSelectionRange(start, end, aDirection);
  }
  if (NS_FAILED(rv)) {
    aError.Throw(rv);
  }
}
void
HTMLTextAreaElement::SetRangeText(const nsAString& aReplacement,
                                  uint32_t aStart, uint32_t aEnd,
                                  const SelectionMode& aSelectMode,
                                  ErrorResult& aRv, int32_t aSelectionStart,
                                  int32_t aSelectionEnd)
{
  if (aStart > aEnd) {
    aRv.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
    return;
  }

  nsAutoString value;
  GetValueInternal(value, false);
  uint32_t inputValueLength = value.Length();

  if (aStart > inputValueLength) {
    aStart = inputValueLength;
  }

  if (aEnd > inputValueLength) {
    aEnd = inputValueLength;
  }

  if (aSelectionStart == -1 && aSelectionEnd == -1) {
    aRv = GetSelectionRange(&aSelectionStart, &aSelectionEnd);
    if (aRv.Failed()) {
      if (mState.IsSelectionCached()) {
        aSelectionStart = mState.GetSelectionProperties().mStart;
        aSelectionEnd = mState.GetSelectionProperties().mEnd;
        aRv = NS_OK;
      }
    }
  }

  if (aStart <= aEnd) {
    value.Replace(aStart, aEnd - aStart, aReplacement);
    SetValueInternal(value, false);
  }

  uint32_t newEnd = aStart + aReplacement.Length();
  int32_t delta =  aReplacement.Length() - (aEnd - aStart);

  switch (aSelectMode) {
    case mozilla::dom::SelectionMode::Select:
    {
      aSelectionStart = aStart;
      aSelectionEnd = newEnd;
    }
    break;
    case mozilla::dom::SelectionMode::Start:
    {
      aSelectionStart = aSelectionEnd = aStart;
    }
    break;
    case mozilla::dom::SelectionMode::End:
    {
      aSelectionStart = aSelectionEnd = newEnd;
    }
    break;
    case mozilla::dom::SelectionMode::Preserve:
    {
      if ((uint32_t)aSelectionStart > aEnd) {
        aSelectionStart += delta;
      } else if ((uint32_t)aSelectionStart > aStart) {
        aSelectionStart = aStart;
      }

      if ((uint32_t)aSelectionEnd > aEnd) {
        aSelectionEnd += delta;
      } else if ((uint32_t)aSelectionEnd > aStart) {
        aSelectionEnd = newEnd;
      }
    }
    break;
  }

  Optional<nsAString> direction;
  SetSelectionRange(aSelectionStart, aSelectionEnd, direction, aRv);
}
示例#12
0
bool SjColumnMixer::SelectShifted(int keyPressed/*-1=up, +1=down*/, long& retScopeColIndex, long& retScopeRowIndex)
{
	long    firstSelColIndex, firstSelRowIndex,
	        lastSelColIndex, lastSelRowIndex;
	bool    prevNextOk;

	// get selection anchor and the first/last selected row

	if( !GetSelectionAnchor(firstSelColIndex/*dummy*/, firstSelRowIndex/*dummy*/)
	        || !GetSelectionRange(firstSelColIndex, firstSelRowIndex, &lastSelColIndex, &lastSelRowIndex) )
	{
		return FALSE; // no anchor, the caller should preform a "simple" selection
	}

	// calculate the new selection...

	if( firstSelColIndex == lastSelColIndex && firstSelRowIndex == lastSelRowIndex )
	{
		if( keyPressed == -1 )
		{
			// ...initial selection from anchor to top
			prevNextOk = PrevNextRow(firstSelColIndex, firstSelRowIndex, -1);
			retScopeColIndex = firstSelColIndex;
			retScopeRowIndex = firstSelRowIndex;
		}
		else
		{
			// ...initial selection from anchor to bottom
			prevNextOk = PrevNextRow(lastSelColIndex, lastSelRowIndex, +1);
			retScopeColIndex = lastSelColIndex;
			retScopeRowIndex = lastSelRowIndex;
		}
	}
	else if(  firstSelColIndex < m_selAnchorColIndex
	          || (firstSelColIndex == m_selAnchorColIndex && firstSelRowIndex < m_selAnchorRowIndex) )
	{
		// ...selected stuff above the anchor...
		prevNextOk = PrevNextRow(firstSelColIndex, firstSelRowIndex, keyPressed);
		retScopeColIndex = firstSelColIndex;
		retScopeRowIndex = firstSelRowIndex;
	}
	else
	{
		// ...select stuff below the anchor...
		prevNextOk = PrevNextRow(lastSelColIndex, lastSelRowIndex, keyPressed);
		retScopeColIndex = lastSelColIndex;
		retScopeRowIndex = lastSelRowIndex;
	}

	if( prevNextOk )
	{
		// set the new selection

		SetSelectionRange(firstSelColIndex, firstSelRowIndex, lastSelColIndex, lastSelRowIndex, TRUE);

		// make sure, the anchor is always selected

		SjCol* col = GetMaskedCol(m_selAnchorColIndex);
		if( col )
		{
			if( m_selAnchorRowIndex >= 0 && m_selAnchorRowIndex < col->m_rowCount )
			{
				col->m_rows[m_selAnchorRowIndex]->Select(TRUE);
			}
			delete col;
		}
	}

	return TRUE;
}
Nullable<uint32_t> HTMLTextAreaElement::GetSelectionEnd(ErrorResult& aError) {
  uint32_t selStart, selEnd;
  GetSelectionRange(&selStart, &selEnd, aError);
  return Nullable<uint32_t>(selEnd);
}