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

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

Issue 2752113005: Let ImeAdapterAndroid have the same lifecycle as its Java peer (Closed)
Patch Set: background rwhva Created 3 years, 9 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
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 557 matching lines...) Expand 10 before | Expand all | Expand 10 after
568 assert windowNativePointer != 0; 568 assert windowNativePointer != 0;
569 569
570 final float dipScale = windowAndroid.getDisplay().getDipScale(); 570 final float dipScale = windowAndroid.getDisplay().getDipScale();
571 571
572 mRenderCoordinates.reset(); 572 mRenderCoordinates.reset();
573 mRenderCoordinates.setDeviceScaleFactor(dipScale, windowAndroid.getConte xt()); 573 mRenderCoordinates.setDeviceScaleFactor(dipScale, windowAndroid.getConte xt());
574 574
575 mJoystickScrollProvider = 575 mJoystickScrollProvider =
576 new JoystickScrollProvider(webContents, getContainerView(), wind owAndroid); 576 new JoystickScrollProvider(webContents, getContainerView(), wind owAndroid);
577 577
578 mImeAdapter = createImeAdapter();
578 mNativeContentViewCore = nativeInit(webContents, mViewAndroidDelegate, w indowNativePointer, 579 mNativeContentViewCore = nativeInit(webContents, mViewAndroidDelegate, w indowNativePointer,
579 dipScale, mRetainedJavaScriptObjects); 580 mImeAdapter.getNativePointer(), dipScale, mRetainedJavaScriptObj ects);
580 mWebContents = nativeGetWebContentsAndroid(mNativeContentViewCore); 581 mWebContents = nativeGetWebContentsAndroid(mNativeContentViewCore);
581 582
582 setContainerViewInternals(internalDispatcher); 583 setContainerViewInternals(internalDispatcher);
583 584
584 initPopupZoomer(mContext); 585 initPopupZoomer(mContext);
585 mImeAdapter = createImeAdapter();
586 attachImeAdapter();
587 586
588 mSelectionPopupController = new SelectionPopupController(mContext, windo wAndroid, 587 mSelectionPopupController = new SelectionPopupController(mContext, windo wAndroid,
589 webContents, viewDelegate.getContainerView(), mRenderCoordinates , mImeAdapter); 588 webContents, viewDelegate.getContainerView(), mRenderCoordinates );
590 mSelectionPopupController.setCallback(ActionModeCallbackHelper.EMPTY_CAL LBACK); 589 mSelectionPopupController.setCallback(ActionModeCallbackHelper.EMPTY_CAL LBACK);
591 mSelectionPopupController.setContainerView(getContainerView()); 590 mSelectionPopupController.setContainerView(getContainerView());
592 591
593 mWebContentsObserver = new ContentViewWebContentsObserver(this); 592 mWebContentsObserver = new ContentViewWebContentsObserver(this);
594 593
595 mShouldRequestUnbufferedDispatch = Build.VERSION.SDK_INT >= Build.VERSIO N_CODES.LOLLIPOP 594 mShouldRequestUnbufferedDispatch = Build.VERSION.SDK_INT >= Build.VERSIO N_CODES.LOLLIPOP
596 && ContentFeatureList.isEnabled(ContentFeatureList.REQUEST_UNBUF FERED_DISPATCH); 595 && ContentFeatureList.isEnabled(ContentFeatureList.REQUEST_UNBUF FERED_DISPATCH);
597 } 596 }
598 597
599 /** 598 /**
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
777 * onDetachedFromWindow() which is guaranteed to be called in Android WebVie w. 776 * onDetachedFromWindow() which is guaranteed to be called in Android WebVie w.
778 */ 777 */
779 public void destroy() { 778 public void destroy() {
780 removeDisplayAndroidObserver(); 779 removeDisplayAndroidObserver();
781 if (mNativeContentViewCore != 0) { 780 if (mNativeContentViewCore != 0) {
782 nativeOnJavaContentViewCoreDestroyed(mNativeContentViewCore); 781 nativeOnJavaContentViewCoreDestroyed(mNativeContentViewCore);
783 } 782 }
784 mWebContentsObserver.destroy(); 783 mWebContentsObserver.destroy();
785 mWebContentsObserver = null; 784 mWebContentsObserver = null;
786 mImeAdapter.resetAndHideKeyboard(); 785 mImeAdapter.resetAndHideKeyboard();
786
boliu 2017/03/24 17:13:16 empty line change..
Jinsuk Kim 2017/03/27 03:19:33 Done.
787 // TODO(igsolla): address TODO in ContentViewClient because ContentViewC lient is not 787 // TODO(igsolla): address TODO in ContentViewClient because ContentViewC lient is not
788 // currently a real Null Object. 788 // currently a real Null Object.
789 // 789 //
790 // Instead of deleting the client we use the Null Object pattern to avoi d null checks 790 // Instead of deleting the client we use the Null Object pattern to avoi d null checks
791 // in this class. 791 // in this class.
792 mContentViewClient = new ContentViewClient(); 792 mContentViewClient = new ContentViewClient();
793 mWebContents = null; 793 mWebContents = null;
794 mNativeContentViewCore = 0; 794 mNativeContentViewCore = 0;
795 mJavaScriptInterfaces.clear(); 795 mJavaScriptInterfaces.clear();
796 mRetainedJavaScriptObjects.clear(); 796 mRetainedJavaScriptObjects.clear();
(...skipping 948 matching lines...) Expand 10 before | Expand all | Expand 10 after
1745 } 1745 }
1746 1746
1747 mImeAdapter.onUpdateFrameInfo(mRenderCoordinates, hasInsertionMarker, 1747 mImeAdapter.onUpdateFrameInfo(mRenderCoordinates, hasInsertionMarker,
1748 isInsertionMarkerVisible, insertionMarkerHorizontal, insertionMa rkerTop, 1748 isInsertionMarkerVisible, insertionMarkerHorizontal, insertionMa rkerTop,
1749 insertionMarkerBottom); 1749 insertionMarkerBottom);
1750 1750
1751 TraceEvent.end("ContentViewCore:updateFrameInfo"); 1751 TraceEvent.end("ContentViewCore:updateFrameInfo");
1752 } 1752 }
1753 1753
1754 @CalledByNative 1754 @CalledByNative
1755 private void updateImeAdapter(long nativeImeAdapterAndroid, int textInputTyp e, 1755 private void updateImeAdapter(int textInputType, int textInputFlags, int tex tInputMode,
1756 int textInputFlags, int textInputMode, String text, int selectionSta rt, 1756 String text, int selectionStart, int selectionEnd, int compositionSt art,
1757 int selectionEnd, int compositionStart, int compositionEnd, boolean showImeIfNeeded, 1757 int compositionEnd, boolean showImeIfNeeded, boolean replyToRequest) {
1758 boolean replyToRequest) {
1759 try { 1758 try {
1760 TraceEvent.begin("ContentViewCore.updateImeAdapter"); 1759 TraceEvent.begin("ContentViewCore.updateImeAdapter");
1761 boolean focusedNodeEditable = (textInputType != TextInputType.NONE); 1760 boolean focusedNodeEditable = (textInputType != TextInputType.NONE);
1762 boolean focusedNodeIsPassword = (textInputType == TextInputType.PASS WORD); 1761 boolean focusedNodeIsPassword = (textInputType == TextInputType.PASS WORD);
1763 1762
1764 mImeAdapter.attach(nativeImeAdapterAndroid);
1765 mImeAdapter.updateState(textInputType, textInputFlags, textInputMode , showImeIfNeeded, 1763 mImeAdapter.updateState(textInputType, textInputFlags, textInputMode , showImeIfNeeded,
1766 text, selectionStart, selectionEnd, compositionStart, compos itionEnd, 1764 text, selectionStart, selectionEnd, compositionStart, compos itionEnd,
1767 replyToRequest); 1765 replyToRequest);
1768 1766
1769 boolean editableToggled = (focusedNodeEditable != isFocusedNodeEdita ble()); 1767 boolean editableToggled = (focusedNodeEditable != isFocusedNodeEdita ble());
1770 mSelectionPopupController.updateSelectionState(focusedNodeEditable, 1768 mSelectionPopupController.updateSelectionState(focusedNodeEditable,
1771 focusedNodeIsPassword); 1769 focusedNodeIsPassword);
1772 if (editableToggled) { 1770 if (editableToggled) {
1773 mJoystickScrollProvider.setEnabled(!focusedNodeEditable); 1771 mJoystickScrollProvider.setEnabled(!focusedNodeEditable);
1774 getContentViewClient().onFocusedNodeEditabilityChanged(focusedNo deEditable); 1772 getContentViewClient().onFocusedNodeEditabilityChanged(focusedNo deEditable);
1775 } 1773 }
1776 } finally { 1774 } finally {
1777 TraceEvent.end("ContentViewCore.updateImeAdapter"); 1775 TraceEvent.end("ContentViewCore.updateImeAdapter");
1778 } 1776 }
1779 } 1777 }
1780 1778
1781 @CalledByNative
1782 private void forceUpdateImeAdapter(long nativeImeAdapterAndroid) {
1783 mImeAdapter.attach(nativeImeAdapterAndroid);
1784 }
1785
1786 /** 1779 /**
1787 * Called (from native) when the <select> popup needs to be shown. 1780 * Called (from native) when the <select> popup needs to be shown.
1788 * @param anchorView View anchored for popup. 1781 * @param anchorView View anchored for popup.
1789 * @param nativeSelectPopupSourceFrame The native RenderFrameHost that owns the popup. 1782 * @param nativeSelectPopupSourceFrame The native RenderFrameHost that owns the popup.
1790 * @param items Items to show. 1783 * @param items Items to show.
1791 * @param enabled POPUP_ITEM_TYPEs for items. 1784 * @param enabled POPUP_ITEM_TYPEs for items.
1792 * @param multiple Whether the popup menu should support multi-select . 1785 * @param multiple Whether the popup menu should support multi-select .
1793 * @param selectedIndices Indices of selected items. 1786 * @param selectedIndices Indices of selected items.
1794 */ 1787 */
1795 @SuppressWarnings("unused") 1788 @SuppressWarnings("unused")
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
1886 } 1879 }
1887 1880
1888 private boolean canPaste() { 1881 private boolean canPaste() {
1889 return ((ClipboardManager) mContext.getSystemService( 1882 return ((ClipboardManager) mContext.getSystemService(
1890 Context.CLIPBOARD_SERVICE)).hasPrimaryClip(); 1883 Context.CLIPBOARD_SERVICE)).hasPrimaryClip();
1891 } 1884 }
1892 1885
1893 @SuppressWarnings("unused") 1886 @SuppressWarnings("unused")
1894 @CalledByNative 1887 @CalledByNative
1895 private void onRenderProcessChange() { 1888 private void onRenderProcessChange() {
1896 attachImeAdapter();
1897 // Immediately sync closed caption settings to the new render process. 1889 // Immediately sync closed caption settings to the new render process.
1898 mSystemCaptioningBridge.syncToListener(this); 1890 mSystemCaptioningBridge.syncToListener(this);
1899 } 1891 }
1900 1892
1901 /** 1893 /**
1902 * Attaches the native ImeAdapter object to the java ImeAdapter to allow com munication via JNI.
1903 */
1904 public void attachImeAdapter() {
1905 if (mImeAdapter != null && mNativeContentViewCore != 0) {
1906 mImeAdapter.attach(nativeGetNativeImeAdapter(mNativeContentViewCore) );
1907 }
1908 }
1909
1910 /**
1911 * @see View#hasFocus() 1894 * @see View#hasFocus()
1912 */ 1895 */
1913 @CalledByNative 1896 @CalledByNative
1914 private boolean hasFocus() { 1897 private boolean hasFocus() {
1915 // If the container view is not focusable, we consider it always focused from 1898 // If the container view is not focusable, we consider it always focused from
1916 // Chromium's point of view. 1899 // Chromium's point of view.
1917 if (!mContainerView.isFocusable()) return true; 1900 if (!mContainerView.isFocusable()) return true;
1918 return mContainerView.hasFocus(); 1901 return mContainerView.hasFocus();
1919 } 1902 }
1920 1903
(...skipping 658 matching lines...) Expand 10 before | Expand all | Expand 10 after
2579 @VisibleForTesting 2562 @VisibleForTesting
2580 public ResultReceiver getNewShowKeyboardReceiver() { 2563 public ResultReceiver getNewShowKeyboardReceiver() {
2581 if (mShowKeyboardResultReceiver == null) { 2564 if (mShowKeyboardResultReceiver == null) {
2582 // Note: the returned object will get leaked by Android framework. 2565 // Note: the returned object will get leaked by Android framework.
2583 mShowKeyboardResultReceiver = new ShowKeyboardResultReceiver(this, n ew Handler()); 2566 mShowKeyboardResultReceiver = new ShowKeyboardResultReceiver(this, n ew Handler());
2584 } 2567 }
2585 return mShowKeyboardResultReceiver; 2568 return mShowKeyboardResultReceiver;
2586 } 2569 }
2587 2570
2588 private native long nativeInit(WebContents webContents, ViewAndroidDelegate viewAndroidDelegate, 2571 private native long nativeInit(WebContents webContents, ViewAndroidDelegate viewAndroidDelegate,
2589 long windowAndroidPtr, float dipScale, HashSet<Object> retainedObjec tSet); 2572 long windowAndroidPtr, long imeAdapterPtr, float dipScale,
2573 HashSet<Object> retainedObjectSet);
2590 private static native ContentViewCore nativeFromWebContentsAndroid(WebConten ts webContents); 2574 private static native ContentViewCore nativeFromWebContentsAndroid(WebConten ts webContents);
2591 2575
2592 private native void nativeUpdateWindowAndroid( 2576 private native void nativeUpdateWindowAndroid(
2593 long nativeContentViewCoreImpl, long windowAndroidPtr); 2577 long nativeContentViewCoreImpl, long windowAndroidPtr);
2594 private native WebContents nativeGetWebContentsAndroid(long nativeContentVie wCoreImpl); 2578 private native WebContents nativeGetWebContentsAndroid(long nativeContentVie wCoreImpl);
2595 private native WindowAndroid nativeGetJavaWindowAndroid(long nativeContentVi ewCoreImpl); 2579 private native WindowAndroid nativeGetJavaWindowAndroid(long nativeContentVi ewCoreImpl);
2596 2580
2597 private native void nativeOnJavaContentViewCoreDestroyed(long nativeContentV iewCoreImpl); 2581 private native void nativeOnJavaContentViewCoreDestroyed(long nativeContentV iewCoreImpl);
2598 2582
2599 private native void nativeSetFocus(long nativeContentViewCoreImpl, boolean f ocused); 2583 private native void nativeSetFocus(long nativeContentViewCoreImpl, boolean f ocused);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
2644 2628
2645 private native void nativeSetDoubleTapSupportEnabled( 2629 private native void nativeSetDoubleTapSupportEnabled(
2646 long nativeContentViewCoreImpl, boolean enabled); 2630 long nativeContentViewCoreImpl, boolean enabled);
2647 2631
2648 private native void nativeSetMultiTouchZoomSupportEnabled( 2632 private native void nativeSetMultiTouchZoomSupportEnabled(
2649 long nativeContentViewCoreImpl, boolean enabled); 2633 long nativeContentViewCoreImpl, boolean enabled);
2650 2634
2651 private native void nativeSelectPopupMenuItems(long nativeContentViewCoreImp l, 2635 private native void nativeSelectPopupMenuItems(long nativeContentViewCoreImp l,
2652 long nativeSelectPopupSourceFrame, int[] indices); 2636 long nativeSelectPopupSourceFrame, int[] indices);
2653 2637
2654
2655 private native long nativeGetNativeImeAdapter(long nativeContentViewCoreImpl );
2656
2657 private native int nativeGetCurrentRenderProcessId(long nativeContentViewCor eImpl); 2638 private native int nativeGetCurrentRenderProcessId(long nativeContentViewCor eImpl);
2658 2639
2659 private native void nativeSetAllowJavascriptInterfacesInspection( 2640 private native void nativeSetAllowJavascriptInterfacesInspection(
2660 long nativeContentViewCoreImpl, boolean allow); 2641 long nativeContentViewCoreImpl, boolean allow);
2661 2642
2662 private native void nativeAddJavascriptInterface(long nativeContentViewCoreI mpl, Object object, 2643 private native void nativeAddJavascriptInterface(long nativeContentViewCoreI mpl, Object object,
2663 String name, Class requiredAnnotation); 2644 String name, Class requiredAnnotation);
2664 2645
2665 private native void nativeRemoveJavascriptInterface(long nativeContentViewCo reImpl, 2646 private native void nativeRemoveJavascriptInterface(long nativeContentViewCo reImpl,
2666 String name); 2647 String name);
2667 2648
2668 private native void nativeWasResized(long nativeContentViewCoreImpl); 2649 private native void nativeWasResized(long nativeContentViewCoreImpl);
2669 2650
2670 private native void nativeSetAccessibilityEnabled( 2651 private native void nativeSetAccessibilityEnabled(
2671 long nativeContentViewCoreImpl, boolean enabled); 2652 long nativeContentViewCoreImpl, boolean enabled);
2672 2653
2673 private native void nativeSetTextTrackSettings(long nativeContentViewCoreImp l, 2654 private native void nativeSetTextTrackSettings(long nativeContentViewCoreImp l,
2674 boolean textTracksEnabled, String textTrackBackgroundColor, String t extTrackFontFamily, 2655 boolean textTracksEnabled, String textTrackBackgroundColor, String t extTrackFontFamily,
2675 String textTrackFontStyle, String textTrackFontVariant, String textT rackTextColor, 2656 String textTrackFontStyle, String textTrackFontVariant, String textT rackTextColor,
2676 String textTrackTextShadow, String textTrackTextSize); 2657 String textTrackTextShadow, String textTrackTextSize);
2677 2658
2678 private native void nativeSetBackgroundOpaque(long nativeContentViewCoreImpl , boolean opaque); 2659 private native void nativeSetBackgroundOpaque(long nativeContentViewCoreImpl , boolean opaque);
2679 private native boolean nativeIsTouchDragDropEnabled(long nativeContentViewCo reImpl); 2660 private native boolean nativeIsTouchDragDropEnabled(long nativeContentViewCo reImpl);
2680 private native void nativeOnDragEvent(long nativeContentViewCoreImpl, int ac tion, int x, int y, 2661 private native void nativeOnDragEvent(long nativeContentViewCoreImpl, int ac tion, int x, int y,
2681 int screenX, int screenY, String[] mimeTypes, String content); 2662 int screenX, int screenY, String[] mimeTypes, String content);
2682 } 2663 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698