| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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.ui.base; | 5 package org.chromium.ui.base; |
| 6 | 6 |
| 7 import android.content.ClipData; | 7 import android.content.ClipData; |
| 8 import android.content.Intent; |
| 8 import android.graphics.Bitmap; | 9 import android.graphics.Bitmap; |
| 9 import android.os.Build; | 10 import android.os.Build; |
| 10 import android.view.View; | 11 import android.view.View; |
| 11 import android.view.ViewGroup; | 12 import android.view.ViewGroup; |
| 12 import android.widget.FrameLayout.LayoutParams; | 13 import android.widget.FrameLayout.LayoutParams; |
| 13 import android.widget.ImageView; | 14 import android.widget.ImageView; |
| 14 | 15 |
| 15 import org.chromium.base.ApiCompatibilityUtils; | 16 import org.chromium.base.ApiCompatibilityUtils; |
| 17 import org.chromium.base.Log; |
| 16 import org.chromium.base.annotations.CalledByNative; | 18 import org.chromium.base.annotations.CalledByNative; |
| 17 import org.chromium.base.annotations.JNINamespace; | 19 import org.chromium.base.annotations.JNINamespace; |
| 18 | 20 |
| 21 import java.net.URISyntaxException; |
| 22 |
| 19 /** | 23 /** |
| 20 * Class to acquire, position, and remove anchor views from the implementing Vie
w. | 24 * Class to acquire, position, and remove anchor views from the implementing Vie
w. |
| 21 */ | 25 */ |
| 22 @JNINamespace("ui") | 26 @JNINamespace("ui") |
| 23 public abstract class ViewAndroidDelegate { | 27 public abstract class ViewAndroidDelegate { |
| 24 | 28 |
| 29 private static final String TAG = "ViewAndroidDelegate"; |
| 30 |
| 25 // TODO(hush): use View#DRAG_FLAG_GLOBAL when Chromium starts to build with
API 24. | 31 // TODO(hush): use View#DRAG_FLAG_GLOBAL when Chromium starts to build with
API 24. |
| 26 private static final int DRAG_FLAG_GLOBAL = 1 << 8; | 32 private static final int DRAG_FLAG_GLOBAL = 1 << 8; |
| 27 | 33 |
| 34 private static final String GEO_SCHEME = "geo"; |
| 35 private static final String TEL_SCHEME = "tel"; |
| 36 private static final String MAILTO_SCHEME = "mailto"; |
| 37 |
| 28 /** | 38 /** |
| 29 * @return An anchor view that can be used to anchor decoration views like A
utofill popup. | 39 * @return An anchor view that can be used to anchor decoration views like A
utofill popup. |
| 30 */ | 40 */ |
| 31 @CalledByNative | 41 @CalledByNative |
| 32 public View acquireView() { | 42 public View acquireView() { |
| 33 ViewGroup containerView = getContainerView(); | 43 ViewGroup containerView = getContainerView(); |
| 34 if (containerView == null || containerView.getParent() == null) return n
ull; | 44 if (containerView == null || containerView.getParent() == null) return n
ull; |
| 35 View anchorView = new View(containerView.getContext()); | 45 View anchorView = new View(containerView.getContext()); |
| 36 containerView.addView(anchorView); | 46 containerView.addView(anchorView); |
| 37 return anchorView; | 47 return anchorView; |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 ImageView imageView = new ImageView(containerView.getContext()); | 108 ImageView imageView = new ImageView(containerView.getContext()); |
| 99 imageView.setImageBitmap(shadowImage); | 109 imageView.setImageBitmap(shadowImage); |
| 100 imageView.layout(0, 0, shadowImage.getWidth(), shadowImage.getHeight()); | 110 imageView.layout(0, 0, shadowImage.getWidth(), shadowImage.getHeight()); |
| 101 | 111 |
| 102 // TODO(hush): use View#startDragAndDrop when Chromium starts to build w
ith API 24. | 112 // TODO(hush): use View#startDragAndDrop when Chromium starts to build w
ith API 24. |
| 103 return containerView.startDrag(ClipData.newPlainText(null, text), | 113 return containerView.startDrag(ClipData.newPlainText(null, text), |
| 104 new View.DragShadowBuilder(imageView), null, DRAG_FLAG_GLOBAL); | 114 new View.DragShadowBuilder(imageView), null, DRAG_FLAG_GLOBAL); |
| 105 } | 115 } |
| 106 | 116 |
| 107 /** | 117 /** |
| 118 * Called whenever the background color of the page changes as notified by B
link. |
| 119 * @param color The new ARGB color of the page background. |
| 120 */ |
| 121 @CalledByNative |
| 122 public void onBackgroundColorChanged(int color) {} |
| 123 |
| 124 /** |
| 125 * Notify the client of the position of the top controls. |
| 126 * @param topControlsOffsetY The Y offset of the top controls in physical pi
xels. |
| 127 * @param topContentOffsetY The Y offset of the content in physical pixels. |
| 128 */ |
| 129 @CalledByNative |
| 130 public void onTopControlsChanged(float topControlsOffsetY, float topContentO
ffsetY) {} |
| 131 |
| 132 /** |
| 133 * Notify the client of the position of the bottom controls. |
| 134 * @param bottomControlsOffsetY The Y offset of the bottom controls in physi
cal pixels. |
| 135 * @param bottomContentOffsetY The Y offset of the content in physical pixel
s. |
| 136 */ |
| 137 @CalledByNative |
| 138 public void onBottomControlsChanged(float bottomControlsOffsetY, float botto
mContentOffsetY) {} |
| 139 |
| 140 /** |
| 141 * Called when a new content intent is requested to be started. |
| 142 * Invokes {@link #startContentIntent(Intent, String, boolean)} only if the
parsed |
| 143 * intent is valid and the scheme is acceptable. |
| 144 */ |
| 145 @CalledByNative |
| 146 private void onStartContentIntent(String intentUrl, boolean isMainFrame) { |
| 147 Intent intent; |
| 148 try { |
| 149 intent = Intent.parseUri(intentUrl, Intent.URI_INTENT_SCHEME); |
| 150 } catch (URISyntaxException e) { |
| 151 Log.d(TAG, "Bad URI %s", intentUrl, e); |
| 152 return; |
| 153 } |
| 154 String scheme = intent.getScheme(); |
| 155 if (!(GEO_SCHEME.equals(scheme) || TEL_SCHEME.equals(scheme) |
| 156 || MAILTO_SCHEME.equals(scheme))) { |
| 157 Log.d(TAG, "Invalid scheme for URI %s", intentUrl); |
| 158 return; |
| 159 } |
| 160 startContentIntent(intent, intentUrl, isMainFrame); |
| 161 } |
| 162 |
| 163 /** |
| 164 * Start a new content intent. |
| 165 */ |
| 166 public void startContentIntent(Intent intent, String intentUrl, boolean isMa
inFrame) {} |
| 167 |
| 168 /** |
| 108 * @return container view that the anchor views are added to. May be null. | 169 * @return container view that the anchor views are added to. May be null. |
| 109 */ | 170 */ |
| 110 @CalledByNative | 171 @CalledByNative |
| 111 public abstract ViewGroup getContainerView(); | 172 public abstract ViewGroup getContainerView(); |
| 112 | 173 |
| 113 /** | 174 /** |
| 114 * Create and return a basic implementation of {@link ViewAndroidDelegate} w
here | 175 * Create and return a basic implementation of {@link ViewAndroidDelegate} w
here |
| 115 * the container view is not allowed to be changed after initialization. | 176 * the container view is not allowed to be changed after initialization. |
| 116 * @param containerView {@link ViewGroup} to be used as a container view. | 177 * @param containerView {@link ViewGroup} to be used as a container view. |
| 117 * @return a new instance of {@link ViewAndroidDelegate}. | 178 * @return a new instance of {@link ViewAndroidDelegate}. |
| 118 */ | 179 */ |
| 119 public static ViewAndroidDelegate createBasicDelegate(ViewGroup containerVie
w) { | 180 public static ViewAndroidDelegate createBasicDelegate(ViewGroup containerVie
w) { |
| 120 return new ViewAndroidDelegate() { | 181 return new ViewAndroidDelegate() { |
| 121 private ViewGroup mContainerView; | 182 private ViewGroup mContainerView; |
| 122 | 183 |
| 123 private ViewAndroidDelegate init(ViewGroup containerView) { | 184 private ViewAndroidDelegate init(ViewGroup containerView) { |
| 124 mContainerView = containerView; | 185 mContainerView = containerView; |
| 125 return this; | 186 return this; |
| 126 } | 187 } |
| 127 | 188 |
| 128 @Override | 189 @Override |
| 129 public ViewGroup getContainerView() { | 190 public ViewGroup getContainerView() { |
| 130 return mContainerView; | 191 return mContainerView; |
| 131 } | 192 } |
| 132 }.init(containerView); | 193 }.init(containerView); |
| 133 } | 194 } |
| 134 } | 195 } |
| OLD | NEW |