OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/views/download_shelf_view.h" | 5 #include "chrome/browser/views/download_shelf_view.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "chrome/app/theme/theme_resources.h" | 9 #include "chrome/app/theme/theme_resources.h" |
10 #include "chrome/browser/browser.h" | 10 #include "chrome/browser/browser.h" |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 void AdjustSize(views::View* view, gfx::Size* size) { | 66 void AdjustSize(views::View* view, gfx::Size* size) { |
67 gfx::Size view_preferred = view->GetPreferredSize(); | 67 gfx::Size view_preferred = view->GetPreferredSize(); |
68 size->Enlarge(view_preferred.width(), 0); | 68 size->Enlarge(view_preferred.width(), 0); |
69 size->set_height(std::max(view_preferred.height(), size->height())); | 69 size->set_height(std::max(view_preferred.height(), size->height())); |
70 } | 70 } |
71 | 71 |
72 int CenterPosition(int size, int target_size) { | 72 int CenterPosition(int size, int target_size) { |
73 return std::max((target_size - size) / 2, kTopBottomPadding); | 73 return std::max((target_size - size) / 2, kTopBottomPadding); |
74 } | 74 } |
75 | 75 |
76 } // namespace | 76 } // namespace |
77 | 77 |
78 DownloadShelfView::DownloadShelfView(TabContents* tab_contents) | 78 DownloadShelfView::DownloadShelfView(TabContents* tab_contents) |
79 : tab_contents_(tab_contents) { | 79 : tab_contents_(tab_contents) { |
80 Init(); | 80 Init(); |
81 } | 81 } |
82 | 82 |
83 void DownloadShelfView::Init() { | 83 void DownloadShelfView::Init() { |
84 ResourceBundle &rb = ResourceBundle::GetSharedInstance(); | 84 ResourceBundle &rb = ResourceBundle::GetSharedInstance(); |
85 arrow_image_ = new views::ImageView(); | 85 arrow_image_ = new views::ImageView(); |
86 arrow_image_->SetImage(rb.GetBitmapNamed(IDR_DOWNLOADS_FAVICON)); | 86 arrow_image_->SetImage(rb.GetBitmapNamed(IDR_DOWNLOADS_FAVICON)); |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 void DownloadShelfView::Layout() { | 200 void DownloadShelfView::Layout() { |
201 // When the download shelf is not visible it is not parented to anything, | 201 // When the download shelf is not visible it is not parented to anything, |
202 // which means it is not safe to lay out the controls, so we return early. | 202 // which means it is not safe to lay out the controls, so we return early. |
203 // Otherwise, we can have problems when for example the user switches to | 203 // Otherwise, we can have problems when for example the user switches to |
204 // another tab (that doesn't have a download shelf) _before_ the download | 204 // another tab (that doesn't have a download shelf) _before_ the download |
205 // has started and we'll crash when calling SetVisible() below because | 205 // has started and we'll crash when calling SetVisible() below because |
206 // the NativeControlContainer ctor tries to use the Container. | 206 // the NativeControlContainer ctor tries to use the Container. |
207 if (!GetWidget()) | 207 if (!GetWidget()) |
208 return; | 208 return; |
209 | 209 |
| 210 // Let our base class layout our child views |
| 211 views::View::Layout(); |
| 212 |
210 gfx::Size image_size = arrow_image_->GetPreferredSize(); | 213 gfx::Size image_size = arrow_image_->GetPreferredSize(); |
211 gfx::Size close_button_size = close_button_->GetPreferredSize(); | 214 gfx::Size close_button_size = close_button_->GetPreferredSize(); |
212 gfx::Size show_all_size = show_all_view_->GetPreferredSize(); | 215 gfx::Size show_all_size = show_all_view_->GetPreferredSize(); |
213 int max_download_x = | 216 int max_download_x = |
214 std::max<int>(0, width() - kRightPadding - close_button_size.width() - | 217 std::max<int>(0, width() - kRightPadding - close_button_size.width() - |
215 kCloseAndLinkPadding - show_all_size.width() - | 218 kCloseAndLinkPadding - show_all_size.width() - |
216 image_size.width() - kDownloadPadding); | 219 image_size.width() - kDownloadPadding); |
217 int next_x = max_download_x + kDownloadPadding; | 220 int next_x = max_download_x + kDownloadPadding; |
218 // Align vertically with show_all_view_. | 221 // Align vertically with show_all_view_. |
219 arrow_image_->SetBounds(next_x, | 222 arrow_image_->SetBounds(next_x, |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 NavigationController* controller = tab_contents_->controller(); | 266 NavigationController* controller = tab_contents_->controller(); |
264 Browser* browser = Browser::GetBrowserForController(controller, &index); | 267 Browser* browser = Browser::GetBrowserForController(controller, &index); |
265 DCHECK(browser); | 268 DCHECK(browser); |
266 browser->ShowNativeUITab(DownloadTabUI::GetURL()); | 269 browser->ShowNativeUITab(DownloadTabUI::GetURL()); |
267 } | 270 } |
268 | 271 |
269 void DownloadShelfView::ButtonPressed(views::BaseButton* button) { | 272 void DownloadShelfView::ButtonPressed(views::BaseButton* button) { |
270 shelf_animation_->Hide(); | 273 shelf_animation_->Hide(); |
271 } | 274 } |
272 | 275 |
| 276 bool DownloadShelfView::IsShowing() const { |
| 277 return shelf_animation_->IsShowing(); |
| 278 } |
OLD | NEW |