• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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_RICH_EDITOR_RICH_EDITOR_THEME_WRAPPER_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_RICH_EDITOR_RICH_EDITOR_THEME_WRAPPER_H
18 
19 #include "base/memory/ace_type.h"
20 #include "core/components_ng/pattern/rich_editor/rich_editor_theme.h"
21 #include "core/components_ng/token_theme/token_theme_wrapper.h"
22 
23 namespace OHOS::Ace::NG {
24 
25 class RichEditorThemeWrapper : public RichEditorTheme, public TokenThemeWrapper {
26     DECLARE_ACE_TYPE(RichEditorThemeWrapper, RichEditorTheme);
27 
28 public:
29     class WrapperBuilder : public Builder {
30     public:
31         WrapperBuilder() = default;
32         ~WrapperBuilder() = default;
33 
BuildWrapper(const RefPtr<ThemeConstants> & themeConstants)34         RefPtr<TokenThemeWrapper> BuildWrapper(const RefPtr<ThemeConstants>& themeConstants) const
35         {
36             auto wrapper = AceType::MakeRefPtr<RichEditorThemeWrapper>();
37             auto theme = AceType::DynamicCast<RichEditorTheme>(wrapper);
38             CHECK_NULL_RETURN(themeConstants, wrapper);
39             InitThemeDefaults(themeConstants, theme);
40             ParsePattern(themeConstants, theme);
41             return wrapper;
42         }
43     };
44 
45     ~RichEditorThemeWrapper() override = default;
46 
ApplyTokenTheme(const TokenTheme & theme)47     void ApplyTokenTheme(const TokenTheme& theme) override
48     {
49         CHECK_NULL_VOID(Container::GreatOrEqualAPITargetVersion(PlatformVersion::VERSION_TWENTY));
50         if (const auto& colors = theme.Colors(); colors) {
51             textStyle_.SetTextColor(colors->FontPrimary());
52             textStyle_.SetTextDecorationColor(colors->FontPrimary());
53             urlDefaultColor_ = colors->FontEmphasize();
54             urlDisabledColor_= urlDefaultColor_.BlendOpacity(urlDisabledOpacity_);
55             urlHoverColor_ = colors->InteractiveHover();
56             urlPressColor_ = colors->InteractivePressed();
57         }
58     }
59 
60 protected:
61     RichEditorThemeWrapper() = default;
62 };
63 
64 } // namespace OHOS::Ace::NG
65 
66 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_RICH_EDITOR_RICH_EDITOR_THEME_WRAPPER_H
67