• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_WEB_RENDER_WEB_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_WEB_RENDER_WEB_H
18 
19 #include "core/components/common/layout/constants.h"
20 #include "core/components/web/resource/web_delegate.h"
21 #include "core/components/web/web_component.h"
22 #include "core/gestures/raw_recognizer.h"
23 #include "core/pipeline/base/render_node.h"
24 
25 namespace OHOS::Ace {
26 
27 namespace {
28 #ifdef OHOS_STANDARD_SYSTEM
29 struct TouchInfo {
30     double x = -1;
31     double y = -1;
32     int32_t id = -1;
33 };
34 #endif
35 }
36 
37 class RenderWeb : public RenderNode {
38     DECLARE_ACE_TYPE(RenderWeb, RenderNode);
39 
40 public:
41     static RefPtr<RenderNode> Create();
42 
43     RenderWeb();
44     ~RenderWeb() override = default;
45 
46     void Update(const RefPtr<Component>& component) override;
47     void PerformLayout() override;
48     void OnAttachContext() override;
49 
50 #ifdef OHOS_STANDARD_SYSTEM
OnAppShow()51     void OnAppShow() override
52     {
53         RenderNode::OnAppShow();
54         if (delegate_) {
55             delegate_->ShowWebView();
56         }
57     }
58 
OnAppHide()59     void OnAppHide() override
60     {
61         RenderNode::OnAppHide();
62         if (delegate_) {
63             delegate_->HideWebView();
64         }
65     }
66 #endif
67 
SetDelegate(const RefPtr<WebDelegate> & delegate)68     void SetDelegate(const RefPtr<WebDelegate>& delegate)
69     {
70         delegate_ = delegate;
71     }
72 
73 protected:
74     RefPtr<WebDelegate> delegate_;
75     RefPtr<WebComponent> web_;
76     Size drawSize_;
77     bool isUrlLoaded_ = false;
78 
79 private:
80 #ifdef OHOS_STANDARD_SYSTEM
81     void Initialize();
82     void HandleTouchDown(const TouchEventInfo& info);
83     void HandleTouchUp(const TouchEventInfo& info);
84     void HandleTouchMove(const TouchEventInfo& info);
85     void HandleTouchCancel(const TouchEventInfo& info);
86     bool ParseTouchInfo(const TouchEventInfo& info, std::list<TouchInfo>& touchInfos, const TouchType& touchType);
87     void OnTouchTestHit(const Offset& coordinateOffset, const TouchRestrict& touchRestrict,
88         TouchTestResult& result) override;
89     RefPtr<RawRecognizer> touchRecognizer_ = nullptr;
90 #endif
91 
92     Offset position_;
93 };
94 
95 } // namespace OHOS::Ace
96 
97 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_WEB_RENDER_WEB_H
98