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>
29 #include <dali-toolkit/internal/visuals/visual-event-observer.h>
30 #include <dali-toolkit/public-api/controls/control-impl.h>
31 #include <dali/devel-api/common/owner-container.h>
32 #include <dali-toolkit/devel-api/visual-factory/visual-base.h>
33 #include <dali-toolkit/internal/builder/dictionary.h>
34 #include <dali-toolkit/internal/builder/style.h>
35 #include <dali-toolkit/internal/controls/tooltip/tooltip.h>
36 #include <dali-toolkit/public-api/controls/control-impl.h>
37 #include <dali-toolkit/public-api/visuals/visual-properties.h>
38 #include <dali/devel-api/common/owner-container.h>
39 #include <dali/integration-api/debug.h>
52 * Struct used to store Visual within the control, index is a unique key for each visual.
54 struct RegisteredVisual
56 Property::Index index;
57 Toolkit::Visual::Base visual;
61 RegisteredVisual( Property::Index aIndex, Toolkit::Visual::Base &aVisual, bool aEnabled, bool aPendingReplacement )
62 : index(aIndex), visual(aVisual), enabled(aEnabled), pending( aPendingReplacement )
67 typedef Dali::OwnerContainer< RegisteredVisual* > RegisteredVisualContainer;
71 * @brief Holds the Implementation for the internal control class
73 class Control::Impl : public ConnectionTracker, public Visual::EventObserver
79 * @brief Retrieves the implementation of the internal control class.
80 * @param[in] internalControl A ref to the control whose internal implementation is required
81 * @return The internal implementation
83 static Control::Impl& Get( Internal::Control& internalControl );
86 * @copydoc Get( Internal::Control& )
88 static const Control::Impl& Get( const Internal::Control& internalControl );
92 * @param[in] controlImpl The control which owns this implementation
94 Impl( Control& controlImpl );
102 * @brief Called when a pinch is detected.
103 * @param[in] actor The actor the pinch occurred on
104 * @param[in] pinch The pinch gesture details
106 void PinchDetected(Actor actor, const PinchGesture& pinch);
109 * @brief Called when a pan is detected.
110 * @param[in] actor The actor the pan occurred on
111 * @param[in] pinch The pan gesture details
113 void PanDetected(Actor actor, const PanGesture& pan);
116 * @brief Called when a tap is detected.
117 * @param[in] actor The actor the tap occurred on
118 * @param[in] pinch The tap gesture details
120 void TapDetected(Actor actor, const TapGesture& tap);
123 * @brief Called when a long-press is detected.
124 * @param[in] actor The actor the long-press occurred on
125 * @param[in] pinch The long-press gesture details
127 void LongPressDetected(Actor actor, const LongPressGesture& longPress);
130 * @brief Called when a resource is ready.
131 * @param[in] object The visual whose resources are ready
132 * @note Overriding method in Visual::EventObserver.
134 void ResourceReady( Visual::Base& object ) override;
137 * @brief Called when an event occurs.
138 * @param[in] object The visual whose events occur
139 * @param[in] signalId The signal to emit. See Visual to find supported signals
140 * @note Overriding method in Visual::EventObserver.
142 void NotifyVisualEvent( Visual::Base& object, Property::Index signalId ) override;
145 * @copydoc Dali::Toolkit::DevelControl::RegisterVisual()
147 void RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual );
150 * @copydoc Dali::Toolkit::DevelControl::RegisterVisual()
152 void RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual, int depthIndex );
155 * @copydoc Dali::Toolkit::DevelControl::RegisterVisual()
157 void RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual, bool enabled );
160 * @copydoc Dali::Toolkit::DevelControl::RegisterVisual()
162 void RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual, bool enabled, int depthIndex );
165 * @copydoc Dali::Toolkit::DevelControl::UnregisterVisual()
167 void UnregisterVisual( Property::Index index );
170 * @copydoc Dali::Toolkit::DevelControl::GetVisual()
172 Toolkit::Visual::Base GetVisual( Property::Index index ) const;
175 * @copydoc Dali::Toolkit::DevelControl::EnableVisual()
177 void EnableVisual( Property::Index index, bool enable );
180 * @copydoc Dali::Toolkit::DevelControl::IsVisualEnabled()
182 bool IsVisualEnabled( Property::Index index ) const;
185 * @brief Stops observing the given visual.
186 * @param[in] visual The visual to stop observing
188 void StopObservingVisual( Toolkit::Visual::Base& visual );
191 * @brief Starts observing the given visual.
192 * @param[in] visual The visual to start observing
194 void StartObservingVisual( Toolkit::Visual::Base& visual);
197 * @copydoc Dali::Toolkit::DevelControl::GetVisualResourceStatus()
199 Toolkit::Visual::ResourceStatus GetVisualResourceStatus( Property::Index index ) const;
202 * @param[in,out] animation Handle to existing animation, or an empty handle that
203 * can be set to a New animation if createAnimation is true
204 * @param[in] transitionData The transition data describing the animation
205 * @param[in] createAnimation True if the animation should be created
207 void AddTransitions( Dali::Animation& animation,
208 const Toolkit::TransitionData& transitionData,
209 bool createAnimation = false );
212 * @copydoc Dali::Toolkit::DevelControl::CreateTransition()
214 Dali::Animation CreateTransition( const Toolkit::TransitionData& transitionData );
217 * @copydoc Dali::Toolkit::DevelControl::DoAction()
219 void DoAction( Dali::Property::Index visualIndex, Dali::Property::Index actionId, const Dali::Property::Value attributes );
222 * @brief Function used to set control properties.
223 * @param[in] object The object whose property to set
224 * @param[in] index The index of the property to set
225 * @param[in] value The value of the property to set
227 static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
230 * @brief Function used to retrieve the value of control properties.
231 * @param[in] object The object whose property to get
232 * @param[in] index The index of the property to get
233 * @return The value of the property
235 static Property::Value GetProperty( BaseObject* object, Property::Index index );
238 * @brief Sets the state of the control.
239 * @param[in] newState The state to set
240 * @param[in] withTransitions Whether to show a transition when changing to the new state
242 void SetState( DevelControl::State newState, bool withTransitions=true );
245 * @brief Sets the sub-state of the control.
246 * @param[in] newState The sub-state to set
247 * @param[in] withTransitions Whether to show a transition when changing to the new sub-state
249 void SetSubState( const std::string& subStateName, bool withTransitions=true );
252 * @brief Replaces visuals and properties from the old state to the new state.
253 * @param[in] oldState The old state
254 * @param[in] newState The new state
255 * @param[in] subState The current sub state
257 void ReplaceStateVisualsAndProperties( const StylePtr oldState, const StylePtr newState, const std::string& subState );
260 * @brief Removes a visual from the control's container.
261 * @param[in] visuals The container of visuals
262 * @param[in] visualName The name of the visual to remove
264 void RemoveVisual( RegisteredVisualContainer& visuals, const std::string& visualName );
267 * @brief Removes several visuals from the control's container.
268 * @param[in] visuals The container of visuals
269 * @param[in] removeVisuals The visuals to remove
271 void RemoveVisuals( RegisteredVisualContainer& visuals, DictionaryKeys& removeVisuals );
274 * @brief Copies the visual properties that are specific to the control instance into the instancedProperties container.
275 * @param[in] visuals The control's visual container
276 * @param[out] instancedProperties The instanced properties are added to this container
278 void CopyInstancedProperties( RegisteredVisualContainer& visuals, Dictionary<Property::Map>& instancedProperties );
281 * @brief On state change, ensures visuals are moved or created appropriately.
283 * Go through the list of visuals that are common to both states.
284 * If they are different types, or are both image types with different
285 * URLs, then the existing visual needs moving and the new visual needs creating
287 * @param[in] stateVisualsToChange The visuals to change
288 * @param[in] instancedProperties The instanced properties @see CopyInstancedProperties
290 void RecreateChangedVisuals( Dictionary<Property::Map>& stateVisualsToChange, Dictionary<Property::Map>& instancedProperties );
293 * @brief Whether the resource is ready
294 * @return True if the resource is read.
296 bool IsResourceReady() const;
299 * @copydoc CustomActorImpl::OnSceneDisconnection()
301 void OnSceneDisconnection();
304 * @brief Sets the margin.
305 * @param[in] margin Margin is a collections of extent ( start, end, top, bottom )
307 void SetMargin( Extents margin );
310 * @brief Returns the value of margin
311 * @return The value of margin
313 Extents GetMargin() const;
316 * @brief Sets the padding.
317 * @param[in] padding Padding is a collections of extent ( start, end, top, bottom ).
319 void SetPadding( Extents padding );
322 * @brief Returns the value of padding
323 * @return The value of padding
325 Extents GetPadding() const;
328 * @brief Set the input method context.
329 * @param[in] inputMethodContext The input method context.
331 void SetInputMethodContext( InputMethodContext& inputMethodContext );
334 * @brief Filter an key event.
335 * @param[in] event The key to be filtered.
336 * @return True if the key handled, otherwise false.
338 bool FilterKeyEvent( const KeyEvent& event );
341 * @brief Adds accessibility attribute
342 * @param[in] key Attribute name to set
343 * @param[in] value Attribute value to set
345 * Attribute is added if not existed previously or updated
348 void AppendAccessibilityAttribute( const std::string& key,
349 const std::string value );
352 * @brief Removes accessibility attribute
353 * @param[in] key Attribute name to remove
355 * Function does nothing if attribute doesn't exist.
357 void RemoveAccessibilityAttribute( const std::string& key );
360 * @brief Removes all accessibility attributes
362 void ClearAccessibilityAttributes();
365 * @brief Sets reading info type attributes
366 * @param[in] types info type attributes to set
368 * This function sets, which part of object will be read out
371 void SetAccessibilityReadingInfoType( const Dali::Accessibility::ReadingInfoTypes types );
374 * @brief Gets currently active reading info type attributes
376 Dali::Accessibility::ReadingInfoTypes GetAccessibilityReadingInfoType() const;
379 * @copydoc DevelControl::VisualEventSignal()
381 DevelControl::VisualEventSignalType& VisualEventSignal();
384 * @brief Sets the shadow with a property map.
385 * @param[in] map The shadow property map
387 void SetShadow(const Property::Map& map);
390 * @brief Clear the shadow.
397 * Used as an alternative to boolean so that it is obvious whether a visual is enabled/disabled.
403 DISABLED = 0, ///< Visual disabled.
404 ENABLED = 1 ///< Visual enabled.
409 * 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.
411 struct DepthIndexValue
415 NOT_SET = 0, ///< Visual depth value not set by caller.
416 SET = 1 ///< Visual depth value set by caller.
421 * @brief Adds the visual to the list of registered visuals.
422 * @param[in] index The Property index of the visual, used to reference visual
423 * @param[in,out] visual The visual to register, which can be altered in this function
424 * @param[in] enabled false if derived class wants to control when visual is set on stage
425 * @param[in] depthIndexValueSet Set to true if the depthIndex has actually been set manually
426 * @param[in] depthIndex The visual's depth-index is set to this
428 * @note Registering a visual with an index that already has a registered visual will replace it. The replacement will
429 * occur once the replacement visual is ready (loaded).
431 void RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual, VisualState::Type enabled, DepthIndexValue::Type depthIndexValueSet, int depthIndex = 0 );
434 * @brief Emits the resource ready signal.
436 void EmitResourceReadySignal();
439 * @brief Callbacks called on idle.
441 void OnIdleCallback();
445 Control& mControlImpl;
446 DevelControl::State mState;
447 std::string mSubStateName;
448 Property::Map mAccessibilityAttributes;
450 int mLeftFocusableActorId; ///< Actor ID of Left focusable control.
451 int mRightFocusableActorId; ///< Actor ID of Right focusable control.
452 int mUpFocusableActorId; ///< Actor ID of Up focusable control.
453 int mDownFocusableActorId; ///< Actor ID of Down focusable control.
455 RegisteredVisualContainer mVisuals; ///< Stores visuals needed by the control, non trivial type so std::vector used.
456 std::string mStyleName;
457 Vector4 mBackgroundColor; ///< The color of the background visual
458 Vector3* mStartingPinchScale; ///< The scale when a pinch gesture starts, TODO: consider removing this
459 Extents mMargin; ///< The margin values
460 Extents mPadding; ///< The padding values
461 Toolkit::Control::KeyEventSignalType mKeyEventSignal;
462 Toolkit::Control::KeyInputFocusSignalType mKeyInputFocusGainedSignal;
463 Toolkit::Control::KeyInputFocusSignalType mKeyInputFocusLostSignal;
464 Toolkit::Control::ResourceReadySignalType mResourceReadySignal;
465 DevelControl::VisualEventSignalType mVisualEventSignal;
466 Toolkit::DevelControl::AccessibilityActivateSignalType mAccessibilityActivateSignal;
467 Toolkit::DevelControl::AccessibilityReadingSkippedSignalType mAccessibilityReadingSkippedSignal;
468 Toolkit::DevelControl::AccessibilityReadingPausedSignalType mAccessibilityReadingPausedSignal;
469 Toolkit::DevelControl::AccessibilityReadingResumedSignalType mAccessibilityReadingResumedSignal;
470 Toolkit::DevelControl::AccessibilityReadingCancelledSignalType mAccessibilityReadingCancelledSignal;
471 Toolkit::DevelControl::AccessibilityReadingStoppedSignalType mAccessibilityReadingStoppedSignal;
473 Toolkit::DevelControl::AccessibilityGetNameSignalType mAccessibilityGetNameSignal;
474 Toolkit::DevelControl::AccessibilityGetDescriptionSignalType mAccessibilityGetDescriptionSignal;
475 Toolkit::DevelControl::AccessibilityDoGestureSignalType mAccessibilityDoGestureSignal;
477 std::string mAccessibilityName;
478 bool mAccessibilityNameSet = false;
480 std::string mAccessibilityDescription;
481 bool mAccessibilityDescriptionSet = false;
483 std::string mAccessibilityTranslationDomain;
484 bool mAccessibilityTranslationDomainSet = false;
486 bool mAccessibilityHighlightable = false;
487 bool mAccessibilityHighlightableSet = false;
489 Dali::Accessibility::Role mAccessibilityRole = Dali::Accessibility::Role::UNKNOWN;
491 std::vector<std::vector<Accessibility::Address>> mAccessibilityRelations;
492 bool mAccessibilityAnimated = false;
495 PinchGestureDetector mPinchGestureDetector;
496 PanGestureDetector mPanGestureDetector;
497 TapGestureDetector mTapGestureDetector;
498 LongPressGestureDetector mLongPressGestureDetector;
503 InputMethodContext mInputMethodContext;
504 CallbackBase* mIdleCallback; ///< The idle callback to emit the resource ready signal.
506 ControlBehaviour mFlags : CONTROL_BEHAVIOUR_FLAG_COUNT; ///< Flags passed in from constructor.
507 bool mIsKeyboardNavigationSupported :1; ///< Stores whether keyboard navigation is supported by the control.
508 bool mIsKeyboardFocusGroup :1; ///< Stores whether the control is a focus group.
509 bool mIsEmittingResourceReadySignal :1; ///< True during ResourceReady().
510 bool mNeedToEmitResourceReady :1; ///< True if need to emit the resource ready signal again.
512 RegisteredVisualContainer mRemoveVisuals; ///< List of visuals that are being replaced by another visual once ready
515 // Properties - these need to be members of Internal::Control::Impl as they access private methods/data of Internal::Control and Internal::Control::Impl.
516 static const PropertyRegistration PROPERTY_1;
517 static const PropertyRegistration PROPERTY_2;
518 static const PropertyRegistration PROPERTY_3;
519 static const PropertyRegistration PROPERTY_4;
520 static const PropertyRegistration PROPERTY_5;
521 static const PropertyRegistration PROPERTY_6;
522 static const PropertyRegistration PROPERTY_7;
523 static const PropertyRegistration PROPERTY_8;
524 static const PropertyRegistration PROPERTY_9;
525 static const PropertyRegistration PROPERTY_10;
526 static const PropertyRegistration PROPERTY_11;
527 static const PropertyRegistration PROPERTY_12;
528 static const PropertyRegistration PROPERTY_13;
529 static const PropertyRegistration PROPERTY_14;
530 static const PropertyRegistration PROPERTY_15;
531 static const PropertyRegistration PROPERTY_16;
532 static const PropertyRegistration PROPERTY_17;
533 static const PropertyRegistration PROPERTY_18;
534 static const PropertyRegistration PROPERTY_19;
535 static const PropertyRegistration PROPERTY_20;
536 static const PropertyRegistration PROPERTY_21;
537 static const PropertyRegistration PROPERTY_22;
540 * The method acquires Accessible handle from Actor object
541 * @param actor Actor object
542 * @return handle to Accessible object
544 static Dali::Accessibility::Accessible *GetAccessibilityObject(Dali::Actor actor);
545 Dali::Accessibility::Accessible *GetAccessibilityObject();
547 void AccessibilityRegister();
548 void AccessibilityDeregister();
550 struct AccessibleImpl : public virtual Dali::Accessibility::Accessible,
551 public virtual Dali::Accessibility::Component,
552 public virtual Dali::Accessibility::Collection,
553 public virtual Dali::Accessibility::Action
556 bool modal = false, root = false;
558 AccessibleImpl(Dali::Actor self, Dali::Accessibility::Role role, bool modal = false);
560 std::string GetName() override;
561 virtual std::string GetNameRaw();
562 std::string GetDescription() override;
563 virtual std::string GetDescriptionRaw();
564 Dali::Accessibility::Accessible* GetParent() override;
565 size_t GetChildCount() override;
566 Dali::Accessibility::Accessible* GetChildAtIndex( size_t index ) override;
567 size_t GetIndexInParent() override;
568 Dali::Accessibility::Role GetRole() override;
569 Dali::Accessibility::States GetStates() override;
570 Dali::Accessibility::Attributes GetAttributes() override;
571 Dali::Rect<> GetExtents( Dali::Accessibility::CoordType ctype ) override;
572 Dali::Accessibility::ComponentLayer GetLayer() override;
573 int16_t GetMdiZOrder() override;
574 bool GrabFocus() override;
575 double GetAlpha() override;
576 bool GrabHighlight() override;
577 bool ClearHighlight() override;
579 std::string GetActionName( size_t index ) override;
580 std::string GetLocalizedActionName( size_t index ) override;
581 std::string GetActionDescription( size_t index ) override;
582 size_t GetActionCount() override;
583 std::string GetActionKeyBinding(size_t index) override;
584 bool DoAction(size_t index) override;
585 bool DoAction(const std::string& name) override;
586 bool DoGesture(const Dali::Accessibility::GestureInfo &gestureInfo) override;
587 std::vector<Dali::Accessibility::Relation> GetRelationSet() override;
589 virtual Dali::Accessibility::States CalculateStates();
590 virtual void EnsureChildVisible(Actor child);
591 virtual void EnsureSelfVisible();
592 virtual Property::Index GetNamePropertyIndex();
593 virtual Property::Index GetDescriptionPropertyIndex();
596 std::function< std::unique_ptr< Dali::Accessibility::Accessible >( Actor ) > accessibilityConstructor;
597 std::unique_ptr< Dali::Accessibility::Accessible > accessibilityObject;
598 Dali::PropertyNotification accessibilityNotificationPosition, accessibilityNotificationSize, accessibilityNotificationCulled;
599 bool accessibilityNotificationSet = false;
600 static void PositionOrSizeChangedCallback( PropertyNotification& );
601 static void CulledChangedCallback( PropertyNotification& );
605 } // namespace Internal
607 } // namespace Toolkit
611 #endif // DALI_TOOLKIT_CONTROL_DATA_IMPL_H