Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(56)

Side by Side Diff: chrome/browser/ui/gtk/location_bar_view_gtk.cc

Issue 10736028: Refactor browser window zoom handling and enable zoom icon on all platforms. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix mac Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #include "chrome/browser/ui/gtk/location_bar_view_gtk.h" 5 #include "chrome/browser/ui/gtk/location_bar_view_gtk.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 1212 matching lines...) Expand 10 before | Expand all | Expand 10 after
1223 GtkAllocation* allocation) { 1223 GtkAllocation* allocation) {
1224 if (entry_box_width_ != allocation->width) { 1224 if (entry_box_width_ != allocation->width) {
1225 entry_box_width_ = allocation->width; 1225 entry_box_width_ = allocation->width;
1226 AdjustChildrenVisibility(); 1226 AdjustChildrenVisibility();
1227 } 1227 }
1228 } 1228 }
1229 1229
1230 gboolean LocationBarViewGtk::OnZoomButtonPress(GtkWidget* widget, 1230 gboolean LocationBarViewGtk::OnZoomButtonPress(GtkWidget* widget,
1231 GdkEventButton* event) { 1231 GdkEventButton* event) {
1232 if (event->button == 1 && GetWebContents()) { 1232 if (event->button == 1 && GetWebContents()) {
1233 // If the zoom icon is clicked, show the zoom bubble and keep it open until 1233 UpdateZoomIcon();
Kyle Horimoto 2012/07/24 03:22:28 OnZoomButtonPress() should display the zoom bubble
Dan Beam 2012/08/15 09:04:59 This works again.
1234 // it loses focus.
1235 ZoomBubbleGtk::Show(zoom_.get(), GetTabContents(), false);
1236 return TRUE; 1234 return TRUE;
1237 } 1235 }
1238 return FALSE; 1236 return FALSE;
1239 } 1237 }
1240 1238
1241 gboolean LocationBarViewGtk::OnStarButtonPress(GtkWidget* widget, 1239 gboolean LocationBarViewGtk::OnStarButtonPress(GtkWidget* widget,
1242 GdkEventButton* event) { 1240 GdkEventButton* event) {
1243 if (event->button == 1) { 1241 if (event->button == 1) {
1244 chrome::ExecuteCommand(browser_, IDC_BOOKMARK_PAGE); 1242 chrome::ExecuteCommand(browser_, IDC_BOOKMARK_PAGE);
1245 return TRUE; 1243 return TRUE;
1246 } 1244 }
1247 return FALSE; 1245 return FALSE;
1248 } 1246 }
1249 1247
1250 gboolean LocationBarViewGtk::OnChromeToMobileButtonPress( 1248 gboolean LocationBarViewGtk::OnChromeToMobileButtonPress(
1251 GtkWidget* widget, 1249 GtkWidget* widget,
1252 GdkEventButton* event) { 1250 GdkEventButton* event) {
1253 if (event->button == 1) { 1251 if (event->button == 1) {
1254 chrome::ExecuteCommand(browser_, IDC_CHROME_TO_MOBILE_PAGE); 1252 chrome::ExecuteCommand(browser_, IDC_CHROME_TO_MOBILE_PAGE);
1255 return TRUE; 1253 return TRUE;
1256 } 1254 }
1257 return FALSE; 1255 return FALSE;
1258 } 1256 }
1259 1257
1260 void LocationBarViewGtk::ShowZoomBubble(int zoom_percent) {
1261 if (!zoom_.get() || toolbar_model_->input_in_progress())
1262 return;
1263
1264 ZoomBubbleGtk::Show(zoom_.get(), GetTabContents(), true);
1265 }
1266
1267 void LocationBarViewGtk::ShowStarBubble(const GURL& url, 1258 void LocationBarViewGtk::ShowStarBubble(const GURL& url,
1268 bool newly_bookmarked) { 1259 bool newly_bookmarked) {
1269 if (!star_.get()) 1260 if (!star_.get())
1270 return; 1261 return;
1271 1262
1272 BookmarkBubbleGtk::Show(star_.get(), browser_->profile(), url, 1263 BookmarkBubbleGtk::Show(star_.get(), browser_->profile(), url,
1273 newly_bookmarked); 1264 newly_bookmarked);
1274 } 1265 }
1275 1266
1276 void LocationBarViewGtk::ShowChromeToMobileBubble() { 1267 void LocationBarViewGtk::ShowChromeToMobileBubble() {
1277 ChromeToMobileBubbleGtk::Show(GTK_IMAGE(chrome_to_mobile_image_), browser_); 1268 ChromeToMobileBubbleGtk::Show(GTK_IMAGE(chrome_to_mobile_image_), browser_);
1278 } 1269 }
1279 1270
1280 void LocationBarViewGtk::SetZoomIconTooltipPercent(int zoom_percent) {
1281 UpdateZoomIcon();
1282 }
1283
1284 void LocationBarViewGtk::SetZoomIconState(
1285 ZoomController::ZoomIconState zoom_icon_state) {
1286 UpdateZoomIcon();
1287 }
1288
1289 void LocationBarViewGtk::SetStarred(bool starred) { 1271 void LocationBarViewGtk::SetStarred(bool starred) {
1290 if (starred == starred_) 1272 if (starred == starred_)
1291 return; 1273 return;
1292 1274
1293 starred_ = starred; 1275 starred_ = starred;
1294 UpdateStarIcon(); 1276 UpdateStarIcon();
1295 } 1277 }
1296 1278
1279 // TODO(dbeam): make a generic helper that updates both the zoom icon and shows
1280 // the zoom bubble, if appropriate, for a zoom change.
1281 void LocationBarViewGtk::ZoomChangedForActiveTab(bool can_show_bubble) {
1282 UpdateZoomIcon();
1283
1284 // TODO(dbeam): show a zoom bubble when appropriate.
1285 }
1286
1297 void LocationBarViewGtk::UpdateZoomIcon() { 1287 void LocationBarViewGtk::UpdateZoomIcon() {
1298 if (!zoom_.get() || !GetWebContents()) 1288 TabContents* tab_contents = GetTabContents();
1289 if (!zoom_.get() || !tab_contents)
1299 return; 1290 return;
1300 1291
1301 const ZoomController* zc = TabContents::FromWebContents( 1292 ZoomController* zoom_controller = tab_contents->zoom_controller();
1302 GetWebContents())->zoom_controller(); 1293 if (!zoom_controller || zoom_controller->IsAtDefaultZoom() ||
1303 1294 toolbar_model_->input_in_progress()) {
1304 if (toolbar_model_->input_in_progress() ||
1305 zc->zoom_icon_state() == ZoomController::NONE) {
1306 gtk_widget_hide(zoom_.get()); 1295 gtk_widget_hide(zoom_.get());
1307 ZoomBubbleGtk::Close();
1308 return; 1296 return;
1309 } 1297 }
1310 1298
1311 gtk_widget_show(zoom_.get()); 1299 int zoom_percent = zoom_controller->zoom_percent();
1312 int zoom_resource = zc->zoom_icon_state() == ZoomController::ZOOM_PLUS_ICON ? 1300 int zoom_resource = zoom_percent > 100 ? IDR_ZOOM_PLUS : IDR_ZOOM_MINUS;
Kyle Horimoto 2012/07/24 03:22:28 This is incorrect: zoom_resource should be IDR_ZOO
Dan Beam 2012/08/15 09:04:59 Done.
1313 IDR_ZOOM_PLUS : IDR_ZOOM_MINUS;
1314 gtk_image_set_from_pixbuf(GTK_IMAGE(zoom_image_), 1301 gtk_image_set_from_pixbuf(GTK_IMAGE(zoom_image_),
1315 theme_service_->GetImageNamed(zoom_resource)->ToGdkPixbuf()); 1302 theme_service_->GetImageNamed(zoom_resource)->ToGdkPixbuf());
1316 1303
1317 string16 tooltip = l10n_util::GetStringFUTF16Int(IDS_TOOLTIP_ZOOM, 1304 string16 tooltip =
1318 zc->zoom_percent()); 1305 l10n_util::GetStringFUTF16Int(IDS_TOOLTIP_ZOOM, zoom_percent);
1319 gtk_widget_set_tooltip_text(zoom_.get(), UTF16ToUTF8(tooltip).c_str()); 1306 gtk_widget_set_tooltip_text(zoom_.get(), UTF16ToUTF8(tooltip).c_str());
1307
1308 gtk_widget_show(zoom_.get());
1320 } 1309 }
1321 1310
1322 void LocationBarViewGtk::UpdateStarIcon() { 1311 void LocationBarViewGtk::UpdateStarIcon() {
1323 if (!star_.get()) 1312 if (!star_.get())
1324 return; 1313 return;
1325 bool star_enabled = !toolbar_model_->input_in_progress() && 1314 bool star_enabled = !toolbar_model_->input_in_progress() &&
1326 edit_bookmarks_enabled_.GetValue(); 1315 edit_bookmarks_enabled_.GetValue();
1327 command_updater_->UpdateCommandEnabled(IDC_BOOKMARK_PAGE, star_enabled); 1316 command_updater_->UpdateCommandEnabled(IDC_BOOKMARK_PAGE, star_enabled);
1328 if (star_enabled) { 1317 if (star_enabled) {
1329 gtk_widget_show_all(star_.get()); 1318 gtk_widget_show_all(star_.get());
(...skipping 643 matching lines...) Expand 10 before | Expand all | Expand 10 after
1973 } 1962 }
1974 1963
1975 void LocationBarViewGtk::PageActionViewGtk::InspectPopup( 1964 void LocationBarViewGtk::PageActionViewGtk::InspectPopup(
1976 ExtensionAction* action) { 1965 ExtensionAction* action) {
1977 ExtensionPopupGtk::Show( 1966 ExtensionPopupGtk::Show(
1978 action->GetPopupUrl(current_tab_id_), 1967 action->GetPopupUrl(current_tab_id_),
1979 owner_->browser_, 1968 owner_->browser_,
1980 event_box_.get(), 1969 event_box_.get(),
1981 ExtensionPopupGtk::SHOW_AND_INSPECT); 1970 ExtensionPopupGtk::SHOW_AND_INSPECT);
1982 } 1971 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698