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.app.Activity; | 7 import android.app.Activity; |
| 8 import android.content.Context; | 8 import android.content.Context; |
| 9 import android.content.res.Configuration; | 9 import android.content.res.Configuration; |
| 10 import android.graphics.Bitmap; | 10 import android.graphics.Bitmap; |
| 11 import android.graphics.Canvas; | 11 import android.graphics.Canvas; |
| 12 import android.graphics.Rect; | 12 import android.graphics.Rect; |
| 13 import android.os.Build; | 13 import android.os.Build; |
| 14 import android.util.AttributeSet; | 14 import android.util.AttributeSet; |
| 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.accessibility.AccessibilityEvent; | 18 import android.view.accessibility.AccessibilityEvent; |
| 19 import android.view.accessibility.AccessibilityNodeInfo; | 19 import android.view.accessibility.AccessibilityNodeInfo; |
| 20 import android.view.inputmethod.EditorInfo; | 20 import android.view.inputmethod.EditorInfo; |
| 21 import android.view.inputmethod.InputConnection; | 21 import android.view.inputmethod.InputConnection; |
| 22 import android.widget.FrameLayout; | 22 import android.widget.FrameLayout; |
| 23 | 23 |
| 24 import com.google.common.annotations.VisibleForTesting; | 24 import com.google.common.annotations.VisibleForTesting; |
| 25 | 25 |
| 26 import org.chromium.content.common.ProcessInitException; | |
| 27 import org.chromium.content.common.TraceEvent; | 26 import org.chromium.content.common.TraceEvent; |
| 28 import org.chromium.ui.gfx.NativeWindow; | 27 import org.chromium.ui.gfx.WindowAndroid; |
| 29 | |
| 30 import java.util.ArrayList; | |
| 31 | 28 |
| 32 /** | 29 /** |
| 33 * The containing view for {@link ContentViewCore} that exists in the Android UI hierarchy and | 30 * The containing view for {@link ContentViewCore} that exists in the Android UI hierarchy and |
| 34 * exposes the various {@link View} functionality to it. | 31 * exposes the various {@link View} functionality to it. |
| 35 * | 32 * |
| 36 * TODO(joth): Remove any methods overrides from this class that were added for WebView | 33 * TODO(joth): Remove any methods overrides from this class that were added for WebView |
| 37 * compatibility. | 34 * compatibility. |
| 38 */ | 35 */ |
| 39 public class ContentView extends FrameLayout implements ContentViewCore.Internal AccessDelegate { | 36 public class ContentView extends FrameLayout implements ContentViewCore.Internal AccessDelegate { |
| 40 // Used when ContentView implements a standalone View. | 37 // Used when ContentView implements a standalone View. |
| 41 public static final int PERSONALITY_VIEW = ContentViewCore.PERSONALITY_VIEW; | 38 public static final int PERSONALITY_VIEW = ContentViewCore.PERSONALITY_VIEW; |
| 42 // Used for Chrome. | 39 // Used for Chrome. |
| 43 public static final int PERSONALITY_CHROME = ContentViewCore.PERSONALITY_CHR OME; | 40 public static final int PERSONALITY_CHROME = ContentViewCore.PERSONALITY_CHR OME; |
| 44 | 41 |
| 45 private ContentViewCore mContentViewCore; | 42 private ContentViewCore mContentViewCore; |
| 46 | 43 |
| 47 private float mCurrentTouchOffsetX; | 44 private float mCurrentTouchOffsetX; |
| 48 private float mCurrentTouchOffsetY; | 45 private float mCurrentTouchOffsetY; |
| 49 | 46 |
| 50 /** | 47 /** |
| 51 * Creates an instance of a ContentView. | 48 * Creates an instance of a ContentView. |
| 52 * @param context The Context the view is running in, through which it can | 49 * @param context The Context the view is running in, through which it can |
| 53 * access the current theme, resources, etc. | 50 * access the current theme, resources, etc. |
| 54 * @param nativeWebContents A pointer to the native web contents. | 51 * @param nativeWebContents A pointer to the native web contents. |
| 55 * @param nativeWindow An instance of the NativeWindow. | 52 * @param windowAndroid An instance of the WindowAndroid. |
| 56 * @param personality One of {@link #PERSONALITY_CHROME} or {@link #PERSONAL ITY_VIEW}. | 53 * @param personality One of {@link #PERSONALITY_CHROME} or {@link #PERSONAL ITY_VIEW}. |
| 57 * @return A ContentView instance. | 54 * @return A ContentView instance. |
| 58 */ | 55 */ |
| 59 public static ContentView newInstance(Context context, int nativeWebContents , | 56 public static ContentView newInstance(Context context, int nativeWebContents , |
| 60 NativeWindow nativeWindow, int personality) { | 57 WindowAndroid windowAndroid, int personality) { |
| 61 return newInstance(context, nativeWebContents, nativeWindow, null, | 58 return newInstance(context, nativeWebContents, windowAndroid, null, |
| 62 android.R.attr.webViewStyle, personality); | 59 android.R.attr.webViewStyle, personality); |
| 63 } | 60 } |
| 64 | 61 |
| 65 /** | 62 /** |
| 66 * Creates an instance of a ContentView. | 63 * Creates an instance of a ContentView. |
| 67 * @param context The Context the view is running in, through which it can | 64 * @param context The Context the view is running in, through which it can |
| 68 * access the current theme, resources, etc. | 65 * access the current theme, resources, etc. |
| 69 * @param nativeWebContents A pointer to the native web contents. | 66 * @param nativeWebContents A pointer to the native web contents. |
| 70 * @param nativeWindow An instance of the NativeWindow. | 67 * @param windowAndroid An instance of the WindowAndroid. |
| 71 * @param attrs The attributes of the XML tag that is inflating the view. | 68 * @param attrs The attributes of the XML tag that is inflating the view. |
| 72 * @return A ContentView instance. | 69 * @return A ContentView instance. |
| 73 */ | 70 */ |
| 74 public static ContentView newInstance(Context context, int nativeWebContents , | 71 public static ContentView newInstance(Context context, int nativeWebContents , |
| 75 NativeWindow nativeWindow, AttributeSet attrs) { | 72 WindowAndroid windowAndroid, AttributeSet attrs) { |
| 76 // TODO(klobag): use the WebViewStyle as the default style for now. It e nables scrollbar. | 73 // TODO(klobag): use the WebViewStyle as the default style for now. It e nables scrollbar. |
| 77 // When ContentView is moved to framework, we can define its own style i n the res. | 74 // When ContentView is moved to framework, we can define its own style i n the res. |
| 78 return newInstance(context, nativeWebContents, nativeWindow, attrs, | 75 return newInstance(context, nativeWebContents, windowAndroid, attrs, |
| 79 android.R.attr.webViewStyle); | 76 android.R.attr.webViewStyle); |
| 80 } | 77 } |
| 81 | 78 |
| 82 /** | 79 /** |
| 83 * Creates an instance of a ContentView. | 80 * Creates an instance of a ContentView. |
| 84 * @param context The Context the view is running in, through which it can | 81 * @param context The Context the view is running in, through which it can |
| 85 * access the current theme, resources, etc. | 82 * access the current theme, resources, etc. |
| 86 * @param nativeWebContents A pointer to the native web contents. | 83 * @param nativeWebContents A pointer to the native web contents. |
| 87 * @param nativeWindow An instance of the NativeWindow. | 84 * @param windowAndroid An instance of the WindowAndroid. |
| 88 * @param attrs The attributes of the XML tag that is inflating the view. | 85 * @param attrs The attributes of the XML tag that is inflating the view. |
| 89 * @param defStyle The default style to apply to this view. | 86 * @param defStyle The default style to apply to this view. |
| 90 * @return A ContentView instance. | 87 * @return A ContentView instance. |
| 91 */ | 88 */ |
| 92 public static ContentView newInstance(Context context, int nativeWebContents , | 89 public static ContentView newInstance(Context context, int nativeWebContents , |
| 93 NativeWindow nativeWindow, AttributeSet attrs, int defStyle) { | 90 WindowAndroid windowAndroid, AttributeSet attrs, int defStyle) { |
| 94 return newInstance(context, nativeWebContents, nativeWindow, attrs, defS tyle, | 91 return newInstance(context, nativeWebContents, windowAndroid, attrs, def Style, |
| 95 PERSONALITY_VIEW); | 92 PERSONALITY_VIEW); |
| 96 } | 93 } |
| 97 | 94 |
| 98 private static ContentView newInstance(Context context, int nativeWebContent s, | 95 private static ContentView newInstance(Context context, int nativeWebContent s, |
| 99 NativeWindow nativeWindow, AttributeSet attrs, int defStyle, int per sonality) { | 96 WindowAndroid windowAndroid, AttributeSet attrs, int defStyle, int p ersonality) { |
| 100 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) { | 97 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) { |
| 101 return new ContentView(context, nativeWebContents, nativeWindow, att rs, defStyle, | 98 return new ContentView(context, nativeWebContents, windowAndroid, at trs, defStyle, |
| 102 personality); | 99 personality); |
| 103 } else { | 100 } else { |
| 104 return new JellyBeanContentView(context, nativeWebContents, nativeWi ndow, attrs, | 101 return new JellyBeanContentView(context, nativeWebContents, windowAn droid, attrs, |
| 105 defStyle, personality); | 102 defStyle, personality); |
| 106 } | 103 } |
| 107 } | 104 } |
| 108 | 105 |
| 109 protected ContentView(Context context, int nativeWebContents, NativeWindow n ativeWindow, | 106 protected ContentView(Context context, int nativeWebContents, WindowAndroid windowAndroid, |
| 110 AttributeSet attrs, int defStyle, int personality) { | 107 AttributeSet attrs, int defStyle, int personality) { |
|
joth
2013/04/18 01:41:17
OT for this patch, but the 3 overloads that take |
| |
| 111 super(context, attrs, defStyle); | 108 super(context, attrs, defStyle); |
| 112 | 109 |
| 113 mContentViewCore = new ContentViewCore(context, personality); | 110 mContentViewCore = new ContentViewCore(context, personality); |
| 114 mContentViewCore.initialize(this, this, nativeWebContents, nativeWindow, false); | 111 mContentViewCore.initialize(this, this, nativeWebContents, windowAndroid , true, false); |
| 115 } | 112 } |
| 116 | 113 |
| 117 /** | 114 /** |
| 118 * @return The core component of the ContentView that handles JNI communicat ion. Should only be | 115 * @return The core component of the ContentView that handles JNI communicat ion. Should only be |
| 119 * used for passing to native. | 116 * used for passing to native. |
| 120 */ | 117 */ |
| 121 public ContentViewCore getContentViewCore() { | 118 public ContentViewCore getContentViewCore() { |
| 122 return mContentViewCore; | 119 return mContentViewCore; |
| 123 } | 120 } |
| 124 | 121 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 137 * TODO(dtrainor) This is still used by other classes. Make sure to pull so me version of this | 134 * TODO(dtrainor) This is still used by other classes. Make sure to pull so me version of this |
| 138 * out before removing it. | 135 * out before removing it. |
| 139 */ | 136 */ |
| 140 public static boolean hasHardwareAcceleration(Activity activity) { | 137 public static boolean hasHardwareAcceleration(Activity activity) { |
| 141 return ContentViewCore.hasHardwareAcceleration(activity); | 138 return ContentViewCore.hasHardwareAcceleration(activity); |
| 142 } | 139 } |
| 143 | 140 |
| 144 /** | 141 /** |
| 145 * @return Whether the configured personality of this ContentView is {@link #PERSONALITY_VIEW}. | 142 * @return Whether the configured personality of this ContentView is {@link #PERSONALITY_VIEW}. |
| 146 */ | 143 */ |
| 147 boolean isPersonalityView() { | 144 boolean isPersonalityView() { |
|
joth
2013/04/18 01:41:17
(ditto)
| |
| 148 return mContentViewCore.isPersonalityView(); | 145 return mContentViewCore.isPersonalityView(); |
| 149 } | 146 } |
| 150 | 147 |
| 151 /** | 148 /** |
| 152 * Destroy the internal state of the WebView. This method may only be called | 149 * Destroy the internal state of the WebView. This method may only be called |
| 153 * after the WebView has been removed from the view system. No other methods | 150 * after the WebView has been removed from the view system. No other methods |
| 154 * may be called on this WebView after this method has been called. | 151 * may be called on this WebView after this method has been called. |
| 155 */ | 152 */ |
| 156 public void destroy() { | 153 public void destroy() { |
| 157 mContentViewCore.destroy(); | 154 mContentViewCore.destroy(); |
| (...skipping 683 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 841 | 838 |
| 842 @Override | 839 @Override |
| 843 public boolean super_awakenScrollBars(int startDelay, boolean invalidate) { | 840 public boolean super_awakenScrollBars(int startDelay, boolean invalidate) { |
| 844 return super.awakenScrollBars(startDelay, invalidate); | 841 return super.awakenScrollBars(startDelay, invalidate); |
| 845 } | 842 } |
| 846 | 843 |
| 847 //////////////////////////////////////////////////////////////////////////// /////////////////// | 844 //////////////////////////////////////////////////////////////////////////// /////////////////// |
| 848 // End Implementation of ContentViewCore.InternalAccessDelega te // | 845 // End Implementation of ContentViewCore.InternalAccessDelega te // |
| 849 //////////////////////////////////////////////////////////////////////////// /////////////////// | 846 //////////////////////////////////////////////////////////////////////////// /////////////////// |
| 850 } | 847 } |
| OLD | NEW |