• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2010 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy of
6  * the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13  * License for the specific language governing permissions and limitations under
14  * the License.
15  */
16 
17 package com.android.browser;
18 
19 import android.content.Context;
20 import android.graphics.Canvas;
21 import android.util.AttributeSet;
22 import android.view.View;
23 import android.webkit.WebView;
24 
25 import java.util.Map;
26 
27 /**
28  * Manage WebView scroll events
29  */
30 public class BrowserWebView extends WebView {
31 
32     public interface OnScrollChangedListener {
onScrollChanged(int l, int t, int oldl, int oldt)33         void onScrollChanged(int l, int t, int oldl, int oldt);
34     }
35 
36     private boolean mBackgroundRemoved = false;
37     private TitleBar mTitleBar;
38     private OnScrollChangedListener mOnScrollChangedListener;
39 
40     /**
41      * @param context
42      * @param attrs
43      * @param defStyle
44      * @param javascriptInterfaces
45      */
BrowserWebView(Context context, AttributeSet attrs, int defStyle, Map<String, Object> javascriptInterfaces, boolean privateBrowsing)46     public BrowserWebView(Context context, AttributeSet attrs, int defStyle,
47             Map<String, Object> javascriptInterfaces, boolean privateBrowsing) {
48         super(context, attrs, defStyle, javascriptInterfaces, privateBrowsing);
49     }
50 
51     /**
52      * @param context
53      * @param attrs
54      * @param defStyle
55      */
BrowserWebView( Context context, AttributeSet attrs, int defStyle, boolean privateBrowsing)56     public BrowserWebView(
57             Context context, AttributeSet attrs, int defStyle, boolean privateBrowsing) {
58         super(context, attrs, defStyle, privateBrowsing);
59     }
60 
61     /**
62      * @param context
63      * @param attrs
64      */
BrowserWebView(Context context, AttributeSet attrs)65     public BrowserWebView(Context context, AttributeSet attrs) {
66         super(context, attrs);
67     }
68 
69     /**
70      * @param context
71      */
BrowserWebView(Context context)72     public BrowserWebView(Context context) {
73         super(context);
74     }
75 
76     @Override
getTitleHeight()77     protected int getTitleHeight() {
78         return (mTitleBar != null) ? mTitleBar.getEmbeddedHeight() : 0;
79     }
80 
hideEmbeddedTitleBar()81     void hideEmbeddedTitleBar() {
82         scrollBy(0, getVisibleTitleHeight());
83     }
84 
85     @Override
setEmbeddedTitleBar(final View title)86     public void setEmbeddedTitleBar(final View title) {
87         super.setEmbeddedTitleBar(title);
88         mTitleBar = (TitleBar) title;
89     }
90 
hasTitleBar()91     public boolean hasTitleBar() {
92         return (mTitleBar != null);
93     }
94 
95     @Override
onDraw(Canvas c)96     protected void onDraw(Canvas c) {
97         super.onDraw(c);
98         if (!mBackgroundRemoved && getRootView().getBackground() != null) {
99             mBackgroundRemoved = true;
100             post(new Runnable() {
101                 public void run() {
102                     getRootView().setBackgroundDrawable(null);
103                 }
104             });
105         }
106     }
107 
drawContent(Canvas c)108     public void drawContent(Canvas c) {
109         onDraw(c);
110     }
111 
112     @Override
onScrollChanged(int l, int t, int oldl, int oldt)113     protected void onScrollChanged(int l, int t, int oldl, int oldt) {
114         super.onScrollChanged(l, t, oldl, oldt);
115         if (mOnScrollChangedListener != null) {
116             mOnScrollChangedListener.onScrollChanged(l, t, oldl, oldt);
117         }
118     }
119 
setOnScrollChangedListener(OnScrollChangedListener listener)120     public void setOnScrollChangedListener(OnScrollChangedListener listener) {
121         mOnScrollChangedListener = listener;
122     }
123 
124     @Override
showContextMenuForChild(View originalView)125     public boolean showContextMenuForChild(View originalView) {
126         return false;
127     }
128 
129 }
130