1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/renderer/webview_color_overlay.h"
7 #include "base/logging.h"
8 #include "content/public/renderer/render_view.h"
9 #include "third_party/skia/include/core/SkCanvas.h"
10 #include "third_party/skia/include/core/SkPaint.h"
11 #include "third_party/skia/include/core/SkRect.h"
12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
13 #include "ui/gfx/size.h"
14 #include "ui/gfx/skia_util.h"
17 #include "skia/ext/skia_utils_mac.h"
20 WebViewColorOverlay::WebViewColorOverlay(content::RenderView
* render_view
,
22 : render_view_(render_view
),
24 render_view_
->GetWebView()->addPageOverlay(this, 0);
27 WebViewColorOverlay::~WebViewColorOverlay() {
28 if (render_view_
->GetWebView())
29 render_view_
->GetWebView()->removePageOverlay(this);
32 void WebViewColorOverlay::paintPageOverlay(WebKit::WebCanvas
* canvas
) {
33 SkRect rect
= gfx::RectToSkRect(gfx::Rect(render_view_
->GetSize()));
37 paint
.setColor(color_
);
38 paint
.setStyle(SkPaint::kFill_Style
);
39 canvas
->drawRect(rect
, paint
);
41 CGContextSaveGState(canvas
);
42 CGColorRef color
= gfx::SkColorToCGColorRef(color_
);
43 CGContextSetFillColorWithColor(canvas
, color
);
44 CGColorRelease(color
);
45 CGContextFillRect(canvas
, gfx::SkRectToCGRect(rect
));
46 CGContextRestoreGState(canvas
);