use of org.chromium.chrome.browser.tabmodel.TabModel in project AndroidChromium by JackyAndroid.
the class ChromeTabbedActivity method onMenuOrKeyboardAction.
@Override
public boolean onMenuOrKeyboardAction(final int id, boolean fromMenu) {
final Tab currentTab = getActivityTab();
if (id == R.id.move_to_other_window_menu_id) {
if (currentTab != null)
moveTabToOtherWindow(currentTab);
} else if (id == R.id.new_tab_menu_id) {
getTabModelSelector().getModel(false).commitAllTabClosures();
RecordUserAction.record("MobileMenuNewTab");
RecordUserAction.record("MobileNewTabOpened");
reportNewTabShortcutUsed(false);
getTabCreator(false).launchUrl(UrlConstants.NTP_URL, TabLaunchType.FROM_CHROME_UI);
mLocaleManager.showSearchEnginePromoIfNeeded(this);
} else if (id == R.id.new_incognito_tab_menu_id) {
if (PrefServiceBridge.getInstance().isIncognitoModeEnabled()) {
getTabModelSelector().getModel(false).commitAllTabClosures();
// This action must be recorded before opening the incognito tab since UMA actions
// are dropped when an incognito tab is open.
RecordUserAction.record("MobileMenuNewIncognitoTab");
RecordUserAction.record("MobileNewTabOpened");
reportNewTabShortcutUsed(true);
getTabCreator(true).launchUrl(UrlConstants.NTP_URL, TabLaunchType.FROM_CHROME_UI);
}
} else if (id == R.id.all_bookmarks_menu_id) {
if (currentTab != null) {
getCompositorViewHolder().hideKeyboard(new Runnable() {
@Override
public void run() {
StartupMetrics.getInstance().recordOpenedBookmarks();
BookmarkUtils.showBookmarkManager(ChromeTabbedActivity.this);
}
});
RecordUserAction.record("MobileMenuAllBookmarks");
}
} else if (id == R.id.recent_tabs_menu_id) {
if (currentTab != null) {
currentTab.loadUrl(new LoadUrlParams(UrlConstants.RECENT_TABS_URL, PageTransition.AUTO_BOOKMARK));
RecordUserAction.record("MobileMenuOpenTabs");
}
} else if (id == R.id.close_all_tabs_menu_id) {
// Close both incognito and normal tabs
getTabModelSelector().closeAllTabs();
RecordUserAction.record("MobileMenuCloseAllTabs");
} else if (id == R.id.close_all_incognito_tabs_menu_id) {
// Close only incognito tabs
getTabModelSelector().getModel(true).closeAllTabs();
// TODO(nileshagrawal) Record unique action for this. See bug http://b/5542946.
RecordUserAction.record("MobileMenuCloseAllTabs");
} else if (id == R.id.find_in_page_id) {
mFindToolbarManager.showToolbar();
if (getContextualSearchManager() != null) {
getContextualSearchManager().hideContextualSearch(StateChangeReason.UNKNOWN);
}
if (fromMenu) {
RecordUserAction.record("MobileMenuFindInPage");
} else {
RecordUserAction.record("MobileShortcutFindInPage");
}
} else if (id == R.id.focus_url_bar) {
boolean isUrlBarVisible = !mLayoutManager.overviewVisible() && (!isTablet() || getCurrentTabModel().getCount() != 0);
if (isUrlBarVisible) {
getToolbarManager().setUrlBarFocus(true);
}
} else if (id == R.id.downloads_menu_id) {
DownloadUtils.showDownloadManager(this, currentTab);
RecordUserAction.record("MobileMenuDownloadManager");
} else if (id == R.id.open_recently_closed_tab) {
TabModel currentModel = mTabModelSelectorImpl.getCurrentModel();
if (!currentModel.isIncognito())
currentModel.openMostRecentlyClosedTab();
RecordUserAction.record("MobileTabClosedUndoShortCut");
} else if (id == R.id.enter_vr_id) {
mVrShellDelegate.enterVRIfNecessary();
} else {
return super.onMenuOrKeyboardAction(id, fromMenu);
}
return true;
}
use of org.chromium.chrome.browser.tabmodel.TabModel in project AndroidChromium by JackyAndroid.
the class ContextualSearchManager method listenForTabModelSelectorNotifications.
/**
* Listens for notifications that should hide the Contextual Search bar.
*/
private void listenForTabModelSelectorNotifications() {
TabModelSelector selector = mActivity.getTabModelSelector();
mTabModelSelectorTabObserver = new TabModelSelectorTabObserver(selector) {
@Override
public void onPageLoadStarted(Tab tab, String url) {
hideContextualSearch(StateChangeReason.UNKNOWN);
mDidBasePageLoadJustStart = true;
}
@Override
public void onCrash(Tab tab, boolean sadTabShown) {
if (sadTabShown) {
// Hide contextual search if the foreground tab crashed
hideContextualSearch(StateChangeReason.UNKNOWN);
}
}
@Override
public void onClosingStateChanged(Tab tab, boolean closing) {
if (closing)
hideContextualSearch(StateChangeReason.UNKNOWN);
}
};
for (TabModel tabModel : selector.getModels()) {
tabModel.addObserver(mTabModelObserver);
}
}
use of org.chromium.chrome.browser.tabmodel.TabModel in project AndroidChromium by JackyAndroid.
the class StackLayout method uiRequestingCloseTab.
/**
* Called when a UI element is attempting to close a tab. This will perform the required close
* animations. When the UI is ready to actually close the tab
* {@link #uiDoneClosingTab(long, int, boolean, boolean)} should be called to actually propagate
* the event to the model.
* @param time The current time of the app in ms.
* @param id The id of the tab to close.
*/
public void uiRequestingCloseTab(long time, int id) {
// Start the tab closing effect if necessary.
getTabStack(id).tabClosingEffect(time, id);
int incognitoCount = mTabModelSelector.getModel(true).getCount();
TabModel model = mTabModelSelector.getModelForTabId(id);
if (model != null && model.isIncognito())
incognitoCount--;
boolean incognitoVisible = incognitoCount > 0;
// Make sure we show/hide both stacks depending on which tab we're closing.
startMarginAnimation(true, incognitoVisible);
if (!incognitoVisible)
uiPreemptivelySelectTabModel(false);
}
use of org.chromium.chrome.browser.tabmodel.TabModel in project AndroidChromium by JackyAndroid.
the class Layout method doneHiding.
/**
* To be called when the transition out of the view mode is done.
* This is currently called by the renderer when all the animation are done while hiding.
*/
public void doneHiding() {
mIsHiding = false;
if (mNextTabId != Tab.INVALID_TAB_ID) {
TabModel model = mTabModelSelector.getModelForTabId(mNextTabId);
if (model != null) {
TabModelUtils.setIndex(model, TabModelUtils.getTabIndexById(model, mNextTabId));
}
mNextTabId = Tab.INVALID_TAB_ID;
}
mUpdateHost.doneHiding();
if (mRenderHost != null && mRenderHost.getResourceManager() != null) {
mRenderHost.getResourceManager().clearTintedResourceCache();
}
}
use of org.chromium.chrome.browser.tabmodel.TabModel in project AndroidChromium by JackyAndroid.
the class SimpleAnimationLayout method onTabClosed.
/**
* Animate the closing of a tab
*/
@Override
public void onTabClosed(long time, int id, int nextId, boolean incognito) {
super.onTabClosed(time, id, nextId, incognito);
if (mClosedTab != null) {
TabModel nextModel = mTabModelSelector.getModelForTabId(nextId);
if (nextModel != null) {
LayoutTab nextLayoutTab = createLayoutTab(nextId, nextModel.isIncognito(), NO_CLOSE_BUTTON, NO_TITLE);
nextLayoutTab.setDrawDecoration(false);
mLayoutTabs = new LayoutTab[] { nextLayoutTab, mClosedTab };
updateCacheVisibleIds(new LinkedList<Integer>(Arrays.asList(nextId, mClosedTab.getId())));
} else {
mLayoutTabs = new LayoutTab[] { mClosedTab };
}
forceAnimationToFinish();
mAnimatedTab = mClosedTab;
addToAnimation(this, Property.DISCARD_AMOUNT, 0, getDiscardRange(), TAB_CLOSED_ANIMATION_DURATION, 0, false, BakedBezierInterpolator.FADE_OUT_CURVE);
mClosedTab = null;
if (nextModel != null) {
mTabModelSelector.selectModel(nextModel.isIncognito());
}
}
startHiding(nextId, false);
}
Aggregations