| 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/views/frame/browser_root_view.h" | 5 #include "chrome/browser/ui/views/frame/browser_root_view.h" |
| 6 | 6 |
| 7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
| 8 #include "chrome/browser/autocomplete/autocomplete.h" | 8 #include "chrome/browser/autocomplete/autocomplete.h" |
| 9 #include "chrome/browser/autocomplete/autocomplete_classifier.h" | 9 #include "chrome/browser/autocomplete/autocomplete_classifier.h" |
| 10 #include "chrome/browser/autocomplete/autocomplete_match.h" | 10 #include "chrome/browser/autocomplete/autocomplete_match.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 return true; | 49 return true; |
| 50 | 50 |
| 51 // If there isn't a URL, see if we can 'paste and go'. | 51 // If there isn't a URL, see if we can 'paste and go'. |
| 52 return GetPasteAndGoURL(data, NULL); | 52 return GetPasteAndGoURL(data, NULL); |
| 53 } | 53 } |
| 54 | 54 |
| 55 void BrowserRootView::OnDragEntered(const views::DropTargetEvent& event) { | 55 void BrowserRootView::OnDragEntered(const views::DropTargetEvent& event) { |
| 56 if (ShouldForwardToTabStrip(event)) { | 56 if (ShouldForwardToTabStrip(event)) { |
| 57 forwarding_to_tab_strip_ = true; | 57 forwarding_to_tab_strip_ = true; |
| 58 scoped_ptr<views::DropTargetEvent> mapped_event( | 58 scoped_ptr<views::DropTargetEvent> mapped_event( |
| 59 MapEventToTabStrip(event, event.GetData())); | 59 MapEventToTabStrip(event, event.data())); |
| 60 tabstrip()->OnDragEntered(*mapped_event.get()); | 60 tabstrip()->OnDragEntered(*mapped_event.get()); |
| 61 } | 61 } |
| 62 } | 62 } |
| 63 | 63 |
| 64 int BrowserRootView::OnDragUpdated(const views::DropTargetEvent& event) { | 64 int BrowserRootView::OnDragUpdated(const views::DropTargetEvent& event) { |
| 65 if (ShouldForwardToTabStrip(event)) { | 65 if (ShouldForwardToTabStrip(event)) { |
| 66 scoped_ptr<views::DropTargetEvent> mapped_event( | 66 scoped_ptr<views::DropTargetEvent> mapped_event( |
| 67 MapEventToTabStrip(event, event.GetData())); | 67 MapEventToTabStrip(event, event.data())); |
| 68 if (!forwarding_to_tab_strip_) { | 68 if (!forwarding_to_tab_strip_) { |
| 69 tabstrip()->OnDragEntered(*mapped_event.get()); | 69 tabstrip()->OnDragEntered(*mapped_event.get()); |
| 70 forwarding_to_tab_strip_ = true; | 70 forwarding_to_tab_strip_ = true; |
| 71 } | 71 } |
| 72 return tabstrip()->OnDragUpdated(*mapped_event.get()); | 72 return tabstrip()->OnDragUpdated(*mapped_event.get()); |
| 73 } else if (forwarding_to_tab_strip_) { | 73 } else if (forwarding_to_tab_strip_) { |
| 74 forwarding_to_tab_strip_ = false; | 74 forwarding_to_tab_strip_ = false; |
| 75 tabstrip()->OnDragExited(); | 75 tabstrip()->OnDragExited(); |
| 76 } | 76 } |
| 77 return ui::DragDropTypes::DRAG_NONE; | 77 return ui::DragDropTypes::DRAG_NONE; |
| 78 } | 78 } |
| 79 | 79 |
| 80 void BrowserRootView::OnDragExited() { | 80 void BrowserRootView::OnDragExited() { |
| 81 if (forwarding_to_tab_strip_) { | 81 if (forwarding_to_tab_strip_) { |
| 82 forwarding_to_tab_strip_ = false; | 82 forwarding_to_tab_strip_ = false; |
| 83 tabstrip()->OnDragExited(); | 83 tabstrip()->OnDragExited(); |
| 84 } | 84 } |
| 85 } | 85 } |
| 86 | 86 |
| 87 int BrowserRootView::OnPerformDrop(const views::DropTargetEvent& event) { | 87 int BrowserRootView::OnPerformDrop(const views::DropTargetEvent& event) { |
| 88 if (!forwarding_to_tab_strip_) | 88 if (!forwarding_to_tab_strip_) |
| 89 return ui::DragDropTypes::DRAG_NONE; | 89 return ui::DragDropTypes::DRAG_NONE; |
| 90 | 90 |
| 91 // Extract the URL and create a new ui::OSExchangeData containing the URL. We | 91 // Extract the URL and create a new ui::OSExchangeData containing the URL. We |
| 92 // do this as the TabStrip doesn't know about the autocomplete edit and needs | 92 // do this as the TabStrip doesn't know about the autocomplete edit and needs |
| 93 // to know about it to handle 'paste and go'. | 93 // to know about it to handle 'paste and go'. |
| 94 GURL url; | 94 GURL url; |
| 95 std::wstring title; | 95 std::wstring title; |
| 96 ui::OSExchangeData mapped_data; | 96 ui::OSExchangeData mapped_data; |
| 97 if (!event.GetData().GetURLAndTitle(&url, &title) || !url.is_valid()) { | 97 if (!event.data().GetURLAndTitle(&url, &title) || !url.is_valid()) { |
| 98 // The url isn't valid. Use the paste and go url. | 98 // The url isn't valid. Use the paste and go url. |
| 99 if (GetPasteAndGoURL(event.GetData(), &url)) | 99 if (GetPasteAndGoURL(event.data(), &url)) |
| 100 mapped_data.SetURL(url, std::wstring()); | 100 mapped_data.SetURL(url, std::wstring()); |
| 101 // else case: couldn't extract a url or 'paste and go' url. This ends up | 101 // else case: couldn't extract a url or 'paste and go' url. This ends up |
| 102 // passing through an ui::OSExchangeData with nothing in it. We need to do | 102 // passing through an ui::OSExchangeData with nothing in it. We need to do |
| 103 // this so that the tab strip cleans up properly. | 103 // this so that the tab strip cleans up properly. |
| 104 } else { | 104 } else { |
| 105 mapped_data.SetURL(url, std::wstring()); | 105 mapped_data.SetURL(url, std::wstring()); |
| 106 } | 106 } |
| 107 forwarding_to_tab_strip_ = false; | 107 forwarding_to_tab_strip_ = false; |
| 108 scoped_ptr<views::DropTargetEvent> mapped_event( | 108 scoped_ptr<views::DropTargetEvent> mapped_event( |
| 109 MapEventToTabStrip(event, mapped_data)); | 109 MapEventToTabStrip(event, mapped_data)); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 122 return event.y() < tab_loc_in_host.y() + tabstrip()->height(); | 122 return event.y() < tab_loc_in_host.y() + tabstrip()->height(); |
| 123 } | 123 } |
| 124 | 124 |
| 125 views::DropTargetEvent* BrowserRootView::MapEventToTabStrip( | 125 views::DropTargetEvent* BrowserRootView::MapEventToTabStrip( |
| 126 const views::DropTargetEvent& event, | 126 const views::DropTargetEvent& event, |
| 127 const ui::OSExchangeData& data) { | 127 const ui::OSExchangeData& data) { |
| 128 gfx::Point tab_strip_loc(event.location()); | 128 gfx::Point tab_strip_loc(event.location()); |
| 129 ConvertPointToView(this, tabstrip(), &tab_strip_loc); | 129 ConvertPointToView(this, tabstrip(), &tab_strip_loc); |
| 130 return new views::DropTargetEvent(data, tab_strip_loc.x(), | 130 return new views::DropTargetEvent(data, tab_strip_loc.x(), |
| 131 tab_strip_loc.y(), | 131 tab_strip_loc.y(), |
| 132 event.GetSourceOperations()); | 132 event.source_operations()); |
| 133 } | 133 } |
| 134 | 134 |
| 135 BaseTabStrip* BrowserRootView::tabstrip() const { | 135 BaseTabStrip* BrowserRootView::tabstrip() const { |
| 136 return browser_view_->tabstrip(); | 136 return browser_view_->tabstrip(); |
| 137 } | 137 } |
| 138 | 138 |
| 139 bool BrowserRootView::GetPasteAndGoURL(const ui::OSExchangeData& data, | 139 bool BrowserRootView::GetPasteAndGoURL(const ui::OSExchangeData& data, |
| 140 GURL* url) { | 140 GURL* url) { |
| 141 if (!data.HasString()) | 141 if (!data.HasString()) |
| 142 return false; | 142 return false; |
| 143 | 143 |
| 144 std::wstring text; | 144 std::wstring text; |
| 145 if (!data.GetString(&text) || text.empty()) | 145 if (!data.GetString(&text) || text.empty()) |
| 146 return false; | 146 return false; |
| 147 | 147 |
| 148 AutocompleteMatch match; | 148 AutocompleteMatch match; |
| 149 browser_view_->browser()->profile()->GetAutocompleteClassifier()->Classify( | 149 browser_view_->browser()->profile()->GetAutocompleteClassifier()->Classify( |
| 150 WideToUTF16Hack(text), string16(), false, &match, NULL); | 150 WideToUTF16Hack(text), string16(), false, &match, NULL); |
| 151 if (!match.destination_url.is_valid()) | 151 if (!match.destination_url.is_valid()) |
| 152 return false; | 152 return false; |
| 153 | 153 |
| 154 if (url) | 154 if (url) |
| 155 *url = match.destination_url; | 155 *url = match.destination_url; |
| 156 return true; | 156 return true; |
| 157 } | 157 } |
| OLD | NEW |