/** Called whenever the host activity is started. */
 public void onStart() {
   if (mFullscreenManager != null) {
     mLastContentOffset = mFullscreenManager.getContentOffset();
     mLastVisibleContentOffset = mFullscreenManager.getVisibleContentOffset();
     mFullscreenManager.addListener(this);
   }
   requestRender();
 }
 /**
  * Sets a fullscreen handler.
  *
  * @param fullscreen A fullscreen handler.
  */
 public void setFullscreenHandler(ChromeFullscreenManager fullscreen) {
   mFullscreenManager = fullscreen;
   if (mFullscreenManager != null) {
     mLastContentOffset = mFullscreenManager.getContentOffset();
     mLastVisibleContentOffset = mFullscreenManager.getVisibleContentOffset();
     mFullscreenManager.addListener(this);
   }
   propagateViewportToLayouts(getWidth(), getHeight());
 }
  /**
   * 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
 public boolean onTouchEvent(MotionEvent e) {
   if (mFullscreenManager != null) mFullscreenManager.onMotionEvent(e);
   if (mFullscreenTouchEvent) return true;
   boolean consumed = mLayoutManager != null && mLayoutManager.onTouchEvent(e);
   setContentViewMotionEventOffsets(e, true);
   return consumed;
 }
  @Override
  public boolean onInterceptTouchEvent(MotionEvent e) {
    super.onInterceptTouchEvent(e);

    if (mLayoutManager == null) return false;

    mFullscreenTouchEvent = false;
    if (mFullscreenManager != null
        && mFullscreenManager.onInterceptMotionEvent(e)
        && !mEnableCompositorTabStrip) {
      // Don't eat the event if the new tab strip is enabled.
      mFullscreenTouchEvent = true;
      return true;
    }

    setContentViewMotionEventOffsets(e, false);
    return mLayoutManager.onInterceptTouchEvent(e, mIsKeyboardShowing);
  }
  private void updateContentOverlayVisibility(boolean show) {
    if (mView == null) return;

    sCachedCVCList.clear();
    if (mLayoutManager != null) {
      mLayoutManager.getActiveLayout().getAllContentViewCores(sCachedCVCList);
    }
    if (show) {
      if (mView.getParent() != this) {
        // Make sure the view isn't a child of something else before we attempt to add it.
        if (mView.getParent() != null && mView.getParent() instanceof ViewGroup) {
          ((ViewGroup) mView.getParent()).removeView(mView);
        }

        for (int i = 0; i < sCachedCVCList.size(); i++) {
          ContentViewCore content = sCachedCVCList.get(i);
          assert content.isAlive();
          content.getContainerView().setVisibility(View.VISIBLE);
          if (mFullscreenManager != null) {
            mFullscreenManager.updateContentViewViewportSize(content);
          }
        }

        FrameLayout.LayoutParams layoutParams =
            new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
        if (mView.getLayoutParams() instanceof MarginLayoutParams) {
          MarginLayoutParams existingLayoutParams = (MarginLayoutParams) mView.getLayoutParams();
          layoutParams.leftMargin = existingLayoutParams.leftMargin;
          layoutParams.rightMargin = existingLayoutParams.rightMargin;
          layoutParams.topMargin = existingLayoutParams.topMargin;
          layoutParams.bottomMargin = existingLayoutParams.bottomMargin;
        }
        addView(mView, layoutParams);

        setFocusable(false);
        setFocusableInTouchMode(false);

        // Claim focus for the new view unless the user is currently using the URL bar.
        if (mUrlBar == null || !mUrlBar.hasFocus()) mView.requestFocus();
      }
    } else {
      if (mView.getParent() == this) {
        setFocusable(true);
        setFocusableInTouchMode(true);

        for (int i = 0; i < sCachedCVCList.size(); i++) {
          ContentViewCore content = sCachedCVCList.get(i);
          if (content.isAlive()) content.getContainerView().setVisibility(View.INVISIBLE);
        }

        if (hasFocus()) {
          InputMethodManager manager =
              (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
          if (manager.isActive(this)) {
            manager.hideSoftInputFromWindow(getWindowToken(), 0, null);
          }
        }
        removeView(mView);
      }
    }
    sCachedCVCList.clear();
  }
 @Override
 public int getTopControlsHeightPixels() {
   return mFullscreenManager != null ? mFullscreenManager.getTopControlsHeight() : 0;
 }
 @Override
 public boolean areTopControlsPermanentlyHidden() {
   return mFullscreenManager != null && mFullscreenManager.areTopControlsPermanentlyHidden();
 }
 /** Called whenever the host activity is stopped. */
 public void onStop() {
   if (mFullscreenManager != null) mFullscreenManager.removeListener(this);
 }