]> khamidou — GitHub mirrors - electron.git/commitdiff
gtk: Set WebKit's style from current theme.
authorCheng Zhao <zcbenz@gmail.com>
Wed, 15 Jan 2014 14:31:26 +0000 (14:31 +0000)
committerCheng Zhao <zcbenz@gmail.com>
Wed, 15 Jan 2014 14:31:26 +0000 (14:31 +0000)
browser/native_window_gtk.cc
browser/native_window_gtk.h

index d063d1ee015dc7c060b0717fdf897a5f93bc31c7..9b73882023090ca35d01ac07bbece66cfe9e7820 100644 (file)
@@ -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<DraggableRegion>& 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();
index 70a855d0360676e6d452a66f1a36a202d63ffad5..553d13116a41fef37dbcd4fed3f4fd4ea60d3415 100644 (file)
@@ -60,6 +60,9 @@ class NativeWindowGtk : public NativeWindow {
       const std::vector<DraggableRegion>& regions) OVERRIDE;
 
  private:
+  // Set WebKit's style from current theme.
+  void SetWebKitColorStyle();
+
   CHROMEGTK_CALLBACK_1(NativeWindowGtk, gboolean, OnWindowDeleteEvent,
                        GdkEvent*);