Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 137 gtk_text_buffer_get_iter_at_mark(buffer, &insert, | 137 gtk_text_buffer_get_iter_at_mark(buffer, &insert, |
| 138 gtk_text_buffer_get_insert(buffer)); | 138 gtk_text_buffer_get_insert(buffer)); |
| 139 gtk_text_buffer_get_iter_at_mark(buffer, &selection_bound, | 139 gtk_text_buffer_get_iter_at_mark(buffer, &selection_bound, |
| 140 gtk_text_buffer_get_selection_bound(buffer)); | 140 gtk_text_buffer_get_selection_bound(buffer)); |
| 141 | 141 |
| 142 if (!gtk_text_iter_equal(&insert, &selection_bound)) { | 142 if (!gtk_text_iter_equal(&insert, &selection_bound)) { |
| 143 gtk_text_buffer_move_mark(buffer, | 143 gtk_text_buffer_move_mark(buffer, |
| 144 gtk_text_buffer_get_selection_bound(buffer), | 144 gtk_text_buffer_get_selection_bound(buffer), |
| 145 &insert); | 145 &insert); |
| 146 } | 146 } |
| 147 } | 147 } |
|
Evan Stade
2012/09/05 21:07:17
blank line and function docs
dominich
2012/09/05 21:21:39
Done.
| |
| 148 guint GetPopupMenuIndexForStockLabel(const char* label, GtkMenu* menu) { | |
| 149 string16 stock_label(UTF8ToUTF16(label)); | |
|
Evan Stade
2012/09/05 21:07:17
why do you convert to utf16 before comparison?
dominich
2012/09/05 21:21:39
It's what the original code was doing. It seemed s
Evan Stade
2012/09/05 22:11:50
well then let's change it.
dominich
2012/09/05 23:35:34
Done.
| |
| 150 GList* list = gtk_container_get_children(GTK_CONTAINER(menu)); | |
| 151 guint index = 1; | |
| 152 for (GList* item = list; item != NULL; item = item->next, ++index) { | |
| 153 if (GTK_IS_IMAGE_MENU_ITEM(item->data)) { | |
| 154 gboolean is_stock = gtk_image_menu_item_get_use_stock( | |
| 155 GTK_IMAGE_MENU_ITEM(item->data)); | |
| 156 if (is_stock) { | |
| 157 string16 menu_item_label = UTF8ToUTF16( | |
| 158 gtk_menu_item_get_label(GTK_MENU_ITEM(item->data))); | |
| 159 if (menu_item_label == stock_label) | |
| 160 break; | |
| 161 } | |
| 162 } | |
| 163 } | |
| 164 g_list_free(list); | |
| 165 return index; | |
| 166 } | |
| 148 | 167 |
| 149 } // namespace | 168 } // namespace |
| 150 | 169 |
| 151 OmniboxViewGtk::OmniboxViewGtk(OmniboxEditController* controller, | 170 OmniboxViewGtk::OmniboxViewGtk(OmniboxEditController* controller, |
| 152 ToolbarModel* toolbar_model, | 171 ToolbarModel* toolbar_model, |
| 153 Browser* browser, | 172 Browser* browser, |
| 154 CommandUpdater* command_updater, | 173 CommandUpdater* command_updater, |
| 155 bool popup_window_mode, | 174 bool popup_window_mode, |
| 156 GtkWidget* location_bar) | 175 GtkWidget* location_bar) |
| 157 : OmniboxView(browser->profile(), controller, toolbar_model, | 176 : OmniboxView(browser->profile(), controller, toolbar_model, |
| (...skipping 1092 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1250 GtkWidget* search_engine_menuitem = gtk_menu_item_new_with_mnemonic( | 1269 GtkWidget* search_engine_menuitem = gtk_menu_item_new_with_mnemonic( |
| 1251 ui::ConvertAcceleratorsFromWindowsStyle( | 1270 ui::ConvertAcceleratorsFromWindowsStyle( |
| 1252 l10n_util::GetStringUTF8(IDS_EDIT_SEARCH_ENGINES)).c_str()); | 1271 l10n_util::GetStringUTF8(IDS_EDIT_SEARCH_ENGINES)).c_str()); |
| 1253 gtk_menu_shell_append(GTK_MENU_SHELL(menu), search_engine_menuitem); | 1272 gtk_menu_shell_append(GTK_MENU_SHELL(menu), search_engine_menuitem); |
| 1254 g_signal_connect(search_engine_menuitem, "activate", | 1273 g_signal_connect(search_engine_menuitem, "activate", |
| 1255 G_CALLBACK(HandleEditSearchEnginesThunk), this); | 1274 G_CALLBACK(HandleEditSearchEnginesThunk), this); |
| 1256 gtk_widget_set_sensitive(search_engine_menuitem, | 1275 gtk_widget_set_sensitive(search_engine_menuitem, |
| 1257 command_updater()->IsCommandEnabled(IDC_EDIT_SEARCH_ENGINES)); | 1276 command_updater()->IsCommandEnabled(IDC_EDIT_SEARCH_ENGINES)); |
| 1258 gtk_widget_show(search_engine_menuitem); | 1277 gtk_widget_show(search_engine_menuitem); |
| 1259 | 1278 |
| 1260 // Detect the Paste menu item by searching for the one that | |
| 1261 // uses the stock Paste label (i.e. gtk-paste). | |
| 1262 string16 stock_paste_label(UTF8ToUTF16(GTK_STOCK_PASTE)); | |
| 1263 GList* list = gtk_container_get_children(GTK_CONTAINER(menu)); | |
| 1264 guint index = 1; | |
| 1265 for (GList* item = list; item != NULL; item = item->next, ++index) { | |
| 1266 if (GTK_IS_IMAGE_MENU_ITEM(item->data)) { | |
| 1267 gboolean is_stock = gtk_image_menu_item_get_use_stock( | |
| 1268 GTK_IMAGE_MENU_ITEM(item->data)); | |
| 1269 if (is_stock) { | |
| 1270 string16 menu_item_label | |
| 1271 (UTF8ToUTF16(gtk_menu_item_get_label(GTK_MENU_ITEM(item->data)))); | |
| 1272 if (menu_item_label == stock_paste_label) { | |
| 1273 break; | |
| 1274 } | |
| 1275 } | |
| 1276 } | |
| 1277 } | |
| 1278 g_list_free(list); | |
| 1279 | |
| 1280 // If we don't find the stock Paste menu item, | |
| 1281 // the Paste and Go item will be appended at the end of the popup menu. | |
| 1282 GtkClipboard* x_clipboard = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD); | 1279 GtkClipboard* x_clipboard = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD); |
| 1283 gchar* text = gtk_clipboard_wait_for_text(x_clipboard); | 1280 gchar* text = gtk_clipboard_wait_for_text(x_clipboard); |
| 1284 sanitized_text_for_paste_and_go_ = text ? | 1281 sanitized_text_for_paste_and_go_ = text ? |
| 1285 StripJavascriptSchemas(CollapseWhitespace(UTF8ToUTF16(text), true)) : | 1282 StripJavascriptSchemas(CollapseWhitespace(UTF8ToUTF16(text), true)) : |
| 1286 string16(); | 1283 string16(); |
| 1287 g_free(text); | 1284 g_free(text); |
| 1285 | |
| 1286 // Copy URL menu item. | |
| 1287 if (toolbar_model()->WouldReplaceSearchURLWithSearchTerms() && | |
| 1288 !model()->user_input_in_progress()) { | |
| 1289 GtkWidget* copy_url_menuitem = gtk_menu_item_new_with_mnemonic( | |
| 1290 ui::ConvertAcceleratorsFromWindowsStyle( | |
| 1291 l10n_util::GetStringUTF8(IDS_COPY_URL)).c_str()); | |
| 1292 // If we don't find the stock Copy menu item, the Copy URL item will be | |
| 1293 // appended at the end of the popup menu. | |
| 1294 gtk_menu_shell_insert(GTK_MENU_SHELL(menu), copy_url_menuitem, | |
| 1295 GetPopupMenuIndexForStockLabel(GTK_STOCK_COPY, menu)); | |
| 1296 g_signal_connect(copy_url_menuitem, "activate", | |
| 1297 G_CALLBACK(HandleCopyURLClipboardThunk), this); | |
| 1298 gtk_widget_set_sensitive(copy_url_menuitem, | |
| 1299 command_updater()->IsCommandEnabled(IDC_COPY_URL)); | |
| 1300 gtk_widget_show(copy_url_menuitem); | |
| 1301 } | |
| 1302 | |
| 1303 // Paste and Go menu item. | |
| 1288 GtkWidget* paste_go_menuitem = gtk_menu_item_new_with_mnemonic( | 1304 GtkWidget* paste_go_menuitem = gtk_menu_item_new_with_mnemonic( |
| 1289 ui::ConvertAcceleratorsFromWindowsStyle(l10n_util::GetStringUTF8( | 1305 ui::ConvertAcceleratorsFromWindowsStyle(l10n_util::GetStringUTF8( |
| 1290 model()->IsPasteAndSearch(sanitized_text_for_paste_and_go_) ? | 1306 model()->IsPasteAndSearch(sanitized_text_for_paste_and_go_) ? |
| 1291 IDS_PASTE_AND_SEARCH : IDS_PASTE_AND_GO)).c_str()); | 1307 IDS_PASTE_AND_SEARCH : IDS_PASTE_AND_GO)).c_str()); |
| 1292 gtk_menu_shell_insert(GTK_MENU_SHELL(menu), paste_go_menuitem, index); | 1308 |
| 1309 // Detect the Paste and Copy menu items by searching for the ones that uses | |
| 1310 // the stock labels (i.e. gtk-paste and gtk-copy). | |
| 1311 | |
| 1312 // If we don't find the stock Paste menu item, the Paste and Go item will be | |
| 1313 // appended at the end of the popup menu. | |
| 1314 gtk_menu_shell_insert(GTK_MENU_SHELL(menu), paste_go_menuitem, | |
| 1315 GetPopupMenuIndexForStockLabel(GTK_STOCK_PASTE, menu)); | |
| 1316 | |
| 1293 g_signal_connect(paste_go_menuitem, "activate", | 1317 g_signal_connect(paste_go_menuitem, "activate", |
| 1294 G_CALLBACK(HandlePasteAndGoThunk), this); | 1318 G_CALLBACK(HandlePasteAndGoThunk), this); |
| 1295 gtk_widget_set_sensitive(paste_go_menuitem, | 1319 gtk_widget_set_sensitive(paste_go_menuitem, |
| 1296 model()->CanPasteAndGo(sanitized_text_for_paste_and_go_)); | 1320 model()->CanPasteAndGo(sanitized_text_for_paste_and_go_)); |
| 1297 gtk_widget_show(paste_go_menuitem); | 1321 gtk_widget_show(paste_go_menuitem); |
| 1298 | 1322 |
| 1299 g_signal_connect(menu, "deactivate", | 1323 g_signal_connect(menu, "deactivate", |
| 1300 G_CALLBACK(HandlePopupMenuDeactivateThunk), this); | 1324 G_CALLBACK(HandlePopupMenuDeactivateThunk), this); |
| 1301 } | 1325 } |
| 1302 | 1326 |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1570 if (handled) { | 1594 if (handled) { |
| 1571 static guint signal_id = g_signal_lookup("move-focus", GTK_TYPE_WIDGET); | 1595 static guint signal_id = g_signal_lookup("move-focus", GTK_TYPE_WIDGET); |
| 1572 g_signal_stop_emission(widget, signal_id, 0); | 1596 g_signal_stop_emission(widget, signal_id, 0); |
| 1573 } | 1597 } |
| 1574 } | 1598 } |
| 1575 | 1599 |
| 1576 void OmniboxViewGtk::HandleCopyClipboard(GtkWidget* sender) { | 1600 void OmniboxViewGtk::HandleCopyClipboard(GtkWidget* sender) { |
| 1577 HandleCopyOrCutClipboard(true); | 1601 HandleCopyOrCutClipboard(true); |
| 1578 } | 1602 } |
| 1579 | 1603 |
| 1604 void OmniboxViewGtk::HandleCopyURLClipboard(GtkWidget* sender) { | |
| 1605 const string16& text = toolbar_model()->GetText(false); | |
|
Evan Stade
2012/09/05 21:07:17
nit: I'd declare these in the order they're used.
dominich
2012/09/05 21:21:39
Done.
| |
| 1606 const GURL& url = toolbar_model()->GetURL(); | |
| 1607 | |
| 1608 BookmarkNodeData data; | |
| 1609 data.ReadFromTuple(url, text); | |
| 1610 data.WriteToClipboard(NULL); | |
|
Evan Stade
2012/09/05 21:07:17
why don't you pass the profile?
dominich
2012/09/05 21:21:39
the HandleCopyOrCutClipboard method below passes N
Evan Stade
2012/09/05 22:11:50
why does that one pass NULL?
dominich
2012/09/05 23:35:34
we don't want to write the profile path to the boo
Evan Stade
2012/09/06 01:35:03
can you add documentation to BookmarkNodeData::Wri
| |
| 1611 } | |
| 1612 | |
| 1580 void OmniboxViewGtk::HandleCutClipboard(GtkWidget* sender) { | 1613 void OmniboxViewGtk::HandleCutClipboard(GtkWidget* sender) { |
| 1581 HandleCopyOrCutClipboard(false); | 1614 HandleCopyOrCutClipboard(false); |
| 1582 } | 1615 } |
| 1583 | 1616 |
| 1584 void OmniboxViewGtk::HandleCopyOrCutClipboard(bool copy) { | 1617 void OmniboxViewGtk::HandleCopyOrCutClipboard(bool copy) { |
| 1585 DCHECK(text_view_); | 1618 DCHECK(text_view_); |
| 1586 | 1619 |
| 1587 // On copy or cut, we manually update the PRIMARY selection to contain the | 1620 // On copy or cut, we manually update the PRIMARY selection to contain the |
| 1588 // highlighted text. This matches Firefox -- we highlight the URL but don't | 1621 // highlighted text. This matches Firefox -- we highlight the URL but don't |
| 1589 // update PRIMARY on Ctrl-L, so Ctrl-L, Ctrl-C and then middle-click is a | 1622 // update PRIMARY on Ctrl-L, so Ctrl-L, Ctrl-C and then middle-click is a |
| (...skipping 578 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2168 void OmniboxViewGtk::AdjustVerticalAlignmentOfInstantView() { | 2201 void OmniboxViewGtk::AdjustVerticalAlignmentOfInstantView() { |
| 2169 // By default, GtkTextView layouts an anchored child widget just above the | 2202 // By default, GtkTextView layouts an anchored child widget just above the |
| 2170 // baseline, so we need to move the |instant_view_| down to make sure it | 2203 // baseline, so we need to move the |instant_view_| down to make sure it |
| 2171 // has the same baseline as the |text_view_|. | 2204 // has the same baseline as the |text_view_|. |
| 2172 PangoLayout* layout = gtk_label_get_layout(GTK_LABEL(instant_view_)); | 2205 PangoLayout* layout = gtk_label_get_layout(GTK_LABEL(instant_view_)); |
| 2173 int height; | 2206 int height; |
| 2174 pango_layout_get_size(layout, NULL, &height); | 2207 pango_layout_get_size(layout, NULL, &height); |
| 2175 int baseline = pango_layout_get_baseline(layout); | 2208 int baseline = pango_layout_get_baseline(layout); |
| 2176 g_object_set(instant_anchor_tag_, "rise", baseline - height, NULL); | 2209 g_object_set(instant_anchor_tag_, "rise", baseline - height, NULL); |
| 2177 } | 2210 } |
| OLD | NEW |