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 "components/ui_repeat_button.h"
17 #include "components/ui_button.h"
18 
19 namespace OHOS {
20 UIRepeatButton* UIRepeatButton::repeatButton_ = nullptr;
21 
22 /** default tick interval 200ms. */
UIRepeatButton()23 UIRepeatButton::UIRepeatButton() : ticksInterval_(200), event_({ 0, 0 }),
24     longPressed_(false), timerRepeatID_(0) {}
25 
~UIRepeatButton()26 UIRepeatButton::~UIRepeatButton() {}
27 
OnDraw(BufferInfo & gfxDstBuffer,const Rect & invalidatedArea)28 void UIRepeatButton::OnDraw(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea)
29 {
30     UIButton::OnDraw(gfxDstBuffer, invalidatedArea);
31 }
32 
OnReleaseEvent(const ReleaseEvent & event)33 bool UIRepeatButton::OnReleaseEvent(const ReleaseEvent& event)
34 {
35     if (longPressed_ && (timerRepeatID_ != 0)) {
36         longPressed_ = false;
37     }
38     return UIButton::OnReleaseEvent(event);
39 }
40 
OnClickEvent(const ClickEvent & event)41 bool UIRepeatButton::OnClickEvent(const ClickEvent& event)
42 {
43     SetEvent(event);
44     return UIButton::OnClickEvent(event);
45 }
46 
HandleTickEvent()47 void UIRepeatButton::HandleTickEvent()
48 {
49     UIButton::OnClickEvent(event_);
50 }
51 
OnLongPressEvent(const LongPressEvent & event)52 bool UIRepeatButton::OnLongPressEvent(const LongPressEvent& event)
53 {
54     longPressed_ = true;
55     repeatButton_ = this;
56     return UIButton::OnLongPressEvent(event);
57 }
58 
SetEvent(const ClickEvent & event)59 void UIRepeatButton::SetEvent(const ClickEvent& event)
60 {
61     event_ = event;
62 }
63 } // namespace OHOS
64