• 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_PATTERNS_WEB_WEB_PATTERN_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_WEB_WEB_PATTERN_H
18 
19 #include <optional>
20 #include <string>
21 #include <utility>
22 
23 #include "base/memory/referenced.h"
24 #include "base/thread/cancelable_callback.h"
25 #include "base/utils/utils.h"
26 #include "base/geometry/axis.h"
27 #include "base/web/webview/ohos_nweb/include/nweb_handler.h"
28 #include "core/common/udmf/unified_data.h"
29 #include "core/components/dialog/dialog_properties.h"
30 #include "core/components/dialog/dialog_theme.h"
31 #include "core/components/web/web_property.h"
32 #include "core/components_ng/gestures/recognizers/pan_recognizer.h"
33 #include "core/components_ng/manager/select_overlay/select_overlay_manager.h"
34 #include "core/components_ng/manager/select_overlay/select_overlay_proxy.h"
35 #include "core/components_ng/manager/select_overlay/selection_host.h"
36 #include "core/components_ng/pattern/pattern.h"
37 #include "core/components_ng/pattern/scrollable/nestable_scroll_container.h"
38 #include "core/components_ng/pattern/web/web_accessibility_node.h"
39 #include "core/components_ng/pattern/web/web_accessibility_property.h"
40 #include "core/components_ng/pattern/web/web_event_hub.h"
41 #include "core/components_ng/pattern/web/web_layout_algorithm.h"
42 #include "core/components_ng/pattern/web/web_paint_property.h"
43 #include "core/components_ng/pattern/web/web_pattern_property.h"
44 #include "core/components_ng/pattern/web/web_paint_method.h"
45 #include "core/components_ng/property/property.h"
46 #include "core/components_ng/render/render_surface.h"
47 #include "core/components_ng/pattern/scroll/scroll_pattern.h"
48 
49 namespace OHOS::Ace {
50 class WebDelegateObserver;
51 }
52 
53 namespace OHOS::Ace::NG {
54 namespace {
55 
56 struct MouseClickInfo {
57     double x = -1;
58     double y = -1;
59     TimeStamp start;
60 };
61 
62 #ifdef OHOS_STANDARD_SYSTEM
63 struct TouchInfo {
64     double x = -1;
65     double y = -1;
66     int32_t id = -1;
67 };
68 
69 struct TouchHandleState {
70     int32_t id = -1;
71     int32_t x = -1;
72     int32_t y = -1;
73     int32_t edge_height = 0;
74 };
75 
76 enum WebOverlayType { INSERT_OVERLAY, SELECTION_OVERLAY, INVALID_OVERLAY };
77 #endif
78 } // namespace
79 
80 class WebPattern : public NestableScrollContainer, public SelectionHost {
81     DECLARE_ACE_TYPE(WebPattern, NestableScrollContainer, SelectionHost);
82 
83 public:
84     using SetWebIdCallback = std::function<void(int32_t)>;
85     using SetHapPathCallback = std::function<void(const std::string&)>;
86     using JsProxyCallback = std::function<void()>;
87     using OnControllerAttachedCallback = std::function<void()>;
88     using PermissionClipboardCallback = std::function<void(const std::shared_ptr<BaseEventInfo>&)>;
89     WebPattern();
90     WebPattern(const std::string& webSrc, const RefPtr<WebController>& webController, WebType type = WebType::SURFACE,
91                bool incognitoMode = false);
92     WebPattern(const std::string& webSrc, const SetWebIdCallback& setWebIdCallback, WebType type = WebType::SURFACE,
93                bool incognitoMode = false);
94 
95     ~WebPattern() override;
96 
97     enum class VkState {
98         VK_NONE,
99         VK_SHOW,
100         VK_HIDE
101     };
102 
GetContextParam()103     std::optional<RenderContext::ContextParam> GetContextParam() const override
104     {
105         if (type_ == WebType::TEXTURE) {
106             return RenderContext::ContextParam { RenderContext::ContextType::CANVAS };
107         } else {
108             return RenderContext::ContextParam { RenderContext::ContextType::HARDWARE_SURFACE, "RosenWeb" };
109         }
110     }
111 
112     RefPtr<NodePaintMethod> CreateNodePaintMethod() override;
113 
IsAtomicNode()114     bool IsAtomicNode() const override
115     {
116         return true;
117     }
118 
119     bool NeedSoftKeyboard() const override;
120 
121     void UpdateScrollOffset(SizeF frameSize) override;
122 
CreateEventHub()123     RefPtr<EventHub> CreateEventHub() override
124     {
125         return MakeRefPtr<WebEventHub>();
126     }
127 
CreateAccessibilityProperty()128     RefPtr<AccessibilityProperty> CreateAccessibilityProperty() override
129     {
130         return MakeRefPtr<WebAccessibilityProperty>();
131     }
132 
133     void OnModifyDone() override;
134 
SetWebSrc(const std::string & webSrc)135     void SetWebSrc(const std::string& webSrc)
136     {
137         if (webSrc_ != webSrc_) {
138             OnWebSrcUpdate();
139             webSrc_ = webSrc;
140         }
141         if (webPaintProperty_) {
142             webPaintProperty_->SetWebPaintData(webSrc);
143         }
144     }
145 
GetWebSrc()146     const std::optional<std::string>& GetWebSrc() const
147     {
148         return webSrc_;
149     }
150 
SetPopup(bool popup)151     void SetPopup(bool popup)
152     {
153         isPopup_ = popup;
154     }
155 
SetParentNWebId(int32_t parentNWebId)156     void SetParentNWebId(int32_t parentNWebId)
157     {
158         parentNWebId_ = parentNWebId;
159     }
160 
SetWebData(const std::string & webData)161     void SetWebData(const std::string& webData)
162     {
163         if (webData_ != webData) {
164             webData_ = webData;
165             OnWebDataUpdate();
166         }
167         if (webPaintProperty_) {
168             webPaintProperty_->SetWebPaintData(webData);
169         }
170     }
171 
GetWebData()172     const std::optional<std::string>& GetWebData() const
173     {
174         return webData_;
175     }
176 
SetCustomScheme(const std::string & scheme)177     void SetCustomScheme(const std::string& scheme)
178     {
179         customScheme_ = scheme;
180     }
181 
GetCustomScheme()182     const std::optional<std::string>& GetCustomScheme() const
183     {
184         return customScheme_;
185     }
186 
SetWebController(const RefPtr<WebController> & webController)187     void SetWebController(const RefPtr<WebController>& webController)
188     {
189         // TODO: add web controller diff function.
190         webController_ = webController;
191     }
192 
GetWebController()193     RefPtr<WebController> GetWebController() const
194     {
195         return webController_;
196     }
197 
SetSetWebIdCallback(SetWebIdCallback && SetIdCallback)198     void SetSetWebIdCallback(SetWebIdCallback&& SetIdCallback)
199     {
200         setWebIdCallback_ = std::move(SetIdCallback);
201     }
202 
GetSetWebIdCallback()203     SetWebIdCallback GetSetWebIdCallback() const
204     {
205         return setWebIdCallback_;
206     }
207 
SetPermissionClipboardCallback(PermissionClipboardCallback && Callback)208     void SetPermissionClipboardCallback(PermissionClipboardCallback&& Callback)
209     {
210         permissionClipboardCallback_ = std::move(Callback);
211     }
212 
GetPermissionClipboardCallback()213     PermissionClipboardCallback GetPermissionClipboardCallback() const
214     {
215         return permissionClipboardCallback_;
216     }
217 
SetWebType(WebType type)218     void SetWebType(WebType type)
219     {
220         type_ = type;
221     }
222 
GetWebType()223     WebType GetWebType()
224     {
225         return type_;
226     }
227 
SetIncognitoMode(bool incognitoMode)228     void SetIncognitoMode(bool incognitoMode)
229     {
230         incognitoMode_ = incognitoMode;
231     }
232 
GetIncognitoMode()233     bool GetIncognitoMode() const
234     {
235         return incognitoMode_;
236     }
237 
SetOnControllerAttachedCallback(OnControllerAttachedCallback && callback)238     void SetOnControllerAttachedCallback(OnControllerAttachedCallback&& callback)
239     {
240         onControllerAttachedCallback_ = std::move(callback);
241     }
242 
GetOnControllerAttachedCallback()243     OnControllerAttachedCallback GetOnControllerAttachedCallback()
244     {
245         return onControllerAttachedCallback_;
246     }
247 
SetSetHapPathCallback(SetHapPathCallback && callback)248     void SetSetHapPathCallback(SetHapPathCallback&& callback)
249     {
250         setHapPathCallback_ = std::move(callback);
251     }
252 
GetSetHapPathCallback()253     SetHapPathCallback GetSetHapPathCallback() const
254     {
255         return setHapPathCallback_;
256     }
257 
SetJsProxyCallback(JsProxyCallback && jsProxyCallback)258     void SetJsProxyCallback(JsProxyCallback&& jsProxyCallback)
259     {
260         jsProxyCallback_ = std::move(jsProxyCallback);
261     }
262 
CallJsProxyCallback()263     void CallJsProxyCallback()
264     {
265         if (jsProxyCallback_) {
266             jsProxyCallback_();
267         }
268     }
269 
GetWebEventHub()270     RefPtr<WebEventHub> GetWebEventHub()
271     {
272         return GetEventHub<WebEventHub>();
273     }
274 
GetFocusPattern()275     FocusPattern GetFocusPattern() const override
276     {
277         return { FocusType::NODE, true };
278     }
279 
CreatePaintProperty()280     RefPtr<PaintProperty> CreatePaintProperty() override
281     {
282         if (!webPaintProperty_) {
283             webPaintProperty_ = MakeRefPtr<WebPaintProperty>();
284             if (!webPaintProperty_) {
285             }
286         }
287         return webPaintProperty_;
288     }
289 
CreateLayoutAlgorithm()290     RefPtr<LayoutAlgorithm> CreateLayoutAlgorithm() override
291     {
292         return MakeRefPtr<WebLayoutAlgorithm>();
293     }
294 
BetweenSelectedPosition(const Offset & globalOffset)295     bool BetweenSelectedPosition(const Offset& globalOffset) override
296     {
297         return false;
298     }
299 
GetDragRecordSize()300     int32_t GetDragRecordSize() override
301     {
302         return 1;
303     }
304 
305     /**
306      *  NestableScrollContainer implementations
307      */
GetAxis()308     Axis GetAxis() const override
309     {
310         return axis_;
311     }
312     ScrollResult HandleScroll(float offset, int32_t source, NestedState state) override;
313     bool HandleScrollVelocity(float velocity) override;
314     void OnScrollStartRecursive(float position) override;
315     void OnScrollEndRecursive(const std::optional<float>& velocity) override;
316     void OnAttachToBuilderNode(NodeStatus nodeStatus) override;
317     Axis GetParentAxis();
318     RefPtr<NestableScrollContainer> WebSearchParent();
319     void SetNestedScroll(const NestedScrollOptions& nestedOpt);
320     /**
321      *  End of NestableScrollContainer implementations
322      */
323 
324     ACE_DEFINE_PROPERTY_GROUP(WebProperty, WebPatternProperty);
325     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, JsEnabled, bool);
326     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, MediaPlayGestureAccess, bool);
327     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, FileAccessEnabled, bool);
328     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, OnLineImageAccessEnabled, bool);
329     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, DomStorageAccessEnabled, bool);
330     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, ImageAccessEnabled, bool);
331     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, MixedMode, MixedModeContent);
332     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, ZoomAccessEnabled, bool);
333     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, GeolocationAccessEnabled, bool);
334     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, UserAgent, std::string);
335     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, CacheMode, WebCacheMode);
336     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, OverviewModeAccessEnabled, bool);
337     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, FileFromUrlAccessEnabled, bool);
338     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, DatabaseAccessEnabled, bool);
339     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, TextZoomRatio, int32_t);
340     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, WebDebuggingAccessEnabled, bool);
341     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, BackgroundColor, int32_t);
342     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, InitialScale, float);
343     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, PinchSmoothModeEnabled, bool);
344     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, MultiWindowAccessEnabled, bool);
345     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, AllowWindowOpenMethod, bool);
346     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, WebCursiveFont, std::string);
347     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, WebFantasyFont, std::string);
348     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, WebFixedFont, std::string);
349     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, WebSansSerifFont, std::string);
350     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, WebSerifFont, std::string);
351     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, WebStandardFont, std::string);
352     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, DefaultFixedFontSize, int32_t);
353     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, DefaultFontSize, int32_t);
354     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, MinFontSize, int32_t);
355     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, MinLogicalFontSize, int32_t);
356     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, BlockNetwork, bool);
357     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, DarkMode, WebDarkMode);
358     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, ForceDarkAccess, bool);
359     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, AudioResumeInterval, int32_t);
360     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, AudioExclusive, bool);
361     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, HorizontalScrollBarAccessEnabled, bool);
362     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, VerticalScrollBarAccessEnabled, bool);
363     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, ScrollBarColor, std::string);
364     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, OverScrollMode, int32_t);
365     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, CopyOptionMode, int32_t);
366     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, NativeEmbedModeEnabled, bool);
367 
368     void RequestFullScreen();
369     void ExitFullScreen();
IsFullScreen()370     bool IsFullScreen() const
371     {
372         return isFullScreen_;
373     }
374     bool RunQuickMenu(std::shared_ptr<OHOS::NWeb::NWebQuickMenuParams> params,
375         std::shared_ptr<OHOS::NWeb::NWebQuickMenuCallback> callback);
376     void OnQuickMenuDismissed();
377     void OnTouchSelectionChanged(std::shared_ptr<OHOS::NWeb::NWebTouchHandleState> insertHandle,
378         std::shared_ptr<OHOS::NWeb::NWebTouchHandleState> startSelectionHandle,
379         std::shared_ptr<OHOS::NWeb::NWebTouchHandleState> endSelectionHandle);
380     bool OnCursorChange(const OHOS::NWeb::CursorType& type, const OHOS::NWeb::NWebCursorInfo& info);
381     void UpdateLocalCursorStyle(int32_t windowId, const OHOS::NWeb::CursorType& type);
382     std::shared_ptr<OHOS::Media::PixelMap> CreatePixelMapFromString(const std::string& filePath);
383     void OnSelectPopupMenu(std::shared_ptr<OHOS::NWeb::NWebSelectPopupMenuParam> params,
384         std::shared_ptr<OHOS::NWeb::NWebSelectPopupMenuCallback> callback);
385     void OnDateTimeChooserPopup(
386         const NWeb::DateTimeChooser& chooser,
387         const std::vector<NWeb::DateTimeSuggestion>& suggestions,
388         std::shared_ptr<NWeb::NWebDateTimeChooserCallback> callback);
389     void OnDateTimeChooserClose();
390     void UpdateTouchHandleForOverlay();
IsSelectOverlayDragging()391     bool IsSelectOverlayDragging()
392     {
393         return selectOverlayDragging_;
394     }
SetSelectOverlayDragging(bool selectOverlayDragging)395     void SetSelectOverlayDragging(bool selectOverlayDragging)
396     {
397         selectOverlayDragging_ = selectOverlayDragging;
398     }
399     void UpdateLocale();
400     void SetDrawRect(int32_t x, int32_t y, int32_t width, int32_t height);
SetSelectPopupMenuShowing(bool showing)401     void SetSelectPopupMenuShowing(bool showing)
402     {
403         selectPopupMenuShowing_ = showing;
404     }
SetCurrentStartHandleDragging(bool isStartHandle)405     void SetCurrentStartHandleDragging(bool isStartHandle)
406     {
407         isCurrentStartHandleDragging_ = isStartHandle;
408     }
409     void UpdateSelectHandleInfo();
410     bool IsSelectHandleReverse();
411     void OnCompleteSwapWithNewSize();
412     void OnResizeNotWork();
413     bool OnBackPressed() const;
414     void SetFullScreenExitHandler(const std::shared_ptr<FullScreenEnterEvent>& fullScreenExitHandler);
415     bool NotifyStartDragTask();
416     bool IsImageDrag();
417     void UpdateJavaScriptOnDocumentStart();
418     void UpdateJavaScriptOnDocumentEnd();
419     void JavaScriptOnDocumentStart(const ScriptItems& scriptItems);
420     void JavaScriptOnDocumentEnd(const ScriptItems& scriptItems);
421     void SetTouchEventInfo(const TouchEvent& touchEvent, TouchEventInfo& touchEventInfo);
422     DragRet GetDragAcceptableStatus();
423     Offset GetDragOffset() const;
424     void OnOverScrollFlingVelocity(float xVelocity, float yVelocity, bool isFling);
425     void OnScrollState(bool scrollState);
SetLayoutMode(WebLayoutMode mode)426     void SetLayoutMode(WebLayoutMode mode)
427     {
428         layoutMode_ = mode;
429     }
GetLayoutMode()430     WebLayoutMode GetLayoutMode() const
431     {
432         return layoutMode_;
433     }
434     void OnRootLayerChanged(int width, int height);
GetRootLayerWidth()435     int GetRootLayerWidth() const
436     {
437         return rootLayerWidth_;
438     }
GetRootLayerHeight()439     int GetRootLayerHeight() const
440     {
441         return rootLayerHeight_;
442     }
443     bool FilterScrollEvent(const float x, const float y, const float xVelocity, const float yVelocity);
444     RefPtr<WebAccessibilityNode> GetFocusedAccessibilityNode(int64_t accessibilityId, bool isAccessibilityFocus);
445     RefPtr<WebAccessibilityNode> GetAccessibilityNodeById(int64_t accessibilityId);
446     RefPtr<WebAccessibilityNode> GetAccessibilityNodeByFocusMove(int64_t accessibilityId, int32_t direction);
447     void ExecuteAction(int64_t accessibilityId, AceAction action) const;
448     void SetAccessibilityState(bool state);
449     bool IsRootNeedExportTexture();
450 
451 private:
452     void RegistVirtualKeyBoardListener();
453     bool ProcessVirtualKeyBoard(int32_t width, int32_t height, double keyboard);
454     void UpdateWebLayoutSize(int32_t width, int32_t height, bool isKeyboard);
455     void UpdateLayoutAfterKerboardShow(int32_t width, int32_t height, double keyboard, double oldWebHeight);
456     bool OnDirtyLayoutWrapperSwap(const RefPtr<LayoutWrapper>& dirty, const DirtySwapConfig& config) override;
457 
458     void OnAttachToFrameNode() override;
459     void OnDetachFromFrameNode(FrameNode* frameNode) override;
460     void OnWindowShow() override;
461     void OnWindowHide() override;
462     void OnWindowSizeChanged(int32_t width, int32_t height, WindowSizeChangeReason type) override;
463     void OnInActive() override;
464     void OnActive() override;
465     void OnVisibleChange(bool isVisible) override;
466     void OnAreaChangedInner() override;
467     void OnNotifyMemoryLevel(int32_t level) override;
468 
469     void OnWebSrcUpdate();
470     void OnWebDataUpdate();
471     void OnJsEnabledUpdate(bool value);
472     void OnMediaPlayGestureAccessUpdate(bool value);
473     void OnFileAccessEnabledUpdate(bool value);
474     void OnOnLineImageAccessEnabledUpdate(bool value);
475     void OnDomStorageAccessEnabledUpdate(bool value);
476     void OnImageAccessEnabledUpdate(bool value);
477     void OnMixedModeUpdate(MixedModeContent value);
478     void OnZoomAccessEnabledUpdate(bool value);
479     void OnGeolocationAccessEnabledUpdate(bool value);
480     void OnUserAgentUpdate(const std::string& value);
481     void OnCacheModeUpdate(WebCacheMode value);
482     void OnOverviewModeAccessEnabledUpdate(bool value);
483     void OnFileFromUrlAccessEnabledUpdate(bool value);
484     void OnDatabaseAccessEnabledUpdate(bool value);
485     void OnTextZoomRatioUpdate(int32_t value);
486     void OnWebDebuggingAccessEnabledUpdate(bool value);
487     void OnPinchSmoothModeEnabledUpdate(bool value);
488     void OnBackgroundColorUpdate(int32_t value);
489     void OnInitialScaleUpdate(float value);
490     void OnMultiWindowAccessEnabledUpdate(bool value);
491     void OnAllowWindowOpenMethodUpdate(bool value);
492     void OnWebCursiveFontUpdate(const std::string& value);
493     void OnWebFantasyFontUpdate(const std::string& value);
494     void OnWebFixedFontUpdate(const std::string& value);
495     void OnWebSerifFontUpdate(const std::string& value);
496     void OnWebSansSerifFontUpdate(const std::string& value);
497     void OnWebStandardFontUpdate(const std::string& value);
498     void OnDefaultFixedFontSizeUpdate(int32_t value);
499     void OnDefaultFontSizeUpdate(int32_t value);
500     void OnMinFontSizeUpdate(int32_t value);
501     void OnMinLogicalFontSizeUpdate(int32_t value);
502     void OnBlockNetworkUpdate(bool value);
503     void OnDarkModeUpdate(WebDarkMode mode);
504     void OnForceDarkAccessUpdate(bool access);
505     void OnAudioResumeIntervalUpdate(int32_t resumeInterval);
506     void OnAudioExclusiveUpdate(bool audioExclusive);
507     void OnHorizontalScrollBarAccessEnabledUpdate(bool value);
508     void OnVerticalScrollBarAccessEnabledUpdate(bool value);
509     void OnScrollBarColorUpdate(const std::string& value);
510     void OnOverScrollModeUpdate(const int32_t value);
511     void OnCopyOptionModeUpdate(const int32_t value);
512     void OnNativeEmbedModeEnabledUpdate(bool value);
513     int GetWebId();
514 
515     void InitEvent();
516     void InitFeatureParam();
517     void InitTouchEvent(const RefPtr<GestureEventHub>& gestureHub);
518     void InitMouseEvent(const RefPtr<InputEventHub>& inputHub);
519     void InitHoverEvent(const RefPtr<InputEventHub>& inputHub);
520     void InitCommonDragDropEvent(const RefPtr<GestureEventHub>& gestureHub);
521     void InitWebEventHubDragDropStart(const RefPtr<WebEventHub>& eventHub);
522     void InitWebEventHubDragDropEnd(const RefPtr<WebEventHub>& eventHub);
523     void InitPanEvent(const RefPtr<GestureEventHub>& gestureHub);
524     void HandleDragMove(const GestureEvent& event);
525     void InitDragEvent(const RefPtr<GestureEventHub>& gestureHub);
526     void HandleDragStart(int32_t x, int32_t y);
527     void HandleDragEnd(int32_t x, int32_t y);
528     void HandleDragCancel();
529     void ClearDragData();
530     bool GenerateDragDropInfo(NG::DragDropInfo& dragDropInfo);
531     void HandleMouseEvent(MouseInfo& info);
532     void WebOnMouseEvent(const MouseInfo& info);
533     bool HandleDoubleClickEvent(const MouseInfo& info);
534     void SendDoubleClickEvent(const MouseClickInfo& info);
535     void InitFocusEvent(const RefPtr<FocusHub>& focusHub);
536     void HandleFocusEvent();
537     void HandleBlurEvent(const BlurReason& blurReason);
538     bool HandleKeyEvent(const KeyEvent& keyEvent);
539     bool WebOnKeyEvent(const KeyEvent& keyEvent);
540     void WebRequestFocus();
541     void ResetDragAction();
542     RefPtr<ScrollPattern> SearchParent();
543     void InitScrollUpdateListener();
544     void CalculateHorizontalDrawRect(const SizeF frameSize);
545     void CalculateVerticalDrawRect(const SizeF frameSize);
546 
547     NG::DragDropInfo HandleOnDragStart(const RefPtr<OHOS::Ace::DragEvent>& info);
548     void HandleOnDragEnter(const RefPtr<OHOS::Ace::DragEvent>& info);
549     void HandleOnDropMove(const RefPtr<OHOS::Ace::DragEvent>& info);
550     void HandleOnDragDrop(const RefPtr<OHOS::Ace::DragEvent>& info);
551     void HandleOnDragDropFile(RefPtr<UnifiedData> aceData);
552     void HandleOnDragDropLink(RefPtr<UnifiedData> aceData);
553     void HandleOnDragLeave(int32_t x, int32_t y);
554     void HandleOnDragEnd(int32_t x, int32_t y);
555     int32_t dropX_ = 0;
556     int32_t dropY_ = 0;
557     int onDragMoveCnt = 0;
558     std::chrono::time_point<std::chrono::system_clock> firstMoveInTime;
559     std::chrono::time_point<std::chrono::system_clock> preMoveInTime;
560     std::chrono::time_point<std::chrono::system_clock> curMoveInTime;
561     CancelableCallback<void()> timer_;
562     int32_t duration_ = 100; // 100: 100ms
563     void DoRepeat();
564     void StartRepeatTimer();
565 
566     void HandleTouchDown(const TouchEventInfo& info, bool fromOverlay);
567 
568     void HandleTouchUp(const TouchEventInfo& info, bool fromOverlay);
569 
570     void HandleTouchMove(const TouchEventInfo& info, bool fromOverlay);
571 
572     void HandleTouchCancel(const TouchEventInfo& info);
573 
574     bool IsTouchHandleValid(std::shared_ptr<OHOS::NWeb::NWebTouchHandleState> handle);
575     bool IsTouchHandleShow(std::shared_ptr<OHOS::NWeb::NWebTouchHandleState> handle);
576 #ifdef OHOS_STANDARD_SYSTEM
577     WebOverlayType GetTouchHandleOverlayType(
578         std::shared_ptr<OHOS::NWeb::NWebTouchHandleState> insertHandle,
579         std::shared_ptr<OHOS::NWeb::NWebTouchHandleState> startSelectionHandle,
580         std::shared_ptr<OHOS::NWeb::NWebTouchHandleState> endSelectionHandle);
581 #endif
582     void RegisterSelectOverlayCallback(SelectOverlayInfo& selectInfo,
583         std::shared_ptr<OHOS::NWeb::NWebQuickMenuParams> params,
584         std::shared_ptr<OHOS::NWeb::NWebQuickMenuCallback> callback);
585     void RegisterSelectOverlayEvent(SelectOverlayInfo& selectInfo);
586     void CloseSelectOverlay();
587     RectF ComputeTouchHandleRect(std::shared_ptr<OHOS::NWeb::NWebTouchHandleState> touchHandle);
588     std::optional<OffsetF> GetCoordinatePoint();
589     void RegisterSelectPopupCallback(RefPtr<FrameNode>& menu,
590         std::shared_ptr<OHOS::NWeb::NWebSelectPopupMenuCallback> callback,
591         std::shared_ptr<OHOS::NWeb::NWebSelectPopupMenuParam> params);
592     OffsetF GetSelectPopupPostion(const OHOS::NWeb::SelectMenuBound& bounds);
593     void SetSelfAsParentOfWebCoreNode(NWeb::NWebAccessibilityNodeInfo& info) const;
594 
595     struct TouchInfo {
596         float x = -1.0f;
597         float y = -1.0f;
598         int32_t id = -1;
599     };
600     static bool ParseTouchInfo(const TouchEventInfo& info, std::list<TouchInfo>& touchInfos);
601     void InitEnhanceSurfaceFlag();
602     void UpdateBackgroundColorRightNow(int32_t color);
603     void UpdateContentOffset(const RefPtr<LayoutWrapper>& dirty);
604     DialogProperties GetDialogProperties(const RefPtr<DialogTheme>& theme);
605     bool ShowDateTimeDialog(const NWeb::DateTimeChooser& chooser,
606         const std::vector<NWeb::DateTimeSuggestion>& suggestions,
607         std::shared_ptr<NWeb::NWebDateTimeChooserCallback> callback);
608     bool ShowTimeDialog(const NWeb::DateTimeChooser& chooser,
609         const std::vector<NWeb::DateTimeSuggestion>& suggestions,
610         std::shared_ptr<NWeb::NWebDateTimeChooserCallback> callback);
611     bool ShowDateTimeSuggestionDialog(const NWeb::DateTimeChooser& chooser,
612         const std::vector<NWeb::DateTimeSuggestion>& suggestions,
613         std::shared_ptr<NWeb::NWebDateTimeChooserCallback> callback);
614     void PostTaskToUI(const std::function<void()>&& task) const;
615     void OfflineMode();
616 
617     std::optional<std::string> webSrc_;
618     std::optional<std::string> webData_;
619     std::optional<std::string> customScheme_;
620     RefPtr<WebController> webController_;
621     SetWebIdCallback setWebIdCallback_ = nullptr;
622     PermissionClipboardCallback permissionClipboardCallback_ = nullptr;
623     WebType type_;
624     bool incognitoMode_ = false;
625     SetHapPathCallback setHapPathCallback_ = nullptr;
626     JsProxyCallback jsProxyCallback_ = nullptr;
627     OnControllerAttachedCallback onControllerAttachedCallback_ = nullptr;
628     RefPtr<RenderSurface> renderSurface_ = RenderSurface::Create();
629     RefPtr<TouchEventImpl> touchEvent_;
630     RefPtr<InputEvent> mouseEvent_;
631     RefPtr<InputEvent> hoverEvent_;
632     RefPtr<PanEvent> panEvent_ = nullptr;
633     RefPtr<SelectOverlayProxy> selectOverlayProxy_ = nullptr;
634     RefPtr<WebPaintProperty> webPaintProperty_ = nullptr;
635     std::shared_ptr<OHOS::NWeb::NWebTouchHandleState> insertHandle_ = nullptr;
636     std::shared_ptr<OHOS::NWeb::NWebTouchHandleState> startSelectionHandle_ = nullptr;
637     std::shared_ptr<OHOS::NWeb::NWebTouchHandleState> endSelectionHandle_ = nullptr;
638     float selectHotZone_ = 10.0f;
639     RefPtr<DragEvent> dragEvent_;
640     bool isUrlLoaded_ = false;
641     std::queue<MouseClickInfo> doubleClickQueue_;
642     bool isFullScreen_ = false;
643     std::shared_ptr<FullScreenEnterEvent> fullScreenExitHandler_ = nullptr;
644     bool needOnFocus_ = false;
645     Size drawSize_;
646     Size drawSizeCache_;
647     bool needUpdateWeb_ = true;
648     bool isFocus_ = false;
649     VkState isVirtualKeyBoardShow_ { VkState::VK_NONE };
650     bool isDragging_ = false;
651     bool isW3cDragEvent_ = false;
652     bool isWindowShow_ = true;
653     bool isActive_ = true;
654     bool isEnhanceSurface_ = false;
655     bool isAllowWindowOpenMethod_ = false;
656     OffsetF webOffset_;
657     std::shared_ptr<OHOS::NWeb::NWebQuickMenuCallback> quickMenuCallback_ = nullptr;
658     SelectMenuInfo selectMenuInfo_;
659     bool selectOverlayDragging_ = false;
660     bool selectPopupMenuShowing_ = false;
661     bool isCurrentStartHandleDragging_ = false;
662     bool isPopup_ = false;
663     int32_t parentNWebId_ = -1;
664     bool isInWindowDrag_ = false;
665     bool isWaiting_ = false;
666     bool isDisableDrag_ = false;
667     bool isMouseEvent_ = false;
668     bool isVisible_ = true;
669     bool isVisibleActiveEnable_ = true;
670     bool isMemoryLevelEnable_ = true;
671     bool isParentHasScroll_ = false;
672     OffsetF relativeOffsetOfScroll_;
673     bool isFirstFlingScrollVelocity_ = true;
674     WebLayoutMode layoutMode_ = WebLayoutMode::NONE;
675     bool scrollState_ = false;
676     NestedScrollMode nestedScrollForwardMode_ = NestedScrollMode::SELF_FIRST;
677     NestedScrollMode nestedScrollBackwardMode_ = NestedScrollMode::SELF_FIRST;
678     Axis axis_ = Axis::FREE;
679     int32_t rootLayerWidth_ = 0;
680     int32_t rootLayerHeight_ = 0;
681     WeakPtr<NestableScrollContainer> parent_;
682     RefPtr<WebDelegate> delegate_;
683     RefPtr<WebDelegateObserver> observer_;
684     std::set<OHOS::Ace::KeyCode> KeyCodeSet_;
685     std::optional<ScriptItems> onDocumentStartScriptItems_;
686     std::optional<ScriptItems> onDocumentEndScriptItems_;
687     bool isOfflineMode_ = false;
688     ACE_DISALLOW_COPY_AND_MOVE(WebPattern);
689     bool accessibilityState_ = false;
690     RefPtr<WebAccessibilityNode> webAccessibilityNode_;
691     TouchEventInfo touchEventInfo_{"touchEvent"};
692     std::vector<TouchEventInfo> touchEventInfoList_ {};
693 };
694 } // namespace OHOS::Ace::NG
695 
696 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_WEB_WEB_PATTERN_H
697