OLD | NEW |
---|---|
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 = "http://www.google.com"; | |
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 public void surfaceChanged(SurfaceHolder holder, int format, int wid th, int height) { | |
Ted C
2012/07/31 20:58:05
add @Override to these methods.
no sievers
2012/07/31 21:17:17
Done.
| |
41 nativeSurfaceSetSize(width, height); | |
42 } | |
43 | |
44 public void surfaceCreated(SurfaceHolder holder) { | |
45 nativeSurfaceCreated(holder.getSurface()); | |
46 mActiveShell.loadUrl(mStartupUrl); | |
47 } | |
48 | |
49 public void surfaceDestroyed(SurfaceHolder holder) { | |
50 nativeSurfaceDestroyed(); | |
51 } | |
52 }); | |
29 } | 53 } |
30 | 54 |
31 /** | 55 /** |
56 * Sets the startup URL for new shell windows. | |
57 */ | |
58 public void setStartupUrl(String url) { | |
59 mStartupUrl = url; | |
60 } | |
61 | |
62 /** | |
32 * @return The currently visible shell view or null if one is not showing. | 63 * @return The currently visible shell view or null if one is not showing. |
33 */ | 64 */ |
34 protected Shell getActiveShell() { | 65 protected Shell getActiveShell() { |
35 return mActiveShell; | 66 return mActiveShell; |
36 } | 67 } |
37 | 68 |
38 /** | 69 /** |
39 * Creates a new shell pointing to the specified URL. | 70 * Creates a new shell pointing to the specified URL. |
40 * @param url The URL the shell should load upon creation. | 71 * @param url The URL the shell should load upon creation. |
41 */ | 72 */ |
42 public void launchShell(String url) { | 73 public void launchShell(String url) { |
43 nativeLaunchShell(url); | 74 nativeLaunchShell(url); |
44 } | 75 } |
45 | 76 |
46 @SuppressWarnings("unused") | 77 @SuppressWarnings("unused") |
47 @CalledByNative | 78 @CalledByNative |
48 private Object createShell() { | 79 private Object createShell() { |
49 LayoutInflater inflater = | 80 LayoutInflater inflater = |
50 (LayoutInflater) getContext().getSystemService(Context.LAYOUT_IN FLATER_SERVICE); | 81 (LayoutInflater) getContext().getSystemService(Context.LAYOUT_IN FLATER_SERVICE); |
51 Shell shellView = (Shell) inflater.inflate(R.layout.shell_view, null); | 82 Shell shellView = (Shell) inflater.inflate(R.layout.shell_view, null); |
83 shellView.setSurfaceView(mSurfaceView); | |
52 | 84 |
53 removeAllViews(); | 85 removeAllViews(); |
54 addView(shellView, new FrameLayout.LayoutParams( | 86 addView(shellView, new FrameLayout.LayoutParams( |
55 FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams. MATCH_PARENT)); | 87 FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams. MATCH_PARENT)); |
56 mActiveShell = shellView; | 88 mActiveShell = shellView; |
57 | 89 |
58 return shellView; | 90 return shellView; |
59 } | 91 } |
60 | 92 |
61 private static native void nativeInit(Object shellManagerInstance); | 93 private static native void nativeInit(Object shellManagerInstance); |
62 private static native void nativeLaunchShell(String url); | 94 private static native void nativeLaunchShell(String url); |
95 private static native void nativeSurfaceCreated(Surface surface); | |
96 private static native void nativeSurfaceDestroyed(); | |
97 private static native void nativeSurfaceSetSize(int width, int height); | |
63 } | 98 } |
OLD | NEW |