From 6912a0513a5c7ddbff34d77ff66f71ae79c22c23 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 15 Jan 2014 14:31:26 +0000 Subject: [PATCH] gtk: Set WebKit's style from current theme. --- browser/native_window_gtk.cc | 41 ++++++++++++++++++++++++++++++++++++ browser/native_window_gtk.h | 3 +++ 2 files changed, 44 insertions(+) diff --git a/browser/native_window_gtk.cc b/browser/native_window_gtk.cc index d063d1ee01..9b73882023 100644 --- a/browser/native_window_gtk.cc +++ b/browser/native_window_gtk.cc @@ -8,10 +8,20 @@ #include "common/options_switches.h" #include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents_view.h" +#include "ui/gfx/gtk_util.h" #include "ui/gfx/rect.h" namespace atom { +namespace { + +// Dividing GTK's cursor blink cycle time (in milliseconds) by this value yields +// an appropriate value for content::RendererPreferences::caret_blink_interval. +// This matches the logic in the WebKit GTK port. +const double kGtkCursorBlinkCycleFactor = 2000.0; + +} // namespace + NativeWindowGtk::NativeWindowGtk(content::WebContents* web_contents, base::DictionaryValue* options) : NativeWindow(web_contents, options), @@ -34,6 +44,8 @@ NativeWindowGtk::NativeWindowGtk(content::WebContents* web_contents, g_signal_connect(window_, "delete-event", G_CALLBACK(OnWindowDeleteEventThunk), this); + + SetWebKitColorStyle(); } NativeWindowGtk::~NativeWindowGtk() { @@ -224,6 +236,35 @@ void NativeWindowGtk::UpdateDraggableRegions( const std::vector& regions) { } +void NativeWindowGtk::SetWebKitColorStyle() { + content::RendererPreferences* prefs = + GetWebContents()->GetMutableRendererPrefs(); + GtkStyle* frame_style = gtk_rc_get_style(GTK_WIDGET(window_)); + prefs->focus_ring_color = + gfx::GdkColorToSkColor(frame_style->bg[GTK_STATE_SELECTED]); + prefs->thumb_active_color = SkColorSetRGB(244, 244, 244); + prefs->thumb_inactive_color = SkColorSetRGB(234, 234, 234); + prefs->track_color = SkColorSetRGB(211, 211, 211); + + GtkWidget* url_entry = gtk_entry_new(); + GtkStyle* entry_style = gtk_rc_get_style(url_entry); + prefs->active_selection_bg_color = + gfx::GdkColorToSkColor(entry_style->base[GTK_STATE_SELECTED]); + prefs->active_selection_fg_color = + gfx::GdkColorToSkColor(entry_style->text[GTK_STATE_SELECTED]); + prefs->inactive_selection_bg_color = + gfx::GdkColorToSkColor(entry_style->base[GTK_STATE_ACTIVE]); + prefs->inactive_selection_fg_color = + gfx::GdkColorToSkColor(entry_style->text[GTK_STATE_ACTIVE]); + gtk_widget_destroy(url_entry); + + const base::TimeDelta cursor_blink_time = gfx::GetCursorBlinkCycle(); + prefs->caret_blink_interval = + cursor_blink_time.InMilliseconds() ? + cursor_blink_time.InMilliseconds() / kGtkCursorBlinkCycleFactor : + 0; +} + gboolean NativeWindowGtk::OnWindowDeleteEvent(GtkWidget* widget, GdkEvent* event) { Close(); diff --git a/browser/native_window_gtk.h b/browser/native_window_gtk.h index 70a855d036..553d13116a 100644 --- a/browser/native_window_gtk.h +++ b/browser/native_window_gtk.h @@ -60,6 +60,9 @@ class NativeWindowGtk : public NativeWindow { const std::vector& regions) OVERRIDE; private: + // Set WebKit's style from current theme. + void SetWebKitColorStyle(); + CHROMEGTK_CALLBACK_1(NativeWindowGtk, gboolean, OnWindowDeleteEvent, GdkEvent*);