summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/app/chrome_dll_main.cc3
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc94
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit_view_gtk.h27
3 files changed, 102 insertions, 22 deletions
diff --git a/chrome/app/chrome_dll_main.cc b/chrome/app/chrome_dll_main.cc
index ddf5b9f..478140c 100644
--- a/chrome/app/chrome_dll_main.cc
+++ b/chrome/app/chrome_dll_main.cc
@@ -186,7 +186,8 @@ static void GLibLogHandler(const gchar* log_domain,
// This warning only occurs in obsolete versions of GTK and is harmless.
// http://crbug.com/11133
} else if (strstr(message, "Theme file for default has no") ||
- strstr(message, "Theme directory")) {
+ strstr(message, "Theme directory") ||
+ strstr(message, "theme pixmap")) {
LOG(ERROR) << "GTK theme error: " << message;
} else {
#ifdef NDEBUG
diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc
index 9e911a1..f356b74 100644
--- a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc
+++ b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc
@@ -26,6 +26,10 @@
#include "googleurl/src/gurl.h"
#include "grit/generated_resources.h"
+#if !defined(TOOLKIT_VIEWS)
+#include "chrome/browser/gtk/gtk_theme_provider.h"
+#endif
+
namespace {
const char kTextBaseColor[] = "#808080";
@@ -76,7 +80,7 @@ AutocompleteEditViewGtk::AutocompleteEditViewGtk(
: text_view_(NULL),
tag_table_(NULL),
text_buffer_(NULL),
- base_tag_(NULL),
+ faded_text_tag_(NULL),
secure_scheme_tag_(NULL),
insecure_scheme_tag_(NULL),
model_(new AutocompleteEditModel(this, controller, profile)),
@@ -93,7 +97,12 @@ AutocompleteEditViewGtk::AutocompleteEditViewGtk(
mark_set_handler_id_(0),
button_1_pressed_(false),
text_selected_during_click_(false),
- text_view_focused_before_button_press_(false) {
+ text_view_focused_before_button_press_(false)
+#if !defined(TOOLKIT_VIEWS)
+ ,
+ theme_provider_(GtkThemeProvider::GetFrom(profile))
+#endif
+ {
model_->set_popup_model(popup_view_->GetModel());
}
@@ -140,10 +149,6 @@ void AutocompleteEditViewGtk::Init() {
popup_window_mode_ ? kPopupWindowFontSize : kFontSize);
}
- // Override the background color for now. http://crbug.com/12195
- gtk_widget_modify_base(text_view_, GTK_STATE_NORMAL,
- &LocationBarViewGtk::kBackgroundColorByLevel[scheme_security_level_]);
-
// The text view was floating. It will now be owned by the alignment.
gtk_container_add(GTK_CONTAINER(alignment_.get()), text_view_);
@@ -152,13 +157,13 @@ void AutocompleteEditViewGtk::Init() {
// We want the tab key to move focus, not insert a tab.
gtk_text_view_set_accepts_tab(GTK_TEXT_VIEW(text_view_), false);
- base_tag_ = gtk_text_buffer_create_tag(text_buffer_,
+ faded_text_tag_ = gtk_text_buffer_create_tag(text_buffer_,
NULL, "foreground", kTextBaseColor, NULL);
secure_scheme_tag_ = gtk_text_buffer_create_tag(text_buffer_,
NULL, "foreground", kSecureSchemeColor, NULL);
insecure_scheme_tag_ = gtk_text_buffer_create_tag(text_buffer_,
NULL, "foreground", kInsecureSchemeColor, NULL);
- black_text_tag_ = gtk_text_buffer_create_tag(text_buffer_,
+ normal_text_tag_ = gtk_text_buffer_create_tag(text_buffer_,
NULL, "foreground", "#000000", NULL);
// NOTE: This code used to connect to "changed", however this was fired too
@@ -197,6 +202,17 @@ void AutocompleteEditViewGtk::Init() {
text_buffer_, "mark-set", G_CALLBACK(&HandleMarkSetThunk), this);
g_signal_connect(text_view_, "drag-data-received",
G_CALLBACK(&HandleDragDataReceivedThunk), this);
+
+#if !defined(TOOLKIT_VIEWS)
+ registrar_.Add(this,
+ NotificationType::BROWSER_THEME_CHANGED,
+ NotificationService::AllSources());
+ theme_provider_->InitThemesFor(this);
+#else
+ // Manually invoke SetBaseColor() because TOOLKIT_VIEWS doesn't observe
+ // themes.
+ SetBaseColor();
+#endif
}
void AutocompleteEditViewGtk::SetFocus() {
@@ -231,8 +247,7 @@ void AutocompleteEditViewGtk::Update(const TabContents* contents) {
// TODO(deanm): This doesn't exactly match Windows. There there is a member
// background_color_. I think we can get away with just the level though.
if (changed_security_level) {
- gtk_widget_modify_base(text_view_, GTK_STATE_NORMAL,
- &LocationBarViewGtk::kBackgroundColorByLevel[security_level]);
+ SetBaseColor();
}
if (contents) {
@@ -435,6 +450,53 @@ gfx::NativeView AutocompleteEditViewGtk::GetNativeView() const {
return alignment_.get();
}
+void AutocompleteEditViewGtk::Observe(NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details) {
+ DCHECK(type == NotificationType::BROWSER_THEME_CHANGED);
+
+ SetBaseColor();
+}
+
+void AutocompleteEditViewGtk::SetBaseColor() {
+#if defined(TOOLKIT_VIEWS)
+ bool use_gtk = false;
+#else
+ bool use_gtk = theme_provider_->UseGtkTheme();
+#endif
+
+ // If we're on a secure connection, ignore what the theme wants us to do
+ // and use a yellow background.
+ if (use_gtk && scheme_security_level_ != ToolbarModel::SECURE) {
+ gtk_widget_modify_base(text_view_, GTK_STATE_NORMAL, NULL);
+
+ // Grab the text colors out of the style and set our tags to use them.
+ GtkStyle* style = gtk_rc_get_style(text_view_);
+
+ // style may be unrealized at this point, so calculate the halfway point
+ // between text[] and base[] manually instead of just using text_aa[].
+ GdkColor average_color;
+ average_color.pixel = 0;
+ average_color.red = (style->text[GTK_STATE_NORMAL].red +
+ style->base[GTK_STATE_NORMAL].red) / 2;
+ average_color.green = (style->text[GTK_STATE_NORMAL].green +
+ style->base[GTK_STATE_NORMAL].green) / 2;
+ average_color.blue = (style->text[GTK_STATE_NORMAL].blue +
+ style->base[GTK_STATE_NORMAL].blue) / 2;
+
+ g_object_set(G_OBJECT(faded_text_tag_), "foreground-gdk",
+ &average_color, NULL);
+ g_object_set(G_OBJECT(normal_text_tag_), "foreground-gdk",
+ &style->text[GTK_STATE_NORMAL], NULL);
+ } else {
+ gtk_widget_modify_base(text_view_, GTK_STATE_NORMAL,
+ &LocationBarViewGtk::kBackgroundColorByLevel[scheme_security_level_]);
+
+ g_object_set(G_OBJECT(faded_text_tag_), "foreground", kTextBaseColor, NULL);
+ g_object_set(G_OBJECT(normal_text_tag_), "foreground", "#000000", NULL);
+ }
+}
+
void AutocompleteEditViewGtk::HandleBeginUserAction() {
OnBeforePossibleChange();
}
@@ -788,7 +850,7 @@ void AutocompleteEditViewGtk::EmphasizeURLComponents() {
gtk_text_buffer_get_bounds(text_buffer_, &start, &end);
gtk_text_buffer_remove_all_tags(text_buffer_, &start, &end);
if (emphasize) {
- gtk_text_buffer_apply_tag(text_buffer_, base_tag_, &start, &end);
+ gtk_text_buffer_apply_tag(text_buffer_, faded_text_tag_, &start, &end);
// We've found a host name, give it more emphasis.
gtk_text_buffer_get_iter_at_line_index(text_buffer_, &start, 0,
@@ -797,14 +859,10 @@ void AutocompleteEditViewGtk::EmphasizeURLComponents() {
gtk_text_buffer_get_iter_at_line_index(text_buffer_, &end, 0,
GetUTF8Offset(text,
parts.host.end()));
- // The following forces the text color to black. When we start obeying the
- // user theme, we want to remove_all_tags (to get the user's default
- // text color) rather than applying a color tag. http://crbug.com/12195
- gtk_text_buffer_apply_tag(text_buffer_, black_text_tag_, &start, &end);
+
+ gtk_text_buffer_apply_tag(text_buffer_, normal_text_tag_, &start, &end);
} else {
- // For now, force the text color to be black. Eventually, we should allow
- // the user to override via gtk theming. http://crbug.com/12195
- gtk_text_buffer_apply_tag(text_buffer_, black_text_tag_, &start, &end);
+ gtk_text_buffer_apply_tag(text_buffer_, normal_text_tag_, &start, &end);
}
// Emphasize the scheme for security UI display purposes (if necessary).
diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.h b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.h
index bd91442..667c756 100644
--- a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.h
+++ b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.h
@@ -12,6 +12,8 @@
#include "base/string_util.h"
#include "chrome/browser/autocomplete/autocomplete_edit_view.h"
#include "chrome/browser/toolbar_model.h"
+#include "chrome/common/notification_observer.h"
+#include "chrome/common/notification_registrar.h"
#include "chrome/common/owned_widget_gtk.h"
#include "chrome/common/page_transition_types.h"
#include "webkit/glue/window_open_disposition.h"
@@ -24,7 +26,12 @@ class CommandUpdater;
class Profile;
class TabContents;
-class AutocompleteEditViewGtk : public AutocompleteEditView {
+#if !defined(TOOLKIT_VIEWS)
+class GtkThemeProvider;
+#endif
+
+class AutocompleteEditViewGtk : public AutocompleteEditView,
+ public NotificationObserver {
public:
// Modeled like the Windows CHARRANGE. Represent a pair of cursor position
// offsets. Since GtkTextIters are invalid after the buffer is changed, we
@@ -99,6 +106,13 @@ class AutocompleteEditViewGtk : public AutocompleteEditView {
virtual bool OnAfterPossibleChange();
virtual gfx::NativeView GetNativeView() const;
+ // Overridden from NotificationObserver:
+ virtual void Observe(NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details);
+
+ void SetBaseColor();
+
private:
// TODO(deanm): Would be nice to insulate the thunkers better, etc.
static void HandleBeginUserActionThunk(GtkTextBuffer* unused, gpointer self) {
@@ -282,10 +296,10 @@ class AutocompleteEditViewGtk : public AutocompleteEditView {
GtkTextTagTable* tag_table_;
GtkTextBuffer* text_buffer_;
- GtkTextTag* base_tag_;
+ GtkTextTag* faded_text_tag_;
GtkTextTag* secure_scheme_tag_;
GtkTextTag* insecure_scheme_tag_;
- GtkTextTag* black_text_tag_;
+ GtkTextTag* normal_text_tag_;
scoped_ptr<AutocompleteEditModel> model_;
scoped_ptr<AutocompletePopupView> popup_view_;
@@ -333,6 +347,13 @@ class AutocompleteEditViewGtk : public AutocompleteEditView {
// is released (we only do so if the view was initially unfocused).
bool text_view_focused_before_button_press_;
+#if !defined(TOOLKIT_VIEWS)
+ // Supplies colors, et cetera.
+ GtkThemeProvider* theme_provider_;
+
+ NotificationRegistrar registrar_;
+#endif
+
DISALLOW_COPY_AND_ASSIGN(AutocompleteEditViewGtk);
};