• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_RENDER_ADAPTER_FOCUS_MODIFIER_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_RENDER_ADAPTER_FOCUS_MODIFIER_H
18 
19 #include "render_service_client/core/modifier/rs_extended_modifier.h"
20 #include "render_service_client/core/modifier/rs_property.h"
21 #include "render_service_client/core/ui/rs_node.h"
22 
23 #include "base/memory/referenced.h"
24 #include "core/components_ng/base/frame_node.h"
25 #include "core/components_ng/property/gradient_property.h"
26 #include "core/components_ng/render/adapter/rosen_modifier_adapter.h"
27 
28 namespace OHOS::Ace::NG {
29 
30 using RSModifierType = Rosen::RSModifierType;
31 using RSExtendedModifier = Rosen::RSExtendedModifier;
32 using RSPropertyBase = Rosen::RSPropertyBase;
33 
34 class FocusModifier {
35 public:
36     FocusModifier() = default;
37     ~FocusModifier() = default;
SetRoundRect(const RoundRect & rect,float borderWidth)38     virtual void SetRoundRect(const RoundRect& rect, float borderWidth)
39     {
40         CHECK_NULL_VOID(&rect);
41         auto cornTopLeft = rect.GetCornerRadius(RoundRect::CornerPos::TOP_LEFT_POS);
42         auto cornTopRight = rect.GetCornerRadius(RoundRect::CornerPos::TOP_RIGHT_POS);
43         auto cornBottomLeft = rect.GetCornerRadius(RoundRect::CornerPos::BOTTOM_LEFT_POS);
44         auto cornBottomRight = rect.GetCornerRadius(RoundRect::CornerPos::BOTTOM_RIGHT_POS);
45 #ifndef USE_ROSEN_DRAWING
46 #ifndef USE_GRAPHIC_TEXT_GINE
47         roundRect_.SetRect(
48             rosen::Rect(rect.GetRect().Left(), rect.GetRect().Top(), rect.GetRect().Right(), rect.GetRect().Bottom()));
49         InitRoundRect(cornTopLeft, cornTopRight, cornBottomLeft, cornBottomRight);
50 #else
51         roundRect_.SetRect(
52             RSRect(rect.GetRect().Left(), rect.GetRect().Top(), rect.GetRect().Right(), rect.GetRect().Bottom()));
53         InitRoundRect(cornTopLeft, cornTopRight, cornBottomLeft, cornBottomRight);
54 #endif
55 #else
56         roundRect_.SetRect(
57             RSRect(rect.GetRect().Left(), rect.GetRect().Top(), rect.GetRect().Right(), rect.GetRect().Bottom()));
58         InitRoundRect(cornTopLeft, cornTopRight, cornBottomLeft, cornBottomRight);
59 #endif
60         InitOverlayRect(rect, borderWidth);
61     }
62 
GetOverlayRect()63     std::shared_ptr<Rosen::RectF> GetOverlayRect()
64     {
65         return overlayRect_;
66     }
67 
SetPaintColor(const Color & paintColor)68     void SetPaintColor(const Color& paintColor)
69     {
70         paintColor_ = paintColor;
71     }
72 
SetFrameNode(const RefPtr<FrameNode> & frameNode)73     void SetFrameNode(const RefPtr<FrameNode>& frameNode)
74     {
75         weakFrameNode_ = AceType::WeakClaim(AceType::RawPtr(frameNode));
76     }
77 
78 protected:
79     RSRoundRect roundRect_;
80     Color paintColor_;
81     float paintWidthPx_ = 0.0f;
82     WeakPtr<FrameNode> weakFrameNode_;
83 
84 private:
InitOverlayRect(const RoundRect & rect,float borderWidth)85     void InitOverlayRect(const RoundRect& rect, float borderWidth)
86     {
87         RSScalar halfDenominator = 2.0f;
88         overlayRect_ = std::make_shared<Rosen::RectF>(rect.GetRect().Left() - borderWidth / halfDenominator,
89             rect.GetRect().Top() - borderWidth / halfDenominator, rect.GetRect().Width() + borderWidth,
90             rect.GetRect().Height() + borderWidth);
91         paintWidthPx_ = borderWidth;
92     }
93 
InitRoundRect(EdgeF cornTopLeft,EdgeF cornTopRight,EdgeF cornBottomLeft,EdgeF cornBottomRight)94     void InitRoundRect(EdgeF cornTopLeft, EdgeF cornTopRight, EdgeF cornBottomLeft, EdgeF cornBottomRight)
95     {
96         roundRect_.SetCornerRadius(RSRoundRect::CornerPos::TOP_LEFT_POS, cornTopLeft.x, cornTopLeft.y);
97         roundRect_.SetCornerRadius(RSRoundRect::CornerPos::TOP_RIGHT_POS, cornTopRight.x, cornTopRight.y);
98         roundRect_.SetCornerRadius(RSRoundRect::CornerPos::BOTTOM_LEFT_POS, cornBottomLeft.x, cornBottomLeft.y);
99         roundRect_.SetCornerRadius(RSRoundRect::CornerPos::BOTTOM_RIGHT_POS, cornBottomRight.x, cornBottomRight.y);
100     }
101 
102     std::shared_ptr<Rosen::RectF> overlayRect_;
103 };
104 
105 } // namespace OHOS::Ace::NG
106 
107 #endif