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
3 // found in the LICENSE file.
5 package org.chromium.android_webview.test;
7 import android.content.Context;
8 import android.content.res.Configuration;
9 import android.graphics.Canvas;
10 import android.graphics.Rect;
11 import android.os.Bundle;
12 import android.view.KeyEvent;
13 import android.view.MotionEvent;
14 import android.view.View;
15 import android.view.accessibility.AccessibilityEvent;
16 import android.view.accessibility.AccessibilityNodeInfo;
17 import android.view.accessibility.AccessibilityNodeProvider;
18 import android.view.inputmethod.EditorInfo;
19 import android.view.inputmethod.InputConnection;
20 import android.widget.FrameLayout;
22 import org.chromium.android_webview.AwContents;
23 import org.chromium.content.browser.ContentViewCore;
26 * A View used for testing the AwContents internals.
28 * This class takes the place android.webkit.WebView would have in the production configuration.
30 public class AwTestContainerView extends FrameLayout {
31 private AwContents mAwContents;
32 private AwContents.InternalAccessDelegate mInternalAccessDelegate;
34 public AwTestContainerView(Context context) {
36 mInternalAccessDelegate = new InternalAccessAdapter();
37 setOverScrollMode(View.OVER_SCROLL_ALWAYS);
39 setFocusableInTouchMode(true);
42 public void initialize(AwContents awContents) {
43 mAwContents = awContents;
46 public ContentViewCore getContentViewCore() {
47 return mAwContents.getContentViewCore();
50 public AwContents getAwContents() {
54 public AwContents.InternalAccessDelegate getInternalAccessDelegate() {
55 return mInternalAccessDelegate;
58 public void destroy() {
59 mAwContents.destroy();
63 public void onConfigurationChanged(Configuration newConfig) {
64 super.onConfigurationChanged(newConfig);
65 mAwContents.onConfigurationChanged(newConfig);
69 public void onAttachedToWindow() {
70 super.onAttachedToWindow();
71 mAwContents.onAttachedToWindow();
75 public void onDetachedFromWindow() {
76 super.onDetachedFromWindow();
77 mAwContents.onDetachedFromWindow();
81 public void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) {
82 super.onFocusChanged(focused, direction, previouslyFocusedRect);
83 mAwContents.onFocusChanged(focused, direction, previouslyFocusedRect);
87 public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
88 return mAwContents.onCreateInputConnection(outAttrs);
92 public boolean onKeyUp(int keyCode, KeyEvent event) {
93 return mAwContents.onKeyUp(keyCode, event);
97 public boolean dispatchKeyEvent(KeyEvent event) {
98 return mAwContents.dispatchKeyEvent(event);
102 public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
103 mAwContents.onMeasure(widthMeasureSpec, heightMeasureSpec);
107 public void onSizeChanged(int w, int h, int ow, int oh) {
108 super.onSizeChanged(w, h, ow, oh);
109 mAwContents.onSizeChanged(w, h, ow, oh);
113 public void onOverScrolled(int scrollX, int scrollY, boolean clampedX, boolean clampedY) {
114 mAwContents.onContainerViewOverScrolled(scrollX, scrollY, clampedX, clampedY);
118 public void onScrollChanged(int l, int t, int oldl, int oldt) {
119 super.onScrollChanged(l, t, oldl, oldt);
120 if (mAwContents != null) {
121 mAwContents.onContainerViewScrollChanged(l, t, oldl, oldt);
126 public void computeScroll() {
127 mAwContents.computeScroll();
131 public void onVisibilityChanged(View changedView, int visibility) {
132 super.onVisibilityChanged(changedView, visibility);
133 mAwContents.onVisibilityChanged(changedView, visibility);
137 public void onWindowVisibilityChanged(int visibility) {
138 super.onWindowVisibilityChanged(visibility);
139 mAwContents.onWindowVisibilityChanged(visibility);
143 public boolean onTouchEvent(MotionEvent ev) {
144 super.onTouchEvent(ev);
145 return mAwContents.onTouchEvent(ev);
149 public void onDraw(Canvas canvas) {
150 mAwContents.onDraw(canvas);
151 super.onDraw(canvas);
155 public AccessibilityNodeProvider getAccessibilityNodeProvider() {
156 AccessibilityNodeProvider provider =
157 mAwContents.getAccessibilityNodeProvider();
158 return provider == null ? super.getAccessibilityNodeProvider() : provider;
162 public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
163 super.onInitializeAccessibilityNodeInfo(info);
164 info.setClassName(AwContents.class.getName());
165 mAwContents.onInitializeAccessibilityNodeInfo(info);
169 public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
170 super.onInitializeAccessibilityEvent(event);
171 event.setClassName(AwContents.class.getName());
172 mAwContents.onInitializeAccessibilityEvent(event);
176 public boolean performAccessibilityAction(int action, Bundle arguments) {
177 return mAwContents.performAccessibilityAction(action, arguments);
180 // TODO: AwContents could define a generic class that holds an implementation similar to
182 private class InternalAccessAdapter implements AwContents.InternalAccessDelegate {
185 public boolean drawChild(Canvas canvas, View child, long drawingTime) {
186 return AwTestContainerView.super.drawChild(canvas, child, drawingTime);
190 public boolean super_onKeyUp(int keyCode, KeyEvent event) {
191 return AwTestContainerView.super.onKeyUp(keyCode, event);
195 public boolean super_dispatchKeyEventPreIme(KeyEvent event) {
196 return AwTestContainerView.super.dispatchKeyEventPreIme(event);
200 public boolean super_dispatchKeyEvent(KeyEvent event) {
201 return AwTestContainerView.super.dispatchKeyEvent(event);
205 public boolean super_onGenericMotionEvent(MotionEvent event) {
206 return AwTestContainerView.super.onGenericMotionEvent(event);
210 public void super_onConfigurationChanged(Configuration newConfig) {
211 AwTestContainerView.super.onConfigurationChanged(newConfig);
215 public void super_scrollTo(int scrollX, int scrollY) {
216 // We're intentionally not calling super.scrollTo here to make testing easier.
217 AwTestContainerView.this.scrollTo(scrollX, scrollY);
221 public void overScrollBy(int deltaX, int deltaY,
222 int scrollX, int scrollY,
223 int scrollRangeX, int scrollRangeY,
224 int maxOverScrollX, int maxOverScrollY,
225 boolean isTouchEvent) {
226 // We're intentionally not calling super.scrollTo here to make testing easier.
227 AwTestContainerView.this.overScrollBy(deltaX, deltaY, scrollX, scrollY,
228 scrollRangeX, scrollRangeY, maxOverScrollX, maxOverScrollY, isTouchEvent);
232 public void onScrollChanged(int l, int t, int oldl, int oldt) {
233 AwTestContainerView.super.onScrollChanged(l, t, oldl, oldt);
237 public boolean awakenScrollBars() {
238 return AwTestContainerView.super.awakenScrollBars();
242 public boolean super_awakenScrollBars(int startDelay, boolean invalidate) {
243 return AwTestContainerView.super.awakenScrollBars(startDelay, invalidate);
247 public void setMeasuredDimension(int measuredWidth, int measuredHeight) {
248 AwTestContainerView.super.setMeasuredDimension(measuredWidth, measuredHeight);
252 public int super_getScrollBarStyle() {
253 return AwTestContainerView.super.getScrollBarStyle();
257 public boolean requestDrawGL(Canvas canvas, boolean waitForCompletion) {