1 /* 2 * Copyright (c) 2021-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_V2_INSPECTOR_INSPECTOR_COMPOSED_ELEMENT_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_INSPECTOR_INSPECTOR_COMPOSED_ELEMENT_H 18 19 #include <tuple> 20 21 #include "base/geometry/matrix4.h" 22 #include "core/components/box/render_box.h" 23 #include "core/components/display/display_component.h" 24 #include "core/components_v2/inspector/inspector_node.h" 25 #include "core/pipeline/base/composed_element.h" 26 27 namespace OHOS::Ace::V2 { 28 29 class ACE_EXPORT InspectorComposedElement : public ComposedElement, public InspectorNode { 30 DECLARE_ACE_TYPE(InspectorComposedElement, ComposedElement, InspectorNode) 31 32 public: 33 explicit InspectorComposedElement(const ComposeId& id); 34 ~InspectorComposedElement() override; 35 36 void Prepare(const WeakPtr<Element>& weakParent) override; 37 void Update() override; 38 bool CanUpdate(const RefPtr<Component>& newComponent) override; 39 template<class T> GetInspectorElement(IdType typeId)40 RefPtr<T> GetInspectorElement(IdType typeId) const 41 { 42 auto child = children_.empty() ? nullptr : children_.front(); 43 while (child) { 44 auto inspectorComposedElement = AceType::DynamicCast<InspectorComposedElement>(child); 45 if (inspectorComposedElement) { 46 return nullptr; 47 } 48 if (AceType::TypeId(child) == typeId) { 49 return AceType::DynamicCast<T>(child->GetRenderNode()); 50 } 51 52 child = child->GetChildren().empty() ? nullptr : child->GetChildren().front(); 53 } 54 return nullptr; 55 } 56 void AddComposedComponentId(); 57 void RemoveInspectorNode(int32_t id); 58 RefPtr<RenderNode> GetInspectorNode(IdType typeId, bool isForward = false) const; 59 60 void OnInactive() override; 61 void OnActive() override; 62 63 template<class T> 64 RefPtr<T> GetContentElement(IdType typeId, bool isFindAll = true) const 65 { 66 auto child = children_.empty() ? nullptr : children_.front(); 67 while (child) { 68 LOGD("GetContentElement: child = %{public}s", AceType::TypeName(child)); 69 auto inspectorComposedElement = AceType::DynamicCast<InspectorComposedElement>(child); 70 if (inspectorComposedElement && !isFindAll) { 71 return nullptr; 72 } 73 if (AceType::TypeId(child) == typeId) { 74 return AceType::DynamicCast<T>(child); 75 } 76 child = child->GetChildren().empty() ? nullptr : child->GetChildren().front(); 77 } 78 return nullptr; 79 } 80 81 template<class T> GetContentRender(IdType typeId)82 RefPtr<T> GetContentRender(IdType typeId) const 83 { 84 auto child = children_.empty() ? nullptr : children_.front(); 85 while (child) { 86 if (AceType::TypeId(child) == typeId) { 87 return AceType::DynamicCast<T>(child->GetRenderNode()); 88 } 89 child = child->GetChildren().empty() ? nullptr : child->GetChildren().front(); 90 } 91 return nullptr; 92 } 93 GetInspectorComposedElement()94 RefPtr<Element> GetInspectorComposedElement() 95 { 96 auto child = children_.empty() ? nullptr : children_.front(); 97 while (child) { 98 auto inspectorComposedElement = AceType::DynamicCast<InspectorComposedElement>(child); 99 if (inspectorComposedElement) { 100 return child; 101 } 102 child = child->GetChildren().empty() ? nullptr : child->GetChildren().front(); 103 } 104 return nullptr; 105 } 106 107 RefPtr<Element> GetElementChildBySlot(const RefPtr<Element>& element, int32_t& slot) const; 108 RefPtr<Element> GetInspectorComposedElementParent(const RefPtr<Element>& element) const; 109 110 // dimension settings 111 std::string GetWidth() const override; 112 std::string GetHeight() const override; 113 std::unique_ptr<JsonValue> GetSize() const override; 114 std::string GetPadding() const override; 115 Dimension GetMargin(OHOS::Ace::AnimatableType type) const override; 116 std::string GetAllMargin() const override; 117 std::string GetConstraintSize() const override; 118 int32_t GetLayoutPriority() const override; 119 int32_t GetLayoutWeight() const override; 120 121 // position settings 122 std::string GetAlign() const override; 123 std::string GetDirectionStr() const override; 124 TextDirection GetDirection() const override; 125 std::unique_ptr<JsonValue> GetPosition() const override; 126 std::unique_ptr<JsonValue> GetMarkAnchor() const override; 127 std::unique_ptr<JsonValue> GetOffset() const override; 128 std::string GetRect() override; 129 Rect GetParentRect() const override; 130 131 // layout constraint 132 double GetAspectRatio() const override; 133 int32_t GetDisplayPriority() const override; 134 135 // flex layout 136 std::string GetFlexBasis() const override; 137 double GetFlexGrow() const override; 138 double GetFlexShrink() const override; 139 std::string GetAlignSelf() const override; 140 141 // border settings 142 Border GetBorder() const override; 143 std::unique_ptr<JsonValue> GetUnifyBorder() const override; 144 std::string GetBorderStyle() const override; 145 std::string GetBorderWidth() const override; 146 std::string GetBorderColor() const override; 147 std::string GetBorderRadius() const override; 148 149 // background settings 150 RefPtr<Decoration> GetBackDecoration() const override; 151 std::string GetBackgroundImage() const override; 152 std::string GetBackgroundColor() const override; 153 std::string GetBackgroundImageSize() const override; 154 std::string GetBackgroundImagePosition() const override; 155 std::string GetAlignmentType(double width, double height) const override; 156 157 // front decoration settings 158 RefPtr<Decoration> GetFrontDecoration() const override; 159 160 // opacity settings 161 double GetOpacity() const override; 162 163 // visibility settings 164 std::string GetVisibility() const override; 165 166 // enable settings 167 bool GetEnabled() const override; 168 169 // zindex settings 170 int32_t GetZIndex() const override; 171 172 // graphical transformation 173 DimensionOffset GetOriginPoint() const override; 174 std::unique_ptr<JsonValue> GetRotate() const override; 175 std::unique_ptr<JsonValue> GetScale() const override; 176 std::unique_ptr<JsonValue> GetTransform() const override; 177 std::unique_ptr<JsonValue> GetTranslate() const override; 178 179 double GetBlur() const override; 180 double GetBackDropBlur() const override; 181 std::unique_ptr<JsonValue> GetWindowBlur() const override; 182 std::unique_ptr<JsonValue> GetShadow() const override; 183 double GetBrightness() const override; 184 double GetSaturate() const override; 185 double GetContrast() const override; 186 double GetInvert() const override; 187 double GetSepia() const override; 188 double GetGrayScale() const override; 189 double GetHueRotate() const override; 190 std::string GetColorBlend() const override; 191 192 // shape clip 193 std::string GetClip() const override; 194 bool GetClipFlag() const; 195 std::unique_ptr<JsonValue> GetMask() const override; 196 197 // grid setting 198 int32_t GetGridSpan() const override; 199 int32_t GetGridOffset() const override; 200 std::unique_ptr<JsonValue> GetUseSizeType() const override; 201 RefPtr<GridColumnInfo> GetGridColumnInfo() const override; 202 203 // useAlign seeting 204 std::unique_ptr<JsonValue> GetUseAlign() const override; 205 std::unique_ptr<JsonValue> ToJsonObject() const override; 206 207 std::unique_ptr<JsonValue> GetOverlay() const override; 208 209 // color gradient 210 std::unique_ptr<JsonValue> GetLinearGradient() const override; 211 std::unique_ptr<JsonValue> GetSweepGradient() const override; 212 std::unique_ptr<JsonValue> GetRadialGradient() const override; 213 void GetColorsAndRepeating(std::unique_ptr<JsonValue>& resultJson, const Gradient& gradient) const; 214 215 // bindpopup 216 virtual std::string GetBindPopup() const override; GetTargetTypeId()217 virtual AceType::IdType GetTargetTypeId() const 218 { 219 return AceType::TypeId(this); 220 } 221 222 // bindcontextmenu 223 std::string GetBindContextMenu() const override; 224 AddChildWithSlot(int32_t slot,const RefPtr<Component> & newComponent)225 virtual void AddChildWithSlot(int32_t slot, const RefPtr<Component>& newComponent) 226 { 227 LOGW("inspector AddChildWithSlot"); 228 } 229 UpdateChildWithSlot(int32_t slot,const RefPtr<Component> & newComponent)230 virtual void UpdateChildWithSlot(int32_t slot, const RefPtr<Component>& newComponent) 231 { 232 LOGW("inspector UpdateChildWithSlot"); 233 } 234 DeleteChildWithSlot(int32_t slot)235 virtual void DeleteChildWithSlot(int32_t slot) 236 { 237 LOGW("inspector DeleteChildWithSlot"); 238 } 239 240 void UpdateEventTarget(BaseEventInfo& info) const override; 241 242 std::pair<Rect, Offset> GetCurrentRectAndOrigin() const override; 243 IsRectValid()244 bool IsRectValid() const 245 { 246 return isRectValid_; 247 } 248 SetKey(const std::string & key)249 void SetKey(const std::string& key) 250 { 251 key_ = key; 252 } 253 GetKey()254 const std::string& GetKey() const 255 { 256 return key_; 257 } 258 259 const std::string& GetTag() const; 260 bool GetClickable() const override; 261 bool GetCheckable() const override; 262 bool GetFocusable() const override; 263 bool GetScrollable() const override; 264 bool GetLongClickable() const override; 265 bool IsSelected() const override; 266 bool IsPassword() const override; 267 bool IsChecked() const override; 268 bool IsFocused() const override; 269 270 protected: 271 RefPtr<RenderBox> GetRenderBox() const; 272 273 RefPtr<AccessibilityNode> accessibilityNode_; 274 bool accessibilityEnabled_ = false; 275 RefPtr<AccessibilityNode> GetAccessibilityNode() const; 276 277 private: 278 bool isRectValid_; 279 std::string key_; 280 }; 281 282 } // namespace OHOS::Ace::V2 283 284 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_INSPECTOR_INSPECTOR_COMPOSED_ELEMENT_H 285