1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 package org.chromium.android_webview;
7 import android.content.Context;
8 import android.content.res.Configuration;
9 import android.graphics.Canvas;
10 import android.graphics.Paint;
11 import android.graphics.Rect;
12 import android.view.KeyEvent;
13 import android.view.MotionEvent;
14 import android.view.View;
15 import android.view.inputmethod.EditorInfo;
16 import android.view.inputmethod.InputConnection;
17 import android.widget.FrameLayout;
20 * A view that is used to render the web contents in fullscreen mode, ie.
21 * html controls and subtitles, over the {@link ContentVideoView}.
23 public class FullScreenView extends FrameLayout {
25 private AwViewMethods mAwViewMethods;
26 private final AwContents mAwContents;
27 private InternalAccessAdapter mInternalAccessAdapter;
29 public FullScreenView(Context context, AwViewMethods awViewMethods,
30 AwContents awContents) {
32 setAwViewMethods(awViewMethods);
33 mAwContents = awContents;
34 mInternalAccessAdapter = new InternalAccessAdapter();
37 public InternalAccessAdapter getInternalAccessAdapter() {
38 return mInternalAccessAdapter;
41 public void setAwViewMethods(AwViewMethods awViewMethods) {
42 mAwViewMethods = awViewMethods;
46 public void onDraw(final Canvas canvas) {
47 mAwViewMethods.onDraw(canvas);
51 public void onMeasure(final int widthMeasureSpec, final int heightMeasureSpec) {
52 mAwViewMethods.onMeasure(widthMeasureSpec, heightMeasureSpec);
56 public boolean requestFocus(final int direction, final Rect previouslyFocusedRect) {
57 mAwViewMethods.requestFocus();
58 return super.requestFocus(direction, previouslyFocusedRect);
62 public void setLayerType(int layerType, Paint paint) {
63 super.setLayerType(layerType, paint);
64 mAwViewMethods.setLayerType(layerType, paint);
68 public InputConnection onCreateInputConnection(final EditorInfo outAttrs) {
69 return mAwViewMethods.onCreateInputConnection(outAttrs);
73 public boolean onKeyUp(final int keyCode, final KeyEvent event) {
74 return mAwViewMethods.onKeyUp(keyCode, event);
78 public boolean dispatchKeyEvent(final KeyEvent event) {
79 if (event.getKeyCode() == KeyEvent.KEYCODE_BACK
80 && event.getAction() == KeyEvent.ACTION_UP
81 && mAwContents.isFullScreen()) {
82 mAwContents.requestExitFullscreen();
85 return mAwViewMethods.dispatchKeyEvent(event);
89 public boolean onTouchEvent(final MotionEvent event) {
90 return mAwViewMethods.onTouchEvent(event);
94 public boolean onHoverEvent(final MotionEvent event) {
95 return mAwViewMethods.onHoverEvent(event);
99 public boolean onGenericMotionEvent(final MotionEvent event) {
100 return mAwViewMethods.onGenericMotionEvent(event);
104 public void onConfigurationChanged(final Configuration newConfig) {
105 mAwViewMethods.onConfigurationChanged(newConfig);
109 protected void onAttachedToWindow() {
110 super.onAttachedToWindow();
111 mAwViewMethods.onAttachedToWindow();
115 public void onDetachedFromWindow() {
116 super.onDetachedFromWindow();
117 mAwViewMethods.onDetachedFromWindow();
121 public void onWindowFocusChanged(final boolean hasWindowFocus) {
122 super.onWindowFocusChanged(hasWindowFocus);
123 mAwViewMethods.onWindowFocusChanged(hasWindowFocus);
127 public void onFocusChanged(final boolean focused, final int direction,
128 final Rect previouslyFocusedRect) {
129 super.onFocusChanged(focused, direction, previouslyFocusedRect);
130 mAwViewMethods.onFocusChanged(
131 focused, direction, previouslyFocusedRect);
135 public void onSizeChanged(final int w, final int h, final int ow, final int oh) {
136 super.onSizeChanged(w, h, ow, oh);
137 mAwViewMethods.onSizeChanged(w, h, ow, oh);
141 protected void onVisibilityChanged(View changedView, int visibility) {
142 super.onVisibilityChanged(changedView, visibility);
143 mAwViewMethods.onVisibilityChanged(changedView, visibility);
147 public void onWindowVisibilityChanged(final int visibility) {
148 super.onWindowVisibilityChanged(visibility);
149 mAwViewMethods.onWindowVisibilityChanged(visibility);
153 public void onOverScrolled(int scrollX, int scrollY, boolean clampedX, boolean clampedY) {
154 mAwViewMethods.onContainerViewOverScrolled(scrollX, scrollY, clampedX, clampedY);
158 public void onScrollChanged(int l, int t, int oldl, int oldt) {
159 super.onScrollChanged(l, t, oldl, oldt);
160 mAwViewMethods.onContainerViewScrollChanged(l, t, oldl, oldt);
164 public int computeHorizontalScrollRange() {
165 return mAwViewMethods.computeHorizontalScrollRange();
169 public int computeHorizontalScrollOffset() {
170 return mAwViewMethods.computeHorizontalScrollOffset();
174 public int computeVerticalScrollRange() {
175 return mAwViewMethods.computeVerticalScrollRange();
179 public int computeVerticalScrollOffset() {
180 return mAwViewMethods.computeVerticalScrollOffset();
184 public int computeVerticalScrollExtent() {
185 return mAwViewMethods.computeVerticalScrollExtent();
189 public void computeScroll() {
190 mAwViewMethods.computeScroll();
193 // AwContents.InternalAccessDelegate implementation --------------------------------------
194 private class InternalAccessAdapter implements AwContents.InternalAccessDelegate {
197 public boolean drawChild(Canvas canvas, View child, long drawingTime) {
203 public boolean super_onKeyUp(int keyCode, KeyEvent event) {
204 return FullScreenView.super.onKeyUp(keyCode, event);
208 public boolean super_dispatchKeyEventPreIme(KeyEvent event) {
209 return FullScreenView.super.dispatchKeyEventPreIme(event);
213 public boolean super_dispatchKeyEvent(KeyEvent event) {
214 return FullScreenView.super.dispatchKeyEvent(event);
218 public boolean super_onGenericMotionEvent(MotionEvent event) {
219 return FullScreenView.super.onGenericMotionEvent(event);
223 public void super_onConfigurationChanged(Configuration newConfig) {
228 public int super_getScrollBarStyle() {
229 return FullScreenView.super.getScrollBarStyle();
233 public boolean awakenScrollBars() {
234 return FullScreenView.this.awakenScrollBars(0);
238 public boolean super_awakenScrollBars(int startDelay, boolean invalidate) {
239 return FullScreenView.super.awakenScrollBars(startDelay, invalidate);
243 public void onScrollChanged(int lPix, int tPix, int oldlPix, int oldtPix) {
244 FullScreenView.this.onScrollChanged(lPix, tPix, oldlPix, oldtPix);
248 public void overScrollBy(int deltaX, int deltaY, int scrollX, int scrollY,
249 int scrollRangeX, int scrollRangeY, int maxOverScrollX,
250 int maxOverScrollY, boolean isTouchEvent) {
251 FullScreenView.this.overScrollBy(deltaX, deltaY, scrollX, scrollY, scrollRangeX,
252 scrollRangeY, maxOverScrollX, maxOverScrollY, isTouchEvent);
256 public void super_scrollTo(int scrollX, int scrollY) {
257 FullScreenView.super.scrollTo(scrollX, scrollY);
261 public void setMeasuredDimension(int measuredWidth, int measuredHeight) {
262 FullScreenView.this.setMeasuredDimension(measuredWidth, measuredHeight);