396 void CWebFepTextEditor::SetCursorSelectionForFepL(const TCursorSelection& aCursorSelection) |
396 void CWebFepTextEditor::SetCursorSelectionForFepL(const TCursorSelection& aCursorSelection) |
397 { |
397 { |
398 // The other part of the rather hackish way to check if we are at the end of the editing field |
398 // The other part of the rather hackish way to check if we are at the end of the editing field |
399 // see WebEditorClient::handleKeypress |
399 // see WebEditorClient::handleKeypress |
400 Frame* frame = m_webView->page()->focusController()->focusedOrMainFrame(); |
400 Frame* frame = m_webView->page()->focusController()->focusedOrMainFrame(); |
401 if ( frame ) { |
401 Node* focusedNode = frame->document()->focusedNode(); |
402 SelectionController* sc = frame->selectionController(); |
402 if ( frame && focusedNode) { |
403 Node* editNode = sc->base().node(); |
403 TInt lowPos = aCursorSelection.LowerPos(); |
404 if ( IsTextAreaFocused() ) { |
404 TInt highPos = aCursorSelection.HigherPos(); |
405 while(editNode && !editNode->isTextNode()){ |
405 if (focusedNode->hasTagName(HTMLNames::textareaTag)) { |
406 editNode = editNode->previousSibling(); |
406 HTMLTextAreaElement* textArea = static_cast<HTMLTextAreaElement*>(focusedNode); |
407 } |
407 textArea->setSelectionRange(lowPos, highPos); |
408 TInt position( aCursorSelection.iAnchorPos ); |
|
409 TInt offset( 0 ); |
|
410 TInt extentoffset = 0; |
|
411 if ( editNode ) { |
|
412 editNode = findTextNodeForCurPos( editNode, position ); |
|
413 if(aCursorSelection.iAnchorPos >= position) { |
|
414 offset = aCursorSelection.iAnchorPos - position; |
|
415 extentoffset = aCursorSelection.iCursorPos - position; |
|
416 } |
|
417 extentoffset = extentoffset < 0 ? 0 : extentoffset; |
|
418 Position base( editNode, offset ); |
|
419 Position extent(editNode,extentoffset); |
|
420 sc->moveTo( base, extent, DOWNSTREAM ); |
|
421 } |
|
422 } |
408 } |
423 else if ( editNode && editNode->isTextNode() ) { |
409 else if (focusedNode->hasTagName(HTMLNames::inputTag)) { |
424 Position base( sc->baseNode(), aCursorSelection.iAnchorPos ); |
410 HTMLInputElement* inputElement = static_cast<HTMLInputElement*>(focusedNode); |
425 Position extent( sc->baseNode(), aCursorSelection.iCursorPos ); |
411 inputElement->setSelectionStart(lowPos); |
426 sc->moveTo( base, extent, DOWNSTREAM ); |
412 inputElement->setSelectionEnd(highPos); |
427 } |
413 } |
428 HandleUpdateCursor(); |
414 HandleUpdateCursor(); |
429 } |
415 } |
430 } |
416 } |
431 |
417 |
437 void CWebFepTextEditor::GetCursorSelectionForFep(TCursorSelection& aCursorSelection) const |
423 void CWebFepTextEditor::GetCursorSelectionForFep(TCursorSelection& aCursorSelection) const |
438 { |
424 { |
439 aCursorSelection.SetSelection(0,0); |
425 aCursorSelection.SetSelection(0,0); |
440 |
426 |
441 Frame* frame = m_webView->page()->focusController()->focusedOrMainFrame(); |
427 Frame* frame = m_webView->page()->focusController()->focusedOrMainFrame(); |
442 if ( frame ) { |
428 Node* focusedNode = frame->document()->focusedNode(); |
443 SelectionController* sc = frame->selectionController(); |
429 if (frame && focusedNode) { |
444 Node* editNode = sc->base().node(); |
430 if (focusedNode->hasTagName(HTMLNames::textareaTag)) { |
445 if ( frame && frame->document()->focusedNode() ) { |
431 HTMLTextAreaElement* textArea = static_cast<HTMLTextAreaElement*>(focusedNode); |
446 if ( IsTextAreaFocused() ) { |
432 TInt anchorPos = textArea->selectionStart(); |
447 HTMLTextAreaElement* ie = static_cast<HTMLTextAreaElement*>(frame->document()->focusedNode()); |
433 TInt cursorPos = textArea->selectionEnd(); |
448 while(editNode && !editNode->isTextNode()) { |
434 aCursorSelection.SetSelection(cursorPos, anchorPos); |
449 editNode = editNode->previousSibling(); |
435 } |
450 } |
436 else if (focusedNode->hasTagName(HTMLNames::inputTag)) { |
451 TInt len( 0 ); |
437 HTMLInputElement* inputElement = static_cast<HTMLInputElement*>(focusedNode); |
452 if ( editNode ) { |
438 TInt anchorPos = inputElement->selectionStart(); |
453 findPrevSiblingTextLen( editNode, len ); |
439 TInt cursorPos = inputElement->selectionEnd(); |
454 } |
440 aCursorSelection.SetSelection(cursorPos, anchorPos); |
455 aCursorSelection.SetSelection( ((sc->baseOffset()+len > ie->value().length()) ? 0 : sc->baseOffset()+len), |
441 } |
456 ((sc->extentOffset()+len > ie->value().length()) ? 0 : sc->extentOffset()+len)); |
442 } |
457 } |
|
458 else { |
|
459 aCursorSelection.SetSelection(sc->baseOffset(), sc->extentOffset()); |
|
460 } |
|
461 } |
|
462 } |
|
463 } |
443 } |
464 |
444 |
465 // ----------------------------------------------------------------------------- |
445 // ----------------------------------------------------------------------------- |
466 // GetEditorContentForFep |
446 // GetEditorContentForFep |
467 // |
447 // |