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 494 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
505 | 505 |
506 // Offset the match classifications by the length of the ellipsi
s prefix to ensure | 506 // Offset the match classifications by the length of the ellipsi
s prefix to ensure |
507 // the highlighting remains correct. | 507 // the highlighting remains correct. |
508 for (int i = 0; i < classifications.size(); i++) { | 508 for (int i = 0; i < classifications.size(); i++) { |
509 classifications.set(i, new MatchClassification( | 509 classifications.set(i, new MatchClassification( |
510 classifications.get(i).offset + ellipsisPrefix.lengt
h(), | 510 classifications.get(i).offset + ellipsisPrefix.lengt
h(), |
511 classifications.get(i).style)); | 511 classifications.get(i).style)); |
512 } | 512 } |
513 classifications.add(0, new MatchClassification(0, MatchClassific
ationStyle.NONE)); | 513 classifications.add(0, new MatchClassification(0, MatchClassific
ationStyle.NONE)); |
514 | 514 |
515 if (DeviceFormFactor.isTablet(getContext())) { | 515 if (DeviceFormFactor.isTablet()) { |
516 TextPaint tp = mContentsView.mTextLine1.getPaint(); | 516 TextPaint tp = mContentsView.mTextLine1.getPaint(); |
517 mContentsView.mRequiredWidth = | 517 mContentsView.mRequiredWidth = |
518 tp.measureText(fillIntoEdit, 0, fillIntoEdit.length(
)); | 518 tp.measureText(fillIntoEdit, 0, fillIntoEdit.length(
)); |
519 mContentsView.mMatchContentsWidth = | 519 mContentsView.mMatchContentsWidth = |
520 tp.measureText(suggestedQuery, 0, suggestedQuery.len
gth()); | 520 tp.measureText(suggestedQuery, 0, suggestedQuery.len
gth()); |
521 | 521 |
522 // Update the max text widths values in SuggestionList. Thes
e will be passed to | 522 // Update the max text widths values in SuggestionList. Thes
e will be passed to |
523 // the contents view on layout. | 523 // the contents view on layout. |
524 mSuggestionDelegate.onTextWidthsUpdated( | 524 mSuggestionDelegate.onTextWidthsUpdated( |
525 mContentsView.mRequiredWidth, mContentsView.mMatchCo
ntentsWidth); | 525 mContentsView.mRequiredWidth, mContentsView.mMatchCo
ntentsWidth); |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
729 | 729 |
730 private void resetTextWidths() { | 730 private void resetTextWidths() { |
731 mRequiredWidth = 0; | 731 mRequiredWidth = 0; |
732 mMatchContentsWidth = 0; | 732 mMatchContentsWidth = 0; |
733 } | 733 } |
734 | 734 |
735 @Override | 735 @Override |
736 protected void onDraw(Canvas canvas) { | 736 protected void onDraw(Canvas canvas) { |
737 super.onDraw(canvas); | 737 super.onDraw(canvas); |
738 | 738 |
739 if (DeviceFormFactor.isTablet(getContext())) { | 739 if (DeviceFormFactor.isTablet()) { |
740 // Use the same image transform matrix as the navigation icon to
ensure the same | 740 // Use the same image transform matrix as the navigation icon to
ensure the same |
741 // scaling, which requires centering vertically based on the hei
ght of the | 741 // scaling, which requires centering vertically based on the hei
ght of the |
742 // navigation icon view and not the image itself. | 742 // navigation icon view and not the image itself. |
743 canvas.save(); | 743 canvas.save(); |
744 mSuggestionIconLeft = getSuggestionIconLeftPosition(); | 744 mSuggestionIconLeft = getSuggestionIconLeftPosition(); |
745 canvas.translate( | 745 canvas.translate( |
746 mSuggestionIconLeft, | 746 mSuggestionIconLeft, |
747 (getMeasuredHeight() - mNavigationButton.getMeasuredHeig
ht()) / 2f); | 747 (getMeasuredHeight() - mNavigationButton.getMeasuredHeig
ht()) / 2f); |
748 canvas.concat(mNavigationButton.getImageMatrix()); | 748 canvas.concat(mNavigationButton.getImageMatrix()); |
749 mSuggestionIcon.draw(canvas); | 749 mSuggestionIcon.draw(canvas); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
815 mUrlBar.addOnLayoutChangeListener(this); | 815 mUrlBar.addOnLayoutChangeListener(this); |
816 } | 816 } |
817 if (mNavigationButton == null) { | 817 if (mNavigationButton == null) { |
818 mNavigationButton = | 818 mNavigationButton = |
819 (ImageView) locationBarView.findViewById(R.id.navigation
_button); | 819 (ImageView) locationBarView.findViewById(R.id.navigation
_button); |
820 mNavigationButton.addOnLayoutChangeListener(this); | 820 mNavigationButton.addOnLayoutChangeListener(this); |
821 } | 821 } |
822 | 822 |
823 // Align the text to be pixel perfectly aligned with the text in the
url bar. | 823 // Align the text to be pixel perfectly aligned with the text in the
url bar. |
824 boolean isRTL = ApiCompatibilityUtils.isLayoutRtl(this); | 824 boolean isRTL = ApiCompatibilityUtils.isLayoutRtl(this); |
825 if (DeviceFormFactor.isTablet(getContext())) { | 825 if (DeviceFormFactor.isTablet()) { |
826 int textWidth = isRTL ? mTextRight : (r - l - mTextLeft); | 826 int textWidth = isRTL ? mTextRight : (r - l - mTextLeft); |
827 final float maxRequiredWidth = mSuggestionDelegate.getMaxRequire
dWidth(); | 827 final float maxRequiredWidth = mSuggestionDelegate.getMaxRequire
dWidth(); |
828 final float maxMatchContentsWidth = mSuggestionDelegate.getMaxMa
tchContentsWidth(); | 828 final float maxMatchContentsWidth = mSuggestionDelegate.getMaxMa
tchContentsWidth(); |
829 float paddingStart = (textWidth > maxRequiredWidth) | 829 float paddingStart = (textWidth > maxRequiredWidth) |
830 ? (mRequiredWidth - mMatchContentsWidth) | 830 ? (mRequiredWidth - mMatchContentsWidth) |
831 : Math.max(textWidth - maxMatchContentsWidth, 0); | 831 : Math.max(textWidth - maxMatchContentsWidth, 0); |
832 ApiCompatibilityUtils.setPaddingRelative( | 832 ApiCompatibilityUtils.setPaddingRelative( |
833 mTextLine1, (int) paddingStart, mTextLine1.getPaddingTop
(), | 833 mTextLine1, (int) paddingStart, mTextLine1.getPaddingTop
(), |
834 0, // TODO(skanuj) : Change to ApiCompatibilityUtils.get
PaddingEnd(...). | 834 0, // TODO(skanuj) : Change to ApiCompatibilityUtils.get
PaddingEnd(...). |
835 mTextLine1.getPaddingBottom()); | 835 mTextLine1.getPaddingBottom()); |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1061 if (mUrlBar != null) mUrlBar.removeOnLayoutChangeListener(this); | 1061 if (mUrlBar != null) mUrlBar.removeOnLayoutChangeListener(this); |
1062 if (mLocationBar != null) { | 1062 if (mLocationBar != null) { |
1063 mLocationBar.getContainerView().removeOnLayoutChangeListener(thi
s); | 1063 mLocationBar.getContainerView().removeOnLayoutChangeListener(thi
s); |
1064 } | 1064 } |
1065 getRootView().removeOnLayoutChangeListener(this); | 1065 getRootView().removeOnLayoutChangeListener(this); |
1066 | 1066 |
1067 super.onDetachedFromWindow(); | 1067 super.onDetachedFromWindow(); |
1068 } | 1068 } |
1069 } | 1069 } |
1070 } | 1070 } |
OLD | NEW |