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 "base/logging.h" | 7 #include "base/logging.h" |
8 #include "chrome/browser/download/download_item_model.h" | 8 #include "chrome/browser/download/download_item_model.h" |
9 #include "chrome/browser/gtk/download_item_gtk.h" | 9 #include "chrome/browser/gtk/download_item_gtk.h" |
10 #include "chrome/common/l10n_util.h" | 10 #include "chrome/common/l10n_util.h" |
11 #include "chrome/common/resource_bundle.h" | 11 #include "chrome/common/resource_bundle.h" |
12 #include "grit/generated_resources.h" | 12 #include "grit/generated_resources.h" |
13 #include "grit/theme_resources.h" | 13 #include "grit/theme_resources.h" |
14 | 14 |
15 // TODO(port): remove this after tab_contents.h is ported. | 15 // TODO(port): remove this after tab_contents.h is ported. |
16 #include "chrome/common/temp_scaffolding_stubs.h" | 16 #include "chrome/common/temp_scaffolding_stubs.h" |
17 | 17 |
18 namespace { | 18 namespace { |
19 | 19 |
20 // Total height of the shelf. | 20 // Total height of the shelf. This must be at least 28 + 2 * kTopBottomPadding, |
21 const int kShelfHeight = 42; | 21 // or there won't be room to draw the download items. |
22 const int kShelfHeight = 32; | |
22 | 23 |
23 // Padding between the download widgets. | 24 // Padding between the download widgets. |
24 const int kDownloadItemPadding = 10; | 25 const int kDownloadItemPadding = 10; |
25 | 26 |
26 // Padding between the top/bottom of the download widgets and the edge of the | 27 // Padding between the top/bottom of the download widgets and the edge of the |
27 // shelf. | 28 // shelf. |
28 const int kTopBottomPadding = 2; | 29 const int kTopBottomPadding = 2; |
29 | 30 |
30 // Padding from right edge and close button/show downloads link. | 31 // Padding from right edge and close button/show downloads link. |
31 const int kRightPadding = 10; | 32 const int kRightPadding = 10; |
32 | 33 |
34 // The background color of the shelf. | |
35 static GdkColor kBackgroundColor = { 0, 230 << 8, 237 << 8, 244 << 8 }; | |
36 | |
33 } | 37 } |
Dean McNamee
2009/03/05 14:16:01
// namespace
| |
34 | 38 |
35 // static | 39 // static |
36 DownloadShelf* DownloadShelf::Create(TabContents* tab_contents) { | 40 DownloadShelf* DownloadShelf::Create(TabContents* tab_contents) { |
37 return new DownloadShelfGtk(tab_contents); | 41 return new DownloadShelfGtk(tab_contents); |
38 } | 42 } |
39 | 43 |
40 DownloadShelfGtk::DownloadShelfGtk(TabContents* tab_contents) | 44 DownloadShelfGtk::DownloadShelfGtk(TabContents* tab_contents) |
41 : DownloadShelf(tab_contents), | 45 : DownloadShelf(tab_contents), |
42 is_showing_(false) { | 46 is_showing_(false) { |
43 shelf_ = gtk_hbox_new(FALSE, 0); | 47 hbox_ = gtk_hbox_new(FALSE, 0); |
44 gtk_widget_set_size_request(shelf_, -1, kShelfHeight); | 48 gtk_widget_set_size_request(hbox_, -1, kShelfHeight); |
45 gtk_container_set_border_width(GTK_CONTAINER(shelf_), kTopBottomPadding); | 49 gtk_container_set_border_width(GTK_CONTAINER(hbox_), kTopBottomPadding); |
50 shelf_ = gtk_event_box_new(); | |
51 gtk_container_add(GTK_CONTAINER(shelf_), hbox_); | |
52 gtk_widget_modify_bg(shelf_, GTK_STATE_NORMAL, &kBackgroundColor); | |
46 | 53 |
47 // Create and pack the close button. | 54 // Create and pack the close button. |
48 close_button_.reset(new CustomDrawButton(IDR_CLOSE_BAR, | 55 close_button_.reset(new CustomDrawButton(IDR_CLOSE_BAR, |
49 IDR_CLOSE_BAR_P, IDR_CLOSE_BAR_H, 0)); | 56 IDR_CLOSE_BAR_P, IDR_CLOSE_BAR_H, 0)); |
50 g_signal_connect(G_OBJECT(close_button_->widget()), "clicked", | 57 g_signal_connect(G_OBJECT(close_button_->widget()), "clicked", |
51 G_CALLBACK(OnCloseButtonClick), this); | 58 G_CALLBACK(OnCloseButtonClick), this); |
52 GTK_WIDGET_UNSET_FLAGS(close_button_->widget(), GTK_CAN_FOCUS); | 59 GTK_WIDGET_UNSET_FLAGS(close_button_->widget(), GTK_CAN_FOCUS); |
53 GtkWidget* vbox = gtk_vbox_new(FALSE, 0); | 60 GtkWidget* vbox = gtk_vbox_new(FALSE, 0); |
54 gtk_box_pack_start(GTK_BOX(vbox), close_button_->widget(), TRUE, FALSE, 0); | 61 gtk_box_pack_start(GTK_BOX(vbox), close_button_->widget(), TRUE, FALSE, 0); |
55 gtk_box_pack_end(GTK_BOX(shelf_), vbox, FALSE, FALSE, kRightPadding); | 62 gtk_box_pack_end(GTK_BOX(hbox_), vbox, FALSE, FALSE, kRightPadding); |
56 | 63 |
57 // Stick ourselves at the bottom of the parent tab contents. | 64 // Stick ourselves at the bottom of the parent tab contents. |
58 GtkWidget* parent_contents = tab_contents->GetNativeView(); | 65 GtkWidget* parent_contents = tab_contents->GetNativeView(); |
59 gtk_box_pack_end(GTK_BOX(parent_contents), shelf_, FALSE, FALSE, 0); | 66 gtk_box_pack_end(GTK_BOX(parent_contents), shelf_, FALSE, FALSE, 0); |
60 Show(); | 67 Show(); |
61 } | 68 } |
62 | 69 |
63 void DownloadShelfGtk::AddDownload(BaseDownloadItemModel* download_model_) { | 70 void DownloadShelfGtk::AddDownload(BaseDownloadItemModel* download_model_) { |
64 // TODO(estade): we need to delete these at some point. There's no explicit | 71 // TODO(estade): we need to delete these at some point. There's no explicit |
65 // mass delete on windows, figure out where they do it. | 72 // mass delete on windows, figure out where they do it. |
66 download_items_.push_back(new DownloadItemGtk(download_model_, shelf_)); | 73 download_items_.push_back(new DownloadItemGtk(download_model_, hbox_)); |
67 Show(); | 74 Show(); |
68 } | 75 } |
69 | 76 |
70 bool DownloadShelfGtk::IsShowing() const { | 77 bool DownloadShelfGtk::IsShowing() const { |
71 return is_showing_; | 78 return is_showing_; |
72 } | 79 } |
73 | 80 |
74 void DownloadShelfGtk::Show() { | 81 void DownloadShelfGtk::Show() { |
75 if (is_showing_) | 82 if (is_showing_) |
76 return; | 83 return; |
77 | 84 |
78 gtk_widget_show_all(shelf_); | 85 gtk_widget_show_all(shelf_); |
79 is_showing_ = true; | 86 is_showing_ = true; |
80 } | 87 } |
81 | 88 |
82 void DownloadShelfGtk::Hide() { | 89 void DownloadShelfGtk::Hide() { |
83 if (!is_showing_) | 90 if (!is_showing_) |
84 return; | 91 return; |
85 | 92 |
86 gtk_widget_hide_all(shelf_); | 93 gtk_widget_hide_all(shelf_); |
87 is_showing_ = false; | 94 is_showing_ = false; |
88 } | 95 } |
89 | 96 |
90 // static | 97 // static |
91 void DownloadShelfGtk::OnCloseButtonClick(GtkWidget* button, | 98 void DownloadShelfGtk::OnCloseButtonClick(GtkWidget* button, |
92 DownloadShelfGtk* shelf) { | 99 DownloadShelfGtk* shelf) { |
93 shelf->Hide(); | 100 shelf->Hide(); |
94 } | 101 } |
95 | 102 |
OLD | NEW |