• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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_PATTERNS_WEB_CORS_WEB_PATTERN_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_WEB_CORS_WEB_PATTERN_H
18 
19 #include <optional>
20 #include <string>
21 #include <utility>
22 
23 #include "base/thread/cancelable_callback.h"
24 #include "base/memory/referenced.h"
25 #include "base/utils/utils.h"
26 #include "base/geometry/axis.h"
27 #include "core/components/dialog/dialog_properties.h"
28 #include "core/components/dialog/dialog_theme.h"
29 #include "core/components/web/web_property.h"
30 #include "core/components_ng/gestures/recognizers/pan_recognizer.h"
31 #include "core/components_ng/manager/select_overlay/select_overlay_manager.h"
32 #include "core/components_ng/manager/select_overlay/select_overlay_proxy.h"
33 #include "core/components_ng/pattern/pattern.h"
34 #include "core/components_ng/pattern/web/web_accessibility_property.h"
35 #include "core/components_ng/pattern/web/web_event_hub.h"
36 #include "core/components_ng/pattern/web/web_layout_algorithm.h"
37 #include "core/components_ng/pattern/web/web_paint_property.h"
38 #include "core/components_ng/pattern/web/web_pattern_property.h"
39 #include "core/components_ng/pattern/web/web_paint_method.h"
40 #include "core/components_ng/pattern/web/web_delegate_interface.h"
41 #include "core/components_ng/property/property.h"
42 #include "core/components_ng/manager/select_overlay/selection_host.h"
43 #include "core/components_ng/render/render_surface.h"
44 #include "core/components_ng/pattern/scrollable/nestable_scroll_container.h"
45 #include "core/components_ng/pattern/scroll/scroll_pattern.h"
46 
47 #include "core/components_ng/pattern/web/web_delegate_interface.h"
48 
49 namespace OHOS::Ace::NG {
50 namespace {
51 struct MouseClickInfo {
52     double x = -1;
53     double y = -1;
54     TimeStamp start;
55 };
56 
57 struct TouchInfo {
58     double x = -1;
59     double y = -1;
60     int32_t id = -1;
61 };
62 
63 struct TouchHandleState {
64     int32_t id = -1;
65     int32_t x = -1;
66     int32_t y = -1;
67     int32_t edge_height = 0;
68 };
69 
70 enum WebOverlayType { INSERT_OVERLAY, SELECTION_OVERLAY, INVALID_OVERLAY };
71 } // namespace
72 
73 enum class WebInfoType : int32_t {
74     TYPE_MOBILE,
75     TYPE_TABLET,
76     TYPE_2IN1,
77     TYPE_UNKNOWN
78 };
79 
80 class WebPattern : public Pattern, public SelectionHost {
81     DECLARE_ACE_TYPE(WebPattern, Pattern, SelectionHost);
82 
83 public:
84     using SetWebIdCallback = std::function<void(int32_t)>;
85     using SetWebDetachCallback = std::function<void(int32_t)>;
86     using SetHapPathCallback = std::function<void(const std::string&)>;
87     using JsProxyCallback = std::function<void()>;
88     using OnControllerAttachedCallback = std::function<void()>;
89     using PermissionClipboardCallback = std::function<void(const std::shared_ptr<BaseEventInfo>&)>;
90     using DefaultFileSelectorShowCallback = std::function<void(const std::shared_ptr<BaseEventInfo>&)>;
91     using OnOpenAppLinkCallback = std::function<void(const std::shared_ptr<BaseEventInfo>&)>;
92     using SetFaviconCallback = std::function<void(const std::shared_ptr<BaseEventInfo>&)>;
93     WebPattern();
94     WebPattern(const std::string& webSrc, const RefPtr<WebController>& webController,
95                RenderMode type = RenderMode::ASYNC_RENDER, bool incognitoMode = false,
96 			   const std::string& sharedRenderProcessToken = "");
97     WebPattern(const std::string& webSrc, const SetWebIdCallback& setWebIdCallback,
98                RenderMode type = RenderMode::ASYNC_RENDER, bool incognitoMode = false,
99 			   const std::string& sharedRenderProcessToken = "");
100 
101     ~WebPattern() override;
102 
103     enum class VkState {
104         VK_NONE,
105         VK_SHOW,
106         VK_HIDE
107     };
108 
GetContextParam()109     std::optional<RenderContext::ContextParam> GetContextParam() const override
110     {
111         if (renderMode_ == RenderMode::SYNC_RENDER) {
112             return RenderContext::ContextParam { RenderContext::ContextType::CANVAS };
113         } else {
114         return RenderContext::ContextParam { RenderContext::ContextType::SURFACE, "RosenWeb" };
115         }
116     }
117 
118     RefPtr<NodePaintMethod> CreateNodePaintMethod() override;
119 
IsAtomicNode()120     bool IsAtomicNode() const override
121     {
122         return true;
123     }
124 
CreateEventHub()125     RefPtr<EventHub> CreateEventHub() override
126     {
127         return MakeRefPtr<WebEventHub>();
128     }
129 
CreateAccessibilityProperty()130     RefPtr<AccessibilityProperty> CreateAccessibilityProperty() override
131     {
132         return MakeRefPtr<WebAccessibilityProperty>();
133     }
134 
135     void OnModifyDone() override;
136 
137     Color GetDefaultBackgroundColor();
138 
SetWebSrc(const std::string & webSrc)139     void SetWebSrc(const std::string& webSrc)
140     {
141         if (webSrc_ != webSrc_) {
142             OnWebSrcUpdate();
143             webSrc_ = webSrc;
144         }
145         if (webPaintProperty_) {
146             webPaintProperty_->SetWebPaintData(webSrc);
147         }
148     }
149 
GetWebSrc()150     const std::optional<std::string>& GetWebSrc() const
151     {
152         return webSrc_;
153     }
154 
SetPopup(bool popup)155     void SetPopup(bool popup)
156     {
157         isPopup_ = popup;
158     }
159 
SetParentNWebId(int32_t parentNWebId)160     void SetParentNWebId(int32_t parentNWebId)
161     {
162         parentNWebId_ = parentNWebId;
163     }
164 
SetWebData(const std::string & webData)165     void SetWebData(const std::string& webData)
166     {
167         if (webData_ != webData) {
168             webData_ = webData;
169             OnWebDataUpdate();
170         }
171         if (webPaintProperty_) {
172             webPaintProperty_->SetWebPaintData(webData);
173         }
174     }
175 
GetWebData()176     const std::optional<std::string>& GetWebData() const
177     {
178         return webData_;
179     }
180 
SetCustomScheme(const std::string & scheme)181     void SetCustomScheme(const std::string& scheme)
182     {
183         customScheme_ = scheme;
184     }
185 
GetCustomScheme()186     const std::optional<std::string>& GetCustomScheme() const
187     {
188         return customScheme_;
189     }
190 
SetWebController(const RefPtr<WebController> & webController)191     void SetWebController(const RefPtr<WebController>& webController)
192     {
193         webController_ = webController;
194     }
195 
GetWebController()196     RefPtr<WebController> GetWebController() const
197     {
198         return webController_;
199     }
200 
SetSetWebIdCallback(SetWebIdCallback && SetIdCallback)201     void SetSetWebIdCallback(SetWebIdCallback&& SetIdCallback)
202     {
203         setWebIdCallback_ = std::move(SetIdCallback);
204     }
205 
GetSetWebIdCallback()206     SetWebIdCallback GetSetWebIdCallback() const
207     {
208         return setWebIdCallback_;
209     }
210 
SetSetWebDetachCallback(SetWebDetachCallback && SetDetachCallback)211     void SetSetWebDetachCallback(SetWebDetachCallback&& SetDetachCallback)
212     {
213         setWebDetachCallback_ = std::move(SetDetachCallback);
214     }
215 
GetSetWebDetachCallback()216     SetWebDetachCallback GetSetWebDetachCallback() const
217     {
218         return setWebDetachCallback_;
219     }
220 
SetRenderMode(RenderMode renderMode)221     void SetRenderMode(RenderMode renderMode)
222     {
223         renderMode_ = renderMode;
224     }
225 
GetRenderMode()226     RenderMode GetRenderMode()
227     {
228         return renderMode_;
229     }
230 
SetIncognitoMode(bool incognitoMode)231     void SetIncognitoMode(bool incognitoMode)
232     {
233         incognitoMode_ = incognitoMode;
234     }
235 
GetIncognitoMode()236     bool GetIncognitoMode() const
237     {
238         return incognitoMode_;
239     }
240 
SetSharedRenderProcessToken(const std::string & sharedRenderProcessToken)241     void SetSharedRenderProcessToken(const std::string& sharedRenderProcessToken)
242     {
243         sharedRenderProcessToken_ = sharedRenderProcessToken;
244     }
245 
GetSharedRenderProcessToken()246     const std::optional<std::string>& GetSharedRenderProcessToken() const
247     {
248         return sharedRenderProcessToken_;
249     }
250 
SetOnControllerAttachedCallback(OnControllerAttachedCallback && callback)251     void SetOnControllerAttachedCallback(OnControllerAttachedCallback&& callback)
252     {
253         onControllerAttachedCallback_ = std::move(callback);
254     }
255 
SetPermissionClipboardCallback(PermissionClipboardCallback && Callback)256     void SetPermissionClipboardCallback(PermissionClipboardCallback&& Callback)
257     {
258         permissionClipboardCallback_ = std::move(Callback);
259     }
260 
GetPermissionClipboardCallback()261     PermissionClipboardCallback GetPermissionClipboardCallback() const
262     {
263         return permissionClipboardCallback_;
264     }
265 
GetOnControllerAttachedCallback()266     OnControllerAttachedCallback GetOnControllerAttachedCallback()
267     {
268         return onControllerAttachedCallback_;
269     }
270 
SetSetHapPathCallback(SetHapPathCallback && callback)271     void SetSetHapPathCallback(SetHapPathCallback&& callback)
272     {
273         setHapPathCallback_ = std::move(callback);
274     }
275 
GetSetHapPathCallback()276     SetHapPathCallback GetSetHapPathCallback() const
277     {
278         return setHapPathCallback_;
279     }
280 
SetJsProxyCallback(JsProxyCallback && jsProxyCallback)281     void SetJsProxyCallback(JsProxyCallback&& jsProxyCallback)
282     {
283         jsProxyCallback_ = std::move(jsProxyCallback);
284     }
285 
CallJsProxyCallback()286     void CallJsProxyCallback()
287     {
288         if (jsProxyCallback_) {
289             jsProxyCallback_();
290         }
291     }
292 
GetWebEventHub()293     RefPtr<WebEventHub> GetWebEventHub()
294     {
295         return GetOrCreateEventHub<WebEventHub>();
296     }
297 
GetFocusPattern()298     FocusPattern GetFocusPattern() const override
299     {
300         return { FocusType::NODE, true };
301     }
302 
CreatePaintProperty()303     RefPtr<PaintProperty> CreatePaintProperty() override
304     {
305         if (!webPaintProperty_) {
306             webPaintProperty_ = MakeRefPtr<WebPaintProperty>();
307             if (!webPaintProperty_) {
308             }
309         }
310         return webPaintProperty_;
311     }
312 
CreateLayoutAlgorithm()313     RefPtr<LayoutAlgorithm> CreateLayoutAlgorithm() override
314     {
315         return MakeRefPtr<WebLayoutAlgorithm>();
316     }
317 
BetweenSelectedPosition(const Offset & globalOffset)318     bool BetweenSelectedPosition(const Offset& globalOffset) override
319     {
320         return false;
321     }
322 
GetDragRecordSize()323     int32_t GetDragRecordSize() override
324     {
325         return 1;
326     }
327 
328     void SetNestedScroll(const NestedScrollOptions& nestedOpt);
329 
330     void SetNestedScrollExt(const NestedScrollOptionsExt& nestedOpt);
331 
332     void OnScrollStart(const float x, const float y);
333     /**
334      *  End of NestableScrollContainer implementations
335      */
336 
337     ACE_DEFINE_PROPERTY_GROUP(WebProperty, WebPatternProperty);
338     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, JsEnabled, bool);
339     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, MediaPlayGestureAccess, bool);
340     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, FileAccessEnabled, bool);
341     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, OnLineImageAccessEnabled, bool);
342     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, DomStorageAccessEnabled, bool);
343     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, ImageAccessEnabled, bool);
344     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, MixedMode, MixedModeContent);
345     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, ZoomAccessEnabled, bool);
346     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, GeolocationAccessEnabled, bool);
347     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, UserAgent, std::string);
348     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, CacheMode, WebCacheMode);
349     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, OverviewModeAccessEnabled, bool);
350     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, FileFromUrlAccessEnabled, bool);
351     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, DatabaseAccessEnabled, bool);
352     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, TextZoomRatio, int32_t);
353     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, WebDebuggingAccessEnabledAndPort,
354         WebPatternProperty::WebDebuggingConfigType);
355     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, BackgroundColor, int32_t);
356     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, InitialScale, float);
357     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, PinchSmoothModeEnabled, bool);
358     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, MultiWindowAccessEnabled, bool);
359     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, AllowWindowOpenMethod, bool);
360     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, WebCursiveFont, std::string);
361     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, WebFantasyFont, std::string);
362     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, WebFixedFont, std::string);
363     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, WebSansSerifFont, std::string);
364     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, WebSerifFont, std::string);
365     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, WebStandardFont, std::string);
366     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, DefaultFixedFontSize, int32_t);
367     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, DefaultFontSize, int32_t);
368     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, DefaultTextEncodingFormat, std::string);
369     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, MinFontSize, int32_t);
370     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, MinLogicalFontSize, int32_t);
371     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, BlockNetwork, bool);
372     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, DarkMode, WebDarkMode);
373     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, ForceDarkAccess, bool);
374     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, AudioResumeInterval, int32_t);
375     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, AudioExclusive, bool);
376     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, AudioSessionType, WebAudioSessionType);
377     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, HorizontalScrollBarAccessEnabled, bool);
378     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, VerticalScrollBarAccessEnabled, bool);
379     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, ScrollBarColor, std::string);
380     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, OverScrollMode, int32_t);
381     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, BlurOnKeyboardHideMode, int32_t);
382     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, TextAutosizing, bool);
383     using NativeVideoPlayerConfigType = std::tuple<bool, bool>;
384     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, NativeVideoPlayerConfig, NativeVideoPlayerConfigType);
385     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, SelectionMenuOptions, WebMenuOptionsParam);
386     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, MetaViewport, bool);
387     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, CopyOptionMode, int32_t);
388     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, NativeEmbedModeEnabled, bool);
389     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, IntrinsicSizeEnabled, bool);
390     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, CssDisplayChangeEnabled, bool);
391     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, NativeEmbedRuleTag, std::string);
392     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, NativeEmbedRuleType, std::string);
393     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, OverlayScrollbarEnabled, bool);
394     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, KeyboardAvoidMode, WebKeyboardAvoidMode);
395     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, EnabledHapticFeedback, bool);
396     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, OptimizeParserBudgetEnabled, bool);
397     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, WebMediaAVSessionEnabled, bool);
398     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, EnableDataDetector, bool);
399     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, BypassVsyncCondition, WebBypassVsyncCondition);
400     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, EnableFollowSystemFontWeight, bool);
401     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, GestureFocusMode, GestureFocusMode);
402     void RequestFullScreen();
403     void ExitFullScreen();
IsFullScreen()404     bool IsFullScreen() const
405     {
406         return isFullScreen_;
407     }
408     void UpdateLocale();
409     void SetDrawRect(int32_t x, int32_t y, int32_t width, int32_t height);
410     void OnCompleteSwapWithNewSize();
411     void OnResizeNotWork();
412     bool OnBackPressed() const;
413     bool OnBackPressedForFullScreen() const;
414     void SetFullScreenExitHandler(const std::shared_ptr<FullScreenEnterEvent>& fullScreenExitHandler);
415     bool NotifyStartDragTask(bool isDelayed = false);
416     void OnContextMenuShow(const std::shared_ptr<BaseEventInfo>& info, bool isRichtext = true, bool result = false);
417     void UpdateJavaScriptOnDocumentStart();
418     void JavaScriptOnDocumentStart(const ScriptItems& scriptItems);
419     void JavaScriptOnDocumentEnd(const ScriptItems& scriptItems);
420     void JavaScriptOnDocumentStartByOrder(const ScriptItems& scriptItems,
421         const ScriptItemsByOrder& scriptItemsByOrder);
422     void JavaScriptOnDocumentEndByOrder(const ScriptItems& scriptItems,
423         const ScriptItemsByOrder& scriptItemsByOrder);
424     bool IsImageDrag();
425     Offset GetDragOffset() const;
426     void RemovePreviewMenuNode();
427     void UpdateImagePreviewParam();
SetLayoutMode(WebLayoutMode mode)428     void SetLayoutMode(WebLayoutMode mode)
429     {
430         layoutMode_ = mode;
431     }
GetLayoutMode()432     WebLayoutMode GetLayoutMode() const
433     {
434         return layoutMode_;
435     }
436     void OnRootLayerChanged(int width, int height);
GetRootLayerWidth()437     int GetRootLayerWidth() const
438     {
439         return rootLayerWidth_;
440     }
GetRootLayerHeight()441     int GetRootLayerHeight() const
442     {
443         return rootLayerHeight_;
444     }
RichTextInit()445     void RichTextInit()
446     {
447         richTextInit_ = true;
448     }
GetRichTextInit()449     bool GetRichTextInit() const
450     {
451         return richTextInit_;
452     }
GetDrawSize()453     Size GetDrawSize() const
454     {
455         return drawSize_;
456     }
IsVirtualKeyBoardShow()457     bool IsVirtualKeyBoardShow() const
458     {
459         // cross platform is not support now;
460         return false;
461     }
462 
463     SizeF GetDragPixelMapSize() const;
464     bool Backward();
465     void OnSelectionMenuOptionsUpdate(const WebMenuOptionsParam& webMenuOption);
466     void UpdateEditMenuOptions(const NG::OnCreateMenuCallback&& onCreateMenuCallback,
467         const NG::OnMenuItemClickCallback&& onMenuItemClick, const NG::OnPrepareMenuCallback&& onPrepareMenuCallback);
468     void UpdateDataDetectorConfig(const TextDetectConfig& config);
469     WebInfoType GetWebInfoType();
470     void SetUpdateInstanceIdCallback(std::function<void(int32_t)> &&callabck);
471 
SetDefaultFileSelectorShowCallback(DefaultFileSelectorShowCallback && Callback)472     void SetDefaultFileSelectorShowCallback(DefaultFileSelectorShowCallback&& Callback)
473     {
474         defaultFileSelectorShowCallback_ = std::move(Callback);
475     }
476 
GetDefaultFileSelectorShowCallback()477     DefaultFileSelectorShowCallback GetDefaultFileSelectorShowCallback()
478     {
479         return defaultFileSelectorShowCallback_;
480     }
481 
SetOnOpenAppLinkCallback(OnOpenAppLinkCallback && callback)482     void SetOnOpenAppLinkCallback(OnOpenAppLinkCallback&& callback)
483     {
484         onOpenAppLinkCallback_ = std::move(callback);
485     }
486 
GetOnOpenAppLinkCallback()487     OnOpenAppLinkCallback GetOnOpenAppLinkCallback() const
488     {
489         return onOpenAppLinkCallback_;
490     }
491 
SetFaviconFunction(OnOpenAppLinkCallback && callback)492     void SetFaviconFunction(OnOpenAppLinkCallback&& callback)
493     {
494         setFaviconCallback_ = std::move(callback);
495     }
496 
GetSetFaviconFunction()497     SetFaviconCallback GetSetFaviconFunction() const
498     {
499         return setFaviconCallback_;
500     }
501 
IsPreviewImageNodeExist()502     bool IsPreviewImageNodeExist() const
503     {
504         // cross platform is not support now;
505         return false;
506     }
507 
SetNewDragStyle(bool isNewDragStyle)508     void SetNewDragStyle(bool isNewDragStyle) {}
509 
IsNewDragStyle()510     bool IsNewDragStyle() const
511     {
512         return false;
513     }
514 
IsDragging()515     bool IsDragging() const
516     {
517         return false;
518     }
519 
520     void SetPreviewSelectionMenu(const std::shared_ptr<WebPreviewSelectionMenuParam>& param);
521 
522     std::shared_ptr<WebPreviewSelectionMenuParam> GetPreviewSelectionMenuParams(
523         const WebElementType& type, const ResponseType& responseType);
524 
525     bool IsPreviewMenuNotNeedShowPreview();
526 
527     bool RunJavascriptAsync(const std::string& jsCode, std::function<void(const std::string&)>&& callback);
528 
529     void JavaScriptOnHeadReadyByOrder(const ScriptItems& scriptItems,
530         const ScriptItemsByOrder& scriptItemsByOrder);
531 
532     void OnWebMediaAVSessionEnabledUpdate(bool enable);
533     void SetDefaultBackgroundColor();
534 private:
535     void RegistVirtualKeyBoardListener();
536     bool ProcessVirtualKeyBoard(int32_t width, int32_t height, double keyboard);
537     void UpdateWebLayoutSize(int32_t width, int32_t height);
538     bool OnDirtyLayoutWrapperSwap(const RefPtr<LayoutWrapper>& dirty, const DirtySwapConfig& config) override;
539 
540     void OnAttachToFrameNode() override;
541     void OnDetachFromFrameNode(FrameNode* frameNode) override;
542     void OnWindowShow() override;
543     void OnWindowHide() override;
544     void OnWindowSizeChanged(int32_t width, int32_t height, WindowSizeChangeReason type) override;
545     void OnInActive() override;
546     void OnActive() override;
547     void OnVisibleChange(bool isVisible) override;
548     void OnAreaChangedInner() override;
549 
550     void OnWebSrcUpdate();
551     void OnWebDataUpdate();
552     void OnJsEnabledUpdate(bool value);
553     void OnMediaPlayGestureAccessUpdate(bool value);
554     void OnFileAccessEnabledUpdate(bool value);
555     void OnOnLineImageAccessEnabledUpdate(bool value);
556     void OnDomStorageAccessEnabledUpdate(bool value);
557     void OnImageAccessEnabledUpdate(bool value);
558     void OnMixedModeUpdate(MixedModeContent value);
559     void OnZoomAccessEnabledUpdate(bool value);
560     void OnGeolocationAccessEnabledUpdate(bool value);
561     void OnUserAgentUpdate(const std::string& value);
562     void OnCacheModeUpdate(WebCacheMode value);
563     void OnOverviewModeAccessEnabledUpdate(bool value);
564     void OnFileFromUrlAccessEnabledUpdate(bool value);
565     void OnDatabaseAccessEnabledUpdate(bool value);
566     void OnTextZoomRatioUpdate(int32_t value);
567     void OnWebDebuggingAccessEnabledAndPortUpdate(
568         const WebPatternProperty::WebDebuggingConfigType& enabled_and_port);
569     void OnPinchSmoothModeEnabledUpdate(bool value);
570     void OnBackgroundColorUpdate(int32_t value);
571     void OnInitialScaleUpdate(float value);
572     void OnMultiWindowAccessEnabledUpdate(bool value);
573     void OnAllowWindowOpenMethodUpdate(bool value);
574     void OnWebCursiveFontUpdate(const std::string& value);
575     void OnWebFantasyFontUpdate(const std::string& value);
576     void OnWebFixedFontUpdate(const std::string& value);
577     void OnWebSerifFontUpdate(const std::string& value);
578     void OnWebSansSerifFontUpdate(const std::string& value);
579     void OnWebStandardFontUpdate(const std::string& value);
580     void OnDefaultFixedFontSizeUpdate(int32_t value);
581     void OnDefaultFontSizeUpdate(int32_t value);
582     void OnDefaultTextEncodingFormatUpdate(const std::string& value);
583     void OnMinFontSizeUpdate(int32_t value);
584     void OnMinLogicalFontSizeUpdate(int32_t value);
585     void OnBlockNetworkUpdate(bool value);
586     void OnDarkModeUpdate(WebDarkMode mode);
587     void OnForceDarkAccessUpdate(bool access);
588     void OnAudioResumeIntervalUpdate(int32_t resumeInterval);
589     void OnAudioExclusiveUpdate(bool audioExclusive);
590     void OnAudioSessionTypeUpdate(WebAudioSessionType value);
591     void OnHorizontalScrollBarAccessEnabledUpdate(bool value);
592     void OnVerticalScrollBarAccessEnabledUpdate(bool value);
593     void OnScrollBarColorUpdate(const std::string& value);
594     void OnOverScrollModeUpdate(const int32_t value);
595     void OnBlurOnKeyboardHideModeUpdate(const int32_t mode);
596     void OnTextAutosizingUpdate(bool isTextAutosizing);
597     void OnNativeVideoPlayerConfigUpdate(const std::tuple<bool, bool>& config);
598     void OnMetaViewportUpdate(bool value);
599     void OnOverlayScrollbarEnabledUpdate(bool value);
600     void OnKeyboardAvoidModeUpdate(const WebKeyboardAvoidMode& mode);
601     void OnEnabledHapticFeedbackUpdate(bool enable);
602     void OnOptimizeParserBudgetEnabledUpdate(bool value);
603     void OnEnableDataDetectorUpdate(bool enable);
604     void OnEnableFollowSystemFontWeightUpdate(bool value);
605     void OnGestureFocusModeUpdate(GestureFocusMode mode);
606 
607     void InitEvent();
608     void InitTouchEvent(const RefPtr<GestureEventHub>& gestureHub);
609     void InitMouseEvent(const RefPtr<InputEventHub>& inputHub);
610     void InitHoverEvent(const RefPtr<InputEventHub>& inputHub);
611     void InitPanEvent(const RefPtr<GestureEventHub>& gestureHub);
612     void HandleMouseEvent(MouseInfo& info);
613     void WebOnMouseEvent(const MouseInfo& info);
614     bool HandleDoubleClickEvent(const MouseInfo& info);
615     void SendDoubleClickEvent(const MouseClickInfo& info);
616     void InitFocusEvent(const RefPtr<FocusHub>& focusHub);
617     void HandleFocusEvent();
618     void HandleBlurEvent(const BlurReason& blurReason);
619     bool HandleKeyEvent(const KeyEvent& keyEvent);
620     bool WebOnKeyEvent(const KeyEvent& keyEvent);
621     void WebRequestFocus();
622     void ResetDragAction();
623     void UpdateRelativeOffset();
624     void InitSlideUpdateListener();
625     void CalculateHorizontalDrawRect();
626     void CalculateVerticalDrawRect();
627     void UpdateSlideOffset(bool isNeedReset = false);
OnNativeEmbedModeEnabledUpdate(bool value)628     void OnNativeEmbedModeEnabledUpdate(bool value) {};
629     void OnIntrinsicSizeEnabledUpdate(bool value);
630     void OnCssDisplayChangeEnabledUpdate(bool value);
631     void OnNativeEmbedRuleTagUpdate(const std::string& tag);
632     void OnNativeEmbedRuleTypeUpdate(const std::string& type);
633     void OnCopyOptionModeUpdate(const int32_t value);
634     void OnBypassVsyncConditionUpdate(WebBypassVsyncCondition condition);
635     int onDragMoveCnt = 0;
636     std::chrono::time_point<std::chrono::system_clock> firstMoveInTime;
637     std::chrono::time_point<std::chrono::system_clock> preMoveInTime;
638     std::chrono::time_point<std::chrono::system_clock> curMoveInTime;
639     CancelableCallback<void()> timer_;
640     int32_t duration_ = 100; // 100: 100ms
641     void DoRepeat();
642     void StartRepeatTimer();
643 
644     void HandleTouchDown(const TouchEventInfo& info, bool fromOverlay);
645 
646     void HandleTouchUp(const TouchEventInfo& info, bool fromOverlay);
647 
648     void HandleTouchMove(const TouchEventInfo& info, bool fromOverlay);
649 
650     void HandleTouchCancel(const TouchEventInfo& info);
651 
652     std::optional<OffsetF> GetCoordinatePoint();
653 
654     struct TouchInfo {
655         float x = -1.0f;
656         float y = -1.0f;
657         int32_t id = -1;
658     };
659     static bool ParseTouchInfo(const TouchEventInfo& info, std::list<TouchInfo>& touchInfos);
660     void InitEnhanceSurfaceFlag();
661     void UpdateBackgroundColorRightNow(int32_t color);
662     void UpdateContentOffset(const RefPtr<LayoutWrapper>& dirty);
663     void PostTaskToUI(const std::function<void()>&& task) const;
664     void StartVibraFeedback(const std::string& vibratorType);
665 
666     std::optional<std::string> webSrc_;
667     std::optional<std::string> webData_;
668     std::optional<std::string> customScheme_;
669     RefPtr<WebController> webController_;
670     SetWebIdCallback setWebIdCallback_ = nullptr;
671     SetWebDetachCallback setWebDetachCallback_ = nullptr;
672     RenderMode renderMode_;
673     bool incognitoMode_ = false;
674     SetHapPathCallback setHapPathCallback_ = nullptr;
675     JsProxyCallback jsProxyCallback_ = nullptr;
676     OnControllerAttachedCallback onControllerAttachedCallback_ = nullptr;
677     PermissionClipboardCallback permissionClipboardCallback_ = nullptr;
678     OnOpenAppLinkCallback onOpenAppLinkCallback_ = nullptr;
679     SetFaviconCallback setFaviconCallback_ = nullptr;
680     DefaultFileSelectorShowCallback defaultFileSelectorShowCallback_ = nullptr;
681     RefPtr<TouchEventImpl> touchEvent_;
682     RefPtr<InputEvent> mouseEvent_;
683     RefPtr<InputEvent> hoverEvent_;
684     RefPtr<PanEvent> panEvent_ = nullptr;
685     RefPtr<WebPaintProperty> webPaintProperty_ = nullptr;
686     RefPtr<DragEvent> dragEvent_;
687     bool isUrlLoaded_ = false;
688     std::queue<MouseClickInfo> doubleClickQueue_;
689     bool isFullScreen_ = false;
690     std::shared_ptr<FullScreenEnterEvent> fullScreenExitHandler_ = nullptr;
691     bool needOnFocus_ = false;
692     Size drawSize_;
693     Size drawSizeCache_;
694     bool needUpdateWeb_ = true;
695     bool isFocus_ = false;
696     VkState isVirtualKeyBoardShow_ { VkState::VK_NONE };
697     bool isDragging_ = false;
698     bool isW3cDragEvent_ = false;
699     bool isWindowShow_ = true;
700     bool isActive_ = true;
701     bool isEnhanceSurface_ = false;
702     bool isAllowWindowOpenMethod_ = false;
703     OffsetF webOffset_;
704     bool isPopup_ = false;
705     int32_t parentNWebId_ = -1;
706     bool isInWindowDrag_ = false;
707     bool isWaiting_ = false;
708     bool isDisableDrag_ = false;
709     bool isMouseEvent_ = false;
710     bool isVisible_ = true;
711     bool isVisibleActiveEnable_ = true;
712     bool isMemoryLevelEnable_ = true;
713     bool isParentHasScroll_ = false;
714     OffsetF relativeOffsetOfScroll_;
715     std::function<void(int32_t)> updateInstanceIdCallback_;
716     RefPtr<WebDelegateInterface> delegate_ = nullptr;
717     std::optional<std::string> sharedRenderProcessToken_;
718 
719     bool selectPopupMenuShowing_ = false;
720     WebLayoutMode layoutMode_ = WebLayoutMode::NONE;
721     int32_t rootLayerWidth_ = 0;
722     int32_t rootLayerHeight_ = 0;
723     bool richTextInit_ = false;
724     ACE_DISALLOW_COPY_AND_MOVE(WebPattern);
725     bool needSetDefaultBackgroundColor_ = false;
726 };
727 } // namespace OHOS::Ace::NG
728 
729 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_WEB_CORS_WEB_PATTERN_H
730