/** * Handle all necessary tasks that can be delayed until initialization completes. * * @param activityCreationTimeMs The time of creation for the activity this toolbar belongs to. * @param activityName Simple class name for the activity this toolbar belongs to. */ public void onDeferredStartup(final long activityCreationTimeMs, final String activityName) { // Record startup performance statistics long elapsedTime = SystemClock.elapsedRealtime() - activityCreationTimeMs; if (elapsedTime < RECORD_UMA_PERFORMANCE_METRICS_DELAY_MS) { ThreadUtils.postOnUiThreadDelayed( new Runnable() { @Override public void run() { onDeferredStartup(activityCreationTimeMs, activityName); } }, RECORD_UMA_PERFORMANCE_METRICS_DELAY_MS - elapsedTime); } RecordHistogram.recordTimesHistogram( "MobileStartup.ToolbarFirstDrawTime." + activityName, mToolbar.getFirstDrawTime() - activityCreationTimeMs, TimeUnit.MILLISECONDS); long firstFocusTime = mToolbar.getLocationBar().getFirstUrlBarFocusTime(); if (firstFocusTime != 0) { RecordHistogram.recordCustomTimesHistogram( "MobileStartup.ToolbarFirstFocusTime." + activityName, firstFocusTime - activityCreationTimeMs, MIN_FOCUS_TIME_FOR_UMA_HISTOGRAM_MS, MAX_FOCUS_TIME_FOR_UMA_HISTOGRAM_MS, TimeUnit.MILLISECONDS, 50); } }
public CFGNodeFigure() { super(); ToolbarLayout layout2 = new ToolbarLayout(); layout2.setMinorAlignment(ToolbarLayout.ALIGN_CENTER); this.setLayoutManager(layout2); layout2.setStretchMinorAxis(false); }
/** * Updates the current button states and calls appropriate abstract visibility methods, giving * inheriting classes the chance to update the button visuals as well. */ private void updateButtonStatus() { Tab currentTab = mToolbarModel.getTab(); boolean tabCrashed = currentTab != null && currentTab.isShowingSadTab(); mToolbar.updateBackButtonVisibility(currentTab != null && currentTab.canGoBack()); mToolbar.updateForwardButtonVisibility(currentTab != null && currentTab.canGoForward()); updateReloadState(tabCrashed); updateBookmarkButtonStatus(); mToolbar .getMenuButton() .setVisibility(mToolbar.shouldShowMenuButton() ? View.VISIBLE : View.GONE); }
private void onNativeLibraryReady() { mNativeLibraryReady = true; mToolbar.onNativeLibraryReady(); final TemplateUrlService templateUrlService = TemplateUrlService.getInstance(); TemplateUrlService.LoadListener mTemplateServiceLoadListener = new TemplateUrlService.LoadListener() { @Override public void onTemplateUrlServiceLoaded() { registerTemplateUrlObserver(); templateUrlService.unregisterLoadListener(this); } }; templateUrlService.registerLoadListener(mTemplateServiceLoadListener); if (templateUrlService.isLoaded()) { mTemplateServiceLoadListener.onTemplateUrlServiceLoaded(); } else { templateUrlService.load(); } mTabModelSelector.addObserver(mTabModelSelectorObserver); for (TabModel model : mTabModelSelector.getModels()) model.addObserver(mTabModelObserver); refreshSelectedTab(); if (mTabModelSelector.isTabStateInitialized()) mTabRestoreCompleted = true; handleTabRestoreCompleted(); }
private void updateBookmarkButtonStatus() { Tab currentTab = mToolbarModel.getTab(); boolean isBookmarked = currentTab != null && currentTab.getBookmarkId() != ChromeBrowserProviderClient.INVALID_BOOKMARK_ID; mToolbar.updateBookmarkButtonVisibility(isBookmarked); }
/** * Update the primary color used by the model to the given color. * * @param color The primary color for the current tab. */ public void updatePrimaryColor(int color) { boolean colorChanged = mToolbarModel.getPrimaryColor() != color; if (!colorChanged) return; mToolbarModel.setPrimaryColor(color); mToolbar.onPrimaryColorChanged(); }
@Override public void onTabOrModelChanged() { super.onTabOrModelChanged(); boolean incognito = isIncognito(); if (mUseLightColorAssets == null || mUseLightColorAssets != incognito) { setBackgroundResource( incognito ? R.color.incognito_primary_color : R.color.default_primary_color); mMenuButton.setTint(incognito ? mLightModeTint : mDarkModeTint); mHomeButton.setTint(incognito ? mLightModeTint : mDarkModeTint); mBackButton.setTint(incognito ? mLightModeTint : mDarkModeTint); mForwardButton.setTint(incognito ? mLightModeTint : mDarkModeTint); if (incognito) { mLocationBar .getContainerView() .getBackground() .setAlpha(ToolbarPhone.LOCATION_BAR_TRANSPARENT_BACKGROUND_ALPHA); } else { mLocationBar.getContainerView().getBackground().setAlpha(255); } mAccessibilitySwitcherButton.setImageDrawable( incognito ? mTabSwitcherButtonDrawableLight : mTabSwitcherButtonDrawable); mLocationBar.updateVisualsForState(); if (mShowMenuBadge) { setAppMenuUpdateBadgeDrawable(incognito); } mUseLightColorAssets = incognito; } mLocationBar.setUrlBarFocus(false); }
/** Triggered when the selected tab has changed. */ private void refreshSelectedTab() { ChromeTab tab = null; if (mPreselectedTabId != Tab.INVALID_TAB_ID) { tab = ChromeTab.fromTab(mTabModelSelector.getTabById(mPreselectedTabId)); } if (tab == null) tab = ChromeTab.fromTab(mTabModelSelector.getCurrentTab()); boolean wasIncognito = mToolbarModel.isIncognito(); ChromeTab previousTab = ChromeTab.fromTab(mToolbarModel.getTab()); boolean isIncognito = tab != null ? tab.isIncognito() : mTabModelSelector.isIncognitoSelected(); mToolbarModel.setTab(tab, isIncognito); updateCurrentTabDisplayStatus(); if (previousTab != tab || wasIncognito != isIncognito) { if (previousTab != tab) { if (previousTab != null) previousTab.removeObserver(mTabObserver); if (tab != null) tab.addObserver(mTabObserver); } int defaultPrimaryColor = isIncognito ? mToolbar.getResources().getColor(R.color.incognito_primary_color) : mToolbar.getResources().getColor(R.color.default_primary_color); int primaryColor = (tab != null && tab.getWebContents() != null) ? tab.getWebContents().getThemeColor(defaultPrimaryColor) : defaultPrimaryColor; updatePrimaryColor(primaryColor); mToolbar.onTabOrModelChanged(); if (tab != null && tab.getWebContents() != null && tab.getWebContents().isLoadingToDifferentDocument()) { mToolbar.onNavigatedToDifferentPage(); } } Profile profile = mTabModelSelector.getModel(isIncognito).getProfile(); if (mCurrentProfile != profile) { if (mBookmarksBridge != null) mBookmarksBridge.destroy(); mBookmarksBridge = new BookmarksBridge(profile); mBookmarksBridge.addObserver(mBookmarksObserver); mLocationBar.setAutocompleteProfile(profile); mCurrentProfile = profile; } }
@Override public void initialize( ToolbarDataProvider toolbarDataProvider, ToolbarTabController tabController, AppMenuButtonHelper appMenuButtonHelper) { super.initialize(toolbarDataProvider, tabController, appMenuButtonHelper); updateVisualsForState(); }
@Override public void onWindowFocusChanged(boolean hasWindowFocus) { // Ensure the the popup is not shown after resuming activity from background. if (hasWindowFocus && mNavigationPopup != null) { mNavigationPopup.dismiss(); mNavigationPopup = null; } super.onWindowFocusChanged(hasWindowFocus); }
private void updateReloadState(boolean tabCrashed) { Tab currentTab = mToolbarModel.getTab(); boolean isLoading = false; if (!tabCrashed) { isLoading = (currentTab != null && currentTab.isLoading()) || !mNativeLibraryReady; } mToolbar.updateReloadButtonVisibility(isLoading); if (mMenuDelegatePhone != null) mMenuDelegatePhone.updateReloadButtonState(isLoading); }
@Override public void showAppMenuUpdateBadge() { super.showAppMenuUpdateBadge(); if (!mIsInTabSwitcherMode) { if (mUseLightColorAssets) { setAppMenuUpdateBadgeDrawable(mUseLightColorAssets); } setAppMenuUpdateBadgeToVisible(true); } }
@Override public void openHomepage() { Tab currentTab = mToolbarModel.getTab(); assert currentTab != null; Context context = mToolbar.getContext(); String homePageUrl = HomepageManager.getHomepageUri(context); if (TextUtils.isEmpty(homePageUrl)) { homePageUrl = UrlConstants.NTP_URL; } currentTab.loadUrl(new LoadUrlParams(homePageUrl, PageTransition.HOME_PAGE)); }
@Override public void onNativeLibraryReady() { super.onNativeLibraryReady(); mSecurityButton.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { Tab currentTab = getToolbarDataProvider().getTab(); if (currentTab == null || currentTab.getWebContents() == null) return; WebsiteSettingsPopup.show( getContext(), currentTab.getProfile(), currentTab.getWebContents()); } }); }
/** * Triggered when the URL input field has gained or lost focus. * * @param hasFocus Whether the URL field has gained focus. */ @Override public void onUrlFocusChange(boolean hasFocus) { mToolbar.onUrlFocusChange(hasFocus); if (mFindToolbarManager != null && hasFocus) mFindToolbarManager.hideToolbar(); if (mFullscreenManager == null) return; if (hasFocus) { mFullscreenFocusToken = mFullscreenManager.showControlsPersistentAndClearOldToken(mFullscreenFocusToken); } else { mFullscreenManager.hideControlsPersistent(mFullscreenFocusToken); mFullscreenFocusToken = FullscreenManager.INVALID_TOKEN; } }
@Override protected void onFinishInflate() { super.onFinishInflate(); setBackground(new ColorDrawable(getResources().getColor(R.color.default_primary_color))); mUrlBar = (UrlBar) findViewById(R.id.url_bar); mUrlBar.setHint(""); mUrlBar.setDelegate(this); mUrlBar.setEnabled(false); mUrlBar.setAllowFocus(false); mTitleBar = (TextView) findViewById(R.id.title_bar); mLocationBarFrameLayout = findViewById(R.id.location_bar_frame_layout); mTitleUrlContainer = findViewById(R.id.title_url_container); mSecurityButton = (ImageButton) findViewById(R.id.security_button); mSecurityIconType = ConnectionSecurityLevel.NONE; mCustomActionButton = (ImageButton) findViewById(R.id.action_button); mCloseButton = (ImageButton) findViewById(R.id.close_button); mCloseButton.setOnLongClickListener(this); mCustomActionButton.setOnLongClickListener(this); populateToolbarAnimations(); }
@Override public void onFinishInflate() { super.onFinishInflate(); mLocationBar = (LocationBar) findViewById(R.id.location_bar); mHomeButton = (TintedImageButton) findViewById(R.id.home_button); mBackButton = (TintedImageButton) findViewById(R.id.back_button); mForwardButton = (TintedImageButton) findViewById(R.id.forward_button); mReloadButton = (TintedImageButton) findViewById(R.id.refresh_button); mShowTabStack = DeviceClassManager.isAccessibilityModeEnabled(getContext()) || CommandLine.getInstance().hasSwitch(ChromeSwitches.ENABLE_TABLET_TAB_STACK); mTabSwitcherButtonDrawable = TabSwitcherDrawable.createTabSwitcherDrawable(getResources(), false); mTabSwitcherButtonDrawableLight = TabSwitcherDrawable.createTabSwitcherDrawable(getResources(), true); mAccessibilitySwitcherButton = (ImageButton) findViewById(R.id.tab_switcher_button); mAccessibilitySwitcherButton.setImageDrawable(mTabSwitcherButtonDrawable); updateSwitcherButtonVisibility(mShowTabStack); mBookmarkButton = (TintedImageButton) findViewById(R.id.bookmark_button); mMenuButton = (TintedImageButton) findViewById(R.id.menu_button); mMenuButtonWrapper.setVisibility(shouldShowMenuButton() ? View.VISIBLE : View.GONE); if (mAccessibilitySwitcherButton.getVisibility() == View.GONE && mMenuButtonWrapper.getVisibility() == View.GONE) { ApiCompatibilityUtils.setPaddingRelative( (View) mMenuButtonWrapper.getParent(), 0, 0, getResources().getDimensionPixelSize(R.dimen.tablet_toolbar_end_padding), 0); } }
private void updateLoadProgressInternal(int progress) { if (progress == mToolbarModel.getLoadProgress()) return; mToolbarModel.setLoadProgress(progress); mToolbar.setLoadProgress(progress); if (progress == 0) mLoadProgressSimulator.cancel(); }
/** Updates the current number of Tabs based on the TabModel this Toolbar contains. */ private void updateTabCount() { if (!mTabRestoreCompleted) return; mToolbar.updateTabCountVisuals(mTabModelSelector.getCurrentModel().getCount()); }
/** Finish any toolbar animations. */ public void finishAnimations() { if (isInitialized()) mToolbar.finishAnimations(); }
/** @return Whether {@link Toolbar} has drawn at least once. */ public boolean hasDoneFirstDraw() { return mToolbar.getFirstDrawTime() != 0; }
/** * Called when the accessibility enabled state changes. * * @param enabled Whether accessibility is enabled. */ public void onAccessibilityStatusChanged(boolean enabled) { mToolbar.onAccessibilityStatusChanged(enabled); }
/** Sets the drawable that the close button shows. */ public void setCloseButtonDrawable(Drawable drawable) { mToolbar.setCloseButtonImageResource(drawable); }
/** * Creates a ToolbarManager object. * * @param controlContainer The container of the toolbar. * @param menuHandler The handler for interacting with the menu. */ public ToolbarManager( final ChromeActivity activity, ToolbarControlContainer controlContainer, final AppMenuHandler menuHandler, final ChromeAppMenuPropertiesDelegate appMenuPropertiesDelegate, Invalidator invalidator) { mActionBarDelegate = new ContextualMenuBar.ActionBarDelegate() { @Override public void setControlTopMargin(int margin) { FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) mControlContainer.getLayoutParams(); lp.topMargin = margin; mControlContainer.setLayoutParams(lp); } @Override public int getControlTopMargin() { FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) mControlContainer.getLayoutParams(); return lp.topMargin; } @Override public ActionBar getSupportActionBar() { return activity.getSupportActionBar(); } @Override public void setActionBarBackgroundVisibility(boolean visible) { int visibility = visible ? View.VISIBLE : View.GONE; activity.findViewById(R.id.action_bar_black_background).setVisibility(visibility); // TODO(tedchoc): Add support for changing the color based on the brand color. } }; mToolbarModel = new ToolbarModelImpl(); mControlContainer = controlContainer; assert mControlContainer != null; mToolbar = (ToolbarLayout) controlContainer.findViewById(R.id.toolbar); mToolbar.setPaintInvalidator(invalidator); mContextualMenuBar = new ContextualMenuBar(activity, mActionBarDelegate); mContextualMenuBar.setCustomSelectionActionModeCallback( new CustomSelectionActionModeCallback()); mContextualMenuBar.setTabStripHeight(mToolbar.getTabStripHeight()); MenuDelegatePhone menuDelegate = new MenuDelegatePhone() { @Override public void updateReloadButtonState(boolean isLoading) { if (appMenuPropertiesDelegate != null) { appMenuPropertiesDelegate.loadingStateChanged(isLoading); menuHandler.menuItemContentChanged(R.id.icon_row_menu_id); } } }; setMenuDelegatePhone(menuDelegate); mLocationBar = mToolbar.getLocationBar(); mLocationBar.setToolbarDataProvider(mToolbarModel); mLocationBar.setUrlFocusChangeListener(this); mLocationBar.setDefaultTextEditActionModeCallback( mContextualMenuBar.getCustomSelectionActionModeCallback()); mLocationBar.initializeControls( new WindowDelegate(activity.getWindow()), mContextualMenuBar.getActionBarDelegate(), activity.getWindowAndroid()); mLocationBar.setIgnoreURLBarModification(false); setMenuHandler(menuHandler); mToolbar.initialize(mToolbarModel, this, mAppMenuButtonHelper); mHomepageStateListener = new HomepageStateListener() { @Override public void onHomepageStateUpdated() { mToolbar.onHomeButtonUpdate(HomepageManager.isHomepageEnabled(mToolbar.getContext())); } }; HomepageManager.getInstance(mToolbar.getContext()).addListener(mHomepageStateListener); mTabModelSelectorObserver = new EmptyTabModelSelectorObserver() { @Override public void onTabModelSelected(TabModel newModel, TabModel oldModel) { refreshSelectedTab(); updateTabCount(); mControlContainer.invalidateBitmap(); } @Override public void onTabStateInitialized() { mTabRestoreCompleted = true; handleTabRestoreCompleted(); } }; mTabModelObserver = new EmptyTabModelObserver() { @Override public void didAddTab(Tab tab, TabLaunchType type) { updateTabCount(); } @Override public void didSelectTab(Tab tab, TabSelectionType type, int lastId) { mPreselectedTabId = Tab.INVALID_TAB_ID; refreshSelectedTab(); } @Override public void tabClosureUndone(Tab tab) { updateTabCount(); refreshSelectedTab(); } @Override public void didCloseTab(Tab tab) { updateTabCount(); refreshSelectedTab(); } @Override public void tabPendingClosure(Tab tab) { updateTabCount(); refreshSelectedTab(); } @Override public void allTabsPendingClosure(List<Integer> tabIds) { updateTabCount(); refreshSelectedTab(); } }; mTabObserver = new EmptyTabObserver() { @Override public void onSSLStateUpdated(Tab tab) { super.onSSLStateUpdated(tab); assert tab == mToolbarModel.getTab(); mLocationBar.updateSecurityIcon(tab.getSecurityLevel()); } @Override public void onWebContentsInstantSupportDisabled() { mLocationBar.setUrlToPageUrl(); } @Override public void onDidNavigateMainFrame( Tab tab, String url, String baseUrl, boolean isNavigationToDifferentPage, boolean isFragmentNavigation, int statusCode) { if (isNavigationToDifferentPage) { mToolbar.onNavigatedToDifferentPage(); } } @Override public void onPageLoadStarted(Tab tab, String url) { updateButtonStatus(); updateTabLoadingState(true, true); } @Override public void onPageLoadFinished(Tab tab) { ToolbarManager.this.onPageLoadFinished(); } @Override public void onPageLoadFailed(Tab tab, int errorCode) { ToolbarManager.this.onPageLoadFailed(); } @Override public void onTitleUpdated(Tab tab) { mLocationBar.setTitleToPageTitle(); } @Override public void onUrlUpdated(Tab tab) { // Update the SSL security state as a result of this notification as it will // sometimes be the only update we receive. updateTabLoadingState(false, true); // A URL update is a decent enough indicator that the toolbar widget is in // a stable state to capture its bitmap for use in fullscreen. mControlContainer.setReadyForBitmapCapture(true); } @Override public void onCrash(Tab tab, boolean sadTabShown) { onTabCrash(); } @Override public void onLoadProgressChanged(Tab tab, int progress) { updateLoadProgress(progress); } @Override public void onContentChanged(Tab tab) { mToolbar.onTabContentViewChanged(); } @Override public void onWebContentsSwapped(Tab tab, boolean didStartLoad, boolean didFinishLoad) { if (!didStartLoad) return; ChromeTab chromeTab = ChromeTab.fromTab(tab); if (!chromeTab.getBackgroundContentViewHelper().isPageSwappingInProgress() && didFinishLoad) { mLoadProgressSimulator.start(); } } @Override public void onDidStartNavigationToPendingEntry(Tab tab, String url) { // Update URL as soon as it becomes available when it's a new tab. // But we want to update only when it's a new tab. So we check whether the current // navigation entry is initial, meaning whether it has the same target URL as the // initial URL of the tab. WebContents webContents = tab.getWebContents(); if (webContents == null) return; NavigationController navigationController = webContents.getNavigationController(); if (navigationController == null) return; if (navigationController.isInitialNavigation()) { mLocationBar.setUrlToPageUrl(); } } @Override public void onLoadUrl(Tab tab, LoadUrlParams params, int loadType) { NewTabPage ntp = mToolbarModel.getNewTabPageForCurrentTab(); if (ntp == null) return; if (!NewTabPage.isNTPUrl(params.getUrl()) && loadType != TabLoadStatus.PAGE_LOAD_FAILED) { ntp.setUrlFocusAnimationsDisabled(true); mToolbar.onTabOrModelChanged(); } } @Override public void onDidFailLoad( Tab tab, boolean isProvisionalLoad, boolean isMainFrame, int errorCode, String description, String failingUrl) { NewTabPage ntp = mToolbarModel.getNewTabPageForCurrentTab(); if (ntp == null) return; if (isProvisionalLoad && isMainFrame) { ntp.setUrlFocusAnimationsDisabled(false); mToolbar.onTabOrModelChanged(); } } @Override public void onContextualActionBarVisibilityChanged(Tab tab, boolean visible) { if (visible) RecordUserAction.record("MobileActionBarShown"); ActionBar actionBar = mActionBarDelegate.getSupportActionBar(); if (!visible && actionBar != null) actionBar.hide(); if (DeviceFormFactor.isTablet(activity)) { if (visible) { mContextualMenuBar.showControls(); } else { mContextualMenuBar.hideControls(); } } } }; mBookmarksObserver = new BookmarksBridge.BookmarkModelObserver() { @Override public void bookmarkModelChanged() { updateBookmarkButtonStatus(); } }; mFindToolbarObserver = new FindToolbarObserver() { @Override public void onFindToolbarShown() { mToolbar.handleFindToolbarStateChange(true); if (mFullscreenManager != null) { mFullscreenFindInPageToken = mFullscreenManager.showControlsPersistentAndClearOldToken( mFullscreenFindInPageToken); } } @Override public void onFindToolbarHidden() { mToolbar.handleFindToolbarStateChange(false); if (mFullscreenManager != null) { mFullscreenManager.hideControlsPersistent(mFullscreenFindInPageToken); mFullscreenFindInPageToken = FullscreenManager.INVALID_TOKEN; } } }; mOverviewModeObserver = new EmptyOverviewModeObserver() { @Override public void onOverviewModeStartedShowing(boolean showToolbar) { mToolbar.setTabSwitcherMode(true, showToolbar, false); updateButtonStatus(); } @Override public void onOverviewModeStartedHiding(boolean showToolbar, boolean delayAnimation) { mToolbar.setTabSwitcherMode(false, showToolbar, delayAnimation); updateButtonStatus(); } @Override public void onOverviewModeFinishedHiding() { mToolbar.onTabSwitcherTransitionFinished(); } }; mSceneChangeObserver = new SceneChangeObserver() { @Override public void onTabSelectionHinted(int tabId) { mPreselectedTabId = tabId; refreshSelectedTab(); } @Override public void onSceneChange(Layout layout) { mToolbar.setContentAttached(layout.shouldDisplayContentOverlay()); } }; mLoadProgressSimulator = new LoadProgressSimulator(this); }
/** * Initialize the manager with the components that had native initialization dependencies. * * <p>Calling this must occur after the native library have completely loaded. * * @param tabModelSelector The selector that handles tab management. * @param fullscreenManager The manager in charge of interacting with the fullscreen feature. * @param findToolbarManager The manager for find in page. * @param overviewModeBehavior The overview mode manager. * @param layoutDriver A {@link LayoutManager} instance used to watch for scene changes. */ public void initializeWithNative( TabModelSelector tabModelSelector, ChromeFullscreenManager fullscreenManager, final FindToolbarManager findToolbarManager, final OverviewModeBehavior overviewModeBehavior, final LayoutManager layoutDriver, OnClickListener tabSwitcherClickHandler, OnClickListener newTabClickHandler, OnClickListener bookmarkClickHandler, OnClickListener customTabsBackClickHandler) { assert !mInitializedWithNative; mTabModelSelector = tabModelSelector; mToolbar.getLocationBar().updateVisualsForState(); mToolbar.getLocationBar().setUrlToPageUrl(); mToolbar.setOnTabSwitcherClickHandler(tabSwitcherClickHandler); mToolbar.setOnNewTabClickHandler(newTabClickHandler); mToolbar.setBookmarkClickHandler(bookmarkClickHandler); mToolbar.setCustomTabCloseClickHandler(customTabsBackClickHandler); mToolbarModel.initializeWithNative(); mToolbar.addOnAttachStateChangeListener( new OnAttachStateChangeListener() { @Override public void onViewDetachedFromWindow(View v) { Context context = mToolbar.getContext(); HomepageManager.getInstance(context).removeListener(mHomepageStateListener); mTabModelSelector.removeObserver(mTabModelSelectorObserver); for (TabModel model : mTabModelSelector.getModels()) { model.removeObserver(mTabModelObserver); } if (mBookmarksBridge != null) { mBookmarksBridge.destroy(); mBookmarksBridge = null; } if (mTemplateUrlObserver != null) { TemplateUrlService.getInstance().removeObserver(mTemplateUrlObserver); mTemplateUrlObserver = null; } findToolbarManager.removeObserver(mFindToolbarObserver); if (overviewModeBehavior != null) { overviewModeBehavior.removeOverviewModeObserver(mOverviewModeObserver); } if (layoutDriver != null) { layoutDriver.removeSceneChangeObserver(mSceneChangeObserver); } } @Override public void onViewAttachedToWindow(View v) { // As we have only just registered for notifications, any that were sent prior to // this may have been missed. // Calling refreshSelectedTab in case we missed the initial selection notification. refreshSelectedTab(); } }); mFindToolbarManager = findToolbarManager; assert fullscreenManager != null; mFullscreenManager = fullscreenManager; mNativeLibraryReady = false; findToolbarManager.addObserver(mFindToolbarObserver); if (overviewModeBehavior != null) { overviewModeBehavior.addOverviewModeObserver(mOverviewModeObserver); } if (layoutDriver != null) layoutDriver.addSceneChangeObserver(mSceneChangeObserver); onNativeLibraryReady(); mInitializedWithNative = true; }
private void handleTabRestoreCompleted() { if (!mTabRestoreCompleted || !mNativeLibraryReady) return; mToolbar.onStateRestored(); updateTabCount(); }
/** @return The view that the pop up menu should be anchored to on the UI. */ public View getMenuAnchor() { return mToolbar.getLocationBar().getMenuAnchor(); }
/** * Focuses or unfocuses the URL bar. * * @param focused Whether URL bar should be focused. */ public void setUrlBarFocus(boolean focused) { if (!isInitialized()) return; mToolbar.getLocationBar().setUrlBarFocus(focused); }
/** * Sets up key listeners after native initialization is complete, so that we can invoke native * functions. */ @Override public void onNativeLibraryReady() { super.onNativeLibraryReady(); mLocationBar.onNativeLibraryReady(); mHomeButton.setOnClickListener(this); mHomeButton.setOnKeyListener( new KeyboardNavigationListener() { @Override public View getNextFocusForward() { if (mBackButton.isFocusable()) { return findViewById(R.id.back_button); } else if (mForwardButton.isFocusable()) { return findViewById(R.id.forward_button); } else { return findViewById(R.id.refresh_button); } } @Override public View getNextFocusBackward() { return findViewById(R.id.menu_button); } }); mBackButton.setOnClickListener(this); mBackButton.setLongClickable(true); mBackButton.setOnKeyListener( new KeyboardNavigationListener() { @Override public View getNextFocusForward() { if (mForwardButton.isFocusable()) { return findViewById(R.id.forward_button); } else { return findViewById(R.id.refresh_button); } } @Override public View getNextFocusBackward() { if (mHomeButton.getVisibility() == VISIBLE) { return findViewById(R.id.home_button); } else { return findViewById(R.id.menu_button); } } }); mForwardButton.setOnClickListener(this); mForwardButton.setLongClickable(true); mForwardButton.setOnKeyListener( new KeyboardNavigationListener() { @Override public View getNextFocusForward() { return findViewById(R.id.refresh_button); } @Override public View getNextFocusBackward() { if (mBackButton.isFocusable()) { return mBackButton; } else if (mHomeButton.getVisibility() == VISIBLE) { return findViewById(R.id.home_button); } else { return findViewById(R.id.menu_button); } } }); mReloadButton.setOnClickListener(this); mReloadButton.setOnKeyListener( new KeyboardNavigationListener() { @Override public View getNextFocusForward() { return findViewById(R.id.url_bar); } @Override public View getNextFocusBackward() { if (mForwardButton.isFocusable()) { return mForwardButton; } else if (mBackButton.isFocusable()) { return mBackButton; } else if (mHomeButton.getVisibility() == VISIBLE) { return findViewById(R.id.home_button); } else { return findViewById(R.id.menu_button); } } }); mAccessibilitySwitcherButton.setOnClickListener(this); mBookmarkButton.setOnClickListener(this); mMenuButton.setOnKeyListener( new KeyboardNavigationListener() { @Override public View getNextFocusForward() { return getCurrentTabView(); } @Override public View getNextFocusBackward() { return findViewById(R.id.url_bar); } @Override protected boolean handleEnterKeyPress() { return getMenuButtonHelper().onEnterKeyPress(mMenuButton); } }); if (HomepageManager.isHomepageEnabled(getContext())) { mHomeButton.setVisibility(VISIBLE); } }
/** * Adds a custom action button to the {@link Toolbar} if it is supported. * * @param drawable The {@link Drawable} to use as the background for the button. * @param description The content description for the custom action button. * @param listener The {@link OnClickListener} to use for clicks to the button. */ public void addCustomActionButton( Drawable drawable, String description, OnClickListener listener) { mToolbar.addCustomActionButton(drawable, description, listener); }