• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "ui_test_input_event.h"
17 
18 #include "common/screen.h"
19 #include "components/root_view.h"
20 
21 namespace OHOS {
22 namespace {
23 const int16_t ITEM_H = 50;
24 const int16_t TEXT_H = 29;
25 const int16_t TEXT_W = 250;
26 const int16_t TEST_VIEW_H = 40;
27 const int16_t TEST_VIEW_W = 40;
28 const int16_t GAP = 5;
29 const int16_t TEST_VIEW_GAP = 80;
30 } // namespace
31 
32 class TestView : public UIView {
33 public:
TestView()34     TestView() {}
~TestView()35     virtual ~TestView() {}
OnLongPressEvent(const LongPressEvent & event)36     bool OnLongPressEvent(const LongPressEvent& event) override
37     {
38         if (label_ != nullptr) {
39             label_->SetText("long press!");
40             label_->Invalidate();
41         }
42         return UIView::OnLongPressEvent(event);
43     }
44 
OnDragEvent(const DragEvent & event)45     bool OnDragEvent(const DragEvent& event) override
46     {
47         if (label_ != nullptr) {
48             label_->SetText("drag!");
49             label_->Invalidate();
50         }
51         return UIView::OnDragEvent(event);
52     }
53 
SetSentence(const char * sentence)54     void SetSentence(const char* sentence)
55     {
56         sentence_ = sentence;
57     }
58 
OnClickEvent(const ClickEvent & event)59     bool OnClickEvent(const ClickEvent& event) override
60     {
61         if (label_ != nullptr) {
62             label_->SetText(sentence_);
63             label_->Invalidate();
64         }
65         return UIView::OnClickEvent(event);
66     }
67 
OnPressEvent(const PressEvent & event)68     bool OnPressEvent(const PressEvent& event) override
69     {
70         if (label_ != nullptr) {
71             label_->SetText("press!");
72             label_->Invalidate();
73         }
74         return UIView::OnPressEvent(event);
75     }
76 
OnReleaseEvent(const ReleaseEvent & event)77     bool OnReleaseEvent(const ReleaseEvent& event) override
78     {
79         if (label_ != nullptr) {
80             label_->SetText("release!");
81             label_->Invalidate();
82         }
83         return UIView::OnReleaseEvent(event);
84     }
85 
OnCancelEvent(const CancelEvent & event)86     bool OnCancelEvent(const CancelEvent& event) override
87     {
88         if (label_ != nullptr) {
89             label_->SetText("cancel!");
90             label_->Invalidate();
91         }
92         return UIView::OnCancelEvent(event);
93     }
94 
SetLabel(UILabel * label)95     void SetLabel(UILabel* label)
96     {
97         label_ = label;
98     }
99 
SetLabel2(UILabel * label)100     void SetLabel2(UILabel* label)
101     {
102         label2_ = label;
103     }
104 
105 private:
106     UILabel* label_ = nullptr;
107     UILabel* label2_ = nullptr;
108     const char* sentence_ = "click";
109 };
110 
111 class TestUIScrollView : public UIScrollView {
112 public:
TestUIScrollView()113     TestUIScrollView() {}
~TestUIScrollView()114     virtual ~TestUIScrollView() {}
OnLongPressEvent(const LongPressEvent & event)115     bool OnLongPressEvent(const LongPressEvent& event) override
116     {
117         if (label_ != nullptr) {
118             label_->SetText("long press!");
119             label_->Invalidate();
120         }
121         return UIView::OnLongPressEvent(event);
122     }
123 
OnDragEvent(const DragEvent & event)124     bool OnDragEvent(const DragEvent& event) override
125     {
126         if (label_ != nullptr) {
127             label_->SetText("drag!");
128             label_->Invalidate();
129         }
130         return UIScrollView::OnDragEvent(event);
131     }
132 
OnDragStartEvent(const DragEvent & event)133     bool OnDragStartEvent(const DragEvent& event) override
134     {
135         if (label_ != nullptr) {
136             label_->SetText("drag start!");
137             label_->Invalidate();
138         }
139         return UIScrollView::OnDragStartEvent(event);
140     }
141 
OnDragEndEvent(const DragEvent & event)142     bool OnDragEndEvent(const DragEvent& event) override
143     {
144         if (label_ != nullptr) {
145             label_->SetText("drag end!");
146             label_->Invalidate();
147         }
148         return UIScrollView::OnDragEndEvent(event);
149     }
150 
SetSentence(const char * sentence)151     void SetSentence(const char* sentence)
152     {
153         sentence_ = sentence;
154     }
155 
OnClickEvent(const ClickEvent & event)156     bool OnClickEvent(const ClickEvent& event) override
157     {
158         if (label_ != nullptr) {
159             label_->SetText(sentence_);
160             label_->Invalidate();
161         }
162         return UIView::OnClickEvent(event);
163     }
164 
OnPressEvent(const PressEvent & event)165     bool OnPressEvent(const PressEvent& event) override
166     {
167         if (label_ != nullptr) {
168             label_->SetText("press!");
169             label_->Invalidate();
170         }
171         return UIView::OnPressEvent(event);
172     }
173 
OnReleaseEvent(const ReleaseEvent & event)174     bool OnReleaseEvent(const ReleaseEvent& event) override
175     {
176         if (label_ != nullptr) {
177             label_->SetText("release!");
178             label_->Invalidate();
179         }
180         return UIView::OnReleaseEvent(event);
181     }
182 
OnCancelEvent(const CancelEvent & event)183     bool OnCancelEvent(const CancelEvent& event) override
184     {
185         if (label_ != nullptr) {
186             label_->SetText("cancel!");
187             label_->Invalidate();
188         }
189         return UIView::OnCancelEvent(event);
190     }
191 
SetLabel(UILabel * label)192     void SetLabel(UILabel* label)
193     {
194         label_ = label;
195     }
196 
197 private:
198     UILabel* label_ = nullptr;
199     const char* sentence_ = "click";
200 };
201 
SetUp()202 void UITestInputEvent::SetUp()
203 {
204     if (container_ == nullptr) {
205         container_ = new UIScrollView();
206         container_->Resize(Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight() - BACK_BUTTON_HEIGHT);
207         container_->SetHorizontalScrollState(false);
208     }
209     positionX_ = 48; // 48: position x
210     positionY_ = 0;
211 }
212 
DeleteChildrenAndListener(UIView * view)213 void DeleteChildrenAndListener(UIView* view)
214 {
215     if (view == nullptr) {
216         return;
217     }
218     while (view != nullptr) {
219         UIView* tempView = view;
220         view = view->GetNextSibling();
221         if (tempView->IsViewGroup()) {
222             DeleteChildrenAndListener(static_cast<UIViewGroup*>(tempView)->GetChildrenHead());
223         }
224         if (tempView->GetParent()) {
225             static_cast<UIViewGroup*>(tempView->GetParent())->Remove(tempView);
226         }
227 
228         if (tempView->GetOnClickListener()) {
229             delete tempView->GetOnClickListener();
230         }
231         if (tempView->GetOnDragListener()) {
232             delete tempView->GetOnDragListener();
233         }
234         if (tempView->GetOnLongPressListener()) {
235             delete tempView->GetOnLongPressListener();
236         }
237         if (tempView->GetTouchListener()) {
238             delete tempView->GetTouchListener();
239         }
240 
241         delete tempView;
242     }
243 }
244 
TearDown()245 void UITestInputEvent::TearDown()
246 {
247     DeleteChildrenAndListener(container_);
248     container_ = nullptr;
249     RootView::GetInstance()->ClearOnKeyActListener();
250     if (keyListener_ != nullptr) {
251         delete keyListener_;
252         keyListener_ = nullptr;
253     }
254 }
255 
GetTestView()256 const UIView* UITestInputEvent::GetTestView()
257 {
258     UIKitPointerInputTestDispatchSimpleEvent001();
259     UIKitPointerInputTestDispatchSimpleEvent002();
260     UIKitPointerInputTestDispatchDragEvent001();
261     UIKitPointerInputTestDispatchDragEvent002();
262     UIKitPointerInputTestDispatchDragEvent003();
263     UIKitPointerInputTestDispatchKeyEvent001();
264     UIKitPointerInputTestDispatchInVisibleEvent001();
265     UIKitPointerInputTestDispatchBubble001();
266     UIKitPointerInputTestDispatchBubble002();
267     UIKitPointerInputTestDispatchBubble003();
268     UIKitPointerInputTestDispatchBubble004();
269     UIKitPointerInputTestDispatchBubble005();
270     UIKitPointerInputTestDispatchBubble006();
271     UIKitPointerInputTestDispatchBubble007();
272     UIKitPointerInputTestDispatchBubble008();
273     UIKitPointerInputTestDispatchBubble009();
274     UIKitPointerInputTestDispatchBubble010();
275     return container_;
276 }
277 
UIKitPointerInputTestDispatchSimpleEvent001()278 void UITestInputEvent::UIKitPointerInputTestDispatchSimpleEvent001()
279 {
280     InnerTest("可点击对象事件测试 ", true, false, false);
281 }
282 
UIKitPointerInputTestDispatchSimpleEvent002()283 void UITestInputEvent::UIKitPointerInputTestDispatchSimpleEvent002()
284 {
285     InnerTest("不可点击对象事件测试 ", false, false, false);
286 }
287 
UIKitPointerInputTestDispatchDragEvent001()288 void UITestInputEvent::UIKitPointerInputTestDispatchDragEvent001()
289 {
290     InnerTest("可点击可拖拽dragparent测试 ", true, true, true);
291 }
292 
UIKitPointerInputTestDispatchDragEvent002()293 void UITestInputEvent::UIKitPointerInputTestDispatchDragEvent002()
294 {
295     InnerTest("可点击可拖拽非dragparent测试 ", true, true, false);
296 }
297 
UIKitPointerInputTestDispatchDragEvent003()298 void UITestInputEvent::UIKitPointerInputTestDispatchDragEvent003()
299 {
300     InnerTest("不可点击可拖拽测试 ", false, true, false);
301 }
302 
UIKitPointerInputTestDispatchBubble001()303 void UITestInputEvent::UIKitPointerInputTestDispatchBubble001()
304 {
305     positionY_ = 0;
306     InnerBubbleTest("可点击有监听事件不消费冒泡测试 ", true, true, true, false);
307 }
308 
UIKitPointerInputTestDispatchBubble002()309 void UITestInputEvent::UIKitPointerInputTestDispatchBubble002()
310 {
311     InnerBubbleTest("可点击有监听事件消费冒泡测试 ", true, true, true, true);
312 }
313 
UIKitPointerInputTestDispatchBubble003()314 void UITestInputEvent::UIKitPointerInputTestDispatchBubble003()
315 {
316     InnerBubbleTest("可点击无监听事件不消费冒泡测试 ", true, true, false, false);
317 }
318 
UIKitPointerInputTestDispatchBubble004()319 void UITestInputEvent::UIKitPointerInputTestDispatchBubble004()
320 {
321     InnerBubbleTest("不可点击有监听事件消费冒泡测试 ", false, false, true, true);
322 }
323 
UIKitPointerInputTestDispatchBubble005()324 void UITestInputEvent::UIKitPointerInputTestDispatchBubble005()
325 {
326     InnerBubbleDragTest("子父可拖拽有监听事件不消费冒泡测试 ", true, true, true, false);
327 }
328 
UIKitPointerInputTestDispatchBubble006()329 void UITestInputEvent::UIKitPointerInputTestDispatchBubble006()
330 {
331     InnerBubbleDragTest("子父可拖拽有监听事件消费冒泡测试 ", true, true, true, true);
332 }
333 
UIKitPointerInputTestDispatchBubble007()334 void UITestInputEvent::UIKitPointerInputTestDispatchBubble007()
335 {
336     InnerBubbleDragTest("子父可拖拽无监听事件消费冒泡测试 ", true, true, false, true);
337 }
338 
UIKitPointerInputTestDispatchBubble008()339 void UITestInputEvent::UIKitPointerInputTestDispatchBubble008()
340 {
341     InnerBubbleDragTest("子父不可拖拽有监听事件消费冒泡测试 ", false, false, true, true);
342 }
343 
UIKitPointerInputTestDispatchBubble009()344 void UITestInputEvent::UIKitPointerInputTestDispatchBubble009()
345 {
346     InnerBubbleDragTest("子不可拖拽父可拖拽有监听事件消费冒泡测试 ", false, true, true, true);
347 }
348 
UIKitPointerInputTestDispatchBubble010()349 void UITestInputEvent::UIKitPointerInputTestDispatchBubble010()
350 {
351     InnerBubbleDragTest("子不可拖拽父可拖拽有监听事件不消费冒泡测试 ", false, true, true, false);
352 }
353 
UIKitPointerInputTestDispatchKeyEvent001()354 void UITestInputEvent::UIKitPointerInputTestDispatchKeyEvent001()
355 {
356     if (container_ != nullptr) {
357         UIViewGroup* uiViewGroup = new UIViewGroup();
358         // 2: half of screen width;
359         uiViewGroup->SetPosition(
360             TEXT_DISTANCE_TO_LEFT_SIDE, positionY_,
361             (Screen::GetInstance().GetWidth() / 2 - TEXT_DISTANCE_TO_LEFT_SIDE), // 2: half of screen width;
362             128);                                                                // 128: height
363         container_->Add(uiViewGroup);
364 
365         UILabel* label = new UILabel();
366         uiViewGroup->Add(label);
367         // 2: half of screen width;
368         label->SetPosition(0, 0, Screen::GetInstance().GetWidth() / 2, TEXT_H);
369         label->SetText("物理按键事件测试 ");
370         label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE);
371         positionY_ += (TEXT_H + GAP);
372         UILabel* label1 = new UILabel();
373         uiViewGroup->Add(label1);
374         label1->SetPosition(0, TEXT_H + GAP, TEXT_W, TEXT_H);
375         label1->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE);
376         if (keyListener_ == nullptr) {
377             keyListener_ = new TestKeyInputListener(label1);
378         }
379         RootView::GetInstance()->SetOnKeyActListener(keyListener_);
380         positionY_ += ITEM_H;
381     }
382 }
383 
UIKitPointerInputTestDispatchInVisibleEvent001()384 void UITestInputEvent::UIKitPointerInputTestDispatchInVisibleEvent001()
385 {
386     if (container_ != nullptr) {
387         UIViewGroup* uiViewGroup = new UIViewGroup();
388         // 2: half of screen width; 36: decrease x-coordinate; 90: y-coordinate
389         uiViewGroup->SetPosition(TEXT_DISTANCE_TO_LEFT_SIDE, positionY_, 480, 128); // 480: width; 128: height
390         container_->Add(uiViewGroup);
391         UILabel* label = new UILabel();
392         uiViewGroup->Add(label);
393         // 2: half of screen width;
394         label->SetPosition(0, 0, Screen::GetInstance().GetWidth() / 2, TEXT_H);
395         label->SetText("不可见对象事件传递测试 ");
396         label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE);
397         positionY_ = 0;
398         positionY_ += (TEXT_H + GAP * 2); // 2: double GAP
399         UIViewGroup* group1 = new UIViewGroup();
400         uiViewGroup->Add(group1);
401         // 20: increase width 20: increase  height
402         group1->SetPosition(positionX_, positionY_, TEST_VIEW_W + 20, TEST_VIEW_H + 20);
403         group1->SetStyle(STYLE_BACKGROUND_COLOR, Color::White().full);
404         group1->SetVisible(false);
405         TestView* testView = new TestView();
406         group1->Add(testView);
407         testView->SetPosition(5, 5, TEST_VIEW_W, TEST_VIEW_H); // 5: position x 5:position y
408         testView->SetStyle(STYLE_BACKGROUND_COLOR, Color::Blue().full);
409         testView->SetTouchable(true);
410         testView->SetSentence("Click From test 0!");
411         UIViewGroup* group2 = new UIViewGroup();
412         uiViewGroup->Add(group2);
413         // 20: increase width 20: increase  height
414         group2->SetPosition(0, positionY_, TEST_VIEW_W + 20, TEST_VIEW_H + 20);
415         group2->SetStyle(STYLE_BACKGROUND_COLOR, Color::White().full);
416         TestView* testView1 = new TestView();
417         group2->Add(testView1);
418         testView1->SetPosition(5, 5, TEST_VIEW_W, TEST_VIEW_H); // 5: position x 5:position y
419         testView1->SetStyle(STYLE_BACKGROUND_COLOR, Color::Red().full);
420         testView1->SetTouchable(true);
421         testView1->SetSentence("Click From test 1!");
422         UILabel* label1 = new UILabel();
423         uiViewGroup->Add(label1);
424         // 50: increase width; 2:double GAP
425         label1->SetPosition(positionX_ + 50, positionY_ + 2 * GAP, TEXT_W, TEXT_H);
426         label1->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE);
427         testView->SetLabel(label1);
428         testView1->SetLabel(label1);
429         positionY_ += ITEM_H;
430     }
431 }
432 
InnerTest(const char * title,bool touchable,bool draggable,bool dragParent)433 void UITestInputEvent::InnerTest(const char* title, bool touchable, bool draggable, bool dragParent)
434 {
435     if (container_ != nullptr) {
436         UILabel* label = new UILabel();
437         container_->Add(label);
438         // 2: half Screen width
439         label->SetPosition(positionX_, positionY_, Screen::GetInstance().GetWidth() / 2, TEXT_H);
440         label->SetText(title);
441         label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE);
442         positionY_ += (TEXT_H + GAP);
443         auto testView = new TestView();
444         container_->Add(testView);
445         testView->SetPosition(positionX_, positionY_, TEST_VIEW_W, TEST_VIEW_H);
446         testView->SetStyle(STYLE_BACKGROUND_COLOR, Color::Blue().full);
447         testView->SetTouchable(touchable);
448         testView->SetDraggable(draggable);
449         testView->SetDragParentInstead(dragParent);
450         UILabel* label1 = new UILabel();
451         container_->Add(label1);
452         label1->SetPosition(positionX_ + TEST_VIEW_GAP, positionY_ + 2 * GAP, TEXT_W, TEXT_H); // 2: double GAP
453         label1->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE);
454         testView->SetLabel(label1);
455         positionY_ += ITEM_H;
456     }
457 }
458 
InnerBubbleTest(const char * title,bool touchable,bool draggable,bool hasListener,bool isBubble)459 void UITestInputEvent::InnerBubbleTest(const char* title,
460                                        bool touchable,
461                                        bool draggable,
462                                        bool hasListener,
463                                        bool isBubble)
464 {
465     if (container_ != nullptr) {
466         UILabel* label = new UILabel();
467         container_->Add(label);
468         label->SetPosition((Screen::GetInstance().GetWidth() / 2 + TEXT_DISTANCE_TO_LEFT_SIDE), // 2: half screen width
469                            positionY_,
470                            (Screen::GetInstance().GetWidth() / 2 - TEXT_DISTANCE_TO_LEFT_SIDE), // 2: half screen width
471                            TEXT_H);
472         label->SetText(title);
473         label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE);
474         positionY_ += (TEXT_H + GAP);
475 
476         OHOS::UIScrollView* parentContainer = new UIScrollView();
477         // 2: half screen width
478         parentContainer->SetPosition(Screen::GetInstance().GetWidth() / 2 + TEXT_DISTANCE_TO_LEFT_SIDE, positionY_,
479                                      Screen::GetInstance().GetWidth() - TEXT_DISTANCE_TO_LEFT_SIDE, ITEM_H);
480         container_->Add(parentContainer);
481         TestView* testView = new TestView();
482         parentContainer->Add(testView);
483         testView->SetPosition(0, 0, TEST_VIEW_W, TEST_VIEW_H);
484         testView->SetStyle(STYLE_BACKGROUND_COLOR, Color::Red().full);
485         testView->SetTouchable(touchable);
486         testView->SetDraggable(draggable);
487         testView->SetDragParentInstead(true);
488         UILabel* label1 = new UILabel();
489         parentContainer->Add(label1);
490         label1->SetPosition(positionX_ + TEST_VIEW_GAP, 2 * GAP, TEXT_W, TEXT_H); // 2: tow gap
491         label1->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE);
492         testView->SetLabel(label1);
493 
494         UILabel* label2 = new UILabel();
495         parentContainer->Add(label2);
496         label2->SetPosition(positionX_ + 2 * TEST_VIEW_GAP, 2 * GAP, TEXT_W, TEXT_H); // 2: tow gap
497         label2->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE);
498         testView->SetLabel2(label2);
499 
500         if (hasListener) {
501             UIView::OnClickListener* clickListenerParent =
502                 new TestOnClickListener(label2, const_cast<char*>("l-parent click"), isBubble);
503             UIView::OnClickListener* clickListenerChild =
504                 new TestOnClickListener(label1, const_cast<char*>("l-click"), isBubble);
505             testView->SetOnClickListener(clickListenerChild);
506             parentContainer->SetOnClickListener(clickListenerParent);
507 
508             UIView::OnLongPressListener* longTouchListenerParent =
509                 new TestOnLongPressListener(label2, const_cast<char*>("l-parent long press"), isBubble);
510             UIView::OnLongPressListener* longTouchListenerChild =
511                 new TestOnLongPressListener(label1, const_cast<char*>("l-long press"), isBubble);
512             testView->SetOnLongPressListener(longTouchListenerChild);
513             parentContainer->SetOnLongPressListener(longTouchListenerParent);
514 
515             UIView::OnTouchListener* touchListenerParent = new TestOnTouchListener(
516                 label2, const_cast<char*>("l-parent press"), const_cast<char*>("l-parent release"),
517                 const_cast<char*>("l-parent cancel"), isBubble);
518             UIView::OnTouchListener* touchListenerChild =
519                 new TestOnTouchListener(label1, const_cast<char*>("l-press"), const_cast<char*>("l-release"),
520                                         const_cast<char*>("l-cancel"), isBubble);
521             testView->SetOnTouchListener(touchListenerChild);
522             parentContainer->SetOnTouchListener(touchListenerParent);
523         }
524 
525         positionY_ += ITEM_H;
526     }
527 }
528 
InnerBubbleDragTest(const char * title,bool childDraggable,bool parentDraggable,bool hasListener,bool isBubble)529 void UITestInputEvent::InnerBubbleDragTest(const char* title,
530                                            bool childDraggable,
531                                            bool parentDraggable,
532                                            bool hasListener,
533                                            bool isBubble)
534 {
535     int32_t itemH1 = ITEM_H * 2; // 2 times of ITEM_H
536     int32_t itemH2 = itemH1 + ITEM_H;
537     int32_t itemH3 = itemH2 + ITEM_H;
538     int32_t halfScreenWith = Screen::GetInstance().GetWidth() / 2; // 2: half screen width
539     if (container_ != nullptr) {
540         int32_t offset = 30;                                         // 40 pixel offset
541         UILabel* label = new UILabel();
542         container_->Add(label);
543         // 2: half screen width
544         label->SetPosition(halfScreenWith + TEXT_DISTANCE_TO_LEFT_SIDE, positionY_,
545                            halfScreenWith - TEXT_DISTANCE_TO_LEFT_SIDE, TEXT_H);
546         label->SetText(title);
547         label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE);
548         positionY_ += (TEXT_H + GAP);
549 
550         OHOS::TestUIScrollView* parentScroll = new TestUIScrollView();
551         parentScroll->SetStyle(STYLE_BACKGROUND_COLOR, Color::Blue().full);
552         parentScroll->SetPosition(halfScreenWith + TEXT_DISTANCE_TO_LEFT_SIDE, positionY_, itemH1, itemH1);
553         parentScroll->SetThrowDrag(parentDraggable);
554         parentScroll->SetDraggable(parentDraggable);
555         container_->Add(parentScroll);
556 
557         OHOS::TestUIScrollView* childScroll = new TestUIScrollView();
558         childScroll->SetStyle(STYLE_BACKGROUND_COLOR, Color::Red().full);
559         childScroll->SetPosition(offset, offset, itemH2, itemH2);
560         childScroll->SetThrowDrag(childDraggable);
561         childScroll->SetDraggable(childDraggable);
562         parentScroll->Add(childScroll);
563 
564         UILabelButton* button1 = new UILabelButton();
565         button1->SetStyle(STYLE_BACKGROUND_COLOR, Color::Yellow().full);
566         button1->SetText("button1");
567         button1->SetPosition(offset, offset, itemH3 * 2, itemH3); // 2: tow width
568         childScroll->Add(button1);
569 
570         UILabel* label1 = new UILabel();
571         container_->Add(label1);
572         label1->SetPosition(itemH3 + offset + halfScreenWith, positionY_ + 2 * GAP, TEXT_W, TEXT_H); // 2: tow gap
573         label1->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE);
574         childScroll->SetLabel(label1);
575 
576         UILabel* label2 = new UILabel();
577         container_->Add(label2);
578         label2->SetPosition(itemH3 + offset + halfScreenWith, positionY_ + 6 * GAP, TEXT_W, TEXT_H); // 6: tow gap
579         label2->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE);
580         parentScroll->SetLabel(label2);
581 
582         if (hasListener) {
583             UIView::OnClickListener* clickListenerParent =
584                 new TestOnClickListener(label2, const_cast<char*>("l-parent click"), isBubble);
585             UIView::OnClickListener* clickListenerChild =
586                 new TestOnClickListener(label1, const_cast<char*>("l-click"), isBubble);
587             childScroll->SetOnClickListener(clickListenerChild);
588             parentScroll->SetOnClickListener(clickListenerParent);
589 
590             UIView::OnLongPressListener* longTouchListenerParent =
591                 new TestOnLongPressListener(label2, const_cast<char*>("l-parent long press"), isBubble);
592             UIView::OnLongPressListener* longTouchListenerChild =
593                 new TestOnLongPressListener(label1, const_cast<char*>("l-long press"), isBubble);
594             childScroll->SetOnLongPressListener(longTouchListenerChild);
595             parentScroll->SetOnLongPressListener(longTouchListenerParent);
596 
597             UIView::OnTouchListener* touchListenerParent = new TestOnTouchListener(
598                 label2, const_cast<char*>("l-parent press"), const_cast<char*>("l-parent release"),
599                 const_cast<char*>("l-parent cancel"), isBubble);
600             UIView::OnTouchListener* touchListenerChild =
601                 new TestOnTouchListener(label1, const_cast<char*>("l-press"), const_cast<char*>("l-release"),
602                                         const_cast<char*>("l-cancel"), isBubble);
603             childScroll->SetOnTouchListener(touchListenerChild);
604             parentScroll->SetOnTouchListener(touchListenerParent);
605 
606             UIView::OnDragListener* dragListenerParent = new TestOnDragListener(
607                 label2, const_cast<char*>("l-dragStart parent"), const_cast<char*>("l-drag parent"),
608                 const_cast<char*>("l-dragEnd parent"), isBubble);
609             UIView::OnDragListener* dragListenerChild =
610                 new TestOnDragListener(label1, const_cast<char*>("l-dragStart"), const_cast<char*>("l-drag"),
611                                        const_cast<char*>("l-dragEnd"), isBubble);
612             childScroll->SetOnDragListener(dragListenerChild);
613             parentScroll->SetOnDragListener(dragListenerParent);
614         }
615         positionY_ += itemH1;
616     }
617 }
618 } // namespace OHOS
619