IsClipboardEmpty works meaningfully.
Temporary code has been applied to paste html type.
Once multiple types and data can be stored in the clipboard, this code should be removed.
Change-Id: I29b279acf19dd1c3397568b55e0567d314c41990
Signed-off-by: Bowon Ryu <bowon.ryu@samsung.com>
Dali::Clipboard::DataReceivedSignalType& DataReceivedSignal();
/**
+ * @copydoc Dali::Clipboard::HasType()
+ */
+ bool HasType(const std::string& mimeType);
+
+ /**
* @copydoc Dali::Clipboard::SetData()
*/
bool SetData(const Dali::Clipboard::ClipData& clipData);
return mDataReceivedSignal;
}
+bool Clipboard::HasType(const std::string& mimeType)
+{
+ return mMimeType == mimeType ? true : false;
+}
+
bool Clipboard::SetData(const Dali::Clipboard::ClipData& clipData)
{
mMimeType = clipData.GetMimeType();
DataReceivedSignalType& DataReceivedSignal();
/**
+ * @brief Check if there is data in the clipboard with a given mime type.
+ * @param[in] mimeType mime type to search for.
+ * @return bool true if there is data, otherwise false.
+ */
+ bool HasType(const std::string& mimeType);
+
+ /**
* @brief Send the given data to the clipboard.
* @param[in] clipData data to send to the clipboard
* @return bool true if the internal clipboard sending was successful.
event.AddPoint(GetPointUpInside(position));
application.ProcessEvent(event);
}
- DALI_TEST_EQUALS(field.GetProperty<std::string>(TextEditor::Property::TEXT), std::string("testTextFieldEvent"), TEST_LOCATION);
+ DALI_TEST_EQUALS(field.GetProperty<std::string>(TextField::Property::TEXT), std::string("testTextFieldEvent"), TEST_LOCATION);
+
+ Dali::Clipboard::ClipData htmlData("application/xhtml+xml", "testTextFieldEventHtml");
+ clipboard.SetData(htmlData);
+
+ field.SetProperty(TextField::Property::TEXT, "");
+
+ // Render and notify
+ application.SendNotification();
+ application.Render();
+
+ // Long Press
+ TestGenerateLongPress(application, 1.0f, 25.0f, 20);
+
+ // Render and notify
+ application.SendNotification();
+ application.Render();
+
+ Wait(application, 500);
+
+ TestEndLongPress(application, 1.0f, 25.0f, 520);
+
+ // Long Press
+ TestGenerateLongPress(application, 1.0f, 25.0f, 600);
+
+ // Render and notify
+ application.Render();
+
+ Wait(application, 500);
+
+ stage = application.GetScene();
+ layer = stage.GetRootLayer();
+ actor = layer.FindChildByName("optionPaste");
+
+ if(actor)
+ {
+ Vector3 worldPosition = actor.GetCurrentProperty<Vector3>(Actor::Property::WORLD_POSITION);
+ Vector2 halfStageSize = stage.GetSize() / 2.0f;
+ Vector2 position(worldPosition.x + halfStageSize.width, worldPosition.y + halfStageSize.height);
+
+ Dali::Integration::TouchEvent event;
+ event = Dali::Integration::TouchEvent();
+ event.AddPoint(GetPointDownInside(position));
+ application.ProcessEvent(event);
+
+ event = Dali::Integration::TouchEvent();
+ event.AddPoint(GetPointUpInside(position));
+ application.ProcessEvent(event);
+ }
+ DALI_TEST_EQUALS(field.GetProperty<std::string>(TextField::Property::TEXT), std::string("testTextFieldEventHtml"), TEST_LOCATION);
END_TEST;
}
const char* EMPTY_STRING = "";
const char* MIME_TYPE_TEXT_PLAIN = "text/plain;charset=utf-8";
+const char* MIME_TYPE_HTML = "application/xhtml+xml";
} // namespace
return false;
}
+bool Controller::Impl::IsClipboardEmpty()
+{
+ bool result(Clipboard::IsAvailable() && EnsureClipboardCreated() && (mClipboard.HasType(MIME_TYPE_TEXT_PLAIN) || mClipboard.HasType(MIME_TYPE_HTML)));
+ return !result;
+}
+
void Controller::Impl::SendSelectionToClipboard(bool deleteAfterSending)
{
std::string selectedText;
return mClipboard != nullptr ? true : false;
}
- bool IsClipboardEmpty()
- {
- bool result(Clipboard::IsAvailable() && EnsureClipboardCreated() && mClipboard.NumberOfItems());
- return !result; // If NumberOfItems greater than 0, return false
- }
-
bool IsClipboardVisible()
{
bool result(Clipboard::IsAvailable() && EnsureClipboardCreated() && mClipboard.IsVisible());
}
/**
+ * @brief Whether the clipboard is empty or not.
+ * Checks the types that the text controller can paste and returns the result.
+ *
+ * @return Return whether or not the clipboard is empty.
+ */
+ bool IsClipboardEmpty();
+
+ /**
* @copydoc Controller::GetLayoutDirection()
*/
Dali::LayoutDirection::Type GetLayoutDirection(Dali::Actor& actor) const;
const char* EMPTY_STRING = "";
const char* MIME_TYPE_TEXT_PLAIN = "text/plain;charset=utf-8";
+const char* MIME_TYPE_HTML = "application/xhtml+xml";
template<typename Type>
void EnsureCreated(Type*& object)
mImpl->mClipboard.DataReceivedSignal().Disconnect(this, &Controller::PasteClipboardItemEvent);
// If the id is 0u, it is an invalid response.
+ if(id == 0u)
+ {
+ return;
+ }
+
// text-controller allows only plain text type.
- if(id != 0u && !strncmp(mimeType, MIME_TYPE_TEXT_PLAIN, strlen(MIME_TYPE_TEXT_PLAIN)))
+ if(!strncmp(mimeType, MIME_TYPE_TEXT_PLAIN, strlen(MIME_TYPE_TEXT_PLAIN)))
{
EventHandler::PasteClipboardItemEvent(*this, data);
}
+ else if(!strncmp(mimeType, MIME_TYPE_HTML, strlen(MIME_TYPE_HTML)))
+ {
+ // This does not mean that text controls can parse html.
+ // This is temporary code, as text controls do not support html type data.
+ // Simply remove the tags inside the angle brackets.
+ // Once multiple types and data can be stored in the clipboard, this code should be removed.
+ std::regex reg("<[^>]*>");
+ std::string result = regex_replace(data, reg, "");
+
+ EventHandler::PasteClipboardItemEvent(*this, result.c_str());
+ }
}
void Controller::PasteText()
// Connect the signal before calling GetData() of the clipboard.
mImpl->mClipboard.DataReceivedSignal().Connect(this, &Controller::PasteClipboardItemEvent);
+ // If there is no plain text type data on the clipboard, request html type data.
+ std::string mimeType = mImpl->mClipboard.HasType(MIME_TYPE_TEXT_PLAIN) ? MIME_TYPE_TEXT_PLAIN : MIME_TYPE_HTML;
+
// Request clipboard service to retrieve an item.
- uint id = mImpl->mClipboard.GetData(MIME_TYPE_TEXT_PLAIN);
+ uint id = mImpl->mClipboard.GetData(mimeType);
if(id == 0u)
{
// If the return id is 0u, the signal is not emitted, we must disconnect signal here.