| 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 "app/l10n_util.h" | 10 #include "app/l10n_util.h" |
| 11 #include "base/gfx/gtk_util.h" | 11 #include "base/gfx/gtk_util.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/string_util.h" | 13 #include "base/string_util.h" |
| 14 #include "chrome/app/chrome_dll_resource.h" | 14 #include "chrome/app/chrome_dll_resource.h" |
| 15 #include "chrome/browser/autocomplete/autocomplete_edit.h" | 15 #include "chrome/browser/autocomplete/autocomplete_edit.h" |
| 16 #include "chrome/browser/autocomplete/autocomplete_popup_model.h" | 16 #include "chrome/browser/autocomplete/autocomplete_popup_model.h" |
| 17 #include "chrome/browser/autocomplete/autocomplete_popup_view_gtk.h" | 17 #include "chrome/browser/autocomplete/autocomplete_popup_view_gtk.h" |
| 18 #include "chrome/browser/command_updater.h" | 18 #include "chrome/browser/command_updater.h" |
| 19 #include "chrome/browser/defaults.h" | 19 #include "chrome/browser/defaults.h" |
| 20 #include "chrome/browser/gtk/location_bar_view_gtk.h" | |
| 21 #include "chrome/browser/tab_contents/tab_contents.h" | 20 #include "chrome/browser/tab_contents/tab_contents.h" |
| 22 #include "chrome/browser/toolbar_model.h" | 21 #include "chrome/browser/toolbar_model.h" |
| 23 #include "chrome/common/gtk_util.h" | 22 #include "chrome/common/gtk_util.h" |
| 24 #include "chrome/common/notification_service.h" | 23 #include "chrome/common/notification_service.h" |
| 25 #include "googleurl/src/gurl.h" | 24 #include "googleurl/src/gurl.h" |
| 26 #include "grit/generated_resources.h" | 25 #include "grit/generated_resources.h" |
| 26 #if !defined(TOOLKIT_VIEWS) |
| 27 #include "chrome/browser/views/location_bar_view.h" |
| 28 #include "skia/ext/skia_utils_gtk.h" |
| 29 #else |
| 30 #include "chrome/browser/gtk/location_bar_view_gtk.h" |
| 27 | 31 |
| 28 namespace { | 32 namespace { |
| 29 | 33 |
| 30 const char kTextBaseColor[] = "#808080"; | 34 const char kTextBaseColor[] = "#808080"; |
| 31 const char kSecureSchemeColor[] = "#009614"; | 35 const char kSecureSchemeColor[] = "#009614"; |
| 32 const char kInsecureSchemeColor[] = "#c80000"; | 36 const char kInsecureSchemeColor[] = "#c80000"; |
| 33 | 37 |
| 34 size_t GetUTF8Offset(const std::wstring& wide_text, size_t wide_text_offset) { | 38 size_t GetUTF8Offset(const std::wstring& wide_text, size_t wide_text_offset) { |
| 35 return WideToUTF8(wide_text.substr(0, wide_text_offset)).size(); | 39 return WideToUTF8(wide_text.substr(0, wide_text_offset)).size(); |
| 36 } | 40 } |
| (...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 419 | 423 |
| 420 bool something_changed = model_->OnAfterPossibleChange(new_text, | 424 bool something_changed = model_->OnAfterPossibleChange(new_text, |
| 421 selection_differs, text_differs, just_deleted_text, at_end_of_edit); | 425 selection_differs, text_differs, just_deleted_text, at_end_of_edit); |
| 422 | 426 |
| 423 if (something_changed && text_differs) | 427 if (something_changed && text_differs) |
| 424 TextChanged(); | 428 TextChanged(); |
| 425 | 429 |
| 426 return something_changed; | 430 return something_changed; |
| 427 } | 431 } |
| 428 | 432 |
| 433 gfx::NativeView AutocompleteEditViewGtk::GetNativeView() const { |
| 434 return alignment_.get(); |
| 435 } |
| 436 |
| 437 void AutocompleteEditViewGtk::Observe(NotificationType type, |
| 438 const NotificationSource& source, |
| 439 const NotificationDetails& details) { |
| 440 DCHECK(type == NotificationType::BROWSER_THEME_CHANGED); |
| 441 |
| 442 SetBaseColor(); |
| 443 } |
| 444 |
| 445 void AutocompleteEditViewGtk::SetBaseColor() { |
| 446 #if defined(TOOLKIT_VIEWS) |
| 447 bool use_gtk = false; |
| 448 #else |
| 449 bool use_gtk = theme_provider_->UseGtkTheme(); |
| 450 #endif |
| 451 |
| 452 // If we're on a secure connection, ignore what the theme wants us to do |
| 453 // and use a yellow background. |
| 454 bool is_secure = (scheme_security_level_ == ToolbarModel::SECURE); |
| 455 if (use_gtk && !is_secure) { |
| 456 gtk_widget_modify_base(text_view_, GTK_STATE_NORMAL, NULL); |
| 457 |
| 458 // Grab the text colors out of the style and set our tags to use them. |
| 459 GtkStyle* style = gtk_rc_get_style(text_view_); |
| 460 |
| 461 // style may be unrealized at this point, so calculate the halfway point |
| 462 // between text[] and base[] manually instead of just using text_aa[]. |
| 463 GdkColor average_color = gtk_util::AverageColors( |
| 464 style->text[GTK_STATE_NORMAL], style->base[GTK_STATE_NORMAL]); |
| 465 |
| 466 g_object_set(G_OBJECT(faded_text_tag_), "foreground-gdk", |
| 467 &average_color, NULL); |
| 468 g_object_set(G_OBJECT(normal_text_tag_), "foreground-gdk", |
| 469 &style->text[GTK_STATE_NORMAL], NULL); |
| 470 } else { |
| 471 #if defined(TOOLKIT_VIEWS) |
| 472 const GdkColor background_color = skia::SkColorToGdkColor( |
| 473 LocationBarView::GetColor(is_secure, LocationBarView::BACKGROUND)); |
| 474 gtk_widget_modify_base(text_view_, GTK_STATE_NORMAL, |
| 475 &background_color); |
| 476 #else |
| 477 gtk_widget_modify_base(text_view_, GTK_STATE_NORMAL, |
| 478 &LocationBarViewGtk::kBackgroundColorByLevel[scheme_security_level_]); |
| 479 #endif |
| 480 |
| 481 g_object_set(G_OBJECT(faded_text_tag_), "foreground", kTextBaseColor, NULL); |
| 482 g_object_set(G_OBJECT(normal_text_tag_), "foreground", "#000000", NULL); |
| 483 } |
| 484 } |
| 485 |
| 429 void AutocompleteEditViewGtk::HandleBeginUserAction() { | 486 void AutocompleteEditViewGtk::HandleBeginUserAction() { |
| 430 OnBeforePossibleChange(); | 487 OnBeforePossibleChange(); |
| 431 } | 488 } |
| 432 | 489 |
| 433 void AutocompleteEditViewGtk::HandleEndUserAction() { | 490 void AutocompleteEditViewGtk::HandleEndUserAction() { |
| 434 // Eat any newline / paragraphs that might have come in, for example in a | 491 // Eat any newline / paragraphs that might have come in, for example in a |
| 435 // copy and paste. We want to make sure our widget stays single line. | 492 // copy and paste. We want to make sure our widget stays single line. |
| 436 for (;;) { | 493 for (;;) { |
| 437 GtkTextIter cur; | 494 GtkTextIter cur; |
| 438 gtk_text_buffer_get_start_iter(text_buffer_, &cur); | 495 gtk_text_buffer_get_start_iter(text_buffer_, &cur); |
| (...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 755 const std::string& selected_text) { | 812 const std::string& selected_text) { |
| 756 GtkClipboard* clipboard = | 813 GtkClipboard* clipboard = |
| 757 gtk_widget_get_clipboard(text_view_, GDK_SELECTION_PRIMARY); | 814 gtk_widget_get_clipboard(text_view_, GDK_SELECTION_PRIMARY); |
| 758 DCHECK(clipboard); | 815 DCHECK(clipboard); |
| 759 if (!clipboard) | 816 if (!clipboard) |
| 760 return; | 817 return; |
| 761 | 818 |
| 762 gtk_clipboard_set_text( | 819 gtk_clipboard_set_text( |
| 763 clipboard, selected_text.data(), selected_text.size()); | 820 clipboard, selected_text.data(), selected_text.size()); |
| 764 } | 821 } |
| OLD | NEW |