• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 "core/components/mouse_listener/render_mouse_listener.h"
17 
18 #include "core/components/mouse_listener/mouse_listener_component.h"
19 #include "core/event/ace_event_helper.h"
20 
21 namespace OHOS::Ace {
22 
Create()23 RefPtr<RenderNode> RenderMouseListener::Create()
24 {
25     return AceType::MakeRefPtr<RenderMouseListener>();
26 }
27 
RenderMouseListener()28 RenderMouseListener::RenderMouseListener() : recognizer_(AceType::MakeRefPtr<MouseRawRecognizer>()) {}
29 
Update(const RefPtr<Component> & component)30 void RenderMouseListener::Update(const RefPtr<Component>& component)
31 {
32     auto mouseComponent = AceType::DynamicCast<MouseListenerComponent>(component);
33     ACE_DCHECK(mouseComponent);
34     SetOnMouse(AceAsyncEvent<void(const MouseEventInfo&)>::Create(mouseComponent->GetOnMouseId(), context_));
35     SetOnMouseHover(AceAsyncEvent<void()>::Create(mouseComponent->GetOnMouseHoverId(), context_));
36     SetOnMouseHoverExit(AceAsyncEvent<void()>::Create(mouseComponent->GetOnMouseHoverExitId(), context_));
37     // Ace 2.0
38     SetOnHover(mouseComponent->GetOnHoverId());
39 }
40 
OnMouseTestHit(const Offset & coordinateOffset,MouseRawResult & result)41 void RenderMouseListener::OnMouseTestHit(const Offset& coordinateOffset, MouseRawResult& result)
42 {
43     LOGD("render touch listener: on touch test hit!");
44     recognizer_->SetCoordinateOffset(coordinateOffset);
45     result.emplace_back(recognizer_);
46 }
47 
HandleMouseHoverEvent(MouseState mouseState)48 void RenderMouseListener::HandleMouseHoverEvent(MouseState mouseState)
49 {
50     if (recognizer_) {
51         recognizer_->HandleHoverEvent(mouseState);
52     }
53 }
54 
UpdateTouchRect()55 void RenderMouseListener::UpdateTouchRect()
56 {
57     const auto& children = GetChildren();
58     for (auto iter = children.rbegin(); iter != children.rend(); ++iter) {
59         auto& child = *iter;
60         for (auto& rect : child->GetTouchRectList()) {
61             // unified coordinate system
62             Rect newRect = rect;
63             newRect.SetOffset(rect.GetOffset() + GetPaintRect().GetOffset());
64             touchRectList_.emplace_back(newRect);
65         }
66     }
67 }
68 
69 } // namespace OHOS::Ace