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; | 5 package org.chromium.chrome.browser; |
6 | 6 |
7 import android.annotation.SuppressLint; | 7 import android.annotation.SuppressLint; |
8 import android.annotation.TargetApi; | 8 import android.annotation.TargetApi; |
9 import android.app.Activity; | 9 import android.app.Activity; |
10 import android.app.SearchManager; | 10 import android.app.SearchManager; |
11 import android.app.assist.AssistContent; | 11 import android.app.assist.AssistContent; |
12 import android.content.Context; | 12 import android.content.Context; |
13 import android.content.Intent; | 13 import android.content.Intent; |
14 import android.content.res.Configuration; | 14 import android.content.res.Configuration; |
15 import android.graphics.Bitmap; | 15 import android.graphics.Bitmap; |
16 import android.graphics.Color; | 16 import android.graphics.Color; |
17 import android.graphics.Rect; | 17 import android.graphics.Rect; |
18 import android.graphics.drawable.ColorDrawable; | 18 import android.graphics.drawable.ColorDrawable; |
19 import android.graphics.drawable.Drawable; | 19 import android.graphics.drawable.Drawable; |
20 import android.net.Uri; | 20 import android.net.Uri; |
21 import android.os.Build; | 21 import android.os.Build; |
22 import android.os.Bundle; | 22 import android.os.Bundle; |
23 import android.os.StrictMode; | 23 import android.os.StrictMode; |
24 import android.os.SystemClock; | 24 import android.os.SystemClock; |
25 import android.support.design.widget.CoordinatorLayout.LayoutParams; | |
26 import android.support.v7.app.AlertDialog; | 25 import android.support.v7.app.AlertDialog; |
27 import android.util.DisplayMetrics; | 26 import android.util.DisplayMetrics; |
28 import android.util.Pair; | 27 import android.util.Pair; |
29 import android.view.Gravity; | |
30 import android.view.Menu; | 28 import android.view.Menu; |
31 import android.view.MenuItem; | 29 import android.view.MenuItem; |
32 import android.view.View; | 30 import android.view.View; |
33 import android.view.ViewConfiguration; | 31 import android.view.ViewConfiguration; |
34 import android.view.ViewGroup; | 32 import android.view.ViewGroup; |
35 import android.view.ViewStub; | 33 import android.view.ViewStub; |
36 import android.view.Window; | 34 import android.view.Window; |
37 import android.view.WindowManager; | 35 import android.view.WindowManager; |
38 import android.view.accessibility.AccessibilityManager; | 36 import android.view.accessibility.AccessibilityManager; |
39 import android.view.accessibility.AccessibilityManager.AccessibilityStateChangeL istener; | 37 import android.view.accessibility.AccessibilityManager.AccessibilityStateChangeL istener; |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
120 import org.chromium.chrome.browser.tabmodel.TabModelSelectorTabObserver; | 118 import org.chromium.chrome.browser.tabmodel.TabModelSelectorTabObserver; |
121 import org.chromium.chrome.browser.tabmodel.TabModelUtils; | 119 import org.chromium.chrome.browser.tabmodel.TabModelUtils; |
122 import org.chromium.chrome.browser.tabmodel.TabWindowManager; | 120 import org.chromium.chrome.browser.tabmodel.TabWindowManager; |
123 import org.chromium.chrome.browser.toolbar.Toolbar; | 121 import org.chromium.chrome.browser.toolbar.Toolbar; |
124 import org.chromium.chrome.browser.toolbar.ToolbarControlContainer; | 122 import org.chromium.chrome.browser.toolbar.ToolbarControlContainer; |
125 import org.chromium.chrome.browser.toolbar.ToolbarManager; | 123 import org.chromium.chrome.browser.toolbar.ToolbarManager; |
126 import org.chromium.chrome.browser.util.ChromeFileProvider; | 124 import org.chromium.chrome.browser.util.ChromeFileProvider; |
127 import org.chromium.chrome.browser.util.ColorUtils; | 125 import org.chromium.chrome.browser.util.ColorUtils; |
128 import org.chromium.chrome.browser.util.FeatureUtilities; | 126 import org.chromium.chrome.browser.util.FeatureUtilities; |
129 import org.chromium.chrome.browser.webapps.AddToHomescreenManager; | 127 import org.chromium.chrome.browser.webapps.AddToHomescreenManager; |
128 import org.chromium.chrome.browser.widget.BottomSheet; | |
130 import org.chromium.chrome.browser.widget.ControlContainer; | 129 import org.chromium.chrome.browser.widget.ControlContainer; |
131 import org.chromium.components.bookmarks.BookmarkId; | 130 import org.chromium.components.bookmarks.BookmarkId; |
132 import org.chromium.content.browser.ContentVideoView; | 131 import org.chromium.content.browser.ContentVideoView; |
133 import org.chromium.content.browser.ContentViewCore; | 132 import org.chromium.content.browser.ContentViewCore; |
134 import org.chromium.content.common.ContentSwitches; | 133 import org.chromium.content.common.ContentSwitches; |
135 import org.chromium.content_public.browser.ContentBitmapCallback; | 134 import org.chromium.content_public.browser.ContentBitmapCallback; |
136 import org.chromium.content_public.browser.LoadUrlParams; | 135 import org.chromium.content_public.browser.LoadUrlParams; |
137 import org.chromium.content_public.browser.WebContents; | 136 import org.chromium.content_public.browser.WebContents; |
138 import org.chromium.content_public.browser.readback_types.ReadbackResponse; | 137 import org.chromium.content_public.browser.readback_types.ReadbackResponse; |
139 import org.chromium.policy.CombinedPolicyProvider; | 138 import org.chromium.policy.CombinedPolicyProvider; |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
353 * super.setContentView() before using {@link #getTabModelSelector()} or | 352 * super.setContentView() before using {@link #getTabModelSelector()} or |
354 * {@link #getCompositorViewHolder()}. | 353 * {@link #getCompositorViewHolder()}. |
355 */ | 354 */ |
356 @Override | 355 @Override |
357 protected final void setContentView() { | 356 protected final void setContentView() { |
358 final long begin = SystemClock.elapsedRealtime(); | 357 final long begin = SystemClock.elapsedRealtime(); |
359 TraceEvent.begin("onCreate->setContentView()"); | 358 TraceEvent.begin("onCreate->setContentView()"); |
360 | 359 |
361 enableHardwareAcceleration(); | 360 enableHardwareAcceleration(); |
362 setLowEndTheme(); | 361 setLowEndTheme(); |
362 BottomSheet bottomSheet = null; | |
363 ControlContainer controlContainer = null; | |
363 int controlContainerLayoutId = getControlContainerLayoutId(); | 364 int controlContainerLayoutId = getControlContainerLayoutId(); |
364 WarmupManager warmupManager = WarmupManager.getInstance(); | 365 WarmupManager warmupManager = WarmupManager.getInstance(); |
365 if (warmupManager.hasViewHierarchyWithToolbar(controlContainerLayoutId)) { | 366 if (warmupManager.hasViewHierarchyWithToolbar(controlContainerLayoutId)) { |
366 View placeHolderView = new View(this); | 367 View placeHolderView = new View(this); |
367 setContentView(placeHolderView); | 368 setContentView(placeHolderView); |
368 ViewGroup contentParent = (ViewGroup) placeHolderView.getParent(); | 369 ViewGroup contentParent = (ViewGroup) placeHolderView.getParent(); |
369 warmupManager.transferViewHierarchyTo(contentParent); | 370 warmupManager.transferViewHierarchyTo(contentParent); |
370 contentParent.removeView(placeHolderView); | 371 contentParent.removeView(placeHolderView); |
371 } else { | 372 } else { |
372 warmupManager.clearViewHierarchy(); | 373 warmupManager.clearViewHierarchy(); |
373 | 374 |
374 // Allow disk access for the content view and toolbar container setu p. | 375 // Allow disk access for the content view and toolbar container setu p. |
375 // On certain android devices this setup sequence results in disk wr ites outside | 376 // On certain android devices this setup sequence results in disk wr ites outside |
376 // of our control, so we have to disable StrictMode to work. See crb ug.com/639352. | 377 // of our control, so we have to disable StrictMode to work. See crb ug.com/639352. |
377 StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites (); | 378 StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites (); |
378 try { | 379 try { |
379 setContentView(R.layout.main); | 380 setContentView(R.layout.main); |
380 if (controlContainerLayoutId != NO_CONTROL_CONTAINER) { | 381 if (controlContainerLayoutId != NO_CONTROL_CONTAINER) { |
381 ViewStub toolbarContainerStub = | 382 ViewStub toolbarContainerStub = |
382 ((ViewStub) findViewById(R.id.control_container_stub )); | 383 ((ViewStub) findViewById(R.id.control_container_stub )); |
383 | 384 |
384 toolbarContainerStub.setLayoutResource(controlContainerLayou tId); | 385 toolbarContainerStub.setLayoutResource(controlContainerLayou tId); |
385 View container = toolbarContainerStub.inflate(); | 386 View container = toolbarContainerStub.inflate(); |
386 | 387 |
387 // If the control container is at the bottom apply Gravity.B OTTOM here since | 388 // Get a handle to the bottom sheet if using the bottom cont rol container. |
388 // it is not respected in the XML while the ViewStub in betw een the | |
389 // CompositorViewHolder and ControlContainer. | |
390 if (controlContainerLayoutId == R.layout.bottom_control_cont ainer) { | 389 if (controlContainerLayoutId == R.layout.bottom_control_cont ainer) { |
391 ((LayoutParams) container.getLayoutParams()).gravity = G ravity.BOTTOM; | 390 bottomSheet = (BottomSheet) findViewById(R.id.bottom_she et); |
392 } | 391 } |
393 } | 392 } |
394 | 393 |
395 // It cannot be assumed that the result of toolbarContainerStub. inflate() will be | 394 // It cannot be assumed that the result of toolbarContainerStub. inflate() will be |
396 // the control container since it may be wrapped in another view . | 395 // the control container since it may be wrapped in another view . |
397 ControlContainer controlContainer = | 396 controlContainer = (ControlContainer) findViewById(R.id.control_ container); |
398 (ControlContainer) findViewById(R.id.control_container); | |
399 | 397 |
400 // Inflate the correct toolbar layout for the device. | 398 // Inflate the correct toolbar layout for the device. |
401 int toolbarLayoutId = getToolbarLayoutId(); | 399 int toolbarLayoutId = getToolbarLayoutId(); |
402 if (toolbarLayoutId != NO_TOOLBAR_LAYOUT && controlContainer != null) { | 400 if (toolbarLayoutId != NO_TOOLBAR_LAYOUT && controlContainer != null) { |
403 controlContainer.initWithToolbar(toolbarLayoutId); | 401 controlContainer.initWithToolbar(toolbarLayoutId); |
404 } | 402 } |
405 } finally { | 403 } finally { |
406 StrictMode.setThreadPolicy(oldPolicy); | 404 StrictMode.setThreadPolicy(oldPolicy); |
407 } | 405 } |
408 } | 406 } |
409 TraceEvent.end("onCreate->setContentView()"); | 407 TraceEvent.end("onCreate->setContentView()"); |
410 mInflateInitialLayoutDurationMs = SystemClock.elapsedRealtime() - begin; | 408 mInflateInitialLayoutDurationMs = SystemClock.elapsedRealtime() - begin; |
411 | 409 |
412 // Set the status bar color to black by default. This is an optimization for | 410 // Set the status bar color to black by default. This is an optimization for |
413 // Chrome not to draw under status and navigation bars when we use the d efault | 411 // Chrome not to draw under status and navigation bars when we use the d efault |
414 // black status bar | 412 // black status bar |
415 ApiCompatibilityUtils.setStatusBarColor(getWindow(), Color.BLACK); | 413 ApiCompatibilityUtils.setStatusBarColor(getWindow(), Color.BLACK); |
416 | 414 |
417 ViewGroup rootView = (ViewGroup) getWindow().getDecorView().getRootView( ); | 415 ViewGroup rootView = (ViewGroup) getWindow().getDecorView().getRootView( ); |
418 mCompositorViewHolder = (CompositorViewHolder) findViewById(R.id.composi tor_view_holder); | 416 mCompositorViewHolder = (CompositorViewHolder) findViewById(R.id.composi tor_view_holder); |
419 mCompositorViewHolder.setRootView(rootView); | 417 mCompositorViewHolder.setRootView(rootView); |
420 | 418 |
419 if (bottomSheet != null) { | |
420 bottomSheet.init(mCompositorViewHolder, controlContainer.getView()); | |
Ian Wen
2017/01/11 19:46:53
I think you shouldn't let the bottom sheet to know
mdjones
2017/01/12 21:26:57
Already forgot about the new coordinator. Fixed.
| |
421 } | |
422 | |
421 // Setting fitsSystemWindows to false ensures that the root view doesn't consume the insets. | 423 // Setting fitsSystemWindows to false ensures that the root view doesn't consume the insets. |
422 rootView.setFitsSystemWindows(false); | 424 rootView.setFitsSystemWindows(false); |
423 | 425 |
424 // Add a custom view right after the root view that stores the insets to access later. | 426 // Add a custom view right after the root view that stores the insets to access later. |
425 // ContentViewCore needs the insets to determine the portion of the scre en obscured by | 427 // ContentViewCore needs the insets to determine the portion of the scre en obscured by |
426 // non-content displaying things such as the OSK. | 428 // non-content displaying things such as the OSK. |
427 mInsetObserverView = InsetObserverView.create(this); | 429 mInsetObserverView = InsetObserverView.create(this); |
428 rootView.addView(mInsetObserverView, 0); | 430 rootView.addView(mInsetObserverView, 0); |
429 } | 431 } |
430 | 432 |
(...skipping 1533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1964 "Android.MultiWindowMode.IsTabletScreenWidthBelow600", | 1966 "Android.MultiWindowMode.IsTabletScreenWidthBelow600", |
1965 mScreenWidthDp < DeviceFormFactor.MINIMUM_TABLET_WIDTH_DP); | 1967 mScreenWidthDp < DeviceFormFactor.MINIMUM_TABLET_WIDTH_DP); |
1966 | 1968 |
1967 if (mScreenWidthDp < DeviceFormFactor.MINIMUM_TABLET_WIDTH_DP) { | 1969 if (mScreenWidthDp < DeviceFormFactor.MINIMUM_TABLET_WIDTH_DP) { |
1968 RecordHistogram.recordLinearCountHistogram( | 1970 RecordHistogram.recordLinearCountHistogram( |
1969 "Android.MultiWindowMode.TabletScreenWidth", mScreenWidthDp, 1, | 1971 "Android.MultiWindowMode.TabletScreenWidth", mScreenWidthDp, 1, |
1970 DeviceFormFactor.MINIMUM_TABLET_WIDTH_DP, 50); | 1972 DeviceFormFactor.MINIMUM_TABLET_WIDTH_DP, 50); |
1971 } | 1973 } |
1972 } | 1974 } |
1973 } | 1975 } |
OLD | NEW |