1 /* 2 * Copyright (c) 2022-2023 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_NG_MOCK_RENDER_CONTEXT_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_MOCK_RENDER_CONTEXT_H 18 19 #include "gmock/gmock.h" 20 21 #include "base/geometry/ng/point_t.h" 22 #include "base/geometry/ng/rect_t.h" 23 #include "core/components_ng/base/frame_node.h" 24 #include "core/components_ng/render/render_context.h" 25 26 namespace OHOS::Ace::NG { 27 class MockRenderContext : public RenderContext { 28 DECLARE_ACE_TYPE(MockRenderContext, RenderContext) 29 public: 30 ~MockRenderContext() override = default; 31 32 MOCK_METHOD1(GetPointWithTransform, void(PointF&)); 33 MOCK_METHOD1(AnimateHoverEffectScale, void(bool)); 34 MOCK_METHOD4(SetBounds, void(float, float, float, float)); 35 MOCK_METHOD1(DoTextureExport, bool(uint64_t)); 36 MOCK_METHOD0(StopTextureExport, bool()); 37 MOCK_METHOD1(GetPointTransform, void(PointF&)); 38 MOCK_METHOD1(GetPointWithRevert, void(PointF&)); 39 MOCK_METHOD1(SetSurfaceRotation, void(bool)); 40 MOCK_METHOD1(SetRenderFit, void(RenderFit)); 41 MOCK_METHOD1(SetSecurityLayer, void(bool)); 42 MOCK_METHOD1(SetContentClip, void(const std::variant<RectF, RefPtr<ShapeRect>>&)); 43 SetVisible(bool visible)44 void SetVisible(bool visible) override 45 { 46 isVisible_ = visible; 47 } 48 ResetBlendBgColor()49 void ResetBlendBgColor() override 50 { 51 blendColor_ = Color::TRANSPARENT; 52 } 53 BlendBgColor(const Color & color)54 void BlendBgColor(const Color& color) override 55 { 56 blendColor_ = color; 57 } 58 UpdatePaintRect(const RectF & rect)59 void UpdatePaintRect(const RectF& rect) override 60 { 61 paintRect_ = rect; 62 } 63 64 void SavePaintRect(bool isRound = true, uint16_t flag = 0) override 65 { 66 auto host = GetHost(); 67 CHECK_NULL_VOID(host); 68 auto geometryNode = host->GetGeometryNode(); 69 CHECK_NULL_VOID(geometryNode); 70 paintRect_ = geometryNode->GetFrameRect(); 71 } 72 GetPaintRectWithTransform()73 RectF GetPaintRectWithTransform() override 74 { 75 return rect_; 76 } 77 SetPaintRectWithTransform(const RectF rect)78 void SetPaintRectWithTransform(const RectF rect) 79 { 80 rect_ = rect; 81 } 82 GetPaintRectWithoutTransform()83 RectF GetPaintRectWithoutTransform() override 84 { 85 return paintRect_; 86 } 87 88 #ifdef ENHANCED_ANIMATION 89 void AttachNodeAnimatableProperty(RefPtr<NodeAnimatablePropertyBase> modifier) override; DetachNodeAnimatableProperty(const RefPtr<NodeAnimatablePropertyBase> & modifier)90 void DetachNodeAnimatableProperty(const RefPtr<NodeAnimatablePropertyBase>& modifier) override {} 91 92 void CancelTranslateXYAnimation() override; 93 OffsetF GetTranslateXYProperty() override; 94 void UpdateTranslateInXY(const OffsetF& offset) override; 95 #endif 96 UpdateBackBlurStyle(const std::optional<BlurStyleOption> & bgBlurStyle)97 void UpdateBackBlurStyle(const std::optional<BlurStyleOption>& bgBlurStyle) 98 { 99 const auto& groupProperty = GetOrCreateBackground(); 100 groupProperty->propBlurStyleOption = bgBlurStyle; 101 } 102 UpdateMotionBlur(const MotionBlurOption & motionBlurOption)103 void UpdateMotionBlur(const MotionBlurOption& motionBlurOption) 104 { 105 const auto& groupProperty = GetOrCreateForeground(); 106 groupProperty->propMotionBlur = motionBlurOption; 107 } 108 CalcExpectedFrameRate(const std::string & scene,float speed)109 int32_t CalcExpectedFrameRate(const std::string& scene, float speed) 110 { 111 return 0; 112 } 113 SetOpacityMultiplier(float opacity)114 void SetOpacityMultiplier(float opacity) 115 { 116 opacityMultiplier_ = opacity; 117 } 118 119 bool isVisible_ = true; 120 RectF rect_; 121 RectF paintRect_; 122 Color blendColor_ = Color::TRANSPARENT; 123 RefPtr<AnimatablePropertyOffsetF> translateXY_; 124 float opacityMultiplier_ = 1.0f; 125 }; 126 } // namespace OHOS::Ace::NG 127 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_MOCK_RENDER_CONTEXT_H 128