| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/autocomplete/autocomplete_edit_view_gtk.h" | 5 #include "chrome/browser/autocomplete/autocomplete_edit_view_gtk.h" |
| 6 | 6 |
| 7 #include <gtk/gtk.h> | 7 #include <gtk/gtk.h> |
| 8 #include <gdk/gdkkeysyms.h> | 8 #include <gdk/gdkkeysyms.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| 11 | 11 |
| 12 #include "app/gfx/font.h" | 12 #include "app/gfx/font.h" |
| 13 #include "app/l10n_util.h" | 13 #include "app/l10n_util.h" |
| 14 #include "base/gfx/gtk_util.h" | 14 #include "base/gfx/gtk_util.h" |
| 15 #include "base/logging.h" | 15 #include "base/logging.h" |
| 16 #include "base/string_util.h" | 16 #include "base/string_util.h" |
| 17 #include "chrome/app/chrome_dll_resource.h" | 17 #include "chrome/app/chrome_dll_resource.h" |
| 18 #include "chrome/browser/autocomplete/autocomplete_edit.h" | 18 #include "chrome/browser/autocomplete/autocomplete_edit.h" |
| 19 #include "chrome/browser/autocomplete/autocomplete_popup_model.h" | 19 #include "chrome/browser/autocomplete/autocomplete_popup_model.h" |
| 20 #include "chrome/browser/autocomplete/autocomplete_popup_view_gtk.h" | 20 #include "chrome/browser/autocomplete/autocomplete_popup_view_gtk.h" |
| 21 #include "chrome/browser/command_updater.h" | 21 #include "chrome/browser/command_updater.h" |
| 22 #include "chrome/browser/defaults.h" | 22 #include "chrome/browser/defaults.h" |
| 23 #include "chrome/browser/gtk/location_bar_view_gtk.h" | |
| 24 #include "chrome/browser/gtk/view_id_util.h" | 23 #include "chrome/browser/gtk/view_id_util.h" |
| 25 #include "chrome/browser/tab_contents/tab_contents.h" | 24 #include "chrome/browser/tab_contents/tab_contents.h" |
| 26 #include "chrome/browser/toolbar_model.h" | 25 #include "chrome/browser/toolbar_model.h" |
| 27 #include "chrome/common/gtk_util.h" | 26 #include "chrome/common/gtk_util.h" |
| 28 #include "chrome/common/notification_service.h" | 27 #include "chrome/common/notification_service.h" |
| 29 #include "googleurl/src/gurl.h" | 28 #include "googleurl/src/gurl.h" |
| 30 #include "grit/generated_resources.h" | 29 #include "grit/generated_resources.h" |
| 31 | 30 |
| 32 #if !defined(TOOLKIT_VIEWS) | 31 #if defined(TOOLKIT_VIEWS) |
| 32 #include "chrome/browser/views/location_bar_view.h" |
| 33 #include "skia/ext/skia_utils_gtk.h" |
| 34 #else |
| 33 #include "chrome/browser/gtk/gtk_theme_provider.h" | 35 #include "chrome/browser/gtk/gtk_theme_provider.h" |
| 36 #include "chrome/browser/gtk/location_bar_view_gtk.h" |
| 34 #endif | 37 #endif |
| 35 | 38 |
| 36 namespace { | 39 namespace { |
| 37 | 40 |
| 38 const char kTextBaseColor[] = "#808080"; | 41 const char kTextBaseColor[] = "#808080"; |
| 39 const char kSecureSchemeColor[] = "#009614"; | 42 const char kSecureSchemeColor[] = "#009614"; |
| 40 const char kInsecureSchemeColor[] = "#c80000"; | 43 const char kInsecureSchemeColor[] = "#c80000"; |
| 41 | 44 |
| 42 size_t GetUTF8Offset(const std::wstring& wide_text, size_t wide_text_offset) { | 45 size_t GetUTF8Offset(const std::wstring& wide_text, size_t wide_text_offset) { |
| 43 return WideToUTF8(wide_text.substr(0, wide_text_offset)).size(); | 46 return WideToUTF8(wide_text.substr(0, wide_text_offset)).size(); |
| (...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 502 | 505 |
| 503 void AutocompleteEditViewGtk::SetBaseColor() { | 506 void AutocompleteEditViewGtk::SetBaseColor() { |
| 504 #if defined(TOOLKIT_VIEWS) | 507 #if defined(TOOLKIT_VIEWS) |
| 505 bool use_gtk = false; | 508 bool use_gtk = false; |
| 506 #else | 509 #else |
| 507 bool use_gtk = theme_provider_->UseGtkTheme(); | 510 bool use_gtk = theme_provider_->UseGtkTheme(); |
| 508 #endif | 511 #endif |
| 509 | 512 |
| 510 // If we're on a secure connection, ignore what the theme wants us to do | 513 // If we're on a secure connection, ignore what the theme wants us to do |
| 511 // and use a yellow background. | 514 // and use a yellow background. |
| 512 if (use_gtk && scheme_security_level_ != ToolbarModel::SECURE) { | 515 bool is_secure = (scheme_security_level_ == ToolbarModel::SECURE); |
| 516 if (use_gtk && !is_secure) { |
| 513 gtk_widget_modify_base(text_view_, GTK_STATE_NORMAL, NULL); | 517 gtk_widget_modify_base(text_view_, GTK_STATE_NORMAL, NULL); |
| 514 | 518 |
| 515 // Grab the text colors out of the style and set our tags to use them. | 519 // Grab the text colors out of the style and set our tags to use them. |
| 516 GtkStyle* style = gtk_rc_get_style(text_view_); | 520 GtkStyle* style = gtk_rc_get_style(text_view_); |
| 517 | 521 |
| 518 // style may be unrealized at this point, so calculate the halfway point | 522 // style may be unrealized at this point, so calculate the halfway point |
| 519 // between text[] and base[] manually instead of just using text_aa[]. | 523 // between text[] and base[] manually instead of just using text_aa[]. |
| 520 GdkColor average_color = gtk_util::AverageColors( | 524 GdkColor average_color = gtk_util::AverageColors( |
| 521 style->text[GTK_STATE_NORMAL], style->base[GTK_STATE_NORMAL]); | 525 style->text[GTK_STATE_NORMAL], style->base[GTK_STATE_NORMAL]); |
| 522 | 526 |
| 523 g_object_set(G_OBJECT(faded_text_tag_), "foreground-gdk", | 527 g_object_set(G_OBJECT(faded_text_tag_), "foreground-gdk", |
| 524 &average_color, NULL); | 528 &average_color, NULL); |
| 525 g_object_set(G_OBJECT(normal_text_tag_), "foreground-gdk", | 529 g_object_set(G_OBJECT(normal_text_tag_), "foreground-gdk", |
| 526 &style->text[GTK_STATE_NORMAL], NULL); | 530 &style->text[GTK_STATE_NORMAL], NULL); |
| 527 } else { | 531 } else { |
| 532 #if defined(TOOLKIT_VIEWS) |
| 533 const GdkColor background_color = skia::SkColorToGdkColor( |
| 534 LocationBarView::GetColor(is_secure, LocationBarView::BACKGROUND)); |
| 535 gtk_widget_modify_base(text_view_, GTK_STATE_NORMAL, |
| 536 &background_color); |
| 537 #else |
| 528 gtk_widget_modify_base(text_view_, GTK_STATE_NORMAL, | 538 gtk_widget_modify_base(text_view_, GTK_STATE_NORMAL, |
| 529 &LocationBarViewGtk::kBackgroundColorByLevel[scheme_security_level_]); | 539 &LocationBarViewGtk::kBackgroundColorByLevel[scheme_security_level_]); |
| 540 #endif |
| 530 | 541 |
| 531 g_object_set(G_OBJECT(faded_text_tag_), "foreground", kTextBaseColor, NULL); | 542 g_object_set(G_OBJECT(faded_text_tag_), "foreground", kTextBaseColor, NULL); |
| 532 g_object_set(G_OBJECT(normal_text_tag_), "foreground", "#000000", NULL); | 543 g_object_set(G_OBJECT(normal_text_tag_), "foreground", "#000000", NULL); |
| 533 } | 544 } |
| 534 } | 545 } |
| 535 | 546 |
| 536 void AutocompleteEditViewGtk::HandleBeginUserAction() { | 547 void AutocompleteEditViewGtk::HandleBeginUserAction() { |
| 537 OnBeforePossibleChange(); | 548 OnBeforePossibleChange(); |
| 538 } | 549 } |
| 539 | 550 |
| (...skipping 617 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1157 const std::string& selected_text) { | 1168 const std::string& selected_text) { |
| 1158 GtkClipboard* clipboard = | 1169 GtkClipboard* clipboard = |
| 1159 gtk_widget_get_clipboard(text_view_, GDK_SELECTION_PRIMARY); | 1170 gtk_widget_get_clipboard(text_view_, GDK_SELECTION_PRIMARY); |
| 1160 DCHECK(clipboard); | 1171 DCHECK(clipboard); |
| 1161 if (!clipboard) | 1172 if (!clipboard) |
| 1162 return; | 1173 return; |
| 1163 | 1174 |
| 1164 gtk_clipboard_set_text( | 1175 gtk_clipboard_set_text( |
| 1165 clipboard, selected_text.data(), selected_text.size()); | 1176 clipboard, selected_text.data(), selected_text.size()); |
| 1166 } | 1177 } |
| OLD | NEW |