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 * End of NestableScrollContainer implementations 321 */ 322 323 ACE_DEFINE_PROPERTY_GROUP(WebProperty, WebPatternProperty); 324 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, JsEnabled, bool); 325 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, MediaPlayGestureAccess, bool); 326 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, FileAccessEnabled, bool); 327 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, OnLineImageAccessEnabled, bool); 328 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, DomStorageAccessEnabled, bool); 329 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, ImageAccessEnabled, bool); 330 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, MixedMode, MixedModeContent); 331 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, ZoomAccessEnabled, bool); 332 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, GeolocationAccessEnabled, bool); 333 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, UserAgent, std::string); 334 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, CacheMode, WebCacheMode); 335 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, OverviewModeAccessEnabled, bool); 336 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, FileFromUrlAccessEnabled, bool); 337 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, DatabaseAccessEnabled, bool); 338 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, TextZoomRatio, int32_t); 339 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, WebDebuggingAccessEnabled, bool); 340 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, BackgroundColor, int32_t); 341 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, InitialScale, float); 342 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, PinchSmoothModeEnabled, bool); 343 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, MultiWindowAccessEnabled, bool); 344 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, AllowWindowOpenMethod, bool); 345 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, WebCursiveFont, std::string); 346 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, WebFantasyFont, std::string); 347 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, WebFixedFont, std::string); 348 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, WebSansSerifFont, std::string); 349 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, WebSerifFont, std::string); 350 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, WebStandardFont, std::string); 351 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, DefaultFixedFontSize, int32_t); 352 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, DefaultFontSize, int32_t); 353 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, DefaultTextEncodingFormat, std::string); 354 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, MinFontSize, int32_t); 355 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, MinLogicalFontSize, int32_t); 356 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, BlockNetwork, bool); 357 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, DarkMode, WebDarkMode); 358 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, ForceDarkAccess, bool); 359 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, AudioResumeInterval, int32_t); 360 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, AudioExclusive, bool); 361 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, HorizontalScrollBarAccessEnabled, bool); 362 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, VerticalScrollBarAccessEnabled, bool); 363 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, ScrollBarColor, std::string); 364 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, OverScrollMode, int32_t); 365 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, BlurOnKeyboardHideMode, int32_t); 366 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, TextAutosizing, bool); 367 using NativeVideoPlayerConfigType = std::tuple<bool, bool>; 368 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, NativeVideoPlayerConfig, NativeVideoPlayerConfigType); 369 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, SelectionMenuOptions, WebMenuOptionsParam); 370 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, MetaViewport, bool); 371 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, CopyOptionMode, int32_t); 372 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, NativeEmbedModeEnabled, bool); 373 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, NativeEmbedRuleTag, std::string); 374 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, NativeEmbedRuleType, std::string); 375 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, OverlayScrollbarEnabled, bool); 376 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, KeyboardAvoidMode, WebKeyboardAvoidMode); 377 ACE_DEFINE_PROPERTY_FUNC_WITH_GROUP(WebProperty, EnabledHapticFeedback, bool); 378 void RequestFullScreen(); 379 void ExitFullScreen(); IsFullScreen()380 bool IsFullScreen() const 381 { 382 return isFullScreen_; 383 } 384 void UpdateLocale(); 385 void SetDrawRect(int32_t x, int32_t y, int32_t width, int32_t height); 386 void OnCompleteSwapWithNewSize(); 387 void OnResizeNotWork(); 388 bool OnBackPressed() const; 389 bool OnBackPressedForFullScreen() const; 390 void SetFullScreenExitHandler(const std::shared_ptr<FullScreenEnterEvent>& fullScreenExitHandler); 391 bool NotifyStartDragTask(bool isDelayed = false); 392 void OnContextMenuShow(const std::shared_ptr<BaseEventInfo>& info, bool isRichtext = true, bool result = false); 393 void UpdateJavaScriptOnDocumentStart(); 394 void JavaScriptOnDocumentStart(const ScriptItems& scriptItems); 395 void JavaScriptOnDocumentEnd(const ScriptItems& scriptItems); 396 bool IsImageDrag(); 397 Offset GetDragOffset() const; 398 void RemovePreviewMenuNode(); 399 void UpdateImagePreviewParam(); SetLayoutMode(WebLayoutMode mode)400 void SetLayoutMode(WebLayoutMode mode) 401 { 402 layoutMode_ = mode; 403 } GetLayoutMode()404 WebLayoutMode GetLayoutMode() const 405 { 406 return layoutMode_; 407 } 408 void OnRootLayerChanged(int width, int height); GetRootLayerWidth()409 int GetRootLayerWidth() const 410 { 411 return rootLayerWidth_; 412 } GetRootLayerHeight()413 int GetRootLayerHeight() const 414 { 415 return rootLayerHeight_; 416 } RichTextInit()417 void RichTextInit() 418 { 419 richTextInit_ = true; 420 } GetRichTextInit()421 bool GetRichTextInit() const 422 { 423 return richTextInit_; 424 } GetDrawSize()425 Size GetDrawSize() const 426 { 427 return drawSize_; 428 } IsVirtualKeyBoardShow()429 bool IsVirtualKeyBoardShow() const 430 { 431 // cross platform is not support now; 432 return false; 433 } 434 435 void UpdateEditMenuOptions(const NG::OnCreateMenuCallback&& onCreateMenuCallback, 436 const NG::OnMenuItemClickCallback&& onMenuItemClick); 437 SizeF GetDragPixelMapSize() const; 438 bool Backward(); 439 void OnSelectionMenuOptionsUpdate(const WebMenuOptionsParam& webMenuOption); 440 WebInfoType GetWebInfoType(); 441 void SetUpdateInstanceIdCallback(std::function<void(int32_t)> &&callabck); 442 SetDefaultFileSelectorShowCallback(DefaultFileSelectorShowCallback && Callback)443 void SetDefaultFileSelectorShowCallback(DefaultFileSelectorShowCallback&& Callback) 444 { 445 defaultFileSelectorShowCallback_ = std::move(Callback); 446 } 447 GetDefaultFileSelectorShowCallback()448 DefaultFileSelectorShowCallback GetDefaultFileSelectorShowCallback() 449 { 450 return defaultFileSelectorShowCallback_; 451 } 452 SetOnOpenAppLinkCallback(OnOpenAppLinkCallback && callback)453 void SetOnOpenAppLinkCallback(OnOpenAppLinkCallback&& callback) 454 { 455 onOpenAppLinkCallback_ = std::move(callback); 456 } 457 GetOnOpenAppLinkCallback()458 OnOpenAppLinkCallback GetOnOpenAppLinkCallback() const 459 { 460 return onOpenAppLinkCallback_; 461 } 462 IsPreviewImageNodeExist()463 bool IsPreviewImageNodeExist() const 464 { 465 // cross platform is not support now; 466 return false; 467 } 468 SetNewDragStyle(bool isNewDragStyle)469 void SetNewDragStyle(bool isNewDragStyle) {} 470 IsNewDragStyle()471 bool IsNewDragStyle() const 472 { 473 return false; 474 } 475 IsDragging()476 bool IsDragging() const 477 { 478 return false; 479 } 480 481 void SetPreviewSelectionMenu(const std::shared_ptr<WebPreviewSelectionMenuParam>& param); 482 483 std::shared_ptr<WebPreviewSelectionMenuParam> GetPreviewSelectionMenuParams( 484 const WebElementType& type, const ResponseType& responseType); 485 486 bool IsPreviewMenuNotNeedShowPreview(); 487 488 private: 489 void RegistVirtualKeyBoardListener(); 490 bool ProcessVirtualKeyBoard(int32_t width, int32_t height, double keyboard); 491 void UpdateWebLayoutSize(int32_t width, int32_t height); 492 bool OnDirtyLayoutWrapperSwap(const RefPtr<LayoutWrapper>& dirty, const DirtySwapConfig& config) override; 493 494 void OnAttachToFrameNode() override; 495 void OnDetachFromFrameNode(FrameNode* frameNode) override; 496 void OnWindowShow() override; 497 void OnWindowHide() override; 498 void OnWindowSizeChanged(int32_t width, int32_t height, WindowSizeChangeReason type) override; 499 void OnInActive() override; 500 void OnActive() override; 501 void OnVisibleChange(bool isVisible) override; 502 void OnAreaChangedInner() override; 503 504 void OnWebSrcUpdate(); 505 void OnWebDataUpdate(); 506 void OnJsEnabledUpdate(bool value); 507 void OnMediaPlayGestureAccessUpdate(bool value); 508 void OnFileAccessEnabledUpdate(bool value); 509 void OnOnLineImageAccessEnabledUpdate(bool value); 510 void OnDomStorageAccessEnabledUpdate(bool value); 511 void OnImageAccessEnabledUpdate(bool value); 512 void OnMixedModeUpdate(MixedModeContent value); 513 void OnZoomAccessEnabledUpdate(bool value); 514 void OnGeolocationAccessEnabledUpdate(bool value); 515 void OnUserAgentUpdate(const std::string& value); 516 void OnCacheModeUpdate(WebCacheMode value); 517 void OnOverviewModeAccessEnabledUpdate(bool value); 518 void OnFileFromUrlAccessEnabledUpdate(bool value); 519 void OnDatabaseAccessEnabledUpdate(bool value); 520 void OnTextZoomRatioUpdate(int32_t value); 521 void OnWebDebuggingAccessEnabledUpdate(bool value); 522 void OnPinchSmoothModeEnabledUpdate(bool value); 523 void OnBackgroundColorUpdate(int32_t value); 524 void OnInitialScaleUpdate(float value); 525 void OnMultiWindowAccessEnabledUpdate(bool value); 526 void OnAllowWindowOpenMethodUpdate(bool value); 527 void OnWebCursiveFontUpdate(const std::string& value); 528 void OnWebFantasyFontUpdate(const std::string& value); 529 void OnWebFixedFontUpdate(const std::string& value); 530 void OnWebSerifFontUpdate(const std::string& value); 531 void OnWebSansSerifFontUpdate(const std::string& value); 532 void OnWebStandardFontUpdate(const std::string& value); 533 void OnDefaultFixedFontSizeUpdate(int32_t value); 534 void OnDefaultFontSizeUpdate(int32_t value); 535 void OnDefaultTextEncodingFormatUpdate(const std::string& value); 536 void OnMinFontSizeUpdate(int32_t value); 537 void OnMinLogicalFontSizeUpdate(int32_t value); 538 void OnBlockNetworkUpdate(bool value); 539 void OnDarkModeUpdate(WebDarkMode mode); 540 void OnForceDarkAccessUpdate(bool access); 541 void OnAudioResumeIntervalUpdate(int32_t resumeInterval); 542 void OnAudioExclusiveUpdate(bool audioExclusive); 543 void OnHorizontalScrollBarAccessEnabledUpdate(bool value); 544 void OnVerticalScrollBarAccessEnabledUpdate(bool value); 545 void OnScrollBarColorUpdate(const std::string& value); 546 void OnOverScrollModeUpdate(const int32_t value); 547 void OnBlurOnKeyboardHideModeUpdate(const int32_t mode); 548 void OnTextAutosizingUpdate(bool isTextAutosizing); 549 void OnNativeVideoPlayerConfigUpdate(const std::tuple<bool, bool>& config); 550 void OnSmoothDragResizeEnabledUpdate(bool value); 551 void OnMetaViewportUpdate(bool value); 552 void OnOverlayScrollbarEnabledUpdate(bool value); 553 void OnKeyboardAvoidModeUpdate(const WebKeyboardAvoidMode& mode); 554 void OnEnabledHapticFeedbackUpdate(bool enable); 555 556 void InitEvent(); 557 void InitTouchEvent(const RefPtr<GestureEventHub>& gestureHub); 558 void InitMouseEvent(const RefPtr<InputEventHub>& inputHub); 559 void InitHoverEvent(const RefPtr<InputEventHub>& inputHub); 560 void InitPanEvent(const RefPtr<GestureEventHub>& gestureHub); 561 void HandleMouseEvent(MouseInfo& info); 562 void WebOnMouseEvent(const MouseInfo& info); 563 bool HandleDoubleClickEvent(const MouseInfo& info); 564 void SendDoubleClickEvent(const MouseClickInfo& info); 565 void InitFocusEvent(const RefPtr<FocusHub>& focusHub); 566 void HandleFocusEvent(); 567 void HandleBlurEvent(const BlurReason& blurReason); 568 bool HandleKeyEvent(const KeyEvent& keyEvent); 569 bool WebOnKeyEvent(const KeyEvent& keyEvent); 570 void WebRequestFocus(); 571 void ResetDragAction(); 572 void UpdateRelativeOffset(); 573 void InitSlideUpdateListener(); 574 void CalculateHorizontalDrawRect(); 575 void CalculateVerticalDrawRect(); 576 void UpdateSlideOffset(bool isNeedReset = false); OnNativeEmbedModeEnabledUpdate(bool value)577 void OnNativeEmbedModeEnabledUpdate(bool value) {}; 578 void OnNativeEmbedRuleTagUpdate(const std::string& tag); 579 void OnNativeEmbedRuleTypeUpdate(const std::string& type); 580 void OnCopyOptionModeUpdate(const int32_t value); 581 int onDragMoveCnt = 0; 582 std::chrono::time_point<std::chrono::system_clock> firstMoveInTime; 583 std::chrono::time_point<std::chrono::system_clock> preMoveInTime; 584 std::chrono::time_point<std::chrono::system_clock> curMoveInTime; 585 CancelableCallback<void()> timer_; 586 int32_t duration_ = 100; // 100: 100ms 587 void DoRepeat(); 588 void StartRepeatTimer(); 589 590 void HandleTouchDown(const TouchEventInfo& info, bool fromOverlay); 591 592 void HandleTouchUp(const TouchEventInfo& info, bool fromOverlay); 593 594 void HandleTouchMove(const TouchEventInfo& info, bool fromOverlay); 595 596 void HandleTouchCancel(const TouchEventInfo& info); 597 598 std::optional<OffsetF> GetCoordinatePoint(); 599 600 struct TouchInfo { 601 float x = -1.0f; 602 float y = -1.0f; 603 int32_t id = -1; 604 }; 605 static bool ParseTouchInfo(const TouchEventInfo& info, std::list<TouchInfo>& touchInfos); 606 void InitEnhanceSurfaceFlag(); 607 void UpdateBackgroundColorRightNow(int32_t color); 608 void UpdateContentOffset(const RefPtr<LayoutWrapper>& dirty); 609 void PostTaskToUI(const std::function<void()>&& task) const; 610 void StartVibraFeedback(const std::string& vibratorType); 611 612 std::optional<std::string> webSrc_; 613 std::optional<std::string> webData_; 614 std::optional<std::string> customScheme_; 615 RefPtr<WebController> webController_; 616 SetWebIdCallback setWebIdCallback_ = nullptr; 617 RenderMode renderMode_; 618 bool incognitoMode_ = false; 619 SetHapPathCallback setHapPathCallback_ = nullptr; 620 JsProxyCallback jsProxyCallback_ = nullptr; 621 OnControllerAttachedCallback onControllerAttachedCallback_ = nullptr; 622 PermissionClipboardCallback permissionClipboardCallback_ = nullptr; 623 OnOpenAppLinkCallback onOpenAppLinkCallback_ = nullptr; 624 DefaultFileSelectorShowCallback defaultFileSelectorShowCallback_ = nullptr; 625 RefPtr<TouchEventImpl> touchEvent_; 626 RefPtr<InputEvent> mouseEvent_; 627 RefPtr<InputEvent> hoverEvent_; 628 RefPtr<PanEvent> panEvent_ = nullptr; 629 RefPtr<WebPaintProperty> webPaintProperty_ = nullptr; 630 RefPtr<DragEvent> dragEvent_; 631 bool isUrlLoaded_ = false; 632 std::queue<MouseClickInfo> doubleClickQueue_; 633 bool isFullScreen_ = false; 634 std::shared_ptr<FullScreenEnterEvent> fullScreenExitHandler_ = nullptr; 635 bool needOnFocus_ = false; 636 Size drawSize_; 637 Size drawSizeCache_; 638 bool needUpdateWeb_ = true; 639 bool isFocus_ = false; 640 VkState isVirtualKeyBoardShow_ { VkState::VK_NONE }; 641 bool isDragging_ = false; 642 bool isW3cDragEvent_ = false; 643 bool isWindowShow_ = true; 644 bool isActive_ = true; 645 bool isEnhanceSurface_ = false; 646 bool isAllowWindowOpenMethod_ = false; 647 OffsetF webOffset_; 648 bool isPopup_ = false; 649 int32_t parentNWebId_ = -1; 650 bool isInWindowDrag_ = false; 651 bool isWaiting_ = false; 652 bool isDisableDrag_ = false; 653 bool isMouseEvent_ = false; 654 bool isVisible_ = true; 655 bool isVisibleActiveEnable_ = true; 656 bool isMemoryLevelEnable_ = true; 657 bool isParentHasScroll_ = false; 658 OffsetF relativeOffsetOfScroll_; 659 std::function<void(int32_t)> updateInstanceIdCallback_; 660 RefPtr<WebDelegateInterface> delegate_ = nullptr; 661 std::optional<std::string> sharedRenderProcessToken_; 662 663 bool selectPopupMenuShowing_ = false; 664 WebLayoutMode layoutMode_ = WebLayoutMode::NONE; 665 int32_t rootLayerWidth_ = 0; 666 int32_t rootLayerHeight_ = 0; 667 bool richTextInit_ = false; 668 ACE_DISALLOW_COPY_AND_MOVE(WebPattern); 669 }; 670 } // namespace OHOS::Ace::NG 671 672 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_WEB_CORS_WEB_PATTERN_H 673