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

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

Issue 10823051: ContentShell rendering support on Android. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address Ted's comments Created 8 years, 4 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.util.AttributeSet; 8 import android.util.AttributeSet;
9 import android.view.LayoutInflater; 9 import android.view.LayoutInflater;
10 import android.view.Surface;
11 import android.view.SurfaceView;
12 import android.view.SurfaceHolder;
10 import android.widget.FrameLayout; 13 import android.widget.FrameLayout;
11 14
12 import org.chromium.base.CalledByNative; 15 import org.chromium.base.CalledByNative;
13 import org.chromium.base.JNINamespace; 16 import org.chromium.base.JNINamespace;
14 17
15 /** 18 /**
16 * Container and generator of ShellViews. 19 * Container and generator of ShellViews.
17 */ 20 */
18 @JNINamespace("content") 21 @JNINamespace("content")
19 public class ShellManager extends FrameLayout { 22 public class ShellManager extends FrameLayout {
20 23
21 private Shell mActiveShell; 24 private Shell mActiveShell;
22 25
26 private String mStartupUrl = ContentShellActivity.DEFAULT_SHELL_URL;
27
28 // The target for all content rendering.
29 private SurfaceView mSurfaceView;
30
23 /** 31 /**
24 * Constructor for inflating via XML. 32 * Constructor for inflating via XML.
25 */ 33 */
26 public ShellManager(Context context, AttributeSet attrs) { 34 public ShellManager(Context context, AttributeSet attrs) {
27 super(context, attrs); 35 super(context, attrs);
28 nativeInit(this); 36 nativeInit(this);
37
38 mSurfaceView = new SurfaceView(context);
39 mSurfaceView.getHolder().addCallback(new SurfaceHolder.Callback() {
40 @Override
41 public void surfaceChanged(SurfaceHolder holder, int format, int wid th, int height) {
42 nativeSurfaceSetSize(width, height);
43 }
44
45 @Override
46 public void surfaceCreated(SurfaceHolder holder) {
47 nativeSurfaceCreated(holder.getSurface());
48 mActiveShell.loadUrl(mStartupUrl);
49 }
50
51 @Override
52 public void surfaceDestroyed(SurfaceHolder holder) {
53 nativeSurfaceDestroyed();
54 }
55 });
29 } 56 }
30 57
31 /** 58 /**
59 * Sets the startup URL for new shell windows.
60 */
61 public void setStartupUrl(String url) {
62 mStartupUrl = url;
63 }
64
65 /**
32 * @return The currently visible shell view or null if one is not showing. 66 * @return The currently visible shell view or null if one is not showing.
33 */ 67 */
34 protected Shell getActiveShell() { 68 protected Shell getActiveShell() {
35 return mActiveShell; 69 return mActiveShell;
36 } 70 }
37 71
38 /** 72 /**
39 * Creates a new shell pointing to the specified URL. 73 * Creates a new shell pointing to the specified URL.
40 * @param url The URL the shell should load upon creation. 74 * @param url The URL the shell should load upon creation.
41 */ 75 */
42 public void launchShell(String url) { 76 public void launchShell(String url) {
43 nativeLaunchShell(url); 77 nativeLaunchShell(url);
44 } 78 }
45 79
46 @SuppressWarnings("unused") 80 @SuppressWarnings("unused")
47 @CalledByNative 81 @CalledByNative
48 private Object createShell() { 82 private Object createShell() {
49 LayoutInflater inflater = 83 LayoutInflater inflater =
50 (LayoutInflater) getContext().getSystemService(Context.LAYOUT_IN FLATER_SERVICE); 84 (LayoutInflater) getContext().getSystemService(Context.LAYOUT_IN FLATER_SERVICE);
51 Shell shellView = (Shell) inflater.inflate(R.layout.shell_view, null); 85 Shell shellView = (Shell) inflater.inflate(R.layout.shell_view, null);
86 shellView.setSurfaceView(mSurfaceView);
52 87
53 removeAllViews(); 88 removeAllViews();
54 addView(shellView, new FrameLayout.LayoutParams( 89 addView(shellView, new FrameLayout.LayoutParams(
55 FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams. MATCH_PARENT)); 90 FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams. MATCH_PARENT));
56 mActiveShell = shellView; 91 mActiveShell = shellView;
57 92
58 return shellView; 93 return shellView;
59 } 94 }
60 95
61 private static native void nativeInit(Object shellManagerInstance); 96 private static native void nativeInit(Object shellManagerInstance);
62 private static native void nativeLaunchShell(String url); 97 private static native void nativeLaunchShell(String url);
98 private static native void nativeSurfaceCreated(Surface surface);
99 private static native void nativeSurfaceDestroyed();
100 private static native void nativeSurfaceSetSize(int width, int height);
63 } 101 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698