use of org.chromium.chrome.browser.tab.Tab in project AndroidChromium by JackyAndroid.
the class AppMenuPropertiesDelegate method prepareMenu.
/**
* Allows the delegate to show and hide items before the App Menu is shown. It is called every
* time the menu is shown. This assumes that the provided menu contains all the items expected
* in the application menu (i.e. that the main menu has been inflated into it).
* @param menu Menu that will be used as the source for the App Menu pop up.
*/
public void prepareMenu(Menu menu) {
// Exactly one of these will be true, depending on the type of menu showing.
boolean isPageMenu;
boolean isOverviewMenu;
boolean isTabletEmptyModeMenu;
boolean isOverview = mActivity.isInOverviewMode();
boolean isIncognito = mActivity.getCurrentTabModel().isIncognito();
Tab currentTab = mActivity.getActivityTab();
// Determine which menu to show.
if (mActivity.isTablet()) {
boolean hasTabs = mActivity.getCurrentTabModel().getCount() != 0;
isPageMenu = hasTabs && !isOverview;
isOverviewMenu = hasTabs && isOverview;
isTabletEmptyModeMenu = !hasTabs;
} else {
isPageMenu = !isOverview;
isOverviewMenu = isOverview;
isTabletEmptyModeMenu = false;
}
menu.setGroupVisible(R.id.PAGE_MENU, isPageMenu);
menu.setGroupVisible(R.id.OVERVIEW_MODE_MENU, isOverviewMenu);
menu.setGroupVisible(R.id.TABLET_EMPTY_MODE_MENU, isTabletEmptyModeMenu);
if (isPageMenu && currentTab != null) {
String url = currentTab.getUrl();
boolean isChromeScheme = url.startsWith(UrlConstants.CHROME_SCHEME) || url.startsWith(UrlConstants.CHROME_NATIVE_SCHEME);
boolean shouldShowIconRow = !mActivity.isTablet() || mActivity.getWindow().getDecorView().getWidth() < DeviceFormFactor.getMinimumTabletWidthPx(mActivity);
// Update the icon row items (shown in narrow form factors).
menu.findItem(R.id.icon_row_menu_id).setVisible(shouldShowIconRow);
if (shouldShowIconRow) {
// Disable the "Forward" menu item if there is no page to go to.
MenuItem forwardMenuItem = menu.findItem(R.id.forward_menu_id);
forwardMenuItem.setEnabled(currentTab.canGoForward());
mReloadMenuItem = menu.findItem(R.id.reload_menu_id);
mReloadMenuItem.setIcon(R.drawable.btn_reload_stop);
loadingStateChanged(currentTab.isLoading());
MenuItem bookmarkMenuItem = menu.findItem(R.id.bookmark_this_page_id);
updateBookmarkMenuItem(bookmarkMenuItem, currentTab);
MenuItem offlineMenuItem = menu.findItem(R.id.offline_page_id);
if (offlineMenuItem != null) {
if (DownloadUtils.isDownloadHomeEnabled()) {
offlineMenuItem.setEnabled(DownloadUtils.isAllowedToDownloadPage(currentTab));
Drawable drawable = offlineMenuItem.getIcon();
if (drawable != null) {
int iconTint = ApiCompatibilityUtils.getColor(mActivity.getResources(), R.color.light_normal_color);
drawable.mutate();
drawable.setColorFilter(iconTint, PorterDuff.Mode.SRC_ATOP);
}
} else {
offlineMenuItem.setVisible(false);
}
}
}
menu.findItem(R.id.downloads_menu_id).setVisible(DownloadUtils.isDownloadHomeEnabled());
menu.findItem(R.id.update_menu_id).setVisible(UpdateMenuItemHelper.getInstance().shouldShowMenuItem(mActivity));
menu.findItem(R.id.move_to_other_window_menu_id).setVisible(MultiWindowUtils.getInstance().isOpenInOtherWindowSupported(mActivity));
MenuItem recentTabsMenuItem = menu.findItem(R.id.recent_tabs_menu_id);
recentTabsMenuItem.setVisible(!isIncognito);
recentTabsMenuItem.setTitle(R.string.menu_recent_tabs);
MenuItem allBookmarksMenuItem = menu.findItem(R.id.all_bookmarks_menu_id);
allBookmarksMenuItem.setTitle(mActivity.getString(R.string.menu_bookmarks));
// Don't allow "chrome://" pages to be shared.
menu.findItem(R.id.share_row_menu_id).setVisible(!isChromeScheme);
ShareHelper.configureDirectShareMenuItem(mActivity, menu.findItem(R.id.direct_share_menu_id));
// Disable find in page on the native NTP.
menu.findItem(R.id.find_in_page_id).setVisible(!currentTab.isNativePage() && currentTab.getWebContents() != null);
// Hide 'Add to homescreen' on all chrome:// pages -- Android doesn't know how to direct
// those URLs. Also hide it on incognito pages to avoid problems where users create
// shortcuts in incognito mode and then open the webapp in regular mode. Also check if
// creating shortcuts is supported at all.
MenuItem homescreenItem = menu.findItem(R.id.add_to_homescreen_id);
boolean canAddShortcutToHomescreen = ShortcutHelper.isAddToHomeIntentSupported(mActivity);
homescreenItem.setVisible(canAddShortcutToHomescreen && !isChromeScheme && !isIncognito);
// Hide request desktop site on all chrome:// pages except for the NTP. Check request
// desktop site if it's activated on this page.
MenuItem requestItem = menu.findItem(R.id.request_desktop_site_id);
requestItem.setVisible(!isChromeScheme || currentTab.isNativePage());
requestItem.setChecked(currentTab.getUseDesktopUserAgent());
requestItem.setTitleCondensed(requestItem.isChecked() ? mActivity.getString(R.string.menu_request_desktop_site_on) : mActivity.getString(R.string.menu_request_desktop_site_off));
// Only display reader mode settings menu option if the current page is in reader mode.
menu.findItem(R.id.reader_mode_prefs_id).setVisible(DomDistillerUrlUtils.isDistilledPage(currentTab.getUrl()));
// Only display the Enter VR button if VR Shell is enabled.
menu.findItem(R.id.enter_vr_id).setVisible(mActivity.isVrShellEnabled());
}
if (isOverviewMenu) {
if (isIncognito) {
// Hide normal close all tabs item.
menu.findItem(R.id.close_all_tabs_menu_id).setVisible(false);
// Enable close incognito tabs only if there are incognito tabs.
menu.findItem(R.id.close_all_incognito_tabs_menu_id).setEnabled(true);
} else {
// Hide close incognito tabs item.
menu.findItem(R.id.close_all_incognito_tabs_menu_id).setVisible(false);
// Enable close all tabs if there are normal tabs or incognito tabs.
menu.findItem(R.id.close_all_tabs_menu_id).setEnabled(mActivity.getTabModelSelector().getTotalTabCount() > 0);
}
}
// Disable new incognito tab when it is blocked (e.g. by a policy).
// findItem(...).setEnabled(...)" is not enough here, because of the inflated
// main_menu.xml contains multiple items with the same id in different groups
// e.g.: new_incognito_tab_menu_id.
disableEnableMenuItem(menu, R.id.new_incognito_tab_menu_id, true, PrefServiceBridge.getInstance().isIncognitoModeEnabled(), PrefServiceBridge.getInstance().isIncognitoModeManaged());
mActivity.prepareMenu(menu);
}
use of org.chromium.chrome.browser.tab.Tab in project AndroidChromium by JackyAndroid.
the class CompositorViewHolder method onFinishNativeInitialization.
/**
* Sets the appropriate objects this class should represent.
* @param tabModelSelector The {@link TabModelSelector} this View should hold and
* represent.
* @param tabCreatorManager The {@link TabCreatorManager} for this view.
* @param tabContentManager The {@link TabContentManager} for the tabs.
* @param androidContentContainer The {@link ViewGroup} the {@link LayoutManager} should bind
* Android content to.
* @param contextualSearchManager A {@link ContextualSearchManagementDelegate} instance.
* @param readerModeManager A {@link ReaderModeManagerDelegate} instance.
*/
public void onFinishNativeInitialization(TabModelSelector tabModelSelector, TabCreatorManager tabCreatorManager, TabContentManager tabContentManager, ViewGroup androidContentContainer, ContextualSearchManagementDelegate contextualSearchManager, ReaderModeManagerDelegate readerModeManager) {
assert mLayoutManager != null;
mLayoutManager.init(tabModelSelector, tabCreatorManager, tabContentManager, androidContentContainer, contextualSearchManager, readerModeManager, mCompositorView.getResourceManager().getDynamicResourceLoader());
mTabModelSelector = tabModelSelector;
tabModelSelector.addObserver(new EmptyTabModelSelectorObserver() {
@Override
public void onChange() {
onContentChanged();
}
@Override
public void onNewTabCreated(Tab tab) {
initializeTab(tab);
}
});
mLayerTitleCache.setTabModelSelector(mTabModelSelector);
onContentChanged();
}
use of org.chromium.chrome.browser.tab.Tab in project AndroidChromium by JackyAndroid.
the class StripLayoutHelper method click.
/**
* Called on click. This is called before the onUpOrCancel event.
* @param time The current time of the app in ms.
* @param x The x coordinate of the position of the click.
* @param y The y coordinate of the position of the click.
* @param fromMouse Whether the event originates from a mouse.
* @param buttons State of all buttons that were pressed when onDown was invoked.
*/
public void click(long time, float x, float y, boolean fromMouse, int buttons) {
resetResizeTimeout(false);
if (mNewTabButton.click(x, y) && mModel != null) {
if (!mModel.isIncognito())
mModel.commitAllTabClosures();
mTabCreator.launchNTP();
return;
}
final StripLayoutTab clickedTab = getTabAtPosition(x);
if (clickedTab == null || clickedTab.isDying())
return;
if (clickedTab.checkCloseHitTest(x, y) || (fromMouse && (buttons & MotionEvent.BUTTON_TERTIARY) != 0)) {
// 1. Start the close animation.
startAnimation(buildTabClosedAnimation(clickedTab), true);
// 2. Set the dying state of the tab.
clickedTab.setIsDying(true);
// 3. Fake a selection on the next tab now.
Tab nextTab = mModel.getNextTabIfClosed(clickedTab.getId());
if (nextTab != null)
tabSelected(time, nextTab.getId(), clickedTab.getId());
// 4. Find out if we're closing the last tab. This determines if we resize immediately.
boolean lastTab = mStripTabs.length == 0 || mStripTabs[mStripTabs.length - 1].getId() == clickedTab.getId();
// 5. Resize the tabs appropriately.
resizeTabStrip(!lastTab);
} else {
int newIndex = TabModelUtils.getTabIndexById(mModel, clickedTab.getId());
TabModelUtils.setIndex(mModel, newIndex);
}
}
use of org.chromium.chrome.browser.tab.Tab in project AndroidChromium by JackyAndroid.
the class SimpleAnimationLayout method show.
@Override
public void show(long time, boolean animate) {
super.show(time, animate);
if (mTabModelSelector != null && mTabContentManager != null) {
Tab tab = mTabModelSelector.getCurrentTab();
if (tab != null && tab.isNativePage())
mTabContentManager.cacheTabThumbnail(tab);
}
reset();
}
use of org.chromium.chrome.browser.tab.Tab in project AndroidChromium by JackyAndroid.
the class StackLayout method show.
@Override
public void show(long time, boolean animate) {
super.show(time, animate);
Tab tab = mTabModelSelector.getCurrentTab();
if (tab != null && tab.isNativePage())
mTabContentManager.cacheTabThumbnail(tab);
// Remove any views in case we're getting another call to show before we hide (quickly
// toggling the tab switcher button).
mViewContainer.removeAllViews();
int currentTabModel = mTabModelSelector.isIncognitoSelected() ? 1 : 0;
for (int i = mStacks.length - 1; i >= 0; --i) {
mStacks[i].reset();
if (mStacks[i].isDisplayable()) {
mStacks[i].show(i == currentTabModel);
} else {
mStacks[i].cleanupTabs();
}
}
// Initialize the animation and the positioning of all the elements
mSortingComparator = mOrderComparator;
resetScrollData();
for (int i = mStacks.length - 1; i >= 0; --i) {
if (mStacks[i].isDisplayable()) {
boolean offscreen = (i != getTabStackIndex());
mStacks[i].stackEntered(time, !offscreen);
}
}
startMarginAnimation(true);
startYOffsetAnimation(true);
flingStacks(getTabStackIndex() == 1);
if (!animate)
onUpdateAnimation(time, true);
// We will render before we get a call to updateLayout. Need to make sure all of the tabs
// we need to render are up to date.
updateLayout(time, 0);
}
Aggregations