From b479cb3aa36c4fabbdb7c406610f4018632731e3 Mon Sep 17 00:00:00 2001 From: Marshall Greenblatt Date: Tue, 7 Jan 2014 18:04:31 +0000 Subject: [PATCH] Windows: Allow customization of background color (issue #1161). git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@1559 5089003a-bbd8-11dd-ad1f-f1f9622dbc98 --- include/internal/cef_types.h | 29 +++++++++++++++++++++++++ include/internal/cef_types_wrappers.h | 1 + libcef/browser/browser_host_impl_win.cc | 22 +++++++++++++++---- 3 files changed, 48 insertions(+), 4 deletions(-) diff --git a/include/internal/cef_types.h b/include/internal/cef_types.h index aa5eecfdd..379dab5ed 100644 --- a/include/internal/cef_types.h +++ b/include/internal/cef_types.h @@ -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( \ + (static_cast(a) << 24) | \ + (static_cast(r) << 16) | \ + (static_cast(g) << 8) | \ + (static_cast(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; /// diff --git a/include/internal/cef_types_wrappers.h b/include/internal/cef_types_wrappers.h index 6c672ffe2..160a73693 100644 --- a/include/internal/cef_types_wrappers.h +++ b/include/internal/cef_types_wrappers.h @@ -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; } }; diff --git a/libcef/browser/browser_host_impl_win.cc b/libcef/browser/browser_host_impl_win.cc index 47430de2d..f386fdf92 100644 --- a/libcef/browser/browser_host_impl_win.cc +++ b/libcef/browser/browser_host_impl_win.cc @@ -12,6 +12,7 @@ #include #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));