@@ -58,71 +58,47 @@ void GetElementRectCommandHandler::ExecuteInternal(
58
58
// Furthermore, we need to invoke the function that is the atom and
59
59
// get the result, but we need to wrap the execution in another function
60
60
// so that it can be invoked without polluting the current namespace.
61
- std::wstring script_source = L" (function() { return function() { var result = " ;
62
- script_source += L" (function() { return (" ;
63
- script_source += atoms::asString (atoms::GET_SIZE);
64
- script_source += L" )})().apply(null, arguments);" ;
65
- script_source += L" return [result.width, result.height]; };})();" ;
61
+ std::wstring script_source (L" (function() { return (" );
62
+ script_source += atoms::asString (atoms::GET_ELEMENT_RECT);
63
+ script_source += L" )})();" ;
66
64
67
65
CComPtr<IHTMLDocument2> doc;
68
66
browser_wrapper->GetDocument (&doc);
69
67
70
- Json::Value size_array ;
68
+ Json::Value rect_object ;
71
69
Script script_wrapper (doc, script_source, 1 );
72
70
script_wrapper.AddArgument (element_wrapper);
73
71
status_code = script_wrapper.Execute ();
74
72
75
73
if (status_code == WD_SUCCESS) {
76
- script_wrapper.ConvertResultToJsonValue (executor, &size_array );
74
+ script_wrapper.ConvertResultToJsonValue (executor, &rect_object );
77
75
78
- Json::UInt index = 0 ;
79
76
Json::Value response_value;
80
- response_value[" width" ] = size_array[index];
81
- ++index;
82
- response_value[" height" ] = size_array[index];
83
-
84
- script_source = L" (function() { return function() { var result = " ;
85
- script_source += L" (function() { return (" ;
86
- script_source += atoms::asString (atoms::GET_LOCATION);
87
- script_source += L" )})().apply(null, arguments);" ;
88
- script_source += L" return [result.x, result.y]; };})();" ;
89
-
90
- Json::Value location_array;
91
- Script location_script_wrapper (doc, script_source, 1 );
92
- location_script_wrapper.AddArgument (element_wrapper);
93
- status_code = location_script_wrapper.Execute ();
94
-
95
- if (status_code == WD_SUCCESS) {
96
- location_script_wrapper.ConvertResultToJsonValue (executor, &location_array);
97
- Json::UInt index = 0 ;
98
- int x = location_array.get (index, 0 ).asInt ();
99
- ++index;
100
- int y = location_array.get (index, 0 ).asInt ();
101
-
102
- CComPtr<IHTMLDocument2> doc;
103
- browser_wrapper->GetDocument (&doc);
104
- int browser_version = executor.browser_factory ()->browser_version ();
105
- bool browser_appears_before_ie8 = browser_version < 8 || DocumentHost::GetDocumentMode (doc) <= 7 ;
106
- bool is_quirks_mode = !DocumentHost::IsStandardsMode (doc);
107
- if (browser_appears_before_ie8 && !is_quirks_mode) {
108
- // NOTE: For IE 6 and 7 in standards mode, elements with "display:none"
109
- // in the CSS style should have a 2-pixel offset for their location.
110
- std::string display_value = " " ;
111
- element_wrapper->GetCssPropertyValue (" display" , &display_value);
112
- if (display_value == " none" ) {
113
- int offset = 2 ;
114
- x += offset;
115
- y += offset;
116
- }
77
+ response_value[" width" ] = rect_object[" width" ];
78
+ response_value[" height" ] = rect_object[" height" ];
79
+
80
+ int x = rect_object.get (" x" , 0 ).asInt ();
81
+ int y = rect_object.get (" y" , 0 ).asInt ();
82
+
83
+ int browser_version = executor.browser_factory ()->browser_version ();
84
+ bool browser_appears_before_ie8 = browser_version < 8 || DocumentHost::GetDocumentMode (doc) <= 7 ;
85
+ bool is_quirks_mode = !DocumentHost::IsStandardsMode (doc);
86
+ if (browser_appears_before_ie8 && !is_quirks_mode) {
87
+ // NOTE: For IE 6 and 7 in standards mode, elements with "display:none"
88
+ // in the CSS style should have a 2-pixel offset for their location.
89
+ std::string display_value = " " ;
90
+ element_wrapper->GetCssPropertyValue (" display" , &display_value);
91
+ if (display_value == " none" ) {
92
+ int offset = 2 ;
93
+ x += offset;
94
+ y += offset;
117
95
}
118
-
119
- response_value[" x" ] = x;
120
- response_value[" y" ] = y;
121
- response->SetSuccessResponse (response_value);
122
- return ;
123
- } else {
124
- response->SetErrorResponse (status_code, " Unable to get element location" );
125
96
}
97
+
98
+ response_value[" x" ] = x;
99
+ response_value[" y" ] = y;
100
+ response->SetSuccessResponse (response_value);
101
+ return ;
126
102
} else {
127
103
response->SetErrorResponse (status_code, " Unable to get element sizes" );
128
104
return ;
0 commit comments