diff options
author | gspencer@chromium.org <gspencer@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-28 17:26:49 +0000 |
---|---|---|
committer | gspencer@chromium.org <gspencer@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-28 17:26:49 +0000 |
commit | d65adb173f09a837c96f96fc24a258f439e46e58 (patch) | |
tree | 43605ab367e97389930c518c4e94bd3da5f20080 /chrome/renderer | |
parent | 7cea56d943924d0c2196bdf4049f592b6182992c (diff) | |
download | chromium_src-d65adb173f09a837c96f96fc24a258f439e46e58.zip chromium_src-d65adb173f09a837c96f96fc24a258f439e46e58.tar.gz chromium_src-d65adb173f09a837c96f96fc24a258f439e46e58.tar.bz2 |
This adds in the ability for Chrome to generate windows with snapshots
of all currently open tabs in all browsers.
This is needed for overview mode on ChromeOS.
BUG=http://code.google.com/p/chromium-os/issues/detail?id=1170
TEST=Ran Chrome under ChromeOS with updated window manager.
Review URL: http://codereview.chromium.org/661237
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@45824 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer')
-rw-r--r-- | chrome/renderer/render_widget.cc | 74 | ||||
-rw-r--r-- | chrome/renderer/render_widget.h | 5 |
2 files changed, 74 insertions, 5 deletions
diff --git a/chrome/renderer/render_widget.cc b/chrome/renderer/render_widget.cc index d7676ed..243665a 100644 --- a/chrome/renderer/render_widget.cc +++ b/chrome/renderer/render_widget.cc @@ -149,6 +149,7 @@ IPC_DEFINE_MESSAGE_MAP(RenderWidget) IPC_MESSAGE_HANDLER(ViewMsg_SetFocus, OnSetFocus) IPC_MESSAGE_HANDLER(ViewMsg_ImeSetInputMode, OnImeSetInputMode) IPC_MESSAGE_HANDLER(ViewMsg_ImeSetComposition, OnImeSetComposition) + IPC_MESSAGE_HANDLER(ViewMsg_PaintAtSize, OnMsgPaintAtSize) IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnMsgRepaint) IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection) IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck) @@ -250,8 +251,8 @@ void RenderWidget::OnWasRestored(bool needs_repainting) { return; needs_repainting_on_restore_ = false; - // Tag the next paint as a restore ack, which is picked up by DoDeferredUpdate - // when it sends out the next PaintRect message. + // Tag the next paint as a restore ack, which is picked up by + // DoDeferredUpdate when it sends out the next PaintRect message. set_next_paint_is_restore_ack(); // Generate a full repaint. @@ -268,7 +269,7 @@ void RenderWidget::OnUpdateRectAck() { update_reply_pending_ = false; // If we sent an UpdateRect message with a zero-sized bitmap, then we should - // have no current update buf. + // have no current paint buffer. if (current_paint_buf_) { RenderProcess::current()->ReleaseTransportDIB(current_paint_buf_); current_paint_buf_ = NULL; @@ -720,6 +721,72 @@ void RenderWidget::OnImeSetComposition(WebCompositionCommand command, ime_control_busy_ = false; } +// Forces a repaint even if we're hidden, so we can update backing +// store even before a tab has been shown for the first time, and it +// does it synchronously. +void RenderWidget::OnMsgPaintAtSize(const TransportDIB::Handle& dib_handle, + const gfx::Size& desired_size) { + if (!webwidget_ || dib_handle == TransportDIB::DefaultHandleValue()) + return; + + if (webwidget_->size().isEmpty() || + desired_size.IsEmpty()) { + // If one of these is empty, then we just return the dib we were + // given, to avoid leaking it. + Send(new ViewHostMsg_PaintAtSize_ACK(routing_id_, + dib_handle, + desired_size)); + return; + } + + // Map the given DIB ID into this process, and unmap it at the end + // of this function. + scoped_ptr<TransportDIB> paint_at_scale_buffer(TransportDIB::Map(dib_handle)); + + DCHECK(paint_at_scale_buffer.get()); + if (!paint_at_scale_buffer.get()) + return; + + // Have to make sure we're laid out before rendering. + webwidget_->layout(); + + gfx::Size canvas_size = webwidget_->size(); + float x_scale = static_cast<float>(desired_size.width()) / + static_cast<float>(canvas_size.width()); + float y_scale = static_cast<float>(desired_size.height()) / + static_cast<float>(canvas_size.height()); + + gfx::Rect orig_bounds(gfx::Point(0,0), canvas_size); + canvas_size.set_width(static_cast<int>(canvas_size.width() * x_scale)); + canvas_size.set_height(static_cast<int>(canvas_size.height() * y_scale)); + gfx::Rect bounds(gfx::Point(0,0), canvas_size); + + scoped_ptr<skia::PlatformCanvas> canvas( + paint_at_scale_buffer->GetPlatformCanvas(canvas_size.width(), + canvas_size.height())); + if (!canvas.get()) { + NOTREACHED(); + return; + } + + // Reset bounds to what we actually received, but they should be the + // same. + DCHECK_EQ(bounds.width(), canvas->getDevice()->width()); + DCHECK_EQ(bounds.height(), canvas->getDevice()->height()); + bounds.set_width(canvas->getDevice()->width()); + bounds.set_height(canvas->getDevice()->height()); + + canvas->save(); + // Add the scale factor to the canvas, so that we'll get what we expect. + canvas->scale(SkFloatToScalar(x_scale), SkFloatToScalar(y_scale)); + + // Paint the entire thing (using original bounds, not scaled bounds). + PaintRect(orig_bounds, orig_bounds.origin(), canvas.get()); + canvas->restore(); + + Send(new ViewHostMsg_PaintAtSize_ACK(routing_id_, dib_handle, bounds.size())); +} + void RenderWidget::OnMsgRepaint(const gfx::Size& size_to_paint) { // During shutdown we can just ignore this message. if (!webwidget_) @@ -878,4 +945,3 @@ void RenderWidget::CleanupWindowInPluginMoves(gfx::PluginWindowHandle window) { } } } - diff --git a/chrome/renderer/render_widget.h b/chrome/renderer/render_widget.h index 2fdc1e5..9577630 100644 --- a/chrome/renderer/render_widget.h +++ b/chrome/renderer/render_widget.h @@ -7,6 +7,7 @@ #include <vector> +#include "app/surface/transport_dib.h" #include "base/basictypes.h" #include "base/ref_counted.h" #include "base/shared_memory.h" @@ -18,12 +19,12 @@ #include "gfx/size.h" #include "ipc/ipc_channel.h" #include "skia/ext/platform_canvas.h" -#include "third_party/skia/include/core/SkBitmap.h" #include "third_party/WebKit/WebKit/chromium/public/WebCompositionCommand.h" #include "third_party/WebKit/WebKit/chromium/public/WebPopupType.h" #include "third_party/WebKit/WebKit/chromium/public/WebRect.h" #include "third_party/WebKit/WebKit/chromium/public/WebTextDirection.h" #include "third_party/WebKit/WebKit/chromium/public/WebWidgetClient.h" +#include "third_party/skia/include/core/SkBitmap.h" #include "webkit/glue/webcursor.h" class RenderThreadBase; @@ -160,6 +161,8 @@ class RenderWidget : public IPC::Channel::Listener, int cursor_position, int target_start, int target_end, const string16& ime_string); + void OnMsgPaintAtSize(const TransportDIB::Handle& dib_id, + const gfx::Size& desired_size); void OnMsgRepaint(const gfx::Size& size_to_paint); void OnSetTextDirection(WebKit::WebTextDirection direction); |