14
14
15
15
namespace webdriver {
16
16
17
- QWebViewVisualizerSourceCommand::QWebViewVisualizerSourceCommand (QWebViewCmdExecutor* executor , Session* session, QWebView* view)
18
- : executor_(executor ), session_(session), view_(view)
17
+ QWebViewVisualizerSourceCommand::QWebViewVisualizerSourceCommand (yasper::ptr<QWebkitProxy> webkitProxy , Session* session, QWebView* view)
18
+ : webkitProxy_(webkitProxy ), session_(session), view_(view)
19
19
{}
20
20
21
21
void QWebViewVisualizerSourceCommand::Execute (std::string* source, Error** error) {
@@ -36,11 +36,10 @@ void QWebViewVisualizerSourceCommand::Execute(std::string* source, Error** error
36
36
" return new XMLSerializer().serializeToString(root);" ;
37
37
38
38
Value* unscoped_value = NULL ;
39
- executor_ ->ExecuteScript (
39
+ *error = webkitProxy_ ->ExecuteScript (
40
40
kSource ,
41
41
new ListValue (),
42
- &unscoped_value,
43
- error);
42
+ &unscoped_value);
44
43
if (*error) {
45
44
(*error)->AddDetails (" getSource execution failed" );
46
45
return ;
@@ -230,15 +229,27 @@ void QWebViewVisualizerSourceCommand::AssembleImg(pugi::xml_node element) const
230
229
231
230
void QWebViewVisualizerSourceCommand::AssembleStyle (pugi::xml_node element) const {
232
231
pugi::xml_attribute type = element.attribute (" type" );
233
- if (type.empty () != 0 &&
232
+ if (! type.empty () &&
234
233
std::string (type.value ()) != " text/css" ) {
235
234
return ;
236
235
}
237
236
238
- QString value = QString::fromUtf8 (element.text ().as_string ());
239
- value = AssembleStyle (value);
240
- clearChildren (element);
241
- element.append_child (pugi::node_pcdata).set_value (value.toStdString ().c_str ());
237
+ if (len (element.children ()) == 1 &&
238
+ element.first_child ().type () == pugi::node_cdata) {
239
+ pugi::xml_node cdata = element.first_child ();
240
+ element.remove_child (cdata);
241
+ QString value = QString::fromUtf8 (cdata.value ());
242
+ value = AssembleStyle (value);
243
+ element.append_child (pugi::node_pcdata).set_value (value.toStdString ().c_str ());
244
+ } else {
245
+ for (pugi::xml_node_iterator childIt = element.begin (); childIt != element.end (); childIt++) {
246
+ if (childIt->type () == pugi::node_pcdata) {
247
+ QString value = QString::fromUtf8 (childIt->value ());
248
+ value = AssembleStyle (value);
249
+ childIt->set_value (value.toStdString ().c_str ());
250
+ }
251
+ }
252
+ }
242
253
}
243
254
244
255
void QWebViewVisualizerSourceCommand::AssembleStyle (pugi::xml_attribute attribute) const {
@@ -353,6 +364,10 @@ bool QWebViewVisualizerSourceCommand::isEmpty(const pugi::xml_object_range<pugi:
353
364
return range.begin () == range.end ();
354
365
}
355
366
367
+ int QWebViewVisualizerSourceCommand::len (const pugi::xml_object_range<pugi::xml_node_iterator>& range) {
368
+ return std::distance (range.begin (), range.end ());
369
+ }
370
+
356
371
void QWebViewVisualizerSourceCommand::clearChildren (pugi::xml_node element) {
357
372
std::vector<pugi::xml_node> children;
358
373
for (pugi::xml_node_iterator it = element.children ().begin (); it != element.children ().end (); it++) {
@@ -390,8 +405,8 @@ class QCursorMark : public QWidget
390
405
static const int RADIUS = 5 ;
391
406
};
392
407
393
- QWebViewVisualizerShowPointCommand::QWebViewVisualizerShowPointCommand (QWebViewCmdExecutor* executor , Session* session, QWebView* view)
394
- : executor_(executor ), session_(session), view_(view)
408
+ QWebViewVisualizerShowPointCommand::QWebViewVisualizerShowPointCommand (yasper::ptr<QWebkitProxy> webkitProxy , Session* session, QWebView* view)
409
+ : webkitProxy_(webkitProxy ), session_(session), view_(view)
395
410
{}
396
411
397
412
void QWebViewVisualizerShowPointCommand::Execute (Error** error) {
0 commit comments