1 #ifndef DALI_TOOLKIT_CONTROL_DATA_IMPL_H
2 #define DALI_TOOLKIT_CONTROL_DATA_IMPL_H
5 * Copyright (c) 2019 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
22 #include <dali/public-api/object/type-registry.h>
23 #include <dali/public-api/object/property-notification.h>
24 #include <dali-toolkit/devel-api/controls/control-devel.h>
25 #include <dali/devel-api/adaptor-framework/accessibility.h>
26 #include <dali/devel-api/adaptor-framework/autofill-item.h>
27 #include <dali/devel-api/adaptor-framework/autofill-manager.h>
31 #include <dali-toolkit/internal/visuals/visual-event-observer.h>
32 #include <dali-toolkit/public-api/controls/control-impl.h>
33 #include <dali-toolkit/devel-api/controls/text-controls/autofill-container.h>
34 #include <dali/devel-api/common/owner-container.h>
35 #include <dali-toolkit/devel-api/visual-factory/visual-base.h>
36 #include <dali-toolkit/internal/builder/dictionary.h>
37 #include <dali-toolkit/internal/builder/style.h>
38 #include <dali-toolkit/internal/controls/tooltip/tooltip.h>
39 #include <dali-toolkit/public-api/controls/control-impl.h>
40 #include <dali-toolkit/public-api/visuals/visual-properties.h>
41 #include <dali/devel-api/common/owner-container.h>
42 #include <dali/integration-api/debug.h>
55 * Struct used to store Visual within the control, index is a unique key for each visual.
57 struct RegisteredVisual
59 Property::Index index;
60 Toolkit::Visual::Base visual;
64 RegisteredVisual( Property::Index aIndex, Toolkit::Visual::Base &aVisual, bool aEnabled, bool aPendingReplacement )
65 : index(aIndex), visual(aVisual), enabled(aEnabled), pending( aPendingReplacement )
70 typedef Dali::OwnerContainer< RegisteredVisual* > RegisteredVisualContainer;
74 * @brief Holds the Implementation for the internal control class
76 class Control::Impl : public ConnectionTracker, public Visual::EventObserver
82 * @brief Retrieves the implementation of the internal control class.
83 * @param[in] internalControl A ref to the control whose internal implementation is required
84 * @return The internal implementation
86 static Control::Impl& Get( Internal::Control& internalControl );
89 * @copydoc Get( Internal::Control& )
91 static const Control::Impl& Get( const Internal::Control& internalControl );
95 * @param[in] controlImpl The control which owns this implementation
97 Impl( Control& controlImpl );
105 * @brief Called when a pinch is detected.
106 * @param[in] actor The actor the pinch occurred on
107 * @param[in] pinch The pinch gesture details
109 void PinchDetected(Actor actor, const PinchGesture& pinch);
112 * @brief Called when a pan is detected.
113 * @param[in] actor The actor the pan occurred on
114 * @param[in] pinch The pan gesture details
116 void PanDetected(Actor actor, const PanGesture& pan);
119 * @brief Called when a tap is detected.
120 * @param[in] actor The actor the tap occurred on
121 * @param[in] pinch The tap gesture details
123 void TapDetected(Actor actor, const TapGesture& tap);
126 * @brief Called when a long-press is detected.
127 * @param[in] actor The actor the long-press occurred on
128 * @param[in] pinch The long-press gesture details
130 void LongPressDetected(Actor actor, const LongPressGesture& longPress);
133 * @brief Called when a resource is ready.
134 * @param[in] object The visual whose resources are ready
135 * @note Overriding method in Visual::EventObserver.
137 void ResourceReady( Visual::Base& object ) override;
140 * @brief Called when an event occurs.
141 * @param[in] object The visual whose events occur
142 * @param[in] signalId The signal to emit. See Visual to find supported signals
143 * @note Overriding method in Visual::EventObserver.
145 void NotifyVisualEvent( Visual::Base& object, Property::Index signalId ) override;
148 * @copydoc Dali::Toolkit::DevelControl::RegisterVisual()
150 void RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual );
153 * @copydoc Dali::Toolkit::DevelControl::RegisterVisual()
155 void RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual, int depthIndex );
158 * @copydoc Dali::Toolkit::DevelControl::RegisterVisual()
160 void RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual, bool enabled );
163 * @copydoc Dali::Toolkit::DevelControl::RegisterVisual()
165 void RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual, bool enabled, int depthIndex );
168 * @copydoc Dali::Toolkit::DevelControl::UnregisterVisual()
170 void UnregisterVisual( Property::Index index );
173 * @copydoc Dali::Toolkit::DevelControl::GetVisual()
175 Toolkit::Visual::Base GetVisual( Property::Index index ) const;
178 * @copydoc Dali::Toolkit::DevelControl::EnableVisual()
180 void EnableVisual( Property::Index index, bool enable );
183 * @copydoc Dali::Toolkit::DevelControl::IsVisualEnabled()
185 bool IsVisualEnabled( Property::Index index ) const;
188 * @brief Stops observing the given visual.
189 * @param[in] visual The visual to stop observing
191 void StopObservingVisual( Toolkit::Visual::Base& visual );
194 * @brief Starts observing the given visual.
195 * @param[in] visual The visual to start observing
197 void StartObservingVisual( Toolkit::Visual::Base& visual);
200 * @copydoc Dali::Toolkit::DevelControl::GetVisualResourceStatus()
202 Toolkit::Visual::ResourceStatus GetVisualResourceStatus( Property::Index index ) const;
205 * @param[in,out] animation Handle to existing animation, or an empty handle that
206 * can be set to a New animation if createAnimation is true
207 * @param[in] transitionData The transition data describing the animation
208 * @param[in] createAnimation True if the animation should be created
210 void AddTransitions( Dali::Animation& animation,
211 const Toolkit::TransitionData& transitionData,
212 bool createAnimation = false );
215 * @copydoc Dali::Toolkit::DevelControl::CreateTransition()
217 Dali::Animation CreateTransition( const Toolkit::TransitionData& transitionData );
220 * @copydoc Dali::Toolkit::DevelControl::DoAction()
222 void DoAction( Dali::Property::Index visualIndex, Dali::Property::Index actionId, const Dali::Property::Value attributes );
225 * @brief Function used to set control properties.
226 * @param[in] object The object whose property to set
227 * @param[in] index The index of the property to set
228 * @param[in] value The value of the property to set
230 static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
233 * @brief Function used to retrieve the value of control properties.
234 * @param[in] object The object whose property to get
235 * @param[in] index The index of the property to get
236 * @return The value of the property
238 static Property::Value GetProperty( BaseObject* object, Property::Index index );
241 * @brief Sets the state of the control.
242 * @param[in] newState The state to set
243 * @param[in] withTransitions Whether to show a transition when changing to the new state
245 void SetState( DevelControl::State newState, bool withTransitions=true );
248 * @brief Sets the sub-state of the control.
249 * @param[in] newState The sub-state to set
250 * @param[in] withTransitions Whether to show a transition when changing to the new sub-state
252 void SetSubState( const std::string& subStateName, bool withTransitions=true );
255 * @brief Replaces visuals and properties from the old state to the new state.
256 * @param[in] oldState The old state
257 * @param[in] newState The new state
258 * @param[in] subState The current sub state
260 void ReplaceStateVisualsAndProperties( const StylePtr oldState, const StylePtr newState, const std::string& subState );
263 * @brief Removes a visual from the control's container.
264 * @param[in] visuals The container of visuals
265 * @param[in] visualName The name of the visual to remove
267 void RemoveVisual( RegisteredVisualContainer& visuals, const std::string& visualName );
270 * @brief Removes several visuals from the control's container.
271 * @param[in] visuals The container of visuals
272 * @param[in] removeVisuals The visuals to remove
274 void RemoveVisuals( RegisteredVisualContainer& visuals, DictionaryKeys& removeVisuals );
277 * @brief Copies the visual properties that are specific to the control instance into the instancedProperties container.
278 * @param[in] visuals The control's visual container
279 * @param[out] instancedProperties The instanced properties are added to this container
281 void CopyInstancedProperties( RegisteredVisualContainer& visuals, Dictionary<Property::Map>& instancedProperties );
284 * @brief On state change, ensures visuals are moved or created appropriately.
286 * Go through the list of visuals that are common to both states.
287 * If they are different types, or are both image types with different
288 * URLs, then the existing visual needs moving and the new visual needs creating
290 * @param[in] stateVisualsToChange The visuals to change
291 * @param[in] instancedProperties The instanced properties @see CopyInstancedProperties
293 void RecreateChangedVisuals( Dictionary<Property::Map>& stateVisualsToChange, Dictionary<Property::Map>& instancedProperties );
296 * @brief Whether the resource is ready
297 * @return True if the resource is read.
299 bool IsResourceReady() const;
302 * @copydoc CustomActorImpl::OnSceneDisconnection()
304 void OnSceneDisconnection();
307 * @brief Sets the margin.
308 * @param[in] margin Margin is a collections of extent ( start, end, top, bottom )
310 void SetMargin( Extents margin );
313 * @brief Returns the value of margin
314 * @return The value of margin
316 Extents GetMargin() const;
319 * @brief Sets the padding.
320 * @param[in] padding Padding is a collections of extent ( start, end, top, bottom ).
322 void SetPadding( Extents padding );
325 * @brief Returns the value of padding
326 * @return The value of padding
328 Extents GetPadding() const;
331 * @brief Set the input method context.
332 * @param[in] inputMethodContext The input method context.
334 void SetInputMethodContext( InputMethodContext& inputMethodContext );
337 * @brief Filter an key event.
338 * @param[in] event The key to be filtered.
339 * @return True if the key handled, otherwise false.
341 bool FilterKeyEvent( const KeyEvent& event );
344 * @brief Adds accessibility attribute
345 * @param[in] key Attribute name to set
346 * @param[in] value Attribute value to set
348 * Attribute is added if not existed previously or updated
351 void AppendAccessibilityAttribute( const std::string& key,
352 const std::string value );
355 * @brief Removes accessibility attribute
356 * @param[in] key Attribute name to remove
358 * Function does nothing if attribute doesn't exist.
360 void RemoveAccessibilityAttribute( const std::string& key );
363 * @brief Removes all accessibility attributes
365 void ClearAccessibilityAttributes();
368 * @brief Sets reading info type attributes
369 * @param[in] types info type attributes to set
371 * This function sets, which part of object will be read out
374 void SetAccessibilityReadingInfoType( const Dali::Accessibility::ReadingInfoTypes types );
377 * @brief Gets currently active reading info type attributes
379 Dali::Accessibility::ReadingInfoTypes GetAccessibilityReadingInfoType() const;
382 * @copydoc DevelControl::VisualEventSignal()
384 DevelControl::VisualEventSignalType& VisualEventSignal();
387 * @brief Sets the shadow with a property map.
388 * @param[in] map The shadow property map
390 void SetShadow(const Property::Map& map);
393 * @brief Clear the shadow.
398 * @brief Sets whether the Autofill functionality is enabled.
399 * @param[in] autofillEnabled Set true when Autofill should be enabled.
401 void SetAutofillEnabled( bool autofillEnabled );
404 * @brief Check if the Autofill framework is enabled.
405 * @return True if Autofill is enabled
407 bool IsAutofillEnabled();
410 * @brief Sets AutofillItemHandle
411 * @param item AutofillItem handle
413 void SetAutofillItemHandle( Dali::AutofillItem item );
416 * @brief Gets AutofillItemHandle
417 * @return AutofillItem handle
419 Dali::AutofillItem GetAutofillItemHandle();
422 * @brief Sets AutofillContainer which this control belongs to.
423 * @param[in] container
425 void SetAutofillContainer( Toolkit::AutofillContainer container );
428 * @brief Gets AutofillContainer that the control belongs to.
429 * @return AutofillContainer handle
431 Toolkit::AutofillContainer GetAutofillContainer();
434 * @copydoc DevelControl::GetVisualProperty()
436 Dali::Property GetVisualProperty(Dali::Property::Index index, Dali::Property::Key visualPropertyKey);
441 * Used as an alternative to boolean so that it is obvious whether a visual is enabled/disabled.
447 DISABLED = 0, ///< Visual disabled.
448 ENABLED = 1 ///< Visual enabled.
453 * Used as an alternative to boolean so that it is obvious whether a visual's depth value has been set or not by the caller.
455 struct DepthIndexValue
459 NOT_SET = 0, ///< Visual depth value not set by caller.
460 SET = 1 ///< Visual depth value set by caller.
465 * @brief Adds the visual to the list of registered visuals.
466 * @param[in] index The Property index of the visual, used to reference visual
467 * @param[in,out] visual The visual to register, which can be altered in this function
468 * @param[in] enabled false if derived class wants to control when visual is set on stage
469 * @param[in] depthIndexValueSet Set to true if the depthIndex has actually been set manually
470 * @param[in] depthIndex The visual's depth-index is set to this
472 * @note Registering a visual with an index that already has a registered visual will replace it. The replacement will
473 * occur once the replacement visual is ready (loaded).
475 void RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual, VisualState::Type enabled, DepthIndexValue::Type depthIndexValueSet, int depthIndex = 0 );
478 * @brief Emits the resource ready signal.
480 void EmitResourceReadySignal();
483 * @brief Callbacks called on idle.
485 void OnIdleCallback();
489 Control& mControlImpl;
490 DevelControl::State mState;
491 std::string mSubStateName;
492 Property::Map mAccessibilityAttributes;
494 int mLeftFocusableActorId; ///< Actor ID of Left focusable control.
495 int mRightFocusableActorId; ///< Actor ID of Right focusable control.
496 int mUpFocusableActorId; ///< Actor ID of Up focusable control.
497 int mDownFocusableActorId; ///< Actor ID of Down focusable control.
499 RegisteredVisualContainer mVisuals; ///< Stores visuals needed by the control, non trivial type so std::vector used.
500 std::string mStyleName;
501 Vector4 mBackgroundColor; ///< The color of the background visual
502 Vector3* mStartingPinchScale; ///< The scale when a pinch gesture starts, TODO: consider removing this
503 Extents mMargin; ///< The margin values
504 Extents mPadding; ///< The padding values
505 Toolkit::Control::KeyEventSignalType mKeyEventSignal;
506 Toolkit::Control::KeyInputFocusSignalType mKeyInputFocusGainedSignal;
507 Toolkit::Control::KeyInputFocusSignalType mKeyInputFocusLostSignal;
508 Toolkit::Control::ResourceReadySignalType mResourceReadySignal;
509 DevelControl::VisualEventSignalType mVisualEventSignal;
510 Toolkit::DevelControl::AccessibilityActivateSignalType mAccessibilityActivateSignal;
511 Toolkit::DevelControl::AccessibilityReadingSkippedSignalType mAccessibilityReadingSkippedSignal;
512 Toolkit::DevelControl::AccessibilityReadingPausedSignalType mAccessibilityReadingPausedSignal;
513 Toolkit::DevelControl::AccessibilityReadingResumedSignalType mAccessibilityReadingResumedSignal;
514 Toolkit::DevelControl::AccessibilityReadingCancelledSignalType mAccessibilityReadingCancelledSignal;
515 Toolkit::DevelControl::AccessibilityReadingStoppedSignalType mAccessibilityReadingStoppedSignal;
517 Toolkit::DevelControl::AccessibilityGetNameSignalType mAccessibilityGetNameSignal;
518 Toolkit::DevelControl::AccessibilityGetDescriptionSignalType mAccessibilityGetDescriptionSignal;
519 Toolkit::DevelControl::AccessibilityDoGestureSignalType mAccessibilityDoGestureSignal;
521 std::string mAccessibilityName;
522 bool mAccessibilityNameSet = false;
524 std::string mAccessibilityDescription;
525 bool mAccessibilityDescriptionSet = false;
527 std::string mAccessibilityTranslationDomain;
528 bool mAccessibilityTranslationDomainSet = false;
530 bool mAccessibilityHighlightable = false;
531 bool mAccessibilityHighlightableSet = false;
533 Dali::Accessibility::Role mAccessibilityRole = Dali::Accessibility::Role::UNKNOWN;
535 std::vector<std::vector<Accessibility::Address>> mAccessibilityRelations;
536 bool mAccessibilityAnimated = false;
539 PinchGestureDetector mPinchGestureDetector;
540 PanGestureDetector mPanGestureDetector;
541 TapGestureDetector mTapGestureDetector;
542 LongPressGestureDetector mLongPressGestureDetector;
547 InputMethodContext mInputMethodContext;
548 CallbackBase* mIdleCallback; ///< The idle callback to emit the resource ready signal.
549 AutofillItem mAutofillItem;
550 Toolkit::AutofillContainer mAutofillContainer;
552 ControlBehaviour mFlags : CONTROL_BEHAVIOUR_FLAG_COUNT; ///< Flags passed in from constructor.
553 bool mIsKeyboardNavigationSupported :1; ///< Stores whether keyboard navigation is supported by the control.
554 bool mIsKeyboardFocusGroup :1; ///< Stores whether the control is a focus group.
555 bool mIsEmittingResourceReadySignal :1; ///< True during ResourceReady().
556 bool mNeedToEmitResourceReady :1; ///< True if need to emit the resource ready signal again.
557 bool mIsAutofillEnabled : 1; ///< Stroes whether the Autofill functionality is enabled.
559 RegisteredVisualContainer mRemoveVisuals; ///< List of visuals that are being replaced by another visual once ready
562 // Properties - these need to be members of Internal::Control::Impl as they access private methods/data of Internal::Control and Internal::Control::Impl.
563 static const PropertyRegistration PROPERTY_1;
564 static const PropertyRegistration PROPERTY_2;
565 static const PropertyRegistration PROPERTY_3;
566 static const PropertyRegistration PROPERTY_4;
567 static const PropertyRegistration PROPERTY_5;
568 static const PropertyRegistration PROPERTY_6;
569 static const PropertyRegistration PROPERTY_7;
570 static const PropertyRegistration PROPERTY_8;
571 static const PropertyRegistration PROPERTY_9;
572 static const PropertyRegistration PROPERTY_10;
573 static const PropertyRegistration PROPERTY_11;
574 static const PropertyRegistration PROPERTY_12;
575 static const PropertyRegistration PROPERTY_13;
576 static const PropertyRegistration PROPERTY_14;
577 static const PropertyRegistration PROPERTY_15;
578 static const PropertyRegistration PROPERTY_16;
579 static const PropertyRegistration PROPERTY_17;
580 static const PropertyRegistration PROPERTY_18;
581 static const PropertyRegistration PROPERTY_19;
582 static const PropertyRegistration PROPERTY_20;
583 static const PropertyRegistration PROPERTY_21;
584 static const PropertyRegistration PROPERTY_22;
587 * The method acquires Accessible handle from Actor object
588 * @param actor Actor object
589 * @return handle to Accessible object
591 static Dali::Accessibility::Accessible *GetAccessibilityObject(Dali::Actor actor);
592 Dali::Accessibility::Accessible *GetAccessibilityObject();
594 void AccessibilityRegister();
595 void AccessibilityDeregister();
597 struct AccessibleImpl : public virtual Dali::Accessibility::Accessible,
598 public virtual Dali::Accessibility::Component,
599 public virtual Dali::Accessibility::Collection,
600 public virtual Dali::Accessibility::Action
603 bool modal = false, root = false;
605 AccessibleImpl(Dali::Actor self, Dali::Accessibility::Role role, bool modal = false);
607 std::string GetName() override;
608 virtual std::string GetNameRaw();
609 std::string GetDescription() override;
610 virtual std::string GetDescriptionRaw();
611 Dali::Accessibility::Accessible* GetParent() override;
612 size_t GetChildCount() override;
613 Dali::Accessibility::Accessible* GetChildAtIndex( size_t index ) override;
614 size_t GetIndexInParent() override;
615 Dali::Accessibility::Role GetRole() override;
616 Dali::Accessibility::States GetStates() override;
617 Dali::Accessibility::Attributes GetAttributes() override;
618 Dali::Rect<> GetExtents( Dali::Accessibility::CoordType ctype ) override;
619 Dali::Accessibility::ComponentLayer GetLayer() override;
620 int16_t GetMdiZOrder() override;
621 bool GrabFocus() override;
622 double GetAlpha() override;
623 bool GrabHighlight() override;
624 bool ClearHighlight() override;
626 std::string GetActionName( size_t index ) override;
627 std::string GetLocalizedActionName( size_t index ) override;
628 std::string GetActionDescription( size_t index ) override;
629 size_t GetActionCount() override;
630 std::string GetActionKeyBinding(size_t index) override;
631 bool DoAction(size_t index) override;
632 bool DoAction(const std::string& name) override;
633 bool DoGesture(const Dali::Accessibility::GestureInfo &gestureInfo) override;
634 std::vector<Dali::Accessibility::Relation> GetRelationSet() override;
636 virtual Dali::Accessibility::States CalculateStates();
637 virtual void EnsureChildVisible(Actor child);
638 virtual void EnsureSelfVisible();
639 virtual Property::Index GetNamePropertyIndex();
640 virtual Property::Index GetDescriptionPropertyIndex();
643 std::function< std::unique_ptr< Dali::Accessibility::Accessible >( Actor ) > accessibilityConstructor;
644 std::unique_ptr< Dali::Accessibility::Accessible > accessibilityObject;
645 Dali::PropertyNotification accessibilityNotificationPosition, accessibilityNotificationSize, accessibilityNotificationCulled;
646 bool accessibilityNotificationSet = false;
647 static void PositionOrSizeChangedCallback( PropertyNotification& );
648 static void CulledChangedCallback( PropertyNotification& );
652 } // namespace Internal
654 } // namespace Toolkit
658 #endif // DALI_TOOLKIT_CONTROL_DATA_IMPL_H