X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Ftext%2Ftext-controller-impl.h;h=5e28f9c4f6fdf6a7539a51f0cb5b8a136fef5c74;hp=9f637d33f1c0b7b5c92a04344f0462c254568e0d;hb=faef4e5740c0024bf3041182a799a2d2395c8787;hpb=9161d9828d1a5bb3c7eaf83002863de84b23b751 diff --git a/dali-toolkit/internal/text/text-controller-impl.h b/dali-toolkit/internal/text/text-controller-impl.h index 9f637d3..5e28f9c 100644 --- a/dali-toolkit/internal/text/text-controller-impl.h +++ b/dali-toolkit/internal/text/text-controller-impl.h @@ -2,7 +2,7 @@ #define DALI_TOOLKIT_TEXT_CONTROLLER_IMPL_H /* - * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * Copyright (c) 2022 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -37,15 +37,17 @@ namespace Toolkit { namespace Text { -const float DEFAULT_TEXTFIT_MIN = 10.f; -const float DEFAULT_TEXTFIT_MAX = 100.f; -const float DEFAULT_TEXTFIT_STEP = 1.f; -const float DEFAULT_FONT_SIZE_SCALE = 1.f; +const float DEFAULT_TEXTFIT_MIN = 10.f; +const float DEFAULT_TEXTFIT_MAX = 100.f; +const float DEFAULT_TEXTFIT_STEP = 1.f; +const float DEFAULT_FONT_SIZE_SCALE = 1.f; +const float DEFAULT_DISABLED_COLOR_OPACITY = 0.3f; //Forward declarations struct CursorInfo; struct FontDefaults; struct ControllerImplEventHandler; +struct ControllerImplModelUpdater; struct SelectionHandleController; class SelectableControlInterface; @@ -66,6 +68,7 @@ struct Event SELECT, SELECT_ALL, SELECT_NONE, + SELECT_RANGE, }; union Param @@ -115,12 +118,12 @@ struct EventData return (stateToCheck == EDITING || stateToCheck == EDITING_WITH_POPUP || stateToCheck == EDITING_WITH_GRAB_HANDLE || stateToCheck == EDITING_WITH_PASTE_POPUP); } - DecoratorPtr mDecorator; ///< Pointer to the decorator. - InputMethodContext mInputMethodContext; ///< The Input Method Framework Manager. - FontDefaults* mPlaceholderFont; ///< The placeholder default font. - std::string mPlaceholderTextActive; ///< The text to display when the TextField is empty with key-input focus. - std::string mPlaceholderTextInactive; ///< The text to display when the TextField is empty and inactive. - Vector4 mPlaceholderTextColor; ///< The in/active placeholder text color. + DecoratorPtr mDecorator; ///< Pointer to the decorator. + InputMethodContext mInputMethodContext; ///< The Input Method Framework Manager. + std::unique_ptr mPlaceholderFont; ///< The placeholder default font. + std::string mPlaceholderTextActive; ///< The text to display when the TextField is empty with key-input focus. + std::string mPlaceholderTextInactive; ///< The text to display when the TextField is empty and inactive. + Vector4 mPlaceholderTextColor; ///< The in/active placeholder text color. /** * This is used to delay handling events until after the model has been updated. @@ -338,6 +341,7 @@ struct Controller::Impl mOperationsPending(NO_OPERATION), mMaximumNumberOfCharacters(50u), mHiddenInput(NULL), + mInputFilter(nullptr), mRecalculateNaturalSize(true), mMarkupProcessorEnabled(false), mClipboardHideEnabled(true), @@ -348,13 +352,19 @@ struct Controller::Impl mShadowSetByString(false), mOutlineSetByString(false), mFontStyleSetByString(false), + mStrikethroughSetByString(false), mShouldClearFocusOnEscape(true), mLayoutDirection(LayoutDirection::LEFT_TO_RIGHT), mTextFitMinSize(DEFAULT_TEXTFIT_MIN), mTextFitMaxSize(DEFAULT_TEXTFIT_MAX), mTextFitStepSize(DEFAULT_TEXTFIT_STEP), + mFontSizeScale(DEFAULT_FONT_SIZE_SCALE), + mDisabledColorOpacity(DEFAULT_DISABLED_COLOR_OPACITY), + mFontSizeScaleEnabled(true), mTextFitEnabled(false), - mFontSizeScale(DEFAULT_FONT_SIZE_SCALE) + mTextFitChanged(false), + mIsLayoutDirectionChanged(false), + mIsUserInteractionEnabled(true) { mModel = Model::New(); @@ -362,6 +372,7 @@ struct Controller::Impl mClipboard = Clipboard::Get(); mView.SetVisualModel(mModel->mVisualModel); + mView.SetLogicalModel(mModel->mLogicalModel); // Use this to access FontClient i.e. to get down-scaled Emoji metrics. mMetrics = Metrics::New(mFontClient); @@ -374,19 +385,17 @@ struct Controller::Impl Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get(); if(styleManager) { - bool temp; - Property::Map config = Toolkit::DevelStyleManager::GetConfigurations(styleManager); - if(config["clearFocusOnEscape"].Get(temp)) - { - mShouldClearFocusOnEscape = temp; - } + const Property::Map& config = Toolkit::DevelStyleManager::GetConfigurations(styleManager); + const auto clearFocusOnEscapeValue = config.Find("clearFocusOnEscape", Property::Type::BOOLEAN); + + // Default is true. If config don't have "clearFocusOnEscape" property, make it true. + mShouldClearFocusOnEscape = (!clearFocusOnEscapeValue || clearFocusOnEscapeValue->Get()); } } ~Impl() { delete mHiddenInput; - delete mFontDefaults; delete mUnderlineDefaults; delete mShadowDefaults; @@ -493,6 +502,11 @@ struct Controller::Impl } } + float GetFontSizeScale() + { + return mFontSizeScaleEnabled ? mFontSizeScale : 1.0f; + } + /** * @brief Helper to notify InputMethodContext with surrounding text & cursor changes. */ @@ -520,6 +534,13 @@ struct Controller::Impl Length GetNumberOfWhiteSpaces(CharacterIndex index) const; /** + * @brief Retrieve any text previously set. + * + * @param[out] text A string of UTF-8 characters. + */ + void GetText(std::string& text) const; + + /** * @brief Retrieve any text previously set starting from the given @p index. * * @param[in] index The character index from where to retrieve the text. @@ -542,42 +563,23 @@ struct Controller::Impl } /** - * @brief Calculates the start character index of the first paragraph to be updated and - * the end character index of the last paragraph to be updated. - * - * @param[out] numberOfCharacters The number of characters to be updated. - */ - void CalculateTextUpdateIndices(Length& numberOfCharacters); - - /** - * @brief Helper to clear completely the parts of the model specified by the given @p operations. - * - * @note It never clears the text stored in utf32. + * @copydoc Controller::GetLayoutDirection() */ - void ClearFullModelData(OperationsMask operations); + Dali::LayoutDirection::Type GetLayoutDirection(Dali::Actor& actor) const; /** - * @brief Helper to clear completely the parts of the model related with the characters specified by the given @p operations. - * - * @note It never clears the text stored in utf32. - * - * @param[in] startIndex Index to the first character to be cleared. - * @param[in] endIndex Index to the last character to be cleared. - * @param[in] operations The operations required. + * @brief Checks text direction. + * @return The text direction. */ - void ClearCharacterModelData(CharacterIndex startIndex, CharacterIndex endIndex, OperationsMask operations); + Toolkit::DevelText::TextDirection::Type GetTextDirection(); /** - * @brief Helper to clear completely the parts of the model related with the glyphs specified by the given @p operations. - * - * @note It never clears the text stored in utf32. - * @note Character indices are transformed to glyph indices. + * @brief Calculates the start character index of the first paragraph to be updated and + * the end character index of the last paragraph to be updated. * - * @param[in] startIndex Index to the first character to be cleared. - * @param[in] endIndex Index to the last character to be cleared. - * @param[in] operations The operations required. + * @param[out] numberOfCharacters The number of characters to be updated. */ - void ClearGlyphModelData(CharacterIndex startIndex, CharacterIndex endIndex, OperationsMask operations); + void CalculateTextUpdateIndices(Length& numberOfCharacters); /** * @brief Helper to clear the parts of the model specified by the given @p operations and from @p startIndex to @p endIndex. @@ -617,6 +619,26 @@ struct Controller::Impl float GetDefaultFontLineHeight(); /** + * @copydoc Controller::SetDefaultLineSpacing + */ + bool SetDefaultLineSpacing(float lineSpacing); + + /** + * @copydoc Controller::SetDefaultLineSize + */ + bool SetDefaultLineSize(float lineSize); + + /** + * @copydoc Controller::SetRelativeLineSize + */ + bool SetRelativeLineSize(float relativeLineSize); + + /** + * @copydoc Controller::GetRelativeLineSize + */ + float GetRelativeLineSize(); + + /** * @copydoc Text::Controller::GetPrimaryCursorPosition() */ CharacterIndex GetPrimaryCursorPosition() const; @@ -624,7 +646,22 @@ struct Controller::Impl /** * @copydoc Text::Controller::SetPrimaryCursorPosition() */ - bool SetPrimaryCursorPosition(CharacterIndex index); + bool SetPrimaryCursorPosition(CharacterIndex index, bool focused); + + /** + * @copydoc Text::SelectableControlInterface::GetSelectedText() + */ + string GetSelectedText(); + + /** + * @copydoc Text::EditableControlInterface::CopyText() + */ + string CopyText(); + + /** + * @copydoc Text::EditableControlInterface::CutText() + */ + string CutText(); /** * @copydoc Text::SelectableControlInterface::SetTextSelectionRange() @@ -647,6 +684,11 @@ struct Controller::Impl void SetEditable(bool editable); /** + * @copydoc Controller::UpdateAfterFontChange + */ + void UpdateAfterFontChange(const std::string& newDefaultFont); + + /** * @brief Retrieves the selected text. It removes the text if the @p deleteAfterRetrieval parameter is @e true. * * @param[out] selectedText The selected text encoded in utf8. @@ -768,6 +810,134 @@ struct Controller::Impl */ Actor CreateBackgroundActor(); + /** + * @brief fill needed relayout parameters whenever a property is changed and a re-layout is needed for the entire text. + */ + void RelayoutAllCharacters(); + + /** + * @copydoc Controller::IsInputStyleChangedSignalsQueueEmpty + */ + bool IsInputStyleChangedSignalsQueueEmpty(); + + /** + * @copydoc Controller::ProcessInputStyleChangedSignals + */ + void ProcessInputStyleChangedSignals(); + + /** + * @copydoc Controller::ScrollBy() + */ + void ScrollBy(Vector2 scroll); + + /** + * @copydoc Controller::GetHorizontalScrollPosition() + */ + float GetHorizontalScrollPosition(); + + /** + * @copydoc Controller::GetVerticalScrollPosition() + */ + float GetVerticalScrollPosition(); + + /** + * @copydoc Controller::SetAutoScrollEnabled() + */ + void SetAutoScrollEnabled(bool enable); + + /** + * @copydoc Controller::SetEnableCursorBlink() + */ + void SetEnableCursorBlink(bool enable); + + /** + * @copydoc Controller::SetMultiLineEnabled() + */ + void SetMultiLineEnabled(bool enable); + + /** + * @copydoc Controller::SetHorizontalAlignment() + */ + void SetHorizontalAlignment(HorizontalAlignment::Type alignment); + + /** + * @copydoc Controller::SetVerticalAlignment() + */ + void SetVerticalAlignment(VerticalAlignment::Type alignment); + + /** + * @copydoc Controller::SetLineWrapMode() + */ + void SetLineWrapMode(Text::LineWrap::Mode textWarpMode); + + /** + * @copydoc Controller::SetDefaultColor() + */ + void SetDefaultColor(const Vector4& color); + + /** + * @copydoc Controller::SetUserInteractionEnabled() + */ + void SetUserInteractionEnabled(bool enabled); + + /** + * @brief Helper to clear font-specific data (only). + */ + void ClearFontData(); + + /** + * @brief Helper to clear text's style data. + */ + void ClearStyleData(); + + /** + * @brief Used to reset the scroll position after setting a new text. + */ + void ResetScrollPosition(); + + /** + * @brief Resets a provided vector with actors that marks the position of anchors in markup enabled text + * + * @param[out] anchorActors the vector of actor (empty collection if no anchors available). + */ + void GetAnchorActors(std::vector& anchorActors); + + /** + * @brief Return an index of first anchor in the anchor vector whose boundaries includes given character offset + * + * @param[in] characterOffset A position in text coords. + * + * @return the 0-based index in anchor vector (-1 if an anchor not found) + */ + int32_t GetAnchorIndex(size_t characterOffset) const; + + /** + * @brief Return the geometrical position of an anchor relative to the parent origin point. + * + * @param[in] anchor An anchor. + * + * @return The x, y, z coordinates of an anchor. + */ + Vector3 GetAnchorPosition(Anchor anchor) const; + + /** + * @brief Return the size of an anchor expresed as a vector containing anchor's width and height. + * + * @param[in] anchor An anchor. + * + * @return The width and height of an anchor. + */ + Vector2 GetAnchorSize(Anchor anchor) const; + + /** + * @brief Return the actor representing an anchor. + * + * @param[in] anchor An anchor. + * + * @return The actor representing an anchor. + */ + Toolkit::TextAnchor CreateAnchorActor(Anchor anchor); + public: /** * @brief Gets implementation from the controller handle. @@ -792,30 +962,43 @@ private: */ void CopyUnderlinedFromLogicalToVisualModels(bool shouldClearPreUnderlineRuns); + /** + * @brief Copy strikethrough-Character-Runs from Logical-Model to strikethrough-Glyph-Runs in Visual-Model + * + */ + void CopyStrikethroughFromLogicalToVisualModels(); + + /** + * @brief Copy CharacterSpacing-Character-Runs from Logical-Model to CharacterSpacing-Glyph-Runs in Visual-Model + * + */ + void CopyCharacterSpacingFromLogicalToVisualModels(); + public: - ControlInterface* mControlInterface; ///< Reference to the text controller. - EditableControlInterface* mEditableControlInterface; ///< Reference to the editable text controller. - SelectableControlInterface* mSelectableControlInterface; ///< Reference to the selectable text controller. - AnchorControlInterface* mAnchorControlInterface; ///< Reference to the anchor controller. - ModelPtr mModel; ///< Pointer to the text's model. - FontDefaults* mFontDefaults; ///< Avoid allocating this when the user does not specify a font. - UnderlineDefaults* mUnderlineDefaults; ///< Avoid allocating this when the user does not specify underline parameters. - ShadowDefaults* mShadowDefaults; ///< Avoid allocating this when the user does not specify shadow parameters. - EmbossDefaults* mEmbossDefaults; ///< Avoid allocating this when the user does not specify emboss parameters. - OutlineDefaults* mOutlineDefaults; ///< Avoid allocating this when the user does not specify outline parameters. - EventData* mEventData; ///< Avoid allocating everything for text input until EnableTextInput(). - TextAbstraction::FontClient mFontClient; ///< Handle to the font client. - Clipboard mClipboard; ///< Handle to the system clipboard - View mView; ///< The view interface to the rendering back-end. - MetricsPtr mMetrics; ///< A wrapper around FontClient used to get metrics & potentially down-scaled Emoji metrics. - Layout::Engine mLayoutEngine; ///< The layout engine. - Vector mModifyEvents; ///< Temporary stores the text set until the next relayout. - Vector4 mTextColor; ///< The regular text color - TextUpdateInfo mTextUpdateInfo; ///< Info of the characters updated. - OperationsMask mOperationsPending; ///< Operations pending to be done to layout the text. - Length mMaximumNumberOfCharacters; ///< Maximum number of characters that can be inserted. - HiddenText* mHiddenInput; ///< Avoid allocating this when the user does not specify hidden input mode. - Vector2 mTextFitContentSize; ///< Size of Text fit content + ControlInterface* mControlInterface; ///< Reference to the text controller. + EditableControlInterface* mEditableControlInterface; ///< Reference to the editable text controller. + SelectableControlInterface* mSelectableControlInterface; ///< Reference to the selectable text controller. + AnchorControlInterface* mAnchorControlInterface; ///< Reference to the anchor controller. + ModelPtr mModel; ///< Pointer to the text's model. + FontDefaults* mFontDefaults; ///< Avoid allocating this when the user does not specify a font. + UnderlineDefaults* mUnderlineDefaults; ///< Avoid allocating this when the user does not specify underline parameters. + ShadowDefaults* mShadowDefaults; ///< Avoid allocating this when the user does not specify shadow parameters. + EmbossDefaults* mEmbossDefaults; ///< Avoid allocating this when the user does not specify emboss parameters. + OutlineDefaults* mOutlineDefaults; ///< Avoid allocating this when the user does not specify outline parameters. + EventData* mEventData; ///< Avoid allocating everything for text input until EnableTextInput(). + TextAbstraction::FontClient mFontClient; ///< Handle to the font client. + Clipboard mClipboard; ///< Handle to the system clipboard + View mView; ///< The view interface to the rendering back-end. + MetricsPtr mMetrics; ///< A wrapper around FontClient used to get metrics & potentially down-scaled Emoji metrics. + Layout::Engine mLayoutEngine; ///< The layout engine. + Vector mModifyEvents; ///< Temporary stores the text set until the next relayout. + Vector4 mTextColor; ///< The regular text color + TextUpdateInfo mTextUpdateInfo; ///< Info of the characters updated. + OperationsMask mOperationsPending; ///< Operations pending to be done to layout the text. + Length mMaximumNumberOfCharacters; ///< Maximum number of characters that can be inserted. + HiddenText* mHiddenInput; ///< Avoid allocating this when the user does not specify hidden input mode. + std::unique_ptr mInputFilter; ///< Avoid allocating this when the user does not specify input filter mode. + Vector2 mTextFitContentSize; ///< Size of Text fit content bool mRecalculateNaturalSize : 1; ///< Whether the natural size needs to be recalculated. bool mMarkupProcessorEnabled : 1; ///< Whether the mark-up procesor is enabled. @@ -828,19 +1011,26 @@ public: bool mShadowSetByString : 1; ///< Set when shadow is set by string (legacy) instead of map bool mOutlineSetByString : 1; ///< Set when outline is set by string (legacy) instead of map bool mFontStyleSetByString : 1; ///< Set when font style is set by string (legacy) instead of map + bool mStrikethroughSetByString : 1; ///< Set when strikethrough is set by string (legacy) instead of map bool mShouldClearFocusOnEscape : 1; ///< Whether text control should clear key input focus LayoutDirection::Type mLayoutDirection; ///< Current system language direction Shader mShaderBackground; ///< The shader for text background. - float mTextFitMinSize; ///< Minimum Font Size for text fit. Default 10 - float mTextFitMaxSize; ///< Maximum Font Size for text fit. Default 100 - float mTextFitStepSize; ///< Step Size for font intervalse. Default 1 - bool mTextFitEnabled : 1; ///< Whether the text's fit is enabled. - float mFontSizeScale; ///< Scale value for Font Size. Default 1.0 + float mTextFitMinSize; ///< Minimum Font Size for text fit. Default 10 + float mTextFitMaxSize; ///< Maximum Font Size for text fit. Default 100 + float mTextFitStepSize; ///< Step Size for font intervalse. Default 1 + float mFontSizeScale; ///< Scale value for Font Size. Default 1.0 + float mDisabledColorOpacity; ///< Color opacity when disabled. + bool mFontSizeScaleEnabled : 1; ///< Whether the font size scale is enabled. + bool mTextFitEnabled : 1; ///< Whether the text's fit is enabled. + bool mTextFitChanged : 1; ///< Whether the text fit property has changed. + bool mIsLayoutDirectionChanged : 1; ///< Whether the layout has changed. + bool mIsUserInteractionEnabled : 1; ///< Whether the user interaction is enabled. private: friend ControllerImplEventHandler; + friend ControllerImplModelUpdater; friend SelectionHandleController; };