Chromium Code Reviews| 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 boolean mLoading = false; | |
| 56 private ImageButton mStopButton; | |
| 57 private ImageButton mReloadButton; | |
| 58 | |
| 55 /** | 59 /** |
| 56 * @param context The Context the view is running in. | 60 * @param context The Context the view is running in. |
| 57 * @param attrs The attributes of the XML tag that is inflating the view. | 61 * @param attrs The attributes of the XML tag that is inflating the view. |
| 58 */ | 62 */ |
| 59 public ChromeShellToolbar(Context context, AttributeSet attrs) { | 63 public ChromeShellToolbar(Context context, AttributeSet attrs) { |
| 60 super(context, attrs); | 64 super(context, attrs); |
| 61 // When running performance benchmark, we don't want to observe the tab | 65 // When running performance benchmark, we don't want to observe the tab |
| 62 // invalidation which would interfere with browser's processing content | 66 // invalidation which would interfere with browser's processing content |
| 63 // frame. See crbug.com/394976. | 67 // frame. See crbug.com/394976. |
| 64 if (CommandLine.getInstance().hasSwitch( | 68 if (CommandLine.getInstance().hasSwitch( |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 80 mUrlTextView.setText(mTab.getContentViewCore().getUrl()); | 84 mUrlTextView.setText(mTab.getContentViewCore().getUrl()); |
| 81 } | 85 } |
| 82 | 86 |
| 83 private void onUpdateUrl(String url) { | 87 private void onUpdateUrl(String url) { |
| 84 mUrlTextView.setText(url); | 88 mUrlTextView.setText(url); |
| 85 } | 89 } |
| 86 | 90 |
| 87 private void onLoadProgressChanged(int progress) { | 91 private void onLoadProgressChanged(int progress) { |
| 88 removeCallbacks(mClearProgressRunnable); | 92 removeCallbacks(mClearProgressRunnable); |
| 89 mProgressDrawable.setLevel(100 * progress); | 93 mProgressDrawable.setLevel(100 * progress); |
| 90 if (progress == 100) postDelayed(mClearProgressRunnable, COMPLETED_PROGR ESS_TIMEOUT_MS); | 94 mLoading = progress == 100 ? false : true; |
|
Bernhard Bauer
2014/09/04 13:17:35
Don't use false and true in a ?: expression. Just
| |
| 95 mStopButton.setVisibility(mLoading ? VISIBLE : GONE); | |
| 96 mReloadButton.setVisibility(mLoading ? GONE : VISIBLE); | |
| 97 if (!mLoading) postDelayed(mClearProgressRunnable, COMPLETED_PROGRESS_TI MEOUT_MS); | |
| 91 } | 98 } |
| 92 | 99 |
| 93 /** | 100 /** |
| 94 * Closes the suggestion popup. | 101 * Closes the suggestion popup. |
| 95 */ | 102 */ |
| 96 public void hideSuggestions() { | 103 public void hideSuggestions() { |
| 97 if (mSuggestionPopup != null) mSuggestionPopup.hideSuggestions(); | 104 if (mSuggestionPopup != null) mSuggestionPopup.hideSuggestions(); |
| 98 } | 105 } |
| 99 | 106 |
| 100 @Override | 107 @Override |
| 101 protected void onFinishInflate() { | 108 protected void onFinishInflate() { |
| 102 super.onFinishInflate(); | 109 super.onFinishInflate(); |
| 103 | 110 |
| 104 mProgressDrawable = (ClipDrawable) findViewById(R.id.toolbar).getBackgro und(); | 111 mProgressDrawable = (ClipDrawable) findViewById(R.id.toolbar).getBackgro und(); |
| 105 initializeUrlField(); | 112 initializeUrlField(); |
| 106 initializeMenuButton(); | 113 initializeMenuButton(); |
| 114 initializeStopReloadButton(); | |
| 107 } | 115 } |
| 108 | 116 |
| 109 void setMenuHandler(AppMenuHandler menuHandler) { | 117 void setMenuHandler(AppMenuHandler menuHandler) { |
| 110 mMenuHandler = menuHandler; | 118 mMenuHandler = menuHandler; |
| 111 ImageButton menuButton = (ImageButton) findViewById(R.id.menu_button); | 119 ImageButton menuButton = (ImageButton) findViewById(R.id.menu_button); |
| 112 mAppMenuButtonHelper = new AppMenuButtonHelper(menuButton, mMenuHandler) ; | 120 mAppMenuButtonHelper = new AppMenuButtonHelper(menuButton, mMenuHandler) ; |
| 113 } | 121 } |
| 114 | 122 |
| 115 private void initializeUrlField() { | 123 private void initializeUrlField() { |
| 116 mUrlTextView = (EditText) findViewById(R.id.url); | 124 mUrlTextView = (EditText) findViewById(R.id.url); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 167 } | 175 } |
| 168 }); | 176 }); |
| 169 menuButton.setOnTouchListener(new OnTouchListener() { | 177 menuButton.setOnTouchListener(new OnTouchListener() { |
| 170 @Override | 178 @Override |
| 171 public boolean onTouch(View view, MotionEvent event) { | 179 public boolean onTouch(View view, MotionEvent event) { |
| 172 return mAppMenuButtonHelper != null && mAppMenuButtonHelper.onTo uch(view, event); | 180 return mAppMenuButtonHelper != null && mAppMenuButtonHelper.onTo uch(view, event); |
| 173 } | 181 } |
| 174 }); | 182 }); |
| 175 } | 183 } |
| 176 | 184 |
| 185 private void initializeStopReloadButton() { | |
| 186 mStopButton = (ImageButton)findViewById(R.id.stop); | |
| 187 mStopButton.setOnClickListener(new OnClickListener() { | |
| 188 @Override | |
| 189 public void onClick(View v) { | |
| 190 if (mLoading) mTab.getContentViewCore().stopLoading(); | |
|
Bernhard Bauer
2014/09/04 13:17:35
Is the loading check actually necessary? The butto
| |
| 191 } | |
| 192 }); | |
| 193 mReloadButton = (ImageButton)findViewById(R.id.reload); | |
| 194 mReloadButton.setOnClickListener(new OnClickListener() { | |
| 195 @Override | |
| 196 public void onClick(View v) { | |
| 197 mTab.getContentViewCore().reload(true); | |
| 198 } | |
| 199 }); | |
| 200 } | |
| 201 | |
| 177 /** | 202 /** |
| 178 * @return Current tab that is shown by ChromeShell. | 203 * @return Current tab that is shown by ChromeShell. |
| 179 */ | 204 */ |
| 180 public ChromeShellTab getCurrentTab() { | 205 public ChromeShellTab getCurrentTab() { |
| 181 return mTab; | 206 return mTab; |
| 182 } | 207 } |
| 183 | 208 |
| 184 /** | 209 /** |
| 185 * Change the visibility of the software keyboard. | 210 * Change the visibility of the software keyboard. |
| 186 * @param visible Whether the keyboard should be shown or hidden. | 211 * @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) { | 231 public void onLoadProgressChanged(Tab tab, int progress) { |
| 207 if (tab == mTab) ChromeShellToolbar.this.onLoadProgressChanged(progr ess); | 232 if (tab == mTab) ChromeShellToolbar.this.onLoadProgressChanged(progr ess); |
| 208 } | 233 } |
| 209 | 234 |
| 210 @Override | 235 @Override |
| 211 public void onUpdateUrl(Tab tab, String url) { | 236 public void onUpdateUrl(Tab tab, String url) { |
| 212 if (tab == mTab) ChromeShellToolbar.this.onUpdateUrl(url); | 237 if (tab == mTab) ChromeShellToolbar.this.onUpdateUrl(url); |
| 213 } | 238 } |
| 214 } | 239 } |
| 215 } | 240 } |
| OLD | NEW |