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

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/fullscreen/ChromeFullscreenManager.java

Issue 844473002: Refactor handleMessage() functionality in fullscreen (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 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
« no previous file with comments | « no previous file | chrome/android/java/src/org/chromium/chrome/browser/fullscreen/FullscreenHtmlApiHandler.java » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 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.chrome.browser.fullscreen; 5 package org.chromium.chrome.browser.fullscreen;
6 6
7 import android.animation.Animator; 7 import android.animation.Animator;
8 import android.animation.AnimatorListenerAdapter; 8 import android.animation.AnimatorListenerAdapter;
9 import android.animation.ObjectAnimator; 9 import android.animation.ObjectAnimator;
10 import android.app.Activity; 10 import android.app.Activity;
(...skipping 17 matching lines...) Expand all
28 import org.chromium.base.ApplicationStatus.ActivityStateListener; 28 import org.chromium.base.ApplicationStatus.ActivityStateListener;
29 import org.chromium.base.BaseChromiumApplication; 29 import org.chromium.base.BaseChromiumApplication;
30 import org.chromium.base.BaseChromiumApplication.WindowFocusChangedListener; 30 import org.chromium.base.BaseChromiumApplication.WindowFocusChangedListener;
31 import org.chromium.base.TraceEvent; 31 import org.chromium.base.TraceEvent;
32 import org.chromium.base.VisibleForTesting; 32 import org.chromium.base.VisibleForTesting;
33 import org.chromium.chrome.browser.Tab; 33 import org.chromium.chrome.browser.Tab;
34 import org.chromium.chrome.browser.fullscreen.FullscreenHtmlApiHandler.Fullscree nHtmlApiDelegate; 34 import org.chromium.chrome.browser.fullscreen.FullscreenHtmlApiHandler.Fullscree nHtmlApiDelegate;
35 import org.chromium.chrome.browser.tabmodel.TabModelSelector; 35 import org.chromium.chrome.browser.tabmodel.TabModelSelector;
36 import org.chromium.content.browser.ContentViewCore; 36 import org.chromium.content.browser.ContentViewCore;
37 37
38 import java.lang.ref.WeakReference;
38 import java.util.ArrayList; 39 import java.util.ArrayList;
39 import java.util.HashSet; 40 import java.util.HashSet;
40 41
41 /** 42 /**
42 * A class that manages control and content views to create the fullscreen mode. 43 * A class that manages control and content views to create the fullscreen mode.
43 */ 44 */
44 public class ChromeFullscreenManager 45 public class ChromeFullscreenManager
45 extends FullscreenManager implements ActivityStateListener, WindowFocusC hangedListener { 46 extends FullscreenManager implements ActivityStateListener, WindowFocusC hangedListener {
46 // Minimum showtime of the toolbar (in ms). 47 // Minimum showtime of the toolbar (in ms).
47 private static final long MINIMUM_SHOW_DURATION_MS = 3000; 48 private static final long MINIMUM_SHOW_DURATION_MS = 3000;
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 if (mControlContainer.getVisibility() == visibility) return; 142 if (mControlContainer.getVisibility() == visibility) return;
142 // requestLayout is required to trigger a new gatherTransparentRegio n(), which 143 // requestLayout is required to trigger a new gatherTransparentRegio n(), which
143 // only occurs together with a layout and let's SurfaceFlinger trim overlays. 144 // only occurs together with a layout and let's SurfaceFlinger trim overlays.
144 // This may be almost equivalent to using View.GONE, but we still us e View.INVISIBLE 145 // This may be almost equivalent to using View.GONE, but we still us e View.INVISIBLE
145 // since drawing caches etc. won't be destroyed, and the layout may be less expensive. 146 // since drawing caches etc. won't be destroyed, and the layout may be less expensive.
146 mControlContainer.setVisibility(visibility); 147 mControlContainer.setVisibility(visibility);
147 mControlContainer.requestLayout(); 148 mControlContainer.requestLayout();
148 } 149 }
149 }; 150 };
150 151
152 // This static inner class holds a WeakReference to the outer object, to avo id triggering the
153 // lint HandlerLeak warning.
154 private static class FullscreenHandler extends Handler {
155 private final WeakReference<ChromeFullscreenManager> mChromeFullscreenMa nager;
156
157 public FullscreenHandler(ChromeFullscreenManager chromeFullscreenManager ) {
158 mChromeFullscreenManager = new WeakReference<ChromeFullscreenManager >(
159 chromeFullscreenManager);
160 }
161
162 @Override
163 public void handleMessage(Message msg) {
164 if (msg == null) return;
165 ChromeFullscreenManager chromeFullscreenManager = mChromeFullscreenM anager.get();
nyquist 2015/01/10 01:27:05 I wonder, are there any cases whatsoever where thi
wajahat 2015/01/12 08:06:46 The reasoning behind this CL was CFM would hold th
166 switch (msg.what) {
167 case MSG_ID_CONTROLS_REQUEST_LAYOUT:
168 chromeFullscreenManager.getControlContainer().requestLayout( );
169 break;
170 case MSG_ID_HIDE_CONTROLS:
171 chromeFullscreenManager.update(false);
172 break;
173 default:
174 assert false : "Unexpected message for ID: " + msg.what;
175 break;
176 }
177 }
178 }
179
151 /** 180 /**
152 * Creates an instance of the fullscreen mode manager. 181 * Creates an instance of the fullscreen mode manager.
153 * @param activity The activity that supports fullscreen. 182 * @param activity The activity that supports fullscreen.
154 * @param controlContainer Container holding the controls (Toolbar). 183 * @param controlContainer Container holding the controls (Toolbar).
155 * @param enabled Whether fullscreen is globally enabled. 184 * @param enabled Whether fullscreen is globally enabled.
156 * @param modelSelector The model selector providing access to the current t ab. 185 * @param modelSelector The model selector providing access to the current t ab.
157 */ 186 */
158 public ChromeFullscreenManager(Activity activity, View controlContainer, boo lean enabled, 187 public ChromeFullscreenManager(Activity activity, View controlContainer, boo lean enabled,
159 boolean persistentFullscreenSupported, TabModelSelector modelSelecto r, 188 boolean persistentFullscreenSupported, TabModelSelector modelSelecto r,
160 int resControlContainerHeight) { 189 int resControlContainerHeight) {
161 super(activity.getWindow(), modelSelector, enabled, persistentFullscreen Supported); 190 super(activity.getWindow(), modelSelector, enabled, persistentFullscreen Supported);
162 191
163 mActivity = activity; 192 mActivity = activity;
164 ApplicationStatus.registerStateListenerForActivity(this, activity); 193 ApplicationStatus.registerStateListenerForActivity(this, activity);
165 ((BaseChromiumApplication) activity.getApplication()) 194 ((BaseChromiumApplication) activity.getApplication())
166 .registerWindowFocusChangedListener(this); 195 .registerWindowFocusChangedListener(this);
167 196
168 mWindow = activity.getWindow(); 197 mWindow = activity.getWindow();
169 mHandler = new Handler() { 198 mHandler = new FullscreenHandler(this);
170 @Override
171 public void handleMessage(Message msg) {
172 if (msg == null) return;
173 switch (msg.what) {
174 case MSG_ID_CONTROLS_REQUEST_LAYOUT:
175 mControlContainer.requestLayout();
176 break;
177 case MSG_ID_HIDE_CONTROLS:
178 update(false);
179 break;
180 default:
181 assert false : "Unexpected message for ID: " + msg.what;
182 break;
183 }
184 }
185 };
186 setControlContainer(controlContainer); 199 setControlContainer(controlContainer);
187 Resources resources = mWindow.getContext().getResources(); 200 Resources resources = mWindow.getContext().getResources();
188 mControlContainerHeight = resources.getDimensionPixelSize(resControlCont ainerHeight); 201 mControlContainerHeight = resources.getDimensionPixelSize(resControlCont ainerHeight);
189 mRendererContentOffset = mControlContainerHeight; 202 mRendererContentOffset = mControlContainerHeight;
190 mEnabled = enabled; 203 mEnabled = enabled;
191 updateControlOffset(); 204 updateControlOffset();
192 } 205 }
193 206
194 /** 207 /**
195 * @return Whether or not fullscreen is enabled. 208 * @return Whether or not fullscreen is enabled.
196 */ 209 */
197 public boolean isEnabled() { 210 public boolean isEnabled() {
198 return mEnabled; 211 return mEnabled;
199 } 212 }
200 213
201 /** 214 /**
202 * Set the control container that is being hidden and shown when manipulatin g the fullscreen 215 * Set the control container that is being hidden and shown when manipulatin g the fullscreen
203 * state. 216 * state.
204 * @param controlContainer The container at the top of the screen that conta ins the controls. 217 * @param controlContainer The container at the top of the screen that conta ins the controls.
205 */ 218 */
206 public void setControlContainer(View controlContainer) { 219 public void setControlContainer(View controlContainer) {
207 assert controlContainer != null; 220 assert controlContainer != null;
208 mControlContainer = controlContainer; 221 mControlContainer = controlContainer;
209 } 222 }
210 223
224 /**
225 * Gets the container at the top of the screen that contains the controls.
226 */
227 public View getControlContainer() {
Ted C 2015/01/09 19:53:36 this doesn't need to be exposed (and shouldn't be
wajahat 2015/01/12 08:06:46 Done.
228 return mControlContainer;
229 }
230
211 @Override 231 @Override
212 public void onActivityStateChange(Activity activity, int newState) { 232 public void onActivityStateChange(Activity activity, int newState) {
213 if (newState == ActivityState.STOPPED) { 233 if (newState == ActivityState.STOPPED) {
214 // Exit fullscreen in onStop to ensure the system UI flags are set c orrectly when 234 // Exit fullscreen in onStop to ensure the system UI flags are set c orrectly when
215 // showing again (on JB MR2+ builds, the omnibox would be covered by the 235 // showing again (on JB MR2+ builds, the omnibox would be covered by the
216 // notification bar when this was done in onStart()). 236 // notification bar when this was done in onStart()).
217 setPersistentFullscreenMode(false); 237 setPersistentFullscreenMode(false);
218 } else if (newState == ActivityState.STARTED) { 238 } else if (newState == ActivityState.STARTED) {
219 showControlsTransient(); 239 showControlsTransient();
220 } else if (newState == ActivityState.DESTROYED) { 240 } else if (newState == ActivityState.DESTROYED) {
(...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after
712 mControlAnimation.start(); 732 mControlAnimation.start();
713 mCurrentAnimationIsShowing = show; 733 mCurrentAnimationIsShowing = show;
714 } 734 }
715 735
716 @Override 736 @Override
717 public void onContentViewScrollingStateChanged(boolean scrolling) { 737 public void onContentViewScrollingStateChanged(boolean scrolling) {
718 mContentViewScrolling = scrolling; 738 mContentViewScrolling = scrolling;
719 if (!scrolling) updateVisuals(); 739 if (!scrolling) updateVisuals();
720 } 740 }
721 } 741 }
OLDNEW
« no previous file with comments | « no previous file | chrome/android/java/src/org/chromium/chrome/browser/fullscreen/FullscreenHtmlApiHandler.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698