OLD | NEW |
---|---|
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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/ui/gtk/omnibox/omnibox_view_gtk.h" | 5 #include "chrome/browser/ui/gtk/omnibox/omnibox_view_gtk.h" |
6 | 6 |
7 #include <gdk/gdkkeysyms.h> | 7 #include <gdk/gdkkeysyms.h> |
8 #include <gtk/gtk.h> | 8 #include <gtk/gtk.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 18 matching lines...) Expand all Loading... | |
29 #include "chrome/browser/ui/gtk/omnibox/omnibox_popup_view_gtk.h" | 29 #include "chrome/browser/ui/gtk/omnibox/omnibox_popup_view_gtk.h" |
30 #include "chrome/browser/ui/gtk/view_id_util.h" | 30 #include "chrome/browser/ui/gtk/view_id_util.h" |
31 #include "chrome/browser/ui/omnibox/omnibox_edit_controller.h" | 31 #include "chrome/browser/ui/omnibox/omnibox_edit_controller.h" |
32 #include "chrome/browser/ui/omnibox/omnibox_edit_model.h" | 32 #include "chrome/browser/ui/omnibox/omnibox_edit_model.h" |
33 #include "chrome/browser/ui/omnibox/omnibox_popup_model.h" | 33 #include "chrome/browser/ui/omnibox/omnibox_popup_model.h" |
34 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 34 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
35 #include "chrome/browser/ui/toolbar/toolbar_model.h" | 35 #include "chrome/browser/ui/toolbar/toolbar_model.h" |
36 #include "chrome/common/chrome_notification_types.h" | 36 #include "chrome/common/chrome_notification_types.h" |
37 #include "content/public/browser/notification_source.h" | 37 #include "content/public/browser/notification_source.h" |
38 #include "content/public/browser/web_contents.h" | 38 #include "content/public/browser/web_contents.h" |
39 #include "extensions/common/constants.h" | |
39 #include "googleurl/src/gurl.h" | 40 #include "googleurl/src/gurl.h" |
40 #include "grit/generated_resources.h" | 41 #include "grit/generated_resources.h" |
41 #include "net/base/escape.h" | 42 #include "net/base/escape.h" |
42 #include "third_party/undoview/undo_view.h" | 43 #include "third_party/undoview/undo_view.h" |
43 #include "ui/base/clipboard/scoped_clipboard_writer.h" | 44 #include "ui/base/clipboard/scoped_clipboard_writer.h" |
44 #include "ui/base/dragdrop/drag_drop_types.h" | 45 #include "ui/base/dragdrop/drag_drop_types.h" |
45 #include "ui/base/dragdrop/gtk_dnd_util.h" | 46 #include "ui/base/dragdrop/gtk_dnd_util.h" |
46 #include "ui/base/gtk/gtk_compat.h" | 47 #include "ui/base/gtk/gtk_compat.h" |
47 #include "ui/base/gtk/gtk_hig_constants.h" | 48 #include "ui/base/gtk/gtk_hig_constants.h" |
48 #include "ui/base/gtk/menu_label_accelerator_util.h" | 49 #include "ui/base/gtk/menu_label_accelerator_util.h" |
(...skipping 1595 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1644 } | 1645 } |
1645 // See whether the contents are a URL with a non-empty host portion, which we | 1646 // See whether the contents are a URL with a non-empty host portion, which we |
1646 // should emphasize. To check for a URL, rather than using the type returned | 1647 // should emphasize. To check for a URL, rather than using the type returned |
1647 // by Parse(), ask the model, which will check the desired page transition for | 1648 // by Parse(), ask the model, which will check the desired page transition for |
1648 // this input. This can tell us whether an UNKNOWN input string is going to | 1649 // this input. This can tell us whether an UNKNOWN input string is going to |
1649 // be treated as a search or a navigation, and is the same method the Paste | 1650 // be treated as a search or a navigation, and is the same method the Paste |
1650 // And Go system uses. | 1651 // And Go system uses. |
1651 url_parse::Component scheme, host; | 1652 url_parse::Component scheme, host; |
1652 string16 text(GetText()); | 1653 string16 text(GetText()); |
1653 AutocompleteInput::ParseForEmphasizeComponents(text, &scheme, &host); | 1654 AutocompleteInput::ParseForEmphasizeComponents(text, &scheme, &host); |
1654 const bool emphasize = model()->CurrentTextIsURL() && (host.len > 0); | |
1655 | 1655 |
1656 // Set the baseline emphasis. | 1656 // Set the baseline emphasis. |
1657 GtkTextIter start, end; | 1657 GtkTextIter start, end; |
1658 GetTextBufferBounds(&start, &end); | 1658 GetTextBufferBounds(&start, &end); |
1659 gtk_text_buffer_remove_all_tags(text_buffer_, &start, &end); | 1659 gtk_text_buffer_remove_all_tags(text_buffer_, &start, &end); |
1660 if (emphasize) { | 1660 bool grey_out_url = GetText().substr(scheme.begin, scheme.len) == |
Peter Kasting
2013/04/11 23:10:40
Use |text| here instead of GetText().
Patrick Riordan
2013/04/11 23:27:38
Done.
| |
1661 gtk_text_buffer_apply_tag(text_buffer_, faded_text_tag_, &start, &end); | 1661 UTF8ToUTF16(extensions::kExtensionScheme); |
1662 bool grey_base = model()->CurrentTextIsURL() && | |
1663 (host.is_nonempty() || grey_out_url); | |
1664 gtk_text_buffer_apply_tag( | |
1665 text_buffer_, grey_base ? faded_text_tag_ : normal_text_tag_ , &start, | |
1666 &end); | |
1662 | 1667 |
1668 if (grey_base && !grey_out_url) { | |
1663 // We've found a host name, give it more emphasis. | 1669 // We've found a host name, give it more emphasis. |
1664 gtk_text_buffer_get_iter_at_line_index(text_buffer_, &start, 0, | 1670 gtk_text_buffer_get_iter_at_line_index( |
1665 GetUTF8Offset(text, | 1671 text_buffer_, &start, 0, GetUTF8Offset(text, host.begin)); |
1666 host.begin)); | 1672 gtk_text_buffer_get_iter_at_line_index( |
1667 gtk_text_buffer_get_iter_at_line_index(text_buffer_, &end, 0, | 1673 text_buffer_, &end, 0, GetUTF8Offset(text, host.end())); |
1668 GetUTF8Offset(text, | |
1669 host.end())); | |
1670 | |
1671 gtk_text_buffer_apply_tag(text_buffer_, normal_text_tag_, &start, &end); | |
1672 } else { | |
1673 gtk_text_buffer_apply_tag(text_buffer_, normal_text_tag_, &start, &end); | 1674 gtk_text_buffer_apply_tag(text_buffer_, normal_text_tag_, &start, &end); |
1674 } | 1675 } |
1675 | 1676 |
1676 strikethrough_ = CharRange(); | 1677 strikethrough_ = CharRange(); |
1677 // Emphasize the scheme for security UI display purposes (if necessary). | 1678 // Emphasize the scheme for security UI display purposes (if necessary). |
1678 if (!model()->user_input_in_progress() && model()->CurrentTextIsURL() && | 1679 if (!model()->user_input_in_progress() && model()->CurrentTextIsURL() && |
1679 scheme.is_nonempty() && (security_level_ != ToolbarModel::NONE)) { | 1680 scheme.is_nonempty() && (security_level_ != ToolbarModel::NONE)) { |
1680 CharRange scheme_range = CharRange(GetUTF8Offset(text, scheme.begin), | 1681 CharRange scheme_range = CharRange(GetUTF8Offset(text, scheme.begin), |
1681 GetUTF8Offset(text, scheme.end())); | 1682 GetUTF8Offset(text, scheme.end())); |
1682 ItersFromCharRange(scheme_range, &start, &end); | 1683 ItersFromCharRange(scheme_range, &start, &end); |
(...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2155 void OmniboxViewGtk::AdjustVerticalAlignmentOfInstantView() { | 2156 void OmniboxViewGtk::AdjustVerticalAlignmentOfInstantView() { |
2156 // By default, GtkTextView layouts an anchored child widget just above the | 2157 // By default, GtkTextView layouts an anchored child widget just above the |
2157 // baseline, so we need to move the |instant_view_| down to make sure it | 2158 // baseline, so we need to move the |instant_view_| down to make sure it |
2158 // has the same baseline as the |text_view_|. | 2159 // has the same baseline as the |text_view_|. |
2159 PangoLayout* layout = gtk_label_get_layout(GTK_LABEL(instant_view_)); | 2160 PangoLayout* layout = gtk_label_get_layout(GTK_LABEL(instant_view_)); |
2160 int height; | 2161 int height; |
2161 pango_layout_get_size(layout, NULL, &height); | 2162 pango_layout_get_size(layout, NULL, &height); |
2162 int baseline = pango_layout_get_baseline(layout); | 2163 int baseline = pango_layout_get_baseline(layout); |
2163 g_object_set(instant_anchor_tag_, "rise", baseline - height, NULL); | 2164 g_object_set(instant_anchor_tag_, "rise", baseline - height, NULL); |
2164 } | 2165 } |
OLD | NEW |