1 // Copyright 2014 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; 6 7 import android.content.res.Configuration; 8 import android.graphics.Canvas; 9 import android.graphics.Paint; 10 import android.graphics.Rect; 11 import android.os.Bundle; 12 import android.view.DragEvent; 13 import android.view.KeyEvent; 14 import android.view.MotionEvent; 15 import android.view.View; 16 import android.view.accessibility.AccessibilityNodeProvider; 17 import android.view.inputmethod.EditorInfo; 18 import android.view.inputmethod.InputConnection; 19 20 import org.chromium.android_webview.AwContents.InternalAccessDelegate; 21 22 /** 23 * No-op implementation of {@link AwViewMethods} that follows the null object pattern. 24 * This {@link NullAwViewMethods} is hooked up to the WebView in fullscreen mode, and 25 * to the {@link FullScreenView} in embedded mode, but not to both at the same time. 26 */ 27 class NullAwViewMethods implements AwViewMethods { 28 private AwContents mAwContents; 29 private InternalAccessDelegate mInternalAccessAdapter; 30 private View mContainerView; 31 NullAwViewMethods( AwContents awContents, InternalAccessDelegate internalAccessAdapter, View containerView)32 public NullAwViewMethods( 33 AwContents awContents, InternalAccessDelegate internalAccessAdapter, 34 View containerView) { 35 mAwContents = awContents; 36 mInternalAccessAdapter = internalAccessAdapter; 37 mContainerView = containerView; 38 } 39 40 @Override onDraw(Canvas canvas)41 public void onDraw(Canvas canvas) { 42 canvas.drawColor(mAwContents.getEffectiveBackgroundColor()); 43 } 44 45 @Override onMeasure(int widthMeasureSpec, int heightMeasureSpec)46 public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 47 // When the containerView is using the NullAwViewMethods then it is not 48 // attached to the AwContents. As such, we don't have any contents to measure 49 // and using the last measured dimension is the best we can do. 50 mInternalAccessAdapter.setMeasuredDimension( 51 mContainerView.getMeasuredWidth(), mContainerView.getMeasuredHeight()); 52 } 53 54 @Override requestFocus()55 public void requestFocus() { 56 // Intentional no-op. 57 } 58 59 @Override setLayerType(int layerType, Paint paint)60 public void setLayerType(int layerType, Paint paint) { 61 // Intentional no-op. 62 } 63 64 @Override onCreateInputConnection(EditorInfo outAttrs)65 public InputConnection onCreateInputConnection(EditorInfo outAttrs) { 66 return null; // Intentional no-op. 67 } 68 69 @Override onDragEvent(DragEvent event)70 public boolean onDragEvent(DragEvent event) { 71 return false; // Intentional no-op. 72 } 73 @Override onKeyUp(int keyCode, KeyEvent event)74 public boolean onKeyUp(int keyCode, KeyEvent event) { 75 return false; // Intentional no-op. 76 } 77 78 @Override dispatchKeyEvent(KeyEvent event)79 public boolean dispatchKeyEvent(KeyEvent event) { 80 return false; // Intentional no-op. 81 } 82 83 @Override onTouchEvent(MotionEvent event)84 public boolean onTouchEvent(MotionEvent event) { 85 return false; // Intentional no-op. 86 } 87 88 @Override onHoverEvent(MotionEvent event)89 public boolean onHoverEvent(MotionEvent event) { 90 return false; // Intentional no-op. 91 } 92 93 @Override onGenericMotionEvent(MotionEvent event)94 public boolean onGenericMotionEvent(MotionEvent event) { 95 return false; // Intentional no-op. 96 } 97 98 @Override onConfigurationChanged(Configuration newConfig)99 public void onConfigurationChanged(Configuration newConfig) { 100 // Intentional no-op. 101 } 102 103 @Override onAttachedToWindow()104 public void onAttachedToWindow() { 105 // Intentional no-op. 106 } 107 108 @Override onDetachedFromWindow()109 public void onDetachedFromWindow() { 110 // Intentional no-op. 111 } 112 113 @Override onWindowFocusChanged(boolean hasWindowFocus)114 public void onWindowFocusChanged(boolean hasWindowFocus) { 115 // Intentional no-op. 116 } 117 118 @Override onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect)119 public void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) { 120 // Intentional no-op. 121 } 122 123 @Override onSizeChanged(int w, int h, int ow, int oh)124 public void onSizeChanged(int w, int h, int ow, int oh) { 125 // Intentional no-op. 126 } 127 128 @Override onVisibilityChanged(View changedView, int visibility)129 public void onVisibilityChanged(View changedView, int visibility) { 130 // Intentional no-op. 131 } 132 133 @Override onWindowVisibilityChanged(int visibility)134 public void onWindowVisibilityChanged(int visibility) { 135 // Intentional no-op. 136 } 137 138 @Override onContainerViewScrollChanged(int l, int t, int oldl, int oldt)139 public void onContainerViewScrollChanged(int l, int t, int oldl, int oldt) { 140 // Intentional no-op. 141 } 142 143 @Override onContainerViewOverScrolled(int scrollX, int scrollY, boolean clampedX, boolean clampedY)144 public void onContainerViewOverScrolled(int scrollX, int scrollY, boolean clampedX, 145 boolean clampedY) { 146 // Intentional no-op. 147 } 148 149 @Override computeHorizontalScrollRange()150 public int computeHorizontalScrollRange() { 151 return 0; 152 } 153 154 @Override computeHorizontalScrollOffset()155 public int computeHorizontalScrollOffset() { 156 return 0; 157 } 158 159 @Override computeVerticalScrollRange()160 public int computeVerticalScrollRange() { 161 return 0; 162 } 163 164 @Override computeVerticalScrollOffset()165 public int computeVerticalScrollOffset() { 166 return 0; 167 } 168 169 @Override computeVerticalScrollExtent()170 public int computeVerticalScrollExtent() { 171 return 0; 172 } 173 174 @Override computeScroll()175 public void computeScroll() { 176 // Intentional no-op. 177 } 178 179 @Override onCheckIsTextEditor()180 public boolean onCheckIsTextEditor() { 181 return false; 182 } 183 184 @Override getAccessibilityNodeProvider()185 public AccessibilityNodeProvider getAccessibilityNodeProvider() { 186 return null; 187 } 188 189 @Override performAccessibilityAction(final int action, final Bundle arguments)190 public boolean performAccessibilityAction(final int action, final Bundle arguments) { 191 return false; 192 } 193 } 194