Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(752)

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/omnibox/SuggestionView.java

Issue 1988553002: Android omnibox: Force paragraph direction to LTR. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Set alignment correctly, and URLs in SuggestionView match URL bar. Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 } else if ((suggestionType == OmniboxSuggestionType.SEARCH_SUGGEST_P ERSONALIZED) 320 } else if ((suggestionType == OmniboxSuggestionType.SEARCH_SUGGEST_P ERSONALIZED)
321 || (suggestionType == OmniboxSuggestionType.SEARCH_HISTORY)) { 321 || (suggestionType == OmniboxSuggestionType.SEARCH_HISTORY)) {
322 // Show history icon for suggestions based on user queries. 322 // Show history icon for suggestions based on user queries.
323 suggestionIcon = SUGGESTION_ICON_HISTORY; 323 suggestionIcon = SUGGESTION_ICON_HISTORY;
324 } 324 }
325 mContentsView.setSuggestionIcon(suggestionIcon, colorsChanged); 325 mContentsView.setSuggestionIcon(suggestionIcon, colorsChanged);
326 setRefinable(!sameAsTyped); 326 setRefinable(!sameAsTyped);
327 setSuggestedQuery(suggestionItem, false, false, false); 327 setSuggestedQuery(suggestionItem, false, false, false);
328 if ((suggestionType == OmniboxSuggestionType.SEARCH_SUGGEST_ENTITY) 328 if ((suggestionType == OmniboxSuggestionType.SEARCH_SUGGEST_ENTITY)
329 || (suggestionType == OmniboxSuggestionType.SEARCH_SUGGEST_P ROFILE)) { 329 || (suggestionType == OmniboxSuggestionType.SEARCH_SUGGEST_P ROFILE)) {
330 showDescriptionLine( 330 showDescriptionLine(SpannableString.valueOf(mSuggestion.getDescr iption()), false);
331 SpannableString.valueOf(mSuggestion.getDescription()),
332 getStandardFontColor());
333 } else { 331 } else {
334 mContentsView.mTextLine2.setVisibility(INVISIBLE); 332 mContentsView.mTextLine2.setVisibility(INVISIBLE);
335 } 333 }
336 } 334 }
337 } 335 }
338 336
339 private void setRefinable(boolean refinable) { 337 private void setRefinable(boolean refinable) {
340 if (refinable) { 338 if (refinable) {
341 mRefineView.setVisibility(VISIBLE); 339 mRefineView.setVisibility(VISIBLE);
342 mRefineView.setOnClickListener(new OnClickListener() { 340 mRefineView.setOnClickListener(new OnClickListener() {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 * Sets (and highlights) the URL text of the second line of the omnibox sugg estion. 384 * Sets (and highlights) the URL text of the second line of the omnibox sugg estion.
387 * 385 *
388 * @param result The suggestion containing the URL. 386 * @param result The suggestion containing the URL.
389 * @return Whether the URL was highlighted based on the user query. 387 * @return Whether the URL was highlighted based on the user query.
390 */ 388 */
391 private boolean setUrlText(OmniboxResultItem result) { 389 private boolean setUrlText(OmniboxResultItem result) {
392 OmniboxSuggestion suggestion = result.getSuggestion(); 390 OmniboxSuggestion suggestion = result.getSuggestion();
393 Spannable str = SpannableString.valueOf(suggestion.getDisplayText()); 391 Spannable str = SpannableString.valueOf(suggestion.getDisplayText());
394 boolean hasMatch = applyHighlightToMatchRegions( 392 boolean hasMatch = applyHighlightToMatchRegions(
395 str, suggestion.getDisplayTextClassifications()); 393 str, suggestion.getDisplayTextClassifications());
396 showDescriptionLine(str, URL_COLOR); 394 showDescriptionLine(str, true);
397 return hasMatch; 395 return hasMatch;
398 } 396 }
399 397
400 private boolean applyHighlightToMatchRegions( 398 private boolean applyHighlightToMatchRegions(
401 Spannable str, List<MatchClassification> classifications) { 399 Spannable str, List<MatchClassification> classifications) {
402 boolean hasMatch = false; 400 boolean hasMatch = false;
403 for (int i = 0; i < classifications.size(); i++) { 401 for (int i = 0; i < classifications.size(); i++) {
404 MatchClassification classification = classifications.get(i); 402 MatchClassification classification = classifications.get(i);
405 if ((classification.style & MatchClassificationStyle.MATCH) 403 if ((classification.style & MatchClassificationStyle.MATCH)
406 == MatchClassificationStyle.MATCH) { 404 == MatchClassificationStyle.MATCH) {
(...skipping 13 matching lines...) Expand all
420 matchStartIndex, matchEndIndex, Spannable.SPAN_EXCLUSIVE _EXCLUSIVE); 418 matchStartIndex, matchEndIndex, Spannable.SPAN_EXCLUSIVE _EXCLUSIVE);
421 } 419 }
422 } 420 }
423 return hasMatch; 421 return hasMatch;
424 } 422 }
425 423
426 /** 424 /**
427 * Sets a description line for the omnibox suggestion. 425 * Sets a description line for the omnibox suggestion.
428 * 426 *
429 * @param str The description text. 427 * @param str The description text.
428 * @param isUrl Whether this text is a URL (as opposed to a normal string).
430 */ 429 */
431 private void showDescriptionLine(Spannable str, int textColor) { 430 private void showDescriptionLine(Spannable str, boolean isUrl) {
432 if (mContentsView.mTextLine2.getVisibility() != VISIBLE) { 431 TextView textLine = mContentsView.mTextLine2;
433 mContentsView.mTextLine2.setVisibility(VISIBLE); 432 if (textLine.getVisibility() != VISIBLE) {
433 textLine.setVisibility(VISIBLE);
434 } 434 }
435 mContentsView.mTextLine2.setTextColor(textColor); 435 textLine.setText(str, BufferType.SPANNABLE);
436 mContentsView.mTextLine2.setText(str, BufferType.SPANNABLE); 436
437 // Force left-to-right rendering for URLs. See UrlBar constructor for de tails.
438 if (isUrl) {
439 textLine.setTextColor(URL_COLOR);
440 textLine.setTextDirection(TEXT_DIRECTION_LTR);
441 textLine.setTextAlignment(TEXT_ALIGNMENT_VIEW_START);
442 } else {
443 textLine.setTextColor(getStandardFontColor());
444 textLine.setTextDirection(TEXT_DIRECTION_INHERIT);
445 textLine.setTextAlignment(TEXT_ALIGNMENT_INHERIT);
446 }
437 } 447 }
438 448
439 /** 449 /**
440 * Sets the text of the first line of the omnibox suggestion. 450 * Sets the text of the first line of the omnibox suggestion.
441 * 451 *
442 * @param suggestionItem The item containing the suggestion data. 452 * @param suggestionItem The item containing the suggestion data.
443 * @param showDescriptionIfPresent Whether to show the description text of t he suggestion if 453 * @param showDescriptionIfPresent Whether to show the description text of t he suggestion if
444 * the item contains valid data. 454 * the item contains valid data.
445 * @param isUrlQuery Whether this suggestion is showing an URL. 455 * @param isUrlQuery Whether this suggestion is showing an URL.
446 * @param isUrlHighlighted Whether the URL contains any highlighted matching sections. 456 * @param isUrlHighlighted Whether the URL contains any highlighted matching sections.
(...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after
985 if (mUrlBar != null) mUrlBar.removeOnLayoutChangeListener(this); 995 if (mUrlBar != null) mUrlBar.removeOnLayoutChangeListener(this);
986 if (mLocationBar != null) { 996 if (mLocationBar != null) {
987 mLocationBar.getContainerView().removeOnLayoutChangeListener(thi s); 997 mLocationBar.getContainerView().removeOnLayoutChangeListener(thi s);
988 } 998 }
989 getRootView().removeOnLayoutChangeListener(this); 999 getRootView().removeOnLayoutChangeListener(this);
990 1000
991 super.onDetachedFromWindow(); 1001 super.onDetachedFromWindow();
992 } 1002 }
993 } 1003 }
994 } 1004 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698