| 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 803 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 814 mUrlBar = (UrlBar) locationBarView.findViewById(R.id.url_bar); | 814 mUrlBar = (UrlBar) locationBarView.findViewById(R.id.url_bar); |
| 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 mTextLeft = getSuggestionTextLeftPosition(); | |
| 825 mTextRight = getSuggestionTextRightPosition(); | |
| 826 boolean isRTL = ApiCompatibilityUtils.isLayoutRtl(this); | 824 boolean isRTL = ApiCompatibilityUtils.isLayoutRtl(this); |
| 827 if (DeviceFormFactor.isTablet(getContext())) { | 825 if (DeviceFormFactor.isTablet(getContext())) { |
| 828 int textWidth = isRTL ? mTextRight : (r - l - mTextLeft); | 826 int textWidth = isRTL ? mTextRight : (r - l - mTextLeft); |
| 829 final float maxRequiredWidth = mSuggestionDelegate.getMaxRequire
dWidth(); | 827 final float maxRequiredWidth = mSuggestionDelegate.getMaxRequire
dWidth(); |
| 830 final float maxMatchContentsWidth = mSuggestionDelegate.getMaxMa
tchContentsWidth(); | 828 final float maxMatchContentsWidth = mSuggestionDelegate.getMaxMa
tchContentsWidth(); |
| 831 float paddingStart = (textWidth > maxRequiredWidth) | 829 float paddingStart = (textWidth > maxRequiredWidth) |
| 832 ? (mRequiredWidth - mMatchContentsWidth) | 830 ? (mRequiredWidth - mMatchContentsWidth) |
| 833 : Math.max(textWidth - maxMatchContentsWidth, 0); | 831 : Math.max(textWidth - maxMatchContentsWidth, 0); |
| 834 ApiCompatibilityUtils.setPaddingRelative( | 832 ApiCompatibilityUtils.setPaddingRelative( |
| 835 mTextLine1, (int) paddingStart, mTextLine1.getPaddingTop
(), | 833 mTextLine1, (int) paddingStart, mTextLine1.getPaddingTop
(), |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 911 getLocationOnScreen(mViewPositionHolder); | 909 getLocationOnScreen(mViewPositionHolder); |
| 912 | 910 |
| 913 return navButtonXPosition - mViewPositionHolder[0]; | 911 return navButtonXPosition - mViewPositionHolder[0]; |
| 914 } | 912 } |
| 915 | 913 |
| 916 @Override | 914 @Override |
| 917 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { | 915 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
| 918 int width = MeasureSpec.getSize(widthMeasureSpec); | 916 int width = MeasureSpec.getSize(widthMeasureSpec); |
| 919 int height = MeasureSpec.getSize(heightMeasureSpec); | 917 int height = MeasureSpec.getSize(heightMeasureSpec); |
| 920 | 918 |
| 919 boolean isRTL = ApiCompatibilityUtils.isLayoutRtl(this); |
| 920 mTextLeft = getSuggestionTextLeftPosition(); |
| 921 mTextRight = getSuggestionTextRightPosition(); |
| 922 |
| 923 int maxWidth = width - (isRTL ? mTextRight : mTextLeft); |
| 921 if (mTextLine1.getMeasuredWidth() != width | 924 if (mTextLine1.getMeasuredWidth() != width |
| 922 || mTextLine1.getMeasuredHeight() != height) { | 925 || mTextLine1.getMeasuredHeight() != height) { |
| 923 mTextLine1.measure( | 926 mTextLine1.measure(MeasureSpec.makeMeasureSpec(maxWidth, Measure
Spec.AT_MOST), |
| 924 MeasureSpec.makeMeasureSpec(widthMeasureSpec, MeasureSpe
c.AT_MOST), | |
| 925 MeasureSpec.makeMeasureSpec(mSuggestionHeight, MeasureSp
ec.AT_MOST)); | 927 MeasureSpec.makeMeasureSpec(mSuggestionHeight, MeasureSp
ec.AT_MOST)); |
| 926 } | 928 } |
| 927 | 929 |
| 928 if (mTextLine2.getMeasuredWidth() != width | 930 if (mTextLine2.getMeasuredWidth() != width |
| 929 || mTextLine2.getMeasuredHeight() != height) { | 931 || mTextLine2.getMeasuredHeight() != height) { |
| 930 mTextLine2.measure( | 932 mTextLine2.measure(MeasureSpec.makeMeasureSpec(maxWidth, Measure
Spec.AT_MOST), |
| 931 MeasureSpec.makeMeasureSpec(widthMeasureSpec, MeasureSpe
c.AT_MOST), | |
| 932 MeasureSpec.makeMeasureSpec(mSuggestionHeight, MeasureSp
ec.AT_MOST)); | 933 MeasureSpec.makeMeasureSpec(mSuggestionHeight, MeasureSp
ec.AT_MOST)); |
| 933 } | 934 } |
| 934 if (MeasureSpec.getMode(heightMeasureSpec) == MeasureSpec.AT_MOST) { | 935 if (MeasureSpec.getMode(heightMeasureSpec) == MeasureSpec.AT_MOST) { |
| 935 int desiredHeight = mTextLine1.getMeasuredHeight() + mTextLine2.
getMeasuredHeight(); | 936 int desiredHeight = mTextLine1.getMeasuredHeight() + mTextLine2.
getMeasuredHeight(); |
| 936 int additionalPadding = (int) getResources().getDimension( | 937 int additionalPadding = (int) getResources().getDimension( |
| 937 R.dimen.omnibox_suggestion_text_vertical_padding); | 938 R.dimen.omnibox_suggestion_text_vertical_padding); |
| 938 if (mSuggestion.hasAnswer()) { | 939 if (mSuggestion.hasAnswer()) { |
| 939 additionalPadding += (int) getResources().getDimension( | 940 additionalPadding += (int) getResources().getDimension( |
| 940 R.dimen.omnibox_suggestion_multiline_text_vertical_p
adding); | 941 R.dimen.omnibox_suggestion_multiline_text_vertical_p
adding); |
| 941 } | 942 } |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1060 if (mUrlBar != null) mUrlBar.removeOnLayoutChangeListener(this); | 1061 if (mUrlBar != null) mUrlBar.removeOnLayoutChangeListener(this); |
| 1061 if (mLocationBar != null) { | 1062 if (mLocationBar != null) { |
| 1062 mLocationBar.getContainerView().removeOnLayoutChangeListener(thi
s); | 1063 mLocationBar.getContainerView().removeOnLayoutChangeListener(thi
s); |
| 1063 } | 1064 } |
| 1064 getRootView().removeOnLayoutChangeListener(this); | 1065 getRootView().removeOnLayoutChangeListener(this); |
| 1065 | 1066 |
| 1066 super.onDetachedFromWindow(); | 1067 super.onDetachedFromWindow(); |
| 1067 } | 1068 } |
| 1068 } | 1069 } |
| 1069 } | 1070 } |
| OLD | NEW |