Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(646)

Side by Side Diff: content/shell/android/java/src/org/chromium/content_shell/Shell.java

Issue 10800019: Refactor ContentShell to remove ContentViewClient dependency. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_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;
26 25
27 /** 26 /**
28 * Container for the various UI components that make up a shell window. 27 * Container for the various UI components that make up a shell window.
29 */ 28 */
30 @JNINamespace("content") 29 @JNINamespace("content")
31 public class ShellView extends LinearLayout { 30 public class Shell extends LinearLayout {
32 31
33 private static final long COMPLETED_PROGRESS_TIMEOUT_MS = 200; 32 private static final long COMPLETED_PROGRESS_TIMEOUT_MS = 200;
34 33
35 private int mNativeShellView; 34 private Runnable mClearProgressRunnable = new Runnable() {
35 @Override
36 public void run() {
37 mProgressDrawable.setLevel(0);
38 }
39 };
40
36 // TODO(jrg): a mContentView.destroy() call is needed, both upstream and dow nstream. 41 // TODO(jrg): a mContentView.destroy() call is needed, both upstream and dow nstream.
37 private ContentView mContentView; 42 private ContentView mContentView;
38 private EditText mUrlTextView; 43 private EditText mUrlTextView;
39 private ImageButton mPrevButton; 44 private ImageButton mPrevButton;
40 private ImageButton mNextButton; 45 private ImageButton mNextButton;
41 46
42 private ClipDrawable mProgressDrawable; 47 private ClipDrawable mProgressDrawable;
43 48
44 /** 49 /**
45 * Constructor for inflating via XML. 50 * Constructor for inflating via XML.
46 */ 51 */
47 public ShellView(Context context, AttributeSet attrs) { 52 public Shell(Context context, AttributeSet attrs) {
48 super(context, attrs); 53 super(context, attrs);
49
50 mNativeShellView = nativeInit();
51 } 54 }
52 55
53 @Override 56 @Override
54 protected void onFinishInflate() { 57 protected void onFinishInflate() {
55 super.onFinishInflate(); 58 super.onFinishInflate();
56 59
57 mProgressDrawable = (ClipDrawable) findViewById(R.id.toolbar).getBackgro und(); 60 mProgressDrawable = (ClipDrawable) findViewById(R.id.toolbar).getBackgro und();
58 61
59 initilizeUrlField(); 62 initilizeUrlField();
60 initializeNavigationButtons(); 63 initializeNavigationButtons();
61 } 64 }
62 65
63 /**
64 * @return the native shell view pointer.
65 */
66 protected int getNativeShellView() {
67 return mNativeShellView;
68 }
69
70 private void initilizeUrlField() { 66 private void initilizeUrlField() {
71 mUrlTextView = (EditText) findViewById(R.id.url); 67 mUrlTextView = (EditText) findViewById(R.id.url);
72 mUrlTextView.setOnEditorActionListener(new OnEditorActionListener() { 68 mUrlTextView.setOnEditorActionListener(new OnEditorActionListener() {
73 @Override 69 @Override
74 public boolean onEditorAction(TextView v, int actionId, KeyEvent eve nt) { 70 public boolean onEditorAction(TextView v, int actionId, KeyEvent eve nt) {
75 if ((actionId != EditorInfo.IME_ACTION_GO) && (event == null || 71 if ((actionId != EditorInfo.IME_ACTION_GO) && (event == null ||
76 event.getKeyCode() != KeyEvent.KEYCODE_ENTER || 72 event.getKeyCode() != KeyEvent.KEYCODE_ENTER ||
77 event.getAction() != KeyEvent.ACTION_UP)) { 73 event.getAction() != KeyEvent.ACTION_UP)) {
78 return false; 74 return false;
79 } 75 }
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 131
136 mNextButton = (ImageButton) findViewById(R.id.next); 132 mNextButton = (ImageButton) findViewById(R.id.next);
137 mNextButton.setOnClickListener(new OnClickListener() { 133 mNextButton.setOnClickListener(new OnClickListener() {
138 @Override 134 @Override
139 public void onClick(View v) { 135 public void onClick(View v) {
140 if (mContentView.canGoForward()) mContentView.goForward(); 136 if (mContentView.canGoForward()) mContentView.goForward();
141 } 137 }
142 }); 138 });
143 } 139 }
144 140
141 @SuppressWarnings("unused")
142 @CalledByNative
143 private void onUpdateUrl(String url) {
144 mUrlTextView.setText(url);
145 }
146
147 @SuppressWarnings("unused")
148 @CalledByNative
149 private void onLoadProgressChanged(double progress) {
150 removeCallbacks(mClearProgressRunnable);
151 mProgressDrawable.setLevel((int) (10000.0 * progress));
152 if (progress == 1.0) postDelayed(mClearProgressRunnable, COMPLETED_PROGR ESS_TIMEOUT_MS);
153 }
154
145 /** 155 /**
146 * Initializes the ContentView based on the native tab contents pointer pass ed in. 156 * Initializes the ContentView based on the native tab contents pointer pass ed in.
147 * @param nativeTabContents The pointer to the native tab contents object. 157 * @param nativeTabContents The pointer to the native tab contents object.
148 */ 158 */
149 @SuppressWarnings("unused") 159 @SuppressWarnings("unused")
150 @CalledByNative 160 @CalledByNative
151 private void initFromNativeTabContents(int nativeTabContents) { 161 private void initFromNativeTabContents(int nativeTabContents) {
152 mContentView = new ContentView( 162 mContentView = new ContentView(
153 getContext(), nativeTabContents, ContentView.PERSONALITY_CHROME) ; 163 getContext(), nativeTabContents, ContentView.PERSONALITY_CHROME) ;
154 mContentView.setContentViewClient(new ShellContentViewClient());
155 ((FrameLayout) findViewById(R.id.contentview_holder)).addView(mContentVi ew, 164 ((FrameLayout) findViewById(R.id.contentview_holder)).addView(mContentVi ew,
156 new FrameLayout.LayoutParams( 165 new FrameLayout.LayoutParams(
157 FrameLayout.LayoutParams.MATCH_PARENT, 166 FrameLayout.LayoutParams.MATCH_PARENT,
158 FrameLayout.LayoutParams.MATCH_PARENT)); 167 FrameLayout.LayoutParams.MATCH_PARENT));
159 mContentView.requestFocus(); 168 mContentView.requestFocus();
160 } 169 }
161 170
162 /** 171 /**
163 * @return The {@link ContentView} currently shown by this Shell. 172 * @return The {@link ContentView} currently shown by this Shell.
164 */ 173 */
165 public ContentView getContentView() { 174 public ContentView getContentView() {
166 return mContentView; 175 return mContentView;
167 } 176 }
168 177
169 private void setKeyboardVisibilityForUrl(boolean visible) { 178 private void setKeyboardVisibilityForUrl(boolean visible) {
170 InputMethodManager imm = (InputMethodManager) getContext().getSystemServ ice( 179 InputMethodManager imm = (InputMethodManager) getContext().getSystemServ ice(
171 Context.INPUT_METHOD_SERVICE); 180 Context.INPUT_METHOD_SERVICE);
172 if (visible) { 181 if (visible) {
173 imm.showSoftInput(mUrlTextView, InputMethodManager.SHOW_IMPLICIT); 182 imm.showSoftInput(mUrlTextView, InputMethodManager.SHOW_IMPLICIT);
174 } else { 183 } else {
175 imm.hideSoftInputFromWindow(mUrlTextView.getWindowToken(), 0); 184 imm.hideSoftInputFromWindow(mUrlTextView.getWindowToken(), 0);
176 } 185 }
177 } 186 }
178
179 private native int nativeInit();
180
181 private class ShellContentViewClient extends ContentViewClient {
182 private Runnable mClearProgressRunnable = new Runnable() {
183 @Override
184 public void run() {
185 mProgressDrawable.setLevel(0);
186 }
187 };
188
189 @Override
190 public void onUpdateUrl(String url) {
191 super.onUpdateUrl(url);
192 mUrlTextView.setText(url);
193 }
194
195 @Override
196 public void onLoadProgressChanged(final double progress) {
197 super.onLoadProgressChanged(progress);
198 removeCallbacks(mClearProgressRunnable);
199 mProgressDrawable.setLevel((int) (10000.0 * progress));
200 if (progress == 1.0) postDelayed(mClearProgressRunnable, COMPLETED_P ROGRESS_TIMEOUT_MS);
201 }
202
203 @Override
204 public void onTabCrash(int pid) {
205 super.onTabCrash(pid);
206 mProgressDrawable.setLevel(0);
207 }
208 }
209 } 187 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698