Commit ac264414 authored by dtrainor's avatar dtrainor Committed by Commit bot

Upstream Layout.java and associated files

Start upstreaming Layout/LayoutManager files.

BUG=428821

Review URL: https://codereview.chromium.org/987883002

Cr-Commit-Position: refs/heads/master@{#319769}
parent 479947d9
...@@ -49,6 +49,9 @@ ...@@ -49,6 +49,9 @@
<dimen name="app_banner_icon_size">48dp</dimen> <dimen name="app_banner_icon_size">48dp</dimen>
<dimen name="app_banner_icon_spacing">16dp</dimen> <dimen name="app_banner_icon_spacing">16dp</dimen>
<!-- Contextual search dimensions -->
<dimen name="contextual_search_bar_height">80dp</dimen>
<!-- Password generation popup dimensions --> <!-- Password generation popup dimensions -->
<dimen name="password_generation_divider_height">1dp</dimen> <dimen name="password_generation_divider_height">1dp</dimen>
<dimen name="password_generation_text_size">14sp</dimen> <dimen name="password_generation_text_size">14sp</dimen>
......
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.chrome.browser.compositor.bottombar.contextualsearch;
import org.chromium.chrome.browser.compositor.bottombar.contextualsearch.ContextualSearchPanel.PanelState;
import org.chromium.chrome.browser.compositor.bottombar.contextualsearch.ContextualSearchPanel.StateChangeReason;
/**
* The delegate that that interfaces with the {@link ContextualSearchPanel}.
*/
public interface ContextualSearchPanelDelegate {
/**
* @return Whether the Panel is showing.
*/
boolean isShowing();
/**
* @return Whether the Search Bar is peeking.
*/
boolean isPeeking();
/**
* Maximizes the Contextual Search Panel, then promotes it to a regular Tab.
* @param reason The {@code StateChangeReason} behind the maximization and promotion to tab.
*/
void maximizePanelThenPromoteToTab(StateChangeReason reason);
/**
* Maximizes the Contextual Search Panel, then promotes it to a regular Tab.
* @param reason The {@code StateChangeReason} behind the maximization and promotion to tab.
* @param duration The animation duration in milliseconds.
*/
void maximizePanelThenPromoteToTab(StateChangeReason reason, long duration);
/**
* Animates the Contextual Search Panel to its peeked state.
* @param reason The {@code StateChangeReason} to which closing the panel is attributed.
*/
void peekPanel(StateChangeReason reason);
/**
* Animates the Contextual Search Panel to its closed state.
* @param reason The {@code StateChangeReason} to which closing the panel is attributed.
* @param animate Whether to animate the close action.
*/
void closePanel(StateChangeReason reason, boolean animate);
/**
* Updates the y coordinate of the Base Page's selection start position.
* @param y The y coordinate.
*/
void updateBasePageSelectionYPx(float y);
/**
* Sets the content height of the First Run Flow Panel.
* @param height The content height of the First Run Flow Panel.
*/
void setPromoContentHeight(float height);
/**
* @param shouldHidePromoHeader Sets whether the First Run Flow's header
* should be hidden.
*/
void setShouldHidePromoHeader(boolean shouldHidePromoHeader);
/**
* Animates the Contextual Search panel after first-run success.
*/
void animateAfterFirstRunSuccess();
/**
* Handles the onLoadStarted event in the WebContents.
*/
void onLoadStarted();
/**
* Handles the onLoadStopped event in the WebContents.
*/
void onLoadStopped();
/**
* Handles the onLoadProgressChanged event in the WebContents.
* @param progress The loading progress in percentage (from 0 to 100).
*/
void onLoadProgressChanged(int progress);
/**
* @return The panel's state.
*/
PanelState getPanelState();
/**
* Sets that the contextual search involved the promo.
*/
void setDidSearchInvolvePromo();
/**
* Sets that the Search Content View was seen.
*/
void setWasSearchContentViewSeen();
/**
* Sets whether the promo is active.
* @param shown Whether the promo is active.
*/
void setIsPromoActive(boolean shown);
/**
* Gets whether a touch on the search content view has been done yet or not.
*/
boolean didTouchSearchContentView();
}
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.chrome.browser.compositor.bottombar.contextualsearch;
/**
* Interface that allows {@link ContextualSearchPanel} to communicate with its host Layout.
*/
public interface ContextualSearchPanelHost {
/**
* Hides the Contextual Search Supported Layout.
* @param immediately Whether it should be hidden immediately.
*/
void hideLayout(boolean immediately);
}
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.chrome.browser.compositor.layouts;
import android.graphics.Rect;
import org.chromium.chrome.browser.compositor.layouts.components.LayoutTab;
import org.chromium.ui.resources.ResourceManager;
/**
* {@link LayoutRenderHost} is the minimal interface the layouts need to know about its host to
* render.
*/
public interface LayoutRenderHost {
/**
* Request layout and draw.
*/
void requestRender();
/**
* Indicates that we are about to draw and final layout changes should be made.
*/
void onCompositorLayout();
/**
* Indicates that a previously rendered frame has been swapped to the OS.
*/
void onSwapBuffersCompleted(int pendingSwapBuffersCount);
/**
* Indicates that the rendering surface has just been created.
*/
void onSurfaceCreated();
/**
* Indicates that the rendering surface has been resized.
*/
void onPhysicalBackingSizeChanged(int width, int height);
/**
* Indicates that the amount the surface is overdrawing on the bottom has changed.
*
* This occurs when the surface is larger than the window viewport.
*
* @param overdrawHeight The overdraw amount.
*/
void onOverdrawBottomHeightChanged(int overdrawHeight);
/**
* @see #onOverdrawBottomHeightChanged(int)
* @return The overdraw bottom height of the last frame rendered by the current tab.
*/
int getCurrentOverdrawBottomHeight();
/**
* @return The number of actually drawn {@link LayoutTab}.
*/
int getLayoutTabsDrawnCount();
/**
* Pushes a debug rectangle that will be drawn.
*
* @param rect The rect to be drawn.
* @param color The color of the rect.
*/
void pushDebugRect(Rect rect, int color);
/**
* Loads the persistent textures if they are not loaded already.
*/
void loadPersitentTextureDataIfNeeded();
/**
* @param rect Rect instance to be used to store the result and return. If null, it uses a new
* Rect instance.
* @return The current visible viewport of the host (takes fullscreen into account).
*/
Rect getVisibleViewport(Rect rect);
/**
* @return Whether or not the toolbar is currently being faked.
*/
boolean areTopControlsPermanentlyHidden();
/**
* @return The height of the top controls in pixels.
*/
int getTopControlsHeightPixels();
/**
* @return The {@link ResourceManager}.
*/
ResourceManager getResourceManager();
/**
* Called when something has changed in the Compositor rendered view system.
*/
void invalidateAccessibilityProvider();
}
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.chrome.browser.compositor.layouts;
import org.chromium.chrome.browser.Tab;
import org.chromium.chrome.browser.compositor.layouts.components.LayoutTab;
/**
* {@link LayoutRenderHost} is the minimal interface the layouts need to know about its host to
* update.
*/
public interface LayoutUpdateHost {
/**
* Requests a next update to refresh the transforms and changing properties. The update occurs
* once a frame. This is requesting a new frame to be updated and rendered (no need to call
* {@link LayoutRenderHost#requestRender()}).
*/
void requestUpdate();
/**
* Tells its host {@link android.view.View} that the hide will be an animation away.
* This is to be called from a {@link Layout}.
* @param nextTabId The id of the next tab.
* @param hintAtTabSelection Whether or not to hint about a new tab being selected.
*/
void startHiding(int nextTabId, boolean hintAtTabSelection);
/**
* Tells its host {@link android.view.View} that the Layout has done all animation so the view
* can hide. This is to be called from a {@link Layout}.
*/
void doneHiding();
/**
* Tells its host that the Layout is done it's preliminary showing animation.
*/
void doneShowing();
/**
* @param layout The {@link Layout} being evaluated.
* @return Whether the given {@link Layout} is being displayed.
*/
boolean isActiveLayout(Layout layout);
/**
* Initializes {@link org.chromium.chrome.browser.compositor.layouts.components.LayoutTab} with
* data accessible only from the {@link LayoutUpdateHost} such as data extracted out of a
* {@link Tab}.
*
* @param tabId The id of the
* {@link org.chromium.chrome.browser.compositor.layouts.components.LayoutTab}
* to be initialized from a {@link Tab}.
*/
void initLayoutTabFromHost(final int tabId);
/**
* Creates or recycles a {@Link LayoutTab}.
*
* @param id The id of the reference tab in the
* {@link org.chromium.chrome.browser.tabmodel.TabModel}.
* @param incognito Whether the new tab is incognito.
* @param showCloseButton True to show and activate a close button on the border.
* @param isTitleNeeded Whether a title will be shown.
* @param maxContentWidth The maximum layout width this tab can be. Negative numbers will use
* the original content width.
* @param maxContentHeight The maximum layout height this tab can be. Negative numbers will use
* the original content height.
* @return The created or recycled {@link LayoutTab}.
*/
LayoutTab createLayoutTab(int id, boolean incognito, boolean showCloseButton,
boolean isTitleNeeded, float maxContentWidth, float maxContentHeight);
/**
* Notifies the host that the {@link LayoutTab} is no longer needed by the layout.
*
* @param id The id of the reference tab in the
* {@link org.chromium.chrome.browser.tabmodel.TabModel}.
*/
void releaseTabLayout(int id);
}
...@@ -876,7 +876,8 @@ public class LayoutTab implements ChromeAnimation.Animatable<LayoutTab.Property> ...@@ -876,7 +876,8 @@ public class LayoutTab implements ChromeAnimation.Animatable<LayoutTab.Property>
} }
/** /**
* Callback for {@link com.google.android.apps.chrome.ChromeAnimation.Animatable} * Callback for
* {@link org.chromium.chrome.browser.compositor.layouts.ChromeAnimation.Animatable}
* *
* @param prop The property to set * @param prop The property to set
* @param val The value to set it to * @param val The value to set it to
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.chrome.browser.compositor.overlays;
import org.chromium.chrome.browser.compositor.LayerTitleCache;
import org.chromium.chrome.browser.compositor.layouts.components.VirtualView;
import org.chromium.chrome.browser.compositor.layouts.eventfilter.EventFilter;
import org.chromium.chrome.browser.compositor.scene_layer.SceneOverlayLayer;
import org.chromium.chrome.browser.fullscreen.ChromeFullscreenManager;
import org.chromium.chrome.browser.tabmodel.TabModel;
import org.chromium.ui.resources.ResourceManager;
import java.util.List;
/**
* An interface which positions the actual tabs and adds additional UI to the them.
*/
public interface SceneOverlay {
/**
* Updates and gets a {@link SceneOverlayLayer} that represents an scene overlay.
*
* @param layerTitleCache A layer title cache.
* @param resourceManager A resource manager.
* @param fullscreenManager A fullscreen manager.
* @return A {@link SceneOverlayLayer} that represents an scene overlay.
* Or {@code null} if this {@link SceneOverlay} doesn't have a tree.
*/
SceneOverlayLayer getUpdatedSceneOverlayTree(LayerTitleCache layerTitleCache,
ResourceManager resourceManager, ChromeFullscreenManager fullscreenManager);
/**
* @return The {@link EventFilter} that processes events for this {@link SceneOverlay}.
*/
EventFilter getEventFilter();
/**
* Called when the viewport size of the screen changes.
* @param width The new width of the viewport available in dp.
* @param height The new height of the viewport available in dp.
* @param visibleViewportOffsetY The visible viewport Y offset in dp.
*/
void onSizeChanged(float width, float height, float visibleViewportOffsetY);
/**
* @param views A list of virtual views representing compositor rendered views.
*/
void getVirtualViews(List<VirtualView> views);
/**
* Helper-specific updates. Cascades the values updated by the animations and flings.
* @param time The current time of the app in ms.
* @param dt The delta time between update frames in ms.
* @return Whether the updating is done.
*/
boolean updateOverlay(long time, long dt);
/**
* Notify the a title has changed.
*
* @param tabId The id of the tab that has changed.
* @param title The new title.
*/
void tabTitleChanged(int tabId, String title);
/**
* Called when the active {@link TabModel} switched (e.g. standard -> incognito).
* @param incognito Whether or not the new active model is incognito.
*/
void tabModelSwitched(boolean incognito);
/**
* Called when a tab get selected.
* @param time The current time of the app in ms.
* @param incognito Whether or not the affected model was incognito.
* @param id The id of the selected tab.
* @param prevId The id of the previously selected tab.
*/
void tabSelected(long time, boolean incognito, int id, int prevId);
/**
* Called when a tab has been moved in the tabModel.
* @param time The current time of the app in ms.
* @param incognito Whether or not the affected model was incognito.
* @param id The id of the Tab.
* @param oldIndex The old index of the tab in the {@link TabModel}.
* @param newIndex The new index of the tab in the {@link TabModel}.
*/
void tabMoved(long time, boolean incognito, int id, int oldIndex, int newIndex);
/**
* Called when a tab is being closed. When called, the closing tab will not
* be part of the model.
* @param time The current time of the app in ms.
* @param incognito Whether or not the affected model was incognito.
* @param id The id of the tab being closed.
*/
void tabClosed(long time, boolean incognito, int id);
/**
* Called when a tab close has been undone and the tab has been restored.
* @param time The current time of the app in ms.
* @param id The id of the Tab.
* @param incognito True if the tab is incognito
*/
void tabClosureCancelled(long time, boolean incognito, int id);
/**
* Called when a tab is created from the top left button.
* @param time The current time of the app in ms.
* @param incognito Whether or not the affected model was incognito.
* @param id The id of the newly created tab.
* @param prevId The id of the source tab.
* @param selected Whether the tab will be selected.
*/
void tabCreated(long time, boolean incognito, int id, int prevId, boolean selected);
/**
* Called when a tab has started loading.
* @param id The id of the Tab.
* @param incognito True if the tab is incognito.
*/
void tabPageLoadStarted(int id, boolean incognito);
/**
* Called when a tab has finished loading.
* @param id The id of the Tab.
* @param incognito True if the tab is incognito.
*/
void tabPageLoadFinished(int id, boolean incognito);
/**
* Called when a tab has started loading resources.
* @param id The id of the Tab.
* @param incognito True if the tab is incognito.
*/
void tabLoadStarted(int id, boolean incognito);
/**
* Called when a tab has stopped loading resources.
* @param id The id of the Tab.
* @param incognito True if the tab is incognito.
*/
void tabLoadFinished(int id, boolean incognito);
}
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.chrome.browser.contextualsearch;
import org.chromium.chrome.browser.Tab;
import org.chromium.chrome.browser.compositor.bottombar.contextualsearch.ContextualSearchPanelDelegate;
import org.chromium.content.browser.ContentViewCore;
import org.chromium.content_public.common.TopControlsState;
/**
* The delegate that provides global management functionality for Contextual Search.
*/
public interface ContextualSearchManagementDelegate {
/**
* @return Whether or not the Contextual Search Bar is peeking.
*/
boolean isSearchBarPeeking();
/**
* Updates the top controls state for the base tab. As these values are set at the renderer
* level, there is potential for this impacting other tabs that might share the same
* process. See {@link Tab#updateTopControlsState(int current, boolean animate)}
* @param current The desired current state for the controls. Pass
* {@link TopControlsState#BOTH} to preserve the current position.
* @param animate Whether the controls should animate to the specified ending condition or
* should jump immediately.
*/
void updateTopControlsState(int current, boolean animate);
/**
* Promotes the current Content View Core in the Contextual Search Panel to its own Tab.
* @param shouldFocusOmnibox Whether the Omnibox should be focused after promoting.
*/
void promoteToTab(boolean shouldFocusOmnibox);
/**
* Resets the Search Content View scroll position.
*/
void resetSearchContentViewScroll();
/**
* Gets the Search Content View's vertical scroll position. If the Search Content View
* is not available it returns -1.
* @return The Search Content View scroll position.
*/
float getSearchContentViewVerticalScroll();
/**
* Sets the visibility of the Search Content View.
* TODO(pedrosimonetti): Revisit this API. Consumers should not be allowed to make
* it invisible, only visible.
* @param isVisible True to make it visible.
*/
void setSearchContentViewVisibility(boolean isVisible);
/**
* Sets the delegate responsible for manipulating the ContextualSearchLayout.
* @param delegate The ContextualSearchLayoutDelegate.
*/
void setContextualSearchPanelDelegate(ContextualSearchPanelDelegate delegate);
/**
* Gets whether the device is running in compatibility mode for Contextual Search.
* If so, a new tab showing search results should be opened instead of showing the panel.
* @return whether the device is running in compatibility mode.
*/
boolean isRunningInCompatibilityMode();
/**
* Opens the resolved search URL in a new tab.
*/
void openResolvedSearchUrlInNewTab();
/**
* Preserves the Base Page's selection next time it loses focus.
*/
void preserveBasePageSelectionOnNextLossOfFocus();
/**
* Dismisses the Contextual Search bar completely. This will hide any panel that's currently
* showing as well as any bar that's peeking.
*/
void dismissContextualSearchBar();
/**
* Gets the {@code ContentViewCore} associated with Contextual Search Panel.
* @return Contextual Search Panel's {@code ContentViewCore}.
*/
ContentViewCore getSearchContentViewCore();
}
...@@ -73,4 +73,71 @@ public class MathUtils { ...@@ -73,4 +73,71 @@ public class MathUtils {
int mod = a % b; int mod = a % b;
return mod >= 0 ? mod : mod + b; return mod >= 0 ? mod : mod + b;
} }
/**
* Moves {@code value} forward to {@code target} based on {@code speed}.
* @param value The current value.
* @param target The target value.
* @param speed How far to move {@code value} to {@code target}. 0 doesn't move it at all. 1
* moves it to {@code target}.
* @return The new interpolated value.
*/
public static float interpolate(float value, float target, float speed) {
return (value + (target - value) * speed);
}
/**
* Smooth a value between 0 and 1.
* @param t The value to smooth.
* @return The smoothed value between 0 and 1.
*/
public static float smoothstep(float t) {
return t * t * (3.0f - 2.0f * t);
}
/**
* Scales the provided dimension such that it is just large enough to fit
* the target width and height.
*
* @param dimensions The dimensions to scale
* @param targetWidth The target width
* @param targetHeight The target height
* @return The scale factor applied to dimensions
*/
public static float scaleToFitTargetSize(
int [] dimensions, int targetWidth, int targetHeight) {
if (dimensions.length < 2 || dimensions[0] <= 0 || dimensions[1] <= 0) {
throw new IllegalArgumentException(
"Expected dimensions to have length >= 2 && dimensions[0] > 0 && "
+ "dimensions[1] > 0");
}
float scale = Math.max(
(float) targetWidth / dimensions[0],
(float) targetHeight / dimensions[1]);
dimensions[0] *= scale;
dimensions[1] *= scale;
return scale;
}
/**
* Flips {@code value} iff {@code flipSign} is {@code true}.
* @param value The value to flip.
* @param flipSign Whether or not to flip the value.
* @return {@code value} iff {@code flipSign} is {@code false}, otherwise negative
* {@code value}.
*/
public static int flipSignIf(int value, boolean flipSign) {
return flipSign ? -value : value;
}
/**
* Flips {@code value} iff {@code flipSign} is {@code true}.
* @param value The value to flip.
* @param flipSign Whether or not to flip the value.
* @return {@code value} iff {@code flipSign} is {@code false}, otherwise negative
* {@code value}.
*/
public static float flipSignIf(float value, boolean flipSign) {
return flipSign ? -value : value;
}
} }
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.chrome.browser.compositor.eventfilter;
import android.view.MotionEvent;
import org.chromium.chrome.browser.compositor.layouts.eventfilter.EventFilterHost;
/**
* Most basic {@link EventFilterHost}.
*/
public class MockEventFilterHost implements EventFilterHost {
public MockEventFilterHost() {
}
@Override
public boolean propagateEvent(MotionEvent e) {
return false;
}
@Override
public int getViewportWidth() {
return 0;
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment