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.h;h=0def96f506209db46a1be3287f06f5187e4ebc13;hp=aaa3a66de5c27e846ab77faaf6db13da549441ac;hb=c427acac5f2616578c05987c99e7b430c9ab0137;hpb=c857a82d2a092fe17e654baf70afd454143310de diff --git a/dali-toolkit/internal/text/text-controller.h b/dali-toolkit/internal/text/text-controller.h index aaa3a66..0def96f 100644 --- a/dali-toolkit/internal/text/text-controller.h +++ b/dali-toolkit/internal/text/text-controller.h @@ -2,7 +2,7 @@ #define DALI_TOOLKIT_TEXT_CONTROLLER_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. @@ -23,22 +23,20 @@ #include // INTERNAL INCLUDES +#include #include #include #include #include #include +#include #include #include #include #include #include -namespace Dali -{ -namespace Toolkit -{ -namespace Text +namespace Dali::Toolkit::Text { class Controller; class ControlInterface; @@ -51,9 +49,10 @@ class RenderingController; */ enum SelectionType { - INTERACTIVE = 0x0000, - ALL = 0x0001, - NONE = 0x0002 + INTERACTIVE = 0x0000, ///< Select the word where the cursor is located. + ALL = 0x0001, ///< Select the whole text. + NONE = 0x0002, ///< Unselect the whole text. + RANGE = 0x0003 ///< Select the range text. }; typedef IntrusivePtr ControllerPtr; @@ -168,7 +167,10 @@ public: // Constructor. * * @return A pointer to a new Controller. */ - static ControllerPtr New(); + static ControllerPtr New() + { + return ControllerPtr(new Controller()); + } /** * @brief Create a new instance of a Controller. @@ -177,7 +179,10 @@ public: // Constructor. * * @return A pointer to a new Controller. */ - static ControllerPtr New(ControlInterface* controlInterface); + static ControllerPtr New(ControlInterface* controlInterface) + { + return ControllerPtr(new Controller(controlInterface)); + } /** * @brief Create a new instance of a Controller. @@ -192,7 +197,13 @@ public: // Constructor. static ControllerPtr New(ControlInterface* controlInterface, EditableControlInterface* editableControlInterface, SelectableControlInterface* selectableControlInterface, - AnchorControlInterface* anchorControlInterface); + AnchorControlInterface* anchorControlInterface) + { + return ControllerPtr(new Controller(controlInterface, + editableControlInterface, + selectableControlInterface, + anchorControlInterface)); + } public: // Configure the text controller. /** @@ -230,6 +241,13 @@ public: // Configure the text controller. bool IsMarkupProcessorEnabled() const; /** + * @brief Retrieves whether the current text contains anchors. + * + * @return @e true if the current text contains anchors. @e false. + */ + bool HasAnchors() const; + + /** * @brief Enables/disables the auto text scrolling * * By default is disabled. @@ -239,6 +257,15 @@ public: // Configure the text controller. void SetAutoScrollEnabled(bool enable); /** + * @brief Whether the auto scrolling texture exceed max texture. + * + * By default is false. + * + * @param[in] exceed Whether the auto scrolling texture exceed max texture. + */ + void SetAutoScrollMaxTextureExceeded(bool exceed); + + /** * @brief Retrieves whether auto text scrolling is enabled. * * By default is disabled. @@ -465,6 +492,41 @@ public: // Configure the text controller. Vector2 GetTextFitContentSize() const; /** + * @brief Retrieve the fited point size. + * + * @return The fited point size. + */ + float GetTextFitPointSize() const; + + /** + * @brief Sets whether the text fit properties have changed. + * + * @param[in] changed Whether to changed the text fit. + */ + void SetTextFitChanged(bool changed); + + /** + * @brief Whether the text fit properties are changed or not. + * + * @return True if the text fit properties are changed + */ + bool IsTextFitChanged() const; + + /** + * @brief Sets disabled color opacity. + * + * @param[in] opacity The color opacity value in disabled state. + */ + void SetDisabledColorOpacity(float opacity); + + /** + * @brief Retrieves the disabled color opacity. + * + * @return The disabled color opacity value for disabled state. + */ + float GetDisabledColorOpacity() const; + + /** * @brief Enable or disable the placeholder text elide. * @param enabled Whether to enable the placeholder text elide. */ @@ -620,6 +682,60 @@ public: // Configure the text controller. */ void FontStyleSetByString(bool setByString); + /** + * @brief Query if Strikethrough settings were provided by string or map + * @return bool true if set by string + */ + bool IsStrikethroughSetByString(); + + /** + * Set method Strikethrough setting were set by + * @param[in] bool, true if set by string + */ + void StrikethroughSetByString(bool setByString); + + /** + * @brief Set the override used for strikethrough height, 0 indicates height will be supplied by font metrics + * + * @param[in] height The height in pixels of the strikethrough + */ + void SetStrikethroughHeight(float height); + + /** + * @brief Retrieves the override height of an strikethrough, 0 indicates height is supplied by font metrics + * + * @return The height of the strikethrough, or 0 if height is not overrided. + */ + float GetStrikethroughHeight() const; + + /** + * @brief Set the strikethrough color. + * + * @param[in] color color of strikethrough. + */ + void SetStrikethroughColor(const Vector4& color); + + /** + * @brief Retrieve the strikethrough color. + * + * @return The strikethrough color. + */ + const Vector4& GetStrikethroughColor() const; + + /** + * @brief Set the strikethrough enabled flag. + * + * @param[in] enabled The strikethrough enabled flag. + */ + void SetStrikethroughEnabled(bool enabled); + + /** + * @brief Returns whether the text has a strikethrough or not. + * + * @return The strikethrough state. + */ + bool IsStrikethroughEnabled() const; + public: // Update. /** * @brief Replaces any text previously set. @@ -869,6 +985,20 @@ public: // Default style & Input style float GetFontSizeScale() const; /** + * @brief Set the font size scale enabled flag. + * + * @param[in] enabled whether to enable the font size scale. + */ + void SetFontSizeScaleEnabled(bool enabled); + + /** + * @brief Returns whether the font size scale is enabled or not. + * + * @return @e true if the font size scale is enabled, otherwise returns @e false. + */ + bool IsFontSizeScaleEnabled() const; + + /** * @brief Sets the Placeholder text font size. * @param[in] fontSize The placeholder text font size * @param[in] type The font size type is point size or pixel size @@ -897,6 +1027,20 @@ public: // Default style & Input style const Vector4& GetDefaultColor() const; /** + * @brief Sets the user interaction enabled. + * + * @param enabled whether to enable the user interaction. + */ + void SetUserInteractionEnabled(bool enabled); + + /** + * @brief Whether the user interaction is enabled. + * + * @return true if the user interaction is enabled, false otherwise. + */ + bool IsUserInteractionEnabled() const; + + /** * @brief Set the text color * * @param textColor The text color @@ -995,6 +1139,46 @@ public: // Default style & Input style float GetUnderlineHeight() const; /** + * @brief Sets the underline type. + * @param[in] type The underline type. + */ + void SetUnderlineType(Text::Underline::Type type); + + /** + * @brief Retrieve underline type. + * @return The underline type. + */ + Text::Underline::Type GetUnderlineType() const; + + /** + * @brief Set the width of the dashes of the dashed underline. + * + * @param[in] width The width in pixels of the dashes of the dashed underline. + */ + void SetDashedUnderlineWidth(float width); + + /** + * @brief Retrieves the width of the dashes of the dashed underline. + * + * @return The width of the dashes of the dashed underline. + */ + float GetDashedUnderlineWidth() const; + + /** + * @brief Set the gap between the dashes of the dashed underline. + * + * @param[in] gap The gap between the dashes of the dashed underline. + */ + void SetDashedUnderlineGap(float gap); + + /** + * @brief Retrieves the gap between the dashes of the dashed underline. + * + * @return The The gap between the dashes of the dashed underline. + */ + float GetDashedUnderlineGap() const; + + /** * @brief Set the outline color. * * @param[in] color color of outline. @@ -1115,6 +1299,22 @@ public: // Default style & Input style float GetDefaultLineSize() const; /** + * @brief Sets the relative line size to the original line size. + * + * @param[in] relativeLineSize The relativeline size. + * + * @return True if relativeLineSize has been updated, false otherwise + */ + bool SetRelativeLineSize(float lineSize); + + /** + * @brief Retrieves the relative line size. + * + * @return The relative line size. + */ + float GetRelativeLineSize() const; + + /** * @brief Sets the input text's color. * * @param[in] color The input text's color. @@ -1292,6 +1492,22 @@ public: // Default style & Input style const std::string& GetInputOutlineProperties() const; /** + * @brief Sets the input strikethrough's properties string. + * + * @note The string is stored to be recovered. + * + * @param[in] strikethroughProperties The strikethrough's properties string. + */ + void SetInputStrikethroughProperties(const std::string& strikethroughProperties); + + /** + * @brief Retrieves the input strikethrough's properties string. + * + * @return The strikethrough's properties string. + */ + const std::string& GetInputStrikethroughProperties() const; + + /** * @brief Set the control's interface. * * @param[in] controlInterface The control's interface. @@ -1305,6 +1521,24 @@ public: // Default style & Input style */ void SetAnchorControlInterface(AnchorControlInterface* anchorControlInterface); + /** + * @brief Sets the character spacing. + * + * @note A positive value will make the characters far apart (expanded) and a negative value will bring them closer (condensed). + * + * @param[in] characterSpacing The character spacing. + */ + void SetCharacterSpacing(float characterSpacing); + + /** + * @brief Retrieves the character spacing. + * + * @note A positive value will make the characters far apart (expanded) and a negative value will bring them closer (condensed). + * + * @return The character spacing. + */ + const float GetCharacterSpacing() const; + public: // Queries & retrieves. /** * @brief Return the layout engine. @@ -1386,6 +1620,16 @@ public: // Queries & retrieves. void GetHiddenInputOption(Property::Map& options); /** + * @brief Used to set the input filter option + */ + void SetInputFilterOption(const Property::Map& options); + + /** + * @brief Used to get the input filter option + */ + void GetInputFilterOption(Property::Map& options); + + /** * @brief Sets the Placeholder Properties. * * @param[in] map The placeholder property map @@ -1418,6 +1662,18 @@ public: // Queries & retrieves. void SetVerticalLineAlignment(Toolkit::DevelText::VerticalLineAlignment::Type alignment); /** + * @brief Retrieves ellipsis position + * @return The ellipsis position + */ + Toolkit::DevelText::EllipsisPosition::Type GetEllipsisPosition() const; + + /** + * @brief Sets ellipsis position + * @param[in] ellipsisPosition The ellipsis position for the text + */ + void SetEllipsisPosition(Toolkit::DevelText::EllipsisPosition::Type ellipsisPosition); + + /** * @brief Retrieves ignoreSpaceAfterText value from model * @return The value of ignoreSpaceAfterText */ @@ -1430,24 +1686,67 @@ public: // Queries & retrieves. void SetIgnoreSpacesAfterText(bool ignore); /** - * @brief Retrieves matchSystemLanguageDirection value from model - * @return The value of matchSystemLanguageDirection + * @brief Sets SetMatchLayoutDirection value to model + * @param[in] match The value of matchLayoutDirection for the text */ - bool IsMatchSystemLanguageDirection() const; + void SetMatchLayoutDirection(DevelText::MatchLayoutDirection type); /** - * @brief Sets matchSystemLanguageDirection value to model - * @param[in] match The value of matchSystemLanguageDirection for the text + * @brief Retrieves matchLayoutDirection value from model + * @return The value of matchLayoutDirection */ - void SetMatchSystemLanguageDirection(bool match); + DevelText::MatchLayoutDirection GetMatchLayoutDirection() const; /** - * @brief Sets layoutDirection value - * @param[in] layoutDirection The value of system language direction + * @brief Sets layoutDirection type value. + * @param[in] layoutDirection The value of the layout direction type. */ void SetLayoutDirection(Dali::LayoutDirection::Type layoutDirection); /** + * @brief Gets layoutDirection type value. + * @param[in] actor The actor which will get the layout direction type. + * @return The value of the layout direction type. + */ + Dali::LayoutDirection::Type GetLayoutDirection(Dali::Actor& actor) const; + + /** + * @brief Get the rendered size of a specific text range. + * if the requested text is at multilines, multiple sizes will be returned for each text located in a separate line. + * if a line contains characters with different directions, multiple sizes will be returned for each block of contiguous characters with the same direction. + * + * @param[in] startIndex start index of the text requested to calculate size for. + * @param[in] endIndex end index(included) of the text requested to calculate size for. + * @return list of sizes of the reuested text. + */ + Vector GetTextSize(CharacterIndex startIndex, CharacterIndex endIndex); + + /** + * @brief Get the top/left rendered position of a specific text range. + * if the requested text is at multilines, multiple positions will be returned for each text located in a separate line. + * if a line contains characters with different directions, multiple positions will be returned for each block of contiguous characters with the same direction. + * + * @param[in] startIndex start index of the text requested to get position to. + * @param[in] endIndex end index(included) of the text requested to get position to. + * @return list of positions of the requested text. + */ + Vector GetTextPosition(CharacterIndex startIndex, CharacterIndex endIndex); + + /** + * @brief Gets the bounding box of a specific text range. + * + * @param[in] startIndex start index of the text requested to get bounding box to. + * @param[in] endIndex end index(included) of the text requested to get bounding box to. + * @return bounding box of the requested text. + */ + Rect<> GetTextBoundingRectangle(CharacterIndex startIndex, CharacterIndex endIndex); + + /** + * @brief Sets the layout direction changed. + */ + void ChangedLayoutDirection(); + + /** * @brief Retrieves if showing real text or not. * @return The value of showing real text. */ @@ -1546,9 +1845,10 @@ public: // Text-input Event Queuing. * @brief Used to set the Primary cursor position. * * @param[in] index for the Primary cursor position. + * @param[in] focused true if UI control has gained focus to receive key event, false otherwise. * @return[in] true if cursor position changed, false otherwise. */ - bool SetPrimaryCursorPosition(CharacterIndex index); + bool SetPrimaryCursorPosition(CharacterIndex index, bool focused); /** * @brief Creates a selection event. @@ -1577,11 +1877,31 @@ public: // Text-input Event Queuing. void SelectWholeText(); /** + * @copydoc Text::EditableControlInterface::CopyText() + */ + string CopyText(); + + /** + * @copydoc Text::EditableControlInterface::CutText() + */ + string CutText(); + + /** + * @copydoc Text::EditableControlInterface::PasteText() + */ + void PasteText(); + + /** * @copydoc Text::SelectableControlInterface::SelectNone() */ void SelectNone(); /** + * @copydoc Text::SelectableControlInterface::SelectText() + */ + void SelectText(const uint32_t start, const uint32_t end); + + /** * @copydoc Text::SelectableControlInterface::GetSelectedText() */ string GetSelectedText() const; @@ -1652,6 +1972,22 @@ public: // Text-input Event Queuing. */ CharacterIndex GetCursorPosition(); + /** + * @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 index in anchor vector (-1 if an anchor not found) + */ + int GetAnchorIndex(size_t characterOffset); + protected: // Inherit from Text::Decorator::ControllerInterface. /** * @copydoc Dali::Toolkit::Text::Decorator::ControllerInterface::GetTargetSize() @@ -1661,7 +1997,7 @@ protected: // Inherit from Text::Decorator::ControllerInterface. /** * @copydoc Dali::Toolkit::Text::Decorator::ControllerInterface::AddDecoration() */ - void AddDecoration(Actor& actor, bool needsClipping) override; + void AddDecoration(Actor& actor, DecorationType type, bool needsClipping) override; /** * @copydoc Dali::Toolkit::Text::Decorator::ControllerInterface::DecorationEvent() @@ -1680,149 +2016,22 @@ protected: // Inherit from HiddenText. */ void DisplayTimeExpired() override; -private: // Update. - /** - * @brief Called by editable UI controls when key events are received. - * - * @param[in] text The text to insert. - * @param[in] type Used to distinguish between regular key events and InputMethodContext events. - */ - void InsertText(const std::string& text, InsertType type); - - /** - * @brief Paste given string into Text model - * @param[in] stringToPaste this string will be inserted into the text model - */ - void PasteText(const std::string& stringToPaste); - - /** - * @brief Remove a given number of characters - * - * When predictve text is used the pre-edit text is removed and inserted again with the new characters. - * The UpdateInputStyleType @type parameter if set to DONT_UPDATE_INPUT_STYLE avoids to update the input - * style when pre-edit text is removed. - * - * @param[in] cursorOffset Start position from the current cursor position to start deleting characters. - * @param[in] numberOfCharacters The number of characters to delete from the cursorOffset. - * @param[in] type Whether to update the input style. - * @return True if the remove was successful. - */ - bool RemoveText(int cursorOffset, - int numberOfCharacters, - UpdateInputStyleType type); - - /** - * @brief Checks if text is selected and if so removes it. - * @return true if text was removed - */ - bool RemoveSelectedText(); - - /** - * @brief Update anchor position from given number of inserted characters. - * - * @param[in] numberOfCharacters The number of inserted characters. - * @param[in] previousCursorIndex A cursor position before event occurs. - */ - void InsertTextAnchor(int numberOfCharacters, - CharacterIndex previousCursorIndex); - - /** - * @brief Update anchor position from given number of removed characters. - * - * @param[in] cursorOffset Start position from the current cursor position to start deleting characters. - * @param[in] numberOfCharacters The number of removed characters. - * @param[in] previousCursorIndex A cursor position before event occurs. - */ - void RemoveTextAnchor(int cursorOffset, - int numberOfCharacters, - CharacterIndex previousCursorIndex); - -private: // Relayout. - /** - * @brief Lays-out the text. - * - * GetNaturalSize(), GetHeightForWidth() and Relayout() calls this method. - * - * @param[in] size A the size of a bounding box to layout text within. - * @param[in] operations The layout operations which need to be done. - * @param[out] layoutSize The size of the laid-out text. - */ - bool DoRelayout(const Size& size, - OperationsMask operations, - Size& layoutSize); - - /** - * @brief Calulates the vertical offset to align the text inside the bounding box. - * - * @param[in] size The size of the bounding box. - */ - void CalculateVerticalOffset(const Size& size); - -private: // Events. - /** - * @brief Process queued events which modify the model. - */ - void ProcessModifyEvents(); - - /** - * @brief Used to process an event queued from SetText() - */ - void TextReplacedEvent(); - - /** - * @brief Used to process an event queued from key events etc. - */ - void TextInsertedEvent(); - - /** - * @brief Used to process an event queued from backspace key etc. - */ - void TextDeletedEvent(); - - /** - * @brief Helper to KeyEvent() to handle the backspace or delete key case. - * - * @param[in] keyCode The keycode for the key pressed - * @return True if a character was deleted. - */ - bool DeleteEvent(int keyCode); - -private: // Helpers. - /** - * @brief Used to remove the text included the placeholder text. - */ - void ResetText(); - - /** - * @brief Helper to show the place holder text.. - */ - void ShowPlaceholderText(); - - /** - * @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(); - private: // Private contructors & copy operator. /** * @brief Private constructor. */ - Controller(); + Controller() + : Controller(nullptr, nullptr, nullptr, nullptr) + { + } /** * @brief Private constructor. */ - Controller(ControlInterface* controlInterface); + Controller(ControlInterface* controlInterface) + : Controller(controlInterface, nullptr, nullptr, nullptr) + { + } /** * @brief Private constructor. @@ -1832,11 +2041,8 @@ private: // Private contructors & copy operator. SelectableControlInterface* selectableControlInterface, AnchorControlInterface* anchorControlInterface); - // Undefined - Controller(const Controller& handle); - - // Undefined - Controller& operator=(const Controller& handle); + Controller(const Controller& handle) = delete; + Controller& operator=(const Controller& handle) = delete; protected: // Destructor. /** @@ -1850,6 +2056,7 @@ public: private: struct EventHandler; struct InputFontHandler; + struct InputProperties; struct PlaceholderHandler; struct Relayouter; struct TextUpdater; @@ -1857,10 +2064,6 @@ private: Impl* mImpl; }; -} // namespace Text - -} // namespace Toolkit - -} // namespace Dali +} // namespace Dali::Toolkit::Text #endif // DALI_TOOLKIT_TEXT_CONTROLLER_H