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 */
25package android.webkit;
26
27import android.app.Dialog;
28import android.view.KeyEvent;
29import android.view.MotionEvent;
30import android.view.SurfaceView;
31import android.view.View;
32import android.view.ViewGroup;
33
34class PluginFullScreenHolder extends Dialog {
35
36    private final WebView mWebView;
37    private final int mNpp;
38    private View mContentView;
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
46    @Override
47    public void setContentView(View contentView) {
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));
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
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.
59        if (contentView instanceof SurfaceView) {
60            final SurfaceView sView = (SurfaceView) contentView;
61            if (sView.isFixedSize()) {
62                sView.getHolder().setSizeFromLayout();
63            }
64        }
65        super.setContentView(contentView);
66        mContentView = contentView;
67    }
68
69    @Override
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) {
97        // always return true as we don't want the event to propagate any further
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();
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        }
116        mWebView.getWebViewCore().sendMessage(
117                WebViewCore.EventHub.HIDE_FULLSCREEN, mNpp, 0);
118    }
119
120}
121