1a3e0fd82Sopenharmony_ci/*
2a3e0fd82Sopenharmony_ci * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
3a3e0fd82Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4a3e0fd82Sopenharmony_ci * you may not use this file except in compliance with the License.
5a3e0fd82Sopenharmony_ci * You may obtain a copy of the License at
6a3e0fd82Sopenharmony_ci *
7a3e0fd82Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8a3e0fd82Sopenharmony_ci *
9a3e0fd82Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10a3e0fd82Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11a3e0fd82Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12a3e0fd82Sopenharmony_ci * See the License for the specific language governing permissions and
13a3e0fd82Sopenharmony_ci * limitations under the License.
14a3e0fd82Sopenharmony_ci */
15a3e0fd82Sopenharmony_ci
16a3e0fd82Sopenharmony_ci#include "components/ui_view.h"
17a3e0fd82Sopenharmony_ci
18a3e0fd82Sopenharmony_ci#include "components/root_view.h"
19a3e0fd82Sopenharmony_ci#include "components/ui_view_group.h"
20a3e0fd82Sopenharmony_ci#include "core/render_manager.h"
21a3e0fd82Sopenharmony_ci#include "dfx/ui_view_bounds.h"
22a3e0fd82Sopenharmony_ci#include "dock/focus_manager.h"
23a3e0fd82Sopenharmony_ci#include "draw/draw_utils.h"
24a3e0fd82Sopenharmony_ci#include "engines/gfx/gfx_engine_manager.h"
25a3e0fd82Sopenharmony_ci#include "gfx_utils/graphic_log.h"
26a3e0fd82Sopenharmony_ci#include "gfx_utils/mem_api.h"
27a3e0fd82Sopenharmony_ci#include "securec.h"
28a3e0fd82Sopenharmony_ci#include "themes/theme_manager.h"
29a3e0fd82Sopenharmony_ci
30a3e0fd82Sopenharmony_cinamespace OHOS {
31a3e0fd82Sopenharmony_ciUIView::UIView()
32a3e0fd82Sopenharmony_ci    : touchable_(false),
33a3e0fd82Sopenharmony_ci      visible_(true),
34a3e0fd82Sopenharmony_ci      draggable_(false),
35a3e0fd82Sopenharmony_ci      dragParentInstead_(true),
36a3e0fd82Sopenharmony_ci      isViewGroup_(false),
37a3e0fd82Sopenharmony_ci      needRedraw_(false),
38a3e0fd82Sopenharmony_ci      styleAllocFlag_(false),
39a3e0fd82Sopenharmony_ci      isIntercept_(false),
40a3e0fd82Sopenharmony_ci#if ENABLE_FOCUS_MANAGER
41a3e0fd82Sopenharmony_ci      focusable_(false),
42a3e0fd82Sopenharmony_ci#endif
43a3e0fd82Sopenharmony_ci      opaScale_(OPA_OPAQUE),
44a3e0fd82Sopenharmony_ci      index_(0),
45a3e0fd82Sopenharmony_ci      zIndex_(0),
46a3e0fd82Sopenharmony_ci      id_(nullptr),
47a3e0fd82Sopenharmony_ci      parent_(nullptr),
48a3e0fd82Sopenharmony_ci      nextSibling_(nullptr),
49a3e0fd82Sopenharmony_ci      nextRenderSibling_(nullptr),
50a3e0fd82Sopenharmony_ci      style_(nullptr),
51a3e0fd82Sopenharmony_ci      transMap_(nullptr),
52a3e0fd82Sopenharmony_ci      onClickListener_(nullptr),
53a3e0fd82Sopenharmony_ci      onLongPressListener_(nullptr),
54a3e0fd82Sopenharmony_ci      onDragListener_(nullptr),
55a3e0fd82Sopenharmony_ci      onTouchListener_(nullptr),
56a3e0fd82Sopenharmony_ci#if ENABLE_FOCUS_MANAGER
57a3e0fd82Sopenharmony_ci      onFocusListener_(nullptr),
58a3e0fd82Sopenharmony_ci#endif
59a3e0fd82Sopenharmony_ci#if ENABLE_ROTATE_INPUT
60a3e0fd82Sopenharmony_ci      onRotateListener_(nullptr),
61a3e0fd82Sopenharmony_ci#endif
62a3e0fd82Sopenharmony_ci      viewExtraMsg_(nullptr),
63a3e0fd82Sopenharmony_ci      rect_(0, 0, 0, 0),
64a3e0fd82Sopenharmony_ci      visibleRect_(nullptr)
65a3e0fd82Sopenharmony_ci{
66a3e0fd82Sopenharmony_ci    SetupThemeStyles();
67a3e0fd82Sopenharmony_ci}
68a3e0fd82Sopenharmony_ci
69a3e0fd82Sopenharmony_ciUIView::~UIView()
70a3e0fd82Sopenharmony_ci{
71a3e0fd82Sopenharmony_ci    if (transMap_ != nullptr) {
72a3e0fd82Sopenharmony_ci        delete transMap_;
73a3e0fd82Sopenharmony_ci        transMap_ = nullptr;
74a3e0fd82Sopenharmony_ci    }
75a3e0fd82Sopenharmony_ci    if (visibleRect_ != nullptr) {
76a3e0fd82Sopenharmony_ci        delete visibleRect_;
77a3e0fd82Sopenharmony_ci        visibleRect_ = nullptr;
78a3e0fd82Sopenharmony_ci    }
79a3e0fd82Sopenharmony_ci    if (styleAllocFlag_) {
80a3e0fd82Sopenharmony_ci        delete style_;
81a3e0fd82Sopenharmony_ci        style_ = nullptr;
82a3e0fd82Sopenharmony_ci        styleAllocFlag_ = false;
83a3e0fd82Sopenharmony_ci    }
84a3e0fd82Sopenharmony_ci}
85a3e0fd82Sopenharmony_ci
86a3e0fd82Sopenharmony_cibool UIView::OnPreDraw(Rect& invalidatedArea) const
87a3e0fd82Sopenharmony_ci{
88a3e0fd82Sopenharmony_ci    Rect rect(GetRect());
89a3e0fd82Sopenharmony_ci    uint16_t r = style_->borderRadius_; // radius must be positive
90a3e0fd82Sopenharmony_ci    if (r == COORD_MAX) {
91a3e0fd82Sopenharmony_ci        return true;
92a3e0fd82Sopenharmony_ci    }
93a3e0fd82Sopenharmony_ci    if (r != 0) {
94a3e0fd82Sopenharmony_ci        r = ((r & 0x1) == 0) ? (r >> 1) : ((r + 1) >> 1);
95a3e0fd82Sopenharmony_ci        rect.SetLeft(rect.GetX() + r);
96a3e0fd82Sopenharmony_ci        rect.SetWidth(rect.GetWidth() - r);
97a3e0fd82Sopenharmony_ci        rect.SetTop(rect.GetY() + r);
98a3e0fd82Sopenharmony_ci        rect.SetHeight(rect.GetHeight() - r);
99a3e0fd82Sopenharmony_ci    }
100a3e0fd82Sopenharmony_ci    if (rect.IsContains(invalidatedArea)) {
101a3e0fd82Sopenharmony_ci        return true;
102a3e0fd82Sopenharmony_ci    }
103a3e0fd82Sopenharmony_ci    invalidatedArea.Intersect(invalidatedArea, rect);
104a3e0fd82Sopenharmony_ci    return false;
105a3e0fd82Sopenharmony_ci}
106a3e0fd82Sopenharmony_ci
107a3e0fd82Sopenharmony_civoid UIView::OnDraw(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea)
108a3e0fd82Sopenharmony_ci{
109a3e0fd82Sopenharmony_ci    uint8_t opa = GetMixOpaScale();
110a3e0fd82Sopenharmony_ci    BaseGfxEngine::GetInstance()->DrawRect(gfxDstBuffer, GetOrigRect(), invalidatedArea, *style_, opa);
111a3e0fd82Sopenharmony_ci}
112a3e0fd82Sopenharmony_ci
113a3e0fd82Sopenharmony_civoid UIView::OnPostDraw(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea)
114a3e0fd82Sopenharmony_ci{
115a3e0fd82Sopenharmony_ci    DrawViewBounds(gfxDstBuffer, invalidatedArea);
116a3e0fd82Sopenharmony_ci}
117a3e0fd82Sopenharmony_ci
118a3e0fd82Sopenharmony_civoid UIView::DrawViewBounds(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea)
119a3e0fd82Sopenharmony_ci{
120a3e0fd82Sopenharmony_ci#if ENABLE_DEBUG
121a3e0fd82Sopenharmony_ci    if (!UIViewBounds::GetInstance()->GetShowState()) {
122a3e0fd82Sopenharmony_ci        return;
123a3e0fd82Sopenharmony_ci    }
124a3e0fd82Sopenharmony_ci    Style* style = new Style();
125a3e0fd82Sopenharmony_ci    style->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT);
126a3e0fd82Sopenharmony_ci    style->SetStyle(STYLE_BORDER_COLOR, Color::Red().full);
127a3e0fd82Sopenharmony_ci    style->SetStyle(STYLE_BORDER_WIDTH, 1);
128a3e0fd82Sopenharmony_ci    style->SetStyle(STYLE_BORDER_OPA, OPA_OPAQUE / 2); // 2: half opacity
129a3e0fd82Sopenharmony_ci    Rect viewRect(GetRect());
130a3e0fd82Sopenharmony_ci    BaseGfxEngine* baseGfxEngine = BaseGfxEngine::GetInstance();
131a3e0fd82Sopenharmony_ci    baseGfxEngine->DrawRect(gfxDstBuffer, viewRect, invalidatedArea, *style, OPA_OPAQUE);
132a3e0fd82Sopenharmony_ci
133a3e0fd82Sopenharmony_ci    style->SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE);
134a3e0fd82Sopenharmony_ci    style->SetStyle(STYLE_BACKGROUND_COLOR, Color::Blue().full);
135a3e0fd82Sopenharmony_ci    style->SetStyle(STYLE_BORDER_WIDTH, 0);
136a3e0fd82Sopenharmony_ci    Rect tmpRect(viewRect);
137a3e0fd82Sopenharmony_ci    int16_t length = 10; // 10: corner length
138a3e0fd82Sopenharmony_ci
139a3e0fd82Sopenharmony_ci    // left top corner
140a3e0fd82Sopenharmony_ci    tmpRect.SetRight(viewRect.GetLeft() + length);
141a3e0fd82Sopenharmony_ci    tmpRect.SetBottom(viewRect.GetTop());
142a3e0fd82Sopenharmony_ci    baseGfxEngine->DrawRect(gfxDstBuffer, tmpRect, invalidatedArea, *style, OPA_OPAQUE);
143a3e0fd82Sopenharmony_ci    tmpRect.SetRight(viewRect.GetLeft());
144a3e0fd82Sopenharmony_ci    tmpRect.SetBottom(viewRect.GetTop() + length);
145a3e0fd82Sopenharmony_ci    baseGfxEngine->DrawRect(gfxDstBuffer, tmpRect, invalidatedArea, *style, OPA_OPAQUE);
146a3e0fd82Sopenharmony_ci
147a3e0fd82Sopenharmony_ci    // left bottom corner
148a3e0fd82Sopenharmony_ci    tmpRect.SetLeft(viewRect.GetLeft());
149a3e0fd82Sopenharmony_ci    tmpRect.SetTop(viewRect.GetBottom() - length);
150a3e0fd82Sopenharmony_ci    tmpRect.SetRight(viewRect.GetLeft());
151a3e0fd82Sopenharmony_ci    tmpRect.SetBottom(viewRect.GetBottom());
152a3e0fd82Sopenharmony_ci    baseGfxEngine->DrawRect(gfxDstBuffer, tmpRect, invalidatedArea, *style, OPA_OPAQUE);
153a3e0fd82Sopenharmony_ci    tmpRect.SetTop(viewRect.GetBottom());
154a3e0fd82Sopenharmony_ci    tmpRect.SetRight(viewRect.GetLeft() + length);
155a3e0fd82Sopenharmony_ci    baseGfxEngine->DrawRect(gfxDstBuffer, tmpRect, invalidatedArea, *style, OPA_OPAQUE);
156a3e0fd82Sopenharmony_ci
157a3e0fd82Sopenharmony_ci    // right top corner
158a3e0fd82Sopenharmony_ci    tmpRect.SetLeft(viewRect.GetRight() - length);
159a3e0fd82Sopenharmony_ci    tmpRect.SetTop(viewRect.GetTop());
160a3e0fd82Sopenharmony_ci    tmpRect.SetRight(viewRect.GetRight());
161a3e0fd82Sopenharmony_ci    tmpRect.SetBottom(viewRect.GetTop());
162a3e0fd82Sopenharmony_ci    baseGfxEngine->DrawRect(gfxDstBuffer, tmpRect, invalidatedArea, *style, OPA_OPAQUE);
163a3e0fd82Sopenharmony_ci    tmpRect.SetLeft(viewRect.GetRight());
164a3e0fd82Sopenharmony_ci    tmpRect.SetBottom(viewRect.GetTop() + length);
165a3e0fd82Sopenharmony_ci    baseGfxEngine->DrawRect(gfxDstBuffer, tmpRect, invalidatedArea, *style, OPA_OPAQUE);
166a3e0fd82Sopenharmony_ci
167a3e0fd82Sopenharmony_ci    // right bottom corner
168a3e0fd82Sopenharmony_ci    tmpRect = viewRect;
169a3e0fd82Sopenharmony_ci    tmpRect.SetLeft(viewRect.GetRight());
170a3e0fd82Sopenharmony_ci    tmpRect.SetTop(viewRect.GetBottom() - length);
171a3e0fd82Sopenharmony_ci    baseGfxEngine->DrawRect(gfxDstBuffer, tmpRect, invalidatedArea, *style, OPA_OPAQUE);
172a3e0fd82Sopenharmony_ci    tmpRect.SetLeft(viewRect.GetRight() - length);
173a3e0fd82Sopenharmony_ci    tmpRect.SetTop(viewRect.GetBottom());
174a3e0fd82Sopenharmony_ci    baseGfxEngine->DrawRect(gfxDstBuffer, tmpRect, invalidatedArea, *style, OPA_OPAQUE);
175a3e0fd82Sopenharmony_ci    delete style;
176a3e0fd82Sopenharmony_ci#endif // ENABLE_DEBUG
177a3e0fd82Sopenharmony_ci}
178a3e0fd82Sopenharmony_ci
179a3e0fd82Sopenharmony_civoid UIView::SetupThemeStyles()
180a3e0fd82Sopenharmony_ci{
181a3e0fd82Sopenharmony_ci    Theme* theme = ThemeManager::GetInstance().GetCurrent();
182a3e0fd82Sopenharmony_ci    if (theme != nullptr) {
183a3e0fd82Sopenharmony_ci        style_ = &(theme->GetMainStyle());
184a3e0fd82Sopenharmony_ci    } else {
185a3e0fd82Sopenharmony_ci        style_ = &(StyleDefault::GetDefaultStyle());
186a3e0fd82Sopenharmony_ci    }
187a3e0fd82Sopenharmony_ci}
188a3e0fd82Sopenharmony_ci
189a3e0fd82Sopenharmony_civoid UIView::SetStyle(Style& style)
190a3e0fd82Sopenharmony_ci{
191a3e0fd82Sopenharmony_ci    if (styleAllocFlag_) {
192a3e0fd82Sopenharmony_ci        delete style_;
193a3e0fd82Sopenharmony_ci        styleAllocFlag_ = false;
194a3e0fd82Sopenharmony_ci    }
195a3e0fd82Sopenharmony_ci    style_ = &style;
196a3e0fd82Sopenharmony_ci}
197a3e0fd82Sopenharmony_ci
198a3e0fd82Sopenharmony_civoid UIView::SetStyle(uint8_t key, int64_t value)
199a3e0fd82Sopenharmony_ci{
200a3e0fd82Sopenharmony_ci    if (!styleAllocFlag_) {
201a3e0fd82Sopenharmony_ci        style_ = new Style(*style_);
202a3e0fd82Sopenharmony_ci        if (style_ == nullptr) {
203a3e0fd82Sopenharmony_ci            GRAPHIC_LOGE("new Style fail");
204a3e0fd82Sopenharmony_ci            return;
205a3e0fd82Sopenharmony_ci        }
206a3e0fd82Sopenharmony_ci        styleAllocFlag_ = true;
207a3e0fd82Sopenharmony_ci    }
208a3e0fd82Sopenharmony_ci    int16_t width = GetWidth();
209a3e0fd82Sopenharmony_ci    int16_t height = GetHeight();
210a3e0fd82Sopenharmony_ci    int16_t x = GetX();
211a3e0fd82Sopenharmony_ci    int16_t y = GetY();
212a3e0fd82Sopenharmony_ci    style_->SetStyle(key, value);
213a3e0fd82Sopenharmony_ci    Rect rect(x, y, x + width - 1, y + height - 1);
214a3e0fd82Sopenharmony_ci    UpdateRectInfo(key, rect);
215a3e0fd82Sopenharmony_ci}
216a3e0fd82Sopenharmony_ci
217a3e0fd82Sopenharmony_civoid UIView::UpdateRectInfo(uint8_t key, const Rect& rect)
218a3e0fd82Sopenharmony_ci{
219a3e0fd82Sopenharmony_ci    switch (key) {
220a3e0fd82Sopenharmony_ci        case STYLE_BORDER_WIDTH: {
221a3e0fd82Sopenharmony_ci            SetWidth(rect.GetWidth());
222a3e0fd82Sopenharmony_ci            SetHeight(rect.GetHeight());
223a3e0fd82Sopenharmony_ci            break;
224a3e0fd82Sopenharmony_ci        }
225a3e0fd82Sopenharmony_ci        case STYLE_PADDING_LEFT:
226a3e0fd82Sopenharmony_ci        case STYLE_PADDING_RIGHT: {
227a3e0fd82Sopenharmony_ci            SetWidth(rect.GetWidth());
228a3e0fd82Sopenharmony_ci            break;
229a3e0fd82Sopenharmony_ci        }
230a3e0fd82Sopenharmony_ci        case STYLE_PADDING_TOP:
231a3e0fd82Sopenharmony_ci        case STYLE_PADDING_BOTTOM: {
232a3e0fd82Sopenharmony_ci            SetHeight(rect.GetHeight());
233a3e0fd82Sopenharmony_ci            break;
234a3e0fd82Sopenharmony_ci        }
235a3e0fd82Sopenharmony_ci        case STYLE_MARGIN_LEFT: {
236a3e0fd82Sopenharmony_ci            SetX(rect.GetX());
237a3e0fd82Sopenharmony_ci            break;
238a3e0fd82Sopenharmony_ci        }
239a3e0fd82Sopenharmony_ci        case STYLE_MARGIN_TOP: {
240a3e0fd82Sopenharmony_ci            SetY(rect.GetY());
241a3e0fd82Sopenharmony_ci            break;
242a3e0fd82Sopenharmony_ci        }
243a3e0fd82Sopenharmony_ci        default:
244a3e0fd82Sopenharmony_ci            break;
245a3e0fd82Sopenharmony_ci    }
246a3e0fd82Sopenharmony_ci}
247a3e0fd82Sopenharmony_ci
248a3e0fd82Sopenharmony_ciint64_t UIView::GetStyle(uint8_t key) const
249a3e0fd82Sopenharmony_ci{
250a3e0fd82Sopenharmony_ci    return style_->GetStyle(key);
251a3e0fd82Sopenharmony_ci}
252a3e0fd82Sopenharmony_ci
253a3e0fd82Sopenharmony_ciconst Style& UIView::GetStyleConst() const
254a3e0fd82Sopenharmony_ci{
255a3e0fd82Sopenharmony_ci    return *style_;
256a3e0fd82Sopenharmony_ci}
257a3e0fd82Sopenharmony_ci
258a3e0fd82Sopenharmony_civoid UIView::SetOpaScale(uint8_t opaScale)
259a3e0fd82Sopenharmony_ci{
260a3e0fd82Sopenharmony_ci    opaScale_ = opaScale;
261a3e0fd82Sopenharmony_ci}
262a3e0fd82Sopenharmony_ci
263a3e0fd82Sopenharmony_ciuint8_t UIView::GetOpaScale() const
264a3e0fd82Sopenharmony_ci{
265a3e0fd82Sopenharmony_ci    return opaScale_;
266a3e0fd82Sopenharmony_ci}
267a3e0fd82Sopenharmony_ci
268a3e0fd82Sopenharmony_ciUIView::ViewExtraMsg* UIView::GetExtraMsg()
269a3e0fd82Sopenharmony_ci{
270a3e0fd82Sopenharmony_ci    return viewExtraMsg_;
271a3e0fd82Sopenharmony_ci}
272a3e0fd82Sopenharmony_ci
273a3e0fd82Sopenharmony_civoid UIView::SetExtraMsg(ViewExtraMsg* extraMsg)
274a3e0fd82Sopenharmony_ci{
275a3e0fd82Sopenharmony_ci    viewExtraMsg_ = extraMsg;
276a3e0fd82Sopenharmony_ci}
277a3e0fd82Sopenharmony_ci
278a3e0fd82Sopenharmony_civoid UIView::Rotate(int16_t angle, const Vector2<float>& pivot)
279a3e0fd82Sopenharmony_ci{
280a3e0fd82Sopenharmony_ci    Vector3<float> pivotStart3D = Vector3<float>(pivot.x_, pivot.y_, 0);
281a3e0fd82Sopenharmony_ci    Vector3<float> pivotEnd3D = Vector3<float>(pivot.x_, pivot.y_, 1.0f);
282a3e0fd82Sopenharmony_ci    Rotate(angle, pivotStart3D, pivotEnd3D);
283a3e0fd82Sopenharmony_ci}
284a3e0fd82Sopenharmony_ci
285a3e0fd82Sopenharmony_civoid UIView::Rotate(int16_t angle, const Vector3<float>& pivotStart, const Vector3<float>& pivotEnd)
286a3e0fd82Sopenharmony_ci{
287a3e0fd82Sopenharmony_ci    if (transMap_ == nullptr) {
288a3e0fd82Sopenharmony_ci        ReMeasure();
289a3e0fd82Sopenharmony_ci        transMap_ = new TransformMap();
290a3e0fd82Sopenharmony_ci    }
291a3e0fd82Sopenharmony_ci    bool firstTrans = transMap_->IsInvalid();
292a3e0fd82Sopenharmony_ci    Rect joinRect = transMap_->GetBoxRect();
293a3e0fd82Sopenharmony_ci    transMap_->SetTransMapRect(GetOrigRect());
294a3e0fd82Sopenharmony_ci    transMap_->Rotate(angle, pivotStart, pivotEnd);
295a3e0fd82Sopenharmony_ci    if (firstTrans) {
296a3e0fd82Sopenharmony_ci        joinRect = transMap_->GetBoxRect();
297a3e0fd82Sopenharmony_ci    } else {
298a3e0fd82Sopenharmony_ci        joinRect.Join(joinRect, transMap_->GetBoxRect());
299a3e0fd82Sopenharmony_ci    }
300a3e0fd82Sopenharmony_ci    joinRect.Join(joinRect, GetOrigRect());
301a3e0fd82Sopenharmony_ci    InvalidateRect(joinRect);
302a3e0fd82Sopenharmony_ci}
303a3e0fd82Sopenharmony_ci
304a3e0fd82Sopenharmony_civoid UIView::Scale(const Vector2<float>& scale, const Vector2<float>& pivot)
305a3e0fd82Sopenharmony_ci{
306a3e0fd82Sopenharmony_ci    Vector3<float> scale3D = Vector3<float>(scale.x_, scale.y_, 1.0f);
307a3e0fd82Sopenharmony_ci    Vector3<float> pivot3D = Vector3<float>(pivot.x_, pivot.y_, 0);
308a3e0fd82Sopenharmony_ci    Scale(scale3D, pivot3D);
309a3e0fd82Sopenharmony_ci}
310a3e0fd82Sopenharmony_ci
311a3e0fd82Sopenharmony_civoid UIView::Scale(const Vector3<float>& scale, const Vector3<float>& pivot)
312a3e0fd82Sopenharmony_ci{
313a3e0fd82Sopenharmony_ci    if (transMap_ == nullptr) {
314a3e0fd82Sopenharmony_ci        ReMeasure();
315a3e0fd82Sopenharmony_ci        transMap_ = new TransformMap();
316a3e0fd82Sopenharmony_ci    }
317a3e0fd82Sopenharmony_ci    bool firstTrans = transMap_->IsInvalid();
318a3e0fd82Sopenharmony_ci    Rect joinRect = transMap_->GetBoxRect();
319a3e0fd82Sopenharmony_ci    transMap_->SetTransMapRect(GetOrigRect());
320a3e0fd82Sopenharmony_ci    transMap_->Scale(scale, pivot);
321a3e0fd82Sopenharmony_ci    if (firstTrans) {
322a3e0fd82Sopenharmony_ci        joinRect = transMap_->GetBoxRect();
323a3e0fd82Sopenharmony_ci    } else {
324a3e0fd82Sopenharmony_ci        joinRect.Join(joinRect, transMap_->GetBoxRect());
325a3e0fd82Sopenharmony_ci    }
326a3e0fd82Sopenharmony_ci    joinRect.Join(joinRect, GetOrigRect());
327a3e0fd82Sopenharmony_ci    InvalidateRect(joinRect);
328a3e0fd82Sopenharmony_ci}
329a3e0fd82Sopenharmony_ci
330a3e0fd82Sopenharmony_civoid UIView::Shear(const Vector2<float>& shearX, const Vector2<float>& shearY, const Vector2<float>& shearZ)
331a3e0fd82Sopenharmony_ci{
332a3e0fd82Sopenharmony_ci    if (transMap_ == nullptr) {
333a3e0fd82Sopenharmony_ci        ReMeasure();
334a3e0fd82Sopenharmony_ci        transMap_ = new TransformMap();
335a3e0fd82Sopenharmony_ci        if (transMap_ == nullptr) {
336a3e0fd82Sopenharmony_ci            return;
337a3e0fd82Sopenharmony_ci        }
338a3e0fd82Sopenharmony_ci    }
339a3e0fd82Sopenharmony_ci    bool firstTrans = transMap_->IsInvalid();
340a3e0fd82Sopenharmony_ci    Rect joinRect = transMap_->GetBoxRect();
341a3e0fd82Sopenharmony_ci    transMap_->SetTransMapRect(GetOrigRect());
342a3e0fd82Sopenharmony_ci    transMap_->Shear(shearX, shearY, shearZ);
343a3e0fd82Sopenharmony_ci    if (firstTrans) {
344a3e0fd82Sopenharmony_ci        joinRect = transMap_->GetBoxRect();
345a3e0fd82Sopenharmony_ci    } else {
346a3e0fd82Sopenharmony_ci        joinRect.Join(joinRect, transMap_->GetBoxRect());
347a3e0fd82Sopenharmony_ci    }
348a3e0fd82Sopenharmony_ci    joinRect.Join(joinRect, GetOrigRect());
349a3e0fd82Sopenharmony_ci    InvalidateRect(joinRect);
350a3e0fd82Sopenharmony_ci}
351a3e0fd82Sopenharmony_ci
352a3e0fd82Sopenharmony_civoid UIView::Translate(const Vector2<int16_t>& trans)
353a3e0fd82Sopenharmony_ci{
354a3e0fd82Sopenharmony_ci    Vector3<int16_t> trans3D = Vector3<int16_t>(trans.x_, trans.y_, 0);
355a3e0fd82Sopenharmony_ci    Translate(trans3D);
356a3e0fd82Sopenharmony_ci}
357a3e0fd82Sopenharmony_ci
358a3e0fd82Sopenharmony_civoid UIView::Translate(const Vector3<int16_t>& trans)
359a3e0fd82Sopenharmony_ci{
360a3e0fd82Sopenharmony_ci    if (transMap_ == nullptr) {
361a3e0fd82Sopenharmony_ci        ReMeasure();
362a3e0fd82Sopenharmony_ci        transMap_ = new TransformMap();
363a3e0fd82Sopenharmony_ci    }
364a3e0fd82Sopenharmony_ci    bool firstTrans = transMap_->IsInvalid();
365a3e0fd82Sopenharmony_ci    Rect joinRect = transMap_->GetBoxRect();
366a3e0fd82Sopenharmony_ci    transMap_->SetTransMapRect(GetOrigRect());
367a3e0fd82Sopenharmony_ci    transMap_->Translate(trans);
368a3e0fd82Sopenharmony_ci    if (firstTrans) {
369a3e0fd82Sopenharmony_ci        joinRect = transMap_->GetBoxRect();
370a3e0fd82Sopenharmony_ci    } else {
371a3e0fd82Sopenharmony_ci        joinRect.Join(joinRect, transMap_->GetBoxRect());
372a3e0fd82Sopenharmony_ci    }
373a3e0fd82Sopenharmony_ci    joinRect.Join(joinRect, GetOrigRect());
374a3e0fd82Sopenharmony_ci    InvalidateRect(joinRect);
375a3e0fd82Sopenharmony_ci}
376a3e0fd82Sopenharmony_ci
377a3e0fd82Sopenharmony_cibool UIView::IsTransInvalid()
378a3e0fd82Sopenharmony_ci{
379a3e0fd82Sopenharmony_ci    if (transMap_ == nullptr) {
380a3e0fd82Sopenharmony_ci        return true;
381a3e0fd82Sopenharmony_ci    }
382a3e0fd82Sopenharmony_ci    return transMap_->IsInvalid();
383a3e0fd82Sopenharmony_ci}
384a3e0fd82Sopenharmony_ci
385a3e0fd82Sopenharmony_civoid UIView::SetCameraDistance(int16_t distance)
386a3e0fd82Sopenharmony_ci{
387a3e0fd82Sopenharmony_ci    if (transMap_ == nullptr) {
388a3e0fd82Sopenharmony_ci        ReMeasure();
389a3e0fd82Sopenharmony_ci        transMap_ = new TransformMap();
390a3e0fd82Sopenharmony_ci    }
391a3e0fd82Sopenharmony_ci    Rect joinRect = transMap_->GetBoxRect();
392a3e0fd82Sopenharmony_ci    transMap_->SetTransMapRect(GetOrigRect());
393a3e0fd82Sopenharmony_ci    transMap_->SetCameraDistance(distance);
394a3e0fd82Sopenharmony_ci    joinRect.Join(joinRect, transMap_->GetBoxRect());
395a3e0fd82Sopenharmony_ci    joinRect.Join(joinRect, GetOrigRect());
396a3e0fd82Sopenharmony_ci    InvalidateRect(joinRect);
397a3e0fd82Sopenharmony_ci}
398a3e0fd82Sopenharmony_ci
399a3e0fd82Sopenharmony_civoid UIView::SetCameraPosition(const Vector2<float>& position)
400a3e0fd82Sopenharmony_ci{
401a3e0fd82Sopenharmony_ci    if (transMap_ == nullptr) {
402a3e0fd82Sopenharmony_ci        ReMeasure();
403a3e0fd82Sopenharmony_ci        transMap_ = new TransformMap();
404a3e0fd82Sopenharmony_ci    }
405a3e0fd82Sopenharmony_ci    Rect joinRect = transMap_->GetBoxRect();
406a3e0fd82Sopenharmony_ci    transMap_->SetTransMapRect(GetOrigRect());
407a3e0fd82Sopenharmony_ci    transMap_->SetCameraPosition(position);
408a3e0fd82Sopenharmony_ci    joinRect.Join(joinRect, transMap_->GetBoxRect());
409a3e0fd82Sopenharmony_ci    joinRect.Join(joinRect, GetOrigRect());
410a3e0fd82Sopenharmony_ci    InvalidateRect(joinRect);
411a3e0fd82Sopenharmony_ci}
412a3e0fd82Sopenharmony_ci
413a3e0fd82Sopenharmony_civoid UIView::ResetTransParameter()
414a3e0fd82Sopenharmony_ci{
415a3e0fd82Sopenharmony_ci    if (transMap_ != nullptr) {
416a3e0fd82Sopenharmony_ci        delete transMap_;
417a3e0fd82Sopenharmony_ci        transMap_ = nullptr;
418a3e0fd82Sopenharmony_ci        Invalidate();
419a3e0fd82Sopenharmony_ci    }
420a3e0fd82Sopenharmony_ci}
421a3e0fd82Sopenharmony_ci
422a3e0fd82Sopenharmony_ci#if ENABLE_ROTATE_INPUT
423a3e0fd82Sopenharmony_civoid UIView::RequestFocus()
424a3e0fd82Sopenharmony_ci{
425a3e0fd82Sopenharmony_ci    FocusManager::GetInstance()->RequestFocus(this);
426a3e0fd82Sopenharmony_ci}
427a3e0fd82Sopenharmony_ci
428a3e0fd82Sopenharmony_civoid UIView::ClearFocus()
429a3e0fd82Sopenharmony_ci{
430a3e0fd82Sopenharmony_ci    FocusManager::GetInstance()->ClearFocus();
431a3e0fd82Sopenharmony_ci}
432a3e0fd82Sopenharmony_ci#endif
433a3e0fd82Sopenharmony_ci
434a3e0fd82Sopenharmony_civoid UIView::Invalidate()
435a3e0fd82Sopenharmony_ci{
436a3e0fd82Sopenharmony_ci    UIView* view = this;
437a3e0fd82Sopenharmony_ci    while (view != nullptr) {
438a3e0fd82Sopenharmony_ci        if (view->transMap_ != nullptr && !view->GetTransformMap().IsInvalid() && view != this) {
439a3e0fd82Sopenharmony_ci            InvalidateRect(view->GetRect(), view);
440a3e0fd82Sopenharmony_ci            return;
441a3e0fd82Sopenharmony_ci        }
442a3e0fd82Sopenharmony_ci        view = view->parent_;
443a3e0fd82Sopenharmony_ci    }
444a3e0fd82Sopenharmony_ci    InvalidateRect(GetRect());
445a3e0fd82Sopenharmony_ci}
446a3e0fd82Sopenharmony_ci
447a3e0fd82Sopenharmony_civoid UIView::InvalidateRect(const Rect& invalidatedArea, UIView* view)
448a3e0fd82Sopenharmony_ci{
449a3e0fd82Sopenharmony_ci    if (!visible_) {
450a3e0fd82Sopenharmony_ci        if (needRedraw_) {
451a3e0fd82Sopenharmony_ci            needRedraw_ = false;
452a3e0fd82Sopenharmony_ci        } else {
453a3e0fd82Sopenharmony_ci            return;
454a3e0fd82Sopenharmony_ci        }
455a3e0fd82Sopenharmony_ci    }
456a3e0fd82Sopenharmony_ci
457a3e0fd82Sopenharmony_ci    if (view == nullptr) {
458a3e0fd82Sopenharmony_ci        view = this;
459a3e0fd82Sopenharmony_ci    }
460a3e0fd82Sopenharmony_ci    Rect trunc(invalidatedArea);
461a3e0fd82Sopenharmony_ci    bool isIntersect = true;
462a3e0fd82Sopenharmony_ci    UIView* par = view->parent_;
463a3e0fd82Sopenharmony_ci    UIView* cur = view;
464a3e0fd82Sopenharmony_ci
465a3e0fd82Sopenharmony_ci    while (par != nullptr) {
466a3e0fd82Sopenharmony_ci        if (!par->visible_) {
467a3e0fd82Sopenharmony_ci            return;
468a3e0fd82Sopenharmony_ci        }
469a3e0fd82Sopenharmony_ci
470a3e0fd82Sopenharmony_ci        isIntersect = trunc.Intersect(par->GetContentRect(), trunc);
471a3e0fd82Sopenharmony_ci        if (!isIntersect) {
472a3e0fd82Sopenharmony_ci            break;
473a3e0fd82Sopenharmony_ci        }
474a3e0fd82Sopenharmony_ci
475a3e0fd82Sopenharmony_ci        cur = par;
476a3e0fd82Sopenharmony_ci        par = par->parent_;
477a3e0fd82Sopenharmony_ci    }
478a3e0fd82Sopenharmony_ci
479a3e0fd82Sopenharmony_ci    if (isIntersect && (cur->GetViewType() == UI_ROOT_VIEW)) {
480a3e0fd82Sopenharmony_ci        RootView* rootView = reinterpret_cast<RootView*>(cur);
481a3e0fd82Sopenharmony_ci        rootView->AddInvalidateRectWithLock(trunc, view);
482a3e0fd82Sopenharmony_ci    }
483a3e0fd82Sopenharmony_ci}
484a3e0fd82Sopenharmony_ci
485a3e0fd82Sopenharmony_cibool UIView::OnLongPressEvent(const LongPressEvent& event)
486a3e0fd82Sopenharmony_ci{
487a3e0fd82Sopenharmony_ci    if (onLongPressListener_ != nullptr) {
488a3e0fd82Sopenharmony_ci        /* To ensure version compatibility, the listeners of both versions are invoked. */
489a3e0fd82Sopenharmony_ci        bool isConsumed = onLongPressListener_->OnLongPress(*this, event);
490a3e0fd82Sopenharmony_ci        return isConsumed;
491a3e0fd82Sopenharmony_ci    }
492a3e0fd82Sopenharmony_ci    return isIntercept_;
493a3e0fd82Sopenharmony_ci}
494a3e0fd82Sopenharmony_ci
495a3e0fd82Sopenharmony_cibool UIView::OnDragStartEvent(const DragEvent& event)
496a3e0fd82Sopenharmony_ci{
497a3e0fd82Sopenharmony_ci    if (onDragListener_ != nullptr) {
498a3e0fd82Sopenharmony_ci        /* To ensure version compatibility, the listeners of both versions are invoked. */
499a3e0fd82Sopenharmony_ci        bool isConsumed = onDragListener_->OnDragStart(*this, event);
500a3e0fd82Sopenharmony_ci        return isConsumed;
501a3e0fd82Sopenharmony_ci    }
502a3e0fd82Sopenharmony_ci    return isIntercept_;
503a3e0fd82Sopenharmony_ci}
504a3e0fd82Sopenharmony_ci
505a3e0fd82Sopenharmony_cibool UIView::OnDragEvent(const DragEvent& event)
506a3e0fd82Sopenharmony_ci{
507a3e0fd82Sopenharmony_ci    if (onDragListener_ != nullptr) {
508a3e0fd82Sopenharmony_ci        /* To ensure version compatibility, the listeners of both versions are invoked. */
509a3e0fd82Sopenharmony_ci        bool isConsumed = onDragListener_->OnDrag(*this, event);
510a3e0fd82Sopenharmony_ci        return isConsumed;
511a3e0fd82Sopenharmony_ci    }
512a3e0fd82Sopenharmony_ci    return isIntercept_;
513a3e0fd82Sopenharmony_ci}
514a3e0fd82Sopenharmony_ci
515a3e0fd82Sopenharmony_cibool UIView::OnDragEndEvent(const DragEvent& event)
516a3e0fd82Sopenharmony_ci{
517a3e0fd82Sopenharmony_ci    if (onDragListener_ != nullptr) {
518a3e0fd82Sopenharmony_ci        /* To ensure version compatibility, the listeners of both versions are invoked. */
519a3e0fd82Sopenharmony_ci        bool isConsumed = onDragListener_->OnDragEnd(*this, event);
520a3e0fd82Sopenharmony_ci        return isConsumed;
521a3e0fd82Sopenharmony_ci    }
522a3e0fd82Sopenharmony_ci    return isIntercept_;
523a3e0fd82Sopenharmony_ci}
524a3e0fd82Sopenharmony_ci
525a3e0fd82Sopenharmony_cibool UIView::OnClickEvent(const ClickEvent& event)
526a3e0fd82Sopenharmony_ci{
527a3e0fd82Sopenharmony_ci    if (onClickListener_ != nullptr) {
528a3e0fd82Sopenharmony_ci        /* To ensure version compatibility, the listeners of both versions are invoked. */
529a3e0fd82Sopenharmony_ci        bool isConsumed = onClickListener_->OnClick(*this, event);
530a3e0fd82Sopenharmony_ci        return isConsumed;
531a3e0fd82Sopenharmony_ci    }
532a3e0fd82Sopenharmony_ci    return isIntercept_;
533a3e0fd82Sopenharmony_ci}
534a3e0fd82Sopenharmony_ci
535a3e0fd82Sopenharmony_cibool UIView::OnPressEvent(const PressEvent& event)
536a3e0fd82Sopenharmony_ci{
537a3e0fd82Sopenharmony_ci    if (onTouchListener_ != nullptr) {
538a3e0fd82Sopenharmony_ci        /* To ensure version compatibility, the listeners of both versions are invoked. */
539a3e0fd82Sopenharmony_ci        bool isConsumed = onTouchListener_->OnPress(*this, event);
540a3e0fd82Sopenharmony_ci        return isConsumed;
541a3e0fd82Sopenharmony_ci    }
542a3e0fd82Sopenharmony_ci    return isIntercept_;
543a3e0fd82Sopenharmony_ci}
544a3e0fd82Sopenharmony_ci
545a3e0fd82Sopenharmony_cibool UIView::OnReleaseEvent(const ReleaseEvent& event)
546a3e0fd82Sopenharmony_ci{
547a3e0fd82Sopenharmony_ci    if (onTouchListener_ != nullptr) {
548a3e0fd82Sopenharmony_ci        /* To ensure version compatibility, the listeners of both versions are invoked. */
549a3e0fd82Sopenharmony_ci        bool isConsumed = onTouchListener_->OnRelease(*this, event);
550a3e0fd82Sopenharmony_ci        return isConsumed;
551a3e0fd82Sopenharmony_ci    }
552a3e0fd82Sopenharmony_ci    return isIntercept_;
553a3e0fd82Sopenharmony_ci}
554a3e0fd82Sopenharmony_ci
555a3e0fd82Sopenharmony_cibool UIView::OnCancelEvent(const CancelEvent& event)
556a3e0fd82Sopenharmony_ci{
557a3e0fd82Sopenharmony_ci    if (onTouchListener_ != nullptr) {
558a3e0fd82Sopenharmony_ci        /* To ensure version compatibility, the listeners of both versions are invoked. */
559a3e0fd82Sopenharmony_ci        bool isConsumed = onTouchListener_->OnCancel(*this, event);
560a3e0fd82Sopenharmony_ci        return isConsumed;
561a3e0fd82Sopenharmony_ci    }
562a3e0fd82Sopenharmony_ci    return isIntercept_;
563a3e0fd82Sopenharmony_ci}
564a3e0fd82Sopenharmony_ci
565a3e0fd82Sopenharmony_civoid UIView::SetOnDragListener(OnDragListener* onDragListener)
566a3e0fd82Sopenharmony_ci{
567a3e0fd82Sopenharmony_ci    onDragListener_ = onDragListener;
568a3e0fd82Sopenharmony_ci}
569a3e0fd82Sopenharmony_ci
570a3e0fd82Sopenharmony_ciUIView::OnDragListener*& UIView::GetOnDragListener()
571a3e0fd82Sopenharmony_ci{
572a3e0fd82Sopenharmony_ci    return onDragListener_;
573a3e0fd82Sopenharmony_ci}
574a3e0fd82Sopenharmony_ci
575a3e0fd82Sopenharmony_civoid UIView::SetOnClickListener(OnClickListener* onClickListener)
576a3e0fd82Sopenharmony_ci{
577a3e0fd82Sopenharmony_ci    onClickListener_ = onClickListener;
578a3e0fd82Sopenharmony_ci}
579a3e0fd82Sopenharmony_ci
580a3e0fd82Sopenharmony_ciUIView::OnClickListener*& UIView::GetOnClickListener()
581a3e0fd82Sopenharmony_ci{
582a3e0fd82Sopenharmony_ci    return onClickListener_;
583a3e0fd82Sopenharmony_ci}
584a3e0fd82Sopenharmony_ci
585a3e0fd82Sopenharmony_civoid UIView::SetOnLongPressListener(OnLongPressListener* onLongPressListener)
586a3e0fd82Sopenharmony_ci{
587a3e0fd82Sopenharmony_ci    onLongPressListener_ = onLongPressListener;
588a3e0fd82Sopenharmony_ci}
589a3e0fd82Sopenharmony_ci
590a3e0fd82Sopenharmony_ciUIView::OnLongPressListener*& UIView::GetOnLongPressListener()
591a3e0fd82Sopenharmony_ci{
592a3e0fd82Sopenharmony_ci    return onLongPressListener_;
593a3e0fd82Sopenharmony_ci}
594a3e0fd82Sopenharmony_ci
595a3e0fd82Sopenharmony_civoid UIView::SetOnTouchListener(OnTouchListener* onTouchListener)
596a3e0fd82Sopenharmony_ci{
597a3e0fd82Sopenharmony_ci    onTouchListener_ = onTouchListener;
598a3e0fd82Sopenharmony_ci}
599a3e0fd82Sopenharmony_ci
600a3e0fd82Sopenharmony_ciUIView::OnTouchListener*& UIView::GetTouchListener()
601a3e0fd82Sopenharmony_ci{
602a3e0fd82Sopenharmony_ci    return onTouchListener_;
603a3e0fd82Sopenharmony_ci}
604a3e0fd82Sopenharmony_ci
605a3e0fd82Sopenharmony_civoid UIView::SetParent(UIView* parent)
606a3e0fd82Sopenharmony_ci{
607a3e0fd82Sopenharmony_ci    parent_ = parent;
608a3e0fd82Sopenharmony_ci}
609a3e0fd82Sopenharmony_ci
610a3e0fd82Sopenharmony_ciUIView* UIView::GetParent() const
611a3e0fd82Sopenharmony_ci{
612a3e0fd82Sopenharmony_ci    return parent_;
613a3e0fd82Sopenharmony_ci}
614a3e0fd82Sopenharmony_ci
615a3e0fd82Sopenharmony_civoid UIView::SetNextSibling(UIView* sibling)
616a3e0fd82Sopenharmony_ci{
617a3e0fd82Sopenharmony_ci    nextSibling_ = sibling;
618a3e0fd82Sopenharmony_ci}
619a3e0fd82Sopenharmony_ci
620a3e0fd82Sopenharmony_ciUIView* UIView::GetNextSibling() const
621a3e0fd82Sopenharmony_ci{
622a3e0fd82Sopenharmony_ci    return nextSibling_;
623a3e0fd82Sopenharmony_ci}
624a3e0fd82Sopenharmony_ci
625a3e0fd82Sopenharmony_civoid UIView::SetNextRenderSibling(UIView* renderSibling)
626a3e0fd82Sopenharmony_ci{
627a3e0fd82Sopenharmony_ci    nextRenderSibling_ = renderSibling;
628a3e0fd82Sopenharmony_ci}
629a3e0fd82Sopenharmony_ci
630a3e0fd82Sopenharmony_ciUIView* UIView::GetNextRenderSibling() const
631a3e0fd82Sopenharmony_ci{
632a3e0fd82Sopenharmony_ci    return nextRenderSibling_;
633a3e0fd82Sopenharmony_ci}
634a3e0fd82Sopenharmony_ci
635a3e0fd82Sopenharmony_civoid UIView::SetVisible(bool visible)
636a3e0fd82Sopenharmony_ci{
637a3e0fd82Sopenharmony_ci    if (visible_ != visible) {
638a3e0fd82Sopenharmony_ci        visible_ = visible;
639a3e0fd82Sopenharmony_ci        needRedraw_ = true;
640a3e0fd82Sopenharmony_ci        Invalidate();
641a3e0fd82Sopenharmony_ci    }
642a3e0fd82Sopenharmony_ci}
643a3e0fd82Sopenharmony_ci
644a3e0fd82Sopenharmony_cibool UIView::IsVisible() const
645a3e0fd82Sopenharmony_ci{
646a3e0fd82Sopenharmony_ci    return visible_;
647a3e0fd82Sopenharmony_ci}
648a3e0fd82Sopenharmony_ci
649a3e0fd82Sopenharmony_civoid UIView::SetTouchable(bool touch)
650a3e0fd82Sopenharmony_ci{
651a3e0fd82Sopenharmony_ci    touchable_ = touch;
652a3e0fd82Sopenharmony_ci}
653a3e0fd82Sopenharmony_ci
654a3e0fd82Sopenharmony_cibool UIView::IsTouchable() const
655a3e0fd82Sopenharmony_ci{
656a3e0fd82Sopenharmony_ci    return touchable_;
657a3e0fd82Sopenharmony_ci}
658a3e0fd82Sopenharmony_ci
659a3e0fd82Sopenharmony_civoid UIView::SetDraggable(bool draggable)
660a3e0fd82Sopenharmony_ci{
661a3e0fd82Sopenharmony_ci    draggable_ = draggable;
662a3e0fd82Sopenharmony_ci    dragParentInstead_ = !draggable;
663a3e0fd82Sopenharmony_ci}
664a3e0fd82Sopenharmony_ci
665a3e0fd82Sopenharmony_cibool UIView::IsDraggable() const
666a3e0fd82Sopenharmony_ci{
667a3e0fd82Sopenharmony_ci    return draggable_;
668a3e0fd82Sopenharmony_ci}
669a3e0fd82Sopenharmony_ci
670a3e0fd82Sopenharmony_civoid UIView::SetDragParentInstead(bool dragParentInstead)
671a3e0fd82Sopenharmony_ci{
672a3e0fd82Sopenharmony_ci    dragParentInstead_ = dragParentInstead;
673a3e0fd82Sopenharmony_ci}
674a3e0fd82Sopenharmony_ci
675a3e0fd82Sopenharmony_cibool UIView::IsDragParentInstead() const
676a3e0fd82Sopenharmony_ci{
677a3e0fd82Sopenharmony_ci    return dragParentInstead_;
678a3e0fd82Sopenharmony_ci}
679a3e0fd82Sopenharmony_ci
680a3e0fd82Sopenharmony_ci#if ENABLE_ROTATE_INPUT
681a3e0fd82Sopenharmony_cibool UIView::OnRotateStartEvent(const RotateEvent& event)
682a3e0fd82Sopenharmony_ci{
683a3e0fd82Sopenharmony_ci    if (onRotateListener_ != nullptr) {
684a3e0fd82Sopenharmony_ci        return onRotateListener_->OnRotateStart(*this, event);
685a3e0fd82Sopenharmony_ci    }
686a3e0fd82Sopenharmony_ci    return false;
687a3e0fd82Sopenharmony_ci}
688a3e0fd82Sopenharmony_ci
689a3e0fd82Sopenharmony_cibool UIView::OnRotateEvent(const RotateEvent& event)
690a3e0fd82Sopenharmony_ci{
691a3e0fd82Sopenharmony_ci    if (onRotateListener_ != nullptr) {
692a3e0fd82Sopenharmony_ci        return onRotateListener_->OnRotate(*this, event);
693a3e0fd82Sopenharmony_ci    }
694a3e0fd82Sopenharmony_ci    return isIntercept_;
695a3e0fd82Sopenharmony_ci}
696a3e0fd82Sopenharmony_ci
697a3e0fd82Sopenharmony_cibool UIView::OnRotateEndEvent(const RotateEvent& event)
698a3e0fd82Sopenharmony_ci{
699a3e0fd82Sopenharmony_ci    if (onRotateListener_ != nullptr) {
700a3e0fd82Sopenharmony_ci        return onRotateListener_->OnRotateEnd(*this, event);
701a3e0fd82Sopenharmony_ci    }
702a3e0fd82Sopenharmony_ci    return false;
703a3e0fd82Sopenharmony_ci}
704a3e0fd82Sopenharmony_ci
705a3e0fd82Sopenharmony_civoid UIView::SetOnRotateListener(OnRotateListener* onRotateListener)
706a3e0fd82Sopenharmony_ci{
707a3e0fd82Sopenharmony_ci    onRotateListener_ = onRotateListener;
708a3e0fd82Sopenharmony_ci}
709a3e0fd82Sopenharmony_ci
710a3e0fd82Sopenharmony_ci#endif
711a3e0fd82Sopenharmony_ci
712a3e0fd82Sopenharmony_civoid UIView::GetTargetView(const Point& point, UIView** last)
713a3e0fd82Sopenharmony_ci{
714a3e0fd82Sopenharmony_ci    if (last == nullptr) {
715a3e0fd82Sopenharmony_ci        return;
716a3e0fd82Sopenharmony_ci    }
717a3e0fd82Sopenharmony_ci    UIView* par = parent_;
718a3e0fd82Sopenharmony_ci    Rect rect = GetRect();
719a3e0fd82Sopenharmony_ci
720a3e0fd82Sopenharmony_ci    if (par != nullptr) {
721a3e0fd82Sopenharmony_ci        rect.Intersect(par->GetContentRect(), rect);
722a3e0fd82Sopenharmony_ci    }
723a3e0fd82Sopenharmony_ci
724a3e0fd82Sopenharmony_ci    if (visible_ && touchable_ && rect.IsContains(point)) {
725a3e0fd82Sopenharmony_ci        *last = this;
726a3e0fd82Sopenharmony_ci    }
727a3e0fd82Sopenharmony_ci}
728a3e0fd82Sopenharmony_ci
729a3e0fd82Sopenharmony_civoid UIView::GetTargetView(const Point& point, UIView** current, UIView** target)
730a3e0fd82Sopenharmony_ci{
731a3e0fd82Sopenharmony_ci    if (current == nullptr) {
732a3e0fd82Sopenharmony_ci        return;
733a3e0fd82Sopenharmony_ci    }
734a3e0fd82Sopenharmony_ci    UIView* par = parent_;
735a3e0fd82Sopenharmony_ci    Rect rect = GetRect();
736a3e0fd82Sopenharmony_ci
737a3e0fd82Sopenharmony_ci    if (par != nullptr) {
738a3e0fd82Sopenharmony_ci        rect.Intersect(par->GetOrigContentRect(), rect);
739a3e0fd82Sopenharmony_ci    }
740a3e0fd82Sopenharmony_ci
741a3e0fd82Sopenharmony_ci    if (visible_ && rect.IsContains(point)) {
742a3e0fd82Sopenharmony_ci        if (touchable_) {
743a3e0fd82Sopenharmony_ci            *current = this;
744a3e0fd82Sopenharmony_ci        }
745a3e0fd82Sopenharmony_ci        *target = this;
746a3e0fd82Sopenharmony_ci    }
747a3e0fd82Sopenharmony_ci}
748a3e0fd82Sopenharmony_ci
749a3e0fd82Sopenharmony_ci#if ENABLE_FOCUS_MANAGER
750a3e0fd82Sopenharmony_civoid UIView::SetFocusable(bool focusable)
751a3e0fd82Sopenharmony_ci{
752a3e0fd82Sopenharmony_ci    focusable_ = focusable;
753a3e0fd82Sopenharmony_ci}
754a3e0fd82Sopenharmony_ci
755a3e0fd82Sopenharmony_cibool UIView::IsFocusable() const
756a3e0fd82Sopenharmony_ci{
757a3e0fd82Sopenharmony_ci    return focusable_;
758a3e0fd82Sopenharmony_ci}
759a3e0fd82Sopenharmony_ci
760a3e0fd82Sopenharmony_civoid UIView::Focus()
761a3e0fd82Sopenharmony_ci{
762a3e0fd82Sopenharmony_ci    if (focusable_ && onFocusListener_ != nullptr) {
763a3e0fd82Sopenharmony_ci        onFocusListener_->OnFocus(*this);
764a3e0fd82Sopenharmony_ci    }
765a3e0fd82Sopenharmony_ci}
766a3e0fd82Sopenharmony_ci
767a3e0fd82Sopenharmony_civoid UIView::Blur()
768a3e0fd82Sopenharmony_ci{
769a3e0fd82Sopenharmony_ci    if (onFocusListener_ != nullptr) {
770a3e0fd82Sopenharmony_ci        onFocusListener_->OnBlur(*this);
771a3e0fd82Sopenharmony_ci    }
772a3e0fd82Sopenharmony_ci}
773a3e0fd82Sopenharmony_ci
774a3e0fd82Sopenharmony_civoid UIView::SetOnFocusListener(OnFocusListener* onFocusListener)
775a3e0fd82Sopenharmony_ci{
776a3e0fd82Sopenharmony_ci    onFocusListener_ = onFocusListener;
777a3e0fd82Sopenharmony_ci}
778a3e0fd82Sopenharmony_ci
779a3e0fd82Sopenharmony_ciUIView::OnFocusListener* UIView::GetOnFocusListener() const
780a3e0fd82Sopenharmony_ci{
781a3e0fd82Sopenharmony_ci    return onFocusListener_;
782a3e0fd82Sopenharmony_ci}
783a3e0fd82Sopenharmony_ci
784a3e0fd82Sopenharmony_ci#endif
785a3e0fd82Sopenharmony_ci
786a3e0fd82Sopenharmony_ciRect UIView::GetRect() const
787a3e0fd82Sopenharmony_ci{
788a3e0fd82Sopenharmony_ci    if ((transMap_ != nullptr) && !transMap_->IsInvalid()) {
789a3e0fd82Sopenharmony_ci        Rect r = transMap_->GetBoxRect();
790a3e0fd82Sopenharmony_ci        Rect origRect = GetOrigRect();
791a3e0fd82Sopenharmony_ci        r.SetX(r.GetX() + origRect.GetX() - transMap_->GetTransMapRect().GetX());
792a3e0fd82Sopenharmony_ci        r.SetY(r.GetY() + origRect.GetY() - transMap_->GetTransMapRect().GetY());
793a3e0fd82Sopenharmony_ci        return r;
794a3e0fd82Sopenharmony_ci    }
795a3e0fd82Sopenharmony_ci    return GetOrigRect();
796a3e0fd82Sopenharmony_ci}
797a3e0fd82Sopenharmony_ci
798a3e0fd82Sopenharmony_ciRect UIView::GetContentRect()
799a3e0fd82Sopenharmony_ci{
800a3e0fd82Sopenharmony_ci    if ((transMap_ != nullptr) && !transMap_->IsInvalid()) {
801a3e0fd82Sopenharmony_ci        Rect r = transMap_->GetBoxRect();
802a3e0fd82Sopenharmony_ci        Rect origRect = GetOrigRect();
803a3e0fd82Sopenharmony_ci        r.SetX(r.GetX() + origRect.GetX() - transMap_->GetTransMapRect().GetX());
804a3e0fd82Sopenharmony_ci        r.SetY(r.GetY() + origRect.GetY() - transMap_->GetTransMapRect().GetY());
805a3e0fd82Sopenharmony_ci        return r;
806a3e0fd82Sopenharmony_ci    }
807a3e0fd82Sopenharmony_ci
808a3e0fd82Sopenharmony_ci    Rect contentRect = GetRect();
809a3e0fd82Sopenharmony_ci    contentRect.SetX(contentRect.GetX() + style_->paddingLeft_ + style_->borderWidth_);
810a3e0fd82Sopenharmony_ci    contentRect.SetY(contentRect.GetY() + style_->paddingTop_ + style_->borderWidth_);
811a3e0fd82Sopenharmony_ci    contentRect.SetWidth(GetWidth());
812a3e0fd82Sopenharmony_ci    contentRect.SetHeight(GetHeight());
813a3e0fd82Sopenharmony_ci    return contentRect;
814a3e0fd82Sopenharmony_ci}
815a3e0fd82Sopenharmony_ci
816a3e0fd82Sopenharmony_ciRect UIView::GetOrigContentRect()
817a3e0fd82Sopenharmony_ci{
818a3e0fd82Sopenharmony_ci    Rect contentRect = GetOrigRect();
819a3e0fd82Sopenharmony_ci    contentRect.SetX(contentRect.GetX() + style_->paddingLeft_ + style_->borderWidth_);
820a3e0fd82Sopenharmony_ci    contentRect.SetY(contentRect.GetY() + style_->paddingTop_ + style_->borderWidth_);
821a3e0fd82Sopenharmony_ci    contentRect.SetWidth(GetWidth());
822a3e0fd82Sopenharmony_ci    contentRect.SetHeight(GetHeight());
823a3e0fd82Sopenharmony_ci    return contentRect;
824a3e0fd82Sopenharmony_ci}
825a3e0fd82Sopenharmony_ci
826a3e0fd82Sopenharmony_ciRect UIView::GetOrigRect() const
827a3e0fd82Sopenharmony_ci{
828a3e0fd82Sopenharmony_ci    int16_t x = rect_.GetX();
829a3e0fd82Sopenharmony_ci    int16_t y = rect_.GetY();
830a3e0fd82Sopenharmony_ci    UIView* par = parent_;
831a3e0fd82Sopenharmony_ci    while (par != nullptr) {
832a3e0fd82Sopenharmony_ci        x += par->GetRelativeRect().GetX() + par->GetStyle(STYLE_PADDING_LEFT) + par->GetStyle(STYLE_BORDER_WIDTH);
833a3e0fd82Sopenharmony_ci        y += par->GetRelativeRect().GetY() + par->GetStyle(STYLE_PADDING_TOP) + par->GetStyle(STYLE_BORDER_WIDTH);
834a3e0fd82Sopenharmony_ci        par = par->parent_;
835a3e0fd82Sopenharmony_ci    }
836a3e0fd82Sopenharmony_ci    return Rect(x, y, x + rect_.GetWidth() - 1, y + rect_.GetHeight() - 1);
837a3e0fd82Sopenharmony_ci}
838a3e0fd82Sopenharmony_ci
839a3e0fd82Sopenharmony_ciRect UIView::GetMaskedRect() const
840a3e0fd82Sopenharmony_ci{
841a3e0fd82Sopenharmony_ci    Rect mask;
842a3e0fd82Sopenharmony_ci    if (visibleRect_ != nullptr) {
843a3e0fd82Sopenharmony_ci        mask.Intersect(GetRect(), GetVisibleRect());
844a3e0fd82Sopenharmony_ci    } else {
845a3e0fd82Sopenharmony_ci        mask = GetRect();
846a3e0fd82Sopenharmony_ci    }
847a3e0fd82Sopenharmony_ci    return mask;
848a3e0fd82Sopenharmony_ci}
849a3e0fd82Sopenharmony_ci
850a3e0fd82Sopenharmony_ciRect UIView::GetVisibleRect() const
851a3e0fd82Sopenharmony_ci{
852a3e0fd82Sopenharmony_ci    if (visibleRect_ == nullptr) {
853a3e0fd82Sopenharmony_ci        return GetRect();
854a3e0fd82Sopenharmony_ci    }
855a3e0fd82Sopenharmony_ci    Rect absoluteRect;
856a3e0fd82Sopenharmony_ci    int16_t x = visibleRect_->GetX();
857a3e0fd82Sopenharmony_ci    int16_t y = visibleRect_->GetY();
858a3e0fd82Sopenharmony_ci    UIView* par = parent_;
859a3e0fd82Sopenharmony_ci    while (par != nullptr) {
860a3e0fd82Sopenharmony_ci        x += par->GetX();
861a3e0fd82Sopenharmony_ci        y += par->GetY();
862a3e0fd82Sopenharmony_ci        par = par->parent_;
863a3e0fd82Sopenharmony_ci    }
864a3e0fd82Sopenharmony_ci    absoluteRect.SetX(x);
865a3e0fd82Sopenharmony_ci    absoluteRect.SetY(y);
866a3e0fd82Sopenharmony_ci    absoluteRect.SetWidth(visibleRect_->GetWidth());
867a3e0fd82Sopenharmony_ci    absoluteRect.SetHeight(visibleRect_->GetHeight());
868a3e0fd82Sopenharmony_ci    return absoluteRect;
869a3e0fd82Sopenharmony_ci}
870a3e0fd82Sopenharmony_ci
871a3e0fd82Sopenharmony_civoid UIView::SetTransformMap(const TransformMap& transMap)
872a3e0fd82Sopenharmony_ci{
873a3e0fd82Sopenharmony_ci    if ((transMap_ != nullptr) && (*transMap_ == transMap)) {
874a3e0fd82Sopenharmony_ci        return;
875a3e0fd82Sopenharmony_ci    }
876a3e0fd82Sopenharmony_ci
877a3e0fd82Sopenharmony_ci    if (transMap_ == nullptr) {
878a3e0fd82Sopenharmony_ci        transMap_ = new TransformMap();
879a3e0fd82Sopenharmony_ci    }
880a3e0fd82Sopenharmony_ci    Rect preRect = GetRect();
881a3e0fd82Sopenharmony_ci    *transMap_ = transMap;
882a3e0fd82Sopenharmony_ci    transMap_->SetTransMapRect(GetOrigRect());
883a3e0fd82Sopenharmony_ci
884a3e0fd82Sopenharmony_ci    Rect joinRect;
885a3e0fd82Sopenharmony_ci    joinRect.Join(preRect, transMap_->GetBoxRect());
886a3e0fd82Sopenharmony_ci    InvalidateRect(joinRect);
887a3e0fd82Sopenharmony_ci}
888a3e0fd82Sopenharmony_ci
889a3e0fd82Sopenharmony_civoid UIView::SetWidth(int16_t width)
890a3e0fd82Sopenharmony_ci{
891a3e0fd82Sopenharmony_ci    if (GetWidth() != width) {
892a3e0fd82Sopenharmony_ci        int16_t newWidth = width + style_->paddingLeft_ + style_->paddingRight_ +
893a3e0fd82Sopenharmony_ci                           (style_->borderWidth_ * 2); /* 2: left and right border */
894a3e0fd82Sopenharmony_ci        rect_.SetWidth(newWidth);
895a3e0fd82Sopenharmony_ci    }
896a3e0fd82Sopenharmony_ci}
897a3e0fd82Sopenharmony_ci
898a3e0fd82Sopenharmony_civoid UIView::SetWidthPercent(float widthPercent)
899a3e0fd82Sopenharmony_ci{
900a3e0fd82Sopenharmony_ci    if (IsInvalid(widthPercent)) {
901a3e0fd82Sopenharmony_ci        return;
902a3e0fd82Sopenharmony_ci    }
903a3e0fd82Sopenharmony_ci    if ((GetParent() != nullptr) && (GetParent()->GetWidth() > 1)) {
904a3e0fd82Sopenharmony_ci        int16_t newWidth = static_cast<int16_t>(GetParent()->GetWidth() * widthPercent);
905a3e0fd82Sopenharmony_ci        SetWidth(newWidth);
906a3e0fd82Sopenharmony_ci    }
907a3e0fd82Sopenharmony_ci}
908a3e0fd82Sopenharmony_ci
909a3e0fd82Sopenharmony_ciint16_t UIView::GetWidth()
910a3e0fd82Sopenharmony_ci{
911a3e0fd82Sopenharmony_ci    return rect_.GetWidth() - (style_->paddingLeft_ + style_->paddingRight_) -
912a3e0fd82Sopenharmony_ci           (style_->borderWidth_ * 2); /* 2: left and right border */
913a3e0fd82Sopenharmony_ci}
914a3e0fd82Sopenharmony_ci
915a3e0fd82Sopenharmony_civoid UIView::SetHeight(int16_t height)
916a3e0fd82Sopenharmony_ci{
917a3e0fd82Sopenharmony_ci    if (GetHeight() != height) {
918a3e0fd82Sopenharmony_ci        int16_t newHeight = height + style_->paddingTop_ + style_->paddingBottom_ +
919a3e0fd82Sopenharmony_ci                            (style_->borderWidth_ * 2); /* 2: top and bottom border */
920a3e0fd82Sopenharmony_ci        rect_.SetHeight(newHeight);
921a3e0fd82Sopenharmony_ci    }
922a3e0fd82Sopenharmony_ci}
923a3e0fd82Sopenharmony_ci
924a3e0fd82Sopenharmony_civoid UIView::SetHeightPercent(float heightPercent)
925a3e0fd82Sopenharmony_ci{
926a3e0fd82Sopenharmony_ci    if (IsInvalid(heightPercent)) {
927a3e0fd82Sopenharmony_ci        return;
928a3e0fd82Sopenharmony_ci    }
929a3e0fd82Sopenharmony_ci    if ((GetParent() != nullptr) && (GetParent()->GetHeight() > 1)) {
930a3e0fd82Sopenharmony_ci        int16_t newHeight = static_cast<int16_t>(GetParent()->GetHeight() * heightPercent);
931a3e0fd82Sopenharmony_ci        SetHeight(newHeight);
932a3e0fd82Sopenharmony_ci    }
933a3e0fd82Sopenharmony_ci}
934a3e0fd82Sopenharmony_ci
935a3e0fd82Sopenharmony_ciint16_t UIView::GetHeight()
936a3e0fd82Sopenharmony_ci{
937a3e0fd82Sopenharmony_ci    return rect_.GetHeight() - (style_->paddingTop_ + style_->paddingBottom_) -
938a3e0fd82Sopenharmony_ci           (style_->borderWidth_ * 2); /* 2: top and bottom border */
939a3e0fd82Sopenharmony_ci}
940a3e0fd82Sopenharmony_ci
941a3e0fd82Sopenharmony_civoid UIView::Resize(int16_t width, int16_t height)
942a3e0fd82Sopenharmony_ci{
943a3e0fd82Sopenharmony_ci    SetWidth(width);
944a3e0fd82Sopenharmony_ci    SetHeight(height);
945a3e0fd82Sopenharmony_ci}
946a3e0fd82Sopenharmony_ci
947a3e0fd82Sopenharmony_civoid UIView::ResizePercent(float widthPercent, float heightPercent)
948a3e0fd82Sopenharmony_ci{
949a3e0fd82Sopenharmony_ci    if (IsInvalid(widthPercent) || IsInvalid(heightPercent)) {
950a3e0fd82Sopenharmony_ci        return;
951a3e0fd82Sopenharmony_ci    }
952a3e0fd82Sopenharmony_ci    if ((GetParent() != nullptr) && (GetParent()->GetWidth() > 1) && (GetParent()->GetHeight() > 1)) {
953a3e0fd82Sopenharmony_ci        int16_t newWidth = static_cast<int16_t>(GetParent()->GetWidth() * widthPercent);
954a3e0fd82Sopenharmony_ci        int16_t newHeight = static_cast<int16_t>(GetParent()->GetHeight() * heightPercent);
955a3e0fd82Sopenharmony_ci        Resize(newWidth, newHeight);
956a3e0fd82Sopenharmony_ci    }
957a3e0fd82Sopenharmony_ci}
958a3e0fd82Sopenharmony_ci
959a3e0fd82Sopenharmony_civoid UIView::SetX(int16_t x)
960a3e0fd82Sopenharmony_ci{
961a3e0fd82Sopenharmony_ci    if (GetX() != x) {
962a3e0fd82Sopenharmony_ci        rect_.SetX(x + GetStyle(STYLE_MARGIN_LEFT));
963a3e0fd82Sopenharmony_ci    }
964a3e0fd82Sopenharmony_ci}
965a3e0fd82Sopenharmony_ci
966a3e0fd82Sopenharmony_civoid UIView::SetXPercent(float xPercent)
967a3e0fd82Sopenharmony_ci{
968a3e0fd82Sopenharmony_ci    if (IsInvalid(xPercent)) {
969a3e0fd82Sopenharmony_ci        return;
970a3e0fd82Sopenharmony_ci    }
971a3e0fd82Sopenharmony_ci    if ((GetParent() != nullptr) && (GetParent()->GetWidth() > 1)) {
972a3e0fd82Sopenharmony_ci        int16_t newX = static_cast<int16_t>(GetParent()->GetWidth() * xPercent);
973a3e0fd82Sopenharmony_ci        SetX(newX);
974a3e0fd82Sopenharmony_ci    }
975a3e0fd82Sopenharmony_ci}
976a3e0fd82Sopenharmony_ci
977a3e0fd82Sopenharmony_ciint16_t UIView::GetX() const
978a3e0fd82Sopenharmony_ci{
979a3e0fd82Sopenharmony_ci    return rect_.GetX() - GetStyle(STYLE_MARGIN_LEFT);
980a3e0fd82Sopenharmony_ci}
981a3e0fd82Sopenharmony_ci
982a3e0fd82Sopenharmony_civoid UIView::SetY(int16_t y)
983a3e0fd82Sopenharmony_ci{
984a3e0fd82Sopenharmony_ci    if (GetY() != y) {
985a3e0fd82Sopenharmony_ci        rect_.SetY(y + GetStyle(STYLE_MARGIN_TOP));
986a3e0fd82Sopenharmony_ci    }
987a3e0fd82Sopenharmony_ci}
988a3e0fd82Sopenharmony_ci
989a3e0fd82Sopenharmony_civoid UIView::SetYPercent(float yPercent)
990a3e0fd82Sopenharmony_ci{
991a3e0fd82Sopenharmony_ci    if (IsInvalid(yPercent)) {
992a3e0fd82Sopenharmony_ci        return;
993a3e0fd82Sopenharmony_ci    }
994a3e0fd82Sopenharmony_ci    if ((GetParent() != nullptr) && (GetParent()->GetHeight() > 1)) {
995a3e0fd82Sopenharmony_ci        int16_t newY = static_cast<int16_t>(GetParent()->GetHeight() * yPercent);
996a3e0fd82Sopenharmony_ci        SetY(newY);
997a3e0fd82Sopenharmony_ci    }
998a3e0fd82Sopenharmony_ci}
999a3e0fd82Sopenharmony_ci
1000a3e0fd82Sopenharmony_ciint16_t UIView::GetY() const
1001a3e0fd82Sopenharmony_ci{
1002a3e0fd82Sopenharmony_ci    return rect_.GetY() - GetStyle(STYLE_MARGIN_TOP);
1003a3e0fd82Sopenharmony_ci}
1004a3e0fd82Sopenharmony_ci
1005a3e0fd82Sopenharmony_civoid UIView::SetPosition(int16_t x, int16_t y)
1006a3e0fd82Sopenharmony_ci{
1007a3e0fd82Sopenharmony_ci    SetX(x);
1008a3e0fd82Sopenharmony_ci    SetY(y);
1009a3e0fd82Sopenharmony_ci}
1010a3e0fd82Sopenharmony_ci
1011a3e0fd82Sopenharmony_civoid UIView::SetPositionPercent(float xPercent, float yPercent)
1012a3e0fd82Sopenharmony_ci{
1013a3e0fd82Sopenharmony_ci    if (IsInvalid(xPercent) || IsInvalid(yPercent)) {
1014a3e0fd82Sopenharmony_ci        return;
1015a3e0fd82Sopenharmony_ci    }
1016a3e0fd82Sopenharmony_ci    if ((GetParent() != nullptr) && (GetParent()->GetWidth() > 1) && (GetParent()->GetHeight() > 1)) {
1017a3e0fd82Sopenharmony_ci        int16_t newX = static_cast<int16_t>(GetParent()->GetWidth() * xPercent);
1018a3e0fd82Sopenharmony_ci        int16_t newY = static_cast<int16_t>(GetParent()->GetHeight() * yPercent);
1019a3e0fd82Sopenharmony_ci        SetPosition(newX, newY);
1020a3e0fd82Sopenharmony_ci    }
1021a3e0fd82Sopenharmony_ci}
1022a3e0fd82Sopenharmony_ci
1023a3e0fd82Sopenharmony_civoid UIView::SetPosition(int16_t x, int16_t y, int16_t width, int16_t height)
1024a3e0fd82Sopenharmony_ci{
1025a3e0fd82Sopenharmony_ci    SetPosition(x, y);
1026a3e0fd82Sopenharmony_ci    SetWidth(width);
1027a3e0fd82Sopenharmony_ci    SetHeight(height);
1028a3e0fd82Sopenharmony_ci}
1029a3e0fd82Sopenharmony_ci
1030a3e0fd82Sopenharmony_civoid UIView::SetPositionPercent(float xPercent, float yPercent, float widthPercent, float heightPercent)
1031a3e0fd82Sopenharmony_ci{
1032a3e0fd82Sopenharmony_ci    if (IsInvalid(xPercent) || IsInvalid(yPercent) || IsInvalid(widthPercent) || IsInvalid(heightPercent)) {
1033a3e0fd82Sopenharmony_ci        return;
1034a3e0fd82Sopenharmony_ci    }
1035a3e0fd82Sopenharmony_ci    if ((GetParent() != nullptr) && (GetParent()->GetWidth() > 1) && (GetParent()->GetHeight() > 1)) {
1036a3e0fd82Sopenharmony_ci        int16_t newX = static_cast<int16_t>(GetParent()->GetWidth() * xPercent);
1037a3e0fd82Sopenharmony_ci        int16_t newY = static_cast<int16_t>(GetParent()->GetHeight() * yPercent);
1038a3e0fd82Sopenharmony_ci        int16_t newWidth = static_cast<int16_t>(GetParent()->GetWidth() * widthPercent);
1039a3e0fd82Sopenharmony_ci        int16_t newHeight = static_cast<int16_t>(GetParent()->GetHeight() * heightPercent);
1040a3e0fd82Sopenharmony_ci        SetPosition(newX, newY, newWidth, newHeight);
1041a3e0fd82Sopenharmony_ci    }
1042a3e0fd82Sopenharmony_ci}
1043a3e0fd82Sopenharmony_ci
1044a3e0fd82Sopenharmony_cibool UIView::IsViewGroup() const
1045a3e0fd82Sopenharmony_ci{
1046a3e0fd82Sopenharmony_ci    return isViewGroup_;
1047a3e0fd82Sopenharmony_ci}
1048a3e0fd82Sopenharmony_ci
1049a3e0fd82Sopenharmony_civoid UIView::SetIntercept(bool isIntercept)
1050a3e0fd82Sopenharmony_ci{
1051a3e0fd82Sopenharmony_ci    isIntercept_ = isIntercept;
1052a3e0fd82Sopenharmony_ci}
1053a3e0fd82Sopenharmony_ci
1054a3e0fd82Sopenharmony_cibool UIView::IsIntercept()
1055a3e0fd82Sopenharmony_ci{
1056a3e0fd82Sopenharmony_ci    return isIntercept_;
1057a3e0fd82Sopenharmony_ci}
1058a3e0fd82Sopenharmony_ci
1059a3e0fd82Sopenharmony_cibool UIView::IsInvalid(float percent)
1060a3e0fd82Sopenharmony_ci{
1061a3e0fd82Sopenharmony_ci    if ((percent < 1) && (percent > 0)) {
1062a3e0fd82Sopenharmony_ci        return false;
1063a3e0fd82Sopenharmony_ci    }
1064a3e0fd82Sopenharmony_ci    return true;
1065a3e0fd82Sopenharmony_ci}
1066a3e0fd82Sopenharmony_ci
1067a3e0fd82Sopenharmony_ciTransformMap& UIView::GetTransformMap()
1068a3e0fd82Sopenharmony_ci{
1069a3e0fd82Sopenharmony_ci    if (transMap_ == nullptr) {
1070a3e0fd82Sopenharmony_ci        transMap_ = new TransformMap();
1071a3e0fd82Sopenharmony_ci    }
1072a3e0fd82Sopenharmony_ci    return *transMap_;
1073a3e0fd82Sopenharmony_ci}
1074a3e0fd82Sopenharmony_ci
1075a3e0fd82Sopenharmony_ciUIView* UIView::GetChildById(const char* id) const
1076a3e0fd82Sopenharmony_ci{
1077a3e0fd82Sopenharmony_ci    return nullptr;
1078a3e0fd82Sopenharmony_ci}
1079a3e0fd82Sopenharmony_ci
1080a3e0fd82Sopenharmony_civoid UIView::SetViewId(const char* id)
1081a3e0fd82Sopenharmony_ci{
1082a3e0fd82Sopenharmony_ci    id_ = id;
1083a3e0fd82Sopenharmony_ci}
1084a3e0fd82Sopenharmony_ci
1085a3e0fd82Sopenharmony_ciconst char* UIView::GetViewId() const
1086a3e0fd82Sopenharmony_ci{
1087a3e0fd82Sopenharmony_ci    return id_;
1088a3e0fd82Sopenharmony_ci}
1089a3e0fd82Sopenharmony_ci
1090a3e0fd82Sopenharmony_civoid UIView::SetViewIndex(int16_t index)
1091a3e0fd82Sopenharmony_ci{
1092a3e0fd82Sopenharmony_ci    index_ = index;
1093a3e0fd82Sopenharmony_ci}
1094a3e0fd82Sopenharmony_ci
1095a3e0fd82Sopenharmony_ciint16_t UIView::GetViewIndex() const
1096a3e0fd82Sopenharmony_ci{
1097a3e0fd82Sopenharmony_ci    return index_;
1098a3e0fd82Sopenharmony_ci}
1099a3e0fd82Sopenharmony_ci
1100a3e0fd82Sopenharmony_ciUIViewType UIView::GetViewType() const
1101a3e0fd82Sopenharmony_ci{
1102a3e0fd82Sopenharmony_ci    return UI_NUMBER_MAX;
1103a3e0fd82Sopenharmony_ci}
1104a3e0fd82Sopenharmony_ci
1105a3e0fd82Sopenharmony_civoid UIView::LayoutCenterOfParent(int16_t xOffset, int16_t yOffset)
1106a3e0fd82Sopenharmony_ci{
1107a3e0fd82Sopenharmony_ci    if (parent_ == nullptr) {
1108a3e0fd82Sopenharmony_ci        return;
1109a3e0fd82Sopenharmony_ci    }
1110a3e0fd82Sopenharmony_ci
1111a3e0fd82Sopenharmony_ci    int16_t topMargin = style_->marginTop_;
1112a3e0fd82Sopenharmony_ci    int16_t leftMargin = style_->marginLeft_;
1113a3e0fd82Sopenharmony_ci    int16_t rightMargin = style_->marginRight_;
1114a3e0fd82Sopenharmony_ci    int16_t bottomMargin = style_->marginBottom_;
1115a3e0fd82Sopenharmony_ci    // 2: half
1116a3e0fd82Sopenharmony_ci    int16_t posX = parent_->GetWidth() / 2 - (rect_.GetWidth() - leftMargin + rightMargin) / 2 + xOffset;
1117a3e0fd82Sopenharmony_ci    // 2: half
1118a3e0fd82Sopenharmony_ci    int16_t posY = parent_->GetHeight() / 2 - (rect_.GetHeight() - topMargin + bottomMargin) / 2 + yOffset;
1119a3e0fd82Sopenharmony_ci    SetPosition(posX, posY);
1120a3e0fd82Sopenharmony_ci}
1121a3e0fd82Sopenharmony_ci
1122a3e0fd82Sopenharmony_civoid UIView::LayoutLeftOfParent(int16_t offset)
1123a3e0fd82Sopenharmony_ci{
1124a3e0fd82Sopenharmony_ci    if (parent_ == nullptr) {
1125a3e0fd82Sopenharmony_ci        return;
1126a3e0fd82Sopenharmony_ci    }
1127a3e0fd82Sopenharmony_ci
1128a3e0fd82Sopenharmony_ci    int16_t leftMargin = style_->marginLeft_;
1129a3e0fd82Sopenharmony_ci    SetPosition(leftMargin + offset, GetY());
1130a3e0fd82Sopenharmony_ci}
1131a3e0fd82Sopenharmony_ci
1132a3e0fd82Sopenharmony_civoid UIView::LayoutRightOfParent(int16_t offset)
1133a3e0fd82Sopenharmony_ci{
1134a3e0fd82Sopenharmony_ci    if (parent_ == nullptr) {
1135a3e0fd82Sopenharmony_ci        return;
1136a3e0fd82Sopenharmony_ci    }
1137a3e0fd82Sopenharmony_ci
1138a3e0fd82Sopenharmony_ci    int16_t rightMargin = style_->marginRight_;
1139a3e0fd82Sopenharmony_ci    SetPosition(parent_->GetWidth() - offset - rect_.GetWidth() - rightMargin, GetY());
1140a3e0fd82Sopenharmony_ci}
1141a3e0fd82Sopenharmony_ci
1142a3e0fd82Sopenharmony_civoid UIView::LayoutTopOfParent(int16_t offset)
1143a3e0fd82Sopenharmony_ci{
1144a3e0fd82Sopenharmony_ci    if (parent_ == nullptr) {
1145a3e0fd82Sopenharmony_ci        return;
1146a3e0fd82Sopenharmony_ci    }
1147a3e0fd82Sopenharmony_ci
1148a3e0fd82Sopenharmony_ci    int16_t topMargin = style_->marginTop_;
1149a3e0fd82Sopenharmony_ci    SetPosition(GetX(), topMargin + offset);
1150a3e0fd82Sopenharmony_ci}
1151a3e0fd82Sopenharmony_ci
1152a3e0fd82Sopenharmony_civoid UIView::LayoutBottomOfParent(int16_t offset)
1153a3e0fd82Sopenharmony_ci{
1154a3e0fd82Sopenharmony_ci    if (parent_ == nullptr) {
1155a3e0fd82Sopenharmony_ci        return;
1156a3e0fd82Sopenharmony_ci    }
1157a3e0fd82Sopenharmony_ci
1158a3e0fd82Sopenharmony_ci    int16_t bottomMargin = style_->marginBottom_;
1159a3e0fd82Sopenharmony_ci    SetPosition(GetX(), parent_->GetHeight() - offset - rect_.GetHeight() - bottomMargin);
1160a3e0fd82Sopenharmony_ci}
1161a3e0fd82Sopenharmony_ci
1162a3e0fd82Sopenharmony_civoid UIView::AlignLeftToSibling(const char* id, int16_t offset)
1163a3e0fd82Sopenharmony_ci{
1164a3e0fd82Sopenharmony_ci    if (parent_ == nullptr) {
1165a3e0fd82Sopenharmony_ci        return;
1166a3e0fd82Sopenharmony_ci    }
1167a3e0fd82Sopenharmony_ci    UIView* sib = parent_->GetChildById(id);
1168a3e0fd82Sopenharmony_ci    if (sib != nullptr) {
1169a3e0fd82Sopenharmony_ci        int16_t margin = sib->style_->marginLeft_ - style_->marginLeft_;
1170a3e0fd82Sopenharmony_ci        SetPosition(sib->GetX() - margin + offset, GetY());
1171a3e0fd82Sopenharmony_ci    }
1172a3e0fd82Sopenharmony_ci}
1173a3e0fd82Sopenharmony_ci
1174a3e0fd82Sopenharmony_civoid UIView::AlignRightToSibling(const char* id, int16_t offset)
1175a3e0fd82Sopenharmony_ci{
1176a3e0fd82Sopenharmony_ci    if (parent_ == nullptr) {
1177a3e0fd82Sopenharmony_ci        return;
1178a3e0fd82Sopenharmony_ci    }
1179a3e0fd82Sopenharmony_ci    UIView* sib = parent_->GetChildById(id);
1180a3e0fd82Sopenharmony_ci    if (sib != nullptr) {
1181a3e0fd82Sopenharmony_ci        int16_t margin = sib->style_->marginRight_ - style_->marginRight_;
1182a3e0fd82Sopenharmony_ci        SetPosition(sib->GetX() + sib->rect_.GetWidth() - rect_.GetWidth() - offset + margin, GetY());
1183a3e0fd82Sopenharmony_ci    }
1184a3e0fd82Sopenharmony_ci}
1185a3e0fd82Sopenharmony_ci
1186a3e0fd82Sopenharmony_civoid UIView::AlignTopToSibling(const char* id, int16_t offset)
1187a3e0fd82Sopenharmony_ci{
1188a3e0fd82Sopenharmony_ci    if (parent_ == nullptr) {
1189a3e0fd82Sopenharmony_ci        return;
1190a3e0fd82Sopenharmony_ci    }
1191a3e0fd82Sopenharmony_ci    UIView* sib = parent_->GetChildById(id);
1192a3e0fd82Sopenharmony_ci    if (sib != nullptr) {
1193a3e0fd82Sopenharmony_ci        int16_t margin = sib->style_->marginTop_ - style_->marginTop_;
1194a3e0fd82Sopenharmony_ci        SetPosition(GetX(), sib->GetY() + offset - margin);
1195a3e0fd82Sopenharmony_ci    }
1196a3e0fd82Sopenharmony_ci}
1197a3e0fd82Sopenharmony_ci
1198a3e0fd82Sopenharmony_civoid UIView::AlignBottomToSibling(const char* id, int16_t offset)
1199a3e0fd82Sopenharmony_ci{
1200a3e0fd82Sopenharmony_ci    if (parent_ == nullptr) {
1201a3e0fd82Sopenharmony_ci        return;
1202a3e0fd82Sopenharmony_ci    }
1203a3e0fd82Sopenharmony_ci    UIView* sib = parent_->GetChildById(id);
1204a3e0fd82Sopenharmony_ci    if (sib != nullptr) {
1205a3e0fd82Sopenharmony_ci        int16_t margin = sib->style_->marginBottom_ - style_->marginBottom_;
1206a3e0fd82Sopenharmony_ci        SetPosition(GetX(), sib->GetY() + sib->rect_.GetHeight() - rect_.GetHeight() - offset + margin);
1207a3e0fd82Sopenharmony_ci    }
1208a3e0fd82Sopenharmony_ci}
1209a3e0fd82Sopenharmony_ci
1210a3e0fd82Sopenharmony_civoid UIView::AlignHorCenterToSibling(const char* id, int16_t offset)
1211a3e0fd82Sopenharmony_ci{
1212a3e0fd82Sopenharmony_ci    if (parent_ == nullptr) {
1213a3e0fd82Sopenharmony_ci        return;
1214a3e0fd82Sopenharmony_ci    }
1215a3e0fd82Sopenharmony_ci    UIView* sib = parent_->GetChildById(id);
1216a3e0fd82Sopenharmony_ci    if (sib != nullptr) {
1217a3e0fd82Sopenharmony_ci        int16_t margin =
1218a3e0fd82Sopenharmony_ci            (sib->style_->marginRight_ - sib->style_->marginLeft_ - style_->marginRight_ + style_->marginLeft_) /
1219a3e0fd82Sopenharmony_ci            2; // 2 : half
1220a3e0fd82Sopenharmony_ci        SetPosition(sib->GetX() + sib->rect_.GetWidth() / 2 - rect_.GetWidth() / 2 + margin + offset, GetY());
1221a3e0fd82Sopenharmony_ci    }
1222a3e0fd82Sopenharmony_ci}
1223a3e0fd82Sopenharmony_civoid UIView::AlignVerCenterToSibling(const char* id, int16_t offset)
1224a3e0fd82Sopenharmony_ci{
1225a3e0fd82Sopenharmony_ci    if (parent_ == nullptr) {
1226a3e0fd82Sopenharmony_ci        return;
1227a3e0fd82Sopenharmony_ci    }
1228a3e0fd82Sopenharmony_ci    UIView* sib = parent_->GetChildById(id);
1229a3e0fd82Sopenharmony_ci    if (sib != nullptr) {
1230a3e0fd82Sopenharmony_ci        int16_t margin =
1231a3e0fd82Sopenharmony_ci            (sib->style_->marginBottom_ - sib->style_->marginTop_ - style_->marginBottom_ + style_->marginTop_) /
1232a3e0fd82Sopenharmony_ci            2; // 2 : half
1233a3e0fd82Sopenharmony_ci        SetPosition(GetX(), sib->GetY() + sib->rect_.GetHeight() / 2 - rect_.GetHeight() / 2 + margin + offset);
1234a3e0fd82Sopenharmony_ci    }
1235a3e0fd82Sopenharmony_ci}
1236a3e0fd82Sopenharmony_ci
1237a3e0fd82Sopenharmony_civoid UIView::LayoutLeftToSibling(const char* id, int16_t offset)
1238a3e0fd82Sopenharmony_ci{
1239a3e0fd82Sopenharmony_ci    if (parent_ == nullptr) {
1240a3e0fd82Sopenharmony_ci        return;
1241a3e0fd82Sopenharmony_ci    }
1242a3e0fd82Sopenharmony_ci    UIView* sib = parent_->GetChildById(id);
1243a3e0fd82Sopenharmony_ci    if (sib != nullptr) {
1244a3e0fd82Sopenharmony_ci        int16_t margin = sib->style_->marginLeft_ + style_->marginRight_;
1245a3e0fd82Sopenharmony_ci        SetPosition(sib->GetX() - offset - rect_.GetWidth() - margin, GetY());
1246a3e0fd82Sopenharmony_ci    }
1247a3e0fd82Sopenharmony_ci}
1248a3e0fd82Sopenharmony_ci
1249a3e0fd82Sopenharmony_civoid UIView::LayoutRightToSibling(const char* id, int16_t offset)
1250a3e0fd82Sopenharmony_ci{
1251a3e0fd82Sopenharmony_ci    if (parent_ == nullptr) {
1252a3e0fd82Sopenharmony_ci        return;
1253a3e0fd82Sopenharmony_ci    }
1254a3e0fd82Sopenharmony_ci    UIView* sib = parent_->GetChildById(id);
1255a3e0fd82Sopenharmony_ci    if (sib != nullptr) {
1256a3e0fd82Sopenharmony_ci        int16_t margin = sib->style_->marginRight_ + style_->marginLeft_;
1257a3e0fd82Sopenharmony_ci        SetPosition(sib->GetX() + sib->rect_.GetWidth() + offset + margin, GetY());
1258a3e0fd82Sopenharmony_ci    }
1259a3e0fd82Sopenharmony_ci}
1260a3e0fd82Sopenharmony_ci
1261a3e0fd82Sopenharmony_civoid UIView::LayoutTopToSibling(const char* id, int16_t offset)
1262a3e0fd82Sopenharmony_ci{
1263a3e0fd82Sopenharmony_ci    if (parent_ == nullptr) {
1264a3e0fd82Sopenharmony_ci        return;
1265a3e0fd82Sopenharmony_ci    }
1266a3e0fd82Sopenharmony_ci    UIView* sib = parent_->GetChildById(id);
1267a3e0fd82Sopenharmony_ci    if (sib != nullptr) {
1268a3e0fd82Sopenharmony_ci        int16_t margin = sib->style_->marginTop_ + style_->marginBottom_;
1269a3e0fd82Sopenharmony_ci        SetPosition(GetX(), sib->GetY() - offset - rect_.GetHeight() - margin);
1270a3e0fd82Sopenharmony_ci    }
1271a3e0fd82Sopenharmony_ci}
1272a3e0fd82Sopenharmony_ci
1273a3e0fd82Sopenharmony_civoid UIView::LayoutBottomToSibling(const char* id, int16_t offset)
1274a3e0fd82Sopenharmony_ci{
1275a3e0fd82Sopenharmony_ci    if (parent_ == nullptr) {
1276a3e0fd82Sopenharmony_ci        return;
1277a3e0fd82Sopenharmony_ci    }
1278a3e0fd82Sopenharmony_ci    UIView* sib = parent_->GetChildById(id);
1279a3e0fd82Sopenharmony_ci    if (sib != nullptr) {
1280a3e0fd82Sopenharmony_ci        int16_t margin = sib->style_->marginBottom_ + style_->marginTop_;
1281a3e0fd82Sopenharmony_ci        SetPosition(GetX(), sib->GetY() + sib->rect_.GetHeight() + offset + margin);
1282a3e0fd82Sopenharmony_ci    }
1283a3e0fd82Sopenharmony_ci}
1284a3e0fd82Sopenharmony_ci
1285a3e0fd82Sopenharmony_ciuint8_t UIView::GetMixOpaScale() const
1286a3e0fd82Sopenharmony_ci{
1287a3e0fd82Sopenharmony_ci    uint8_t opaMix = opaScale_;
1288a3e0fd82Sopenharmony_ci    UIView* parent = parent_;
1289a3e0fd82Sopenharmony_ci    while (parent != nullptr) {
1290a3e0fd82Sopenharmony_ci        uint8_t opaParent = parent->GetOpaScale();
1291a3e0fd82Sopenharmony_ci        // 8: Shift right 8 bits
1292a3e0fd82Sopenharmony_ci        opaMix = (opaParent == OPA_OPAQUE) ? opaMix : ((static_cast<uint16_t>(opaParent) * opaMix) >> 8);
1293a3e0fd82Sopenharmony_ci        parent = parent->GetParent();
1294a3e0fd82Sopenharmony_ci    }
1295a3e0fd82Sopenharmony_ci    return opaMix;
1296a3e0fd82Sopenharmony_ci}
1297a3e0fd82Sopenharmony_ci
1298a3e0fd82Sopenharmony_cibool UIView::GetBitmap(ImageInfo& imageInfo, ColorMode colorMode)
1299a3e0fd82Sopenharmony_ci{
1300a3e0fd82Sopenharmony_ci    UIView* tempRenderSibling = nextRenderSibling_;
1301a3e0fd82Sopenharmony_ci    nextRenderSibling_ = nullptr;
1302a3e0fd82Sopenharmony_ci    UIView* tempParent = parent_;
1303a3e0fd82Sopenharmony_ci    parent_ = nullptr;
1304a3e0fd82Sopenharmony_ci    int16_t tempX = rect_.GetX();
1305a3e0fd82Sopenharmony_ci    int16_t tempY = rect_.GetY();
1306a3e0fd82Sopenharmony_ci    rect_.SetPosition(0, 0);
1307a3e0fd82Sopenharmony_ci
1308a3e0fd82Sopenharmony_ci    Rect mask = GetRect();
1309a3e0fd82Sopenharmony_ci    BufferInfo bufInfo{mask, 0, nullptr, nullptr, 0, 0, colorMode, 0};
1310a3e0fd82Sopenharmony_ci    bufInfo.width = mask.GetWidth();
1311a3e0fd82Sopenharmony_ci    bufInfo.height = mask.GetHeight();
1312a3e0fd82Sopenharmony_ci    bufInfo.stride = bufInfo.width * DrawUtils::GetByteSizeByColorMode(bufInfo.mode);
1313a3e0fd82Sopenharmony_ci    BaseGfxEngine::GetInstance()->AdjustLineStride(bufInfo);
1314a3e0fd82Sopenharmony_ci    imageInfo.header.colorMode = bufInfo.mode;
1315a3e0fd82Sopenharmony_ci    imageInfo.dataSize = bufInfo.stride * bufInfo.height;
1316a3e0fd82Sopenharmony_ci    imageInfo.header.width = bufInfo.width;
1317a3e0fd82Sopenharmony_ci    imageInfo.header.height = bufInfo.height;
1318a3e0fd82Sopenharmony_ci    imageInfo.header.reserved = 0;
1319a3e0fd82Sopenharmony_ci
1320a3e0fd82Sopenharmony_ci    bufInfo.virAddr = ImageCacheMalloc(imageInfo);
1321a3e0fd82Sopenharmony_ci    if (bufInfo.virAddr == nullptr) {
1322a3e0fd82Sopenharmony_ci        GRAPHIC_LOGE("GetBitmap buffer alloc failed.");
1323a3e0fd82Sopenharmony_ci        nextRenderSibling_ = tempRenderSibling;
1324a3e0fd82Sopenharmony_ci        parent_ = tempParent;
1325a3e0fd82Sopenharmony_ci        rect_.SetPosition(tempX, tempY);
1326a3e0fd82Sopenharmony_ci        return false;
1327a3e0fd82Sopenharmony_ci    }
1328a3e0fd82Sopenharmony_ci    imageInfo.data = reinterpret_cast<uint8_t*>(bufInfo.virAddr);
1329a3e0fd82Sopenharmony_ci    if (memset_s(bufInfo.virAddr, imageInfo.dataSize, 0, imageInfo.dataSize) != EOK) {
1330a3e0fd82Sopenharmony_ci        GRAPHIC_LOGE("GetBitmap buffer memset failed.");
1331a3e0fd82Sopenharmony_ci        ImageCacheFree(imageInfo);
1332a3e0fd82Sopenharmony_ci        imageInfo.data = nullptr;
1333a3e0fd82Sopenharmony_ci        return false;
1334a3e0fd82Sopenharmony_ci    }
1335a3e0fd82Sopenharmony_ci    bufInfo.phyAddr = bufInfo.virAddr;
1336a3e0fd82Sopenharmony_ci    RootView* rootView = RootView::GetInstance();
1337a3e0fd82Sopenharmony_ci    rootView->SaveDrawContext();
1338a3e0fd82Sopenharmony_ci    rootView->UpdateBufferInfo(&bufInfo);
1339a3e0fd82Sopenharmony_ci    rootView->MeasureView(this);
1340a3e0fd82Sopenharmony_ci    rootView->DrawTop(this, mask);
1341a3e0fd82Sopenharmony_ci    rootView->RestoreDrawContext();
1342a3e0fd82Sopenharmony_ci
1343a3e0fd82Sopenharmony_ci    nextRenderSibling_ = tempRenderSibling;
1344a3e0fd82Sopenharmony_ci    parent_ = tempParent;
1345a3e0fd82Sopenharmony_ci    rect_.SetPosition(tempX, tempY);
1346a3e0fd82Sopenharmony_ci    return true;
1347a3e0fd82Sopenharmony_ci}
1348a3e0fd82Sopenharmony_ci
1349a3e0fd82Sopenharmony_cibool UIView::IsOnViewTree()
1350a3e0fd82Sopenharmony_ci{
1351a3e0fd82Sopenharmony_ci    UIView* par = this;
1352a3e0fd82Sopenharmony_ci    while (par->GetParent() != nullptr) {
1353a3e0fd82Sopenharmony_ci        par = par->GetParent();
1354a3e0fd82Sopenharmony_ci    }
1355a3e0fd82Sopenharmony_ci    if (par->GetViewType() != UI_ROOT_VIEW) {
1356a3e0fd82Sopenharmony_ci        return false;
1357a3e0fd82Sopenharmony_ci    }
1358a3e0fd82Sopenharmony_ci    return true;
1359a3e0fd82Sopenharmony_ci}
1360a3e0fd82Sopenharmony_ci
1361a3e0fd82Sopenharmony_ciint16_t UIView::GetWidthWithMargin()
1362a3e0fd82Sopenharmony_ci{
1363a3e0fd82Sopenharmony_ci    return GetRelativeRect().GetWidth() + GetStyle(STYLE_MARGIN_LEFT) + GetStyle(STYLE_MARGIN_RIGHT);
1364a3e0fd82Sopenharmony_ci}
1365a3e0fd82Sopenharmony_ci
1366a3e0fd82Sopenharmony_ciint16_t UIView::GetHeightWithMargin()
1367a3e0fd82Sopenharmony_ci{
1368a3e0fd82Sopenharmony_ci    return GetRelativeRect().GetHeight() + GetStyle(STYLE_MARGIN_TOP) + GetStyle(STYLE_MARGIN_BOTTOM);
1369a3e0fd82Sopenharmony_ci}
1370a3e0fd82Sopenharmony_ci
1371a3e0fd82Sopenharmony_ciRect UIView::GetRelativeRect() const
1372a3e0fd82Sopenharmony_ci{
1373a3e0fd82Sopenharmony_ci    return rect_;
1374a3e0fd82Sopenharmony_ci}
1375a3e0fd82Sopenharmony_ci
1376a3e0fd82Sopenharmony_civoid UIView::ResizeVisibleArea(int16_t x, int16_t y, int16_t width, int16_t height)
1377a3e0fd82Sopenharmony_ci{
1378a3e0fd82Sopenharmony_ci    if (visibleRect_ == nullptr) {
1379a3e0fd82Sopenharmony_ci        visibleRect_ = new Rect();
1380a3e0fd82Sopenharmony_ci        if (visibleRect_ == nullptr) {
1381a3e0fd82Sopenharmony_ci            GRAPHIC_LOGE("new Rect fail");
1382a3e0fd82Sopenharmony_ci            return;
1383a3e0fd82Sopenharmony_ci        }
1384a3e0fd82Sopenharmony_ci    }
1385a3e0fd82Sopenharmony_ci    visibleRect_->SetWidth(width);
1386a3e0fd82Sopenharmony_ci    visibleRect_->SetHeight(height);
1387a3e0fd82Sopenharmony_ci    visibleRect_->SetPosition(x, y);
1388a3e0fd82Sopenharmony_ci}
1389a3e0fd82Sopenharmony_ci
1390a3e0fd82Sopenharmony_civoid UIView::SetZIndex(int16_t zIndex)
1391a3e0fd82Sopenharmony_ci{
1392a3e0fd82Sopenharmony_ci    if (zIndex_ == zIndex) {
1393a3e0fd82Sopenharmony_ci        return;
1394a3e0fd82Sopenharmony_ci    }
1395a3e0fd82Sopenharmony_ci
1396a3e0fd82Sopenharmony_ci    zIndex_ = zIndex;
1397a3e0fd82Sopenharmony_ci    if (parent_ != nullptr) {
1398a3e0fd82Sopenharmony_ci        reinterpret_cast<UIViewGroup*>(parent_)->UpdateRenderView(this);
1399a3e0fd82Sopenharmony_ci    }
1400a3e0fd82Sopenharmony_ci}
1401a3e0fd82Sopenharmony_ci
1402a3e0fd82Sopenharmony_ciint16_t UIView::GetZIndex()
1403a3e0fd82Sopenharmony_ci{
1404a3e0fd82Sopenharmony_ci    return zIndex_;
1405a3e0fd82Sopenharmony_ci}
1406a3e0fd82Sopenharmony_ci} // namespace OHOS
1407