2 * Copyright (c) 2021 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali-toolkit/internal/text/text-controller-text-updater.h>
22 #include <dali/integration-api/debug.h>
26 #include <dali-toolkit/internal/text/character-set-conversion.h>
27 #include <dali-toolkit/internal/text/markup-processor.h>
28 #include <dali-toolkit/internal/text/text-controller-impl.h>
29 #include <dali-toolkit/internal/text/text-editable-control-interface.h>
33 #if defined(DEBUG_ENABLED)
34 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_TEXT_CONTROLS");
45 void Controller::TextUpdater::SetText(Controller& controller, const std::string& text)
47 DALI_LOG_INFO(gLogFilter, Debug::Verbose, "Controller::SetText\n");
49 Controller::Impl& impl = *controller.mImpl;
51 // Reset keyboard as text changed
52 impl.ResetInputMethodContext();
54 // Remove the previously set text and style.
55 ResetText(controller);
58 impl.ClearStyleData();
60 CharacterIndex lastCursorIndex = 0u;
62 EventData*& eventData = impl.mEventData;
64 if(nullptr != eventData)
66 // If popup shown then hide it by switching to Editing state
67 if((EventData::SELECTING == eventData->mState) ||
68 (EventData::EDITING_WITH_POPUP == eventData->mState) ||
69 (EventData::EDITING_WITH_GRAB_HANDLE == eventData->mState) ||
70 (EventData::EDITING_WITH_PASTE_POPUP == eventData->mState))
72 if((impl.mSelectableControlInterface != nullptr) && (EventData::SELECTING == eventData->mState))
74 impl.mSelectableControlInterface->SelectionChanged(eventData->mLeftSelectionPosition, eventData->mRightSelectionPosition, eventData->mPrimaryCursorPosition, eventData->mPrimaryCursorPosition);
77 impl.ChangeState(EventData::EDITING);
83 ModelPtr& model = impl.mModel;
84 LogicalModelPtr& logicalModel = model->mLogicalModel;
85 model->mVisualModel->SetTextColor(impl.mTextColor);
87 MarkupProcessData markupProcessData(logicalModel->mColorRuns,
88 logicalModel->mFontDescriptionRuns,
89 logicalModel->mEmbeddedItems,
90 logicalModel->mAnchors,
91 logicalModel->mUnderlinedCharacterRuns,
92 logicalModel->mBackgroundColorRuns);
95 const uint8_t* utf8 = NULL;
96 if(impl.mMarkupProcessorEnabled)
98 ProcessMarkupString(text, markupProcessData);
99 textSize = markupProcessData.markupProcessedText.size();
101 // This is a bit horrible but std::string returns a (signed) char*
102 utf8 = reinterpret_cast<const uint8_t*>(markupProcessData.markupProcessedText.c_str());
106 textSize = text.size();
108 // This is a bit horrible but std::string returns a (signed) char*
109 utf8 = reinterpret_cast<const uint8_t*>(text.c_str());
112 // Convert text into UTF-32
113 Vector<Character>& utf32Characters = logicalModel->mText;
114 utf32Characters.Resize(textSize);
116 // Transform a text array encoded in utf8 into an array encoded in utf32.
117 // It returns the actual number of characters.
118 Length characterCount = Utf8ToUtf32(utf8, textSize, utf32Characters.Begin());
119 utf32Characters.Resize(characterCount);
121 DALI_ASSERT_DEBUG(textSize >= characterCount && "Invalid UTF32 conversion length");
122 DALI_LOG_INFO(gLogFilter, Debug::Verbose, "Controller::SetText %p UTF8 size %d, UTF32 size %d\n", &controller, textSize, logicalModel->mText.Count());
124 // The characters to be added.
125 impl.mTextUpdateInfo.mNumberOfCharactersToAdd = logicalModel->mText.Count();
127 // To reset the cursor position
128 lastCursorIndex = characterCount;
130 // Update the rest of the model during size negotiation
131 impl.QueueModifyEvent(ModifyEvent::TEXT_REPLACED);
133 // The natural size needs to be re-calculated.
134 impl.mRecalculateNaturalSize = true;
136 // The text direction needs to be updated.
137 impl.mUpdateTextDirection = true;
139 // Apply modifications to the model
140 impl.mOperationsPending = ALL_OPERATIONS;
144 controller.ShowPlaceholderText();
147 unsigned int oldCursorPos = (nullptr != eventData ? eventData->mPrimaryCursorPosition : 0);
149 // Resets the cursor position.
150 controller.ResetCursorPosition(lastCursorIndex);
152 // Scrolls the text to make the cursor visible.
153 impl.ResetScrollPosition();
155 impl.RequestRelayout();
157 if(nullptr != eventData)
159 // Cancel previously queued events
160 eventData->mEventQueue.clear();
163 // Do this last since it provides callbacks into application code.
164 if(NULL != impl.mEditableControlInterface)
166 impl.mEditableControlInterface->CursorPositionChanged(oldCursorPos, lastCursorIndex);
167 impl.mEditableControlInterface->TextChanged(true);
171 void Controller::TextUpdater::InsertText(Controller& controller, const std::string& text, Controller::InsertType type)
173 Controller::Impl& impl = *controller.mImpl;
174 EventData*& eventData = impl.mEventData;
176 DALI_ASSERT_DEBUG(nullptr != eventData && "Unexpected InsertText")
178 if(NULL == eventData)
183 bool removedPrevious = false;
184 bool removedSelected = false;
185 bool maxLengthReached = false;
186 unsigned int oldCursorPos = eventData->mPrimaryCursorPosition;
188 DALI_LOG_INFO(gLogFilter, Debug::Verbose, "Controller::InsertText %p %s (%s) mPrimaryCursorPosition %d mPreEditFlag %d mPreEditStartPosition %d mPreEditLength %d\n", &controller, text.c_str(), (COMMIT == type ? "COMMIT" : "PRE_EDIT"), eventData->mPrimaryCursorPosition, eventData->mPreEditFlag, eventData->mPreEditStartPosition, eventData->mPreEditLength);
190 ModelPtr& model = impl.mModel;
191 LogicalModelPtr& logicalModel = model->mLogicalModel;
193 // TODO: At the moment the underline runs are only for pre-edit.
194 model->mVisualModel->mUnderlineRuns.Clear();
196 // Remove the previous InputMethodContext pre-edit.
197 if(eventData->mPreEditFlag && (0u != eventData->mPreEditLength))
199 removedPrevious = RemoveText(controller,
200 -static_cast<int>(eventData->mPrimaryCursorPosition - eventData->mPreEditStartPosition),
201 eventData->mPreEditLength,
202 DONT_UPDATE_INPUT_STYLE);
204 eventData->mPrimaryCursorPosition = eventData->mPreEditStartPosition;
205 eventData->mPreEditLength = 0u;
209 // Remove the previous Selection.
210 removedSelected = RemoveSelectedText(controller);
213 Vector<Character> utf32Characters;
214 Length characterCount = 0u;
218 // Convert text into UTF-32
219 utf32Characters.Resize(text.size());
221 // This is a bit horrible but std::string returns a (signed) char*
222 const uint8_t* utf8 = reinterpret_cast<const uint8_t*>(text.c_str());
224 // Transform a text array encoded in utf8 into an array encoded in utf32.
225 // It returns the actual number of characters.
226 characterCount = Utf8ToUtf32(utf8, text.size(), utf32Characters.Begin());
227 utf32Characters.Resize(characterCount);
229 DALI_ASSERT_DEBUG(text.size() >= utf32Characters.Count() && "Invalid UTF32 conversion length");
230 DALI_LOG_INFO(gLogFilter, Debug::Verbose, "UTF8 size %d, UTF32 size %d\n", text.size(), utf32Characters.Count());
233 if(0u != utf32Characters.Count()) // Check if Utf8ToUtf32 conversion succeeded
235 // The placeholder text is no longer needed
236 if(impl.IsShowingPlaceholderText())
238 ResetText(controller);
241 impl.ChangeState(EventData::EDITING);
243 // Handle the InputMethodContext (predicitive text) state changes
246 // InputMethodContext is no longer handling key-events
247 impl.ClearPreEditFlag();
251 if(!eventData->mPreEditFlag)
253 DALI_LOG_INFO(gLogFilter, Debug::Verbose, "Entered PreEdit state\n");
255 // Record the start of the pre-edit text
256 eventData->mPreEditStartPosition = eventData->mPrimaryCursorPosition;
259 eventData->mPreEditLength = utf32Characters.Count();
260 eventData->mPreEditFlag = true;
262 DALI_LOG_INFO(gLogFilter, Debug::Verbose, "mPreEditStartPosition %d mPreEditLength %d\n", eventData->mPreEditStartPosition, eventData->mPreEditLength);
265 const Length numberOfCharactersInModel = logicalModel->mText.Count();
267 // Restrict new text to fit within Maximum characters setting.
268 Length temp_length = (impl.mMaximumNumberOfCharacters > numberOfCharactersInModel ? impl.mMaximumNumberOfCharacters - numberOfCharactersInModel : 0);
269 Length maxSizeOfNewText = std::min(temp_length, characterCount);
270 maxLengthReached = (characterCount > maxSizeOfNewText);
272 // The cursor position.
273 CharacterIndex& cursorIndex = eventData->mPrimaryCursorPosition;
275 // Update the text's style.
277 // Updates the text style runs by adding characters.
278 logicalModel->UpdateTextStyleRuns(cursorIndex, maxSizeOfNewText);
280 // Get the character index from the cursor index.
281 const CharacterIndex styleIndex = (cursorIndex > 0u) ? cursorIndex - 1u : 0u;
283 // Retrieve the text's style for the given index.
285 impl.RetrieveDefaultInputStyle(style);
286 logicalModel->RetrieveStyle(styleIndex, style);
288 InputStyle& inputStyle = eventData->mInputStyle;
290 // Whether to add a new text color run.
291 const bool addColorRun = (style.textColor != inputStyle.textColor) && !inputStyle.isDefaultColor;
293 // Whether to add a new font run.
294 const bool addFontNameRun = (style.familyName != inputStyle.familyName) && inputStyle.isFamilyDefined;
295 const bool addFontWeightRun = (style.weight != inputStyle.weight) && inputStyle.isWeightDefined;
296 const bool addFontWidthRun = (style.width != inputStyle.width) && inputStyle.isWidthDefined;
297 const bool addFontSlantRun = (style.slant != inputStyle.slant) && inputStyle.isSlantDefined;
298 const bool addFontSizeRun = (style.size != inputStyle.size) && inputStyle.isSizeDefined;
303 const VectorBase::SizeType numberOfRuns = logicalModel->mColorRuns.Count();
304 logicalModel->mColorRuns.Resize(numberOfRuns + 1u);
306 ColorRun& colorRun = *(logicalModel->mColorRuns.Begin() + numberOfRuns);
307 colorRun.color = inputStyle.textColor;
308 colorRun.characterRun.characterIndex = cursorIndex;
309 colorRun.characterRun.numberOfCharacters = maxSizeOfNewText;
318 const VectorBase::SizeType numberOfRuns = logicalModel->mFontDescriptionRuns.Count();
319 logicalModel->mFontDescriptionRuns.Resize(numberOfRuns + 1u);
321 FontDescriptionRun& fontDescriptionRun = *(logicalModel->mFontDescriptionRuns.Begin() + numberOfRuns);
325 fontDescriptionRun.familyLength = inputStyle.familyName.size();
326 fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength];
327 memcpy(fontDescriptionRun.familyName, inputStyle.familyName.c_str(), fontDescriptionRun.familyLength);
328 fontDescriptionRun.familyDefined = true;
330 // The memory allocated for the font family name is freed when the font description is removed from the logical model.
335 fontDescriptionRun.weight = inputStyle.weight;
336 fontDescriptionRun.weightDefined = true;
341 fontDescriptionRun.width = inputStyle.width;
342 fontDescriptionRun.widthDefined = true;
347 fontDescriptionRun.slant = inputStyle.slant;
348 fontDescriptionRun.slantDefined = true;
353 fontDescriptionRun.size = static_cast<PointSize26Dot6>(inputStyle.size * impl.mFontSizeScale * 64.f);
354 fontDescriptionRun.sizeDefined = true;
357 fontDescriptionRun.characterRun.characterIndex = cursorIndex;
358 fontDescriptionRun.characterRun.numberOfCharacters = maxSizeOfNewText;
361 // Insert at current cursor position.
362 Vector<Character>& modifyText = logicalModel->mText;
364 auto pos = modifyText.End();
365 if(cursorIndex < numberOfCharactersInModel)
367 pos = modifyText.Begin() + cursorIndex;
369 unsigned int realPos = pos - modifyText.Begin();
370 modifyText.Insert(pos, utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText);
372 if(NULL != impl.mEditableControlInterface)
374 impl.mEditableControlInterface->TextInserted(realPos, maxSizeOfNewText, text);
377 TextUpdateInfo& textUpdateInfo = impl.mTextUpdateInfo;
379 // Mark the first paragraph to be updated.
380 if(Layout::Engine::SINGLE_LINE_BOX == impl.mLayoutEngine.GetLayout())
382 textUpdateInfo.mCharacterIndex = 0;
383 textUpdateInfo.mNumberOfCharactersToRemove = textUpdateInfo.mPreviousNumberOfCharacters;
384 textUpdateInfo.mNumberOfCharactersToAdd = numberOfCharactersInModel + maxSizeOfNewText;
385 textUpdateInfo.mClearAll = true;
389 textUpdateInfo.mCharacterIndex = std::min(cursorIndex, textUpdateInfo.mCharacterIndex);
390 textUpdateInfo.mNumberOfCharactersToAdd += maxSizeOfNewText;
393 if(impl.mMarkupProcessorEnabled)
395 InsertTextAnchor(controller, maxSizeOfNewText, cursorIndex);
398 // Update the cursor index.
399 cursorIndex += maxSizeOfNewText;
401 DALI_LOG_INFO(gLogFilter, Debug::Verbose, "Inserted %d characters, new size %d new cursor %d\n", maxSizeOfNewText, logicalModel->mText.Count(), eventData->mPrimaryCursorPosition);
404 if((0u == logicalModel->mText.Count()) &&
405 impl.IsPlaceholderAvailable())
407 // Show place-holder if empty after removing the pre-edit text
408 controller.ShowPlaceholderText();
409 eventData->mUpdateCursorPosition = true;
410 impl.ClearPreEditFlag();
412 else if(removedPrevious ||
414 (0 != utf32Characters.Count()))
416 // Queue an inserted event
417 impl.QueueModifyEvent(ModifyEvent::TEXT_INSERTED);
419 eventData->mUpdateCursorPosition = true;
422 eventData->mScrollAfterDelete = true;
426 eventData->mScrollAfterUpdatePosition = true;
430 if(nullptr != impl.mEditableControlInterface)
432 impl.mEditableControlInterface->CursorPositionChanged(oldCursorPos, eventData->mPrimaryCursorPosition);
437 DALI_LOG_INFO(gLogFilter, Debug::Verbose, "MaxLengthReached (%d)\n", logicalModel->mText.Count());
439 impl.ResetInputMethodContext();
441 if(NULL != impl.mEditableControlInterface)
443 // Do this last since it provides callbacks into application code
444 impl.mEditableControlInterface->MaxLengthReached();
449 void Controller::TextUpdater::PasteText(Controller& controller, const std::string& stringToPaste)
451 InsertText(controller, stringToPaste, Text::Controller::COMMIT);
452 Controller::Impl& impl = *controller.mImpl;
453 impl.ChangeState(EventData::EDITING);
454 impl.RequestRelayout();
456 if(NULL != impl.mEditableControlInterface)
458 // Do this last since it provides callbacks into application code
459 impl.mEditableControlInterface->TextChanged(true);
463 bool Controller::TextUpdater::RemoveText(
464 Controller& controller,
466 int numberOfCharacters,
467 UpdateInputStyleType type)
469 bool removed = false;
471 Controller::Impl& impl = *controller.mImpl;
472 EventData*& eventData = impl.mEventData;
474 if(nullptr == eventData)
479 ModelPtr& model = impl.mModel;
480 LogicalModelPtr& logicalModel = model->mLogicalModel;
482 DALI_LOG_INFO(gLogFilter, Debug::General, "Controller::RemoveText %p mText.Count() %d cursor %d cursorOffset %d numberOfCharacters %d\n", &controller, logicalModel->mText.Count(), eventData->mPrimaryCursorPosition, cursorOffset, numberOfCharacters);
484 if(!impl.IsShowingPlaceholderText())
486 // Delete at current cursor position
487 Vector<Character>& currentText = logicalModel->mText;
488 CharacterIndex& previousCursorIndex = eventData->mPrimaryCursorPosition;
490 CharacterIndex cursorIndex = 0;
492 // Validate the cursor position & number of characters
493 if((static_cast<int>(eventData->mPrimaryCursorPosition) + cursorOffset) >= 0)
495 cursorIndex = eventData->mPrimaryCursorPosition + cursorOffset;
498 if((cursorIndex + numberOfCharacters) > currentText.Count())
500 numberOfCharacters = currentText.Count() - cursorIndex;
503 TextUpdateInfo& textUpdateInfo = impl.mTextUpdateInfo;
505 if(eventData->mPreEditFlag || // If the preedit flag is enabled, it means two (or more) of them came together i.e. when two keys have been pressed at the same time.
506 ((cursorIndex + numberOfCharacters) <= textUpdateInfo.mPreviousNumberOfCharacters))
508 // Mark the paragraphs to be updated.
509 if(Layout::Engine::SINGLE_LINE_BOX == impl.mLayoutEngine.GetLayout())
511 textUpdateInfo.mCharacterIndex = 0;
512 textUpdateInfo.mNumberOfCharactersToRemove = textUpdateInfo.mPreviousNumberOfCharacters;
513 textUpdateInfo.mNumberOfCharactersToAdd = textUpdateInfo.mPreviousNumberOfCharacters - numberOfCharacters;
514 textUpdateInfo.mClearAll = true;
518 textUpdateInfo.mCharacterIndex = std::min(cursorIndex, textUpdateInfo.mCharacterIndex);
519 textUpdateInfo.mNumberOfCharactersToRemove += numberOfCharacters;
522 // Update the input style and remove the text's style before removing the text.
524 if(UPDATE_INPUT_STYLE == type)
526 InputStyle& eventDataInputStyle = eventData->mInputStyle;
528 // Keep a copy of the current input style.
529 InputStyle currentInputStyle;
530 currentInputStyle.Copy(eventDataInputStyle);
532 // Set first the default input style.
533 impl.RetrieveDefaultInputStyle(eventDataInputStyle);
535 // Update the input style.
536 logicalModel->RetrieveStyle(cursorIndex, eventDataInputStyle);
538 // Compare if the input style has changed.
539 const bool hasInputStyleChanged = !currentInputStyle.Equal(eventDataInputStyle);
541 if(hasInputStyleChanged)
543 const InputStyle::Mask styleChangedMask = currentInputStyle.GetInputStyleChangeMask(eventDataInputStyle);
544 // Queue the input style changed signal.
545 eventData->mInputStyleChangedQueue.PushBack(styleChangedMask);
549 // If the number of current text and the number of characters to be deleted are same,
550 // it means all texts should be removed and all Preedit variables should be initialized.
551 if((currentText.Count() - numberOfCharacters == 0) && (cursorIndex == 0))
553 impl.ClearPreEditFlag();
554 textUpdateInfo.mNumberOfCharactersToAdd = 0;
557 // Updates the text style runs by removing characters. Runs with no characters are removed.
558 logicalModel->UpdateTextStyleRuns(cursorIndex, -numberOfCharacters);
560 // Remove the characters.
561 Vector<Character>::Iterator first = currentText.Begin() + cursorIndex;
562 Vector<Character>::Iterator last = first + numberOfCharacters;
564 if(NULL != impl.mEditableControlInterface)
567 Utf32ToUtf8(first, numberOfCharacters, utf8);
568 impl.mEditableControlInterface->TextDeleted(cursorIndex, numberOfCharacters, utf8);
571 currentText.Erase(first, last);
573 if(impl.mMarkupProcessorEnabled)
575 RemoveTextAnchor(controller, cursorOffset, numberOfCharacters, previousCursorIndex);
578 if(nullptr != impl.mEditableControlInterface)
580 impl.mEditableControlInterface->CursorPositionChanged(previousCursorIndex, cursorIndex);
583 // Cursor position retreat
584 previousCursorIndex = cursorIndex;
586 eventData->mScrollAfterDelete = true;
588 if(EventData::INACTIVE == eventData->mState)
590 impl.ChangeState(EventData::EDITING);
593 DALI_LOG_INFO(gLogFilter, Debug::General, "Controller::RemoveText %p removed %d\n", &controller, numberOfCharacters);
601 bool Controller::TextUpdater::RemoveSelectedText(Controller& controller)
603 bool textRemoved(false);
605 Controller::Impl& impl = *controller.mImpl;
607 if(EventData::SELECTING == impl.mEventData->mState)
609 std::string removedString;
610 uint32_t oldSelStart = impl.mEventData->mLeftSelectionPosition;
611 uint32_t oldSelEnd = impl.mEventData->mRightSelectionPosition;
613 impl.RetrieveSelection(removedString, true);
615 if(!removedString.empty())
618 impl.ChangeState(EventData::EDITING);
620 if(impl.mMarkupProcessorEnabled)
622 int cursorOffset = -1;
623 int numberOfCharacters = removedString.length();
624 CharacterIndex& cursorIndex = impl.mEventData->mPrimaryCursorPosition;
625 CharacterIndex previousCursorIndex = cursorIndex + numberOfCharacters;
627 RemoveTextAnchor(controller, cursorOffset, numberOfCharacters, previousCursorIndex);
630 if(impl.mSelectableControlInterface != nullptr)
632 impl.mSelectableControlInterface->SelectionChanged(oldSelStart, oldSelEnd, impl.mEventData->mPrimaryCursorPosition, impl.mEventData->mPrimaryCursorPosition);
640 void Controller::TextUpdater::ResetText(Controller& controller)
642 Controller::Impl& impl = *controller.mImpl;
643 LogicalModelPtr& logicalModel = impl.mModel->mLogicalModel;
646 logicalModel->mText.Clear();
648 // Reset the embedded images buffer.
649 logicalModel->ClearEmbeddedImages();
651 // Reset the anchors buffer.
652 logicalModel->ClearAnchors();
654 // We have cleared everything including the placeholder-text
655 impl.PlaceholderCleared();
657 impl.mTextUpdateInfo.mCharacterIndex = 0u;
658 impl.mTextUpdateInfo.mNumberOfCharactersToRemove = impl.mTextUpdateInfo.mPreviousNumberOfCharacters;
659 impl.mTextUpdateInfo.mNumberOfCharactersToAdd = 0u;
661 // Clear any previous text.
662 impl.mTextUpdateInfo.mClearAll = true;
664 // The natural size needs to be re-calculated.
665 impl.mRecalculateNaturalSize = true;
667 // The text direction needs to be updated.
668 impl.mUpdateTextDirection = true;
670 // Apply modifications to the model
671 impl.mOperationsPending = ALL_OPERATIONS;
674 void Controller::TextUpdater::InsertTextAnchor(Controller& controller, int numberOfCharacters, CharacterIndex previousCursorIndex)
676 Controller::Impl& impl = *controller.mImpl;
677 ModelPtr& model = impl.mModel;
678 LogicalModelPtr& logicalModel = model->mLogicalModel;
680 for(auto& anchor : logicalModel->mAnchors)
682 if(anchor.endIndex < previousCursorIndex) // [anchor] CUR
686 if(anchor.startIndex < previousCursorIndex) // [anCURr]
688 anchor.endIndex += numberOfCharacters;
692 anchor.startIndex += numberOfCharacters;
693 anchor.endIndex += numberOfCharacters;
695 DALI_LOG_INFO(gLogFilter, Debug::General, "Controller::InsertTextAnchor[%p] Anchor[%s] start[%d] end[%d]\n", &controller, anchor.href, anchor.startIndex, anchor.endIndex);
699 void Controller::TextUpdater::RemoveTextAnchor(Controller& controller, int cursorOffset, int numberOfCharacters, CharacterIndex previousCursorIndex)
701 Controller::Impl& impl = *controller.mImpl;
702 ModelPtr& model = impl.mModel;
703 LogicalModelPtr& logicalModel = model->mLogicalModel;
704 Vector<Anchor>::Iterator it = logicalModel->mAnchors.Begin();
706 while(it != logicalModel->mAnchors.End())
708 Anchor& anchor = *it;
710 if(anchor.endIndex <= previousCursorIndex && cursorOffset == 0) // [anchor] CUR >>
714 else if(anchor.endIndex <= previousCursorIndex && cursorOffset == -1) // [anchor] << CUR
716 int endIndex = anchor.endIndex;
717 int offset = previousCursorIndex - endIndex;
718 int index = endIndex - (numberOfCharacters - offset);
725 if((int)anchor.startIndex >= endIndex)
729 delete[] anchor.href;
731 it = logicalModel->mAnchors.Erase(it);
736 anchor.endIndex = endIndex;
739 else if(anchor.startIndex >= previousCursorIndex && cursorOffset == -1) // << CUR [anchor]
741 anchor.startIndex -= numberOfCharacters;
742 anchor.endIndex -= numberOfCharacters;
744 else if(anchor.startIndex >= previousCursorIndex && cursorOffset == 0) // CUR >> [anchor]
746 int startIndex = anchor.startIndex;
747 int endIndex = anchor.endIndex;
748 int index = previousCursorIndex + numberOfCharacters - 1;
750 if(startIndex > index)
752 anchor.startIndex -= numberOfCharacters;
753 anchor.endIndex -= numberOfCharacters;
755 else if(endIndex > index + 1)
757 anchor.endIndex -= numberOfCharacters;
763 delete[] anchor.href;
765 it = logicalModel->mAnchors.Erase(it);
769 else if(cursorOffset == -1) // [<< CUR]
771 int startIndex = anchor.startIndex;
772 int index = previousCursorIndex - numberOfCharacters;
774 if(startIndex >= index)
776 anchor.startIndex = index;
778 anchor.endIndex -= numberOfCharacters;
780 else if(cursorOffset == 0) // [CUR >>]
782 anchor.endIndex -= numberOfCharacters;
786 // When this condition is reached, someting is wrong.
787 DALI_LOG_ERROR("Controller::RemoveTextAnchor[%p] Invaild state cursorOffset[%d]\n", &controller, cursorOffset);
790 DALI_LOG_INFO(gLogFilter, Debug::General, "Controller::RemoveTextAnchor[%p] Anchor[%s] start[%d] end[%d]\n", &controller, anchor.href, anchor.startIndex, anchor.endIndex);
798 } // namespace Toolkit