- cefclient: Add background-color command-line argument (issue #1161).

- Rename cef_url.h to cef_parser.h.
- Add new CefParseCSSColor function.
This commit is contained in:
Marshall Greenblatt
2015-04-09 16:59:34 +02:00
parent 2c03492160
commit ae91d8f4e5
33 changed files with 645 additions and 434 deletions

View File

@@ -913,10 +913,9 @@ class ScopedGLContext {
BrowserWindowOsrGtk::BrowserWindowOsrGtk(BrowserWindow::Delegate* delegate,
const std::string& startup_url,
bool transparent,
bool show_update_rect)
const OsrRenderer::Settings& settings)
: BrowserWindow(delegate),
renderer_(transparent, show_update_rect),
renderer_(settings),
glarea_(NULL),
hidden_(false),
gl_enabled_(false),

View File

@@ -22,8 +22,7 @@ class BrowserWindowOsrGtk : public BrowserWindow,
// |delegate| must outlive this object.
BrowserWindowOsrGtk(BrowserWindow::Delegate* delegate,
const std::string& startup_url,
bool transparent,
bool show_update_rect);
const OsrRenderer::Settings& settings);
// BrowserWindow methods.
void CreateBrowser(ClientWindowHandle parent_handle,

View File

@@ -22,8 +22,7 @@ class BrowserWindowOsrMac : public BrowserWindow,
// |delegate| must outlive this object.
BrowserWindowOsrMac(BrowserWindow::Delegate* delegate,
const std::string& startup_url,
bool transparent,
bool show_update_rect);
const OsrRenderer::Settings& settings);
~BrowserWindowOsrMac();
// BrowserWindow methods.

View File

@@ -9,7 +9,7 @@
#include <OpenGL/gl.h>
#include "include/base/cef_logging.h"
#include "include/cef_url.h"
#include "include/cef_parser.h"
#include "include/wrapper/cef_closure_task.h"
#include "cefclient/browser/bytes_write_handler.h"
#include "cefclient/browser/main_message_loop.h"
@@ -662,12 +662,22 @@ BrowserOpenGLView* GLView(NSView* view) {
}
- (void)drawRect: (NSRect) dirtyRect {
// The Invalidate below fixes flicker when resizing
if ([self inLiveResize]) {
CefRefPtr<CefBrowser> browser = [self getBrowser];
if (browser.get())
browser->GetHost()->Invalidate(PET_VIEW);
CefRefPtr<CefBrowser> browser = [self getBrowser];
if ([self inLiveResize] || !browser.get()) {
// Fill with the background color.
const cef_color_t background_color = renderer_->GetBackgroundColor();
NSColor* color =
[NSColor colorWithRed:float(CefColorGetR(background_color)) / 255.0f
green:float(CefColorGetG(background_color)) / 255.0f
blue:float(CefColorGetB(background_color)) / 255.0f
alpha:1.f];
[color setFill];
NSRectFill(dirtyRect);
}
// The Invalidate below fixes flicker when resizing.
if ([self inLiveResize] && browser.get())
browser->GetHost()->Invalidate(PET_VIEW);
}
// Drag and drop
@@ -1083,10 +1093,9 @@ namespace client {
BrowserWindowOsrMac::BrowserWindowOsrMac(BrowserWindow::Delegate* delegate,
const std::string& startup_url,
bool transparent,
bool show_update_rect)
const OsrRenderer::Settings& settings)
: BrowserWindow(delegate),
renderer_(transparent, show_update_rect),
renderer_(settings),
nsview_(NULL),
hidden_(false),
painting_popup_(false) {

View File

@@ -10,12 +10,11 @@ namespace client {
BrowserWindowOsrWin::BrowserWindowOsrWin(BrowserWindow::Delegate* delegate,
const std::string& startup_url,
bool transparent,
bool show_update_rect)
const OsrRenderer::Settings& settings)
: BrowserWindow(delegate),
transparent_(transparent),
transparent_(settings.transparent),
osr_hwnd_(NULL) {
osr_window_ = new OsrWindowWin(this, transparent, show_update_rect);
osr_window_ = new OsrWindowWin(this, settings);
client_handler_ = new ClientHandlerOsr(this, osr_window_.get(), startup_url);
}

View File

@@ -21,8 +21,7 @@ class BrowserWindowOsrWin : public BrowserWindow,
// |delegate| must outlive this object.
BrowserWindowOsrWin(BrowserWindow::Delegate* delegate,
const std::string& startup_url,
bool transparent,
bool show_update_rect);
const OsrRenderer::Settings& settings);
// BrowserWindow methods.
void CreateBrowser(ClientWindowHandle parent_handle,

View File

@@ -13,7 +13,7 @@
#include "include/base/cef_bind.h"
#include "include/cef_browser.h"
#include "include/cef_frame.h"
#include "include/cef_url.h"
#include "include/cef_parser.h"
#include "include/wrapper/cef_closure_task.h"
#include "cefclient/browser/main_context.h"
#include "cefclient/browser/resource_util.h"

View File

@@ -8,7 +8,7 @@
#include <sys/stat.h>
#include "include/cef_browser.h"
#include "include/cef_url.h"
#include "include/cef_parser.h"
#include "include/wrapper/cef_helpers.h"
#include "cefclient/browser/root_window.h"

View File

@@ -10,6 +10,7 @@
#include "include/base/cef_ref_counted.h"
#include "include/internal/cef_types_wrappers.h"
#include "cefclient/browser/osr_renderer.h"
namespace client {
@@ -33,10 +34,14 @@ class MainContext {
// Returns the main application URL.
virtual std::string GetMainURL() = 0;
// Returns the background color.
virtual cef_color_t GetBackgroundColor() = 0;
// Populate |settings| based on command-line arguments.
virtual void PopulateSettings(CefSettings* settings) = 0;
virtual void PopulateBrowserSettings(CefBrowserSettings* settings) = 0;
virtual void PopulateOsrSettings(OsrRenderer::Settings* settings) = 0;
// Returns the object used to create/manage RootWindow instances.
virtual RootWindowManager* GetRootWindowManager() = 0;

View File

@@ -4,6 +4,7 @@
#include "cefclient/browser/main_context_impl.h"
#include "include/cef_parser.h"
#include "cefclient/common/client_switches.h"
namespace client {
@@ -20,7 +21,8 @@ MainContextImpl::MainContextImpl(CefRefPtr<CefCommandLine> command_line,
: command_line_(command_line),
terminate_when_all_windows_closed_(terminate_when_all_windows_closed),
initialized_(false),
shutdown_(false) {
shutdown_(false),
background_color_(CefColorSetARGB(255, 255, 255, 255)) {
DCHECK(command_line_.get());
// Set the main URL.
@@ -28,6 +30,12 @@ MainContextImpl::MainContextImpl(CefRefPtr<CefCommandLine> command_line,
main_url_ = command_line_->GetSwitchValue(switches::kUrl);
if (main_url_.empty())
main_url_ = kDefaultUrl;
if (command_line_->HasSwitch(switches::kBackgroundColor)) {
// Parse the background color value.
CefParseCSSColor(command_line_->GetSwitchValue(switches::kBackgroundColor),
false, background_color_);
}
}
MainContextImpl::~MainContextImpl() {
@@ -44,6 +52,10 @@ std::string MainContextImpl::GetMainURL() {
return main_url_;
}
cef_color_t MainContextImpl::GetBackgroundColor() {
return background_color_;
}
void MainContextImpl::PopulateSettings(CefSettings* settings) {
#if defined(OS_WIN)
settings->multi_threaded_message_loop =
@@ -55,6 +67,8 @@ void MainContextImpl::PopulateSettings(CefSettings* settings) {
if (command_line_->HasSwitch(switches::kOffScreenRenderingEnabled))
settings->windowless_rendering_enabled = true;
settings->background_color = background_color_;
}
void MainContextImpl::PopulateBrowserSettings(CefBrowserSettings* settings) {
@@ -64,6 +78,14 @@ void MainContextImpl::PopulateBrowserSettings(CefBrowserSettings* settings) {
}
}
void MainContextImpl::PopulateOsrSettings(OsrRenderer::Settings* settings) {
settings->transparent =
command_line_->HasSwitch(switches::kTransparentPaintingEnabled);
settings->show_update_rect =
command_line_->HasSwitch(switches::kShowUpdateRect);
settings->background_color = background_color_;
}
RootWindowManager* MainContextImpl::GetRootWindowManager() {
DCHECK(InValidState());
return root_window_manager_.get();

View File

@@ -26,8 +26,10 @@ class MainContextImpl : public MainContext {
std::string GetDownloadPath(const std::string& file_name) OVERRIDE;
std::string GetAppWorkingDirectory() OVERRIDE;
std::string GetMainURL() OVERRIDE;
cef_color_t GetBackgroundColor() OVERRIDE;
void PopulateSettings(CefSettings* settings) OVERRIDE;
void PopulateBrowserSettings(CefBrowserSettings* settings) OVERRIDE;
void PopulateOsrSettings(OsrRenderer::Settings* settings) OVERRIDE;
RootWindowManager* GetRootWindowManager() OVERRIDE;
// Initialize CEF and associated main context state. This method must be
@@ -63,6 +65,7 @@ class MainContextImpl : public MainContext {
bool shutdown_;
std::string main_url_;
cef_color_t background_color_;
scoped_ptr<RootWindowManager> root_window_manager_;

View File

@@ -41,10 +41,14 @@
namespace client {
OsrRenderer::OsrRenderer(bool transparent,
bool show_update_rect)
: transparent_(transparent),
show_update_rect_(show_update_rect),
OsrRenderer::Settings::Settings()
: transparent(false),
show_update_rect(false),
background_color(CefColorSetARGB(255, 255, 255, 255)) {
}
OsrRenderer::OsrRenderer(const Settings& settings)
: settings_(settings),
initialized_(false),
texture_id_(0),
view_width_(0),
@@ -63,7 +67,10 @@ void OsrRenderer::Initialize() {
glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST); VERIFY_NO_ERROR;
glClearColor(0.0f, 0.0f, 0.0f, 1.0f); VERIFY_NO_ERROR;
glClearColor(float(CefColorGetR(settings_.background_color)) / 255.0f,
float(CefColorGetG(settings_.background_color)) / 255.0f,
float(CefColorGetB(settings_.background_color)) / 255.0f,
1.0f); VERIFY_NO_ERROR;
// Necessary for non-power-of-2 textures to render correctly.
glPixelStorei(GL_UNPACK_ALIGNMENT, 1); VERIFY_NO_ERROR;
@@ -134,7 +141,7 @@ void OsrRenderer::Render() {
glRotatef(-spin_y_, 0.0f, 1.0f, 0.0f); VERIFY_NO_ERROR;
}
if (transparent_) {
if (settings_.transparent) {
// Alpha blending style. Texture values have premultiplied alpha.
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); VERIFY_NO_ERROR;
@@ -154,13 +161,13 @@ void OsrRenderer::Render() {
// Disable 2D textures.
glDisable(GL_TEXTURE_2D); VERIFY_NO_ERROR;
if (transparent_) {
if (settings_.transparent) {
// Disable alpha blending.
glDisable(GL_BLEND); VERIFY_NO_ERROR;
}
// Draw a rectangle around the update region.
if (show_update_rect_ && !update_rect_.IsEmpty()) {
if (settings_.show_update_rect && !update_rect_.IsEmpty()) {
int left = update_rect_.x;
int right = update_rect_.x + update_rect_.width;
int top = update_rect_.y;
@@ -246,7 +253,7 @@ void OsrRenderer::OnPaint(CefRefPtr<CefBrowser> browser,
if (!initialized_)
Initialize();
if (transparent_) {
if (settings_.transparent) {
// Enable alpha blending.
glEnable(GL_BLEND); VERIFY_NO_ERROR;
}
@@ -264,7 +271,7 @@ void OsrRenderer::OnPaint(CefRefPtr<CefBrowser> browser,
view_width_ = width;
view_height_ = height;
if (show_update_rect_)
if (settings_.show_update_rect)
update_rect_ = dirtyRects[0];
glPixelStorei(GL_UNPACK_ROW_LENGTH, view_width_); VERIFY_NO_ERROR;
@@ -324,7 +331,7 @@ void OsrRenderer::OnPaint(CefRefPtr<CefBrowser> browser,
// Disable 2D textures.
glDisable(GL_TEXTURE_2D); VERIFY_NO_ERROR;
if (transparent_) {
if (settings_.transparent) {
// Disable alpha blending.
glDisable(GL_BLEND); VERIFY_NO_ERROR;
}

View File

@@ -13,8 +13,20 @@ namespace client {
class OsrRenderer {
public:
OsrRenderer(bool transparent,
bool show_update_rect);
struct Settings {
Settings();
// If true use transparent rendering.
bool transparent;
// If true draw a border around update rectangles.
bool show_update_rect;
// Background color.
cef_color_t background_color;
};
explicit OsrRenderer(const Settings& settings);
~OsrRenderer();
// Initialize the OpenGL environment.
@@ -41,10 +53,11 @@ class OsrRenderer {
void SetSpin(float spinX, float spinY);
void IncrementSpin(float spinDX, float spinDY);
bool IsTransparent() { return transparent_; }
bool IsTransparent() const { return settings_.transparent; }
cef_color_t GetBackgroundColor() const { return settings_.background_color; }
int GetViewWidth() { return view_width_; }
int GetViewHeight() { return view_height_; }
int GetViewWidth() const { return view_width_; }
int GetViewHeight() const { return view_height_; }
const CefRect& popup_rect() const { return popup_rect_; }
const CefRect& original_popup_rect() const { return original_popup_rect_; }
@@ -53,8 +66,7 @@ class OsrRenderer {
void ClearPopupRects();
private:
const bool transparent_;
const bool show_update_rect_;
const Settings settings_;
bool initialized_;
unsigned int texture_id_;
int view_width_;

View File

@@ -48,10 +48,9 @@ class ScopedGLContext {
OsrWindowWin::OsrWindowWin(Delegate* delegate,
bool transparent,
bool show_update_rect)
const OsrRenderer::Settings& settings)
: delegate_(delegate),
renderer_(transparent, show_update_rect),
renderer_(settings),
hwnd_(NULL),
hdc_(NULL),
hrc_(NULL),
@@ -208,7 +207,13 @@ void OsrWindowWin::Create(HWND parent_hwnd, const RECT& rect) {
HINSTANCE hInst = ::GetModuleHandle(NULL);
RegisterOsrClass(hInst);
const cef_color_t background_color = renderer_.GetBackgroundColor();
const HBRUSH background_brush = CreateSolidBrush(
RGB(CefColorGetR(background_color),
CefColorGetG(background_color),
CefColorGetB(background_color)));
RegisterOsrClass(hInst, background_brush);
// Create the native window with a border so it's easier to visually identify
// OSR windows.
@@ -339,7 +344,8 @@ void OsrWindowWin::NotifyNativeWindowCreated(HWND hwnd) {
}
// static
void OsrWindowWin::RegisterOsrClass(HINSTANCE hInstance) {
void OsrWindowWin::RegisterOsrClass(HINSTANCE hInstance,
HBRUSH background_brush) {
// Only register the class one time.
static bool class_registered = false;
if (class_registered)
@@ -356,7 +362,7 @@ void OsrWindowWin::RegisterOsrClass(HINSTANCE hInstance) {
wcex.hInstance = hInstance;
wcex.hIcon = NULL;
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wcex.hbrBackground = background_brush;
wcex.lpszMenuName = NULL;
wcex.lpszClassName = kWndClass;
wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
@@ -383,25 +389,21 @@ LRESULT CALLBACK OsrWindowWin::OsrWndProc(HWND hWnd, UINT message,
case WM_MOUSEMOVE:
case WM_MOUSELEAVE:
case WM_MOUSEWHEEL:
if (self)
self->OnMouseEvent(message, wParam, lParam);
self->OnMouseEvent(message, wParam, lParam);
break;
case WM_SIZE:
if (self)
self->OnSize();
self->OnSize();
break;
case WM_SETFOCUS:
case WM_KILLFOCUS:
if (self)
self->OnFocus(message == WM_SETFOCUS);
self->OnFocus(message == WM_SETFOCUS);
break;
case WM_CAPTURECHANGED:
case WM_CANCELMODE:
if (self)
self->OnCaptureLost();
self->OnCaptureLost();
break;
case WM_SYSCHAR:
@@ -410,17 +412,17 @@ LRESULT CALLBACK OsrWindowWin::OsrWndProc(HWND hWnd, UINT message,
case WM_KEYDOWN:
case WM_KEYUP:
case WM_CHAR:
if (self)
self->OnKeyEvent(message, wParam, lParam);
self->OnKeyEvent(message, wParam, lParam);
break;
case WM_PAINT:
if (self)
self->OnPaint();
self->OnPaint();
return 0;
case WM_ERASEBKGND:
// Never erase the background.
if (self->OnEraseBkgnd())
break;
// Don't erase the background.
return 0;
case WM_NCDESTROY:
@@ -674,6 +676,11 @@ void OsrWindowWin::OnPaint() {
browser_->GetHost()->Invalidate(PET_VIEW);
}
bool OsrWindowWin::OnEraseBkgnd() {
// Erase the background when the browser does not exist.
return (browser_ == NULL);
}
bool OsrWindowWin::IsOverPopupWidget(int x, int y) const {
CEF_REQUIRE_UI_THREAD();
const CefRect& rc = renderer_.popup_rect();

View File

@@ -40,8 +40,7 @@ class OsrWindowWin :
// |delegate| must outlive this object.
OsrWindowWin(Delegate* delegate,
bool transparent,
bool show_update_rect);
const OsrRenderer::Settings& settings);
// Create a new browser and native window.
void CreateBrowser(HWND parent_hwnd,
@@ -80,7 +79,8 @@ class OsrWindowWin :
void NotifyNativeWindowCreated(HWND hwnd);
static void RegisterOsrClass(HINSTANCE hInstance);
static void RegisterOsrClass(HINSTANCE hInstance,
HBRUSH background_brush);
static LRESULT CALLBACK OsrWndProc(HWND hWnd, UINT message, WPARAM wParam,
LPARAM lParam);
@@ -91,6 +91,7 @@ class OsrWindowWin :
void OnCaptureLost();
void OnKeyEvent(UINT message, WPARAM wParam, LPARAM lParam);
void OnPaint();
bool OnEraseBkgnd();
// Manage popup bounds.
bool IsOverPopupWidget(int x, int y) const;

View File

@@ -15,6 +15,7 @@
#include "include/cef_app.h"
#include "cefclient/browser/browser_window_osr_gtk.h"
#include "cefclient/browser/browser_window_std_gtk.h"
#include "cefclient/browser/main_context.h"
#include "cefclient/browser/main_message_loop.h"
#include "cefclient/browser/resource.h"
#include "cefclient/browser/temp_window.h"
@@ -205,15 +206,9 @@ ClientWindowHandle RootWindowGtk::GetWindowHandle() const {
void RootWindowGtk::CreateBrowserWindow(const std::string& startup_url) {
if (with_osr_) {
CefRefPtr<CefCommandLine> command_line =
CefCommandLine::GetGlobalCommandLine();
const bool transparent =
command_line->HasSwitch(switches::kTransparentPaintingEnabled);
const bool show_update_rect =
command_line->HasSwitch(switches::kShowUpdateRect);
browser_window_.reset(new BrowserWindowOsrGtk(this, startup_url,
transparent,
show_update_rect));
OsrRenderer::Settings settings;
MainContext::Get()->PopulateOsrSettings(&settings);
browser_window_.reset(new BrowserWindowOsrGtk(this, startup_url, settings));
} else {
browser_window_.reset(new BrowserWindowStdGtk(this, startup_url));
}
@@ -250,6 +245,13 @@ void RootWindowGtk::CreateRootWindow(const CefBrowserSettings& settings) {
g_signal_connect(G_OBJECT(window_), "delete_event",
G_CALLBACK(&RootWindowGtk::WindowDelete), this);
const cef_color_t background_color = MainContext::Get()->GetBackgroundColor();
GdkColor color = {0};
color.red = CefColorGetR(background_color) * 65535 / 255;
color.green = CefColorGetG(background_color) * 65535 / 255;
color.blue = CefColorGetB(background_color) * 65535 / 255;
gtk_widget_modify_bg(window_, GTK_STATE_NORMAL, &color);
GtkWidget* vbox = gtk_vbox_new(FALSE, 0);
g_signal_connect(vbox, "size-allocate",
G_CALLBACK(&RootWindowGtk::VboxSizeAllocated), this);

View File

@@ -9,6 +9,7 @@
#include "include/cef_application_mac.h"
#include "cefclient/browser/browser_window_osr_mac.h"
#include "cefclient/browser/browser_window_std_mac.h"
#include "cefclient/browser/main_context.h"
#include "cefclient/browser/main_message_loop.h"
#include "cefclient/browser/temp_window.h"
#include "cefclient/common/client_switches.h"
@@ -414,15 +415,9 @@ void RootWindowMac::WindowDestroyed() {
void RootWindowMac::CreateBrowserWindow(const std::string& startup_url) {
if (with_osr_) {
CefRefPtr<CefCommandLine> command_line =
CefCommandLine::GetGlobalCommandLine();
const bool transparent =
command_line->HasSwitch(switches::kTransparentPaintingEnabled);
const bool show_update_rect =
command_line->HasSwitch(switches::kShowUpdateRect);
browser_window_.reset(new BrowserWindowOsrMac(this, startup_url,
transparent,
show_update_rect));
OsrRenderer::Settings settings;
MainContext::Get()->PopulateOsrSettings(&settings);
browser_window_.reset(new BrowserWindowOsrMac(this, startup_url, settings));
} else {
browser_window_.reset(new BrowserWindowStdMac(this, startup_url));
}
@@ -470,6 +465,13 @@ void RootWindowMac::CreateRootWindow(const CefBrowserSettings& settings) {
// during cleanup (ie, a window close from javascript).
[window_ setReleasedWhenClosed:NO];
const cef_color_t background_color = MainContext::Get()->GetBackgroundColor();
[window_ setBackgroundColor:
[NSColor colorWithRed:float(CefColorGetR(background_color)) / 255.0f
green:float(CefColorGetG(background_color)) / 255.0f
blue:float(CefColorGetB(background_color)) / 255.0f
alpha:1.f]];
NSView* contentView = [window_ contentView];
NSRect contentBounds = [contentView bounds];

View File

@@ -8,6 +8,7 @@
#include "include/cef_app.h"
#include "cefclient/browser/browser_window_osr_win.h"
#include "cefclient/browser/browser_window_std_win.h"
#include "cefclient/browser/main_context.h"
#include "cefclient/browser/main_message_loop.h"
#include "cefclient/browser/resource.h"
#include "cefclient/browser/temp_window.h"
@@ -201,15 +202,9 @@ ClientWindowHandle RootWindowWin::GetWindowHandle() const {
void RootWindowWin::CreateBrowserWindow(bool with_osr,
const std::string& startup_url) {
if (with_osr) {
CefRefPtr<CefCommandLine> command_line =
CefCommandLine::GetGlobalCommandLine();
const bool transparent =
command_line->HasSwitch(switches::kTransparentPaintingEnabled);
const bool show_update_rect =
command_line->HasSwitch(switches::kShowUpdateRect);
browser_window_.reset(new BrowserWindowOsrWin(this, startup_url,
transparent,
show_update_rect));
OsrRenderer::Settings settings;
MainContext::Get()->PopulateOsrSettings(&settings);
browser_window_.reset(new BrowserWindowOsrWin(this, startup_url, settings));
} else {
browser_window_.reset(new BrowserWindowStdWin(this, startup_url));
}
@@ -225,8 +220,14 @@ void RootWindowWin::CreateRootWindow(const CefBrowserSettings& settings) {
const std::wstring& window_title = GetResourceString(IDS_APP_TITLE);
const std::wstring& window_class = GetResourceString(IDC_CEFCLIENT);
const cef_color_t background_color = MainContext::Get()->GetBackgroundColor();
const HBRUSH background_brush = CreateSolidBrush(
RGB(CefColorGetR(background_color),
CefColorGetG(background_color),
CefColorGetB(background_color)));
// Register the window class.
RegisterRootClass(hInstance, window_class);
RegisterRootClass(hInstance, window_class, background_brush);
// Register the message used with the find dialog.
find_message_id_ = RegisterWindowMessage(FINDMSGSTRING);
@@ -342,7 +343,8 @@ void RootWindowWin::CreateRootWindow(const CefBrowserSettings& settings) {
// static
void RootWindowWin::RegisterRootClass(HINSTANCE hInstance,
const std::wstring& window_class) {
const std::wstring& window_class,
HBRUSH background_brush) {
// Only register the class one time.
static bool class_registered = false;
if (class_registered)
@@ -360,7 +362,7 @@ void RootWindowWin::RegisterRootClass(HINSTANCE hInstance,
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_CEFCLIENT));
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.hbrBackground = background_brush;
wcex.lpszMenuName = MAKEINTRESOURCE(IDC_CEFCLIENT);
wcex.lpszClassName = window_class.c_str();
wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
@@ -472,7 +474,9 @@ LRESULT CALLBACK RootWindowWin::RootWndProc(HWND hWnd, UINT message,
return 0;
case WM_ERASEBKGND:
// Never erase the background.
if (self->OnEraseBkgnd())
break;
// Don't erase the background.
return 0;
case WM_ENTERMENULOOP:
@@ -563,6 +567,11 @@ void RootWindowWin::OnMove() {
browser->GetHost()->NotifyMoveOrResizeStarted();
}
bool RootWindowWin::OnEraseBkgnd() {
// Erase the background when the browser does not exist.
return (GetBrowser() == NULL);
}
bool RootWindowWin::OnCommand(UINT id) {
if (id >= ID_TESTS_FIRST && id <= ID_TESTS_LAST) {
delegate_->OnTest(this, id);

View File

@@ -54,7 +54,8 @@ class RootWindowWin : public RootWindow,
// Register the root window class.
static void RegisterRootClass(HINSTANCE hInstance,
const std::wstring& window_class);
const std::wstring& window_class,
HBRUSH background_brush);
// Window procedure for the edit field.
static LRESULT CALLBACK EditWndProc(HWND hWnd, UINT message, WPARAM wParam,
@@ -73,6 +74,7 @@ class RootWindowWin : public RootWindow,
void OnFocus();
void OnSize(bool minimized);
void OnMove();
bool OnEraseBkgnd();
bool OnCommand(UINT id);
void OnFind();
void OnFindEvent();

View File

@@ -7,9 +7,9 @@
#include <sstream>
#include "include/base/cef_bind.h"
#include "include/cef_parser.h"
#include "include/cef_task.h"
#include "include/cef_trace.h"
#include "include/cef_url.h"
#include "include/cef_web_plugin.h"
#include "include/wrapper/cef_closure_task.h"
#include "include/wrapper/cef_stream_resource_handler.h"

View File

@@ -26,6 +26,7 @@ const char kTransparentPaintingEnabled[] = "transparent-painting-enabled";
const char kShowUpdateRect[] = "show-update-rect";
const char kMouseCursorChangeDisabled[] = "mouse-cursor-change-disabled";
const char kRequestContextPerBrowser[] = "request-context-per-browser";
const char kBackgroundColor[] = "background-color";
} // namespace switches
} // namespace client

View File

@@ -20,6 +20,7 @@ extern const char kTransparentPaintingEnabled[];
extern const char kShowUpdateRect[];
extern const char kMouseCursorChangeDisabled[];
extern const char kRequestContextPerBrowser[];
extern const char kBackgroundColor[];
} // namespace switches
} // namespace client

View File

@@ -5,11 +5,11 @@
// Include this first to avoid type conflicts with CEF headers.
#include "tests/unittests/chromium_includes.h"
#include "include/cef_url.h"
#include "include/cef_parser.h"
#include "testing/gtest/include/gtest/gtest.h"
// Create the URL using the spec.
TEST(URLTest, CreateURLSpec) {
TEST(ParserTest, CreateURLSpec) {
CefURLParts parts;
CefString url;
CefString(&parts.spec).FromASCII(
@@ -21,7 +21,7 @@ TEST(URLTest, CreateURLSpec) {
}
// Test that host is required.
TEST(URLTest, CreateURLHostRequired) {
TEST(ParserTest, CreateURLHostRequired) {
CefURLParts parts;
CefString url;
CefString(&parts.scheme).FromASCII("http");
@@ -29,7 +29,7 @@ TEST(URLTest, CreateURLHostRequired) {
}
// Test that scheme is required.
TEST(URLTest, CreateURLSchemeRequired) {
TEST(ParserTest, CreateURLSchemeRequired) {
CefURLParts parts;
CefString url;
CefString(&parts.host).FromASCII("www.example.com");
@@ -37,7 +37,7 @@ TEST(URLTest, CreateURLSchemeRequired) {
}
// Create the URL using scheme and host.
TEST(URLTest, CreateURLSchemeHost) {
TEST(ParserTest, CreateURLSchemeHost) {
CefURLParts parts;
CefString url;
CefString(&parts.scheme).FromASCII("http");
@@ -47,7 +47,7 @@ TEST(URLTest, CreateURLSchemeHost) {
}
// Create the URL using scheme, host and path.
TEST(URLTest, CreateURLSchemeHostPath) {
TEST(ParserTest, CreateURLSchemeHostPath) {
CefURLParts parts;
CefString url;
CefString(&parts.scheme).FromASCII("http");
@@ -58,7 +58,7 @@ TEST(URLTest, CreateURLSchemeHostPath) {
}
// Create the URL using scheme, host, path and query.
TEST(URLTest, CreateURLSchemeHostPathQuery) {
TEST(ParserTest, CreateURLSchemeHostPathQuery) {
CefURLParts parts;
CefString url;
CefString(&parts.scheme).FromASCII("http");
@@ -71,7 +71,7 @@ TEST(URLTest, CreateURLSchemeHostPathQuery) {
}
// Create the URL using all the various components.
TEST(URLTest, CreateURLAll) {
TEST(ParserTest, CreateURLAll) {
CefURLParts parts;
CefString url;
CefString(&parts.scheme).FromASCII("http");
@@ -88,7 +88,7 @@ TEST(URLTest, CreateURLAll) {
}
// Parse the URL using scheme and host.
TEST(URLTest, ParseURLSchemeHost) {
TEST(ParserTest, ParseURLSchemeHost) {
CefURLParts parts;
CefString url;
url.FromASCII("http://www.example.com");
@@ -111,7 +111,7 @@ TEST(URLTest, ParseURLSchemeHost) {
}
// Parse the URL using scheme, host and path.
TEST(URLTest, ParseURLSchemeHostPath) {
TEST(ParserTest, ParseURLSchemeHostPath) {
CefURLParts parts;
CefString url;
url.FromASCII("http://www.example.com/path/to.html");
@@ -135,7 +135,7 @@ TEST(URLTest, ParseURLSchemeHostPath) {
}
// Parse the URL using scheme, host, path and query.
TEST(URLTest, ParseURLSchemeHostPathQuery) {
TEST(ParserTest, ParseURLSchemeHostPathQuery) {
CefURLParts parts;
CefString url;
url.FromASCII("http://www.example.com/path/to.html?foo=test&bar=test2");
@@ -160,7 +160,7 @@ TEST(URLTest, ParseURLSchemeHostPathQuery) {
}
// Parse the URL using all the various components.
TEST(URLTest, ParseURLAll) {
TEST(ParserTest, ParseURLAll) {
CefURLParts parts;
CefString url;
url.FromASCII(
@@ -190,7 +190,7 @@ TEST(URLTest, ParseURLAll) {
}
// Parse an invalid URL.
TEST(URLTest, ParseURLInvalid) {
TEST(ParserTest, ParseURLInvalid) {
CefURLParts parts;
CefString url;
url.FromASCII("www.example.com");
@@ -198,7 +198,7 @@ TEST(URLTest, ParseURLInvalid) {
}
// Parse a non-standard scheme.
TEST(URLTest, ParseURLNonStandard) {
TEST(ParserTest, ParseURLNonStandard) {
CefURLParts parts;
CefString url;
url.FromASCII("custom:something%20else?foo");
@@ -219,7 +219,7 @@ TEST(URLTest, ParseURLNonStandard) {
EXPECT_STREQ("foo", query.ToString().c_str());
}
TEST(URLTest, GetMimeType) {
TEST(ParserTest, GetMimeType) {
CefString mime_type;
mime_type = CefGetMimeType("html");
@@ -232,7 +232,7 @@ TEST(URLTest, GetMimeType) {
EXPECT_STREQ("image/gif", mime_type.ToString().c_str());
}
TEST(URLTest, Base64Encode) {
TEST(ParserTest, Base64Encode) {
const std::string& test_str_decoded = "A test string";
const std::string& test_str_encoded = "QSB0ZXN0IHN0cmluZw==";
const CefString& encoded_value =
@@ -240,7 +240,7 @@ TEST(URLTest, Base64Encode) {
EXPECT_STREQ(test_str_encoded.c_str(), encoded_value.ToString().c_str());
}
TEST(URLTest, Base64Decode) {
TEST(ParserTest, Base64Decode) {
const std::string& test_str_decoded = "A test string";
const std::string& test_str_encoded = "QSB0ZXN0IHN0cmluZw==";
CefRefPtr<CefBinaryValue> decoded_value = CefBase64Decode(test_str_encoded);
@@ -258,14 +258,14 @@ TEST(URLTest, Base64Decode) {
EXPECT_STREQ(test_str_decoded.c_str(), decoded_str.c_str());
}
TEST(URLTest, URIEncode) {
TEST(ParserTest, URIEncode) {
const std::string& test_str_decoded = "A test string=";
const std::string& test_str_encoded = "A%20test%20string%3D";
const CefString& encoded_value = CefURIEncode(test_str_decoded, false);
EXPECT_STREQ(test_str_encoded.c_str(), encoded_value.ToString().c_str());
}
TEST(URLTest, URIDecode) {
TEST(ParserTest, URIDecode) {
const std::string& test_str_decoded = "A test string=";
const std::string& test_str_encoded = "A%20test%20string%3D";
const CefString& decoded_value =
@@ -274,3 +274,38 @@ TEST(URLTest, URIDecode) {
UU_SPACES | UU_URL_SPECIAL_CHARS));
EXPECT_STREQ(test_str_decoded.c_str(), decoded_value.ToString().c_str());
}
TEST(ParserTest, ParseCSSColor) {
std::string value;
cef_color_t color;
// Color by name.
value = "red";
color = 0;
EXPECT_TRUE(CefParseCSSColor(value, false, color));
EXPECT_EQ(CefColorSetARGB(255, 255, 0, 0), color);
// Color by RGB.
value = "rgb(1,2,3)";
color = 0;
EXPECT_TRUE(CefParseCSSColor(value, false, color));
EXPECT_EQ(CefColorSetARGB(255, 1, 2, 3), color);
// Color by RGBA.
value = "rgba(1,2,3,0.0)";
color = 0;
EXPECT_TRUE(CefParseCSSColor(value, false, color));
EXPECT_EQ(CefColorSetARGB(0, 1, 2, 3), color);
// Color by hex code.
value = "#FFAACC";
color = 0;
EXPECT_TRUE(CefParseCSSColor(value, false, color));
EXPECT_EQ(CefColorSetARGB(255, 0xFF, 0xAA, 0xCC), color);
// Invalid color.
value = "not_a_color";
color = 0;
EXPECT_FALSE(CefParseCSSColor(value, false, color));
EXPECT_EQ(0U, color);
}