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_FOCUS_STATE_MODIFIER_H 16 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_RENDER_ADAPTER_FOCUS_STATE_MODIFIER_H 17 18 #include "render_service_client/core/modifier/rs_extended_modifier.h" 19 #include "render_service_client/core/modifier/rs_property.h" 20 #include "render_service_client/core/ui/rs_node.h" 21 22 #include "core/components_ng/property/gradient_property.h" 23 #include "core/components_ng/render/adapter/rosen_modifier_adapter.h" 24 25 namespace OHOS::Ace::NG { 26 27 using RSModifierType = Rosen::RSModifierType; 28 using RSExtendedModifier = Rosen::RSExtendedModifier; 29 using RSPropertyBase = Rosen::RSPropertyBase; 30 31 class RS_EXPORT FocusStateModifier : public RSOverlayStyleModifier { 32 public: 33 FocusStateModifier() = default; 34 GetModifierType()35 RSModifierType GetModifierType() const override 36 { 37 return RSModifierType::OVERLAY_STYLE; 38 } 39 Draw(RSDrawingContext & context)40 void Draw(RSDrawingContext& context) const override 41 { 42 #ifndef USE_ROSEN_DRAWING 43 std::shared_ptr<SkCanvas> skCanvas { context.canvas, [](SkCanvas* /*unused*/) {} }; 44 RSCanvas rsCanvas(&skCanvas); 45 CHECK_NULL_VOID(&rsCanvas); 46 paintTask_(roundRect_, rsCanvas); 47 #else 48 CHECK_NULL_VOID(context.canvas); 49 CHECK_NULL_VOID(paintTask_); 50 paintTask_(roundRect_, *context.canvas); 51 #endif 52 } 53 SetRoundRect(const RoundRect & rect,float borderWidth)54 void SetRoundRect(const RoundRect& rect, float borderWidth) 55 { 56 #ifndef USE_ROSEN_DRAWING 57 roundRect_.SetRect( 58 rosen::Rect(rect.GetRect().Left(), rect.GetRect().Top(), rect.GetRect().Right(), rect.GetRect().Bottom())); 59 roundRect_.SetCornerRadius(rosen::RoundRect::CornerPos::TOP_LEFT_POS, 60 rect.GetCornerRadius(RoundRect::CornerPos::TOP_LEFT_POS).x, 61 rect.GetCornerRadius(RoundRect::CornerPos::TOP_LEFT_POS).y); 62 roundRect_.SetCornerRadius(rosen::RoundRect::CornerPos::TOP_RIGHT_POS, 63 rect.GetCornerRadius(RoundRect::CornerPos::TOP_RIGHT_POS).x, 64 rect.GetCornerRadius(RoundRect::CornerPos::TOP_RIGHT_POS).y); 65 roundRect_.SetCornerRadius(rosen::RoundRect::CornerPos::BOTTOM_LEFT_POS, 66 rect.GetCornerRadius(RoundRect::CornerPos::BOTTOM_LEFT_POS).x, 67 rect.GetCornerRadius(RoundRect::CornerPos::BOTTOM_LEFT_POS).y); 68 roundRect_.SetCornerRadius(rosen::RoundRect::CornerPos::BOTTOM_RIGHT_POS, 69 rect.GetCornerRadius(RoundRect::CornerPos::BOTTOM_RIGHT_POS).x, 70 rect.GetCornerRadius(RoundRect::CornerPos::BOTTOM_RIGHT_POS).y); 71 #else 72 roundRect_.SetRect( 73 RSRect(rect.GetRect().Left(), rect.GetRect().Top(), rect.GetRect().Right(), rect.GetRect().Bottom())); 74 roundRect_.SetCornerRadius(RSRoundRect::CornerPos::TOP_LEFT_POS, 75 rect.GetCornerRadius(RoundRect::CornerPos::TOP_LEFT_POS).x, 76 rect.GetCornerRadius(RoundRect::CornerPos::TOP_LEFT_POS).y); 77 roundRect_.SetCornerRadius(RSRoundRect::CornerPos::TOP_RIGHT_POS, 78 rect.GetCornerRadius(RoundRect::CornerPos::TOP_RIGHT_POS).x, 79 rect.GetCornerRadius(RoundRect::CornerPos::TOP_RIGHT_POS).y); 80 roundRect_.SetCornerRadius(RSRoundRect::CornerPos::BOTTOM_LEFT_POS, 81 rect.GetCornerRadius(RoundRect::CornerPos::BOTTOM_LEFT_POS).x, 82 rect.GetCornerRadius(RoundRect::CornerPos::BOTTOM_LEFT_POS).y); 83 roundRect_.SetCornerRadius(RSRoundRect::CornerPos::BOTTOM_RIGHT_POS, 84 rect.GetCornerRadius(RoundRect::CornerPos::BOTTOM_RIGHT_POS).x, 85 rect.GetCornerRadius(RoundRect::CornerPos::BOTTOM_RIGHT_POS).y); 86 #endif 87 } 88 SetPaintTask(const std::function<void (const RSRoundRect &,RSCanvas &)> & paintTask)89 void SetPaintTask(const std::function<void(const RSRoundRect&, RSCanvas&)>& paintTask) 90 { 91 paintTask_ = paintTask; 92 } 93 94 private: 95 RSRoundRect roundRect_; 96 std::function<void(const RSRoundRect&, RSCanvas&)> paintTask_; 97 98 ACE_DISALLOW_COPY_AND_MOVE(FocusStateModifier); 99 }; 100 } // namespace OHOS::Ace::NG 101 102 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_RENDER_ADAPTER_FOCUS_STATE_MODIFIER_H 103