Home | History | Annotate | Download | only in android_webview
      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.view.KeyEvent;
     12 import android.view.MotionEvent;
     13 import android.view.View;
     14 import android.view.inputmethod.EditorInfo;
     15 import android.view.inputmethod.InputConnection;
     16 
     17 import org.chromium.android_webview.AwContents.InternalAccessDelegate;
     18 
     19 /**
     20  * No-op implementation of {@link AwViewMethods} that follows the null object pattern.
     21  * This {@link NullAwViewMethods} is hooked up to the WebView in fullscreen mode, and
     22  * to the {@link FullScreenView} in embedded mode, but not to both at the same time.
     23  */
     24 class NullAwViewMethods implements AwViewMethods {
     25     private AwContents mAwContents;
     26     private InternalAccessDelegate mInternalAccessAdapter;
     27     private View mContainerView;
     28 
     29     public NullAwViewMethods(
     30             AwContents awContents, InternalAccessDelegate internalAccessAdapter,
     31             View containerView) {
     32         mAwContents = awContents;
     33         mInternalAccessAdapter = internalAccessAdapter;
     34         mContainerView = containerView;
     35     }
     36 
     37     @Override
     38     public void onDraw(Canvas canvas) {
     39         canvas.drawColor(mAwContents.getEffectiveBackgroundColor());
     40     }
     41 
     42     @Override
     43     public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
     44         // When the containerView is using the NullAwViewMethods then it is not
     45         // attached to the AwContents. As such, we don't have any contents to measure
     46         // and using the last measured dimension is the best we can do.
     47         mInternalAccessAdapter.setMeasuredDimension(
     48                 mContainerView.getMeasuredWidth(), mContainerView.getMeasuredHeight());
     49     }
     50 
     51     @Override
     52     public void requestFocus() {
     53         // Intentional no-op.
     54     }
     55 
     56     @Override
     57     public void setLayerType(int layerType, Paint paint) {
     58         // Intentional no-op.
     59     }
     60 
     61     @Override
     62     public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
     63         return null; // Intentional no-op.
     64     }
     65 
     66     @Override
     67     public boolean onKeyUp(int keyCode, KeyEvent event) {
     68         return false; // Intentional no-op.
     69     }
     70 
     71     @Override
     72     public boolean dispatchKeyEvent(KeyEvent event) {
     73         return false; // Intentional no-op.
     74     }
     75 
     76     @Override
     77     public boolean onTouchEvent(MotionEvent event) {
     78         return false; // Intentional no-op.
     79     }
     80 
     81     @Override
     82     public boolean onHoverEvent(MotionEvent event) {
     83         return false; // Intentional no-op.
     84     }
     85 
     86     @Override
     87     public boolean onGenericMotionEvent(MotionEvent event) {
     88         return false; // Intentional no-op.
     89     }
     90 
     91     @Override
     92     public void onConfigurationChanged(Configuration newConfig) {
     93         // Intentional no-op.
     94     }
     95 
     96     @Override
     97     public void onAttachedToWindow() {
     98         // Intentional no-op.
     99     }
    100 
    101     @Override
    102     public void onDetachedFromWindow() {
    103         // Intentional no-op.
    104     }
    105 
    106     @Override
    107     public void onWindowFocusChanged(boolean hasWindowFocus) {
    108         // Intentional no-op.
    109     }
    110 
    111     @Override
    112     public void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) {
    113         // Intentional no-op.
    114     }
    115 
    116     @Override
    117     public void onSizeChanged(int w, int h, int ow, int oh) {
    118         // Intentional no-op.
    119     }
    120 
    121     @Override
    122     public void onVisibilityChanged(View changedView, int visibility) {
    123         // Intentional no-op.
    124     }
    125 
    126     @Override
    127     public void onWindowVisibilityChanged(int visibility) {
    128         // Intentional no-op.
    129     }
    130 }
    131