• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 NWEB_CREAT_WINDOW_H
17 #define NWEB_CREAT_WINDOW_H
18 
19 #include "nweb.h"
20 #include "window.h"
21 
22 #define private public
23 #include "rs_surface_node.h"
24 #undef private
25 
26 namespace OHOS::Rosen {
27 class RSSurfaceMock : public OHOS::Rosen::RSSurface {
28 public:
IsValid()29     bool IsValid() const override
30     {
31         return true;
32     }
33     std::unique_ptr<Rosen::RSSurfaceFrame> RequestFrame(int32_t width, int32_t height,
34         uint64_t uiTimestamp = 0, bool useAFBC = true) override
35     {
36         return nullptr;
37     }
38 
39     bool FlushFrame(std::unique_ptr<Rosen::RSSurfaceFrame>& frame, uint64_t uiTimestamp = 0) override
40     {
41         return true;
42     }
43 
GetRenderContext()44     Rosen::RenderContext* GetRenderContext() override
45     {
46         return nullptr;
47     }
SetRenderContext(Rosen::RenderContext * context)48     void SetRenderContext(Rosen::RenderContext* context) override
49     {}
GetColorSpace()50     ColorGamut GetColorSpace() const override
51     {
52         return ColorGamut::COLOR_GAMUT_STANDARD_BT601;
53     }
SetColorSpace(ColorGamut colorSpace)54     void SetColorSpace(ColorGamut colorSpace) override
55     {}
GetQueueSize()56     uint32_t GetQueueSize() const override
57     {
58         return 1;
59     }
ClearBuffer()60     void ClearBuffer() override
61     {}
62 };
63 }
64 namespace OHOS::NWeb {
65 NWebInitArgs GetInitArgs(void);
66 OHOS::sptr<OHOS::Rosen::Window> CreateWindow(void);
67 
68 class NWebMock : public NWeb {
69 public:
Resize(uint32_t width,uint32_t height)70     void Resize(uint32_t width, uint32_t height) override
71     {}
OnPause()72     void OnPause() const override
73     {}
OnContinue()74     void OnContinue() const override
75     {}
OnDestroy()76     void OnDestroy() override
77     {}
OnFocus()78     void OnFocus() const override
79     {}
OnBlur(const BlurReason & blurReason)80     void OnBlur(const BlurReason& blurReason) const override
81     {}
OnTouchPress(int32_t id,double x,double y)82     void OnTouchPress(int32_t id, double x, double y) override
83     {}
84     void OnTouchRelease(int32_t id, double x = 0, double y = 0) override
85     {}
OnTouchMove(int32_t id,double x,double y)86     void OnTouchMove(int32_t id, double x, double y) override
87     {}
OnTouchCancel()88     void OnTouchCancel() override
89     {}
OnNavigateBack()90     void OnNavigateBack() override
91     {}
SendKeyEvent(int32_t keyCode,int32_t keyAction)92     bool SendKeyEvent(int32_t keyCode, int32_t keyAction) override
93     {
94         return true;
95     }
SendMouseWheelEvent(double x,double y,double deltaX,double deltaY)96     void SendMouseWheelEvent(double x, double y, double deltaX, double deltaY) override
97     {}
SendMouseEvent(int x,int y,int button,int action,int count)98     void SendMouseEvent(int x, int y, int button, int action, int count) override
99     {}
Load(const std::string & url)100     int Load(const std::string& url) const override
101     {
102         return 0;
103     }
IsNavigatebackwardAllowed()104     bool IsNavigatebackwardAllowed() const override
105     {
106         return true;
107     }
IsNavigateForwardAllowed()108     bool IsNavigateForwardAllowed() const override
109     {
110         return true;
111     }
CanNavigateBackOrForward(int numSteps)112     bool CanNavigateBackOrForward(int numSteps) const override
113     {
114         return true;
115     }
NavigateBack()116     void NavigateBack() const override
117     {}
NavigateForward()118     void NavigateForward() const override
119     {}
NavigateBackOrForward(int step)120     void NavigateBackOrForward(int step) const override
121     {}
DeleteNavigateHistory()122     void DeleteNavigateHistory() override
123     {}
Reload()124     void Reload() const override
125     {}
Zoom(float zoomFactor)126     int Zoom(float zoomFactor) const override
127     {
128         return 0;
129     }
ZoomIn()130     int ZoomIn() const override
131     {
132         return 0;
133     }
ZoomOut()134     int ZoomOut() const override
135     {
136         return 0;
137     }
Stop()138     void Stop() const override
139     {}
ExecuteJavaScript(const std::string & code)140     void ExecuteJavaScript(const std::string& code) const override
141     {}
ExecuteJavaScript(const std::string & code,std::shared_ptr<NWebValueCallback<std::string>> callback)142     void ExecuteJavaScript(
143         const std::string& code,
144         std::shared_ptr<NWebValueCallback<std::string>> callback) const override
145     {}
GetPreference()146     const std::shared_ptr<NWebPreference> GetPreference() const override
147     {
148         return nullptr;
149     }
GetWebId()150     unsigned int GetWebId() const override
151     {
152         return 0;
153     }
GetHitTestResult()154     HitTestResult GetHitTestResult() const override
155     {
156         HitTestResult test;
157         return test;
158     }
PutBackgroundColor(int color)159     void PutBackgroundColor(int color) const override
160     {}
InitialScale(float scale)161     void InitialScale(float scale) const override
162     {}
PutDownloadCallback(std::shared_ptr<NWebDownloadCallback> downloadListener)163     void PutDownloadCallback(
164         std::shared_ptr<NWebDownloadCallback> downloadListener) override
165     {}
PutReleaseSurfaceCallback(std::shared_ptr<NWebReleaseSurfaceCallback> releaseSurfaceListener)166     void PutReleaseSurfaceCallback(
167         std::shared_ptr<NWebReleaseSurfaceCallback> releaseSurfaceListener) override
168     {}
SetNWebHandler(std::shared_ptr<NWebHandler> handler)169     void SetNWebHandler(std::shared_ptr<NWebHandler> handler) override
170     {}
GetNWebHandler()171     const std::shared_ptr<NWebHandler> GetNWebHandler() const override
172     {
173         return nullptr;
174     }
Title()175     std::string Title() override
176     {
177         return nullptr;
178     }
PageLoadProgress()179     int PageLoadProgress() override
180     {
181         return 0;
182     }
ContentHeight()183     int ContentHeight() override
184     {
185         return 0;
186     }
Scale()187     float Scale() override
188     {
189         return 0;
190     }
Load(std::string & url,std::map<std::string,std::string> additionalHttpHeaders)191     int Load(
192         std::string& url,
193         std::map<std::string, std::string> additionalHttpHeaders) override
194     {
195         return 0;
196     }
LoadWithDataAndBaseUrl(const std::string & baseUrl,const std::string & data,const std::string & mimeType,const std::string & encoding,const std::string & historyUrl)197     int LoadWithDataAndBaseUrl(const std::string& baseUrl,
198                                         const std::string& data,
199                                         const std::string& mimeType,
200                                         const std::string& encoding,
201                                         const std::string& historyUrl) override
202     {
203         return 0;
204     }
LoadWithData(const std::string & data,const std::string & mimeType,const std::string & encoding)205     int LoadWithData(const std::string& data,
206                               const std::string& mimeType,
207                               const std::string& encoding) override
208     {
209         return 0;
210     }
RegisterArkJSfunction(const std::string & object_name,const std::vector<std::string> & method_list)211     void RegisterArkJSfunction(
212         const std::string& object_name,
213         const std::vector<std::string>& method_list) override
214     {}
UnregisterArkJSfunction(const std::string & object_name,const std::vector<std::string> & method_list)215     void UnregisterArkJSfunction(
216         const std::string& object_name,
217         const std::vector<std::string>& method_list) override
218     {}
SetNWebJavaScriptResultCallBack(std::shared_ptr<NWebJavaScriptResultCallBack> callback)219     void SetNWebJavaScriptResultCallBack(
220         std::shared_ptr<NWebJavaScriptResultCallBack> callback) override
221     {}
PutFindCallback(std::shared_ptr<NWebFindCallback> findListener)222     void PutFindCallback(
223         std::shared_ptr<NWebFindCallback> findListener) override
224     {}
FindAllAsync(const std::string & searchStr)225     void FindAllAsync(const std::string &searchStr) const override
226     {}
ClearMatches()227     void ClearMatches() const override
228     {}
FindNext(const bool forward)229     void FindNext(const bool forward) const override
230     {}
StoreWebArchive(const std::string & baseName,bool autoName,std::shared_ptr<NWebValueCallback<std::string>> callback)231     void StoreWebArchive(const std::string &baseName, bool autoName,
232         std::shared_ptr<NWebValueCallback<std::string>> callback) const override
233     {}
CreateWebMessagePorts(std::vector<std::string> & ports)234     void CreateWebMessagePorts(std::vector<std::string>& ports) override
235     {}
PostWebMessage(std::string & message,std::vector<std::string> & ports,std::string & targetUri)236     void PostWebMessage(std::string& message, std::vector<std::string>& ports, std::string& targetUri) override
237     {}
ClosePort(std::string & handle)238     void ClosePort(std::string& handle) override
239     {}
PostPortMessage(std::string & handle,std::shared_ptr<NWebMessage> data)240     void PostPortMessage(std::string& handle, std::shared_ptr<NWebMessage> data) override
241     {}
SetPortMessageCallback(std::string & handle,std::shared_ptr<NWebValueCallback<std::shared_ptr<NWebMessage>>> callback)242     void SetPortMessageCallback(std::string& handle,
243         std::shared_ptr<NWebValueCallback<std::shared_ptr<NWebMessage>>> callback) override
244     {}
SendDragEvent(const DragEvent & dragEvent)245     void SendDragEvent(const DragEvent& dragEvent) const override
246     {}
ClearSslCache()247     void ClearSslCache() override
248     {}
GetUrl()249     std::string GetUrl() const override
250     {
251         return "/data";
252     }
ClearClientAuthenticationCache()253     void ClearClientAuthenticationCache() override
254     {}
UpdateLocale(const std::string & language,const std::string & region)255     void UpdateLocale(const std::string& language, const std::string& region) override
256     {}
257 
GetOriginalUrl()258     const std::string GetOriginalUrl() const override
259     {
260         return "";
261     }
GetFavicon(const void ** data,size_t & width,size_t & height,ImageColorType & colorType,ImageAlphaType & alphaType)262     bool GetFavicon(const void** data, size_t& width, size_t& height,
263         ImageColorType& colorType, ImageAlphaType& alphaType) override
264     {
265         return false;
266     }
PutNetworkAvailable(bool available)267     void PutNetworkAvailable(bool available) override
268     {}
269 
HasImages(std::shared_ptr<NWebValueCallback<bool>> callback)270     void HasImages(std::shared_ptr<NWebValueCallback<bool>> callback) override
271     {}
272 
RemoveCache(bool include_disk_files)273     void RemoveCache(bool include_disk_files) override
274     {}
GetHistoryList()275     std::shared_ptr<NWebHistoryList> GetHistoryList() override
276     {
277         return nullptr;
278     }
SerializeWebState()279     WebState SerializeWebState() override
280     {
281         return nullptr;
282     }
RestoreWebState(WebState state)283     bool RestoreWebState(WebState state) override
284     {
285         return false;
286     }
PageUp(bool top)287     void PageUp(bool top) override
288     {}
PageDown(bool bottom)289     void PageDown(bool bottom) override
290     {}
ScrollTo(float x,float y)291     void ScrollTo(float x, float y) override
292     {}
ScrollBy(float deltaX,float deltaY)293     void ScrollBy(float deltaX, float deltaY) override
294     {}
SlideScroll(float vx,float vy)295     void SlideScroll(float vx, float vy) override
296     {}
NotifyPopupWindowResult(bool result)297     void NotifyPopupWindowResult(bool result) override
298     {}
299 };
300 }
301 #endif
302