1 /* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_TEXT_TIMER_MODEL_NG_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_TEXT_TIMER_MODEL_NG_H 18 19 #include "core/components_ng/base/common_configuration.h" 20 #include "core/components_ng/base/frame_node.h" 21 #include "core/components_ng/pattern/texttimer/text_timer_model.h" 22 23 namespace OHOS::Ace::NG { 24 class TextTimerConfiguration : public CommonConfiguration { 25 public: TextTimerConfiguration(double count,bool isCountDown,bool started,int64_t elapsedTime,bool enabled)26 TextTimerConfiguration(double count, bool isCountDown, bool started, int64_t elapsedTime, bool enabled) 27 : CommonConfiguration(enabled), 28 count_(count), 29 isCountDown_(isCountDown), 30 started_(started), 31 elapsedTime_(elapsedTime) 32 {} 33 double count_ = 60000.0; 34 bool isCountDown_ = false; 35 bool started_ = false; 36 uint64_t elapsedTime_ = 0; 37 }; 38 using TextTimerMakeCallback = 39 std::function<RefPtr<FrameNode>(const TextTimerConfiguration& textTimerConfiguration)>; 40 class ACE_EXPORT TextTimerModelNG : public OHOS::Ace::TextTimerModel { 41 public: 42 RefPtr<TextTimerController> Create() override; 43 void SetFormat(const std::string& format) override; 44 void SetIsCountDown(bool isCountDown) override; 45 void SetInputCount(double count) override; 46 void SetOnTimer(std::function<void(int64_t, int64_t)> && onChange) override; 47 void SetFontSize(const Dimension& value) override; 48 void SetTextColor(const Color& value) override; 49 void SetTextColorByUser(bool isSetByUser) override; 50 void SetTextShadow(const std::vector<Shadow>& value) override; 51 void SetItalicFontStyle(Ace::FontStyle value) override; 52 void SetFontWeight(FontWeight value) override; 53 void SetFontFamily(const std::vector<std::string>& value) override; 54 void CreateWithResourceObj(JsTextTimerResourceType jsResourceType, const RefPtr<ResourceObject>& resObj) override; 55 void SetFontSizeByUser(bool value) override; 56 void SetFontWeightByUser(bool value) override; 57 void SetFontFamilyByUser(bool value) override; 58 static RefPtr<FrameNode> CreateFrameNode(int32_t nodeId); 59 static RefPtr<TextTimerController> InitTextController(FrameNode* frameNode); 60 static void SetIsCountDown(FrameNode* frameNode, bool isCountDown); 61 static void SetInputCount(FrameNode* frameNode, double count); 62 static void SetFontColor(FrameNode* frameNode, const Color& value); 63 static void SetFontSize(FrameNode* frameNode, const Dimension& value); 64 static void SetFontStyle(FrameNode* frameNode, Ace::FontStyle value); 65 static void SetFontWeight(FrameNode* frameNode, FontWeight value); 66 static void SetFontFamily(FrameNode* frameNode, const std::vector<std::string>& value); 67 static void SetFormat(FrameNode* frameNode, const std::string& format); 68 static void SetTextShadow(FrameNode* frameNode, const std::vector<Shadow>& value); 69 static void SetBuilderFunc(FrameNode* frameNode, TextTimerMakeCallback&& jsMake); 70 static void SetJSTextTimerController(FrameNode* frameNode, const RefPtr<Referenced>& controller); 71 static void SetOnTimer(FrameNode* frameNode, std::function<void(int64_t, int64_t)>&& onChange); 72 static RefPtr<Referenced> GetJSTextTimerController(FrameNode* frameNode); 73 static void HandleTextColor(FrameNode* frameNode, const RefPtr<ResourceObject>& resObj); 74 static void HandleFontWeight(FrameNode* frameNode, const RefPtr<ResourceObject>& resObj); 75 static void HandleFontSize(FrameNode* frameNode, const RefPtr<ResourceObject>& resObj); 76 static void HandleFontFamily(FrameNode* frameNode, const RefPtr<ResourceObject>& resObj); 77 static void CreateWithResourceObj( 78 FrameNode* frameNode, JsTextTimerResourceType jsResourceType, const RefPtr<ResourceObject>& resObj); 79 static void SetTextColorByUser(FrameNode* frameNode, bool isSetByUser); 80 static void SetFontSizeByUser(FrameNode* frameNode, bool value); 81 static void SetFontWeightByUser(FrameNode* frameNode, bool value); 82 static void SetFontFamilyByUser(FrameNode* frameNode, bool value); 83 }; 84 } // namespace OHOS::Ace::NG 85 86 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_TEXT_TIMER_MODEL_NG_H 87