blob: 8ea112335396a1247b294e10647a937b650a8bc2 [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
17package com.android.browser;
18
19import android.content.Context;
20import android.util.AttributeSet;
21import android.view.View;
22import android.webkit.WebView;
23
24import java.util.Map;
25
26/**
Michael Kolb377ea312011-02-17 14:36:56 -080027 * Manage WebView scroll events
Michael Kolba2b2ba82010-08-04 17:54:03 -070028 */
Michael Kolbb14ff2f2011-07-01 15:33:56 -070029public class BrowserWebView extends WebView {
Michael Kolba2b2ba82010-08-04 17:54:03 -070030
Romain Guy860662a2011-01-10 12:57:22 -080031 private boolean mBackgroundRemoved = false;
John Reck0f602f32011-07-07 15:38:43 -070032 private TitleBar mTitleBar;
Michael Kolba2b2ba82010-08-04 17:54:03 -070033
34 /**
35 * @param context
36 * @param attrs
37 * @param defStyle
38 * @param javascriptInterfaces
39 */
John Reckb9a051b2011-03-18 11:55:48 -070040 public BrowserWebView(Context context, AttributeSet attrs, int defStyle,
Michael Kolba2b2ba82010-08-04 17:54:03 -070041 Map<String, Object> javascriptInterfaces, boolean privateBrowsing) {
42 super(context, attrs, defStyle, javascriptInterfaces, privateBrowsing);
43 }
44
45 /**
46 * @param context
47 * @param attrs
48 * @param defStyle
49 */
John Reckb9a051b2011-03-18 11:55:48 -070050 public BrowserWebView(
Michael Kolb377ea312011-02-17 14:36:56 -080051 Context context, AttributeSet attrs, int defStyle, boolean privateBrowsing) {
Michael Kolba2b2ba82010-08-04 17:54:03 -070052 super(context, attrs, defStyle, privateBrowsing);
53 }
54
55 /**
56 * @param context
57 * @param attrs
58 */
John Reckb9a051b2011-03-18 11:55:48 -070059 public BrowserWebView(Context context, AttributeSet attrs) {
Michael Kolba2b2ba82010-08-04 17:54:03 -070060 super(context, attrs);
61 }
62
63 /**
64 * @param context
65 */
John Reckb9a051b2011-03-18 11:55:48 -070066 public BrowserWebView(Context context) {
Michael Kolba2b2ba82010-08-04 17:54:03 -070067 super(context);
Michael Kolb2814a362011-05-19 15:49:41 -070068 }
69
Michael Kolb08a687a2011-04-22 16:13:02 -070070 @Override
Michael Kolb29ccf8a2011-02-23 16:13:24 -080071 protected int getTitleHeight() {
72 return (mTitleBar != null) ? mTitleBar.getEmbeddedHeight() : 0;
73 }
74
Michael Kolbed217742010-08-10 17:52:34 -070075 void hideEmbeddedTitleBar() {
76 scrollBy(0, getVisibleTitleHeight());
77 }
78
Michael Kolba2b2ba82010-08-04 17:54:03 -070079 @Override
80 public void setEmbeddedTitleBar(final View title) {
81 super.setEmbeddedTitleBar(title);
John Reck0f602f32011-07-07 15:38:43 -070082 mTitleBar = (TitleBar) title;
Michael Kolba2b2ba82010-08-04 17:54:03 -070083 }
84
Michael Kolb377ea312011-02-17 14:36:56 -080085 public boolean hasTitleBar() {
86 return (mTitleBar != null);
87 }
88
Michael Kolb377ea312011-02-17 14:36:56 -080089 @Override
90 protected void onDraw(android.graphics.Canvas c) {
Michael Kolbf2628922011-03-09 17:15:28 -080091 super.onDraw(c);
92 if (!mBackgroundRemoved && getRootView().getBackground() != null) {
93 mBackgroundRemoved = true;
94 post(new Runnable() {
95 public void run() {
96 getRootView().setBackgroundDrawable(null);
97 }
98 });
Michael Kolb377ea312011-02-17 14:36:56 -080099 }
100 }
101
John Reck378a4102011-06-09 16:23:01 -0700102 @Override
103 protected void updateCachedTextfield(String updatedText) {
104 super.updateCachedTextfield(updatedText);
105 CrashRecoveryHandler handler = CrashRecoveryHandler.getInstance();
106 if (handler != null) {
107 handler.backupState();
108 }
109 }
110
Michael Kolba2b2ba82010-08-04 17:54:03 -0700111}