Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 860 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 871 int OmniboxViewGtk::OnPerformDrop( | 871 int OmniboxViewGtk::OnPerformDrop( |
| 872 const views::DropTargetEvent& event) { | 872 const views::DropTargetEvent& event) { |
| 873 string16 text; | 873 string16 text; |
| 874 const ui::OSExchangeData& data = event.data(); | 874 const ui::OSExchangeData& data = event.data(); |
| 875 if (data.HasURL()) { | 875 if (data.HasURL()) { |
| 876 GURL url; | 876 GURL url; |
| 877 string16 title; | 877 string16 title; |
| 878 if (data.GetURLAndTitle(&url, &title)) | 878 if (data.GetURLAndTitle(&url, &title)) |
| 879 text = UTF8ToUTF16(url.spec()); | 879 text = UTF8ToUTF16(url.spec()); |
| 880 } else { | 880 } else { |
| 881 string16 data_string; | 881 string16 data_string; |
|
Peter Kasting
2011/11/21 21:23:43
Nit: This whole block can be collapsed to just:
d
SanjoyPal
2011/11/22 07:02:14
Done.
| |
| 882 if (data.GetString(&data_string)) | 882 if (data.GetString(&data_string)) |
| 883 text = CollapseWhitespace(data_string, true); | 883 text = CollapseWhitespace(data_string, true); |
| 884 } | 884 } |
| 885 | 885 |
| 886 if (!text.empty() && OnPerformDropImpl(text)) | 886 if (!text.empty() && OnPerformDropImpl(text)) |
| 887 return CopyOrLinkDragOperation(event.source_operations()); | 887 return CopyOrLinkDragOperation(event.source_operations()); |
| 888 | 888 |
| 889 return ui::DragDropTypes::DRAG_NONE; | 889 return ui::DragDropTypes::DRAG_NONE; |
| 890 } | 890 } |
| 891 #endif // defined(TOOLKIT_VIEWS) | 891 #endif // defined(TOOLKIT_VIEWS) |
| (...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1437 gtk_widget_set_sensitive(search_engine_menuitem, | 1437 gtk_widget_set_sensitive(search_engine_menuitem, |
| 1438 command_updater_->IsCommandEnabled(IDC_EDIT_SEARCH_ENGINES)); | 1438 command_updater_->IsCommandEnabled(IDC_EDIT_SEARCH_ENGINES)); |
| 1439 gtk_widget_show(search_engine_menuitem); | 1439 gtk_widget_show(search_engine_menuitem); |
| 1440 | 1440 |
| 1441 // We need to update the paste and go controller before we know what text | 1441 // We need to update the paste and go controller before we know what text |
| 1442 // to show. We could do this all asynchronously, but it would be elaborate | 1442 // to show. We could do this all asynchronously, but it would be elaborate |
| 1443 // because we'd have to account for multiple menus showing, getting called | 1443 // because we'd have to account for multiple menus showing, getting called |
| 1444 // back after shutdown, and similar issues. | 1444 // back after shutdown, and similar issues. |
| 1445 GtkClipboard* x_clipboard = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD); | 1445 GtkClipboard* x_clipboard = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD); |
| 1446 gchar* text = gtk_clipboard_wait_for_text(x_clipboard); | 1446 gchar* text = gtk_clipboard_wait_for_text(x_clipboard); |
| 1447 string16 text_wstr = UTF8ToUTF16(text ? text : ""); | 1447 string16 sanitized_text(text ? |
| 1448 CollapseWhitespace(StripJavascriptSchemas(UTF8ToUTF16(text)), true) : | |
|
Peter Kasting
2011/11/21 21:23:43
Why did you reverse the order of the calls here?
SanjoyPal
2011/11/22 07:02:14
Done.
| |
| 1449 string16()); | |
| 1448 g_free(text); | 1450 g_free(text); |
| 1449 | 1451 |
| 1450 // Paste and Go menu item. | 1452 // Paste and Go menu item. |
| 1451 GtkWidget* paste_go_menuitem = gtk_menu_item_new_with_mnemonic( | 1453 GtkWidget* paste_go_menuitem = gtk_menu_item_new_with_mnemonic( |
| 1452 gfx::ConvertAcceleratorsFromWindowsStyle( | 1454 gfx::ConvertAcceleratorsFromWindowsStyle( |
| 1453 l10n_util::GetStringUTF8(model_->is_paste_and_search() ? | 1455 l10n_util::GetStringUTF8(model_->is_paste_and_search() ? |
| 1454 IDS_PASTE_AND_SEARCH : IDS_PASTE_AND_GO)).c_str()); | 1456 IDS_PASTE_AND_SEARCH : IDS_PASTE_AND_GO)).c_str()); |
| 1455 gtk_menu_shell_append(GTK_MENU_SHELL(menu), paste_go_menuitem); | 1457 gtk_menu_shell_append(GTK_MENU_SHELL(menu), paste_go_menuitem); |
| 1456 g_signal_connect(paste_go_menuitem, "activate", | 1458 g_signal_connect(paste_go_menuitem, "activate", |
| 1457 G_CALLBACK(HandlePasteAndGoThunk), this); | 1459 G_CALLBACK(HandlePasteAndGoThunk), this); |
| 1458 gtk_widget_set_sensitive(paste_go_menuitem, | 1460 gtk_widget_set_sensitive(paste_go_menuitem, |
| 1459 model_->CanPasteAndGo(text_wstr)); | 1461 model_->CanPasteAndGo(sanitized_text)); |
|
Peter Kasting
2011/11/21 21:23:43
Why did you move this call back down here since th
SanjoyPal
2011/11/22 07:02:14
Done.
| |
| 1460 gtk_widget_show(paste_go_menuitem); | 1462 gtk_widget_show(paste_go_menuitem); |
| 1461 | 1463 |
| 1462 g_signal_connect(menu, "deactivate", | 1464 g_signal_connect(menu, "deactivate", |
| 1463 G_CALLBACK(HandlePopupMenuDeactivateThunk), this); | 1465 G_CALLBACK(HandlePopupMenuDeactivateThunk), this); |
| 1464 } | 1466 } |
| 1465 | 1467 |
| 1466 void OmniboxViewGtk::HandleEditSearchEngines(GtkWidget* sender) { | 1468 void OmniboxViewGtk::HandleEditSearchEngines(GtkWidget* sender) { |
| 1467 command_updater_->ExecuteCommand(IDC_EDIT_SEARCH_ENGINES); | 1469 command_updater_->ExecuteCommand(IDC_EDIT_SEARCH_ENGINES); |
| 1468 } | 1470 } |
| 1469 | 1471 |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1648 | 1650 |
| 1649 const gchar* p = text; | 1651 const gchar* p = text; |
| 1650 while (*p && (p - text) < len) { | 1652 while (*p && (p - text) < len) { |
| 1651 gunichar c = g_utf8_get_char(p); | 1653 gunichar c = g_utf8_get_char(p); |
| 1652 const gchar* next = g_utf8_next_char(p); | 1654 const gchar* next = g_utf8_next_char(p); |
| 1653 | 1655 |
| 1654 // 0x200B is Zero Width Space, which is inserted just before the instant | 1656 // 0x200B is Zero Width Space, which is inserted just before the instant |
| 1655 // anchor for working around the GtkTextView's misalignment bug. | 1657 // anchor for working around the GtkTextView's misalignment bug. |
| 1656 // This character might be captured and inserted into the content by undo | 1658 // This character might be captured and inserted into the content by undo |
| 1657 // manager, so we need to filter it out here. | 1659 // manager, so we need to filter it out here. |
| 1658 if (c != L'\n' && c != L'\r' && c != L'\t' && c != 0x200B) | 1660 if (c != L'\n' && c != L'\r' && c != L'\t' && c != 0x200B) |
|
Peter Kasting
2011/11/21 21:23:43
Seems like we should remove the first three checks
SanjoyPal
2011/11/22 07:02:14
It was hitting when pressing single keys.
Done.
| |
| 1659 filtered_text.append(p, next); | 1661 filtered_text.append(p, next); |
| 1660 | 1662 |
| 1661 p = next; | 1663 p = next; |
| 1662 } | 1664 } |
| 1663 | 1665 |
| 1664 if (filtered_text.length()) { | 1666 const std::string sanitized_text = |
| 1667 UTF16ToUTF8(StripJavascriptSchemas(UTF8ToUTF16(filtered_text))); | |
| 1668 if (sanitized_text.length()) { | |
|
Peter Kasting
2011/11/21 21:23:43
Nit: Change to using !empty()
SanjoyPal
2011/11/22 07:02:14
Done.
| |
| 1665 // Avoid inserting the text after the instant anchor. | 1669 // Avoid inserting the text after the instant anchor. |
| 1666 ValidateTextBufferIter(location); | 1670 ValidateTextBufferIter(location); |
| 1667 | 1671 |
| 1668 // Call the default handler to insert filtered text. | 1672 // Call the default handler to insert filtered text. |
| 1669 GtkTextBufferClass* klass = GTK_TEXT_BUFFER_GET_CLASS(buffer); | 1673 GtkTextBufferClass* klass = GTK_TEXT_BUFFER_GET_CLASS(buffer); |
| 1670 klass->insert_text(buffer, location, filtered_text.data(), | 1674 klass->insert_text(buffer, location, sanitized_text.data(), |
| 1671 static_cast<gint>(filtered_text.length())); | 1675 static_cast<gint>(sanitized_text.length())); |
| 1672 } | 1676 } |
| 1673 | 1677 |
| 1674 // Stop propagating the signal emission to prevent the default handler from | 1678 // Stop propagating the signal emission to prevent the default handler from |
| 1675 // being called again. | 1679 // being called again. |
| 1676 static guint signal_id = g_signal_lookup("insert-text", GTK_TYPE_TEXT_BUFFER); | 1680 static guint signal_id = g_signal_lookup("insert-text", GTK_TYPE_TEXT_BUFFER); |
| 1677 g_signal_stop_emission(buffer, signal_id, 0); | 1681 g_signal_stop_emission(buffer, signal_id, 0); |
| 1678 } | 1682 } |
| 1679 | 1683 |
| 1680 void OmniboxViewGtk::HandleBackSpace(GtkWidget* sender) { | 1684 void OmniboxViewGtk::HandleBackSpace(GtkWidget* sender) { |
| 1681 // Checks if it's currently in keyword search mode. | 1685 // Checks if it's currently in keyword search mode. |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1788 0); | 1792 0); |
| 1789 | 1793 |
| 1790 if (!copy && gtk_text_view_get_editable(GTK_TEXT_VIEW(text_view_))) | 1794 if (!copy && gtk_text_view_get_editable(GTK_TEXT_VIEW(text_view_))) |
| 1791 gtk_text_buffer_delete_selection(text_buffer_, true, true); | 1795 gtk_text_buffer_delete_selection(text_buffer_, true, true); |
| 1792 } | 1796 } |
| 1793 | 1797 |
| 1794 OwnPrimarySelection(UTF16ToUTF8(text)); | 1798 OwnPrimarySelection(UTF16ToUTF8(text)); |
| 1795 } | 1799 } |
| 1796 | 1800 |
| 1797 bool OmniboxViewGtk::OnPerformDropImpl(const string16& text) { | 1801 bool OmniboxViewGtk::OnPerformDropImpl(const string16& text) { |
| 1798 if (model_->CanPasteAndGo(CollapseWhitespace(text, true))) { | 1802 if (model_->CanPasteAndGo(CollapseWhitespace(text, true))) { |
|
Peter Kasting
2011/11/21 21:23:43
Nit: This needs a StripJavaScriptSchemas() call in
SanjoyPal
2011/11/22 07:02:14
Done.
| |
| 1799 model_->PasteAndGo(); | 1803 model_->PasteAndGo(); |
| 1800 return true; | 1804 return true; |
| 1801 } | 1805 } |
| 1802 | 1806 |
| 1803 return false; | 1807 return false; |
| 1804 } | 1808 } |
| 1805 | 1809 |
| 1806 gfx::Font OmniboxViewGtk::GetFont() { | 1810 gfx::Font OmniboxViewGtk::GetFont() { |
| 1807 #if defined(TOOLKIT_VIEWS) | 1811 #if defined(TOOLKIT_VIEWS) |
| 1808 bool use_gtk = false; | 1812 bool use_gtk = false; |
| (...skipping 585 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2394 | 2398 |
| 2395 // Make all the children of the widget visible. NOTE: this won't display | 2399 // Make all the children of the widget visible. NOTE: this won't display |
| 2396 // anything, it just toggles the visible flag. | 2400 // anything, it just toggles the visible flag. |
| 2397 gtk_widget_show_all(omnibox_view->GetNativeView()); | 2401 gtk_widget_show_all(omnibox_view->GetNativeView()); |
| 2398 // Hide the widget. NativeViewHostGtk will make it visible again as necessary. | 2402 // Hide the widget. NativeViewHostGtk will make it visible again as necessary. |
| 2399 gtk_widget_hide(omnibox_view->GetNativeView()); | 2403 gtk_widget_hide(omnibox_view->GetNativeView()); |
| 2400 | 2404 |
| 2401 return omnibox_view; | 2405 return omnibox_view; |
| 2402 } | 2406 } |
| 2403 #endif | 2407 #endif |
| OLD | NEW |