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 package org.chromium.content.browser; | 5 package org.chromium.content.browser; |
6 | 6 |
7 import android.content.Context; | 7 import android.content.Context; |
8 import android.content.res.Configuration; | 8 import android.content.res.Configuration; |
9 import android.graphics.Bitmap; | 9 import android.graphics.Bitmap; |
10 import android.graphics.Canvas; | 10 import android.graphics.Canvas; |
11 import android.os.Build; | 11 import android.os.Build; |
12 import android.os.Bundle; | 12 import android.os.Bundle; |
13 import android.util.Log; | 13 import android.util.Log; |
14 import android.view.ActionMode; | 14 import android.view.ActionMode; |
15 import android.view.KeyEvent; | 15 import android.view.KeyEvent; |
16 import android.view.MotionEvent; | 16 import android.view.MotionEvent; |
17 import android.view.View; | 17 import android.view.View; |
18 import android.view.ViewGroup; | 18 import android.view.ViewGroup; |
19 import android.view.accessibility.AccessibilityEvent; | 19 import android.view.accessibility.AccessibilityEvent; |
20 import android.view.accessibility.AccessibilityNodeInfo; | 20 import android.view.accessibility.AccessibilityNodeInfo; |
21 import android.webkit.DownloadListener; | 21 import android.webkit.DownloadListener; |
22 | 22 |
23 import org.chromium.base.CalledByNative; | 23 import org.chromium.base.CalledByNative; |
24 import org.chromium.base.JNINamespace; | 24 import org.chromium.base.JNINamespace; |
25 import org.chromium.base.WeakContext; | 25 import org.chromium.base.WeakContext; |
26 import org.chromium.content.app.AppResource; | 26 import org.chromium.content.app.AppResource; |
| 27 import org.chromium.content.browser.accessibility.AccessibilityInjector; |
27 import org.chromium.content.browser.ContentViewGestureHandler; | 28 import org.chromium.content.browser.ContentViewGestureHandler; |
| 29 import org.chromium.content.browser.ContentViewGestureHandler.MotionEventDelegat
e; |
28 import org.chromium.content.browser.TouchPoint; | 30 import org.chromium.content.browser.TouchPoint; |
29 import org.chromium.content.browser.ZoomManager; | 31 import org.chromium.content.browser.ZoomManager; |
30 import org.chromium.content.common.CleanupReference; | 32 import org.chromium.content.common.CleanupReference; |
31 import org.chromium.content.common.TraceEvent; | 33 import org.chromium.content.common.TraceEvent; |
32 | 34 |
33 import org.chromium.content.browser.accessibility.AccessibilityInjector; | |
34 import org.chromium.content.browser.ContentViewGestureHandler.MotionEventDelegat
e; | |
35 | |
36 /** | 35 /** |
37 * Provides a Java-side 'wrapper' around a WebContent (native) instance. | 36 * Provides a Java-side 'wrapper' around a WebContent (native) instance. |
38 * Contains all the major functionality necessary to manage the lifecycle of a C
ontentView without | 37 * Contains all the major functionality necessary to manage the lifecycle of a C
ontentView without |
39 * being tied to the view system. | 38 * being tied to the view system. |
40 */ | 39 */ |
41 @JNINamespace("content") | 40 @JNINamespace("content") |
42 public class ContentViewCore implements MotionEventDelegate { | 41 public class ContentViewCore implements MotionEventDelegate { |
43 private static final String TAG = ContentViewCore.class.getName(); | 42 private static final String TAG = ContentViewCore.class.getName(); |
44 | 43 |
45 // The following constants match the ones in chrome/common/page_transition_t
ypes.h. | 44 // The following constants match the ones in chrome/common/page_transition_t
ypes.h. |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 private int mNativeContentViewCore = 0; | 155 private int mNativeContentViewCore = 0; |
157 | 156 |
158 private ContentViewGestureHandler mContentViewGestureHandler; | 157 private ContentViewGestureHandler mContentViewGestureHandler; |
159 private ZoomManager mZoomManager; | 158 private ZoomManager mZoomManager; |
160 | 159 |
161 // Cached page scale factor from native | 160 // Cached page scale factor from native |
162 private float mNativePageScaleFactor = 1.0f; | 161 private float mNativePageScaleFactor = 1.0f; |
163 private float mNativeMinimumScale = 1.0f; | 162 private float mNativeMinimumScale = 1.0f; |
164 private float mNativeMaximumScale = 1.0f; | 163 private float mNativeMaximumScale = 1.0f; |
165 | 164 |
| 165 private PopupZoomer mPopupZoomer; |
| 166 |
166 // TODO(klobag): this is to avoid a bug in GestureDetector. With multi-touch
, | 167 // TODO(klobag): this is to avoid a bug in GestureDetector. With multi-touch
, |
167 // mAlwaysInTapRegion is not reset. So when the last finger is up, onSingleT
apUp() | 168 // mAlwaysInTapRegion is not reset. So when the last finger is up, onSingleT
apUp() |
168 // will be mistakenly fired. | 169 // will be mistakenly fired. |
169 private boolean mIgnoreSingleTap; | 170 private boolean mIgnoreSingleTap; |
170 | 171 |
171 // Only valid when focused on a text / password field. | 172 // Only valid when focused on a text / password field. |
172 private ImeAdapter mImeAdapter; | 173 private ImeAdapter mImeAdapter; |
173 | 174 |
174 // Tracks whether a selection is currently active. When applied to selected
text, indicates | 175 // Tracks whether a selection is currently active. When applied to selected
text, indicates |
175 // whether the last selected text is still highlighted. | 176 // whether the last selected text is still highlighted. |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 } else { | 289 } else { |
289 contentDescription = mContext.getResources().getString( | 290 contentDescription = mContext.getResources().getString( |
290 AppResource.STRING_CONTENT_VIEW_CONTENT_DESCRIPTION); | 291 AppResource.STRING_CONTENT_VIEW_CONTENT_DESCRIPTION); |
291 } | 292 } |
292 mContainerView.setContentDescription(contentDescription); | 293 mContainerView.setContentDescription(contentDescription); |
293 | 294 |
294 mZoomManager = new ZoomManager(context, this); | 295 mZoomManager = new ZoomManager(context, this); |
295 mZoomManager.updateMultiTouchSupport(); | 296 mZoomManager.updateMultiTouchSupport(); |
296 mContentViewGestureHandler = new ContentViewGestureHandler(context, this
, mZoomManager); | 297 mContentViewGestureHandler = new ContentViewGestureHandler(context, this
, mZoomManager); |
297 | 298 |
| 299 initPopupZoomer(mContext); |
| 300 |
298 Log.i(TAG, "mNativeContentView=0x"+ Integer.toHexString(mNativeContentVi
ewCore)); | 301 Log.i(TAG, "mNativeContentView=0x"+ Integer.toHexString(mNativeContentVi
ewCore)); |
299 } | 302 } |
300 | 303 |
| 304 private void initPopupZoomer(Context context){ |
| 305 assert AppResource.DIMENSION_LINK_PREVIEW_OVERLAY_RADIUS != 0; |
| 306 mPopupZoomer = new PopupZoomer(context, AppResource.DIMENSION_LINK_PREVI
EW_OVERLAY_RADIUS); |
| 307 mContainerView.addView(mPopupZoomer); |
| 308 PopupZoomer.OnTapListener listener = new PopupZoomer.OnTapListener() { |
| 309 @Override |
| 310 public boolean onSingleTap(View v, MotionEvent e) { |
| 311 mContainerView.requestFocus(); |
| 312 if (mNativeContentViewCore != 0) { |
| 313 nativeSingleTap(mNativeContentViewCore, e.getEventTime(), (i
nt) e.getX(), |
| 314 (int) e.getY(), true); |
| 315 } |
| 316 return true; |
| 317 } |
| 318 |
| 319 @Override |
| 320 public boolean onLongPress(View v, MotionEvent e) { |
| 321 if (mNativeContentViewCore != 0) { |
| 322 nativeLongPress(mNativeContentViewCore, e.getEventTime(), (i
nt) e.getX(), |
| 323 (int) e.getY(), true); |
| 324 } |
| 325 return true; |
| 326 } |
| 327 }; |
| 328 mPopupZoomer.setOnTapListener(listener); |
| 329 } |
| 330 |
301 /** | 331 /** |
302 * @return Whether the configured personality of this ContentView is {@link
#PERSONALITY_VIEW}. | 332 * @return Whether the configured personality of this ContentView is {@link
#PERSONALITY_VIEW}. |
303 */ | 333 */ |
304 boolean isPersonalityView() { | 334 boolean isPersonalityView() { |
305 switch (mPersonality) { | 335 switch (mPersonality) { |
306 case PERSONALITY_VIEW: | 336 case PERSONALITY_VIEW: |
307 return true; | 337 return true; |
308 case PERSONALITY_CHROME: | 338 case PERSONALITY_CHROME: |
309 return false; | 339 return false; |
310 default: | 340 default: |
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
695 } else { | 725 } else { |
696 return mContainerViewInternals.super_awakenScrollBars(startDelay, in
validate); | 726 return mContainerViewInternals.super_awakenScrollBars(startDelay, in
validate); |
697 } | 727 } |
698 } | 728 } |
699 | 729 |
700 private void handleTapOrPress( | 730 private void handleTapOrPress( |
701 long timeMs, int x, int y, boolean isLongPress, boolean showPress) { | 731 long timeMs, int x, int y, boolean isLongPress, boolean showPress) { |
702 //TODO(yusufo):Upstream the rest of the bits about handlerControllers. | 732 //TODO(yusufo):Upstream the rest of the bits about handlerControllers. |
703 if (!mContainerView.isFocused()) mContainerView.requestFocus(); | 733 if (!mContainerView.isFocused()) mContainerView.requestFocus(); |
704 | 734 |
| 735 if (!mPopupZoomer.isShowing()) mPopupZoomer.setLastTouch(x, y); |
| 736 |
705 if (isLongPress) { | 737 if (isLongPress) { |
706 if (mNativeContentViewCore != 0) { | 738 if (mNativeContentViewCore != 0) { |
707 nativeLongPress(mNativeContentViewCore, timeMs, x, y, false); | 739 nativeLongPress(mNativeContentViewCore, timeMs, x, y, false); |
708 } | 740 } |
709 } else { | 741 } else { |
710 if (!showPress && mNativeContentViewCore != 0) { | 742 if (!showPress && mNativeContentViewCore != 0) { |
711 nativeShowPressState(mNativeContentViewCore, timeMs, x, y); | 743 nativeShowPressState(mNativeContentViewCore, timeMs, x, y); |
712 } | 744 } |
713 if (mNativeContentViewCore != 0) { | 745 if (mNativeContentViewCore != 0) { |
714 nativeSingleTap(mNativeContentViewCore, timeMs, x, y, false); | 746 nativeSingleTap(mNativeContentViewCore, timeMs, x, y, false); |
(...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1212 | 1244 |
1213 private native int nativeEvaluateJavaScript(String script); | 1245 private native int nativeEvaluateJavaScript(String script); |
1214 | 1246 |
1215 private native void nativeAddJavascriptInterface(int nativeContentViewCoreIm
pl, Object object, | 1247 private native void nativeAddJavascriptInterface(int nativeContentViewCoreIm
pl, Object object, |
1216 String name, boolean requir
eAnnotation); | 1248 String name, boolean requir
eAnnotation); |
1217 | 1249 |
1218 private native void nativeRemoveJavascriptInterface(int nativeContentViewCor
eImpl, String name); | 1250 private native void nativeRemoveJavascriptInterface(int nativeContentViewCor
eImpl, String name); |
1219 | 1251 |
1220 private native int nativeGetNavigationHistory(int nativeContentViewCoreImpl,
Object context); | 1252 private native int nativeGetNavigationHistory(int nativeContentViewCoreImpl,
Object context); |
1221 } | 1253 } |
OLD | NEW |