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

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

Issue 8311014: GTK: add TEXT_URI_LIST as a data type for drags from the omnibox. (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 9 years, 2 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/public/browser/notification_source.h" 31 #include "content/public/browser/notification_source.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 1550 matching lines...) Expand 10 before | Expand all | Expand 10 after
1596 g_signal_stop_emission(text_view_, signal_id, 0); 1599 g_signal_stop_emission(text_view_, signal_id, 0);
1597 } 1600 }
1598 } 1601 }
1599 1602
1600 void OmniboxViewGtk::HandleDragDataGet(GtkWidget* widget, 1603 void OmniboxViewGtk::HandleDragDataGet(GtkWidget* widget,
1601 GdkDragContext* context, 1604 GdkDragContext* context,
1602 GtkSelectionData* selection_data, 1605 GtkSelectionData* selection_data,
1603 guint target_type, 1606 guint target_type,
1604 guint time) { 1607 guint time) {
1605 DCHECK(text_view_); 1608 DCHECK(text_view_);
1606 // If GTK put the normal textual version of the selection in our drag data, 1609
1607 // put our doctored selection that might have the 'http://' prefix. Also, GTK
1608 // is confused about signedness of its datatypes, leading to the weird switch
1609 // statement (no set of casts fixes this).
1610 switch (target_type) { 1610 switch (target_type) {
1611 case GTK_TEXT_BUFFER_TARGET_INFO_TEXT: { 1611 case GTK_TEXT_BUFFER_TARGET_INFO_TEXT: {
1612 gtk_selection_data_set_text(selection_data, dragged_text_.c_str(), -1); 1612 gtk_selection_data_set_text(selection_data, dragged_text_.c_str(), -1);
1613 break;
1614 }
1615 case ui::CHROME_NAMED_URL: {
1616 TabContents* current_tab =
1617 BrowserList::GetLastActive()->GetSelectedTabContents();
1618 string16 tab_title = current_tab->GetTitle();
1619 // Pass an empty string if user has edited the URL.
1620 if (current_tab->GetURL().spec() != dragged_text_)
1621 tab_title = string16();
1622 ui::WriteURLWithName(selection_data, GURL(dragged_text_),
1623 tab_title, target_type);
1624 break;
1613 } 1625 }
1614 } 1626 }
1615 } 1627 }
1616 1628
1617 void OmniboxViewGtk::HandleDragBegin(GtkWidget* widget, 1629 void OmniboxViewGtk::HandleDragBegin(GtkWidget* widget,
1618 GdkDragContext* context) { 1630 GdkDragContext* context) {
1631 string16 text = UTF8ToUTF16(GetSelectedText());
1632
1633 if (text.empty())
1634 return;
1635
1636 // Use AdjustTextForCopy to make sure we prefix the text with 'http://'.
1637 CharRange selection = GetSelection();
1638 GURL url;
1639 bool write_url;
1640 model_->AdjustTextForCopy(selection.selection_min(), IsSelectAll(), &text,
1641 &url, &write_url);
1642 if (write_url) {
1643 selected_text_ = UTF16ToUTF8(text);
1644 GtkTargetList* copy_targets =
1645 gtk_text_buffer_get_copy_target_list(text_buffer_);
1646 gtk_target_list_add(copy_targets,
1647 ui::GetAtomForTarget(ui::CHROME_NAMED_URL),
1648 GTK_TARGET_SAME_APP, ui::CHROME_NAMED_URL);
1649 }
1619 dragged_text_ = selected_text_; 1650 dragged_text_ = selected_text_;
1620 } 1651 }
1621 1652
1622 void OmniboxViewGtk::HandleDragEnd(GtkWidget* widget, 1653 void OmniboxViewGtk::HandleDragEnd(GtkWidget* widget,
1623 GdkDragContext* context) { 1654 GdkDragContext* context) {
1655 GdkAtom atom = ui::GetAtomForTarget(ui::CHROME_NAMED_URL);
1656 GtkTargetList* copy_targets =
1657 gtk_text_buffer_get_copy_target_list(text_buffer_);
1658 gtk_target_list_remove(copy_targets, atom);
1624 dragged_text_.clear(); 1659 dragged_text_.clear();
1625 } 1660 }
1626 1661
1627 void OmniboxViewGtk::HandleInsertText(GtkTextBuffer* buffer, 1662 void OmniboxViewGtk::HandleInsertText(GtkTextBuffer* buffer,
1628 GtkTextIter* location, 1663 GtkTextIter* location,
1629 const gchar* text, 1664 const gchar* text,
1630 gint len) { 1665 gint len) {
1631 std::string filtered_text; 1666 std::string filtered_text;
1632 filtered_text.reserve(len); 1667 filtered_text.reserve(len);
1633 1668
(...skipping 718 matching lines...) Expand 10 before | Expand all | Expand 10 after
2352 // baseline, so we need to move the |instant_view_| down to make sure it 2387 // baseline, so we need to move the |instant_view_| down to make sure it
2353 // has the same baseline as the |text_view_|. 2388 // has the same baseline as the |text_view_|.
2354 PangoLayout* layout = gtk_label_get_layout(GTK_LABEL(instant_view_)); 2389 PangoLayout* layout = gtk_label_get_layout(GTK_LABEL(instant_view_));
2355 int height; 2390 int height;
2356 pango_layout_get_size(layout, NULL, &height); 2391 pango_layout_get_size(layout, NULL, &height);
2357 PangoLayoutIter* iter = pango_layout_get_iter(layout); 2392 PangoLayoutIter* iter = pango_layout_get_iter(layout);
2358 int baseline = pango_layout_iter_get_baseline(iter); 2393 int baseline = pango_layout_iter_get_baseline(iter);
2359 pango_layout_iter_free(iter); 2394 pango_layout_iter_free(iter);
2360 g_object_set(instant_anchor_tag_, "rise", baseline - height, NULL); 2395 g_object_set(instant_anchor_tag_, "rise", baseline - height, NULL);
2361 } 2396 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698