| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 package org.chromium.ui.base; | 5 package org.chromium.ui.base; |
| 6 | 6 |
| 7 import android.content.ClipData; | 7 import android.content.ClipData; |
| 8 import android.graphics.Bitmap; | 8 import android.graphics.Bitmap; |
| 9 import android.os.Build; | 9 import android.os.Build; |
| 10 import android.view.View; | 10 import android.view.View; |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 | 82 |
| 83 /** | 83 /** |
| 84 * Drag the text out of current view. | 84 * Drag the text out of current view. |
| 85 * @param text The dragged text. | 85 * @param text The dragged text. |
| 86 * @param shadowImage The shadow image for the dragged text. | 86 * @param shadowImage The shadow image for the dragged text. |
| 87 */ | 87 */ |
| 88 @SuppressWarnings("deprecation") | 88 @SuppressWarnings("deprecation") |
| 89 // TODO(hush): uncomment below when we build with API 24. | 89 // TODO(hush): uncomment below when we build with API 24. |
| 90 // @TargetApi(Build.VERSION_CODES.N) | 90 // @TargetApi(Build.VERSION_CODES.N) |
| 91 @CalledByNative | 91 @CalledByNative |
| 92 private boolean startDragAndDrop(String text, Bitmap shadowImage) { | 92 private boolean startDragAndDrop(String text, Bitmap shadowImage, float page
Scale) { |
| 93 if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.M) return false; | 93 if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.M) return false; |
| 94 | 94 |
| 95 ViewGroup containerView = getContainerView(); | 95 ViewGroup containerView = getContainerView(); |
| 96 if (containerView == null) return false; | 96 if (containerView == null) return false; |
| 97 | 97 |
| 98 ImageView imageView = new ImageView(containerView.getContext()); | 98 ImageView imageView = new ImageView(containerView.getContext()); |
| 99 imageView.setImageBitmap(shadowImage); | 99 imageView.setImageBitmap(shadowImage); |
| 100 imageView.layout(0, 0, shadowImage.getWidth(), shadowImage.getHeight()); | 100 // The width and height of shadowImage are already normalized by DIP sca
le. Now we just |
| 101 // need to normalize it by page scale. |
| 102 imageView.layout(0, 0, (int) (shadowImage.getWidth() * pageScale), |
| 103 (int) (shadowImage.getHeight() * pageScale)); |
| 101 | 104 |
| 102 // TODO(hush): use View#startDragAndDrop when Chromium starts to build w
ith API 24. | 105 // TODO(hush): use View#startDragAndDrop when Chromium starts to build w
ith API 24. |
| 103 return containerView.startDrag(ClipData.newPlainText(null, text), | 106 return containerView.startDrag(ClipData.newPlainText(null, text), |
| 104 new View.DragShadowBuilder(imageView), null, DRAG_FLAG_GLOBAL); | 107 new View.DragShadowBuilder(imageView), null, DRAG_FLAG_GLOBAL); |
| 105 } | 108 } |
| 106 | 109 |
| 107 /** | 110 /** |
| 108 * @return container view that the anchor views are added to. May be null. | 111 * @return container view that the anchor views are added to. May be null. |
| 109 */ | 112 */ |
| 110 public abstract ViewGroup getContainerView(); | 113 public abstract ViewGroup getContainerView(); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 124 return this; | 127 return this; |
| 125 } | 128 } |
| 126 | 129 |
| 127 @Override | 130 @Override |
| 128 public ViewGroup getContainerView() { | 131 public ViewGroup getContainerView() { |
| 129 return mContainerView; | 132 return mContainerView; |
| 130 } | 133 } |
| 131 }.init(containerView); | 134 }.init(containerView); |
| 132 } | 135 } |
| 133 } | 136 } |
| OLD | NEW |