webengine/osswebengine/WebKit/s60/webview/WebFepTextEditor.cpp
changeset 26 cb62a4f66ebe
parent 25 0ed94ceaa377
child 27 6297cdf66332
--- a/webengine/osswebengine/WebKit/s60/webview/WebFepTextEditor.cpp	Thu Dec 17 09:20:16 2009 +0200
+++ b/webengine/osswebengine/WebKit/s60/webview/WebFepTextEditor.cpp	Thu Jan 07 13:31:38 2010 +0200
@@ -54,6 +54,8 @@
 #include <aknutils.h>
 #include "Text.h"
 
+#define KLineEnterChar 0x21b2
+
 using namespace WebCore;
 
 static const int kInfinite = -1;
@@ -85,7 +87,7 @@
 #if defined(BRDO_BROWSER_50_FF)
     SetAlignment( CAknExtendedInputCapabilities::EInputEditorAlignBidi );
 #endif
-	EnableCcpu(ETrue);
+    TRAP_IGNORE( EnableCcpuL() );
 }
 
 // -----------------------------------------------------------------------------
@@ -99,6 +101,7 @@
     delete m_inlineEditText;
     delete m_textFormatMask;
 	delete m_ExtendedInputCapabilities;
+	delete m_CcpuSupport;
     }
 
 // -----------------------------------------------------------------------------
@@ -341,6 +344,22 @@
 // -----------------------------------------------------------------------------
 void CWebFepTextEditor::CancelFepInlineEdit()
 {
+    if (IsTextAreaFocused()) {
+        if (m_inlineEditText && DocumentLengthForFep() < DocumentMaximumLengthForFep()) {
+            HBufC* tempBuf = HBufC::NewLC(DocumentLengthForFep());
+            TPtr ptr(tempBuf->Des());
+            GetEditorContentForFep(ptr, 0, DocumentLengthForFep());
+            TInt position = ptr.Locate(KLineEnterChar);
+            if(position != KErrNotFound){
+                TRAP_IGNORE(m_webView->fepTextEditor()->DoCommitFepInlineEditL());
+                Frame* frame = m_webView->page()->focusController()->focusedOrMainFrame();
+				if(frame){
+                	frame->editor()->execCommand("BackwardDelete");
+				}
+            }
+            CleanupStack::PopAndDestroy();
+        }
+    }
 }
 
 // -----------------------------------------------------------------------------
@@ -704,6 +723,10 @@
     	}
 
     state->ReportAknEdStateEventL(MAknEdStateObserver::EAknEdwinStateFlagsUpdate);
+    if (m_CcpuSupport)
+    {
+        TRAP_IGNORE(m_CcpuSupport->HandleFocusChangeL());
+    }
 }
 
 // -----------------------------------------------------------------------------
@@ -773,6 +796,10 @@
     CAknEdwinState* state = static_cast<CAknEdwinState*>(State(KNullUid));
     if ( state ) {
         TRAP_IGNORE( state->ReportAknEdStateEventL( MAknEdStateObserver::EAknCursorPositionChanged ) );
+		if (m_CcpuSupport)
+		{
+			TRAP_IGNORE(m_CcpuSupport->HandleSelectionChangeL());
+		}
     }
 }
 
@@ -1069,7 +1096,7 @@
 {
     TCursorSelection selection;
     GetCursorSelectionForFep(selection);
-    return selection.Length();
+    return m_CcpuSupport && selection.Length();
 }
 
 // -----------------------------------------------------------------------------
@@ -1082,6 +1109,12 @@
     PlaceDataOnClipboardL();
     TCursorSelection selection;
     GetCursorSelectionForFep(selection);
+    Frame* frame = m_webView->page()->focusController()->focusedOrMainFrame();
+    if (frame) {      
+        frame->editor()->deleteWithDirection(SelectionController::BACKWARD,
+            CharacterGranularity, false, true);
+        }
+    HandleUpdateCursor();
 }
 
 // -----------------------------------------------------------------------------
@@ -1093,7 +1126,7 @@
 {
     TCursorSelection selection;
     GetCursorSelectionForFep(selection);
-    return selection.Length();
+    return m_CcpuSupport && selection.Length();
 }
 
 // -----------------------------------------------------------------------------
@@ -1114,7 +1147,7 @@
 TBool CWebFepTextEditor::CcpuCanPaste() const
 {
     TRAPD(err, DoCcpuCanPasteL());
-    return err == KErrNone;
+    return (err == KErrNone) && m_CcpuSupport;
 }
 
 // -----------------------------------------------------------------------------
@@ -1320,17 +1353,24 @@
 //
 //
 // -----------------------------------------------------------------------------
-void CWebFepTextEditor::EnableCcpu(TBool aSupport)
+void CWebFepTextEditor::EnableCcpuL()
 {
+    CAknCcpuSupport* ccpu = NULL;
     CAknEdwinState* edwinState = static_cast<CAknEdwinState*>(this->State(KNullUid));
-    if(aSupport)
+    ccpu = new(ELeave) CAknCcpuSupport(this);
+    ccpu->SetMopParent(this);
+    CleanupStack::PushL(ccpu);
+    ccpu->ConstructL();
+    CleanupStack::Pop(ccpu);
+    delete m_CcpuSupport;
+    m_CcpuSupport = ccpu;
+    if (edwinState)
         {
-        edwinState->SetCcpuState(this);
-        }
-    else
-        {
-        edwinState->SetCcpuState(NULL);
-        }
+        edwinState->SetCcpuState(this);    
+        edwinState->SetMenu();
+        if (edwinState->MenuBar())
+            edwinState->MenuBar()->SetEditMenuObserver( m_CcpuSupport );
+        }        
 }
 
 // -----------------------------------------------------------------------------
@@ -1415,3 +1455,19 @@
     }
 }
 
+// -----------------------------------------------------------------------------
+// FocusChanging
+//
+// Called when the focus of the node changes, to commit the text 
+// -----------------------------------------------------------------------------
+void CWebFepTextEditor::FocusChanging()
+    { 
+    CAknEdwinState* state = static_cast<CAknEdwinState*>(State(KNullUid));
+    if ( state ) {
+        TRAP_IGNORE( state->ReportAknEdStateEventL(MAknEdStateObserver::EAknSyncEdwinState ) );
+    }
+    CommitFepInlineEditL(*CEikonEnv::Static());
+    CancelEditingMode();    
+    } 
+
+