OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 package org.chromium.chrome.browser.fullscreen; |
| 6 |
| 7 import android.view.View; |
| 8 import android.view.Window; |
| 9 |
| 10 import org.chromium.chrome.browser.Tab; |
| 11 import org.chromium.chrome.browser.fullscreen.FullscreenHtmlApiHandler.Fullscree
nHtmlApiDelegate; |
| 12 import org.chromium.chrome.browser.tabmodel.TabModelSelector; |
| 13 import org.chromium.content.browser.ContentVideoView; |
| 14 |
| 15 /** |
| 16 * Manages the basic fullscreen functionality required by a Tab. |
| 17 */ |
| 18 // TODO(tedchoc): Remove Tab's requirement on the fullscreen tokens to slim down
the API of this |
| 19 // class. |
| 20 public abstract class FullscreenManager { |
| 21 public static final int INVALID_TOKEN = -1; |
| 22 |
| 23 private final TabModelSelector mModelSelector; |
| 24 private final FullscreenHtmlApiHandler mHtmlApiHandler; |
| 25 private boolean mOverlayVideoMode; |
| 26 |
| 27 /** |
| 28 * Constructs the basic ChromeTab oriented FullscreenManager. |
| 29 * |
| 30 * @param window Top-level window to turn to fullscreen. |
| 31 * @param modelSelector The model selector providing access to the current t
ab. |
| 32 * @param enabled Whether fullscreen is globally enabled. |
| 33 * @param persistentFullscreenSupported Whether persistent fullscreen via th
e HTML5 API is |
| 34 * enabled. |
| 35 */ |
| 36 public FullscreenManager(Window window, TabModelSelector modelSelector, bool
ean enabled, |
| 37 boolean persistentFullscreenSupported) { |
| 38 mModelSelector = modelSelector; |
| 39 mHtmlApiHandler = new FullscreenHtmlApiHandler( |
| 40 window, createApiDelegate(), enabled && persistentFullscreenSupp
orted); |
| 41 mOverlayVideoMode = false; |
| 42 } |
| 43 |
| 44 /** |
| 45 * @return The delegate that will handle the embedder specific requirements
of the |
| 46 * fullscreen API handler. |
| 47 */ |
| 48 protected abstract FullscreenHtmlApiDelegate createApiDelegate(); |
| 49 |
| 50 /** |
| 51 * @return The handler for managing interactions with the HTML fullscreen AP
I. |
| 52 */ |
| 53 protected FullscreenHtmlApiHandler getHtmlApiHandler() { |
| 54 return mHtmlApiHandler; |
| 55 } |
| 56 |
| 57 /** |
| 58 * @return The selector for accessing the current Tab. |
| 59 */ |
| 60 protected TabModelSelector getTabModelSelector() { |
| 61 return mModelSelector; |
| 62 } |
| 63 |
| 64 /** |
| 65 * Trigger a temporary showing of the top controls. |
| 66 */ |
| 67 public abstract void showControlsTransient(); |
| 68 |
| 69 /** |
| 70 * Trigger a permanent showing of the top controls until requested otherwise
. |
| 71 * |
| 72 * @return The token that determines whether the requester still needs persi
stent controls to |
| 73 * be present on the screen. |
| 74 * @see #hideControlsPersistent(int) |
| 75 */ |
| 76 public abstract int showControlsPersistent(); |
| 77 |
| 78 /** |
| 79 * Same behavior as {@link #showControlsPersistent()} but also handles remov
ing a previously |
| 80 * requested token if necessary. |
| 81 * |
| 82 * @param oldToken The old fullscreen token to be cleared. |
| 83 * @return The fullscreen token as defined in {@link #showControlsPersistent
()}. |
| 84 */ |
| 85 public abstract int showControlsPersistentAndClearOldToken(int oldToken); |
| 86 |
| 87 /** |
| 88 * Notify the manager that the top controls are no longer required for the g
iven token. |
| 89 * |
| 90 * @param token The fullscreen token returned from {@link #showControlsPersi
stent()}. |
| 91 */ |
| 92 public abstract void hideControlsPersistent(int token); |
| 93 |
| 94 /** |
| 95 * @return The offset of the content from the top of the screen. |
| 96 */ |
| 97 public abstract float getContentOffset(); |
| 98 |
| 99 /** |
| 100 * Tells the fullscreen manager a ContentVideoView is created below the cont
ents. |
| 101 * @param enabled Whether to enter or leave overlay video mode. |
| 102 */ |
| 103 public void setOverlayVideoMode(boolean enabled) { |
| 104 mOverlayVideoMode = enabled; |
| 105 } |
| 106 |
| 107 /** |
| 108 * @return Check whether ContentVideoView is shown. |
| 109 */ |
| 110 public boolean isOverlayVideoMode() { |
| 111 return mOverlayVideoMode; |
| 112 } |
| 113 |
| 114 /** |
| 115 * Updates the positions of the top controls and content to the default non
fullscreen |
| 116 * values. |
| 117 */ |
| 118 public abstract void setPositionsForTabToNonFullscreen(); |
| 119 |
| 120 /** |
| 121 * Updates the positions of the top controls and content based on the desire
d position of |
| 122 * the current tab. |
| 123 * |
| 124 * @param controlsOffset The Y offset of the top controls. |
| 125 * @param contentOffset The Y offset for the content. |
| 126 */ |
| 127 public abstract void setPositionsForTab(float controlsOffset, float contentO
ffset); |
| 128 |
| 129 /** |
| 130 * Updates the current ContentView's children and any popups with the correc
t offsets based on |
| 131 * the current fullscreen state. |
| 132 */ |
| 133 public abstract void updateContentViewChildrenState(); |
| 134 |
| 135 /** |
| 136 * Enters or exits persistent fullscreen mode. In this mode, the top contro
ls will be |
| 137 * permanently hidden until this mode is exited. |
| 138 * |
| 139 * @param enabled Whether to enable persistent fullscreen mode. |
| 140 */ |
| 141 public void setPersistentFullscreenMode(boolean enabled) { |
| 142 mHtmlApiHandler.setPersistentFullscreenMode(enabled); |
| 143 |
| 144 Tab tab = mModelSelector.getCurrentTab(); |
| 145 if (!enabled && mOverlayVideoMode) { |
| 146 ContentVideoView videoView = ContentVideoView.getContentVideoView(); |
| 147 if (videoView != null) videoView.exitFullscreen(false); |
| 148 } |
| 149 if (tab != null) { |
| 150 tab.updateFullscreenEnabledState(); |
| 151 } |
| 152 } |
| 153 |
| 154 /** |
| 155 * @return Whether the application is in persistent fullscreen mode. |
| 156 * @see #setPersistentFullscreenMode(boolean) |
| 157 */ |
| 158 public boolean getPersistentFullscreenMode() { |
| 159 return mHtmlApiHandler.getPersistentFullscreenMode(); |
| 160 } |
| 161 |
| 162 /** |
| 163 * Notified when the system UI visibility for the current ContentView has ch
anged. |
| 164 * @param visibility The updated UI visibility. |
| 165 * @see View#getSystemUiVisibility() |
| 166 */ |
| 167 public void onContentViewSystemUiVisibilityChange(int visibility) { |
| 168 mHtmlApiHandler.onContentViewSystemUiVisibilityChange(visibility); |
| 169 } |
| 170 |
| 171 /** |
| 172 * Ensure the proper system UI flags are set after the window regains focus. |
| 173 * @see android.app.Activity#onWindowFocusChanged(boolean) |
| 174 */ |
| 175 public void onWindowFocusChanged(boolean hasWindowFocus) { |
| 176 mHtmlApiHandler.onWindowFocusChanged(hasWindowFocus); |
| 177 } |
| 178 |
| 179 /** |
| 180 * Called when scrolling state of the ContentView changed. |
| 181 */ |
| 182 public void onContentViewScrollingStateChanged(boolean scrolling) {} |
| 183 } |
OLD | NEW |