/*
- * 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.
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");
DALI_TEST_EQUALS( colorIndicesBuffer2[7], 0u, TEST_LOCATION);
END_TEST;
+}
+
+int UtcDaliTextEditorControlBackgroundColor(void)
+{
+ ToolkitTestApplication application;
+ tet_infoline(" UtcDaliTextEditorControlBackgroundColor\n");
+
+ TextEditor editor = TextEditor::New();
+ DALI_TEST_CHECK(editor);
+
+ Vector4 backgroundColor;
+
+ editor.SetProperty(TextEditor::Property::TEXT, "Background Color");
+ application.GetScene().Add(editor);
+ application.SendNotification();
+ application.Render();
+
+ Toolkit::Internal::TextEditor& editorImpl = GetImpl(editor);
+ ControllerPtr controller = editorImpl.getController();
+ Controller::Impl& controllerImpl = Controller::Impl::GetImplementation(*controller.Get());
+
+ // Default color is transparent
+ controllerImpl.mEditableControlInterface->GetControlBackgroundColor(backgroundColor);
+ DALI_TEST_EQUALS(backgroundColor, Color::TRANSPARENT, TEST_LOCATION);
+
+ // Set background color to red
+ editor.SetBackgroundColor(Color::RED);
+ application.SendNotification();
+ application.Render();
+
+ // Should be red
+ controllerImpl.mEditableControlInterface->GetControlBackgroundColor(backgroundColor);
+ DALI_TEST_EQUALS(backgroundColor, Color::RED, TEST_LOCATION);
+
+ END_TEST;
}
\ No newline at end of file
DALI_TEST_EQUALS( colorIndicesBuffer2[7], 0u, TEST_LOCATION);
END_TEST;
+}
+
+int UtcDaliTextFieldControlBackgroundColor(void)
+{
+ ToolkitTestApplication application;
+ tet_infoline(" UtcDaliTextFieldControlBackgroundColor\n");
+
+ TextField field = TextField::New();
+ DALI_TEST_CHECK(field);
+
+ Vector4 backgroundColor;
+
+ field.SetProperty(TextField::Property::TEXT, "Background Color");
+ application.GetScene().Add(field);
+ application.SendNotification();
+ application.Render();
+
+ Toolkit::Internal::TextField& fieldImpl = GetImpl(field);
+ ControllerPtr controller = fieldImpl.getController();
+ Controller::Impl& controllerImpl = Controller::Impl::GetImplementation(*controller.Get());
+
+ // Default color is transparent
+ controllerImpl.mEditableControlInterface->GetControlBackgroundColor(backgroundColor);
+ DALI_TEST_EQUALS(backgroundColor, Color::TRANSPARENT, TEST_LOCATION);
+
+ // Set background color to red
+ field.SetBackgroundColor(Color::RED);
+ application.SendNotification();
+ application.Render();
+
+ // Should be red
+ controllerImpl.mEditableControlInterface->GetControlBackgroundColor(backgroundColor);
+ DALI_TEST_EQUALS(backgroundColor, Color::RED, TEST_LOCATION);
+
+ END_TEST;
}
\ No newline at end of file
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;
*/
void InputFiltered(Toolkit::InputFilter::Property::Type type) override;
+ /**
+ * @copydoc Text::EditableControlInterface::GetControlBackgroundColor()
+ */
+ void GetControlBackgroundColor(Vector4& color) const override;
+
// From SelectableControlInterface
public:
/**
}
}
+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)
return states;
}
-bool TextField::AccessibleImpl::InsertText(size_t startPosition,
- std::string text)
+bool TextField::AccessibleImpl::InsertText(size_t startPosition,
+ std::string text)
{
auto slf = Toolkit::TextField::DownCast(Self());
auto txt = slf.GetProperty(Toolkit::TextField::Property::TEXT).Get<std::string>();
*/
void InputFiltered(Toolkit::InputFilter::Property::Type type) override;
+ /**
+ * @copydoc Text::EditableControlInterface::GetControlBackgroundColor()
+ */
+ void GetControlBackgroundColor(Vector4& color) const override;
+
// From SelectableControlInterface
public:
/**
#include <dali-toolkit/internal/text/shaper.h>
#include <dali-toolkit/internal/text/text-control-interface.h>
#include <dali-toolkit/internal/text/text-controller-impl-event-handler.h>
+#include <dali-toolkit/internal/text/text-editable-control-interface.h>
+#include <dali-toolkit/internal/text/text-enumerations-impl.h>
#include <dali-toolkit/internal/text/text-run-container.h>
#include <dali-toolkit/internal/text/text-selection-handle-controller.h>
-#include <dali-toolkit/internal/text/text-enumerations-impl.h>
-
using namespace Dali;
namespace
Vector<unsigned short> mIndices; ///< container of indices
};
+// 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);
backgroundColorRun.color = textColor;
mModel->mLogicalModel->mBackgroundColorRuns.PushBack(backgroundColorRun);
- Vector4 backgroundColor = mModel->mVisualModel->GetBackgroundColor();
+ Vector4 backgroundColor = mModel->mVisualModel->GetBackgroundColor();
+ 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<ColorRun> colorRuns;
colorRuns.Resize(1u);
ColorRun& colorRun = *(colorRuns.Begin());
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.