1 /* 2 * Copyright (c) 2024 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 FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_BASE_PROPERTIES_COMMON_DECORATION_H 16 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_BASE_PROPERTIES_COMMON_DECORATION_H 17 18 #include "core/components/common/properties/color.h" 19 20 namespace OHOS::Ace { 21 enum class BlurStyle { 22 NO_MATERIAL = 0, 23 THIN, 24 REGULAR, 25 THICK, 26 BACKGROUND_THIN, 27 BACKGROUND_REGULAR, 28 BACKGROUND_THICK, 29 BACKGROUND_ULTRA_THICK, 30 COMPONENT_ULTRA_THIN, 31 COMPONENT_THIN, 32 COMPONENT_REGULAR, 33 COMPONENT_THICK, 34 COMPONENT_ULTRA_THICK, 35 COMPONENT_ULTRA_THICK_WINDOW 36 }; 37 38 enum class AdaptiveColor { 39 DEFAULT = 0, 40 AVERAGE, 41 }; 42 43 enum class EffectType { 44 DEFAULT = 0, 45 WINDOW_EFFECT = 1 46 }; 47 48 enum class TransitionHierarchyStrategy { 49 NONE = 0, 50 ADAPTIVE, 51 }; 52 53 struct BlurOption { 54 std::vector<float> grayscale; 55 }; 56 57 enum class BlurStyleActivePolicy { 58 FOLLOWS_WINDOW_ACTIVE_STATE = 0, 59 ALWAYS_ACTIVE = 1, 60 ALWAYS_INACTIVE = 2, 61 }; 62 63 enum class BlurType { 64 WITHIN_WINDOW = 0, 65 BEHIND_WINDOW = 1 66 }; 67 68 struct EffectOption { 69 Dimension radius; 70 double saturation { 1.0f }; 71 double brightness { 1.0f }; 72 Color color { Color::TRANSPARENT }; 73 AdaptiveColor adaptiveColor = AdaptiveColor::DEFAULT; 74 BlurOption blurOption; 75 BlurType blurType = BlurType::WITHIN_WINDOW; 76 BlurStyleActivePolicy policy = BlurStyleActivePolicy::ALWAYS_ACTIVE; 77 Color inactiveColor { Color::TRANSPARENT }; 78 bool isValidColor = false; 79 bool isWindowFocused = true; 80 bool operator == (const EffectOption &other) const 81 { 82 return radius == other.radius && NearEqual(saturation, other.saturation) && 83 NearEqual(brightness, other.brightness) && color == other.color && adaptiveColor == other.adaptiveColor && 84 policy == other.policy && blurType == other.blurType && 85 inactiveColor == other.inactiveColor && isValidColor == other.isValidColor && 86 isWindowFocused == other.isWindowFocused; 87 } 88 ToJsonValueEffectOption89 void ToJsonValue(std::unique_ptr<JsonValue> &json, const NG::InspectorFilter &filter) const 90 { 91 json->PutExtAttr("backgroundEffect", ToJsonValue(), filter); 92 } 93 ToJsonValueEffectOption94 std::unique_ptr<JsonValue> ToJsonValue() const 95 { 96 static const char* ADAPTIVE_COLOR[] = { "AdaptiveColor.Default", "AdaptiveColor.Average" }; 97 static const char* POLICY[] = { "BlurStyleActivePolicy.FOLLOWS_WINDOW_ACTIVE_STATE", 98 "BlurStyleActivePolicy.ALWAYS_ACTIVE", "BlurStyleActivePolicy.ALWAYS_INACTIVE" }; 99 static const char* BLUR_TYPE[] = { "WITHIN_WINDOW", "BEHIND_WINDOW" }; 100 auto jsonEffect = JsonUtil::Create(true); 101 auto jsonBrightnessOption = JsonUtil::Create(true); 102 jsonBrightnessOption->Put("radius", radius.Value()); 103 jsonBrightnessOption->Put("saturation", saturation); 104 jsonBrightnessOption->Put("brightness", brightness); 105 jsonBrightnessOption->Put("color", color.ColorToString().c_str()); 106 jsonBrightnessOption->Put("adaptiveColor", ADAPTIVE_COLOR[static_cast<int32_t>(adaptiveColor)]); 107 jsonBrightnessOption->Put("policy", POLICY[static_cast<int>(policy)]); 108 jsonBrightnessOption->Put("type", BLUR_TYPE[static_cast<int>(blurType)]); 109 jsonBrightnessOption->Put("inactiveColor", inactiveColor.ColorToString().c_str()); 110 auto grayscale = "[0,0]"; 111 if (blurOption.grayscale.size() > 1) { 112 grayscale = 113 ("[" + std::to_string(blurOption.grayscale[0]) + "," + std::to_string(blurOption.grayscale[1]) + "]") 114 .c_str(); 115 } 116 jsonBrightnessOption->Put("blurOption", grayscale); 117 jsonEffect->Put("options", jsonBrightnessOption); 118 return jsonEffect; 119 } 120 }; 121 } // namespace OHOS::Ace 122 123 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_BASE_PROPERTIES_COMMON_DECORATION_H