EditingCallbacks.cpp 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /*
  2. * Copyright (C) 2010 Igalia S.L.
  3. * Copyright (C) 2012 Samsung Electronics
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. *
  9. * 1. Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * 2. Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
  15. * its contributors may be used to endorse or promote products derived
  16. * from this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
  19. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  20. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  21. * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
  22. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  23. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  24. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  25. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  27. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. */
  29. #include "config.h"
  30. #include "EditingCallbacks.h"
  31. #include "DumpRenderTree.h"
  32. #include "EditorClientEfl.h"
  33. #include "EditorInsertAction.h"
  34. #include "Node.h"
  35. #include "Range.h"
  36. #include "StylePropertySet.h"
  37. #include "TestRunner.h"
  38. #include "TextAffinity.h"
  39. #include <wtf/text/CString.h>
  40. #include <wtf/text/WTFString.h>
  41. static WTF::String dumpPath(WebCore::Node* node)
  42. {
  43. WebCore::Node* parent = node->parentNode();
  44. WTF::String str = WTF::String::format("%s", node->nodeName().utf8().data());
  45. if (parent) {
  46. str.append(" > ");
  47. str.append(dumpPath(parent));
  48. }
  49. return str;
  50. }
  51. static WTF::String dumpRange(WebCore::Range* range)
  52. {
  53. if (!range)
  54. return "(null)";
  55. return WTF::String::format("range from %d of %s to %d of %s", range->startOffset(), dumpPath(range->startContainer()).utf8().data(), range->endOffset(), dumpPath(range->endContainer()).utf8().data());
  56. }
  57. static const char* insertActionString(WebCore::EditorInsertAction action)
  58. {
  59. switch (action) {
  60. case WebCore::EditorInsertActionTyped:
  61. return "WebViewInsertActionTyped";
  62. case WebCore::EditorInsertActionPasted:
  63. return "WebViewInsertActionPasted";
  64. case WebCore::EditorInsertActionDropped:
  65. return "WebViewInsertActionDropped";
  66. }
  67. ASSERT_NOT_REACHED();
  68. return "WebViewInsertActionTyped";
  69. }
  70. static const char* selectionAffinityString(WebCore::EAffinity affinity)
  71. {
  72. switch (affinity) {
  73. case WebCore::UPSTREAM:
  74. return "NSSelectionAffinityUpstream";
  75. case WebCore::DOWNSTREAM:
  76. return "NSSelectionAffinityDownstream";
  77. }
  78. ASSERT_NOT_REACHED();
  79. return "NSSelectionAffinityUpstream";
  80. }
  81. void shouldBeginEditing(void*, Evas_Object*, void* eventInfo)
  82. {
  83. if (!done && gTestRunner->dumpEditingCallbacks()) {
  84. WebCore::Range* range = static_cast<WebCore::Range*>(eventInfo);
  85. printf("EDITING DELEGATE: shouldBeginEditingInDOMRange:%s\n", dumpRange(range).utf8().data());
  86. }
  87. }
  88. void shouldEndEditing(void*, Evas_Object*, void* eventInfo)
  89. {
  90. if (!done && gTestRunner->dumpEditingCallbacks()) {
  91. WebCore::Range* range = static_cast<WebCore::Range*>(eventInfo);
  92. printf("EDITING DELEGATE: shouldEndEditingInDOMRange:%s\n", dumpRange(range).utf8().data());
  93. }
  94. }
  95. void shouldInsertNode(void*, Evas_Object*, void* eventInfo)
  96. {
  97. if (!done && gTestRunner->dumpEditingCallbacks()) {
  98. Ewk_Should_Insert_Node_Event* shouldInsertNodeEvent = static_cast<Ewk_Should_Insert_Node_Event*>(eventInfo);
  99. printf("EDITING DELEGATE: shouldInsertNode:%s replacingDOMRange:%s givenAction:%s\n",
  100. dumpPath(shouldInsertNodeEvent->node).utf8().data(), dumpRange(shouldInsertNodeEvent->range).utf8().data(),
  101. insertActionString(shouldInsertNodeEvent->action));
  102. }
  103. }
  104. void shouldInsertText(void*, Evas_Object*, void* eventInfo)
  105. {
  106. if (!done && gTestRunner->dumpEditingCallbacks()) {
  107. Ewk_Should_Insert_Text_Event* shouldInsertTextEvent = static_cast<Ewk_Should_Insert_Text_Event*>(eventInfo);
  108. printf("EDITING DELEGATE: shouldInsertText:%s replacingDOMRange:%s givenAction:%s\n",
  109. shouldInsertTextEvent->text, dumpRange(shouldInsertTextEvent->range).utf8().data(), insertActionString(shouldInsertTextEvent->action));
  110. }
  111. }
  112. void shouldDeleteRange(void*, Evas_Object*, void* eventInfo)
  113. {
  114. if (!done && gTestRunner->dumpEditingCallbacks()) {
  115. WebCore::Range* range = static_cast<WebCore::Range*>(eventInfo);
  116. printf("EDITING DELEGATE: shouldDeleteDOMRange:%s\n", dumpRange(range).utf8().data());
  117. }
  118. }
  119. void shouldChangeSelectedRange(void*, Evas_Object*, void* eventInfo)
  120. {
  121. if (!done && gTestRunner->dumpEditingCallbacks()) {
  122. Ewk_Should_Change_Selected_Range_Event* shouldChangeSelectedRangeEvent = static_cast<Ewk_Should_Change_Selected_Range_Event*>(eventInfo);
  123. printf("EDITING DELEGATE: shouldChangeSelectedDOMRange:%s toDOMRange:%s affinity:%s stillSelecting:%s\n",
  124. dumpRange(shouldChangeSelectedRangeEvent->fromRange).utf8().data(), dumpRange(shouldChangeSelectedRangeEvent->toRange).utf8().data(),
  125. selectionAffinityString(shouldChangeSelectedRangeEvent->affinity), shouldChangeSelectedRangeEvent->stillSelecting ? "TRUE" : "FALSE");
  126. }
  127. }
  128. void shouldApplyStyle(void*, Evas_Object*, void* eventInfo)
  129. {
  130. if (!done && gTestRunner->dumpEditingCallbacks()) {
  131. Ewk_Should_Apply_Style_Event* shouldApplyStyleEvent = static_cast<Ewk_Should_Apply_Style_Event*>(eventInfo);
  132. printf("EDITING DELEGATE: shouldApplyStyle:%s toElementsInDOMRange:%s\n",
  133. shouldApplyStyleEvent->style->asText().utf8().data(), dumpRange(shouldApplyStyleEvent->range).utf8().data());
  134. }
  135. }
  136. void editingBegan(void*, Evas_Object*, void*)
  137. {
  138. if (!done && gTestRunner->dumpEditingCallbacks())
  139. printf("EDITING DELEGATE: webViewDidBeginEditing:WebViewDidBeginEditingNotification\n");
  140. }
  141. void userChangedContents(void*, Evas_Object*, void*)
  142. {
  143. if (!done && gTestRunner->dumpEditingCallbacks())
  144. printf("EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification\n");
  145. }
  146. void editingEnded(void*, Evas_Object*, void*)
  147. {
  148. if (!done && gTestRunner->dumpEditingCallbacks())
  149. printf("EDITING DELEGATE: webViewDidEndEditing:WebViewDidEndEditingNotification\n");
  150. }
  151. void selectionChanged(void*, Evas_Object*, void*)
  152. {
  153. if (!done && gTestRunner->dumpEditingCallbacks())
  154. printf("EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification\n");
  155. }
  156. void connectEditingCallbacks(Evas_Object* webView)
  157. {
  158. evas_object_smart_callback_add(webView, "editorclient,editing,begin", shouldBeginEditing, 0);
  159. evas_object_smart_callback_add(webView, "editorclient,editing,end", shouldEndEditing, 0);
  160. evas_object_smart_callback_add(webView, "editorclient,node,insert", shouldInsertNode, 0);
  161. evas_object_smart_callback_add(webView, "editorclient,text,insert", shouldInsertText, 0);
  162. evas_object_smart_callback_add(webView, "editorclient,range,delete", shouldDeleteRange, 0);
  163. evas_object_smart_callback_add(webView, "editorclient,selected,range,change", shouldChangeSelectedRange, 0);
  164. evas_object_smart_callback_add(webView, "editorclient,style,apply", shouldApplyStyle, 0);
  165. evas_object_smart_callback_add(webView, "editorclient,editing,began", editingBegan, 0);
  166. evas_object_smart_callback_add(webView, "editorclient,contents,changed", userChangedContents, 0);
  167. evas_object_smart_callback_add(webView, "editorclient,editing,ended", editingEnded, 0);
  168. evas_object_smart_callback_add(webView, "editorclient,selection,changed", selectionChanged, 0);
  169. }