Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(20)

Side by Side Diff: android_webview/java/src/org/chromium/android_webview/AwContentViewClient.java

Issue 618013003: Support fullscreen for non-video elements in the WebView. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@refactorFullscreenNonMedia
Patch Set: Fix failing test Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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.android_webview; 5 package org.chromium.android_webview;
6 6
7 import android.content.Context; 7 import android.content.Context;
8 import android.view.KeyEvent; 8 import android.view.KeyEvent;
9 import android.view.View; 9 import android.view.View;
10 import android.webkit.URLUtil; 10 import android.webkit.URLUtil;
11 import android.webkit.WebChromeClient; 11 import android.webkit.WebChromeClient;
12 import android.widget.FrameLayout; 12 import android.widget.FrameLayout;
13 13
14 import org.chromium.content.browser.ContentVideoView;
15 import org.chromium.content.browser.ContentVideoViewClient; 14 import org.chromium.content.browser.ContentVideoViewClient;
16 import org.chromium.content.browser.ContentViewClient; 15 import org.chromium.content.browser.ContentViewClient;
17 16
18 /** 17 /**
19 * ContentViewClient implementation for WebView 18 * ContentViewClient implementation for WebView
20 */ 19 */
21 public class AwContentViewClient extends ContentViewClient implements ContentVid eoViewClient { 20 public class AwContentViewClient extends ContentViewClient implements ContentVid eoViewClient {
22 private AwContentsClient mAwContentsClient; 21 private final AwContentsClient mAwContentsClient;
23 private AwSettings mAwSettings; 22 private final AwSettings mAwSettings;
24 private AwContents mAwContents; 23 private final AwContents mAwContents;
25 private Context mContext; 24 private final Context mContext;
25 private FrameLayout mCustomView;
26 26
27 public AwContentViewClient( 27 public AwContentViewClient(AwContentsClient awContentsClient, AwSettings awS ettings,
28 AwContentsClient awContentsClient, AwSettings awSettings, AwContents awContents, 28 AwContents awContents, Context context) {
29 Context context) {
30 mAwContentsClient = awContentsClient; 29 mAwContentsClient = awContentsClient;
31 mAwSettings = awSettings; 30 mAwSettings = awSettings;
32 mAwContents = awContents; 31 mAwContents = awContents;
33 mContext = context; 32 mContext = context;
34 } 33 }
35 34
36 @Override 35 @Override
37 public void onBackgroundColorChanged(int color) { 36 public void onBackgroundColorChanged(int color) {
38 mAwContentsClient.onBackgroundColorChanged(color); 37 mAwContentsClient.onBackgroundColorChanged(color);
39 } 38 }
(...skipping 19 matching lines...) Expand all
59 return this; 58 return this;
60 } 59 }
61 60
62 @Override 61 @Override
63 public boolean shouldBlockMediaRequest(String url) { 62 public boolean shouldBlockMediaRequest(String url) {
64 return mAwSettings != null ? 63 return mAwSettings != null ?
65 mAwSettings.getBlockNetworkLoads() && URLUtil.isNetworkUrl(url) : true; 64 mAwSettings.getBlockNetworkLoads() && URLUtil.isNetworkUrl(url) : true;
66 } 65 }
67 66
68 @Override 67 @Override
69 public void enterFullscreenVideo(View view) { 68 public void enterFullscreenVideo(View videoView) {
70 final FrameLayout viewGroup = new FrameLayout(mContext); 69 // enterFullscreenVideo will only be called after enterFullscreen.
71 viewGroup.addView(view); 70 assert mCustomView != null;
72 viewGroup.addOnAttachStateChangeListener(new View.OnAttachStateChangeLis tener() { 71 mCustomView.addView(videoView, 0);
73 @Override
74 public void onViewDetachedFromWindow(View v) {
75 // Intentional no-op (see onDestroyContentVideoView).
76 }
77
78 @Override
79 public void onViewAttachedToWindow(View v) {
80 if (mAwContents.isFullScreen()) {
81 return;
82 }
83 View fullscreenView = mAwContents.enterFullScreen();
84 if (fullscreenView != null) {
85 viewGroup.addView(fullscreenView);
86 }
87 }
88 });
89 WebChromeClient.CustomViewCallback cb = new WebChromeClient.CustomViewCa llback() {
90 @Override
91 public void onCustomViewHidden() {
92 ContentVideoView contentVideoView = ContentVideoView.getContentV ideoView();
93 if (contentVideoView != null)
94 contentVideoView.exitFullscreen(false);
95 }
96 };
97 mAwContentsClient.onShowCustomView(viewGroup, cb);
98 } 72 }
99 73
100 @Override 74 @Override
101 public void exitFullscreenVideo() { 75 public void exitFullscreenVideo() {
102 mAwContents.exitFullScreen(); 76 // Intentional no-op
103 mAwContentsClient.onHideCustomView();
104 } 77 }
105 78
106 @Override 79 @Override
107 public View getVideoLoadingProgressView() { 80 public View getVideoLoadingProgressView() {
108 return mAwContentsClient.getVideoLoadingProgressView(); 81 return mAwContentsClient.getVideoLoadingProgressView();
109 } 82 }
83
84 /**
85 * Called to show the web contents in fullscreen mode.
86 *
87 * <p>If entering fullscreen on a video element the web contents will contai n just
88 * the html5 video controls. {@link #enterFullscreenVideo(View)} will be cal led later
89 * once the ContentVideoView, which contains the hardware accelerated fullsc reen video,
90 * is ready to be shown.
91 */
92 public void enterFullscreen() {
93 if (mAwContents.isFullScreen()) {
94 return;
95 }
96 View fullscreenView = mAwContents.enterFullScreen();
97 if (fullscreenView == null) {
98 return;
99 }
100 WebChromeClient.CustomViewCallback cb = new WebChromeClient.CustomViewCa llback() {
101 @Override
102 public void onCustomViewHidden() {
103 mAwContents.requestExitFullscreen();
104 }
105 };
106 mCustomView = new FrameLayout(mContext);
107 mCustomView.addView(fullscreenView);
108 mAwContentsClient.onShowCustomView(mCustomView, cb);
109 }
110
111 /**
112 * Called to show the web contents in embedded mode.
113 */
114 public void exitFullscreen() {
115 if (mCustomView != null) {
116 mAwContents.exitFullScreen();
117 mAwContentsClient.onHideCustomView();
118 mCustomView = null;
119 }
120 }
110 } 121 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698