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 18 matching lines...) Expand all Loading... | |
74 } else { | 76 } else { |
75 contentViewHolder.addView(contentViewRenderView, | 77 contentViewHolder.addView(contentViewRenderView, |
76 new FrameLayout.LayoutParams( | 78 new FrameLayout.LayoutParams( |
77 FrameLayout.LayoutParams.MATCH_PARENT, | 79 FrameLayout.LayoutParams.MATCH_PARENT, |
78 FrameLayout.LayoutParams.MATCH_PARENT)); | 80 FrameLayout.LayoutParams.MATCH_PARENT)); |
79 } | 81 } |
80 mContentViewRenderView = contentViewRenderView; | 82 mContentViewRenderView = contentViewRenderView; |
81 } | 83 } |
82 | 84 |
83 /** | 85 /** |
86 * @param client The {@link ContentViewClient} to be bound to any current or new | |
87 * {@link ContentViewCore}s associated with this {@link Shell} . | |
88 */ | |
89 public void setContentViewClient(ContentViewClient client) { | |
Ted C
2014/02/20 00:54:08
with my comment in ShellManager, you should be abl
| |
90 if (mContentViewClient == client) return; | |
91 | |
92 ContentViewClient oldClient = mContentViewClient; | |
93 mContentViewClient = client; | |
94 | |
95 if (mContentView == null) return; | |
96 | |
97 if (mContentViewClient != null) { | |
98 mContentView.setContentViewClient(mContentViewClient); | |
99 } else if (oldClient != null) { | |
100 // We can't set a null client, but we should clear references to the last one. | |
101 mContentView.setContentViewClient(new ContentViewClient()); | |
102 } | |
103 } | |
104 | |
105 /** | |
84 * Initializes the Shell for use. | 106 * Initializes the Shell for use. |
85 * | 107 * |
86 * @param nativeShell The pointer to the native Shell object. | 108 * @param nativeShell The pointer to the native Shell object. |
87 * @param window The owning window for this shell. | 109 * @param window The owning window for this shell. |
88 */ | 110 */ |
89 public void initialize(long nativeShell, WindowAndroid window) { | 111 public void initialize(long nativeShell, WindowAndroid window) { |
90 mNativeShell = nativeShell; | 112 mNativeShell = nativeShell; |
91 mWindow = window; | 113 mWindow = window; |
92 } | 114 } |
93 | 115 |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
239 } | 261 } |
240 | 262 |
241 /** | 263 /** |
242 * Initializes the ContentView based on the native tab contents pointer pass ed in. | 264 * Initializes the ContentView based on the native tab contents pointer pass ed in. |
243 * @param nativeTabContents The pointer to the native tab contents object. | 265 * @param nativeTabContents The pointer to the native tab contents object. |
244 */ | 266 */ |
245 @SuppressWarnings("unused") | 267 @SuppressWarnings("unused") |
246 @CalledByNative | 268 @CalledByNative |
247 private void initFromNativeTabContents(long nativeTabContents) { | 269 private void initFromNativeTabContents(long nativeTabContents) { |
248 mContentView = ContentView.newInstance(getContext(), nativeTabContents, mWindow); | 270 mContentView = ContentView.newInstance(getContext(), nativeTabContents, mWindow); |
271 if (mContentViewClient != null) mContentView.setContentViewClient(mConte ntViewClient); | |
Ted C
2014/02/20 00:54:08
we will know that mContentViewClient isn't null, s
| |
249 if (mContentView.getUrl() != null) mUrlTextView.setText(mContentView.get Url()); | 272 if (mContentView.getUrl() != null) mUrlTextView.setText(mContentView.get Url()); |
250 ((FrameLayout) findViewById(R.id.contentview_holder)).addView(mContentVi ew, | 273 ((FrameLayout) findViewById(R.id.contentview_holder)).addView(mContentVi ew, |
251 new FrameLayout.LayoutParams( | 274 new FrameLayout.LayoutParams( |
252 FrameLayout.LayoutParams.MATCH_PARENT, | 275 FrameLayout.LayoutParams.MATCH_PARENT, |
253 FrameLayout.LayoutParams.MATCH_PARENT)); | 276 FrameLayout.LayoutParams.MATCH_PARENT)); |
254 mContentView.requestFocus(); | 277 mContentView.requestFocus(); |
255 mContentViewRenderView.setCurrentContentView(mContentView); | 278 mContentViewRenderView.setCurrentContentView(mContentView); |
256 } | 279 } |
257 | 280 |
258 /** | 281 /** |
259 * @return The {@link ContentView} currently shown by this Shell. | 282 * @return The {@link ContentView} currently shown by this Shell. |
260 */ | 283 */ |
261 public ContentView getContentView() { | 284 public ContentView getContentView() { |
262 return mContentView; | 285 return mContentView; |
263 } | 286 } |
264 | 287 |
265 private void setKeyboardVisibilityForUrl(boolean visible) { | 288 private void setKeyboardVisibilityForUrl(boolean visible) { |
266 InputMethodManager imm = (InputMethodManager) getContext().getSystemServ ice( | 289 InputMethodManager imm = (InputMethodManager) getContext().getSystemServ ice( |
267 Context.INPUT_METHOD_SERVICE); | 290 Context.INPUT_METHOD_SERVICE); |
268 if (visible) { | 291 if (visible) { |
269 imm.showSoftInput(mUrlTextView, InputMethodManager.SHOW_IMPLICIT); | 292 imm.showSoftInput(mUrlTextView, InputMethodManager.SHOW_IMPLICIT); |
270 } else { | 293 } else { |
271 imm.hideSoftInputFromWindow(mUrlTextView.getWindowToken(), 0); | 294 imm.hideSoftInputFromWindow(mUrlTextView.getWindowToken(), 0); |
272 } | 295 } |
273 } | 296 } |
274 | 297 |
275 private static native void nativeCloseShell(long shellPtr); | 298 private static native void nativeCloseShell(long shellPtr); |
276 } | 299 } |
OLD | NEW |