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();
436 * Used as an alternative to boolean so that it is obvious whether a visual is enabled/disabled.
442 DISABLED = 0, ///< Visual disabled.
443 ENABLED = 1 ///< Visual enabled.
448 * 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.
450 struct DepthIndexValue
454 NOT_SET = 0, ///< Visual depth value not set by caller.
455 SET = 1 ///< Visual depth value set by caller.
460 * @brief Adds the visual to the list of registered visuals.
461 * @param[in] index The Property index of the visual, used to reference visual
462 * @param[in,out] visual The visual to register, which can be altered in this function
463 * @param[in] enabled false if derived class wants to control when visual is set on stage
464 * @param[in] depthIndexValueSet Set to true if the depthIndex has actually been set manually
465 * @param[in] depthIndex The visual's depth-index is set to this
467 * @note Registering a visual with an index that already has a registered visual will replace it. The replacement will
468 * occur once the replacement visual is ready (loaded).
470 void RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual, VisualState::Type enabled, DepthIndexValue::Type depthIndexValueSet, int depthIndex = 0 );
473 * @brief Emits the resource ready signal.
475 void EmitResourceReadySignal();
478 * @brief Callbacks called on idle.
480 void OnIdleCallback();
484 Control& mControlImpl;
485 DevelControl::State mState;
486 std::string mSubStateName;
487 Property::Map mAccessibilityAttributes;
489 int mLeftFocusableActorId; ///< Actor ID of Left focusable control.
490 int mRightFocusableActorId; ///< Actor ID of Right focusable control.
491 int mUpFocusableActorId; ///< Actor ID of Up focusable control.
492 int mDownFocusableActorId; ///< Actor ID of Down focusable control.
494 RegisteredVisualContainer mVisuals; ///< Stores visuals needed by the control, non trivial type so std::vector used.
495 std::string mStyleName;
496 Vector4 mBackgroundColor; ///< The color of the background visual
497 Vector3* mStartingPinchScale; ///< The scale when a pinch gesture starts, TODO: consider removing this
498 Extents mMargin; ///< The margin values
499 Extents mPadding; ///< The padding values
500 Toolkit::Control::KeyEventSignalType mKeyEventSignal;
501 Toolkit::Control::KeyInputFocusSignalType mKeyInputFocusGainedSignal;
502 Toolkit::Control::KeyInputFocusSignalType mKeyInputFocusLostSignal;
503 Toolkit::Control::ResourceReadySignalType mResourceReadySignal;
504 DevelControl::VisualEventSignalType mVisualEventSignal;
505 Toolkit::DevelControl::AccessibilityActivateSignalType mAccessibilityActivateSignal;
506 Toolkit::DevelControl::AccessibilityReadingSkippedSignalType mAccessibilityReadingSkippedSignal;
507 Toolkit::DevelControl::AccessibilityReadingPausedSignalType mAccessibilityReadingPausedSignal;
508 Toolkit::DevelControl::AccessibilityReadingResumedSignalType mAccessibilityReadingResumedSignal;
509 Toolkit::DevelControl::AccessibilityReadingCancelledSignalType mAccessibilityReadingCancelledSignal;
510 Toolkit::DevelControl::AccessibilityReadingStoppedSignalType mAccessibilityReadingStoppedSignal;
512 Toolkit::DevelControl::AccessibilityGetNameSignalType mAccessibilityGetNameSignal;
513 Toolkit::DevelControl::AccessibilityGetDescriptionSignalType mAccessibilityGetDescriptionSignal;
514 Toolkit::DevelControl::AccessibilityDoGestureSignalType mAccessibilityDoGestureSignal;
516 std::string mAccessibilityName;
517 bool mAccessibilityNameSet = false;
519 std::string mAccessibilityDescription;
520 bool mAccessibilityDescriptionSet = false;
522 std::string mAccessibilityTranslationDomain;
523 bool mAccessibilityTranslationDomainSet = false;
525 bool mAccessibilityHighlightable = false;
526 bool mAccessibilityHighlightableSet = false;
528 Dali::Accessibility::Role mAccessibilityRole = Dali::Accessibility::Role::UNKNOWN;
530 std::vector<std::vector<Accessibility::Address>> mAccessibilityRelations;
531 bool mAccessibilityAnimated = false;
534 PinchGestureDetector mPinchGestureDetector;
535 PanGestureDetector mPanGestureDetector;
536 TapGestureDetector mTapGestureDetector;
537 LongPressGestureDetector mLongPressGestureDetector;
542 InputMethodContext mInputMethodContext;
543 CallbackBase* mIdleCallback; ///< The idle callback to emit the resource ready signal.
544 AutofillItem mAutofillItem;
545 Toolkit::AutofillContainer mAutofillContainer;
547 ControlBehaviour mFlags : CONTROL_BEHAVIOUR_FLAG_COUNT; ///< Flags passed in from constructor.
548 bool mIsKeyboardNavigationSupported :1; ///< Stores whether keyboard navigation is supported by the control.
549 bool mIsKeyboardFocusGroup :1; ///< Stores whether the control is a focus group.
550 bool mIsEmittingResourceReadySignal :1; ///< True during ResourceReady().
551 bool mNeedToEmitResourceReady :1; ///< True if need to emit the resource ready signal again.
552 bool mIsAutofillEnabled : 1; ///< Stroes whether the Autofill functionality is enabled.
554 RegisteredVisualContainer mRemoveVisuals; ///< List of visuals that are being replaced by another visual once ready
557 // Properties - these need to be members of Internal::Control::Impl as they access private methods/data of Internal::Control and Internal::Control::Impl.
558 static const PropertyRegistration PROPERTY_1;
559 static const PropertyRegistration PROPERTY_2;
560 static const PropertyRegistration PROPERTY_3;
561 static const PropertyRegistration PROPERTY_4;
562 static const PropertyRegistration PROPERTY_5;
563 static const PropertyRegistration PROPERTY_6;
564 static const PropertyRegistration PROPERTY_7;
565 static const PropertyRegistration PROPERTY_8;
566 static const PropertyRegistration PROPERTY_9;
567 static const PropertyRegistration PROPERTY_10;
568 static const PropertyRegistration PROPERTY_11;
569 static const PropertyRegistration PROPERTY_12;
570 static const PropertyRegistration PROPERTY_13;
571 static const PropertyRegistration PROPERTY_14;
572 static const PropertyRegistration PROPERTY_15;
573 static const PropertyRegistration PROPERTY_16;
574 static const PropertyRegistration PROPERTY_17;
575 static const PropertyRegistration PROPERTY_18;
576 static const PropertyRegistration PROPERTY_19;
577 static const PropertyRegistration PROPERTY_20;
578 static const PropertyRegistration PROPERTY_21;
579 static const PropertyRegistration PROPERTY_22;
582 * The method acquires Accessible handle from Actor object
583 * @param actor Actor object
584 * @return handle to Accessible object
586 static Dali::Accessibility::Accessible *GetAccessibilityObject(Dali::Actor actor);
587 Dali::Accessibility::Accessible *GetAccessibilityObject();
589 void AccessibilityRegister();
590 void AccessibilityDeregister();
592 struct AccessibleImpl : public virtual Dali::Accessibility::Accessible,
593 public virtual Dali::Accessibility::Component,
594 public virtual Dali::Accessibility::Collection,
595 public virtual Dali::Accessibility::Action
598 bool modal = false, root = false;
600 AccessibleImpl(Dali::Actor self, Dali::Accessibility::Role role, bool modal = false);
602 std::string GetName() override;
603 virtual std::string GetNameRaw();
604 std::string GetDescription() override;
605 virtual std::string GetDescriptionRaw();
606 Dali::Accessibility::Accessible* GetParent() override;
607 size_t GetChildCount() override;
608 Dali::Accessibility::Accessible* GetChildAtIndex( size_t index ) override;
609 size_t GetIndexInParent() override;
610 Dali::Accessibility::Role GetRole() override;
611 Dali::Accessibility::States GetStates() override;
612 Dali::Accessibility::Attributes GetAttributes() override;
613 Dali::Rect<> GetExtents( Dali::Accessibility::CoordType ctype ) override;
614 Dali::Accessibility::ComponentLayer GetLayer() override;
615 int16_t GetMdiZOrder() override;
616 bool GrabFocus() override;
617 double GetAlpha() override;
618 bool GrabHighlight() override;
619 bool ClearHighlight() override;
621 std::string GetActionName( size_t index ) override;
622 std::string GetLocalizedActionName( size_t index ) override;
623 std::string GetActionDescription( size_t index ) override;
624 size_t GetActionCount() override;
625 std::string GetActionKeyBinding(size_t index) override;
626 bool DoAction(size_t index) override;
627 bool DoAction(const std::string& name) override;
628 bool DoGesture(const Dali::Accessibility::GestureInfo &gestureInfo) override;
629 std::vector<Dali::Accessibility::Relation> GetRelationSet() override;
631 virtual Dali::Accessibility::States CalculateStates();
632 virtual void EnsureChildVisible(Actor child);
633 virtual void EnsureSelfVisible();
634 virtual Property::Index GetNamePropertyIndex();
635 virtual Property::Index GetDescriptionPropertyIndex();
638 std::function< std::unique_ptr< Dali::Accessibility::Accessible >( Actor ) > accessibilityConstructor;
639 std::unique_ptr< Dali::Accessibility::Accessible > accessibilityObject;
640 Dali::PropertyNotification accessibilityNotificationPosition, accessibilityNotificationSize, accessibilityNotificationCulled;
641 bool accessibilityNotificationSet = false;
642 static void PositionOrSizeChangedCallback( PropertyNotification& );
643 static void CulledChangedCallback( PropertyNotification& );
647 } // namespace Internal
649 } // namespace Toolkit
653 #endif // DALI_TOOLKIT_CONTROL_DATA_IMPL_H