Grace Kloba | 11438c3 | 2009-12-16 11:39:12 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2009, The Android Open Source Project |
| 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions |
| 6 | * are met: |
| 7 | * * Redistributions of source code must retain the above copyright |
| 8 | * notice, this list of conditions and the following disclaimer. |
| 9 | * * Redistributions in binary form must reproduce the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer in the |
| 11 | * documentation and/or other materials provided with the distribution. |
| 12 | * |
| 13 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY |
| 14 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
| 17 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 18 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 19 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 20 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 21 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 | */ |
| 25 | package android.webkit; |
| 26 | |
| 27 | import android.app.Dialog; |
Grace Kloba | 11438c3 | 2009-12-16 11:39:12 -0800 | [diff] [blame] | 28 | import android.view.KeyEvent; |
| 29 | import android.view.MotionEvent; |
Grace Kloba | 6edb379 | 2010-04-19 12:14:17 -0700 | [diff] [blame] | 30 | import android.view.SurfaceView; |
Grace Kloba | 11438c3 | 2009-12-16 11:39:12 -0800 | [diff] [blame] | 31 | import android.view.View; |
Derek Sollenberger | 7c5bf46 | 2010-01-11 12:50:51 -0500 | [diff] [blame] | 32 | import android.view.ViewGroup; |
Grace Kloba | 11438c3 | 2009-12-16 11:39:12 -0800 | [diff] [blame] | 33 | |
| 34 | class PluginFullScreenHolder extends Dialog { |
| 35 | |
Grace Kloba | 11438c3 | 2009-12-16 11:39:12 -0800 | [diff] [blame] | 36 | private final WebView mWebView; |
| 37 | private final int mNpp; |
Derek Sollenberger | 7c5bf46 | 2010-01-11 12:50:51 -0500 | [diff] [blame] | 38 | private View mContentView; |
Grace Kloba | 11438c3 | 2009-12-16 11:39:12 -0800 | [diff] [blame] | 39 | |
| 40 | PluginFullScreenHolder(WebView webView, int npp) { |
| 41 | super(webView.getContext(), android.R.style.Theme_NoTitleBar_Fullscreen); |
| 42 | mWebView = webView; |
| 43 | mNpp = npp; |
| 44 | } |
| 45 | |
Grace Kloba | 11438c3 | 2009-12-16 11:39:12 -0800 | [diff] [blame] | 46 | @Override |
Derek Sollenberger | 7c5bf46 | 2010-01-11 12:50:51 -0500 | [diff] [blame] | 47 | public void setContentView(View contentView) { |
Derek Sollenberger | c28ff44 | 2010-03-09 17:38:49 -0500 | [diff] [blame] | 48 | // as we are sharing the View between full screen and |
| 49 | // embedded mode, we have to remove the |
| 50 | // AbsoluteLayout.LayoutParams set by embedded mode to |
| 51 | // ViewGroup.LayoutParams before adding it to the dialog |
| 52 | contentView.setLayoutParams(new ViewGroup.LayoutParams( |
| 53 | ViewGroup.LayoutParams.MATCH_PARENT, |
| 54 | ViewGroup.LayoutParams.MATCH_PARENT)); |
Grace Kloba | 6edb379 | 2010-04-19 12:14:17 -0700 | [diff] [blame] | 55 | // fixed size is only used either during pinch zoom or surface is too |
| 56 | // big. Make sure it is not fixed size before setting it to the full |
Grace Kloba | f706ef8 | 2010-04-19 16:05:19 -0700 | [diff] [blame] | 57 | // screen content view. The SurfaceView will be set to the correct mode |
| 58 | // by the ViewManager when it is re-attached to the WebView. |
Grace Kloba | 6edb379 | 2010-04-19 12:14:17 -0700 | [diff] [blame] | 59 | if (contentView instanceof SurfaceView) { |
| 60 | final SurfaceView sView = (SurfaceView) contentView; |
| 61 | if (sView.isFixedSize()) { |
| 62 | sView.getHolder().setSizeFromLayout(); |
| 63 | } |
| 64 | } |
Derek Sollenberger | 7c5bf46 | 2010-01-11 12:50:51 -0500 | [diff] [blame] | 65 | super.setContentView(contentView); |
| 66 | mContentView = contentView; |
| 67 | } |
| 68 | |
| 69 | @Override |
Grace Kloba | 11438c3 | 2009-12-16 11:39:12 -0800 | [diff] [blame] | 70 | public void onBackPressed() { |
| 71 | mWebView.mPrivateHandler.obtainMessage(WebView.HIDE_FULLSCREEN) |
| 72 | .sendToTarget(); |
| 73 | } |
| 74 | |
| 75 | @Override |
| 76 | public boolean onKeyDown(int keyCode, KeyEvent event) { |
| 77 | if (event.isSystem()) { |
| 78 | return super.onKeyDown(keyCode, event); |
| 79 | } |
| 80 | mWebView.onKeyDown(keyCode, event); |
| 81 | // always return true as we are the handler |
| 82 | return true; |
| 83 | } |
| 84 | |
| 85 | @Override |
| 86 | public boolean onKeyUp(int keyCode, KeyEvent event) { |
| 87 | if (event.isSystem()) { |
| 88 | return super.onKeyUp(keyCode, event); |
| 89 | } |
| 90 | mWebView.onKeyUp(keyCode, event); |
| 91 | // always return true as we are the handler |
| 92 | return true; |
| 93 | } |
| 94 | |
| 95 | @Override |
| 96 | public boolean onTouchEvent(MotionEvent event) { |
Derek Sollenberger | c28ff44 | 2010-03-09 17:38:49 -0500 | [diff] [blame] | 97 | // always return true as we don't want the event to propagate any further |
Grace Kloba | 11438c3 | 2009-12-16 11:39:12 -0800 | [diff] [blame] | 98 | return true; |
| 99 | } |
| 100 | |
| 101 | @Override |
| 102 | public boolean onTrackballEvent(MotionEvent event) { |
| 103 | mWebView.onTrackballEvent(event); |
| 104 | // always return true as we are the handler |
| 105 | return true; |
| 106 | } |
| 107 | |
| 108 | @Override |
| 109 | protected void onStop() { |
| 110 | super.onStop(); |
Derek Sollenberger | 7c5bf46 | 2010-01-11 12:50:51 -0500 | [diff] [blame] | 111 | // manually remove the contentView's parent since the dialog does not |
| 112 | if (mContentView != null && mContentView.getParent() != null) { |
| 113 | ViewGroup vg = (ViewGroup) mContentView.getParent(); |
| 114 | vg.removeView(mContentView); |
| 115 | } |
Grace Kloba | 11438c3 | 2009-12-16 11:39:12 -0800 | [diff] [blame] | 116 | mWebView.getWebViewCore().sendMessage( |
| 117 | WebViewCore.EventHub.HIDE_FULLSCREEN, mNpp, 0); |
| 118 | } |
| 119 | |
| 120 | } |