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 // The target for all content rendering. |
| 27 private SurfaceView mSurfaceView; |
| 28 |
23 /** | 29 /** |
24 * Constructor for inflating via XML. | 30 * Constructor for inflating via XML. |
25 */ | 31 */ |
26 public ShellManager(Context context, AttributeSet attrs) { | 32 public ShellManager(Context context, AttributeSet attrs) { |
27 super(context, attrs); | 33 super(context, attrs); |
28 nativeInit(this); | 34 nativeInit(this); |
| 35 |
| 36 mSurfaceView = new SurfaceView(context); |
| 37 mSurfaceView.getHolder().addCallback(new SurfaceHolder.Callback() { |
| 38 public void surfaceChanged(SurfaceHolder holder, int format, int wid
th, int height) { |
| 39 nativeSurfaceSetSize(width, height); |
| 40 } |
| 41 |
| 42 public void surfaceCreated(SurfaceHolder holder) { |
| 43 nativeSurfaceCreated(holder.getSurface()); |
| 44 mActiveShell.onSurfaceCreated(); |
| 45 } |
| 46 |
| 47 public void surfaceDestroyed(SurfaceHolder holder) { |
| 48 nativeSurfaceDestroyed(); |
| 49 } |
| 50 }); |
29 } | 51 } |
30 | 52 |
31 /** | 53 /** |
32 * @return The currently visible shell view or null if one is not showing. | 54 * @return The currently visible shell view or null if one is not showing. |
33 */ | 55 */ |
34 protected Shell getActiveShell() { | 56 protected Shell getActiveShell() { |
35 return mActiveShell; | 57 return mActiveShell; |
36 } | 58 } |
37 | 59 |
38 @SuppressWarnings("unused") | 60 @SuppressWarnings("unused") |
39 @CalledByNative | 61 @CalledByNative |
40 private Object createShell() { | 62 private Object createShell() { |
41 LayoutInflater inflater = | 63 LayoutInflater inflater = |
42 (LayoutInflater) getContext().getSystemService(Context.LAYOUT_IN
FLATER_SERVICE); | 64 (LayoutInflater) getContext().getSystemService(Context.LAYOUT_IN
FLATER_SERVICE); |
43 Shell shellView = (Shell) inflater.inflate(R.layout.shell_view, null); | 65 Shell shellView = (Shell) inflater.inflate(R.layout.shell_view, null); |
| 66 shellView.setSurfaceView(mSurfaceView); |
44 | 67 |
45 removeAllViews(); | 68 removeAllViews(); |
46 addView(shellView, new FrameLayout.LayoutParams( | 69 addView(shellView, new FrameLayout.LayoutParams( |
47 FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.
MATCH_PARENT)); | 70 FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.
MATCH_PARENT)); |
48 mActiveShell = shellView; | 71 mActiveShell = shellView; |
49 | 72 |
50 return shellView; | 73 return shellView; |
51 } | 74 } |
52 | 75 |
53 private static native void nativeInit(Object shellManagerInstance); | 76 private static native void nativeInit(Object shellManagerInstance); |
| 77 private static native void nativeSurfaceCreated(Surface surface); |
| 78 private static native void nativeSurfaceDestroyed(); |
| 79 private static native void nativeSurfaceSetSize(int width, int height); |
54 } | 80 } |
OLD | NEW |