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_MANAGER_H 17 #define OHOS_ACELITE_APP_STYLE_MANAGER_H 18 19 #include "keys.h" 20 #include "non_copyable.h" 21 #include "stylemgr/app_style.h" 22 #include "stylemgr/app_style_sheet.h" 23 24 namespace OHOS { 25 namespace ACELite { 26 class Component; 27 class AppStyleManager final : public MemoryHeap { 28 public: 29 ACE_DISALLOW_COPY_AND_MOVE(AppStyleManager); 30 AppStyleManager(); 31 ~AppStyleManager(); 32 33 void InitStyleSheet(jerry_value_t jsStyleSheetObj); 34 const AppStyleSheet* GetStyleSheet(); 35 void ApplyComponentStyles(const jerry_value_t options, Component& curr); 36 void Prepare(); 37 bool isStandardExist(uint16_t styleItemNameId); 38 bool isPseudoExist(uint16_t styleItemNameId, uint16_t type); 39 40 private: 41 void ApplySingleStyle(AppStyle &appStyle, Component &curr); 42 jerry_value_t GetStyleObjFromOptions(jerry_value_t options, const jerry_value_t name); 43 void HandleStaticStyle(const jerry_value_t options, Component& curr); 44 void HandleDynamicStyle(const jerry_value_t options, Component& curr); 45 void HandleIDSelectors(const jerry_value_t options, Component &curr); 46 void HandleClassSelectors(const jerry_value_t options, Component &curr); 47 void HandleSelectors(const jerry_value_t options, const jerry_value_t type, Component &curr); 48 void HandleSingleSelector(const jerry_value_t selectorValue, const jerry_value_t type, Component &curr); 49 void ResetFlags(); 50 void MarkStandardFlag(uint16_t styleItemNameId); 51 void MarkPseudoFlag(uint16_t styleItemNameId, uint16_t type); 52 AppStyleSheet* styleSheet_; 53 54 // prepare jerry string value in advance to speed up 55 jerry_value_t idStrValue_; 56 jerry_value_t attrsStrValue_; 57 jerry_value_t dynamicStyleStrValue_; 58 jerry_value_t staticStyleStrValue_; 59 jerry_value_t staticClassStrValue_; 60 StyleFlag* flags_; 61 uint16_t flagsLen_; 62 static const char * const ID; 63 static const char * const ATTR_STATIC_STYLE; 64 static const char * const ATTR_DYNAMIC_STYLE; 65 static const char * const ATTR_STATIC_CLASS; 66 }; 67 } // namespace ACELite 68 } // namespace OHOS 69 70 #endif // OHOS_ACELITE_APP_STYLE_MANAGER_H 71