|
Line 0
a/Source/WebKit/efl/tests/src/UnitTestLauncher/EFLTestView.cpp_sec1
|
|
|
1 |
/* |
| 2 |
Copyright (C) 2011 Samsung Electronics |
| 3 |
|
| 4 |
This library is free software; you can redistribute it and/or |
| 5 |
modify it under the terms of the GNU Lesser General Public |
| 6 |
License as published by the Free Software Foundation; either |
| 7 |
version 2.1 of the License, or (at your option) any later version. |
| 8 |
|
| 9 |
This library is distributed in the hope that it will be useful, |
| 10 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 |
Lesser General Public License for more details. |
| 13 |
|
| 14 |
You should have received a copy of the GNU Lesser General Public License |
| 15 |
along with this library; if not, write to the Free Software Foundation, |
| 16 |
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 17 |
*/ |
| 18 |
|
| 19 |
#include "config.h" |
| 20 |
#include "EFLTestView.h" |
| 21 |
|
| 22 |
#include "EFLTestConfig.h" |
| 23 |
#include "EWebKit.h" |
| 24 |
|
| 25 |
#include <Ecore.h> |
| 26 |
#include <Ecore_File.h> |
| 27 |
#include <Edje.h> |
| 28 |
#include <Eina.h> |
| 29 |
|
| 30 |
#include <string.h> |
| 31 |
|
| 32 |
namespace EFLUnitTests { |
| 33 |
|
| 34 |
EFLTestEcoreEvas::EFLTestEcoreEvas() |
| 35 |
: m_ecore_evas(0) |
| 36 |
{ |
| 37 |
m_ecore_evas = ecore_evas_new(0, 0, 0, EFLUnitTests::Config::defaultViewWidth, EFLUnitTests::Config::defaultViewHeight, 0); |
| 38 |
} |
| 39 |
|
| 40 |
EFLTestEcoreEvas::EFLTestEcoreEvas(const char *engine_name, int viewport_x, int viewport_y, int viewport_w, int viewport_h, const char *extra_options) |
| 41 |
: m_ecore_evas(0) |
| 42 |
{ |
| 43 |
m_ecore_evas = ecore_evas_new(engine_name, viewport_x, viewport_y, viewport_w, viewport_h, extra_options); |
| 44 |
} |
| 45 |
|
| 46 |
EFLTestEcoreEvas::~EFLTestEcoreEvas() |
| 47 |
{ |
| 48 |
if (m_ecore_evas) |
| 49 |
ecore_evas_free(m_ecore_evas); |
| 50 |
} |
| 51 |
|
| 52 |
Evas* EFLTestEcoreEvas::getEvas() |
| 53 |
{ |
| 54 |
if (m_ecore_evas) |
| 55 |
return ecore_evas_get(m_ecore_evas); |
| 56 |
return 0; |
| 57 |
} |
| 58 |
|
| 59 |
void EFLTestEcoreEvas::show() |
| 60 |
{ |
| 61 |
if (m_ecore_evas) |
| 62 |
ecore_evas_show(m_ecore_evas); |
| 63 |
} |
| 64 |
|
| 65 |
EFLTestView::EFLTestView(Evas* evas) |
| 66 |
: m_webView(0) |
| 67 |
, m_evas(evas) |
| 68 |
, m_url(0) |
| 69 |
, m_defaultViewType(TiledView) |
| 70 |
, m_width(EFLUnitTests::Config::defaultViewWidth) |
| 71 |
, m_height(EFLUnitTests::Config::defaultViewHeight) |
| 72 |
{ |
| 73 |
m_url = createTestUrl(EFLUnitTests::Config::defaultTestPage); |
| 74 |
} |
| 75 |
|
| 76 |
EFLTestView::EFLTestView(Evas *evas, const char* url) |
| 77 |
: m_webView(0) |
| 78 |
, m_evas(evas) |
| 79 |
, m_url(0) |
| 80 |
, m_defaultViewType(TiledView) |
| 81 |
, m_width(EFLUnitTests::Config::defaultViewWidth) |
| 82 |
, m_height(EFLUnitTests::Config::defaultViewHeight) |
| 83 |
{ |
| 84 |
m_url = createTestUrl(url); |
| 85 |
} |
| 86 |
|
| 87 |
EFLTestView::EFLTestView(Evas *evas, EwkViewType type, const char* url) |
| 88 |
: m_webView(0) |
| 89 |
, m_evas(evas) |
| 90 |
, m_url(0) |
| 91 |
, m_defaultViewType(type) |
| 92 |
, m_width(EFLUnitTests::Config::defaultViewWidth) |
| 93 |
, m_height(EFLUnitTests::Config::defaultViewHeight) |
| 94 |
{ |
| 95 |
m_url = createTestUrl(url); |
| 96 |
} |
| 97 |
|
| 98 |
EFLTestView::EFLTestView(Evas *evas, EwkViewType type, const char* url, int width, int height) |
| 99 |
: m_webView(0) |
| 100 |
, m_evas(evas) |
| 101 |
, m_url(0) |
| 102 |
, m_defaultViewType(type) |
| 103 |
, m_width(width) |
| 104 |
, m_height(height) |
| 105 |
{ |
| 106 |
m_url = createTestUrl(url); |
| 107 |
} |
| 108 |
|
| 109 |
EFLTestView::~EFLTestView() |
| 110 |
{ |
| 111 |
if (m_webView) |
| 112 |
evas_object_del(m_webView); |
| 113 |
free(m_url); |
| 114 |
} |
| 115 |
|
| 116 |
char* EFLTestView::createTestUrl(const char* url) |
| 117 |
{ |
| 118 |
if (url) |
| 119 |
return strdup(url); |
| 120 |
return 0; |
| 121 |
} |
| 122 |
|
| 123 |
Eina_Bool EFLTestView::init() |
| 124 |
{ |
| 125 |
if (!m_evas || !m_url) |
| 126 |
return EINA_FALSE; |
| 127 |
|
| 128 |
switch (m_defaultViewType) { |
| 129 |
case SingleView: |
| 130 |
m_webView = ewk_view_single_add(m_evas); |
| 131 |
break; |
| 132 |
|
| 133 |
case TiledView: |
| 134 |
m_webView = ewk_view_tiled_add(m_evas); |
| 135 |
break; |
| 136 |
} |
| 137 |
|
| 138 |
if (!m_webView) |
| 139 |
return EINA_FALSE; |
| 140 |
|
| 141 |
ewk_view_theme_set(m_webView, EFLUnitTests::Config::defaultThemePath); |
| 142 |
ewk_view_uri_set(m_webView, m_url); |
| 143 |
} |
| 144 |
|
| 145 |
void EFLTestView::show() |
| 146 |
{ |
| 147 |
if (!m_webView) |
| 148 |
return; |
| 149 |
evas_object_resize(m_webView, m_width, m_height); |
| 150 |
evas_object_show(m_webView); |
| 151 |
evas_object_focus_set(m_webView, EINA_TRUE); |
| 152 |
} |
| 153 |
|
| 154 |
Evas_Object* EFLTestView::getMainFrame() |
| 155 |
{ |
| 156 |
if (m_webView) |
| 157 |
return ewk_view_frame_main_get(m_webView); |
| 158 |
return 0; |
| 159 |
} |
| 160 |
|
| 161 |
Evas* EFLTestView::getEvas() |
| 162 |
{ |
| 163 |
if (m_webView) |
| 164 |
return evas_object_evas_get(m_webView); |
| 165 |
return 0; |
| 166 |
} |
| 167 |
|
| 168 |
void EFLTestView::bindEvents(void (*callback)(void*, Evas_Object*, void*), const char* eventName, void* ptr) |
| 169 |
{ |
| 170 |
if (!m_webView) |
| 171 |
return; |
| 172 |
|
| 173 |
evas_object_smart_callback_del(m_webView, eventName, callback); |
| 174 |
evas_object_smart_callback_add(m_webView, eventName, callback, ptr); |
| 175 |
} |
| 176 |
|
| 177 |
} |