Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1844)

Unified Diff: content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java

Issue 2779033004: [Android] Focus/Blur contents when window focus changes (Closed)
Patch Set: Use pause/resume instead of WindowFocusChanged Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/test/data/android/content_view_focus/content_view_blur_focus.html ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java
diff --git a/content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java b/content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java
index 445312965ac5a6be50d33a5e9662be89582bf1ad..6cae0306e6b02cee2884e9b011fe82d609bb6d30 100644
--- a/content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java
+++ b/content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java
@@ -360,6 +360,8 @@ public class ContentViewCore
// ResultReceiver in the InputMethodService (IME app) gets gc'ed.
private ShowKeyboardResultReceiver mShowKeyboardResultReceiver;
+ private Boolean mHasViewFocus;
+
// The list of observers that are notified when ContentViewCore changes its WindowAndroid.
private final ObserverList<WindowAndroidChangedObserver> mWindowAndroidChangedObservers;
@@ -1314,6 +1316,24 @@ public class ContentViewCore
}
/**
+ * When the activity pauses, the content should lose focus.
+ * TODO(mthiesse): See crbug.com/686232 for context. Desktop platforms use keyboard focus to
+ * trigger blur/focus, and the equivalent to this on Android is Window focus. However, we don't
+ * use Window focus because of the complexity around popups stealing Window focus.
+ */
+ public void onPause() {
+ onFocusChanged(false, true);
+ }
+
+ /**
+ * When the activity resumes, the View#onFocusChanged may not be called, so we should restore
+ * the View focus state.
+ */
+ public void onResume() {
+ onFocusChanged(getContainerView().hasFocus(), true);
+ }
+
+ /**
* @see View#onWindowFocusChanged(boolean)
*/
public void onWindowFocusChanged(boolean hasWindowFocus) {
@@ -1326,6 +1346,8 @@ public class ContentViewCore
}
public void onFocusChanged(boolean gainFocus, boolean hideKeyboardOnBlur) {
+ if (mHasViewFocus != null && mHasViewFocus == gainFocus) return;
+ mHasViewFocus = gainFocus;
mImeAdapter.onViewFocusChanged(gainFocus, hideKeyboardOnBlur);
if (mJoystickScrollProvider != null) {
« no previous file with comments | « chrome/test/data/android/content_view_focus/content_view_blur_focus.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698