Ask StyleManager::Configuration only we need at TextController 77/318577/2
authorEunki, Hong <eunkiki.hong@samsung.com>
Wed, 2 Oct 2024 09:32:50 +0000 (18:32 +0900)
committerEunki, Hong <eunkiki.hong@samsung.com>
Thu, 10 Oct 2024 01:43:37 +0000 (10:43 +0900)
We don't need to know the mShouldClearFocusOnEscape value for TextLabel.
And also, if input key is never be Escape, we also don't need it.

But that value required to ask singletone class, StyleManager,
and StyleManager might try to parse json file synchronously.

And also, for every TextVisual, we try to get Configure and find some value
by string, what we don't need to know.

It might make overhead for TextLabel creation.

To reduce the overhead, let we get the value only if we need.

Change-Id: I744cff4b05f8ed83d7924c4cbff3ed8f209a5571
Signed-off-by: Eunki, Hong <eunkiki.hong@samsung.com>
dali-toolkit/internal/text/controller/text-controller-impl.cpp
dali-toolkit/internal/text/controller/text-controller-impl.h
dali-toolkit/internal/text/controller/text-controller.cpp

index a33ebe3e7868c5a910d9607afa979441a5441366..5e7a5b3d9fca347b09c7ebad865fa40b079b04c4 100644 (file)
@@ -1675,8 +1675,8 @@ bool Controller::Impl::IsScrollable(const Vector2& displacement)
     const bool isVerticalScrollEnabled   = mEventData->mDecorator->IsVerticalScrollEnabled();
     if(isHorizontalScrollEnabled || isVerticalScrollEnabled)
     {
-      const Vector2& targetSize     = mModel->mVisualModel->mControlSize;
-      const Vector2& layoutSize     = mModel->mVisualModel->GetLayoutSize();
+      const Vector2& targetSize = mModel->mVisualModel->mControlSize;
+      const Vector2& layoutSize = mModel->mVisualModel->GetLayoutSize();
 
       if(isHorizontalScrollEnabled)
       {
@@ -1768,6 +1768,26 @@ int32_t Controller::Impl::GetAnchorIndex(size_t characterOffset) const
   return it == mModel->mLogicalModel->mAnchors.End() ? -1 : it - mModel->mLogicalModel->mAnchors.Begin();
 }
 
+bool Controller::Impl::ShouldClearFocusOnEscape() const
+{
+  if(DALI_UNLIKELY(mShouldClearFocusOnEscape == ClearFocusOnEscapeState::UNKNOWN))
+  {
+    mShouldClearFocusOnEscape = ClearFocusOnEscapeState::ENABLE;
+
+    Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
+    if(styleManager)
+    {
+      const auto clearFocusOnEscapeValue = Toolkit::DevelStyleManager::GetConfigurations(styleManager).Find("clearFocusOnEscape", Property::Type::BOOLEAN);
+
+      // Default is ENABLE. If config don't have "clearFocusOnEscape" property, make it ENABLE.
+      mShouldClearFocusOnEscape = (!clearFocusOnEscapeValue || clearFocusOnEscapeValue->Get<bool>()) ? ClearFocusOnEscapeState::ENABLE : ClearFocusOnEscapeState::DISABLE;
+    }
+  }
+  DALI_ASSERT_DEBUG(mShouldClearFocusOnEscape != ClearFocusOnEscapeState::UNKNOWN && "mShouldClearFocusOnEscape Should be set now");
+
+  return (mShouldClearFocusOnEscape == ClearFocusOnEscapeState::ENABLE);
+}
+
 void Controller::Impl::CopyUnderlinedFromLogicalToVisualModels(bool shouldClearPreUnderlineRuns)
 {
   //Underlined character runs for markup-processor
index f172b17c9a9d36d8c5a6cac31d133fd9bef05c4f..1861fdd1a31cb6cb367a2a6dc2657059ae654fa7 100644 (file)
@@ -316,6 +316,15 @@ struct OutlineDefaults
 
 struct Controller::Impl
 {
+public:
+  enum class ClearFocusOnEscapeState
+  {
+    UNKNOWN = -1, ///< Unknown state
+    ENABLE  = 0,
+    DISABLE = 1,
+  };
+
+public:
   Impl(ControlInterface*           controlInterface,
        EditableControlInterface*   editableControlInterface,
        SelectableControlInterface* selectableControlInterface,
@@ -360,7 +369,7 @@ struct Controller::Impl
     mOutlineSetByString(false),
     mFontStyleSetByString(false),
     mStrikethroughSetByString(false),
-    mShouldClearFocusOnEscape(true),
+    mShouldClearFocusOnEscape(ClearFocusOnEscapeState::UNKNOWN),
     mLayoutDirection(LayoutDirection::LEFT_TO_RIGHT),
     mCurrentLineSize(0.f),
     mTextFitMinSize(DEFAULT_TEXTFIT_MIN),
@@ -397,15 +406,6 @@ struct Controller::Impl
     // Set the text properties to default
     mModel->mVisualModel->SetUnderlineEnabled(false);
     mModel->mVisualModel->SetUnderlineHeight(0.0f);
-
-    Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get();
-    if(styleManager)
-    {
-      const auto clearFocusOnEscapeValue = Toolkit::DevelStyleManager::GetConfigurations(styleManager).Find("clearFocusOnEscape", Property::Type::BOOLEAN);
-
-      // Default is true. If config don't have "clearFocusOnEscape" property, make it true.
-      mShouldClearFocusOnEscape = (!clearFocusOnEscapeValue || clearFocusOnEscapeValue->Get<bool>());
-    }
   }
 
   ~Impl()
@@ -1012,6 +1012,16 @@ struct Controller::Impl
    */
   Toolkit::TextAnchor CreateAnchorActor(Anchor anchor);
 
+  /**
+   * @brief Return true when text control should clear key input focus when escape key is pressed.
+   *
+   * @note We ask to style manager configurations, and store the option.
+   * @note Default is true. Mean, without any options, text control should clear key input focus when escape key is pressed.
+   *
+   * @return Whether text control should clear key input focus or not when escape key is pressed.
+   */
+  bool ShouldClearFocusOnEscape() const;
+
 public:
   /**
    * @brief Gets implementation from the controller handle.
@@ -1080,21 +1090,25 @@ public:
 
   std::vector<Toolkit::DevelTextLabel::FitOption> mTextFitArray; ///< List of FitOption for TextFitArray operation.
 
-  bool               mRecalculateNaturalSize : 1;         ///< Whether the natural size needs to be recalculated.
-  bool               mMarkupProcessorEnabled : 1;         ///< Whether the mark-up procesor is enabled.
-  bool               mClipboardHideEnabled : 1;           ///< Whether the ClipboardHide function work or not
-  bool               mIsAutoScrollEnabled : 1;            ///< Whether auto text scrolling is enabled.
-  bool               mIsAutoScrollMaxTextureExceeded : 1; ///< Whether auto text scrolling is exceed max texture size.
-  bool               mUpdateTextDirection : 1;            ///< Whether the text direction needs to be updated.
-  CharacterDirection mIsTextDirectionRTL : 1;             ///< Whether the text direction is right to left or not
-
-  bool                  mUnderlineSetByString : 1;     ///< Set when underline is set by string (legacy) instead of map
-  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
+  bool mRecalculateNaturalSize : 1;         ///< Whether the natural size needs to be recalculated.
+  bool mMarkupProcessorEnabled : 1;         ///< Whether the mark-up procesor is enabled.
+  bool mClipboardHideEnabled : 1;           ///< Whether the ClipboardHide function work or not
+  bool mIsAutoScrollEnabled : 1;            ///< Whether auto text scrolling is enabled.
+  bool mIsAutoScrollMaxTextureExceeded : 1; ///< Whether auto text scrolling is exceed max texture size.
+  bool mUpdateTextDirection : 1;            ///< Whether the text direction needs to be updated.
+
+  CharacterDirection mIsTextDirectionRTL : 1; ///< Whether the text direction is right to left or not
+
+  bool mUnderlineSetByString : 1;     ///< Set when underline is set by string (legacy) instead of map
+  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
+
+  mutable ClearFocusOnEscapeState mShouldClearFocusOnEscape : 3; ///< Whether text control should clear key input focus.
+                                                                 ///< Make it mutable so we can update it at const method.
+
+  LayoutDirection::Type mLayoutDirection; ///< Current system language direction
 
   Shader mShaderBackground; ///< The shader for text background.
 
index dfeed9eee96df57d92985ced4bffd443af38bd7a..0b398ecd6e1c9a1fb077ac94b0af635a89fe98f8 100644 (file)
@@ -1961,7 +1961,7 @@ void Controller::SetAnchorControlInterface(AnchorControlInterface* anchorControl
 
 bool Controller::ShouldClearFocusOnEscape() const
 {
-  return mImpl->mShouldClearFocusOnEscape;
+  return mImpl->ShouldClearFocusOnEscape();
 }
 
 Actor Controller::CreateBackgroundActor()