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 #include "frameworks/bridge/common/dom/dom_rich_text.h"
17
18 #include "core/components/declaration/richtext/rich_text_declaration.h"
19 #include "frameworks/bridge/common/dom/dom_type.h"
20 #include "frameworks/bridge/common/utils/utils.h"
21
22 namespace OHOS::Ace::Framework {
23
DOMRichText(NodeId nodeId,const std::string & nodeName)24 DOMRichText::DOMRichText(NodeId nodeId, const std::string& nodeName) : DOMNode(nodeId, nodeName)
25 {
26 childComponent_ = AceType::MakeRefPtr<WebComponent>("");
27 }
28
SetSpecializedAttr(const std::pair<std::string,std::string> & attr)29 bool DOMRichText::SetSpecializedAttr(const std::pair<std::string, std::string>& attr)
30 {
31 if (attr.first == DOM_RICH_TEXT_DATA) {
32 childComponent_->SetData(attr.second);
33 return true;
34 }
35 return false;
36 }
37
AddSpecializedEvent(int32_t pageId,const std::string & event)38 bool DOMRichText::AddSpecializedEvent(int32_t pageId, const std::string& event)
39 {
40 if (event == DOM_LOAD_START) {
41 auto eventMarker = EventMarker(GetNodeIdForEvent(), event, pageId);
42 childComponent_->SetPageStartedEventId(eventMarker);
43 } else if (event == DOM_LOAD_COMPLETE) {
44 auto eventMarker = EventMarker(GetNodeIdForEvent(), event, pageId);
45 childComponent_->SetPageFinishedEventId(eventMarker);
46 } else {
47 return false;
48 }
49 return true;
50 }
51
52 } // namespace OHOS::Ace::Framework
53