Fix key event propagation in text controller
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-TextField.cpp
index 3e8b0de..5ec1035 100644 (file)
@@ -27,6 +27,7 @@
 #include <dali-toolkit-test-suite-utils.h>
 #include <dali-toolkit/dali-toolkit.h>
 #include <dali-toolkit/devel-api/controls/text-controls/text-field-devel.h>
+#include <dali-toolkit/devel-api/controls/text-controls/text-selection-popup.h>
 #include <dali-toolkit/devel-api/text/rendering-backend.h>
 #include <dali-toolkit/devel-api/text/text-enumerations-devel.h>
 #include <dali/devel-api/adaptor-framework/key-devel.h>
@@ -72,6 +73,7 @@ const char* const PROPERTY_NAME_GRAB_HANDLE_IMAGE                    = "grabHand
 const char* const PROPERTY_NAME_GRAB_HANDLE_PRESSED_IMAGE            = "grabHandlePressedImage";
 const char* const PROPERTY_NAME_SCROLL_THRESHOLD                     = "scrollThreshold";
 const char* const PROPERTY_NAME_SCROLL_SPEED                         = "scrollSpeed";
+const char* const PROPERTY_NAME_SELECTION_POPUP_STYLE                = "selectionPopupStyle";
 const char* const PROPERTY_NAME_SELECTION_HANDLE_IMAGE_LEFT          = "selectionHandleImageLeft";
 const char* const PROPERTY_NAME_SELECTION_HANDLE_IMAGE_RIGHT         = "selectionHandleImageRight";
 const char* const PROPERTY_NAME_SELECTION_HANDLE_PRESSED_IMAGE_LEFT  = "selectionHandlePressedImageLeft";
@@ -591,6 +593,7 @@ int UtcDaliTextFieldGetPropertyP(void)
   DALI_TEST_CHECK(field.GetPropertyIndex(PROPERTY_NAME_INPUT_FILTER) == DevelTextField::Property::INPUT_FILTER);
   DALI_TEST_CHECK(field.GetPropertyIndex(PROPERTY_NAME_STRIKETHROUGH) == DevelTextField::Property::STRIKETHROUGH);
   DALI_TEST_CHECK(field.GetPropertyIndex(PROPERTY_NAME_INPUT_STRIKETHROUGH) == DevelTextField::Property::INPUT_STRIKETHROUGH);
+  DALI_TEST_CHECK(field.GetPropertyIndex(PROPERTY_NAME_SELECTION_POPUP_STYLE) == DevelTextField::Property::SELECTION_POPUP_STYLE);
 
   END_TEST;
 }
@@ -765,6 +768,64 @@ int UtcDaliTextFieldSetPropertyP(void)
   DALI_TEST_CHECK(SetPropertyMapRetrieved(field, TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT, "filename", "leftHandleMarkerImage"));
   DALI_TEST_CHECK(SetPropertyMapRetrieved(field, TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT, "filename", "rightHandleMarkerImage"));
 
+  // Check the selection popup style
+  const Vector2 popupMaxSize(200.0f, 300.0f);
+  const Vector2 optionDividerSize(30.0f, 5.0f);
+  const Vector4 optionDividerPadding(20.0f, 20.0f, 10.0f, 10.0f);
+  const Vector4 labelPadding(5.0f, 5.0f, 50.0f, 25.0f);
+
+  Property::Map selectionPopupStyle;
+  selectionPopupStyle.Insert(TextSelectionPopup::Property::POPUP_MAX_SIZE, popupMaxSize);
+  selectionPopupStyle.Insert(TextSelectionPopup::Property::OPTION_DIVIDER_SIZE, optionDividerSize);
+  selectionPopupStyle.Insert(TextSelectionPopup::Property::OPTION_DIVIDER_PADDING, optionDividerPadding);
+  selectionPopupStyle.Insert(TextSelectionPopup::Property::LABEL_PADDING, labelPadding);
+
+  field.SetProperty(DevelTextField::Property::SELECTION_POPUP_STYLE, selectionPopupStyle);
+
+  Property::Map selectionPopupStyleGet;
+  selectionPopupStyleGet = field.GetProperty<Property::Map>(DevelTextField::Property::SELECTION_POPUP_STYLE);
+
+  Property::Value* popupValue;
+  popupValue = selectionPopupStyleGet.Find(TextSelectionPopup::Property::POPUP_MAX_SIZE);
+  DALI_TEST_CHECK(NULL != popupValue);
+  if(popupValue)
+  {
+    Vector2 popupMaxSizeGet;
+    popupValue->Get(popupMaxSizeGet);
+    DALI_TEST_EQUALS(popupMaxSizeGet, popupMaxSize, TEST_LOCATION);
+  }
+
+  popupValue = selectionPopupStyleGet.Find(TextSelectionPopup::Property::OPTION_DIVIDER_SIZE);
+  DALI_TEST_CHECK(NULL != popupValue);
+  if(popupValue)
+  {
+    Vector2 optionDividerSizeGet;
+    popupValue->Get(optionDividerSizeGet);
+    DALI_TEST_EQUALS(optionDividerSizeGet, optionDividerSize, TEST_LOCATION);
+  }
+
+  popupValue = selectionPopupStyleGet.Find(TextSelectionPopup::Property::OPTION_DIVIDER_PADDING);
+  DALI_TEST_CHECK(NULL != popupValue);
+  if(popupValue)
+  {
+    Vector4 optionDividerPaddingGet;
+    popupValue->Get(optionDividerPaddingGet);
+    DALI_TEST_EQUALS(optionDividerPaddingGet, optionDividerPadding, TEST_LOCATION);
+  }
+
+  popupValue = selectionPopupStyleGet.Find(TextSelectionPopup::Property::LABEL_PADDING);
+  DALI_TEST_CHECK(NULL != popupValue);
+  if(popupValue)
+  {
+    Vector4 labelPaddingGet;
+    popupValue->Get(labelPaddingGet);
+    DALI_TEST_EQUALS(labelPaddingGet, labelPadding, TEST_LOCATION);
+  }
+
+  // Reset selection popup style
+  selectionPopupStyle.Clear();
+  field.SetProperty(DevelTextField::Property::SELECTION_POPUP_STYLE, selectionPopupStyle);
+
   // Check the highlight color
   field.SetProperty(TextField::Property::SELECTION_HIGHLIGHT_COLOR, Color::GREEN);
   DALI_TEST_EQUALS(field.GetProperty<Vector4>(TextField::Property::SELECTION_HIGHLIGHT_COLOR), Color::GREEN, TEST_LOCATION);
@@ -3225,6 +3286,14 @@ int utcDaliTextFieldSomeSpecialKeys(void)
   application.SendNotification();
   application.Render();
 
+  // Generate a Back key event. Nothing happens to the text field.
+  application.ProcessEvent(GenerateKey("XF86Back", "", "XF86Back", DALI_KEY_BACK, 0, 0, Integration::KeyEvent::DOWN, "XF86Back", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE));
+  application.ProcessEvent(GenerateKey("XF86Back", "", "XF86Back", DALI_KEY_BACK, 0, 0, Integration::KeyEvent::UP, "XF86Back", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE));
+
+  // Render and notify
+  application.SendNotification();
+  application.Render();
+
   // The text shouldn't be deleted.
   DALI_TEST_EQUALS(field.GetProperty<std::string>(TextField::Property::TEXT), longText, TEST_LOCATION);