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.content.browser; | 5 package org.chromium.content.browser; |
6 | 6 |
7 import android.annotation.SuppressLint; | 7 import android.annotation.SuppressLint; |
8 import android.annotation.TargetApi; | 8 import android.annotation.TargetApi; |
9 import android.app.assist.AssistStructure.ViewNode; | 9 import android.app.assist.AssistStructure.ViewNode; |
10 import android.content.ClipData; | |
11 import android.content.ClipDescription; | |
12 import android.content.Context; | 10 import android.content.Context; |
13 import android.content.Intent; | 11 import android.content.Intent; |
14 import android.content.res.Configuration; | 12 import android.content.res.Configuration; |
15 import android.graphics.Bitmap; | 13 import android.graphics.Bitmap; |
16 import android.graphics.Rect; | 14 import android.graphics.Rect; |
17 import android.os.Build; | 15 import android.os.Build; |
18 import android.os.Bundle; | 16 import android.os.Bundle; |
19 import android.os.SystemClock; | 17 import android.os.SystemClock; |
20 import android.util.Pair; | 18 import android.util.Pair; |
21 import android.view.ActionMode; | 19 import android.view.ActionMode; |
22 import android.view.DragEvent; | |
23 import android.view.HapticFeedbackConstants; | 20 import android.view.HapticFeedbackConstants; |
24 import android.view.InputDevice; | 21 import android.view.InputDevice; |
25 import android.view.KeyEvent; | 22 import android.view.KeyEvent; |
26 import android.view.MotionEvent; | 23 import android.view.MotionEvent; |
27 import android.view.Surface; | 24 import android.view.Surface; |
28 import android.view.View; | 25 import android.view.View; |
29 import android.view.ViewGroup; | 26 import android.view.ViewGroup; |
30 import android.view.ViewStructure; | 27 import android.view.ViewStructure; |
31 import android.view.accessibility.AccessibilityEvent; | 28 import android.view.accessibility.AccessibilityEvent; |
32 import android.view.accessibility.AccessibilityManager; | 29 import android.view.accessibility.AccessibilityManager; |
(...skipping 2117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2150 return new Rect(x, y, right, bottom); | 2147 return new Rect(x, y, right, bottom); |
2151 } | 2148 } |
2152 | 2149 |
2153 public void setBackgroundOpaque(boolean opaque) { | 2150 public void setBackgroundOpaque(boolean opaque) { |
2154 if (mNativeContentViewCore != 0) { | 2151 if (mNativeContentViewCore != 0) { |
2155 nativeSetBackgroundOpaque(mNativeContentViewCore, opaque); | 2152 nativeSetBackgroundOpaque(mNativeContentViewCore, opaque); |
2156 } | 2153 } |
2157 } | 2154 } |
2158 | 2155 |
2159 /** | 2156 /** |
2160 * @see View#onDragEvent(DragEvent) | |
2161 */ | |
2162 @TargetApi(Build.VERSION_CODES.N) | |
2163 public boolean onDragEvent(DragEvent event) { | |
2164 if (mNativeContentViewCore == 0 || Build.VERSION.SDK_INT <= Build.VERSIO
N_CODES.M) { | |
2165 return false; | |
2166 } | |
2167 | |
2168 ClipDescription clipDescription = event.getClipDescription(); | |
2169 | |
2170 // text/* will match text/uri-list, text/html, text/plain. | |
2171 String[] mimeTypes = | |
2172 clipDescription == null ? new String[0] : clipDescription.filter
MimeTypes("text/*"); | |
2173 | |
2174 if (event.getAction() == DragEvent.ACTION_DRAG_STARTED) { | |
2175 // TODO(hush): support dragging more than just text. | |
2176 return mimeTypes != null && mimeTypes.length > 0 | |
2177 && nativeIsTouchDragDropEnabled(mNativeContentViewCore); | |
2178 } | |
2179 | |
2180 StringBuilder content = new StringBuilder(""); | |
2181 if (event.getAction() == DragEvent.ACTION_DROP) { | |
2182 // TODO(hush): obtain dragdrop permissions, when dragging files into
Chrome/WebView is | |
2183 // supported. Not necessary to do so for now, because only text drag
ging is supported. | |
2184 ClipData clipData = event.getClipData(); | |
2185 final int itemCount = clipData.getItemCount(); | |
2186 for (int i = 0; i < itemCount; i++) { | |
2187 ClipData.Item item = clipData.getItemAt(i); | |
2188 content.append(item.coerceToStyledText(mContainerView.getContext
())); | |
2189 } | |
2190 } | |
2191 | |
2192 int[] locationOnScreen = new int[2]; | |
2193 mContainerView.getLocationOnScreen(locationOnScreen); | |
2194 | |
2195 float xPix = event.getX() + mCurrentTouchOffsetX; | |
2196 float yPix = event.getY() + mCurrentTouchOffsetY; | |
2197 | |
2198 int xCss = (int) mRenderCoordinates.fromPixToDip(xPix); | |
2199 int yCss = (int) mRenderCoordinates.fromPixToDip(yPix); | |
2200 int screenXCss = (int) mRenderCoordinates.fromPixToDip(xPix + locationOn
Screen[0]); | |
2201 int screenYCss = (int) mRenderCoordinates.fromPixToDip(yPix + locationOn
Screen[1]); | |
2202 | |
2203 nativeOnDragEvent(mNativeContentViewCore, event.getAction(), xCss, yCss,
screenXCss, | |
2204 screenYCss, mimeTypes, content.toString()); | |
2205 return true; | |
2206 } | |
2207 | |
2208 /** | |
2209 * Offer a long press gesture to the embedding View, primarily for WebView c
ompatibility. | 2157 * Offer a long press gesture to the embedding View, primarily for WebView c
ompatibility. |
2210 * | 2158 * |
2211 * @return true if the embedder handled the event. | 2159 * @return true if the embedder handled the event. |
2212 */ | 2160 */ |
2213 private boolean offerLongPressToEmbedder() { | 2161 private boolean offerLongPressToEmbedder() { |
2214 return mContainerView.performLongClick(); | 2162 return mContainerView.performLongClick(); |
2215 } | 2163 } |
2216 | 2164 |
2217 /** | 2165 /** |
2218 * Reset scroll and fling accounting, notifying listeners as appropriate. | 2166 * Reset scroll and fling accounting, notifying listeners as appropriate. |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2408 | 2356 |
2409 private native void nativeSetAccessibilityEnabled( | 2357 private native void nativeSetAccessibilityEnabled( |
2410 long nativeContentViewCoreImpl, boolean enabled); | 2358 long nativeContentViewCoreImpl, boolean enabled); |
2411 | 2359 |
2412 private native void nativeSetTextTrackSettings(long nativeContentViewCoreImp
l, | 2360 private native void nativeSetTextTrackSettings(long nativeContentViewCoreImp
l, |
2413 boolean textTracksEnabled, String textTrackBackgroundColor, String t
extTrackFontFamily, | 2361 boolean textTracksEnabled, String textTrackBackgroundColor, String t
extTrackFontFamily, |
2414 String textTrackFontStyle, String textTrackFontVariant, String textT
rackTextColor, | 2362 String textTrackFontStyle, String textTrackFontVariant, String textT
rackTextColor, |
2415 String textTrackTextShadow, String textTrackTextSize); | 2363 String textTrackTextShadow, String textTrackTextSize); |
2416 | 2364 |
2417 private native void nativeSetBackgroundOpaque(long nativeContentViewCoreImpl
, boolean opaque); | 2365 private native void nativeSetBackgroundOpaque(long nativeContentViewCoreImpl
, boolean opaque); |
2418 private native boolean nativeIsTouchDragDropEnabled(long nativeContentViewCo
reImpl); | |
2419 private native void nativeOnDragEvent(long nativeContentViewCoreImpl, int ac
tion, int x, int y, | |
2420 int screenX, int screenY, String[] mimeTypes, String content); | |
2421 } | 2366 } |
OLD | NEW |