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 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_BASE_CUSTOM_TITLE_NODE_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_BASE_CUSTOM_TITLE_NODE_H 18 19 #include "core/components_ng/pattern/custom/custom_node.h" 20 21 namespace OHOS::Ace::NG { 22 class ACE_EXPORT CustomTitleNode : public CustomNode { 23 DECLARE_ACE_TYPE(CustomTitleNode, CustomNode); 24 25 public: 26 static RefPtr<CustomTitleNode> CreateCustomTitleNode(int32_t nodeId, const std::string& viewKey); 27 28 CustomTitleNode(int32_t nodeId, const std::string& viewKey); 29 ~CustomTitleNode() override = default; 30 SetAppTitleCallback(const std::function<void (const std::string &)> & callback)31 void SetAppTitleCallback(const std::function<void(const std::string&)>& callback) 32 { 33 appTitleCallback_ = callback; 34 } 35 FireAppTitleCallback(const std::string & title)36 void FireAppTitleCallback(const std::string& title) 37 { 38 if (appTitleCallback_) { 39 appTitleCallback_(title); 40 } 41 } 42 SetAppIconCallback(const std::function<void (const RefPtr<PixelMap> &)> & callback)43 void SetAppIconCallback(const std::function<void(const RefPtr<PixelMap>&)>& callback) 44 { 45 appIconCallback_ = callback; 46 } 47 FireAppIconCallback(const RefPtr<PixelMap> & icon)48 void FireAppIconCallback(const RefPtr<PixelMap>& icon) 49 { 50 if (appIconCallback_) { 51 appIconCallback_(icon); 52 } 53 } 54 SetOnWindowFocusedCallback(const std::function<void ()> & callback)55 void SetOnWindowFocusedCallback(const std::function<void()>& callback) 56 { 57 onWindowFocusedCallback_ = callback; 58 } 59 FireOnWindowFocusedCallback()60 void FireOnWindowFocusedCallback() 61 { 62 if (onWindowFocusedCallback_) { 63 onWindowFocusedCallback_(); 64 } 65 } 66 SetOnWindowUnfocusedCallback(const std::function<void ()> & callback)67 void SetOnWindowUnfocusedCallback(const std::function<void()>& callback) 68 { 69 onWindowUnfocusedCallback_ = callback; 70 } 71 FireOnWindowUnfocusedCallback()72 void FireOnWindowUnfocusedCallback() 73 { 74 if (onWindowUnfocusedCallback_) { 75 onWindowUnfocusedCallback_(); 76 } 77 } 78 79 private: 80 std::function<void(const std::string&)> appTitleCallback_ = nullptr; 81 std::function<void(const RefPtr<PixelMap>&)> appIconCallback_ = nullptr; 82 std::function<void()> onWindowFocusedCallback_ = nullptr; 83 std::function<void()> onWindowUnfocusedCallback_ = nullptr; 84 }; 85 } // namespace OHOS::Ace::NG 86 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_BASE_CUSTOM_NODE_H