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/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_classifier.h" | 8 #include "chrome/browser/autocomplete/autocomplete_classifier.h" |
9 #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h" | 9 #include "chrome/browser/autocomplete/autocomplete_classifier_factory.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 false; | 49 return false; |
50 | 50 |
51 // If there is a URL, we'll allow the drop. | 51 // If there is a URL, we'll allow the drop. |
52 if (data.HasURL()) | 52 if (data.HasURL()) |
53 return true; | 53 return true; |
54 | 54 |
55 // If there isn't a URL, see if we can 'paste and go'. | 55 // If there isn't a URL, see if we can 'paste and go'. |
56 return GetPasteAndGoURL(data, NULL); | 56 return GetPasteAndGoURL(data, NULL); |
57 } | 57 } |
58 | 58 |
59 void BrowserRootView::OnDragEntered(const views::DropTargetEvent& event) { | 59 void BrowserRootView::OnDragEntered(const ui::DropTargetEvent& event) { |
60 if (ShouldForwardToTabStrip(event)) { | 60 if (ShouldForwardToTabStrip(event)) { |
61 forwarding_to_tab_strip_ = true; | 61 forwarding_to_tab_strip_ = true; |
62 scoped_ptr<views::DropTargetEvent> mapped_event( | 62 scoped_ptr<ui::DropTargetEvent> mapped_event( |
63 MapEventToTabStrip(event, event.data())); | 63 MapEventToTabStrip(event, event.data())); |
64 tabstrip()->OnDragEntered(*mapped_event.get()); | 64 tabstrip()->OnDragEntered(*mapped_event.get()); |
65 } | 65 } |
66 } | 66 } |
67 | 67 |
68 int BrowserRootView::OnDragUpdated(const views::DropTargetEvent& event) { | 68 int BrowserRootView::OnDragUpdated(const ui::DropTargetEvent& event) { |
69 if (ShouldForwardToTabStrip(event)) { | 69 if (ShouldForwardToTabStrip(event)) { |
70 scoped_ptr<views::DropTargetEvent> mapped_event( | 70 scoped_ptr<ui::DropTargetEvent> mapped_event( |
71 MapEventToTabStrip(event, event.data())); | 71 MapEventToTabStrip(event, event.data())); |
72 if (!forwarding_to_tab_strip_) { | 72 if (!forwarding_to_tab_strip_) { |
73 tabstrip()->OnDragEntered(*mapped_event.get()); | 73 tabstrip()->OnDragEntered(*mapped_event.get()); |
74 forwarding_to_tab_strip_ = true; | 74 forwarding_to_tab_strip_ = true; |
75 } | 75 } |
76 return tabstrip()->OnDragUpdated(*mapped_event.get()); | 76 return tabstrip()->OnDragUpdated(*mapped_event.get()); |
77 } else if (forwarding_to_tab_strip_) { | 77 } else if (forwarding_to_tab_strip_) { |
78 forwarding_to_tab_strip_ = false; | 78 forwarding_to_tab_strip_ = false; |
79 tabstrip()->OnDragExited(); | 79 tabstrip()->OnDragExited(); |
80 } | 80 } |
81 return ui::DragDropTypes::DRAG_NONE; | 81 return ui::DragDropTypes::DRAG_NONE; |
82 } | 82 } |
83 | 83 |
84 void BrowserRootView::OnDragExited() { | 84 void BrowserRootView::OnDragExited() { |
85 if (forwarding_to_tab_strip_) { | 85 if (forwarding_to_tab_strip_) { |
86 forwarding_to_tab_strip_ = false; | 86 forwarding_to_tab_strip_ = false; |
87 tabstrip()->OnDragExited(); | 87 tabstrip()->OnDragExited(); |
88 } | 88 } |
89 } | 89 } |
90 | 90 |
91 int BrowserRootView::OnPerformDrop(const views::DropTargetEvent& event) { | 91 int BrowserRootView::OnPerformDrop(const ui::DropTargetEvent& event) { |
92 if (!forwarding_to_tab_strip_) | 92 if (!forwarding_to_tab_strip_) |
93 return ui::DragDropTypes::DRAG_NONE; | 93 return ui::DragDropTypes::DRAG_NONE; |
94 | 94 |
95 // Extract the URL and create a new ui::OSExchangeData containing the URL. We | 95 // Extract the URL and create a new ui::OSExchangeData containing the URL. We |
96 // do this as the TabStrip doesn't know about the autocomplete edit and needs | 96 // do this as the TabStrip doesn't know about the autocomplete edit and needs |
97 // to know about it to handle 'paste and go'. | 97 // to know about it to handle 'paste and go'. |
98 GURL url; | 98 GURL url; |
99 string16 title; | 99 string16 title; |
100 ui::OSExchangeData mapped_data; | 100 ui::OSExchangeData mapped_data; |
101 if (!event.data().GetURLAndTitle(&url, &title) || !url.is_valid()) { | 101 if (!event.data().GetURLAndTitle(&url, &title) || !url.is_valid()) { |
102 // The url isn't valid. Use the paste and go url. | 102 // The url isn't valid. Use the paste and go url. |
103 if (GetPasteAndGoURL(event.data(), &url)) | 103 if (GetPasteAndGoURL(event.data(), &url)) |
104 mapped_data.SetURL(url, string16()); | 104 mapped_data.SetURL(url, string16()); |
105 // else case: couldn't extract a url or 'paste and go' url. This ends up | 105 // else case: couldn't extract a url or 'paste and go' url. This ends up |
106 // passing through an ui::OSExchangeData with nothing in it. We need to do | 106 // passing through an ui::OSExchangeData with nothing in it. We need to do |
107 // this so that the tab strip cleans up properly. | 107 // this so that the tab strip cleans up properly. |
108 } else { | 108 } else { |
109 mapped_data.SetURL(url, string16()); | 109 mapped_data.SetURL(url, string16()); |
110 } | 110 } |
111 forwarding_to_tab_strip_ = false; | 111 forwarding_to_tab_strip_ = false; |
112 scoped_ptr<views::DropTargetEvent> mapped_event( | 112 scoped_ptr<ui::DropTargetEvent> mapped_event( |
113 MapEventToTabStrip(event, mapped_data)); | 113 MapEventToTabStrip(event, mapped_data)); |
114 return tabstrip()->OnPerformDrop(*mapped_event); | 114 return tabstrip()->OnPerformDrop(*mapped_event); |
115 } | 115 } |
116 | 116 |
117 void BrowserRootView::GetAccessibleState(ui::AccessibleViewState* state) { | 117 void BrowserRootView::GetAccessibleState(ui::AccessibleViewState* state) { |
118 views::internal::RootView::GetAccessibleState(state); | 118 views::internal::RootView::GetAccessibleState(state); |
119 state->name = l10n_util::GetStringUTF16(IDS_PRODUCT_NAME); | 119 state->name = l10n_util::GetStringUTF16(IDS_PRODUCT_NAME); |
120 } | 120 } |
121 | 121 |
122 std::string BrowserRootView::GetClassName() const { | 122 std::string BrowserRootView::GetClassName() const { |
123 return kViewClassName; | 123 return kViewClassName; |
124 } | 124 } |
125 | 125 |
126 bool BrowserRootView::ShouldForwardToTabStrip( | 126 bool BrowserRootView::ShouldForwardToTabStrip( |
127 const views::DropTargetEvent& event) { | 127 const ui::DropTargetEvent& event) { |
128 if (!tabstrip()->visible()) | 128 if (!tabstrip()->visible()) |
129 return false; | 129 return false; |
130 | 130 |
131 // Allow the drop as long as the mouse is over the tabstrip or vertically | 131 // Allow the drop as long as the mouse is over the tabstrip or vertically |
132 // before it. | 132 // before it. |
133 gfx::Point tab_loc_in_host; | 133 gfx::Point tab_loc_in_host; |
134 ConvertPointToTarget(tabstrip(), this, &tab_loc_in_host); | 134 ConvertPointToTarget(tabstrip(), this, &tab_loc_in_host); |
135 return event.y() < tab_loc_in_host.y() + tabstrip()->height(); | 135 return event.y() < tab_loc_in_host.y() + tabstrip()->height(); |
136 } | 136 } |
137 | 137 |
138 views::DropTargetEvent* BrowserRootView::MapEventToTabStrip( | 138 ui::DropTargetEvent* BrowserRootView::MapEventToTabStrip( |
139 const views::DropTargetEvent& event, | 139 const ui::DropTargetEvent& event, |
140 const ui::OSExchangeData& data) { | 140 const ui::OSExchangeData& data) { |
141 gfx::Point tab_strip_loc(event.location()); | 141 gfx::Point tab_strip_loc(event.location()); |
142 ConvertPointToTarget(this, tabstrip(), &tab_strip_loc); | 142 ConvertPointToTarget(this, tabstrip(), &tab_strip_loc); |
143 return new views::DropTargetEvent(data, tab_strip_loc.x(), | 143 return new ui::DropTargetEvent(data, tab_strip_loc, tab_strip_loc, |
144 tab_strip_loc.y(), | 144 event.source_operations()); |
145 event.source_operations()); | |
146 } | 145 } |
147 | 146 |
148 TabStrip* BrowserRootView::tabstrip() const { | 147 TabStrip* BrowserRootView::tabstrip() const { |
149 return browser_view_->tabstrip(); | 148 return browser_view_->tabstrip(); |
150 } | 149 } |
151 | 150 |
152 bool BrowserRootView::GetPasteAndGoURL(const ui::OSExchangeData& data, | 151 bool BrowserRootView::GetPasteAndGoURL(const ui::OSExchangeData& data, |
153 GURL* url) { | 152 GURL* url) { |
154 if (!data.HasString()) | 153 if (!data.HasString()) |
155 return false; | 154 return false; |
156 | 155 |
157 string16 text; | 156 string16 text; |
158 if (!data.GetString(&text) || text.empty()) | 157 if (!data.GetString(&text) || text.empty()) |
159 return false; | 158 return false; |
160 text = AutocompleteMatch::SanitizeString(text); | 159 text = AutocompleteMatch::SanitizeString(text); |
161 | 160 |
162 AutocompleteMatch match; | 161 AutocompleteMatch match; |
163 AutocompleteClassifierFactory::GetForProfile( | 162 AutocompleteClassifierFactory::GetForProfile( |
164 browser_view_->browser()->profile())->Classify(text, string16(), false, | 163 browser_view_->browser()->profile())->Classify(text, string16(), false, |
165 false, &match, NULL); | 164 false, &match, NULL); |
166 if (!match.destination_url.is_valid()) | 165 if (!match.destination_url.is_valid()) |
167 return false; | 166 return false; |
168 | 167 |
169 if (url) | 168 if (url) |
170 *url = match.destination_url; | 169 *url = match.destination_url; |
171 return true; | 170 return true; |
172 } | 171 } |
OLD | NEW |