1 /* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_WEB_CORS_WEB_PATTERN_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_WEB_CORS_WEB_PATTERN_H 18 19 #include <optional> 20 #include <string> 21 #include <utility> 22 23 #include "base/thread/cancelable_callback.h" 24 #include "base/memory/referenced.h" 25 #include "base/utils/utils.h" 26 #include "base/geometry/axis.h" 27 #include "core/components/dialog/dialog_properties.h" 28 #include "core/components/dialog/dialog_theme.h" 29 #include "core/components/web/web_property.h" 30 #include "core/components_ng/gestures/recognizers/pan_recognizer.h" 31 #include "core/components_ng/manager/select_overlay/select_overlay_manager.h" 32 #include "core/components_ng/manager/select_overlay/select_overlay_proxy.h" 33 #include "core/components_ng/pattern/pattern.h" 34 #include "core/components_ng/pattern/web/web_accessibility_property.h" 35 #include "core/components_ng/pattern/web/web_event_hub.h" 36 #include "core/components_ng/pattern/web/web_layout_algorithm.h" 37 #include "core/components_ng/pattern/web/web_paint_property.h" 38 #include "core/components_ng/pattern/web/web_pattern_property.h" 39 #include "core/components_ng/pattern/web/web_paint_method.h" 40 #include "core/components_ng/pattern/web/web_delegate_interface.h" 41 #include "core/components_ng/property/property.h" 42 #include "core/components_ng/manager/select_overlay/selection_host.h" 43 #include "core/components_ng/render/render_surface.h" 44 #include "core/components_ng/pattern/scrollable/nestable_scroll_container.h" 45 #include "core/components_ng/pattern/scroll/scroll_pattern.h" 46 47 #include "core/components_ng/pattern/web/web_delegate_interface.h" 48 49 namespace OHOS::Ace::NG { 50 namespace { 51 struct MouseClickInfo { 52 double x = -1; 53 double y = -1; 54 TimeStamp start; 55 }; 56 57 struct TouchInfo { 58 double x = -1; 59 double y = -1; 60 int32_t id = -1; 61 }; 62 63 struct TouchHandleState { 64 int32_t id = -1; 65 int32_t x = -1; 66 int32_t y = -1; 67 int32_t edge_height = 0; 68 }; 69 70 enum WebOverlayType { INSERT_OVERLAY, SELECTION_OVERLAY, INVALID_OVERLAY }; 71 } // namespace 72 73 enum class WebInfoType : int32_t { 74 TYPE_MOBILE, 75 TYPE_TABLET, 76 TYPE_2IN1, 77 TYPE_UNKNOWN 78 }; 79 80 class WebPattern : public Pattern, public SelectionHost { 81 DECLARE_ACE_TYPE(WebPattern, Pattern, SelectionHost); 82 83 public: 84 using SetWebIdCallback = std::function<void(int32_t)>; 85 using SetHapPathCallback = std::function<void(const std::string&)>; 86 using JsProxyCallback = std::function<void()>; 87 using OnControllerAttachedCallback = std::function<void()>; 88 using PermissionClipboardCallback = std::function<void(const std::shared_ptr<BaseEventInfo>&)>; 89 using DefaultFileSelectorShowCallback = std::function<void(const std::shared_ptr<BaseEventInfo>&)>; 90 using OnOpenAppLinkCallback = std::function<void(const std::shared_ptr<BaseEventInfo>&)>; 91 WebPattern(); 92 WebPattern(const std::string& webSrc, const RefPtr<WebController>& webController, 93 RenderMode type = RenderMode::ASYNC_RENDER, bool incognitoMode = false, 94 const std::string& sharedRenderProcessToken = ""); 95 WebPattern(const std::string& webSrc, const SetWebIdCallback& setWebIdCallback, 96 RenderMode type = RenderMode::ASYNC_RENDER, bool incognitoMode = false, 97 const std::string& sharedRenderProcessToken = ""); 98 99 ~WebPattern() override; 100 101 enum class VkState { 102 VK_NONE, 103 VK_SHOW, 104 VK_HIDE 105 }; 106 GetContextParam()107 std::optional<RenderContext::ContextParam> GetContextParam() const override 108 { 109 if (renderMode_ == RenderMode::SYNC_RENDER) { 110 return RenderContext::ContextParam { RenderContext::ContextType::CANVAS }; 111 } else { 112 return RenderContext::ContextParam { RenderContext::ContextType::SURFACE, "RosenWeb" }; 113 } 114 } 115 116 RefPtr<NodePaintMethod> CreateNodePaintMethod() override; 117 IsAtomicNode()118 bool IsAtomicNode() const override 119 { 120 return true; 121 } 122 CreateEventHub()123 RefPtr<EventHub> CreateEventHub() override 124 { 125 return MakeRefPtr<WebEventHub>(); 126 } 127 CreateAccessibilityProperty()128 RefPtr<AccessibilityProperty> CreateAccessibilityProperty() override 129 { 130 return MakeRefPtr<WebAccessibilityProperty>(); 131 } 132 133 void OnModifyDone() override; 134 135 Color GetDefaultBackgroundColor(); 136 SetWebSrc(const std::string & webSrc)137 void SetWebSrc(const std::string& webSrc) 138 { 139 if (webSrc_ != webSrc_) { 140 OnWebSrcUpdate(); 141 webSrc_ = webSrc; 142 } 143 if (webPaintProperty_) { 144 webPaintProperty_->SetWebPaintData(webSrc); 145 } 146 } 147 GetWebSrc()148 const std::optional<std::string>& GetWebSrc() const 149 { 150 return webSrc_; 151 } 152 SetPopup(bool popup)153 void SetPopup(bool popup) 154 { 155 isPopup_ = popup; 156 } 157 SetParentNWebId(int32_t parentNWebId)158 void SetParentNWebId(int32_t parentNWebId) 159 { 160 parentNWebId_ = parentNWebId; 161 } 162 SetWebData(const std::string & webData)163 void SetWebData(const std::string& webData) 164 { 165 if (webData_ != webData) { 166 webData_ = webData; 167 OnWebDataUpdate(); 168 } 169 if (webPaintProperty_) { 170 webPaintProperty_->SetWebPaintData(webData); 171 } 172 } 173 GetWebData()174 const std::optional<std::string>& GetWebData() const 175 { 176 return webData_; 177 } 178 SetCustomScheme(const std::string & scheme)179 void SetCustomScheme(const std::string& scheme) 180 { 181 customScheme_ = scheme; 182 } 183 GetCustomScheme()184 const std::optional<std::string>& GetCustomScheme() const 185 { 186 return customScheme_; 187 } 188 SetWebController(const RefPtr<WebController> & webController)189 void SetWebController(const RefPtr<WebController>& webController) 190 { 191 webController_ = webController; 192 } 193 GetWebController()194 RefPtr<WebController> GetWebController() const 195 { 196 return webController_; 197 } 198 SetSetWebIdCallback(SetWebIdCallback && SetIdCallback)199 void SetSetWebIdCallback(SetWebIdCallback&& SetIdCallback) 200 { 201 setWebIdCallback_ = std::move(SetIdCallback); 202 } 203 GetSetWebIdCallback()204 SetWebIdCallback GetSetWebIdCallback() const 205 { 206 return setWebIdCallback_; 207 } 208 SetRenderMode(RenderMode renderMode)209 void SetRenderMode(RenderMode renderMode) 210 { 211 renderMode_ = renderMode; 212 } 213 GetRenderMode()214 RenderMode GetRenderMode() 215 { 216 return renderMode_; 217 } 218 SetIncognitoMode(bool incognitoMode)219 void SetIncognitoMode(bool incognitoMode) 220 { 221 incognitoMode_ = incognitoMode; 222 } 223 GetIncognitoMode()224 bool GetIncognitoMode() const 225 { 226 return incognitoMode_; 227 } 228 SetSharedRenderProcessToken(const std::string & sharedRenderProcessToken)229 void SetSharedRenderProcessToken(const std::string& sharedRenderProcessToken) 230 { 231 sharedRenderProcessToken_ = sharedRenderProcessToken; 232 } 233 GetSharedRenderProcessToken()234 const std::optional<std::string>& GetSharedRenderProcessToken() const 235 { 236 return sharedRenderProcessToken_; 237 } 238 SetOnControllerAttachedCallback(OnControllerAttachedCallback && callback)239 void SetOnControllerAttachedCallback(OnControllerAttachedCallback&& callback) 240 { 241 onControllerAttachedCallback_ = std::move(callback); 242 } 243 SetPermissionClipboardCallback(PermissionClipboardCallback && Callback)244 void SetPermissionClipboardCallback(PermissionClipboardCallback&& Callback) 245 { 246 permissionClipboardCallback_ = std::move(Callback); 247 } 248 GetPermissionClipboardCallback()249 PermissionClipboardCallback GetPermissionClipboardCallback() const 250 { 251 return permissionClipboardCallback_; 252 } 253 GetOnControllerAttachedCallback()254 OnControllerAttachedCallback GetOnControllerAttachedCallback() 255 { 256 return onControllerAttachedCallback_; 257 } 258 SetSetHapPathCallback(SetHapPathCallback && callback)259 void SetSetHapPathCallback(SetHapPathCallback&& callback) 260 { 261 setHapPathCallback_ = std::move(callback); 262 } 263 GetSetHapPathCallback()264 SetHapPathCallback GetSetHapPathCallback() const 265 { 266 return setHapPathCallback_; 267 } 268 SetJsProxyCallback(JsProxyCallback && jsProxyCallback)269 void SetJsProxyCallback(JsProxyCallback&& jsProxyCallback) 270 { 271 jsProxyCallback_ = std::move(jsProxyCallback); 272 } 273 CallJsProxyCallback()274 void CallJsProxyCallback() 275 { 276 if (jsProxyCallback_) { 277 jsProxyCallback_(); 278 } 279 } 280 GetWebEventHub()281 RefPtr<WebEventHub> GetWebEventHub() 282 { 283 return GetEventHub<WebEventHub>(); 284 } 285 GetFocusPattern()286 FocusPattern GetFocusPattern() const override 287 { 288 return { FocusType::NODE, true }; 289 } 290 CreatePaintProperty()291 RefPtr<PaintProperty> CreatePaintProperty() override 292 { 293 if (!webPaintProperty_) { 294 webPaintProperty_ = MakeRefPtr<WebPaintProperty>(); 295 if (!webPaintProperty_) { 296 } 297 } 298 return webPaintProperty_; 299 } 300 CreateLayoutAlgorithm()301 RefPtr<LayoutAlgorithm> CreateLayoutAlgorithm() override 302 { 303 return MakeRefPtr<WebLayoutAlgorithm>(); 304 } 305 BetweenSelectedPosition(const Offset & globalOffset)306 bool BetweenSelectedPosition(const Offset& globalOffset) override 307 { 308 return false; 309 } 310 GetDragRecordSize()311 int32_t GetDragRecordSize() override 312 { 313 return 1; 314 } 315 316 void SetNestedScroll(const NestedScrollOptions& nestedOpt); 317 318 void SetNestedScrollExt(const NestedScrollOptionsExt& nestedOpt); 319 320 void OnScrollStart(const float x, const float y); 321 /** 322 * End of NestableScrollContainer implementations 323 */ 324 325 ACE_DEFINE_PROPERTY_GROUP(WebProperty, WebPatternProperty); 326 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, JsEnabled, bool); 327 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, MediaPlayGestureAccess, bool); 328 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, FileAccessEnabled, bool); 329 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, OnLineImageAccessEnabled, bool); 330 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, DomStorageAccessEnabled, bool); 331 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, ImageAccessEnabled, bool); 332 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, MixedMode, MixedModeContent); 333 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, ZoomAccessEnabled, bool); 334 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, GeolocationAccessEnabled, bool); 335 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, UserAgent, std::string); 336 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, CacheMode, WebCacheMode); 337 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, OverviewModeAccessEnabled, bool); 338 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, FileFromUrlAccessEnabled, bool); 339 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, DatabaseAccessEnabled, bool); 340 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, TextZoomRatio, int32_t); 341 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, WebDebuggingAccessEnabled, bool); 342 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, BackgroundColor, int32_t); 343 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, InitialScale, float); 344 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, PinchSmoothModeEnabled, bool); 345 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, MultiWindowAccessEnabled, bool); 346 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, AllowWindowOpenMethod, bool); 347 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, WebCursiveFont, std::string); 348 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, WebFantasyFont, std::string); 349 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, WebFixedFont, std::string); 350 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, WebSansSerifFont, std::string); 351 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, WebSerifFont, std::string); 352 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, WebStandardFont, std::string); 353 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, DefaultFixedFontSize, int32_t); 354 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, DefaultFontSize, int32_t); 355 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, DefaultTextEncodingFormat, std::string); 356 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, MinFontSize, int32_t); 357 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, MinLogicalFontSize, int32_t); 358 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, BlockNetwork, bool); 359 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, DarkMode, WebDarkMode); 360 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, ForceDarkAccess, bool); 361 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, AudioResumeInterval, int32_t); 362 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, AudioExclusive, bool); 363 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, HorizontalScrollBarAccessEnabled, bool); 364 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, VerticalScrollBarAccessEnabled, bool); 365 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, ScrollBarColor, std::string); 366 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, OverScrollMode, int32_t); 367 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, BlurOnKeyboardHideMode, int32_t); 368 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, TextAutosizing, bool); 369 using NativeVideoPlayerConfigType = std::tuple<bool, bool>; 370 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, NativeVideoPlayerConfig, NativeVideoPlayerConfigType); 371 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, SelectionMenuOptions, WebMenuOptionsParam); 372 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, MetaViewport, bool); 373 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, CopyOptionMode, int32_t); 374 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, NativeEmbedModeEnabled, bool); 375 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, NativeEmbedRuleTag, std::string); 376 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, NativeEmbedRuleType, std::string); 377 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, OverlayScrollbarEnabled, bool); 378 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, KeyboardAvoidMode, WebKeyboardAvoidMode); 379 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, EnabledHapticFeedback, bool); 380 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, OptimizeParserBudgetEnabled, bool); 381 void RequestFullScreen(); 382 void ExitFullScreen(); IsFullScreen()383 bool IsFullScreen() const 384 { 385 return isFullScreen_; 386 } 387 void UpdateLocale(); 388 void SetDrawRect(int32_t x, int32_t y, int32_t width, int32_t height); 389 void OnCompleteSwapWithNewSize(); 390 void OnResizeNotWork(); 391 bool OnBackPressed() const; 392 bool OnBackPressedForFullScreen() const; 393 void SetFullScreenExitHandler(const std::shared_ptr<FullScreenEnterEvent>& fullScreenExitHandler); 394 bool NotifyStartDragTask(bool isDelayed = false); 395 void OnContextMenuShow(const std::shared_ptr<BaseEventInfo>& info, bool isRichtext = true, bool result = false); 396 void UpdateJavaScriptOnDocumentStart(); 397 void JavaScriptOnDocumentStart(const ScriptItems& scriptItems); 398 void JavaScriptOnDocumentEnd(const ScriptItems& scriptItems); 399 void JavaScriptOnDocumentStartByOrder(const ScriptItems& scriptItems, 400 const ScriptItemsByOrder& scriptItemsByOrder); 401 void JavaScriptOnDocumentEndByOrder(const ScriptItems& scriptItems, 402 const ScriptItemsByOrder& scriptItemsByOrder); 403 bool IsImageDrag(); 404 Offset GetDragOffset() const; 405 void RemovePreviewMenuNode(); 406 void UpdateImagePreviewParam(); SetLayoutMode(WebLayoutMode mode)407 void SetLayoutMode(WebLayoutMode mode) 408 { 409 layoutMode_ = mode; 410 } GetLayoutMode()411 WebLayoutMode GetLayoutMode() const 412 { 413 return layoutMode_; 414 } 415 void OnRootLayerChanged(int width, int height); GetRootLayerWidth()416 int GetRootLayerWidth() const 417 { 418 return rootLayerWidth_; 419 } GetRootLayerHeight()420 int GetRootLayerHeight() const 421 { 422 return rootLayerHeight_; 423 } RichTextInit()424 void RichTextInit() 425 { 426 richTextInit_ = true; 427 } GetRichTextInit()428 bool GetRichTextInit() const 429 { 430 return richTextInit_; 431 } GetDrawSize()432 Size GetDrawSize() const 433 { 434 return drawSize_; 435 } IsVirtualKeyBoardShow()436 bool IsVirtualKeyBoardShow() const 437 { 438 // cross platform is not support now; 439 return false; 440 } 441 442 void UpdateEditMenuOptions(const NG::OnCreateMenuCallback&& onCreateMenuCallback, 443 const NG::OnMenuItemClickCallback&& onMenuItemClick); 444 SizeF GetDragPixelMapSize() const; 445 bool Backward(); 446 void OnSelectionMenuOptionsUpdate(const WebMenuOptionsParam& webMenuOption); 447 WebInfoType GetWebInfoType(); 448 void SetUpdateInstanceIdCallback(std::function<void(int32_t)> &&callabck); 449 SetDefaultFileSelectorShowCallback(DefaultFileSelectorShowCallback && Callback)450 void SetDefaultFileSelectorShowCallback(DefaultFileSelectorShowCallback&& Callback) 451 { 452 defaultFileSelectorShowCallback_ = std::move(Callback); 453 } 454 GetDefaultFileSelectorShowCallback()455 DefaultFileSelectorShowCallback GetDefaultFileSelectorShowCallback() 456 { 457 return defaultFileSelectorShowCallback_; 458 } 459 SetOnOpenAppLinkCallback(OnOpenAppLinkCallback && callback)460 void SetOnOpenAppLinkCallback(OnOpenAppLinkCallback&& callback) 461 { 462 onOpenAppLinkCallback_ = std::move(callback); 463 } 464 GetOnOpenAppLinkCallback()465 OnOpenAppLinkCallback GetOnOpenAppLinkCallback() const 466 { 467 return onOpenAppLinkCallback_; 468 } 469 IsPreviewImageNodeExist()470 bool IsPreviewImageNodeExist() const 471 { 472 // cross platform is not support now; 473 return false; 474 } 475 SetNewDragStyle(bool isNewDragStyle)476 void SetNewDragStyle(bool isNewDragStyle) {} 477 IsNewDragStyle()478 bool IsNewDragStyle() const 479 { 480 return false; 481 } 482 IsDragging()483 bool IsDragging() const 484 { 485 return false; 486 } 487 488 void SetPreviewSelectionMenu(const std::shared_ptr<WebPreviewSelectionMenuParam>& param); 489 490 std::shared_ptr<WebPreviewSelectionMenuParam> GetPreviewSelectionMenuParams( 491 const WebElementType& type, const ResponseType& responseType); 492 493 bool IsPreviewMenuNotNeedShowPreview(); 494 495 void JavaScriptOnHeadReadyByOrder(const ScriptItems& scriptItems, 496 const ScriptItemsByOrder& scriptItemsByOrder); 497 private: 498 void RegistVirtualKeyBoardListener(); 499 bool ProcessVirtualKeyBoard(int32_t width, int32_t height, double keyboard); 500 void UpdateWebLayoutSize(int32_t width, int32_t height); 501 bool OnDirtyLayoutWrapperSwap(const RefPtr<LayoutWrapper>& dirty, const DirtySwapConfig& config) override; 502 503 void OnAttachToFrameNode() override; 504 void OnDetachFromFrameNode(FrameNode* frameNode) override; 505 void OnWindowShow() override; 506 void OnWindowHide() override; 507 void OnWindowSizeChanged(int32_t width, int32_t height, WindowSizeChangeReason type) override; 508 void OnInActive() override; 509 void OnActive() override; 510 void OnVisibleChange(bool isVisible) override; 511 void OnAreaChangedInner() override; 512 513 void OnWebSrcUpdate(); 514 void OnWebDataUpdate(); 515 void OnJsEnabledUpdate(bool value); 516 void OnMediaPlayGestureAccessUpdate(bool value); 517 void OnFileAccessEnabledUpdate(bool value); 518 void OnOnLineImageAccessEnabledUpdate(bool value); 519 void OnDomStorageAccessEnabledUpdate(bool value); 520 void OnImageAccessEnabledUpdate(bool value); 521 void OnMixedModeUpdate(MixedModeContent value); 522 void OnZoomAccessEnabledUpdate(bool value); 523 void OnGeolocationAccessEnabledUpdate(bool value); 524 void OnUserAgentUpdate(const std::string& value); 525 void OnCacheModeUpdate(WebCacheMode value); 526 void OnOverviewModeAccessEnabledUpdate(bool value); 527 void OnFileFromUrlAccessEnabledUpdate(bool value); 528 void OnDatabaseAccessEnabledUpdate(bool value); 529 void OnTextZoomRatioUpdate(int32_t value); 530 void OnWebDebuggingAccessEnabledUpdate(bool value); 531 void OnPinchSmoothModeEnabledUpdate(bool value); 532 void OnBackgroundColorUpdate(int32_t value); 533 void OnInitialScaleUpdate(float value); 534 void OnMultiWindowAccessEnabledUpdate(bool value); 535 void OnAllowWindowOpenMethodUpdate(bool value); 536 void OnWebCursiveFontUpdate(const std::string& value); 537 void OnWebFantasyFontUpdate(const std::string& value); 538 void OnWebFixedFontUpdate(const std::string& value); 539 void OnWebSerifFontUpdate(const std::string& value); 540 void OnWebSansSerifFontUpdate(const std::string& value); 541 void OnWebStandardFontUpdate(const std::string& value); 542 void OnDefaultFixedFontSizeUpdate(int32_t value); 543 void OnDefaultFontSizeUpdate(int32_t value); 544 void OnDefaultTextEncodingFormatUpdate(const std::string& value); 545 void OnMinFontSizeUpdate(int32_t value); 546 void OnMinLogicalFontSizeUpdate(int32_t value); 547 void OnBlockNetworkUpdate(bool value); 548 void OnDarkModeUpdate(WebDarkMode mode); 549 void OnForceDarkAccessUpdate(bool access); 550 void OnAudioResumeIntervalUpdate(int32_t resumeInterval); 551 void OnAudioExclusiveUpdate(bool audioExclusive); 552 void OnHorizontalScrollBarAccessEnabledUpdate(bool value); 553 void OnVerticalScrollBarAccessEnabledUpdate(bool value); 554 void OnScrollBarColorUpdate(const std::string& value); 555 void OnOverScrollModeUpdate(const int32_t value); 556 void OnBlurOnKeyboardHideModeUpdate(const int32_t mode); 557 void OnTextAutosizingUpdate(bool isTextAutosizing); 558 void OnNativeVideoPlayerConfigUpdate(const std::tuple<bool, bool>& config); 559 void OnSmoothDragResizeEnabledUpdate(bool value); 560 void OnMetaViewportUpdate(bool value); 561 void OnOverlayScrollbarEnabledUpdate(bool value); 562 void OnKeyboardAvoidModeUpdate(const WebKeyboardAvoidMode& mode); 563 void OnEnabledHapticFeedbackUpdate(bool enable); 564 void OnOptimizeParserBudgetEnabledUpdate(bool value); 565 566 void InitEvent(); 567 void InitTouchEvent(const RefPtr<GestureEventHub>& gestureHub); 568 void InitMouseEvent(const RefPtr<InputEventHub>& inputHub); 569 void InitHoverEvent(const RefPtr<InputEventHub>& inputHub); 570 void InitPanEvent(const RefPtr<GestureEventHub>& gestureHub); 571 void HandleMouseEvent(MouseInfo& info); 572 void WebOnMouseEvent(const MouseInfo& info); 573 bool HandleDoubleClickEvent(const MouseInfo& info); 574 void SendDoubleClickEvent(const MouseClickInfo& info); 575 void InitFocusEvent(const RefPtr<FocusHub>& focusHub); 576 void HandleFocusEvent(); 577 void HandleBlurEvent(const BlurReason& blurReason); 578 bool HandleKeyEvent(const KeyEvent& keyEvent); 579 bool WebOnKeyEvent(const KeyEvent& keyEvent); 580 void WebRequestFocus(); 581 void ResetDragAction(); 582 void UpdateRelativeOffset(); 583 void InitSlideUpdateListener(); 584 void CalculateHorizontalDrawRect(); 585 void CalculateVerticalDrawRect(); 586 void UpdateSlideOffset(bool isNeedReset = false); OnNativeEmbedModeEnabledUpdate(bool value)587 void OnNativeEmbedModeEnabledUpdate(bool value) {}; 588 void OnNativeEmbedRuleTagUpdate(const std::string& tag); 589 void OnNativeEmbedRuleTypeUpdate(const std::string& type); 590 void OnCopyOptionModeUpdate(const int32_t value); 591 int onDragMoveCnt = 0; 592 std::chrono::time_point<std::chrono::system_clock> firstMoveInTime; 593 std::chrono::time_point<std::chrono::system_clock> preMoveInTime; 594 std::chrono::time_point<std::chrono::system_clock> curMoveInTime; 595 CancelableCallback<void()> timer_; 596 int32_t duration_ = 100; // 100: 100ms 597 void DoRepeat(); 598 void StartRepeatTimer(); 599 600 void HandleTouchDown(const TouchEventInfo& info, bool fromOverlay); 601 602 void HandleTouchUp(const TouchEventInfo& info, bool fromOverlay); 603 604 void HandleTouchMove(const TouchEventInfo& info, bool fromOverlay); 605 606 void HandleTouchCancel(const TouchEventInfo& info); 607 608 std::optional<OffsetF> GetCoordinatePoint(); 609 610 struct TouchInfo { 611 float x = -1.0f; 612 float y = -1.0f; 613 int32_t id = -1; 614 }; 615 static bool ParseTouchInfo(const TouchEventInfo& info, std::list<TouchInfo>& touchInfos); 616 void InitEnhanceSurfaceFlag(); 617 void UpdateBackgroundColorRightNow(int32_t color); 618 void UpdateContentOffset(const RefPtr<LayoutWrapper>& dirty); 619 void PostTaskToUI(const std::function<void()>&& task) const; 620 void StartVibraFeedback(const std::string& vibratorType); 621 622 std::optional<std::string> webSrc_; 623 std::optional<std::string> webData_; 624 std::optional<std::string> customScheme_; 625 RefPtr<WebController> webController_; 626 SetWebIdCallback setWebIdCallback_ = nullptr; 627 RenderMode renderMode_; 628 bool incognitoMode_ = false; 629 SetHapPathCallback setHapPathCallback_ = nullptr; 630 JsProxyCallback jsProxyCallback_ = nullptr; 631 OnControllerAttachedCallback onControllerAttachedCallback_ = nullptr; 632 PermissionClipboardCallback permissionClipboardCallback_ = nullptr; 633 OnOpenAppLinkCallback onOpenAppLinkCallback_ = nullptr; 634 DefaultFileSelectorShowCallback defaultFileSelectorShowCallback_ = nullptr; 635 RefPtr<TouchEventImpl> touchEvent_; 636 RefPtr<InputEvent> mouseEvent_; 637 RefPtr<InputEvent> hoverEvent_; 638 RefPtr<PanEvent> panEvent_ = nullptr; 639 RefPtr<WebPaintProperty> webPaintProperty_ = nullptr; 640 RefPtr<DragEvent> dragEvent_; 641 bool isUrlLoaded_ = false; 642 std::queue<MouseClickInfo> doubleClickQueue_; 643 bool isFullScreen_ = false; 644 std::shared_ptr<FullScreenEnterEvent> fullScreenExitHandler_ = nullptr; 645 bool needOnFocus_ = false; 646 Size drawSize_; 647 Size drawSizeCache_; 648 bool needUpdateWeb_ = true; 649 bool isFocus_ = false; 650 VkState isVirtualKeyBoardShow_ { VkState::VK_NONE }; 651 bool isDragging_ = false; 652 bool isW3cDragEvent_ = false; 653 bool isWindowShow_ = true; 654 bool isActive_ = true; 655 bool isEnhanceSurface_ = false; 656 bool isAllowWindowOpenMethod_ = false; 657 OffsetF webOffset_; 658 bool isPopup_ = false; 659 int32_t parentNWebId_ = -1; 660 bool isInWindowDrag_ = false; 661 bool isWaiting_ = false; 662 bool isDisableDrag_ = false; 663 bool isMouseEvent_ = false; 664 bool isVisible_ = true; 665 bool isVisibleActiveEnable_ = true; 666 bool isMemoryLevelEnable_ = true; 667 bool isParentHasScroll_ = false; 668 OffsetF relativeOffsetOfScroll_; 669 std::function<void(int32_t)> updateInstanceIdCallback_; 670 RefPtr<WebDelegateInterface> delegate_ = nullptr; 671 std::optional<std::string> sharedRenderProcessToken_; 672 673 bool selectPopupMenuShowing_ = false; 674 WebLayoutMode layoutMode_ = WebLayoutMode::NONE; 675 int32_t rootLayerWidth_ = 0; 676 int32_t rootLayerHeight_ = 0; 677 bool richTextInit_ = false; 678 ACE_DISALLOW_COPY_AND_MOVE(WebPattern); 679 }; 680 } // namespace OHOS::Ace::NG 681 682 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_WEB_CORS_WEB_PATTERN_H 683