| OLD | NEW |
| 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/zoom_bubble_gtk.h" | 5 #include "chrome/browser/ui/gtk/zoom_bubble_gtk.h" |
| 6 | 6 |
| 7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
| 8 #include "chrome/browser/prefs/pref_service.h" | 8 #include "chrome/browser/prefs/pref_service.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/browser/ui/gtk/gtk_theme_service.h" | 10 #include "chrome/browser/ui/gtk/gtk_theme_service.h" |
| 11 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 11 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| 12 #include "chrome/browser/ui/zoom/zoom_controller.h" | 12 #include "chrome/browser/ui/zoom/zoom_controller.h" |
| 13 #include "chrome/common/pref_names.h" | 13 #include "chrome/common/pref_names.h" |
| 14 #include "content/public/browser/render_view_host.h" | 14 #include "content/public/browser/render_view_host.h" |
| 15 #include "content/public/browser/web_contents.h" | 15 #include "content/public/browser/web_contents.h" |
| 16 #include "grit/generated_resources.h" | 16 #include "grit/generated_resources.h" |
| 17 #include "ui/base/gtk/gtk_hig_constants.h" | 17 #include "ui/base/gtk/gtk_hig_constants.h" |
| 18 #include "ui/base/l10n/l10n_util.h" | 18 #include "ui/base/l10n/l10n_util.h" |
| 19 #include "ui/gfx/rect.h" | 19 #include "ui/gfx/rect.h" |
| 20 | 20 |
| 21 namespace { | 21 namespace { |
| 22 | 22 |
| 23 // Pointer to singleton object (NULL if no bubble is open). | 23 // Pointer to singleton object (NULL if no bubble is open). |
| 24 ZoomBubbleGtk* g_bubble = NULL; | 24 ZoomBubbleGtk* g_bubble = NULL; |
| 25 | 25 |
| 26 // Padding on each side of the percentage label and the left and right sides of | |
| 27 // the "Set to default" button. | |
| 28 const int kSidePadding = 5; | |
| 29 | |
| 30 // Number of milliseconds the bubble should stay open for if it will auto-close. | 26 // Number of milliseconds the bubble should stay open for if it will auto-close. |
| 31 const int kBubbleCloseDelay = 1500; | 27 const int kBubbleCloseDelay = 1500; |
| 32 | 28 |
| 33 // Need to manually set anchor width and height to ensure that the bubble shows | 29 // Need to manually set anchor width and height to ensure that the bubble shows |
| 34 // in the correct spot the first time it is displayed when no icon is present. | 30 // in the correct spot the first time it is displayed when no icon is present. |
| 35 const int kBubbleAnchorWidth = 20; | 31 const int kBubbleAnchorWidth = 20; |
| 36 const int kBubbleAnchorHeight = 25; | 32 const int kBubbleAnchorHeight = 25; |
| 37 | 33 |
| 38 } // namespace | 34 } // namespace |
| 39 | 35 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 69 TabContents* tab_contents, | 65 TabContents* tab_contents, |
| 70 bool auto_close) | 66 bool auto_close) |
| 71 : auto_close_(auto_close), | 67 : auto_close_(auto_close), |
| 72 mouse_inside_(false), | 68 mouse_inside_(false), |
| 73 tab_contents_(tab_contents) { | 69 tab_contents_(tab_contents) { |
| 74 GtkThemeService* theme_service = | 70 GtkThemeService* theme_service = |
| 75 GtkThemeService::GetFrom(Profile::FromBrowserContext( | 71 GtkThemeService::GetFrom(Profile::FromBrowserContext( |
| 76 tab_contents->web_contents()->GetBrowserContext())); | 72 tab_contents->web_contents()->GetBrowserContext())); |
| 77 | 73 |
| 78 event_box_ = gtk_event_box_new(); | 74 event_box_ = gtk_event_box_new(); |
| 75 gtk_event_box_set_visible_window(GTK_EVENT_BOX(event_box_), FALSE); |
| 79 GtkWidget* container = gtk_vbox_new(FALSE, 0); | 76 GtkWidget* container = gtk_vbox_new(FALSE, 0); |
| 80 gtk_container_add(GTK_CONTAINER(event_box_), container); | 77 gtk_container_add(GTK_CONTAINER(event_box_), container); |
| 81 | 78 |
| 82 int zoom_percent = tab_contents->zoom_controller()->zoom_percent(); | 79 int zoom_percent = tab_contents->zoom_controller()->zoom_percent(); |
| 83 std::string percentage_text = UTF16ToUTF8(l10n_util::GetStringFUTF16Int( | 80 std::string percentage_text = UTF16ToUTF8(l10n_util::GetStringFUTF16Int( |
| 84 IDS_TOOLTIP_ZOOM, zoom_percent)); | 81 IDS_TOOLTIP_ZOOM, zoom_percent)); |
| 85 label_ = theme_service->BuildLabel(percentage_text, ui::kGdkBlack); | 82 label_ = theme_service->BuildLabel(percentage_text, ui::kGdkBlack); |
| 86 gtk_widget_modify_font(label_, pango_font_description_from_string("13")); | 83 gtk_widget_modify_font(label_, pango_font_description_from_string("13")); |
| 87 gtk_misc_set_padding(GTK_MISC(label_), kSidePadding, kSidePadding); | 84 gtk_misc_set_padding(GTK_MISC(label_), |
| 88 | 85 ui::kControlSpacing, ui::kControlSpacing); |
| 89 gtk_box_pack_start(GTK_BOX(container), label_, FALSE, FALSE, 0); | 86 gtk_box_pack_start(GTK_BOX(container), label_, FALSE, FALSE, 0); |
| 90 | 87 |
| 91 GtkWidget* separator = gtk_hseparator_new(); | 88 GtkWidget* separator = gtk_hseparator_new(); |
| 92 gtk_box_pack_start(GTK_BOX(container), separator, FALSE, FALSE, 0); | 89 gtk_box_pack_start(GTK_BOX(container), separator, FALSE, FALSE, 0); |
| 93 | 90 |
| 94 GtkWidget* set_default_button = theme_service->BuildChromeButton(); | 91 GtkWidget* set_default_button = theme_service->BuildChromeButton(); |
| 95 gtk_button_set_label(GTK_BUTTON(set_default_button), | 92 gtk_button_set_label(GTK_BUTTON(set_default_button), |
| 96 l10n_util::GetStringUTF8(IDS_ZOOM_SET_DEFAULT).c_str()); | 93 l10n_util::GetStringUTF8(IDS_ZOOM_SET_DEFAULT).c_str()); |
| 97 | 94 |
| 98 GtkWidget* alignment = gtk_alignment_new(0, 0, 1, 1); | 95 GtkWidget* alignment = gtk_alignment_new(0, 0, 1, 1); |
| 99 gtk_alignment_set_padding( | 96 gtk_alignment_set_padding( |
| 100 GTK_ALIGNMENT(alignment), 0, 0, kSidePadding, kSidePadding); | 97 GTK_ALIGNMENT(alignment), 0, 0, ui::kControlSpacing, ui::kControlSpacing); |
| 101 gtk_container_add(GTK_CONTAINER(alignment), set_default_button); | 98 gtk_container_add(GTK_CONTAINER(alignment), set_default_button); |
| 102 | 99 |
| 103 gtk_box_pack_start(GTK_BOX(container), alignment, FALSE, FALSE, 0); | 100 gtk_box_pack_start(GTK_BOX(container), alignment, FALSE, FALSE, 0); |
| 104 g_signal_connect(set_default_button, "clicked", | 101 g_signal_connect(set_default_button, "clicked", |
| 105 G_CALLBACK(&OnSetDefaultLinkClickThunk), this); | 102 G_CALLBACK(&OnSetDefaultLinkClickThunk), this); |
| 106 | 103 |
| 107 gtk_container_set_focus_child(GTK_CONTAINER(container), NULL); | 104 gtk_container_set_focus_child(GTK_CONTAINER(container), NULL); |
| 108 | 105 |
| 109 gfx::Rect rect(kBubbleAnchorWidth, kBubbleAnchorHeight); | 106 gfx::Rect rect(kBubbleAnchorWidth, kBubbleAnchorHeight); |
| 110 BubbleGtk::ArrowLocationGtk arrow_location = | 107 BubbleGtk::ArrowLocationGtk arrow_location = |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 StopTimerIfNecessary(); | 197 StopTimerIfNecessary(); |
| 201 return FALSE; | 198 return FALSE; |
| 202 } | 199 } |
| 203 | 200 |
| 204 gboolean ZoomBubbleGtk::OnMouseLeave(GtkWidget* widget, | 201 gboolean ZoomBubbleGtk::OnMouseLeave(GtkWidget* widget, |
| 205 GdkEventCrossing* event) { | 202 GdkEventCrossing* event) { |
| 206 mouse_inside_ = false; | 203 mouse_inside_ = false; |
| 207 StartTimerIfNecessary(); | 204 StartTimerIfNecessary(); |
| 208 return FALSE; | 205 return FALSE; |
| 209 } | 206 } |
| OLD | NEW |