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 controller.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 impl.ChangeState(EventData::EDITING);
78 ModelPtr& model = impl.mModel;
79 LogicalModelPtr& logicalModel = model->mLogicalModel;
80 model->mVisualModel->SetTextColor(impl.mTextColor);
82 MarkupProcessData markupProcessData(logicalModel->mColorRuns,
83 logicalModel->mFontDescriptionRuns,
84 logicalModel->mEmbeddedItems,
85 logicalModel->mAnchors,
86 logicalModel->mUnderlinedCharacterRuns,
87 logicalModel->mBackgroundColorRuns);
90 const uint8_t* utf8 = NULL;
91 if(impl.mMarkupProcessorEnabled)
93 ProcessMarkupString(text, markupProcessData);
94 textSize = markupProcessData.markupProcessedText.size();
96 // This is a bit horrible but std::string returns a (signed) char*
97 utf8 = reinterpret_cast<const uint8_t*>(markupProcessData.markupProcessedText.c_str());
101 textSize = text.size();
103 // This is a bit horrible but std::string returns a (signed) char*
104 utf8 = reinterpret_cast<const uint8_t*>(text.c_str());
107 // Convert text into UTF-32
108 Vector<Character>& utf32Characters = logicalModel->mText;
109 utf32Characters.Resize(textSize);
111 // Transform a text array encoded in utf8 into an array encoded in utf32.
112 // It returns the actual number of characters.
113 Length characterCount = Utf8ToUtf32(utf8, textSize, utf32Characters.Begin());
114 utf32Characters.Resize(characterCount);
116 DALI_ASSERT_DEBUG(textSize >= characterCount && "Invalid UTF32 conversion length");
117 DALI_LOG_INFO(gLogFilter, Debug::Verbose, "Controller::SetText %p UTF8 size %d, UTF32 size %d\n", &controller, textSize, logicalModel->mText.Count());
119 // The characters to be added.
120 impl.mTextUpdateInfo.mNumberOfCharactersToAdd = logicalModel->mText.Count();
122 // To reset the cursor position
123 lastCursorIndex = characterCount;
125 // Update the rest of the model during size negotiation
126 impl.QueueModifyEvent(ModifyEvent::TEXT_REPLACED);
128 // The natural size needs to be re-calculated.
129 impl.mRecalculateNaturalSize = true;
131 // The text direction needs to be updated.
132 impl.mUpdateTextDirection = true;
134 // Apply modifications to the model
135 impl.mOperationsPending = ALL_OPERATIONS;
139 controller.ShowPlaceholderText();
142 unsigned int oldCursorPos = (nullptr != eventData ? eventData->mPrimaryCursorPosition : 0);
144 // Resets the cursor position.
145 controller.ResetCursorPosition(lastCursorIndex);
147 // Scrolls the text to make the cursor visible.
148 controller.ResetScrollPosition();
150 impl.RequestRelayout();
152 if(nullptr != eventData)
154 // Cancel previously queued events
155 eventData->mEventQueue.clear();
158 // Do this last since it provides callbacks into application code.
159 if(NULL != impl.mEditableControlInterface)
161 impl.mEditableControlInterface->CursorPositionChanged(oldCursorPos, lastCursorIndex);
162 impl.mEditableControlInterface->TextChanged(true);
166 void Controller::TextUpdater::InsertText(Controller& controller, const std::string& text, Controller::InsertType type)
168 Controller::Impl& impl = *controller.mImpl;
169 EventData*& eventData = impl.mEventData;
171 DALI_ASSERT_DEBUG(nullptr != eventData && "Unexpected InsertText")
173 if(NULL == eventData)
178 bool removedPrevious = false;
179 bool removedSelected = false;
180 bool maxLengthReached = false;
181 unsigned int oldCursorPos = eventData->mPrimaryCursorPosition;
183 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);
185 ModelPtr& model = impl.mModel;
186 LogicalModelPtr& logicalModel = model->mLogicalModel;
188 // TODO: At the moment the underline runs are only for pre-edit.
189 model->mVisualModel->mUnderlineRuns.Clear();
191 // Remove the previous InputMethodContext pre-edit.
192 if(eventData->mPreEditFlag && (0u != eventData->mPreEditLength))
194 removedPrevious = RemoveText(controller,
195 -static_cast<int>(eventData->mPrimaryCursorPosition - eventData->mPreEditStartPosition),
196 eventData->mPreEditLength,
197 DONT_UPDATE_INPUT_STYLE);
199 eventData->mPrimaryCursorPosition = eventData->mPreEditStartPosition;
200 eventData->mPreEditLength = 0u;
204 // Remove the previous Selection.
205 removedSelected = RemoveSelectedText(controller);
208 Vector<Character> utf32Characters;
209 Length characterCount = 0u;
213 // Convert text into UTF-32
214 utf32Characters.Resize(text.size());
216 // This is a bit horrible but std::string returns a (signed) char*
217 const uint8_t* utf8 = reinterpret_cast<const uint8_t*>(text.c_str());
219 // Transform a text array encoded in utf8 into an array encoded in utf32.
220 // It returns the actual number of characters.
221 characterCount = Utf8ToUtf32(utf8, text.size(), utf32Characters.Begin());
222 utf32Characters.Resize(characterCount);
224 DALI_ASSERT_DEBUG(text.size() >= utf32Characters.Count() && "Invalid UTF32 conversion length");
225 DALI_LOG_INFO(gLogFilter, Debug::Verbose, "UTF8 size %d, UTF32 size %d\n", text.size(), utf32Characters.Count());
228 if(0u != utf32Characters.Count()) // Check if Utf8ToUtf32 conversion succeeded
230 // The placeholder text is no longer needed
231 if(impl.IsShowingPlaceholderText())
233 ResetText(controller);
236 impl.ChangeState(EventData::EDITING);
238 // Handle the InputMethodContext (predicitive text) state changes
241 // InputMethodContext is no longer handling key-events
242 impl.ClearPreEditFlag();
246 if(!eventData->mPreEditFlag)
248 DALI_LOG_INFO(gLogFilter, Debug::Verbose, "Entered PreEdit state\n");
250 // Record the start of the pre-edit text
251 eventData->mPreEditStartPosition = eventData->mPrimaryCursorPosition;
254 eventData->mPreEditLength = utf32Characters.Count();
255 eventData->mPreEditFlag = true;
257 DALI_LOG_INFO(gLogFilter, Debug::Verbose, "mPreEditStartPosition %d mPreEditLength %d\n", eventData->mPreEditStartPosition, eventData->mPreEditLength);
260 const Length numberOfCharactersInModel = logicalModel->mText.Count();
262 // Restrict new text to fit within Maximum characters setting.
263 Length temp_length = (impl.mMaximumNumberOfCharacters > numberOfCharactersInModel ? impl.mMaximumNumberOfCharacters - numberOfCharactersInModel : 0);
264 Length maxSizeOfNewText = std::min(temp_length, characterCount);
265 maxLengthReached = (characterCount > maxSizeOfNewText);
267 // The cursor position.
268 CharacterIndex& cursorIndex = eventData->mPrimaryCursorPosition;
270 // Update the text's style.
272 // Updates the text style runs by adding characters.
273 logicalModel->UpdateTextStyleRuns(cursorIndex, maxSizeOfNewText);
275 // Get the character index from the cursor index.
276 const CharacterIndex styleIndex = (cursorIndex > 0u) ? cursorIndex - 1u : 0u;
278 // Retrieve the text's style for the given index.
280 impl.RetrieveDefaultInputStyle(style);
281 logicalModel->RetrieveStyle(styleIndex, style);
283 InputStyle& inputStyle = eventData->mInputStyle;
285 // Whether to add a new text color run.
286 const bool addColorRun = (style.textColor != inputStyle.textColor) && !inputStyle.isDefaultColor;
288 // Whether to add a new font run.
289 const bool addFontNameRun = (style.familyName != inputStyle.familyName) && inputStyle.isFamilyDefined;
290 const bool addFontWeightRun = (style.weight != inputStyle.weight) && inputStyle.isWeightDefined;
291 const bool addFontWidthRun = (style.width != inputStyle.width) && inputStyle.isWidthDefined;
292 const bool addFontSlantRun = (style.slant != inputStyle.slant) && inputStyle.isSlantDefined;
293 const bool addFontSizeRun = (style.size != inputStyle.size) && inputStyle.isSizeDefined;
298 const VectorBase::SizeType numberOfRuns = logicalModel->mColorRuns.Count();
299 logicalModel->mColorRuns.Resize(numberOfRuns + 1u);
301 ColorRun& colorRun = *(logicalModel->mColorRuns.Begin() + numberOfRuns);
302 colorRun.color = inputStyle.textColor;
303 colorRun.characterRun.characterIndex = cursorIndex;
304 colorRun.characterRun.numberOfCharacters = maxSizeOfNewText;
313 const VectorBase::SizeType numberOfRuns = logicalModel->mFontDescriptionRuns.Count();
314 logicalModel->mFontDescriptionRuns.Resize(numberOfRuns + 1u);
316 FontDescriptionRun& fontDescriptionRun = *(logicalModel->mFontDescriptionRuns.Begin() + numberOfRuns);
320 fontDescriptionRun.familyLength = inputStyle.familyName.size();
321 fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength];
322 memcpy(fontDescriptionRun.familyName, inputStyle.familyName.c_str(), fontDescriptionRun.familyLength);
323 fontDescriptionRun.familyDefined = true;
325 // The memory allocated for the font family name is freed when the font description is removed from the logical model.
330 fontDescriptionRun.weight = inputStyle.weight;
331 fontDescriptionRun.weightDefined = true;
336 fontDescriptionRun.width = inputStyle.width;
337 fontDescriptionRun.widthDefined = true;
342 fontDescriptionRun.slant = inputStyle.slant;
343 fontDescriptionRun.slantDefined = true;
348 fontDescriptionRun.size = static_cast<PointSize26Dot6>(inputStyle.size * impl.mFontSizeScale * 64.f);
349 fontDescriptionRun.sizeDefined = true;
352 fontDescriptionRun.characterRun.characterIndex = cursorIndex;
353 fontDescriptionRun.characterRun.numberOfCharacters = maxSizeOfNewText;
356 // Insert at current cursor position.
357 Vector<Character>& modifyText = logicalModel->mText;
359 auto pos = modifyText.End();
360 if(cursorIndex < numberOfCharactersInModel)
362 pos = modifyText.Begin() + cursorIndex;
364 unsigned int realPos = pos - modifyText.Begin();
365 modifyText.Insert(pos, utf32Characters.Begin(), utf32Characters.Begin() + maxSizeOfNewText);
367 if(NULL != impl.mEditableControlInterface)
369 impl.mEditableControlInterface->TextInserted(realPos, maxSizeOfNewText, text);
372 TextUpdateInfo& textUpdateInfo = impl.mTextUpdateInfo;
374 // Mark the first paragraph to be updated.
375 if(Layout::Engine::SINGLE_LINE_BOX == impl.mLayoutEngine.GetLayout())
377 textUpdateInfo.mCharacterIndex = 0;
378 textUpdateInfo.mNumberOfCharactersToRemove = textUpdateInfo.mPreviousNumberOfCharacters;
379 textUpdateInfo.mNumberOfCharactersToAdd = numberOfCharactersInModel + maxSizeOfNewText;
380 textUpdateInfo.mClearAll = true;
384 textUpdateInfo.mCharacterIndex = std::min(cursorIndex, textUpdateInfo.mCharacterIndex);
385 textUpdateInfo.mNumberOfCharactersToAdd += maxSizeOfNewText;
388 if(impl.mMarkupProcessorEnabled)
390 InsertTextAnchor(controller, maxSizeOfNewText, cursorIndex);
393 // Update the cursor index.
394 cursorIndex += maxSizeOfNewText;
396 DALI_LOG_INFO(gLogFilter, Debug::Verbose, "Inserted %d characters, new size %d new cursor %d\n", maxSizeOfNewText, logicalModel->mText.Count(), eventData->mPrimaryCursorPosition);
399 if((0u == logicalModel->mText.Count()) &&
400 impl.IsPlaceholderAvailable())
402 // Show place-holder if empty after removing the pre-edit text
403 controller.ShowPlaceholderText();
404 eventData->mUpdateCursorPosition = true;
405 impl.ClearPreEditFlag();
407 else if(removedPrevious ||
409 (0 != utf32Characters.Count()))
411 // Queue an inserted event
412 impl.QueueModifyEvent(ModifyEvent::TEXT_INSERTED);
414 eventData->mUpdateCursorPosition = true;
417 eventData->mScrollAfterDelete = true;
421 eventData->mScrollAfterUpdatePosition = true;
425 if(nullptr != impl.mEditableControlInterface)
427 impl.mEditableControlInterface->CursorPositionChanged(oldCursorPos, eventData->mPrimaryCursorPosition);
432 DALI_LOG_INFO(gLogFilter, Debug::Verbose, "MaxLengthReached (%d)\n", logicalModel->mText.Count());
434 impl.ResetInputMethodContext();
436 if(NULL != impl.mEditableControlInterface)
438 // Do this last since it provides callbacks into application code
439 impl.mEditableControlInterface->MaxLengthReached();
444 void Controller::TextUpdater::PasteText(Controller& controller, const std::string& stringToPaste)
446 InsertText(controller, stringToPaste, Text::Controller::COMMIT);
447 Controller::Impl& impl = *controller.mImpl;
448 impl.ChangeState(EventData::EDITING);
449 impl.RequestRelayout();
451 if(NULL != impl.mEditableControlInterface)
453 // Do this last since it provides callbacks into application code
454 impl.mEditableControlInterface->TextChanged(true);
458 bool Controller::TextUpdater::RemoveText(
459 Controller& controller,
461 int numberOfCharacters,
462 UpdateInputStyleType type)
464 bool removed = false;
466 Controller::Impl& impl = *controller.mImpl;
467 EventData*& eventData = impl.mEventData;
469 if(nullptr == eventData)
474 ModelPtr& model = impl.mModel;
475 LogicalModelPtr& logicalModel = model->mLogicalModel;
477 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);
479 if(!impl.IsShowingPlaceholderText())
481 // Delete at current cursor position
482 Vector<Character>& currentText = logicalModel->mText;
483 CharacterIndex& previousCursorIndex = eventData->mPrimaryCursorPosition;
485 CharacterIndex cursorIndex = 0;
487 // Validate the cursor position & number of characters
488 if((static_cast<int>(eventData->mPrimaryCursorPosition) + cursorOffset) >= 0)
490 cursorIndex = eventData->mPrimaryCursorPosition + cursorOffset;
493 if((cursorIndex + numberOfCharacters) > currentText.Count())
495 numberOfCharacters = currentText.Count() - cursorIndex;
498 TextUpdateInfo& textUpdateInfo = impl.mTextUpdateInfo;
500 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.
501 ((cursorIndex + numberOfCharacters) <= textUpdateInfo.mPreviousNumberOfCharacters))
503 // Mark the paragraphs to be updated.
504 if(Layout::Engine::SINGLE_LINE_BOX == impl.mLayoutEngine.GetLayout())
506 textUpdateInfo.mCharacterIndex = 0;
507 textUpdateInfo.mNumberOfCharactersToRemove = textUpdateInfo.mPreviousNumberOfCharacters;
508 textUpdateInfo.mNumberOfCharactersToAdd = textUpdateInfo.mPreviousNumberOfCharacters - numberOfCharacters;
509 textUpdateInfo.mClearAll = true;
513 textUpdateInfo.mCharacterIndex = std::min(cursorIndex, textUpdateInfo.mCharacterIndex);
514 textUpdateInfo.mNumberOfCharactersToRemove += numberOfCharacters;
517 // Update the input style and remove the text's style before removing the text.
519 if(UPDATE_INPUT_STYLE == type)
521 InputStyle& eventDataInputStyle = eventData->mInputStyle;
523 // Keep a copy of the current input style.
524 InputStyle currentInputStyle;
525 currentInputStyle.Copy(eventDataInputStyle);
527 // Set first the default input style.
528 impl.RetrieveDefaultInputStyle(eventDataInputStyle);
530 // Update the input style.
531 logicalModel->RetrieveStyle(cursorIndex, eventDataInputStyle);
533 // Compare if the input style has changed.
534 const bool hasInputStyleChanged = !currentInputStyle.Equal(eventDataInputStyle);
536 if(hasInputStyleChanged)
538 const InputStyle::Mask styleChangedMask = currentInputStyle.GetInputStyleChangeMask(eventDataInputStyle);
539 // Queue the input style changed signal.
540 eventData->mInputStyleChangedQueue.PushBack(styleChangedMask);
544 // If the number of current text and the number of characters to be deleted are same,
545 // it means all texts should be removed and all Preedit variables should be initialized.
546 if((currentText.Count() - numberOfCharacters == 0) && (cursorIndex == 0))
548 impl.ClearPreEditFlag();
549 textUpdateInfo.mNumberOfCharactersToAdd = 0;
552 // Updates the text style runs by removing characters. Runs with no characters are removed.
553 logicalModel->UpdateTextStyleRuns(cursorIndex, -numberOfCharacters);
555 // Remove the characters.
556 Vector<Character>::Iterator first = currentText.Begin() + cursorIndex;
557 Vector<Character>::Iterator last = first + numberOfCharacters;
559 if(NULL != impl.mEditableControlInterface)
562 Utf32ToUtf8(first, numberOfCharacters, utf8);
563 impl.mEditableControlInterface->TextDeleted(cursorIndex, numberOfCharacters, utf8);
566 currentText.Erase(first, last);
568 if(impl.mMarkupProcessorEnabled)
570 RemoveTextAnchor(controller, cursorOffset, numberOfCharacters, previousCursorIndex);
573 if(nullptr != impl.mEditableControlInterface)
575 impl.mEditableControlInterface->CursorPositionChanged(previousCursorIndex, cursorIndex);
578 // Cursor position retreat
579 previousCursorIndex = cursorIndex;
581 eventData->mScrollAfterDelete = true;
583 if(EventData::INACTIVE == eventData->mState)
585 impl.ChangeState(EventData::EDITING);
588 DALI_LOG_INFO(gLogFilter, Debug::General, "Controller::RemoveText %p removed %d\n", &controller, numberOfCharacters);
596 bool Controller::TextUpdater::RemoveSelectedText(Controller& controller)
598 bool textRemoved(false);
600 Controller::Impl& impl = *controller.mImpl;
602 if(EventData::SELECTING == impl.mEventData->mState)
604 std::string removedString;
605 impl.RetrieveSelection(removedString, true);
607 if(!removedString.empty())
610 impl.ChangeState(EventData::EDITING);
612 if(impl.mMarkupProcessorEnabled)
614 int cursorOffset = -1;
615 int numberOfCharacters = removedString.length();
616 CharacterIndex& cursorIndex = impl.mEventData->mPrimaryCursorPosition;
617 CharacterIndex previousCursorIndex = cursorIndex + numberOfCharacters;
619 RemoveTextAnchor(controller, cursorOffset, numberOfCharacters, previousCursorIndex);
627 void Controller::TextUpdater::ResetText(Controller& controller)
629 Controller::Impl& impl = *controller.mImpl;
630 LogicalModelPtr& logicalModel = impl.mModel->mLogicalModel;
633 logicalModel->mText.Clear();
635 // Reset the embedded images buffer.
636 logicalModel->ClearEmbeddedImages();
638 // Reset the anchors buffer.
639 logicalModel->ClearAnchors();
641 // We have cleared everything including the placeholder-text
642 impl.PlaceholderCleared();
644 impl.mTextUpdateInfo.mCharacterIndex = 0u;
645 impl.mTextUpdateInfo.mNumberOfCharactersToRemove = impl.mTextUpdateInfo.mPreviousNumberOfCharacters;
646 impl.mTextUpdateInfo.mNumberOfCharactersToAdd = 0u;
648 // Clear any previous text.
649 impl.mTextUpdateInfo.mClearAll = true;
651 // The natural size needs to be re-calculated.
652 impl.mRecalculateNaturalSize = true;
654 // The text direction needs to be updated.
655 impl.mUpdateTextDirection = true;
657 // Apply modifications to the model
658 impl.mOperationsPending = ALL_OPERATIONS;
661 void Controller::TextUpdater::InsertTextAnchor(Controller& controller, int numberOfCharacters, CharacterIndex previousCursorIndex)
663 Controller::Impl& impl = *controller.mImpl;
664 ModelPtr& model = impl.mModel;
665 LogicalModelPtr& logicalModel = model->mLogicalModel;
667 for(auto& anchor : logicalModel->mAnchors)
669 if(anchor.endIndex < previousCursorIndex) // [anchor] CUR
673 if(anchor.startIndex < previousCursorIndex) // [anCURr]
675 anchor.endIndex += numberOfCharacters;
679 anchor.startIndex += numberOfCharacters;
680 anchor.endIndex += numberOfCharacters;
682 DALI_LOG_INFO(gLogFilter, Debug::General, "Controller::InsertTextAnchor[%p] Anchor[%s] start[%d] end[%d]\n", &controller, anchor.href, anchor.startIndex, anchor.endIndex);
686 void Controller::TextUpdater::RemoveTextAnchor(Controller& controller, int cursorOffset, int numberOfCharacters, CharacterIndex previousCursorIndex)
688 Controller::Impl& impl = *controller.mImpl;
689 ModelPtr& model = impl.mModel;
690 LogicalModelPtr& logicalModel = model->mLogicalModel;
691 Vector<Anchor>::Iterator it = logicalModel->mAnchors.Begin();
693 while(it != logicalModel->mAnchors.End())
695 Anchor& anchor = *it;
697 if(anchor.endIndex <= previousCursorIndex && cursorOffset == 0) // [anchor] CUR >>
701 else if(anchor.endIndex <= previousCursorIndex && cursorOffset == -1) // [anchor] << CUR
703 int endIndex = anchor.endIndex;
704 int offset = previousCursorIndex - endIndex;
705 int index = endIndex - (numberOfCharacters - offset);
712 if((int)anchor.startIndex >= endIndex)
716 delete[] anchor.href;
718 it = logicalModel->mAnchors.Erase(it);
723 anchor.endIndex = endIndex;
726 else if(anchor.startIndex >= previousCursorIndex && cursorOffset == -1) // << CUR [anchor]
728 anchor.startIndex -= numberOfCharacters;
729 anchor.endIndex -= numberOfCharacters;
731 else if(anchor.startIndex >= previousCursorIndex && cursorOffset == 0) // CUR >> [anchor]
733 int startIndex = anchor.startIndex;
734 int endIndex = anchor.endIndex;
735 int index = previousCursorIndex + numberOfCharacters - 1;
737 if(startIndex > index)
739 anchor.startIndex -= numberOfCharacters;
740 anchor.endIndex -= numberOfCharacters;
742 else if(endIndex > index + 1)
744 anchor.endIndex -= numberOfCharacters;
750 delete[] anchor.href;
752 it = logicalModel->mAnchors.Erase(it);
756 else if(cursorOffset == -1) // [<< CUR]
758 int startIndex = anchor.startIndex;
759 int index = previousCursorIndex - numberOfCharacters;
761 if(startIndex >= index)
763 anchor.startIndex = index;
765 anchor.endIndex -= numberOfCharacters;
767 else if(cursorOffset == 0) // [CUR >>]
769 anchor.endIndex -= numberOfCharacters;
773 // When this condition is reached, someting is wrong.
774 DALI_LOG_ERROR("Controller::RemoveTextAnchor[%p] Invaild state cursorOffset[%d]\n", &controller, cursorOffset);
777 DALI_LOG_INFO(gLogFilter, Debug::General, "Controller::RemoveTextAnchor[%p] Anchor[%s] start[%d] end[%d]\n", &controller, anchor.href, anchor.startIndex, anchor.endIndex);
785 } // namespace Toolkit