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 26 matching lines...) Expand all Loading... |
37 | 37 |
38 private static final long COMPLETED_PROGRESS_TIMEOUT_MS = 200; | 38 private static final long COMPLETED_PROGRESS_TIMEOUT_MS = 200; |
39 | 39 |
40 private final Runnable mClearProgressRunnable = new Runnable() { | 40 private final Runnable mClearProgressRunnable = new Runnable() { |
41 @Override | 41 @Override |
42 public void run() { | 42 public void run() { |
43 mProgressDrawable.setLevel(0); | 43 mProgressDrawable.setLevel(0); |
44 } | 44 } |
45 }; | 45 }; |
46 | 46 |
47 private ContentView mContentView; | |
48 private ContentViewCore mContentViewCore; | 47 private ContentViewCore mContentViewCore; |
49 private ContentViewClient mContentViewClient; | 48 private ContentViewClient mContentViewClient; |
50 private EditText mUrlTextView; | 49 private EditText mUrlTextView; |
51 private ImageButton mPrevButton; | 50 private ImageButton mPrevButton; |
52 private ImageButton mNextButton; | 51 private ImageButton mNextButton; |
53 | 52 |
54 private ClipDrawable mProgressDrawable; | 53 private ClipDrawable mProgressDrawable; |
55 | 54 |
56 private long mNativeShell; | 55 private long mNativeShell; |
57 private ContentViewRenderView mContentViewRenderView; | 56 private ContentViewRenderView mContentViewRenderView; |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 mUrlTextView.setOnEditorActionListener(new OnEditorActionListener() { | 142 mUrlTextView.setOnEditorActionListener(new OnEditorActionListener() { |
144 @Override | 143 @Override |
145 public boolean onEditorAction(TextView v, int actionId, KeyEvent eve
nt) { | 144 public boolean onEditorAction(TextView v, int actionId, KeyEvent eve
nt) { |
146 if ((actionId != EditorInfo.IME_ACTION_GO) && (event == null || | 145 if ((actionId != EditorInfo.IME_ACTION_GO) && (event == null || |
147 event.getKeyCode() != KeyEvent.KEYCODE_ENTER || | 146 event.getKeyCode() != KeyEvent.KEYCODE_ENTER || |
148 event.getAction() != KeyEvent.ACTION_DOWN)) { | 147 event.getAction() != KeyEvent.ACTION_DOWN)) { |
149 return false; | 148 return false; |
150 } | 149 } |
151 loadUrl(mUrlTextView.getText().toString()); | 150 loadUrl(mUrlTextView.getText().toString()); |
152 setKeyboardVisibilityForUrl(false); | 151 setKeyboardVisibilityForUrl(false); |
153 mContentView.requestFocus(); | 152 mContentViewCore.getContainerView().requestFocus(); |
154 return true; | 153 return true; |
155 } | 154 } |
156 }); | 155 }); |
157 mUrlTextView.setOnFocusChangeListener(new OnFocusChangeListener() { | 156 mUrlTextView.setOnFocusChangeListener(new OnFocusChangeListener() { |
158 @Override | 157 @Override |
159 public void onFocusChange(View v, boolean hasFocus) { | 158 public void onFocusChange(View v, boolean hasFocus) { |
160 setKeyboardVisibilityForUrl(hasFocus); | 159 setKeyboardVisibilityForUrl(hasFocus); |
161 mNextButton.setVisibility(hasFocus ? GONE : VISIBLE); | 160 mNextButton.setVisibility(hasFocus ? GONE : VISIBLE); |
162 mPrevButton.setVisibility(hasFocus ? GONE : VISIBLE); | 161 mPrevButton.setVisibility(hasFocus ? GONE : VISIBLE); |
163 if (!hasFocus) { | 162 if (!hasFocus) { |
(...skipping 12 matching lines...) Expand all Loading... |
176 public void loadUrl(String url) { | 175 public void loadUrl(String url) { |
177 if (url == null) return; | 176 if (url == null) return; |
178 | 177 |
179 if (TextUtils.equals(url, mContentViewCore.getUrl())) { | 178 if (TextUtils.equals(url, mContentViewCore.getUrl())) { |
180 mContentViewCore.reload(true); | 179 mContentViewCore.reload(true); |
181 } else { | 180 } else { |
182 mContentViewCore.loadUrl(new LoadUrlParams(sanitizeUrl(url))); | 181 mContentViewCore.loadUrl(new LoadUrlParams(sanitizeUrl(url))); |
183 } | 182 } |
184 mUrlTextView.clearFocus(); | 183 mUrlTextView.clearFocus(); |
185 // TODO(aurimas): Remove this when crbug.com/174541 is fixed. | 184 // TODO(aurimas): Remove this when crbug.com/174541 is fixed. |
186 mContentView.clearFocus(); | 185 mContentViewCore.getContainerView().clearFocus(); |
187 mContentView.requestFocus(); | 186 mContentViewCore.getContainerView().requestFocus(); |
188 } | 187 } |
189 | 188 |
190 /** | 189 /** |
191 * Given an URL, this performs minimal sanitizing to ensure it will be valid
. | 190 * Given an URL, this performs minimal sanitizing to ensure it will be valid
. |
192 * @param url The url to be sanitized. | 191 * @param url The url to be sanitized. |
193 * @return The sanitized URL. | 192 * @return The sanitized URL. |
194 */ | 193 */ |
195 public static String sanitizeUrl(String url) { | 194 public static String sanitizeUrl(String url) { |
196 if (url == null) return url; | 195 if (url == null) return url; |
197 if (url.startsWith("www.") || url.indexOf(":") == -1) url = "http://" +
url; | 196 if (url.startsWith("www.") || url.indexOf(":") == -1) url = "http://" +
url; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 } | 239 } |
241 | 240 |
242 @SuppressWarnings("unused") | 241 @SuppressWarnings("unused") |
243 @CalledByNative | 242 @CalledByNative |
244 private void setIsLoading(boolean loading) { | 243 private void setIsLoading(boolean loading) { |
245 mLoading = loading; | 244 mLoading = loading; |
246 } | 245 } |
247 | 246 |
248 /** | 247 /** |
249 * Initializes the ContentView based on the native tab contents pointer pass
ed in. | 248 * Initializes the ContentView based on the native tab contents pointer pass
ed in. |
250 * @param nativeTabContents The pointer to the native tab contents object. | 249 * @param nativeWebContents The pointer to the native tab contents object. |
251 */ | 250 */ |
252 @SuppressWarnings("unused") | 251 @SuppressWarnings("unused") |
253 @CalledByNative | 252 @CalledByNative |
254 private void initFromNativeTabContents(long nativeTabContents) { | 253 private void initFromNativeTabContents(long nativeWebContents) { |
255 mContentView = ContentView.newInstance(getContext(), nativeTabContents,
mWindow); | 254 Context context = getContext(); |
256 mContentViewCore = mContentView.getContentViewCore(); | 255 mContentViewCore = new ContentViewCore(context); |
| 256 ContentView cv = ContentView.newInstance(context, mContentViewCore); |
| 257 mContentViewCore.initialize(cv, cv, nativeWebContents, mWindow); |
257 mContentViewCore.setContentViewClient(mContentViewClient); | 258 mContentViewCore.setContentViewClient(mContentViewClient); |
258 | 259 |
259 if (getParent() != null) mContentViewCore.onShow(); | 260 if (getParent() != null) mContentViewCore.onShow(); |
260 if (mContentViewCore.getUrl() != null) mUrlTextView.setText(mContentView
Core.getUrl()); | 261 if (mContentViewCore.getUrl() != null) mUrlTextView.setText(mContentView
Core.getUrl()); |
261 ((FrameLayout) findViewById(R.id.contentview_holder)).addView(mContentVi
ew, | 262 ((FrameLayout) findViewById(R.id.contentview_holder)).addView(cv, |
262 new FrameLayout.LayoutParams( | 263 new FrameLayout.LayoutParams( |
263 FrameLayout.LayoutParams.MATCH_PARENT, | 264 FrameLayout.LayoutParams.MATCH_PARENT, |
264 FrameLayout.LayoutParams.MATCH_PARENT)); | 265 FrameLayout.LayoutParams.MATCH_PARENT)); |
265 mContentView.requestFocus(); | 266 cv.requestFocus(); |
266 mContentViewRenderView.setCurrentContentViewCore(mContentViewCore); | 267 mContentViewRenderView.setCurrentContentViewCore(mContentViewCore); |
267 } | 268 } |
268 | 269 |
269 /** | 270 /** |
270 * @return The {@link ViewGroup} currently shown by this Shell. | 271 * @return The {@link ViewGroup} currently shown by this Shell. |
271 */ | 272 */ |
272 public ViewGroup getContentView() { | 273 public ViewGroup getContentView() { |
273 return mContentView; | 274 return mContentViewCore.getContainerView(); |
274 } | 275 } |
275 | 276 |
276 /** | 277 /** |
277 * @return The {@link ContentViewCore} currently managing the view shown by
this Shell. | 278 * @return The {@link ContentViewCore} currently managing the view shown by
this Shell. |
278 */ | 279 */ |
279 public ContentViewCore getContentViewCore() { | 280 public ContentViewCore getContentViewCore() { |
280 return mContentViewCore; | 281 return mContentViewCore; |
281 } | 282 } |
282 | 283 |
283 private void setKeyboardVisibilityForUrl(boolean visible) { | 284 private void setKeyboardVisibilityForUrl(boolean visible) { |
284 InputMethodManager imm = (InputMethodManager) getContext().getSystemServ
ice( | 285 InputMethodManager imm = (InputMethodManager) getContext().getSystemServ
ice( |
285 Context.INPUT_METHOD_SERVICE); | 286 Context.INPUT_METHOD_SERVICE); |
286 if (visible) { | 287 if (visible) { |
287 imm.showSoftInput(mUrlTextView, InputMethodManager.SHOW_IMPLICIT); | 288 imm.showSoftInput(mUrlTextView, InputMethodManager.SHOW_IMPLICIT); |
288 } else { | 289 } else { |
289 imm.hideSoftInputFromWindow(mUrlTextView.getWindowToken(), 0); | 290 imm.hideSoftInputFromWindow(mUrlTextView.getWindowToken(), 0); |
290 } | 291 } |
291 } | 292 } |
292 | 293 |
293 private static native void nativeCloseShell(long shellPtr); | 294 private static native void nativeCloseShell(long shellPtr); |
294 } | 295 } |
OLD | NEW |