1 /*
2  * Copyright (c) 2020-2021 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 #ifndef OHOS_ACELITE_APP_STYLE_H
16 #define OHOS_ACELITE_APP_STYLE_H
17 
18 #include "non_copyable.h"
19 #include "securec.h"
20 #include "stylemgr/app_style_item.h"
21 
22 namespace OHOS {
23 namespace ACELite {
24 class AppStyle final : public MemoryHeap {
25 public:
26     ACE_DISALLOW_COPY_AND_MOVE(AppStyle);
AppStyle()27     AppStyle() : firstStyleItem_(nullptr), lastStyleItem_(nullptr), pre_(nullptr), next_(nullptr), styleName_(nullptr)
28     {
29     }
30 
~AppStyle()31     ~AppStyle()
32     {
33         Reset();
34     }
35 
GetStyleName()36     const char* GetStyleName() const
37     {
38         return styleName_;
39     }
40 
GetFirst()41     const AppStyleItem* GetFirst() const
42     {
43         return firstStyleItem_;
44     }
45 
SetPre(AppStyle * preStyle)46     void SetPre(AppStyle* preStyle)
47     {
48         if (preStyle == nullptr) {
49             return;
50         }
51 
52         pre_ = preStyle;
53     }
54 
GetPre()55     const AppStyle* GetPre() const
56     {
57         return pre_;
58     }
59 
SetNext(AppStyle * nextStyle)60     void SetNext(AppStyle* nextStyle)
61     {
62         if (nextStyle == nullptr) {
63             return;
64         }
65         next_ = nextStyle;
66     }
67 
GetNext()68     const AppStyle* GetNext() const
69     {
70         return next_;
71     }
72 
73     void Reset();
74     void AddStyleItem(AppStyleItem* newStyleItem);
75     const AppStyleItem* GetStyleItemByName(const char * const stylePropName) const;
76     const AppStyleItem* GetStyleItemByNameId(uint16_t stylePropNameId) const;
77     static AppStyle* GenerateFromJS(jerry_value_t styleKey, jerry_value_t styleValue, bool isKeyFrames);
78     static void CombineStyles(AppStyle &dest, const AppStyle &source, bool overwrite = false);
79 
80 private:
81     void SetStyleName(const char * const name, size_t nameLen);
82     static void AddItemsInLoop(jerry_value_t object, AppStyle& newStyle);
83     static void AddKeyFramesItemsInLoop(jerry_value_t objFrom, jerry_value_t objTo, AppStyle& newStyle);
84     static jerry_value_t AddKeyFramesTransformValue(jerry_value_t propValueFrom,
85                                                     jerry_value_t propValueTo,
86                                                     bool& isItemNeedToAdd,
87                                                     jerry_value_t& propKeyFrom);
88     static jerry_value_t ConcatJerryString(jerry_value_t strA, jerry_value_t strB);
89     static bool MergeAnimationString(char* dest, uint16_t destSz, const char * const src1, const char * const src2);
90     const AppStyleItem* firstStyleItem_;
91     AppStyleItem* lastStyleItem_;
92     AppStyle* pre_;
93     AppStyle* next_;
94     char *styleName_;
95 };
96 } // namespace ACELite
97 } // namespace OHOS
98 
99 #endif // OHOS_ACELITE_APP_STYLE_H
100