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

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/infobar/InfoBarControlLayout.java

Issue 1539643002: Make InfoBarControlLayouts more aesthetically pleasing (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Logs Created 5 years 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
« no previous file with comments | « no previous file | chrome/android/javatests/src/org/chromium/chrome/browser/infobar/InfoBarControlLayoutTest.java » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.infobar; 5 package org.chromium.chrome.browser.infobar;
6 6
7 import android.content.Context; 7 import android.content.Context;
8 import android.content.res.Resources; 8 import android.content.res.Resources;
9 import android.support.v7.widget.SwitchCompat; 9 import android.support.v7.widget.SwitchCompat;
10 import android.text.method.LinkMovementMethod; 10 import android.text.method.LinkMovementMethod;
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 85
86 int fullWidth = MeasureSpec.getMode(widthMeasureSpec) == MeasureSpec.UNS PECIFIED 86 int fullWidth = MeasureSpec.getMode(widthMeasureSpec) == MeasureSpec.UNS PECIFIED
87 ? mMaxInfoBarWidth : MeasureSpec.getSize(widthMeasureSpec); 87 ? mMaxInfoBarWidth : MeasureSpec.getSize(widthMeasureSpec);
88 int columnWidth = Math.max(0, (fullWidth - mMarginBetweenColumns) / 2); 88 int columnWidth = Math.max(0, (fullWidth - mMarginBetweenColumns) / 2);
89 89
90 int atMostFullWidthSpec = MeasureSpec.makeMeasureSpec(fullWidth, Measure Spec.AT_MOST); 90 int atMostFullWidthSpec = MeasureSpec.makeMeasureSpec(fullWidth, Measure Spec.AT_MOST);
91 int exactlyFullWidthSpec = MeasureSpec.makeMeasureSpec(fullWidth, Measur eSpec.EXACTLY); 91 int exactlyFullWidthSpec = MeasureSpec.makeMeasureSpec(fullWidth, Measur eSpec.EXACTLY);
92 int exactlyColumnWidthSpec = MeasureSpec.makeMeasureSpec(columnWidth, Me asureSpec.EXACTLY); 92 int exactlyColumnWidthSpec = MeasureSpec.makeMeasureSpec(columnWidth, Me asureSpec.EXACTLY);
93 int unspecifiedSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECI FIED); 93 int unspecifiedSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECI FIED);
94 94
95 // Measure all children, assuming they all have to fit within the width of the layout. 95 // Figure out how many columns each child requires.
96 // Height is unconstrained.
97 for (int i = 0; i < getChildCount(); i++) { 96 for (int i = 0; i < getChildCount(); i++) {
98 View child = getChildAt(i); 97 View child = getChildAt(i);
99 measureChild(child, atMostFullWidthSpec, unspecifiedSpec); 98 measureChild(child, atMostFullWidthSpec, unspecifiedSpec);
100 99
101 if (child.getMeasuredWidth() <= columnWidth 100 if (child.getMeasuredWidth() <= columnWidth
102 && !getControlLayoutParams(child).mMustBeFullWidth) { 101 && !getControlLayoutParams(child).mMustBeFullWidth) {
103 // Stretch out the control to take up a column width.
104 getControlLayoutParams(child).columnsRequired = 1; 102 getControlLayoutParams(child).columnsRequired = 1;
105 measureChild(child, exactlyColumnWidthSpec, unspecifiedSpec);
106 } else { 103 } else {
107 // Stretch out the control to take up the full width.
108 getControlLayoutParams(child).columnsRequired = 2; 104 getControlLayoutParams(child).columnsRequired = 2;
109 measureChild(child, exactlyFullWidthSpec, unspecifiedSpec);
110 } 105 }
111 } 106 }
112 107
113 // Pack all the children as tightly into rows as possible without changi ng their ordering. 108 // Pack all the children as tightly into rows as possible without changi ng their ordering.
109 // Stretch out column-width controls if either it is the last control or the next one is
110 // a full-width control.
111 for (int i = 0; i < getChildCount(); i++) {
112 ControlLayoutParams lp = getControlLayoutParams(getChildAt(i));
113
114 if (i == getChildCount() - 1) {
115 lp.columnsRequired = 2;
116 } else {
117 ControlLayoutParams nextLp = getControlLayoutParams(getChildAt(i + 1));
118 if (lp.columnsRequired + nextLp.columnsRequired > 2) {
119 // This control is too big to place with the next child.
120 lp.columnsRequired = 2;
121 } else {
122 // This and the next control fit on the same line. Skip pla cing the next child.
123 i++;
124 }
125 }
126 }
127
128 // Measure all children, assuming they all have to fit within the width of the layout.
129 // Height is unconstrained.
130 for (int i = 0; i < getChildCount(); i++) {
131 View child = getChildAt(i);
132 ControlLayoutParams lp = getControlLayoutParams(child);
133 int spec = lp.columnsRequired == 1 ? exactlyColumnWidthSpec : exactl yFullWidthSpec;
134 measureChild(child, spec, unspecifiedSpec);
135 }
136
137 // Pack all the children as tightly into rows as possible without changi ng their ordering.
114 int layoutHeight = 0; 138 int layoutHeight = 0;
115 int nextChildStart = 0; 139 int nextChildStart = 0;
116 int nextChildTop = 0; 140 int nextChildTop = 0;
117 int currentRowHeight = 0; 141 int currentRowHeight = 0;
118 int columnsAvailable = 2; 142 int columnsAvailable = 2;
119 for (int i = 0; i < getChildCount(); i++) { 143 for (int i = 0; i < getChildCount(); i++) {
120 View child = getChildAt(i); 144 View child = getChildAt(i);
121 ControlLayoutParams lp = getControlLayoutParams(child); 145 ControlLayoutParams lp = getControlLayoutParams(child);
122 146
123 // If there isn't enough room left for the control, move to the next row. 147 // If there isn't enough room left for the control, move to the next row.
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 290
267 /** 291 /**
268 * @return The {@link ControlLayoutParams} for the given child. 292 * @return The {@link ControlLayoutParams} for the given child.
269 */ 293 */
270 @VisibleForTesting 294 @VisibleForTesting
271 static ControlLayoutParams getControlLayoutParams(View child) { 295 static ControlLayoutParams getControlLayoutParams(View child) {
272 return (ControlLayoutParams) child.getLayoutParams(); 296 return (ControlLayoutParams) child.getLayoutParams();
273 } 297 }
274 298
275 } 299 }
OLDNEW
« no previous file with comments | « no previous file | chrome/android/javatests/src/org/chromium/chrome/browser/infobar/InfoBarControlLayoutTest.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698