summaryrefslogtreecommitdiffstats
path: root/chrome/renderer
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/renderer')
-rw-r--r--chrome/renderer/render_view.cc8
-rw-r--r--chrome/renderer/render_view.h6
-rw-r--r--chrome/renderer/render_widget.cc26
-rw-r--r--chrome/renderer/render_widget.h9
4 files changed, 48 insertions, 1 deletions
diff --git a/chrome/renderer/render_view.cc b/chrome/renderer/render_view.cc
index 1893e25..e3cbc9f 100644
--- a/chrome/renderer/render_view.cc
+++ b/chrome/renderer/render_view.cc
@@ -443,6 +443,7 @@ void RenderView::OnMessageReceived(const IPC::Message& message) {
IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted)
IPC_MESSAGE_HANDLER(ViewMsg_ExtensionResponse, OnExtensionResponse)
IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedNode, OnClearFocusedNode)
+ IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground)
// Have the super handle all other messages.
IPC_MESSAGE_UNHANDLED(RenderWidget::OnMessageReceived(message))
@@ -2954,6 +2955,13 @@ void RenderView::OnClearFocusedNode() {
webview()->ClearFocusedNode();
}
+void RenderView::OnSetBackground(const SkBitmap& background) {
+ if (webview())
+ webview()->SetIsTransparent(!background.empty());
+
+ SetBackground(background);
+}
+
void RenderView::SendExtensionRequest(const std::string& name,
const std::string& args,
int callback_id,
diff --git a/chrome/renderer/render_view.h b/chrome/renderer/render_view.h
index eb3aa55..505dca0 100644
--- a/chrome/renderer/render_view.h
+++ b/chrome/renderer/render_view.h
@@ -26,6 +26,7 @@
#include "chrome/renderer/external_host_bindings.h"
#include "chrome/renderer/external_js_object.h"
#include "chrome/renderer/render_widget.h"
+#include "skia/include/SkBitmap.h"
#include "testing/gtest/include/gtest/gtest_prod.h"
#include "third_party/WebKit/WebKit/chromium/public/WebConsoleMessage.h"
#include "webkit/glue/dom_serializer_delegate.h"
@@ -52,7 +53,6 @@ class FilePath;
class GURL;
class RenderThread;
class ResourceDispatcher;
-class SkBitmap;
class WebAccessibilityManager;
class WebError;
class WebFrame;
@@ -582,6 +582,10 @@ class RenderView : public RenderWidget,
// Sends the selection text to the browser.
void OnRequestSelectionText();
+ // Handle message to make the RenderView transparent and render it on top of
+ // a custom background.
+ void OnSetBackground(const SkBitmap& background);
+
// Prints the page listed in |params|.
void PrintPage(const ViewMsg_PrintPage_Params& params,
const gfx::Size& canvas_size,
diff --git a/chrome/renderer/render_widget.cc b/chrome/renderer/render_widget.cc
index 4cd54c1..23f27da 100644
--- a/chrome/renderer/render_widget.cc
+++ b/chrome/renderer/render_widget.cc
@@ -14,6 +14,7 @@
#include "chrome/common/transport_dib.h"
#include "chrome/renderer/render_process.h"
#include "skia/ext/platform_canvas.h"
+#include "skia/include/SkShader.h"
#include "third_party/WebKit/WebKit/chromium/public/WebRect.h"
#include "third_party/WebKit/WebKit/chromium/public/WebScreenInfo.h"
#include "third_party/WebKit/WebKit/chromium/public/WebSize.h"
@@ -308,6 +309,25 @@ void RenderWidget::ClearFocus() {
void RenderWidget::PaintRect(const gfx::Rect& rect,
skia::PlatformCanvas* canvas) {
+
+ // If there is a custom background, tile it.
+ if (!background_.empty()) {
+ canvas->save();
+
+ SkIRect clipRect = { rect.x(), rect.y(), rect.right(), rect.bottom() };
+ canvas->setClipRegion(SkRegion(clipRect));
+
+ SkPaint paint;
+ SkShader* shader = SkShader::CreateBitmapShader(background_,
+ SkShader::kRepeat_TileMode,
+ SkShader::kRepeat_TileMode);
+ paint.setShader(shader)->unref();
+ paint.setPorterDuffXfermode(SkPorterDuff::kSrcOver_Mode);
+ canvas->drawPaint(paint);
+
+ canvas->restore();
+ }
+
// Bring the canvas into the coordinate system of the paint rect
canvas->translate(static_cast<SkScalar>(-rect.x()),
static_cast<SkScalar>(-rect.y()));
@@ -675,6 +695,12 @@ void RenderWidget::OnSetTextDirection(int direction) {
}
}
+void RenderWidget::SetBackground(const SkBitmap& background) {
+ background_ = background;
+ // Generate a full repaint.
+ DidInvalidateRect(webwidget_, gfx::Rect(size_.width(), size_.height()));
+}
+
bool RenderWidget::next_paint_is_resize_ack() const {
return ViewHostMsg_PaintRect_Flags::is_resize_ack(next_paint_flags_);
}
diff --git a/chrome/renderer/render_widget.h b/chrome/renderer/render_widget.h
index 668b4fd..62777e8 100644
--- a/chrome/renderer/render_widget.h
+++ b/chrome/renderer/render_widget.h
@@ -16,6 +16,7 @@
#include "chrome/common/ipc_channel.h"
#include "chrome/renderer/render_process.h"
#include "skia/ext/platform_canvas.h"
+#include "skia/include/SkBitmap.h"
#include "webkit/glue/webwidget_delegate.h"
#include "webkit/glue/webcursor.h"
@@ -123,6 +124,11 @@ class RenderWidget : public IPC::Channel::Listener,
// corresponding paint or scroll message is send to the widget host.
virtual void DidPaint() {}
+ // Set the background of the render widget to a bitmap. The bitmap will be
+ // tiled in both directions if it isn't big enough to fill the area. This is
+ // mainly intended to be used in conjuction with WebView::SetIsTransparent().
+ virtual void SetBackground(const SkBitmap& bitmap);
+
// RenderWidget IPC message handlers
void OnClose();
void OnCreatingNewAck(gfx::NativeViewId parent);
@@ -271,6 +277,9 @@ class RenderWidget : public IPC::Channel::Listener,
// Holds all the needed plugin window moves for a scroll.
std::vector<WebPluginGeometry> plugin_window_moves_;
+ // A custom background for the widget.
+ SkBitmap background_;
+
DISALLOW_COPY_AND_ASSIGN(RenderWidget);
};