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