diff --git a/interfaces/innerkits/wm/window.h b/interfaces/innerkits/wm/window.h index 9664a7b5..6599f3df 100644 --- a/interfaces/innerkits/wm/window.h +++ b/interfaces/innerkits/wm/window.h @@ -150,6 +150,9 @@ public: virtual bool IsKeepScreenOn() const = 0; virtual void SetTurnScreenOn(bool turnScreenOn) = 0; virtual bool IsTurnScreenOn() const = 0; + virtual void SetBackgroundColor(const std::string& color) = 0; + virtual void SetTransparent(bool isTransparent) = 0; + virtual bool IsTransparent() const = 0; virtual WMError RequestFocus() const = 0; // AddInputEventListener is for api 7 diff --git a/utils/include/window_helper.h b/utils/include/window_helper.h index 360145b4..c25ff4d8 100644 --- a/utils/include/window_helper.h +++ b/utils/include/window_helper.h @@ -200,6 +200,7 @@ public: return AvoidPosType::AVOID_POS_UNKNOWN; } +private: WindowHelper() = default; ~WindowHelper() = default; }; diff --git a/wm/BUILD.gn b/wm/BUILD.gn index e9cb5bab..b1ccdf80 100644 --- a/wm/BUILD.gn +++ b/wm/BUILD.gn @@ -38,6 +38,7 @@ config("libwm_public_config") { ohos_shared_library("libwm") { sources = [ "../wmserver/src/window_manager_proxy.cpp", + "src/color_parser.cpp", "src/input_transfer_station.cpp", "src/static_call.cpp", "src/vsync_station.cpp", diff --git a/wm/include/color_parser.h b/wm/include/color_parser.h new file mode 100644 index 00000000..58445679 --- /dev/null +++ b/wm/include/color_parser.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2022-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_ROSEN_COLOR_PARSER_H +#define OHOS_ROSEN_COLOR_PARSER_H + +#include + +namespace OHOS { +namespace Rosen { +class ColorParser { +public: + static bool Parse(const std::string& colorStr, uint32_t& colorValue); + +private: + static bool IsValidHexString(const std::string& colorStr); + + ColorParser() = default; + ~ColorParser() = default; +}; +} +} +#endif // OHOS_ROSEN_COLOR_PARSER_H diff --git a/wm/include/window_impl.h b/wm/include/window_impl.h index 73ba8952..51b29e42 100644 --- a/wm/include/window_impl.h +++ b/wm/include/window_impl.h @@ -35,6 +35,25 @@ namespace OHOS { namespace Rosen { +union ColorParam { +#if BIG_ENDIANNESS + struct { + uint8_t alpha; + uint8_t red; + uint8_t green; + uint8_t blue; + } argb; +#else + struct { + uint8_t blue; + uint8_t green; + uint8_t red; + uint8_t alpha; + } argb; +#endif + uint32_t value; +}; + class WindowImpl : public Window { #define CALL_LIFECYCLE_LISTENER(windowLifecycleCb) \ do { \ @@ -108,6 +127,9 @@ public: virtual bool IsKeepScreenOn() const override; virtual void SetTurnScreenOn(bool turnScreenOn) override; virtual bool IsTurnScreenOn() const override; + virtual void SetBackgroundColor(const std::string& color) override; + virtual void SetTransparent(bool isTransparent) override; + virtual bool IsTransparent() const override; virtual bool IsDecorEnable() const override; virtual WMError Maximize() override; @@ -275,6 +297,7 @@ private: Rect startRectExceptCorner_ = { 0, 0, 0, 0 }; bool keepScreenOn_ = false; bool turnScreenOn_ = false; + ColorParam backgroundColor_ = { .value = 0xff000000 }; std::shared_ptr keepScreenLock_; }; } diff --git a/wm/src/color_parser.cpp b/wm/src/color_parser.cpp new file mode 100644 index 00000000..720d97e1 --- /dev/null +++ b/wm/src/color_parser.cpp @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2022-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "color_parser.h" +#include + +#include "window_manager_hilog.h" + +namespace OHOS { +namespace Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "ColorParser"}; +} + +bool ColorParser::Parse(const std::string& colorStr, uint32_t& colorValue) +{ + if (colorStr.empty()) { + WLOGFE("color string is empty"); + return false; + } + + if (colorStr[0] == '#') { // start with '#' + std::string color = colorStr.substr(1); + if (!IsValidHexString(color)) { + return false; + } + char* ptr; + colorValue = std::strtoul(color.c_str(), &ptr, 16); // convert hex string to number + if (colorStr.size() == 7) { // #RRGGBB: RRGGBB -> AARRGGBB + colorValue |= 0xff000000; + return true; + } else if (colorStr.size() == 9) { // #AARRGGBB + return true; + } else { + // do nothing + } + } + return false; +} + +bool ColorParser::IsValidHexString(const std::string& colorStr) +{ + if (colorStr.empty()) { + return false; + } + for (char ch : colorStr) { + if ((ch >= '0' && ch <= '9') || (ch >= 'a' && ch <= 'f') || (ch >= 'A' && ch <= 'F')) { + continue; + } + return false; + } + return true; +} +} // namespace Rosen +} // namespace OHOS \ No newline at end of file diff --git a/wm/src/window_impl.cpp b/wm/src/window_impl.cpp index 1567f559..02a38cce 100644 --- a/wm/src/window_impl.cpp +++ b/wm/src/window_impl.cpp @@ -20,6 +20,7 @@ #include #include +#include "color_parser.h" #include "display_manager.h" #include "singleton_container.h" #include "window_adapter.h" @@ -196,6 +197,9 @@ bool WindowImpl::GetShowState() const void WindowImpl::SetFocusable(bool isFocusable) { + if (!IsWindowValid()) { + return; + } property_->SetFocusable(isFocusable); UpdateProperty(PropertyChangeAction::ACTION_UPDATE_FOCUSABLE); } @@ -207,6 +211,9 @@ bool WindowImpl::GetFocusable() const void WindowImpl::SetTouchable(bool isTouchable) { + if (!IsWindowValid()) { + return; + } property_->SetTouchable(isTouchable); UpdateProperty(PropertyChangeAction::ACTION_UPDATE_TOUCHABLE); } @@ -849,6 +856,39 @@ bool WindowImpl::IsTurnScreenOn() const return turnScreenOn_; } +void WindowImpl::SetBackgroundColor(const std::string& color) +{ + uint32_t colorValue; + if (ColorParser::Parse(color, colorValue)) { + backgroundColor_.value = colorValue; + // need update background color for ace + return; + } + WLOGFE("invalid color string: %{public}s", color.c_str()); +} + +void WindowImpl::SetTransparent(bool isTransparent) +{ + if (isTransparent) { + backgroundColor_.argb.alpha = 0x00; + } else { + // need get background color from ace to backgroundColor_.value + if (backgroundColor_.argb.alpha == 0x00) { + backgroundColor_.argb.alpha = 0xff; + // need update background color for ace + } + } +} + +bool WindowImpl::IsTransparent() const +{ + // need get background color from ace to backgroundColor_.value + if (backgroundColor_.argb.alpha == 0x00) { + return true; + } + return false; +} + WMError WindowImpl::Drag(const Rect& rect) { if (!IsWindowValid()) {