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 ACE_DEFINE_PROPERTY_GROUP(WebProperty, WebPatternProperty); 429 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, JsEnabled, bool); 430 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, MediaPlayGestureAccess, bool); 431 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, FileAccessEnabled, bool); 432 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, OnLineImageAccessEnabled, bool); 433 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, DomStorageAccessEnabled, bool); 434 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, ImageAccessEnabled, bool); 435 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, MixedMode, MixedModeContent); 436 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, ZoomAccessEnabled, bool); 437 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, GeolocationAccessEnabled, bool); 438 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, UserAgent, std::string); 439 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, CacheMode, WebCacheMode); 440 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, OverviewModeAccessEnabled, bool); 441 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, FileFromUrlAccessEnabled, bool); 442 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, DatabaseAccessEnabled, bool); 443 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, TextZoomRatio, int32_t); 444 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, WebDebuggingAccessEnabled, bool); 445 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, BackgroundColor, int32_t); 446 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, InitialScale, float); 447 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, PinchSmoothModeEnabled, bool); 448 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, MultiWindowAccessEnabled, bool); 449 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, AllowWindowOpenMethod, bool); 450 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, WebCursiveFont, std::string); 451 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, WebFantasyFont, std::string); 452 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, WebFixedFont, std::string); 453 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, WebSansSerifFont, std::string); 454 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, WebSerifFont, std::string); 455 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, WebStandardFont, std::string); 456 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, DefaultFixedFontSize, int32_t); 457 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, DefaultFontSize, int32_t); 458 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, DefaultTextEncodingFormat, std::string); 459 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, MinFontSize, int32_t); 460 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, MinLogicalFontSize, int32_t); 461 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, BlockNetwork, bool); 462 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, DarkMode, WebDarkMode); 463 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, ForceDarkAccess, bool); 464 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, AudioResumeInterval, int32_t); 465 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, AudioExclusive, bool); 466 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, HorizontalScrollBarAccessEnabled, bool); 467 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, VerticalScrollBarAccessEnabled, bool); 468 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, ScrollBarColor, std::string); 469 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, OverScrollMode, int32_t); 470 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, CopyOptionMode, int32_t); 471 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, MetaViewport, bool); 472 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, NativeEmbedModeEnabled, bool); 473 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, NativeEmbedRuleTag, std::string); 474 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, NativeEmbedRuleType, std::string); 475 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, TextAutosizing, bool); 476 using NativeVideoPlayerConfigType = std::tuple<bool, bool>; 477 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, NativeVideoPlayerConfig, NativeVideoPlayerConfigType); 478 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, SelectionMenuOptions, WebMenuOptionsParam); 479 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, OverlayScrollbarEnabled, bool); 480 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, KeyboardAvoidMode, WebKeyboardAvoidMode); 481 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, EnabledHapticFeedback, bool); 482 IsFocus()483 bool IsFocus() const 484 { 485 return isFocus_; 486 } 487 488 void RequestFullScreen(); 489 void ExitFullScreen(); IsFullScreen()490 bool IsFullScreen() const 491 { 492 return isFullScreen_; 493 } 494 void UpdateClippedSelectionBounds(int32_t x, int32_t y, int32_t w, int32_t h); 495 bool RunQuickMenu(std::shared_ptr<OHOS::NWeb::NWebQuickMenuParams> params, 496 std::shared_ptr<OHOS::NWeb::NWebQuickMenuCallback> callback); 497 void OnContextMenuShow(const std::shared_ptr<BaseEventInfo>& info, bool isRichtext = true, bool result = false); 498 void OnContextMenuHide(); 499 void QuickMenuIsNeedNewAvoid( 500 SelectOverlayInfo& selectInfo, 501 std::shared_ptr<OHOS::NWeb::NWebQuickMenuParams> params, 502 std::shared_ptr<OHOS::NWeb::NWebTouchHandleState> startHandle, 503 std::shared_ptr<OHOS::NWeb::NWebTouchHandleState> endHandle); 504 RectF ComputeClippedSelectionBounds( 505 std::shared_ptr<OHOS::NWeb::NWebQuickMenuParams> params, 506 std::shared_ptr<OHOS::NWeb::NWebTouchHandleState> startHandle, 507 std::shared_ptr<OHOS::NWeb::NWebTouchHandleState> endHandle, 508 bool& isNewAvoid); 509 void OnQuickMenuDismissed(); 510 void HideHandleAndQuickMenuIfNecessary(bool hide, bool isScroll = false); 511 void ChangeVisibilityOfQuickMenu(); 512 bool IsQuickMenuShow(); 513 void OnTouchSelectionChanged(std::shared_ptr<OHOS::NWeb::NWebTouchHandleState> insertHandle, 514 std::shared_ptr<OHOS::NWeb::NWebTouchHandleState> startSelectionHandle, 515 std::shared_ptr<OHOS::NWeb::NWebTouchHandleState> endSelectionHandle); 516 bool OnCursorChange(const OHOS::NWeb::CursorType& type, std::shared_ptr<OHOS::NWeb::NWebCursorInfo> info); 517 void UpdateLocalCursorStyle(int32_t windowId, const OHOS::NWeb::CursorType& type); 518 void UpdateCustomCursor(int32_t windowId, std::shared_ptr<OHOS::NWeb::NWebCursorInfo> info); 519 std::shared_ptr<OHOS::Media::PixelMap> CreatePixelMapFromString(const std::string& filePath); 520 void OnSelectPopupMenu(std::shared_ptr<OHOS::NWeb::NWebSelectPopupMenuParam> params, 521 std::shared_ptr<OHOS::NWeb::NWebSelectPopupMenuCallback> callback); 522 void OnDateTimeChooserPopup( 523 std::shared_ptr<OHOS::NWeb::NWebDateTimeChooser> chooser, 524 const std::vector<std::shared_ptr<OHOS::NWeb::NWebDateTimeSuggestion>>& suggestions, 525 std::shared_ptr<NWeb::NWebDateTimeChooserCallback> callback); 526 void OnDateTimeChooserClose(); 527 void OnShowAutofillPopup(const float offsetX, const float offsetY, const std::vector<std::string>& menu_items); 528 void OnHideAutofillPopup(); 529 void UpdateTouchHandleForOverlay(bool fromOverlay = false); IsSelectOverlayDragging()530 bool IsSelectOverlayDragging() 531 { 532 return selectOverlayDragging_; 533 } SetSelectOverlayDragging(bool selectOverlayDragging)534 void SetSelectOverlayDragging(bool selectOverlayDragging) 535 { 536 selectOverlayDragging_ = selectOverlayDragging; 537 } 538 void UpdateLocale(); 539 void SetDrawRect(int32_t x, int32_t y, int32_t width, int32_t height); SetSelectPopupMenuShowing(bool showing)540 void SetSelectPopupMenuShowing(bool showing) 541 { 542 selectPopupMenuShowing_ = showing; 543 } SetCurrentStartHandleDragging(bool isStartHandle)544 void SetCurrentStartHandleDragging(bool isStartHandle) 545 { 546 isCurrentStartHandleDragging_ = isStartHandle; 547 } 548 void ParseViewDataNumber(const std::string& key, int32_t value, 549 RefPtr<PageNodeInfoWrap> node, RectT<float>& rect, float viewScale); 550 void ParseNWebViewDataNode(std::unique_ptr<JsonValue> child, 551 std::vector<RefPtr<PageNodeInfoWrap>>& nodeInfos, int32_t nodeId); 552 void ParseNWebViewDataCommonField(std::unique_ptr<JsonValue> child, ViewDataCommon& viewDataCommon); 553 void ParseNWebViewDataJson(const std::shared_ptr<OHOS::NWeb::NWebMessage>& viewDataJson, 554 std::vector<RefPtr<PageNodeInfoWrap>>& nodeInfos, ViewDataCommon& viewDataCommon); 555 AceAutoFillType GetFocusedType(); 556 HintToTypeWrap GetHintTypeAndMetadata(const std::string& attribute, RefPtr<PageNodeInfoWrap> node); 557 bool HandleAutoFillEvent(const std::shared_ptr<OHOS::NWeb::NWebMessage>& viewDataJson); 558 bool RequestAutoFill(AceAutoFillType autoFillType); 559 bool RequestAutoSave(); 560 bool UpdateAutoFillPopup(); 561 bool CloseAutoFillPopup(); 562 void UpdateSelectHandleInfo(); 563 bool IsSelectHandleReverse(); 564 void OnCompleteSwapWithNewSize(); 565 void OnResizeNotWork(); 566 void UpdateOnFocusTextField(bool isFocus); 567 bool OnBackPressed() override; 568 bool OnBackPressedForFullScreen() const; 569 void SetFullScreenExitHandler(const std::shared_ptr<FullScreenEnterEvent>& fullScreenExitHandler); 570 bool NotifyStartDragTask(bool isDelayed = false); 571 bool IsImageDrag(); 572 void UpdateJavaScriptOnDocumentStart(); 573 void UpdateJavaScriptOnDocumentEnd(); 574 void JavaScriptOnDocumentStart(const ScriptItems& scriptItems); 575 void JavaScriptOnDocumentEnd(const ScriptItems& scriptItems); 576 void SetTouchEventInfo(const TouchEvent& touchEvent, 577 TouchEventInfo& touchEventInfo, const std::string& embdedId); 578 DragRet GetDragAcceptableStatus(); 579 Offset GetDragOffset() const; 580 void RemovePreviewMenuNode(); 581 void UpdateImagePreviewParam(); 582 void OnOverScrollFlingVelocity(float xVelocity, float yVelocity, bool isFling); 583 void OnScrollState(bool scrollState); 584 void SetLayoutMode(WebLayoutMode mode); GetLayoutMode()585 WebLayoutMode GetLayoutMode() const 586 { 587 return layoutMode_; 588 } 589 void OnRootLayerChanged(int width, int height); 590 void ReleaseResizeHold(); 591 bool GetPendingSizeStatus(); GetRootLayerWidth()592 int GetRootLayerWidth() const 593 { 594 return rootLayerWidth_; 595 } GetRootLayerHeight()596 int GetRootLayerHeight() const 597 { 598 return rootLayerHeight_; 599 } GetDrawSize()600 Size GetDrawSize() const 601 { 602 return drawSize_; 603 } 604 SizeF GetDragPixelMapSize() const; IsVirtualKeyBoardShow()605 bool IsVirtualKeyBoardShow() const 606 { 607 return isVirtualKeyBoardShow_ == VkState::VK_SHOW; 608 } 609 bool FilterScrollEvent(const float x, const float y, const float xVelocity, const float yVelocity); 610 std::shared_ptr<OHOS::NWeb::NWebAccessibilityNodeInfo> GetFocusedAccessibilityNode(int64_t accessibilityId, 611 bool isAccessibilityFocus); 612 std::shared_ptr<OHOS::NWeb::NWebAccessibilityNodeInfo> GetAccessibilityNodeById(int64_t accessibilityId); 613 std::shared_ptr<OHOS::NWeb::NWebAccessibilityNodeInfo> GetAccessibilityNodeByFocusMove(int64_t accessibilityId, 614 int32_t direction); 615 bool ExecuteAction(int64_t accessibilityId, AceAction action, 616 const std::map<std::string, std::string>& actionArguments) const; 617 void SetAccessibilityState(bool state); 618 void UpdateFocusedAccessibilityId(int64_t accessibilityId = -1); 619 void ClearFocusedAccessibilityId(); 620 void OnTooltip(const std::string& tooltip); 621 bool IsDefaultFocusNodeExist(); 622 bool IsRootNeedExportTexture(); 623 std::vector<int8_t> GetWordSelection(const std::string& text, int8_t offset); 624 void CloseKeyboard(); 625 bool Backward(); 626 void OnSelectionMenuOptionsUpdate(const WebMenuOptionsParam& webMenuOption); 627 void UpdateEditMenuOptions(const NG::OnCreateMenuCallback&& onCreateMenuCallback, 628 const NG::OnMenuItemClickCallback&& onMenuItemClick); 629 void NotifyForNextTouchEvent() override; 630 void RequestFocus(); 631 void CreateOverlay(const RefPtr<OHOS::Ace::PixelMap>& pixelMap, int offsetX, int offsetY, int rectWidth, 632 int rectHeight, int pointX, int pointY); 633 void OnOverlayStateChanged(int offsetX, int offsetY, int rectWidth, int rectHeight); 634 void OnTextSelected(); 635 void DestroyAnalyzerOverlay(); OnCursorUpdate(double x,double y,double width,double height)636 void OnCursorUpdate(double x, double y, double width, double height) 637 { 638 cursorInfo_ = RectF(x, y, width, height); 639 } GetCaretRect()640 RectF GetCaretRect() const override 641 { 642 return cursorInfo_; 643 } 644 void OnProgressChanged(int param); 645 WebInfoType GetWebInfoType(); GetWebSurfaceNodeId()646 Rosen::NodeId GetWebSurfaceNodeId() const 647 { 648 auto rosenRenderContext = AceType::DynamicCast<NG::RosenRenderContext>(renderContextForSurface_); 649 CHECK_NULL_RETURN(rosenRenderContext, 0); 650 auto rsNode = rosenRenderContext->GetRSNode(); 651 CHECK_NULL_RETURN(rsNode, 0); 652 auto surfaceNodeId = rsNode->GetId(); 653 TAG_LOGD(AceLogTag::ACE_WEB, "Web surfaceNodeId is %{public}" PRIu64 "", surfaceNodeId); 654 return surfaceNodeId; 655 } SetCustomKeyboardBuilder(std::function<void ()> customKeyboardBuilder)656 void SetCustomKeyboardBuilder(std::function<void()> customKeyboardBuilder) 657 { 658 customKeyboardBuilder_ = customKeyboardBuilder; 659 } 660 void AttachCustomKeyboard(); 661 void CloseCustomKeyboard(); 662 std::shared_ptr<Rosen::RSNode> GetSurfaceRSNode() const; 663 664 void OnAttachContext(PipelineContext *context) override; 665 void OnDetachContext(PipelineContext *context) override; 666 void SetUpdateInstanceIdCallback(std::function<void(int32_t)> &&callabck); 667 void KeyboardReDispatch(const std::shared_ptr<OHOS::NWeb::NWebKeyEvent>& event, bool isUsed); 668 void GetAllWebAccessibilityNodeInfos(WebNodeInfoCallback cb, int32_t webId); 669 bool OnAccessibilityHoverEvent(const PointF& point) override; 670 void RegisterWebComponentClickCallback(WebComponentClickCallback&& callback); 671 void UnregisterWebComponentClickCallback(); GetWebComponentClickCallback()672 WebComponentClickCallback GetWebComponentClickCallback() const { return webComponentClickCallback_; } 673 674 void RegisterTextBlurCallback(TextBlurCallback&& callback); 675 void UnRegisterTextBlurCallback(); GetTextBlurCallback()676 TextBlurCallback GetTextBlurCallback() const 677 { 678 return textBlurCallback_; 679 } 680 void OnSetAccessibilityChildTree(int32_t childWindowId, int32_t childTreeId); 681 bool OnAccessibilityChildTreeRegister(); 682 bool OnAccessibilityChildTreeDeregister(); 683 bool GetActiveStatus() const; 684 void StartVibraFeedback(const std::string& vibratorType); GetTreeId()685 int32_t GetTreeId() 686 { 687 return treeId_; 688 } 689 // The magnifier needs this to know the web's offset 690 OffsetF GetTextPaintOffset() const override; 691 void OnColorConfigurationUpdate() override; 692 bool CloseImageOverlaySelection(); SetImageOverlaySelectedStatus(bool isSelected)693 void SetImageOverlaySelectedStatus(bool isSelected) 694 { 695 imageOverlayIsSelected_ = isSelected; 696 } 697 IsPreviewImageNodeExist()698 bool IsPreviewImageNodeExist() const 699 { 700 return previewImageNodeId_.has_value(); 701 } 702 SetNewDragStyle(bool isNewDragStyle)703 void SetNewDragStyle(bool isNewDragStyle) 704 { 705 isNewDragStyle_ = isNewDragStyle; 706 } 707 IsNewDragStyle()708 bool IsNewDragStyle() const 709 { 710 return isNewDragStyle_; 711 } 712 IsDragging()713 bool IsDragging() const 714 { 715 return isDragging_; 716 } 717 718 void SetPreviewSelectionMenu(const std::shared_ptr<WebPreviewSelectionMenuParam>& param); 719 720 std::shared_ptr<WebPreviewSelectionMenuParam> GetPreviewSelectionMenuParams( 721 const WebElementType& type, const ResponseType& responseType); 722 723 bool IsPreviewMenuNotNeedShowPreview(); 724 725 bool GetAccessibilityVisible(int64_t accessibilityId); 726 727 private: 728 friend class WebContextSelectOverlay; 729 730 void GetPreviewImageOffsetAndSize(bool isImage, Offset& previewOffset, SizeF& previewSize); 731 RefPtr<FrameNode> CreatePreviewImageFrameNode(bool isImage); 732 void ShowContextSelectOverlay(const RectF& firstHandle, const RectF& secondHandle, 733 TextResponseType responseType = TextResponseType::RIGHT_CLICK, bool handleReverse = false); 734 void CloseContextSelectionMenu(); 735 RectF ComputeMouseClippedSelectionBounds(int32_t x, int32_t y, int32_t w, int32_t h); 736 void RegistVirtualKeyBoardListener(const RefPtr<PipelineContext> &context); 737 bool IsNeedResizeVisibleViewport(); 738 bool ProcessVirtualKeyBoardHide(int32_t width, int32_t height, bool safeAreaEnabled); 739 bool ProcessVirtualKeyBoardShow(int32_t width, int32_t height, double keyboard, bool safeAreaEnabled); 740 bool ProcessVirtualKeyBoard(int32_t width, int32_t height, double keyboard); 741 void UpdateWebLayoutSize(int32_t width, int32_t height, bool isKeyboard, bool isUpdate = true); 742 void UpdateLayoutAfterKeyboardShow(int32_t width, int32_t height, double keyboard, double oldWebHeight); 743 bool OnDirtyLayoutWrapperSwap(const RefPtr<LayoutWrapper>& dirty, const DirtySwapConfig& config) override; 744 void BeforeSyncGeometryProperties(const DirtySwapConfig& config) override; 745 void OnRebuildFrame() override; 746 747 void OnAttachToFrameNode() override; 748 void OnDetachFromFrameNode(FrameNode* frameNode) override; 749 void OnAttachToMainTree() override; 750 void OnDetachFromMainTree() override; 751 752 void OnWindowShow() override; 753 void OnWindowHide() override; 754 void OnWindowSizeChanged(int32_t width, int32_t height, WindowSizeChangeReason type) override; 755 void OnInActive() override; 756 void OnActive() override; 757 void OnVisibleAreaChange(bool isVisible); 758 void OnAreaChangedInner() override; 759 void OnNotifyMemoryLevel(int32_t level) override; 760 761 void OnWebSrcUpdate(); 762 void OnWebDataUpdate(); 763 void OnJsEnabledUpdate(bool value); 764 void OnMediaPlayGestureAccessUpdate(bool value); 765 void OnFileAccessEnabledUpdate(bool value); 766 void OnOnLineImageAccessEnabledUpdate(bool value); 767 void OnDomStorageAccessEnabledUpdate(bool value); 768 void OnImageAccessEnabledUpdate(bool value); 769 void OnMixedModeUpdate(MixedModeContent value); 770 void OnZoomAccessEnabledUpdate(bool value); 771 void OnGeolocationAccessEnabledUpdate(bool value); 772 void OnUserAgentUpdate(const std::string& value); 773 void OnCacheModeUpdate(WebCacheMode value); 774 void OnOverviewModeAccessEnabledUpdate(bool value); 775 void OnFileFromUrlAccessEnabledUpdate(bool value); 776 void OnDatabaseAccessEnabledUpdate(bool value); 777 void OnTextZoomRatioUpdate(int32_t value); 778 void OnWebDebuggingAccessEnabledUpdate(bool value); 779 void OnPinchSmoothModeEnabledUpdate(bool value); 780 void OnBackgroundColorUpdate(int32_t value); 781 void OnInitialScaleUpdate(float value); 782 void OnMultiWindowAccessEnabledUpdate(bool value); 783 void OnAllowWindowOpenMethodUpdate(bool value); 784 void OnWebCursiveFontUpdate(const std::string& value); 785 void OnWebFantasyFontUpdate(const std::string& value); 786 void OnWebFixedFontUpdate(const std::string& value); 787 void OnWebSerifFontUpdate(const std::string& value); 788 void OnWebSansSerifFontUpdate(const std::string& value); 789 void OnWebStandardFontUpdate(const std::string& value); 790 void OnDefaultFixedFontSizeUpdate(int32_t value); 791 void OnDefaultFontSizeUpdate(int32_t value); 792 void OnDefaultTextEncodingFormatUpdate(const std::string& value); 793 void OnMinFontSizeUpdate(int32_t value); 794 void OnMinLogicalFontSizeUpdate(int32_t value); 795 void OnBlockNetworkUpdate(bool value); 796 void OnDarkModeUpdate(WebDarkMode mode); 797 void OnForceDarkAccessUpdate(bool access); 798 void OnAudioResumeIntervalUpdate(int32_t resumeInterval); 799 void OnAudioExclusiveUpdate(bool audioExclusive); 800 void OnHorizontalScrollBarAccessEnabledUpdate(bool value); 801 void OnVerticalScrollBarAccessEnabledUpdate(bool value); 802 void OnScrollBarColorUpdate(const std::string& value); 803 void OnOverScrollModeUpdate(const int32_t value); 804 void OnCopyOptionModeUpdate(const int32_t value); 805 void OnMetaViewportUpdate(bool value); 806 void OnNativeEmbedModeEnabledUpdate(bool value); 807 void OnNativeEmbedRuleTagUpdate(const std::string& tag); 808 void OnNativeEmbedRuleTypeUpdate(const std::string& type); 809 void OnTextAutosizingUpdate(bool isTextAutosizing); 810 void OnNativeVideoPlayerConfigUpdate(const std::tuple<bool, bool>& config); 811 void WindowDrag(int32_t width, int32_t height); 812 void OnSmoothDragResizeEnabledUpdate(bool value); 813 void OnOverlayScrollbarEnabledUpdate(bool enable); 814 void OnKeyboardAvoidModeUpdate(const WebKeyboardAvoidMode& mode); 815 void OnEnabledHapticFeedbackUpdate(bool enable); 816 int GetWebId(); 817 818 void InitEvent(); 819 void InitConfigChangeCallback(const RefPtr<PipelineContext>& context); 820 void InitFeatureParam(); 821 void InitTouchEvent(const RefPtr<GestureEventHub>& gestureHub); 822 void InitMouseEvent(const RefPtr<InputEventHub>& inputHub); 823 void InitHoverEvent(const RefPtr<InputEventHub>& inputHub); 824 void InitCommonDragDropEvent(const RefPtr<GestureEventHub>& gestureHub); 825 void InitWebEventHubDragDropStart(const RefPtr<WebEventHub>& eventHub); 826 void InitWebEventHubDragDropEnd(const RefPtr<WebEventHub>& eventHub); 827 void InitWebEventHubDragMove(const RefPtr<WebEventHub>& eventHub); 828 void InitPanEvent(const RefPtr<GestureEventHub>& gestureHub); 829 void HandleFlingMove(const GestureEvent& event); 830 void HandleDragMove(const GestureEvent& event); 831 void InitDragEvent(const RefPtr<GestureEventHub>& gestureHub); 832 void HandleDragStart(int32_t x, int32_t y); 833 void HandleDragEnd(int32_t x, int32_t y); 834 void HandleDragCancel(); 835 void ClearDragData(); 836 bool GenerateDragDropInfo(NG::DragDropInfo& dragDropInfo); 837 void HandleMouseEvent(MouseInfo& info); 838 void WebOnMouseEvent(const MouseInfo& info); 839 bool HandleDoubleClickEvent(const MouseInfo& info); 840 void SendDoubleClickEvent(const MouseClickInfo& info); 841 void InitFocusEvent(const RefPtr<FocusHub>& focusHub); 842 void HandleFocusEvent(); 843 void HandleBlurEvent(const BlurReason& blurReason); 844 bool HandleKeyEvent(const KeyEvent& keyEvent); 845 bool WebOnKeyEvent(const KeyEvent& keyEvent); 846 void WebRequestFocus(); 847 void ResetDragAction(); 848 void InitSlideUpdateListener(); 849 void CalculateHorizontalDrawRect(); 850 void CalculateVerticalDrawRect(); 851 void InitPinchEvent(const RefPtr<GestureEventHub>& gestureHub); 852 bool CheckZoomStatus(const double& curScale); 853 bool ZoomOutAndIn(const double& curScale, double& scale); 854 void HandleScaleGestureChange(const GestureEvent& event); 855 856 NG::DragDropInfo HandleOnDragStart(const RefPtr<OHOS::Ace::DragEvent>& info); 857 void HandleOnDragEnter(const RefPtr<OHOS::Ace::DragEvent>& info); 858 void HandleOnDropMove(const RefPtr<OHOS::Ace::DragEvent>& info); 859 void HandleOnDragDrop(const RefPtr<OHOS::Ace::DragEvent>& info); 860 void HandleOnDragDropFile(RefPtr<UnifiedData> aceData); 861 void HandleOnDragDropLink(RefPtr<UnifiedData> aceData); 862 void HandleOnDragLeave(int32_t x, int32_t y); 863 void HandleOnDragEnd(int32_t x, int32_t y); 864 void InitTouchEventListener(); 865 void UninitTouchEventListener(); 866 void OnDragFileNameStart(const RefPtr<UnifiedData>& aceUnifiedData, const std::string& fileName); 867 bool needRestoreMenuForDrag_ = false; 868 int32_t dropX_ = 0; 869 int32_t dropY_ = 0; 870 int onDragMoveCnt = 0; 871 bool isDragEndMenuShow_ = false; 872 std::shared_ptr<OHOS::NWeb::NWebQuickMenuParams> dropParams_ = nullptr; 873 std::chrono::time_point<std::chrono::system_clock> firstMoveInTime; 874 std::chrono::time_point<std::chrono::system_clock> preMoveInTime; 875 std::chrono::time_point<std::chrono::system_clock> curMoveInTime; 876 CancelableCallback<void()> timer_; 877 int32_t duration_ = 100; // 100: 100ms 878 void DoRepeat(); 879 void StartRepeatTimer(); 880 881 void HandleTouchDown(const TouchEventInfo& info, bool fromOverlay); 882 883 void HandleTouchUp(const TouchEventInfo& info, bool fromOverlay); 884 885 void HandleTouchMove(const TouchEventInfo& info, bool fromOverlay); 886 887 void HandleTouchCancel(const TouchEventInfo& info); 888 889 void HandleTouchClickEventFromOverlay(const GestureEvent& info); 890 RectF ChangeHandleHeight( 891 const std::shared_ptr<SelectOverlayInfo>& info, const GestureEvent& event, bool isFirst); 892 void OnSelectHandleStart(const GestureEvent& event, bool isFirst); 893 void OnSelectHandleDone(const RectF& handleRect, bool isFirst); 894 void OnSelectHandleMove(const RectF& handleRect, bool isFirst); 895 896 bool IsTouchHandleValid(std::shared_ptr<OHOS::NWeb::NWebTouchHandleState> handle); 897 void CheckHandles(SelectHandleInfo& handleInfo, const std::shared_ptr<OHOS::NWeb::NWebTouchHandleState>& handle); 898 899 void SuggestionSelected(int32_t index); 900 void RegisterSelectOverLayOnClose(SelectOverlayInfo& selectInfo); 901 void InitializeAccessibility(); 902 void UninitializeAccessibility(); 903 #ifdef OHOS_STANDARD_SYSTEM 904 WebOverlayType GetTouchHandleOverlayType( 905 std::shared_ptr<OHOS::NWeb::NWebTouchHandleState> insertHandle, 906 std::shared_ptr<OHOS::NWeb::NWebTouchHandleState> startSelectionHandle, 907 std::shared_ptr<OHOS::NWeb::NWebTouchHandleState> endSelectionHandle); 908 #endif 909 void OnParentScrollStartOrEndCallback(bool isEnd); 910 void RegisterSelectOverlayParentScrollCallback(int32_t parentId, int32_t callbackId); 911 void StartListenSelectOverlayParentScroll(const RefPtr<FrameNode>& host); 912 void StopListenSelectOverlayParentScroll(const RefPtr<FrameNode>& host); 913 void RegisterSelectOverlayCallback(SelectOverlayInfo& selectInfo, 914 std::shared_ptr<OHOS::NWeb::NWebQuickMenuParams> params, 915 std::shared_ptr<OHOS::NWeb::NWebQuickMenuCallback> callback); 916 void RegisterSelectOverlayEvent(SelectOverlayInfo& selectInfo); 917 void CloseSelectOverlay(); 918 RectF ComputeTouchHandleRect(std::shared_ptr<OHOS::NWeb::NWebTouchHandleState> touchHandle); 919 void DelTouchOverlayInfoByTouchId(int32_t touchId); 920 std::optional<OffsetF> GetCoordinatePoint(); 921 static void InitSelectPopupMenuViewOption(const std::vector<RefPtr<FrameNode>>& options, 922 const std::shared_ptr<OHOS::NWeb::NWebSelectPopupMenuCallback>& callback, 923 const std::shared_ptr<OHOS::NWeb::NWebSelectPopupMenuParam>& params, 924 const double& dipScale); 925 static void InitSelectPopupMenuView(RefPtr<FrameNode>& menuWrapper, 926 std::shared_ptr<OHOS::NWeb::NWebSelectPopupMenuCallback> callback, 927 std::shared_ptr<OHOS::NWeb::NWebSelectPopupMenuParam> params, 928 const double& dipScale); 929 OffsetF GetSelectPopupPostion(std::shared_ptr<OHOS::NWeb::NWebSelectMenuBound> bound); 930 bool GetAccessibilityFocusRect(RectT<int32_t>& paintRect, int64_t accessibilityId) const; 931 void SetTouchLocationInfo(const TouchEvent& touchEvent, const TouchLocationInfo& changedInfo, 932 const TouchEventInfo& tempTouchInfo, TouchEventInfo& touchEventInfo); 933 struct TouchInfo { 934 float x = -1.0f; 935 float y = -1.0f; 936 int32_t id = -1; 937 }; 938 static bool ParseTouchInfo(const TouchEventInfo& info, std::list<TouchInfo>& touchInfos); 939 void InitEnhanceSurfaceFlag(); 940 void UpdateBackgroundColorRightNow(int32_t color); 941 void UpdateContentOffset(const RefPtr<LayoutWrapper>& dirty); 942 DialogProperties GetDialogProperties(const RefPtr<DialogTheme>& theme); 943 bool ShowDateTimeDialog(std::shared_ptr<OHOS::NWeb::NWebDateTimeChooser> chooser, 944 const std::vector<std::shared_ptr<OHOS::NWeb::NWebDateTimeSuggestion>>& suggestions, 945 std::shared_ptr<NWeb::NWebDateTimeChooserCallback> callback); 946 bool ShowTimeDialog(std::shared_ptr<OHOS::NWeb::NWebDateTimeChooser> chooser, 947 const std::vector<std::shared_ptr<OHOS::NWeb::NWebDateTimeSuggestion>>& suggestions, 948 std::shared_ptr<NWeb::NWebDateTimeChooserCallback> callback); 949 bool ShowDateTimeSuggestionDialog(std::shared_ptr<OHOS::NWeb::NWebDateTimeChooser> chooser, 950 const std::vector<std::shared_ptr<OHOS::NWeb::NWebDateTimeSuggestion>>& suggestions, 951 std::shared_ptr<NWeb::NWebDateTimeChooserCallback> callback); 952 void PostTaskToUI(const std::function<void()>&& task, const std::string& name) const; 953 void RegisterVisibleAreaChangeCallback(const RefPtr<PipelineContext> &context); 954 void SetSurfaceDensity(double density); 955 void InitInOfflineMode(); 956 void OnOverScrollFlingVelocityHandler(float velocity, bool isFling); 957 bool FilterScrollEventHandleOffset(const float offset); 958 bool FilterScrollEventHandlevVlocity(const float velocity); 959 bool IsDialogNested(); 960 void CalculateTooltipOffset(RefPtr<FrameNode>& tooltipNode, OffsetF& tooltipOfffset); 961 void SetTooltipTextLayoutPropertyInner(const RefPtr<PipelineContext>& pipeline, 962 const std::string& tooltip, RefPtr<OverlayManager>& overlayManager); 963 void HandleShowTooltip(const std::string& tooltip, int64_t tooltipTimestamp); 964 void ShowTooltip(const std::string& tooltip, int64_t tooltipTimestamp); SetMouseHoverExit(bool isHoverExit)965 void SetMouseHoverExit(bool isHoverExit) 966 { 967 isHoverExit_ = isHoverExit; 968 } 969 void SelectCancel() const; 970 bool IsSelectInfoValid(); 971 std::string GetSelectInfo() const; 972 void UpdateRunQuickMenuSelectInfo(SelectOverlayInfo& selectInfo, 973 std::shared_ptr<OHOS::NWeb::NWebQuickMenuParams> params, 974 std::shared_ptr<OHOS::NWeb::NWebTouchHandleState> insertTouchHandle, 975 std::shared_ptr<OHOS::NWeb::NWebTouchHandleState> beginTouchHandle, 976 std::shared_ptr<OHOS::NWeb::NWebTouchHandleState> endTouchHandle); 977 void UpdateSlideOffset(); 978 double GetNewScale(double& scale) const; 979 void SetRotation(uint32_t rotation); 980 Color GetSystemColor() const; UpdateTransformHintChangedCallbackId(std::optional<int32_t> id)981 void UpdateTransformHintChangedCallbackId(std::optional<int32_t> id) 982 { 983 transformHintChangedCallbackId_ = id; 984 } 985 HasTransformHintChangedCallbackId()986 bool HasTransformHintChangedCallbackId() 987 { 988 return transformHintChangedCallbackId_.has_value(); 989 } 990 void ClearKeyEventByKeyCode(int32_t keyCode); 991 bool CheckSafeAreaIsExpand(); 992 bool CheckSafeAreaKeyBoard(); 993 void JsonNodePutDefaultValue(std::unique_ptr<OHOS::Ace::JsonValue>& jsonNode, 994 WebAccessibilityType key, int32_t value, int32_t defaultValue); 995 void JsonNodePutDefaultValue(std::unique_ptr<OHOS::Ace::JsonValue>& jsonNode, 996 WebAccessibilityType key, bool value); 997 void JsonNodePutDefaultValue(std::unique_ptr<OHOS::Ace::JsonValue>& jsonNode, 998 WebAccessibilityType key, std::string value); 999 void WebNodeInfoToJsonValue(std::shared_ptr<OHOS::Ace::JsonValue>& jsonNodeArray, 1000 std::shared_ptr<OHOS::NWeb::NWebAccessibilityNodeInfo> webNodeInfo, 1001 std::string& nodeTag); 1002 void GetWebAllInfosImpl(WebNodeInfoCallback cb, int32_t webId); 1003 std::string EnumTypeToString(WebAccessibilityType type); 1004 std::string VectorIntToString(std::vector<int64_t>&& vec); 1005 void InitMagnifier(); 1006 void ShowMagnifier(int centerOffsetX, int centerOffsetY); 1007 void HideMagnifier(); 1008 void OnMagnifierHandleMove(const RectF& handleRect, bool isFirst); 1009 int32_t GetBufferSizeByDeviceType(); 1010 1011 std::optional<std::string> webSrc_; 1012 std::optional<std::string> webData_; 1013 std::optional<std::string> customScheme_; 1014 RefPtr<WebController> webController_; 1015 std::optional<int32_t> transformHintChangedCallbackId_; 1016 uint32_t rotation_ = 0; 1017 SetWebIdCallback setWebIdCallback_ = nullptr; 1018 DefaultFileSelectorShowCallback defaultFileSelectorShowCallback_ = nullptr; 1019 PermissionClipboardCallback permissionClipboardCallback_ = nullptr; 1020 OnOpenAppLinkCallback onOpenAppLinkCallback_ = nullptr; 1021 RenderMode renderMode_; 1022 bool incognitoMode_ = false; 1023 SetHapPathCallback setHapPathCallback_ = nullptr; 1024 JsProxyCallback jsProxyCallback_ = nullptr; 1025 OnControllerAttachedCallback onControllerAttachedCallback_ = nullptr; 1026 RefPtr<RenderSurface> renderSurface_ = RenderSurface::Create(); 1027 RefPtr<RenderContext> renderContextForSurface_; 1028 RefPtr<TouchEventImpl> touchEvent_; 1029 RefPtr<InputEvent> mouseEvent_; 1030 RefPtr<InputEvent> hoverEvent_; 1031 RefPtr<PanEvent> panEvent_ = nullptr; 1032 bool selectTemporarilyHidden_ = false; 1033 bool selectTemporarilyHiddenByScroll_ = false; 1034 bool nodeAttach_ = false; 1035 ScrollableParentInfo scrollableParentInfo_; 1036 RefPtr<SelectOverlayProxy> selectOverlayProxy_ = nullptr; 1037 RefPtr<WebPaintProperty> webPaintProperty_ = nullptr; 1038 std::shared_ptr<OHOS::NWeb::NWebTouchHandleState> insertHandle_ = nullptr; 1039 std::shared_ptr<OHOS::NWeb::NWebTouchHandleState> startSelectionHandle_ = nullptr; 1040 std::shared_ptr<OHOS::NWeb::NWebTouchHandleState> endSelectionHandle_ = nullptr; 1041 bool isQuickMenuMouseTrigger_ = false; 1042 RefPtr<DragEvent> dragEvent_; 1043 bool isUrlLoaded_ = false; 1044 std::queue<MouseClickInfo> doubleClickQueue_; 1045 bool isFullScreen_ = false; 1046 std::shared_ptr<FullScreenEnterEvent> fullScreenExitHandler_ = nullptr; 1047 bool needOnFocus_ = false; 1048 Size drawSize_; 1049 Size visibleViewportSize_{-1.0, -1.0}; 1050 bool isKeyboardInSafeArea_ = false; 1051 WebKeyboardAvoidMode keyBoardAvoidMode_ = WebKeyboardAvoidMode::DEFAULT; 1052 Size rootLayerChangeSize_; 1053 Size drawSizeCache_; 1054 Size areaChangeSize_; 1055 bool isNeedReDrawRect_ = false; 1056 bool needUpdateWeb_ = true; 1057 bool isFocus_ = false; 1058 VkState isVirtualKeyBoardShow_ { VkState::VK_NONE }; 1059 bool isDragging_ = false; 1060 bool isReceivedArkDrag_ = false; 1061 bool isW3cDragEvent_ = false; 1062 1063 bool isNewDragStyle_ = false; 1064 std::map<std::pair<WebElementType, ResponseType>, 1065 std::shared_ptr<WebPreviewSelectionMenuParam>> previewSelectionMenuMap_; 1066 std::optional<int32_t> previewImageNodeId_ = std::nullopt; 1067 bool needUpdateImagePreviewParam_ = false; 1068 WebElementType curElementType_ = WebElementType::NONE; 1069 ResponseType curResponseType_ = ResponseType::LONG_PRESS; 1070 bool curContextMenuResult_ = false; 1071 1072 bool isWindowShow_ = true; 1073 bool isActive_ = true; 1074 bool isEnhanceSurface_ = false; 1075 bool isAllowWindowOpenMethod_ = false; 1076 bool isShowAutofillPopup_ = false; 1077 OffsetF webOffset_; 1078 RefPtr<WebContextSelectOverlay> contextSelectOverlay_ = nullptr; 1079 RefPtr<WebContextMenuParam> contextMenuParam_ = nullptr; 1080 RefPtr<ContextMenuResult> contextMenuResult_ = nullptr; 1081 RectF selectArea_; 1082 RectF cursorInfo_; 1083 std::shared_ptr<OHOS::NWeb::NWebQuickMenuCallback> quickMenuCallback_ = nullptr; 1084 SelectMenuInfo selectMenuInfo_; 1085 bool selectOverlayDragging_ = false; 1086 bool selectPopupMenuShowing_ = false; 1087 bool isCurrentStartHandleDragging_ = false; 1088 std::list<TouchInfo> touchOverlayInfo_; 1089 bool isPopup_ = false; 1090 int32_t tooltipId_ = -1; 1091 int32_t mouseHoveredX_ = -1; 1092 int32_t mouseHoveredY_ = -1; 1093 int32_t mouseEventDeviceId_ = -1; 1094 int64_t tooltipTimestamp_ = -1; 1095 int32_t parentNWebId_ = -1; 1096 bool isInWindowDrag_ = false; 1097 bool isWaiting_ = false; 1098 bool isDisableDrag_ = false; 1099 bool isMouseEvent_ = false; 1100 bool isHoverExit_ = false; 1101 bool isVisible_ = true; 1102 bool isVisibleActiveEnable_ = true; 1103 bool isMemoryLevelEnable_ = true; 1104 OffsetF fitContentOffset_; 1105 bool isFirstFlingScrollVelocity_ = true; 1106 bool isNeedUpdateScrollAxis_ = true; 1107 bool isScrollStarted_ = false; 1108 WebLayoutMode layoutMode_ = WebLayoutMode::NONE; 1109 bool isEmbedModeEnabled_ = false; 1110 bool scrollState_ = false; 1111 Axis axis_ = Axis::FREE; 1112 Axis syncAxis_ = Axis::NONE; 1113 Axis expectedScrollAxis_ = Axis::FREE; 1114 int32_t rootLayerWidth_ = 0; 1115 int32_t rootLayerHeight_ = 0; 1116 int32_t drawRectWidth_ = 0; 1117 int32_t drawRectHeight_ = 0; 1118 std::unordered_map<Axis, WeakPtr<NestableScrollContainer>> parentsMap_; 1119 RefPtr<WebDelegate> delegate_; 1120 RefPtr<WebDelegateObserver> observer_; 1121 std::optional<ScriptItems> onDocumentStartScriptItems_; 1122 std::optional<ScriptItems> onDocumentEndScriptItems_; 1123 bool isAttachedToMainTree_ = false; 1124 bool offlineWebInited_ = false; 1125 bool offlineWebRendered_ = false; 1126 ACE_DISALLOW_COPY_AND_MOVE(WebPattern); 1127 bool accessibilityState_ = false; 1128 TouchEventInfo touchEventInfo_{"touchEvent"}; 1129 std::vector<TouchEventInfo> touchEventInfoList_ {}; 1130 bool isParentReachEdge_ = false; 1131 RefPtr<PinchGesture> pinchGesture_ = nullptr; 1132 std::queue<TouchEventInfo> touchEventQueue_; 1133 std::vector<NG::MenuOptionsParam> menuOptionParam_ {}; 1134 std::list<KeyEvent> webKeyEvent_ {}; 1135 double startPinchScale_ = -1.0; 1136 double preScale_ = -1.0; 1137 double pageScale_ = 1.0; 1138 int32_t pinchIndex_ = 0; 1139 bool zoomOutSwitch_ = false; 1140 bool isTouchUpEvent_ = false; 1141 std::shared_ptr<ImageAnalyzerManager> imageAnalyzerManager_ = nullptr; 1142 bool overlayCreating_ = false; 1143 int32_t zoomStatus_ = 0; 1144 int32_t zoomErrorCount_ = 0; 1145 int progressParam_ = 0; 1146 double lastKeyboardHeight_ = 0.0; 1147 std::shared_ptr<TouchEventListener> touchEventListener_ {nullptr}; 1148 RefPtr<OverlayManager> keyboardOverlay_; 1149 std::function<void()> customKeyboardBuilder_ = nullptr; 1150 std::optional<std::string> sharedRenderProcessToken_; 1151 std::function<void(int32_t)> updateInstanceIdCallback_; 1152 bool inspectorAccessibilityEnable_ = false; 1153 bool textBlurAccessibilityEnable_ = false; 1154 WebComponentClickCallback webComponentClickCallback_ = nullptr; 1155 TextBlurCallback textBlurCallback_ = nullptr; 1156 uint32_t autoFillSessionId_ = 0; 1157 std::unordered_map<int32_t, std::shared_ptr<AccessibilityChildTreeCallback>> accessibilityChildTreeCallback_; 1158 int32_t treeId_ = 0; 1159 int32_t instanceId_ = -1; 1160 int64_t focusedAccessibilityId_ = -1; 1161 std::vector<RefPtr<PageNodeInfoWrap>> pageNodeInfo_; 1162 bool isRenderModeInit_ = false; 1163 bool isAutoFillClosing_ = true; 1164 ViewDataCommon viewDataCommon_; 1165 bool isPasswordFill_ = false; 1166 bool isEnabledHapticFeedback_ = true; 1167 bool imageOverlayIsSelected_ = false; 1168 int32_t densityCallbackId_ = 0; 1169 bool isLayoutModeChanged_ = false; 1170 float touchPointX = 0; 1171 float touchPointY = 0; 1172 bool isDragEnd_ = false; 1173 1174 protected: 1175 OnCreateMenuCallback onCreateMenuCallback_; 1176 OnMenuItemClickCallback onMenuItemClick_; 1177 }; 1178 } // namespace OHOS::Ace::NG 1179 1180 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_WEB_WEB_PATTERN_H 1181