Merge "Set TapGesture only if there is an anchor." into devel/master
authorjoogab yun <joogab.yun@samsung.com>
Sun, 1 Aug 2021 23:52:33 +0000 (23:52 +0000)
committerGerrit Code Review <gerrit@review>
Sun, 1 Aug 2021 23:52:33 +0000 (23:52 +0000)
automated-tests/src/dali-toolkit/utc-Dali-TextLabel.cpp
dali-toolkit/internal/controls/text-controls/text-label-impl.cpp
dali-toolkit/internal/text/text-controller.cpp
dali-toolkit/internal/text/text-controller.h

index e91c2b8..f4655ab 100644 (file)
@@ -1788,7 +1788,34 @@ int UtcDaliToolkitTextlabelAnchorClicked(void)
   application.Render();
 
   // Create a tap event to touch the text label.
-  TestGenerateTap(application, 5.0f, 25.0f);
+  TestGenerateTap(application, 5.0f, 25.0f, 100);
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_CHECK(gAnchorClickedCallBackCalled);
+  DALI_TEST_CHECK(anchorClickedSignal);
+
+  // reset
+  gAnchorClickedCallBackCalled = false;
+  anchorClickedSignal = false;
+  label.SetProperty(TextLabel::Property::TEXT, "");
+  label.SetProperty(TextLabel::Property::ENABLE_MARKUP, false);
+
+  application.SendNotification();
+  application.Render();
+
+  // sets anchor text
+  label.SetProperty(TextLabel::Property::ENABLE_MARKUP, true);
+  label.SetProperty(TextLabel::Property::TEXT, "<a href='https://www.tizen.org'>TIZEN</a>");
+  label.SetProperty(Actor::Property::SIZE, Vector2(100.f, 50.f));
+  label.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
+  label.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
+
+  application.SendNotification();
+  application.Render();
+
+  // Create a tap event to touch the text label.
+  TestGenerateTap(application, 5.0f, 25.0f, 200);
   application.SendNotification();
   application.Render();
 
@@ -1798,7 +1825,7 @@ int UtcDaliToolkitTextlabelAnchorClicked(void)
 
   gAnchorClickedCallBackNotCalled = true;
   // Tap the outside of anchor, callback should not be called.
-  TestGenerateTap(application, 150.f, 100.f);
+  TestGenerateTap(application, 150.f, 100.f, 300);
   application.SendNotification();
   application.Render();
 
index 263b879..21e13c8 100644 (file)
@@ -266,6 +266,17 @@ void TextLabel::SetProperty(BaseObject* object, Property::Index index, const Pro
       case Toolkit::TextLabel::Property::TEXT:
       {
         impl.mController->SetText(value.Get<std::string>());
+
+        if(impl.mController->HasAnchors())
+        {
+          // Forward input events to controller
+          impl.EnableGestureDetection(static_cast<GestureType::Value>(GestureType::TAP));
+        }
+        else
+        {
+          impl.DisableGestureDetection(static_cast<GestureType::Value>(GestureType::TAP));
+        }
+
         break;
       }
       case Toolkit::TextLabel::Property::FONT_FAMILY:
@@ -318,6 +329,16 @@ void TextLabel::SetProperty(BaseObject* object, Property::Index index, const Pro
       {
         const bool enableMarkup = value.Get<bool>();
         impl.mController->SetMarkupProcessorEnabled(enableMarkup);
+
+        if(impl.mController->HasAnchors())
+        {
+          // Forward input events to controller
+          impl.EnableGestureDetection(static_cast<GestureType::Value>(GestureType::TAP));
+        }
+        else
+        {
+          impl.DisableGestureDetection(static_cast<GestureType::Value>(GestureType::TAP));
+        }
         break;
       }
       case Toolkit::TextLabel::Property::ENABLE_AUTO_SCROLL:
@@ -804,10 +825,6 @@ void TextLabel::OnInitialize()
 
   self.LayoutDirectionChangedSignal().Connect(this, &TextLabel::OnLayoutDirectionChanged);
 
-  // Forward input events to controller
-  EnableGestureDetection(static_cast<GestureType::Value>(GestureType::TAP));
-  GetTapGestureDetector().SetMaximumTapsRequired(1);
-
   Layout::Engine& engine = mController->GetLayoutEngine();
   engine.SetCursorWidth(0u); // Do not layout space for the cursor.
 
@@ -858,9 +875,6 @@ void TextLabel::OnTap(const TapGesture& gesture)
   padding                   = Self().GetProperty<Extents>(Toolkit::Control::Property::PADDING);
   const Vector2& localPoint = gesture.GetLocalPoint();
   mController->AnchorEvent(localPoint.x - padding.start, localPoint.y - padding.top);
-
-  // parents can also listen for tap gesture events
-  Dali::DevelActor::SetNeedGesturePropagation(Self(), true);
 }
 
 void TextLabel::AnchorClicked(const std::string& href)
index 304276c..7e0410d 100644 (file)
@@ -136,6 +136,11 @@ bool Controller::IsMarkupProcessorEnabled() const
   return mImpl->mMarkupProcessorEnabled;
 }
 
+bool Controller::HasAnchors() const
+{
+  return (mImpl->mMarkupProcessorEnabled && mImpl->mModel->mLogicalModel->mAnchors.Count() && mImpl->IsShowingRealText());
+}
+
 void Controller::SetAutoScrollEnabled(bool enable)
 {
   DALI_LOG_INFO(gLogFilter, Debug::General, "Controller::SetAutoScrollEnabled[%s] SingleBox[%s]-> [%p]\n", (enable) ? "true" : "false", (mImpl->mLayoutEngine.GetLayout() == Layout::Engine::SINGLE_LINE_BOX) ? "true" : "false", this);
index 73f132b..63a77a4 100644 (file)
@@ -231,6 +231,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.