From: Bowon Ryu Date: Mon, 28 Jun 2021 05:31:57 +0000 (+0900) Subject: [Tizen] Fix behaviour when PreeditStyle is REVERSE X-Git-Tag: accepted/tizen/6.0/unified/20211026.160138^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F62%2F265562%2F2;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git [Tizen] Fix behaviour when PreeditStyle is REVERSE In REVERSE case, TextColor uses text's background color. but in most cases, there is no text's background color and the the default alpha value is 0. So in this case, the text is not visible. (text color's alpah value becomes 0) To solve this, if there is no text's background, the control's color is used. And if there is no control's color, set white or black according to the contrast. In this case, the color is determined based on W3C recommendations. (https://www.w3.org/TR/WCAG20/) Change-Id: I251ec3283d761e08bb8214f4e53b0da05ad9ba4f Signed-off-by: Bowon Ryu --- diff --git a/automated-tests/src/dali-toolkit-internal/utc-Dali-Text-Controller.cpp b/automated-tests/src/dali-toolkit-internal/utc-Dali-Text-Controller.cpp index 1d394e6..024942f 100755 --- a/automated-tests/src/dali-toolkit-internal/utc-Dali-Text-Controller.cpp +++ b/automated-tests/src/dali-toolkit-internal/utc-Dali-Text-Controller.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * Copyright (c) 2021 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -386,6 +386,50 @@ int UtcDaliTextControllerImfPreeditStyle(void) END_TEST; } +int UtcDaliTextControllerImfPreeditStyleReverse(void) +{ + tet_infoline(" UtcDaliTextControllerImfPreeditStyleReverse"); + ToolkitTestApplication application; + + // Creates a text controller. + ControllerPtr controller = Controller::New(); + + std::string text; + InputMethodContext::EventData imfEvent; + + DALI_TEST_CHECK(controller); + + // Configures the text controller similarly to the text-field. + ConfigureTextField(controller); + + InputMethodContext inputMethodContext = InputMethodContext::New(); + + // Send PRE_EDIT event + imfEvent = InputMethodContext::EventData(InputMethodContext::PRE_EDIT, "Reverse", 0, 7); + controller->OnInputMethodContextEvent(inputMethodContext, imfEvent); + + // For coverage, mEditableControlInterface is required. + // Creates a temporary text-field to use mEditableControlInterface. + TextField field = TextField::New(); + Toolkit::Internal::TextField& fieldImpl = GetImpl(field); + ControllerPtr fieldController = fieldImpl.getController(); + Controller::Impl& fieldControllerImpl = Controller::Impl::GetImplementation(*fieldController.Get()); + Controller::Impl& controllerImpl = Controller::Impl::GetImplementation(*controller.Get()); + + // For coverage, mEditableControlInterface is required. + controllerImpl.mEditableControlInterface = fieldControllerImpl.mEditableControlInterface; + + // Set the preedit style as REVERSE + inputMethodContext.SetPreeditStyle(InputMethodContext::PreeditStyle::REVERSE); + controller->GetNaturalSize(); + + controller->GetText(text); + DALI_TEST_EQUALS("Reverse", text, TEST_LOCATION); + + tet_result(TET_PASS); + END_TEST; +} + int UtcDaliTextControllerTextPopupButtonTouched(void) { tet_infoline(" UtcDaliTextControllerTextPopupButtonTouched"); diff --git a/dali-toolkit/internal/controls/text-controls/text-editor-impl.cpp b/dali-toolkit/internal/controls/text-controls/text-editor-impl.cpp index 09c2f20..bd924a4 100644 --- a/dali-toolkit/internal/controls/text-controls/text-editor-impl.cpp +++ b/dali-toolkit/internal/controls/text-controls/text-editor-impl.cpp @@ -1630,6 +1630,18 @@ Uint32Pair TextEditor::GetTextSelectionRange() const return range; } +void TextEditor::GetControlBackgroundColor(Vector4& color) const +{ + Property::Value propValue = Self().GetProperty(Toolkit::Control::Property::BACKGROUND); + Property::Map* resultMap = propValue.GetMap(); + + Property::Value* colorValue = nullptr; + if(resultMap && (colorValue = resultMap->Find(ColorVisual::Property::MIX_COLOR))) + { + colorValue->Get(color); + } +} + void TextEditor::UpdateScrollBar() { using namespace Dali; diff --git a/dali-toolkit/internal/controls/text-controls/text-editor-impl.h b/dali-toolkit/internal/controls/text-controls/text-editor-impl.h index 8ebda42..1fb17a9 100644 --- a/dali-toolkit/internal/controls/text-controls/text-editor-impl.h +++ b/dali-toolkit/internal/controls/text-controls/text-editor-impl.h @@ -199,6 +199,11 @@ private: // From Control */ void AddDecoration(Actor& actor, bool needsClipping) override; + /** + * @copydoc Text::EditableControlInterface::GetControlBackgroundColor() + */ + void GetControlBackgroundColor(Vector4& color) const override; + // From SelectableControlInterface public: /** diff --git a/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp b/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp index c5b7ef7..f332a73 100644 --- a/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp +++ b/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp @@ -1714,6 +1714,18 @@ void TextField::AddDecoration(Actor& actor, bool needsClipping) } } +void TextField::GetControlBackgroundColor(Vector4& color) const +{ + Property::Value propValue = Self().GetProperty(Toolkit::Control::Property::BACKGROUND); + Property::Map* resultMap = propValue.GetMap(); + + Property::Value* colorValue = nullptr; + if(resultMap && (colorValue = resultMap->Find(ColorVisual::Property::MIX_COLOR))) + { + colorValue->Get(color); + } +} + void TextField::OnSceneConnect(Dali::Actor actor) { if(mHasBeenStaged) diff --git a/dali-toolkit/internal/controls/text-controls/text-field-impl.h b/dali-toolkit/internal/controls/text-controls/text-field-impl.h index b5fc8a4..47f0986 100644 --- a/dali-toolkit/internal/controls/text-controls/text-field-impl.h +++ b/dali-toolkit/internal/controls/text-controls/text-field-impl.h @@ -191,6 +191,11 @@ private: // From Control */ void AddDecoration(Actor& actor, bool needsClipping) override; + /** + * @copydoc Text::EditableControlInterface::GetControlBackgroundColor() + */ + void GetControlBackgroundColor(Vector4& color) const override; + // From SelectableControlInterface public: /** diff --git a/dali-toolkit/internal/text/text-controller-impl.cpp b/dali-toolkit/internal/text/text-controller-impl.cpp index 0cd6adb..ac871d6 100644 --- a/dali-toolkit/internal/text/text-controller-impl.cpp +++ b/dali-toolkit/internal/text/text-controller-impl.cpp @@ -34,6 +34,8 @@ #include #include #include +#include +#include #include using namespace Dali; @@ -98,11 +100,19 @@ struct BackgroundMesh Vector< unsigned short > mIndices; ///< container of indices }; -const Dali::Vector4 LIGHT_BLUE( 0.75f, 0.96f, 1.f, 1.f ); -const Dali::Vector4 BACKGROUND_SUB4( 0.58f, 0.87f, 0.96f, 1.f ); -const Dali::Vector4 BACKGROUND_SUB5( 0.83f, 0.94f, 0.98f, 1.f ); -const Dali::Vector4 BACKGROUND_SUB6( 1.f, 0.5f, 0.5f, 1.f ); -const Dali::Vector4 BACKGROUND_SUB7( 1.f, 0.8f, 0.8f, 1.f ); +// The relative luminance of a color is defined as (L = 0.2126 * R + 0.7152 * G + 0.0722 * B) +// based on W3C Recommendations (https://www.w3.org/TR/WCAG20/) +const float BRIGHTNESS_THRESHOLD = 0.179f; +const float CONSTANT_R = 0.2126f; +const float CONSTANT_G = 0.7152f; +const float CONSTANT_B = 0.0722f; +const Dali::Vector4 BLACK(0.f, 0.f, 0.f, 1.f); +const Dali::Vector4 WHITE(1.f, 1.f, 1.f, 1.f); +const Dali::Vector4 LIGHT_BLUE(0.75f, 0.96f, 1.f, 1.f); +const Dali::Vector4 BACKGROUND_SUB4(0.58f, 0.87f, 0.96f, 1.f); +const Dali::Vector4 BACKGROUND_SUB5(0.83f, 0.94f, 0.98f, 1.f); +const Dali::Vector4 BACKGROUND_SUB6(1.f, 0.5f, 0.5f, 1.f); +const Dali::Vector4 BACKGROUND_SUB7(1.f, 0.8f, 0.8f, 1.f); } // namespace @@ -1124,15 +1134,31 @@ bool Controller::Impl::UpdateModel( OperationsMask operationsRequired ) ColorRun backgroundColorRun; backgroundColorRun.characterRun.characterIndex = attrData.startIndex + numberOfCommit; backgroundColorRun.characterRun.numberOfCharacters = numberOfIndices; - backgroundColorRun.color = textColor; - mModel->mLogicalModel->mBackgroundColorRuns.PushBack( backgroundColorRun ); + backgroundColorRun.color = textColor; + mModel->mLogicalModel->mBackgroundColorRuns.PushBack(backgroundColorRun); Vector4 backgroundColor = mModel->mVisualModel->GetBackgroundColor(); - Vector colorRuns; - colorRuns.Resize( 1u ); - ColorRun& colorRun = *( colorRuns.Begin() ); - colorRun.color = backgroundColor; - colorRun.characterRun.characterIndex = attrData.startIndex + numberOfCommit; + if(backgroundColor.a == 0) // There is no text background color. + { + // Try use the control's background color. + if(nullptr != mEditableControlInterface) + { + mEditableControlInterface->GetControlBackgroundColor(backgroundColor); + if(backgroundColor.a == 0) // There is no control background color. + { + // Determines black or white color according to text color. + // Based on W3C Recommendations (https://www.w3.org/TR/WCAG20/) + float L = CONSTANT_R * textColor.r + CONSTANT_G * textColor.g + CONSTANT_B * textColor.b; + backgroundColor = L > BRIGHTNESS_THRESHOLD ? BLACK : WHITE; + } + } + } + + Vector colorRuns; + colorRuns.Resize(1u); + ColorRun& colorRun = *(colorRuns.Begin()); + colorRun.color = backgroundColor; + colorRun.characterRun.characterIndex = attrData.startIndex + numberOfCommit; colorRun.characterRun.numberOfCharacters = numberOfIndices; mModel->mLogicalModel->mColorRuns.PushBack( colorRun ); diff --git a/dali-toolkit/internal/text/text-editable-control-interface.h b/dali-toolkit/internal/text/text-editable-control-interface.h index cda25df..7f53cdb 100644 --- a/dali-toolkit/internal/text/text-editable-control-interface.h +++ b/dali-toolkit/internal/text/text-editable-control-interface.h @@ -70,6 +70,13 @@ public: virtual void AddDecoration(Actor& actor, bool needsClipping) = 0; /** + * @brief Gets the color of the control. + * + * @param[out] The color of the control. + */ + virtual void GetControlBackgroundColor(Vector4& color) const = 0; + + /** * @brief Editable status (on/off). * * @return true if it can be edit, else false.