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