| OLD | NEW |
| 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/infobars/infobar_container_gtk.h" | 5 #include "chrome/browser/ui/gtk/infobars/infobar_container_gtk.h" |
| 6 | 6 |
| 7 #include <gtk/gtk.h> | 7 #include <gtk/gtk.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 } | 85 } |
| 86 | 86 |
| 87 void InfoBarContainerGtk::ChangeTabContents(TabContentsWrapper* contents) { | 87 void InfoBarContainerGtk::ChangeTabContents(TabContentsWrapper* contents) { |
| 88 registrar_.RemoveAll(); | 88 registrar_.RemoveAll(); |
| 89 | 89 |
| 90 gtk_util::RemoveAllChildren(widget()); | 90 gtk_util::RemoveAllChildren(widget()); |
| 91 UpdateToolbarInfoBarState(NULL, false); | 91 UpdateToolbarInfoBarState(NULL, false); |
| 92 | 92 |
| 93 tab_contents_ = contents; | 93 tab_contents_ = contents; |
| 94 if (tab_contents_) { | 94 if (tab_contents_) { |
| 95 Source<TabContents> source(tab_contents_->tab_contents()); | 95 Source<TabContentsWrapper> source(tab_contents_); |
| 96 registrar_.Add(this, NotificationType::TAB_CONTENTS_INFOBAR_ADDED, source); | 96 registrar_.Add(this, NotificationType::TAB_CONTENTS_INFOBAR_ADDED, source); |
| 97 registrar_.Add(this, NotificationType::TAB_CONTENTS_INFOBAR_REMOVED, | 97 registrar_.Add(this, NotificationType::TAB_CONTENTS_INFOBAR_REMOVED, |
| 98 source); | 98 source); |
| 99 registrar_.Add(this, NotificationType::TAB_CONTENTS_INFOBAR_REPLACED, | 99 registrar_.Add(this, NotificationType::TAB_CONTENTS_INFOBAR_REPLACED, |
| 100 source); | 100 source); |
| 101 for (size_t i = 0; i < tab_contents_->infobar_count(); ++i) { | 101 for (size_t i = 0; i < tab_contents_->infobar_count(); ++i) { |
| 102 InfoBarDelegate* delegate = tab_contents_->GetInfoBarDelegateAt(i); | 102 InfoBarDelegate* delegate = tab_contents_->GetInfoBarDelegateAt(i); |
| 103 AddInfoBar(delegate, false); | 103 AddInfoBar(delegate->CreateInfoBar(tab_contents_), false); |
| 104 } | 104 } |
| 105 } | 105 } |
| 106 } | 106 } |
| 107 | 107 |
| 108 void InfoBarContainerGtk::RemoveDelegate(InfoBarDelegate* delegate) { | 108 void InfoBarContainerGtk::RemoveDelegate(InfoBarDelegate* delegate) { |
| 109 tab_contents_->RemoveInfoBar(delegate); | 109 tab_contents_->RemoveInfoBar(delegate); |
| 110 } | 110 } |
| 111 | 111 |
| 112 int InfoBarContainerGtk::TotalHeightOfAnimatingBars() const { | 112 int InfoBarContainerGtk::TotalHeightOfAnimatingBars() const { |
| 113 int sum = 0; | 113 int sum = 0; |
| 114 gtk_container_foreach(GTK_CONTAINER(widget()), SumAnimatingBarHeight, &sum); | 114 gtk_container_foreach(GTK_CONTAINER(widget()), SumAnimatingBarHeight, &sum); |
| 115 return sum; | 115 return sum; |
| 116 } | 116 } |
| 117 | 117 |
| 118 void InfoBarContainerGtk::Observe(NotificationType type, | 118 void InfoBarContainerGtk::Observe(NotificationType type, |
| 119 const NotificationSource& source, | 119 const NotificationSource& source, |
| 120 const NotificationDetails& details) { | 120 const NotificationDetails& details) { |
| 121 if (type == NotificationType::TAB_CONTENTS_INFOBAR_ADDED) { | 121 switch (type.value) { |
| 122 AddInfoBar(Details<InfoBarDelegate>(details).ptr(), true); | 122 case NotificationType::TAB_CONTENTS_INFOBAR_ADDED: |
| 123 } else if (type == NotificationType::TAB_CONTENTS_INFOBAR_REMOVED) { | 123 AddInfoBar(Details<InfoBar>(details).ptr(), true); |
| 124 RemoveInfoBar(Details<InfoBarDelegate>(details).ptr(), true); | 124 break; |
| 125 } else if (type == NotificationType::TAB_CONTENTS_INFOBAR_REPLACED) { | |
| 126 std::pair<InfoBarDelegate*, InfoBarDelegate*>* delegates = | |
| 127 Details<std::pair<InfoBarDelegate*, InfoBarDelegate*> >(details).ptr(); | |
| 128 | 125 |
| 129 // By not animating the removal/addition, this appears to be a replace. | 126 case NotificationType::TAB_CONTENTS_INFOBAR_REMOVED: { |
| 130 RemoveInfoBar(delegates->first, false); | 127 typedef std::pair<InfoBarDelegate*, bool> RemoveDetails; |
| 131 AddInfoBar(delegates->second, false); | 128 RemoveDetails* remove_details = Details<RemoveDetails>(details).ptr(); |
| 132 } else { | 129 RemoveInfoBar(remove_details->first, remove_details->second); |
| 133 NOTREACHED(); | 130 break; |
| 131 } |
| 132 |
| 133 case NotificationType::TAB_CONTENTS_INFOBAR_REPLACED: { |
| 134 typedef std::pair<InfoBarDelegate*, InfoBar*> ReplaceDetails; |
| 135 ReplaceDetails* replace_details = Details<ReplaceDetails>(details).ptr(); |
| 136 RemoveInfoBar(replace_details->first, false); |
| 137 AddInfoBar(replace_details->second, false); |
| 138 break; |
| 139 } |
| 140 |
| 141 default: |
| 142 NOTREACHED(); |
| 143 break; |
| 134 } | 144 } |
| 135 } | 145 } |
| 136 | 146 |
| 137 void InfoBarContainerGtk::ShowArrowForDelegate(InfoBarDelegate* delegate, | 147 void InfoBarContainerGtk::ShowArrowForDelegate(InfoBarDelegate* delegate, |
| 138 bool animate) { | 148 bool animate) { |
| 139 GList* children = gtk_container_get_children(GTK_CONTAINER(widget())); | 149 GList* children = gtk_container_get_children(GTK_CONTAINER(widget())); |
| 140 if (!children) | 150 if (!children) |
| 141 return; | 151 return; |
| 142 | 152 |
| 143 // Iterate through the infobars and find the last one that isn't closing. | 153 // Iterate through the infobars and find the last one that isn't closing. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 157 } | 167 } |
| 158 | 168 |
| 159 if (last_bar) | 169 if (last_bar) |
| 160 last_bar->ShowArrowFor(this_bar, animate); | 170 last_bar->ShowArrowFor(this_bar, animate); |
| 161 else | 171 else |
| 162 UpdateToolbarInfoBarState(this_bar, animate); | 172 UpdateToolbarInfoBarState(this_bar, animate); |
| 163 | 173 |
| 164 g_list_free(children); | 174 g_list_free(children); |
| 165 } | 175 } |
| 166 | 176 |
| 167 void InfoBarContainerGtk::AddInfoBar(InfoBarDelegate* delegate, bool animate) { | 177 void InfoBarContainerGtk::AddInfoBar(InfoBar* infobar, bool animate) { |
| 168 InfoBar* infobar = delegate->CreateInfoBar(tab_contents_); | |
| 169 infobar->set_container(this); | 178 infobar->set_container(this); |
| 170 infobar->SetThemeProvider(GtkThemeService::GetFrom(profile_)); | 179 infobar->SetThemeProvider(GtkThemeService::GetFrom(profile_)); |
| 171 gtk_box_pack_start(GTK_BOX(widget()), infobar->widget(), | 180 gtk_box_pack_start(GTK_BOX(widget()), infobar->widget(), |
| 172 FALSE, FALSE, 0); | 181 FALSE, FALSE, 0); |
| 173 | 182 |
| 174 infobar->Show(animate); | 183 infobar->Show(animate); |
| 175 ShowArrowForDelegate(delegate, animate); | 184 ShowArrowForDelegate(infobar->delegate(), animate); |
| 176 } | 185 } |
| 177 | 186 |
| 178 void InfoBarContainerGtk::RemoveInfoBar(InfoBarDelegate* delegate, | 187 void InfoBarContainerGtk::RemoveInfoBar(InfoBarDelegate* delegate, |
| 179 bool animate) { | 188 bool animate) { |
| 180 if (animate) { | 189 if (animate) { |
| 181 gtk_container_foreach(GTK_CONTAINER(widget()), | 190 gtk_container_foreach(GTK_CONTAINER(widget()), |
| 182 AnimateClosingForDelegate, delegate); | 191 AnimateClosingForDelegate, delegate); |
| 183 } else { | 192 } else { |
| 184 gtk_container_foreach(GTK_CONTAINER(widget()), ClosingForDelegate, | 193 gtk_container_foreach(GTK_CONTAINER(widget()), ClosingForDelegate, |
| 185 delegate); | 194 delegate); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 197 } | 206 } |
| 198 | 207 |
| 199 void InfoBarContainerGtk::UpdateToolbarInfoBarState(InfoBar* infobar, | 208 void InfoBarContainerGtk::UpdateToolbarInfoBarState(InfoBar* infobar, |
| 200 bool animate) { | 209 bool animate) { |
| 201 GtkWindow* parent = platform_util::GetTopLevel(widget()); | 210 GtkWindow* parent = platform_util::GetTopLevel(widget()); |
| 202 BrowserWindowGtk* browser_window = | 211 BrowserWindowGtk* browser_window = |
| 203 BrowserWindowGtk::GetBrowserWindowForNativeWindow(parent); | 212 BrowserWindowGtk::GetBrowserWindowForNativeWindow(parent); |
| 204 if (browser_window) | 213 if (browser_window) |
| 205 browser_window->SetInfoBarShowing(infobar, animate); | 214 browser_window->SetInfoBarShowing(infobar, animate); |
| 206 } | 215 } |
| OLD | NEW |