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