• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "core/components_ng/pattern/web/cross_platform/web_pattern.h"
17 
18 #include <securec.h>
19 
20 #include "base/geometry/ng/offset_t.h"
21 #include "base/mousestyle/mouse_style.h"
22 #include "base/utils/date_util.h"
23 #include "base/utils/linear_map.h"
24 #include "base/utils/utils.h"
25 #include "core/components/dialog/dialog_theme.h"
26 #include "core/components/picker/picker_data.h"
27 #include "core/components/text_overlay/text_overlay_theme.h"
28 #include "core/components/web/web_property.h"
29 #include "core/components_ng/base/view_stack_processor.h"
30 #include "core/components_ng/pattern/menu/menu_view.h"
31 #include "core/components_ng/pattern/overlay/overlay_manager.h"
32 #include "core/components_ng/pattern/web/web_event_hub.h"
33 #include "core/event/key_event.h"
34 #include "core/event/touch_event.h"
35 #include "core/pipeline_ng/pipeline_context.h"
36 #include "frameworks/base/utils/system_properties.h"
37 
38 #include "core/components_ng/pattern/web/cross_platform/web_delegate_cross.h"
39 
40 namespace OHOS::Ace::NG {
41 
42 constexpr int32_t SINGLE_CLICK_NUM = 1;
43 constexpr int32_t DOUBLE_CLICK_NUM = 2;
44 constexpr double DEFAULT_DBCLICK_INTERVAL = 0.5;
45 constexpr double DEFAULT_DBCLICK_OFFSET = 2.0;
46 constexpr double DEFAULT_AXIS_RATIO = -0.06;
47 constexpr uint32_t DEFAULT_WEB_DRAW_HEIGHT = 4000;
48 const std::string PATTERN_TYPE_WEB = "WEBPATTERN";
49 constexpr int32_t ASYNC_SURFACE_QUEUE_SIZE = 3;
50 constexpr int32_t SYNC_SURFACE_QUEUE_SIZE = 8;
51 constexpr int32_t SIZE_GAP = 2;
52 // web feature params
53 const std::string VISIBLE_ACTIVE_ENABLE = "persist.web.visible_active_enable";
54 const std::string MEMORY_LEVEL_ENABEL = "persist.web.memory_level_enable";
55 const std::vector<int32_t> DEFAULT_HEIGHT_GEAR {7998, 7999, 8001, 8002, 8003};
56 const std::vector<int32_t> DEFAULT_ORIGN_GEAR {0, 2000, 4000, 6000, 8000};
57 
58 WebPattern::WebPattern() = default;
59 
WebPattern(const std::string & webSrc,const RefPtr<WebController> & webController,RenderMode renderMode,bool incognitoMode,const std::string & sharedRenderProcessToken)60 WebPattern::WebPattern(const std::string& webSrc, const RefPtr<WebController>& webController, RenderMode renderMode,
61     bool incognitoMode, const std::string& sharedRenderProcessToken)
62     : webSrc_(std::move(webSrc)), webController_(webController), renderMode_(renderMode), incognitoMode_(incognitoMode),
63       sharedRenderProcessToken_(sharedRenderProcessToken)
64 {}
65 
WebPattern(const std::string & webSrc,const SetWebIdCallback & setWebIdCallback,RenderMode renderMode,bool incognitoMode,const std::string & sharedRenderProcessToken)66 WebPattern::WebPattern(const std::string& webSrc, const SetWebIdCallback& setWebIdCallback, RenderMode renderMode,
67     bool incognitoMode, const std::string& sharedRenderProcessToken)
68     : webSrc_(std::move(webSrc)), setWebIdCallback_(setWebIdCallback), renderMode_(renderMode),
69       incognitoMode_(incognitoMode), sharedRenderProcessToken_(sharedRenderProcessToken)
70 {}
71 
~WebPattern()72 WebPattern::~WebPattern()
73 {
74     if (isActive_) {
75         OnInActive();
76     }
77 }
78 
OnAttachToFrameNode()79 void WebPattern::OnAttachToFrameNode()
80 {
81     auto host = GetHost();
82     CHECK_NULL_VOID(host);
83     host->GetRenderContext()->SetClipToFrame(true);
84     host->GetRenderContext()->UpdateBackgroundColor(Color::WHITE);
85     host->GetLayoutProperty()->UpdateMeasureType(MeasureType::MATCH_PARENT);
86     auto pipeline = PipelineContext::GetCurrentContext();
87     CHECK_NULL_VOID(pipeline);
88     pipeline->AddNodesToNotifyMemoryLevel(host->GetId());
89     auto OnAreaChangedCallBack = [weak = WeakClaim(this)](float x, float y, float w, float h) mutable {
90         auto webPattern = weak.Upgrade();
91         CHECK_NULL_VOID(webPattern);
92         auto offset = Offset(webPattern->GetCoordinatePoint()->GetX(), webPattern->GetCoordinatePoint()->GetY());
93         auto host = webPattern->GetHost();
94         CHECK_NULL_VOID(host);
95         auto renderContext = host->GetRenderContext();
96         CHECK_NULL_VOID(renderContext);
97         renderContext->SetContentRectToFrame(RectF(offset.GetX(), offset.GetY(),
98             webPattern->drawSize_.Width() - SIZE_GAP, webPattern->drawSize_.Height() - SIZE_GAP));
99     };
100     host->GetRenderContext()->SetSurfaceChangedCallBack(OnAreaChangedCallBack);
101 }
102 
OnDetachFromFrameNode(FrameNode * frameNode)103 void WebPattern::OnDetachFromFrameNode(FrameNode* frameNode)
104 {
105     CHECK_NULL_VOID(delegate_);
106     isFocus_ = false;
107     delegate_->OnBlur();
108 
109     auto id = frameNode->GetId();
110     auto pipeline = AceType::DynamicCast<PipelineContext>(PipelineBase::GetCurrentContext());
111     CHECK_NULL_VOID(pipeline);
112     pipeline->RemoveWindowStateChangedCallback(id);
113     pipeline->RemoveWindowSizeChangeCallback(id);
114     pipeline->RemoveNodesToNotifyMemoryLevel(id);
115 }
116 
InitEvent()117 void WebPattern::InitEvent()
118 {
119     auto host = GetHost();
120     CHECK_NULL_VOID(host);
121     auto eventHub = host->GetOrCreateEventHub<WebEventHub>();
122     CHECK_NULL_VOID(eventHub);
123 
124     auto gestureHub = eventHub->GetOrCreateGestureEventHub();
125     CHECK_NULL_VOID(gestureHub);
126 
127     InitTouchEvent(gestureHub);
128 
129     auto inputHub = eventHub->GetOrCreateInputEventHub();
130     CHECK_NULL_VOID(inputHub);
131     InitMouseEvent(inputHub);
132     InitHoverEvent(inputHub);
133 
134     auto focusHub = eventHub->GetOrCreateFocusHub();
135     CHECK_NULL_VOID(focusHub);
136     InitFocusEvent(focusHub);
137 
138     auto context = PipelineContext::GetCurrentContext();
139     CHECK_NULL_VOID(context);
140     auto langTask = [weak = AceType::WeakClaim(this)]() {
141         auto WebPattern = weak.Upgrade();
142         CHECK_NULL_VOID(WebPattern);
143         WebPattern->UpdateLocale();
144     };
145     context->SetConfigChangedCallback(GetHost()->GetId(), std::move(langTask));
146 }
147 
InitTouchEvent(const RefPtr<GestureEventHub> & gestureHub)148 void WebPattern::InitTouchEvent(const RefPtr<GestureEventHub>& gestureHub)
149 {
150     if (touchEvent_) {
151         return;
152     }
153 
154     auto touchTask = [weak = WeakClaim(this)](const TouchEventInfo& info) {
155         auto pattern = weak.Upgrade();
156         CHECK_NULL_VOID(pattern);
157         if (info.GetChangedTouches().empty()) {
158             return;
159         }
160 
161         // only handle touch event
162         if (info.GetSourceDevice() != SourceType::TOUCH) {
163             return;
164         }
165 
166         pattern->isMouseEvent_ = false;
167         const auto& changedPoint = info.GetChangedTouches().front();
168         if (changedPoint.GetTouchType() == TouchType::DOWN) {
169             pattern->HandleTouchDown(info, false);
170             return;
171         }
172         if (changedPoint.GetTouchType() == TouchType::MOVE) {
173             pattern->HandleTouchMove(info, false);
174             return;
175         }
176         if (changedPoint.GetTouchType() == TouchType::UP) {
177             pattern->HandleTouchUp(info, false);
178             return;
179         }
180         if (changedPoint.GetTouchType() == TouchType::CANCEL) {
181             pattern->HandleTouchCancel(info);
182             return;
183         }
184     };
185     touchEvent_ = MakeRefPtr<TouchEventImpl>(std::move(touchTask));
186     gestureHub->AddTouchEvent(touchEvent_);
187 }
188 
InitMouseEvent(const RefPtr<InputEventHub> & inputHub)189 void WebPattern::InitMouseEvent(const RefPtr<InputEventHub>& inputHub)
190 {
191     if (mouseEvent_) {
192         return;
193     }
194 
195     auto mouseTask = [weak = WeakClaim(this)](MouseInfo& info) {
196         auto pattern = weak.Upgrade();
197         CHECK_NULL_VOID(pattern);
198         pattern->HandleMouseEvent(info);
199     };
200 
201     mouseEvent_ = MakeRefPtr<InputEvent>(std::move(mouseTask));
202     inputHub->AddOnMouseEvent(mouseEvent_);
203 }
204 
InitHoverEvent(const RefPtr<InputEventHub> & inputHub)205 void WebPattern::InitHoverEvent(const RefPtr<InputEventHub>& inputHub)
206 {
207     if (hoverEvent_) {
208         return;
209     }
210 
211     auto hoverTask = [weak = WeakClaim(this)](bool isHover) {
212         auto pattern = weak.Upgrade();
213         CHECK_NULL_VOID(pattern);
214         MouseInfo info;
215         info.SetAction(isHover ? MouseAction::HOVER : MouseAction::HOVER_EXIT);
216         pattern->WebOnMouseEvent(info);
217     };
218 
219     hoverEvent_ = MakeRefPtr<InputEvent>(std::move(hoverTask));
220     inputHub->AddOnHoverEvent(hoverEvent_);
221 }
222 
HandleMouseEvent(MouseInfo & info)223 void WebPattern::HandleMouseEvent(MouseInfo& info)
224 {
225     isMouseEvent_ = true;
226     WebOnMouseEvent(info);
227 
228     auto host = GetHost();
229     CHECK_NULL_VOID(host);
230     auto eventHub = host->GetOrCreateEventHub<WebEventHub>();
231     CHECK_NULL_VOID(eventHub);
232     auto mouseEventCallback = eventHub->GetOnMouseEvent();
233     CHECK_NULL_VOID(mouseEventCallback);
234     mouseEventCallback(info);
235 }
236 
WebOnMouseEvent(const MouseInfo & info)237 void WebPattern::WebOnMouseEvent(const MouseInfo& info)
238 {}
239 
GetDragOffset() const240 Offset WebPattern::GetDragOffset() const
241 {
242     Offset webDragOffset;
243     int x = 0;
244     int y = 0;
245 
246     webDragOffset.SetX(x);
247     webDragOffset.SetY(y);
248 
249     return webDragOffset;
250 }
251 
GetDragPixelMapSize() const252 SizeF WebPattern::GetDragPixelMapSize() const
253 {
254     return SizeF(0, 0);
255 }
256 
HandleDoubleClickEvent(const MouseInfo & info)257 bool WebPattern::HandleDoubleClickEvent(const MouseInfo& info)
258 {
259     if (info.GetButton() != MouseButton::LEFT_BUTTON || info.GetAction() != MouseAction::PRESS) {
260         return false;
261     }
262     auto localLocation = info.GetLocalLocation();
263     MouseClickInfo clickInfo;
264     clickInfo.x = localLocation.GetX();
265     clickInfo.y = localLocation.GetY();
266     clickInfo.start = info.GetTimeStamp();
267     if (doubleClickQueue_.empty()) {
268         doubleClickQueue_.push(clickInfo);
269         return false;
270     }
271     std::chrono::duration<float> timeout_ = clickInfo.start - doubleClickQueue_.back().start;
272     double offsetX = clickInfo.x - doubleClickQueue_.back().x;
273     double offsetY = clickInfo.y - doubleClickQueue_.back().y;
274     double offset = sqrt(offsetX * offsetX + offsetY * offsetY);
275     if (timeout_.count() < DEFAULT_DBCLICK_INTERVAL && offset < DEFAULT_DBCLICK_OFFSET) {
276         SendDoubleClickEvent(clickInfo);
277         std::queue<MouseClickInfo> empty;
278         swap(empty, doubleClickQueue_);
279         return true;
280     }
281     if (doubleClickQueue_.size() == 1) {
282         doubleClickQueue_.push(clickInfo);
283         return false;
284     }
285     doubleClickQueue_.pop();
286     doubleClickQueue_.push(clickInfo);
287     return false;
288 }
289 
SendDoubleClickEvent(const MouseClickInfo & info)290 void WebPattern::SendDoubleClickEvent(const MouseClickInfo& info)
291 {
292     CHECK_NULL_VOID(delegate_);
293     delegate_->OnMouseEvent(info.x, info.y, MouseButton::LEFT_BUTTON, MouseAction::PRESS, DOUBLE_CLICK_NUM);
294 }
295 
IsImageDrag()296 bool WebPattern::IsImageDrag()
297 {
298     return false;
299 }
300 
InitFocusEvent(const RefPtr<FocusHub> & focusHub)301 void WebPattern::InitFocusEvent(const RefPtr<FocusHub>& focusHub)
302 {
303     auto focusTask = [weak = WeakClaim(this)](FocusReason reason) {
304         auto pattern = weak.Upgrade();
305         CHECK_NULL_VOID(pattern);
306         pattern->HandleFocusEvent();
307     };
308     focusHub->SetOnFocusInternal(focusTask);
309 
310     auto blurTask = [weak = WeakClaim(this)](const BlurReason& blurReason) {
311         auto pattern = weak.Upgrade();
312         CHECK_NULL_VOID(pattern);
313         pattern->HandleBlurEvent(blurReason);
314     };
315     focusHub->SetOnBlurReasonInternal(blurTask);
316 
317     auto keyTask = [weak = WeakClaim(this)](const KeyEvent& keyEvent) -> bool {
318         auto pattern = weak.Upgrade();
319         CHECK_NULL_RETURN(pattern, false);
320         return pattern->HandleKeyEvent(keyEvent);
321     };
322     focusHub->SetOnKeyEventInternal(keyTask);
323 }
324 
HandleFocusEvent()325 void WebPattern::HandleFocusEvent()
326 {
327     CHECK_NULL_VOID(delegate_);
328     isFocus_ = true;
329     if (needOnFocus_) {
330         delegate_->OnFocus();
331     } else {
332         needOnFocus_ = true;
333     }
334 }
335 
HandleBlurEvent(const BlurReason & blurReason)336 void WebPattern::HandleBlurEvent(const BlurReason& blurReason)
337 {
338     CHECK_NULL_VOID(delegate_);
339     isFocus_ = false;
340     if (!selectPopupMenuShowing_) {
341         delegate_->OnBlur();
342     }
343 }
344 
HandleKeyEvent(const KeyEvent & keyEvent)345 bool WebPattern::HandleKeyEvent(const KeyEvent& keyEvent)
346 {
347     bool ret = false;
348 
349     auto host = GetHost();
350     CHECK_NULL_RETURN(host, ret);
351     auto eventHub = host->GetOrCreateEventHub<WebEventHub>();
352     CHECK_NULL_RETURN(eventHub, ret);
353 
354     KeyEventInfo info(keyEvent);
355     auto keyEventCallback = eventHub->GetOnKeyEvent();
356     if (keyEventCallback) {
357         keyEventCallback(info);
358     }
359 
360     auto preKeyEventCallback = eventHub->GetOnPreKeyEvent();
361     if (preKeyEventCallback) {
362         ret = preKeyEventCallback(info);
363         if (ret) {
364             return ret;
365         }
366     }
367 
368     ret = WebOnKeyEvent(keyEvent);
369     return ret;
370 }
371 
WebOnKeyEvent(const KeyEvent & keyEvent)372 bool WebPattern::WebOnKeyEvent(const KeyEvent& keyEvent)
373 {
374     CHECK_NULL_RETURN(delegate_, false);
375     return delegate_->OnKeyEvent(static_cast<int32_t>(keyEvent.code), static_cast<int32_t>(keyEvent.action));
376 }
377 
WebRequestFocus()378 void WebPattern::WebRequestFocus()
379 {
380     auto host = GetHost();
381     CHECK_NULL_VOID(host);
382     auto eventHub = host->GetOrCreateEventHub<WebEventHub>();
383     CHECK_NULL_VOID(eventHub);
384     auto focusHub = eventHub->GetOrCreateFocusHub();
385     CHECK_NULL_VOID(focusHub);
386 
387     focusHub->RequestFocusImmediately();
388 }
389 
GetWebInfoType()390 WebInfoType WebPattern::GetWebInfoType()
391 {
392     return WebInfoType::TYPE_MOBILE;
393 }
394 
UpdateContentOffset(const RefPtr<LayoutWrapper> & dirty)395 void WebPattern::UpdateContentOffset(const RefPtr<LayoutWrapper>& dirty)
396 {
397     CHECK_NULL_VOID(dirty);
398     auto geometryNode = dirty->GetGeometryNode();
399     CHECK_NULL_VOID(geometryNode);
400     auto host = GetHost();
401     CHECK_NULL_VOID(host);
402     auto renderContext = host->GetRenderContext();
403     CHECK_NULL_VOID(renderContext);
404     auto paddingOffset = geometryNode->GetPaddingOffset();
405     auto webContentSize = geometryNode->GetContentSize();
406     renderContext->SetBounds(
407         paddingOffset.GetX(), paddingOffset.GetY(), webContentSize.Width(), webContentSize.Height());
408 }
409 
OnDirtyLayoutWrapperSwap(const RefPtr<LayoutWrapper> & dirty,const DirtySwapConfig & config)410 bool WebPattern::OnDirtyLayoutWrapperSwap(const RefPtr<LayoutWrapper>& dirty, const DirtySwapConfig& config)
411 {
412     if (!config.contentSizeChange || isInWindowDrag_) {
413         return false;
414     }
415     CHECK_NULL_RETURN(delegate_, false);
416     CHECK_NULL_RETURN(dirty, false);
417     auto geometryNode = dirty->GetGeometryNode();
418     auto drawSize = Size(geometryNode->GetContentSize().Width(), geometryNode->GetContentSize().Height());
419     if (drawSize.IsInfinite() || drawSize.IsEmpty()) {
420         return false;
421     }
422 
423     drawSize_ = drawSize;
424     drawSizeCache_ = drawSize_;
425     auto offset = Offset(GetCoordinatePoint()->GetX(), GetCoordinatePoint()->GetY());
426     delegate_->SetBoundsOrResize(drawSize_, offset);
427     if (!isUrlLoaded_) {
428         isUrlLoaded_ = true;
429         if (webData_) {
430             delegate_->LoadDataWithRichText();
431         }
432     }
433     return false;
434 }
435 
OnAreaChangedInner()436 void WebPattern::OnAreaChangedInner()
437 {
438     auto offset = OffsetF(GetCoordinatePoint()->GetX(), GetCoordinatePoint()->GetY());
439     if (webOffset_ == offset) {
440         return;
441     }
442     auto pipeline = PipelineContext::GetCurrentContext();
443     CHECK_NULL_VOID(pipeline);
444     const double SCREEN_CENTER_POSITION = pipeline->GetRootWidth() / 2.f;
445     if (offset.GetX() == webOffset_.GetX() + SCREEN_CENTER_POSITION) {
446         auto pageOutOffset = Offset(webOffset_.GetX() + drawSize_.Width(), offset.GetY());
447         TAG_LOGI(AceLogTag::ACE_WEB, "Set offset to pageOutOffset");
448         delegate_->SetBoundsOrResize(drawSize_, pageOutOffset);
449         return;
450     }
451     webOffset_ = offset;
452     if (isInWindowDrag_)
453         return;
454     auto resizeOffset = Offset(offset.GetX(), offset.GetY());
455     delegate_->SetBoundsOrResize(drawSize_, resizeOffset);
456 }
457 
OnWebSrcUpdate()458 void WebPattern::OnWebSrcUpdate()
459 {
460     if (delegate_ && isUrlLoaded_) {
461         delegate_->LoadUrl();
462     }
463 }
464 
OnWebDataUpdate()465 void WebPattern::OnWebDataUpdate()
466 {
467     if (delegate_ && isUrlLoaded_) {
468         delegate_->LoadDataWithRichText();
469     }
470 }
471 
OnJsEnabledUpdate(bool value)472 void WebPattern::OnJsEnabledUpdate(bool value)
473 {
474     if (delegate_) {
475         delegate_->UpdateJavaScriptEnabled(value);
476     }
477 }
478 
OnMediaPlayGestureAccessUpdate(bool value)479 void WebPattern::OnMediaPlayGestureAccessUpdate(bool value)
480 {
481     if (delegate_) {
482         delegate_->UpdateMediaPlayGestureAccess(value);
483     }
484 }
485 
OnFileAccessEnabledUpdate(bool value)486 void WebPattern::OnFileAccessEnabledUpdate(bool value)
487 {
488     if (delegate_) {
489         delegate_->UpdateAllowFileAccess(value);
490     }
491 }
492 
OnOnLineImageAccessEnabledUpdate(bool value)493 void WebPattern::OnOnLineImageAccessEnabledUpdate(bool value)
494 {
495     if (delegate_) {
496         delegate_->UpdateBlockNetworkImage(!value);
497     }
498 }
499 
OnDomStorageAccessEnabledUpdate(bool value)500 void WebPattern::OnDomStorageAccessEnabledUpdate(bool value)
501 {
502     if (delegate_) {
503         delegate_->UpdateDomStorageEnabled(value);
504     }
505 }
506 
OnImageAccessEnabledUpdate(bool value)507 void WebPattern::OnImageAccessEnabledUpdate(bool value)
508 {
509     if (delegate_) {
510         delegate_->UpdateLoadsImagesAutomatically(value);
511     }
512 }
513 
OnMixedModeUpdate(MixedModeContent value)514 void WebPattern::OnMixedModeUpdate(MixedModeContent value)
515 {
516     if (delegate_) {
517         delegate_->UpdateMixedContentMode(value);
518     }
519 }
520 
OnZoomAccessEnabledUpdate(bool value)521 void WebPattern::OnZoomAccessEnabledUpdate(bool value)
522 {
523     if (delegate_) {
524         delegate_->UpdateSupportZoom(value);
525     }
526 }
527 
OnGeolocationAccessEnabledUpdate(bool value)528 void WebPattern::OnGeolocationAccessEnabledUpdate(bool value)
529 {
530     if (delegate_) {
531         delegate_->UpdateGeolocationEnabled(value);
532     }
533 }
534 
OnUserAgentUpdate(const std::string & value)535 void WebPattern::OnUserAgentUpdate(const std::string& value)
536 {
537     if (delegate_) {
538         delegate_->UpdateUserAgent(value);
539     }
540 }
541 
OnCacheModeUpdate(WebCacheMode value)542 void WebPattern::OnCacheModeUpdate(WebCacheMode value)
543 {
544     if (delegate_) {
545         delegate_->UpdateCacheMode(value);
546     }
547 }
548 
OnDarkModeUpdate(WebDarkMode mode)549 void WebPattern::OnDarkModeUpdate(WebDarkMode mode)
550 {
551     if (delegate_) {
552         delegate_->UpdateDarkMode(mode);
553     }
554 }
555 
OnForceDarkAccessUpdate(bool access)556 void WebPattern::OnForceDarkAccessUpdate(bool access)
557 {
558     if (delegate_) {
559         delegate_->UpdateForceDarkAccess(access);
560     }
561 }
562 
OnAudioResumeIntervalUpdate(int32_t resumeInterval)563 void WebPattern::OnAudioResumeIntervalUpdate(int32_t resumeInterval)
564 {
565     if (delegate_) {
566         delegate_->UpdateAudioResumeInterval(resumeInterval);
567     }
568 }
569 
OnAudioExclusiveUpdate(bool audioExclusive)570 void WebPattern::OnAudioExclusiveUpdate(bool audioExclusive)
571 {
572     if (delegate_) {
573         delegate_->UpdateAudioExclusive(audioExclusive);
574     }
575 }
576 
OnAudioSessionTypeUpdate(WebAudioSessionType value)577 void WebPattern::OnAudioSessionTypeUpdate(WebAudioSessionType value)
578 {
579     if (delegate_) {
580         delegate_->UpdateAudioSessionType(value);
581     }
582 }
583 
OnOverviewModeAccessEnabledUpdate(bool value)584 void WebPattern::OnOverviewModeAccessEnabledUpdate(bool value)
585 {
586     if (delegate_) {
587         delegate_->UpdateOverviewModeEnabled(value);
588     }
589 }
590 
OnFileFromUrlAccessEnabledUpdate(bool value)591 void WebPattern::OnFileFromUrlAccessEnabledUpdate(bool value)
592 {
593     if (delegate_) {
594         delegate_->UpdateFileFromUrlEnabled(value);
595     }
596 }
597 
OnDatabaseAccessEnabledUpdate(bool value)598 void WebPattern::OnDatabaseAccessEnabledUpdate(bool value)
599 {
600     if (delegate_) {
601         delegate_->UpdateDatabaseEnabled(value);
602     }
603 }
604 
OnTextZoomRatioUpdate(int32_t value)605 void WebPattern::OnTextZoomRatioUpdate(int32_t value)
606 {
607     if (delegate_) {
608         delegate_->UpdateTextZoomRatio(value);
609     }
610 }
611 
OnWebDebuggingAccessEnabledAndPortUpdate(const WebPatternProperty::WebDebuggingConfigType & enabled_and_port)612 void WebPattern::OnWebDebuggingAccessEnabledAndPortUpdate(
613     const WebPatternProperty::WebDebuggingConfigType& enabled_and_port)
614 {
615     if (delegate_) {
616         bool enabled = std::get<0>(enabled_and_port);
617         delegate_->UpdateWebDebuggingAccess(enabled);
618     }
619 }
620 
OnPinchSmoothModeEnabledUpdate(bool value)621 void WebPattern::OnPinchSmoothModeEnabledUpdate(bool value)
622 {
623     if (delegate_) {
624         delegate_->UpdatePinchSmoothModeEnabled(value);
625     }
626 }
627 
OnBackgroundColorUpdate(int32_t value)628 void WebPattern::OnBackgroundColorUpdate(int32_t value)
629 {
630     UpdateBackgroundColorRightNow(value);
631     if (delegate_) {
632         delegate_->UpdateBackgroundColor(value);
633     }
634 }
635 
OnInitialScaleUpdate(float value)636 void WebPattern::OnInitialScaleUpdate(float value)
637 {
638     if (delegate_) {
639         delegate_->UpdateInitialScale(value);
640     }
641 }
642 
OnMultiWindowAccessEnabledUpdate(bool value)643 void WebPattern::OnMultiWindowAccessEnabledUpdate(bool value)
644 {
645     if (delegate_) {
646         delegate_->UpdateMultiWindowAccess(value);
647     }
648 }
649 
OnAllowWindowOpenMethodUpdate(bool value)650 void WebPattern::OnAllowWindowOpenMethodUpdate(bool value)
651 {
652     if (delegate_) {
653         delegate_->UpdateAllowWindowOpenMethod(value);
654     }
655 }
656 
OnWebCursiveFontUpdate(const std::string & value)657 void WebPattern::OnWebCursiveFontUpdate(const std::string& value)
658 {
659     if (delegate_) {
660         delegate_->UpdateWebCursiveFont(value);
661     }
662 }
663 
OnWebFantasyFontUpdate(const std::string & value)664 void WebPattern::OnWebFantasyFontUpdate(const std::string& value)
665 {
666     if (delegate_) {
667         delegate_->UpdateWebFantasyFont(value);
668     }
669 }
670 
OnWebFixedFontUpdate(const std::string & value)671 void WebPattern::OnWebFixedFontUpdate(const std::string& value)
672 {
673     if (delegate_) {
674         delegate_->UpdateWebFixedFont(value);
675     }
676 }
677 
OnWebSansSerifFontUpdate(const std::string & value)678 void WebPattern::OnWebSansSerifFontUpdate(const std::string& value)
679 {
680     if (delegate_) {
681         delegate_->UpdateWebSansSerifFont(value);
682     }
683 }
684 
OnWebSerifFontUpdate(const std::string & value)685 void WebPattern::OnWebSerifFontUpdate(const std::string& value)
686 {
687     if (delegate_) {
688         delegate_->UpdateWebSerifFont(value);
689     }
690 }
691 
OnWebStandardFontUpdate(const std::string & value)692 void WebPattern::OnWebStandardFontUpdate(const std::string& value)
693 {
694     if (delegate_) {
695         delegate_->UpdateWebStandardFont(value);
696     }
697 }
698 
OnDefaultFixedFontSizeUpdate(int32_t value)699 void WebPattern::OnDefaultFixedFontSizeUpdate(int32_t value)
700 {
701     if (delegate_) {
702         delegate_->UpdateDefaultFixedFontSize(value);
703     }
704 }
705 
OnDefaultFontSizeUpdate(int32_t value)706 void WebPattern::OnDefaultFontSizeUpdate(int32_t value)
707 {
708     if (delegate_) {
709         delegate_->UpdateDefaultFontSize(value);
710     }
711 }
712 
OnMinFontSizeUpdate(int32_t value)713 void WebPattern::OnMinFontSizeUpdate(int32_t value)
714 {
715     if (delegate_) {
716         delegate_->UpdateMinFontSize(value);
717     }
718 }
719 
OnMinLogicalFontSizeUpdate(int32_t value)720 void WebPattern::OnMinLogicalFontSizeUpdate(int32_t value)
721 {
722     if (delegate_) {
723         delegate_->UpdateMinLogicalFontSize(value);
724     }
725 }
726 
OnBlockNetworkUpdate(bool value)727 void WebPattern::OnBlockNetworkUpdate(bool value)
728 {
729     if (delegate_) {
730         delegate_->UpdateBlockNetwork(value);
731     }
732 }
733 
OnHorizontalScrollBarAccessEnabledUpdate(bool value)734 void WebPattern::OnHorizontalScrollBarAccessEnabledUpdate(bool value)
735 {
736     if (delegate_) {
737         delegate_->UpdateHorizontalScrollBarAccess(value);
738     }
739 }
740 
OnVerticalScrollBarAccessEnabledUpdate(bool value)741 void WebPattern::OnVerticalScrollBarAccessEnabledUpdate(bool value)
742 {
743     if (delegate_) {
744         delegate_->UpdateVerticalScrollBarAccess(value);
745     }
746 }
747 
SetUpdateInstanceIdCallback(std::function<void (int32_t)> && callback)748 void WebPattern::SetUpdateInstanceIdCallback(std::function<void(int32_t)>&& callback)
749 {
750     updateInstanceIdCallback_ = callback;
751 }
752 
OnScrollBarColorUpdate(const std::string & value)753 void WebPattern::OnScrollBarColorUpdate(const std::string& value)
754 {
755     if (delegate_) {
756         delegate_->UpdateScrollBarColor(value);
757     }
758 }
759 
RegistVirtualKeyBoardListener()760 void WebPattern::RegistVirtualKeyBoardListener()
761 {
762     if (!needUpdateWeb_) {
763         return;
764     }
765     auto pipelineContext = PipelineContext::GetCurrentContext();
766     CHECK_NULL_VOID(pipelineContext);
767     pipelineContext->SetVirtualKeyBoardCallback(
768         [weak = AceType::WeakClaim(this)](int32_t width, int32_t height, double keyboard, bool isCustomKeyboard) {
769             auto webPattern = weak.Upgrade();
770             CHECK_NULL_RETURN(webPattern, false);
771             return webPattern->ProcessVirtualKeyBoard(width, height, keyboard);
772         });
773     needUpdateWeb_ = false;
774 }
775 
InitEnhanceSurfaceFlag()776 void WebPattern::InitEnhanceSurfaceFlag()
777 {
778     if (SystemProperties::GetExtSurfaceEnabled()) {
779         isEnhanceSurface_ = true;
780     } else {
781         isEnhanceSurface_ = false;
782     }
783 }
784 
OnModifyDone()785 void WebPattern::OnModifyDone()
786 {
787     Pattern::OnModifyDone();
788     // called in each update function.
789     auto host = GetHost();
790     CHECK_NULL_VOID(host);
791     auto renderContext = host->GetRenderContext();
792     CHECK_NULL_VOID(renderContext);
793 
794 #if !defined(IOS_PLATFORM) && !defined(ANDROID_PLATFORM)
795     RegistVirtualKeyBoardListener();
796 #endif
797     if (!delegate_) {
798         // first create case,
799 #if defined(IOS_PLATFORM) || defined(ANDROID_PLATFORM)
800         WeakPtr<PipelineContext> context = WeakPtr<PipelineContext>(PipelineContext::GetCurrentContext());
801         delegate_ = AceType::MakeRefPtr<WebDelegateCross>(PipelineContext::GetCurrentContext(), nullptr, "web");
802         delegate_->SetNGWebPattern(Claim(this));
803         delegate_->CreatePlatformResource(Size(0, 0), Offset(0, 0), context);
804         if (setWebIdCallback_) {
805             setWebIdCallback_(delegate_->GetWebId());
806         }
807         auto container = Container::Current();
808         CHECK_NULL_VOID(container);
809         if (setHapPathCallback_) {
810             setHapPathCallback_(container->GetHapPath());
811         }
812         if (onControllerAttachedCallback_) {
813             onControllerAttachedCallback_();
814         }
815 
816 #else
817         delegate_ = AceType::MakeRefPtr<WebDelegate>(PipelineContext::GetCurrentContext(), nullptr, "");
818         CHECK_NULL_VOID(delegate_);
819         observer_ = AceType::MakeRefPtr<WebDelegateObserver>(delegate_, PipelineContext::GetCurrentContext());
820         CHECK_NULL_VOID(observer_);
821         delegate_->SetObserver(observer_);
822         delegate_->SetRenderMode(renderMode_);
823         InitEnhanceSurfaceFlag();
824         delegate_->SetNGWebPattern(Claim(this));
825         delegate_->SetEnhanceSurfaceFlag(isEnhanceSurface_);
826         delegate_->SetPopup(isPopup_);
827         delegate_->SetParentNWebId(parentNWebId_);
828         delegate_->SetBackgroundColor(GetBackgroundColorValue(
829             static_cast<int32_t>(renderContext->GetBackgroundColor().value_or(Color::WHITE).GetValue())));
830         if (isEnhanceSurface_) {
831             auto drawSize = Size(1, 1);
832             delegate_->SetDrawSize(drawSize);
833             delegate_->InitOHOSWeb(PipelineContext::GetCurrentContext());
834         } else {
835             auto drawSize = Size(1, 1);
836             delegate_->SetDrawSize(drawSize);
837             renderSurface_->SetRenderContext(host->GetRenderContext());
838             if (renderMode_ == RenderMode::SYNC_RENDER) {
839                 renderSurface_->SetIsTexture(true);
840                 renderSurface_->SetPatternType(PATTERN_TYPE_WEB);
841                 renderSurface_->SetSurfaceQueueSize(SYNC_SURFACE_QUEUE_SIZE);
842             } else {
843                 renderSurface_->SetIsTexture(false);
844                 renderSurface_->SetSurfaceQueueSize(ASYNC_SURFACE_QUEUE_SIZE);
845             }
846             renderSurface_->InitSurface();
847             renderSurface_->UpdateSurfaceConfig();
848             delegate_->InitOHOSWeb(PipelineContext::GetCurrentContext(), renderSurface_);
849         }
850 #endif
851         delegate_->UpdateBackgroundColor(GetBackgroundColorValue(
852             static_cast<int32_t>(renderContext->GetBackgroundColor().value_or(Color::WHITE).GetValue())));
853         delegate_->UpdateJavaScriptEnabled(GetJsEnabledValue(true));
854         delegate_->UpdateBlockNetworkImage(!GetOnLineImageAccessEnabledValue(true));
855         delegate_->UpdateAllowFileAccess(GetFileAccessEnabledValue(true));
856         delegate_->UpdateLoadsImagesAutomatically(GetImageAccessEnabledValue(true));
857         delegate_->UpdateMixedContentMode(GetMixedModeValue(MixedModeContent::MIXED_CONTENT_NEVER_ALLOW));
858         delegate_->UpdateSupportZoom(GetZoomAccessEnabledValue(true));
859         delegate_->UpdateDomStorageEnabled(GetDomStorageAccessEnabledValue(false));
860         delegate_->UpdateGeolocationEnabled(GetGeolocationAccessEnabledValue(true));
861         delegate_->UpdateCacheMode(GetCacheModeValue(WebCacheMode::DEFAULT));
862         delegate_->UpdateDarkMode(GetDarkModeValue(WebDarkMode::Off));
863         delegate_->UpdateForceDarkAccess(GetForceDarkAccessValue(false));
864         delegate_->UpdateAudioResumeInterval(GetAudioResumeIntervalValue(-1));
865         delegate_->UpdateAudioExclusive(GetAudioExclusiveValue(true));
866         delegate_->UpdateAudioSessionType(GetAudioSessionTypeValue(WebAudioSessionType::AUTO));
867         delegate_->UpdateOverviewModeEnabled(GetOverviewModeAccessEnabledValue(true));
868         delegate_->UpdateFileFromUrlEnabled(GetFileFromUrlAccessEnabledValue(false));
869         delegate_->UpdateDatabaseEnabled(GetDatabaseAccessEnabledValue(false));
870         delegate_->UpdateTextZoomRatio(GetTextZoomRatioValue(DEFAULT_TEXT_ZOOM_RATIO));
871         auto webDebugingConfig = GetWebDebuggingAccessEnabledAndPort();
872         if (webDebugingConfig) {
873             bool enabled = std::get<0>(webDebugingConfig.value());
874             delegate_->UpdateWebDebuggingAccess(enabled);
875         }
876         delegate_->UpdateMediaPlayGestureAccess(GetMediaPlayGestureAccessValue(true));
877         delegate_->UpdatePinchSmoothModeEnabled(GetPinchSmoothModeEnabledValue(false));
878         delegate_->UpdateMultiWindowAccess(GetMultiWindowAccessEnabledValue(false));
879         delegate_->UpdateWebCursiveFont(GetWebCursiveFontValue(DEFAULT_CURSIVE_FONT_FAMILY));
880         delegate_->UpdateWebFantasyFont(GetWebFantasyFontValue(DEFAULT_FANTASY_FONT_FAMILY));
881         delegate_->UpdateWebFixedFont(GetWebFixedFontValue(DEFAULT_FIXED_fONT_FAMILY));
882         delegate_->UpdateWebSansSerifFont(GetWebSansSerifFontValue(DEFAULT_SANS_SERIF_FONT_FAMILY));
883         delegate_->UpdateWebSerifFont(GetWebSerifFontValue(DEFAULT_SERIF_FONT_FAMILY));
884         delegate_->UpdateWebStandardFont(GetWebStandardFontValue(DEFAULT_STANDARD_FONT_FAMILY));
885         delegate_->UpdateDefaultFixedFontSize(GetDefaultFixedFontSizeValue(DEFAULT_FIXED_FONT_SIZE));
886         delegate_->UpdateDefaultFontSize(GetDefaultFontSizeValue(DEFAULT_FONT_SIZE));
887         delegate_->UpdateMinFontSize(GetMinFontSizeValue(DEFAULT_MINIMUM_FONT_SIZE));
888         delegate_->UpdateMinLogicalFontSize(GetMinLogicalFontSizeValue(DEFAULT_MINIMUM_LOGICAL_FONT_SIZE));
889         delegate_->UpdateHorizontalScrollBarAccess(GetHorizontalScrollBarAccessEnabledValue(true));
890         delegate_->UpdateVerticalScrollBarAccess(GetVerticalScrollBarAccessEnabledValue(true));
891         delegate_->UpdateScrollBarColor(GetScrollBarColorValue(DEFAULT_SCROLLBAR_COLOR));
892         if (GetBlockNetwork()) {
893             delegate_->UpdateBlockNetwork(GetBlockNetwork().value());
894         }
895         if (GetUserAgent()) {
896             delegate_->UpdateUserAgent(GetUserAgent().value());
897         }
898         if (GetInitialScale()) {
899             delegate_->UpdateInitialScale(GetInitialScale().value());
900         }
901     }
902 
903     // Initialize events such as keyboard, focus, etc.
904     InitEvent();
905 
906     // Initialize scrollupdate listener
907     if (renderMode_ == RenderMode::SYNC_RENDER) {
908         auto task = [this]() {
909             InitSlideUpdateListener();
910         };
911         PostTaskToUI(std::move(task));
912     }
913     auto pipelineContext = PipelineContext::GetCurrentContext();
914     CHECK_NULL_VOID(pipelineContext);
915     pipelineContext->AddOnAreaChangeNode(host->GetId());
916 }
917 
ProcessVirtualKeyBoard(int32_t width,int32_t height,double keyboard)918 bool WebPattern::ProcessVirtualKeyBoard(int32_t width, int32_t height, double keyboard)
919 {
920     CHECK_NULL_RETURN(delegate_, false);
921     if (!isFocus_) {
922         if (isVirtualKeyBoardShow_ == VkState::VK_SHOW) {
923             drawSize_.SetSize(drawSizeCache_);
924             UpdateWebLayoutSize(width, height);
925             isVirtualKeyBoardShow_ = VkState::VK_HIDE;
926         }
927         return false;
928     }
929     if (NearZero(keyboard)) {
930         drawSize_.SetSize(drawSizeCache_);
931         UpdateWebLayoutSize(width, height);
932         isVirtualKeyBoardShow_ = VkState::VK_HIDE;
933     } else if (isVirtualKeyBoardShow_ != VkState::VK_SHOW) {
934         drawSizeCache_.SetSize(drawSize_);
935         if (drawSize_.Height() <= (height - keyboard - GetCoordinatePoint()->GetY())) {
936             isVirtualKeyBoardShow_ = VkState::VK_SHOW;
937             return true;
938         }
939         if (height - GetCoordinatePoint()->GetY() < keyboard) {
940             return true;
941         }
942         drawSize_.SetHeight(height - keyboard - GetCoordinatePoint()->GetY());
943         UpdateWebLayoutSize(width, height);
944         isVirtualKeyBoardShow_ = VkState::VK_SHOW;
945     }
946     return true;
947 }
948 
UpdateWebLayoutSize(int32_t width,int32_t height)949 void WebPattern::UpdateWebLayoutSize(int32_t width, int32_t height)
950 {
951     auto frameNode = GetHost();
952     CHECK_NULL_VOID(frameNode);
953     auto rect = frameNode->GetGeometryNode()->GetFrameRect();
954     auto offset = Offset(GetCoordinatePoint()->GetX(), GetCoordinatePoint()->GetY());
955     delegate_->SetBoundsOrResize(drawSize_, offset);
956     rect.SetSize(SizeF(drawSize_.Width(), drawSize_.Height()));
957     frameNode->GetRenderContext()->SyncGeometryProperties(rect);
958     frameNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE_SELF);
959     auto context = PipelineContext::GetCurrentContext();
960     CHECK_NULL_VOID(context);
961     context->SetRootRect(width, height, 0);
962 }
963 
HandleTouchDown(const TouchEventInfo & info,bool fromOverlay)964 void WebPattern::HandleTouchDown(const TouchEventInfo& info, bool fromOverlay)
965 {
966     CHECK_NULL_VOID(delegate_);
967     Offset touchOffset = Offset(0, 0);
968     std::list<TouchInfo> touchInfos;
969     if (!ParseTouchInfo(info, touchInfos)) {
970         return;
971     }
972     for (auto& touchPoint : touchInfos) {
973         if (fromOverlay) {
974             touchPoint.x -= webOffset_.GetX();
975             touchPoint.y -= webOffset_.GetY();
976         }
977         delegate_->HandleTouchDown(touchPoint.id, touchPoint.x, touchPoint.y, fromOverlay);
978     }
979 }
980 
HandleTouchUp(const TouchEventInfo & info,bool fromOverlay)981 void WebPattern::HandleTouchUp(const TouchEventInfo& info, bool fromOverlay)
982 {
983     CHECK_NULL_VOID(delegate_);
984     std::list<TouchInfo> touchInfos;
985     if (!ParseTouchInfo(info, touchInfos)) {
986         return;
987     }
988     for (auto& touchPoint : touchInfos) {
989         if (fromOverlay) {
990             touchPoint.x -= webOffset_.GetX();
991             touchPoint.y -= webOffset_.GetY();
992         }
993         delegate_->HandleTouchUp(touchPoint.id, touchPoint.x, touchPoint.y, fromOverlay);
994     }
995     if (!touchInfos.empty()) {
996         WebRequestFocus();
997     }
998 }
999 
HandleTouchMove(const TouchEventInfo & info,bool fromOverlay)1000 void WebPattern::HandleTouchMove(const TouchEventInfo& info, bool fromOverlay)
1001 {
1002     if (isDragging_) {
1003         return;
1004     }
1005     auto pipeline = PipelineContext::GetCurrentContext();
1006     CHECK_NULL_VOID(pipeline);
1007     auto manager = pipeline->GetDragDropManager();
1008     CHECK_NULL_VOID(manager);
1009     if (manager->IsDragged()) {
1010         return;
1011     }
1012     CHECK_NULL_VOID(delegate_);
1013     std::list<TouchInfo> touchInfos;
1014     if (!ParseTouchInfo(info, touchInfos)) {
1015         return;
1016     }
1017     for (auto& touchPoint : touchInfos) {
1018         if (fromOverlay) {
1019             touchPoint.x -= webOffset_.GetX();
1020             touchPoint.y -= webOffset_.GetY();
1021         }
1022         delegate_->HandleTouchMove(touchPoint.id, touchPoint.x, touchPoint.y, fromOverlay);
1023     }
1024 }
1025 
HandleTouchCancel(const TouchEventInfo & info)1026 void WebPattern::HandleTouchCancel(const TouchEventInfo& info)
1027 {
1028     CHECK_NULL_VOID(delegate_);
1029     delegate_->HandleTouchCancel();
1030 }
1031 
ParseTouchInfo(const TouchEventInfo & info,std::list<TouchInfo> & touchInfos)1032 bool WebPattern::ParseTouchInfo(const TouchEventInfo& info, std::list<TouchInfo>& touchInfos)
1033 {
1034     auto context = PipelineContext::GetCurrentContext();
1035     CHECK_NULL_RETURN(context, false);
1036     auto viewScale = context->GetViewScale();
1037     if (info.GetChangedTouches().empty()) {
1038         return false;
1039     }
1040     for (const auto& point : info.GetChangedTouches()) {
1041         TouchInfo touchInfo;
1042         touchInfo.id = point.GetFingerId();
1043         const Offset& location = point.GetLocalLocation();
1044         touchInfo.x = static_cast<float>(location.GetX() * viewScale);
1045         touchInfo.y = static_cast<float>(location.GetY() * viewScale);
1046         touchInfos.emplace_back(touchInfo);
1047     }
1048     return true;
1049 }
1050 
RequestFullScreen()1051 void WebPattern::RequestFullScreen()
1052 {
1053     isFullScreen_ = true;
1054 }
1055 
ExitFullScreen()1056 void WebPattern::ExitFullScreen()
1057 {
1058     isFullScreen_ = false;
1059 }
1060 
GetCoordinatePoint()1061 std::optional<OffsetF> WebPattern::GetCoordinatePoint()
1062 {
1063     auto frameNode = GetHost();
1064     CHECK_NULL_RETURN(frameNode, OffsetF());
1065     return frameNode->GetTransformRelativeOffset();
1066 }
1067 
UpdateLocale()1068 void WebPattern::UpdateLocale()
1069 {
1070     CHECK_NULL_VOID(delegate_);
1071     delegate_->UpdateLocale();
1072 }
1073 
OnWindowShow()1074 void WebPattern::OnWindowShow()
1075 {
1076     if (isWindowShow_ || !isVisible_) {
1077         return;
1078     }
1079 
1080     CHECK_NULL_VOID(delegate_);
1081     delegate_->ShowWebView();
1082     isWindowShow_ = true;
1083 }
1084 
OnWindowHide()1085 void WebPattern::OnWindowHide()
1086 {
1087     if (!isWindowShow_ || !isVisible_) {
1088         return;
1089     }
1090 
1091     CHECK_NULL_VOID(delegate_);
1092     delegate_->HideWebView();
1093     needOnFocus_ = false;
1094     isWindowShow_ = false;
1095 }
1096 
OnWindowSizeChanged(int32_t width,int32_t height,WindowSizeChangeReason type)1097 void WebPattern::OnWindowSizeChanged(int32_t width, int32_t height, WindowSizeChangeReason type) {}
1098 
OnCompleteSwapWithNewSize()1099 void WebPattern::OnCompleteSwapWithNewSize()
1100 {
1101     if (!isInWindowDrag_ || !isWaiting_)
1102         return;
1103 
1104     ACE_SCOPED_TRACE("WebPattern::OnCompleteSwapWithNewSize");
1105     isWaiting_ = false;
1106 }
1107 
OnResizeNotWork()1108 void WebPattern::OnResizeNotWork()
1109 {
1110     if (!isInWindowDrag_ || !isWaiting_)
1111         return;
1112 
1113     ACE_SCOPED_TRACE("WebPattern::OnResizeNotWork");
1114     isWaiting_ = false;
1115 }
1116 
OnBackPressed() const1117 bool WebPattern::OnBackPressed() const
1118 {
1119     if (!isFullScreen_) {
1120         return false;
1121     }
1122 
1123     CHECK_NULL_RETURN(fullScreenExitHandler_, false);
1124     auto webFullScreenExitHandler = fullScreenExitHandler_->GetHandler();
1125     CHECK_NULL_RETURN(webFullScreenExitHandler, false);
1126     webFullScreenExitHandler->ExitFullScreen();
1127     return true;
1128 }
1129 
OnBackPressedForFullScreen() const1130 bool WebPattern::OnBackPressedForFullScreen() const
1131 {
1132     if (!isFullScreen_) {
1133         return false;
1134     }
1135 
1136     CHECK_NULL_RETURN(fullScreenExitHandler_, false);
1137     auto webFullScreenExitHandler = fullScreenExitHandler_->GetHandler();
1138     CHECK_NULL_RETURN(webFullScreenExitHandler, false);
1139     webFullScreenExitHandler->ExitFullScreen();
1140     return true;
1141 }
1142 
SetFullScreenExitHandler(const std::shared_ptr<FullScreenEnterEvent> & fullScreenExitHandler)1143 void WebPattern::SetFullScreenExitHandler(const std::shared_ptr<FullScreenEnterEvent>& fullScreenExitHandler)
1144 {
1145     fullScreenExitHandler_ = fullScreenExitHandler;
1146 }
1147 
OnInActive()1148 void WebPattern::OnInActive()
1149 {
1150     if (!isActive_) {
1151         return;
1152     }
1153 
1154     CHECK_NULL_VOID(delegate_);
1155     delegate_->OnInactive();
1156     isActive_ = false;
1157 }
1158 
OnActive()1159 void WebPattern::OnActive()
1160 {
1161     if (isActive_) {
1162         return;
1163     }
1164 
1165     CHECK_NULL_VOID(delegate_);
1166     delegate_->OnActive();
1167     isActive_ = true;
1168 }
1169 
OnVisibleChange(bool isVisible)1170 void WebPattern::OnVisibleChange(bool isVisible)
1171 {
1172     if (isVisible_ == isVisible) {
1173         return;
1174     }
1175 
1176     isVisible_ = isVisible;
1177     if (!isVisible_) {
1178         if (isVisibleActiveEnable_) {
1179             OnInActive();
1180         }
1181     } else {
1182         if (isVisibleActiveEnable_) {
1183             OnActive();
1184         }
1185     }
1186 }
1187 
GetDefaultBackgroundColor()1188 Color WebPattern::GetDefaultBackgroundColor()
1189 {
1190     return Color::WHITE;
1191 }
1192 
UpdateBackgroundColorRightNow(int32_t color)1193 void WebPattern::UpdateBackgroundColorRightNow(int32_t color)
1194 {
1195     auto host = GetHost();
1196     CHECK_NULL_VOID(host);
1197     auto renderContext = host->GetRenderContext();
1198     CHECK_NULL_VOID(renderContext);
1199     renderContext->UpdateBackgroundColor(Color(static_cast<uint32_t>(color)));
1200 }
1201 
OnRootLayerChanged(int width,int height)1202 void WebPattern::OnRootLayerChanged(int width, int height)
1203 {
1204     // cross platform is not support now;
1205 }
1206 
SetNestedScroll(const NestedScrollOptions & nestedOpt)1207 void WebPattern::SetNestedScroll(const NestedScrollOptions& nestedOpt)
1208 {
1209     // cross platform is not support now;
1210 }
1211 
SetNestedScrollExt(const NestedScrollOptionsExt & nestedOpt)1212 void WebPattern::SetNestedScrollExt(const NestedScrollOptionsExt& nestedOpt)
1213 {
1214     // cross platform is not support now;
1215 }
1216 
OnScrollStart(const float x,const float y)1217 void WebPattern::OnScrollStart(const float x, const float y)
1218 {
1219     // cross platform is not support now;
1220 }
1221 
JavaScriptOnDocumentStart(const ScriptItems & scriptItems)1222 void WebPattern::JavaScriptOnDocumentStart(const ScriptItems& scriptItems)
1223 {
1224     // cross platform is not support now;
1225 }
1226 
UpdateJavaScriptOnDocumentStart()1227 void WebPattern::UpdateJavaScriptOnDocumentStart()
1228 {
1229     // cross platform is not support now;
1230 }
1231 
JavaScriptOnDocumentEnd(const ScriptItems & scriptItems)1232 void WebPattern::JavaScriptOnDocumentEnd(const ScriptItems& scriptItems)
1233 {
1234     // cross platform is not support now;
1235 }
1236 
JavaScriptOnDocumentStartByOrder(const ScriptItems & scriptItems,const ScriptItemsByOrder & scriptItemsByOrder)1237 void WebPattern::JavaScriptOnDocumentStartByOrder(const ScriptItems& scriptItems,
1238     const ScriptItemsByOrder& scriptItemsByOrder)
1239 {
1240     // cross platform is not support now;
1241 }
1242 
JavaScriptOnDocumentEndByOrder(const ScriptItems & scriptItems,const ScriptItemsByOrder & scriptItemsByOrder)1243 void WebPattern::JavaScriptOnDocumentEndByOrder(const ScriptItems& scriptItems,
1244     const ScriptItemsByOrder& scriptItemsByOrder)
1245 {
1246     // cross platform is not support now;
1247 }
1248 
JavaScriptOnHeadReadyByOrder(const ScriptItems & scriptItems,const ScriptItemsByOrder & scriptItemsByOrder)1249 void WebPattern::JavaScriptOnHeadReadyByOrder(const ScriptItems& scriptItems,
1250     const ScriptItemsByOrder& scriptItemsByOrder)
1251 {
1252     // cross platform is not support now;
1253 }
1254 
OnOverScrollModeUpdate(int mode)1255 void WebPattern::OnOverScrollModeUpdate(int mode)
1256 {
1257    // cross platform is not support now;
1258 }
1259 
OnBlurOnKeyboardHideModeUpdate(int mode)1260 void WebPattern::OnBlurOnKeyboardHideModeUpdate(int mode)
1261 {
1262    // cross platform is not support now;
1263 }
1264 
OnCopyOptionModeUpdate(int32_t mode)1265 void WebPattern::OnCopyOptionModeUpdate(int32_t mode)
1266 {
1267     // cross platform is not support now;
1268 }
1269 
OnTextAutosizingUpdate(bool isTextAutosizing)1270 void WebPattern::OnTextAutosizingUpdate(bool isTextAutosizing)
1271 {
1272     // cross platform is not support now;
1273 }
1274 
UpdateRelativeOffset()1275 void WebPattern::UpdateRelativeOffset()
1276 {
1277     // cross platform is not support now;
1278 }
1279 
InitSlideUpdateListener()1280 void WebPattern::InitSlideUpdateListener()
1281 {
1282     // cross platform is not support now;
1283 }
1284 
UpdateSlideOffset(bool isNeedReset)1285 void WebPattern::UpdateSlideOffset(bool isNeedReset)
1286 {
1287     // cross platform is not support now;
1288 }
1289 
Backward()1290 bool WebPattern::Backward()
1291 {
1292     return false;
1293 }
1294 
CalculateHorizontalDrawRect()1295 void WebPattern::CalculateHorizontalDrawRect()
1296 {
1297    // cross platform is not support now;
1298 }
1299 
CalculateVerticalDrawRect()1300 void WebPattern::CalculateVerticalDrawRect()
1301 {
1302     // cross platform is not support now;
1303 }
1304 
PostTaskToUI(const std::function<void ()> && task) const1305 void WebPattern::PostTaskToUI(const std::function<void()>&& task) const
1306 {
1307     // cross platform is not support now;
1308 }
1309 
SetDrawRect(int32_t x,int32_t y,int32_t width,int32_t height)1310 void WebPattern::SetDrawRect(int32_t x, int32_t y, int32_t width, int32_t height)
1311 {
1312     // cross platform is not support now;
1313 }
1314 
CreateNodePaintMethod()1315 RefPtr<NodePaintMethod> WebPattern::CreateNodePaintMethod()
1316 {
1317     // cross platform is not support now;
1318     return nullptr;
1319 }
1320 
OnDefaultTextEncodingFormatUpdate(const std::string & value)1321 void WebPattern::OnDefaultTextEncodingFormatUpdate(const std::string& value)
1322 {
1323     // cross platform is not support now;
1324 }
1325 
OnSelectionMenuOptionsUpdate(const WebMenuOptionsParam & webMenuOption)1326 void  WebPattern::OnSelectionMenuOptionsUpdate(const WebMenuOptionsParam& webMenuOption)
1327 {
1328     // cross platform is not support now;
1329 }
1330 
OnNativeVideoPlayerConfigUpdate(const std::tuple<bool,bool> & config)1331 void WebPattern::OnNativeVideoPlayerConfigUpdate(const std::tuple<bool, bool>& config)
1332 {
1333     // cross platform is not support now;
1334 }
1335 
OnOverlayScrollbarEnabledUpdate(bool value)1336 void WebPattern::OnOverlayScrollbarEnabledUpdate(bool value)
1337 {
1338     // cross platform is not support now;
1339 }
1340 
OnIntrinsicSizeEnabledUpdate(bool value)1341 void WebPattern::OnIntrinsicSizeEnabledUpdate(bool value)
1342 {
1343     // cross platform is not support now;
1344 }
1345 
OnCssDisplayChangeEnabledUpdate(bool value)1346 void WebPattern::OnCssDisplayChangeEnabledUpdate(bool value)
1347 {
1348     // cross platform is not support now;
1349 }
1350 
OnNativeEmbedRuleTagUpdate(const std::string & tag)1351 void WebPattern::OnNativeEmbedRuleTagUpdate(const std::string& tag)
1352 {
1353     // cross platform is not support now;
1354 }
1355 
OnNativeEmbedRuleTypeUpdate(const std::string & type)1356 void WebPattern::OnNativeEmbedRuleTypeUpdate(const std::string& type)
1357 {
1358     // cross platform is not support now;
1359 }
1360 
OnMetaViewportUpdate(bool value)1361 void WebPattern::OnMetaViewportUpdate(bool value)
1362 {
1363     // cross platform is not support now;
1364 }
1365 
OnKeyboardAvoidModeUpdate(const WebKeyboardAvoidMode & mode)1366 void WebPattern::OnKeyboardAvoidModeUpdate(const WebKeyboardAvoidMode& mode)
1367 {
1368     // cross platform is not support now;
1369 }
1370 
1371 
UpdateEditMenuOptions(const NG::OnCreateMenuCallback && onCreateMenuCallback,const NG::OnMenuItemClickCallback && onMenuItemClick,const NG::OnPrepareMenuCallback && onPrepareMenuCallback)1372 void WebPattern::UpdateEditMenuOptions(const NG::OnCreateMenuCallback&& onCreateMenuCallback,
1373     const NG::OnMenuItemClickCallback&& onMenuItemClick, const NG::OnPrepareMenuCallback&& onPrepareMenuCallback)
1374 {
1375     // cross platform is not support now;
1376 }
1377 
UpdateDataDetectorConfig(const TextDetectConfig & config)1378 void WebPattern::UpdateDataDetectorConfig(const TextDetectConfig& config)
1379 {
1380     // cross platform is not support now;
1381 }
1382 
OnEnabledHapticFeedbackUpdate(bool enable)1383 void WebPattern::OnEnabledHapticFeedbackUpdate(bool enable)
1384 {
1385     // cross platform is not support now;
1386 }
1387 
OnBypassVsyncConditionUpdate(WebBypassVsyncCondition condition)1388 void WebPattern::OnBypassVsyncConditionUpdate(WebBypassVsyncCondition condition)
1389 {
1390     // cross platform is not support now;
1391 }
1392 
StartVibraFeedback(const std::string & vibratorType)1393 void WebPattern::StartVibraFeedback(const std::string& vibratorType)
1394 {
1395     // cross platform is not support now;
1396 }
1397 
SetPreviewSelectionMenu(const std::shared_ptr<WebPreviewSelectionMenuParam> & param)1398 void WebPattern::SetPreviewSelectionMenu(const std::shared_ptr<WebPreviewSelectionMenuParam>& param)
1399 {
1400     // cross platform is not support now;
1401 }
1402 
GetPreviewSelectionMenuParams(const WebElementType & type,const ResponseType & responseType)1403 std::shared_ptr<WebPreviewSelectionMenuParam> WebPattern::GetPreviewSelectionMenuParams(
1404     const WebElementType& type, const ResponseType& responseType)
1405 {
1406     // cross platform is not support now;
1407     return nullptr;
1408 }
1409 
IsPreviewMenuNotNeedShowPreview()1410 bool WebPattern::IsPreviewMenuNotNeedShowPreview()
1411 {
1412     // cross platform is not support now;
1413     return false;
1414 }
1415 
NotifyStartDragTask(bool isDelayed)1416 bool WebPattern::NotifyStartDragTask(bool isDelayed)
1417 {
1418     // cross platform is not support now;
1419     return false;
1420 }
1421 
OnContextMenuShow(const std::shared_ptr<BaseEventInfo> & info,bool isRichtext,bool result)1422 void WebPattern::OnContextMenuShow(const std::shared_ptr<BaseEventInfo>& info, bool isRichtext, bool result)
1423 {
1424     // cross platform is not support now;
1425 }
1426 
RemovePreviewMenuNode()1427 void WebPattern::RemovePreviewMenuNode()
1428 {
1429     // cross platform is not support now;
1430 }
1431 
UpdateImagePreviewParam()1432 void WebPattern::UpdateImagePreviewParam()
1433 {
1434     // cross platform is not support now;
1435 }
1436 
RunJavascriptAsync(const std::string & jsCode,std::function<void (const std::string &)> && callback)1437 bool WebPattern::RunJavascriptAsync(const std::string& jsCode, std::function<void(const std::string&)>&& callback)
1438 {
1439     // cross platform is not support now;
1440     return false;
1441 }
1442 
OnOptimizeParserBudgetEnabledUpdate(bool value)1443 void WebPattern::OnOptimizeParserBudgetEnabledUpdate(bool value)
1444 {
1445     // cross platform is not support now;
1446 }
1447 
OnWebMediaAVSessionEnabledUpdate(bool value)1448 void WebPattern::OnWebMediaAVSessionEnabledUpdate(bool value)
1449 {
1450     // cross platform is not support now;
1451 }
1452 
OnEnableDataDetectorUpdate(bool enable)1453 void WebPattern::OnEnableDataDetectorUpdate(bool enable)
1454 {
1455     // cross platform is not support now;
1456 }
1457 
OnEnableFollowSystemFontWeightUpdate(bool value)1458 void WebPattern::OnEnableFollowSystemFontWeightUpdate(bool value)
1459 {
1460     // cross platform is not support now;
1461 }
1462 
SetDefaultBackgroundColor()1463 void WebPattern::SetDefaultBackgroundColor()
1464 {
1465     // cross platform is not support now;
1466 }
1467 
OnGestureFocusModeUpdate(GestureFocusMode mode)1468 void WebPattern::OnGestureFocusModeUpdate(GestureFocusMode mode)
1469 {
1470     // cross platform is not support now;
1471 }
1472 } // namespace OHOS::Ace::NG
1473