diff --git a/frameworks/src/core/base/key_parser.cpp b/frameworks/src/core/base/key_parser.cpp index 94c9e71..c7758cd 100644 --- a/frameworks/src/core/base/key_parser.cpp +++ b/frameworks/src/core/base/key_parser.cpp @@ -560,6 +560,9 @@ uint16_t KeyParser::ParseKeyId(const char *s, const size_t len) if (!strcmp(s, "crollamount")) { return K_SCROLLAMOUNT; } + if (!strcmp(s, "crolldelay")) { + return K_SCROLLDELAY; + } if (!strcmp(s, "crollend")) { return K_SCROLLEND; } @@ -715,9 +718,9 @@ uint16_t KeyParser::ParseKeyId(const char *s, const size_t len) break; case 'u': #ifdef FEATURE_NUMBER_FORMAT - if (!strcmp(s, "seGrouping")) { - return K_USEGROUP; - } + if (!strcmp(s, "seGrouping")) { + return K_USEGROUP; + } #endif // FEATURE_NUMBER_FORMAT break; case 'v': diff --git a/frameworks/src/core/base/keys.h b/frameworks/src/core/base/keys.h index 814b575..00e25ac 100755 --- a/frameworks/src/core/base/keys.h +++ b/frameworks/src/core/base/keys.h @@ -218,6 +218,7 @@ enum { KEYWORD(ROW_REVERSE, row-reverse) // layout style KEYWORD(SCALE_DOWN, scaleDown) // image component scale down KEYWORD(SCROLLAMOUNT, scrollamount) // marquee scroll speed + KEYWORD(SCROLLDELAY, scrolldelay) // marquee scroll delay KEYWORD(SCROLLEND, scrollend) // scroll end event listener KEYWORD(SCROLLSTART, scrollstart) // scroll start event listener #ifdef FEATURE_COMPONENT_ANALOG_CLOCK diff --git a/frameworks/src/core/components/marquee_component.cpp b/frameworks/src/core/components/marquee_component.cpp index 090ba2b..d528506 100644 --- a/frameworks/src/core/components/marquee_component.cpp +++ b/frameworks/src/core/components/marquee_component.cpp @@ -13,12 +13,16 @@ * limitations under the License. */ #include "marquee_component.h" +#include "ace_log.h" +#include "js_app_context.h" #include "key_parser.h" #include "keys.h" namespace OHOS { namespace ACELite { -MarqueeComponent::MarqueeComponent(jerry_value_t options, jerry_value_t children, AppStyleManager* styleManager) +static constexpr uint16_t MILLISECONDS_PER_SECOND = 1000; + +MarqueeComponent::MarqueeComponent(jerry_value_t options, jerry_value_t children, AppStyleManager *styleManager) : TextComponent(options, children, styleManager) { SetComponentName(K_MARQUEE); @@ -31,12 +35,67 @@ bool MarqueeComponent::CreateNativeViews() if (uiLabel != nullptr) { // default mode, speed uiLabel->SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE); - uiLabel->SetRollSpeed(DEFAULT_SPEED); + SetRollSpeed(); return true; } } return false; } + +bool MarqueeComponent::SetPrivateAttribute(uint16_t attrKeyId, jerry_value_t attrValue) +{ + bool isSuccess = TextComponent::SetPrivateAttribute(attrKeyId, attrValue); + if (!isSuccess) { + switch (attrKeyId) { + case K_SCROLLAMOUNT: { + SetScrollamount(IntegerOf(attrValue)); + break; + } + case K_SCROLLDELAY: { + SetScrolldelay(IntegerOf(attrValue)); + break; + } + default: { + return false; + } + } + } + return true; +} + +void MarqueeComponent::SetScrollamount(uint16_t scrollamount) +{ + scrollamount_ = scrollamount; + SetRollSpeed(); +} + +void MarqueeComponent::SetScrolldelay(uint16_t scrolldelay) +{ + const int16_t minScrolldelay = 60; + if (scrolldelay >= minScrolldelay) { + scrolldelay_ = scrolldelay; + } else { + scrolldelay_ = minScrolldelay; + } + SetRollSpeed(); +} + +void MarqueeComponent::SetRollSpeed() +{ + UILabelTypeWrapper *uiLabel = TextComponent::GetUILabelView(); + if (uiLabel != nullptr) { + const int32_t supportScrolldelayApiVersion = 5; + if (JsAppContext::GetInstance()->GetTargetApi() >= supportScrolldelayApiVersion) { + uint32_t rollSpeed = (uint32_t)scrollamount_ * MILLISECONDS_PER_SECOND / scrolldelay_; + if (rollSpeed > UINT16_MAX) { + rollSpeed = UINT16_MAX; + } + uiLabel->SetRollSpeed(rollSpeed); + } else { + uiLabel->SetRollSpeed(scrollamount_); + } + } +} } // namespace ACELite } // namespace OHOS diff --git a/frameworks/src/core/components/marquee_component.h b/frameworks/src/core/components/marquee_component.h index 6a3c2e3..9d00fd6 100644 --- a/frameworks/src/core/components/marquee_component.h +++ b/frameworks/src/core/components/marquee_component.h @@ -21,17 +21,23 @@ namespace OHOS { namespace ACELite { class MarqueeComponent final : public TextComponent { -// default animator speed value -static constexpr int16_t DEFAULT_SPEED = 6; - public: ACE_DISALLOW_COPY_AND_MOVE(MarqueeComponent); MarqueeComponent() = delete; - MarqueeComponent(jerry_value_t options, jerry_value_t children, AppStyleManager* styleManager); + MarqueeComponent(jerry_value_t options, jerry_value_t children, AppStyleManager *styleManager); ~MarqueeComponent() override {} protected: bool CreateNativeViews() override; + bool SetPrivateAttribute(uint16_t attrKeyId, jerry_value_t attrValue) override; + +private: + void SetScrollamount(uint16_t scrollamount); + void SetScrolldelay(uint16_t scrolldelay); + void SetRollSpeed(); + + uint16_t scrollamount_ = 6; + uint16_t scrolldelay_ = 85; }; } // namespace ACELite } // namespace OHOS diff --git a/frameworks/src/core/components/text_component.cpp b/frameworks/src/core/components/text_component.cpp index 4822cc2..9faad29 100644 --- a/frameworks/src/core/components/text_component.cpp +++ b/frameworks/src/core/components/text_component.cpp @@ -72,18 +72,6 @@ bool TextComponent::SetPrivateAttribute(uint16_t attrKeyId, jerry_value_t attrVa textValue_ = MallocStringOf(attrValue); break; } - case K_SCROLLAMOUNT: { - const uint16_t scrollAmount = IntegerOf(attrValue); - const uint16_t thousand = 1000; - if (scrollAmount > (UINT16_MAX / thousand)) { - HILOG_ERROR(HILOG_MODULE_ACE, "marquee speed is overflow"); - break; - } - const uint8_t rate = 85; - uint16_t speed = scrollAmount * thousand / rate; - uiLabel_.SetRollSpeed(speed); - break; - } default: { return false; } diff --git a/frameworks/tools/qt/simulator/jsfwk/targets/simulator/acelite_config.h b/frameworks/tools/qt/simulator/jsfwk/targets/simulator/acelite_config.h index 14ba3c7..e7edb28 100644 --- a/frameworks/tools/qt/simulator/jsfwk/targets/simulator/acelite_config.h +++ b/frameworks/tools/qt/simulator/jsfwk/targets/simulator/acelite_config.h @@ -46,7 +46,10 @@ #define FEATURE_TEST_IMPLEMENTATION #endif +#define FEATURE_API_VERSION + #ifndef QT_SIMULATOR + /** * enable FeatureAbility API */ @@ -142,7 +145,6 @@ #endif #endif - #ifdef _WIN32 #define PROFILER_ENABLE_FLAG_FILE "..\\profiler_enable" #ifdef SIMULATOR_MEMORY_ANALYSIS diff --git a/frameworks/tools/qt/simulator/jsfwk/targets/simulator/mock/bms_interfaces/bundle_manager_mock.cpp b/frameworks/tools/qt/simulator/jsfwk/targets/simulator/mock/bms_interfaces/bundle_manager_mock.cpp index 0f88e9b..1dc1d44 100644 --- a/frameworks/tools/qt/simulator/jsfwk/targets/simulator/mock/bms_interfaces/bundle_manager_mock.cpp +++ b/frameworks/tools/qt/simulator/jsfwk/targets/simulator/mock/bms_interfaces/bundle_manager_mock.cpp @@ -30,9 +30,9 @@ uint8_t GetBundleInfo(const char *bundleName, int32_t flags, BundleInfo *bundleI return UINT8_MAX; } - const uint8_t mockCompatibleApi = 5; + const uint8_t mockCompatibleApi = 6; bundleInfo->compatibleApi = mockCompatibleApi; - const uint8_t mockTargetApi = 4; + const uint8_t mockTargetApi = 6; bundleInfo->targetApi = mockTargetApi; return 0;