OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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.chrome.browser.omnibox; | 5 package org.chromium.chrome.browser.omnibox; |
6 | 6 |
7 import android.annotation.SuppressLint; | 7 import android.annotation.SuppressLint; |
8 import android.content.Context; | 8 import android.content.Context; |
9 import android.content.DialogInterface; | 9 import android.content.DialogInterface; |
10 import android.content.res.TypedArray; | 10 import android.content.res.TypedArray; |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 } else if ((suggestionType == OmniboxSuggestionType.SEARCH_SUGGEST_P
ERSONALIZED) | 325 } else if ((suggestionType == OmniboxSuggestionType.SEARCH_SUGGEST_P
ERSONALIZED) |
326 || (suggestionType == OmniboxSuggestionType.SEARCH_HISTORY))
{ | 326 || (suggestionType == OmniboxSuggestionType.SEARCH_HISTORY))
{ |
327 // Show history icon for suggestions based on user queries. | 327 // Show history icon for suggestions based on user queries. |
328 suggestionIcon = SUGGESTION_ICON_HISTORY; | 328 suggestionIcon = SUGGESTION_ICON_HISTORY; |
329 } | 329 } |
330 mContentsView.setSuggestionIcon(suggestionIcon, colorsChanged); | 330 mContentsView.setSuggestionIcon(suggestionIcon, colorsChanged); |
331 setRefinable(!sameAsTyped); | 331 setRefinable(!sameAsTyped); |
332 setSuggestedQuery(suggestionItem, false, false, false); | 332 setSuggestedQuery(suggestionItem, false, false, false); |
333 if ((suggestionType == OmniboxSuggestionType.SEARCH_SUGGEST_ENTITY) | 333 if ((suggestionType == OmniboxSuggestionType.SEARCH_SUGGEST_ENTITY) |
334 || (suggestionType == OmniboxSuggestionType.SEARCH_SUGGEST_P
ROFILE)) { | 334 || (suggestionType == OmniboxSuggestionType.SEARCH_SUGGEST_P
ROFILE)) { |
335 showDescriptionLine( | 335 showDescriptionLine(SpannableString.valueOf(mSuggestion.getDescr
iption()), false); |
336 SpannableString.valueOf(mSuggestion.getDescription()), | |
337 getStandardFontColor()); | |
338 } else { | 336 } else { |
339 mContentsView.mTextLine2.setVisibility(INVISIBLE); | 337 mContentsView.mTextLine2.setVisibility(INVISIBLE); |
340 } | 338 } |
341 } | 339 } |
342 } | 340 } |
343 | 341 |
344 private void setRefinable(boolean refinable) { | 342 private void setRefinable(boolean refinable) { |
345 if (refinable) { | 343 if (refinable) { |
346 mRefineView.setVisibility(VISIBLE); | 344 mRefineView.setVisibility(VISIBLE); |
347 mRefineView.setOnClickListener(new OnClickListener() { | 345 mRefineView.setOnClickListener(new OnClickListener() { |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 * Sets (and highlights) the URL text of the second line of the omnibox sugg
estion. | 389 * Sets (and highlights) the URL text of the second line of the omnibox sugg
estion. |
392 * | 390 * |
393 * @param result The suggestion containing the URL. | 391 * @param result The suggestion containing the URL. |
394 * @return Whether the URL was highlighted based on the user query. | 392 * @return Whether the URL was highlighted based on the user query. |
395 */ | 393 */ |
396 private boolean setUrlText(OmniboxResultItem result) { | 394 private boolean setUrlText(OmniboxResultItem result) { |
397 OmniboxSuggestion suggestion = result.getSuggestion(); | 395 OmniboxSuggestion suggestion = result.getSuggestion(); |
398 Spannable str = SpannableString.valueOf(suggestion.getDisplayText()); | 396 Spannable str = SpannableString.valueOf(suggestion.getDisplayText()); |
399 boolean hasMatch = applyHighlightToMatchRegions( | 397 boolean hasMatch = applyHighlightToMatchRegions( |
400 str, suggestion.getDisplayTextClassifications()); | 398 str, suggestion.getDisplayTextClassifications()); |
401 showDescriptionLine(str, URL_COLOR); | 399 showDescriptionLine(str, true); |
402 return hasMatch; | 400 return hasMatch; |
403 } | 401 } |
404 | 402 |
405 private boolean applyHighlightToMatchRegions( | 403 private boolean applyHighlightToMatchRegions( |
406 Spannable str, List<MatchClassification> classifications) { | 404 Spannable str, List<MatchClassification> classifications) { |
407 boolean hasMatch = false; | 405 boolean hasMatch = false; |
408 for (int i = 0; i < classifications.size(); i++) { | 406 for (int i = 0; i < classifications.size(); i++) { |
409 MatchClassification classification = classifications.get(i); | 407 MatchClassification classification = classifications.get(i); |
410 if ((classification.style & MatchClassificationStyle.MATCH) | 408 if ((classification.style & MatchClassificationStyle.MATCH) |
411 == MatchClassificationStyle.MATCH) { | 409 == MatchClassificationStyle.MATCH) { |
(...skipping 13 matching lines...) Expand all Loading... |
425 matchStartIndex, matchEndIndex, Spannable.SPAN_EXCLUSIVE
_EXCLUSIVE); | 423 matchStartIndex, matchEndIndex, Spannable.SPAN_EXCLUSIVE
_EXCLUSIVE); |
426 } | 424 } |
427 } | 425 } |
428 return hasMatch; | 426 return hasMatch; |
429 } | 427 } |
430 | 428 |
431 /** | 429 /** |
432 * Sets a description line for the omnibox suggestion. | 430 * Sets a description line for the omnibox suggestion. |
433 * | 431 * |
434 * @param str The description text. | 432 * @param str The description text. |
| 433 * @param isUrl Whether this text is a URL (as opposed to a normal string). |
435 */ | 434 */ |
436 private void showDescriptionLine(Spannable str, int textColor) { | 435 private void showDescriptionLine(Spannable str, boolean isUrl) { |
437 if (mContentsView.mTextLine2.getVisibility() != VISIBLE) { | 436 TextView textLine = mContentsView.mTextLine2; |
438 mContentsView.mTextLine2.setVisibility(VISIBLE); | 437 if (textLine.getVisibility() != VISIBLE) { |
| 438 textLine.setVisibility(VISIBLE); |
439 } | 439 } |
440 mContentsView.mTextLine2.setTextColor(textColor); | 440 textLine.setText(str, BufferType.SPANNABLE); |
441 mContentsView.mTextLine2.setText(str, BufferType.SPANNABLE); | 441 |
| 442 // Force left-to-right rendering for URLs. See UrlBar constructor for de
tails. |
| 443 if (isUrl) { |
| 444 textLine.setTextColor(URL_COLOR); |
| 445 ApiCompatibilityUtils.setTextDirection(textLine, TEXT_DIRECTION_LTR)
; |
| 446 } else { |
| 447 textLine.setTextColor(getStandardFontColor()); |
| 448 ApiCompatibilityUtils.setTextDirection(textLine, TEXT_DIRECTION_INHE
RIT); |
| 449 } |
442 } | 450 } |
443 | 451 |
444 /** | 452 /** |
445 * Sets the text of the first line of the omnibox suggestion. | 453 * Sets the text of the first line of the omnibox suggestion. |
446 * | 454 * |
447 * @param suggestionItem The item containing the suggestion data. | 455 * @param suggestionItem The item containing the suggestion data. |
448 * @param showDescriptionIfPresent Whether to show the description text of t
he suggestion if | 456 * @param showDescriptionIfPresent Whether to show the description text of t
he suggestion if |
449 * the item contains valid data. | 457 * the item contains valid data. |
450 * @param isUrlQuery Whether this suggestion is showing an URL. | 458 * @param isUrlQuery Whether this suggestion is showing an URL. |
451 * @param isUrlHighlighted Whether the URL contains any highlighted matching
sections. | 459 * @param isUrlHighlighted Whether the URL contains any highlighted matching
sections. |
(...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
997 if (mUrlBar != null) mUrlBar.removeOnLayoutChangeListener(this); | 1005 if (mUrlBar != null) mUrlBar.removeOnLayoutChangeListener(this); |
998 if (mLocationBar != null) { | 1006 if (mLocationBar != null) { |
999 mLocationBar.getContainerView().removeOnLayoutChangeListener(thi
s); | 1007 mLocationBar.getContainerView().removeOnLayoutChangeListener(thi
s); |
1000 } | 1008 } |
1001 getRootView().removeOnLayoutChangeListener(this); | 1009 getRootView().removeOnLayoutChangeListener(this); |
1002 | 1010 |
1003 super.onDetachedFromWindow(); | 1011 super.onDetachedFromWindow(); |
1004 } | 1012 } |
1005 } | 1013 } |
1006 } | 1014 } |
OLD | NEW |