OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 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 | 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/gtk/bookmark_bar_gtk.h" | 5 #include "chrome/browser/gtk/bookmark_bar_gtk.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "app/gfx/gtk_util.h" | 9 #include "app/gfx/gtk_util.h" |
10 #include "app/gfx/canvas_paint.h" | 10 #include "app/gfx/canvas_paint.h" |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 Profile* profile, Browser* browser, | 111 Profile* profile, Browser* browser, |
112 TabstripOriginProvider* tabstrip_origin_provider) | 112 TabstripOriginProvider* tabstrip_origin_provider) |
113 : profile_(NULL), | 113 : profile_(NULL), |
114 page_navigator_(NULL), | 114 page_navigator_(NULL), |
115 browser_(browser), | 115 browser_(browser), |
116 window_(window), | 116 window_(window), |
117 tabstrip_origin_provider_(tabstrip_origin_provider), | 117 tabstrip_origin_provider_(tabstrip_origin_provider), |
118 model_(NULL), | 118 model_(NULL), |
119 instructions_label_(NULL), | 119 instructions_label_(NULL), |
120 instructions_(NULL), | 120 instructions_(NULL), |
121 #if defined(BROWSER_SYNC) | |
122 sync_error_button_(NULL), | 121 sync_error_button_(NULL), |
123 sync_service_(NULL), | 122 sync_service_(NULL), |
124 #endif | |
125 dragged_node_(NULL), | 123 dragged_node_(NULL), |
126 toolbar_drop_item_(NULL), | 124 toolbar_drop_item_(NULL), |
127 theme_provider_(GtkThemeProvider::GetFrom(profile)), | 125 theme_provider_(GtkThemeProvider::GetFrom(profile)), |
128 show_instructions_(true), | 126 show_instructions_(true), |
129 menu_bar_helper_(this), | 127 menu_bar_helper_(this), |
130 floating_(false), | 128 floating_(false), |
131 last_allocation_width_(-1), | 129 last_allocation_width_(-1), |
132 event_box_paint_factory_(this) { | 130 event_box_paint_factory_(this) { |
133 #if defined(BROWSER_SYNC) | |
134 if (profile->GetProfileSyncService()) { | 131 if (profile->GetProfileSyncService()) { |
135 // Obtain a pointer to the profile sync service and add our instance as an | 132 // Obtain a pointer to the profile sync service and add our instance as an |
136 // observer. | 133 // observer. |
137 sync_service_ = profile->GetProfileSyncService(); | 134 sync_service_ = profile->GetProfileSyncService(); |
138 sync_service_->AddObserver(this); | 135 sync_service_->AddObserver(this); |
139 } | 136 } |
140 #endif | |
141 | 137 |
142 Init(profile); | 138 Init(profile); |
143 SetProfile(profile); | 139 SetProfile(profile); |
144 // Force an update by simulating being in the wrong state. | 140 // Force an update by simulating being in the wrong state. |
145 floating_ = !ShouldBeFloating(); | 141 floating_ = !ShouldBeFloating(); |
146 UpdateFloatingState(); | 142 UpdateFloatingState(); |
147 | 143 |
148 registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED, | 144 registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED, |
149 NotificationService::AllSources()); | 145 NotificationService::AllSources()); |
150 } | 146 } |
151 | 147 |
152 BookmarkBarGtk::~BookmarkBarGtk() { | 148 BookmarkBarGtk::~BookmarkBarGtk() { |
153 if (model_) | 149 if (model_) |
154 model_->RemoveObserver(this); | 150 model_->RemoveObserver(this); |
155 | 151 |
156 RemoveAllBookmarkButtons(); | 152 RemoveAllBookmarkButtons(); |
157 bookmark_toolbar_.Destroy(); | 153 bookmark_toolbar_.Destroy(); |
158 event_box_.Destroy(); | 154 event_box_.Destroy(); |
159 | 155 |
160 #if defined(BROWSER_SYNC) | |
161 if (sync_service_) | 156 if (sync_service_) |
162 sync_service_->RemoveObserver(this); | 157 sync_service_->RemoveObserver(this); |
163 #endif | |
164 } | 158 } |
165 | 159 |
166 void BookmarkBarGtk::SetProfile(Profile* profile) { | 160 void BookmarkBarGtk::SetProfile(Profile* profile) { |
167 DCHECK(profile); | 161 DCHECK(profile); |
168 if (profile_ == profile) | 162 if (profile_ == profile) |
169 return; | 163 return; |
170 | 164 |
171 RemoveAllBookmarkButtons(); | 165 RemoveAllBookmarkButtons(); |
172 | 166 |
173 profile_ = profile; | 167 profile_ = profile; |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 G_CALLBACK(&OnToolbarDragLeave), this); | 254 G_CALLBACK(&OnToolbarDragLeave), this); |
261 g_signal_connect(bookmark_toolbar_.get(), "drag-data-received", | 255 g_signal_connect(bookmark_toolbar_.get(), "drag-data-received", |
262 G_CALLBACK(&OnDragReceived), this); | 256 G_CALLBACK(&OnDragReceived), this); |
263 | 257 |
264 GtkWidget* vseparator = gtk_vseparator_new(); | 258 GtkWidget* vseparator = gtk_vseparator_new(); |
265 gtk_box_pack_start(GTK_BOX(bookmark_hbox_), vseparator, | 259 gtk_box_pack_start(GTK_BOX(bookmark_hbox_), vseparator, |
266 FALSE, FALSE, 0); | 260 FALSE, FALSE, 0); |
267 g_signal_connect(vseparator, "expose-event", | 261 g_signal_connect(vseparator, "expose-event", |
268 G_CALLBACK(OnSeparatorExpose), this); | 262 G_CALLBACK(OnSeparatorExpose), this); |
269 | 263 |
270 #if defined(BROWSER_SYNC) | |
271 sync_error_button_ = theme_provider_->BuildChromeButton(); | 264 sync_error_button_ = theme_provider_->BuildChromeButton(); |
272 ConnectFolderButtonEvents(sync_error_button_); | 265 ConnectFolderButtonEvents(sync_error_button_); |
273 gtk_box_pack_start(GTK_BOX(bookmark_hbox_), sync_error_button_, | 266 gtk_box_pack_start(GTK_BOX(bookmark_hbox_), sync_error_button_, |
274 FALSE, FALSE, 0); | 267 FALSE, FALSE, 0); |
275 #endif | |
276 | 268 |
277 // We pack the button manually (rather than using gtk_button_set_*) so that | 269 // We pack the button manually (rather than using gtk_button_set_*) so that |
278 // we can have finer control over its label. | 270 // we can have finer control over its label. |
279 other_bookmarks_button_ = theme_provider_->BuildChromeButton(); | 271 other_bookmarks_button_ = theme_provider_->BuildChromeButton(); |
280 ConnectFolderButtonEvents(other_bookmarks_button_); | 272 ConnectFolderButtonEvents(other_bookmarks_button_); |
281 gtk_box_pack_start(GTK_BOX(bookmark_hbox_), other_bookmarks_button_, | 273 gtk_box_pack_start(GTK_BOX(bookmark_hbox_), other_bookmarks_button_, |
282 FALSE, FALSE, 0); | 274 FALSE, FALSE, 0); |
283 | 275 |
284 gtk_widget_set_size_request(event_box_.get(), -1, kBookmarkBarMinimumHeight); | 276 gtk_widget_set_size_request(event_box_.get(), -1, kBookmarkBarMinimumHeight); |
285 | 277 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 // then force hide. | 322 // then force hide. |
331 if (slide_animation_->IsShowing() && animate) { | 323 if (slide_animation_->IsShowing() && animate) { |
332 slide_animation_->Hide(); | 324 slide_animation_->Hide(); |
333 } else { | 325 } else { |
334 gtk_widget_hide(bookmark_hbox_); | 326 gtk_widget_hide(bookmark_hbox_); |
335 slide_animation_->Reset(0); | 327 slide_animation_->Reset(0); |
336 AnimationProgressed(slide_animation_.get()); | 328 AnimationProgressed(slide_animation_.get()); |
337 } | 329 } |
338 } | 330 } |
339 | 331 |
340 #if defined(BROWSER_SYNC) | |
341 void BookmarkBarGtk::OnStateChanged() { | 332 void BookmarkBarGtk::OnStateChanged() { |
342 // TODO(zork): TODO | 333 // TODO(zork): TODO |
343 } | 334 } |
344 #endif | |
345 | 335 |
346 void BookmarkBarGtk::EnterFullscreen() { | 336 void BookmarkBarGtk::EnterFullscreen() { |
347 if (ShouldBeFloating()) | 337 if (ShouldBeFloating()) |
348 Show(false); | 338 Show(false); |
349 else | 339 else |
350 gtk_widget_hide(widget()); | 340 gtk_widget_hide(widget()); |
351 } | 341 } |
352 | 342 |
353 int BookmarkBarGtk::GetHeight() { | 343 int BookmarkBarGtk::GetHeight() { |
354 return event_box_->allocation.height; | 344 return event_box_->allocation.height; |
(...skipping 912 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1267 break; | 1257 break; |
1268 } | 1258 } |
1269 } | 1259 } |
1270 DCHECK_NE(button_idx, -1); | 1260 DCHECK_NE(button_idx, -1); |
1271 | 1261 |
1272 // Find the GtkWidget* for the actual target button. | 1262 // Find the GtkWidget* for the actual target button. |
1273 int shift = dir == GTK_MENU_DIR_PARENT ? -1 : 1; | 1263 int shift = dir == GTK_MENU_DIR_PARENT ? -1 : 1; |
1274 button_idx = (button_idx + shift + folder_list.size()) % folder_list.size(); | 1264 button_idx = (button_idx + shift + folder_list.size()) % folder_list.size(); |
1275 PopupForButton(folder_list[button_idx]); | 1265 PopupForButton(folder_list[button_idx]); |
1276 } | 1266 } |
OLD | NEW |