From: Eunki, Hong Date: Mon, 24 Jan 2022 06:06:31 +0000 (+0900) Subject: New with additional behavior flag for some Controls X-Git-Tag: dali_2.1.8~1 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=commitdiff_plain;h=b3f769e350cf3c159ab22bd947f1e98d47cb4038 New with additional behavior flag for some Controls Add new "New" function that we can append additional ControlBehaviour Toolkit::Control::ControlBehaviour was hard-coding. we should change it as valid type as we can in future. Current code only works in Control and ImageView and TextLabel. Change-Id: Iee12d71f699444cd0e85dfa84b485f12086545f2 Signed-off-by: Eunki, Hong --- diff --git a/automated-tests/src/dali-toolkit-styling/utc-Dali-StyleManager.cpp b/automated-tests/src/dali-toolkit-styling/utc-Dali-StyleManager.cpp index 45e1c64..3d9e206 100644 --- a/automated-tests/src/dali-toolkit-styling/utc-Dali-StyleManager.cpp +++ b/automated-tests/src/dali-toolkit-styling/utc-Dali-StyleManager.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * Copyright (c) 2022 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -34,6 +34,9 @@ #include #include +// for Internal::StyleManager +#include + using namespace Dali; using namespace Dali::Toolkit; @@ -1354,3 +1357,53 @@ int UtcDaliStyleManagerConfigSectionTest(void) END_TEST; } + + +int UtcDaliStyleManagerNewWithAdditionalBehavior(void) +{ + ToolkitTestApplication application; + + Toolkit::StyleManager styleManager = StyleManager::Get(); + Toolkit::Internal::StyleManager& styleManagerImpl = GetImpl(styleManager); + + auto checkup = [&styleManagerImpl](int enableStyleChangeSignal, const Control& control){ + DALI_TEST_EQUALS( enableStyleChangeSignal, styleManagerImpl.ControlStyleChangeSignal().GetConnectionCount(), TEST_LOCATION ); + }; + + // Default New + tet_infoline( "Check whether ControlStyleChangeSignal connected in default New\n"); + checkup(1, Control::New()); + checkup(1, ImageView::New()); + checkup(1, ImageView::New("url")); + checkup(1, ImageView::New("url", Dali::ImageDimensions(32u, 32u))); + checkup(1, TextLabel::New()); + checkup(1, TextLabel::New("text")); + + // New with additional behaviour, but enable style change signals + tet_infoline( "Check whether ControlStyleChangeSignal connected in non-disable style change signals\n"); + checkup(1, Control::New(Toolkit::Control::ControlBehaviour::CONTROL_BEHAVIOUR_DEFAULT)); + checkup(1, Control::New(Toolkit::Control::ControlBehaviour::DISABLE_SIZE_NEGOTIATION)); + checkup(1, Control::New(Toolkit::Control::ControlBehaviour::REQUIRES_KEYBOARD_NAVIGATION_SUPPORT)); + checkup(1, ImageView::New(Toolkit::Control::ControlBehaviour::CONTROL_BEHAVIOUR_DEFAULT)); + checkup(1, ImageView::New(Toolkit::Control::ControlBehaviour::CONTROL_BEHAVIOUR_DEFAULT, "url")); + checkup(1, ImageView::New(Toolkit::Control::ControlBehaviour::CONTROL_BEHAVIOUR_DEFAULT, "url", Dali::ImageDimensions(32u, 32u))); + checkup(1, ImageView::New(Toolkit::Control::ControlBehaviour::DISABLE_SIZE_NEGOTIATION)); + checkup(1, ImageView::New(Toolkit::Control::ControlBehaviour::DISABLE_SIZE_NEGOTIATION, "url")); + checkup(1, ImageView::New(Toolkit::Control::ControlBehaviour::DISABLE_SIZE_NEGOTIATION, "url", Dali::ImageDimensions(32u, 32u))); + checkup(1, TextLabel::New(Toolkit::Control::ControlBehaviour::CONTROL_BEHAVIOUR_DEFAULT)); + checkup(1, TextLabel::New(Toolkit::Control::ControlBehaviour::CONTROL_BEHAVIOUR_DEFAULT, "text")); + checkup(1, TextLabel::New(Toolkit::Control::ControlBehaviour::DISABLE_SIZE_NEGOTIATION)); + checkup(1, TextLabel::New(Toolkit::Control::ControlBehaviour::DISABLE_SIZE_NEGOTIATION, "text")); + + // New with additional behaviour, so disable style change signals + tet_infoline( "Check whether ControlStyleChangeSignal did not connected\n"); + checkup(0, Control::New(Toolkit::Control::ControlBehaviour::DISABLE_STYLE_CHANGE_SIGNALS)); + checkup(0, Control::New(Toolkit::Control::ControlBehaviour(Toolkit::Control::ControlBehaviour::DISABLE_STYLE_CHANGE_SIGNALS | Toolkit::Control::ControlBehaviour::DISABLE_SIZE_NEGOTIATION))); + checkup(0, ImageView::New(Toolkit::Control::ControlBehaviour::DISABLE_STYLE_CHANGE_SIGNALS)); + checkup(0, ImageView::New(Toolkit::Control::ControlBehaviour::DISABLE_STYLE_CHANGE_SIGNALS, "url")); + checkup(0, ImageView::New(Toolkit::Control::ControlBehaviour::DISABLE_STYLE_CHANGE_SIGNALS, "url", Dali::ImageDimensions(32u, 32u))); + checkup(0, TextLabel::New(Toolkit::Control::ControlBehaviour::DISABLE_STYLE_CHANGE_SIGNALS)); + checkup(0, TextLabel::New(Toolkit::Control::ControlBehaviour::DISABLE_STYLE_CHANGE_SIGNALS, "text")); + + END_TEST; +} diff --git a/dali-toolkit/internal/controls/image-view/image-view-impl.cpp b/dali-toolkit/internal/controls/image-view/image-view-impl.cpp index 0011c02..46c9e11 100644 --- a/dali-toolkit/internal/controls/image-view/image-view-impl.cpp +++ b/dali-toolkit/internal/controls/image-view/image-view-impl.cpp @@ -61,8 +61,8 @@ DALI_TYPE_REGISTRATION_END() using namespace Dali; -ImageView::ImageView() -: Control(ControlBehaviour(CONTROL_BEHAVIOUR_DEFAULT)), +ImageView::ImageView(ControlBehaviour additionalBehaviour) +: Control(ControlBehaviour(CONTROL_BEHAVIOUR_DEFAULT | additionalBehaviour)), mImageSize(), mImageVisualPaddingSetByTransform(false), mImageViewPixelAreaSetByFittingMode(false) @@ -73,9 +73,9 @@ ImageView::~ImageView() { } -Toolkit::ImageView ImageView::New() +Toolkit::ImageView ImageView::New(ControlBehaviour additionalBehaviour) { - ImageView* impl = new ImageView(); + ImageView* impl = new ImageView(additionalBehaviour); Toolkit::ImageView handle = Toolkit::ImageView(*impl); diff --git a/dali-toolkit/internal/controls/image-view/image-view-impl.h b/dali-toolkit/internal/controls/image-view/image-view-impl.h index cf288ab..47f7283 100644 --- a/dali-toolkit/internal/controls/image-view/image-view-impl.h +++ b/dali-toolkit/internal/controls/image-view/image-view-impl.h @@ -39,8 +39,10 @@ class ImageView : public Control protected: /** * Construct a new ImageView. + * + * @param[in] additionalBehaviour additional behaviour flags for this ImageView */ - ImageView(); + ImageView(ControlBehaviour additionalBehaviour); /** * A reference counted object may only be deleted by calling Unreference() @@ -50,9 +52,11 @@ protected: public: /** * Create a new ImageView. + * + * @param[in] additionalBehaviour custom behavior flags for this ImageView. Default is CONTROL_BEHAVIOUR_DEFAULT * @return A smart-pointer to the newly allocated ImageView. */ - static Toolkit::ImageView New(); + static Toolkit::ImageView New(ControlBehaviour additionalBehaviour = ControlBehaviour::CONTROL_BEHAVIOUR_DEFAULT); /** * @brief Sets this ImageView from an Dali::Property::Map diff --git a/dali-toolkit/internal/controls/text-controls/text-label-impl.cpp b/dali-toolkit/internal/controls/text-controls/text-label-impl.cpp index fb91c6f..49a9af8 100644 --- a/dali-toolkit/internal/controls/text-controls/text-label-impl.cpp +++ b/dali-toolkit/internal/controls/text-controls/text-label-impl.cpp @@ -222,10 +222,10 @@ void ParseTextFitProperty(Text::ControllerPtr& controller, const Property::Map* } // namespace -Toolkit::TextLabel TextLabel::New() +Toolkit::TextLabel TextLabel::New(ControlBehaviour additionalBehaviour) { // Create the implementation, temporarily owned by this handle on stack - IntrusivePtr impl = new TextLabel(); + IntrusivePtr impl = new TextLabel(additionalBehaviour); // Pass ownership to CustomActor handle Toolkit::TextLabel handle(*impl); @@ -1163,8 +1163,8 @@ void TextLabel::OnAccessibilityStatusChanged() CommonTextUtils::SynchronizeTextAnchorsInParent(Self(), mController, mAnchorActors); } -TextLabel::TextLabel() -: Control(ControlBehaviour(CONTROL_BEHAVIOUR_DEFAULT)), +TextLabel::TextLabel(ControlBehaviour additionalBehavior) +: Control(ControlBehaviour(CONTROL_BEHAVIOUR_DEFAULT | additionalBehavior)), mRenderingBackend(DEFAULT_RENDERING_BACKEND), mTextUpdateNeeded(false) { diff --git a/dali-toolkit/internal/controls/text-controls/text-label-impl.h b/dali-toolkit/internal/controls/text-controls/text-label-impl.h index 8bedc5b..978ad97 100644 --- a/dali-toolkit/internal/controls/text-controls/text-label-impl.h +++ b/dali-toolkit/internal/controls/text-controls/text-label-impl.h @@ -2,7 +2,7 @@ #define DALI_TOOLKIT_INTERNAL_TEXT_LABEL_H /* - * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * Copyright (c) 2022 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -49,8 +49,9 @@ class TextLabel : public Control, public Text::ControlInterface, public Text::Sc public: /** * @copydoc Dali::Toollkit::TextLabel::New() + * @param[in] additionalBehaviour custom behavior flags for this TextLabel. Default is CONTROL_BEHAVIOUR_DEFAULT */ - static Toolkit::TextLabel New(); + static Toolkit::TextLabel New(ControlBehaviour additionalBehaviour = ControlBehaviour::CONTROL_BEHAVIOUR_DEFAULT); // Properties @@ -180,8 +181,10 @@ public: // From AnchorControlInterface private: // Implementation /** * Construct a new TextLabel. + * + * @param[in] additionalBehaviour additional behaviour flags for this TextLabel */ - TextLabel(); + TextLabel(ControlBehaviour additionalBehaviour); /** * A reference counted object may only be deleted by calling Unreference() diff --git a/dali-toolkit/public-api/controls/control-impl.cpp b/dali-toolkit/public-api/controls/control-impl.cpp index 1a2445c..4ad7103 100644 --- a/dali-toolkit/public-api/controls/control-impl.cpp +++ b/dali-toolkit/public-api/controls/control-impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * Copyright (c) 2022 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -88,8 +88,13 @@ void CreateClippingRenderer(Control& controlImpl) Toolkit::Control Control::New() { + return New(ControlBehaviour::CONTROL_BEHAVIOUR_DEFAULT); +} + +Toolkit::Control Control::New(ControlBehaviour additionalBehaviour) +{ // Create the implementation, temporarily owned on stack - IntrusivePtr controlImpl = new Control(ControlBehaviour(CONTROL_BEHAVIOUR_DEFAULT)); + IntrusivePtr controlImpl = new Control(ControlBehaviour(CONTROL_BEHAVIOUR_DEFAULT | additionalBehaviour)); // Pass ownership to handle Toolkit::Control handle(*controlImpl); diff --git a/dali-toolkit/public-api/controls/control-impl.h b/dali-toolkit/public-api/controls/control-impl.h index 48c6b9c..e2d1ca4 100644 --- a/dali-toolkit/public-api/controls/control-impl.h +++ b/dali-toolkit/public-api/controls/control-impl.h @@ -2,7 +2,7 @@ #define DALI_TOOLKIT_CONTROL_IMPL_H /* - * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * Copyright (c) 2022 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -60,7 +60,6 @@ public: class Extension; ///< Forward declare future extension interface // Creation & Destruction - /** * @brief Creates a new ControlImpl instance that does not require touch by default. * @@ -382,8 +381,7 @@ protected: // From CustomActorImpl */ void OnLayoutNegotiated(float size, Dimension::Type dimension) override; -protected: // Helpers for deriving classes - // Construction +public: // Helpers for deriving classes /** * @brief Flags for the constructor. @@ -402,6 +400,19 @@ protected: // Helpers for deriving classes static const int CONTROL_BEHAVIOUR_FLAG_COUNT = Log::value + 1; ///< Total count of flags /** + * @brief Creates a new ControlImpl instance that does not require touch by default. + * + * If touch is required, then the user can connect to this class' touch signal. + * @SINCE_2_1.8 + * @param[in] additionalBehaviour Additional control behaviour. + * @return A handle to the ControlImpl instance + */ + static Toolkit::Control New(ControlBehaviour additionalBehaviour); + +protected: + // Construction + + /** * @brief Control constructor. * * @SINCE_1_0.0 diff --git a/dali-toolkit/public-api/controls/control.cpp b/dali-toolkit/public-api/controls/control.cpp index ec37028..245bdd5 100644 --- a/dali-toolkit/public-api/controls/control.cpp +++ b/dali-toolkit/public-api/controls/control.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * Copyright (c) 2022 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,7 +31,12 @@ namespace Toolkit { Control Control::New() { - return Internal::Control::New(); + return Toolkit::Internal::Control::New(); +} + +Control Control::New(ControlBehaviour additionalBehaviour) +{ + return Toolkit::Internal::Control::New(static_cast(additionalBehaviour)); } Control::Control() diff --git a/dali-toolkit/public-api/controls/control.h b/dali-toolkit/public-api/controls/control.h index fb2b5ad..cbcb6ff 100644 --- a/dali-toolkit/public-api/controls/control.h +++ b/dali-toolkit/public-api/controls/control.h @@ -2,7 +2,7 @@ #define DALI_TOOLKIT_CONTROL_H /* - * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * Copyright (c) 2022 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -168,6 +168,21 @@ public: typedef Signal ResourceReadySignalType; public: // Creation & Destruction + + /** + * @brief Additional control behaviour flags for the control constructor. + * @note TODO : Currunt code is hard-coded. We Should sync type values as + * CustomActorImpl::ActorFlag and Internal::Control::ControlBehaviour in future. + * @SINCE_2_1.8 + */ + enum ControlBehaviour + { + CONTROL_BEHAVIOUR_DEFAULT = 0, ///< Default behaviour: Size negotiation is enabled & listens to Style Change signal, but doesn't receive event callbacks. @SINCE_1_2_10 + DISABLE_SIZE_NEGOTIATION = 1 << (0 + 0), ///< True if control does not need size negotiation, i.e. it can be skipped in the algorithm @SINCE_1_0.0 + REQUIRES_KEYBOARD_NAVIGATION_SUPPORT = 1 << (4 + 1), ///< True if needs to support keyboard navigation @SINCE_1_0.0 + DISABLE_STYLE_CHANGE_SIGNALS = 1 << (4 + 2), ///< True if control should not monitor style change signals @SINCE_1_2_10 + }; + /** * @brief Creates a new instance of a Control. * @@ -177,6 +192,15 @@ public: // Creation & Destruction static Control New(); /** + * @brief Creates a new instance of a Control with additional behaviour. + * + * @SINCE_2_1.8 + * @param[in] additionalBehaviour Additional control behaviour + * @return A handle to a new Control + */ + static Control New(ControlBehaviour additionalBehaviour); + + /** * @brief Creates an uninitialized Control handle. * * Only derived versions can be instantiated. Calling member diff --git a/dali-toolkit/public-api/controls/image-view/image-view.cpp b/dali-toolkit/public-api/controls/image-view/image-view.cpp index d65bef0..d0b1401 100644 --- a/dali-toolkit/public-api/controls/image-view/image-view.cpp +++ b/dali-toolkit/public-api/controls/image-view/image-view.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * Copyright (c) 2022 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -47,7 +47,7 @@ ImageView::~ImageView() ImageView ImageView::New() { - return Internal::ImageView::New(); + return Toolkit::Internal::ImageView::New(); } ImageView ImageView::New(const std::string& url) @@ -64,6 +64,25 @@ ImageView ImageView::New(const std::string& url, ImageDimensions size) return imageView; } +ImageView ImageView::New(ControlBehaviour additionalBehaviour) +{ + return Toolkit::Internal::ImageView::New(static_cast(additionalBehaviour)); +} + +ImageView ImageView::New(ControlBehaviour additionalBehaviour, const std::string& url) +{ + ImageView imageView = Internal::ImageView::New(static_cast(additionalBehaviour)); + imageView.SetImage(url, ImageDimensions()); + return imageView; +} + +ImageView ImageView::New(ControlBehaviour additionalBehaviour, const std::string& url, ImageDimensions size) +{ + ImageView imageView = Internal::ImageView::New(static_cast(additionalBehaviour)); + imageView.SetImage(url, size); + return imageView; +} + ImageView ImageView::DownCast(BaseHandle handle) { return Control::DownCast(handle); diff --git a/dali-toolkit/public-api/controls/image-view/image-view.h b/dali-toolkit/public-api/controls/image-view/image-view.h index bb6d966..78178fa 100644 --- a/dali-toolkit/public-api/controls/image-view/image-view.h +++ b/dali-toolkit/public-api/controls/image-view/image-view.h @@ -2,7 +2,7 @@ #define DALI_TOOLKIT_IMAGE_VIEW_H /* - * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * Copyright (c) 2022 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -173,6 +173,49 @@ public: static ImageView New(const std::string& url, ImageDimensions size); /** + * @brief Create an initialized ImageView with additional behaviour. + * + * @SINCE_2_1.8 + * @param[in] additionalBehaviour Additional control behaviour + * @return A handle to a newly allocated Dali ImageView + * + * @note ImageView will not display anything. + */ + static ImageView New(ControlBehaviour additionalBehaviour); + + /** + * @brief Creates an initialized ImageView from an URL to an image resource with additional behaviour. + * + * If the string is empty, ImageView will not display anything. + * + * @SINCE_2_1.8 + * @REMARK_INTERNET + * @REMARK_STORAGE + * @param[in] additionalBehaviour Additional control behaviour + * @param[in] url The url of the image resource to display + * @return A handle to a newly allocated ImageView + */ + static ImageView New(ControlBehaviour additionalBehaviour, const std::string& url); + + /** + * @brief Creates an initialized ImageView from a URL to an image resource with additional behaviour. + * + * If the string is empty, ImageView will not display anything. + * + * @SINCE_2_1.8 + * @REMARK_INTERNET + * @REMARK_STORAGE + * @param[in] additionalBehaviour Additional control behaviour + * @param[in] url The url of the image resource to display + * @param[in] size The width and height to which to fit the loaded image + * @return A handle to a newly allocated ImageView + * @note A valid size is preferable for efficiency. + * However, do not set a size that is bigger than the actual image size, as up-scaling is not available. + * The content of the area not covered by the actual image is undefined and will not be cleared. + */ + static ImageView New(ControlBehaviour additionalBehaviour, const std::string& url, ImageDimensions size); + + /** * @brief Destructor. * * This is non-virtual since derived Handle types must not contain data or virtual methods. diff --git a/dali-toolkit/public-api/controls/text-controls/text-label.cpp b/dali-toolkit/public-api/controls/text-controls/text-label.cpp index 66710a1..6591d8d 100644 --- a/dali-toolkit/public-api/controls/text-controls/text-label.cpp +++ b/dali-toolkit/public-api/controls/text-controls/text-label.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * Copyright (c) 2022 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -38,6 +38,19 @@ TextLabel TextLabel::New(const std::string& text) return label; } +TextLabel TextLabel::New(ControlBehaviour additionalBehaviour) +{ + return Internal::TextLabel::New(static_cast(additionalBehaviour)); +} + +TextLabel TextLabel::New(ControlBehaviour additionalBehaviour, const std::string& text) +{ + TextLabel label = Internal::TextLabel::New(static_cast(additionalBehaviour)); + label.SetProperty(TextLabel::Property::TEXT, text); + + return label; +} + TextLabel::TextLabel() { } diff --git a/dali-toolkit/public-api/controls/text-controls/text-label.h b/dali-toolkit/public-api/controls/text-controls/text-label.h index 471a619..3f0323f 100644 --- a/dali-toolkit/public-api/controls/text-controls/text-label.h +++ b/dali-toolkit/public-api/controls/text-controls/text-label.h @@ -2,7 +2,7 @@ #define DALI_TOOLKIT_TEXT_LABEL_H /* - * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * Copyright (c) 2022 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -382,6 +382,25 @@ public: static TextLabel New(const std::string& text); /** + * @brief Creates the TextLabel control with additional behavior. + * + * @SINCE_2_1.8 + * @param[in] additionalBehaviour Additional control behaviour + * @return A handle to the TextLabel control + */ + static TextLabel New(ControlBehaviour additionalBehaviour); + + /** + * @brief Creates the TextLabel control with additional behavior. + * + * @SINCE_2_1.8 + * @param[in] additionalBehaviour Additional control behaviour + * @param[in] text The text to display + * @return A handle to the TextLabel control + */ + static TextLabel New(ControlBehaviour additionalBehaviour, const std::string& text); + + /** * @brief Creates an empty handle. * @SINCE_1_0.0 */