Skip to content

Commit

Permalink
Fix an NPE in location bar suggestion showing.
Browse files Browse the repository at this point in the history
Ensure the suggestion list container is initialized before attempting
to add things to it.

BUG=565113

Review URL: https://codereview.chromium.org/1516273004

Cr-Commit-Position: refs/heads/master@{#364886}

Review URL: https://codereview.chromium.org/1528693002 .

Cr-Commit-Position: refs/branch-heads/2564@{crosswalk-project#353}
Cr-Branched-From: 1283eca-refs/heads/master@{#359700}
  • Loading branch information
Ted Choc committed Dec 14, 2015
1 parent ed6983c commit 0d208d9
Showing 1 changed file with 28 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1411,7 +1411,11 @@ public void run() {
.addOnLayoutChangeListener(suggestionListResizer);

mSuggestionList = new OmniboxSuggestionsList(getContext());

// Ensure the results container is initialized and add the suggestion list to it.
initOmniboxResultsContainer();
mOmniboxResultsContainer.addView(mSuggestionList);

// Start with visibility GONE to ensure that show() is called. http://crbug.com/517438
mSuggestionList.setVisibility(GONE);
mSuggestionList.setAdapter(mSuggestionListAdapter);
Expand Down Expand Up @@ -2078,28 +2082,32 @@ private ContentViewCore getContentViewCore() {
return currentTab != null ? currentTab.getContentViewCore() : null;
}

private void initOmniboxResultsContainer() {
if (mOmniboxResultsContainer != null) return;

ViewStub overlayStub =
(ViewStub) getRootView().findViewById(R.id.omnibox_results_container_stub);
mOmniboxResultsContainer = (ViewGroup) overlayStub.inflate();
mOmniboxResultsContainer.setBackgroundColor(CONTENT_OVERLAY_COLOR);
// Prevent touch events from propagating down to the chrome view.
mOmniboxResultsContainer.setOnTouchListener(new OnTouchListener() {
@Override
@SuppressLint("ClickableViewAccessibility")
public boolean onTouch(View v, MotionEvent event) {
int action = event.getActionMasked();
if (action == MotionEvent.ACTION_CANCEL
|| action == MotionEvent.ACTION_UP) {
mUrlBar.clearFocus();
updateOmniboxResultsContainerBackground(false);
}
return true;
}
});
}

private void updateOmniboxResultsContainer() {
if (mSuggestionsShown || mUrlHasFocus) {
if (mOmniboxResultsContainer == null) {
ViewStub overlayStub =
(ViewStub) getRootView().findViewById(R.id.omnibox_results_container_stub);
mOmniboxResultsContainer = (ViewGroup) overlayStub.inflate();
mOmniboxResultsContainer.setBackgroundColor(CONTENT_OVERLAY_COLOR);
// Prevent touch events from propagating down to the chrome view.
mOmniboxResultsContainer.setOnTouchListener(new OnTouchListener() {
@Override
@SuppressLint("ClickableViewAccessibility")
public boolean onTouch(View v, MotionEvent event) {
int action = event.getActionMasked();
if (action == MotionEvent.ACTION_CANCEL
|| action == MotionEvent.ACTION_UP) {
mUrlBar.clearFocus();
updateOmniboxResultsContainerBackground(false);
}
return true;
}
});
}
initOmniboxResultsContainer();
updateOmniboxResultsContainerVisibility(true);
} else if (mOmniboxResultsContainer != null) {
updateOmniboxResultsContainerBackground(false);
Expand Down

0 comments on commit 0d208d9

Please sign in to comment.