Fix web backgroundcolor problem

Signed-off-by: liyou88 <liyou44@huawei.com>
Change-Id: Ie7c70217889195c7a14a094c61b56aa882630efa
This commit is contained in:
liyou88 2024-09-13 17:01:25 +08:00
parent 2a4cb3e8c7
commit 2012db50cc
6 changed files with 24 additions and 8 deletions

View File

@ -3535,7 +3535,7 @@ void JSWeb::BackgroundColor(const JSCallbackInfo& info)
}
Color backgroundColor;
if (!ParseJsColor(info[0], backgroundColor)) {
return;
backgroundColor = WebModel::GetInstance()->GetDefaultBackgroundColor();
}
WebModel::GetInstance()->SetBackgroundColor(backgroundColor);
}

View File

@ -35,6 +35,7 @@ public:
std::function<void(const std::string&)>&& setHapPathCallback, int32_t parentWebId, bool popup,
RenderMode renderMode = RenderMode::ASYNC_RENDER, bool incognitoMode = false,
const std::string& sharedRenderProcessToken = "") = 0;
virtual Color GetDefaultBackgroundColor() { return Color::WHITE; }
virtual void SetCustomScheme(const std::string& cmdLine) = 0;
virtual void SetFocusable(bool focusable) {};
virtual void SetFocusNode(bool isFocusNode) {};

View File

@ -583,6 +583,13 @@ void WebModelNG::SetScreenCaptureRequestEventId(std::function<void(const BaseEve
webEventHub->SetOnScreenCaptureRequestEvent(std::move(uiCallback));
}
Color WebModelNG::GetDefaultBackgroundColor()
{
auto webPattern = ViewStackProcessor::GetInstance()->GetMainFrameNodePattern<WebPattern>();
CHECK_NULL_RETURN(webPattern, Color::WHITE);
return webPattern->GetDefaultBackgroundColor();
}
void WebModelNG::SetBackgroundColor(Color backgroundColor)
{
auto webPattern = ViewStackProcessor::GetInstance()->GetMainFrameNodePattern<WebPattern>();

View File

@ -39,6 +39,7 @@ public:
std::function<void(const std::string&)>&& setHapPathCallback, int32_t parentWebId, bool popup,
RenderMode renderMode = RenderMode::ASYNC_RENDER, bool incognitoMode = false,
const std::string& sharedRenderProcessToken = "") override;
Color GetDefaultBackgroundColor() override;
void SetCustomScheme(const std::string& cmdLine) override;
void SetOnCommonDialog(std::function<bool(const BaseEventInfo* info)>&& jsCallback, int dialogEventType) override;
void SetOnConsoleLog(std::function<bool(const BaseEventInfo* info)>&& jsCallback) override;

View File

@ -2545,13 +2545,7 @@ void WebPattern::OnModifyDone()
}
if (!GetBackgroundColor()) {
auto darkMode = GetDarkModeValue(webData_ ? (WebDarkMode::Auto) : (WebDarkMode::Off));
if (GetForceDarkAccessValue(false) &&
(darkMode == WebDarkMode::On || ((darkMode == WebDarkMode::Auto) && (GetSystemColor() == Color::BLACK)))) {
UpdateBackgroundColorRightNow((Color::BLACK).GetValue());
} else {
UpdateBackgroundColorRightNow((Color::WHITE).GetValue());
}
UpdateBackgroundColorRightNow(GetDefaultBackgroundColor().GetValue());
}
// Initialize events such as keyboard, focus, etc.
@ -4737,6 +4731,17 @@ void WebPattern::OnVisibleAreaChange(bool isVisible)
}
}
Color WebPattern::GetDefaultBackgroundColor()
{
auto darkMode = GetDarkModeValue(webData_ ? (WebDarkMode::Auto) : (WebDarkMode::Off));
if (GetForceDarkAccessValue(false) &&
(darkMode == WebDarkMode::On || ((darkMode == WebDarkMode::Auto) && (GetSystemColor() == Color::BLACK)))) {
return Color::BLACK;
} else {
return Color::WHITE;
}
}
void WebPattern::UpdateBackgroundColorRightNow(int32_t color)
{
auto host = GetHost();

View File

@ -204,6 +204,8 @@ public:
void NotifyFillRequestFailed(int32_t errCode, const std::string& fillContent = "", bool isPopup = false) override;
Color GetDefaultBackgroundColor();
void SetWebSrc(const std::string& webSrc)
{
if (webSrc_ != webSrc_) {