OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.chrome.shell; | 5 package org.chromium.chrome.shell; |
6 | 6 |
7 import android.content.Context; | 7 import android.content.Context; |
8 import android.content.res.Configuration; | 8 import android.content.res.Configuration; |
9 import android.graphics.drawable.ClipDrawable; | 9 import android.graphics.drawable.ClipDrawable; |
10 import android.util.AttributeSet; | 10 import android.util.AttributeSet; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 private ClipDrawable mProgressDrawable; | 45 private ClipDrawable mProgressDrawable; |
46 | 46 |
47 private ChromeShellTab mTab; | 47 private ChromeShellTab mTab; |
48 private final TabObserver mTabObserver; | 48 private final TabObserver mTabObserver; |
49 | 49 |
50 private AppMenuHandler mMenuHandler; | 50 private AppMenuHandler mMenuHandler; |
51 private AppMenuButtonHelper mAppMenuButtonHelper; | 51 private AppMenuButtonHelper mAppMenuButtonHelper; |
52 | 52 |
53 private SuggestionPopup mSuggestionPopup; | 53 private SuggestionPopup mSuggestionPopup; |
54 | 54 |
| 55 private ImageButton mStopButton; |
| 56 private ImageButton mReloadButton; |
| 57 |
55 /** | 58 /** |
56 * @param context The Context the view is running in. | 59 * @param context The Context the view is running in. |
57 * @param attrs The attributes of the XML tag that is inflating the view. | 60 * @param attrs The attributes of the XML tag that is inflating the view. |
58 */ | 61 */ |
59 public ChromeShellToolbar(Context context, AttributeSet attrs) { | 62 public ChromeShellToolbar(Context context, AttributeSet attrs) { |
60 super(context, attrs); | 63 super(context, attrs); |
61 // When running performance benchmark, we don't want to observe the tab | 64 // When running performance benchmark, we don't want to observe the tab |
62 // invalidation which would interfere with browser's processing content | 65 // invalidation which would interfere with browser's processing content |
63 // frame. See crbug.com/394976. | 66 // frame. See crbug.com/394976. |
64 if (CommandLine.getInstance().hasSwitch( | 67 if (CommandLine.getInstance().hasSwitch( |
(...skipping 15 matching lines...) Expand all Loading... |
80 mUrlTextView.setText(mTab.getContentViewCore().getUrl()); | 83 mUrlTextView.setText(mTab.getContentViewCore().getUrl()); |
81 } | 84 } |
82 | 85 |
83 private void onUpdateUrl(String url) { | 86 private void onUpdateUrl(String url) { |
84 mUrlTextView.setText(url); | 87 mUrlTextView.setText(url); |
85 } | 88 } |
86 | 89 |
87 private void onLoadProgressChanged(int progress) { | 90 private void onLoadProgressChanged(int progress) { |
88 removeCallbacks(mClearProgressRunnable); | 91 removeCallbacks(mClearProgressRunnable); |
89 mProgressDrawable.setLevel(100 * progress); | 92 mProgressDrawable.setLevel(100 * progress); |
90 if (progress == 100) postDelayed(mClearProgressRunnable, COMPLETED_PROGR
ESS_TIMEOUT_MS); | 93 boolean isLoading = progress != 100; |
| 94 mStopButton.setVisibility(isLoading ? VISIBLE : GONE); |
| 95 mReloadButton.setVisibility(isLoading ? GONE : VISIBLE); |
| 96 if (!isLoading) postDelayed(mClearProgressRunnable, COMPLETED_PROGRESS_T
IMEOUT_MS); |
91 } | 97 } |
92 | 98 |
93 /** | 99 /** |
94 * Closes the suggestion popup. | 100 * Closes the suggestion popup. |
95 */ | 101 */ |
96 public void hideSuggestions() { | 102 public void hideSuggestions() { |
97 if (mSuggestionPopup != null) mSuggestionPopup.hideSuggestions(); | 103 if (mSuggestionPopup != null) mSuggestionPopup.hideSuggestions(); |
98 } | 104 } |
99 | 105 |
100 @Override | 106 @Override |
101 protected void onFinishInflate() { | 107 protected void onFinishInflate() { |
102 super.onFinishInflate(); | 108 super.onFinishInflate(); |
103 | 109 |
104 mProgressDrawable = (ClipDrawable) findViewById(R.id.toolbar).getBackgro
und(); | 110 mProgressDrawable = (ClipDrawable) findViewById(R.id.toolbar).getBackgro
und(); |
105 initializeUrlField(); | 111 initializeUrlField(); |
106 initializeMenuButton(); | 112 initializeMenuButton(); |
| 113 initializeStopReloadButton(); |
107 } | 114 } |
108 | 115 |
109 void setMenuHandler(AppMenuHandler menuHandler) { | 116 void setMenuHandler(AppMenuHandler menuHandler) { |
110 mMenuHandler = menuHandler; | 117 mMenuHandler = menuHandler; |
111 ImageButton menuButton = (ImageButton) findViewById(R.id.menu_button); | 118 ImageButton menuButton = (ImageButton) findViewById(R.id.menu_button); |
112 mAppMenuButtonHelper = new AppMenuButtonHelper(menuButton, mMenuHandler)
; | 119 mAppMenuButtonHelper = new AppMenuButtonHelper(menuButton, mMenuHandler)
; |
113 } | 120 } |
114 | 121 |
115 private void initializeUrlField() { | 122 private void initializeUrlField() { |
116 mUrlTextView = (EditText) findViewById(R.id.url); | 123 mUrlTextView = (EditText) findViewById(R.id.url); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 } | 174 } |
168 }); | 175 }); |
169 menuButton.setOnTouchListener(new OnTouchListener() { | 176 menuButton.setOnTouchListener(new OnTouchListener() { |
170 @Override | 177 @Override |
171 public boolean onTouch(View view, MotionEvent event) { | 178 public boolean onTouch(View view, MotionEvent event) { |
172 return mAppMenuButtonHelper != null && mAppMenuButtonHelper.onTo
uch(view, event); | 179 return mAppMenuButtonHelper != null && mAppMenuButtonHelper.onTo
uch(view, event); |
173 } | 180 } |
174 }); | 181 }); |
175 } | 182 } |
176 | 183 |
| 184 private void initializeStopReloadButton() { |
| 185 mStopButton = (ImageButton)findViewById(R.id.stop); |
| 186 mStopButton.setOnClickListener(new OnClickListener() { |
| 187 @Override |
| 188 public void onClick(View v) { |
| 189 mTab.getContentViewCore().stopLoading(); |
| 190 } |
| 191 }); |
| 192 mReloadButton = (ImageButton)findViewById(R.id.reload); |
| 193 mReloadButton.setOnClickListener(new OnClickListener() { |
| 194 @Override |
| 195 public void onClick(View v) { |
| 196 mTab.getContentViewCore().reload(true); |
| 197 } |
| 198 }); |
| 199 } |
| 200 |
177 /** | 201 /** |
178 * @return Current tab that is shown by ChromeShell. | 202 * @return Current tab that is shown by ChromeShell. |
179 */ | 203 */ |
180 public ChromeShellTab getCurrentTab() { | 204 public ChromeShellTab getCurrentTab() { |
181 return mTab; | 205 return mTab; |
182 } | 206 } |
183 | 207 |
184 /** | 208 /** |
185 * Change the visibility of the software keyboard. | 209 * Change the visibility of the software keyboard. |
186 * @param visible Whether the keyboard should be shown or hidden. | 210 * @param visible Whether the keyboard should be shown or hidden. |
(...skipping 19 matching lines...) Expand all Loading... |
206 public void onLoadProgressChanged(Tab tab, int progress) { | 230 public void onLoadProgressChanged(Tab tab, int progress) { |
207 if (tab == mTab) ChromeShellToolbar.this.onLoadProgressChanged(progr
ess); | 231 if (tab == mTab) ChromeShellToolbar.this.onLoadProgressChanged(progr
ess); |
208 } | 232 } |
209 | 233 |
210 @Override | 234 @Override |
211 public void onUpdateUrl(Tab tab, String url) { | 235 public void onUpdateUrl(Tab tab, String url) { |
212 if (tab == mTab) ChromeShellToolbar.this.onUpdateUrl(url); | 236 if (tab == mTab) ChromeShellToolbar.this.onUpdateUrl(url); |
213 } | 237 } |
214 } | 238 } |
215 } | 239 } |
OLD | NEW |