Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / android_webview / test / shell / src / org / chromium / android_webview / test / AwTestContainerView.java
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.
4
5 package org.chromium.android_webview.test;
6
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;
21
22 import org.chromium.android_webview.AwContents;
23 import org.chromium.content.browser.ContentViewCore;
24
25 /**
26  * A View used for testing the AwContents internals.
27  *
28  * This class takes the place android.webkit.WebView would have in the production configuration.
29  */
30 public class AwTestContainerView extends FrameLayout {
31     private AwContents mAwContents;
32     private AwContents.InternalAccessDelegate mInternalAccessDelegate;
33
34     public AwTestContainerView(Context context) {
35         super(context);
36         mInternalAccessDelegate = new InternalAccessAdapter();
37         setOverScrollMode(View.OVER_SCROLL_ALWAYS);
38         setFocusable(true);
39         setFocusableInTouchMode(true);
40     }
41
42     public void initialize(AwContents awContents) {
43         mAwContents = awContents;
44     }
45
46     public ContentViewCore getContentViewCore() {
47         return mAwContents.getContentViewCore();
48     }
49
50     public AwContents getAwContents() {
51         return mAwContents;
52     }
53
54     public AwContents.InternalAccessDelegate getInternalAccessDelegate() {
55         return mInternalAccessDelegate;
56     }
57
58     public void destroy() {
59         mAwContents.destroy();
60     }
61
62     @Override
63     public void onConfigurationChanged(Configuration newConfig) {
64         super.onConfigurationChanged(newConfig);
65         mAwContents.onConfigurationChanged(newConfig);
66     }
67
68     @Override
69     public void onAttachedToWindow() {
70         super.onAttachedToWindow();
71         mAwContents.onAttachedToWindow();
72     }
73
74     @Override
75     public void onDetachedFromWindow() {
76         super.onDetachedFromWindow();
77         mAwContents.onDetachedFromWindow();
78     }
79
80     @Override
81     public void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) {
82         super.onFocusChanged(focused, direction, previouslyFocusedRect);
83         mAwContents.onFocusChanged(focused, direction, previouslyFocusedRect);
84     }
85
86     @Override
87     public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
88         return mAwContents.onCreateInputConnection(outAttrs);
89     }
90
91     @Override
92     public boolean onKeyUp(int keyCode, KeyEvent event) {
93         return mAwContents.onKeyUp(keyCode, event);
94     }
95
96     @Override
97     public boolean dispatchKeyEvent(KeyEvent event) {
98         return mAwContents.dispatchKeyEvent(event);
99     }
100
101     @Override
102     public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
103         mAwContents.onMeasure(widthMeasureSpec, heightMeasureSpec);
104     }
105
106     @Override
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);
110     }
111
112     @Override
113     public void onOverScrolled(int scrollX, int scrollY, boolean clampedX, boolean clampedY) {
114         mAwContents.onContainerViewOverScrolled(scrollX, scrollY, clampedX, clampedY);
115     }
116
117     @Override
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);
122         }
123     }
124
125     @Override
126     public void computeScroll() {
127         mAwContents.computeScroll();
128     }
129
130     @Override
131     public void onVisibilityChanged(View changedView, int visibility) {
132         super.onVisibilityChanged(changedView, visibility);
133         mAwContents.onVisibilityChanged(changedView, visibility);
134     }
135
136     @Override
137     public void onWindowVisibilityChanged(int visibility) {
138         super.onWindowVisibilityChanged(visibility);
139         mAwContents.onWindowVisibilityChanged(visibility);
140     }
141
142     @Override
143     public boolean onTouchEvent(MotionEvent ev) {
144         super.onTouchEvent(ev);
145         return mAwContents.onTouchEvent(ev);
146     }
147
148     @Override
149     public void onDraw(Canvas canvas) {
150         mAwContents.onDraw(canvas);
151         super.onDraw(canvas);
152     }
153
154     @Override
155     public AccessibilityNodeProvider getAccessibilityNodeProvider() {
156         AccessibilityNodeProvider provider =
157             mAwContents.getAccessibilityNodeProvider();
158         return provider == null ? super.getAccessibilityNodeProvider() : provider;
159     }
160
161     @Override
162     public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
163         super.onInitializeAccessibilityNodeInfo(info);
164         info.setClassName(AwContents.class.getName());
165         mAwContents.onInitializeAccessibilityNodeInfo(info);
166     }
167
168     @Override
169     public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
170         super.onInitializeAccessibilityEvent(event);
171         event.setClassName(AwContents.class.getName());
172         mAwContents.onInitializeAccessibilityEvent(event);
173     }
174
175     @Override
176     public boolean performAccessibilityAction(int action, Bundle arguments) {
177         return mAwContents.performAccessibilityAction(action, arguments);
178     }
179
180     // TODO: AwContents could define a generic class that holds an implementation similar to
181     // the one below.
182     private class InternalAccessAdapter implements AwContents.InternalAccessDelegate {
183
184         @Override
185         public boolean drawChild(Canvas canvas, View child, long drawingTime) {
186             return AwTestContainerView.super.drawChild(canvas, child, drawingTime);
187         }
188
189         @Override
190         public boolean super_onKeyUp(int keyCode, KeyEvent event) {
191             return AwTestContainerView.super.onKeyUp(keyCode, event);
192         }
193
194         @Override
195         public boolean super_dispatchKeyEventPreIme(KeyEvent event) {
196             return AwTestContainerView.super.dispatchKeyEventPreIme(event);
197         }
198
199         @Override
200         public boolean super_dispatchKeyEvent(KeyEvent event) {
201             return AwTestContainerView.super.dispatchKeyEvent(event);
202         }
203
204         @Override
205         public boolean super_onGenericMotionEvent(MotionEvent event) {
206             return AwTestContainerView.super.onGenericMotionEvent(event);
207         }
208
209         @Override
210         public void super_onConfigurationChanged(Configuration newConfig) {
211             AwTestContainerView.super.onConfigurationChanged(newConfig);
212         }
213
214         @Override
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);
218         }
219
220         @Override
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);
229         }
230
231         @Override
232         public void onScrollChanged(int l, int t, int oldl, int oldt) {
233             AwTestContainerView.super.onScrollChanged(l, t, oldl, oldt);
234         }
235
236         @Override
237         public boolean awakenScrollBars() {
238             return AwTestContainerView.super.awakenScrollBars();
239         }
240
241         @Override
242         public boolean super_awakenScrollBars(int startDelay, boolean invalidate) {
243             return AwTestContainerView.super.awakenScrollBars(startDelay, invalidate);
244         }
245
246         @Override
247         public void setMeasuredDimension(int measuredWidth, int measuredHeight) {
248             AwTestContainerView.super.setMeasuredDimension(measuredWidth, measuredHeight);
249         }
250
251         @Override
252         public int super_getScrollBarStyle() {
253             return AwTestContainerView.super.getScrollBarStyle();
254         }
255
256         @Override
257         public boolean requestDrawGL(Canvas canvas, boolean waitForCompletion) {
258             return false;
259         }
260     }
261 }