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> |
| 11 | 11 |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/string_util.h" | 13 #include "base/string_util.h" |
| 14 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
| 15 #include "chrome/app/chrome_command_ids.h" | 15 #include "chrome/app/chrome_command_ids.h" |
| 16 #include "chrome/browser/autocomplete/autocomplete_edit.h" | 16 #include "chrome/browser/autocomplete/autocomplete_edit.h" |
| 17 #include "chrome/browser/autocomplete/autocomplete_match.h" | 17 #include "chrome/browser/autocomplete/autocomplete_match.h" |
| 18 #include "chrome/browser/autocomplete/autocomplete_popup_model.h" | 18 #include "chrome/browser/autocomplete/autocomplete_popup_model.h" |
| 19 #include "chrome/browser/bookmarks/bookmark_node_data.h" | 19 #include "chrome/browser/bookmarks/bookmark_node_data.h" |
| 20 #include "chrome/browser/command_updater.h" | 20 #include "chrome/browser/command_updater.h" |
| 21 #include "chrome/browser/defaults.h" | 21 #include "chrome/browser/defaults.h" |
| 22 #include "chrome/browser/instant/instant_controller.h" | 22 #include "chrome/browser/instant/instant_controller.h" |
| 23 #include "chrome/browser/platform_util.h" | 23 #include "chrome/browser/platform_util.h" |
| 24 #include "chrome/browser/ui/browser.h" | |
| 25 #include "chrome/browser/ui/browser_list.h" | |
| 24 #include "chrome/browser/ui/gtk/gtk_util.h" | 26 #include "chrome/browser/ui/gtk/gtk_util.h" |
| 25 #include "chrome/browser/ui/gtk/view_id_util.h" | 27 #include "chrome/browser/ui/gtk/view_id_util.h" |
| 26 #include "chrome/browser/ui/toolbar/toolbar_model.h" | 28 #include "chrome/browser/ui/toolbar/toolbar_model.h" |
| 27 #include "chrome/common/chrome_notification_types.h" | 29 #include "chrome/common/chrome_notification_types.h" |
| 28 #include "content/browser/tab_contents/tab_contents.h" | 30 #include "content/browser/tab_contents/tab_contents.h" |
| 29 #include "content/common/notification_service.h" | 31 #include "content/common/notification_service.h" |
| 30 #include "googleurl/src/gurl.h" | 32 #include "googleurl/src/gurl.h" |
| 31 #include "grit/generated_resources.h" | 33 #include "grit/generated_resources.h" |
| 32 #include "net/base/escape.h" | 34 #include "net/base/escape.h" |
| 33 #include "third_party/undoview/undo_view.h" | 35 #include "third_party/undoview/undo_view.h" |
| 34 #include "ui/base/animation/multi_animation.h" | 36 #include "ui/base/animation/multi_animation.h" |
| 35 #include "ui/base/dragdrop/drag_drop_types.h" | 37 #include "ui/base/dragdrop/drag_drop_types.h" |
| 38 #include "ui/base/dragdrop/gtk_dnd_util.h" | |
| 36 #include "ui/base/gtk/gtk_hig_constants.h" | 39 #include "ui/base/gtk/gtk_hig_constants.h" |
| 37 #include "ui/base/l10n/l10n_util.h" | 40 #include "ui/base/l10n/l10n_util.h" |
| 38 #include "ui/base/resource/resource_bundle.h" | 41 #include "ui/base/resource/resource_bundle.h" |
| 39 #include "ui/gfx/color_utils.h" | 42 #include "ui/gfx/color_utils.h" |
| 40 #include "ui/gfx/font.h" | 43 #include "ui/gfx/font.h" |
| 41 #include "ui/gfx/gtk_util.h" | 44 #include "ui/gfx/gtk_util.h" |
| 42 #include "ui/gfx/skia_utils_gtk.h" | 45 #include "ui/gfx/skia_utils_gtk.h" |
| 43 | 46 |
| 44 #if defined(TOOLKIT_VIEWS) | 47 #if defined(TOOLKIT_VIEWS) |
| 45 #include "chrome/browser/ui/views/autocomplete/autocomplete_popup_contents_view. h" | 48 #include "chrome/browser/ui/views/autocomplete/autocomplete_popup_contents_view. h" |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 237 alignment_.Own(gtk_alignment_new(0., 0.5, 1.0, 0.0)); | 240 alignment_.Own(gtk_alignment_new(0., 0.5, 1.0, 0.0)); |
| 238 gtk_widget_set_name(alignment_.get(), | 241 gtk_widget_set_name(alignment_.get(), |
| 239 "chrome-autocomplete-edit-view"); | 242 "chrome-autocomplete-edit-view"); |
| 240 | 243 |
| 241 // The GtkTagTable and GtkTextBuffer are not initially unowned, so we have | 244 // The GtkTagTable and GtkTextBuffer are not initially unowned, so we have |
| 242 // our own reference when we create them, and we own them. Adding them to | 245 // our own reference when we create them, and we own them. Adding them to |
| 243 // the other objects adds a reference; it doesn't adopt them. | 246 // the other objects adds a reference; it doesn't adopt them. |
| 244 tag_table_ = gtk_text_tag_table_new(); | 247 tag_table_ = gtk_text_tag_table_new(); |
| 245 text_buffer_ = gtk_text_buffer_new(tag_table_); | 248 text_buffer_ = gtk_text_buffer_new(tag_table_); |
| 246 g_object_set_data(G_OBJECT(text_buffer_), kOmniboxViewGtkKey, this); | 249 g_object_set_data(G_OBJECT(text_buffer_), kOmniboxViewGtkKey, this); |
| 250 copy_targets_ = gtk_text_buffer_get_copy_target_list(text_buffer_); | |
|
Evan Stade
2011/10/21 19:16:11
doing this opens a can of worms regarding object o
SanjoyPal
2011/10/22 03:34:02
Done.
| |
| 247 | 251 |
| 248 // We need to run this two handlers before undo manager's handlers, so that | 252 // We need to run this two handlers before undo manager's handlers, so that |
| 249 // text iterators modified by these handlers can be passed down to undo | 253 // text iterators modified by these handlers can be passed down to undo |
| 250 // manager's handlers. | 254 // manager's handlers. |
| 251 g_signal_connect(text_buffer_, "delete-range", | 255 g_signal_connect(text_buffer_, "delete-range", |
| 252 G_CALLBACK(&HandleDeleteRangeThunk), this); | 256 G_CALLBACK(&HandleDeleteRangeThunk), this); |
| 253 g_signal_connect(text_buffer_, "mark-set", | 257 g_signal_connect(text_buffer_, "mark-set", |
| 254 G_CALLBACK(&HandleMarkSetAlwaysThunk), this); | 258 G_CALLBACK(&HandleMarkSetAlwaysThunk), this); |
| 255 | 259 |
| 256 text_view_ = gtk_undo_view_new(text_buffer_); | 260 text_view_ = gtk_undo_view_new(text_buffer_); |
| (...skipping 1340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1597 } | 1601 } |
| 1598 } | 1602 } |
| 1599 | 1603 |
| 1600 void OmniboxViewGtk::HandleDragDataGet(GtkWidget* widget, | 1604 void OmniboxViewGtk::HandleDragDataGet(GtkWidget* widget, |
| 1601 GdkDragContext* context, | 1605 GdkDragContext* context, |
| 1602 GtkSelectionData* selection_data, | 1606 GtkSelectionData* selection_data, |
| 1603 guint target_type, | 1607 guint target_type, |
| 1604 guint time) { | 1608 guint time) { |
| 1605 DCHECK(text_view_); | 1609 DCHECK(text_view_); |
| 1606 // If GTK put the normal textual version of the selection in our drag data, | 1610 // If GTK put the normal textual version of the selection in our drag data, |
| 1607 // put our doctored selection that might have the 'http://' prefix. Also, GTK | 1611 // put our doctored selection that might have the 'http://' prefix. Also, GTK |
|
Evan Stade
2011/10/21 19:16:11
you can remove the comment about the switch
SanjoyPal
2011/10/22 03:34:02
Done.
| |
| 1608 // is confused about signedness of its datatypes, leading to the weird switch | 1612 // is confused about signedness of its datatypes, leading to the weird switch |
| 1609 // statement (no set of casts fixes this). | 1613 // statement (no set of casts fixes this). |
| 1610 switch (target_type) { | 1614 switch (target_type) { |
| 1611 case GTK_TEXT_BUFFER_TARGET_INFO_TEXT: { | 1615 case GTK_TEXT_BUFFER_TARGET_INFO_TEXT: { |
| 1612 gtk_selection_data_set_text(selection_data, dragged_text_.c_str(), -1); | 1616 gtk_selection_data_set_text(selection_data, dragged_text_.c_str(), -1); |
| 1617 break; | |
| 1618 } | |
| 1619 case ui::TEXT_URI_LIST: { | |
| 1620 TabContents* current_tab = | |
| 1621 BrowserList::GetLastActive()->GetSelectedTabContents(); | |
| 1622 string16 tab_title = current_tab->GetTitle(); | |
| 1623 // Pass an empty string if user has edited the URL. | |
| 1624 if (current_tab->GetURL().spec() != dragged_text_) | |
| 1625 tab_title = string16(); | |
| 1626 ui::WriteURLWithName(selection_data, GURL(dragged_text_), | |
| 1627 tab_title, target_type); | |
| 1628 break; | |
| 1613 } | 1629 } |
| 1614 } | 1630 } |
| 1615 } | 1631 } |
| 1616 | 1632 |
| 1617 void OmniboxViewGtk::HandleDragBegin(GtkWidget* widget, | 1633 void OmniboxViewGtk::HandleDragBegin(GtkWidget* widget, |
| 1618 GdkDragContext* context) { | 1634 GdkDragContext* context) { |
| 1635 // Add TEXT_URI_TARGET to the omnibox target list only if its a valid url. | |
| 1636 if (GURL(selected_text_).is_valid()) | |
|
Evan Stade
2011/10/21 19:16:11
no. You need to use AdjustTextForCopy
SanjoyPal
2011/10/22 03:34:02
Done.
| |
| 1637 gtk_target_list_add_uri_targets(copy_targets_, ui::TEXT_URI_LIST); | |
| 1619 dragged_text_ = selected_text_; | 1638 dragged_text_ = selected_text_; |
| 1620 } | 1639 } |
| 1621 | 1640 |
| 1622 void OmniboxViewGtk::HandleDragEnd(GtkWidget* widget, | 1641 void OmniboxViewGtk::HandleDragEnd(GtkWidget* widget, |
| 1623 GdkDragContext* context) { | 1642 GdkDragContext* context) { |
| 1643 GdkAtom text_uri_atom = ui::GetAtomForTarget(ui::TEXT_URI_LIST); | |
| 1644 if (gtk_target_list_find(copy_targets_, text_uri_atom, NULL)) | |
|
Evan Stade
2011/10/21 19:16:11
I don't think you need this check
SanjoyPal
2011/10/22 03:34:02
Done.
| |
| 1645 gtk_target_list_remove(copy_targets_, text_uri_atom); | |
| 1624 dragged_text_.clear(); | 1646 dragged_text_.clear(); |
| 1625 } | 1647 } |
| 1626 | 1648 |
| 1627 void OmniboxViewGtk::HandleInsertText(GtkTextBuffer* buffer, | 1649 void OmniboxViewGtk::HandleInsertText(GtkTextBuffer* buffer, |
| 1628 GtkTextIter* location, | 1650 GtkTextIter* location, |
| 1629 const gchar* text, | 1651 const gchar* text, |
| 1630 gint len) { | 1652 gint len) { |
| 1631 std::string filtered_text; | 1653 std::string filtered_text; |
| 1632 filtered_text.reserve(len); | 1654 filtered_text.reserve(len); |
| 1633 | 1655 |
| (...skipping 718 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2352 // baseline, so we need to move the |instant_view_| down to make sure it | 2374 // baseline, so we need to move the |instant_view_| down to make sure it |
| 2353 // has the same baseline as the |text_view_|. | 2375 // has the same baseline as the |text_view_|. |
| 2354 PangoLayout* layout = gtk_label_get_layout(GTK_LABEL(instant_view_)); | 2376 PangoLayout* layout = gtk_label_get_layout(GTK_LABEL(instant_view_)); |
| 2355 int height; | 2377 int height; |
| 2356 pango_layout_get_size(layout, NULL, &height); | 2378 pango_layout_get_size(layout, NULL, &height); |
| 2357 PangoLayoutIter* iter = pango_layout_get_iter(layout); | 2379 PangoLayoutIter* iter = pango_layout_get_iter(layout); |
| 2358 int baseline = pango_layout_iter_get_baseline(iter); | 2380 int baseline = pango_layout_iter_get_baseline(iter); |
| 2359 pango_layout_iter_free(iter); | 2381 pango_layout_iter_free(iter); |
| 2360 g_object_set(instant_anchor_tag_, "rise", baseline - height, NULL); | 2382 g_object_set(instant_anchor_tag_, "rise", baseline - height, NULL); |
| 2361 } | 2383 } |
| OLD | NEW |