| 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_shell; | 5 package org.chromium.content_shell; |
| 6 | 6 |
| 7 import android.content.Context; | 7 import android.content.Context; |
| 8 import android.graphics.drawable.ClipDrawable; | 8 import android.graphics.drawable.ClipDrawable; |
| 9 import android.text.TextUtils; | 9 import android.text.TextUtils; |
| 10 import android.util.AttributeSet; | 10 import android.util.AttributeSet; |
| 11 import android.view.KeyEvent; | 11 import android.view.KeyEvent; |
| 12 import android.view.View; | 12 import android.view.View; |
| 13 import android.view.inputmethod.EditorInfo; | 13 import android.view.inputmethod.EditorInfo; |
| 14 import android.view.inputmethod.InputMethodManager; | 14 import android.view.inputmethod.InputMethodManager; |
| 15 import android.widget.EditText; | 15 import android.widget.EditText; |
| 16 import android.widget.FrameLayout; | 16 import android.widget.FrameLayout; |
| 17 import android.widget.ImageButton; | 17 import android.widget.ImageButton; |
| 18 import android.widget.LinearLayout; | 18 import android.widget.LinearLayout; |
| 19 import android.widget.TextView; | 19 import android.widget.TextView; |
| 20 import android.widget.TextView.OnEditorActionListener; | 20 import android.widget.TextView.OnEditorActionListener; |
| 21 | 21 |
| 22 import org.chromium.base.CalledByNative; | 22 import org.chromium.base.CalledByNative; |
| 23 import org.chromium.base.JNINamespace; | 23 import org.chromium.base.JNINamespace; |
| 24 import org.chromium.content.browser.ContentView; | 24 import org.chromium.content.browser.ContentView; |
| 25 import org.chromium.content.browser.ContentViewClient; |
| 25 import org.chromium.content.browser.ContentViewRenderView; | 26 import org.chromium.content.browser.ContentViewRenderView; |
| 26 import org.chromium.content.browser.LoadUrlParams; | 27 import org.chromium.content.browser.LoadUrlParams; |
| 27 import org.chromium.ui.base.WindowAndroid; | 28 import org.chromium.ui.base.WindowAndroid; |
| 28 | 29 |
| 29 /** | 30 /** |
| 30 * Container for the various UI components that make up a shell window. | 31 * Container for the various UI components that make up a shell window. |
| 31 */ | 32 */ |
| 32 @JNINamespace("content") | 33 @JNINamespace("content") |
| 33 public class Shell extends LinearLayout { | 34 public class Shell extends LinearLayout { |
| 34 | 35 |
| 35 private static final long COMPLETED_PROGRESS_TIMEOUT_MS = 200; | 36 private static final long COMPLETED_PROGRESS_TIMEOUT_MS = 200; |
| 36 | 37 |
| 37 private final Runnable mClearProgressRunnable = new Runnable() { | 38 private final Runnable mClearProgressRunnable = new Runnable() { |
| 38 @Override | 39 @Override |
| 39 public void run() { | 40 public void run() { |
| 40 mProgressDrawable.setLevel(0); | 41 mProgressDrawable.setLevel(0); |
| 41 } | 42 } |
| 42 }; | 43 }; |
| 43 | 44 |
| 44 // TODO(jrg): a mContentView.destroy() call is needed, both upstream and dow
nstream. | 45 // TODO(jrg): a mContentView.destroy() call is needed, both upstream and dow
nstream. |
| 45 private ContentView mContentView; | 46 private ContentView mContentView; |
| 47 private ContentViewClient mContentViewClient; |
| 46 private EditText mUrlTextView; | 48 private EditText mUrlTextView; |
| 47 private ImageButton mPrevButton; | 49 private ImageButton mPrevButton; |
| 48 private ImageButton mNextButton; | 50 private ImageButton mNextButton; |
| 49 | 51 |
| 50 private ClipDrawable mProgressDrawable; | 52 private ClipDrawable mProgressDrawable; |
| 51 | 53 |
| 52 private long mNativeShell; | 54 private long mNativeShell; |
| 53 private ContentViewRenderView mContentViewRenderView; | 55 private ContentViewRenderView mContentViewRenderView; |
| 54 private WindowAndroid mWindow; | 56 private WindowAndroid mWindow; |
| 55 | 57 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 78 FrameLayout.LayoutParams.MATCH_PARENT)); | 80 FrameLayout.LayoutParams.MATCH_PARENT)); |
| 79 } | 81 } |
| 80 mContentViewRenderView = contentViewRenderView; | 82 mContentViewRenderView = contentViewRenderView; |
| 81 } | 83 } |
| 82 | 84 |
| 83 /** | 85 /** |
| 84 * Initializes the Shell for use. | 86 * Initializes the Shell for use. |
| 85 * | 87 * |
| 86 * @param nativeShell The pointer to the native Shell object. | 88 * @param nativeShell The pointer to the native Shell object. |
| 87 * @param window The owning window for this shell. | 89 * @param window The owning window for this shell. |
| 90 * @param client The {@link ContentViewClient} to be bound to any current or
new |
| 91 * {@link ContentViewCore}s associated with this shell. |
| 88 */ | 92 */ |
| 89 public void initialize(long nativeShell, WindowAndroid window) { | 93 public void initialize(long nativeShell, WindowAndroid window, ContentViewCl
ient client) { |
| 90 mNativeShell = nativeShell; | 94 mNativeShell = nativeShell; |
| 91 mWindow = window; | 95 mWindow = window; |
| 96 mContentViewClient = client; |
| 92 } | 97 } |
| 93 | 98 |
| 94 /** | 99 /** |
| 95 * Closes the shell and cleans up the native instance, which will handle des
troying all | 100 * Closes the shell and cleans up the native instance, which will handle des
troying all |
| 96 * dependencies. | 101 * dependencies. |
| 97 */ | 102 */ |
| 98 public void close() { | 103 public void close() { |
| 99 if (mNativeShell == 0) return; | 104 if (mNativeShell == 0) return; |
| 100 nativeCloseShell(mNativeShell); | 105 nativeCloseShell(mNativeShell); |
| 101 } | 106 } |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 } | 244 } |
| 240 | 245 |
| 241 /** | 246 /** |
| 242 * Initializes the ContentView based on the native tab contents pointer pass
ed in. | 247 * Initializes the ContentView based on the native tab contents pointer pass
ed in. |
| 243 * @param nativeTabContents The pointer to the native tab contents object. | 248 * @param nativeTabContents The pointer to the native tab contents object. |
| 244 */ | 249 */ |
| 245 @SuppressWarnings("unused") | 250 @SuppressWarnings("unused") |
| 246 @CalledByNative | 251 @CalledByNative |
| 247 private void initFromNativeTabContents(long nativeTabContents) { | 252 private void initFromNativeTabContents(long nativeTabContents) { |
| 248 mContentView = ContentView.newInstance(getContext(), nativeTabContents,
mWindow); | 253 mContentView = ContentView.newInstance(getContext(), nativeTabContents,
mWindow); |
| 254 mContentView.setContentViewClient(mContentViewClient); |
| 249 if (mContentView.getUrl() != null) mUrlTextView.setText(mContentView.get
Url()); | 255 if (mContentView.getUrl() != null) mUrlTextView.setText(mContentView.get
Url()); |
| 250 ((FrameLayout) findViewById(R.id.contentview_holder)).addView(mContentVi
ew, | 256 ((FrameLayout) findViewById(R.id.contentview_holder)).addView(mContentVi
ew, |
| 251 new FrameLayout.LayoutParams( | 257 new FrameLayout.LayoutParams( |
| 252 FrameLayout.LayoutParams.MATCH_PARENT, | 258 FrameLayout.LayoutParams.MATCH_PARENT, |
| 253 FrameLayout.LayoutParams.MATCH_PARENT)); | 259 FrameLayout.LayoutParams.MATCH_PARENT)); |
| 254 mContentView.requestFocus(); | 260 mContentView.requestFocus(); |
| 255 mContentViewRenderView.setCurrentContentView(mContentView); | 261 mContentViewRenderView.setCurrentContentView(mContentView); |
| 256 } | 262 } |
| 257 | 263 |
| 258 /** | 264 /** |
| 259 * @return The {@link ContentView} currently shown by this Shell. | 265 * @return The {@link ContentView} currently shown by this Shell. |
| 260 */ | 266 */ |
| 261 public ContentView getContentView() { | 267 public ContentView getContentView() { |
| 262 return mContentView; | 268 return mContentView; |
| 263 } | 269 } |
| 264 | 270 |
| 265 private void setKeyboardVisibilityForUrl(boolean visible) { | 271 private void setKeyboardVisibilityForUrl(boolean visible) { |
| 266 InputMethodManager imm = (InputMethodManager) getContext().getSystemServ
ice( | 272 InputMethodManager imm = (InputMethodManager) getContext().getSystemServ
ice( |
| 267 Context.INPUT_METHOD_SERVICE); | 273 Context.INPUT_METHOD_SERVICE); |
| 268 if (visible) { | 274 if (visible) { |
| 269 imm.showSoftInput(mUrlTextView, InputMethodManager.SHOW_IMPLICIT); | 275 imm.showSoftInput(mUrlTextView, InputMethodManager.SHOW_IMPLICIT); |
| 270 } else { | 276 } else { |
| 271 imm.hideSoftInputFromWindow(mUrlTextView.getWindowToken(), 0); | 277 imm.hideSoftInputFromWindow(mUrlTextView.getWindowToken(), 0); |
| 272 } | 278 } |
| 273 } | 279 } |
| 274 | 280 |
| 275 private static native void nativeCloseShell(long shellPtr); | 281 private static native void nativeCloseShell(long shellPtr); |
| 276 } | 282 } |
| OLD | NEW |