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 "content/browser/web_contents/web_contents_view_android.h" | 5 #include "content/browser/web_contents/web_contents_view_android.h" |
6 | 6 |
7 #include "base/android/jni_android.h" | |
8 #include "base/android/jni_string.h" | |
7 #include "base/logging.h" | 9 #include "base/logging.h" |
8 #include "content/browser/android/content_view_core_impl.h" | 10 #include "content/browser/android/content_view_core_impl.h" |
9 #include "content/browser/frame_host/interstitial_page_impl.h" | 11 #include "content/browser/frame_host/interstitial_page_impl.h" |
10 #include "content/browser/renderer_host/render_widget_host_view_android.h" | 12 #include "content/browser/renderer_host/render_widget_host_view_android.h" |
11 #include "content/browser/renderer_host/render_view_host_factory.h" | 13 #include "content/browser/renderer_host/render_view_host_factory.h" |
12 #include "content/browser/renderer_host/render_view_host_impl.h" | 14 #include "content/browser/renderer_host/render_view_host_impl.h" |
13 #include "content/browser/web_contents/web_contents_impl.h" | 15 #include "content/browser/web_contents/web_contents_impl.h" |
14 #include "content/public/browser/render_widget_host.h" | 16 #include "content/public/browser/render_widget_host.h" |
15 #include "content/public/browser/web_contents_delegate.h" | 17 #include "content/public/browser/web_contents_delegate.h" |
16 #include "content/public/common/drop_data.h" | 18 #include "content/public/common/drop_data.h" |
19 #include "ui/gfx/android/java_bitmap.h" | |
20 #include "ui/gfx/image/image_skia.h" | |
21 | |
22 using base::android::AttachCurrentThread; | |
23 using base::android::ConvertUTF16ToJavaString; | |
24 using base::android::JavaRef; | |
25 using base::android::ScopedJavaLocalRef; | |
17 | 26 |
18 namespace content { | 27 namespace content { |
19 | 28 |
20 WebContentsView* CreateWebContentsView( | 29 WebContentsView* CreateWebContentsView( |
21 WebContentsImpl* web_contents, | 30 WebContentsImpl* web_contents, |
22 WebContentsViewDelegate* delegate, | 31 WebContentsViewDelegate* delegate, |
23 RenderViewHostDelegateView** render_view_host_delegate_view) { | 32 RenderViewHostDelegateView** render_view_host_delegate_view) { |
24 WebContentsViewAndroid* rv = new WebContentsViewAndroid( | 33 WebContentsViewAndroid* rv = new WebContentsViewAndroid( |
25 web_contents, delegate); | 34 web_contents, delegate); |
26 *render_view_host_delegate_view = rv; | 35 *render_view_host_delegate_view = rv; |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
192 if (content_view_core_) | 201 if (content_view_core_) |
193 content_view_core_->HideSelectPopupMenu(); | 202 content_view_core_->HideSelectPopupMenu(); |
194 } | 203 } |
195 | 204 |
196 void WebContentsViewAndroid::StartDragging( | 205 void WebContentsViewAndroid::StartDragging( |
197 const DropData& drop_data, | 206 const DropData& drop_data, |
198 blink::WebDragOperationsMask allowed_ops, | 207 blink::WebDragOperationsMask allowed_ops, |
199 const gfx::ImageSkia& image, | 208 const gfx::ImageSkia& image, |
200 const gfx::Vector2d& image_offset, | 209 const gfx::Vector2d& image_offset, |
201 const DragEventSourceInfo& event_info) { | 210 const DragEventSourceInfo& event_info) { |
202 NOTIMPLEMENTED(); | 211 if (drop_data.text.is_null()) |
212 return; | |
213 | |
214 gfx::NativeView native_view = GetNativeView(); | |
215 if (!native_view) | |
216 return; | |
217 | |
218 JNIEnv* env = AttachCurrentThread(); | |
219 ScopedJavaLocalRef<jstring> jtext = | |
220 ConvertUTF16ToJavaString(env, drop_data.text.string()); | |
221 | |
222 native_view->StartDragAndDrop(jtext, | |
sgurun-gerrit only
2016/07/14 18:13:35
it is better to convert the java type in location
hush (inactive)
2016/07/14 18:37:07
because window_android is in ui and cannot depend
sgurun-gerrit only
2016/07/14 18:43:04
ok in this case, I am fine.
Daniel:
By convertin
no sievers
2016/07/14 20:31:13
I think we'll probably want to eventually just add
| |
223 gfx::ConvertToJavaBitmap(image.bitmap())); | |
224 | |
225 if (content_view_core_) | |
226 content_view_core_->HidePopupsAndPreserveSelection(); | |
203 } | 227 } |
204 | 228 |
205 void WebContentsViewAndroid::UpdateDragCursor(blink::WebDragOperation op) { | 229 void WebContentsViewAndroid::UpdateDragCursor(blink::WebDragOperation op) { |
206 // Intentional no-op because Android does not have cursor. | 230 // Intentional no-op because Android does not have cursor. |
207 } | 231 } |
208 | 232 |
209 void WebContentsViewAndroid::OnDragEntered( | 233 void WebContentsViewAndroid::OnDragEntered( |
210 const std::vector<DropData::Metadata>& metadata, | 234 const std::vector<DropData::Metadata>& metadata, |
211 const gfx::Point& location, | 235 const gfx::Point& location, |
212 const gfx::Point& screen_location) { | 236 const gfx::Point& screen_location) { |
237 blink::WebDragOperationsMask allowed_ops = | |
238 static_cast<blink::WebDragOperationsMask>(blink::WebDragOperationCopy | | |
239 blink::WebDragOperationMove); | |
213 web_contents_->GetRenderViewHost()->DragTargetDragEnterWithMetaData( | 240 web_contents_->GetRenderViewHost()->DragTargetDragEnterWithMetaData( |
214 metadata, location, screen_location, blink::WebDragOperationCopy, 0); | 241 metadata, location, screen_location, allowed_ops, 0); |
215 } | 242 } |
216 | 243 |
217 void WebContentsViewAndroid::OnDragUpdated(const gfx::Point& location, | 244 void WebContentsViewAndroid::OnDragUpdated(const gfx::Point& location, |
218 const gfx::Point& screen_location) { | 245 const gfx::Point& screen_location) { |
246 blink::WebDragOperationsMask allowed_ops = | |
247 static_cast<blink::WebDragOperationsMask>(blink::WebDragOperationCopy | | |
248 blink::WebDragOperationMove); | |
219 web_contents_->GetRenderViewHost()->DragTargetDragOver( | 249 web_contents_->GetRenderViewHost()->DragTargetDragOver( |
220 location, screen_location, blink::WebDragOperationCopy, 0); | 250 location, screen_location, allowed_ops, 0); |
221 } | 251 } |
222 | 252 |
223 void WebContentsViewAndroid::OnDragExited() { | 253 void WebContentsViewAndroid::OnDragExited() { |
224 web_contents_->GetRenderViewHost()->DragTargetDragLeave(); | 254 web_contents_->GetRenderViewHost()->DragTargetDragLeave(); |
225 } | 255 } |
226 | 256 |
227 void WebContentsViewAndroid::OnPerformDrop(DropData* drop_data, | 257 void WebContentsViewAndroid::OnPerformDrop(DropData* drop_data, |
228 const gfx::Point& location, | 258 const gfx::Point& location, |
229 const gfx::Point& screen_location) { | 259 const gfx::Point& screen_location) { |
230 web_contents_->GetRenderViewHost()->FilterDropData(drop_data); | 260 web_contents_->GetRenderViewHost()->FilterDropData(drop_data); |
231 web_contents_->GetRenderViewHost()->DragTargetDrop(*drop_data, location, | 261 web_contents_->GetRenderViewHost()->DragTargetDrop(*drop_data, location, |
232 screen_location, 0); | 262 screen_location, 0); |
233 } | 263 } |
234 | 264 |
265 void WebContentsViewAndroid::OnDragEnded() { | |
266 web_contents_->GetRenderViewHost()->DragSourceSystemDragEnded(); | |
267 } | |
268 | |
235 void WebContentsViewAndroid::GotFocus() { | 269 void WebContentsViewAndroid::GotFocus() { |
236 // This is only used in the views FocusManager stuff but it bleeds through | 270 // This is only used in the views FocusManager stuff but it bleeds through |
237 // all subclasses. http://crbug.com/21875 | 271 // all subclasses. http://crbug.com/21875 |
238 } | 272 } |
239 | 273 |
240 // This is called when we the renderer asks us to take focus back (i.e., it has | 274 // This is called when we the renderer asks us to take focus back (i.e., it has |
241 // iterated past the last focusable element on the page). | 275 // iterated past the last focusable element on the page). |
242 void WebContentsViewAndroid::TakeFocus(bool reverse) { | 276 void WebContentsViewAndroid::TakeFocus(bool reverse) { |
243 if (web_contents_->GetDelegate() && | 277 if (web_contents_->GetDelegate() && |
244 web_contents_->GetDelegate()->TakeFocus(web_contents_, reverse)) | 278 web_contents_->GetDelegate()->TakeFocus(web_contents_, reverse)) |
245 return; | 279 return; |
246 web_contents_->GetRenderWidgetHostView()->Focus(); | 280 web_contents_->GetRenderWidgetHostView()->Focus(); |
247 } | 281 } |
248 | 282 |
249 } // namespace content | 283 } // namespace content |
OLD | NEW |