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/controls/text-controls/text-anchor-impl.h>
22 #include <dali/devel-api/actors/actor-devel.h>
23 #include <dali/devel-api/object/property-helper-devel.h>
24 #include <dali/integration-api/debug.h>
25 #include <dali/public-api/common/dali-common.h>
26 #include <dali/public-api/object/type-registry-helper.h>
31 #include <dali-toolkit/devel-api/controls/control-devel.h>
33 using namespace Dali::Toolkit::Text;
43 #if defined(DEBUG_ENABLED)
44 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_TEXT_CONTROLS");
50 return Toolkit::TextAnchor::New();
54 // Setup properties, signals and actions using the type-registry.
55 DALI_TYPE_REGISTRATION_BEGIN(Toolkit::TextAnchor, Toolkit::Control, Create);
57 DALI_PROPERTY_REGISTRATION(Toolkit, TextAnchor, "startCharacterIndex", INTEGER, START_CHARACTER_INDEX)
58 DALI_PROPERTY_REGISTRATION(Toolkit, TextAnchor, "endCharacterIndex", INTEGER, END_CHARACTER_INDEX )
59 DALI_PROPERTY_REGISTRATION(Toolkit, TextAnchor, "uri", STRING, URI )
61 DALI_TYPE_REGISTRATION_END()
66 Toolkit::TextAnchor TextAnchor::New()
68 // Create the implementation, temporarily owned by this handle on stack
69 IntrusivePtr<TextAnchor> impl = new TextAnchor();
71 // Pass ownership to CustomActor handle
72 Toolkit::TextAnchor handle(*impl);
74 // Second-phase init of the implementation
75 // This can only be done after the CustomActor connection has been made...
81 Property::Value TextAnchor::GetProperty(BaseObject* object, Property::Index index)
83 Property::Value value;
85 Toolkit::TextAnchor anchor = Toolkit::TextAnchor::DownCast(Dali::BaseHandle(object));
89 TextAnchor& impl(GetImpl(anchor));
93 case Toolkit::TextAnchor::Property::START_CHARACTER_INDEX:
95 value = impl.mStartCharacterIndex;
98 case Toolkit::TextAnchor::Property::END_CHARACTER_INDEX:
100 value = impl.mEndCharacterIndex;
103 case Toolkit::TextAnchor::Property::URI:
114 void TextAnchor::SetProperty(BaseObject* object, Property::Index index, const Property::Value& value)
116 Toolkit::TextAnchor anchor = Toolkit::TextAnchor::DownCast(Dali::BaseHandle(object));
120 TextAnchor& impl(GetImpl(anchor));
123 case Toolkit::TextAnchor::Property::START_CHARACTER_INDEX:
125 value.Get(impl.mStartCharacterIndex);
129 case Toolkit::TextAnchor::Property::END_CHARACTER_INDEX:
131 value.Get(impl.mEndCharacterIndex);
135 case Toolkit::TextAnchor::Property::URI:
137 value.Get(impl.mUri);
144 void TextAnchor::OnInitialize()
148 // Enable highlightability
149 self.SetProperty(Toolkit::DevelControl::Property::ACCESSIBILITY_HIGHLIGHTABLE, true);
151 DevelControl::SetAccessibilityConstructor(self, [](Dali::Actor actor) {
152 return std::unique_ptr<Dali::Accessibility::Accessible>(
153 new AccessibleImpl(actor, Dali::Accessibility::Role::LINK));
157 TextAnchor::TextAnchor()
158 : Control(ControlBehaviour(CONTROL_BEHAVIOUR_DEFAULT)),
159 mStartCharacterIndex(0),
160 mEndCharacterIndex(0),
165 TextAnchor::~TextAnchor()
169 int32_t TextAnchor::AccessibleImpl::GetEndIndex() const
171 auto self = Toolkit::TextAnchor::DownCast(Self());
172 return self.GetProperty(Toolkit::TextAnchor::Property::END_CHARACTER_INDEX).Get<int>();
175 int32_t TextAnchor::AccessibleImpl::GetStartIndex() const
177 auto self = Toolkit::TextAnchor::DownCast(Self());
178 return self.GetProperty(Toolkit::TextAnchor::Property::START_CHARACTER_INDEX).Get<int>();
181 int32_t TextAnchor::AccessibleImpl::GetAnchorCount() const
186 Dali::Accessibility::Accessible* TextAnchor::AccessibleImpl::GetAnchorAccessible(int32_t anchorIndex) const
188 return Control::Impl::GetAccessibilityObject(Self());
191 std::string TextAnchor::AccessibleImpl::GetAnchorUri(int32_t anchorIndex) const
193 auto self = Toolkit::TextAnchor::DownCast(Self());
194 return self.GetProperty(Toolkit::TextAnchor::Property::URI).Get<std::string>();
197 bool TextAnchor::AccessibleImpl::IsValid() const
199 return !GetAnchorUri(0).empty();
202 bool TextAnchor::OnAccessibilityActivated()
204 auto uri = Self().GetProperty(Toolkit::TextAnchor::Property::URI).Get<std::string>();
207 Dali::Actor current = Self();
208 Dali::Toolkit::Text::AnchorControlInterface* parentImplementationAnchorInterface = nullptr;
209 while(!current.GetProperty<bool>(Actor::Property::IS_ROOT) && !parentImplementationAnchorInterface)
211 Dali::Actor parentAsActor = current.GetParent();
212 Dali::CustomActor parentAsCustomActor = Dali::CustomActor::DownCast(parentAsActor);
213 Dali::CustomActorImpl& parentImplementation = parentAsCustomActor.GetImplementation();
214 parentImplementationAnchorInterface = dynamic_cast<Dali::Toolkit::Text::AnchorControlInterface*>(&parentImplementation);
215 current = parentAsActor;
217 if(parentImplementationAnchorInterface)
219 parentImplementationAnchorInterface->AnchorClicked(uri);
224 DALI_LOG_ERROR("TextAnchor::OnAccessibilityActivate cannot find ancestor actor implementing Dali::Toolkit::Text::AnchorControlInterface.\n");
230 } // namespace Internal
232 } // namespace Toolkit