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(SetHDRBrightness, void(float)); 43 MOCK_METHOD1(SetContentClip, void(const std::variant<RectF, RefPtr<ShapeRect>>&)); 44 MOCK_METHOD0(ResetContentClip, void()); 45 MOCK_METHOD1(SetTransparentLayer, void(bool)); 46 MOCK_METHOD1(SetClipToBounds, void(bool)); 47 MOCK_METHOD1(RemoveOverlayModifier, void(const RefPtr<OverlayModifier>&)); 48 MOCK_METHOD0(UpdateCustomBackground, void()); 49 SetVisible(bool visible)50 void SetVisible(bool visible) override 51 { 52 isVisible_ = visible; 53 } 54 ResetBlendBgColor()55 void ResetBlendBgColor() override 56 { 57 blendColor_ = Color::TRANSPARENT; 58 } 59 BlendBgColor(const Color & color)60 void BlendBgColor(const Color& color) override 61 { 62 blendColor_ = color; 63 } 64 UpdatePaintRect(const RectF & rect)65 void UpdatePaintRect(const RectF& rect) override 66 { 67 paintRect_ = rect; 68 } 69 70 void SavePaintRect(bool isRound = true, uint16_t flag = 0) override 71 { 72 auto host = GetHost(); 73 CHECK_NULL_VOID(host); 74 auto geometryNode = host->GetGeometryNode(); 75 CHECK_NULL_VOID(geometryNode); 76 paintRect_ = geometryNode->GetFrameRect(); 77 } 78 GetPaintRectWithTransform()79 RectF GetPaintRectWithTransform() override 80 { 81 return rect_; 82 } 83 SetPaintRectWithTransform(const RectF rect)84 void SetPaintRectWithTransform(const RectF rect) 85 { 86 rect_ = rect; 87 } 88 GetPaintRectWithoutTransform()89 RectF GetPaintRectWithoutTransform() override 90 { 91 return paintRect_; 92 } 93 94 #ifdef ENHANCED_ANIMATION 95 void AttachNodeAnimatableProperty(RefPtr<NodeAnimatablePropertyBase> modifier) override; DetachNodeAnimatableProperty(const RefPtr<NodeAnimatablePropertyBase> & modifier)96 void DetachNodeAnimatableProperty(const RefPtr<NodeAnimatablePropertyBase>& modifier) override {} 97 98 void CancelTranslateXYAnimation() override; 99 OffsetF GetTranslateXYProperty() override; 100 void UpdateTranslateInXY(const OffsetF& offset) override; 101 #endif 102 103 void UpdateBackBlurStyle( 104 const std::optional<BlurStyleOption>& bgBlurStyle, const SysOptions& sysOptions = SysOptions()) 105 { 106 const auto& groupProperty = GetOrCreateBackground(); 107 groupProperty->propBlurStyleOption = bgBlurStyle; 108 } 109 110 void UpdateBackgroundEffect( 111 const std::optional<EffectOption>& effectOption, const SysOptions& sysOptions = SysOptions()) 112 { 113 const auto& groupProperty = GetOrCreateBackground(); 114 groupProperty->propEffectOption = effectOption; 115 } 116 UpdateMotionBlur(const MotionBlurOption & motionBlurOption)117 void UpdateMotionBlur(const MotionBlurOption& motionBlurOption) 118 { 119 const auto& groupProperty = GetOrCreateForeground(); 120 groupProperty->propMotionBlur = motionBlurOption; 121 } 122 CalcExpectedFrameRate(const std::string & scene,float speed)123 int32_t CalcExpectedFrameRate(const std::string& scene, float speed) 124 { 125 return 0; 126 } 127 SetOpacityMultiplier(float opacity)128 void SetOpacityMultiplier(float opacity) 129 { 130 opacityMultiplier_ = opacity; 131 } 132 HasDisappearTransition()133 bool HasDisappearTransition() const 134 { 135 return hasDisappearTransition_; 136 } 137 SetTransitionOutCallback(std::function<void ()> && callback)138 void SetTransitionOutCallback(std::function<void()>&& callback) 139 { 140 transitionOutCallback_ = std::move(callback); 141 } 142 SetActualForegroundColor(const Color & value)143 void SetActualForegroundColor(const Color& value) override 144 { 145 actualForegroundColor_ = value; 146 } 147 GetAnimationsCount()148 size_t GetAnimationsCount() const override 149 { 150 return animationsCount_; 151 } 152 SetAnimationsCount(size_t count)153 void SetAnimationsCount(size_t count) 154 { 155 animationsCount_ = count; 156 } 157 158 bool isVisible_ = true; 159 bool hasDisappearTransition_ = false; 160 RectF rect_; 161 RectF paintRect_; 162 Color blendColor_ = Color::TRANSPARENT; 163 RefPtr<AnimatablePropertyOffsetF> translateXY_; 164 float opacityMultiplier_ = 1.0f; 165 std::function<void()> transitionOutCallback_; 166 Color actualForegroundColor_; 167 168 private: 169 size_t animationsCount_ = 0; 170 }; 171 } // namespace OHOS::Ace::NG 172 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_MOCK_RENDER_CONTEXT_H 173