Commit 9eb27571 authored by r.ghatage@samsung.com's avatar r.ghatage@samsung.com

Hide PopupZoomer when the container view or window loses focus

Currently there is a method which hides all the popups but call to 
hide PopupZoomer is missing. Added the call to hide PopupZoomer inside 
hidePopups and hiding the zoomer when the view loses focus or the 
window loses focus. Also added unit test code.

BUG=405477

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

Cr-Commit-Position: refs/heads/master@{#291359}
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@291359 0039d316-1c4b-4281-b951-d872f2087c98
parent 0f95b406
......@@ -521,9 +521,7 @@ public class ContentViewCore
new ImeAdapter.ImeAdapterDelegate() {
@Override
public void onImeEvent() {
if (mPopupZoomer.isShowing()) {
mPopupZoomer.hide(true);
}
mPopupZoomer.hide(true);
getContentViewClient().onImeEvent();
hideTextHandles();
}
......@@ -754,6 +752,11 @@ public class ContentViewCore
mPopupZoomer.setOnTapListener(listener);
}
@VisibleForTesting
public void setPopupZoomerForTest(PopupZoomer popupZoomer) {
mPopupZoomer = popupZoomer;
}
/**
* Destroy the internal state of the ContentView. This method may only be
* called after the ContentView has been removed from the view system. No
......@@ -1430,6 +1433,7 @@ public class ContentViewCore
hidePastePopup();
hideSelectPopup();
hideTextHandles();
mPopupZoomer.hide(false);
}
public void hideSelectActionBar() {
......@@ -1623,6 +1627,7 @@ public class ContentViewCore
cancelRequestToScrollFocusedEditableNodeIntoView();
hidePastePopup();
hideTextHandles();
mPopupZoomer.hide(false);
}
if (mNativeContentViewCore != 0) nativeSetFocus(mNativeContentViewCore, gainFocus);
}
......
......@@ -9,18 +9,19 @@ import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.os.SystemClock;
import android.test.InstrumentationTestCase;
import android.test.suitebuilder.annotation.SmallTest;
import android.view.MotionEvent;
import android.view.View;
import org.chromium.base.test.util.Feature;
import org.chromium.content_shell_apk.ContentShellTestBase;
/**
* Tests for PopupZoomer.
*/
public class PopupZoomerTest extends InstrumentationTestCase {
public class PopupZoomerTest extends ContentShellTestBase {
private CustomCanvasPopupZoomer mPopupZoomer;
private ContentViewCore mContentViewCore;
private static class CustomCanvasPopupZoomer extends PopupZoomer {
Canvas mCanvas;
......@@ -74,6 +75,8 @@ public class PopupZoomerTest extends InstrumentationTestCase {
@Override
public void setUp() {
mPopupZoomer = createPopupZoomerForTest(getInstrumentation().getTargetContext());
mContentViewCore = new ContentViewCore(getActivity());
mContentViewCore.setPopupZoomerForTest(mPopupZoomer);
}
@SmallTest
......@@ -172,4 +175,29 @@ public class PopupZoomerTest extends InstrumentationTestCase {
assertEquals(View.VISIBLE, mPopupZoomer.getVisibility());
assertTrue(mPopupZoomer.isShowing());
}
@SmallTest
@Feature({"Navigation"})
public void testHidePopupOnLosingFocus() throws Exception {
mPopupZoomer.setBitmap(
Bitmap.createBitmap(10, 10, Bitmap.Config.ALPHA_8));
mPopupZoomer.show(new Rect(0, 0, 5, 5));
// Wait for the animation to finish.
mPopupZoomer.finishPendingDraws();
// The view should be visible.
assertEquals(View.VISIBLE, mPopupZoomer.getVisibility());
assertTrue(mPopupZoomer.isShowing());
// Simulate losing the focus.
mContentViewCore.onFocusChanged(false);
// Wait for the hide animation to finish.
mPopupZoomer.finishPendingDraws();
// Now that another view has been focused, the view should be invisible.
assertEquals(View.INVISIBLE, mPopupZoomer.getVisibility());
assertFalse(mPopupZoomer.isShowing());
}
}
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