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

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: review comments incorporated 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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 if (mControlContainer.getVisibility() == visibility) return; 143 if (mControlContainer.getVisibility() == visibility) return;
143 // requestLayout is required to trigger a new gatherTransparentRegio n(), which 144 // requestLayout is required to trigger a new gatherTransparentRegio n(), which
144 // only occurs together with a layout and let's SurfaceFlinger trim overlays. 145 // only occurs together with a layout and let's SurfaceFlinger trim overlays.
145 // This may be almost equivalent to using View.GONE, but we still us e View.INVISIBLE 146 // This may be almost equivalent to using View.GONE, but we still us e View.INVISIBLE
146 // since drawing caches etc. won't be destroyed, and the layout may be less expensive. 147 // since drawing caches etc. won't be destroyed, and the layout may be less expensive.
147 mControlContainer.setVisibility(visibility); 148 mControlContainer.setVisibility(visibility);
148 mControlContainer.requestLayout(); 149 mControlContainer.requestLayout();
149 } 150 }
150 }; 151 };
151 152
153 // This static inner class holds a WeakReference to the outer object, to avo id triggering the
154 // lint HandlerLeak warning.
155 private static class FullscreenHandler extends Handler {
156 private final WeakReference<ChromeFullscreenManager> mChromeFullscreenMa nager;
157
158 public FullscreenHandler(ChromeFullscreenManager chromeFullscreenManager ) {
159 mChromeFullscreenManager = new WeakReference<ChromeFullscreenManager >(
160 chromeFullscreenManager);
161 }
162
163 @Override
164 public void handleMessage(Message msg) {
165 if (msg == null) return;
166 ChromeFullscreenManager chromeFullscreenManager = mChromeFullscreenM anager.get();
167 if (chromeFullscreenManager == null) return;
168 switch (msg.what) {
169 case MSG_ID_CONTROLS_REQUEST_LAYOUT:
170 chromeFullscreenManager.mControlContainer.requestLayout();
171 break;
172 case MSG_ID_HIDE_CONTROLS:
173 chromeFullscreenManager.update(false);
174 break;
175 default:
176 assert false : "Unexpected message for ID: " + msg.what;
177 break;
178 }
179 }
180 }
181
152 /** 182 /**
153 * Creates an instance of the fullscreen mode manager. 183 * Creates an instance of the fullscreen mode manager.
154 * @param activity The activity that supports fullscreen. 184 * @param activity The activity that supports fullscreen.
155 * @param controlContainer Container holding the controls (Toolbar). 185 * @param controlContainer Container holding the controls (Toolbar).
156 * @param enabled Whether fullscreen is globally enabled. 186 * @param enabled Whether fullscreen is globally enabled.
157 * @param modelSelector The model selector providing access to the current t ab. 187 * @param modelSelector The model selector providing access to the current t ab.
158 */ 188 */
159 public ChromeFullscreenManager(Activity activity, View controlContainer, boo lean enabled, 189 public ChromeFullscreenManager(Activity activity, View controlContainer, boo lean enabled,
160 boolean persistentFullscreenSupported, TabModelSelector modelSelecto r, 190 boolean persistentFullscreenSupported, TabModelSelector modelSelecto r,
161 int resControlContainerHeight) { 191 int resControlContainerHeight) {
162 super(activity.getWindow(), modelSelector, enabled, persistentFullscreen Supported); 192 super(activity.getWindow(), modelSelector, enabled, persistentFullscreen Supported);
163 193
164 mActivity = activity; 194 mActivity = activity;
165 ApplicationStatus.registerStateListenerForActivity(this, activity); 195 ApplicationStatus.registerStateListenerForActivity(this, activity);
166 ((BaseChromiumApplication) activity.getApplication()) 196 ((BaseChromiumApplication) activity.getApplication())
167 .registerWindowFocusChangedListener(this); 197 .registerWindowFocusChangedListener(this);
168 198
169 mWindow = activity.getWindow(); 199 mWindow = activity.getWindow();
170 mHandler = new Handler() { 200 mHandler = new FullscreenHandler(this);
171 @Override
172 public void handleMessage(Message msg) {
173 if (msg == null) return;
174 switch (msg.what) {
175 case MSG_ID_CONTROLS_REQUEST_LAYOUT:
176 mControlContainer.requestLayout();
177 break;
178 case MSG_ID_HIDE_CONTROLS:
179 update(false);
180 break;
181 default:
182 assert false : "Unexpected message for ID: " + msg.what;
183 break;
184 }
185 }
186 };
187 setControlContainer(controlContainer); 201 setControlContainer(controlContainer);
188 Resources resources = mWindow.getContext().getResources(); 202 Resources resources = mWindow.getContext().getResources();
189 mControlContainerHeight = resources.getDimensionPixelSize(resControlCont ainerHeight); 203 mControlContainerHeight = resources.getDimensionPixelSize(resControlCont ainerHeight);
190 mRendererContentOffset = mControlContainerHeight; 204 mRendererContentOffset = mControlContainerHeight;
191 mEnabled = enabled; 205 mEnabled = enabled;
192 updateControlOffset(); 206 updateControlOffset();
193 } 207 }
194 208
195 /** 209 /**
196 * @return Whether or not fullscreen is enabled. 210 * @return Whether or not fullscreen is enabled.
(...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after
723 mControlAnimation.start(); 737 mControlAnimation.start();
724 mCurrentAnimationIsShowing = show; 738 mCurrentAnimationIsShowing = show;
725 } 739 }
726 740
727 @Override 741 @Override
728 public void onContentViewScrollingStateChanged(boolean scrolling) { 742 public void onContentViewScrollingStateChanged(boolean scrolling) {
729 mContentViewScrolling = scrolling; 743 mContentViewScrolling = scrolling;
730 if (!scrolling) updateVisuals(); 744 if (!scrolling) updateVisuals();
731 } 745 }
732 } 746 }
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