зеркало из https://github.com/mozilla/gecko-dev.git
Bug 748469 - (Part 1) Move FormAssistPopup viewport math to Java. r=kats
This commit is contained in:
Родитель
a678d5982d
Коммит
51e346166d
|
@ -6,6 +6,7 @@
|
|||
package org.mozilla.gecko;
|
||||
|
||||
import org.mozilla.gecko.gfx.FloatSize;
|
||||
import org.mozilla.gecko.gfx.ImmutableViewportMetrics;
|
||||
import org.mozilla.gecko.util.GeckoEventListener;
|
||||
|
||||
import org.json.JSONArray;
|
||||
|
@ -99,24 +100,22 @@ public class FormAssistPopup extends RelativeLayout implements GeckoEventListene
|
|||
|
||||
private void handleAutoCompleteMessage(JSONObject message) throws JSONException {
|
||||
final JSONArray suggestions = message.getJSONArray("suggestions");
|
||||
final JSONArray rect = message.getJSONArray("rect");
|
||||
final double zoom = message.getDouble("zoom");
|
||||
final JSONObject rect = message.getJSONObject("rect");
|
||||
GeckoApp.mAppContext.mMainHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
showAutoCompleteSuggestions(suggestions, rect, zoom);
|
||||
showAutoCompleteSuggestions(suggestions, rect);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void handleValidationMessage(JSONObject message) throws JSONException {
|
||||
final String validationMessage = message.getString("validationMessage");
|
||||
final JSONArray rect = message.getJSONArray("rect");
|
||||
final double zoom = message.getDouble("zoom");
|
||||
final JSONObject rect = message.getJSONObject("rect");
|
||||
GeckoApp.mAppContext.mMainHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
showValidationMessage(validationMessage, rect, zoom);
|
||||
showValidationMessage(validationMessage, rect);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -130,7 +129,7 @@ public class FormAssistPopup extends RelativeLayout implements GeckoEventListene
|
|||
});
|
||||
}
|
||||
|
||||
private void showAutoCompleteSuggestions(JSONArray suggestions, JSONArray rect, double zoom) {
|
||||
private void showAutoCompleteSuggestions(JSONArray suggestions, JSONObject rect) {
|
||||
if (mAutoCompleteList == null) {
|
||||
LayoutInflater inflater = LayoutInflater.from(mContext);
|
||||
mAutoCompleteList = (ListView) inflater.inflate(R.layout.autocomplete_list, null);
|
||||
|
@ -154,10 +153,10 @@ public class FormAssistPopup extends RelativeLayout implements GeckoEventListene
|
|||
adapter.populateSuggestionsList(suggestions);
|
||||
mAutoCompleteList.setAdapter(adapter);
|
||||
|
||||
positionAndShowPopup(rect, zoom, true);
|
||||
positionAndShowPopup(rect, true);
|
||||
}
|
||||
|
||||
private void showValidationMessage(String validationMessage, JSONArray rect, double zoom) {
|
||||
private void showValidationMessage(String validationMessage, JSONObject rect) {
|
||||
if (mValidationMessage == null) {
|
||||
LayoutInflater inflater = LayoutInflater.from(mContext);
|
||||
mValidationMessage = (RelativeLayout) inflater.inflate(R.layout.validation_message, null);
|
||||
|
@ -182,11 +181,11 @@ public class FormAssistPopup extends RelativeLayout implements GeckoEventListene
|
|||
// We need to set the text as selected for the marquee text to work.
|
||||
mValidationMessageText.setSelected(true);
|
||||
|
||||
positionAndShowPopup(rect, zoom, false);
|
||||
positionAndShowPopup(rect, false);
|
||||
}
|
||||
|
||||
// Returns true if the popup is successfully shown, false otherwise
|
||||
private boolean positionAndShowPopup(JSONArray rect, double zoom, boolean isAutoComplete) {
|
||||
private boolean positionAndShowPopup(JSONObject rect, boolean isAutoComplete) {
|
||||
// Don't show the form assist popup when using fullscreen VKB
|
||||
InputMethodManager imm =
|
||||
(InputMethodManager) GeckoApp.mAppContext.getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
|
@ -211,6 +210,9 @@ public class FormAssistPopup extends RelativeLayout implements GeckoEventListene
|
|||
sValidationMessageHeight = (int) (res.getDimension(R.dimen.validation_message_height));
|
||||
}
|
||||
|
||||
ImmutableViewportMetrics viewportMetrics = GeckoApp.mAppContext.getLayerView().getViewportMetrics();
|
||||
float zoom = viewportMetrics.zoomFactor;
|
||||
|
||||
// These values correspond to the input box for which we want to
|
||||
// display the FormAssistPopup.
|
||||
int left = 0;
|
||||
|
@ -219,16 +221,16 @@ public class FormAssistPopup extends RelativeLayout implements GeckoEventListene
|
|||
int height = 0;
|
||||
|
||||
try {
|
||||
left = (int) (rect.getDouble(0) * zoom);
|
||||
top = (int) (rect.getDouble(1) * zoom);
|
||||
width = (int) (rect.getDouble(2) * zoom);
|
||||
height = (int) (rect.getDouble(3) * zoom);
|
||||
left = (int) (rect.getDouble("x") * zoom - viewportMetrics.viewportRectLeft);
|
||||
top = (int) (rect.getDouble("y") * zoom - viewportMetrics.viewportRectTop);
|
||||
width = (int) (rect.getDouble("w") * zoom);
|
||||
height = (int) (rect.getDouble("h") * zoom);
|
||||
} catch (JSONException e) { }
|
||||
|
||||
int popupWidth = RelativeLayout.LayoutParams.FILL_PARENT;
|
||||
int popupLeft = left < 0 ? 0 : left;
|
||||
|
||||
FloatSize viewport = GeckoApp.mAppContext.getLayerView().getViewportMetrics().getSize();
|
||||
FloatSize viewport = viewportMetrics.getSize();
|
||||
|
||||
// For autocomplete suggestions, if the input is smaller than the screen-width,
|
||||
// shrink the popup's width. Otherwise, keep it as FILL_PARENT.
|
||||
|
|
|
@ -5178,18 +5178,6 @@ var FormAssistant = {
|
|||
return suggestions;
|
||||
},
|
||||
|
||||
// Gets the element position data necessary for the Java UI to position
|
||||
// the form assist popup.
|
||||
_getElementPositionData: function _getElementPositionData(aElement) {
|
||||
let rect = ElementTouchHelper.getBoundingContentRect(aElement);
|
||||
let viewport = BrowserApp.selectedTab.getViewport();
|
||||
|
||||
return { rect: [rect.x - (viewport.x / viewport.zoom),
|
||||
rect.y - (viewport.y / viewport.zoom),
|
||||
rect.w, rect.h],
|
||||
zoom: viewport.zoom }
|
||||
},
|
||||
|
||||
// Retrieves autocomplete suggestions for an element from the form autocomplete service
|
||||
// and sends the suggestions to the Java UI, along with element position data.
|
||||
// Returns true if there are suggestions to show, false otherwise.
|
||||
|
@ -5214,12 +5202,10 @@ var FormAssistant = {
|
|||
if (!suggestions.length)
|
||||
return false;
|
||||
|
||||
let positionData = this._getElementPositionData(aElement);
|
||||
sendMessageToJava({
|
||||
type: "FormAssist:AutoComplete",
|
||||
suggestions: suggestions,
|
||||
rect: positionData.rect,
|
||||
zoom: positionData.zoom
|
||||
rect: ElementTouchHelper.getBoundingContentRect(aElement)
|
||||
});
|
||||
|
||||
// Keep track of input element so we can fill it in if the user
|
||||
|
@ -5249,12 +5235,10 @@ var FormAssistant = {
|
|||
if (!this._isValidateable(aElement))
|
||||
return false;
|
||||
|
||||
let positionData = this._getElementPositionData(aElement);
|
||||
sendMessageToJava({
|
||||
type: "FormAssist:ValidationMessage",
|
||||
validationMessage: aElement.validationMessage,
|
||||
rect: positionData.rect,
|
||||
zoom: positionData.zoom
|
||||
rect: ElementTouchHelper.getBoundingContentRect(aElement)
|
||||
});
|
||||
|
||||
return true;
|
||||
|
|
Загрузка…
Ссылка в новой задаче