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; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 }; | 42 }; |
43 | 43 |
44 // TODO(jrg): a mContentView.destroy() call is needed, both upstream and dow
nstream. | 44 // TODO(jrg): a mContentView.destroy() call is needed, both upstream and dow
nstream. |
45 private ContentView mContentView; | 45 private ContentView mContentView; |
46 private EditText mUrlTextView; | 46 private EditText mUrlTextView; |
47 private ImageButton mPrevButton; | 47 private ImageButton mPrevButton; |
48 private ImageButton mNextButton; | 48 private ImageButton mNextButton; |
49 | 49 |
50 private ClipDrawable mProgressDrawable; | 50 private ClipDrawable mProgressDrawable; |
51 | 51 |
| 52 private long mNativeShell; |
52 private ContentViewRenderView mContentViewRenderView; | 53 private ContentViewRenderView mContentViewRenderView; |
53 private WindowAndroid mWindow; | 54 private WindowAndroid mWindow; |
54 | 55 |
55 private boolean mLoading = false; | 56 private boolean mLoading = false; |
56 | 57 |
57 /** | 58 /** |
58 * Constructor for inflating via XML. | 59 * Constructor for inflating via XML. |
59 */ | 60 */ |
60 public Shell(Context context, AttributeSet attrs) { | 61 public Shell(Context context, AttributeSet attrs) { |
61 super(context, attrs); | 62 super(context, attrs); |
(...skipping 11 matching lines...) Expand all Loading... |
73 } else { | 74 } else { |
74 contentViewHolder.addView(contentViewRenderView, | 75 contentViewHolder.addView(contentViewRenderView, |
75 new FrameLayout.LayoutParams( | 76 new FrameLayout.LayoutParams( |
76 FrameLayout.LayoutParams.MATCH_PARENT, | 77 FrameLayout.LayoutParams.MATCH_PARENT, |
77 FrameLayout.LayoutParams.MATCH_PARENT)); | 78 FrameLayout.LayoutParams.MATCH_PARENT)); |
78 } | 79 } |
79 mContentViewRenderView = contentViewRenderView; | 80 mContentViewRenderView = contentViewRenderView; |
80 } | 81 } |
81 | 82 |
82 /** | 83 /** |
| 84 * Initializes the Shell for use. |
| 85 * |
| 86 * @param nativeShell The pointer to the native Shell object. |
83 * @param window The owning window for this shell. | 87 * @param window The owning window for this shell. |
84 */ | 88 */ |
85 public void setWindow(WindowAndroid window) { | 89 public void initialize(long nativeShell, WindowAndroid window) { |
| 90 mNativeShell = nativeShell; |
86 mWindow = window; | 91 mWindow = window; |
87 } | 92 } |
88 | 93 |
89 /** | 94 /** |
| 95 * Closes the shell and cleans up the native instance, which will handle des
troying all |
| 96 * dependencies. |
| 97 */ |
| 98 public void close() { |
| 99 if (mNativeShell == 0) return; |
| 100 nativeCloseShell(mNativeShell); |
| 101 } |
| 102 |
| 103 @CalledByNative |
| 104 private void onNativeDestroyed() { |
| 105 mWindow = null; |
| 106 mNativeShell = 0; |
| 107 assert !mContentView.isAttachedToWindow() |
| 108 : "Attempting to destroy the content view while attached to the
view hierarchy."; |
| 109 mContentView.destroy(); |
| 110 } |
| 111 |
| 112 /** |
| 113 * @return Whether the Shell has been destroyed. |
| 114 * @see #onNativeDestroyed() |
| 115 */ |
| 116 public boolean isDestroyed() { |
| 117 return mNativeShell == 0; |
| 118 } |
| 119 |
| 120 /** |
90 * @return Whether or not the Shell is loading content. | 121 * @return Whether or not the Shell is loading content. |
91 */ | 122 */ |
92 public boolean isLoading() { | 123 public boolean isLoading() { |
93 return mLoading; | 124 return mLoading; |
94 } | 125 } |
95 | 126 |
96 @Override | 127 @Override |
97 protected void onFinishInflate() { | 128 protected void onFinishInflate() { |
98 super.onFinishInflate(); | 129 super.onFinishInflate(); |
99 | 130 |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 | 266 |
236 private void setKeyboardVisibilityForUrl(boolean visible) { | 267 private void setKeyboardVisibilityForUrl(boolean visible) { |
237 InputMethodManager imm = (InputMethodManager) getContext().getSystemServ
ice( | 268 InputMethodManager imm = (InputMethodManager) getContext().getSystemServ
ice( |
238 Context.INPUT_METHOD_SERVICE); | 269 Context.INPUT_METHOD_SERVICE); |
239 if (visible) { | 270 if (visible) { |
240 imm.showSoftInput(mUrlTextView, InputMethodManager.SHOW_IMPLICIT); | 271 imm.showSoftInput(mUrlTextView, InputMethodManager.SHOW_IMPLICIT); |
241 } else { | 272 } else { |
242 imm.hideSoftInputFromWindow(mUrlTextView.getWindowToken(), 0); | 273 imm.hideSoftInputFromWindow(mUrlTextView.getWindowToken(), 0); |
243 } | 274 } |
244 } | 275 } |
| 276 |
| 277 private static native void nativeCloseShell(long shellPtr); |
245 } | 278 } |
OLD | NEW |