|
1 /* |
|
2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: WebFepTextEditor.cpp |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #include "config.h" |
|
21 #include "../../bidi.h" |
|
22 |
|
23 #include "WebFepTextEditor.h" |
|
24 #include "WebEditorClient.h" |
|
25 #include "WebTextFormatMask.h" |
|
26 #include "WebView.h" |
|
27 #include "WebFrame.h" |
|
28 #include "Page.h" |
|
29 #include "FocusController.h" |
|
30 |
|
31 #include "Frame.h" |
|
32 #include "Editor.h" |
|
33 #include "HtmlNames.h" |
|
34 #include "EventHandler.h" |
|
35 #include "HtmlInputElement.h" |
|
36 #include "HtmlTextAreaElement.h" |
|
37 #include "PlatformKeyboardEvent.h" |
|
38 #include "CSSPropertyNames.h" |
|
39 #include "CSSValueKeywords.h" |
|
40 |
|
41 #include <coemain.h> |
|
42 #include <eikpanic.h> |
|
43 #include <aknedsts.h> |
|
44 #include <aknutils.h> |
|
45 #include "Text.h" |
|
46 |
|
47 using namespace WebCore; |
|
48 |
|
49 static const int kInfinite = -1; |
|
50 _LIT(KBlankDesC," "); |
|
51 |
|
52 GLDEF_C void Panic(TEikPanic aPanic) |
|
53 { |
|
54 _LIT(KPanicCat,"WEBKIT-FEP"); |
|
55 User::Panic(KPanicCat,aPanic); |
|
56 } |
|
57 |
|
58 // ----------------------------------------------------------------------------- |
|
59 // CWebFepTextEditor |
|
60 // |
|
61 // |
|
62 // ----------------------------------------------------------------------------- |
|
63 CWebFepTextEditor::CWebFepTextEditor(WebView* aView) |
|
64 : m_webView(aView), |
|
65 m_textFormatMask(NULL), |
|
66 m_inlineEditText(NULL) |
|
67 { |
|
68 // Set up the extended capabilities |
|
69 TRAP_IGNORE( |
|
70 m_ExtendedInputCapabilities = CAknExtendedInputCapabilities::NewL(); |
|
71 ); |
|
72 |
|
73 // Set alignment on m_ExtendedInputCapabilities, yes it checks if NULL |
|
74 // The EInputEditorAlignXXX flags are defined for 5.0+ platforms |
|
75 #if defined(BRDO_BROWSER_50_FF) |
|
76 SetAlignment( CAknExtendedInputCapabilities::EInputEditorAlignBidi ); |
|
77 #endif |
|
78 EnableCcpu(ETrue); |
|
79 } |
|
80 |
|
81 // ----------------------------------------------------------------------------- |
|
82 // ~CWebFepTextEditor |
|
83 // |
|
84 // |
|
85 // ----------------------------------------------------------------------------- |
|
86 CWebFepTextEditor::~CWebFepTextEditor() |
|
87 { |
|
88 delete m_state; |
|
89 delete m_inlineEditText; |
|
90 delete m_textFormatMask; |
|
91 } |
|
92 |
|
93 // ----------------------------------------------------------------------------- |
|
94 // CreateTextFormatMask |
|
95 // |
|
96 // |
|
97 // ----------------------------------------------------------------------------- |
|
98 void CWebFepTextEditor::CreateTextFormatMask() |
|
99 { |
|
100 if (!m_textFormatMask) { |
|
101 Frame* frame = m_webView->page()->focusController()->focusedOrMainFrame(); |
|
102 if (frame && |
|
103 frame->document() && |
|
104 frame->document()->focusedNode()) { |
|
105 RenderStyle* s = frame->document()->focusedNode()->renderStyle(); |
|
106 if (s && |
|
107 (!s->wapInputFormat().isEmpty() || s->wapInputRequired())){ |
|
108 m_textFormatMask = new WebTextFormatMask(s->wapInputFormat(), s->wapInputRequired()); |
|
109 } |
|
110 } |
|
111 } |
|
112 } |
|
113 |
|
114 // ----------------------------------------------------------------------------- |
|
115 // UpdateEditingMode |
|
116 // |
|
117 // |
|
118 // ----------------------------------------------------------------------------- |
|
119 void CWebFepTextEditor::UpdateEditingMode() |
|
120 { |
|
121 Frame* frame = m_webView->page()->focusController()->focusedOrMainFrame(); |
|
122 if (frame) { |
|
123 SelectionController* sc = frame->selectionController(); |
|
124 if (sc && sc->isContentEditable() && sc->isInPasswordField()) { |
|
125 |
|
126 // Set the state as if it was the CEikSecretEditor |
|
127 CAknEdwinState* state = static_cast<CAknEdwinState*>(State(KNullUid)); |
|
128 if (state) { |
|
129 state->SetFlags( EAknEditorFlagNoLRNavigation | |
|
130 EAknEditorFlagLatinInputModesOnly | |
|
131 EAknEditorFlagNoT9 | |
|
132 EAknEditorFlagUseSCTNumericCharmap ); |
|
133 |
|
134 state->SetDefaultInputMode(EAknEditorSecretAlphaInputMode); |
|
135 state->SetCurrentInputMode(EAknEditorSecretAlphaInputMode); |
|
136 state->SetPermittedCases(EAknEditorLowerCase|EAknEditorUpperCase); |
|
137 state->SetCurrentCase(EAknEditorLowerCase); |
|
138 state->SetPermittedInputModes(EAknEditorSecretAlphaInputMode | EAknEditorNumericInputMode); |
|
139 state->SetDefaultCase(EAknEditorLowerCase); |
|
140 state->SetSpecialCharacterTableResourceId(R_AVKON_SPECIAL_CHARACTER_TABLE_DIALOG_LATIN_ONLY); |
|
141 state->SetNumericKeymap(EAknEditorPlainNumberModeKeymap); |
|
142 } |
|
143 |
|
144 } |
|
145 else { |
|
146 |
|
147 CreateTextFormatMask(); |
|
148 |
|
149 TUint currentCase ( EAknEditorLowerCase ) ; |
|
150 TUint permittedCase ( EAknEditorAllCaseModes ) ; |
|
151 TUint inputMode( EAknEditorNullInputMode ); |
|
152 TUint permittedInputModes( EAknEditorAllInputModes ); |
|
153 TUint flags( EAknEditorFlagDefault ); |
|
154 TUint numericKeyMap( EAknEditorStandardNumberModeKeymap ); |
|
155 |
|
156 if (GetStateFromFormatMask(currentCase, permittedCase, inputMode, permittedInputModes, flags, numericKeyMap)) { |
|
157 UpdateFlagsState(flags); |
|
158 UpdateInputModeState(inputMode, permittedInputModes, numericKeyMap); |
|
159 UpdateCaseState(currentCase, permittedCase); |
|
160 } |
|
161 else { |
|
162 CAknEdwinState* state = static_cast<CAknEdwinState*>(State(KNullUid)); |
|
163 if (state) { |
|
164 state->SetPermittedInputModes(EAknEditorAllInputModes); |
|
165 state->SetPermittedCases(EAknEditorAllCaseModes);//allow everything |
|
166 } |
|
167 } |
|
168 } |
|
169 } // End of if (frame) |
|
170 } |
|
171 |
|
172 // ----------------------------------------------------------------------------- |
|
173 // CancelEditingMode |
|
174 // |
|
175 // |
|
176 // ----------------------------------------------------------------------------- |
|
177 void CWebFepTextEditor::CancelEditingMode() |
|
178 { |
|
179 delete m_textFormatMask; |
|
180 m_textFormatMask = NULL; |
|
181 |
|
182 delete m_inlineEditText; |
|
183 m_inlineEditText = NULL; |
|
184 |
|
185 UpdateFlagsState(EAknEditorFlagDefault); |
|
186 UpdateInputModeState(EAknEditorNullInputMode, EAknEditorAllInputModes,EAknEditorStandardNumberModeKeymap); |
|
187 UpdateCaseState(EAknEditorLowerCase, EAknEditorAllCaseModes); |
|
188 |
|
189 CancelFepInlineEdit(); |
|
190 } |
|
191 |
|
192 // ----------------------------------------------------------------------------- |
|
193 // ActivatePenInputRequest |
|
194 // |
|
195 // |
|
196 // ----------------------------------------------------------------------------- |
|
197 void CWebFepTextEditor::ActivatePenInputRequest() |
|
198 { |
|
199 CAknEdwinState* state = static_cast<CAknEdwinState*>(State(KNullUid)); |
|
200 if ( state ) { |
|
201 TRAP_IGNORE( state->ReportAknEdStateEventL(MAknEdStateObserver::EAknActivatePenInputRequest ) ); |
|
202 } |
|
203 } |
|
204 |
|
205 // ----------------------------------------------------------------------------- |
|
206 // DeactivatePenInputRequest |
|
207 // |
|
208 // |
|
209 // ----------------------------------------------------------------------------- |
|
210 void CWebFepTextEditor::DeactivatePenInputRequest() |
|
211 { |
|
212 } |
|
213 |
|
214 // ----------------------------------------------------------------------------- |
|
215 // InputCapabilities |
|
216 // |
|
217 // |
|
218 // ----------------------------------------------------------------------------- |
|
219 TCoeInputCapabilities CWebFepTextEditor::InputCapabilities() |
|
220 { |
|
221 Frame* frame = m_webView->page()->focusController()->focusedOrMainFrame(); |
|
222 if (frame) { |
|
223 SelectionController* sc = frame->selectionController(); |
|
224 if (sc && sc->isContentEditable()) { |
|
225 |
|
226 // Set up the input capabilities, based on the <input> box |
|
227 TUint caps = TCoeInputCapabilities::ENavigation; |
|
228 |
|
229 if ( sc->isInPasswordField() ) { |
|
230 caps |= TCoeInputCapabilities::ESecretText; |
|
231 } |
|
232 else { |
|
233 |
|
234 CAknEdwinState* state = static_cast<CAknEdwinState*>(State(KNullUid)); |
|
235 if ( state ) { |
|
236 if ( state->PermittedInputModes() == EAknEditorNumericInputMode ) { |
|
237 caps |= (TCoeInputCapabilities::EWesternNumericIntegerPositive | |
|
238 TCoeInputCapabilities::EWesternNumericIntegerNegative)| |
|
239 TCoeInputCapabilities::EAllText; |
|
240 } |
|
241 else if ( state->PermittedInputModes() == EAknEditorTextInputMode ) { |
|
242 caps |= TCoeInputCapabilities::EWesternAlphabetic; |
|
243 } |
|
244 else if ( state->PermittedInputModes() == (EAknEditorTextInputMode | EAknEditorNumericInputMode) ) { |
|
245 caps |= (TCoeInputCapabilities::EWesternNumericIntegerPositive | |
|
246 TCoeInputCapabilities::EWesternNumericIntegerNegative | |
|
247 TCoeInputCapabilities::EWesternAlphabetic); |
|
248 } |
|
249 else { |
|
250 caps |= TCoeInputCapabilities::EAllText; |
|
251 } |
|
252 } |
|
253 } |
|
254 |
|
255 // Set up the extended input capabilities, based on dir="rtl". |
|
256 // EInputEditorAlignXXX flags are only valid for 5.0+ platform. |
|
257 #if defined(BRDO_BROWSER_50_FF) |
|
258 if ( IsDirectionRTL() ) { |
|
259 SetAlignment(CAknExtendedInputCapabilities::EInputEditorAlignRight ); |
|
260 } |
|
261 else { |
|
262 SetAlignment(CAknExtendedInputCapabilities::EInputEditorAlignBidi ); |
|
263 } |
|
264 #endif |
|
265 // Set up the ObjectProvider, so ExtendedInputCapablities can be called by FEP. |
|
266 // MObjectProvider callback method MopSupplyObject(). |
|
267 TCoeInputCapabilities inputCaps( caps, this, NULL, TUid::Uid(0x100056de), this ); |
|
268 inputCaps.SetObjectProvider( this ); |
|
269 |
|
270 return inputCaps; |
|
271 } |
|
272 } |
|
273 |
|
274 // Empty input capabilities |
|
275 TCoeInputCapabilities emptyCaps(TCoeInputCapabilities::ENone); |
|
276 emptyCaps.SetObjectProvider( this ); |
|
277 |
|
278 return emptyCaps; |
|
279 } |
|
280 |
|
281 |
|
282 //////////////////////////////////////////////////////////////////////////////// |
|
283 // from MCoeFepAwareTextEditor |
|
284 // |
|
285 |
|
286 // ----------------------------------------------------------------------------- |
|
287 // StartFepInlineEditL |
|
288 // |
|
289 // |
|
290 // ----------------------------------------------------------------------------- |
|
291 void CWebFepTextEditor::StartFepInlineEditL( |
|
292 const TDesC& aInitialInlineText, |
|
293 TInt /*aPositionOfInsertionPointInInlineText*/, |
|
294 TBool /*aCursorVisibility*/, |
|
295 const MFormCustomDraw*, |
|
296 MFepInlineTextFormatRetriever&, |
|
297 MFepPointerEventHandlerDuringInlineEdit& /*aPointerEventHandlerDuringInlineEdit*/) |
|
298 { |
|
299 CCoeEnv::Static()->ForEachFepObserverCall(FepObserverHandleStartOfTransactionL); |
|
300 ClearInlineText(); |
|
301 UpdateInlineText(aInitialInlineText); |
|
302 } |
|
303 |
|
304 // ----------------------------------------------------------------------------- |
|
305 // UpdateFepInlineTextL |
|
306 // |
|
307 // |
|
308 // ----------------------------------------------------------------------------- |
|
309 void CWebFepTextEditor::UpdateFepInlineTextL( const TDesC& aNewInlineText, |
|
310 TInt /*aPositionOfInsertionPointInInlineText*/ ) |
|
311 { |
|
312 ClearInlineText(); |
|
313 UpdateInlineText(aNewInlineText); |
|
314 } |
|
315 |
|
316 // ----------------------------------------------------------------------------- |
|
317 // SetInlineEditingCursorVisibilityL |
|
318 // |
|
319 // |
|
320 // ----------------------------------------------------------------------------- |
|
321 void CWebFepTextEditor::SetInlineEditingCursorVisibilityL(TBool /*aCursorVisibility*/) |
|
322 { |
|
323 } |
|
324 |
|
325 // ----------------------------------------------------------------------------- |
|
326 // CancelFepInlineEdit |
|
327 // |
|
328 // |
|
329 // ----------------------------------------------------------------------------- |
|
330 void CWebFepTextEditor::CancelFepInlineEdit() |
|
331 { |
|
332 } |
|
333 |
|
334 // ----------------------------------------------------------------------------- |
|
335 // DocumentLengthForFep |
|
336 // |
|
337 // |
|
338 // ----------------------------------------------------------------------------- |
|
339 TInt CWebFepTextEditor::DocumentLengthForFep() const |
|
340 { |
|
341 TInt length = 0; |
|
342 Frame* frame = m_webView->page()->focusController()->focusedOrMainFrame(); |
|
343 if (frame && |
|
344 frame->document() && |
|
345 frame->document()->focusedNode()) { |
|
346 |
|
347 if (frame->document()->focusedNode()->hasTagName(HTMLNames::inputTag)) { |
|
348 HTMLInputElement* ie = static_cast<HTMLInputElement*>(frame->document()->focusedNode()); |
|
349 length = ie->value().length(); |
|
350 } |
|
351 else if (frame->document()->focusedNode()->hasTagName(HTMLNames::textareaTag)) { |
|
352 HTMLTextAreaElement* ie = static_cast<HTMLTextAreaElement*>(frame->document()->focusedNode()); |
|
353 length = ie->value().length(); |
|
354 } |
|
355 } |
|
356 |
|
357 return length; |
|
358 } |
|
359 |
|
360 // ----------------------------------------------------------------------------- |
|
361 // DocumentMaximumLengthForFep |
|
362 // |
|
363 // |
|
364 // ----------------------------------------------------------------------------- |
|
365 TInt CWebFepTextEditor::DocumentMaximumLengthForFep() const |
|
366 { |
|
367 TInt length = KMaxTInt; |
|
368 |
|
369 Frame* frame = m_webView->page()->focusController()->focusedOrMainFrame(); |
|
370 if (frame && |
|
371 frame->document() && |
|
372 frame->document()->focusedNode() && |
|
373 frame->document()->focusedNode()->hasTagName(HTMLNames::inputTag) ) { |
|
374 length = static_cast<HTMLInputElement*>(frame->document()->focusedNode())->maxLength(); |
|
375 } |
|
376 |
|
377 // Override the length if a text format mask is set |
|
378 if ( m_textFormatMask && m_textFormatMask->getMultitude() > 0 ) |
|
379 length = m_textFormatMask->getMultitude(); |
|
380 |
|
381 // TextArea node has no member function maxLength(), so return KMaxTInt |
|
382 return length; |
|
383 } |
|
384 |
|
385 // ----------------------------------------------------------------------------- |
|
386 // SetCursorSelectionForFepL |
|
387 // |
|
388 // |
|
389 // ----------------------------------------------------------------------------- |
|
390 void CWebFepTextEditor::SetCursorSelectionForFepL(const TCursorSelection& aCursorSelection) |
|
391 { |
|
392 // The other part of the rather hackish way to check if we are at the end of the editing field |
|
393 // see WebEditorClient::handleKeypress |
|
394 Frame* frame = m_webView->page()->focusController()->focusedOrMainFrame(); |
|
395 if ( frame ) { |
|
396 SelectionController* sc = frame->selectionController(); |
|
397 Node* editNode = sc->base().node(); |
|
398 if ( IsTextAreaFocused() ) { |
|
399 TInt position( aCursorSelection.iAnchorPos ); |
|
400 TInt offset( 0 ); |
|
401 if ( editNode ) { |
|
402 editNode = findTextNodeForCurPos( editNode, position ); |
|
403 if ( aCursorSelection.iAnchorPos > position ) { |
|
404 offset = aCursorSelection.iAnchorPos - position; |
|
405 } |
|
406 Position base( editNode, offset ); |
|
407 Position extent( editNode, offset ); |
|
408 sc->moveTo( base, extent, DOWNSTREAM ); |
|
409 } |
|
410 } |
|
411 else if ( editNode && editNode->isTextNode() ) { |
|
412 Position base( sc->baseNode(), aCursorSelection.iAnchorPos ); |
|
413 Position extent( sc->baseNode(), aCursorSelection.iCursorPos ); |
|
414 sc->moveTo( base, extent, DOWNSTREAM ); |
|
415 } |
|
416 HandleUpdateCursor(); |
|
417 } |
|
418 } |
|
419 |
|
420 // ----------------------------------------------------------------------------- |
|
421 // GetCursorSelectionForFep |
|
422 // |
|
423 // |
|
424 // ----------------------------------------------------------------------------- |
|
425 void CWebFepTextEditor::GetCursorSelectionForFep(TCursorSelection& aCursorSelection) const |
|
426 { |
|
427 aCursorSelection.SetSelection(0,0); |
|
428 |
|
429 Frame* frame = m_webView->page()->focusController()->focusedOrMainFrame(); |
|
430 if ( frame ) { |
|
431 SelectionController* sc = frame->selectionController(); |
|
432 Node* editNode = sc->base().node(); |
|
433 if ( frame && frame->document()->focusedNode() ) { |
|
434 if ( IsTextAreaFocused() ) { |
|
435 TInt len( 0 ); |
|
436 if ( editNode ) { |
|
437 findPrevSiblingTextLen( editNode, len ); |
|
438 } |
|
439 aCursorSelection.SetSelection( sc->baseOffset() + len, |
|
440 sc->extentOffset() + len ); |
|
441 } |
|
442 else { |
|
443 aCursorSelection.SetSelection(sc->baseOffset(), sc->extentOffset()); |
|
444 } |
|
445 } |
|
446 } |
|
447 } |
|
448 |
|
449 // ----------------------------------------------------------------------------- |
|
450 // GetEditorContentForFep |
|
451 // |
|
452 // |
|
453 // ----------------------------------------------------------------------------- |
|
454 void CWebFepTextEditor::GetEditorContentForFep( TDes& aEditorContent, |
|
455 TInt aDocumentPosition, |
|
456 TInt aLengthToRetrieve ) const |
|
457 { |
|
458 aEditorContent = KNullDesC; // KNullDesC has length 0 |
|
459 |
|
460 if (aLengthToRetrieve == 0) { |
|
461 return; |
|
462 } |
|
463 |
|
464 Frame* frame = m_webView->page()->focusController()->focusedOrMainFrame(); |
|
465 if (frame && |
|
466 frame->document() && |
|
467 frame->document()->focusedNode()) { |
|
468 |
|
469 if (frame->document()->focusedNode()->hasTagName(HTMLNames::inputTag)) { |
|
470 HTMLInputElement* ie = static_cast<HTMLInputElement*>(frame->document()->focusedNode()); |
|
471 aEditorContent = ie->value().substring(aDocumentPosition, aLengthToRetrieve); |
|
472 } |
|
473 else if (frame->document()->focusedNode()->hasTagName(HTMLNames::textareaTag)) { |
|
474 HTMLTextAreaElement* ie = static_cast<HTMLTextAreaElement*>(frame->document()->focusedNode()); |
|
475 // Convert the newline to paragraph separator, because the FEP |
|
476 // input editors (vkb, etc) ignore newline |
|
477 String str(ie->value().substring(aDocumentPosition, aLengthToRetrieve)); |
|
478 str.replace(EKeyLineFeed, CEditableText::EParagraphDelimiter); |
|
479 aEditorContent = str; |
|
480 } |
|
481 } |
|
482 } |
|
483 |
|
484 // ----------------------------------------------------------------------------- |
|
485 // GetFormatForFep |
|
486 // |
|
487 // |
|
488 // ----------------------------------------------------------------------------- |
|
489 void CWebFepTextEditor::GetFormatForFep(TCharFormat& /*aFormat*/,TInt /*aDocumentPosition*/) const |
|
490 { |
|
491 } |
|
492 |
|
493 // ----------------------------------------------------------------------------- |
|
494 // GetScreenCoordinatesForFepL |
|
495 // |
|
496 // |
|
497 // ----------------------------------------------------------------------------- |
|
498 void CWebFepTextEditor::GetScreenCoordinatesForFepL(TPoint& /*aLeftSideOfBaseLine*/, |
|
499 TInt& /*aHeight*/, |
|
500 TInt& /*aAscent*/, |
|
501 TInt /*aDocumentPosition*/) const |
|
502 { |
|
503 } |
|
504 |
|
505 // ----------------------------------------------------------------------------- |
|
506 // DoCommitFepInlineEditL |
|
507 // |
|
508 // |
|
509 // ----------------------------------------------------------------------------- |
|
510 void CWebFepTextEditor::DoCommitFepInlineEditL() |
|
511 { |
|
512 ClearInlineText(); |
|
513 |
|
514 if (m_inlineEditText && DocumentLengthForFep() < DocumentMaximumLengthForFep()) { |
|
515 Frame* frame = m_webView->page()->focusController()->focusedOrMainFrame(); |
|
516 if (frame){ |
|
517 frame->editor()->insertTextWithoutSendingTextEvent(String(*m_inlineEditText), false); |
|
518 } |
|
519 } |
|
520 |
|
521 //delete the m_inlineEditText since text is commited |
|
522 delete m_inlineEditText; |
|
523 m_inlineEditText = NULL; |
|
524 |
|
525 HandleUpdateCursor(); |
|
526 UpdateEditingMode(); |
|
527 } |
|
528 |
|
529 // ----------------------------------------------------------------------------- |
|
530 // Extension1 |
|
531 // |
|
532 // |
|
533 // ----------------------------------------------------------------------------- |
|
534 MCoeFepAwareTextEditor_Extension1* CWebFepTextEditor::Extension1(TBool& aSetToTrue) |
|
535 { |
|
536 aSetToTrue=ETrue; |
|
537 return STATIC_CAST(MCoeFepAwareTextEditor_Extension1*, this); |
|
538 } |
|
539 |
|
540 // ----------------------------------------------------------------------------- |
|
541 // MCoeFepAwareTextEditor_Reserved_2 |
|
542 // |
|
543 // |
|
544 // ----------------------------------------------------------------------------- |
|
545 void CWebFepTextEditor::MCoeFepAwareTextEditor_Reserved_2() |
|
546 { |
|
547 } |
|
548 |
|
549 //////////////////////////////////////////////////////////////////////////////// |
|
550 // from MCoeFepAwareTextEditor_Extension1 |
|
551 |
|
552 // ----------------------------------------------------------------------------- |
|
553 // SetStateTransferingOwnershipL |
|
554 // |
|
555 // |
|
556 // ----------------------------------------------------------------------------- |
|
557 void CWebFepTextEditor::SetStateTransferingOwnershipL(CState* aState, TUid /*aTypeSafetyUid*/) |
|
558 { |
|
559 delete m_state; |
|
560 m_state = aState; |
|
561 } |
|
562 |
|
563 // ----------------------------------------------------------------------------- |
|
564 // State |
|
565 // |
|
566 // |
|
567 // ----------------------------------------------------------------------------- |
|
568 MCoeFepAwareTextEditor_Extension1::CState* CWebFepTextEditor::State(TUid /*aTypeSafetyUid*/) |
|
569 { |
|
570 if (!m_state) { |
|
571 CAknEdwinState* state = new CAknEdwinState(); |
|
572 state->SetObjectProvider(m_webView); |
|
573 m_state = state; |
|
574 } |
|
575 return m_state; |
|
576 } |
|
577 |
|
578 // ----------------------------------------------------------------------------- |
|
579 // StartFepInlineEditL |
|
580 // |
|
581 // |
|
582 // ----------------------------------------------------------------------------- |
|
583 void CWebFepTextEditor::StartFepInlineEditL( |
|
584 TBool& aSetToTrue, |
|
585 const TCursorSelection& aCursorSelection, |
|
586 const TDesC& aInitialInlineText, |
|
587 TInt aPositionOfInsertionPointInInlineText, |
|
588 TBool aCursorVisibility, |
|
589 const MFormCustomDraw* aCustomDraw, |
|
590 MFepInlineTextFormatRetriever& aInlineTextFormatRetriever, |
|
591 MFepPointerEventHandlerDuringInlineEdit& aPointerEventHandlerDuringInlineEdit) |
|
592 { |
|
593 aSetToTrue=ETrue; |
|
594 SetCursorSelectionForFepL(aCursorSelection); |
|
595 StartFepInlineEditL(aInitialInlineText, aPositionOfInsertionPointInInlineText, aCursorVisibility, aCustomDraw, aInlineTextFormatRetriever, aPointerEventHandlerDuringInlineEdit); |
|
596 } |
|
597 |
|
598 // ----------------------------------------------------------------------------- |
|
599 // SetCursorType |
|
600 // |
|
601 // |
|
602 // ----------------------------------------------------------------------------- |
|
603 void CWebFepTextEditor::SetCursorType(TBool& /*aSetToTrue*/, const TTextCursor& /*aTextCursor*/) |
|
604 { |
|
605 } |
|
606 |
|
607 //////////////////////////////////////////////////////////////////////////////// |
|
608 // from TCoeInputCapabilities::MCoeFepSpecificExtensions |
|
609 |
|
610 // ----------------------------------------------------------------------------- |
|
611 // IsValidCharacter |
|
612 // |
|
613 // |
|
614 // ----------------------------------------------------------------------------- |
|
615 TBool CWebFepTextEditor::IsValidCharacter(TInt aChar) |
|
616 { |
|
617 return ETrue; |
|
618 } |
|
619 |
|
620 //////////////////////////////////////////////////////////////////////////////// |
|
621 // from MObjectProvider |
|
622 |
|
623 // ----------------------------------------------------------------------------- |
|
624 // MopSupplyObject |
|
625 // Fep Manager will call us to get pointers to our bits. We currently support |
|
626 // returning our ExtendedInputCapabilities. |
|
627 // ----------------------------------------------------------------------------- |
|
628 TTypeUid::Ptr CWebFepTextEditor::MopSupplyObject(TTypeUid aId) |
|
629 { |
|
630 if ( aId.iUid == CAknExtendedInputCapabilities::ETypeId ) |
|
631 { |
|
632 return aId.MakePtr( m_ExtendedInputCapabilities ); |
|
633 } |
|
634 |
|
635 return aId.Null(); |
|
636 } |
|
637 |
|
638 |
|
639 //////////////////////////////////////////////////////////////////////////////// |
|
640 // New public methods |
|
641 // |
|
642 |
|
643 // ----------------------------------------------------------------------------- |
|
644 // UpdateFlagsState |
|
645 // |
|
646 // |
|
647 // ----------------------------------------------------------------------------- |
|
648 void CWebFepTextEditor::UpdateFlagsState(TUint flags) |
|
649 { |
|
650 CAknEdwinState* state = static_cast<CAknEdwinState*>(State(KNullUid)); |
|
651 |
|
652 if ( IsTextAreaFocused() ) { |
|
653 // If in a TextArea, allow "enter" key presses to be newline/paragraph |
|
654 state->SetFlags( flags | EAknEditorFlagUseSCTNumericCharmap |
|
655 | EAknEditorFlagAllowEntersWithScrollDown ); |
|
656 } |
|
657 else { |
|
658 state->SetFlags(flags | EAknEditorFlagUseSCTNumericCharmap); |
|
659 } |
|
660 |
|
661 state->ReportAknEdStateEventL(MAknEdStateObserver::EAknEdwinStateFlagsUpdate); |
|
662 } |
|
663 |
|
664 // ----------------------------------------------------------------------------- |
|
665 // UpdateInputModeState |
|
666 // |
|
667 // |
|
668 // ----------------------------------------------------------------------------- |
|
669 void CWebFepTextEditor::UpdateInputModeState(TUint inputMode, TUint permittedInputModes, TUint numericKeyMap) |
|
670 { |
|
671 |
|
672 CAknEdwinState* state = static_cast<CAknEdwinState*>(State(KNullUid)); |
|
673 |
|
674 if (permittedInputModes != EAknEditorNumericInputMode) { |
|
675 EVariantFlag variant = AknLayoutUtils::Variant(); |
|
676 if (variant == EApacVariant) { |
|
677 permittedInputModes |= EAknEditorTextInputMode | |
|
678 EAknEditorHalfWidthTextInputMode | EAknEditorFullWidthTextInputMode | |
|
679 EAknEditorKatakanaInputMode | EAknEditorFullWidthKatakanaInputMode | |
|
680 EAknEditorHiraganaKanjiInputMode | EAknEditorHiraganaInputMode; |
|
681 |
|
682 } |
|
683 } |
|
684 |
|
685 state->SetDefaultInputMode(inputMode); |
|
686 state->SetCurrentInputMode(inputMode); |
|
687 state->SetPermittedInputModes(permittedInputModes); |
|
688 state->SetNumericKeymap(static_cast<TAknEditorNumericKeymap>(numericKeyMap)); |
|
689 |
|
690 state->ReportAknEdStateEventL(MAknEdStateObserver::EAknEdwinStateInputModeUpdate); |
|
691 |
|
692 } |
|
693 |
|
694 // ----------------------------------------------------------------------------- |
|
695 // UpdateCaseState |
|
696 // |
|
697 // |
|
698 // ----------------------------------------------------------------------------- |
|
699 void CWebFepTextEditor::UpdateCaseState(TUint currentCase, TUint permittedCase) |
|
700 { |
|
701 CAknEdwinState* state = static_cast<CAknEdwinState*>(State(KNullUid)); |
|
702 |
|
703 Frame* frame = m_webView->page()->focusController()->focusedOrMainFrame(); |
|
704 if (frame){ |
|
705 |
|
706 if (frame->editor()->canEditRichly()) { |
|
707 state->SetDefaultCase(EAknEditorTextCase); |
|
708 } |
|
709 else { |
|
710 state->SetDefaultCase(currentCase); |
|
711 state->SetCurrentCase(currentCase); |
|
712 state->SetPermittedCases(permittedCase); |
|
713 } |
|
714 } |
|
715 |
|
716 state->ReportAknEdStateEventL(MAknEdStateObserver::EAknEdwinStateCaseModeUpdate); |
|
717 } |
|
718 |
|
719 // ----------------------------------------------------------------------------- |
|
720 // HandleUpdateCursor |
|
721 // |
|
722 // |
|
723 // ----------------------------------------------------------------------------- |
|
724 void CWebFepTextEditor::HandleUpdateCursor() |
|
725 { |
|
726 // ReportAknEdStateEventL, for events see aknedstsobs.h |
|
727 // MAknEdStateObserver::EAknCursorPositionChanged |
|
728 |
|
729 CAknEdwinState* state = static_cast<CAknEdwinState*>(State(KNullUid)); |
|
730 if ( state ) { |
|
731 TRAP_IGNORE( state->ReportAknEdStateEventL( MAknEdStateObserver::EAknCursorPositionChanged ) ); |
|
732 } |
|
733 } |
|
734 |
|
735 // ----------------------------------------------------------------------------- |
|
736 // GetStateFromFormatMask |
|
737 // |
|
738 // |
|
739 // ----------------------------------------------------------------------------- |
|
740 bool CWebFepTextEditor::GetStateFromFormatMask(TUint& currentCase, |
|
741 TUint& permittedCase, |
|
742 TUint& inputMode, |
|
743 TUint& permittedInputModes, |
|
744 TUint& flags, |
|
745 TUint& numericKeyMap) |
|
746 { |
|
747 Frame* frame = m_webView->page()->focusController()->focusedOrMainFrame(); |
|
748 if (frame && m_textFormatMask) { |
|
749 |
|
750 TInt cursorpos = DocumentLengthForFep(); |
|
751 TInputFormatMaskType fm = m_textFormatMask->getInputFormatMaskType(frame, cursorpos); |
|
752 |
|
753 switch( fm ) { |
|
754 case ELeUpSymPuc: //A any upper case letter or symbolic |
|
755 flags = EAknEditorFlagNoT9 | EAknEditorFlagFixedCase; |
|
756 currentCase = EAknEditorUpperCase; |
|
757 permittedCase = EAknEditorUpperCase; |
|
758 inputMode = EAknEditorTextInputMode; |
|
759 permittedInputModes = EAknEditorTextInputMode; |
|
760 break; |
|
761 case ELeLoSymPuc: //a any lower case letter or symbolic |
|
762 flags = EAknEditorFlagNoT9 | EAknEditorFlagFixedCase; |
|
763 currentCase = EAknEditorLowerCase; |
|
764 permittedCase= EAknEditorLowerCase; |
|
765 inputMode = EAknEditorTextInputMode; |
|
766 permittedInputModes= EAknEditorTextInputMode; |
|
767 break; |
|
768 case ELeUpNumSymPuc: //X any upper case, number or symbolic |
|
769 flags = EAknEditorFlagNoT9 | EAknEditorFlagFixedCase; |
|
770 currentCase = EAknEditorUpperCase; |
|
771 permittedCase= EAknEditorUpperCase; |
|
772 inputMode = EAknEditorTextInputMode; |
|
773 permittedInputModes= EAknEditorTextInputMode; |
|
774 break; |
|
775 case ELeLoNumSymPuc: //x any lower case, number or symbolic |
|
776 flags = EAknEditorFlagNoT9 | EAknEditorFlagFixedCase; |
|
777 currentCase = EAknEditorLowerCase; |
|
778 permittedCase= EAknEditorLowerCase; |
|
779 inputMode = EAknEditorTextInputMode; |
|
780 permittedInputModes= EAknEditorTextInputMode | EAknEditorNumericInputMode; |
|
781 break; |
|
782 case EAnyLow: //m any lower character can be changed to upper |
|
783 currentCase = EAknEditorLowerCase; |
|
784 permittedCase= EAknEditorAllCaseModes; |
|
785 inputMode = EAknEditorTextInputMode; |
|
786 permittedInputModes= EAknEditorAllInputModes; |
|
787 break; |
|
788 case EAnyUpper: //M any upper character can be changed to lower |
|
789 currentCase = EAknEditorUpperCase; |
|
790 permittedCase= EAknEditorAllCaseModes; |
|
791 inputMode = EAknEditorTextInputMode; |
|
792 permittedInputModes= EAknEditorAllInputModes; |
|
793 break; |
|
794 case ENumSymPuc: //n any number or symbolic |
|
795 flags = EAknEditorFlagNoT9; |
|
796 currentCase = EAknEditorUpperCase; |
|
797 permittedCase = EAknEditorAllCaseModes; |
|
798 inputMode = EAknEditorNumericInputMode; |
|
799 permittedInputModes= EAknEditorAllInputModes; |
|
800 break; |
|
801 case ENumChar: //N any number |
|
802 flags = EAknEditorFlagNoT9; |
|
803 currentCase = EAknEditorUpperCase; |
|
804 permittedCase = EAknEditorAllCaseModes; |
|
805 inputMode = EAknEditorNumericInputMode; |
|
806 permittedInputModes= EAknEditorNumericInputMode; |
|
807 break; |
|
808 case EStatic: |
|
809 return EFalse; |
|
810 break; |
|
811 case ENoFormat: |
|
812 return EFalse; |
|
813 break; |
|
814 default: |
|
815 return EFalse; |
|
816 } |
|
817 |
|
818 return ETrue; |
|
819 } |
|
820 |
|
821 return EFalse; |
|
822 } |
|
823 |
|
824 // ----------------------------------------------------------------------------- |
|
825 // validateTextFormat |
|
826 // |
|
827 // |
|
828 // ----------------------------------------------------------------------------- |
|
829 bool CWebFepTextEditor::validateTextFormat() |
|
830 { |
|
831 Frame* frame = m_webView->page()->focusController()->focusedOrMainFrame(); |
|
832 if (!frame || !frame->document()->focusedNode()) |
|
833 return true; |
|
834 |
|
835 RenderStyle* s = frame->document()->focusedNode()->renderStyle(); |
|
836 if (!m_textFormatMask) { |
|
837 return true; |
|
838 } |
|
839 |
|
840 Node* n = frame->document()->focusedNode(); |
|
841 if (n->hasTagName(HTMLNames::inputTag)) { |
|
842 HTMLInputElement* input = static_cast<HTMLInputElement*>(n); |
|
843 WebTextFormatMask::ErrorBlock eb; |
|
844 CSSStyleDeclaration* style = input->style(); |
|
845 ExceptionCode ec = 0; |
|
846 |
|
847 String inputColor = style->getPropertyValue(CSS_PROP_COLOR); |
|
848 if ( inputColor.lower() != "red" ) |
|
849 { |
|
850 m_inputTextColor = inputColor; |
|
851 } |
|
852 |
|
853 if (!m_textFormatMask->checkText(input->value(), eb)) { |
|
854 style->setProperty(CSS_PROP_COLOR, "red", false, ec); |
|
855 return false; |
|
856 } |
|
857 else |
|
858 { |
|
859 style->setProperty(CSS_PROP_COLOR, m_inputTextColor, false, ec); |
|
860 CancelEditingMode(); |
|
861 return true; |
|
862 } |
|
863 } |
|
864 else if ( n->hasTagName(HTMLNames::textareaTag)) { |
|
865 CancelEditingMode(); |
|
866 } |
|
867 |
|
868 return true; |
|
869 } |
|
870 |
|
871 // ----------------------------------------------------------------------------- |
|
872 // IsDirectionRTL |
|
873 // Walk through the DOM and find if the focus node or a parent (table, html, |
|
874 // body, etc) has dir attribute set to RTL. |
|
875 // ----------------------------------------------------------------------------- |
|
876 TBool CWebFepTextEditor::IsDirectionRTL() |
|
877 { |
|
878 Frame* frame = m_webView->page()->focusController()->focusedOrMainFrame(); |
|
879 if ( frame && |
|
880 frame->document() && |
|
881 frame->document()->focusedNode() ) { |
|
882 |
|
883 Node* node = frame->document()->focusedNode(); |
|
884 RenderStyle* renderStyle = node->renderStyle(); |
|
885 if ( renderStyle ) { |
|
886 TextDirection txtDir = renderStyle->direction(); |
|
887 if ( txtDir == RTL ) { |
|
888 return ETrue; |
|
889 } |
|
890 } |
|
891 } |
|
892 |
|
893 return EFalse; |
|
894 } |
|
895 |
|
896 #if defined(BRDO_BROWSER_50_FF) |
|
897 // ----------------------------------------------------------------------------- |
|
898 // SetAlignment |
|
899 // The EInputEditorAlignXXX flags are only supported in 5.0+ platforms |
|
900 // |
|
901 // ----------------------------------------------------------------------------- |
|
902 void CWebFepTextEditor::SetAlignment(CAknExtendedInputCapabilities::TInputCapabilities aAlignment) |
|
903 { |
|
904 if ( !m_ExtendedInputCapabilities ) { |
|
905 return; |
|
906 } |
|
907 |
|
908 // Clear the old alignment |
|
909 TUint capabilities = m_ExtendedInputCapabilities->Capabilities(); |
|
910 capabilities &= ~( CAknExtendedInputCapabilities::KAknEditorAlignMask ); |
|
911 |
|
912 // Set the new alignment |
|
913 capabilities |= aAlignment; |
|
914 m_ExtendedInputCapabilities->SetCapabilities( capabilities ); |
|
915 } |
|
916 #endif |
|
917 |
|
918 // ----------------------------------------------------------------------------- |
|
919 // UpdateInlineText |
|
920 // |
|
921 // |
|
922 // ----------------------------------------------------------------------------- |
|
923 void CWebFepTextEditor::UpdateInlineText(const TDesC& aText) |
|
924 { |
|
925 delete m_inlineEditText; |
|
926 m_inlineEditText = NULL; |
|
927 |
|
928 if (DocumentLengthForFep() >= DocumentMaximumLengthForFep()) |
|
929 return; |
|
930 |
|
931 m_inlineEditText = aText.Alloc(); |
|
932 |
|
933 Frame* frame = m_webView->page()->focusController()->focusedOrMainFrame(); |
|
934 |
|
935 if (!frame) |
|
936 return; |
|
937 |
|
938 |
|
939 RenderStyle* r = NULL; |
|
940 if ( Node *n = frame->selectionController()->selection().start().node() ) { |
|
941 r = n->renderStyle(); |
|
942 } |
|
943 |
|
944 bool textSecurity = r && r->textSecurity() != TSNONE; |
|
945 |
|
946 RefPtr<CSSMutableStyleDeclaration> oldStyle; |
|
947 if (textSecurity) { |
|
948 oldStyle = frame->typingStyle(); |
|
949 RefPtr<CSSMutableStyleDeclaration> style = new CSSMutableStyleDeclaration; |
|
950 style->setProperty(CSS_PROP__WEBKIT_TEXT_SECURITY, CSS_VAL_NONE); |
|
951 frame->computeAndSetTypingStyle(style.get(), EditActionTyping); |
|
952 } |
|
953 |
|
954 frame->editor()->insertTextWithoutSendingTextEvent(String(*m_inlineEditText), false); |
|
955 |
|
956 if (textSecurity) { |
|
957 if (oldStyle) |
|
958 frame->setTypingStyle(oldStyle.get()); |
|
959 else |
|
960 frame->clearTypingStyle(); |
|
961 } |
|
962 } |
|
963 |
|
964 // ----------------------------------------------------------------------------- |
|
965 // ClearInlineText |
|
966 // |
|
967 // |
|
968 // ----------------------------------------------------------------------------- |
|
969 void CWebFepTextEditor::ClearInlineText() |
|
970 { |
|
971 TInt oldlen = m_inlineEditText ? m_inlineEditText->Length() : 0; |
|
972 |
|
973 TKeyEvent keyEvent = { EKeyBackspace, EKeyBackspace, 0, 0 }; |
|
974 Frame* frame = m_webView->page()->focusController()->focusedOrMainFrame(); |
|
975 if (frame) { |
|
976 while ( oldlen-- ) { |
|
977 frame->editor()->deleteWithDirection(SelectionController::BACKWARD, |
|
978 CharacterGranularity, false, true); |
|
979 } |
|
980 } |
|
981 } |
|
982 |
|
983 // ----------------------------------------------------------------------------- |
|
984 // IsTextAreaFocused |
|
985 // |
|
986 // |
|
987 // ----------------------------------------------------------------------------- |
|
988 bool CWebFepTextEditor::IsTextAreaFocused() const |
|
989 { |
|
990 Frame* frame = m_webView->page()->focusController()->focusedOrMainFrame(); |
|
991 return ( frame && frame->document()->focusedNode() && |
|
992 frame->document()->focusedNode()->hasTagName(HTMLNames::textareaTag)); |
|
993 } |
|
994 |
|
995 // ----------------------------------------------------------------------------- |
|
996 // CcpuIsFocused |
|
997 // |
|
998 // |
|
999 // ----------------------------------------------------------------------------- |
|
1000 TBool CWebFepTextEditor::CcpuIsFocused() const |
|
1001 { |
|
1002 return ETrue; |
|
1003 } |
|
1004 |
|
1005 // ----------------------------------------------------------------------------- |
|
1006 // CcpuCanCut |
|
1007 // |
|
1008 // |
|
1009 // ----------------------------------------------------------------------------- |
|
1010 TBool CWebFepTextEditor::CcpuCanCut() const |
|
1011 { |
|
1012 TCursorSelection selection; |
|
1013 GetCursorSelectionForFep(selection); |
|
1014 return selection.Length(); |
|
1015 } |
|
1016 |
|
1017 // ----------------------------------------------------------------------------- |
|
1018 // CcpuCutL |
|
1019 // |
|
1020 // |
|
1021 // ----------------------------------------------------------------------------- |
|
1022 void CWebFepTextEditor::CcpuCutL() |
|
1023 { |
|
1024 PlaceDataOnClipboardL(); |
|
1025 TCursorSelection selection; |
|
1026 GetCursorSelectionForFep(selection); |
|
1027 } |
|
1028 |
|
1029 // ----------------------------------------------------------------------------- |
|
1030 // CcpuCanCopy |
|
1031 // |
|
1032 // |
|
1033 // ----------------------------------------------------------------------------- |
|
1034 TBool CWebFepTextEditor::CcpuCanCopy() const |
|
1035 { |
|
1036 TCursorSelection selection; |
|
1037 GetCursorSelectionForFep(selection); |
|
1038 return selection.Length(); |
|
1039 } |
|
1040 |
|
1041 // ----------------------------------------------------------------------------- |
|
1042 // CcpuCopyL |
|
1043 // |
|
1044 // |
|
1045 // ----------------------------------------------------------------------------- |
|
1046 void CWebFepTextEditor::CcpuCopyL() |
|
1047 { |
|
1048 PlaceDataOnClipboardL(); |
|
1049 } |
|
1050 |
|
1051 // ----------------------------------------------------------------------------- |
|
1052 // CcpuCanPaste |
|
1053 // |
|
1054 // |
|
1055 // ----------------------------------------------------------------------------- |
|
1056 TBool CWebFepTextEditor::CcpuCanPaste() const |
|
1057 { |
|
1058 TRAPD(err, DoCcpuCanPasteL()); |
|
1059 return err == KErrNone; |
|
1060 } |
|
1061 |
|
1062 // ----------------------------------------------------------------------------- |
|
1063 // CcpuPasteL |
|
1064 // |
|
1065 // |
|
1066 // ----------------------------------------------------------------------------- |
|
1067 void CWebFepTextEditor::CcpuPasteL() |
|
1068 { |
|
1069 RetrieveDataFromClipboardL(); |
|
1070 } |
|
1071 |
|
1072 // ----------------------------------------------------------------------------- |
|
1073 // DoCcpuCanPasteL |
|
1074 // |
|
1075 // |
|
1076 // ----------------------------------------------------------------------------- |
|
1077 void CWebFepTextEditor::DoCcpuCanPasteL() const |
|
1078 { |
|
1079 CClipboard* cb=CClipboard::NewForReadingL(CCoeEnv::Static()->FsSession()); |
|
1080 CleanupStack::PushL(cb); |
|
1081 TStreamId streamId=cb->StreamDictionary().At(KClipboardUidTypePlainText); |
|
1082 if (streamId==KNullStreamId) |
|
1083 User::Leave(KErrNotFound); |
|
1084 CleanupStack::PopAndDestroy(); // allowedChars, cb |
|
1085 } |
|
1086 |
|
1087 // ----------------------------------------------------------------------------- |
|
1088 // PlaceDataOnClipboardL |
|
1089 // |
|
1090 // |
|
1091 // ----------------------------------------------------------------------------- |
|
1092 void CWebFepTextEditor::PlaceDataOnClipboardL() |
|
1093 { |
|
1094 CancelFepInlineEdit(); |
|
1095 CClipboard* cb=CClipboard::NewForWritingLC(CCoeEnv::Static()->FsSession()); |
|
1096 CopyToStoreL(cb->Store(),cb->StreamDictionary()); |
|
1097 cb->CommitL(); |
|
1098 CleanupStack::PopAndDestroy(); |
|
1099 } |
|
1100 |
|
1101 // ----------------------------------------------------------------------------- |
|
1102 // CopyToStoreL |
|
1103 // |
|
1104 // |
|
1105 // ----------------------------------------------------------------------------- |
|
1106 void CWebFepTextEditor::CopyToStoreL(CStreamStore& aStore,CStreamDictionary& aDict) |
|
1107 { |
|
1108 if ( DocumentLengthForFep()== 0) |
|
1109 return ; |
|
1110 TCursorSelection selection; |
|
1111 GetCursorSelectionForFep(selection); |
|
1112 |
|
1113 HBufC* buf = HBufC::NewLC(512); |
|
1114 TPtr ptr(buf->Des()); |
|
1115 |
|
1116 GetEditorContentForFep(ptr,0,DocumentLengthForFep()); |
|
1117 CPlainText* text = CPlainText::NewL(CPlainText::EFlatStorage); |
|
1118 |
|
1119 text->InsertL(0,*buf); |
|
1120 text->CopyToStoreL(aStore, aDict, selection.LowerPos(), selection.Length()); |
|
1121 |
|
1122 delete text; |
|
1123 CleanupStack::PopAndDestroy(); |
|
1124 } |
|
1125 |
|
1126 // ----------------------------------------------------------------------------- |
|
1127 // RetrieveDataFromClipboardL |
|
1128 // |
|
1129 // |
|
1130 // ----------------------------------------------------------------------------- |
|
1131 void CWebFepTextEditor::RetrieveDataFromClipboardL() |
|
1132 { |
|
1133 m_webView->fepTextEditor()->CancelFepInlineEdit(); |
|
1134 CClipboard* cb=NULL; |
|
1135 TRAPD(err,cb=CClipboard::NewForReadingL(CCoeEnv::Static()->FsSession())); |
|
1136 CleanupStack::PushL(cb); |
|
1137 User::LeaveIfError(err); |
|
1138 TStreamId streamId=cb->StreamDictionary().At(KClipboardUidTypePlainText); |
|
1139 PasteFromStoreL(cb->Store(), cb->StreamDictionary()); |
|
1140 CleanupStack::PopAndDestroy(); // cb |
|
1141 } |
|
1142 |
|
1143 // ----------------------------------------------------------------------------- |
|
1144 // PasteFromStoreL |
|
1145 // |
|
1146 // |
|
1147 // ----------------------------------------------------------------------------- |
|
1148 void CWebFepTextEditor::PasteFromStoreL(CStreamStore& aStore,CStreamDictionary& aDict) |
|
1149 { |
|
1150 //Read the content into Text |
|
1151 CancelFepInlineEdit(); |
|
1152 TStreamId streamId=aDict.At(KClipboardUidTypePlainText); |
|
1153 TCursorSelection selection; |
|
1154 GetCursorSelectionForFep(selection); |
|
1155 const TInt cursorPos=selection.LowerPos(); |
|
1156 |
|
1157 HBufC* buf1 = HBufC::NewLC(512); |
|
1158 TPtr ptr1(buf1->Des()); |
|
1159 |
|
1160 CPlainText* text = CPlainText::NewL(CPlainText::EFlatStorage); |
|
1161 |
|
1162 GetEditorContentForFep(ptr1,0,DocumentLengthForFep()); |
|
1163 |
|
1164 text->InsertL(0,*buf1); |
|
1165 |
|
1166 TInt charPasted = text->PasteFromStoreL(aStore,aDict,cursorPos); |
|
1167 |
|
1168 HBufC* buf = HBufC::NewLC(512); |
|
1169 TPtr ptr(buf->Des()); |
|
1170 text->Extract(ptr,cursorPos,charPasted); |
|
1171 |
|
1172 //remove Paragraph Delimiter |
|
1173 TInt position = ptr.Mid(0).LocateReverse(TChar(CEditableText::EParagraphDelimiter)); |
|
1174 while (position != KErrNotFound ){ |
|
1175 ptr.Delete( position, 1 ); |
|
1176 position = ptr.Left(position).LocateReverse(TChar(CEditableText::EParagraphDelimiter)); |
|
1177 } |
|
1178 |
|
1179 Frame* frame = m_webView->page()->mainFrame(); |
|
1180 frame = m_webView->page()->focusController()->focusedOrMainFrame(); |
|
1181 frame->editor()->insertTextWithoutSendingTextEvent(String(ptr), false); |
|
1182 |
|
1183 delete text; |
|
1184 CleanupStack::PopAndDestroy(2); |
|
1185 } |
|
1186 |
|
1187 // ----------------------------------------------------------------------------- |
|
1188 // EnableCcpu |
|
1189 // |
|
1190 // |
|
1191 // ----------------------------------------------------------------------------- |
|
1192 void CWebFepTextEditor::EnableCcpu(TBool aSupport) |
|
1193 { |
|
1194 CAknEdwinState* edwinState = static_cast<CAknEdwinState*>(this->State(KNullUid)); |
|
1195 if(aSupport) |
|
1196 { |
|
1197 edwinState->SetCcpuState(this); |
|
1198 } |
|
1199 else |
|
1200 { |
|
1201 edwinState->SetCcpuState(NULL); |
|
1202 } |
|
1203 } |
|
1204 |
|
1205 // ----------------------------------------------------------------------------- |
|
1206 // findPrevSiblingTextLen |
|
1207 // |
|
1208 // Walk the previous text nodes and add up the len of each text node, so we can |
|
1209 // calculate the total length from first text node to current text node cursor |
|
1210 // position. |
|
1211 // NOTES: |
|
1212 // 1. Each "inserted" newline creates a new node. |
|
1213 // 2. Text area's with newline characters prepopulated (not "entered" by users, |
|
1214 // but in the original html) do not create separate nodes. |
|
1215 // ----------------------------------------------------------------------------- |
|
1216 void CWebFepTextEditor::findPrevSiblingTextLen(Node* aNode, TInt& aLen) const |
|
1217 { |
|
1218 String str; |
|
1219 while ( aNode ) { |
|
1220 aNode = aNode->previousSibling(); |
|
1221 if ( aNode && aNode->isTextNode() ) { |
|
1222 WebCore::Text* text = (WebCore::Text*)aNode; |
|
1223 str = text->data(); |
|
1224 aLen += str.length(); |
|
1225 } |
|
1226 } |
|
1227 } |
|
1228 |
|
1229 // ----------------------------------------------------------------------------- |
|
1230 // findTextNodeCurPos |
|
1231 // |
|
1232 // Returns the text node that contains the current text (cursor) position and |
|
1233 // returns the summed length (aPos) of all the text nodes before the current |
|
1234 // text node. |
|
1235 // NOTE: The length (aPos) doesn't include the current text node's length. |
|
1236 // ----------------------------------------------------------------------------- |
|
1237 Node* CWebFepTextEditor::findTextNodeForCurPos(Node* aNode, TInt& aPos) const |
|
1238 { |
|
1239 // Get the first text node |
|
1240 Node* firstTextNode = NULL; |
|
1241 Node* retNode = aNode; |
|
1242 while ( aNode ) { |
|
1243 firstTextNode = aNode; |
|
1244 aNode = aNode->previousSibling(); |
|
1245 } |
|
1246 |
|
1247 TInt len( 0 ); |
|
1248 String str; |
|
1249 aNode = firstTextNode; |
|
1250 for ( ; aNode; aNode=aNode->nextSibling() ) { |
|
1251 if ( aNode && aNode->isTextNode() ) { |
|
1252 WebCore::Text* aText = (WebCore::Text*)aNode; |
|
1253 str = aText->data(); |
|
1254 len += str.length(); |
|
1255 if ( len >= aPos ) { |
|
1256 // We found the text node at aPos, calculate the length of all |
|
1257 // previous text nodes |
|
1258 retNode = aNode; |
|
1259 aPos = len - str.length(); |
|
1260 break; |
|
1261 } |
|
1262 } |
|
1263 } |
|
1264 |
|
1265 return retNode; |
|
1266 } |