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

Side by Side Diff: chrome/browser/gtk/download_shelf_gtk.cc

Issue 115740: Move download shelf from per-tab to per-window (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 11 years, 6 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
« no previous file with comments | « chrome/browser/gtk/download_shelf_gtk.h ('k') | chrome/browser/gtk/tabs/tab_renderer_gtk.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/l10n_util.h" 7 #include "app/l10n_util.h"
8 #include "app/resource_bundle.h" 8 #include "app/resource_bundle.h"
9 #include "base/gfx/gtk_util.h" 9 #include "base/gfx/gtk_util.h"
10 #include "chrome/browser/browser.h"
10 #include "chrome/browser/download/download_item_model.h" 11 #include "chrome/browser/download/download_item_model.h"
11 #include "chrome/browser/download/download_util.h" 12 #include "chrome/browser/download/download_util.h"
13 #include "chrome/browser/gtk/browser_window_gtk.h"
12 #include "chrome/browser/gtk/custom_button.h" 14 #include "chrome/browser/gtk/custom_button.h"
13 #include "chrome/browser/gtk/download_item_gtk.h" 15 #include "chrome/browser/gtk/download_item_gtk.h"
14 #include "chrome/browser/gtk/gtk_chrome_link_button.h" 16 #include "chrome/browser/gtk/gtk_chrome_link_button.h"
15 #include "chrome/browser/gtk/slide_animator_gtk.h" 17 #include "chrome/browser/gtk/slide_animator_gtk.h"
16 #include "chrome/browser/tab_contents/tab_contents.h" 18 #include "chrome/browser/tab_contents/tab_contents.h"
17 #include "chrome/common/gtk_util.h" 19 #include "chrome/common/gtk_util.h"
18 #include "grit/generated_resources.h" 20 #include "grit/generated_resources.h"
19 #include "grit/theme_resources.h" 21 #include "grit/theme_resources.h"
20 22
21 namespace { 23 namespace {
(...skipping 18 matching lines...) Expand all
40 const GdkColor kBackgroundColor = GDK_COLOR_RGB(230, 237, 244); 42 const GdkColor kBackgroundColor = GDK_COLOR_RGB(230, 237, 244);
41 43
42 // Border color (the top pixel of the shelf). 44 // Border color (the top pixel of the shelf).
43 const GdkColor kBorderColor = GDK_COLOR_RGB(214, 214, 214); 45 const GdkColor kBorderColor = GDK_COLOR_RGB(214, 214, 214);
44 46
45 // Speed of the shelf show/hide animation. 47 // Speed of the shelf show/hide animation.
46 const int kShelfAnimationDurationMs = 120; 48 const int kShelfAnimationDurationMs = 120;
47 49
48 } // namespace 50 } // namespace
49 51
50 // static 52 DownloadShelfGtk::DownloadShelfGtk(Browser* browser, GtkWidget* parent)
51 DownloadShelf* DownloadShelf::Create(TabContents* tab_contents) { 53 : DownloadShelf(browser),
52 return new DownloadShelfGtk(tab_contents);
53 }
54
55 DownloadShelfGtk::DownloadShelfGtk(TabContents* tab_contents)
56 : DownloadShelf(tab_contents),
57 is_showing_(false) { 54 is_showing_(false) {
58 // Logically, the shelf is a vbox that contains two children: a one pixel 55 // Logically, the shelf is a vbox that contains two children: a one pixel
59 // tall event box, which serves as the top border, and an hbox, which holds 56 // tall event box, which serves as the top border, and an hbox, which holds
60 // the download items and other shelf widgets (close button, show-all- 57 // the download items and other shelf widgets (close button, show-all-
61 // downloads link). 58 // downloads link).
62 // To make things pretty, we have to add a few more widgets. To get padding 59 // To make things pretty, we have to add a few more widgets. To get padding
63 // right, we stick the hbox in an alignment. We put that alignment in an 60 // right, we stick the hbox in an alignment. We put that alignment in an
64 // event box so we can color the background. 61 // event box so we can color the background.
65 62
66 // Create the top border. 63 // Create the top border.
67 GtkWidget* top_border = gtk_event_box_new(); 64 GtkWidget* top_border = gtk_event_box_new();
68 gtk_widget_set_size_request(GTK_WIDGET(top_border), 0, 1); 65 gtk_widget_set_size_request(GTK_WIDGET(top_border), 0, 1);
69 gtk_widget_modify_bg(top_border, GTK_STATE_NORMAL, &kBorderColor); 66 gtk_widget_modify_bg(top_border, GTK_STATE_NORMAL, &kBorderColor);
70 67
71 // Create |hbox_|. 68 // Create |hbox_|.
72 hbox_ = gtk_hbox_new(FALSE, kDownloadItemPadding); 69 hbox_.Own(gtk_hbox_new(FALSE, kDownloadItemPadding));
73 gtk_widget_set_size_request(hbox_, -1, kDownloadItemHeight); 70 gtk_widget_set_size_request(hbox_.get(), -1, kDownloadItemHeight);
74 71
75 // Get the padding and background color for |hbox_| right. 72 // Get the padding and background color for |hbox_| right.
76 GtkWidget* padding = gtk_alignment_new(0, 0, 1, 1); 73 GtkWidget* padding = gtk_alignment_new(0, 0, 1, 1);
77 // Subtract 1 from top spacing to account for top border. 74 // Subtract 1 from top spacing to account for top border.
78 gtk_alignment_set_padding(GTK_ALIGNMENT(padding), 75 gtk_alignment_set_padding(GTK_ALIGNMENT(padding),
79 kTopBottomPadding - 1, kTopBottomPadding, kLeftPadding, kRightPadding); 76 kTopBottomPadding - 1, kTopBottomPadding, kLeftPadding, kRightPadding);
80 GtkWidget* padding_bg = gtk_event_box_new(); 77 GtkWidget* padding_bg = gtk_event_box_new();
81 gtk_container_add(GTK_CONTAINER(padding_bg), padding); 78 gtk_container_add(GTK_CONTAINER(padding_bg), padding);
82 gtk_container_add(GTK_CONTAINER(padding), hbox_); 79 gtk_container_add(GTK_CONTAINER(padding), hbox_.get());
83 gtk_widget_modify_bg(padding_bg, GTK_STATE_NORMAL, &kBackgroundColor); 80 gtk_widget_modify_bg(padding_bg, GTK_STATE_NORMAL, &kBackgroundColor);
84 81
85 shelf_.Own(gtk_vbox_new(FALSE, 0)); 82 shelf_.Own(gtk_vbox_new(FALSE, 0));
86 gtk_box_pack_start(GTK_BOX(shelf_.get()), top_border, FALSE, FALSE, 0); 83 gtk_box_pack_start(GTK_BOX(shelf_.get()), top_border, FALSE, FALSE, 0);
87 gtk_box_pack_start(GTK_BOX(shelf_.get()), padding_bg, FALSE, FALSE, 0); 84 gtk_box_pack_start(GTK_BOX(shelf_.get()), padding_bg, FALSE, FALSE, 0);
88 85
89 // Create and pack the close button. 86 // Create and pack the close button.
90 close_button_.reset(CustomDrawButton::CloseButton()); 87 close_button_.reset(CustomDrawButton::CloseButton());
91 gtk_util::CenterWidgetInHBox(hbox_, close_button_->widget(), true, 0); 88 gtk_util::CenterWidgetInHBox(hbox_.get(), close_button_->widget(), true, 0);
92 g_signal_connect(close_button_->widget(), "clicked", 89 g_signal_connect(close_button_->widget(), "clicked",
93 G_CALLBACK(OnButtonClick), this); 90 G_CALLBACK(OnButtonClick), this);
94 91
95 // Create the "Show all downloads..." link and connect to the click event. 92 // Create the "Show all downloads..." link and connect to the click event.
96 std::string link_text = 93 std::string link_text =
97 l10n_util::GetStringUTF8(IDS_SHOW_ALL_DOWNLOADS); 94 l10n_util::GetStringUTF8(IDS_SHOW_ALL_DOWNLOADS);
98 GtkWidget* link_button = gtk_chrome_link_button_new(link_text.c_str()); 95 GtkWidget* link_button = gtk_chrome_link_button_new(link_text.c_str());
99 g_signal_connect(link_button, "clicked", 96 g_signal_connect(link_button, "clicked",
100 G_CALLBACK(OnButtonClick), this); 97 G_CALLBACK(OnButtonClick), this);
101 // Until we switch to vector graphics, force the font size. 98 // Until we switch to vector graphics, force the font size.
102 // 13.4px == 10pt @ 96dpi 99 // 13.4px == 10pt @ 96dpi
103 gtk_util::ForceFontSizePixels(GTK_CHROME_LINK_BUTTON(link_button)->label, 100 gtk_util::ForceFontSizePixels(GTK_CHROME_LINK_BUTTON(link_button)->label,
104 13.4); 101 13.4);
105 102
106 // Make the download arrow icon. 103 // Make the download arrow icon.
107 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 104 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
108 GdkPixbuf* download_pixbuf = rb.GetPixbufNamed(IDR_DOWNLOADS_FAVICON); 105 GdkPixbuf* download_pixbuf = rb.GetPixbufNamed(IDR_DOWNLOADS_FAVICON);
109 GtkWidget* download_image = gtk_image_new_from_pixbuf(download_pixbuf); 106 GtkWidget* download_image = gtk_image_new_from_pixbuf(download_pixbuf);
110 107
111 // Pack the link and the icon in an hbox. 108 // Pack the link and the icon in an hbox.
112 link_hbox_ = gtk_hbox_new(FALSE, 5); 109 link_hbox_ = gtk_hbox_new(FALSE, 5);
113 gtk_util::CenterWidgetInHBox(link_hbox_, download_image, false, 0); 110 gtk_util::CenterWidgetInHBox(link_hbox_, download_image, false, 0);
114 gtk_util::CenterWidgetInHBox(link_hbox_, link_button, false, 0); 111 gtk_util::CenterWidgetInHBox(link_hbox_, link_button, false, 0);
115 gtk_box_pack_end(GTK_BOX(hbox_), link_hbox_, FALSE, FALSE, 0); 112 gtk_box_pack_end(GTK_BOX(hbox_.get()), link_hbox_, FALSE, FALSE, 0);
116 113
117 slide_widget_.reset(new SlideAnimatorGtk(shelf_.get(), 114 slide_widget_.reset(new SlideAnimatorGtk(shelf_.get(),
118 SlideAnimatorGtk::UP, 115 SlideAnimatorGtk::UP,
119 kShelfAnimationDurationMs, 116 kShelfAnimationDurationMs,
120 false, NULL)); 117 false, NULL));
121 gtk_widget_show_all(shelf_.get()); 118 gtk_widget_show_all(shelf_.get());
122 // Stick ourselves at the bottom of the parent tab contents. 119
123 GtkWidget* parent_contents = tab_contents->GetNativeView(); 120 // Stick ourselves at the bottom of the parent browser.
124 gtk_box_pack_end(GTK_BOX(parent_contents), slide_widget_->widget(), 121 gtk_box_pack_end(GTK_BOX(parent), slide_widget_->widget(),
125 FALSE, FALSE, 0); 122 FALSE, FALSE, 0);
126 slide_widget_->Open(); 123 slide_widget_->Open();
127 } 124 }
128 125
129 DownloadShelfGtk::~DownloadShelfGtk() { 126 DownloadShelfGtk::~DownloadShelfGtk() {
130 for (std::vector<DownloadItemGtk*>::iterator iter = download_items_.begin(); 127 for (std::vector<DownloadItemGtk*>::iterator iter = download_items_.begin();
131 iter != download_items_.end(); ++iter) { 128 iter != download_items_.end(); ++iter) {
132 delete *iter; 129 delete *iter;
133 } 130 }
134 131
135 shelf_.Destroy(); 132 shelf_.Destroy();
133 hbox_.Destroy();
136 } 134 }
137 135
138 void DownloadShelfGtk::AddDownload(BaseDownloadItemModel* download_model_) { 136 void DownloadShelfGtk::AddDownload(BaseDownloadItemModel* download_model_) {
139 download_items_.push_back(new DownloadItemGtk(this, download_model_)); 137 download_items_.push_back(new DownloadItemGtk(this, download_model_));
140 slide_widget_->Open(); 138 Show();
141 } 139 }
142 140
143 bool DownloadShelfGtk::IsShowing() const { 141 bool DownloadShelfGtk::IsShowing() const {
144 return slide_widget_->IsShowing(); 142 return slide_widget_->IsShowing();
145 } 143 }
146 144
147 bool DownloadShelfGtk::IsClosing() const { 145 bool DownloadShelfGtk::IsClosing() const {
148 return slide_widget_->IsClosing(); 146 return slide_widget_->IsClosing();
149 } 147 }
150 148
149 void DownloadShelfGtk::Show() {
150 slide_widget_->Open();
151 }
152
153 void DownloadShelfGtk::Close() {
154 slide_widget_->Close();
155
156 // TODO(estade): Remove. The status bubble should query its window instead.
157 browser_->UpdateDownloadShelfVisibility(false);
158 }
159
160 int DownloadShelfGtk::GetHeight() const {
161 return slide_widget_->widget()->allocation.height;
162 }
163
151 void DownloadShelfGtk::RemoveDownloadItem(DownloadItemGtk* download_item) { 164 void DownloadShelfGtk::RemoveDownloadItem(DownloadItemGtk* download_item) {
152 DCHECK(download_item); 165 DCHECK(download_item);
153 std::vector<DownloadItemGtk*>::iterator i = 166 std::vector<DownloadItemGtk*>::iterator i =
154 find(download_items_.begin(), download_items_.end(), download_item); 167 find(download_items_.begin(), download_items_.end(), download_item);
155 DCHECK(i != download_items_.end()); 168 DCHECK(i != download_items_.end());
156 download_items_.erase(i); 169 download_items_.erase(i);
157 delete download_item; 170 delete download_item;
158 if (download_items_.empty()) { 171 if (download_items_.empty()) {
159 slide_widget_->CloseWithoutAnimation(); 172 slide_widget_->CloseWithoutAnimation();
160 tab_contents_->SetDownloadShelfVisible(false); 173
174 // TODO(estade): Remove. The status bubble should query its window instead.
175 browser_->UpdateDownloadShelfVisibility(false);
161 } 176 }
162 } 177 }
163 178
164 GtkWidget* DownloadShelfGtk::GetRightBoundingWidget() const { 179 GtkWidget* DownloadShelfGtk::GetRightBoundingWidget() const {
165 return link_hbox_; 180 return link_hbox_;
166 } 181 }
167 182
168 GtkWidget* DownloadShelfGtk::GetHBox() const { 183 GtkWidget* DownloadShelfGtk::GetHBox() const {
169 return hbox_; 184 return hbox_.get();
170 } 185 }
171 186
172 // static 187 // static
173 void DownloadShelfGtk::OnButtonClick(GtkWidget* button, 188 void DownloadShelfGtk::OnButtonClick(GtkWidget* button,
174 DownloadShelfGtk* shelf) { 189 DownloadShelfGtk* shelf) {
175 if (button == shelf->close_button_->widget()) { 190 if (button == shelf->close_button_->widget()) {
176 shelf->slide_widget_->Close(); 191 shelf->Close();
177 shelf->tab_contents_->SetDownloadShelfVisible(false);
178 } else { 192 } else {
179 // The link button was clicked. 193 // The link button was clicked.
180 shelf->ShowAllDownloads(); 194 shelf->ShowAllDownloads();
181 } 195 }
182 } 196 }
OLDNEW
« no previous file with comments | « chrome/browser/gtk/download_shelf_gtk.h ('k') | chrome/browser/gtk/tabs/tab_renderer_gtk.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698