1 /*
2  * Copyright (c) 2020-2021 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 OHOS_ACELITE_IMAGE_COMPONENT_H
17 #define OHOS_ACELITE_IMAGE_COMPONENT_H
18 
19 #include "component.h"
20 #include "key_parser.h"
21 #include "layout/flex_layout.h"
22 #include "non_copyable.h"
23 #include "ui_image_view.h"
24 
25 namespace OHOS {
26 namespace ACELite {
27 struct ImageAttrMap {
28     ACE_DISALLOW_COPY_AND_MOVE(ImageAttrMap);
29     const char *attrName;
30     jerry_external_handler_t setterName;
31     jerry_external_handler_t getterName;
32 };
33 
34 class ImageComponent final : public Component {
35 public:
36     ACE_DISALLOW_COPY_AND_MOVE(ImageComponent);
37     ImageComponent() = delete;
38     ImageComponent(jerry_value_t options, jerry_value_t children, AppStyleManager *styleManager);
~ImageComponent()39     ~ImageComponent() override {}
40     const char *GetSrc();
41 
42 protected:
43     bool CreateNativeViews() override;
44     UIView *GetComponentRootView() const override;
45     bool SetPrivateAttribute(uint16_t attrKeyId, jerry_value_t attrValue) override;
46     bool ApplyPrivateStyle(const AppStyleItem *style) override;
47     void UpdateResizeMode(uint16_t mode);
48     void UpdateWidgetFitMode();
49 private:
50     UIImageView imageView_;
51     UIImageView::ImageResizeMode resizeMode_ = UIImageView::ImageResizeMode::COVER;
52     bool fitOriginalSize_ : 1;
53     bool hasSetWidth_ : 1;
54     bool hasSetHeight_ : 1;
55 };
56 } // namespace ACELite
57 } // namespace OHOS
58 
59 #endif // OHOS_ACELITE_IMAGE_COMPONENT_H
60