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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.content.browser; 5 package org.chromium.content.browser;
6 6
7 import android.annotation.SuppressLint; 7 import android.annotation.SuppressLint;
8 import android.annotation.TargetApi; 8 import android.annotation.TargetApi;
9 import android.app.assist.AssistStructure.ViewNode; 9 import android.app.assist.AssistStructure.ViewNode;
10 import android.content.ClipData; 10 import android.content.ClipData;
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 // screen orientation. 353 // screen orientation.
354 private boolean mFullscreenRequiredForOrientationLock = true; 354 private boolean mFullscreenRequiredForOrientationLock = true;
355 355
356 // A ViewAndroidDelegate that delegates to the current container view. 356 // A ViewAndroidDelegate that delegates to the current container view.
357 private ViewAndroidDelegate mViewAndroidDelegate; 357 private ViewAndroidDelegate mViewAndroidDelegate;
358 358
359 // NOTE: This object will not be released by Android framework until the mat ching 359 // NOTE: This object will not be released by Android framework until the mat ching
360 // ResultReceiver in the InputMethodService (IME app) gets gc'ed. 360 // ResultReceiver in the InputMethodService (IME app) gets gc'ed.
361 private ShowKeyboardResultReceiver mShowKeyboardResultReceiver; 361 private ShowKeyboardResultReceiver mShowKeyboardResultReceiver;
362 362
363 private Boolean mHasViewFocus;
364
363 // The list of observers that are notified when ContentViewCore changes its WindowAndroid. 365 // The list of observers that are notified when ContentViewCore changes its WindowAndroid.
364 private final ObserverList<WindowAndroidChangedObserver> mWindowAndroidChang edObservers; 366 private final ObserverList<WindowAndroidChangedObserver> mWindowAndroidChang edObservers;
365 367
366 /** 368 /**
367 * @param webContents The {@link WebContents} to find a {@link ContentViewCo re} of. 369 * @param webContents The {@link WebContents} to find a {@link ContentViewCo re} of.
368 * @return A {@link ContentViewCore} that is connected to {@code webContents} or 370 * @return A {@link ContentViewCore} that is connected to {@code webContents} or
369 * {@code null} if none exists. 371 * {@code null} if none exists.
370 */ 372 */
371 public static ContentViewCore fromWebContents(WebContents webContents) { 373 public static ContentViewCore fromWebContents(WebContents webContents) {
372 return nativeFromWebContentsAndroid(webContents); 374 return nativeFromWebContentsAndroid(webContents);
(...skipping 934 matching lines...) Expand 10 before | Expand all | Expand 10 after
1307 } 1309 }
1308 } 1310 }
1309 1311
1310 private void cancelRequestToScrollFocusedEditableNodeIntoView() { 1312 private void cancelRequestToScrollFocusedEditableNodeIntoView() {
1311 // Zero-ing the rect will prevent |updateAfterSizeChanged()| from 1313 // Zero-ing the rect will prevent |updateAfterSizeChanged()| from
1312 // issuing the delayed form focus event. 1314 // issuing the delayed form focus event.
1313 mFocusPreOSKViewportRect.setEmpty(); 1315 mFocusPreOSKViewportRect.setEmpty();
1314 } 1316 }
1315 1317
1316 /** 1318 /**
1319 * When the activity pauses, the content should lose focus.
1320 * TODO(mthiesse): See crbug.com/686232 for context. Desktop platforms use k eyboard focus to
1321 * trigger blur/focus, and the equivalent to this on Android is Window focus . However, we don't
1322 * use Window focus because of the complexity around popups stealing Window focus.
1323 */
1324 public void onPause() {
1325 onFocusChanged(false, true);
1326 }
1327
1328 /**
1329 * When the activity resumes, the View#onFocusChanged may not be called, so we should restore
1330 * the View focus state.
1331 */
1332 public void onResume() {
1333 onFocusChanged(getContainerView().hasFocus(), true);
1334 }
1335
1336 /**
1317 * @see View#onWindowFocusChanged(boolean) 1337 * @see View#onWindowFocusChanged(boolean)
1318 */ 1338 */
1319 public void onWindowFocusChanged(boolean hasWindowFocus) { 1339 public void onWindowFocusChanged(boolean hasWindowFocus) {
1320 mImeAdapter.onWindowFocusChanged(hasWindowFocus); 1340 mImeAdapter.onWindowFocusChanged(hasWindowFocus);
1321 if (!hasWindowFocus) resetGestureDetection(); 1341 if (!hasWindowFocus) resetGestureDetection();
1322 mSelectionPopupController.onWindowFocusChanged(hasWindowFocus); 1342 mSelectionPopupController.onWindowFocusChanged(hasWindowFocus);
1323 for (mGestureStateListenersIterator.rewind(); mGestureStateListenersIter ator.hasNext();) { 1343 for (mGestureStateListenersIterator.rewind(); mGestureStateListenersIter ator.hasNext();) {
1324 mGestureStateListenersIterator.next().onWindowFocusChanged(hasWindow Focus); 1344 mGestureStateListenersIterator.next().onWindowFocusChanged(hasWindow Focus);
1325 } 1345 }
1326 } 1346 }
1327 1347
1328 public void onFocusChanged(boolean gainFocus, boolean hideKeyboardOnBlur) { 1348 public void onFocusChanged(boolean gainFocus, boolean hideKeyboardOnBlur) {
1349 if (mHasViewFocus != null && mHasViewFocus == gainFocus) return;
1350 mHasViewFocus = gainFocus;
1329 mImeAdapter.onViewFocusChanged(gainFocus, hideKeyboardOnBlur); 1351 mImeAdapter.onViewFocusChanged(gainFocus, hideKeyboardOnBlur);
1330 1352
1331 if (mJoystickScrollProvider != null) { 1353 if (mJoystickScrollProvider != null) {
1332 mJoystickScrollProvider.setEnabled(gainFocus && !isFocusedNodeEditab le()); 1354 mJoystickScrollProvider.setEnabled(gainFocus && !isFocusedNodeEditab le());
1333 } 1355 }
1334 1356
1335 if (gainFocus) { 1357 if (gainFocus) {
1336 restoreSelectionPopupsIfNecessary(); 1358 restoreSelectionPopupsIfNecessary();
1337 } else { 1359 } else {
1338 cancelRequestToScrollFocusedEditableNodeIntoView(); 1360 cancelRequestToScrollFocusedEditableNodeIntoView();
(...skipping 1311 matching lines...) Expand 10 before | Expand all | Expand 10 after
2650 private native void nativeSetTextTrackSettings(long nativeContentViewCoreImp l, 2672 private native void nativeSetTextTrackSettings(long nativeContentViewCoreImp l,
2651 boolean textTracksEnabled, String textTrackBackgroundColor, String t extTrackFontFamily, 2673 boolean textTracksEnabled, String textTrackBackgroundColor, String t extTrackFontFamily,
2652 String textTrackFontStyle, String textTrackFontVariant, String textT rackTextColor, 2674 String textTrackFontStyle, String textTrackFontVariant, String textT rackTextColor,
2653 String textTrackTextShadow, String textTrackTextSize); 2675 String textTrackTextShadow, String textTrackTextSize);
2654 2676
2655 private native void nativeSetBackgroundOpaque(long nativeContentViewCoreImpl , boolean opaque); 2677 private native void nativeSetBackgroundOpaque(long nativeContentViewCoreImpl , boolean opaque);
2656 private native boolean nativeIsTouchDragDropEnabled(long nativeContentViewCo reImpl); 2678 private native boolean nativeIsTouchDragDropEnabled(long nativeContentViewCo reImpl);
2657 private native void nativeOnDragEvent(long nativeContentViewCoreImpl, int ac tion, int x, int y, 2679 private native void nativeOnDragEvent(long nativeContentViewCoreImpl, int ac tion, int x, int y,
2658 int screenX, int screenY, String[] mimeTypes, String content); 2680 int screenX, int screenY, String[] mimeTypes, String content);
2659 } 2681 }
OLDNEW
« 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