1 /*
2  * Copyright (c) 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 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_RENDER_ADAPTER_MOUSE_SELECT_MODIFIER_H
16 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_RENDER_ADAPTER_MOUSE_SELECT_MODIFIER_H
17 
18 #include "render_service_client/core/modifier/rs_extended_modifier.h"
19 
20 #include "core/components_ng/render/adapter/rosen_modifier_adapter.h"
21 
22 namespace OHOS::Ace::NG {
23 
24 class MouseSelectModifier : public Rosen::RSForegroundStyleModifier {
25 public:
26     MouseSelectModifier() = default;
27     ~MouseSelectModifier() override = default;
28 
Draw(RSDrawingContext & context)29     void Draw(RSDrawingContext& context) const override
30     {
31         CHECK_NULL_VOID(rectProperty_);
32 
33 #ifndef USE_ROSEN_DRAWING
34         std::shared_ptr<SkCanvas> skCanvas { context.canvas, [](SkCanvas* /*unused*/) {} };
35         RSCanvas rsCanvas(&skCanvas);
36         CHECK_NULL_VOID(&rsCanvas);
37         paintTask_(rectProperty_->Get(), rsCanvas);
38 #else
39         CHECK_NULL_VOID(context.canvas);
40         CHECK_NULL_VOID(paintTask_);
41         paintTask_(rectProperty_->Get(), *context.canvas);
42 #endif
43     }
44 
SetSelectRect(const RectF & rect)45     void SetSelectRect(const RectF& rect)
46     {
47         if (rectProperty_ == nullptr) {
48             rectProperty_ = std::make_shared<Rosen::RSProperty<RectF>>(rect);
49             AttachProperty(rectProperty_);
50         } else {
51             rectProperty_->Set(rect);
52         }
53     }
54 
SetPaintTask(const std::function<void (const RectF &,RSCanvas &)> & paintTask)55     void SetPaintTask(const std::function<void(const RectF&, RSCanvas&)>& paintTask)
56     {
57         paintTask_ = paintTask;
58     }
59 
60 private:
61     std::shared_ptr<Rosen::RSProperty<RectF>> rectProperty_;
62     std::function<void(const RectF&, RSCanvas&)> paintTask_;
63 
64     ACE_DISALLOW_COPY_AND_MOVE(MouseSelectModifier);
65 };
66 
67 } // namespace OHOS::Ace::NG
68 
69 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_RENDER_ADAPTER_MOUSE_SELECT_MODIFIER_H
70