Chromium Code Reviews| Index: chrome/browser/ui/window_snapshot/window_snapshot_gtk.cc |
| diff --git a/chrome/browser/ui/window_snapshot/window_snapshot_gtk.cc b/chrome/browser/ui/window_snapshot/window_snapshot_gtk.cc |
| index 4507996ad5264b6ab7102f84d2648e8b98d2de3a..6ee162ac3860bf6d5a9fc43bb2c3de44594113c3 100644 |
| --- a/chrome/browser/ui/window_snapshot/window_snapshot_gtk.cc |
| +++ b/chrome/browser/ui/window_snapshot/window_snapshot_gtk.cc |
| @@ -13,6 +13,20 @@ |
| namespace browser { |
| +namespace { |
| +gfx::Rect GetWindowBounds(gfx::NativeWindow window_handle) { |
|
jonathan.backer
2011/11/14 13:45:02
There are two functions in ui/base/x11_util.h that
sky
2011/11/14 16:23:09
nit: newline between 16 and 17.
|
| + GdkWindow* gdk_window = GTK_WIDGET(window_handle)->window; |
| + Display* display = GDK_WINDOW_XDISPLAY(gdk_window); |
| + XID win = GDK_WINDOW_XID(gdk_window); |
| + XWindowAttributes attr; |
| + if (XGetWindowAttributes(display, win, &attr) == 0) { |
| + return gfx::Rect(); |
| + } |
| + return gfx::Rect(0, 0, attr.width, attr.height); |
| +} |
| + |
| +} // namespace |
| + |
| static cairo_status_t SnapshotCallback( |
| void *closure, const unsigned char *data, unsigned int length) { |
| std::vector<unsigned char>* png_representation = |
| @@ -24,18 +38,31 @@ static cairo_status_t SnapshotCallback( |
| return CAIRO_STATUS_SUCCESS; |
| } |
| -gfx::Rect GrabWindowSnapshot(gfx::NativeWindow gtk_window, |
| +gfx::Rect GrabWindowSnapshot(gfx::NativeWindow window_handle, |
| std::vector<unsigned char>* png_representation) { |
| - GdkWindow* gdk_window = GTK_WIDGET(gtk_window)->window; |
| - Display* display = GDK_WINDOW_XDISPLAY(gdk_window); |
| - XID win = GDK_WINDOW_XID(gdk_window); |
| - XWindowAttributes attr; |
| - if (XGetWindowAttributes(display, win, &attr) == 0) { |
| + return GrabWindowSnapshot(window_handle, png_representation, |
| + GetWindowBounds(window_handle)); |
| +} |
| + |
| +gfx::Rect GrabWindowSnapshot(gfx::NativeWindow window_handle, |
| + std::vector<unsigned char>* png_representation, |
| + const gfx::Rect snapshot_bounds) { |
| + gfx::Rect window_bounds = GetWindowBounds(window_handle); |
| + if (window_bounds.IsEmpty()) { |
| LOG(ERROR) << "Couldn't get window attributes"; |
| return gfx::Rect(); |
| } |
| + |
| + DCHECK(snapshot_bounds.right() <= window_bounds.width()); |
| + DCHECK(snapshot_bounds.bottom() <= window_bounds.height()); |
| + |
| + GdkWindow* gdk_window = GTK_WIDGET(window_handle)->window; |
|
jonathan.backer
2011/11/14 13:45:02
GetX11WindowFromGtkWidget
|
| + Display* display = GDK_WINDOW_XDISPLAY(gdk_window); |
|
jonathan.backer
2011/11/14 13:45:02
GetXDisplay?
pkotwicz
2011/11/15 15:56:12
It seems as if we are trying to deprecate this met
Elliot Glaysher
2011/11/15 18:06:34
Please don't use GetXDisplay(). We aren't guarante
|
| + XID win = GDK_WINDOW_XID(gdk_window); |
| + |
| XImage* image = XGetImage( |
| - display, win, 0, 0, attr.width, attr.height, AllPlanes, ZPixmap); |
| + display, win, snapshot_bounds.x(), snapshot_bounds.y(), |
| + snapshot_bounds.width(), snapshot_bounds.height(), AllPlanes, ZPixmap); |
| if (!image) { |
| LOG(ERROR) << "Couldn't get image"; |
| return gfx::Rect(); |