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()->UpdateClipEdge(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->GetEventHub<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->GetEventHub<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)]() {
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->GetEventHub<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->GetEventHub<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 webOffset_ = offset;
443 if (isInWindowDrag_)
444 return;
445 auto resizeOffset = Offset(offset.GetX(), offset.GetY());
446 delegate_->SetBoundsOrResize(drawSize_, resizeOffset);
447 }
448
OnWebSrcUpdate()449 void WebPattern::OnWebSrcUpdate()
450 {
451 if (delegate_ && isUrlLoaded_) {
452 delegate_->LoadUrl();
453 }
454 }
455
OnWebDataUpdate()456 void WebPattern::OnWebDataUpdate()
457 {
458 if (delegate_ && isUrlLoaded_) {
459 delegate_->LoadDataWithRichText();
460 }
461 }
462
OnJsEnabledUpdate(bool value)463 void WebPattern::OnJsEnabledUpdate(bool value)
464 {
465 if (delegate_) {
466 delegate_->UpdateJavaScriptEnabled(value);
467 }
468 }
469
OnMediaPlayGestureAccessUpdate(bool value)470 void WebPattern::OnMediaPlayGestureAccessUpdate(bool value)
471 {
472 if (delegate_) {
473 delegate_->UpdateMediaPlayGestureAccess(value);
474 }
475 }
476
OnFileAccessEnabledUpdate(bool value)477 void WebPattern::OnFileAccessEnabledUpdate(bool value)
478 {
479 if (delegate_) {
480 delegate_->UpdateAllowFileAccess(value);
481 }
482 }
483
OnOnLineImageAccessEnabledUpdate(bool value)484 void WebPattern::OnOnLineImageAccessEnabledUpdate(bool value)
485 {
486 if (delegate_) {
487 delegate_->UpdateBlockNetworkImage(!value);
488 }
489 }
490
OnDomStorageAccessEnabledUpdate(bool value)491 void WebPattern::OnDomStorageAccessEnabledUpdate(bool value)
492 {
493 if (delegate_) {
494 delegate_->UpdateDomStorageEnabled(value);
495 }
496 }
497
OnImageAccessEnabledUpdate(bool value)498 void WebPattern::OnImageAccessEnabledUpdate(bool value)
499 {
500 if (delegate_) {
501 delegate_->UpdateLoadsImagesAutomatically(value);
502 }
503 }
504
OnMixedModeUpdate(MixedModeContent value)505 void WebPattern::OnMixedModeUpdate(MixedModeContent value)
506 {
507 if (delegate_) {
508 delegate_->UpdateMixedContentMode(value);
509 }
510 }
511
OnZoomAccessEnabledUpdate(bool value)512 void WebPattern::OnZoomAccessEnabledUpdate(bool value)
513 {
514 if (delegate_) {
515 delegate_->UpdateSupportZoom(value);
516 }
517 }
518
OnGeolocationAccessEnabledUpdate(bool value)519 void WebPattern::OnGeolocationAccessEnabledUpdate(bool value)
520 {
521 if (delegate_) {
522 delegate_->UpdateGeolocationEnabled(value);
523 }
524 }
525
OnUserAgentUpdate(const std::string & value)526 void WebPattern::OnUserAgentUpdate(const std::string& value)
527 {
528 if (delegate_) {
529 delegate_->UpdateUserAgent(value);
530 }
531 }
532
OnCacheModeUpdate(WebCacheMode value)533 void WebPattern::OnCacheModeUpdate(WebCacheMode value)
534 {
535 if (delegate_) {
536 delegate_->UpdateCacheMode(value);
537 }
538 }
539
OnDarkModeUpdate(WebDarkMode mode)540 void WebPattern::OnDarkModeUpdate(WebDarkMode mode)
541 {
542 if (delegate_) {
543 delegate_->UpdateDarkMode(mode);
544 }
545 }
546
OnForceDarkAccessUpdate(bool access)547 void WebPattern::OnForceDarkAccessUpdate(bool access)
548 {
549 if (delegate_) {
550 delegate_->UpdateForceDarkAccess(access);
551 }
552 }
553
OnAudioResumeIntervalUpdate(int32_t resumeInterval)554 void WebPattern::OnAudioResumeIntervalUpdate(int32_t resumeInterval)
555 {
556 if (delegate_) {
557 delegate_->UpdateAudioResumeInterval(resumeInterval);
558 }
559 }
560
OnAudioExclusiveUpdate(bool audioExclusive)561 void WebPattern::OnAudioExclusiveUpdate(bool audioExclusive)
562 {
563 if (delegate_) {
564 delegate_->UpdateAudioExclusive(audioExclusive);
565 }
566 }
567
OnOverviewModeAccessEnabledUpdate(bool value)568 void WebPattern::OnOverviewModeAccessEnabledUpdate(bool value)
569 {
570 if (delegate_) {
571 delegate_->UpdateOverviewModeEnabled(value);
572 }
573 }
574
OnFileFromUrlAccessEnabledUpdate(bool value)575 void WebPattern::OnFileFromUrlAccessEnabledUpdate(bool value)
576 {
577 if (delegate_) {
578 delegate_->UpdateFileFromUrlEnabled(value);
579 }
580 }
581
OnDatabaseAccessEnabledUpdate(bool value)582 void WebPattern::OnDatabaseAccessEnabledUpdate(bool value)
583 {
584 if (delegate_) {
585 delegate_->UpdateDatabaseEnabled(value);
586 }
587 }
588
OnTextZoomRatioUpdate(int32_t value)589 void WebPattern::OnTextZoomRatioUpdate(int32_t value)
590 {
591 if (delegate_) {
592 delegate_->UpdateTextZoomRatio(value);
593 }
594 }
595
OnWebDebuggingAccessEnabledUpdate(bool value)596 void WebPattern::OnWebDebuggingAccessEnabledUpdate(bool value)
597 {
598 if (delegate_) {
599 delegate_->UpdateWebDebuggingAccess(value);
600 }
601 }
602
OnPinchSmoothModeEnabledUpdate(bool value)603 void WebPattern::OnPinchSmoothModeEnabledUpdate(bool value)
604 {
605 if (delegate_) {
606 delegate_->UpdatePinchSmoothModeEnabled(value);
607 }
608 }
609
OnBackgroundColorUpdate(int32_t value)610 void WebPattern::OnBackgroundColorUpdate(int32_t value)
611 {
612 UpdateBackgroundColorRightNow(value);
613 if (delegate_) {
614 delegate_->UpdateBackgroundColor(value);
615 }
616 }
617
OnInitialScaleUpdate(float value)618 void WebPattern::OnInitialScaleUpdate(float value)
619 {
620 if (delegate_) {
621 delegate_->UpdateInitialScale(value);
622 }
623 }
624
OnMultiWindowAccessEnabledUpdate(bool value)625 void WebPattern::OnMultiWindowAccessEnabledUpdate(bool value)
626 {
627 if (delegate_) {
628 delegate_->UpdateMultiWindowAccess(value);
629 }
630 }
631
OnAllowWindowOpenMethodUpdate(bool value)632 void WebPattern::OnAllowWindowOpenMethodUpdate(bool value)
633 {
634 if (delegate_) {
635 delegate_->UpdateAllowWindowOpenMethod(value);
636 }
637 }
638
OnWebCursiveFontUpdate(const std::string & value)639 void WebPattern::OnWebCursiveFontUpdate(const std::string& value)
640 {
641 if (delegate_) {
642 delegate_->UpdateWebCursiveFont(value);
643 }
644 }
645
OnWebFantasyFontUpdate(const std::string & value)646 void WebPattern::OnWebFantasyFontUpdate(const std::string& value)
647 {
648 if (delegate_) {
649 delegate_->UpdateWebFantasyFont(value);
650 }
651 }
652
OnWebFixedFontUpdate(const std::string & value)653 void WebPattern::OnWebFixedFontUpdate(const std::string& value)
654 {
655 if (delegate_) {
656 delegate_->UpdateWebFixedFont(value);
657 }
658 }
659
OnWebSansSerifFontUpdate(const std::string & value)660 void WebPattern::OnWebSansSerifFontUpdate(const std::string& value)
661 {
662 if (delegate_) {
663 delegate_->UpdateWebSansSerifFont(value);
664 }
665 }
666
OnWebSerifFontUpdate(const std::string & value)667 void WebPattern::OnWebSerifFontUpdate(const std::string& value)
668 {
669 if (delegate_) {
670 delegate_->UpdateWebSerifFont(value);
671 }
672 }
673
OnWebStandardFontUpdate(const std::string & value)674 void WebPattern::OnWebStandardFontUpdate(const std::string& value)
675 {
676 if (delegate_) {
677 delegate_->UpdateWebStandardFont(value);
678 }
679 }
680
OnDefaultFixedFontSizeUpdate(int32_t value)681 void WebPattern::OnDefaultFixedFontSizeUpdate(int32_t value)
682 {
683 if (delegate_) {
684 delegate_->UpdateDefaultFixedFontSize(value);
685 }
686 }
687
OnDefaultFontSizeUpdate(int32_t value)688 void WebPattern::OnDefaultFontSizeUpdate(int32_t value)
689 {
690 if (delegate_) {
691 delegate_->UpdateDefaultFontSize(value);
692 }
693 }
694
OnMinFontSizeUpdate(int32_t value)695 void WebPattern::OnMinFontSizeUpdate(int32_t value)
696 {
697 if (delegate_) {
698 delegate_->UpdateMinFontSize(value);
699 }
700 }
701
OnMinLogicalFontSizeUpdate(int32_t value)702 void WebPattern::OnMinLogicalFontSizeUpdate(int32_t value)
703 {
704 if (delegate_) {
705 delegate_->UpdateMinLogicalFontSize(value);
706 }
707 }
708
OnBlockNetworkUpdate(bool value)709 void WebPattern::OnBlockNetworkUpdate(bool value)
710 {
711 if (delegate_) {
712 delegate_->UpdateBlockNetwork(value);
713 }
714 }
715
OnHorizontalScrollBarAccessEnabledUpdate(bool value)716 void WebPattern::OnHorizontalScrollBarAccessEnabledUpdate(bool value)
717 {
718 if (delegate_) {
719 delegate_->UpdateHorizontalScrollBarAccess(value);
720 }
721 }
722
OnVerticalScrollBarAccessEnabledUpdate(bool value)723 void WebPattern::OnVerticalScrollBarAccessEnabledUpdate(bool value)
724 {
725 if (delegate_) {
726 delegate_->UpdateVerticalScrollBarAccess(value);
727 }
728 }
729
SetUpdateInstanceIdCallback(std::function<void (int32_t)> && callback)730 void WebPattern::SetUpdateInstanceIdCallback(std::function<void(int32_t)>&& callback)
731 {
732 updateInstanceIdCallback_ = callback;
733 }
734
OnScrollBarColorUpdate(const std::string & value)735 void WebPattern::OnScrollBarColorUpdate(const std::string& value)
736 {
737 if (delegate_) {
738 delegate_->UpdateScrollBarColor(value);
739 }
740 }
741
RegistVirtualKeyBoardListener()742 void WebPattern::RegistVirtualKeyBoardListener()
743 {
744 if (!needUpdateWeb_) {
745 return;
746 }
747 auto pipelineContext = PipelineContext::GetCurrentContext();
748 CHECK_NULL_VOID(pipelineContext);
749 pipelineContext->SetVirtualKeyBoardCallback(
750 [weak = AceType::WeakClaim(this)](int32_t width, int32_t height, double keyboard) {
751 auto webPattern = weak.Upgrade();
752 CHECK_NULL_RETURN(webPattern, false);
753 return webPattern->ProcessVirtualKeyBoard(width, height, keyboard);
754 });
755 needUpdateWeb_ = false;
756 }
757
InitEnhanceSurfaceFlag()758 void WebPattern::InitEnhanceSurfaceFlag()
759 {
760 if (SystemProperties::GetExtSurfaceEnabled()) {
761 isEnhanceSurface_ = true;
762 } else {
763 isEnhanceSurface_ = false;
764 }
765 }
766
OnModifyDone()767 void WebPattern::OnModifyDone()
768 {
769 Pattern::OnModifyDone();
770 // called in each update function.
771 auto host = GetHost();
772 CHECK_NULL_VOID(host);
773 auto renderContext = host->GetRenderContext();
774 CHECK_NULL_VOID(renderContext);
775
776 #if !defined(IOS_PLATFORM) && !defined(ANDROID_PLATFORM)
777 RegistVirtualKeyBoardListener();
778 #endif
779 if (!delegate_) {
780 // first create case,
781 #if defined(IOS_PLATFORM) || defined(ANDROID_PLATFORM)
782 WeakPtr<PipelineContext> context = WeakPtr<PipelineContext>(PipelineContext::GetCurrentContext());
783 delegate_ = AceType::MakeRefPtr<WebDelegateCross>(PipelineContext::GetCurrentContext(), nullptr, "web");
784 delegate_->SetNGWebPattern(Claim(this));
785 delegate_->CreatePlatformResource(Size(0, 0), Offset(0, 0), context);
786 if (setWebIdCallback_) {
787 setWebIdCallback_(delegate_->GetWebId());
788 }
789 auto container = Container::Current();
790 CHECK_NULL_VOID(container);
791 if (setHapPathCallback_) {
792 setHapPathCallback_(container->GetHapPath());
793 }
794 if (onControllerAttachedCallback_) {
795 onControllerAttachedCallback_();
796 }
797
798 #else
799 delegate_ = AceType::MakeRefPtr<WebDelegate>(PipelineContext::GetCurrentContext(), nullptr, "");
800 CHECK_NULL_VOID(delegate_);
801 observer_ = AceType::MakeRefPtr<WebDelegateObserver>(delegate_, PipelineContext::GetCurrentContext());
802 CHECK_NULL_VOID(observer_);
803 delegate_->SetObserver(observer_);
804 delegate_->SetRenderMode(renderMode_);
805 InitEnhanceSurfaceFlag();
806 delegate_->SetNGWebPattern(Claim(this));
807 delegate_->SetEnhanceSurfaceFlag(isEnhanceSurface_);
808 delegate_->SetPopup(isPopup_);
809 delegate_->SetParentNWebId(parentNWebId_);
810 delegate_->SetBackgroundColor(GetBackgroundColorValue(
811 static_cast<int32_t>(renderContext->GetBackgroundColor().value_or(Color::WHITE).GetValue())));
812 if (isEnhanceSurface_) {
813 auto drawSize = Size(1, 1);
814 delegate_->SetDrawSize(drawSize);
815 delegate_->InitOHOSWeb(PipelineContext::GetCurrentContext());
816 } else {
817 auto drawSize = Size(1, 1);
818 delegate_->SetDrawSize(drawSize);
819 renderSurface_->SetRenderContext(host->GetRenderContext());
820 if (renderMode_ == RenderMode::SYNC_RENDER) {
821 renderSurface_->SetIsTexture(true);
822 renderSurface_->SetPatternType(PATTERN_TYPE_WEB);
823 renderSurface_->SetSurfaceQueueSize(SYNC_SURFACE_QUEUE_SIZE);
824 } else {
825 renderSurface_->SetIsTexture(false);
826 renderSurface_->SetSurfaceQueueSize(ASYNC_SURFACE_QUEUE_SIZE);
827 }
828 renderSurface_->InitSurface();
829 renderSurface_->UpdateSurfaceConfig();
830 delegate_->InitOHOSWeb(PipelineContext::GetCurrentContext(), renderSurface_);
831 }
832 #endif
833 delegate_->UpdateBackgroundColor(GetBackgroundColorValue(
834 static_cast<int32_t>(renderContext->GetBackgroundColor().value_or(Color::WHITE).GetValue())));
835 delegate_->UpdateJavaScriptEnabled(GetJsEnabledValue(true));
836 delegate_->UpdateBlockNetworkImage(!GetOnLineImageAccessEnabledValue(true));
837 delegate_->UpdateAllowFileAccess(GetFileAccessEnabledValue(true));
838 delegate_->UpdateLoadsImagesAutomatically(GetImageAccessEnabledValue(true));
839 delegate_->UpdateMixedContentMode(GetMixedModeValue(MixedModeContent::MIXED_CONTENT_NEVER_ALLOW));
840 delegate_->UpdateSupportZoom(GetZoomAccessEnabledValue(true));
841 delegate_->UpdateDomStorageEnabled(GetDomStorageAccessEnabledValue(false));
842 delegate_->UpdateGeolocationEnabled(GetGeolocationAccessEnabledValue(true));
843 delegate_->UpdateCacheMode(GetCacheModeValue(WebCacheMode::DEFAULT));
844 delegate_->UpdateDarkMode(GetDarkModeValue(WebDarkMode::Off));
845 delegate_->UpdateForceDarkAccess(GetForceDarkAccessValue(false));
846 delegate_->UpdateAudioResumeInterval(GetAudioResumeIntervalValue(-1));
847 delegate_->UpdateAudioExclusive(GetAudioExclusiveValue(true));
848 delegate_->UpdateOverviewModeEnabled(GetOverviewModeAccessEnabledValue(true));
849 delegate_->UpdateFileFromUrlEnabled(GetFileFromUrlAccessEnabledValue(false));
850 delegate_->UpdateDatabaseEnabled(GetDatabaseAccessEnabledValue(false));
851 delegate_->UpdateTextZoomRatio(GetTextZoomRatioValue(DEFAULT_TEXT_ZOOM_RATIO));
852 delegate_->UpdateWebDebuggingAccess(GetWebDebuggingAccessEnabledValue(false));
853 delegate_->UpdateMediaPlayGestureAccess(GetMediaPlayGestureAccessValue(true));
854 delegate_->UpdatePinchSmoothModeEnabled(GetPinchSmoothModeEnabledValue(false));
855 delegate_->UpdateMultiWindowAccess(GetMultiWindowAccessEnabledValue(false));
856 delegate_->UpdateWebCursiveFont(GetWebCursiveFontValue(DEFAULT_CURSIVE_FONT_FAMILY));
857 delegate_->UpdateWebFantasyFont(GetWebFantasyFontValue(DEFAULT_FANTASY_FONT_FAMILY));
858 delegate_->UpdateWebFixedFont(GetWebFixedFontValue(DEFAULT_FIXED_fONT_FAMILY));
859 delegate_->UpdateWebSansSerifFont(GetWebSansSerifFontValue(DEFAULT_SANS_SERIF_FONT_FAMILY));
860 delegate_->UpdateWebSerifFont(GetWebSerifFontValue(DEFAULT_SERIF_FONT_FAMILY));
861 delegate_->UpdateWebStandardFont(GetWebStandardFontValue(DEFAULT_STANDARD_FONT_FAMILY));
862 delegate_->UpdateDefaultFixedFontSize(GetDefaultFixedFontSizeValue(DEFAULT_FIXED_FONT_SIZE));
863 delegate_->UpdateDefaultFontSize(GetDefaultFontSizeValue(DEFAULT_FONT_SIZE));
864 delegate_->UpdateMinFontSize(GetMinFontSizeValue(DEFAULT_MINIMUM_FONT_SIZE));
865 delegate_->UpdateMinLogicalFontSize(GetMinLogicalFontSizeValue(DEFAULT_MINIMUM_LOGICAL_FONT_SIZE));
866 delegate_->UpdateHorizontalScrollBarAccess(GetHorizontalScrollBarAccessEnabledValue(true));
867 delegate_->UpdateVerticalScrollBarAccess(GetVerticalScrollBarAccessEnabledValue(true));
868 delegate_->UpdateScrollBarColor(GetScrollBarColorValue(DEFAULT_SCROLLBAR_COLOR));
869 if (GetBlockNetwork()) {
870 delegate_->UpdateBlockNetwork(GetBlockNetwork().value());
871 }
872 if (GetUserAgent()) {
873 delegate_->UpdateUserAgent(GetUserAgent().value());
874 }
875 if (GetInitialScale()) {
876 delegate_->UpdateInitialScale(GetInitialScale().value());
877 }
878 }
879
880 // Initialize events such as keyboard, focus, etc.
881 InitEvent();
882
883 // Initialize scrollupdate listener
884 if (renderMode_ == RenderMode::SYNC_RENDER) {
885 auto task = [this]() {
886 InitSlideUpdateListener();
887 };
888 PostTaskToUI(std::move(task));
889 }
890 auto pipelineContext = PipelineContext::GetCurrentContext();
891 CHECK_NULL_VOID(pipelineContext);
892 pipelineContext->AddOnAreaChangeNode(host->GetId());
893 }
894
ProcessVirtualKeyBoard(int32_t width,int32_t height,double keyboard)895 bool WebPattern::ProcessVirtualKeyBoard(int32_t width, int32_t height, double keyboard)
896 {
897 CHECK_NULL_RETURN(delegate_, false);
898 if (!isFocus_) {
899 if (isVirtualKeyBoardShow_ == VkState::VK_SHOW) {
900 drawSize_.SetSize(drawSizeCache_);
901 UpdateWebLayoutSize(width, height);
902 isVirtualKeyBoardShow_ = VkState::VK_HIDE;
903 }
904 return false;
905 }
906 if (NearZero(keyboard)) {
907 drawSize_.SetSize(drawSizeCache_);
908 UpdateWebLayoutSize(width, height);
909 isVirtualKeyBoardShow_ = VkState::VK_HIDE;
910 } else if (isVirtualKeyBoardShow_ != VkState::VK_SHOW) {
911 drawSizeCache_.SetSize(drawSize_);
912 if (drawSize_.Height() <= (height - keyboard - GetCoordinatePoint()->GetY())) {
913 isVirtualKeyBoardShow_ = VkState::VK_SHOW;
914 return true;
915 }
916 if (height - GetCoordinatePoint()->GetY() < keyboard) {
917 return true;
918 }
919 drawSize_.SetHeight(height - keyboard - GetCoordinatePoint()->GetY());
920 UpdateWebLayoutSize(width, height);
921 isVirtualKeyBoardShow_ = VkState::VK_SHOW;
922 }
923 return true;
924 }
925
UpdateWebLayoutSize(int32_t width,int32_t height)926 void WebPattern::UpdateWebLayoutSize(int32_t width, int32_t height)
927 {
928 auto frameNode = GetHost();
929 CHECK_NULL_VOID(frameNode);
930 auto rect = frameNode->GetGeometryNode()->GetFrameRect();
931 auto offset = Offset(GetCoordinatePoint()->GetX(), GetCoordinatePoint()->GetY());
932 delegate_->SetBoundsOrResize(drawSize_, offset);
933 rect.SetSize(SizeF(drawSize_.Width(), drawSize_.Height()));
934 frameNode->GetRenderContext()->SyncGeometryProperties(rect);
935 frameNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE_SELF);
936 auto context = PipelineContext::GetCurrentContext();
937 CHECK_NULL_VOID(context);
938 context->SetRootRect(width, height, 0);
939 }
940
HandleTouchDown(const TouchEventInfo & info,bool fromOverlay)941 void WebPattern::HandleTouchDown(const TouchEventInfo& info, bool fromOverlay)
942 {
943 CHECK_NULL_VOID(delegate_);
944 Offset touchOffset = Offset(0, 0);
945 std::list<TouchInfo> touchInfos;
946 if (!ParseTouchInfo(info, touchInfos)) {
947 return;
948 }
949 for (auto& touchPoint : touchInfos) {
950 if (fromOverlay) {
951 touchPoint.x -= webOffset_.GetX();
952 touchPoint.y -= webOffset_.GetY();
953 }
954 delegate_->HandleTouchDown(touchPoint.id, touchPoint.x, touchPoint.y, fromOverlay);
955 }
956 }
957
HandleTouchUp(const TouchEventInfo & info,bool fromOverlay)958 void WebPattern::HandleTouchUp(const TouchEventInfo& info, bool fromOverlay)
959 {
960 CHECK_NULL_VOID(delegate_);
961 std::list<TouchInfo> touchInfos;
962 if (!ParseTouchInfo(info, touchInfos)) {
963 return;
964 }
965 for (auto& touchPoint : touchInfos) {
966 if (fromOverlay) {
967 touchPoint.x -= webOffset_.GetX();
968 touchPoint.y -= webOffset_.GetY();
969 }
970 delegate_->HandleTouchUp(touchPoint.id, touchPoint.x, touchPoint.y, fromOverlay);
971 }
972 if (!touchInfos.empty()) {
973 WebRequestFocus();
974 }
975 }
976
HandleTouchMove(const TouchEventInfo & info,bool fromOverlay)977 void WebPattern::HandleTouchMove(const TouchEventInfo& info, bool fromOverlay)
978 {
979 if (isDragging_) {
980 return;
981 }
982 auto pipeline = PipelineContext::GetCurrentContext();
983 CHECK_NULL_VOID(pipeline);
984 auto manager = pipeline->GetDragDropManager();
985 CHECK_NULL_VOID(manager);
986 if (manager->IsDragged()) {
987 return;
988 }
989 CHECK_NULL_VOID(delegate_);
990 std::list<TouchInfo> touchInfos;
991 if (!ParseTouchInfo(info, touchInfos)) {
992 return;
993 }
994 for (auto& touchPoint : touchInfos) {
995 if (fromOverlay) {
996 touchPoint.x -= webOffset_.GetX();
997 touchPoint.y -= webOffset_.GetY();
998 }
999 delegate_->HandleTouchMove(touchPoint.id, touchPoint.x, touchPoint.y, fromOverlay);
1000 }
1001 }
1002
HandleTouchCancel(const TouchEventInfo & info)1003 void WebPattern::HandleTouchCancel(const TouchEventInfo& info)
1004 {
1005 CHECK_NULL_VOID(delegate_);
1006 delegate_->HandleTouchCancel();
1007 }
1008
ParseTouchInfo(const TouchEventInfo & info,std::list<TouchInfo> & touchInfos)1009 bool WebPattern::ParseTouchInfo(const TouchEventInfo& info, std::list<TouchInfo>& touchInfos)
1010 {
1011 auto context = PipelineContext::GetCurrentContext();
1012 CHECK_NULL_RETURN(context, false);
1013 auto viewScale = context->GetViewScale();
1014 if (info.GetChangedTouches().empty()) {
1015 return false;
1016 }
1017 for (const auto& point : info.GetChangedTouches()) {
1018 TouchInfo touchInfo;
1019 touchInfo.id = point.GetFingerId();
1020 const Offset& location = point.GetLocalLocation();
1021 touchInfo.x = static_cast<float>(location.GetX() * viewScale);
1022 touchInfo.y = static_cast<float>(location.GetY() * viewScale);
1023 touchInfos.emplace_back(touchInfo);
1024 }
1025 return true;
1026 }
1027
RequestFullScreen()1028 void WebPattern::RequestFullScreen()
1029 {
1030 isFullScreen_ = true;
1031 }
1032
ExitFullScreen()1033 void WebPattern::ExitFullScreen()
1034 {
1035 isFullScreen_ = false;
1036 }
1037
GetCoordinatePoint()1038 std::optional<OffsetF> WebPattern::GetCoordinatePoint()
1039 {
1040 auto frameNode = GetHost();
1041 CHECK_NULL_RETURN(frameNode, std::nullopt);
1042 return frameNode->GetTransformRelativeOffset();
1043 }
1044
UpdateLocale()1045 void WebPattern::UpdateLocale()
1046 {
1047 CHECK_NULL_VOID(delegate_);
1048 delegate_->UpdateLocale();
1049 }
1050
OnWindowShow()1051 void WebPattern::OnWindowShow()
1052 {
1053 if (isWindowShow_ || !isVisible_) {
1054 return;
1055 }
1056
1057 CHECK_NULL_VOID(delegate_);
1058 delegate_->ShowWebView();
1059 isWindowShow_ = true;
1060 }
1061
OnWindowHide()1062 void WebPattern::OnWindowHide()
1063 {
1064 if (!isWindowShow_ || !isVisible_) {
1065 return;
1066 }
1067
1068 CHECK_NULL_VOID(delegate_);
1069 delegate_->HideWebView();
1070 needOnFocus_ = false;
1071 isWindowShow_ = false;
1072 }
1073
OnWindowSizeChanged(int32_t width,int32_t height,WindowSizeChangeReason type)1074 void WebPattern::OnWindowSizeChanged(int32_t width, int32_t height, WindowSizeChangeReason type) {}
1075
OnCompleteSwapWithNewSize()1076 void WebPattern::OnCompleteSwapWithNewSize()
1077 {
1078 if (!isInWindowDrag_ || !isWaiting_)
1079 return;
1080
1081 ACE_SCOPED_TRACE("WebPattern::OnCompleteSwapWithNewSize");
1082 isWaiting_ = false;
1083 }
1084
OnResizeNotWork()1085 void WebPattern::OnResizeNotWork()
1086 {
1087 if (!isInWindowDrag_ || !isWaiting_)
1088 return;
1089
1090 ACE_SCOPED_TRACE("WebPattern::OnResizeNotWork");
1091 isWaiting_ = false;
1092 }
1093
OnBackPressed() const1094 bool WebPattern::OnBackPressed() const
1095 {
1096 if (!isFullScreen_) {
1097 return false;
1098 }
1099
1100 CHECK_NULL_RETURN(fullScreenExitHandler_, false);
1101 auto webFullScreenExitHandler = fullScreenExitHandler_->GetHandler();
1102 CHECK_NULL_RETURN(webFullScreenExitHandler, false);
1103 webFullScreenExitHandler->ExitFullScreen();
1104 return true;
1105 }
1106
OnBackPressedForFullScreen() const1107 bool WebPattern::OnBackPressedForFullScreen() const
1108 {
1109 if (!isFullScreen_) {
1110 return false;
1111 }
1112
1113 CHECK_NULL_RETURN(fullScreenExitHandler_, false);
1114 auto webFullScreenExitHandler = fullScreenExitHandler_->GetHandler();
1115 CHECK_NULL_RETURN(webFullScreenExitHandler, false);
1116 webFullScreenExitHandler->ExitFullScreen();
1117 return true;
1118 }
1119
SetFullScreenExitHandler(const std::shared_ptr<FullScreenEnterEvent> & fullScreenExitHandler)1120 void WebPattern::SetFullScreenExitHandler(const std::shared_ptr<FullScreenEnterEvent>& fullScreenExitHandler)
1121 {
1122 fullScreenExitHandler_ = fullScreenExitHandler;
1123 }
1124
OnInActive()1125 void WebPattern::OnInActive()
1126 {
1127 if (!isActive_) {
1128 return;
1129 }
1130
1131 CHECK_NULL_VOID(delegate_);
1132 delegate_->OnInactive();
1133 isActive_ = false;
1134 }
1135
OnActive()1136 void WebPattern::OnActive()
1137 {
1138 if (isActive_) {
1139 return;
1140 }
1141
1142 CHECK_NULL_VOID(delegate_);
1143 delegate_->OnActive();
1144 isActive_ = true;
1145 }
1146
OnVisibleChange(bool isVisible)1147 void WebPattern::OnVisibleChange(bool isVisible)
1148 {
1149 if (isVisible_ == isVisible) {
1150 return;
1151 }
1152
1153 isVisible_ = isVisible;
1154 if (!isVisible_) {
1155 if (isVisibleActiveEnable_) {
1156 OnInActive();
1157 }
1158 } else {
1159 if (isVisibleActiveEnable_) {
1160 OnActive();
1161 }
1162 }
1163 }
1164
GetDefaultBackgroundColor()1165 Color WebPattern::GetDefaultBackgroundColor()
1166 {
1167 return Color::WHITE;
1168 }
1169
UpdateBackgroundColorRightNow(int32_t color)1170 void WebPattern::UpdateBackgroundColorRightNow(int32_t color)
1171 {
1172 auto host = GetHost();
1173 CHECK_NULL_VOID(host);
1174 auto renderContext = host->GetRenderContext();
1175 CHECK_NULL_VOID(renderContext);
1176 renderContext->UpdateBackgroundColor(Color(static_cast<uint32_t>(color)));
1177 }
1178
OnSmoothDragResizeEnabledUpdate(bool value)1179 void WebPattern::OnSmoothDragResizeEnabledUpdate(bool value)
1180 {
1181 // cross platform is not support now;
1182 }
1183
OnRootLayerChanged(int width,int height)1184 void WebPattern::OnRootLayerChanged(int width, int height)
1185 {
1186 // cross platform is not support now;
1187 }
1188
SetNestedScroll(const NestedScrollOptions & nestedOpt)1189 void WebPattern::SetNestedScroll(const NestedScrollOptions& nestedOpt)
1190 {
1191 // cross platform is not support now;
1192 }
1193
SetNestedScrollExt(const NestedScrollOptionsExt & nestedOpt)1194 void WebPattern::SetNestedScrollExt(const NestedScrollOptionsExt& nestedOpt)
1195 {
1196 // cross platform is not support now;
1197 }
1198
JavaScriptOnDocumentStart(const ScriptItems & scriptItems)1199 void WebPattern::JavaScriptOnDocumentStart(const ScriptItems& scriptItems)
1200 {
1201 // cross platform is not support now;
1202 }
1203
UpdateJavaScriptOnDocumentStart()1204 void WebPattern::UpdateJavaScriptOnDocumentStart()
1205 {
1206 // cross platform is not support now;
1207 }
1208
JavaScriptOnDocumentEnd(const ScriptItems & scriptItems)1209 void WebPattern::JavaScriptOnDocumentEnd(const ScriptItems& scriptItems)
1210 {
1211 // cross platform is not support now;
1212 }
1213
OnOverScrollModeUpdate(int mode)1214 void WebPattern::OnOverScrollModeUpdate(int mode)
1215 {
1216 // cross platform is not support now;
1217 }
1218
OnBlurOnKeyboardHideModeUpdate(int mode)1219 void WebPattern::OnBlurOnKeyboardHideModeUpdate(int mode)
1220 {
1221 // cross platform is not support now;
1222 }
1223
OnCopyOptionModeUpdate(int32_t mode)1224 void WebPattern::OnCopyOptionModeUpdate(int32_t mode)
1225 {
1226 // cross platform is not support now;
1227 }
1228
OnTextAutosizingUpdate(bool isTextAutosizing)1229 void WebPattern::OnTextAutosizingUpdate(bool isTextAutosizing)
1230 {
1231 // cross platform is not support now;
1232 }
1233
UpdateRelativeOffset()1234 void WebPattern::UpdateRelativeOffset()
1235 {
1236 // cross platform is not support now;
1237 }
1238
InitSlideUpdateListener()1239 void WebPattern::InitSlideUpdateListener()
1240 {
1241 // cross platform is not support now;
1242 }
1243
UpdateSlideOffset(bool isNeedReset)1244 void WebPattern::UpdateSlideOffset(bool isNeedReset)
1245 {
1246 // cross platform is not support now;
1247 }
1248
Backward()1249 bool WebPattern::Backward()
1250 {
1251 return false;
1252 }
1253
CalculateHorizontalDrawRect()1254 void WebPattern::CalculateHorizontalDrawRect()
1255 {
1256 // cross platform is not support now;
1257 }
1258
CalculateVerticalDrawRect()1259 void WebPattern::CalculateVerticalDrawRect()
1260 {
1261 // cross platform is not support now;
1262 }
1263
PostTaskToUI(const std::function<void ()> && task) const1264 void WebPattern::PostTaskToUI(const std::function<void()>&& task) const
1265 {
1266 // cross platform is not support now;
1267 }
1268
SetDrawRect(int32_t x,int32_t y,int32_t width,int32_t height)1269 void WebPattern::SetDrawRect(int32_t x, int32_t y, int32_t width, int32_t height)
1270 {
1271 // cross platform is not support now;
1272 }
1273
CreateNodePaintMethod()1274 RefPtr<NodePaintMethod> WebPattern::CreateNodePaintMethod()
1275 {
1276 // cross platform is not support now;
1277 return nullptr;
1278 }
1279
OnDefaultTextEncodingFormatUpdate(const std::string & value)1280 void WebPattern::OnDefaultTextEncodingFormatUpdate(const std::string& value)
1281 {
1282 // cross platform is not support now;
1283 }
1284
OnSelectionMenuOptionsUpdate(const WebMenuOptionsParam & webMenuOption)1285 void WebPattern::OnSelectionMenuOptionsUpdate(const WebMenuOptionsParam& webMenuOption)
1286 {
1287 // cross platform is not support now;
1288 }
1289
OnNativeVideoPlayerConfigUpdate(const std::tuple<bool,bool> & config)1290 void WebPattern::OnNativeVideoPlayerConfigUpdate(const std::tuple<bool, bool>& config)
1291 {
1292 // cross platform is not support now;
1293 }
1294
OnOverlayScrollbarEnabledUpdate(bool value)1295 void WebPattern::OnOverlayScrollbarEnabledUpdate(bool value)
1296 {
1297 // cross platform is not support now;
1298 }
1299
OnNativeEmbedRuleTagUpdate(const std::string & tag)1300 void WebPattern::OnNativeEmbedRuleTagUpdate(const std::string& tag)
1301 {
1302 // cross platform is not support now;
1303 }
1304
OnNativeEmbedRuleTypeUpdate(const std::string & type)1305 void WebPattern::OnNativeEmbedRuleTypeUpdate(const std::string& type)
1306 {
1307 // cross platform is not support now;
1308 }
1309
OnMetaViewportUpdate(bool value)1310 void WebPattern::OnMetaViewportUpdate(bool value)
1311 {
1312 // cross platform is not support now;
1313 }
1314
OnKeyboardAvoidModeUpdate(const WebKeyboardAvoidMode & mode)1315 void WebPattern::OnKeyboardAvoidModeUpdate(const WebKeyboardAvoidMode& mode)
1316 {
1317 // cross platform is not support now;
1318 }
1319
1320
UpdateEditMenuOptions(const NG::OnCreateMenuCallback && onCreateMenuCallback,const NG::OnMenuItemClickCallback && onMenuItemClick)1321 void WebPattern::UpdateEditMenuOptions(const NG::OnCreateMenuCallback&& onCreateMenuCallback,
1322 const NG::OnMenuItemClickCallback&& onMenuItemClick)
1323 {
1324 // cross platform is not support now;
1325 }
1326
OnEnabledHapticFeedbackUpdate(bool enable)1327 void WebPattern::OnEnabledHapticFeedbackUpdate(bool enable)
1328 {
1329 // cross platform is not support now;
1330 }
1331
StartVibraFeedback(const std::string & vibratorType)1332 void WebPattern::StartVibraFeedback(const std::string& vibratorType)
1333 {
1334 // cross platform is not support now;
1335 }
1336
SetPreviewSelectionMenu(const std::shared_ptr<WebPreviewSelectionMenuParam> & param)1337 void WebPattern::SetPreviewSelectionMenu(const std::shared_ptr<WebPreviewSelectionMenuParam>& param)
1338 {
1339 // cross platform is not support now;
1340 }
1341
GetPreviewSelectionMenuParams(const WebElementType & type,const ResponseType & responseType)1342 std::shared_ptr<WebPreviewSelectionMenuParam> WebPattern::GetPreviewSelectionMenuParams(
1343 const WebElementType& type, const ResponseType& responseType)
1344 {
1345 // cross platform is not support now;
1346 return nullptr;
1347 }
1348
IsPreviewMenuNotNeedShowPreview()1349 bool WebPattern::IsPreviewMenuNotNeedShowPreview()
1350 {
1351 // cross platform is not support now;
1352 return false;
1353 }
1354
NotifyStartDragTask(bool isDelayed)1355 bool WebPattern::NotifyStartDragTask(bool isDelayed)
1356 {
1357 // cross platform is not support now;
1358 return false;
1359 }
1360
OnContextMenuShow(const std::shared_ptr<BaseEventInfo> & info,bool isRichtext,bool result)1361 void WebPattern::OnContextMenuShow(const std::shared_ptr<BaseEventInfo>& info, bool isRichtext, bool result)
1362 {
1363 // cross platform is not support now;
1364 }
1365
RemovePreviewMenuNode()1366 void WebPattern::RemovePreviewMenuNode()
1367 {
1368 // cross platform is not support now;
1369 }
1370
UpdateImagePreviewParam()1371 void WebPattern::UpdateImagePreviewParam()
1372 {
1373 // cross platform is not support now;
1374 }
1375 } // namespace OHOS::Ace::NG
1376