| 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; | 10 import android.view.Surface; |
| 11 import android.view.SurfaceView; | 11 import android.view.SurfaceView; |
| 12 import android.view.SurfaceHolder; | 12 import android.view.SurfaceHolder; |
| 13 import android.widget.FrameLayout; | 13 import android.widget.FrameLayout; |
| 14 | 14 |
| 15 import org.chromium.base.CalledByNative; | 15 import org.chromium.base.CalledByNative; |
| 16 import org.chromium.base.JNINamespace; | 16 import org.chromium.base.JNINamespace; |
| 17 import org.chromium.ui.gfx.NativeWindow; |
| 17 | 18 |
| 18 /** | 19 /** |
| 19 * Container and generator of ShellViews. | 20 * Container and generator of ShellViews. |
| 20 */ | 21 */ |
| 21 @JNINamespace("content") | 22 @JNINamespace("content") |
| 22 public class ShellManager extends FrameLayout { | 23 public class ShellManager extends FrameLayout { |
| 23 | 24 |
| 25 private NativeWindow mWindow; |
| 24 private Shell mActiveShell; | 26 private Shell mActiveShell; |
| 25 | 27 |
| 26 private String mStartupUrl = ContentShellActivity.DEFAULT_SHELL_URL; | 28 private String mStartupUrl = ContentShellActivity.DEFAULT_SHELL_URL; |
| 27 | 29 |
| 28 // The target for all content rendering. | 30 // The target for all content rendering. |
| 29 private SurfaceView mSurfaceView; | 31 private SurfaceView mSurfaceView; |
| 30 | 32 |
| 31 /** | 33 /** |
| 32 * Constructor for inflating via XML. | 34 * Constructor for inflating via XML. |
| 33 */ | 35 */ |
| (...skipping 15 matching lines...) Expand all Loading... |
| 49 } | 51 } |
| 50 | 52 |
| 51 @Override | 53 @Override |
| 52 public void surfaceDestroyed(SurfaceHolder holder) { | 54 public void surfaceDestroyed(SurfaceHolder holder) { |
| 53 nativeSurfaceDestroyed(); | 55 nativeSurfaceDestroyed(); |
| 54 } | 56 } |
| 55 }); | 57 }); |
| 56 } | 58 } |
| 57 | 59 |
| 58 /** | 60 /** |
| 61 * @param window The window used to generate all shells. |
| 62 */ |
| 63 public void setWindow(NativeWindow window) { |
| 64 mWindow = window; |
| 65 } |
| 66 |
| 67 /** |
| 59 * Sets the startup URL for new shell windows. | 68 * Sets the startup URL for new shell windows. |
| 60 */ | 69 */ |
| 61 public void setStartupUrl(String url) { | 70 public void setStartupUrl(String url) { |
| 62 mStartupUrl = url; | 71 mStartupUrl = url; |
| 63 } | 72 } |
| 64 | 73 |
| 65 /** | 74 /** |
| 66 * @return The currently visible shell view or null if one is not showing. | 75 * @return The currently visible shell view or null if one is not showing. |
| 67 */ | 76 */ |
| 68 protected Shell getActiveShell() { | 77 protected Shell getActiveShell() { |
| 69 return mActiveShell; | 78 return mActiveShell; |
| 70 } | 79 } |
| 71 | 80 |
| 72 /** | 81 /** |
| 73 * Creates a new shell pointing to the specified URL. | 82 * Creates a new shell pointing to the specified URL. |
| 74 * @param url The URL the shell should load upon creation. | 83 * @param url The URL the shell should load upon creation. |
| 75 */ | 84 */ |
| 76 public void launchShell(String url) { | 85 public void launchShell(String url) { |
| 77 nativeLaunchShell(url); | 86 nativeLaunchShell(url); |
| 78 } | 87 } |
| 79 | 88 |
| 80 @SuppressWarnings("unused") | 89 @SuppressWarnings("unused") |
| 81 @CalledByNative | 90 @CalledByNative |
| 82 private Object createShell() { | 91 private Object createShell() { |
| 83 LayoutInflater inflater = | 92 LayoutInflater inflater = |
| 84 (LayoutInflater) getContext().getSystemService(Context.LAYOUT_IN
FLATER_SERVICE); | 93 (LayoutInflater) getContext().getSystemService(Context.LAYOUT_IN
FLATER_SERVICE); |
| 85 Shell shellView = (Shell) inflater.inflate(R.layout.shell_view, null); | 94 Shell shellView = (Shell) inflater.inflate(R.layout.shell_view, null); |
| 86 shellView.setSurfaceView(mSurfaceView); | 95 shellView.setSurfaceView(mSurfaceView); |
| 96 shellView.setWindow(mWindow); |
| 87 | 97 |
| 88 removeAllViews(); | 98 removeAllViews(); |
| 89 if (mActiveShell != null && mActiveShell.getContentView() != null) { | 99 if (mActiveShell != null && mActiveShell.getContentView() != null) { |
| 90 mActiveShell.getContentView().onHide(); | 100 mActiveShell.getContentView().onHide(); |
| 91 } | 101 } |
| 92 | 102 |
| 93 addView(shellView, new FrameLayout.LayoutParams( | 103 addView(shellView, new FrameLayout.LayoutParams( |
| 94 FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.
MATCH_PARENT)); | 104 FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.
MATCH_PARENT)); |
| 95 mActiveShell = shellView; | 105 mActiveShell = shellView; |
| 96 if (mActiveShell.getContentView() != null) mActiveShell.getContentView()
.onShow(); | 106 if (mActiveShell.getContentView() != null) mActiveShell.getContentView()
.onShow(); |
| 97 | 107 |
| 98 return shellView; | 108 return shellView; |
| 99 } | 109 } |
| 100 | 110 |
| 101 private static native void nativeInit(Object shellManagerInstance); | 111 private static native void nativeInit(Object shellManagerInstance); |
| 102 private static native void nativeLaunchShell(String url); | 112 private static native void nativeLaunchShell(String url); |
| 103 private static native void nativeSurfaceCreated(Surface surface); | 113 private static native void nativeSurfaceCreated(Surface surface); |
| 104 private static native void nativeSurfaceDestroyed(); | 114 private static native void nativeSurfaceDestroyed(); |
| 105 private static native void nativeSurfaceSetSize(int width, int height); | 115 private static native void nativeSurfaceSetSize(int width, int height); |
| 106 } | 116 } |
| OLD | NEW |