xref: /base/update/updater/services/ui/view/page/page.h (revision fb299fa2)
1/*
2 * Copyright (c) 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 PAGE_H
17#define PAGE_H
18
19#include <string>
20#include <unordered_set>
21#include <vector>
22#include "components/ui_view_group.h"
23#include "view_api.h"
24#include "view_proxy.h"
25
26namespace Updater {
27class Page {
28    DISALLOW_COPY_MOVE(Page);
29public:
30    virtual ~Page() = default;
31    virtual std::string GetPageId() = 0;
32    virtual void SetVisible(bool isVisible) = 0;
33    [[nodiscard]] virtual bool IsVisible() const = 0;
34    [[nodiscard]] virtual OHOS::UIViewGroup *GetView() const = 0;
35    [[nodiscard]] virtual bool IsValid() const = 0;
36    [[nodiscard]] virtual bool IsValidCom(const std::string &id) const = 0;
37    virtual ViewProxy &operator[](const std::string &id) = 0;
38    void UpdateFocus(bool isVisible);
39    template<typename T, typename ... Args>
40    static std::shared_ptr<T> Create(Args && ... args)
41    {
42        static_assert(std::is_base_of_v<Page, T>, "T should be derived class of Page");
43        return std::shared_ptr<T>(new(std::nothrow) T(std::forward<Args>(args)...));
44    }
45protected:
46    OHOS::UIView *focusedView_;
47    Page() : focusedView_ {nullptr} {}
48};
49} // namespace Updater
50#endif
51