OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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> |
(...skipping 1684 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1695 DCHECK(clipboard); | 1695 DCHECK(clipboard); |
1696 if (!clipboard) | 1696 if (!clipboard) |
1697 return; | 1697 return; |
1698 | 1698 |
1699 gtk_clipboard_set_text( | 1699 gtk_clipboard_set_text( |
1700 clipboard, selected_text.data(), selected_text.size()); | 1700 clipboard, selected_text.data(), selected_text.size()); |
1701 } | 1701 } |
1702 | 1702 |
1703 void AutocompleteEditViewGtk::SetTextAndSelectedRange(const std::wstring& text, | 1703 void AutocompleteEditViewGtk::SetTextAndSelectedRange(const std::wstring& text, |
1704 const CharRange& range) { | 1704 const CharRange& range) { |
1705 std::string utf8 = WideToUTF8(text); | 1705 if (text != GetText()) { |
1706 gtk_text_buffer_set_text(text_buffer_, utf8.data(), utf8.length()); | 1706 std::string utf8 = WideToUTF8(text); |
| 1707 gtk_text_buffer_set_text(text_buffer_, utf8.data(), utf8.length()); |
| 1708 } |
1707 SetSelectedRange(range); | 1709 SetSelectedRange(range); |
1708 AdjustTextJustification(); | 1710 AdjustTextJustification(); |
1709 } | 1711 } |
1710 | 1712 |
1711 void AutocompleteEditViewGtk::SetSelectedRange(const CharRange& range) { | 1713 void AutocompleteEditViewGtk::SetSelectedRange(const CharRange& range) { |
1712 GtkTextIter insert, bound; | 1714 GtkTextIter insert, bound; |
1713 ItersFromCharRange(range, &bound, &insert); | 1715 ItersFromCharRange(range, &bound, &insert); |
1714 gtk_text_buffer_select_range(text_buffer_, &insert, &bound); | 1716 gtk_text_buffer_select_range(text_buffer_, &insert, &bound); |
1715 | 1717 |
1716 // This should be set *after* setting the selection range, in case setting the | 1718 // This should be set *after* setting the selection range, in case setting the |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1919 // baseline, so we need to move the |instant_view_| down to make sure it | 1921 // baseline, so we need to move the |instant_view_| down to make sure it |
1920 // has the same baseline as the |text_view_|. | 1922 // has the same baseline as the |text_view_|. |
1921 PangoLayout* layout = gtk_label_get_layout(GTK_LABEL(instant_view_)); | 1923 PangoLayout* layout = gtk_label_get_layout(GTK_LABEL(instant_view_)); |
1922 int height; | 1924 int height; |
1923 pango_layout_get_size(layout, NULL, &height); | 1925 pango_layout_get_size(layout, NULL, &height); |
1924 PangoLayoutIter* iter = pango_layout_get_iter(layout); | 1926 PangoLayoutIter* iter = pango_layout_get_iter(layout); |
1925 int baseline = pango_layout_iter_get_baseline(iter); | 1927 int baseline = pango_layout_iter_get_baseline(iter); |
1926 pango_layout_iter_free(iter); | 1928 pango_layout_iter_free(iter); |
1927 g_object_set(instant_anchor_tag_, "rise", baseline - height, NULL); | 1929 g_object_set(instant_anchor_tag_, "rise", baseline - height, NULL); |
1928 } | 1930 } |
OLD | NEW |