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 
16 #ifndef OHOS_ACELITE_APP_STYLE_SHEET_H
17 #define OHOS_ACELITE_APP_STYLE_SHEET_H
18 
19 #include "non_copyable.h"
20 #include "scope_js_value.h"
21 #include "stylemgr/app_style_item.h"
22 #include "stylemgr/app_style_list.h"
23 
24 namespace OHOS {
25 namespace ACELite {
26 class AppStyleSheet final : public MemoryHeap {
27 public:
28     ACE_DISALLOW_COPY_AND_MOVE(AppStyleSheet);
AppStyleSheet()29     AppStyleSheet() : idSelectors_(nullptr), classSelectors_(nullptr), keyFrameSelectors_(nullptr) {}
~AppStyleSheet()30     ~AppStyleSheet()
31     {
32         Reset();
33     }
34     void InitSheet(jerry_value_t jsObj);
35     void Reset();
36     AppStyle* GetStyleFromIDSelectors(const char * const name) const;
37     AppStyle* GetStyleFromClassSelectors(const char * const name) const;
38     AppStyle* GetStyleFromKeyFramesSelectors(const char * const name) const;
39     AppStyle* GetStyleFromSelectors(AppStyleList* selectors, const char * const name) const;
40     AppStyleList* idSelectors_;
41     AppStyleList* classSelectors_;
42     AppStyleList* keyFrameSelectors_;
43 
44 private:
45     void InitNormalSelectors(const jerry_value_t styleSheetObj, bool overwrite = false);
46     void InitMediaSelectors(const jerry_value_t styleSheetObj);
47     void HandleSingleMediaItem(const jerry_value_t mediaItem);
48     void InitSelectors(AppStyleList** selectorsList, jerry_value_t selectorsObj,
49                        bool isKeyFrames, bool overwrite = false);
50 };
51 } // namespace ACELite
52 } // namespace OHOS
53 
54 #endif // OHOS_ACELITE_APP_STYLE_SHEET_H
55