Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(31)

Side by Side Diff: chrome/browser/ui/gtk/omnibox/omnibox_view_gtk.cc

Issue 10704074: "Paste and go" state was being calculated wrong on views (at least). Fix by making this calculatio… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 1300 matching lines...) Expand 10 before | Expand all | Expand 10 after
1311 GtkWidget* search_engine_menuitem = gtk_menu_item_new_with_mnemonic( 1311 GtkWidget* search_engine_menuitem = gtk_menu_item_new_with_mnemonic(
1312 ui::ConvertAcceleratorsFromWindowsStyle( 1312 ui::ConvertAcceleratorsFromWindowsStyle(
1313 l10n_util::GetStringUTF8(IDS_EDIT_SEARCH_ENGINES)).c_str()); 1313 l10n_util::GetStringUTF8(IDS_EDIT_SEARCH_ENGINES)).c_str());
1314 gtk_menu_shell_append(GTK_MENU_SHELL(menu), search_engine_menuitem); 1314 gtk_menu_shell_append(GTK_MENU_SHELL(menu), search_engine_menuitem);
1315 g_signal_connect(search_engine_menuitem, "activate", 1315 g_signal_connect(search_engine_menuitem, "activate",
1316 G_CALLBACK(HandleEditSearchEnginesThunk), this); 1316 G_CALLBACK(HandleEditSearchEnginesThunk), this);
1317 gtk_widget_set_sensitive(search_engine_menuitem, 1317 gtk_widget_set_sensitive(search_engine_menuitem,
1318 command_updater_->IsCommandEnabled(IDC_EDIT_SEARCH_ENGINES)); 1318 command_updater_->IsCommandEnabled(IDC_EDIT_SEARCH_ENGINES));
1319 gtk_widget_show(search_engine_menuitem); 1319 gtk_widget_show(search_engine_menuitem);
1320 1320
1321 // We need to update the paste and go controller before we know what text
1322 // to show. We could do this all asynchronously, but it would be elaborate
1323 // because we'd have to account for multiple menus showing, getting called
1324 // back after shutdown, and similar issues.
1325 GtkClipboard* x_clipboard = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD);
1326 gchar* text = gtk_clipboard_wait_for_text(x_clipboard);
1327 string16 sanitized_text(text ?
1328 StripJavascriptSchemas(CollapseWhitespace(UTF8ToUTF16(text), true)) :
1329 string16());
1330 g_free(text);
1331
1332 // Paste and Go menu item. Note that CanPasteAndGo() needs to be called
1333 // before is_paste_and_search() in order to set up the paste-and-go state.
1334 bool can_paste_and_go = model_->CanPasteAndGo(sanitized_text);
1335 GtkWidget* paste_go_menuitem = gtk_menu_item_new_with_mnemonic(
1336 ui::ConvertAcceleratorsFromWindowsStyle(
1337 l10n_util::GetStringUTF8(model_->is_paste_and_search() ?
1338 IDS_PASTE_AND_SEARCH : IDS_PASTE_AND_GO)).c_str());
1339
1340 // Detect the Paste menu item by searching for the one that 1321 // Detect the Paste menu item by searching for the one that
1341 // uses the stock Paste label (i.e. gtk-paste). 1322 // uses the stock Paste label (i.e. gtk-paste).
1342 string16 stock_paste_label(UTF8ToUTF16(GTK_STOCK_PASTE)); 1323 string16 stock_paste_label(UTF8ToUTF16(GTK_STOCK_PASTE));
1343 GList* list = gtk_container_get_children(GTK_CONTAINER(menu)); 1324 GList* list = gtk_container_get_children(GTK_CONTAINER(menu));
1344 guint index = 1; 1325 guint index = 1;
1345 for (GList* item = list; item != NULL; item = item->next, ++index) { 1326 for (GList* item = list; item != NULL; item = item->next, ++index) {
1346 if (GTK_IS_IMAGE_MENU_ITEM(item->data)) { 1327 if (GTK_IS_IMAGE_MENU_ITEM(item->data)) {
1347 gboolean is_stock = gtk_image_menu_item_get_use_stock( 1328 gboolean is_stock = gtk_image_menu_item_get_use_stock(
1348 GTK_IMAGE_MENU_ITEM(item->data)); 1329 GTK_IMAGE_MENU_ITEM(item->data));
1349 if (is_stock) { 1330 if (is_stock) {
1350 string16 menu_item_label 1331 string16 menu_item_label
1351 (UTF8ToUTF16(gtk_menu_item_get_label(GTK_MENU_ITEM(item->data)))); 1332 (UTF8ToUTF16(gtk_menu_item_get_label(GTK_MENU_ITEM(item->data))));
1352 if (menu_item_label == stock_paste_label) { 1333 if (menu_item_label == stock_paste_label) {
1353 break; 1334 break;
1354 } 1335 }
1355 } 1336 }
1356 } 1337 }
1357 } 1338 }
1358 g_list_free(list); 1339 g_list_free(list);
1359 1340
1360 // If we don't find the stock Paste menu item, 1341 // If we don't find the stock Paste menu item,
1361 // the Paste and Go item will be appended at the end of the popup menu. 1342 // the Paste and Go item will be appended at the end of the popup menu.
1343 GtkClipboard* x_clipboard = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD);
1344 gchar* text = gtk_clipboard_wait_for_text(x_clipboard);
1345 string16 sanitized_text_for_paste_and_go_(text ?
Elliot Glaysher 2012/07/09 16:29:08 Is this supposed to be a member variable? It's dec
Peter Kasting 2012/07/09 17:17:22 Yes. Fixed.
1346 StripJavascriptSchemas(CollapseWhitespace(UTF8ToUTF16(text), true)) :
1347 string16());
1348 g_free(text);
1349 GtkWidget* paste_go_menuitem = gtk_menu_item_new_with_mnemonic(
1350 ui::ConvertAcceleratorsFromWindowsStyle(l10n_util::GetStringUTF8(
1351 model_->IsPasteAndSearch(sanitized_text_for_paste_and_go_) ?
1352 IDS_PASTE_AND_SEARCH : IDS_PASTE_AND_GO)).c_str());
1362 gtk_menu_shell_insert(GTK_MENU_SHELL(menu), paste_go_menuitem, index); 1353 gtk_menu_shell_insert(GTK_MENU_SHELL(menu), paste_go_menuitem, index);
1363 g_signal_connect(paste_go_menuitem, "activate", 1354 g_signal_connect(paste_go_menuitem, "activate",
1364 G_CALLBACK(HandlePasteAndGoThunk), this); 1355 G_CALLBACK(HandlePasteAndGoThunk), this);
1365 gtk_widget_set_sensitive(paste_go_menuitem, can_paste_and_go); 1356 gtk_widget_set_sensitive(paste_go_menuitem,
1357 model_->CanPasteAndGo(sanitized_text_for_paste_and_go_));
1366 gtk_widget_show(paste_go_menuitem); 1358 gtk_widget_show(paste_go_menuitem);
1367 1359
1368 g_signal_connect(menu, "deactivate", 1360 g_signal_connect(menu, "deactivate",
1369 G_CALLBACK(HandlePopupMenuDeactivateThunk), this); 1361 G_CALLBACK(HandlePopupMenuDeactivateThunk), this);
1370 } 1362 }
1371 1363
1372 void OmniboxViewGtk::HandleEditSearchEngines(GtkWidget* sender) { 1364 void OmniboxViewGtk::HandleEditSearchEngines(GtkWidget* sender) {
1373 command_updater_->ExecuteCommand(IDC_EDIT_SEARCH_ENGINES); 1365 command_updater_->ExecuteCommand(IDC_EDIT_SEARCH_ENGINES);
1374 } 1366 }
1375 1367
1376 void OmniboxViewGtk::HandlePasteAndGo(GtkWidget* sender) { 1368 void OmniboxViewGtk::HandlePasteAndGo(GtkWidget* sender) {
1377 model_->PasteAndGo(); 1369 model_->PasteAndGo(sanitized_text_for_paste_and_go_);
1378 } 1370 }
1379 1371
1380 void OmniboxViewGtk::HandleMarkSet(GtkTextBuffer* buffer, 1372 void OmniboxViewGtk::HandleMarkSet(GtkTextBuffer* buffer,
1381 GtkTextIter* location, 1373 GtkTextIter* location,
1382 GtkTextMark* mark) { 1374 GtkTextMark* mark) {
1383 if (!text_buffer_ || buffer != text_buffer_) 1375 if (!text_buffer_ || buffer != text_buffer_)
1384 return; 1376 return;
1385 1377
1386 if (mark != gtk_text_buffer_get_insert(text_buffer_) && 1378 if (mark != gtk_text_buffer_get_insert(text_buffer_) &&
1387 mark != gtk_text_buffer_get_selection_bound(text_buffer_)) { 1379 mark != gtk_text_buffer_get_selection_bound(text_buffer_)) {
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
1687 0); 1679 0);
1688 1680
1689 if (!copy && gtk_text_view_get_editable(GTK_TEXT_VIEW(text_view_))) 1681 if (!copy && gtk_text_view_get_editable(GTK_TEXT_VIEW(text_view_)))
1690 gtk_text_buffer_delete_selection(text_buffer_, true, true); 1682 gtk_text_buffer_delete_selection(text_buffer_, true, true);
1691 } 1683 }
1692 1684
1693 OwnPrimarySelection(UTF16ToUTF8(text)); 1685 OwnPrimarySelection(UTF16ToUTF8(text));
1694 } 1686 }
1695 1687
1696 bool OmniboxViewGtk::OnPerformDropImpl(const string16& text) { 1688 bool OmniboxViewGtk::OnPerformDropImpl(const string16& text) {
1697 if (model_->CanPasteAndGo(StripJavascriptSchemas( 1689 string16 sanitized_string(StripJavascriptSchemas(
1698 CollapseWhitespace(text, true)))) { 1690 CollapseWhitespace(text, true)));
1699 model_->PasteAndGo(); 1691 if (model_->CanPasteAndGo(sanitized_string)) {
1692 model_->PasteAndGo(sanitized_string);
1700 return true; 1693 return true;
1701 } 1694 }
1702 1695
1703 return false; 1696 return false;
1704 } 1697 }
1705 1698
1706 gfx::Font OmniboxViewGtk::GetFont() { 1699 gfx::Font OmniboxViewGtk::GetFont() {
1707 bool use_gtk = theme_service_->UsingNativeTheme(); 1700 bool use_gtk = theme_service_->UsingNativeTheme();
1708 if (use_gtk) { 1701 if (use_gtk) {
1709 // If we haven't initialized the text view yet, just create a temporary one 1702 // If we haven't initialized the text view yet, just create a temporary one
(...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after
2247 void OmniboxViewGtk::AdjustVerticalAlignmentOfInstantView() { 2240 void OmniboxViewGtk::AdjustVerticalAlignmentOfInstantView() {
2248 // By default, GtkTextView layouts an anchored child widget just above the 2241 // By default, GtkTextView layouts an anchored child widget just above the
2249 // baseline, so we need to move the |instant_view_| down to make sure it 2242 // baseline, so we need to move the |instant_view_| down to make sure it
2250 // has the same baseline as the |text_view_|. 2243 // has the same baseline as the |text_view_|.
2251 PangoLayout* layout = gtk_label_get_layout(GTK_LABEL(instant_view_)); 2244 PangoLayout* layout = gtk_label_get_layout(GTK_LABEL(instant_view_));
2252 int height; 2245 int height;
2253 pango_layout_get_size(layout, NULL, &height); 2246 pango_layout_get_size(layout, NULL, &height);
2254 int baseline = pango_layout_get_baseline(layout); 2247 int baseline = pango_layout_get_baseline(layout);
2255 g_object_set(instant_anchor_tag_, "rise", baseline - height, NULL); 2248 g_object_set(instant_anchor_tag_, "rise", baseline - height, NULL);
2256 } 2249 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/gtk/omnibox/omnibox_view_gtk.h ('k') | chrome/browser/ui/omnibox/omnibox_edit_model.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698