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/autofill-item.h>
26 #include <dali/devel-api/adaptor-framework/autofill-manager.h>
27 #include <dali/devel-api/adaptor-framework/accessibility.h>
28 #include <dali/public-api/adaptor-framework/accessibility.h>
32 #include <dali-toolkit/internal/visuals/visual-event-observer.h>
33 #include <dali-toolkit/public-api/controls/control-impl.h>
34 #include <dali-toolkit/devel-api/controls/text-controls/autofill-container.h>
35 #include <dali/devel-api/common/owner-container.h>
36 #include <dali-toolkit/devel-api/visual-factory/visual-base.h>
37 #include <dali-toolkit/internal/builder/dictionary.h>
38 #include <dali-toolkit/internal/builder/style.h>
39 #include <dali-toolkit/internal/controls/tooltip/tooltip.h>
40 #include <dali-toolkit/public-api/controls/control-impl.h>
41 #include <dali-toolkit/public-api/visuals/visual-properties.h>
42 #include <dali/devel-api/common/owner-container.h>
43 #include <dali/integration-api/debug.h>
56 * Struct used to store Visual within the control, index is a unique key for each visual.
58 struct RegisteredVisual
60 Property::Index index;
61 Toolkit::Visual::Base visual;
65 RegisteredVisual( Property::Index aIndex, Toolkit::Visual::Base &aVisual, bool aEnabled, bool aPendingReplacement )
66 : index(aIndex), visual(aVisual), enabled(aEnabled), pending( aPendingReplacement )
71 typedef Dali::OwnerContainer< RegisteredVisual* > RegisteredVisualContainer;
75 * @brief Holds the Implementation for the internal control class
77 class Control::Impl : public ConnectionTracker, public Visual::EventObserver
83 * @brief Retrieves the implementation of the internal control class.
84 * @param[in] internalControl A ref to the control whose internal implementation is required
85 * @return The internal implementation
87 static Control::Impl& Get( Internal::Control& internalControl );
90 * @copydoc Get( Internal::Control& )
92 static const Control::Impl& Get( const Internal::Control& internalControl );
96 * @param[in] controlImpl The control which owns this implementation
98 Impl( Control& controlImpl );
106 * @brief Called when a pinch is detected.
107 * @param[in] actor The actor the pinch occurred on
108 * @param[in] pinch The pinch gesture details
110 void PinchDetected(Actor actor, const PinchGesture& pinch);
113 * @brief Called when a pan is detected.
114 * @param[in] actor The actor the pan occurred on
115 * @param[in] pinch The pan gesture details
117 void PanDetected(Actor actor, const PanGesture& pan);
120 * @brief Called when a tap is detected.
121 * @param[in] actor The actor the tap occurred on
122 * @param[in] pinch The tap gesture details
124 void TapDetected(Actor actor, const TapGesture& tap);
127 * @brief Called when a long-press is detected.
128 * @param[in] actor The actor the long-press occurred on
129 * @param[in] pinch The long-press gesture details
131 void LongPressDetected(Actor actor, const LongPressGesture& longPress);
134 * @brief Called when a resource is ready.
135 * @param[in] object The visual whose resources are ready
136 * @note Overriding method in Visual::EventObserver.
138 virtual void ResourceReady( Visual::Base& object ) override;
141 * @brief Called when an event occurs.
142 * @param[in] object The visual whose events occur
143 * @param[in] signalId The signal to emit. See Visual to find supported signals
144 * @note Overriding method in Visual::EventObserver.
146 virtual void NotifyVisualEvent( Visual::Base& object, Property::Index signalId ) override;
149 * @copydoc Dali::Toolkit::DevelControl::RegisterVisual()
151 void RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual );
154 * @copydoc Dali::Toolkit::DevelControl::RegisterVisual()
156 void RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual, int depthIndex );
159 * @copydoc Dali::Toolkit::DevelControl::RegisterVisual()
161 void RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual, bool enabled );
164 * @copydoc Dali::Toolkit::DevelControl::RegisterVisual()
166 void RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual, bool enabled, int depthIndex );
169 * @copydoc Dali::Toolkit::DevelControl::UnregisterVisual()
171 void UnregisterVisual( Property::Index index );
174 * @copydoc Dali::Toolkit::DevelControl::GetVisual()
176 Toolkit::Visual::Base GetVisual( Property::Index index ) const;
179 * @copydoc Dali::Toolkit::DevelControl::EnableVisual()
181 void EnableVisual( Property::Index index, bool enable );
184 * @copydoc Dali::Toolkit::DevelControl::IsVisualEnabled()
186 bool IsVisualEnabled( Property::Index index ) const;
189 * @brief Stops observing the given visual.
190 * @param[in] visual The visual to stop observing
192 void StopObservingVisual( Toolkit::Visual::Base& visual );
195 * @brief Starts observing the given visual.
196 * @param[in] visual The visual to start observing
198 void StartObservingVisual( Toolkit::Visual::Base& visual);
201 * @copydoc Dali::Toolkit::DevelControl::GetVisualResourceStatus()
203 Toolkit::Visual::ResourceStatus GetVisualResourceStatus( Property::Index index ) const;
206 * @param[in,out] animation Handle to existing animation, or an empty handle that
207 * can be set to a New animation if createAnimation is true
208 * @param[in] transitionData The transition data describing the animation
209 * @param[in] createAnimation True if the animation should be created
211 void AddTransitions( Dali::Animation& animation,
212 const Toolkit::TransitionData& transitionData,
213 bool createAnimation = false );
216 * @copydoc Dali::Toolkit::DevelControl::CreateTransition()
218 Dali::Animation CreateTransition( const Toolkit::TransitionData& transitionData );
221 * @copydoc Dali::Toolkit::DevelControl::DoAction()
223 void DoAction( Dali::Property::Index visualIndex, Dali::Property::Index actionId, const Dali::Property::Value attributes );
226 * @brief Function used to set control properties.
227 * @param[in] object The object whose property to set
228 * @param[in] index The index of the property to set
229 * @param[in] value The value of the property to set
231 static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
234 * @brief Function used to retrieve the value of control properties.
235 * @param[in] object The object whose property to get
236 * @param[in] index The index of the property to get
237 * @return The value of the property
239 static Property::Value GetProperty( BaseObject* object, Property::Index index );
242 * @brief Sets the state of the control.
243 * @param[in] newState The state to set
244 * @param[in] withTransitions Whether to show a transition when changing to the new state
246 void SetState( DevelControl::State newState, bool withTransitions=true );
249 * @brief Sets the sub-state of the control.
250 * @param[in] newState The sub-state to set
251 * @param[in] withTransitions Whether to show a transition when changing to the new sub-state
253 void SetSubState( const std::string& subStateName, bool withTransitions=true );
256 * @brief Replaces visuals and properties from the old state to the new state.
257 * @param[in] oldState The old state
258 * @param[in] newState The new state
259 * @param[in] subState The current sub state
261 void ReplaceStateVisualsAndProperties( const StylePtr oldState, const StylePtr newState, const std::string& subState );
264 * @brief Removes a visual from the control's container.
265 * @param[in] visuals The container of visuals
266 * @param[in] visualName The name of the visual to remove
268 void RemoveVisual( RegisteredVisualContainer& visuals, const std::string& visualName );
271 * @brief Removes several visuals from the control's container.
272 * @param[in] visuals The container of visuals
273 * @param[in] removeVisuals The visuals to remove
275 void RemoveVisuals( RegisteredVisualContainer& visuals, DictionaryKeys& removeVisuals );
278 * @brief Copies the visual properties that are specific to the control instance into the instancedProperties container.
279 * @param[in] visuals The control's visual container
280 * @param[out] instancedProperties The instanced properties are added to this container
282 void CopyInstancedProperties( RegisteredVisualContainer& visuals, Dictionary<Property::Map>& instancedProperties );
285 * @brief On state change, ensures visuals are moved or created appropriately.
287 * Go through the list of visuals that are common to both states.
288 * If they are different types, or are both image types with different
289 * URLs, then the existing visual needs moving and the new visual needs creating
291 * @param[in] stateVisualsToChange The visuals to change
292 * @param[in] instancedProperties The instanced properties @see CopyInstancedProperties
294 void RecreateChangedVisuals( Dictionary<Property::Map>& stateVisualsToChange, Dictionary<Property::Map>& instancedProperties );
297 * @brief Whether the resource is ready
298 * @return True if the resource is read.
300 bool IsResourceReady() const;
303 * @copydoc CustomActorImpl::OnStageDisconnection()
305 void OnStageDisconnection();
308 * @brief Sets the margin.
309 * @param[in] margin Margin is a collections of extent ( start, end, top, bottom )
311 void SetMargin( Extents margin );
314 * @brief Returns the value of margin
315 * @return The value of margin
317 Extents GetMargin() const;
320 * @brief Sets the padding.
321 * @param[in] padding Padding is a collections of extent ( start, end, top, bottom ).
323 void SetPadding( Extents padding );
326 * @brief Returns the value of padding
327 * @return The value of padding
329 Extents GetPadding() const;
332 * @brief Set the input method context.
333 * @param[in] inputMethodContext The input method context.
335 void SetInputMethodContext( InputMethodContext& inputMethodContext );
338 * @brief Filter an key event.
339 * @param[in] event The key to be filtered.
340 * @return True if the key handled, otherwise false.
342 bool FilterKeyEvent( const KeyEvent& event );
345 * @brief Adds accessibility attribute
346 * @param[in] key Attribute name to set
347 * @param[in] value Attribute value to set
349 * Attribute is added if not existed previously or updated
352 void AppendAccessibilityAttribute( const std::string& key,
353 const std::string value );
356 * @brief Removes accessibility attribute
357 * @param[in] key Attribute name to remove
359 * Function does nothing if attribute doesn't exist.
361 void RemoveAccessibilityAttribute( const std::string& key );
364 * @brief Removes all accessibility attributes
366 void ClearAccessibilityAttributes();
369 * @brief Sets reading info type attributes
370 * @param[in] types info type attributes to set
372 * This function sets, which part of object will be read out
375 void SetAccessibilityReadingInfoType( const Dali::Accessibility::ReadingInfoTypes types );
378 * @brief Gets currently active reading info type attributes
380 Dali::Accessibility::ReadingInfoTypes GetAccessibilityReadingInfoType() const;
383 * @copydoc DevelControl::VisualEventSignal()
385 DevelControl::VisualEventSignalType& VisualEventSignal();
388 * @brief Sets whether the Autofill functionality is enabled.
389 * @param[in] autofillEnabled Set true when Autofill should be enabled.
391 void SetAutofillEnabled( bool autofillEnabled );
394 * @brief Check if the Autofill framework is enabled.
395 * @return True if Autofill is enabled
397 bool IsAutofillEnabled();
400 * @brief Sets AutofillItemHandle
401 * @param item AutofillItem handle
403 void SetAutofillItemHandle( Dali::AutofillItem item );
406 * @brief Gets AutofillItemHandle
407 * @return AutofillItem handle
409 Dali::AutofillItem GetAutofillItemHandle();
412 * @brief Sets AutofillContainer which this control belongs to.
413 * @param[in] container
415 void SetAutofillContainer( Toolkit::AutofillContainer container );
418 * @brief Gets AutofillContainer that the control belongs to.
419 * @return AutofillContainer handle
421 Toolkit::AutofillContainer GetAutofillContainer();
426 * Used as an alternative to boolean so that it is obvious whether a visual is enabled/disabled.
432 DISABLED = 0, ///< Visual disabled.
433 ENABLED = 1 ///< Visual enabled.
438 * 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.
440 struct DepthIndexValue
444 NOT_SET = 0, ///< Visual depth value not set by caller.
445 SET = 1 ///< Visual depth value set by caller.
450 * @brief Adds the visual to the list of registered visuals.
451 * @param[in] index The Property index of the visual, used to reference visual
452 * @param[in,out] visual The visual to register, which can be altered in this function
453 * @param[in] enabled false if derived class wants to control when visual is set on stage
454 * @param[in] depthIndexValueSet Set to true if the depthIndex has actually been set manually
455 * @param[in] depthIndex The visual's depth-index is set to this
457 * @note Registering a visual with an index that already has a registered visual will replace it. The replacement will
458 * occur once the replacement visual is ready (loaded).
460 void RegisterVisual( Property::Index index, Toolkit::Visual::Base& visual, VisualState::Type enabled, DepthIndexValue::Type depthIndexValueSet, int depthIndex = 0 );
464 Control& mControlImpl;
465 DevelControl::State mState;
466 std::string mSubStateName;
467 Property::Map mAccessibilityAttributes;
469 int mLeftFocusableActorId; ///< Actor ID of Left focusable control.
470 int mRightFocusableActorId; ///< Actor ID of Right focusable control.
471 int mUpFocusableActorId; ///< Actor ID of Up focusable control.
472 int mDownFocusableActorId; ///< Actor ID of Down focusable control.
474 RegisteredVisualContainer mVisuals; ///< Stores visuals needed by the control, non trivial type so std::vector used.
475 std::string mStyleName;
476 Vector4 mBackgroundColor; ///< The color of the background visual
477 Vector3* mStartingPinchScale; ///< The scale when a pinch gesture starts, TODO: consider removing this
478 Extents mMargin; ///< The margin values
479 Extents mPadding; ///< The padding values
480 Toolkit::Control::KeyEventSignalType mKeyEventSignal;
481 Toolkit::Control::KeyInputFocusSignalType mKeyInputFocusGainedSignal;
482 Toolkit::Control::KeyInputFocusSignalType mKeyInputFocusLostSignal;
483 Toolkit::Control::ResourceReadySignalType mResourceReadySignal;
484 DevelControl::VisualEventSignalType mVisualEventSignal;
485 Toolkit::Control::AccessibilityActivateSignalType mAccessibilityActivateSignal;
486 Toolkit::Control::AccessibilityReadingSkippedSignalType mAccessibilityReadingSkippedSignal;
487 Toolkit::Control::AccessibilityReadingCancelledSignalType mAccessibilityReadingCancelledSignal;
488 Toolkit::Control::AccessibilityReadingStoppedSignalType mAccessibilityReadingStoppedSignal;
490 Toolkit::Control::AccessibilityGetNameSignalType mAccessibilityGetNameSignal;
491 Toolkit::Control::AccessibilityGetDescriptionSignalType mAccessibilityGetDescriptionSignal;
492 Toolkit::Control::AccessibilityDoGestureSignalType mAccessibilityDoGestureSignal;
494 std::string mAccessibilityName;
495 bool mAccessibilityNameSet = false;
497 std::string mAccessibilityDescription;
498 bool mAccessibilityDescriptionSet = false;
500 std::string mAccessibilityTranslationDomain;
501 bool mAccessibilityTranslationDomainSet = false;
503 bool mAccessibilityHighlightable = false;
504 bool mAccessibilityHighlightableSet = false;
506 Dali::Accessibility::Role mAccessibilityRole = Dali::Accessibility::Role::UNKNOWN;
508 std::vector<std::vector<Accessibility::Address>> mAccessibilityRelations;
509 bool mAccessibilityAnimated = false;
512 PinchGestureDetector mPinchGestureDetector;
513 PanGestureDetector mPanGestureDetector;
514 TapGestureDetector mTapGestureDetector;
515 LongPressGestureDetector mLongPressGestureDetector;
520 InputMethodContext mInputMethodContext;
521 AutofillItem mAutofillItem;
522 Toolkit::AutofillContainer mAutofillContainer;
524 ControlBehaviour mFlags : CONTROL_BEHAVIOUR_FLAG_COUNT; ///< Flags passed in from constructor.
525 bool mIsKeyboardNavigationSupported :1; ///< Stores whether keyboard navigation is supported by the control.
526 bool mIsKeyboardFocusGroup :1; ///< Stores whether the control is a focus group.
527 bool mIsAutofillEnabled : 1; ///< Stroes whether the Autofill functionality is enabled.
529 RegisteredVisualContainer mRemoveVisuals; ///< List of visuals that are being replaced by another visual once ready
532 // Properties - these need to be members of Internal::Control::Impl as they access private methods/data of Internal::Control and Internal::Control::Impl.
533 static const PropertyRegistration PROPERTY_1;
534 static const PropertyRegistration PROPERTY_2;
535 static const PropertyRegistration PROPERTY_3;
536 static const PropertyRegistration PROPERTY_4;
537 static const PropertyRegistration PROPERTY_5;
538 static const PropertyRegistration PROPERTY_6;
539 static const PropertyRegistration PROPERTY_7;
540 static const PropertyRegistration PROPERTY_8;
541 static const PropertyRegistration PROPERTY_9;
542 static const PropertyRegistration PROPERTY_10;
543 static const PropertyRegistration PROPERTY_11;
544 static const PropertyRegistration PROPERTY_12;
545 static const PropertyRegistration PROPERTY_13;
546 static const PropertyRegistration PROPERTY_14;
547 static const PropertyRegistration PROPERTY_15;
548 static const PropertyRegistration PROPERTY_16;
549 static const PropertyRegistration PROPERTY_17;
550 static const PropertyRegistration PROPERTY_18;
551 static const PropertyRegistration PROPERTY_19;
552 static const PropertyRegistration PROPERTY_20;
553 static const PropertyRegistration PROPERTY_21;
556 * The method acquires Accessible handle from Actor object
557 * @param actor Actor object
558 * @return handle to Accessible object
560 static Dali::Accessibility::Accessible *GetAccessibilityObject(Dali::Actor actor);
561 Dali::Accessibility::Accessible *GetAccessibilityObject();
563 void AccessibilityRegister();
564 void AccessibilityDeregister();
566 struct AccessibleImpl : public virtual Dali::Accessibility::Accessible,
567 public virtual Dali::Accessibility::Component,
568 public virtual Dali::Accessibility::Collection,
569 public virtual Dali::Accessibility::Action
572 bool modal = false, root = false;
574 AccessibleImpl(Dali::Actor self, Dali::Accessibility::Role role, bool modal = false);
576 std::string GetName() override;
577 virtual std::string GetNameRaw();
578 std::string GetDescription() override;
579 virtual std::string GetDescriptionRaw();
580 Dali::Accessibility::Accessible* GetParent() override;
581 size_t GetChildCount() override;
582 Dali::Accessibility::Accessible* GetChildAtIndex( size_t index ) override;
583 size_t GetIndexInParent() override;
584 Dali::Accessibility::Role GetRole() override;
585 Dali::Accessibility::States GetStates() override;
586 Dali::Accessibility::Attributes GetAttributes() override;
587 Dali::Rect<> GetExtents( Dali::Accessibility::CoordType ctype ) override;
588 Dali::Accessibility::ComponentLayer GetLayer() override;
589 int16_t GetMdiZOrder() override;
590 bool GrabFocus() override;
591 double GetAlpha() override;
592 bool GrabHighlight() override;
593 bool ClearHighlight() override;
594 int GetHighlightIndex() override;
596 std::string GetActionName( size_t index ) override;
597 std::string GetLocalizedActionName( size_t index ) override;
598 std::string GetActionDescription( size_t index ) override;
599 size_t GetActionCount() override;
600 std::string GetActionKeyBinding(size_t index) override;
601 bool DoAction(size_t index) override;
602 bool DoAction(const std::string& name) override;
603 bool DoGesture(const Dali::Accessibility::GestureInfo &gestureInfo) override;
604 std::vector<Dali::Accessibility::Relation> GetRelationSet() override;
606 virtual Dali::Accessibility::States CalculateStates();
609 std::function< std::unique_ptr< Dali::Accessibility::Accessible >( Actor ) > accessibilityConstructor;
610 std::unique_ptr< Dali::Accessibility::Accessible > accessibilityObject;
611 Dali::PropertyNotification accessibilityNotificationPosition, accessibilityNotificationSize, accessibilityNotificationCulled;
612 bool accessibilityNotificationSet = false;
613 static void PositionOrSizeChangedCallback( PropertyNotification& );
614 static void CulledChangedCallback( PropertyNotification& );
618 } // namespace Internal
620 } // namespace Toolkit
624 #endif // DALI_TOOLKIT_CONTROL_DATA_IMPL_H