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