Skip to content

Commit 219e898

Browse files
committed
Updating screenshot code to retain scroll bars in required directions.
When an IE window needs to be resized to obtain the full-DOM screenshot, if it has scroll bars in either direction, those scroll bars need to be present in the resized window, so that layout recalculation doesn't occur. In practice, this means reducing the window size by 2 pixels in the appropriate direction before taking the screenshot. The resulting scroll bars are cropped from the image.
1 parent ab1e647 commit 219e898

File tree

5 files changed

+24
-12
lines changed

5 files changed

+24
-12
lines changed

cpp/iedriver/CommandHandlers/ScreenshotCommandHandler.h

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -156,25 +156,25 @@ class ScreenshotCommandHandler : public IECommandHandler {
156156
// If the window is already wide enough to accomodate
157157
// the document, don't resize that dimension. Otherwise,
158158
// the window will display a horizontal scroll bar, and
159-
// we need to take the scroll bar height into account when
160-
// we size resulting image.
161-
int horizontal_scrollbar_height = 0;
159+
// we need to retain the scrollbar to avoid rerendering
160+
// during the resize, so reduce the target window width
161+
// by two pixels.
162162
if (original_width > target_window_width) {
163163
target_window_width = original_width;
164164
} else {
165-
horizontal_scrollbar_height = ::GetSystemMetrics(SM_CYHSCROLL);
165+
target_window_width -= 2;
166166
}
167167

168168
// If the window is already tall enough to accomodate
169169
// the document, don't resize that dimension. Otherwise,
170170
// the window will display a vertical scroll bar, and
171-
// we need to take the scrollbar width into account when
172-
// we size the resulting image.
173-
int vertical_scrollbar_width = 0;
171+
// we need to retain the scrollbar to avoid rerendering
172+
// during the resize, so reduce the target window height
173+
// by two pixels.
174174
if (original_height > target_window_height) {
175175
target_window_height = original_height;
176176
} else {
177-
vertical_scrollbar_width = ::GetSystemMetrics(SM_CXVSCROLL);
177+
target_window_height -= 2;
178178
}
179179

180180
BOOL is_maximized = ::IsZoomed(ie_window_handle);
@@ -211,10 +211,12 @@ class ScreenshotCommandHandler : public IECommandHandler {
211211
}
212212

213213
// Capture the window's canvas to a DIB.
214-
BOOL created = this->image_->Create(
215-
document_info.width + vertical_scrollbar_width,
216-
document_info.height + horizontal_scrollbar_height,
217-
/*numbers of bits per pixel = */ 32);
214+
// If there are any scroll bars in the window, they should
215+
// be explicitly cropped out of the image, because of the
216+
// size of image we are creating..
217+
BOOL created = this->image_->Create(document_info.width,
218+
document_info.height,
219+
/*numbers of bits per pixel = */ 32);
218220
if (!created) {
219221
LOG(WARN) << "Unable to initialize image object";
220222
}

cpp/iedriverserver/CHANGELOG

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@ available via the project downloads page. Changes in "revision" field indicate
99
private releases checked into the prebuilts directory of the source tree, but
1010
not made generally available on the downloads page.
1111

12+
v2.47.0.5
13+
=========
14+
* Updating screenshot code to retain scroll bars in required directions.
15+
When an IE window needs to be resized to obtain the full-DOM screenshot,
16+
if it has scroll bars in either direction, those scroll bars need to be
17+
present in the resized window, so that layout recalculation doesn't occur.
18+
In practice, this means reducing the window size by 2 pixels in the
19+
appropriate direction before taking the screenshot. The resulting scroll
20+
bars are cropped from the image.
21+
1222
v2.47.0.4
1323
=========
1424
* Updates to JavaScript automation atoms.

cpp/iedriverserver/IEDriverServer.rc

0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)