Windows: Allow customization of background color (issue #1161).

git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@1559 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
Marshall Greenblatt 2014-01-07 18:04:31 +00:00
parent 72660c6fed
commit b479cb3aa3
3 changed files with 48 additions and 4 deletions

View File

@ -85,6 +85,27 @@ typedef unsigned short char16;
#endif
#endif
// 32-bit ARGB color value, not premultiplied. The color components are always
// in a known order. Equivalent to the SkColor type.
typedef uint32 cef_color_t;
// Return the alpha byte from a cef_color_t value.
#define CefColorGetA(color) (((color) >> 24) & 0xFF)
// Return the red byte from a cef_color_t value.
#define CefColorGetR(color) (((color) >> 16) & 0xFF)
// Return the green byte from a cef_color_t value.
#define CefColorGetG(color) (((color) >> 8) & 0xFF)
// Return the blue byte from a cef_color_t value.
#define CefColorGetB(color) (((color) >> 0) & 0xFF)
// Return an cef_color_t value with the specified byte component values.
#define CefColorSetARGB(a, r, g, b) \
static_cast<cef_color_t>( \
(static_cast<unsigned>(a) << 24) | \
(static_cast<unsigned>(r) << 16) | \
(static_cast<unsigned>(g) << 8) | \
(static_cast<unsigned>(b) << 0))
#ifdef __cplusplus
extern "C" {
#endif
@ -344,6 +365,14 @@ typedef struct _cef_settings_t {
// "ignore-certificate-errors" command-line switch.
///
int ignore_certificate_errors;
///
// Opaque background color used for accelerated content. By default the
// background color will be white. Only the RGB compontents of the specified
// value will be used. The alpha component must greater than 0 to enable use
// of the background color but will be otherwise ignored.
///
cef_color_t background_color;
} cef_settings_t;
///

View File

@ -377,6 +377,7 @@ struct CefSettingsTraits {
target->uncaught_exception_stack_size = src->uncaught_exception_stack_size;
target->context_safety_implementation = src->context_safety_implementation;
target->ignore_certificate_errors = src->ignore_certificate_errors;
target->background_color = src->background_color;
}
};

View File

@ -12,6 +12,7 @@
#include <winspool.h>
#include "libcef/browser/content_browser_client.h"
#include "libcef/browser/context.h"
#include "libcef/browser/thread_util.h"
#include "base/file_util.h"
@ -552,8 +553,10 @@ bool IsSystemCursorID(LPCWSTR cursor_id) {
// will be deleted automatically when the associated root window is destroyed.
class CefWindowDelegateView : public views::WidgetDelegateView {
public:
CefWindowDelegateView()
: web_view_(NULL) {
explicit CefWindowDelegateView(SkColor background_color)
: background_color_(background_color),
web_view_(NULL) {
}
// Create the Widget and associated root window.
@ -592,7 +595,7 @@ class CefWindowDelegateView : public views::WidgetDelegateView {
private:
// Initialize the Widget's content.
void InitContent() {
set_background(views::Background::CreateStandardPanelBackground());
set_background(views::Background::CreateSolidBackground(background_color_));
SetLayoutManager(new views::FillLayout());
AddChildView(web_view_);
}
@ -610,6 +613,7 @@ class CefWindowDelegateView : public views::WidgetDelegateView {
}
private:
SkColor background_color_;
views::WebView* web_view_;
DISALLOW_COPY_AND_ASSIGN(CefWindowDelegateView);
@ -753,7 +757,17 @@ bool CefBrowserHostImpl::PlatformCreateWindow() {
DCHECK(!window_widget_);
CefWindowDelegateView* delegate_view = new CefWindowDelegateView();
SkColor background_color = SK_ColorWHITE;
const CefSettings& settings = CefContext::Get()->settings();
if (CefColorGetA(settings.background_color) > 0) {
background_color = SkColorSetRGB(
CefColorGetR(settings.background_color),
CefColorGetG(settings.background_color),
CefColorGetB(settings.background_color));
}
CefWindowDelegateView* delegate_view =
new CefWindowDelegateView(background_color);
delegate_view->Init(window_info_.window,
web_contents(),
gfx::Rect(0, 0, cr.right, cr.bottom));