Bug 911828 - Treat clicks on SearchEngineRows differently than clicks on TwoLinePageRows in BrowserSearch. r=bnicholson
authorMargaret Leibovic <margaret.leibovic@gmail.com>
Wed, 04 Sep 2013 15:10:13 -0700
changeset 146325 dedfb60795aab1b72cf6264e2d1bd3f1011fba70
parent 146324 41539c7111e0cebc2e0e8a2c66b4d5c2410ff3ce
child 146326 b8a5df4364044fc83529005d87e798b6c9e0392e
push id25252
push usercbook@mozilla.com
push dateTue, 10 Sep 2013 08:27:30 +0000
treeherdermozilla-central@9f9733d4c20e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbnicholson
bugs911828
milestone26.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 911828 - Treat clicks on SearchEngineRows differently than clicks on TwoLinePageRows in BrowserSearch. r=bnicholson
mobile/android/base/home/BrowserSearch.java
mobile/android/base/home/SearchEngineRow.java
--- a/mobile/android/base/home/BrowserSearch.java
+++ b/mobile/android/base/home/BrowserSearch.java
@@ -224,32 +224,43 @@ public class BrowserSearch extends HomeF
 
     @Override
     public void onViewCreated(View view, Bundle savedInstanceState) {
         super.onViewCreated(view, savedInstanceState);
 
         mList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
             @Override
             public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
-                // Account for the search engines
+                // Perform the user-entered search if the user clicks on a search engine row.
+                // This row will be disabled if suggestions (in addition to the user-entered term) are showing.
+                if (view instanceof SearchEngineRow) {
+                    ((SearchEngineRow) view).performUserEnteredSearch();
+                    return;
+                }
+
+                // Account for the search engine rows.
                 position -= getSuggestEngineCount();
                 final Cursor c = mAdapter.getCursor(position);
                 final String url = c.getString(c.getColumnIndexOrThrow(URLColumns.URL));
 
                 // This item is a TwoLinePageRow, so we allow switch-to-tab.
                 mUrlOpenListener.onUrlOpen(url, EnumSet.of(OnUrlOpenListener.Flags.ALLOW_SWITCH_TO_TAB));
             }
         });
 
         mList.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
             @Override
             public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
-                // Account for the search engines
+                // Don't do anything when the user long-clicks on a search engine row.
+                if (view instanceof SearchEngineRow) {
+                    return true;
+                }
+
+                // Account for the search engine rows.
                 position -= getSuggestEngineCount();
-
                 return mList.onItemLongClick(parent, view, position, id);
             }
         });
 
         final ListSelectionListener listener = new ListSelectionListener();
         mList.setOnItemSelectedListener(listener);
         mList.setOnFocusChangeListener(listener);
 
--- a/mobile/android/base/home/SearchEngineRow.java
+++ b/mobile/android/base/home/SearchEngineRow.java
@@ -106,41 +106,16 @@ class SearchEngineRow extends AnimatedHe
         mSuggestionView = (FlowLayout) findViewById(R.id.suggestion_layout);
         mIconView = (FaviconView) findViewById(R.id.suggestion_icon);
 
         // User-entered search term is first suggestion
         mUserEnteredView = (LinearLayout) findViewById(R.id.suggestion_user_entered);
         mUserEnteredView.setOnClickListener(mClickListener);
 
         mUserEnteredTextView = (TextView) findViewById(R.id.suggestion_text);
-
-        // Handle clicks on this row that don't happen on individual suggestion views.
-        setOnClickListener(new OnClickListener() {
-            @Override
-            public void onClick(View v) {
-                // Don't do anything if we are showing suggestions.
-                if (mSearchEngine.suggestions.size() > 0) {
-                    return;
-                }
-
-                // Otherwise, perform a search for the user entered term.
-                String searchTerm = getSuggestionTextFromView(mUserEnteredView);
-                if (mSearchListener != null) {
-                    mSearchListener.onSearch(mSearchEngine.name, searchTerm);
-                }
-            }
-        });
-
-        // Intercept long clicks to avoid trying to show a context menu.
-        setOnLongClickListener(new OnLongClickListener() {
-            @Override
-            public boolean onLongClick(View v) {
-                return true;
-            }
-        });
     }
 
     private void setDescriptionOnSuggestion(View v, String suggestion) {
         v.setContentDescription(getResources().getString(R.string.suggestion_for_engine,
                                                          mSearchEngine.name, suggestion));
     }
 
     private String getSuggestionTextFromView(View v) {
@@ -149,16 +124,26 @@ class SearchEngineRow extends AnimatedHe
     }
 
     private void setSuggestionOnView(View v, String suggestion) {
         final TextView suggestionText = (TextView) v.findViewById(R.id.suggestion_text);
         suggestionText.setText(suggestion);
         setDescriptionOnSuggestion(suggestionText, suggestion);
     }
 
+    /**
+     * Perform a search for the user-entered term.
+     */
+    public void performUserEnteredSearch() {
+        String searchTerm = getSuggestionTextFromView(mUserEnteredView);
+        if (mSearchListener != null) {
+            mSearchListener.onSearch(mSearchEngine.name, searchTerm);
+        }
+    }
+
     public void setSearchTerm(String searchTerm) {
         mUserEnteredTextView.setText(searchTerm);
 
         // mSearchEngine is not set in the first call to this method; the content description
         // is instead initially set in updateFromSearchEngine.
         if (mSearchEngine != null) {
             setDescriptionOnSuggestion(mUserEnteredTextView, searchTerm);
         }