Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 The Android Open Source Project |
| 3 | * |
Michael Kolb | 377ea31 | 2011-02-17 14:36:56 -0800 | [diff] [blame] | 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 |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 7 | * |
Michael Kolb | 377ea31 | 2011-02-17 14:36:56 -0800 | [diff] [blame] | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
Michael Kolb | 377ea31 | 2011-02-17 14:36:56 -0800 | [diff] [blame] | 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. |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | package com.android.browser; |
| 18 | |
| 19 | import android.content.Context; |
| 20 | import android.util.AttributeSet; |
| 21 | import android.view.View; |
| 22 | import android.webkit.WebView; |
| 23 | |
| 24 | import java.util.Map; |
| 25 | |
| 26 | /** |
Michael Kolb | 377ea31 | 2011-02-17 14:36:56 -0800 | [diff] [blame] | 27 | * Manage WebView scroll events |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 28 | */ |
Michael Kolb | b14ff2f | 2011-07-01 15:33:56 -0700 | [diff] [blame] | 29 | public class BrowserWebView extends WebView { |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 30 | |
Romain Guy | 860662a | 2011-01-10 12:57:22 -0800 | [diff] [blame] | 31 | private boolean mBackgroundRemoved = false; |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 32 | private TitleBar mTitleBar; |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 33 | |
| 34 | /** |
| 35 | * @param context |
| 36 | * @param attrs |
| 37 | * @param defStyle |
| 38 | * @param javascriptInterfaces |
| 39 | */ |
John Reck | b9a051b | 2011-03-18 11:55:48 -0700 | [diff] [blame] | 40 | public BrowserWebView(Context context, AttributeSet attrs, int defStyle, |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 41 | 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 Reck | b9a051b | 2011-03-18 11:55:48 -0700 | [diff] [blame] | 50 | public BrowserWebView( |
Michael Kolb | 377ea31 | 2011-02-17 14:36:56 -0800 | [diff] [blame] | 51 | Context context, AttributeSet attrs, int defStyle, boolean privateBrowsing) { |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 52 | super(context, attrs, defStyle, privateBrowsing); |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * @param context |
| 57 | * @param attrs |
| 58 | */ |
John Reck | b9a051b | 2011-03-18 11:55:48 -0700 | [diff] [blame] | 59 | public BrowserWebView(Context context, AttributeSet attrs) { |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 60 | super(context, attrs); |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * @param context |
| 65 | */ |
John Reck | b9a051b | 2011-03-18 11:55:48 -0700 | [diff] [blame] | 66 | public BrowserWebView(Context context) { |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 67 | super(context); |
Michael Kolb | 2814a36 | 2011-05-19 15:49:41 -0700 | [diff] [blame] | 68 | } |
| 69 | |
Michael Kolb | 08a687a | 2011-04-22 16:13:02 -0700 | [diff] [blame] | 70 | @Override |
Michael Kolb | 29ccf8a | 2011-02-23 16:13:24 -0800 | [diff] [blame] | 71 | protected int getTitleHeight() { |
| 72 | return (mTitleBar != null) ? mTitleBar.getEmbeddedHeight() : 0; |
| 73 | } |
| 74 | |
Michael Kolb | ed21774 | 2010-08-10 17:52:34 -0700 | [diff] [blame] | 75 | void hideEmbeddedTitleBar() { |
| 76 | scrollBy(0, getVisibleTitleHeight()); |
| 77 | } |
| 78 | |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 79 | @Override |
| 80 | public void setEmbeddedTitleBar(final View title) { |
| 81 | super.setEmbeddedTitleBar(title); |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 82 | mTitleBar = (TitleBar) title; |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 83 | } |
| 84 | |
Michael Kolb | 377ea31 | 2011-02-17 14:36:56 -0800 | [diff] [blame] | 85 | public boolean hasTitleBar() { |
| 86 | return (mTitleBar != null); |
| 87 | } |
| 88 | |
Michael Kolb | 377ea31 | 2011-02-17 14:36:56 -0800 | [diff] [blame] | 89 | @Override |
| 90 | protected void onDraw(android.graphics.Canvas c) { |
Michael Kolb | f262892 | 2011-03-09 17:15:28 -0800 | [diff] [blame] | 91 | 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 Kolb | 377ea31 | 2011-02-17 14:36:56 -0800 | [diff] [blame] | 99 | } |
| 100 | } |
| 101 | |
John Reck | 378a410 | 2011-06-09 16:23:01 -0700 | [diff] [blame] | 102 | @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 Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 111 | } |