зеркало из https://github.com/mozilla/gecko-dev.git
Bug 896764 - Initially populate Find in Page string with current text selection, r=margaret
This commit is contained in:
Родитель
9b8f2cd83e
Коммит
1fa65593c1
|
@ -713,6 +713,11 @@ abstract public class BrowserApp extends GeckoApp
|
|||
if (mBrowserToolbar != null)
|
||||
mBrowserToolbar.onDestroy();
|
||||
|
||||
if (mFindInPageBar != null) {
|
||||
mFindInPageBar.onDestroy();
|
||||
mFindInPageBar = null;
|
||||
}
|
||||
|
||||
if (mSharedPreferencesHelper != null) {
|
||||
mSharedPreferencesHelper.uninit();
|
||||
mSharedPreferencesHelper = null;
|
||||
|
|
|
@ -4,8 +4,14 @@
|
|||
|
||||
package org.mozilla.gecko;
|
||||
|
||||
import org.mozilla.gecko.util.GeckoEventListener;
|
||||
import org.mozilla.gecko.util.ThreadUtils;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import android.content.Context;
|
||||
import android.text.Editable;
|
||||
import android.text.TextUtils;
|
||||
import android.text.TextWatcher;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.KeyEvent;
|
||||
|
@ -14,8 +20,8 @@ import android.view.View;
|
|||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
public class FindInPageBar extends LinearLayout implements TextWatcher, View.OnClickListener {
|
||||
private static final String LOGTAG = "GeckoFindInPagePopup";
|
||||
public class FindInPageBar extends LinearLayout implements TextWatcher, View.OnClickListener, GeckoEventListener {
|
||||
private static final String REQUEST_ID = "FindInPageBar";
|
||||
|
||||
private final Context mContext;
|
||||
private CustomEditText mFindText;
|
||||
|
@ -53,6 +59,7 @@ public class FindInPageBar extends LinearLayout implements TextWatcher, View.OnC
|
|||
});
|
||||
|
||||
mInflated = true;
|
||||
GeckoAppShell.getEventDispatcher().registerEventListener("SelectedText:Data", this);
|
||||
}
|
||||
|
||||
public void show() {
|
||||
|
@ -62,21 +69,8 @@ public class FindInPageBar extends LinearLayout implements TextWatcher, View.OnC
|
|||
setVisibility(VISIBLE);
|
||||
mFindText.requestFocus();
|
||||
|
||||
// Show the virtual keyboard.
|
||||
if (mFindText.hasWindowFocus()) {
|
||||
getInputMethodManager(mFindText).showSoftInput(mFindText, 0);
|
||||
} else {
|
||||
// showSoftInput won't work until after the window is focused.
|
||||
mFindText.setOnWindowFocusChangeListener(new CustomEditText.OnWindowFocusChangeListener() {
|
||||
@Override
|
||||
public void onWindowFocusChanged(boolean hasFocus) {
|
||||
if (!hasFocus)
|
||||
return;
|
||||
mFindText.setOnWindowFocusChangeListener(null);
|
||||
getInputMethodManager(mFindText).showSoftInput(mFindText, 0);
|
||||
}
|
||||
});
|
||||
}
|
||||
// handleMessage() receives response message and determines initial state of softInput
|
||||
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("SelectedText:Get", REQUEST_ID));
|
||||
}
|
||||
|
||||
public void hide() {
|
||||
|
@ -90,6 +84,10 @@ public class FindInPageBar extends LinearLayout implements TextWatcher, View.OnC
|
|||
return (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
}
|
||||
|
||||
public void onDestroy() {
|
||||
GeckoAppShell.getEventDispatcher().unregisterEventListener("SelectedText:Data", this);
|
||||
}
|
||||
|
||||
// TextWatcher implementation
|
||||
|
||||
@Override
|
||||
|
@ -125,4 +123,44 @@ public class FindInPageBar extends LinearLayout implements TextWatcher, View.OnC
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// GeckoEventListener implementation
|
||||
|
||||
@Override
|
||||
public void handleMessage(String event, JSONObject message) {
|
||||
if (!event.equals("SelectedText:Data") || !REQUEST_ID.equals(message.optString("requestId"))) {
|
||||
return;
|
||||
}
|
||||
|
||||
final String text = message.optString("text");
|
||||
|
||||
// Populate an initial find string, virtual keyboard not required.
|
||||
if (!TextUtils.isEmpty(text)) {
|
||||
// Populate initial selection
|
||||
ThreadUtils.postToUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mFindText.setText(text);
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// Show the virtual keyboard.
|
||||
if (mFindText.hasWindowFocus()) {
|
||||
getInputMethodManager(mFindText).showSoftInput(mFindText, 0);
|
||||
} else {
|
||||
// showSoftInput won't work until after the window is focused.
|
||||
mFindText.setOnWindowFocusChangeListener(new CustomEditText.OnWindowFocusChangeListener() {
|
||||
@Override
|
||||
public void onWindowFocusChanged(boolean hasFocus) {
|
||||
if (!hasFocus)
|
||||
return;
|
||||
|
||||
mFindText.setOnWindowFocusChangeListener(null);
|
||||
getInputMethodManager(mFindText).showSoftInput(mFindText, 0);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -237,7 +237,10 @@ var SelectionHandler = {
|
|||
return this._contentWindow.getSelection();
|
||||
},
|
||||
|
||||
_getSelectedText: function sh_getSelectedText() {
|
||||
getSelectedText: function sh_getSelectedText() {
|
||||
if (!this._contentWindow)
|
||||
return "";
|
||||
|
||||
let selection = this._getSelection();
|
||||
if (selection)
|
||||
return selection.toString().trim();
|
||||
|
@ -373,7 +376,7 @@ var SelectionHandler = {
|
|||
},
|
||||
|
||||
copySelection: function sh_copySelection() {
|
||||
let selectedText = this._getSelectedText();
|
||||
let selectedText = this.getSelectedText();
|
||||
if (selectedText.length) {
|
||||
let clipboard = Cc["@mozilla.org/widget/clipboardhelper;1"].getService(Ci.nsIClipboardHelper);
|
||||
clipboard.copyString(selectedText, this._contentWindow.document);
|
||||
|
@ -383,7 +386,7 @@ var SelectionHandler = {
|
|||
},
|
||||
|
||||
shareSelection: function sh_shareSelection() {
|
||||
let selectedText = this._getSelectedText();
|
||||
let selectedText = this.getSelectedText();
|
||||
if (selectedText.length) {
|
||||
sendMessageToJava({
|
||||
type: "Share:Text",
|
||||
|
|
|
@ -295,6 +295,7 @@ var BrowserApp = {
|
|||
Services.obs.addObserver(this, "FormHistory:Init", false);
|
||||
Services.obs.addObserver(this, "gather-telemetry", false);
|
||||
Services.obs.addObserver(this, "keyword-search", false);
|
||||
Services.obs.addObserver(this, "SelectedText:Get", false);
|
||||
|
||||
Services.obs.addObserver(this, "sessionstore-state-purge-complete", false);
|
||||
|
||||
|
@ -1442,6 +1443,14 @@ var BrowserApp = {
|
|||
});
|
||||
break;
|
||||
|
||||
case "SelectedText:Get":
|
||||
sendMessageToJava({
|
||||
type: "SelectedText:Data",
|
||||
requestId: aData,
|
||||
text: SelectionHandler.getSelectedText()
|
||||
});
|
||||
break;
|
||||
|
||||
case "Browser:Quit":
|
||||
this.quit();
|
||||
break;
|
||||
|
|
Загрузка…
Ссылка в новой задаче