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

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/toolbar/ToolbarControlContainer.java

Issue 2752693003: chrome/android: Update toolbar drawing in native. (Closed)
Patch Set: fix math for tablets Created 3 years, 9 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.toolbar; 5 package org.chromium.chrome.browser.toolbar;
6 6
7 import android.content.Context; 7 import android.content.Context;
8 import android.graphics.Canvas; 8 import android.graphics.Canvas;
9 import android.graphics.PorterDuff; 9 import android.graphics.PorterDuff;
10 import android.graphics.Rect; 10 import android.graphics.Rect;
11 import android.graphics.Region; 11 import android.graphics.Region;
12 import android.util.AttributeSet; 12 import android.util.AttributeSet;
13 import android.view.MotionEvent; 13 import android.view.MotionEvent;
14 import android.view.View; 14 import android.view.View;
15 import android.view.ViewStub; 15 import android.view.ViewStub;
16 import android.widget.FrameLayout; 16 import android.widget.FrameLayout;
17 17
18 import org.chromium.chrome.R; 18 import org.chromium.chrome.R;
19 import org.chromium.chrome.browser.compositor.layouts.eventfilter.EdgeSwipeHandl er; 19 import org.chromium.chrome.browser.compositor.layouts.eventfilter.EdgeSwipeHandl er;
20 import org.chromium.chrome.browser.compositor.resources.ResourceFactory;
20 import org.chromium.chrome.browser.contextualsearch.SwipeRecognizer; 21 import org.chromium.chrome.browser.contextualsearch.SwipeRecognizer;
21 import org.chromium.chrome.browser.util.ViewUtils; 22 import org.chromium.chrome.browser.util.ViewUtils;
22 import org.chromium.chrome.browser.widget.ClipDrawableProgressBar.DrawingInfo; 23 import org.chromium.chrome.browser.widget.ClipDrawableProgressBar.DrawingInfo;
23 import org.chromium.chrome.browser.widget.ControlContainer; 24 import org.chromium.chrome.browser.widget.ControlContainer;
24 import org.chromium.chrome.browser.widget.ToolbarProgressBar; 25 import org.chromium.chrome.browser.widget.ToolbarProgressBar;
25 import org.chromium.chrome.browser.widget.ViewResourceFrameLayout; 26 import org.chromium.chrome.browser.widget.ViewResourceFrameLayout;
26 import org.chromium.ui.UiUtils; 27 import org.chromium.ui.UiUtils;
27 import org.chromium.ui.resources.dynamics.ViewResourceAdapter; 28 import org.chromium.ui.resources.dynamics.ViewResourceAdapter;
28 29
29 /** 30 /**
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 } 154 }
154 155
155 @Override 156 @Override
156 protected boolean isReadyForCapture() { 157 protected boolean isReadyForCapture() {
157 return mReadyForBitmapCapture; 158 return mReadyForBitmapCapture;
158 } 159 }
159 } 160 }
160 161
161 private static class ToolbarViewResourceAdapter extends ViewResourceAdapter { 162 private static class ToolbarViewResourceAdapter extends ViewResourceAdapter {
162 private final int[] mTempPosition = new int[2]; 163 private final int[] mTempPosition = new int[2];
164 private final Rect mLocationBarRect = new Rect();
165 private final Rect mToolbarRect = new Rect();
163 private final View mToolbarContainer; 166 private final View mToolbarContainer;
164 167
165 private Toolbar mToolbar; 168 private Toolbar mToolbar;
166 private int mToolbarActualHeightPx; 169 private int mToolbarHeightPx;
mdjones 2017/03/16 21:01:47 This can be pulled directly from toolbar now.
Khushal 2017/03/17 23:02:58 Done.
167 private int mTabStripHeightPx; 170 private int mTabStripHeightPx;
168 171
169 /** Builds the resource adapter for the toolbar. */ 172 /** Builds the resource adapter for the toolbar. */
170 public ToolbarViewResourceAdapter(View toolbarContainer) { 173 public ToolbarViewResourceAdapter(View toolbarContainer) {
171 super(toolbarContainer); 174 super(toolbarContainer);
172 mToolbarContainer = toolbarContainer; 175 mToolbarContainer = toolbarContainer;
173 } 176 }
174 177
175 /** 178 /**
176 * Set the toolbar after it has been dynamically inflated. 179 * Set the toolbar after it has been dynamically inflated.
177 * @param toolbar The browser's toolbar. 180 * @param toolbar The browser's toolbar.
178 */ 181 */
179 public void setToolbar(Toolbar toolbar) { 182 public void setToolbar(Toolbar toolbar) {
180 mToolbar = toolbar; 183 mToolbar = toolbar;
181 int containerHeightResId = R.dimen.control_container_height; 184 int containerHeightResId = R.dimen.control_container_height;
182 if (mToolbar instanceof CustomTabToolbar) { 185 if (mToolbar instanceof CustomTabToolbar) {
183 containerHeightResId = R.dimen.custom_tabs_control_container_hei ght; 186 containerHeightResId = R.dimen.custom_tabs_control_container_hei ght;
184 } 187 }
185 mToolbarActualHeightPx = mToolbarContainer.getResources().getDimensi onPixelSize( 188 int toolbarHeightMinusShadow =
186 containerHeightResId); 189 mToolbarContainer.getResources().getDimensionPixelSize(conta inerHeightResId);
187 mTabStripHeightPx = mToolbarContainer.getResources().getDimensionPix elSize( 190 mTabStripHeightPx = mToolbarContainer.getResources().getDimensionPix elSize(
188 R.dimen.tab_strip_height); 191 R.dimen.tab_strip_height);
192 mToolbarHeightPx = toolbarHeightMinusShadow - mTabStripHeightPx;
189 } 193 }
190 194
191 /** 195 /**
192 * Force this resource to be recaptured in full, ignoring the checks 196 * Force this resource to be recaptured in full, ignoring the checks
193 * {@link #invalidate(Rect)} does. 197 * {@link #invalidate(Rect)} does.
194 */ 198 */
195 public void forceInvalidate() { 199 public void forceInvalidate() {
196 super.invalidate(null); 200 super.invalidate(null);
197 } 201 }
198 202
(...skipping 21 matching lines...) Expand all
220 224
221 @Override 225 @Override
222 protected void onCaptureEnd() { 226 protected void onCaptureEnd() {
223 mToolbar.setTextureCaptureMode(false); 227 mToolbar.setTextureCaptureMode(false);
224 // Forcing a texture capture should only be done for one draw. Turn off forced 228 // Forcing a texture capture should only be done for one draw. Turn off forced
225 // texture capture. 229 // texture capture.
226 mToolbar.setForceTextureCapture(false); 230 mToolbar.setForceTextureCapture(false);
227 } 231 }
228 232
229 @Override 233 @Override
230 protected void computeContentPadding(Rect outContentPadding) { 234 public long createNativeResource() {
231 outContentPadding.set(0, mTabStripHeightPx, mToolbarContainer.getWid th(), 235 mToolbar.getPositionRelativeToContainer(mToolbarContainer, mTempPosi tion);
232 mToolbarActualHeightPx); 236 mToolbarRect.set(mTempPosition[0], mTempPosition[1], mToolbarContain er.getWidth(),
233 } 237 mTempPosition[1] + mToolbarHeightPx);
234 238
235 @Override 239 mToolbar.getLocationBarContentRect(mLocationBarRect);
236 protected void computeContentAperture(Rect outContentAperture) { 240 mLocationBarRect.offset(mTempPosition[0], mTempPosition[1]);
237 mToolbar.getLocationBarContentRect(outContentAperture); 241
238 mToolbar.getPositionRelativeToContainer(mToolbarContainer, mTempPosi tion); 242 int shadowHeight = mToolbarContainer.getHeight() - mToolbarHeightPx - mTabStripHeightPx;
239 outContentAperture.offset(mTempPosition[0], mTempPosition[1]); 243 return ResourceFactory.createToolbarContainerResource(
244 mToolbarRect, mLocationBarRect, shadowHeight);
240 } 245 }
241 } 246 }
242 247
243 @Override 248 @Override
244 public boolean onTouchEvent(MotionEvent event) { 249 public boolean onTouchEvent(MotionEvent event) {
245 // Don't eat the event if we don't have a handler. 250 // Don't eat the event if we don't have a handler.
246 if (mSwipeHandler == null) return false; 251 if (mSwipeHandler == null) return false;
247 252
248 // If we have ACTION_DOWN in this context, that means either no child co nsumed the event or 253 // If we have ACTION_DOWN in this context, that means either no child co nsumed the event or
249 // this class is the top UI at the event position. Then, we don't need t o feed the event to 254 // this class is the top UI at the event position. Then, we don't need t o feed the event to
(...skipping 25 matching lines...) Expand all
275 280
276 @Override 281 @Override
277 public boolean shouldRecognizeSwipe(MotionEvent e1, MotionEvent e2) { 282 public boolean shouldRecognizeSwipe(MotionEvent e1, MotionEvent e2) {
278 if (isOnTabStrip(e1)) return false; 283 if (isOnTabStrip(e1)) return false;
279 if (mToolbar.shouldIgnoreSwipeGesture()) return false; 284 if (mToolbar.shouldIgnoreSwipeGesture()) return false;
280 if (UiUtils.isKeyboardShowing(getContext(), ToolbarControlContainer. this)) return false; 285 if (UiUtils.isKeyboardShowing(getContext(), ToolbarControlContainer. this)) return false;
281 return true; 286 return true;
282 } 287 }
283 } 288 }
284 } 289 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698