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

Side by Side Diff: chrome/browser/ui/gtk/bookmarks/bookmark_bar_gtk.cc

Issue 7574021: Remove frontend code that allows for dynamic profile setting, and read the profile off the browse... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 4 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/bookmarks/bookmark_bar_gtk.h" 5 #include "chrome/browser/ui/gtk/bookmarks/bookmark_bar_gtk.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 UMA_HISTOGRAM_ENUMERATION(extension_misc::kAppLaunchHistogram, 114 UMA_HISTOGRAM_ENUMERATION(extension_misc::kAppLaunchHistogram,
115 extension_misc::APP_LAUNCH_BOOKMARK_BAR, 115 extension_misc::APP_LAUNCH_BOOKMARK_BAR,
116 extension_misc::APP_LAUNCH_BUCKET_BOUNDARY); 116 extension_misc::APP_LAUNCH_BUCKET_BOUNDARY);
117 } 117 }
118 118
119 } // namespace 119 } // namespace
120 120
121 const int BookmarkBarGtk::kBookmarkBarNTPHeight = 57; 121 const int BookmarkBarGtk::kBookmarkBarNTPHeight = 57;
122 122
123 BookmarkBarGtk::BookmarkBarGtk(BrowserWindowGtk* window, 123 BookmarkBarGtk::BookmarkBarGtk(BrowserWindowGtk* window,
124 Profile* profile, Browser* browser, 124 Browser* browser,
125 TabstripOriginProvider* tabstrip_origin_provider) 125 TabstripOriginProvider* tabstrip_origin_provider)
126 : profile_(NULL), 126 : page_navigator_(NULL),
127 page_navigator_(NULL),
128 browser_(browser), 127 browser_(browser),
129 window_(window), 128 window_(window),
130 tabstrip_origin_provider_(tabstrip_origin_provider), 129 tabstrip_origin_provider_(tabstrip_origin_provider),
131 model_(NULL), 130 model_(NULL),
132 instructions_(NULL), 131 instructions_(NULL),
133 sync_service_(NULL), 132 sync_service_(NULL),
134 dragged_node_(NULL), 133 dragged_node_(NULL),
135 drag_icon_(NULL), 134 drag_icon_(NULL),
136 toolbar_drop_item_(NULL), 135 toolbar_drop_item_(NULL),
137 theme_service_(GtkThemeService::GetFrom(profile)), 136 theme_service_(GtkThemeService::GetFrom(browser->profile())),
138 show_instructions_(true), 137 show_instructions_(true),
139 menu_bar_helper_(this), 138 menu_bar_helper_(this),
140 slide_animation_(this), 139 slide_animation_(this),
141 last_allocation_width_(-1), 140 last_allocation_width_(-1),
142 throbbing_widget_(NULL), 141 throbbing_widget_(NULL),
143 method_factory_(this), 142 method_factory_(this),
144 bookmark_bar_state_(BookmarkBar::DETACHED) { 143 bookmark_bar_state_(BookmarkBar::DETACHED) {
144 Profile* profile = browser->profile();
145 if (profile->GetProfileSyncService()) { 145 if (profile->GetProfileSyncService()) {
146 // Obtain a pointer to the profile sync service and add our instance as an 146 // Obtain a pointer to the profile sync service and add our instance as an
147 // observer. 147 // observer.
148 sync_service_ = profile->GetProfileSyncService(); 148 sync_service_ = profile->GetProfileSyncService();
149 sync_service_->AddObserver(this); 149 sync_service_->AddObserver(this);
150 } 150 }
151 151
152 Init(profile); 152 Init();
153 SetProfile(profile);
154 // Force an update by simulating being in the wrong state. 153 // Force an update by simulating being in the wrong state.
155 // BrowserWindowGtk sets our true state after we're created. 154 // BrowserWindowGtk sets our true state after we're created.
156 SetBookmarkBarState(BookmarkBar::SHOW, 155 SetBookmarkBarState(BookmarkBar::SHOW,
157 BookmarkBar::DONT_ANIMATE_STATE_CHANGE); 156 BookmarkBar::DONT_ANIMATE_STATE_CHANGE);
158 157
159 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, 158 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED,
160 Source<ThemeService>(theme_service_)); 159 Source<ThemeService>(theme_service_));
161 160
162 edit_bookmarks_enabled_.Init(prefs::kEditBookmarksEnabled, 161 edit_bookmarks_enabled_.Init(prefs::kEditBookmarksEnabled,
163 profile_->GetPrefs(), this); 162 profile->GetPrefs(), this);
164 OnEditBookmarksEnabledChanged(); 163 OnEditBookmarksEnabledChanged();
165 } 164 }
166 165
167 BookmarkBarGtk::~BookmarkBarGtk() { 166 BookmarkBarGtk::~BookmarkBarGtk() {
168 RemoveAllBookmarkButtons(); 167 RemoveAllButtons();
169 bookmark_toolbar_.Destroy(); 168 bookmark_toolbar_.Destroy();
170 event_box_.Destroy(); 169 event_box_.Destroy();
171 } 170 }
172 171
173 void BookmarkBarGtk::SetProfile(Profile* profile) {
174 DCHECK(profile);
175 if (profile_ == profile)
176 return;
177
178 RemoveAllBookmarkButtons();
179
180 profile_ = profile;
181
182 if (model_)
183 model_->RemoveObserver(this);
184
185 // TODO(erg): Handle extensions
186
187 model_ = profile_->GetBookmarkModel();
188 model_->AddObserver(this);
189 if (model_->IsLoaded())
190 Loaded(model_, false);
191
192 // else case: we'll receive notification back from the BookmarkModel when done
193 // loading, then we'll populate the bar.
194 }
195
196 void BookmarkBarGtk::SetPageNavigator(PageNavigator* navigator) { 172 void BookmarkBarGtk::SetPageNavigator(PageNavigator* navigator) {
197 page_navigator_ = navigator; 173 page_navigator_ = navigator;
198 } 174 }
199 175
200 void BookmarkBarGtk::Init(Profile* profile) { 176 void BookmarkBarGtk::Init() {
201 event_box_.Own(gtk_event_box_new()); 177 event_box_.Own(gtk_event_box_new());
202 g_signal_connect(event_box_.get(), "destroy", 178 g_signal_connect(event_box_.get(), "destroy",
203 G_CALLBACK(&OnEventBoxDestroyThunk), this); 179 G_CALLBACK(&OnEventBoxDestroyThunk), this);
204 g_signal_connect(event_box_.get(), "button-press-event", 180 g_signal_connect(event_box_.get(), "button-press-event",
205 G_CALLBACK(&OnButtonPressedThunk), this); 181 G_CALLBACK(&OnButtonPressedThunk), this);
206 182
207 ntp_padding_box_ = gtk_alignment_new(0, 0, 1, 1); 183 ntp_padding_box_ = gtk_alignment_new(0, 0, 1, 1);
208 gtk_container_add(GTK_CONTAINER(event_box_.get()), ntp_padding_box_); 184 gtk_container_add(GTK_CONTAINER(event_box_.get()), ntp_padding_box_);
209 185
210 paint_box_ = gtk_event_box_new(); 186 paint_box_ = gtk_event_box_new();
211 gtk_container_add(GTK_CONTAINER(ntp_padding_box_), paint_box_); 187 gtk_container_add(GTK_CONTAINER(ntp_padding_box_), paint_box_);
212 GdkColor paint_box_color = 188 GdkColor paint_box_color =
213 theme_service_->GetGdkColor(ThemeService::COLOR_TOOLBAR); 189 theme_service_->GetGdkColor(ThemeService::COLOR_TOOLBAR);
214 gtk_widget_modify_bg(paint_box_, GTK_STATE_NORMAL, &paint_box_color); 190 gtk_widget_modify_bg(paint_box_, GTK_STATE_NORMAL, &paint_box_color);
215 gtk_widget_add_events(paint_box_, GDK_POINTER_MOTION_MASK | 191 gtk_widget_add_events(paint_box_, GDK_POINTER_MOTION_MASK |
216 GDK_BUTTON_PRESS_MASK); 192 GDK_BUTTON_PRESS_MASK);
217 193
218 bookmark_hbox_ = gtk_hbox_new(FALSE, 0); 194 bookmark_hbox_ = gtk_hbox_new(FALSE, 0);
219 gtk_container_add(GTK_CONTAINER(paint_box_), bookmark_hbox_); 195 gtk_container_add(GTK_CONTAINER(paint_box_), bookmark_hbox_);
220 196
221 instructions_ = gtk_alignment_new(0, 0, 1, 1); 197 instructions_ = gtk_alignment_new(0, 0, 1, 1);
222 gtk_alignment_set_padding(GTK_ALIGNMENT(instructions_), 0, 0, 198 gtk_alignment_set_padding(GTK_ALIGNMENT(instructions_), 0, 0,
223 kInstructionsPadding, 0); 199 kInstructionsPadding, 0);
200 Profile* profile = browser_->profile();
224 instructions_gtk_.reset(new BookmarkBarInstructionsGtk(this, profile)); 201 instructions_gtk_.reset(new BookmarkBarInstructionsGtk(this, profile));
225 gtk_container_add(GTK_CONTAINER(instructions_), instructions_gtk_->widget()); 202 gtk_container_add(GTK_CONTAINER(instructions_), instructions_gtk_->widget());
226 gtk_box_pack_start(GTK_BOX(bookmark_hbox_), instructions_, 203 gtk_box_pack_start(GTK_BOX(bookmark_hbox_), instructions_,
227 TRUE, TRUE, 0); 204 TRUE, TRUE, 0);
228 205
229 gtk_drag_dest_set(instructions_, 206 gtk_drag_dest_set(instructions_,
230 GtkDestDefaults(GTK_DEST_DEFAULT_DROP | GTK_DEST_DEFAULT_MOTION), 207 GtkDestDefaults(GTK_DEST_DEFAULT_DROP | GTK_DEST_DEFAULT_MOTION),
231 NULL, 0, kDragAction); 208 NULL, 0, kDragAction);
232 ui::SetDestTargetList(instructions_, kDestTargetList); 209 ui::SetDestTargetList(instructions_, kDestTargetList);
233 g_signal_connect(instructions_, "drag-data-received", 210 g_signal_connect(instructions_, "drag-data-received",
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 gtk_box_pack_start(GTK_BOX(bookmark_hbox_), sync_error_button_, 280 gtk_box_pack_start(GTK_BOX(bookmark_hbox_), sync_error_button_,
304 FALSE, FALSE, 0); 281 FALSE, FALSE, 0);
305 282
306 gtk_widget_set_size_request(event_box_.get(), -1, kBookmarkBarMinimumHeight); 283 gtk_widget_set_size_request(event_box_.get(), -1, kBookmarkBarMinimumHeight);
307 284
308 ViewIDUtil::SetID(other_bookmarks_button_, VIEW_ID_OTHER_BOOKMARKS); 285 ViewIDUtil::SetID(other_bookmarks_button_, VIEW_ID_OTHER_BOOKMARKS);
309 ViewIDUtil::SetID(widget(), VIEW_ID_BOOKMARK_BAR); 286 ViewIDUtil::SetID(widget(), VIEW_ID_BOOKMARK_BAR);
310 287
311 gtk_widget_show_all(widget()); 288 gtk_widget_show_all(widget());
312 gtk_widget_hide(widget()); 289 gtk_widget_hide(widget());
290
291 AddCoreButtons();
292 // TODO(erg): Handle extensions
293 model_ = profile->GetBookmarkModel();
294 model_->AddObserver(this);
295 if (model_->IsLoaded())
296 Loaded(model_, false);
297 // else case: we'll receive notification back from the BookmarkModel when done
298 // loading, then we'll populate the bar.
313 } 299 }
314 300
315 void BookmarkBarGtk::SetBookmarkBarState( 301 void BookmarkBarGtk::SetBookmarkBarState(
316 BookmarkBar::State state, 302 BookmarkBar::State state,
317 BookmarkBar::AnimateChangeType animate_type) { 303 BookmarkBar::AnimateChangeType animate_type) {
318 if (animate_type == BookmarkBar::ANIMATE_STATE_CHANGE && 304 if (animate_type == BookmarkBar::ANIMATE_STATE_CHANGE &&
319 (state == BookmarkBar::DETACHED || 305 (state == BookmarkBar::DETACHED ||
320 bookmark_bar_state_ == BookmarkBar::DETACHED)) { 306 bookmark_bar_state_ == BookmarkBar::DETACHED)) {
321 // TODO(estade): animate the transition between detached and non or remove 307 // TODO(estade): animate the transition between detached and non or remove
322 // detached entirely. 308 // detached entirely.
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 return; 377 return;
392 } else { 378 } else {
393 // Overflow exists: don't show anything for an overflowed folder button. 379 // Overflow exists: don't show anything for an overflowed folder button.
394 if (button != overflow_button_ && button != other_bookmarks_button_ && 380 if (button != overflow_button_ && button != other_bookmarks_button_ &&
395 node->parent()->GetIndexOf(node) >= first_hidden) { 381 node->parent()->GetIndexOf(node) >= first_hidden) {
396 return; 382 return;
397 } 383 }
398 } 384 }
399 385
400 current_menu_.reset( 386 current_menu_.reset(
401 new BookmarkMenuController(browser_, profile_, page_navigator_, 387 new BookmarkMenuController(browser_, browser_->profile(), page_navigator_,
402 GTK_WINDOW(gtk_widget_get_toplevel(button)), 388 GTK_WINDOW(gtk_widget_get_toplevel(button)),
403 node, 389 node,
404 button == overflow_button_ ? 390 button == overflow_button_ ?
405 first_hidden : 0)); 391 first_hidden : 0));
406 menu_bar_helper_.MenuStartedShowing(button, current_menu_->widget()); 392 menu_bar_helper_.MenuStartedShowing(button, current_menu_->widget());
407 GdkEvent* event = gtk_get_current_event(); 393 GdkEvent* event = gtk_get_current_event();
408 current_menu_->Popup(button, event->button.button, event->button.time); 394 current_menu_->Popup(button, event->button.button, event->button.time);
409 gdk_event_free(event); 395 gdk_event_free(event);
410 } 396 }
411 397
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 if (slide_animation_.IsShowing() && 485 if (slide_animation_.IsShowing() &&
500 animate_type == BookmarkBar::ANIMATE_STATE_CHANGE) { 486 animate_type == BookmarkBar::ANIMATE_STATE_CHANGE) {
501 slide_animation_.Hide(); 487 slide_animation_.Hide();
502 } else { 488 } else {
503 gtk_widget_hide(bookmark_hbox_); 489 gtk_widget_hide(bookmark_hbox_);
504 slide_animation_.Reset(0); 490 slide_animation_.Reset(0);
505 AnimationProgressed(&slide_animation_); 491 AnimationProgressed(&slide_animation_);
506 } 492 }
507 } 493 }
508 494
509 void BookmarkBarGtk::CreateAllBookmarkButtons() {
510 const BookmarkNode* bar = model_->bookmark_bar_node();
511 DCHECK(bar && model_->other_node());
512
513 // Create a button for each of the children on the bookmark bar.
514 for (int i = 0; i < bar->child_count(); ++i) {
515 const BookmarkNode* node = bar->GetChild(i);
516 GtkToolItem* item = CreateBookmarkToolItem(node);
517 gtk_toolbar_insert(GTK_TOOLBAR(bookmark_toolbar_.get()), item, -1);
518 if (node->is_folder())
519 menu_bar_helper_.Add(gtk_bin_get_child(GTK_BIN(item)));
520 }
521
522 bookmark_utils::ConfigureButtonForNode(model_->other_node(),
523 model_, other_bookmarks_button_, theme_service_);
524
525 SetInstructionState();
526 SetChevronState();
527 }
528
529 void BookmarkBarGtk::SetInstructionState() { 495 void BookmarkBarGtk::SetInstructionState() {
530 if (model_) 496 if (model_)
531 show_instructions_ = model_->bookmark_bar_node()->empty(); 497 show_instructions_ = model_->bookmark_bar_node()->empty();
532 498
533 gtk_widget_set_visible(bookmark_toolbar_.get(), !show_instructions_); 499 gtk_widget_set_visible(bookmark_toolbar_.get(), !show_instructions_);
534 gtk_widget_set_visible(instructions_, show_instructions_); 500 gtk_widget_set_visible(instructions_, show_instructions_);
535 } 501 }
536 502
537 void BookmarkBarGtk::SetChevronState() { 503 void BookmarkBarGtk::SetChevronState() {
538 if (!gtk_widget_get_visible(bookmark_hbox_)) 504 if (!gtk_widget_get_visible(bookmark_hbox_))
(...skipping 17 matching lines...) Expand all
556 522
557 void BookmarkBarGtk::UpdateOtherBookmarksVisibility() { 523 void BookmarkBarGtk::UpdateOtherBookmarksVisibility() {
558 bool has_other_children = !model_->other_node()->empty(); 524 bool has_other_children = !model_->other_node()->empty();
559 if (has_other_children == gtk_widget_get_visible(other_bookmarks_button_)) 525 if (has_other_children == gtk_widget_get_visible(other_bookmarks_button_))
560 return; 526 return;
561 527
562 gtk_widget_set_visible(other_bookmarks_button_, has_other_children); 528 gtk_widget_set_visible(other_bookmarks_button_, has_other_children);
563 gtk_widget_set_visible(other_bookmarks_separator_, has_other_children); 529 gtk_widget_set_visible(other_bookmarks_separator_, has_other_children);
564 } 530 }
565 531
566 void BookmarkBarGtk::RemoveAllBookmarkButtons() { 532 void BookmarkBarGtk::RemoveAllButtons() {
567 gtk_util::RemoveAllChildren(bookmark_toolbar_.get()); 533 gtk_util::RemoveAllChildren(bookmark_toolbar_.get());
568 menu_bar_helper_.Clear(); 534 menu_bar_helper_.Clear();
535 }
536
537 void BookmarkBarGtk::AddCoreButtons() {
569 menu_bar_helper_.Add(other_bookmarks_button_); 538 menu_bar_helper_.Add(other_bookmarks_button_);
570 menu_bar_helper_.Add(overflow_button_); 539 menu_bar_helper_.Add(overflow_button_);
571 } 540 }
572 541
542 void BookmarkBarGtk::ResetButtons() {
543 RemoveAllButtons();
544 AddCoreButtons();
545
546 const BookmarkNode* bar = model_->bookmark_bar_node();
547 DCHECK(bar && model_->other_node());
548
549 // Create a button for each of the children on the bookmark bar.
550 for (int i = 0; i < bar->child_count(); ++i) {
551 const BookmarkNode* node = bar->GetChild(i);
552 GtkToolItem* item = CreateBookmarkToolItem(node);
553 gtk_toolbar_insert(GTK_TOOLBAR(bookmark_toolbar_.get()), item, -1);
554 if (node->is_folder())
555 menu_bar_helper_.Add(gtk_bin_get_child(GTK_BIN(item)));
556 }
557
558 bookmark_utils::ConfigureButtonForNode(model_->other_node(),
559 model_, other_bookmarks_button_, theme_service_);
560
561 SetInstructionState();
562 SetChevronState();
563 }
564
573 int BookmarkBarGtk::GetBookmarkButtonCount() { 565 int BookmarkBarGtk::GetBookmarkButtonCount() {
574 GList* children = gtk_container_get_children( 566 GList* children = gtk_container_get_children(
575 GTK_CONTAINER(bookmark_toolbar_.get())); 567 GTK_CONTAINER(bookmark_toolbar_.get()));
576 int count = g_list_length(children); 568 int count = g_list_length(children);
577 g_list_free(children); 569 g_list_free(children);
578 return count; 570 return count;
579 } 571 }
580 572
581 void BookmarkBarGtk::SetOverflowButtonAppearance() { 573 void BookmarkBarGtk::SetOverflowButtonAppearance() {
582 GtkWidget* former_child = gtk_bin_get_child(GTK_BIN(overflow_button_)); 574 GtkWidget* former_child = gtk_bin_get_child(GTK_BIN(overflow_button_));
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
846 NULL, 0); 838 NULL, 0);
847 } 839 }
848 840
849 void BookmarkBarGtk::Loaded(BookmarkModel* model, bool ids_reassigned) { 841 void BookmarkBarGtk::Loaded(BookmarkModel* model, bool ids_reassigned) {
850 // If |instructions_| has been nulled, we are in the middle of browser 842 // If |instructions_| has been nulled, we are in the middle of browser
851 // shutdown. Do nothing. 843 // shutdown. Do nothing.
852 if (!instructions_) 844 if (!instructions_)
853 return; 845 return;
854 846
855 UpdateOtherBookmarksVisibility(); 847 UpdateOtherBookmarksVisibility();
856 RemoveAllBookmarkButtons(); 848 ResetButtons();
857 CreateAllBookmarkButtons();
858 } 849 }
859 850
860 void BookmarkBarGtk::BookmarkModelBeingDeleted(BookmarkModel* model) { 851 void BookmarkBarGtk::BookmarkModelBeingDeleted(BookmarkModel* model) {
861 // The bookmark model should never be deleted before us. This code exists 852 // The bookmark model should never be deleted before us. This code exists
862 // to check for regressions in shutdown code and not crash. 853 // to check for regressions in shutdown code and not crash.
863 if (!browser_shutdown::ShuttingDownWithoutClosingBrowsers()) 854 if (!browser_shutdown::ShuttingDownWithoutClosingBrowsers())
864 NOTREACHED(); 855 NOTREACHED();
865 856
866 // Do minimal cleanup, presumably we'll be deleted shortly. 857 // Do minimal cleanup, presumably we'll be deleted shortly.
867 model_->RemoveObserver(this); 858 model_->RemoveObserver(this);
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
942 void BookmarkBarGtk::BookmarkNodeFaviconChanged(BookmarkModel* model, 933 void BookmarkBarGtk::BookmarkNodeFaviconChanged(BookmarkModel* model,
943 const BookmarkNode* node) { 934 const BookmarkNode* node) {
944 BookmarkNodeChanged(model, node); 935 BookmarkNodeChanged(model, node);
945 } 936 }
946 937
947 void BookmarkBarGtk::BookmarkNodeChildrenReordered(BookmarkModel* model, 938 void BookmarkBarGtk::BookmarkNodeChildrenReordered(BookmarkModel* model,
948 const BookmarkNode* node) { 939 const BookmarkNode* node) {
949 if (node != model_->bookmark_bar_node()) 940 if (node != model_->bookmark_bar_node())
950 return; // We only care about reordering of the bookmark bar node. 941 return; // We only care about reordering of the bookmark bar node.
951 942
952 // Purge and rebuild the bar. 943 ResetButtons();
953 RemoveAllBookmarkButtons();
954 CreateAllBookmarkButtons();
955 } 944 }
956 945
957 void BookmarkBarGtk::Observe(int type, 946 void BookmarkBarGtk::Observe(int type,
958 const NotificationSource& source, 947 const NotificationSource& source,
959 const NotificationDetails& details) { 948 const NotificationDetails& details) {
960 if (type == chrome::NOTIFICATION_BROWSER_THEME_CHANGED) { 949 if (type == chrome::NOTIFICATION_BROWSER_THEME_CHANGED) {
961 if (model_ && model_->IsLoaded()) { 950 if (model_ && model_->IsLoaded()) {
962 // Regenerate the bookmark bar with all new objects with their theme 951 // Regenerate the bookmark bar with all new objects with their theme
963 // properties set correctly for the new theme. 952 // properties set correctly for the new theme.
964 RemoveAllBookmarkButtons(); 953 ResetButtons();
965 CreateAllBookmarkButtons();
966 } 954 }
967 955
968 // Resize the bookmark bar since the target height may have changed. 956 // Resize the bookmark bar since the target height may have changed.
969 AnimationProgressed(&slide_animation_); 957 AnimationProgressed(&slide_animation_);
970 958
971 UpdateEventBoxPaintability(); 959 UpdateEventBoxPaintability();
972 960
973 GdkColor paint_box_color = 961 GdkColor paint_box_color =
974 theme_service_->GetGdkColor(ThemeService::COLOR_TOOLBAR); 962 theme_service_->GetGdkColor(ThemeService::COLOR_TOOLBAR);
975 gtk_widget_modify_bg(paint_box_, GTK_STATE_NORMAL, &paint_box_color); 963 gtk_widget_modify_bg(paint_box_, GTK_STATE_NORMAL, &paint_box_color);
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
1112 nodes.push_back(node); 1100 nodes.push_back(node);
1113 parent = node->parent(); 1101 parent = node->parent();
1114 } else { 1102 } else {
1115 parent = model_->bookmark_bar_node(); 1103 parent = model_->bookmark_bar_node();
1116 nodes.push_back(parent); 1104 nodes.push_back(parent);
1117 } 1105 }
1118 1106
1119 GtkWindow* window = GTK_WINDOW(gtk_widget_get_toplevel(sender)); 1107 GtkWindow* window = GTK_WINDOW(gtk_widget_get_toplevel(sender));
1120 current_context_menu_controller_.reset( 1108 current_context_menu_controller_.reset(
1121 new BookmarkContextMenuController( 1109 new BookmarkContextMenuController(
1122 window, this, profile_, page_navigator_, parent, nodes)); 1110 window, this, browser_->profile(), page_navigator_, parent, nodes));
1123 current_context_menu_.reset( 1111 current_context_menu_.reset(
1124 new MenuGtk(NULL, current_context_menu_controller_->menu_model())); 1112 new MenuGtk(NULL, current_context_menu_controller_->menu_model()));
1125 current_context_menu_->PopupAsContext( 1113 current_context_menu_->PopupAsContext(
1126 gfx::Point(event->x_root, event->y_root), 1114 gfx::Point(event->x_root, event->y_root),
1127 event->time); 1115 event->time);
1128 } 1116 }
1129 1117
1130 gboolean BookmarkBarGtk::OnButtonPressed(GtkWidget* sender, 1118 gboolean BookmarkBarGtk::OnButtonPressed(GtkWidget* sender,
1131 GdkEventButton* event) { 1119 GdkEventButton* event) {
1132 last_pressed_coordinates_ = gfx::Point(event->x, event->y); 1120 last_pressed_coordinates_ = gfx::Point(event->x, event->y);
(...skipping 17 matching lines...) Expand all
1150 1138
1151 return FALSE; 1139 return FALSE;
1152 } 1140 }
1153 1141
1154 void BookmarkBarGtk::OnClicked(GtkWidget* sender) { 1142 void BookmarkBarGtk::OnClicked(GtkWidget* sender) {
1155 const BookmarkNode* node = GetNodeForToolButton(sender); 1143 const BookmarkNode* node = GetNodeForToolButton(sender);
1156 DCHECK(node); 1144 DCHECK(node);
1157 DCHECK(node->is_url()); 1145 DCHECK(node->is_url());
1158 DCHECK(page_navigator_); 1146 DCHECK(page_navigator_);
1159 1147
1160 RecordAppLaunch(profile_, node->url()); 1148 Profile* profile = browser_->profile();
1161 bookmark_utils::OpenAll(window_->GetNativeHandle(), 1149 RecordAppLaunch(profile, node->url());
1162 profile_, page_navigator_, node, 1150 bookmark_utils::OpenAll(window_->GetNativeHandle(), profile, page_navigator_,
1163 gtk_util::DispositionForCurrentButtonPressEvent()); 1151 node, gtk_util::DispositionForCurrentButtonPressEvent());
1164 1152
1165 UserMetrics::RecordAction(UserMetricsAction("ClickedBookmarkBarURLButton")); 1153 UserMetrics::RecordAction(UserMetricsAction("ClickedBookmarkBarURLButton"));
1166 } 1154 }
1167 1155
1168 void BookmarkBarGtk::OnButtonDragBegin(GtkWidget* button, 1156 void BookmarkBarGtk::OnButtonDragBegin(GtkWidget* button,
1169 GdkDragContext* drag_context) { 1157 GdkDragContext* drag_context) {
1170 // The parent tool item might be removed during the drag. Ref it so |button| 1158 // The parent tool item might be removed during the drag. Ref it so |button|
1171 // won't get destroyed. 1159 // won't get destroyed.
1172 g_object_ref(button->parent); 1160 g_object_ref(button->parent);
1173 1161
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1213 DCHECK(dragged_node_); 1201 DCHECK(dragged_node_);
1214 dragged_node_ = NULL; 1202 dragged_node_ = NULL;
1215 1203
1216 DCHECK(drag_icon_); 1204 DCHECK(drag_icon_);
1217 gtk_widget_destroy(drag_icon_); 1205 gtk_widget_destroy(drag_icon_);
1218 drag_icon_ = NULL; 1206 drag_icon_ = NULL;
1219 1207
1220 g_object_unref(button->parent); 1208 g_object_unref(button->parent);
1221 } 1209 }
1222 1210
1223 void BookmarkBarGtk::OnButtonDragGet(GtkWidget* widget, GdkDragContext* context, 1211 void BookmarkBarGtk::OnButtonDragGet(GtkWidget* widget,
1212 GdkDragContext* context,
1224 GtkSelectionData* selection_data, 1213 GtkSelectionData* selection_data,
1225 guint target_type, guint time) { 1214 guint target_type,
1215 guint time) {
1226 const BookmarkNode* node = bookmark_utils::BookmarkNodeForWidget(widget); 1216 const BookmarkNode* node = bookmark_utils::BookmarkNodeForWidget(widget);
1227 bookmark_utils::WriteBookmarkToSelection(node, selection_data, target_type, 1217 bookmark_utils::WriteBookmarkToSelection(node, selection_data, target_type,
1228 profile_); 1218 browser_->profile());
1229 } 1219 }
1230 1220
1231 void BookmarkBarGtk::OnFolderClicked(GtkWidget* sender) { 1221 void BookmarkBarGtk::OnFolderClicked(GtkWidget* sender) {
1232 // Stop its throbbing, if any. 1222 // Stop its throbbing, if any.
1233 HoverControllerGtk* hover_controller = 1223 HoverControllerGtk* hover_controller =
1234 HoverControllerGtk::GetHoverControllerGtk(sender); 1224 HoverControllerGtk::GetHoverControllerGtk(sender);
1235 if (hover_controller) 1225 if (hover_controller)
1236 hover_controller->StartThrobbing(0); 1226 hover_controller->StartThrobbing(0);
1237 1227
1238 GdkEvent* event = gtk_get_current_event(); 1228 GdkEvent* event = gtk_get_current_event();
1239 if (event->button.button == 1) { 1229 if (event->button.button == 1) {
1240 PopupForButton(sender); 1230 PopupForButton(sender);
1241 } else if (event->button.button == 2) { 1231 } else if (event->button.button == 2) {
1242 const BookmarkNode* node = GetNodeForToolButton(sender); 1232 const BookmarkNode* node = GetNodeForToolButton(sender);
1243 bookmark_utils::OpenAll(window_->GetNativeHandle(), 1233 bookmark_utils::OpenAll(window_->GetNativeHandle(), browser_->profile(),
1244 profile_, page_navigator_, 1234 page_navigator_, node, NEW_BACKGROUND_TAB);
1245 node, NEW_BACKGROUND_TAB);
1246 } 1235 }
1247 } 1236 }
1248 1237
1249 gboolean BookmarkBarGtk::OnToolbarDragMotion(GtkWidget* toolbar, 1238 gboolean BookmarkBarGtk::OnToolbarDragMotion(GtkWidget* toolbar,
1250 GdkDragContext* context, 1239 GdkDragContext* context,
1251 gint x, 1240 gint x,
1252 gint y, 1241 gint y,
1253 guint time) { 1242 guint time) {
1254 gint index = gtk_toolbar_get_drop_index(GTK_TOOLBAR(toolbar), x, y); 1243 gint index = gtk_toolbar_get_drop_index(GTK_TOOLBAR(toolbar), x, y);
1255 return ItemDraggedOverToolbar(context, index, time); 1244 return ItemDraggedOverToolbar(context, index, time);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1297 dest_node = GetNodeForToolButton(widget); 1286 dest_node = GetNodeForToolButton(widget);
1298 index = dest_node->child_count(); 1287 index = dest_node->child_count();
1299 } 1288 }
1300 } 1289 }
1301 1290
1302 switch (target_type) { 1291 switch (target_type) {
1303 case ui::CHROME_BOOKMARK_ITEM: { 1292 case ui::CHROME_BOOKMARK_ITEM: {
1304 std::vector<const BookmarkNode*> nodes = 1293 std::vector<const BookmarkNode*> nodes =
1305 bookmark_utils::GetNodesFromSelection(context, selection_data, 1294 bookmark_utils::GetNodesFromSelection(context, selection_data,
1306 target_type, 1295 target_type,
1307 profile_, 1296 browser_->profile(),
1308 &delete_selection_data, 1297 &delete_selection_data,
1309 &dnd_success); 1298 &dnd_success);
1310 DCHECK(!nodes.empty()); 1299 DCHECK(!nodes.empty());
1311 for (std::vector<const BookmarkNode*>::iterator it = nodes.begin(); 1300 for (std::vector<const BookmarkNode*>::iterator it = nodes.begin();
1312 it != nodes.end(); ++it) { 1301 it != nodes.end(); ++it) {
1313 model_->Move(*it, dest_node, index); 1302 model_->Move(*it, dest_node, index);
1314 index = dest_node->GetIndexOf(*it) + 1; 1303 index = dest_node->GetIndexOf(*it) + 1;
1315 } 1304 }
1316 break; 1305 break;
1317 } 1306 }
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
1471 void BookmarkBarGtk::OnEditBookmarksEnabledChanged() { 1460 void BookmarkBarGtk::OnEditBookmarksEnabledChanged() {
1472 GtkDestDefaults dest_defaults = 1461 GtkDestDefaults dest_defaults =
1473 *edit_bookmarks_enabled_ ? GTK_DEST_DEFAULT_ALL : 1462 *edit_bookmarks_enabled_ ? GTK_DEST_DEFAULT_ALL :
1474 GTK_DEST_DEFAULT_DROP; 1463 GTK_DEST_DEFAULT_DROP;
1475 gtk_drag_dest_set(overflow_button_, dest_defaults, NULL, 0, kDragAction); 1464 gtk_drag_dest_set(overflow_button_, dest_defaults, NULL, 0, kDragAction);
1476 gtk_drag_dest_set(other_bookmarks_button_, dest_defaults, 1465 gtk_drag_dest_set(other_bookmarks_button_, dest_defaults,
1477 NULL, 0, kDragAction); 1466 NULL, 0, kDragAction);
1478 ui::SetDestTargetList(overflow_button_, kDestTargetList); 1467 ui::SetDestTargetList(overflow_button_, kDestTargetList);
1479 ui::SetDestTargetList(other_bookmarks_button_, kDestTargetList); 1468 ui::SetDestTargetList(other_bookmarks_button_, kDestTargetList);
1480 } 1469 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/gtk/bookmarks/bookmark_bar_gtk.h ('k') | chrome/browser/ui/gtk/bookmarks/bookmark_bar_gtk_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698