1 /*
2  * Copyright (c) 2022-2024 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 <tuple>
22 #include <utility>
23 
24 #include "base/memory/referenced.h"
25 #include "base/thread/cancelable_callback.h"
26 #include "base/utils/utils.h"
27 #include "base/geometry/axis.h"
28 #include "base/view_data/hint_to_type_wrap.h"
29 #include "base/web/webview/ohos_nweb/include/nweb_autofill.h"
30 #include "base/web/webview/ohos_nweb/include/nweb_handler.h"
31 #include "core/common/udmf/unified_data.h"
32 #include "core/components/dialog/dialog_properties.h"
33 #include "core/components/dialog/dialog_theme.h"
34 #include "core/components/web/web_event.h"
35 #include "core/components/web/web_property.h"
36 #include "core/components_ng/gestures/recognizers/pan_recognizer.h"
37 #include "core/components_ng/manager/select_overlay/select_overlay_manager.h"
38 #include "core/components_ng/manager/select_overlay/select_overlay_proxy.h"
39 #include "core/components_ng/manager/select_overlay/selection_host.h"
40 #include "core/components_ng/pattern/pattern.h"
41 #include "core/components_ng/pattern/scrollable/nestable_scroll_container.h"
42 #include "core/components_ng/pattern/text/text_base.h"
43 #include "core/components_ng/pattern/web/touch_event_listener.h"
44 #include "core/components_ng/pattern/web/web_accessibility_property.h"
45 #include "core/components_ng/pattern/web/web_context_select_overlay.h"
46 #include "core/components_ng/pattern/web/web_event_hub.h"
47 #include "core/components_ng/pattern/web/web_layout_algorithm.h"
48 #include "core/components_ng/pattern/web/web_paint_property.h"
49 #include "core/components_ng/pattern/web/web_pattern_property.h"
50 #include "core/components_ng/pattern/web/web_paint_method.h"
51 #include "core/components_ng/property/property.h"
52 #include "core/components_ng/render/adapter/rosen_render_context.h"
53 #include "core/components_ng/render/render_surface.h"
54 #include "core/components_ng/pattern/scroll/scroll_pattern.h"
55 #include "core/components_ng/gestures/pinch_gesture.h"
56 #include "core/components_ng/pattern/select_overlay/magnifier.h"
57 #include "core/components_ng/pattern/select_overlay/magnifier_controller.h"
58 #include "ui/rs_surface_node.h"
59 
60 namespace OHOS::Ace {
61 class WebDelegateObserver;
62 class ImageAnalyzerManager;
63 }
64 
65 namespace OHOS::Ace::NG {
66 namespace {
67 
68 struct MouseClickInfo {
69     double x = -1;
70     double y = -1;
71     TimeStamp start;
72 };
73 
74 struct ViewDataCommon {
75     OHOS::NWeb::NWebAutofillEvent eventType = OHOS::NWeb::NWebAutofillEvent::UNKNOWN;
76     std::string pageUrl;
77     bool isUserSelected = false;
78     bool isOtherAccount = false;
79     std::string source;
80 };
81 
82 #ifdef OHOS_STANDARD_SYSTEM
83 struct TouchInfo {
84     double x = -1;
85     double y = -1;
86     int32_t id = -1;
87 };
88 
89 struct TouchHandleState {
90     int32_t id = -1;
91     int32_t x = -1;
92     int32_t y = -1;
93     int32_t edge_height = 0;
94 };
95 
96 enum WebOverlayType { INSERT_OVERLAY, SELECTION_OVERLAY, INVALID_OVERLAY };
97 #endif
98 } // namespace
99 
100 enum class WebInfoType : int32_t {
101     TYPE_MOBILE,
102     TYPE_TABLET,
103     TYPE_2IN1,
104     TYPE_UNKNOWN
105 };
106 
107 class WebPattern : public NestableScrollContainer, public TextBase, public Magnifier {
108     DECLARE_ACE_TYPE(WebPattern, NestableScrollContainer, TextBase, Magnifier);
109 
110 public:
111     using SetWebIdCallback = std::function<void(int32_t)>;
112     using SetHapPathCallback = std::function<void(const std::string&)>;
113     using JsProxyCallback = std::function<void()>;
114     using OnControllerAttachedCallback = std::function<void()>;
115     using PermissionClipboardCallback = std::function<void(const std::shared_ptr<BaseEventInfo>&)>;
116     using OnOpenAppLinkCallback = std::function<void(const std::shared_ptr<BaseEventInfo>&)>;
117     using DefaultFileSelectorShowCallback = std::function<void(const std::shared_ptr<BaseEventInfo>&)>;
118     using WebNodeInfoCallback = const std::function<void(std::shared_ptr<JsonValue>& jsonNodeArray, int32_t webId)>;
119     using WebComponentClickCallback = std::function<void(int64_t, const std::string)>;
120     using TextBlurCallback = std::function<void(int64_t, const std::string)>;
121     WebPattern();
122     WebPattern(const std::string& webSrc, const RefPtr<WebController>& webController,
123                RenderMode type = RenderMode::ASYNC_RENDER, bool incognitoMode = false,
124 			   const std::string& sharedRenderProcessToken = "");
125     WebPattern(const std::string& webSrc, const SetWebIdCallback& setWebIdCallback,
126                RenderMode type = RenderMode::ASYNC_RENDER, bool incognitoMode = false,
127 			   const std::string& sharedRenderProcessToken = "");
128 
129     ~WebPattern() override;
130 
131     enum class VkState {
132         VK_NONE,
133         VK_SHOW,
134         VK_HIDE
135     };
136 
137     enum class WebAccessibilityType : int32_t {
138         ID = 0,
139         SEL_START,
140         SEL_END,
141         INPUT_TYPE,
142         LIVE_REGION,
143         HINT,
144         CONTENT,
145         ERROR,
146         CHILD_IDS,
147         PARENT_ID,
148         GRID_ROWS,
149         GRID_COLS,
150         GRID_SEL_MODE,
151         GRID_ITEM_ROW,
152         GRID_ITEM_ROW_SPAN,
153         GRID_ITEM_COL,
154         GRID_ITEM_COL_SPAN,
155         PAGE_ID,
156         RECTX,
157         RECTY,
158         RECT_WIDTH,
159         RECT_HEIGHT,
160         HEADING,
161         CHECKED,
162         EDITABLE,
163         ENABLED,
164         FOCUSED,
165         SELECTED,
166         CHECKABLE,
167         CLICKABLE,
168         FOCUSABLE,
169         SCROLLABLE,
170         PASSWORD,
171         VISIBLE,
172         PLURAL_LINE,
173         POPUP,
174         DELETABLE,
175         FOCUS,
176     };
177 
178     RefPtr<NodePaintMethod> CreateNodePaintMethod() override;
179 
IsAtomicNode()180     bool IsAtomicNode() const override
181     {
182         return true;
183     }
184 
185     bool NeedSoftKeyboard() const override;
186 
CreateEventHub()187     RefPtr<EventHub> CreateEventHub() override
188     {
189         return MakeRefPtr<WebEventHub>();
190     }
191 
CreateAccessibilityProperty()192     RefPtr<AccessibilityProperty> CreateAccessibilityProperty() override
193     {
194         return MakeRefPtr<WebAccessibilityProperty>();
195     }
196 
197     void OnModifyDone() override;
198 
199     void DumpViewDataPageNode(RefPtr<ViewDataWrap> viewDataWrap, bool needsRecordData = false) override;
200 
201     void NotifyFillRequestSuccess(RefPtr<ViewDataWrap> viewDataWrap,
202         RefPtr<PageNodeInfoWrap> nodeWrap, AceAutoFillType autoFillType) override;
203 
204     void NotifyFillRequestFailed(int32_t errCode, const std::string& fillContent = "", bool isPopup = false) override;
205 
206     Color GetDefaultBackgroundColor();
207 
SetWebSrc(const std::string & webSrc)208     void SetWebSrc(const std::string& webSrc)
209     {
210         if (webSrc_ != webSrc_) {
211             OnWebSrcUpdate();
212             webSrc_ = webSrc;
213         }
214         if (webPaintProperty_) {
215             webPaintProperty_->SetWebPaintData(webSrc);
216         }
217     }
218 
GetWebSrc()219     const std::optional<std::string>& GetWebSrc() const
220     {
221         return webSrc_;
222     }
223 
SetPopup(bool popup)224     void SetPopup(bool popup)
225     {
226         isPopup_ = popup;
227     }
228 
SetParentNWebId(int32_t parentNWebId)229     void SetParentNWebId(int32_t parentNWebId)
230     {
231         parentNWebId_ = parentNWebId;
232     }
233 
SetWebData(const std::string & webData)234     void SetWebData(const std::string& webData)
235     {
236         if (webData_ != webData) {
237             webData_ = webData;
238             OnWebDataUpdate();
239         }
240         if (webPaintProperty_) {
241             webPaintProperty_->SetWebPaintData(webData);
242         }
243     }
244 
GetWebData()245     const std::optional<std::string>& GetWebData() const
246     {
247         return webData_;
248     }
249 
SetCustomScheme(const std::string & scheme)250     void SetCustomScheme(const std::string& scheme)
251     {
252         customScheme_ = scheme;
253     }
254 
GetCustomScheme()255     const std::optional<std::string>& GetCustomScheme() const
256     {
257         return customScheme_;
258     }
259 
SetWebController(const RefPtr<WebController> & webController)260     void SetWebController(const RefPtr<WebController>& webController)
261     {
262         webController_ = webController;
263     }
264 
GetWebController()265     RefPtr<WebController> GetWebController() const
266     {
267         return webController_;
268     }
269 
SetSetWebIdCallback(SetWebIdCallback && SetIdCallback)270     void SetSetWebIdCallback(SetWebIdCallback&& SetIdCallback)
271     {
272         setWebIdCallback_ = std::move(SetIdCallback);
273     }
274 
GetSetWebIdCallback()275     SetWebIdCallback GetSetWebIdCallback() const
276     {
277         return setWebIdCallback_;
278     }
279 
SetPermissionClipboardCallback(PermissionClipboardCallback && Callback)280     void SetPermissionClipboardCallback(PermissionClipboardCallback&& Callback)
281     {
282         permissionClipboardCallback_ = std::move(Callback);
283     }
284 
SetDefaultFileSelectorShowCallback(DefaultFileSelectorShowCallback && Callback)285     void SetDefaultFileSelectorShowCallback(DefaultFileSelectorShowCallback&& Callback)
286     {
287         defaultFileSelectorShowCallback_ = std::move(Callback);
288     }
289 
GetDefaultFileSelectorShowCallback()290     DefaultFileSelectorShowCallback GetDefaultFileSelectorShowCallback()
291     {
292         return defaultFileSelectorShowCallback_;
293     }
294 
GetPermissionClipboardCallback()295     PermissionClipboardCallback GetPermissionClipboardCallback() const
296     {
297         return permissionClipboardCallback_;
298     }
299 
SetOnOpenAppLinkCallback(OnOpenAppLinkCallback && callback)300     void SetOnOpenAppLinkCallback(OnOpenAppLinkCallback&& callback)
301     {
302         onOpenAppLinkCallback_ = std::move(callback);
303     }
304 
GetOnOpenAppLinkCallback()305     OnOpenAppLinkCallback GetOnOpenAppLinkCallback() const
306     {
307         return onOpenAppLinkCallback_;
308     }
309 
310     void SetRenderMode(RenderMode renderMode);
311 
GetRenderMode()312     RenderMode GetRenderMode()
313     {
314         return renderMode_;
315     }
316 
SetIncognitoMode(bool incognitoMode)317     void SetIncognitoMode(bool incognitoMode)
318     {
319         incognitoMode_ = incognitoMode;
320     }
321 
GetIncognitoMode()322     bool GetIncognitoMode() const
323     {
324         return incognitoMode_;
325     }
326 
SetSharedRenderProcessToken(const std::string & sharedRenderProcessToken)327     void SetSharedRenderProcessToken(const std::string& sharedRenderProcessToken)
328     {
329         sharedRenderProcessToken_ = sharedRenderProcessToken;
330     }
331 
GetSharedRenderProcessToken()332     const std::optional<std::string>& GetSharedRenderProcessToken() const
333     {
334         return sharedRenderProcessToken_;
335     }
336 
SetOnControllerAttachedCallback(OnControllerAttachedCallback && callback)337     void SetOnControllerAttachedCallback(OnControllerAttachedCallback&& callback)
338     {
339         onControllerAttachedCallback_ = std::move(callback);
340     }
341 
GetOnControllerAttachedCallback()342     OnControllerAttachedCallback GetOnControllerAttachedCallback()
343     {
344         return onControllerAttachedCallback_;
345     }
346 
SetSetHapPathCallback(SetHapPathCallback && callback)347     void SetSetHapPathCallback(SetHapPathCallback&& callback)
348     {
349         setHapPathCallback_ = std::move(callback);
350     }
351 
GetSetHapPathCallback()352     SetHapPathCallback GetSetHapPathCallback() const
353     {
354         return setHapPathCallback_;
355     }
356 
SetJsProxyCallback(JsProxyCallback && jsProxyCallback)357     void SetJsProxyCallback(JsProxyCallback&& jsProxyCallback)
358     {
359         jsProxyCallback_ = std::move(jsProxyCallback);
360     }
361 
CallJsProxyCallback()362     void CallJsProxyCallback()
363     {
364         if (jsProxyCallback_) {
365             jsProxyCallback_();
366         }
367     }
368 
GetWebEventHub()369     RefPtr<WebEventHub> GetWebEventHub()
370     {
371         return GetEventHub<WebEventHub>();
372     }
373 
GetFocusPattern()374     FocusPattern GetFocusPattern() const override
375     {
376         FocusPattern focusPattern = { FocusType::NODE, true, FocusStyleType::FORCE_NONE };
377         focusPattern.SetIsFocusActiveWhenFocused(true);
378         return focusPattern;
379     }
380 
CreatePaintProperty()381     RefPtr<PaintProperty> CreatePaintProperty() override
382     {
383         if (!webPaintProperty_) {
384             webPaintProperty_ = MakeRefPtr<WebPaintProperty>();
385             if (!webPaintProperty_) {
386             }
387         }
388         return webPaintProperty_;
389     }
390 
CreateLayoutAlgorithm()391     RefPtr<LayoutAlgorithm> CreateLayoutAlgorithm() override
392     {
393         return MakeRefPtr<WebLayoutAlgorithm>();
394     }
395 
BetweenSelectedPosition(const Offset & globalOffset)396     bool BetweenSelectedPosition(const Offset& globalOffset) override
397     {
398         return false;
399     }
400 
GetDragRecordSize()401     int32_t GetDragRecordSize() override
402     {
403         return 1;
404     }
405 
406     /**
407      *  NestableScrollContainer implementations
408      */
GetAxis()409     Axis GetAxis() const override
410     {
411         return axis_;
412     }
413     ScrollResult HandleScroll(float offset, int32_t source, NestedState state, float velocity = 0.f) override;
414     ScrollResult HandleScroll(RefPtr<NestableScrollContainer> parent, float offset, int32_t source, NestedState state);
415     bool HandleScrollVelocity(float velocity, const RefPtr<NestableScrollContainer>& child = nullptr) override;
416     bool HandleScrollVelocity(RefPtr<NestableScrollContainer> parent, float velocity);
417     void OnScrollStartRecursive(WeakPtr<NestableScrollContainer> child, float position, float velocity = 0.f) override;
418     void OnScrollStartRecursive(std::vector<float> positions);
419     void OnScrollEndRecursive(const std::optional<float>& velocity) override;
420     void OnAttachToBuilderNode(NodeStatus nodeStatus) override;
421     void GetParentAxis();
422     RefPtr<NestableScrollContainer> SearchParent() override;
423     RefPtr<NestableScrollContainer> SearchParent(Axis scrollAxis);
424     /**
425      *  End of NestableScrollContainer implementations
426      */
427     void OnParentScrollDragEndRecursive(RefPtr<NestableScrollContainer> parent);
428 
429     void SetNestedScrollExt(const NestedScrollOptionsExt &nestedScroll);
GetNestedScrollExt()430     NestedScrollOptionsExt GetNestedScrollExt() const
431     {
432         return nestedScroll_;
433     }
434     ACE_DEFINE_PROPERTY_GROUP(WebProperty, WebPatternProperty);
435     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, JsEnabled, bool);
436     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, MediaPlayGestureAccess, bool);
437     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, FileAccessEnabled, bool);
438     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, OnLineImageAccessEnabled, bool);
439     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, DomStorageAccessEnabled, bool);
440     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, ImageAccessEnabled, bool);
441     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, MixedMode, MixedModeContent);
442     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, ZoomAccessEnabled, bool);
443     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, GeolocationAccessEnabled, bool);
444     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, UserAgent, std::string);
445     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, CacheMode, WebCacheMode);
446     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, OverviewModeAccessEnabled, bool);
447     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, FileFromUrlAccessEnabled, bool);
448     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, DatabaseAccessEnabled, bool);
449     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, TextZoomRatio, int32_t);
450     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, WebDebuggingAccessEnabled, bool);
451     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, BackgroundColor, int32_t);
452     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, InitialScale, float);
453     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, PinchSmoothModeEnabled, bool);
454     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, MultiWindowAccessEnabled, bool);
455     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, AllowWindowOpenMethod, bool);
456     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, WebCursiveFont, std::string);
457     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, WebFantasyFont, std::string);
458     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, WebFixedFont, std::string);
459     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, WebSansSerifFont, std::string);
460     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, WebSerifFont, std::string);
461     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, WebStandardFont, std::string);
462     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, DefaultFixedFontSize, int32_t);
463     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, DefaultFontSize, int32_t);
464     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, DefaultTextEncodingFormat, std::string);
465     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, MinFontSize, int32_t);
466     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, MinLogicalFontSize, int32_t);
467     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, BlockNetwork, bool);
468     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, DarkMode, WebDarkMode);
469     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, ForceDarkAccess, bool);
470     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, AudioResumeInterval, int32_t);
471     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, AudioExclusive, bool);
472     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, HorizontalScrollBarAccessEnabled, bool);
473     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, VerticalScrollBarAccessEnabled, bool);
474     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, ScrollBarColor, std::string);
475     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, OverScrollMode, int32_t);
476     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, BlurOnKeyboardHideMode, int32_t);
477     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, CopyOptionMode, int32_t);
478     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, MetaViewport, bool);
479     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, NativeEmbedModeEnabled, bool);
480     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, NativeEmbedRuleTag, std::string);
481     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, NativeEmbedRuleType, std::string);
482     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, TextAutosizing, bool);
483     using NativeVideoPlayerConfigType = std::tuple<bool, bool>;
484     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, NativeVideoPlayerConfig, NativeVideoPlayerConfigType);
485     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, SelectionMenuOptions, WebMenuOptionsParam);
486     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, OverlayScrollbarEnabled, bool);
487     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, KeyboardAvoidMode, WebKeyboardAvoidMode);
488     ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, EnabledHapticFeedback, bool);
489 
IsFocus()490     bool IsFocus() const
491     {
492         return isFocus_;
493     }
494 
495     void RequestFullScreen();
496     void ExitFullScreen();
IsFullScreen()497     bool IsFullScreen() const
498     {
499         return isFullScreen_;
500     }
501     void UpdateClippedSelectionBounds(int32_t x, int32_t y, int32_t w, int32_t h);
502     bool RunQuickMenu(std::shared_ptr<OHOS::NWeb::NWebQuickMenuParams> params,
503         std::shared_ptr<OHOS::NWeb::NWebQuickMenuCallback> callback);
504     void OnContextMenuShow(const std::shared_ptr<BaseEventInfo>& info, bool isRichtext = true, bool result = false);
505     void OnContextMenuHide();
506     void QuickMenuIsNeedNewAvoid(
507         SelectOverlayInfo& selectInfo,
508         std::shared_ptr<OHOS::NWeb::NWebQuickMenuParams> params,
509         std::shared_ptr<OHOS::NWeb::NWebTouchHandleState> startHandle,
510         std::shared_ptr<OHOS::NWeb::NWebTouchHandleState> endHandle);
511     RectF ComputeClippedSelectionBounds(
512         std::shared_ptr<OHOS::NWeb::NWebQuickMenuParams> params,
513         std::shared_ptr<OHOS::NWeb::NWebTouchHandleState> startHandle,
514         std::shared_ptr<OHOS::NWeb::NWebTouchHandleState> endHandle,
515         bool& isNewAvoid);
516     void OnQuickMenuDismissed();
517     void HideHandleAndQuickMenuIfNecessary(bool hide, bool isScroll = false);
518     void ChangeVisibilityOfQuickMenu();
519     bool IsQuickMenuShow();
520     void OnTouchSelectionChanged(std::shared_ptr<OHOS::NWeb::NWebTouchHandleState> insertHandle,
521         std::shared_ptr<OHOS::NWeb::NWebTouchHandleState> startSelectionHandle,
522         std::shared_ptr<OHOS::NWeb::NWebTouchHandleState> endSelectionHandle);
523     bool OnCursorChange(const OHOS::NWeb::CursorType& type, std::shared_ptr<OHOS::NWeb::NWebCursorInfo> info);
524     void UpdateLocalCursorStyle(int32_t windowId, const OHOS::NWeb::CursorType& type);
525     void UpdateCustomCursor(int32_t windowId, std::shared_ptr<OHOS::NWeb::NWebCursorInfo> info);
526     std::shared_ptr<OHOS::Media::PixelMap> CreatePixelMapFromString(const std::string& filePath);
527     void OnSelectPopupMenu(std::shared_ptr<OHOS::NWeb::NWebSelectPopupMenuParam> params,
528         std::shared_ptr<OHOS::NWeb::NWebSelectPopupMenuCallback> callback);
529     void OnDateTimeChooserPopup(
530         std::shared_ptr<OHOS::NWeb::NWebDateTimeChooser> chooser,
531         const std::vector<std::shared_ptr<OHOS::NWeb::NWebDateTimeSuggestion>>& suggestions,
532         std::shared_ptr<NWeb::NWebDateTimeChooserCallback> callback);
533     void OnDateTimeChooserClose();
534     void OnShowAutofillPopup(const float offsetX, const float offsetY, const std::vector<std::string>& menu_items);
535     void OnHideAutofillPopup();
536     void UpdateTouchHandleForOverlay(bool fromOverlay = false);
IsSelectOverlayDragging()537     bool IsSelectOverlayDragging()
538     {
539         return selectOverlayDragging_;
540     }
SetSelectOverlayDragging(bool selectOverlayDragging)541     void SetSelectOverlayDragging(bool selectOverlayDragging)
542     {
543         selectOverlayDragging_ = selectOverlayDragging;
544     }
545     void UpdateLocale();
546     void SetDrawRect(int32_t x, int32_t y, int32_t width, int32_t height);
SetSelectPopupMenuShowing(bool showing)547     void SetSelectPopupMenuShowing(bool showing)
548     {
549         selectPopupMenuShowing_ = showing;
550     }
SetCurrentStartHandleDragging(bool isStartHandle)551     void SetCurrentStartHandleDragging(bool isStartHandle)
552     {
553         isCurrentStartHandleDragging_ = isStartHandle;
554     }
555     void ParseViewDataNumber(const std::string& key, int32_t value,
556         RefPtr<PageNodeInfoWrap> node, RectT<float>& rect, float viewScale);
557     void ParseNWebViewDataNode(std::unique_ptr<JsonValue> child,
558         std::vector<RefPtr<PageNodeInfoWrap>>& nodeInfos, int32_t nodeId);
559     void ParseNWebViewDataCommonField(std::unique_ptr<JsonValue> child, ViewDataCommon& viewDataCommon);
560     void ParseNWebViewDataJson(const std::shared_ptr<OHOS::NWeb::NWebMessage>& viewDataJson,
561         std::vector<RefPtr<PageNodeInfoWrap>>& nodeInfos, ViewDataCommon& viewDataCommon);
562     AceAutoFillType GetFocusedType();
563     HintToTypeWrap GetHintTypeAndMetadata(const std::string& attribute, RefPtr<PageNodeInfoWrap> node);
564     bool HandleAutoFillEvent(const std::shared_ptr<OHOS::NWeb::NWebMessage>& viewDataJson);
565     bool RequestAutoFill(AceAutoFillType autoFillType);
566     bool RequestAutoSave();
567     bool UpdateAutoFillPopup();
568     bool CloseAutoFillPopup();
569     void UpdateSelectHandleInfo();
570     bool IsSelectHandleReverse();
571     void OnCompleteSwapWithNewSize();
572     void OnResizeNotWork();
573     void UpdateOnFocusTextField(bool isFocus);
574     bool OnBackPressed() override;
575     bool OnBackPressedForFullScreen() const;
576     void SetFullScreenExitHandler(const std::shared_ptr<FullScreenEnterEvent>& fullScreenExitHandler);
577     bool NotifyStartDragTask(bool isDelayed = false);
578     bool IsImageDrag();
579     void UpdateJavaScriptOnDocumentStart();
580     void UpdateJavaScriptOnDocumentEnd();
581     void JavaScriptOnDocumentStart(const ScriptItems& scriptItems);
582     void JavaScriptOnDocumentEnd(const ScriptItems& scriptItems);
583     void SetTouchEventInfo(const TouchEvent& touchEvent,
584         TouchEventInfo& touchEventInfo, const std::string& embdedId);
585     DragRet GetDragAcceptableStatus();
586     Offset GetDragOffset() const;
587     void RemovePreviewMenuNode();
588     void UpdateImagePreviewParam();
589     void OnOverScrollFlingVelocity(float xVelocity, float yVelocity, bool isFling);
590     void OnScrollState(bool scrollState);
591     void SetLayoutMode(WebLayoutMode mode);
GetLayoutMode()592     WebLayoutMode GetLayoutMode() const
593     {
594         return layoutMode_;
595     }
596     void OnRootLayerChanged(int width, int height);
597     void ReleaseResizeHold();
598     bool GetPendingSizeStatus();
GetRootLayerWidth()599     int GetRootLayerWidth() const
600     {
601         return rootLayerWidth_;
602     }
GetRootLayerHeight()603     int GetRootLayerHeight() const
604     {
605         return rootLayerHeight_;
606     }
GetDrawSize()607     Size GetDrawSize() const
608     {
609         return drawSize_;
610     }
611     SizeF GetDragPixelMapSize() const;
IsVirtualKeyBoardShow()612     bool IsVirtualKeyBoardShow() const
613     {
614         return isVirtualKeyBoardShow_ == VkState::VK_SHOW;
615     }
616     bool FilterScrollEvent(const float x, const float y, const float xVelocity, const float yVelocity);
617     std::shared_ptr<OHOS::NWeb::NWebAccessibilityNodeInfo> GetFocusedAccessibilityNode(int64_t accessibilityId,
618         bool isAccessibilityFocus);
619     std::shared_ptr<OHOS::NWeb::NWebAccessibilityNodeInfo> GetAccessibilityNodeById(int64_t accessibilityId);
620     std::shared_ptr<OHOS::NWeb::NWebAccessibilityNodeInfo> GetAccessibilityNodeByFocusMove(int64_t accessibilityId,
621         int32_t direction);
622     bool ExecuteAction(int64_t accessibilityId, AceAction action,
623         const std::map<std::string, std::string>& actionArguments) const;
624     void SetAccessibilityState(bool state);
625     void UpdateFocusedAccessibilityId(int64_t accessibilityId = -1);
626     void ClearFocusedAccessibilityId();
627     void OnTooltip(const std::string& tooltip);
628     void GetVisibleRectToWeb(int& visibleX, int& visibleY, int& visibleWidth, int& visibleHeight);
629     bool IsDefaultFocusNodeExist();
630     bool IsRootNeedExportTexture();
631     std::vector<int8_t> GetWordSelection(const std::string& text, int8_t offset);
632     void CloseKeyboard();
633     bool Backward();
634     void OnSelectionMenuOptionsUpdate(const WebMenuOptionsParam& webMenuOption);
635     void UpdateEditMenuOptions(const NG::OnCreateMenuCallback&& onCreateMenuCallback,
636         const NG::OnMenuItemClickCallback&& onMenuItemClick);
637     void NotifyForNextTouchEvent() override;
638     void RequestFocus();
639     void CreateOverlay(const RefPtr<OHOS::Ace::PixelMap>& pixelMap, int offsetX, int offsetY, int rectWidth,
640         int rectHeight, int pointX, int pointY);
641     void OnOverlayStateChanged(int offsetX, int offsetY, int rectWidth, int rectHeight);
642     void OnTextSelected();
643     void DestroyAnalyzerOverlay();
OnCursorUpdate(double x,double y,double width,double height)644     void OnCursorUpdate(double x, double y, double width, double height)
645     {
646         cursorInfo_ = RectF(x, y, width, height);
647     }
GetCaretRect()648     RectF GetCaretRect() const override
649     {
650         return cursorInfo_;
651     }
652     void OnProgressChanged(int param);
653     WebInfoType GetWebInfoType();
GetWebSurfaceNodeId()654     Rosen::NodeId GetWebSurfaceNodeId() const
655     {
656         auto rosenRenderContext = AceType::DynamicCast<NG::RosenRenderContext>(renderContextForSurface_);
657         CHECK_NULL_RETURN(rosenRenderContext, 0);
658         auto rsNode = rosenRenderContext->GetRSNode();
659         CHECK_NULL_RETURN(rsNode, 0);
660         auto surfaceNodeId = rsNode->GetId();
661         TAG_LOGD(AceLogTag::ACE_WEB, "Web surfaceNodeId is %{public}" PRIu64 "", surfaceNodeId);
662         return surfaceNodeId;
663     }
SetCustomKeyboardBuilder(std::function<void ()> customKeyboardBuilder)664     void SetCustomKeyboardBuilder(std::function<void()> customKeyboardBuilder)
665     {
666         customKeyboardBuilder_ = customKeyboardBuilder;
667     }
668     void AttachCustomKeyboard();
669     void CloseCustomKeyboard();
670     std::shared_ptr<Rosen::RSNode> GetSurfaceRSNode() const;
671 
672     void OnAttachContext(PipelineContext *context) override;
673     void OnDetachContext(PipelineContext *context) override;
674     void SetUpdateInstanceIdCallback(std::function<void(int32_t)> &&callabck);
675     void KeyboardReDispatch(const std::shared_ptr<OHOS::NWeb::NWebKeyEvent>& event, bool isUsed);
676     void GetAllWebAccessibilityNodeInfos(WebNodeInfoCallback cb, int32_t webId);
677     bool OnAccessibilityHoverEvent(const PointF& point) override;
678     void RegisterWebComponentClickCallback(WebComponentClickCallback&& callback);
679     void UnregisterWebComponentClickCallback();
GetWebComponentClickCallback()680     WebComponentClickCallback GetWebComponentClickCallback() const { return webComponentClickCallback_; }
681 
682     void RegisterTextBlurCallback(TextBlurCallback&& callback);
683     void UnRegisterTextBlurCallback();
GetTextBlurCallback()684     TextBlurCallback GetTextBlurCallback() const
685     {
686         return textBlurCallback_;
687     }
688     void OnSetAccessibilityChildTree(int32_t childWindowId, int32_t childTreeId);
689     bool OnAccessibilityChildTreeRegister();
690     bool OnAccessibilityChildTreeDeregister();
691     bool GetActiveStatus() const;
692     void StartVibraFeedback(const std::string& vibratorType);
GetTreeId()693     int32_t GetTreeId()
694     {
695         return treeId_;
696     }
697     // The magnifier needs this to know the web's offset
698     OffsetF GetTextPaintOffset() const override;
699     void OnColorConfigurationUpdate() override;
700     bool CloseImageOverlaySelection();
SetImageOverlaySelectedStatus(bool isSelected)701     void SetImageOverlaySelectedStatus(bool isSelected)
702     {
703         imageOverlayIsSelected_ = isSelected;
704     }
705 
IsPreviewImageNodeExist()706     bool IsPreviewImageNodeExist() const
707     {
708         return previewImageNodeId_.has_value();
709     }
710 
SetNewDragStyle(bool isNewDragStyle)711     void SetNewDragStyle(bool isNewDragStyle)
712     {
713         isNewDragStyle_ = isNewDragStyle;
714     }
715 
IsNewDragStyle()716     bool IsNewDragStyle() const
717     {
718         return isNewDragStyle_;
719     }
720 
IsDragging()721     bool IsDragging() const
722     {
723         return isDragging_;
724     }
725 
726     void SetPreviewSelectionMenu(const std::shared_ptr<WebPreviewSelectionMenuParam>& param);
727 
728     std::shared_ptr<WebPreviewSelectionMenuParam> GetPreviewSelectionMenuParams(
729         const WebElementType& type, const ResponseType& responseType);
730 
731     bool IsPreviewMenuNotNeedShowPreview();
732 
733     bool GetAccessibilityVisible(int64_t accessibilityId);
734 
735 private:
736     friend class WebContextSelectOverlay;
737 
738     void GetPreviewImageOffsetAndSize(bool isImage, Offset& previewOffset, SizeF& previewSize);
739     RefPtr<FrameNode> CreatePreviewImageFrameNode(bool isImage);
740     void ShowContextSelectOverlay(const RectF& firstHandle, const RectF& secondHandle,
741         TextResponseType responseType = TextResponseType::RIGHT_CLICK, bool handleReverse = false);
742     void CloseContextSelectionMenu();
743     RectF ComputeMouseClippedSelectionBounds(int32_t x, int32_t y, int32_t w, int32_t h);
744     void RegistVirtualKeyBoardListener(const RefPtr<PipelineContext> &context);
745     bool IsNeedResizeVisibleViewport();
746     bool ProcessVirtualKeyBoardHide(int32_t width, int32_t height, bool safeAreaEnabled);
747     bool ProcessVirtualKeyBoardShow(int32_t width, int32_t height, double keyboard, bool safeAreaEnabled);
748     bool ProcessVirtualKeyBoard(int32_t width, int32_t height, double keyboard);
749     void UpdateWebLayoutSize(int32_t width, int32_t height, bool isKeyboard, bool isUpdate = true);
750     void UpdateLayoutAfterKeyboardShow(int32_t width, int32_t height, double keyboard, double oldWebHeight);
751     bool OnDirtyLayoutWrapperSwap(const RefPtr<LayoutWrapper>& dirty, const DirtySwapConfig& config) override;
752     void BeforeSyncGeometryProperties(const DirtySwapConfig& config) override;
753     void OnRebuildFrame() override;
754 
755     void OnAttachToFrameNode() override;
756     void OnDetachFromFrameNode(FrameNode* frameNode) override;
757     void OnAttachToMainTree() override;
758     void OnDetachFromMainTree() override;
759 
760     void OnWindowShow() override;
761     void OnWindowHide() override;
762     void OnWindowSizeChanged(int32_t width, int32_t height, WindowSizeChangeReason type) override;
763     void OnInActive() override;
764     void OnActive() override;
765     void OnVisibleAreaChange(bool isVisible);
766     void OnAreaChangedInner() override;
767     void OnNotifyMemoryLevel(int32_t level) override;
768 
769     void OnWebSrcUpdate();
770     void OnWebDataUpdate();
771     void OnJsEnabledUpdate(bool value);
772     void OnMediaPlayGestureAccessUpdate(bool value);
773     void OnFileAccessEnabledUpdate(bool value);
774     void OnOnLineImageAccessEnabledUpdate(bool value);
775     void OnDomStorageAccessEnabledUpdate(bool value);
776     void OnImageAccessEnabledUpdate(bool value);
777     void OnMixedModeUpdate(MixedModeContent value);
778     void OnZoomAccessEnabledUpdate(bool value);
779     void OnGeolocationAccessEnabledUpdate(bool value);
780     void OnUserAgentUpdate(const std::string& value);
781     void OnCacheModeUpdate(WebCacheMode value);
782     void OnOverviewModeAccessEnabledUpdate(bool value);
783     void OnFileFromUrlAccessEnabledUpdate(bool value);
784     void OnDatabaseAccessEnabledUpdate(bool value);
785     void OnTextZoomRatioUpdate(int32_t value);
786     void OnWebDebuggingAccessEnabledUpdate(bool value);
787     void OnPinchSmoothModeEnabledUpdate(bool value);
788     void OnBackgroundColorUpdate(int32_t value);
789     void OnInitialScaleUpdate(float value);
790     void OnMultiWindowAccessEnabledUpdate(bool value);
791     void OnAllowWindowOpenMethodUpdate(bool value);
792     void OnWebCursiveFontUpdate(const std::string& value);
793     void OnWebFantasyFontUpdate(const std::string& value);
794     void OnWebFixedFontUpdate(const std::string& value);
795     void OnWebSerifFontUpdate(const std::string& value);
796     void OnWebSansSerifFontUpdate(const std::string& value);
797     void OnWebStandardFontUpdate(const std::string& value);
798     void OnDefaultFixedFontSizeUpdate(int32_t value);
799     void OnDefaultFontSizeUpdate(int32_t value);
800     void OnDefaultTextEncodingFormatUpdate(const std::string& value);
801     void OnMinFontSizeUpdate(int32_t value);
802     void OnMinLogicalFontSizeUpdate(int32_t value);
803     void OnBlockNetworkUpdate(bool value);
804     void OnDarkModeUpdate(WebDarkMode mode);
805     void OnForceDarkAccessUpdate(bool access);
806     void OnAudioResumeIntervalUpdate(int32_t resumeInterval);
807     void OnAudioExclusiveUpdate(bool audioExclusive);
808     void OnHorizontalScrollBarAccessEnabledUpdate(bool value);
809     void OnVerticalScrollBarAccessEnabledUpdate(bool value);
810     void OnScrollBarColorUpdate(const std::string& value);
811     void OnOverScrollModeUpdate(const int32_t value);
812     void OnBlurOnKeyboardHideModeUpdate(const int32_t value);
813     void OnCopyOptionModeUpdate(const int32_t value);
814     void OnMetaViewportUpdate(bool value);
815     void OnNativeEmbedModeEnabledUpdate(bool value);
816     void OnNativeEmbedRuleTagUpdate(const std::string& tag);
817     void OnNativeEmbedRuleTypeUpdate(const std::string& type);
818     void OnTextAutosizingUpdate(bool isTextAutosizing);
819     void OnNativeVideoPlayerConfigUpdate(const std::tuple<bool, bool>& config);
820     void WindowDrag(int32_t width, int32_t height);
821     void OnSmoothDragResizeEnabledUpdate(bool value);
822     void OnOverlayScrollbarEnabledUpdate(bool enable);
823     void OnKeyboardAvoidModeUpdate(const WebKeyboardAvoidMode& mode);
824     void OnEnabledHapticFeedbackUpdate(bool enable);
825     int GetWebId();
826 
827     void InitEvent();
828     void InitConfigChangeCallback(const RefPtr<PipelineContext>& context);
829     void InitFeatureParam();
830     void InitTouchEvent(const RefPtr<GestureEventHub>& gestureHub);
831     void InitMouseEvent(const RefPtr<InputEventHub>& inputHub);
832     void InitHoverEvent(const RefPtr<InputEventHub>& inputHub);
833     void InitCommonDragDropEvent(const RefPtr<GestureEventHub>& gestureHub);
834     void InitWebEventHubDragDropStart(const RefPtr<WebEventHub>& eventHub);
835     void InitWebEventHubDragDropEnd(const RefPtr<WebEventHub>& eventHub);
836     void InitWebEventHubDragMove(const RefPtr<WebEventHub>& eventHub);
837     void InitPanEvent(const RefPtr<GestureEventHub>& gestureHub);
838     void HandleFlingMove(const GestureEvent& event);
839     void HandleDragMove(const GestureEvent& event);
840     void InitDragEvent(const RefPtr<GestureEventHub>& gestureHub);
841     void HandleDragStart(int32_t x, int32_t y);
842     void HandleDragEnd(int32_t x, int32_t y);
843     void HandleDragCancel();
844     void ClearDragData();
845     bool GenerateDragDropInfo(NG::DragDropInfo& dragDropInfo);
846     void HandleMouseEvent(MouseInfo& info);
847     void WebOnMouseEvent(const MouseInfo& info);
848     bool HandleDoubleClickEvent(const MouseInfo& info);
849     void SendDoubleClickEvent(const MouseClickInfo& info);
850     void InitFocusEvent(const RefPtr<FocusHub>& focusHub);
851     void HandleFocusEvent();
852     void HandleBlurEvent(const BlurReason& blurReason);
853     bool HandleKeyEvent(const KeyEvent& keyEvent);
854     bool WebOnKeyEvent(const KeyEvent& keyEvent);
855     void WebRequestFocus();
856     void ResetDragAction();
857     void InitSlideUpdateListener();
858     void CalculateHorizontalDrawRect();
859     void CalculateVerticalDrawRect();
860     void InitPinchEvent(const RefPtr<GestureEventHub>& gestureHub);
861     bool CheckZoomStatus(const double& curScale);
862     bool ZoomOutAndIn(const double& curScale, double& scale);
863     void HandleScaleGestureChange(const GestureEvent& event);
864 
865     NG::DragDropInfo HandleOnDragStart(const RefPtr<OHOS::Ace::DragEvent>& info);
866     void HandleOnDragEnter(const RefPtr<OHOS::Ace::DragEvent>& info);
867     void HandleOnDropMove(const RefPtr<OHOS::Ace::DragEvent>& info);
868     void HandleOnDragDrop(const RefPtr<OHOS::Ace::DragEvent>& info);
869     void HandleOnDragDropFile(RefPtr<UnifiedData> aceData);
870     void HandleOnDragDropLink(RefPtr<UnifiedData> aceData);
871     void HandleOnDragLeave(int32_t x, int32_t y);
872     void HandleOnDragEnd(int32_t x, int32_t y);
873     void InitTouchEventListener();
874     void UninitTouchEventListener();
875     void OnDragFileNameStart(const RefPtr<UnifiedData>& aceUnifiedData, const std::string& fileName);
876     bool needRestoreMenuForDrag_ = false;
877     int32_t dropX_ = 0;
878     int32_t dropY_ = 0;
879     int onDragMoveCnt = 0;
880     bool isDragEndMenuShow_ = false;
881     std::shared_ptr<OHOS::NWeb::NWebQuickMenuParams> dropParams_ = nullptr;
882     std::chrono::time_point<std::chrono::system_clock> firstMoveInTime;
883     std::chrono::time_point<std::chrono::system_clock> preMoveInTime;
884     std::chrono::time_point<std::chrono::system_clock> curMoveInTime;
885     CancelableCallback<void()> timer_;
886     int32_t duration_ = 100; // 100: 100ms
887     void DoRepeat();
888     void StartRepeatTimer();
889 
890     void HandleTouchDown(const TouchEventInfo& info, bool fromOverlay);
891 
892     void HandleTouchUp(const TouchEventInfo& info, bool fromOverlay);
893 
894     void HandleTouchMove(const TouchEventInfo& info, bool fromOverlay);
895 
896     void HandleTouchCancel(const TouchEventInfo& info);
897 
898     void HandleTouchClickEventFromOverlay(const GestureEvent& info);
899     RectF ChangeHandleHeight(
900         const std::shared_ptr<SelectOverlayInfo>& info, const GestureEvent& event, bool isFirst);
901     void OnSelectHandleStart(const GestureEvent& event, bool isFirst);
902     void OnSelectHandleDone(const RectF& handleRect, bool isFirst);
903     void OnSelectHandleMove(const RectF& handleRect, bool isFirst);
904 
905     bool IsTouchHandleValid(std::shared_ptr<OHOS::NWeb::NWebTouchHandleState> handle);
906     void CheckHandles(SelectHandleInfo& handleInfo, const std::shared_ptr<OHOS::NWeb::NWebTouchHandleState>& handle);
907 
908     void SuggestionSelected(int32_t index);
909     void RegisterSelectOverLayOnClose(SelectOverlayInfo& selectInfo);
910     void InitializeAccessibility();
911     void UninitializeAccessibility();
912 #ifdef OHOS_STANDARD_SYSTEM
913     WebOverlayType GetTouchHandleOverlayType(
914         std::shared_ptr<OHOS::NWeb::NWebTouchHandleState> insertHandle,
915         std::shared_ptr<OHOS::NWeb::NWebTouchHandleState> startSelectionHandle,
916         std::shared_ptr<OHOS::NWeb::NWebTouchHandleState> endSelectionHandle);
917 #endif
918     void OnParentScrollStartOrEndCallback(bool isEnd);
919     void RegisterSelectOverlayParentScrollCallback(int32_t parentId, int32_t callbackId);
920     void StartListenSelectOverlayParentScroll(const RefPtr<FrameNode>& host);
921     void StopListenSelectOverlayParentScroll(const RefPtr<FrameNode>& host);
922     void RegisterSelectOverlayCallback(SelectOverlayInfo& selectInfo,
923         std::shared_ptr<OHOS::NWeb::NWebQuickMenuParams> params,
924         std::shared_ptr<OHOS::NWeb::NWebQuickMenuCallback> callback);
925     void RegisterSelectOverlayEvent(SelectOverlayInfo& selectInfo);
926     void CloseSelectOverlay();
927     RectF ComputeTouchHandleRect(std::shared_ptr<OHOS::NWeb::NWebTouchHandleState> touchHandle);
928     void DelTouchOverlayInfoByTouchId(int32_t touchId);
929     std::optional<OffsetF> GetCoordinatePoint();
930     static void InitSelectPopupMenuViewOption(const std::vector<RefPtr<FrameNode>>& options,
931         const std::shared_ptr<OHOS::NWeb::NWebSelectPopupMenuCallback>& callback,
932         const std::shared_ptr<OHOS::NWeb::NWebSelectPopupMenuParam>& params,
933         const double& dipScale);
934     static void InitSelectPopupMenuView(RefPtr<FrameNode>& menuWrapper,
935         std::shared_ptr<OHOS::NWeb::NWebSelectPopupMenuCallback> callback,
936         std::shared_ptr<OHOS::NWeb::NWebSelectPopupMenuParam> params,
937         const double& dipScale);
938     OffsetF GetSelectPopupPostion(std::shared_ptr<OHOS::NWeb::NWebSelectMenuBound> bound);
939     bool GetAccessibilityFocusRect(RectT<int32_t>& paintRect, int64_t accessibilityId) const;
940     void SetTouchLocationInfo(const TouchEvent& touchEvent, const TouchLocationInfo& changedInfo,
941         const TouchEventInfo& tempTouchInfo, TouchEventInfo& touchEventInfo);
942     struct TouchInfo {
943         float x = -1.0f;
944         float y = -1.0f;
945         int32_t id = -1;
946     };
947     static bool ParseTouchInfo(const TouchEventInfo& info, std::list<TouchInfo>& touchInfos);
948     void InitEnhanceSurfaceFlag();
949     void UpdateBackgroundColorRightNow(int32_t color);
950     void UpdateContentOffset(const RefPtr<LayoutWrapper>& dirty);
951     DialogProperties GetDialogProperties(const RefPtr<DialogTheme>& theme);
952     bool ShowDateTimeDialog(std::shared_ptr<OHOS::NWeb::NWebDateTimeChooser> chooser,
953         const std::vector<std::shared_ptr<OHOS::NWeb::NWebDateTimeSuggestion>>& suggestions,
954         std::shared_ptr<NWeb::NWebDateTimeChooserCallback> callback);
955     bool ShowTimeDialog(std::shared_ptr<OHOS::NWeb::NWebDateTimeChooser> chooser,
956         const std::vector<std::shared_ptr<OHOS::NWeb::NWebDateTimeSuggestion>>& suggestions,
957         std::shared_ptr<NWeb::NWebDateTimeChooserCallback> callback);
958     bool ShowDateTimeSuggestionDialog(std::shared_ptr<OHOS::NWeb::NWebDateTimeChooser> chooser,
959         const std::vector<std::shared_ptr<OHOS::NWeb::NWebDateTimeSuggestion>>& suggestions,
960         std::shared_ptr<NWeb::NWebDateTimeChooserCallback> callback);
961     void PostTaskToUI(const std::function<void()>&& task, const std::string& name) const;
962     void RegisterVisibleAreaChangeCallback(const RefPtr<PipelineContext> &context);
963     void SetSurfaceDensity(double density);
964     void InitInOfflineMode();
965     void OnOverScrollFlingVelocityHandler(float velocity, bool isFling);
966     bool FilterScrollEventHandleOffset(const float offset);
967     bool CheckParentScroll(const float &directValue, const NestedScrollMode &scrollMode);
968     bool CheckOverParentScroll(const float &directValue, const NestedScrollMode &scrollMode);
969     bool FilterScrollEventHandlevVlocity(const float velocity);
970     bool IsDialogNested();
971     void CalculateTooltipOffset(RefPtr<FrameNode>& tooltipNode, OffsetF& tooltipOfffset);
972     void SetTooltipTextLayoutPropertyInner(const RefPtr<PipelineContext>& pipeline,
973         const std::string& tooltip, RefPtr<OverlayManager>& overlayManager);
974     void HandleShowTooltip(const std::string& tooltip, int64_t tooltipTimestamp);
975     void ShowTooltip(const std::string& tooltip, int64_t tooltipTimestamp);
SetMouseHoverExit(bool isHoverExit)976     void SetMouseHoverExit(bool isHoverExit)
977     {
978         isHoverExit_ = isHoverExit;
979     }
980     void SelectCancel() const;
981     bool IsSelectInfoValid();
982     std::string GetSelectInfo() const;
983     void UpdateRunQuickMenuSelectInfo(SelectOverlayInfo& selectInfo,
984         std::shared_ptr<OHOS::NWeb::NWebQuickMenuParams> params,
985         std::shared_ptr<OHOS::NWeb::NWebTouchHandleState> insertTouchHandle,
986         std::shared_ptr<OHOS::NWeb::NWebTouchHandleState> beginTouchHandle,
987         std::shared_ptr<OHOS::NWeb::NWebTouchHandleState> endTouchHandle);
988     void UpdateSlideOffset();
989     double GetNewScale(double& scale) const;
990     void SetRotation(uint32_t rotation);
991     Color GetSystemColor() const;
UpdateTransformHintChangedCallbackId(std::optional<int32_t> id)992     void UpdateTransformHintChangedCallbackId(std::optional<int32_t> id)
993     {
994         transformHintChangedCallbackId_ = id;
995     }
996 
HasTransformHintChangedCallbackId()997     bool HasTransformHintChangedCallbackId()
998     {
999         return transformHintChangedCallbackId_.has_value();
1000     }
1001     void ClearKeyEventByKeyCode(int32_t keyCode);
1002     bool CheckSafeAreaIsExpand();
1003     bool CheckSafeAreaKeyBoard();
1004     void JsonNodePutDefaultValue(std::unique_ptr<OHOS::Ace::JsonValue>& jsonNode,
1005         WebAccessibilityType key, int32_t value, int32_t defaultValue);
1006     void JsonNodePutDefaultValue(std::unique_ptr<OHOS::Ace::JsonValue>& jsonNode,
1007         WebAccessibilityType key, bool value);
1008     void JsonNodePutDefaultValue(std::unique_ptr<OHOS::Ace::JsonValue>& jsonNode,
1009         WebAccessibilityType key, std::string value);
1010     void WebNodeInfoToJsonValue(std::shared_ptr<OHOS::Ace::JsonValue>& jsonNodeArray,
1011                                 std::shared_ptr<OHOS::NWeb::NWebAccessibilityNodeInfo> webNodeInfo,
1012                                 std::string& nodeTag);
1013     void GetWebAllInfosImpl(WebNodeInfoCallback cb, int32_t webId);
1014     std::string EnumTypeToString(WebAccessibilityType type);
1015     std::string VectorIntToString(std::vector<int64_t>&& vec);
1016     void InitMagnifier();
1017     void ShowMagnifier(int centerOffsetX, int centerOffsetY);
1018     void HideMagnifier();
1019     void OnMagnifierHandleMove(const RectF& handleRect, bool isFirst);
1020     int32_t GetBufferSizeByDeviceType();
1021 
1022     std::optional<std::string> webSrc_;
1023     std::optional<std::string> webData_;
1024     std::optional<std::string> customScheme_;
1025     RefPtr<WebController> webController_;
1026     std::optional<int32_t> transformHintChangedCallbackId_;
1027     uint32_t rotation_ = 0;
1028     SetWebIdCallback setWebIdCallback_ = nullptr;
1029     DefaultFileSelectorShowCallback defaultFileSelectorShowCallback_ = nullptr;
1030     PermissionClipboardCallback permissionClipboardCallback_ = nullptr;
1031     OnOpenAppLinkCallback onOpenAppLinkCallback_ = nullptr;
1032     RenderMode renderMode_;
1033     bool incognitoMode_ = false;
1034     SetHapPathCallback setHapPathCallback_ = nullptr;
1035     JsProxyCallback jsProxyCallback_ = nullptr;
1036     OnControllerAttachedCallback onControllerAttachedCallback_ = nullptr;
1037     RefPtr<RenderSurface> renderSurface_ = RenderSurface::Create();
1038     RefPtr<RenderContext> renderContextForSurface_;
1039     RefPtr<TouchEventImpl> touchEvent_;
1040     RefPtr<InputEvent> mouseEvent_;
1041     RefPtr<InputEvent> hoverEvent_;
1042     RefPtr<PanEvent> panEvent_ = nullptr;
1043     bool selectTemporarilyHidden_ = false;
1044     bool selectTemporarilyHiddenByScroll_ = false;
1045     bool nodeAttach_ = false;
1046     ScrollableParentInfo scrollableParentInfo_;
1047     RefPtr<SelectOverlayProxy> selectOverlayProxy_ = nullptr;
1048     RefPtr<WebPaintProperty> webPaintProperty_ = nullptr;
1049     std::shared_ptr<OHOS::NWeb::NWebTouchHandleState> insertHandle_ = nullptr;
1050     std::shared_ptr<OHOS::NWeb::NWebTouchHandleState> startSelectionHandle_ = nullptr;
1051     std::shared_ptr<OHOS::NWeb::NWebTouchHandleState> endSelectionHandle_ = nullptr;
1052     bool isQuickMenuMouseTrigger_ = false;
1053     RefPtr<DragEvent> dragEvent_;
1054     bool isUrlLoaded_ = false;
1055     std::queue<MouseClickInfo> doubleClickQueue_;
1056     bool isFullScreen_ = false;
1057     std::shared_ptr<FullScreenEnterEvent> fullScreenExitHandler_ = nullptr;
1058     bool needOnFocus_ = false;
1059     Size drawSize_;
1060     Size visibleViewportSize_{-1.0, -1.0};
1061     bool isKeyboardInSafeArea_ = false;
1062     WebKeyboardAvoidMode keyBoardAvoidMode_ = WebKeyboardAvoidMode::DEFAULT;
1063     Size rootLayerChangeSize_;
1064     Size drawSizeCache_;
1065     Size areaChangeSize_;
1066     bool isNeedReDrawRect_ = false;
1067     bool needUpdateWeb_ = true;
1068     bool isFocus_ = false;
1069     VkState isVirtualKeyBoardShow_ { VkState::VK_NONE };
1070     bool isDragging_ = false;
1071     bool isReceivedArkDrag_ = false;
1072     bool isW3cDragEvent_ = false;
1073     bool isDragStartFromWeb_ = false;
1074 
1075     bool isNewDragStyle_ = false;
1076     std::map<std::pair<WebElementType, ResponseType>,
1077         std::shared_ptr<WebPreviewSelectionMenuParam>> previewSelectionMenuMap_;
1078     std::optional<int32_t> previewImageNodeId_ = std::nullopt;
1079     bool needUpdateImagePreviewParam_ = false;
1080     WebElementType curElementType_ = WebElementType::NONE;
1081     ResponseType curResponseType_ = ResponseType::LONG_PRESS;
1082     bool curContextMenuResult_ = false;
1083 
1084     bool isWindowShow_ = true;
1085     bool isActive_ = true;
1086     bool isEnhanceSurface_ = false;
1087     bool isAllowWindowOpenMethod_ = false;
1088     bool isShowAutofillPopup_ = false;
1089     OffsetF webOffset_;
1090     RefPtr<WebContextSelectOverlay> contextSelectOverlay_ = nullptr;
1091     RefPtr<WebContextMenuParam> contextMenuParam_ = nullptr;
1092     RefPtr<ContextMenuResult> contextMenuResult_ = nullptr;
1093     RectF selectArea_;
1094     RectF cursorInfo_;
1095     std::shared_ptr<OHOS::NWeb::NWebQuickMenuCallback> quickMenuCallback_ = nullptr;
1096     SelectMenuInfo selectMenuInfo_;
1097     bool selectOverlayDragging_ = false;
1098     bool selectPopupMenuShowing_ = false;
1099     bool isCurrentStartHandleDragging_ = false;
1100     std::list<TouchInfo> touchOverlayInfo_;
1101     bool isPopup_ = false;
1102     int32_t tooltipId_ = -1;
1103     int32_t mouseHoveredX_ = -1;
1104     int32_t mouseHoveredY_ = -1;
1105     int32_t mouseEventDeviceId_ = -1;
1106     int64_t tooltipTimestamp_ = -1;
1107     int32_t parentNWebId_ = -1;
1108     bool isInWindowDrag_ = false;
1109     bool isWaiting_ = false;
1110     bool isDisableDrag_ = false;
1111     bool isMouseEvent_ = false;
1112     bool isHoverExit_ = false;
1113     bool isVisible_ = true;
1114     bool isVisibleActiveEnable_ = true;
1115     bool isMemoryLevelEnable_ = true;
1116     OffsetF fitContentOffset_;
1117     bool isFirstFlingScrollVelocity_ = true;
1118     bool isNeedUpdateScrollAxis_ = true;
1119     bool isScrollStarted_ = false;
1120     WebLayoutMode layoutMode_ = WebLayoutMode::NONE;
1121     bool isEmbedModeEnabled_ = false;
1122     bool scrollState_ = false;
1123     Axis axis_ = Axis::FREE;
1124     Axis syncAxis_ = Axis::NONE;
1125     Axis expectedScrollAxis_ = Axis::FREE;
1126     int32_t rootLayerWidth_ = 0;
1127     int32_t rootLayerHeight_ = 0;
1128     int32_t drawRectWidth_ = 0;
1129     int32_t drawRectHeight_ = 0;
1130     std::unordered_map<Axis, WeakPtr<NestableScrollContainer>> parentsMap_;
1131     RefPtr<WebDelegate> delegate_;
1132     RefPtr<WebDelegateObserver> observer_;
1133     std::optional<ScriptItems> onDocumentStartScriptItems_;
1134     std::optional<ScriptItems> onDocumentEndScriptItems_;
1135     bool isAttachedToMainTree_ = false;
1136     bool offlineWebInited_ = false;
1137     bool offlineWebRendered_ = false;
1138     ACE_DISALLOW_COPY_AND_MOVE(WebPattern);
1139     bool accessibilityState_ = false;
1140     TouchEventInfo touchEventInfo_{"touchEvent"};
1141     std::vector<TouchEventInfo> touchEventInfoList_ {};
1142     bool isParentReachEdge_ = false;
1143     RefPtr<PinchGesture> pinchGesture_ = nullptr;
1144     std::queue<TouchEventInfo> touchEventQueue_;
1145     std::vector<NG::MenuOptionsParam> menuOptionParam_ {};
1146     std::list<KeyEvent> webKeyEvent_ {};
1147     double startPinchScale_ = -1.0;
1148     double preScale_ = -1.0;
1149     double pageScale_ = 1.0;
1150     int32_t pinchIndex_ = 0;
1151     bool zoomOutSwitch_ = false;
1152     bool isTouchUpEvent_ = false;
1153     std::shared_ptr<ImageAnalyzerManager> imageAnalyzerManager_ = nullptr;
1154     bool overlayCreating_ = false;
1155     int32_t zoomStatus_ = 0;
1156     int32_t zoomErrorCount_ = 0;
1157     int progressParam_ = 0;
1158     double lastKeyboardHeight_ = 0.0;
1159     std::shared_ptr<TouchEventListener> touchEventListener_ {nullptr};
1160     RefPtr<OverlayManager> keyboardOverlay_;
1161     std::function<void()> customKeyboardBuilder_ = nullptr;
1162     std::optional<std::string> sharedRenderProcessToken_;
1163     std::function<void(int32_t)> updateInstanceIdCallback_;
1164     bool inspectorAccessibilityEnable_ = false;
1165     bool textBlurAccessibilityEnable_ = false;
1166     WebComponentClickCallback webComponentClickCallback_ = nullptr;
1167     TextBlurCallback textBlurCallback_ = nullptr;
1168     uint32_t autoFillSessionId_ = 0;
1169     std::unordered_map<int32_t, std::shared_ptr<AccessibilityChildTreeCallback>> accessibilityChildTreeCallback_;
1170     int32_t treeId_ = 0;
1171     int32_t instanceId_ = -1;
1172     int64_t focusedAccessibilityId_ = -1;
1173     std::vector<RefPtr<PageNodeInfoWrap>> pageNodeInfo_;
1174     bool isRenderModeInit_ = false;
1175     bool isAutoFillClosing_ = true;
1176     ViewDataCommon viewDataCommon_;
1177     bool isPasswordFill_ = false;
1178     bool isEnabledHapticFeedback_ = true;
1179     bool imageOverlayIsSelected_ = false;
1180     int32_t densityCallbackId_ = 0;
1181     bool isLayoutModeChanged_ = false;
1182     float touchPointX = 0;
1183     float touchPointY = 0;
1184     bool isDragEnd_ = false;
1185 
1186 protected:
1187     OnCreateMenuCallback onCreateMenuCallback_;
1188     OnMenuItemClickCallback onMenuItemClick_;
1189     NestedScrollOptionsExt nestedScroll_ = {
1190         .scrollUp = NestedScrollMode::SELF_ONLY,
1191         .scrollDown = NestedScrollMode::SELF_ONLY,
1192         .scrollLeft = NestedScrollMode::SELF_ONLY,
1193         .scrollRight = NestedScrollMode::SELF_ONLY,
1194     };
1195 };
1196 } // namespace OHOS::Ace::NG
1197 
1198 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_WEB_WEB_PATTERN_H
1199