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

Side by Side Diff: chrome/browser/gtk/browser_toolbar_view_gtk.cc

Issue 21176: Porting the toolbar to GTK. (Closed)
Patch Set: Move into gtk/ folder at Ben's request. Created 11 years, 10 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
OLDNEW
(Empty)
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/gtk/browser_toolbar_view_gtk.h"
6
7 #include "base/logging.h"
8 #include "chrome/app/chrome_dll_resource.h"
9 #include "chrome/browser/browser.h"
10 #include "chrome/common/l10n_util.h"
11
12 #include "chromium_strings.h"
13 #include "generated_resources.h"
14
15 BrowserToolbarGtk::BrowserToolbarGtk(Browser* browser)
16 : toolbar_(NULL),
17 back_(NULL),
18 forward_(NULL),
19 reload_(NULL),
20 home_(NULL),
21 star_(NULL),
22 model_(browser->toolbar_model()),
23 browser_(browser),
24 profile_(NULL) {
25 browser_->command_updater()->AddCommandObserver(IDC_BACK, this);
26 browser_->command_updater()->AddCommandObserver(IDC_FORWARD, this);
27 browser_->command_updater()->AddCommandObserver(IDC_RELOAD, this);
28 browser_->command_updater()->AddCommandObserver(IDC_HOME, this);
29 browser_->command_updater()->AddCommandObserver(IDC_STAR, this);
30
31 // TODO(port): Port BackForwardMenuModel
32 // back_menu_model_.reset(new BackForwardMenuModel(
33 // browser, BackForwardMenuModel::BACKWARD_MENU_DELEGATE));
34 // forward_menu_model_.reset(new BackForwardMenuModel(
35 // browser, BackForwardMenuModel::FORWARD_MENU_DELEGATE));
36 }
37
38 BrowserToolbarGtk::~BrowserToolbarGtk() {
39 }
40
41 void BrowserToolbarGtk::Init(Profile* profile) {
42 toolbar_ = gtk_hbox_new(FALSE, 0);
43 gtk_container_set_border_width(GTK_CONTAINER(toolbar_), 6);
44
45 toolbar_tooltips_ = gtk_tooltips_new();
46
47 back_ = BuildToolbarButton(l10n_util::GetString(IDS_TOOLTIP_BACK));
48 forward_ = BuildToolbarButton(l10n_util::GetString(IDS_TOOLTIP_FORWARD));
49 reload_ = BuildToolbarButton(l10n_util::GetString(IDS_TOOLTIP_RELOAD));
50 home_ = BuildToolbarButton(l10n_util::GetString(IDS_TOOLTIP_HOME));
51 star_ = BuildToolbarButton(l10n_util::GetString(IDS_TOOLTIP_STAR));
52
53 gtk_box_pack_start(GTK_BOX(toolbar_), gtk_label_new(" "), FALSE, FALSE, 0);
54 gtk_box_pack_start(GTK_BOX(toolbar_), gtk_entry_new(), TRUE, TRUE, 0);
55
56 go_ = BuildToolbarButton(L"");
57 page_menu_ = BuildToolbarButton(l10n_util::GetString(IDS_PAGEMENU_TOOLTIP));
58
59 // TODO(port): Need to get l10n_util::GetStringF working under linux to get
60 // the correct string here.
61 app_menu_ = BuildToolbarButton(l10n_util::GetString(IDS_APPMENU_TOOLTIP));
62
63 // TODO(erg): wchar_t mismatch on linux. Fix later.
64 // show_home_button_.Init(prefs::kShowHomeButton, profile->GetPrefs(), this);
65
66 SetProfile(profile);
67 }
68
69 void BrowserToolbarGtk::AddToolbarToBox(GtkWidget* box) {
70 gtk_box_pack_start(GTK_BOX(box), toolbar_, FALSE, FALSE, 0);
71 }
72
73 void BrowserToolbarGtk::EnabledStateChangedForCommand(int id, bool enabled) {
74 GtkWidget* widget = NULL;
75 switch (id) {
76 case IDC_BACK:
77 widget = back_;
78 break;
79 case IDC_FORWARD:
80 widget = forward_;
81 break;
82 case IDC_RELOAD:
83 widget = reload_;
84 break;
85 case IDC_HOME:
86 widget = home_;
87 break;
88 case IDC_STAR:
89 widget = star_;
90 break;
91 }
92 if (widget)
93 gtk_widget_set_sensitive(widget, enabled);
94 }
95
96 void BrowserToolbarGtk::SetProfile(Profile* profile) {
97 if (profile == profile_)
98 return;
99
100 profile_ = profile;
101 // TODO(erg): location_bar_ is a normal gtk text box right now. Change this
102 // when we get omnibox support.
103 // location_bar_->SetProfile(profile);
104 }
105
106 // TODO(port): This needs to deal with our styled pixmaps.
107 GtkWidget* BrowserToolbarGtk::BuildToolbarButton(
108 const std::wstring& localized_tooltip) {
109 GtkWidget* b = gtk_button_new();
110 gtk_widget_set_size_request(b, 29, 29);
111
112 // TODO(erg): Mismatch between wstring and string.
113 // gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tooltips_),
114 // GTK_WIDGET(back_),
115 // localized_tooltip, localized_tooltip);
116 g_signal_connect(G_OBJECT(b), "clicked",
117 G_CALLBACK(ButtonClickCallback), this);
118 gtk_box_pack_start(GTK_BOX(toolbar_), b, FALSE, FALSE, 0);
119
120 // TODO(erg): Change this when pixmap loading is working.
121 return b;
122 }
123
124 /* static */
125 void BrowserToolbarGtk::ButtonClickCallback(GtkWidget* button,
126 BrowserToolbarGtk* toolbar) {
127 int tag = -1;
128 if (button == toolbar->back_)
129 tag = IDC_BACK;
130 else if (button == toolbar->forward_)
131 tag = IDC_FORWARD;
132 else if (button == toolbar->reload_)
133 tag = IDC_RELOAD;
134 else if (button == toolbar->home_)
135 tag = IDC_HOME;
136 else if (button == toolbar->star_)
137 tag = IDC_STAR;
138
139 if (tag != -1) {
140 toolbar->browser_->ExecuteCommand(tag);
141 } else {
142 // TODO(erg): The menu buttons are special; they need to spawn menus.
143 }
144 }
OLDNEW
« no previous file with comments | « chrome/browser/gtk/browser_toolbar_view_gtk.h ('k') | chrome/browser/gtk/browser_window_factory_gtk.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698