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