2 Copyright (C) 2011 ProFUSION embedded systems
3 Copyright (C) 2011 Samsung Electronics
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
22 #include "DumpRenderTreeSupportEfl.h"
24 #include "FrameLoaderClientEfl.h"
25 #include "ewk_private.h"
27 #include <AnimationController.h>
28 #include <CSSComputedStyleDeclaration.h>
29 #include <DocumentLoader.h>
30 #include <EditorClientEfl.h>
33 #include <FindOptions.h>
34 #include <FloatSize.h>
35 #include <FocusController.h>
36 #include <FrameView.h>
37 #include <HTMLInputElement.h>
38 #include <InspectorController.h>
40 #include <JSCSSStyleDeclaration.h>
41 #include <JSElement.h>
42 #include <PageGroup.h>
43 #include <PrintContext.h>
44 #include <RenderTreeAsText.h>
46 #include <WebKitMutationObserver.h>
47 #include <bindings/js/GCController.h>
48 #include <history/HistoryItem.h>
49 #include <workers/WorkerThread.h>
51 unsigned DumpRenderTreeSupportEfl::activeAnimationsCount(const Evas_Object* ewkFrame)
53 WebCore::Frame* frame = EWKPrivate::coreFrame(ewkFrame);
58 WebCore::AnimationController* animationController = frame->animation();
60 if (!animationController)
63 return animationController->numberOfActiveAnimations(frame->document());
66 bool DumpRenderTreeSupportEfl::callShouldCloseOnWebView(Evas_Object* ewkFrame)
68 WebCore::Frame* frame = EWKPrivate::coreFrame(ewkFrame);
73 return frame->loader()->shouldClose();
76 void DumpRenderTreeSupportEfl::clearFrameName(Evas_Object* ewkFrame)
78 if (WebCore::Frame* frame = EWKPrivate::coreFrame(ewkFrame))
79 frame->tree()->clearName();
82 void DumpRenderTreeSupportEfl::clearOpener(Evas_Object* ewkFrame)
84 if (WebCore::Frame* frame = EWKPrivate::coreFrame(ewkFrame))
85 frame->loader()->setOpener(0);
88 String DumpRenderTreeSupportEfl::counterValueByElementId(const Evas_Object* ewkFrame, const char* elementId)
90 WebCore::Frame* frame = EWKPrivate::coreFrame(ewkFrame);
95 WebCore::Element* element = frame->document()->getElementById(elementId);
100 return WebCore::counterValueForElement(element);
103 bool DumpRenderTreeSupportEfl::elementDoesAutoCompleteForElementWithId(const Evas_Object* ewkFrame, const String& elementId)
105 WebCore::Frame* frame = EWKPrivate::coreFrame(ewkFrame);
110 WebCore::Document* document = frame->document();
113 WebCore::HTMLInputElement* inputElement = static_cast<WebCore::HTMLInputElement*>(document->getElementById(elementId));
118 return inputElement->isTextField() && !inputElement->isPasswordField() && inputElement->shouldAutocomplete();
121 Eina_List* DumpRenderTreeSupportEfl::frameChildren(const Evas_Object* ewkFrame)
123 WebCore::Frame* frame = EWKPrivate::coreFrame(ewkFrame);
128 Eina_List* childFrames = 0;
130 for (unsigned index = 0; index < frame->tree()->childCount(); index++) {
131 WebCore::Frame *childFrame = frame->tree()->child(index);
132 WebCore::FrameLoaderClientEfl *client = static_cast<WebCore::FrameLoaderClientEfl*>(childFrame->loader()->client());
137 childFrames = eina_list_append(childFrames, client->webFrame());
143 WebCore::Frame* DumpRenderTreeSupportEfl::frameParent(const Evas_Object* ewkFrame)
145 WebCore::Frame* frame = EWKPrivate::coreFrame(ewkFrame);
150 return frame->tree()->parent();
153 void DumpRenderTreeSupportEfl::layoutFrame(Evas_Object* ewkFrame)
155 WebCore::Frame* frame = EWKPrivate::coreFrame(ewkFrame);
160 WebCore::FrameView* frameView = frame->view();
168 int DumpRenderTreeSupportEfl::numberOfPages(const Evas_Object* ewkFrame, float pageWidth, float pageHeight)
170 WebCore::Frame* frame = EWKPrivate::coreFrame(ewkFrame);
175 return WebCore::PrintContext::numberOfPages(frame, WebCore::FloatSize(pageWidth, pageHeight));
178 int DumpRenderTreeSupportEfl::numberOfPagesForElementId(const Evas_Object* ewkFrame, const char* elementId, float pageWidth, float pageHeight)
180 WebCore::Frame* frame = EWKPrivate::coreFrame(ewkFrame);
185 WebCore::Element *element = frame->document()->getElementById(elementId);
190 return WebCore::PrintContext::pageNumberForElement(element, WebCore::FloatSize(pageWidth, pageHeight));
193 String DumpRenderTreeSupportEfl::pageSizeAndMarginsInPixels(const Evas_Object* ewkFrame, int pageNumber, int width, int height, int marginTop, int marginRight, int marginBottom, int marginLeft)
195 WebCore::Frame* frame = EWKPrivate::coreFrame(ewkFrame);
200 return WebCore::PrintContext::pageSizeAndMarginsInPixels(frame, pageNumber, width, height, marginTop, marginRight, marginBottom, marginLeft);
203 String DumpRenderTreeSupportEfl::pageProperty(const Evas_Object* ewkFrame, const char* propertyName, int pageNumber)
205 WebCore::Frame* coreFrame = EWKPrivate::coreFrame(ewkFrame);
209 return WebCore::PrintContext::pageProperty(coreFrame, propertyName, pageNumber);
212 bool DumpRenderTreeSupportEfl::pauseAnimation(Evas_Object* ewkFrame, const char* name, const char* elementId, double time)
214 WebCore::Frame* frame = EWKPrivate::coreFrame(ewkFrame);
219 WebCore::Element* element = frame->document()->getElementById(elementId);
221 if (!element || !element->renderer())
224 return frame->animation()->pauseAnimationAtTime(element->renderer(), name, time);
227 bool DumpRenderTreeSupportEfl::pauseTransition(Evas_Object* ewkFrame, const char* name, const char* elementId, double time)
229 WebCore::Frame* frame = EWKPrivate::coreFrame(ewkFrame);
234 WebCore::Element* element = frame->document()->getElementById(elementId);
236 if (!element || !element->renderer())
239 return frame->animation()->pauseTransitionAtTime(element->renderer(), name, time);
242 unsigned DumpRenderTreeSupportEfl::pendingUnloadEventCount(const Evas_Object* ewkFrame)
244 if (WebCore::Frame* frame = EWKPrivate::coreFrame(ewkFrame))
245 return frame->domWindow()->pendingUnloadEventListeners();
250 String DumpRenderTreeSupportEfl::renderTreeDump(Evas_Object* ewkFrame)
252 WebCore::Frame* frame = EWKPrivate::coreFrame(ewkFrame);
257 WebCore::FrameView *frameView = frame->view();
259 if (frameView && frameView->layoutPending())
262 return WebCore::externalRepresentation(frame);
265 String DumpRenderTreeSupportEfl::responseMimeType(const Evas_Object* ewkFrame)
267 WebCore::Frame* frame = EWKPrivate::coreFrame(ewkFrame);
272 WebCore::DocumentLoader *documentLoader = frame->loader()->documentLoader();
277 return documentLoader->responseMIMEType();
280 void DumpRenderTreeSupportEfl::resumeAnimations(Evas_Object* ewkFrame)
282 WebCore::Frame* frame = EWKPrivate::coreFrame(ewkFrame);
287 WebCore::AnimationController *animationController = frame->animation();
288 if (animationController)
289 animationController->resumeAnimations();
292 WebCore::IntRect DumpRenderTreeSupportEfl::selectionRectangle(const Evas_Object* ewkFrame)
294 WebCore::Frame* frame = EWKPrivate::coreFrame(ewkFrame);
297 return WebCore::IntRect();
299 return enclosingIntRect(frame->selection()->bounds());
302 // Compare with "WebKit/Tools/DumpRenderTree/mac/FrameLoadDelegate.mm
303 String DumpRenderTreeSupportEfl::suitableDRTFrameName(const Evas_Object* ewkFrame)
305 WebCore::Frame* frame = EWKPrivate::coreFrame(ewkFrame);
310 const String frameName(ewk_frame_name_get(ewkFrame));
312 if (ewkFrame == ewk_view_frame_main_get(ewk_frame_view_get(ewkFrame))) {
313 if (!frameName.isEmpty())
314 return String("main frame \"") + frameName + String("\"");
316 return String("main frame");
319 if (!frameName.isEmpty())
320 return String("frame \"") + frameName + String("\"");
322 return String("frame (anonymous)");
325 void DumpRenderTreeSupportEfl::suspendAnimations(Evas_Object* ewkFrame)
327 WebCore::Frame* frame = EWKPrivate::coreFrame(ewkFrame);
332 WebCore::AnimationController *animationController = frame->animation();
333 if (animationController)
334 animationController->suspendAnimations();
337 void DumpRenderTreeSupportEfl::setValueForUser(JSContextRef context, JSValueRef nodeObject, const String& value)
339 JSC::ExecState* exec = toJS(context);
340 WebCore::Element* element = WebCore::toElement(toJS(exec, nodeObject));
343 WebCore::HTMLInputElement* inputElement = element->toInputElement();
347 inputElement->setValueForUser(value);
350 void DumpRenderTreeSupportEfl::setAutofilled(JSContextRef context, JSValueRef nodeObject, bool autofilled)
352 JSC::ExecState* exec = toJS(context);
353 WebCore::Element* element = WebCore::toElement(toJS(exec, nodeObject));
356 WebCore::HTMLInputElement* inputElement = element->toInputElement();
360 inputElement->setAutofilled(autofilled);
363 void DumpRenderTreeSupportEfl::setDefersLoading(Evas_Object* ewkView, bool defers)
365 WebCore::Page* page = EWKPrivate::corePage(ewkView);
370 page->setDefersLoading(defers);
373 void DumpRenderTreeSupportEfl::setLoadsSiteIconsIgnoringImageLoadingSetting(Evas_Object* ewkView, bool loadsSiteIconsIgnoringImageLoadingPreferences)
375 WebCore::Page* page = EWKPrivate::corePage(ewkView);
379 page->settings()->setLoadsSiteIconsIgnoringImageLoadingSetting(loadsSiteIconsIgnoringImageLoadingPreferences);
382 void DumpRenderTreeSupportEfl::addUserStyleSheet(const Evas_Object* ewkView, const String& sourceCode, bool allFrames)
384 WebCore::Page* page = EWKPrivate::corePage(ewkView);
388 page->group().addUserStyleSheetToWorld(WebCore::mainThreadNormalWorld(), sourceCode, WebCore::KURL(), nullptr, nullptr, allFrames ? WebCore::InjectInAllFrames : WebCore::InjectInTopFrameOnly);
391 void DumpRenderTreeSupportEfl::executeCoreCommandByName(const Evas_Object* ewkView, const char* name, const char* value)
393 WebCore::Page* page = EWKPrivate::corePage(ewkView);
397 page->focusController()->focusedOrMainFrame()->editor()->command(name).execute(value);
400 bool DumpRenderTreeSupportEfl::findString(const Evas_Object* ewkView, const String& text, WebCore::FindOptions options)
402 WebCore::Page* page = EWKPrivate::corePage(ewkView);
407 return page->findString(text, options);
410 void DumpRenderTreeSupportEfl::setJavaScriptProfilingEnabled(const Evas_Object* ewkView, bool enabled)
412 #if ENABLE(JAVASCRIPT_DEBUGGER) && ENABLE(INSPECTOR)
413 WebCore::Page* corePage = EWKPrivate::corePage(ewkView);
417 WebCore::InspectorController* controller = corePage->inspectorController();
422 controller->enableProfiler();
424 controller->disableProfiler();
428 bool DumpRenderTreeSupportEfl::isCommandEnabled(const Evas_Object* ewkView, const char* name)
430 WebCore::Page* page = EWKPrivate::corePage(ewkView);
434 return page->focusController()->focusedOrMainFrame()->editor()->command(name).isEnabled();
437 void DumpRenderTreeSupportEfl::setSmartInsertDeleteEnabled(Evas_Object* ewkView, bool enabled)
439 WebCore::Page* page = EWKPrivate::corePage(ewkView);
443 WebCore::EditorClientEfl* editorClient = static_cast<WebCore::EditorClientEfl*>(page->editorClient());
447 editorClient->setSmartInsertDeleteEnabled(enabled);
450 void DumpRenderTreeSupportEfl::setSelectTrailingWhitespaceEnabled(Evas_Object* ewkView, bool enabled)
452 WebCore::Page* page = EWKPrivate::corePage(ewkView);
456 WebCore::EditorClientEfl* editorClient = static_cast<WebCore::EditorClientEfl*>(page->editorClient());
460 editorClient->setSelectTrailingWhitespaceEnabled(enabled);
463 void DumpRenderTreeSupportEfl::garbageCollectorCollect()
465 WebCore::gcController().garbageCollectNow();
468 void DumpRenderTreeSupportEfl::garbageCollectorCollectOnAlternateThread(bool waitUntilDone)
470 WebCore::gcController().garbageCollectOnAlternateThreadForDebugging(waitUntilDone);
473 size_t DumpRenderTreeSupportEfl::javaScriptObjectsCount()
475 return WebCore::JSDOMWindow::commonJSGlobalData()->heap.objectCount();
478 unsigned DumpRenderTreeSupportEfl::workerThreadCount()
481 return WebCore::WorkerThread::workerThreadCount();
487 HistoryItemChildrenVector DumpRenderTreeSupportEfl::childHistoryItems(const Ewk_History_Item* ewkHistoryItem)
489 WebCore::HistoryItem* historyItem = EWKPrivate::coreHistoryItem(ewkHistoryItem);
490 HistoryItemChildrenVector kids;
495 const WebCore::HistoryItemVector& children = historyItem->children();
496 const unsigned size = children.size();
498 for (unsigned i = 0; i < size; ++i) {
499 Ewk_History_Item* kid = ewk_history_item_new_from_core(children[i].get());
506 String DumpRenderTreeSupportEfl::historyItemTarget(const Ewk_History_Item* ewkHistoryItem)
508 WebCore::HistoryItem* historyItem = EWKPrivate::coreHistoryItem(ewkHistoryItem);
513 return historyItem->target();
516 bool DumpRenderTreeSupportEfl::isTargetItem(const Ewk_History_Item* ewkHistoryItem)
518 WebCore::HistoryItem* historyItem = EWKPrivate::coreHistoryItem(ewkHistoryItem);
523 return historyItem->isTargetItem();
526 void DumpRenderTreeSupportEfl::setMockScrollbarsEnabled(bool enable)
528 WebCore::Settings::setMockScrollbarsEnabled(enable);
531 void DumpRenderTreeSupportEfl::dumpConfigurationForViewport(Evas_Object* ewkView, int deviceDPI, const WebCore::IntSize& deviceSize, const WebCore::IntSize& availableSize)
533 WebCore::Page* page = EWKPrivate::corePage(ewkView);
537 WebCore::ViewportArguments arguments = page->mainFrame()->document()->viewportArguments();
538 WebCore::ViewportAttributes attributes = computeViewportAttributes(arguments,
539 /* default layout width for non-mobile pages */ 980,
540 deviceSize.width(), deviceSize.height(),
543 restrictMinimumScaleFactorToViewportSize(attributes, availableSize);
544 restrictScaleFactorToInitialScaleIfNotUserScalable(attributes);
545 fprintf(stdout, "viewport size %dx%d scale %f with limits [%f, %f] and userScalable %f\n", static_cast<int>(attributes.layoutSize.width()), static_cast<int>(attributes.layoutSize.height()), attributes.initialScale, attributes.minimumScale, attributes.maximumScale, attributes.userScalable);
548 void DumpRenderTreeSupportEfl::deliverAllMutationsIfNecessary()
550 #if ENABLE(MUTATION_OBSERVERS)
551 WebCore::WebKitMutationObserver::deliverAllMutations();
555 void DumpRenderTreeSupportEfl::setEditingBehavior(Evas_Object* ewkView, const char* editingBehavior)
557 WebCore::EditingBehaviorType coreEditingBehavior;
559 if (!strcmp(editingBehavior, "win"))
560 coreEditingBehavior = WebCore::EditingWindowsBehavior;
561 else if (!strcmp(editingBehavior, "mac"))
562 coreEditingBehavior = WebCore::EditingMacBehavior;
563 else if (!strcmp(editingBehavior, "unix"))
564 coreEditingBehavior = WebCore::EditingUnixBehavior;
566 ASSERT_NOT_REACHED();
570 WebCore::Page* corePage = EWKPrivate::corePage(ewkView);
574 corePage->settings()->setEditingBehaviorType(coreEditingBehavior);
577 String DumpRenderTreeSupportEfl::markerTextForListItem(JSContextRef context, JSValueRef nodeObject)
579 JSC::ExecState* exec = toJS(context);
580 WebCore::Element* element = WebCore::toElement(toJS(exec, nodeObject));
584 return WebCore::markerTextForListItem(element);
587 void DumpRenderTreeSupportEfl::setInteractiveFormValidationEnabled(Evas_Object* ewkView, bool enabled)
589 WebCore::Page* corePage = EWKPrivate::corePage(ewkView);
591 corePage->settings()->setInteractiveFormValidationEnabled(enabled);
594 JSValueRef DumpRenderTreeSupportEfl::computedStyleIncludingVisitedInfo(JSContextRef context, JSValueRef value)
597 return JSValueMakeUndefined(context);
599 JSC::ExecState* exec = toJS(context);
600 JSC::JSValue jsValue = toJS(exec, value);
601 if (!jsValue.inherits(&WebCore::JSElement::s_info))
602 return JSValueMakeUndefined(context);
604 WebCore::JSElement* jsElement = static_cast<WebCore::JSElement*>(asObject(jsValue));
605 WebCore::Element* element = jsElement->impl();
606 RefPtr<WebCore::CSSComputedStyleDeclaration> style = WebCore::CSSComputedStyleDeclaration::create(element, true);
607 return toRef(exec, toJS(exec, jsElement->globalObject(), style.get()));
610 void DumpRenderTreeSupportEfl::setAuthorAndUserStylesEnabled(Evas_Object* ewkView, bool enabled)
612 WebCore::Page* corePage = EWKPrivate::corePage(ewkView);
616 corePage->settings()->setAuthorAndUserStylesEnabled(enabled);