blob: ae326d597997f858090e78b92a650d9721f789c9 [file] [log] [blame]
Grace Kloba11438c32009-12-16 11:39:12 -08001/*
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 */
25package android.webkit;
26
27import android.app.Dialog;
Grace Kloba11438c32009-12-16 11:39:12 -080028import android.view.KeyEvent;
29import android.view.MotionEvent;
Grace Kloba6edb3792010-04-19 12:14:17 -070030import android.view.SurfaceView;
Grace Kloba11438c32009-12-16 11:39:12 -080031import android.view.View;
Derek Sollenberger7c5bf462010-01-11 12:50:51 -050032import android.view.ViewGroup;
Grace Kloba11438c32009-12-16 11:39:12 -080033
34class PluginFullScreenHolder extends Dialog {
35
Grace Kloba11438c32009-12-16 11:39:12 -080036 private final WebView mWebView;
37 private final int mNpp;
Derek Sollenberger7c5bf462010-01-11 12:50:51 -050038 private View mContentView;
Grace Kloba11438c32009-12-16 11:39:12 -080039
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 Kloba11438c32009-12-16 11:39:12 -080046 @Override
Derek Sollenberger7c5bf462010-01-11 12:50:51 -050047 public void setContentView(View contentView) {
Derek Sollenbergerc28ff442010-03-09 17:38:49 -050048 // 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 Kloba6edb3792010-04-19 12:14:17 -070055 // 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 Klobaf706ef82010-04-19 16:05:19 -070057 // 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 Kloba6edb3792010-04-19 12:14:17 -070059 if (contentView instanceof SurfaceView) {
60 final SurfaceView sView = (SurfaceView) contentView;
61 if (sView.isFixedSize()) {
62 sView.getHolder().setSizeFromLayout();
63 }
64 }
Derek Sollenberger7c5bf462010-01-11 12:50:51 -050065 super.setContentView(contentView);
66 mContentView = contentView;
67 }
68
69 @Override
Grace Kloba11438c32009-12-16 11:39:12 -080070 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 Sollenbergerc28ff442010-03-09 17:38:49 -050097 // always return true as we don't want the event to propagate any further
Grace Kloba11438c32009-12-16 11:39:12 -080098 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 Sollenberger7c5bf462010-01-11 12:50:51 -0500111 // 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 Kloba11438c32009-12-16 11:39:12 -0800116 mWebView.getWebViewCore().sendMessage(
117 WebViewCore.EventHub.HIDE_FULLSCREEN, mNpp, 0);
118 }
119
120}