| 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/download_shelf_gtk.h" | 5 #include "chrome/browser/gtk/download_shelf_gtk.h" |
| 6 | 6 |
| 7 #include "app/gfx/gtk_util.h" | 7 #include "app/gfx/gtk_util.h" |
| 8 #include "app/l10n_util.h" | 8 #include "app/l10n_util.h" |
| 9 #include "app/resource_bundle.h" | 9 #include "app/resource_bundle.h" |
| 10 #include "chrome/browser/browser.h" | 10 #include "chrome/browser/browser.h" |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED, | 120 registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED, |
| 121 NotificationService::AllSources()); | 121 NotificationService::AllSources()); |
| 122 | 122 |
| 123 gtk_widget_show_all(shelf_.get()); | 123 gtk_widget_show_all(shelf_.get()); |
| 124 | 124 |
| 125 // Stick ourselves at the bottom of the parent browser. | 125 // Stick ourselves at the bottom of the parent browser. |
| 126 gtk_box_pack_end(GTK_BOX(parent), slide_widget_->widget(), | 126 gtk_box_pack_end(GTK_BOX(parent), slide_widget_->widget(), |
| 127 FALSE, FALSE, 0); | 127 FALSE, FALSE, 0); |
| 128 // Make sure we are at the very end. | 128 // Make sure we are at the very end. |
| 129 gtk_box_reorder_child(GTK_BOX(parent), slide_widget_->widget(), 0); | 129 gtk_box_reorder_child(GTK_BOX(parent), slide_widget_->widget(), 0); |
| 130 slide_widget_->Open(); | 130 Show(); |
| 131 } | 131 } |
| 132 | 132 |
| 133 DownloadShelfGtk::~DownloadShelfGtk() { | 133 DownloadShelfGtk::~DownloadShelfGtk() { |
| 134 for (std::vector<DownloadItemGtk*>::iterator iter = download_items_.begin(); | 134 for (std::vector<DownloadItemGtk*>::iterator iter = download_items_.begin(); |
| 135 iter != download_items_.end(); ++iter) { | 135 iter != download_items_.end(); ++iter) { |
| 136 delete *iter; | 136 delete *iter; |
| 137 } | 137 } |
| 138 | 138 |
| 139 shelf_.Destroy(); | 139 shelf_.Destroy(); |
| 140 hbox_.Destroy(); | 140 hbox_.Destroy(); |
| 141 } | 141 } |
| 142 | 142 |
| 143 void DownloadShelfGtk::AddDownload(BaseDownloadItemModel* download_model_) { | 143 void DownloadShelfGtk::AddDownload(BaseDownloadItemModel* download_model_) { |
| 144 download_items_.push_back(new DownloadItemGtk(this, download_model_)); | 144 download_items_.push_back(new DownloadItemGtk(this, download_model_)); |
| 145 Show(); | 145 Show(); |
| 146 } | 146 } |
| 147 | 147 |
| 148 bool DownloadShelfGtk::IsShowing() const { | 148 bool DownloadShelfGtk::IsShowing() const { |
| 149 return slide_widget_->IsShowing(); | 149 return slide_widget_->IsShowing(); |
| 150 } | 150 } |
| 151 | 151 |
| 152 bool DownloadShelfGtk::IsClosing() const { | 152 bool DownloadShelfGtk::IsClosing() const { |
| 153 return slide_widget_->IsClosing(); | 153 return slide_widget_->IsClosing(); |
| 154 } | 154 } |
| 155 | 155 |
| 156 void DownloadShelfGtk::Show() { | 156 void DownloadShelfGtk::Show() { |
| 157 slide_widget_->Open(); | 157 slide_widget_->Open(); |
| 158 browser_->UpdateDownloadShelfVisibility(true); |
| 158 } | 159 } |
| 159 | 160 |
| 160 void DownloadShelfGtk::Close() { | 161 void DownloadShelfGtk::Close() { |
| 161 // When we are closing, we can vertically overlap the render view. Make sure | 162 // When we are closing, we can vertically overlap the render view. Make sure |
| 162 // we are on top. | 163 // we are on top. |
| 163 gdk_window_raise(shelf_.get()->window); | 164 gdk_window_raise(shelf_.get()->window); |
| 164 slide_widget_->Close(); | 165 slide_widget_->Close(); |
| 165 | |
| 166 // TODO(estade): Remove. The status bubble should query its window instead. | |
| 167 browser_->UpdateDownloadShelfVisibility(false); | 166 browser_->UpdateDownloadShelfVisibility(false); |
| 168 } | 167 } |
| 169 | 168 |
| 170 void DownloadShelfGtk::Closed() { | 169 void DownloadShelfGtk::Closed() { |
| 171 // When the close animation is complete, remove all completed downloads. | 170 // When the close animation is complete, remove all completed downloads. |
| 172 size_t i = 0; | 171 size_t i = 0; |
| 173 while (i < download_items_.size()) { | 172 while (i < download_items_.size()) { |
| 174 DownloadItem* download = download_items_[i]->get_download(); | 173 DownloadItem* download = download_items_[i]->get_download(); |
| 175 bool is_transfer_done = download->state() == DownloadItem::COMPLETE || | 174 bool is_transfer_done = download->state() == DownloadItem::COMPLETE || |
| 176 download->state() == DownloadItem::CANCELLED; | 175 download->state() == DownloadItem::CANCELLED; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 | 216 |
| 218 void DownloadShelfGtk::RemoveDownloadItem(DownloadItemGtk* download_item) { | 217 void DownloadShelfGtk::RemoveDownloadItem(DownloadItemGtk* download_item) { |
| 219 DCHECK(download_item); | 218 DCHECK(download_item); |
| 220 std::vector<DownloadItemGtk*>::iterator i = | 219 std::vector<DownloadItemGtk*>::iterator i = |
| 221 find(download_items_.begin(), download_items_.end(), download_item); | 220 find(download_items_.begin(), download_items_.end(), download_item); |
| 222 DCHECK(i != download_items_.end()); | 221 DCHECK(i != download_items_.end()); |
| 223 download_items_.erase(i); | 222 download_items_.erase(i); |
| 224 delete download_item; | 223 delete download_item; |
| 225 if (download_items_.empty()) { | 224 if (download_items_.empty()) { |
| 226 slide_widget_->CloseWithoutAnimation(); | 225 slide_widget_->CloseWithoutAnimation(); |
| 227 | |
| 228 // TODO(estade): Remove. The status bubble should query its window instead. | |
| 229 browser_->UpdateDownloadShelfVisibility(false); | 226 browser_->UpdateDownloadShelfVisibility(false); |
| 230 } | 227 } |
| 231 } | 228 } |
| 232 | 229 |
| 233 GtkWidget* DownloadShelfGtk::GetRightBoundingWidget() const { | 230 GtkWidget* DownloadShelfGtk::GetRightBoundingWidget() const { |
| 234 return link_hbox_; | 231 return link_hbox_; |
| 235 } | 232 } |
| 236 | 233 |
| 237 GtkWidget* DownloadShelfGtk::GetHBox() const { | 234 GtkWidget* DownloadShelfGtk::GetHBox() const { |
| 238 return hbox_.get(); | 235 return hbox_.get(); |
| 239 } | 236 } |
| 240 | 237 |
| 241 // static | 238 // static |
| 242 void DownloadShelfGtk::OnButtonClick(GtkWidget* button, | 239 void DownloadShelfGtk::OnButtonClick(GtkWidget* button, |
| 243 DownloadShelfGtk* shelf) { | 240 DownloadShelfGtk* shelf) { |
| 244 if (button == shelf->close_button_->widget()) { | 241 if (button == shelf->close_button_->widget()) { |
| 245 shelf->Close(); | 242 shelf->Close(); |
| 246 } else { | 243 } else { |
| 247 // The link button was clicked. | 244 // The link button was clicked. |
| 248 shelf->browser_->ShowDownloadsTab(); | 245 shelf->browser_->ShowDownloadsTab(); |
| 249 } | 246 } |
| 250 } | 247 } |
| OLD | NEW |