OLD | NEW |
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-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/views/frame/browser_view.h" | 5 #include "chrome/browser/views/frame/browser_view.h" |
6 | 6 |
7 #if defined(OS_LINUX) | 7 #if defined(OS_LINUX) |
8 #include <gtk/gtk.h> | 8 #include <gtk/gtk.h> |
9 #endif | 9 #endif |
10 | 10 |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 explicit_show_state = state; | 267 explicit_show_state = state; |
268 } | 268 } |
269 | 269 |
270 BrowserView::BrowserView(Browser* browser) | 270 BrowserView::BrowserView(Browser* browser) |
271 : views::ClientView(NULL, NULL), | 271 : views::ClientView(NULL, NULL), |
272 frame_(NULL), | 272 frame_(NULL), |
273 browser_(browser), | 273 browser_(browser), |
274 active_bookmark_bar_(NULL), | 274 active_bookmark_bar_(NULL), |
275 tabstrip_(NULL), | 275 tabstrip_(NULL), |
276 toolbar_(NULL), | 276 toolbar_(NULL), |
277 download_shelf_(NULL), | |
278 infobar_container_(NULL), | 277 infobar_container_(NULL), |
279 find_bar_y_(0), | 278 find_bar_y_(0), |
280 contents_container_(NULL), | 279 contents_container_(NULL), |
281 initialized_(false), | 280 initialized_(false), |
282 ignore_layout_(false), | 281 ignore_layout_(false), |
283 #if defined(OS_WIN) | 282 #if defined(OS_WIN) |
284 hung_window_detector_(&hung_plugin_action_), | 283 hung_window_detector_(&hung_plugin_action_), |
285 ticker_(0), | 284 ticker_(0), |
286 #endif | 285 #endif |
287 extension_shelf_(NULL) { | 286 extension_shelf_(NULL) { |
288 InitClass(); | 287 InitClass(); |
289 browser_->tabstrip_model()->AddObserver(this); | 288 browser_->tabstrip_model()->AddObserver(this); |
290 } | 289 } |
291 | 290 |
292 BrowserView::~BrowserView() { | 291 BrowserView::~BrowserView() { |
293 browser_->tabstrip_model()->RemoveObserver(this); | 292 browser_->tabstrip_model()->RemoveObserver(this); |
294 | 293 |
295 #if defined(OS_WIN) | 294 #if defined(OS_WIN) |
296 // Stop hung plugin monitoring. | 295 // Stop hung plugin monitoring. |
297 ticker_.Stop(); | 296 ticker_.Stop(); |
298 ticker_.UnregisterTickHandler(&hung_window_detector_); | 297 ticker_.UnregisterTickHandler(&hung_window_detector_); |
299 #endif | 298 #endif |
300 | 299 |
| 300 // We destroy the download shelf before |browser_| to remove its child |
| 301 // download views from the set of download observers (since the observed |
| 302 // downloads can be destroyed along with |browser_| and the observer |
| 303 // notifications will call back into deleted objects). |
| 304 download_shelf_.reset(); |
| 305 |
301 // Explicitly set browser_ to NULL | 306 // Explicitly set browser_ to NULL |
302 browser_.reset(); | 307 browser_.reset(); |
303 } | 308 } |
304 | 309 |
305 // static | 310 // static |
306 BrowserView* BrowserView::GetBrowserViewForNativeWindow( | 311 BrowserView* BrowserView::GetBrowserViewForNativeWindow( |
307 gfx::NativeWindow window) { | 312 gfx::NativeWindow window) { |
308 #if defined(OS_WIN) | 313 #if defined(OS_WIN) |
309 if (IsWindow(window)) { | 314 if (IsWindow(window)) { |
310 HANDLE data = GetProp(window, kBrowserViewKey); | 315 HANDLE data = GetProp(window, kBrowserViewKey); |
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
780 | 785 |
781 gfx::Rect BrowserView::GetRootWindowResizerRect() const { | 786 gfx::Rect BrowserView::GetRootWindowResizerRect() const { |
782 if (frame_->GetWindow()->IsMaximized() || frame_->GetWindow()->IsFullscreen()) | 787 if (frame_->GetWindow()->IsMaximized() || frame_->GetWindow()->IsFullscreen()) |
783 return gfx::Rect(); | 788 return gfx::Rect(); |
784 | 789 |
785 // We don't specify a resize corner size if we have a bottom shelf either. | 790 // We don't specify a resize corner size if we have a bottom shelf either. |
786 // This is because we take care of drawing the resize corner on top of that | 791 // This is because we take care of drawing the resize corner on top of that |
787 // shelf, so we don't want others to do it for us in this case. | 792 // shelf, so we don't want others to do it for us in this case. |
788 // Currently, the only visible bottom shelf is the download shelf. | 793 // Currently, the only visible bottom shelf is the download shelf. |
789 // Other tests should be added here if we add more bottom shelves. | 794 // Other tests should be added here if we add more bottom shelves. |
790 if (download_shelf_ && download_shelf_->IsShowing()) { | 795 if (download_shelf_.get() && download_shelf_->IsShowing()) { |
791 return gfx::Rect(); | 796 return gfx::Rect(); |
792 } | 797 } |
793 | 798 |
794 gfx::Rect client_rect = contents_container_->bounds(); | 799 gfx::Rect client_rect = contents_container_->bounds(); |
795 gfx::Size resize_corner_size = ResizeCorner::GetSize(); | 800 gfx::Size resize_corner_size = ResizeCorner::GetSize(); |
796 int x = client_rect.width() - resize_corner_size.width(); | 801 int x = client_rect.width() - resize_corner_size.width(); |
797 if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) | 802 if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) |
798 x = 0; | 803 x = 0; |
799 return gfx::Rect(x, client_rect.height() - resize_corner_size.height(), | 804 return gfx::Rect(x, client_rect.height() - resize_corner_size.height(), |
800 resize_corner_size.width(), resize_corner_size.height()); | 805 resize_corner_size.width(), resize_corner_size.height()); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
835 browser_->UpdateDownloadShelfVisibility(visible); | 840 browser_->UpdateDownloadShelfVisibility(visible); |
836 } | 841 } |
837 | 842 |
838 // SetDownloadShelfVisible can force-close the shelf, so make sure we lay out | 843 // SetDownloadShelfVisible can force-close the shelf, so make sure we lay out |
839 // everything correctly, as if the animation had finished. This doesn't | 844 // everything correctly, as if the animation had finished. This doesn't |
840 // matter for showing the shelf, as the show animation will do it. | 845 // matter for showing the shelf, as the show animation will do it. |
841 SelectedTabToolbarSizeChanged(false); | 846 SelectedTabToolbarSizeChanged(false); |
842 } | 847 } |
843 | 848 |
844 bool BrowserView::IsDownloadShelfVisible() const { | 849 bool BrowserView::IsDownloadShelfVisible() const { |
845 return download_shelf_ && download_shelf_->IsShowing(); | 850 return download_shelf_.get() && download_shelf_->IsShowing(); |
846 } | 851 } |
847 | 852 |
848 DownloadShelf* BrowserView::GetDownloadShelf() { | 853 DownloadShelf* BrowserView::GetDownloadShelf() { |
849 if (!download_shelf_) | 854 if (!download_shelf_.get()) { |
850 download_shelf_ = new DownloadShelfView(browser_.get(), this); | 855 download_shelf_.reset(new DownloadShelfView(browser_.get(), this)); |
851 return download_shelf_; | 856 download_shelf_->SetParentOwned(false); |
| 857 } |
| 858 return download_shelf_.get(); |
852 } | 859 } |
853 | 860 |
854 void BrowserView::ShowReportBugDialog() { | 861 void BrowserView::ShowReportBugDialog() { |
855 // Retrieve the URL for the current tab (if any) and tell the BugReportView | 862 // Retrieve the URL for the current tab (if any) and tell the BugReportView |
856 TabContents* current_tab = browser_->GetSelectedTabContents(); | 863 TabContents* current_tab = browser_->GetSelectedTabContents(); |
857 if (!current_tab) | 864 if (!current_tab) |
858 return; | 865 return; |
859 browser::ShowBugReportView(GetWidget(), browser_->profile(), current_tab); | 866 browser::ShowBugReportView(GetWidget(), browser_->profile(), current_tab); |
860 } | 867 } |
861 | 868 |
(...skipping 624 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1486 } | 1493 } |
1487 | 1494 |
1488 void BrowserView::LayoutTabContents(int top, int bottom) { | 1495 void BrowserView::LayoutTabContents(int top, int bottom) { |
1489 contents_container_->SetBounds(0, top, width(), bottom - top); | 1496 contents_container_->SetBounds(0, top, width(), bottom - top); |
1490 } | 1497 } |
1491 | 1498 |
1492 int BrowserView::LayoutDownloadShelf(int bottom) { | 1499 int BrowserView::LayoutDownloadShelf(int bottom) { |
1493 if (IsDownloadShelfVisible()) { | 1500 if (IsDownloadShelfVisible()) { |
1494 bool visible = browser_->SupportsWindowFeature( | 1501 bool visible = browser_->SupportsWindowFeature( |
1495 Browser::FEATURE_DOWNLOADSHELF); | 1502 Browser::FEATURE_DOWNLOADSHELF); |
1496 DCHECK(download_shelf_); | 1503 DCHECK(download_shelf_.get()); |
1497 int height = visible ? download_shelf_->GetPreferredSize().height() : 0; | 1504 int height = visible ? download_shelf_->GetPreferredSize().height() : 0; |
1498 download_shelf_->SetVisible(visible); | 1505 download_shelf_->SetVisible(visible); |
1499 download_shelf_->SetBounds(0, bottom - height, width(), height); | 1506 download_shelf_->SetBounds(0, bottom - height, width(), height); |
1500 download_shelf_->Layout(); | 1507 download_shelf_->Layout(); |
1501 bottom -= height; | 1508 bottom -= height; |
1502 } | 1509 } |
1503 return bottom; | 1510 return bottom; |
1504 } | 1511 } |
1505 | 1512 |
1506 void BrowserView::LayoutStatusBubble(int top) { | 1513 void BrowserView::LayoutStatusBubble(int top) { |
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1794 | 1801 |
1795 // static | 1802 // static |
1796 FindBar* BrowserWindow::CreateFindBar(Browser* browser) { | 1803 FindBar* BrowserWindow::CreateFindBar(Browser* browser) { |
1797 return browser::CreateFindBar(static_cast<BrowserView*>(browser->window())); | 1804 return browser::CreateFindBar(static_cast<BrowserView*>(browser->window())); |
1798 } | 1805 } |
1799 | 1806 |
1800 // static | 1807 // static |
1801 void BrowserList::AllBrowsersClosed() { | 1808 void BrowserList::AllBrowsersClosed() { |
1802 views::Window::CloseAllSecondaryWindows(); | 1809 views::Window::CloseAllSecondaryWindows(); |
1803 } | 1810 } |
OLD | NEW |