add SetTransparent & SetBackgroundColor interface

Signed-off-by: xiahaiqin <xiahaiqin1@huawei.com>
Change-Id: Ie7756087ff60c6de964a3297c3b74c066a13032a
This commit is contained in:
xiahaiqin
2022-03-29 21:24:13 +08:00
parent 7e422e325a
commit ae183e2ec9
7 changed files with 170 additions and 0 deletions
+3
View File
@@ -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
+1
View File
@@ -200,6 +200,7 @@ public:
return AvoidPosType::AVOID_POS_UNKNOWN;
}
private:
WindowHelper() = default;
~WindowHelper() = default;
};
+1
View File
@@ -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",
+35
View File
@@ -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 <string>
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
+23
View File
@@ -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<PowerMgr::RunningLock> keepScreenLock_;
};
}
+67
View File
@@ -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 <cstdlib>
#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
+40
View File
@@ -20,6 +20,7 @@
#include <ability_manager_client.h>
#include <power_mgr_client.h>
#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()) {