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