summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorerg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-27 01:03:10 +0000
committererg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-27 01:03:10 +0000
commit644d77efccd8242e1977ed5e35398b0966026873 (patch)
tree01f6e0efa342ff8b2c09b469636e6df00b84dae5
parent3236cbe0edcbedef5d1ea689c48e19a714ab6ccb (diff)
downloadchromium_src-644d77efccd8242e1977ed5e35398b0966026873.zip
chromium_src-644d77efccd8242e1977ed5e35398b0966026873.tar.gz
chromium_src-644d77efccd8242e1977ed5e35398b0966026873.tar.bz2
GTK: Use GTK+ theme selection colors and plumb them into webkit. [Chromium side of patch]
BUG=25831 TEST=none Review URL: http://codereview.chromium.org/554004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@37193 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/gtk/gtk_theme_provider.cc35
-rw-r--r--chrome/browser/gtk/gtk_theme_provider.h16
-rw-r--r--chrome/browser/renderer_preferences_util.cc6
-rw-r--r--chrome/common/render_messages.h16
-rw-r--r--chrome/common/renderer_preferences.h10
-rw-r--r--chrome/renderer/render_view.cc8
-rw-r--r--webkit/data/layout_tests/LayoutTests/fast/linux_selection_color.html21
-rw-r--r--webkit/data/layout_tests/platform/chromium-linux/LayoutTests/linux_selection_color-expected.checksum1
-rw-r--r--webkit/data/layout_tests/platform/chromium-linux/LayoutTests/linux_selection_color-expected.pngbin0 -> 9207 bytes
-rw-r--r--webkit/data/layout_tests/platform/chromium-linux/LayoutTests/linux_selection_color-expected.txt14
-rw-r--r--webkit/tools/test_shell/layout_test_controller.cc14
-rw-r--r--webkit/tools/test_shell/layout_test_controller.h4
12 files changed, 134 insertions, 11 deletions
diff --git a/chrome/browser/gtk/gtk_theme_provider.cc b/chrome/browser/gtk/gtk_theme_provider.cc
index c6cf09d..48353ec0 100644
--- a/chrome/browser/gtk/gtk_theme_provider.cc
+++ b/chrome/browser/gtk/gtk_theme_provider.cc
@@ -552,15 +552,6 @@ void GtkThemeProvider::LoadGtkValues() {
SetTintToExactColor(BrowserThemeProvider::TINT_FRAME_INCOGNITO_INACTIVE,
&inactive_frame_color);
- focus_ring_color_ = GdkToSkColor(&button_color);
- GdkColor thumb_active_color, thumb_inactive_color, track_color;
- GtkThemeProvider::GetScrollbarColors(&thumb_active_color,
- &thumb_inactive_color,
- &track_color);
- thumb_active_color_ = GdkToSkColor(&thumb_active_color);
- thumb_inactive_color_ = GdkToSkColor(&thumb_inactive_color);
- track_color_ = GdkToSkColor(&track_color);
-
// We pick the text and background colors for the NTP out of the colors for a
// GtkEntry. We do this because GtkEntries background color is never the same
// as |toolbar_color|, is usually a white, and when it isn't a white,
@@ -601,6 +592,27 @@ void GtkThemeProvider::LoadGtkValues() {
link_color);
SetThemeColorFromGtk(BrowserThemeProvider::COLOR_NTP_SECTION_LINK_UNDERLINE,
link_color);
+
+ // Generate the colors that we pass to WebKit.
+ focus_ring_color_ = GdkToSkColor(&button_color);
+ GdkColor thumb_active_color, thumb_inactive_color, track_color;
+ GtkThemeProvider::GetScrollbarColors(&thumb_active_color,
+ &thumb_inactive_color,
+ &track_color);
+ thumb_active_color_ = GdkToSkColor(&thumb_active_color);
+ thumb_inactive_color_ = GdkToSkColor(&thumb_inactive_color);
+ track_color_ = GdkToSkColor(&track_color);
+
+ // Some GTK themes only define the text selection colors on the GtkEntry
+ // class, so we need to use that for getting selection colors.
+ active_selection_bg_color_ =
+ GdkToSkColor(&entry_style->base[GTK_STATE_SELECTED]);
+ active_selection_fg_color_ =
+ GdkToSkColor(&entry_style->text[GTK_STATE_SELECTED]);
+ inactive_selection_bg_color_ =
+ GdkToSkColor(&entry_style->base[GTK_STATE_ACTIVE]);
+ inactive_selection_fg_color_ =
+ GdkToSkColor(&entry_style->text[GTK_STATE_ACTIVE]);
}
GtkStyle* GtkThemeProvider::GetFrameStyle() {
@@ -622,6 +634,11 @@ void GtkThemeProvider::LoadDefaultValues() {
thumb_active_color_ = SkColorSetRGB(250, 248, 245);
thumb_inactive_color_ = SkColorSetRGB(240, 235, 229);
track_color_ = SkColorSetRGB(227, 221, 216);
+
+ active_selection_bg_color_ = SkColorSetRGB(30, 144, 255);
+ active_selection_fg_color_ = SK_ColorBLACK;
+ inactive_selection_bg_color_ = SkColorSetRGB(200, 200, 200);
+ inactive_selection_fg_color_ = SkColorSetRGB(50, 50, 50);
}
void GtkThemeProvider::SetThemeColorFromGtk(int id, const GdkColor* color) {
diff --git a/chrome/browser/gtk/gtk_theme_provider.h b/chrome/browser/gtk/gtk_theme_provider.h
index db396ab..919c522 100644
--- a/chrome/browser/gtk/gtk_theme_provider.h
+++ b/chrome/browser/gtk/gtk_theme_provider.h
@@ -89,6 +89,18 @@ class GtkThemeProvider : public BrowserThemeProvider,
return thumb_inactive_color_;
}
const SkColor& get_track_color() const { return track_color_; }
+ const SkColor& get_active_selection_bg_color() const {
+ return active_selection_bg_color_;
+ }
+ const SkColor& get_active_selection_fg_color() const {
+ return active_selection_fg_color_;
+ }
+ const SkColor& get_inactive_selection_bg_color() const {
+ return inactive_selection_bg_color_;
+ }
+ const SkColor& get_inactive_selection_fg_color() const {
+ return inactive_selection_fg_color_;
+ }
// These functions do not add a ref to the returned pixbuf, and it should not
// be unreffed. If |native| is true, get the GTK_STOCK version of the icon.
@@ -180,6 +192,10 @@ class GtkThemeProvider : public BrowserThemeProvider,
SkColor thumb_active_color_;
SkColor thumb_inactive_color_;
SkColor track_color_;
+ SkColor active_selection_bg_color_;
+ SkColor active_selection_fg_color_;
+ SkColor inactive_selection_bg_color_;
+ SkColor inactive_selection_fg_color_;
// Image cache of lazily created images, created when requested by
// GetBitmapNamed().
diff --git a/chrome/browser/renderer_preferences_util.cc b/chrome/browser/renderer_preferences_util.cc
index de9f711..28b4c05 100644
--- a/chrome/browser/renderer_preferences_util.cc
+++ b/chrome/browser/renderer_preferences_util.cc
@@ -24,6 +24,12 @@ void UpdateFromSystemSettings(RendererPreferences* prefs, Profile* profile) {
prefs->thumb_active_color = provider->get_thumb_active_color();
prefs->thumb_inactive_color = provider->get_thumb_inactive_color();
prefs->track_color = provider->get_track_color();
+ prefs->active_selection_bg_color = provider->get_active_selection_bg_color();
+ prefs->active_selection_fg_color = provider->get_active_selection_fg_color();
+ prefs->inactive_selection_bg_color =
+ provider->get_inactive_selection_bg_color();
+ prefs->inactive_selection_fg_color =
+ provider->get_inactive_selection_fg_color();
#endif // !defined(TOOLKIT_VIEWS)
#endif // defined(OS_LINUX)
}
diff --git a/chrome/common/render_messages.h b/chrome/common/render_messages.h
index 5efe75e..24e1e72 100644
--- a/chrome/common/render_messages.h
+++ b/chrome/common/render_messages.h
@@ -1601,6 +1601,10 @@ struct ParamTraits<RendererPreferences> {
WriteParam(m, p.thumb_active_color);
WriteParam(m, p.thumb_inactive_color);
WriteParam(m, p.track_color);
+ WriteParam(m, p.active_selection_bg_color);
+ WriteParam(m, p.active_selection_fg_color);
+ WriteParam(m, p.inactive_selection_bg_color);
+ WriteParam(m, p.inactive_selection_fg_color);
WriteParam(m, p.browser_handles_top_level_requests);
}
static bool Read(const Message* m, void** iter, param_type* p) {
@@ -1627,13 +1631,23 @@ struct ParamTraits<RendererPreferences> {
p->focus_ring_color = focus_ring_color;
int thumb_active_color, thumb_inactive_color, track_color;
+ int active_selection_bg_color, active_selection_fg_color;
+ int inactive_selection_bg_color, inactive_selection_fg_color;
if (!ReadParam(m, iter, &thumb_active_color) ||
!ReadParam(m, iter, &thumb_inactive_color) ||
- !ReadParam(m, iter, &track_color))
+ !ReadParam(m, iter, &track_color) ||
+ !ReadParam(m, iter, &active_selection_bg_color) ||
+ !ReadParam(m, iter, &active_selection_fg_color) ||
+ !ReadParam(m, iter, &inactive_selection_bg_color) ||
+ !ReadParam(m, iter, &inactive_selection_fg_color))
return false;
p->thumb_active_color = thumb_active_color;
p->thumb_inactive_color = thumb_inactive_color;
p->track_color = track_color;
+ p->active_selection_bg_color = active_selection_bg_color;
+ p->active_selection_fg_color = active_selection_fg_color;
+ p->inactive_selection_bg_color = inactive_selection_bg_color;
+ p->inactive_selection_fg_color = inactive_selection_fg_color;
if (!ReadParam(m, iter, &p->browser_handles_top_level_requests))
return false;
diff --git a/chrome/common/renderer_preferences.h b/chrome/common/renderer_preferences.h
index a982d57..30b267f 100644
--- a/chrome/common/renderer_preferences.h
+++ b/chrome/common/renderer_preferences.h
@@ -57,6 +57,12 @@ struct RendererPreferences {
SkColor thumb_inactive_color;
SkColor track_color;
+ // The colors used in selection text. Currently only used on Linux.
+ SkColor active_selection_bg_color;
+ SkColor active_selection_fg_color;
+ SkColor inactive_selection_bg_color;
+ SkColor inactive_selection_fg_color;
+
// Browser wants a look at all top level requests
bool browser_handles_top_level_requests;
@@ -70,6 +76,10 @@ struct RendererPreferences {
thumb_active_color(0),
thumb_inactive_color(0),
track_color(0),
+ active_selection_bg_color(0),
+ active_selection_fg_color(0),
+ inactive_selection_bg_color(0),
+ inactive_selection_fg_color(0),
browser_handles_top_level_requests(false) {
}
};
diff --git a/chrome/renderer/render_view.cc b/chrome/renderer/render_view.cc
index 364763a..7c9176d6 100644
--- a/chrome/renderer/render_view.cc
+++ b/chrome/renderer/render_view.cc
@@ -3346,11 +3346,17 @@ void RenderView::OnSetRendererPrefs(const RendererPreferences& renderer_prefs) {
WebColorName name = WebKit::WebColorWebkitFocusRingColor;
WebKit::setNamedColors(&name, &renderer_prefs.focus_ring_color, 1);
- if (webview())
+ if (webview()) {
webview()->setScrollbarColors(
renderer_prefs.thumb_inactive_color,
renderer_prefs.thumb_active_color,
renderer_prefs.track_color);
+ webview()->setSelectionColors(
+ renderer_prefs.active_selection_bg_color,
+ renderer_prefs.active_selection_fg_color,
+ renderer_prefs.inactive_selection_bg_color,
+ renderer_prefs.inactive_selection_fg_color);
+ }
#endif
}
diff --git a/webkit/data/layout_tests/LayoutTests/fast/linux_selection_color.html b/webkit/data/layout_tests/LayoutTests/fast/linux_selection_color.html
new file mode 100644
index 0000000..eea9d28
--- /dev/null
+++ b/webkit/data/layout_tests/LayoutTests/fast/linux_selection_color.html
@@ -0,0 +1,21 @@
+<html>
+<body>
+<div>
+<p id="text">
+This tests that the methods that set selection colors for Linux work correctly.
+</p>
+<p>(All the text in the above sentence should be highlighted red with green text)</p>
+</div>
+<script>
+if (window.layoutTestController) {
+ layoutTestController.forceRedSelectionColors()
+}
+
+var div = document.getElementById("text");
+var sel = window.getSelection();
+var range = document.createRange();
+range.selectNode(div);
+sel.addRange(range);
+</script>
+</body>
+</html>
diff --git a/webkit/data/layout_tests/platform/chromium-linux/LayoutTests/linux_selection_color-expected.checksum b/webkit/data/layout_tests/platform/chromium-linux/LayoutTests/linux_selection_color-expected.checksum
new file mode 100644
index 0000000..089b2cd
--- /dev/null
+++ b/webkit/data/layout_tests/platform/chromium-linux/LayoutTests/linux_selection_color-expected.checksum
@@ -0,0 +1 @@
+a1a9a42b0e1cabfe99ebc1083217b82f \ No newline at end of file
diff --git a/webkit/data/layout_tests/platform/chromium-linux/LayoutTests/linux_selection_color-expected.png b/webkit/data/layout_tests/platform/chromium-linux/LayoutTests/linux_selection_color-expected.png
new file mode 100644
index 0000000..5e8c8cc
--- /dev/null
+++ b/webkit/data/layout_tests/platform/chromium-linux/LayoutTests/linux_selection_color-expected.png
Binary files differ
diff --git a/webkit/data/layout_tests/platform/chromium-linux/LayoutTests/linux_selection_color-expected.txt b/webkit/data/layout_tests/platform/chromium-linux/LayoutTests/linux_selection_color-expected.txt
new file mode 100644
index 0000000..ffc44d8
--- /dev/null
+++ b/webkit/data/layout_tests/platform/chromium-linux/LayoutTests/linux_selection_color-expected.txt
@@ -0,0 +1,14 @@
+layer at (0,0) size 800x600
+ RenderView at (0,0) size 800x600
+layer at (0,0) size 800x600
+ RenderBlock {HTML} at (0,0) size 800x600
+ RenderBody {BODY} at (8,8) size 784x576
+ RenderBlock {DIV} at (0,0) size 784x56
+ RenderBlock {P} at (0,0) size 784x20
+ RenderText {#text} at (0,0) size 458x19
+ text run at (0,0) width 458: "This tests that the methods that set selection colors for Linux work correctly."
+ RenderBlock {P} at (0,36) size 784x20
+ RenderText {#text} at (0,0) size 453x19
+ text run at (0,0) width 453: "(All the text in the above sentence should be highlighted red with green text)"
+selection start: position 1 of child 0 {#text} of child 1 {P} of child 1 {DIV} of child 1 {BODY} of child 0 {HTML} of document
+selection end: position 0 of child 3 {P} of child 1 {DIV} of child 1 {BODY} of child 0 {HTML} of document
diff --git a/webkit/tools/test_shell/layout_test_controller.cc b/webkit/tools/test_shell/layout_test_controller.cc
index 0dc1259..7dedc70 100644
--- a/webkit/tools/test_shell/layout_test_controller.cc
+++ b/webkit/tools/test_shell/layout_test_controller.cc
@@ -150,6 +150,7 @@ LayoutTestController::LayoutTestController(TestShell* shell) :
BindMethod("setAllowUniversalAccessFromFileURLs", &LayoutTestController::setAllowUniversalAccessFromFileURLs);
BindMethod("setTimelineProfilingEnabled", &LayoutTestController::setTimelineProfilingEnabled);
BindMethod("evaluateInWebInspector", &LayoutTestController::evaluateInWebInspector);
+ BindMethod("forceRedSelectionColors", &LayoutTestController::forceRedSelectionColors);
// The fallback method is called when an unknown method is invoked.
BindFallbackMethod(&LayoutTestController::fallbackMethod);
@@ -440,6 +441,12 @@ void LayoutTestController::Reset() {
if (shell_) {
shell_->webView()->setZoomLevel(false, 0);
shell_->webView()->setTabKeyCyclesThroughElements(true);
+#if defined(OS_LINUX)
+ // (Constants copied because we can't depend on the header that defined
+ // them from this file.)
+ shell_->webView()->setSelectionColors(
+ 0xff1e90ff, 0xff000000, 0xffc8c8c8, 0xff323232);
+#endif // defined(OS_LINUX)
}
dump_as_text_ = false;
dump_editing_callbacks_ = false;
@@ -1081,3 +1088,10 @@ void LayoutTestController::evaluateInWebInspector(const CppArgumentList& args,
shell_->dev_tools_agent()->evaluateInWebInspector(args[0].ToInt32(),
args[1].ToString());
}
+
+void LayoutTestController::forceRedSelectionColors(const CppArgumentList& args,
+ CppVariant* result) {
+ result->SetNull();
+ shell_->webView()->setSelectionColors(0xffee0000, 0xff00ee00, 0xff000000,
+ 0xffc0c0c0);
+}
diff --git a/webkit/tools/test_shell/layout_test_controller.h b/webkit/tools/test_shell/layout_test_controller.h
index 0fe2df8..ff16d6f 100644
--- a/webkit/tools/test_shell/layout_test_controller.h
+++ b/webkit/tools/test_shell/layout_test_controller.h
@@ -230,6 +230,10 @@ class LayoutTestController : public CppBoundClass {
// Allows layout tests to exec scripts at WebInspector side.
void evaluateInWebInspector(const CppArgumentList& args, CppVariant* result);
+ // Forces the selection colors for testing under Linux.
+ void forceRedSelectionColors(const CppArgumentList& args,
+ CppVariant* result);
+
public:
// The following methods are not exposed to JavaScript.
void SetWorkQueueFrozen(bool frozen) { work_queue_.set_frozen(frozen); }