Chromium Code Reviews| Index: android_webview/java/src/org/chromium/android_webview/AwZoomControls.java |
| diff --git a/android_webview/java/src/org/chromium/android_webview/AwZoomControls.java b/android_webview/java/src/org/chromium/android_webview/AwZoomControls.java |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..9579d50f509612402f04c2d7340e9a4ed774254c |
| --- /dev/null |
| +++ b/android_webview/java/src/org/chromium/android_webview/AwZoomControls.java |
| @@ -0,0 +1,98 @@ |
| +// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +package org.chromium.android_webview; |
| + |
| +import android.view.Gravity; |
| +import android.view.View; |
| +import android.view.ViewGroup; |
| +import android.widget.FrameLayout; |
| +import android.widget.ZoomButtonsController; |
| +import org.chromium.content.browser.ContentViewCore.ZoomControlsDelegate; |
| + |
| +class AwZoomControls implements ZoomControlsDelegate { |
| + |
| + private AwContents mAwContents; |
| + private ZoomButtonsController mZoomButtonsController; |
| + |
| + AwZoomControls(AwContents awContents) { |
| + mAwContents = awContents; |
| + } |
| + |
| + @Override |
| + public void invokeZoomPicker() { |
| + ZoomButtonsController zoomControls = getZoomControls(); |
| + if (zoomControls != null && !zoomControls.isVisible()) { |
|
joth
2013/05/03 19:32:43
maybe we should call setVisible(true) even if they
mnaganov (inactive)
2013/05/07 09:55:44
Right, it seems better to omit this check. Also, t
|
| + zoomControls.setVisible(true); |
|
joth
2013/05/03 19:32:43
do we need to update the individual button states
mnaganov (inactive)
2013/05/07 09:55:44
ZoomButtonsController calls ZoomListener's onVisib
|
| + } |
| + } |
| + |
| + @Override |
| + public void dismissZoomPicker() { |
| + ZoomButtonsController zoomControls = getZoomControls(); |
| + if (zoomControls != null && zoomControls.isVisible()) { |
| + zoomControls.setVisible(false); |
| + } |
| + } |
| + |
| + @Override |
| + public void updateZoomControls() { |
| + if (mZoomButtonsController == null) return; |
|
joth
2013/05/03 19:32:43
not obvious why you use mZoomButtonsController her
mnaganov (inactive)
2013/05/07 09:55:44
Yes, that's a strange assymetry. Changed to getZoo
|
| + boolean canZoomIn = mAwContents.canZoomIn(); |
| + boolean canZoomOut = mAwContents.canZoomOut(); |
| + if (!canZoomIn && !canZoomOut) { |
| + // Hide the zoom in and out buttons if the page cannot zoom |
| + mZoomButtonsController.getZoomControls().setVisibility(View.GONE); |
| + } else { |
| + // Set each one individually, as a page may be able to zoom in or out |
| + mZoomButtonsController.setZoomInEnabled(canZoomIn); |
| + mZoomButtonsController.setZoomOutEnabled(canZoomOut); |
|
joth
2013/05/03 19:32:43
how do these settings nest? do we need to call mZ
mnaganov (inactive)
2013/05/07 09:55:44
Visibility and button status are orthogonal. But w
|
| + } |
| + } |
| + |
| + // This method is used in tests. It doesn't modify the state of zoom controls. |
| + View getZoomControlsViewForTest() { |
| + return mZoomButtonsController != null ? mZoomButtonsController.getZoomControls() : null; |
| + } |
| + |
| + private ZoomButtonsController getZoomControls() { |
|
joth
2013/05/03 19:32:43
getZoomController() ? Maybe comment when to use th
mnaganov (inactive)
2013/05/07 09:55:44
Renamed. Added a comment on the field to advice to
|
| + if (mZoomButtonsController == null && |
| + mAwContents.getSettings().shouldDisplayZoomControls()) { |
| + mZoomButtonsController = new ZoomButtonsController( |
| + mAwContents.getContentViewCore().getContainerView()); |
| + mZoomButtonsController.setOnZoomListener(new ZoomListener()); |
| + // ZoomButtonsController positions the buttons at the bottom, but in |
| + // the middle. Change their layout parameters so they appear on the |
| + // right. |
| + View controls = mZoomButtonsController.getZoomControls(); |
| + ViewGroup.LayoutParams params = controls.getLayoutParams(); |
| + if (params instanceof FrameLayout.LayoutParams) { |
| + ((FrameLayout.LayoutParams) params).gravity = Gravity.RIGHT; |
| + } |
| + } |
| + return mZoomButtonsController; |
| + } |
| + |
| + private class ZoomListener implements ZoomButtonsController.OnZoomListener { |
| + @Override |
| + public void onVisibilityChanged(boolean visible) { |
| + if (visible) { |
| + // Bring back the hidden zoom controls. |
| + mZoomButtonsController.getZoomControls().setVisibility(View.VISIBLE); |
| + updateZoomControls(); |
| + } |
| + } |
| + |
| + @Override |
| + public void onZoom(boolean zoomIn) { |
| + if (zoomIn) { |
| + mAwContents.zoomIn(); |
| + } else { |
| + mAwContents.zoomOut(); |
| + } |
| + // ContentView will call updateZoomControls after its current page scale |
| + // is got updated from the native code. |
| + } |
| + } |
| +} |