| 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 "app/drag_drop_types.h" | 7 #include "app/drag_drop_types.h" |
| 8 #include "app/l10n_util.h" | 8 #include "app/l10n_util.h" |
| 9 #include "app/os_exchange_data.h" | |
| 10 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 11 #include "chrome/browser/autocomplete/autocomplete.h" | 10 #include "chrome/browser/autocomplete/autocomplete.h" |
| 12 #include "chrome/browser/autocomplete/autocomplete_classifier.h" | 11 #include "chrome/browser/autocomplete/autocomplete_classifier.h" |
| 13 #include "chrome/browser/autocomplete/autocomplete_match.h" | 12 #include "chrome/browser/autocomplete/autocomplete_match.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/ui/omnibox/location_bar.h" | 14 #include "chrome/browser/ui/omnibox/location_bar.h" |
| 16 #include "chrome/browser/ui/views/frame/browser_view.h" | 15 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 17 #include "chrome/browser/ui/views/frame/browser_frame.h" | 16 #include "chrome/browser/ui/views/frame/browser_frame.h" |
| 18 #include "chrome/browser/ui/views/tabs/tab_strip.h" | 17 #include "chrome/browser/ui/views/tabs/tab_strip.h" |
| 19 #include "grit/chromium_strings.h" | 18 #include "grit/chromium_strings.h" |
| 19 #include "ui/base/dragdrop/os_exchange_data.h" |
| 20 | 20 |
| 21 BrowserRootView::BrowserRootView(BrowserView* browser_view, | 21 BrowserRootView::BrowserRootView(BrowserView* browser_view, |
| 22 views::Widget* widget) | 22 views::Widget* widget) |
| 23 : views::RootView(widget), | 23 : views::RootView(widget), |
| 24 browser_view_(browser_view), | 24 browser_view_(browser_view), |
| 25 forwarding_to_tab_strip_(false) { | 25 forwarding_to_tab_strip_(false) { |
| 26 SetAccessibleName(UTF16ToWide(l10n_util::GetStringUTF16(IDS_PRODUCT_NAME))); | 26 SetAccessibleName(UTF16ToWide(l10n_util::GetStringUTF16(IDS_PRODUCT_NAME))); |
| 27 } | 27 } |
| 28 | 28 |
| 29 bool BrowserRootView::GetDropFormats( | 29 bool BrowserRootView::GetDropFormats( |
| 30 int* formats, | 30 int* formats, |
| 31 std::set<OSExchangeData::CustomFormat>* custom_formats) { | 31 std::set<ui::OSExchangeData::CustomFormat>* custom_formats) { |
| 32 if (tabstrip() && tabstrip()->IsVisible() && !tabstrip()->IsAnimating()) { | 32 if (tabstrip() && tabstrip()->IsVisible() && !tabstrip()->IsAnimating()) { |
| 33 *formats = OSExchangeData::URL | OSExchangeData::STRING; | 33 *formats = ui::OSExchangeData::URL | ui::OSExchangeData::STRING; |
| 34 return true; | 34 return true; |
| 35 } | 35 } |
| 36 return false; | 36 return false; |
| 37 } | 37 } |
| 38 | 38 |
| 39 bool BrowserRootView::AreDropTypesRequired() { | 39 bool BrowserRootView::AreDropTypesRequired() { |
| 40 return true; | 40 return true; |
| 41 } | 41 } |
| 42 | 42 |
| 43 bool BrowserRootView::CanDrop(const OSExchangeData& data) { | 43 bool BrowserRootView::CanDrop(const ui::OSExchangeData& data) { |
| 44 if (!tabstrip() || !tabstrip()->IsVisible() || tabstrip()->IsAnimating()) | 44 if (!tabstrip() || !tabstrip()->IsVisible() || tabstrip()->IsAnimating()) |
| 45 return false; | 45 return false; |
| 46 | 46 |
| 47 // If there is a URL, we'll allow the drop. | 47 // If there is a URL, we'll allow the drop. |
| 48 if (data.HasURL()) | 48 if (data.HasURL()) |
| 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 } |
| (...skipping 27 matching lines...) Expand all Loading... |
| 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 DragDropTypes::DRAG_NONE; | 89 return DragDropTypes::DRAG_NONE; |
| 90 | 90 |
| 91 // Extract the URL and create a new OSExchangeData containing the URL. We do | 91 // Extract the URL and create a new ui::OSExchangeData containing the URL. We |
| 92 // this as the TabStrip doesn't know about the autocomplete edit and neeeds | 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 OSExchangeData mapped_data; | 96 ui::OSExchangeData mapped_data; |
| 97 if (!event.GetData().GetURLAndTitle(&url, &title) || !url.is_valid()) { | 97 if (!event.GetData().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.GetData(), &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 OSExchangeData with nothing in it. We need to do this | 102 // passing through an ui::OSExchangeData with nothing in it. We need to do |
| 103 // 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)); |
| 110 return tabstrip()->OnPerformDrop(*mapped_event); | 110 return tabstrip()->OnPerformDrop(*mapped_event); |
| 111 } | 111 } |
| 112 | 112 |
| 113 bool BrowserRootView::ShouldForwardToTabStrip( | 113 bool BrowserRootView::ShouldForwardToTabStrip( |
| 114 const views::DropTargetEvent& event) { | 114 const views::DropTargetEvent& event) { |
| 115 if (!tabstrip()->IsVisible()) | 115 if (!tabstrip()->IsVisible()) |
| 116 return false; | 116 return false; |
| 117 | 117 |
| 118 // Allow the drop as long as the mouse is over the tabstrip or vertically | 118 // Allow the drop as long as the mouse is over the tabstrip or vertically |
| 119 // before it. | 119 // before it. |
| 120 gfx::Point tab_loc_in_host; | 120 gfx::Point tab_loc_in_host; |
| 121 ConvertPointToView(tabstrip(), this, &tab_loc_in_host); | 121 ConvertPointToView(tabstrip(), this, &tab_loc_in_host); |
| 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 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.GetSourceOperations()); |
| 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 OSExchangeData& data, GURL* url) { | 139 bool BrowserRootView::GetPasteAndGoURL(const ui::OSExchangeData& data, |
| 140 GURL* url) { |
| 140 if (!data.HasString()) | 141 if (!data.HasString()) |
| 141 return false; | 142 return false; |
| 142 | 143 |
| 143 std::wstring text; | 144 std::wstring text; |
| 144 if (!data.GetString(&text) || text.empty()) | 145 if (!data.GetString(&text) || text.empty()) |
| 145 return false; | 146 return false; |
| 146 | 147 |
| 147 AutocompleteMatch match; | 148 AutocompleteMatch match; |
| 148 browser_view_->browser()->profile()->GetAutocompleteClassifier()->Classify( | 149 browser_view_->browser()->profile()->GetAutocompleteClassifier()->Classify( |
| 149 text, std::wstring(), false, &match, NULL); | 150 text, std::wstring(), false, &match, NULL); |
| 150 if (!match.destination_url.is_valid()) | 151 if (!match.destination_url.is_valid()) |
| 151 return false; | 152 return false; |
| 152 | 153 |
| 153 if (url) | 154 if (url) |
| 154 *url = match.destination_url; | 155 *url = match.destination_url; |
| 155 return true; | 156 return true; |
| 156 } | 157 } |
| OLD | NEW |