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