blob: 5d71ce30571dee708a5aff938ea799a768085bf0 [file] [log] [blame]
Michael Kolba2b2ba82010-08-04 17:54:03 -07001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
Michael Kolb377ea312011-02-17 14:36:56 -08004 * 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
Michael Kolba2b2ba82010-08-04 17:54:03 -07007 *
Michael Kolb377ea312011-02-17 14:36:56 -08008 * http://www.apache.org/licenses/LICENSE-2.0
Michael Kolba2b2ba82010-08-04 17:54:03 -07009 *
10 * Unless required by applicable law or agreed to in writing, software
Michael Kolb377ea312011-02-17 14:36:56 -080011 * 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.
Michael Kolba2b2ba82010-08-04 17:54:03 -070015 */
16
Bijan Amirzada41242f22014-03-21 12:12:18 -070017package com.android.browser;
Michael Kolba2b2ba82010-08-04 17:54:03 -070018
19import android.content.Context;
John Reck8ee633f2011-08-09 16:00:35 -070020import android.graphics.Canvas;
Michael Kolba2b2ba82010-08-04 17:54:03 -070021import android.util.AttributeSet;
22import android.view.View;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080023import org.codeaurora.swe.WebChromeClient;
24import org.codeaurora.swe.WebView;
25import org.codeaurora.swe.WebViewClient;
Michael Kolba2b2ba82010-08-04 17:54:03 -070026
27import java.util.Map;
28
29/**
Michael Kolb377ea312011-02-17 14:36:56 -080030 * Manage WebView scroll events
Michael Kolba2b2ba82010-08-04 17:54:03 -070031 */
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080032public class BrowserWebView extends WebView implements WebView.TitleBarDelegate {
Michael Kolba2b2ba82010-08-04 17:54:03 -070033
John Reck718a24d2011-08-12 11:08:30 -070034 public interface OnScrollChangedListener {
35 void onScrollChanged(int l, int t, int oldl, int oldt);
36 }
37
Romain Guy860662a2011-01-10 12:57:22 -080038 private boolean mBackgroundRemoved = false;
John Reck0f602f32011-07-07 15:38:43 -070039 private TitleBar mTitleBar;
John Reck718a24d2011-08-12 11:08:30 -070040 private OnScrollChangedListener mOnScrollChangedListener;
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -080041 private WebChromeClient mWebChromeClient;
42 private WebViewClient mWebViewClient;
Michael Kolba2b2ba82010-08-04 17:54:03 -070043
44 /**
45 * @param context
46 * @param attrs
47 * @param defStyle
48 * @param javascriptInterfaces
49 */
John Reckb9a051b2011-03-18 11:55:48 -070050 public BrowserWebView(Context context, AttributeSet attrs, int defStyle,
Michael Kolba2b2ba82010-08-04 17:54:03 -070051 Map<String, Object> javascriptInterfaces, boolean privateBrowsing) {
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080052 super(context, attrs, defStyle, privateBrowsing);
53 this.setJavascriptInterfaces(javascriptInterfaces);
Michael Kolba2b2ba82010-08-04 17:54:03 -070054 }
55
56 /**
57 * @param context
58 * @param attrs
59 * @param defStyle
60 */
John Reckb9a051b2011-03-18 11:55:48 -070061 public BrowserWebView(
Michael Kolb377ea312011-02-17 14:36:56 -080062 Context context, AttributeSet attrs, int defStyle, boolean privateBrowsing) {
Michael Kolba2b2ba82010-08-04 17:54:03 -070063 super(context, attrs, defStyle, privateBrowsing);
64 }
65
66 /**
67 * @param context
68 * @param attrs
69 */
John Reckb9a051b2011-03-18 11:55:48 -070070 public BrowserWebView(Context context, AttributeSet attrs) {
Michael Kolba2b2ba82010-08-04 17:54:03 -070071 super(context, attrs);
72 }
73
74 /**
75 * @param context
76 */
John Reckb9a051b2011-03-18 11:55:48 -070077 public BrowserWebView(Context context) {
Michael Kolba2b2ba82010-08-04 17:54:03 -070078 super(context);
Michael Kolb2814a362011-05-19 15:49:41 -070079 }
80
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -080081 @Override
82 public void setWebChromeClient(WebChromeClient client) {
83 mWebChromeClient = client;
84 super.setWebChromeClient(client);
85 }
86
87 public WebChromeClient getWebChromeClient() {
88 return mWebChromeClient;
89 }
90
91 @Override
92 public void setWebViewClient(WebViewClient client) {
93 mWebViewClient = client;
94 super.setWebViewClient(client);
95 }
96
97 public WebViewClient getWebViewClient() {
98 return mWebViewClient;
99 }
100
Michael Kolb4923c222012-04-02 16:18:36 -0700101 public void setTitleBar(TitleBar title) {
102 mTitleBar = title;
103 }
104
Jonathan Dixon4d2fcab2012-02-24 00:13:06 +0000105 // From TitleBarDelegate
Michael Kolb08a687a2011-04-22 16:13:02 -0700106 @Override
Jonathan Dixon4d2fcab2012-02-24 00:13:06 +0000107 public int getTitleHeight() {
Michael Kolb29ccf8a2011-02-23 16:13:24 -0800108 return (mTitleBar != null) ? mTitleBar.getEmbeddedHeight() : 0;
109 }
110
Jonathan Dixon4d2fcab2012-02-24 00:13:06 +0000111 // From TitleBarDelegate
Michael Kolba2b2ba82010-08-04 17:54:03 -0700112 @Override
Jonathan Dixon4d2fcab2012-02-24 00:13:06 +0000113 public void onSetEmbeddedTitleBar(final View title) {
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800114 // TODO: Remove this method; it is never invoked.
Michael Kolba2b2ba82010-08-04 17:54:03 -0700115 }
116
Michael Kolb377ea312011-02-17 14:36:56 -0800117 public boolean hasTitleBar() {
118 return (mTitleBar != null);
119 }
120
Michael Kolb377ea312011-02-17 14:36:56 -0800121 @Override
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800122 public void onDraw(Canvas c) {
Michael Kolbf2628922011-03-09 17:15:28 -0800123 super.onDraw(c);
124 if (!mBackgroundRemoved && getRootView().getBackground() != null) {
125 mBackgroundRemoved = true;
126 post(new Runnable() {
127 public void run() {
128 getRootView().setBackgroundDrawable(null);
129 }
130 });
Michael Kolb377ea312011-02-17 14:36:56 -0800131 }
132 }
133
John Reck8ee633f2011-08-09 16:00:35 -0700134 public void drawContent(Canvas c) {
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800135 //super.drawContent(c);
John Reck8ee633f2011-08-09 16:00:35 -0700136 }
137
John Reck718a24d2011-08-12 11:08:30 -0700138 @Override
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800139 public void onScrollChanged(int l, int t, int oldl, int oldt) {
John Reck718a24d2011-08-12 11:08:30 -0700140 super.onScrollChanged(l, t, oldl, oldt);
Michael Kolb4923c222012-04-02 16:18:36 -0700141 if (mTitleBar != null) {
142 mTitleBar.onScrollChanged();
143 }
John Reck718a24d2011-08-12 11:08:30 -0700144 if (mOnScrollChangedListener != null) {
145 mOnScrollChangedListener.onScrollChanged(l, t, oldl, oldt);
146 }
147 }
148
149 public void setOnScrollChangedListener(OnScrollChangedListener listener) {
150 mOnScrollChangedListener = listener;
151 }
152
John Reckbd546312011-09-19 11:47:52 -0700153 @Override
154 public boolean showContextMenuForChild(View originalView) {
155 return false;
156 }
157
John Reckd1d87312012-03-08 13:25:00 -0800158 @Override
159 public void destroy() {
160 BrowserSettings.getInstance().stopManagingSettings(getSettings());
161 super.destroy();
162 }
163
Michael Kolba2b2ba82010-08-04 17:54:03 -0700164}