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 "core/components/select_popup/render_select_popup.h"
17 
18 #include "base/subwindow/subwindow_manager.h"
19 
20 namespace OHOS::Ace {
21 namespace {
22 constexpr int32_t DEFAULT_DISTANCE = 5;
23 constexpr Dimension MENU_ARROW_PADDING = 4.0_vp;
24 } // namespace
25 
RenderSelectPopup()26 RenderSelectPopup::RenderSelectPopup()
27 {
28     rawDetector_ = AceType::MakeRefPtr<RawRecognizer>();
29     rawDetector_->SetOnTouchDown([weak = WeakClaim(this)](const TouchEventInfo& info) {
30         auto selectPopup = weak.Upgrade();
31         if (selectPopup) {
32             selectPopup->ProcessTouchDown(info);
33             selectPopup->HandleRawEvent(info.GetTouches().front().GetLocalLocation());
34         }
35     });
36 }
37 
OnPaintFinish()38 void RenderSelectPopup::OnPaintFinish()
39 {
40     auto pipeline = context_.Upgrade();
41     if (!selectPopup_ || !selectPopup_->GetNode() || !pipeline || !renderPositioned_) {
42         LOGE("can not get accessibility node of select popup or pipeline is null or positional is null.");
43         return;
44     }
45     auto node = selectPopup_->GetNode();
46     auto viewScale = pipeline->GetViewScale();
47     auto leftTop = renderPositioned_->GetGlobalOffsetExternal();
48     node->SetLeft(leftTop.GetX() * viewScale);
49     node->SetTop(leftTop.GetY() * viewScale);
50     auto size = renderPositioned_->GetLayoutSize();
51     node->SetWidth(size.Width() * viewScale);
52     node->SetHeight(size.Height() * viewScale);
53 #if defined(PREVIEW)
54     auto parentNode = node->GetParentNode();
55     if (parentNode && parentNode->GetTag() == "menu") {
56         parentNode->SetLeft(leftTop.GetX() * viewScale);
57         parentNode->SetTop(leftTop.GetY() * viewScale);
58         parentNode->SetWidth(size.Width() * viewScale);
59         parentNode->SetHeight(size.Height() * viewScale);
60     }
61 #endif
62     node->SetEnabledState(true);
63     node->SetCheckableState(false);
64     node->SetClickableState(false);
65     node->SetFocusableState(false);
66     if (isContextMenu_) {
67         std::vector<Rect> rects;
68 
69         // When the menu is context menu, set the hot area.
70         // Now only one menu is supported, so just add one area.
71         // When the framework support multiple menus, add all the areas.
72         rects.emplace_back(renderPositioned_->GetRectBasedWindowTopLeft());
73         SubwindowManager::GetInstance()->SetHotAreas(rects);
74     }
75 }
76 
Update(const RefPtr<Component> & component)77 void RenderSelectPopup::Update(const RefPtr<Component>& component)
78 {
79     auto popup = AceType::DynamicCast<SelectPopupComponent>(component);
80     if (!popup || !popup->GetTheme()) {
81         LOGE("select: input component is null or not SelectPopupComponent.");
82         return;
83     }
84 
85     theme_ = popup->GetTheme();
86     tvBackColor_ = theme_->GetTvBackColor();
87     selectPopup_ = popup;
88     popup->GetPopupLayout(selectLeftTop_, selectRightBottom_);
89     optionSize_ = popup->GetOptionSize();
90     rrectSize_ = popup->GetPopupRRectSize();
91     optionInterval_ = theme_->GetOptionInterval();
92     minWidth_ = popup->GetPopupMinWidth();
93     horizontalSpacing_ = popup->GetHorizontalSpacing();
94     verticalSpacing_ = popup->GetVerticalSpacing();
95     contentSpacing_ = popup->GetContentSpacing();
96     isFullScreen_ = popup->IsFullScreen();
97     isContextMenu_ = popup->IsContextMenu();
98     MarkNeedLayout();
99 }
100 
AdjustTvChildVerticalLayout(const Size & size,double & y,double & height)101 void RenderSelectPopup::AdjustTvChildVerticalLayout(const Size& size, double& y, double& height)
102 {
103     double bottomSpace = globalRightBottom_.GetY() - selectLeftTop_.GetY();
104     if (bottomSpace >= size.Height() + verticalSpacing_.Value()) {
105         y = selectLeftTop_.GetY();
106         height = size.Height();
107         return;
108     }
109     bottomSpace = globalRightBottom_.GetY();
110     if (bottomSpace >= size.Height() + 2.0 * verticalSpacing_.Value()) {
111         height = size.Height();
112         y = bottomSpace - verticalSpacing_.Value() - height;
113         return;
114     }
115     height = bottomSpace - 2.0 * verticalSpacing_.Value();
116     y = verticalSpacing_.Value();
117 }
118 
AdjustTvChildHorizontalLayout(const Size & size,double & x,double & width)119 void RenderSelectPopup::AdjustTvChildHorizontalLayout(const Size& size, double& x, double& width)
120 {
121     double leftSpace = selectLeftTop_.GetX();
122     double rightSpace = globalRightBottom_.GetX() - selectRightBottom_.GetX();
123     if (selectPopup_ && selectPopup_->GetTextDirection() == TextDirection::RTL) {
124         if (leftSpace >= contentSpacing_.Value() + size.Width() + horizontalSpacing_.Value()) {
125             width = size.Width();
126             x = selectLeftTop_.GetX() - contentSpacing_.Value() - width;
127             return;
128         }
129         if (rightSpace <= leftSpace) {
130             width = leftSpace - contentSpacing_.Value() - horizontalSpacing_.Value();
131             x = horizontalSpacing_.Value();
132             return;
133         }
134         x = selectRightBottom_.GetX() + contentSpacing_.Value();
135         if (rightSpace >= contentSpacing_.Value() + size.Width() + horizontalSpacing_.Value()) {
136             width = size.Width();
137             return;
138         }
139         width = rightSpace - contentSpacing_.Value() - horizontalSpacing_.Value();
140         return;
141     }
142 
143     if (rightSpace >= contentSpacing_.Value() + size.Width() + horizontalSpacing_.Value()) {
144         width = size.Width();
145         x = selectRightBottom_.GetX() + contentSpacing_.Value();
146         return;
147     }
148     if (leftSpace <= rightSpace) {
149         width = rightSpace - contentSpacing_.Value() - horizontalSpacing_.Value();
150         x = selectRightBottom_.GetX() + contentSpacing_.Value();
151         return;
152     }
153     if (leftSpace >= contentSpacing_.Value() + size.Width() + horizontalSpacing_.Value()) {
154         width = size.Width();
155         x = selectLeftTop_.GetX() - contentSpacing_.Value() - width;
156         return;
157     }
158     width = leftSpace - contentSpacing_.Value() - horizontalSpacing_.Value();
159     x = horizontalSpacing_.Value();
160 }
161 
AdjustChildVerticalLayout(const Size & size,double & y,double & height)162 void RenderSelectPopup::AdjustChildVerticalLayout(const Size& size, double& y, double& height)
163 {
164     if (selectPopup_ && selectPopup_->IsMenu() && selectPopup_->IsTV()) {
165         AdjustTvChildVerticalLayout(size, y, height);
166         y -= NormalizeToPx(optionInterval_);
167         y -= NormalizeToPx(rrectSize_);
168         return;
169     }
170 
171     double globalOffsetExternalY = GetGlobalOffsetExternal().GetY();
172     double bottomSpace = globalRightBottom_.GetY() - selectRightBottom_.GetY();
173     double topSpace = selectLeftTop_.GetY();
174     // think about top padding and bottom padding
175     if (bottomSpace >= size.Height() + 2.0 * normalPadding_) {
176         y = selectRightBottom_.GetY() + normalPadding_ - globalOffsetExternalY;
177         height = size.Height();
178         return;
179     }
180 
181     if (bottomSpace >= topSpace) {
182         y = selectRightBottom_.GetY() + normalPadding_ - globalOffsetExternalY;
183         // think about top padding and bottom padding
184         height = bottomSpace - 2.0 * normalPadding_;
185         return;
186     }
187 
188     // think about top padding and bottom padding
189     if (topSpace >= size.Height() + 2.0 * normalPadding_) {
190         height = size.Height();
191         y = selectLeftTop_.GetY() - normalPadding_ - height + globalOffsetExternalY;
192         return;
193     }
194 
195     y = normalPadding_;
196     // think about top padding and bottom padding
197     height = topSpace - 2.0 * normalPadding_;
198 }
199 
AdjustChildHorizontalLayout(const Size & size,double & x,double & width)200 void RenderSelectPopup::AdjustChildHorizontalLayout(const Size& size, double& x, double& width)
201 {
202     double rightSpace = globalRightBottom_.GetX() - selectLeftTop_.GetX();
203     if (selectRightBottom_ != selectLeftTop_) {
204         if (selectPopup_ && selectPopup_->IsMenu() && selectPopup_->IsTV()) {
205             AdjustTvChildHorizontalLayout(size, x, width);
206             return;
207         }
208         if (selectPopup_ && selectPopup_->GetTextDirection() == TextDirection::RTL) {
209             // align right for select popup dialog
210             double space = selectRightBottom_.GetX();
211             width = (space > size.Width() + normalPadding_ ? size.Width() : space - normalPadding_);
212             x = space - width;
213         } else {
214             x = selectLeftTop_.GetX();
215             width = (rightSpace > size.Width() + normalPadding_ ? size.Width() : rightSpace - normalPadding_);
216         }
217         return;
218     }
219 
220     double leftSpace = selectLeftTop_.GetX();
221     // think about left padding and right padding
222     if (rightSpace >= size.Width() + 2.0 * normalPadding_) {
223         x = selectLeftTop_.GetX() + normalPadding_;
224         width = size.Width();
225         return;
226     }
227 
228     if (rightSpace >= leftSpace) {
229         x = selectLeftTop_.GetX() + normalPadding_;
230         // think about left padding and right padding
231         width = rightSpace - 2.0 * normalPadding_;
232         return;
233     }
234 
235     // think about left padding and right padding
236     if (leftSpace >= size.Width() + 2.0 * normalPadding_) {
237         width = size.Width();
238         x = selectLeftTop_.GetX() - normalPadding_ - width;
239         return;
240     }
241 
242     x = normalPadding_;
243     // think about left padding and right padding
244     width = leftSpace - 2.0 * normalPadding_;
245 }
246 
AdjustChildLayout(Size & size)247 void RenderSelectPopup::AdjustChildLayout(Size& size)
248 {
249     double x = 0.0;
250     double width = 0.0;
251     AdjustChildHorizontalLayout(size, x, width);
252     double y = 0.0;
253     double height = 0.0;
254     AdjustChildVerticalLayout(size, y, height);
255     childLayoutParam_.SetFixedSize(Size(width, height));
256     size.SetWidth(width);
257     size.SetHeight(height);
258     childPosition_.SetX(x);
259     childPosition_.SetY(y);
260 }
261 
CreateAnimation()262 void RenderSelectPopup::CreateAnimation()
263 {
264     if (animationCreated_) {
265         return;
266     }
267     if (selectPopup_) {
268         // When the popup is used for contextmenu, add the animation, the same with menu.
269         CreatePopupAnimation(selectPopup_->IsMenu() || selectPopup_->IsContextMenu());
270     }
271     animationCreated_ = true;
272 }
273 
CreatePopupAnimation(bool isMenu)274 void RenderSelectPopup::CreatePopupAnimation(bool isMenu)
275 {
276     if (!selectPopup_ || !selectPopup_->GetTheme()) {
277         LOGE("select theme or select popup component is null.");
278         return;
279     }
280 
281     auto theme = selectPopup_->GetTheme();
282     auto showScaleAnimation = AceType::MakeRefPtr<CurveAnimation<float>>(0.9f, 1.0f, Curves::FRICTION);
283     auto showAlphaAnimation = AceType::MakeRefPtr<CurveAnimation<float>>(0.0f, 1.0f, Curves::FAST_OUT_SLOW_IN);
284     TweenOption showOption;
285     showOption.SetDuration(theme->GetShowTime(isMenu));
286     showOption.SetTransformFloatAnimation(AnimationType::SCALE, showScaleAnimation);
287     showOption.SetOpacityAnimation(showAlphaAnimation);
288     selectPopup_->SetShowOption(showOption);
289 
290     auto hideScaleAnimation = AceType::MakeRefPtr<CurveAnimation<float>>(1.0f, 0.9f, Curves::FRICTION);
291     auto hideAlphaAnimation = AceType::MakeRefPtr<CurveAnimation<float>>(1.0f, 0.0f, Curves::FAST_OUT_SLOW_IN);
292     TweenOption hideOption;
293     hideOption.SetDuration(theme->GetHideTime(isMenu));
294     hideOption.SetFillMode(FillMode::FORWARDS);
295     hideOption.SetTransformFloatAnimation(AnimationType::SCALE, hideScaleAnimation);
296     hideOption.SetOpacityAnimation(hideAlphaAnimation);
297     selectPopup_->SetHideOption(hideOption);
298 }
299 
PerformLayout()300 void RenderSelectPopup::PerformLayout()
301 {
302     if (ScreenDirectionSwitched()) {
303         return;
304     }
305     if (!renderRoot_ || !renderScroll_ || (isFullScreen_ && !renderPositioned_)) {
306         LOGE("render child is null.");
307         return;
308     }
309     verticalSpacing_ = Dimension(NormalizeToPx(verticalSpacing_), DimensionUnit::PX);
310     horizontalSpacing_ = Dimension(NormalizeToPx(horizontalSpacing_), DimensionUnit::PX);
311     contentSpacing_ = Dimension(NormalizeToPx(contentSpacing_), DimensionUnit::PX);
312     if (selectPopup_ && (selectPopup_->IsMenu() || selectPopup_->IsContextMenu())) {
313         normalPadding_ = NormalizeToPx(MENU_ARROW_PADDING);
314     } else {
315         normalPadding_ = NormalizeToPx(rrectSize_);
316     }
317     globalRightBottom_ = Offset() + renderRoot_->GetLayoutSize();
318     double outPadding = NormalizeToPx(4.0_vp); // the out padding is 4dp from doc.
319     Size totalSize;
320     double fixHeight = 0.0;
321     if (renderTitleBox_) {
322         renderTitleBox_->Layout(LayoutParam());
323         totalSize = renderTitleBox_->GetLayoutSize();
324         // add 8.0dp delta width for title so that it will show full title.
325         totalSize.SetWidth(totalSize.Width() + NormalizeToPx(8.0_vp));
326         fixHeight = totalSize.Height();
327     }
328     for (const auto& option : renderOptions_) {
329         if (selectLeftTop_ != selectRightBottom_ && selectPopup_ && !selectPopup_->IsMenu()) {
330             option->SetMaxWidth(
331                 (selectPopup_->GetTextDirection() == TextDirection::RTL
332                         ? selectRightBottom_.GetX() - normalPadding_ - 2.0 * outPadding
333                         : globalRightBottom_.GetX() - selectLeftTop_.GetX() - normalPadding_ - 2.0 * outPadding));
334         } else if (selectLeftTop_ == selectRightBottom_ && selectPopup_ && selectPopup_->IsMenu()) {
335             auto leftSpace = selectLeftTop_.GetX();
336             auto rightSpace = globalRightBottom_.GetX() - leftSpace;
337             leftSpace -= 2.0 * normalPadding_ + 2.0 * outPadding;
338             rightSpace -= 2.0 * normalPadding_ + 2.0 * outPadding;
339             option->SetMaxWidth(std::max(leftSpace, rightSpace));
340         }
341 
342         option->Layout(LayoutParam());
343         if (option->GetLayoutSize().Width() > totalSize.Width()) {
344             totalSize.SetWidth(option->GetLayoutSize().Width());
345         }
346         totalSize.AddHeight(option->GetLayoutSize().Height());
347     }
348     if (selectPopup_ && !selectPopup_->IsMenu() && !selectPopup_->IsContextMenu() &&
349         totalSize.Width() < NormalizeToPx(minWidth_)) {
350         totalSize.SetWidth(NormalizeToPx(minWidth_));
351     }
352     totalSize.AddHeight(2.0 * outPadding);
353     totalSize.AddWidth(2.0 * outPadding);
354 
355     AdjustChildLayout(totalSize);
356     for (const auto& option : renderOptions_) {
357         // leave the space of 8.0dp for interval of innner and out box.
358         option->SetFixedWidth(totalSize.Width() - 2.0 * outPadding);
359     }
360     if (isFullScreen_) {
361         renderPositioned_->SetPosition(childPosition_);
362         renderPositioned_->Layout(childLayoutParam_);
363     } else {
364         if (GetChildren().front()) {
365             GetChildren().front()->Layout(childLayoutParam_);
366         }
367     }
368     LayoutParam scrollLayout;
369     scrollLayout.SetFixedSize(
370         Size(totalSize.Width() - 2.0 * outPadding, totalSize.Height() - fixHeight - 2.0 * outPadding));
371     renderScroll_->Layout(scrollLayout);
372     if (renderTitleBox_) {
373         LayoutParam layout;
374         layout.SetFixedSize(Size(totalSize.Width() - 2.0 * outPadding, renderTitleBox_->GetLayoutSize().Height()));
375         renderTitleBox_->Layout(layout);
376     }
377 
378     if (isFullScreen_) {
379         SetLayoutSize(GetLayoutParam().GetMaxSize());
380         touchRegion_ = TouchRegion(
381             renderPositioned_->GetPosition(), renderPositioned_->GetPosition() + renderPositioned_->GetLayoutSize());
382     } else {
383         if (GetChildren().front()) {
384             SetLayoutSize(GetChildren().front()->GetLayoutSize());
385         }
386         touchRegion_ = TouchRegion(GetPosition(), GetPosition() + GetLayoutSize());
387     }
388 
389     CreateAnimation();
390 }
391 
HandleRawEvent(const Offset & clickPosition)392 void RenderSelectPopup::HandleRawEvent(const Offset& clickPosition)
393 {
394     if (touchRegion_.ContainsInRegion(clickPosition.GetX(), clickPosition.GetY())) {
395         LOGI("Contains the touch region.");
396         return;
397     }
398 
399     if (!selectPopup_) {
400         return;
401     }
402     if (isContextMenu_) {
403         LOGI("Hide the contextmenu.");
404         selectPopup_->CloseContextMenu();
405         return;
406     }
407     selectPopup_->HideDialog(SELECT_INVALID_INDEX);
408 }
409 
ProcessTouchDown(const TouchEventInfo & info)410 void RenderSelectPopup::ProcessTouchDown(const TouchEventInfo& info)
411 {
412     LOGI("ProcessTouchDown");
413     auto touches = info.GetTouches();
414     if (touches.empty()) {
415         LOGE("touch event info is empty.");
416         return;
417     }
418 
419     auto clickPosition = touches.front().GetLocalLocation();
420     if (!touchRegion_.ContainsInRegion(clickPosition.GetX(), clickPosition.GetY())) {
421         LOGI("Do not contains the touch region.");
422         return;
423     }
424 
425     firstFingerDownOffset_ = touches.front().GetGlobalLocation();
426 }
427 
ProcessTouchUp(const TouchEventInfo & info)428 void RenderSelectPopup::ProcessTouchUp(const TouchEventInfo& info)
429 {
430     LOGI("ProcessTouchUp");
431     auto touches = info.GetTouches();
432     if (touches.empty()) {
433         LOGE("touch event info is empty.");
434         return;
435     }
436 
437     auto clickPosition = touches.front().GetLocalLocation();
438 
439     if (selectPopup_->GetSelectOptions().empty()) {
440         return;
441     }
442 
443     auto firstOption = selectPopup_->GetSelectOptions().front();
444     bool isCustomOption = (firstOption->GetCustomComponent() != nullptr);
445 
446     auto offset = touches.front().GetGlobalLocation();
447     firstFingerUpOffset_ = offset;
448     if ((((offset - firstFingerDownOffset_).GetDistance() <= DEFAULT_DISTANCE) && isCustomOption) ||
449         !touchRegion_.ContainsInRegion(clickPosition.GetX(), clickPosition.GetY())) {
450         if (isContextMenu_) {
451             selectPopup_->CloseContextMenu();
452         } else {
453             selectPopup_->HideDialog(SELECT_INVALID_INDEX);
454         }
455         firstFingerDownOffset_ = Offset();
456     }
457 }
458 
OnTouchTestHit(const Offset & coordinateOffset,const TouchRestrict & touchRestrict,TouchTestResult & result)459 void RenderSelectPopup::OnTouchTestHit(
460     const Offset& coordinateOffset, const TouchRestrict& touchRestrict, TouchTestResult& result)
461 {
462     if (!dragDetector_) {
463         dragDetector_ = AceType::MakeRefPtr<FreeDragRecognizer>();
464     }
465     if (!longPressDetector_) {
466         longPressDetector_ = AceType::MakeRefPtr<LongPressRecognizer>(context_);
467     }
468     if (!clickDetector_) {
469         clickDetector_ = AceType::MakeRefPtr<ClickRecognizer>();
470     }
471 
472     rawDetector_->SetOnTouchUp([weak = AceType::WeakClaim(this)](const TouchEventInfo& info) {
473         auto ref = weak.Upgrade();
474         if (!ref) {
475             LOGE("renderSelectPopup upgrade fail.");
476             return;
477         }
478 
479         ref->ProcessTouchUp(info);
480     });
481 
482     rawDetector_->SetOnTouchCancel([weak = AceType::WeakClaim(this)](const TouchEventInfo& info) {
483         auto ref = weak.Upgrade();
484         if (!ref) {
485             LOGE("renderSelectPopup upgrade fail.");
486             return;
487         }
488 
489         ref->ProcessTouchUp(info);
490     });
491 
492     rawDetector_->SetCoordinateOffset(coordinateOffset);
493     dragDetector_->SetCoordinateOffset(coordinateOffset);
494     longPressDetector_->SetCoordinateOffset(coordinateOffset);
495     clickDetector_->SetCoordinateOffset(coordinateOffset);
496     result.emplace_back(rawDetector_);
497     result.emplace_back(dragDetector_);
498     result.emplace_back(longPressDetector_);
499     result.emplace_back(clickDetector_);
500 }
501 
GetReferenceRenders()502 void RenderSelectPopup::GetReferenceRenders()
503 {
504     auto context = context_.Upgrade();
505     if (!context) {
506         return;
507     }
508     auto pageElement = context->GetLastStack();
509     if (!pageElement) {
510         return;
511     }
512     renderRoot_ = pageElement->GetRenderNode();
513     renderOptions_.clear();
514     GetReferenceRenders(AceType::Claim(this));
515 }
516 
GetReferenceRenders(const RefPtr<RenderNode> & render)517 void RenderSelectPopup::GetReferenceRenders(const RefPtr<RenderNode>& render)
518 {
519     if (!render) {
520         return;
521     }
522 
523     if (AceType::InstanceOf<RenderBox>(render)) {
524         auto boxParent = render->GetParent().Upgrade();
525         if (boxParent && AceType::InstanceOf<RenderFlex>(boxParent)) {
526             renderTitleBox_ = AceType::DynamicCast<RenderBox>(render);
527             return;
528         }
529     }
530 
531     if (AceType::InstanceOf<RenderOption>(render)) {
532         renderOptions_.emplace_back(AceType::DynamicCast<RenderOption>(render));
533         return;
534     }
535 
536     if (AceType::InstanceOf<RenderPositioned>(render)) {
537         renderPositioned_ = AceType::DynamicCast<RenderPositioned>(render);
538     }
539 
540     if (AceType::InstanceOf<RenderScroll>(render)) {
541         renderScroll_ = AceType::DynamicCast<RenderScroll>(render);
542     }
543 
544     for (const auto& child : render->GetChildren()) {
545         GetReferenceRenders(child);
546     }
547 }
548 
ClearReferenceRenders()549 void RenderSelectPopup::ClearReferenceRenders()
550 {
551     renderRoot_ = nullptr;
552     renderPositioned_ = nullptr;
553     renderTitleBox_ = nullptr;
554     renderScroll_ = nullptr;
555     renderOptions_.clear();
556 }
557 
ScreenDirectionSwitched()558 bool RenderSelectPopup::ScreenDirectionSwitched()
559 {
560     auto pipeline = context_.Upgrade();
561     if (!pipeline) {
562         return false;
563     }
564 
565     bool check = GreatNotEqual(pipeline->GetRootWidth(), pipeline->GetRootHeight());
566     bool switched = (!screenHorizontal_ && !screenVertical_) ? false : (check ? screenVertical_ : screenHorizontal_);
567     screenHorizontal_ = check;
568     screenVertical_ = !check;
569     if (switched && selectPopup_) {
570         selectPopup_->HideDialog(SELECT_INVALID_INDEX);
571     }
572     return switched;
573 }
574 
HandleMouseEvent(const MouseEvent & event)575 bool RenderSelectPopup::HandleMouseEvent(const MouseEvent& event)
576 {
577     if (event.button != MouseButton::NONE_BUTTON && event.button != MouseButton::LEFT_BUTTON &&
578         event.action == MouseAction::PRESS) {
579         HandleRawEvent({ event.x, event.y });
580     }
581     return true;
582 }
583 
584 } // namespace OHOS::Ace
585