Chromium Code Reviews| 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 mPopupZoomer = new PopupZoomer(context); | |
| 306 mContainerView.addView(mPopupZoomer); | |
| 307 PopupZoomer.OnTapListener listener = new PopupZoomer.OnTapListener() { | |
| 308 @Override | |
| 309 public boolean onSingleTap(View v, MotionEvent e) { | |
| 310 mContainerView.requestFocus(); | |
| 311 if (mNativeContentViewCore != 0) { | |
| 312 nativeSingleTap(mNativeContentViewCore, e.getEventTime(), (i nt)e.getX(), | |
|
Ted C
2012/08/23 00:19:08
space after the casts (same for below)
nilesh
2012/08/23 17:04:30
Done.
| |
| 313 (int)e.getY(), true); | |
| 314 } | |
| 315 return true; | |
| 316 } | |
| 317 | |
| 318 @Override | |
| 319 public boolean onLongPress(View v, MotionEvent e) { | |
| 320 if (mNativeContentViewCore != 0) { | |
| 321 nativeLongPress(mNativeContentViewCore, e.getEventTime(), (i nt)e.getX(), | |
| 322 (int)e.getY(), true); | |
| 323 } | |
| 324 return true; | |
| 325 } | |
| 326 }; | |
| 327 mPopupZoomer.setOnTapListener(listener); | |
| 328 } | |
| 329 | |
| 301 /** | 330 /** |
| 302 * @return Whether the configured personality of this ContentView is {@link #PERSONALITY_VIEW}. | 331 * @return Whether the configured personality of this ContentView is {@link #PERSONALITY_VIEW}. |
| 303 */ | 332 */ |
| 304 boolean isPersonalityView() { | 333 boolean isPersonalityView() { |
| 305 switch (mPersonality) { | 334 switch (mPersonality) { |
| 306 case PERSONALITY_VIEW: | 335 case PERSONALITY_VIEW: |
| 307 return true; | 336 return true; |
| 308 case PERSONALITY_CHROME: | 337 case PERSONALITY_CHROME: |
| 309 return false; | 338 return false; |
| 310 default: | 339 default: |
| (...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 695 } else { | 724 } else { |
| 696 return mContainerViewInternals.super_awakenScrollBars(startDelay, in validate); | 725 return mContainerViewInternals.super_awakenScrollBars(startDelay, in validate); |
| 697 } | 726 } |
| 698 } | 727 } |
| 699 | 728 |
| 700 private void handleTapOrPress( | 729 private void handleTapOrPress( |
| 701 long timeMs, int x, int y, boolean isLongPress, boolean showPress) { | 730 long timeMs, int x, int y, boolean isLongPress, boolean showPress) { |
| 702 //TODO(yusufo):Upstream the rest of the bits about handlerControllers. | 731 //TODO(yusufo):Upstream the rest of the bits about handlerControllers. |
| 703 if (!mContainerView.isFocused()) mContainerView.requestFocus(); | 732 if (!mContainerView.isFocused()) mContainerView.requestFocus(); |
| 704 | 733 |
| 734 if (!mPopupZoomer.isShowing()) mPopupZoomer.setLastTouch(x, y); | |
| 735 | |
| 705 if (isLongPress) { | 736 if (isLongPress) { |
| 706 if (mNativeContentViewCore != 0) { | 737 if (mNativeContentViewCore != 0) { |
| 707 nativeLongPress(mNativeContentViewCore, timeMs, x, y, false); | 738 nativeLongPress(mNativeContentViewCore, timeMs, x, y, false); |
| 708 } | 739 } |
| 709 } else { | 740 } else { |
| 710 if (!showPress && mNativeContentViewCore != 0) { | 741 if (!showPress && mNativeContentViewCore != 0) { |
| 711 nativeShowPressState(mNativeContentViewCore, timeMs, x, y); | 742 nativeShowPressState(mNativeContentViewCore, timeMs, x, y); |
| 712 } | 743 } |
| 713 if (mNativeContentViewCore != 0) { | 744 if (mNativeContentViewCore != 0) { |
| 714 nativeSingleTap(mNativeContentViewCore, timeMs, x, y, false); | 745 nativeSingleTap(mNativeContentViewCore, timeMs, x, y, false); |
| (...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1212 | 1243 |
| 1213 private native int nativeEvaluateJavaScript(String script); | 1244 private native int nativeEvaluateJavaScript(String script); |
| 1214 | 1245 |
| 1215 private native void nativeAddJavascriptInterface(int nativeContentViewCoreIm pl, Object object, | 1246 private native void nativeAddJavascriptInterface(int nativeContentViewCoreIm pl, Object object, |
| 1216 String name, boolean requir eAnnotation); | 1247 String name, boolean requir eAnnotation); |
| 1217 | 1248 |
| 1218 private native void nativeRemoveJavascriptInterface(int nativeContentViewCor eImpl, String name); | 1249 private native void nativeRemoveJavascriptInterface(int nativeContentViewCor eImpl, String name); |
| 1219 | 1250 |
| 1220 private native int nativeGetNavigationHistory(int nativeContentViewCoreImpl, Object context); | 1251 private native int nativeGetNavigationHistory(int nativeContentViewCoreImpl, Object context); |
| 1221 } | 1252 } |
| OLD | NEW |