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 "base/command_line.h" | 5 #include "base/command_line.h" |
6 | 6 |
7 #include "chrome/browser/views/frame/browser_view.h" | 7 #include "chrome/browser/views/frame/browser_view.h" |
8 | 8 |
9 #include "base/file_version_info.h" | 9 #include "base/file_version_info.h" |
10 #include "base/time.h" | 10 #include "base/time.h" |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 GetStartupInfo(&si); | 145 GetStartupInfo(&si); |
146 return si.wShowWindow; | 146 return si.wShowWindow; |
147 } | 147 } |
148 | 148 |
149 void BrowserView::WindowMoved() { | 149 void BrowserView::WindowMoved() { |
150 // Cancel any tabstrip animations, some of them may be invalidated by the | 150 // Cancel any tabstrip animations, some of them may be invalidated by the |
151 // window being repositioned. | 151 // window being repositioned. |
152 // Comment out for one cycle to see if this fixes dist tests. | 152 // Comment out for one cycle to see if this fixes dist tests. |
153 //tabstrip_->DestroyDragController(); | 153 //tabstrip_->DestroyDragController(); |
154 | 154 |
155 status_bubble_->Reposition(); | 155 if(status_bubble_.get()) |
| 156 status_bubble_->Reposition(); |
156 | 157 |
157 // Close the omnibox popup, if any. | 158 // Close the omnibox popup, if any. |
158 if (GetLocationBarView()) | 159 if (GetLocationBarView()) |
159 GetLocationBarView()->location_entry()->ClosePopup(); | 160 GetLocationBarView()->location_entry()->ClosePopup(); |
160 } | 161 } |
161 | 162 |
162 gfx::Rect BrowserView::GetToolbarBounds() const { | 163 gfx::Rect BrowserView::GetToolbarBounds() const { |
163 return toolbar_->bounds(); | 164 if(toolbar_) |
| 165 return toolbar_->bounds(); |
| 166 return gfx::Rect(); |
164 } | 167 } |
165 | 168 |
166 gfx::Rect BrowserView::GetClientAreaBounds() const { | 169 gfx::Rect BrowserView::GetClientAreaBounds() const { |
167 gfx::Rect container_bounds = contents_container_->bounds(); | 170 gfx::Rect container_bounds = contents_container_->bounds(); |
168 container_bounds.Offset(x(), y()); | 171 container_bounds.Offset(x(), y()); |
169 return container_bounds; | 172 return container_bounds; |
170 } | 173 } |
171 | 174 |
172 int BrowserView::GetTabStripHeight() const { | 175 int BrowserView::GetTabStripHeight() const { |
173 return tabstrip_->GetPreferredHeight(); | 176 return tabstrip_->GetPreferredHeight(); |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 | 281 |
279 bool BrowserView::SupportsWindowFeature(WindowFeature feature) const { | 282 bool BrowserView::SupportsWindowFeature(WindowFeature feature) const { |
280 return !!(FeaturesForBrowserType(browser_->type()) & feature); | 283 return !!(FeaturesForBrowserType(browser_->type()) & feature); |
281 } | 284 } |
282 | 285 |
283 // static | 286 // static |
284 unsigned int BrowserView::FeaturesForBrowserType(BrowserType::Type type) { | 287 unsigned int BrowserView::FeaturesForBrowserType(BrowserType::Type type) { |
285 unsigned int features = FEATURE_INFOBAR | FEATURE_DOWNLOADSHELF; | 288 unsigned int features = FEATURE_INFOBAR | FEATURE_DOWNLOADSHELF; |
286 if (type == BrowserType::TABBED_BROWSER) | 289 if (type == BrowserType::TABBED_BROWSER) |
287 features |= FEATURE_TABSTRIP | FEATURE_TOOLBAR | FEATURE_BOOKMARKBAR; | 290 features |= FEATURE_TABSTRIP | FEATURE_TOOLBAR | FEATURE_BOOKMARKBAR; |
288 if (type != BrowserType::APPLICATION) | 291 if (type != BrowserType::APPLICATION && type != BrowserType::EMBEDDED) |
289 features |= FEATURE_LOCATIONBAR; | 292 features |= FEATURE_LOCATIONBAR; |
290 if (type != BrowserType::TABBED_BROWSER) | 293 if (type != BrowserType::TABBED_BROWSER && type != BrowserType::EMBEDDED) |
291 features |= FEATURE_TITLEBAR; | 294 features |= FEATURE_TITLEBAR; |
292 return features; | 295 return features; |
293 } | 296 } |
294 | 297 |
295 // static | 298 // static |
296 void BrowserView::RegisterBrowserViewPrefs(PrefService* prefs) { | 299 void BrowserView::RegisterBrowserViewPrefs(PrefService* prefs) { |
297 prefs->RegisterIntegerPref(prefs::kPluginMessageResponseTimeout, | 300 prefs->RegisterIntegerPref(prefs::kPluginMessageResponseTimeout, |
298 kDefaultPluginMessageResponseTimeout); | 301 kDefaultPluginMessageResponseTimeout); |
299 prefs->RegisterIntegerPref(prefs::kHungPluginDetectFrequency, | 302 prefs->RegisterIntegerPref(prefs::kHungPluginDetectFrequency, |
300 kDefaultHungPluginDetectFrequency); | 303 kDefaultHungPluginDetectFrequency); |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
444 const bool ret = !!GetWindowPlacement(frame_->GetWindow()->GetHWND(), &wp); | 447 const bool ret = !!GetWindowPlacement(frame_->GetWindow()->GetHWND(), &wp); |
445 DCHECK(ret); | 448 DCHECK(ret); |
446 return gfx::Rect(wp.rcNormalPosition); | 449 return gfx::Rect(wp.rcNormalPosition); |
447 } | 450 } |
448 | 451 |
449 bool BrowserView::IsMaximized() { | 452 bool BrowserView::IsMaximized() { |
450 return frame_->GetWindow()->IsMaximized(); | 453 return frame_->GetWindow()->IsMaximized(); |
451 } | 454 } |
452 | 455 |
453 ToolbarStarToggle* BrowserView::GetStarButton() const { | 456 ToolbarStarToggle* BrowserView::GetStarButton() const { |
454 return toolbar_->star_button(); | 457 if(toolbar_) |
| 458 return toolbar_->star_button(); |
| 459 return NULL; |
455 } | 460 } |
456 | 461 |
457 LocationBarView* BrowserView::GetLocationBarView() const { | 462 LocationBarView* BrowserView::GetLocationBarView() const { |
458 return toolbar_->GetLocationBarView(); | 463 if(toolbar_) |
| 464 return toolbar_->GetLocationBarView(); |
| 465 return NULL; |
459 } | 466 } |
460 | 467 |
461 GoButton* BrowserView::GetGoButton() const { | 468 GoButton* BrowserView::GetGoButton() const { |
462 return toolbar_->GetGoButton(); | 469 if(toolbar_) |
| 470 return toolbar_->GetGoButton(); |
| 471 return NULL; |
463 } | 472 } |
464 | 473 |
465 BookmarkBarView* BrowserView::GetBookmarkBarView() { | 474 BookmarkBarView* BrowserView::GetBookmarkBarView() { |
466 TabContents* current_tab = browser_->GetSelectedTabContents(); | 475 TabContents* current_tab = browser_->GetSelectedTabContents(); |
467 if (!bookmark_bar_view_.get()) { | 476 if (!bookmark_bar_view_.get()) { |
468 bookmark_bar_view_.reset(new BookmarkBarView(current_tab->profile(), | 477 bookmark_bar_view_.reset(new BookmarkBarView(current_tab->profile(), |
469 browser_.get())); | 478 browser_.get())); |
470 bookmark_bar_view_->SetParentOwned(false); | 479 bookmark_bar_view_->SetParentOwned(false); |
471 } else { | 480 } else { |
472 bookmark_bar_view_->SetProfile(current_tab->profile()); | 481 bookmark_bar_view_->SetProfile(current_tab->profile()); |
473 } | 482 } |
474 bookmark_bar_view_->SetPageNavigator(current_tab); | 483 bookmark_bar_view_->SetPageNavigator(current_tab); |
475 return bookmark_bar_view_.get(); | 484 return bookmark_bar_view_.get(); |
476 } | 485 } |
477 | 486 |
478 BrowserView* BrowserView::GetBrowserView() const { | 487 BrowserView* BrowserView::GetBrowserView() const { |
479 return NULL; | 488 return NULL; |
480 } | 489 } |
481 | 490 |
482 void BrowserView::UpdateToolbar(TabContents* contents, | 491 void BrowserView::UpdateToolbar(TabContents* contents, |
483 bool should_restore_state) { | 492 bool should_restore_state) { |
484 toolbar_->Update(contents, should_restore_state); | 493 if(toolbar_) |
| 494 toolbar_->Update(contents, should_restore_state); |
485 } | 495 } |
486 | 496 |
487 void BrowserView::FocusToolbar() { | 497 void BrowserView::FocusToolbar() { |
488 toolbar_->RequestFocus(); | 498 if(toolbar_) |
| 499 toolbar_->RequestFocus(); |
489 } | 500 } |
490 | 501 |
491 void BrowserView::DestroyBrowser() { | 502 void BrowserView::DestroyBrowser() { |
492 // Explicitly delete the BookmarkBarView now. That way we don't have to | 503 // Explicitly delete the BookmarkBarView now. That way we don't have to |
493 // worry about the BookmarkBarView potentially outliving the Browser & | 504 // worry about the BookmarkBarView potentially outliving the Browser & |
494 // Profile. | 505 // Profile. |
495 bookmark_bar_view_.reset(); | 506 bookmark_bar_view_.reset(); |
496 browser_.reset(); | 507 browser_.reset(); |
497 } | 508 } |
498 | 509 |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
638 // TODO(beng): This should be called automatically by SetTabContents, but I | 649 // TODO(beng): This should be called automatically by SetTabContents, but I |
639 // am striving for parity now rather than cleanliness. This is | 650 // am striving for parity now rather than cleanliness. This is |
640 // required to make features like Duplicate Tab, Undo Close Tab, | 651 // required to make features like Duplicate Tab, Undo Close Tab, |
641 // etc not result in sad tab. | 652 // etc not result in sad tab. |
642 new_contents->DidBecomeSelected(); | 653 new_contents->DidBecomeSelected(); |
643 if (BrowserList::GetLastActive() == browser_) | 654 if (BrowserList::GetLastActive() == browser_) |
644 new_contents->RestoreFocus(); | 655 new_contents->RestoreFocus(); |
645 | 656 |
646 // Update all the UI bits. | 657 // Update all the UI bits. |
647 UpdateTitleBar(); | 658 UpdateTitleBar(); |
648 toolbar_->SetProfile(new_contents->profile()); | 659 if(toolbar_) |
| 660 toolbar_->SetProfile(new_contents->profile()); |
649 UpdateToolbar(new_contents, true); | 661 UpdateToolbar(new_contents, true); |
650 UpdateUIForContents(new_contents); | 662 UpdateUIForContents(new_contents); |
651 } | 663 } |
652 | 664 |
653 void BrowserView::TabStripEmpty() { | 665 void BrowserView::TabStripEmpty() { |
654 // Make sure all optional UI is removed before we are destroyed, otherwise | 666 // Make sure all optional UI is removed before we are destroyed, otherwise |
655 // there will be consequences (since our view hierarchy will still have | 667 // there will be consequences (since our view hierarchy will still have |
656 // references to freed views). | 668 // references to freed views). |
657 UpdateUIForContents(NULL); | 669 UpdateUIForContents(NULL); |
658 } | 670 } |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
717 bool maximized, | 729 bool maximized, |
718 bool always_on_top) { | 730 bool always_on_top) { |
719 if (browser_->ShouldSaveWindowPlacement()) { | 731 if (browser_->ShouldSaveWindowPlacement()) { |
720 WindowDelegate::SaveWindowPlacement(bounds, maximized, always_on_top); | 732 WindowDelegate::SaveWindowPlacement(bounds, maximized, always_on_top); |
721 browser_->SaveWindowPlacement(bounds, maximized); | 733 browser_->SaveWindowPlacement(bounds, maximized); |
722 } | 734 } |
723 } | 735 } |
724 | 736 |
725 bool BrowserView::GetSavedWindowBounds(gfx::Rect* bounds) const { | 737 bool BrowserView::GetSavedWindowBounds(gfx::Rect* bounds) const { |
726 *bounds = browser_->GetSavedWindowBounds(); | 738 *bounds = browser_->GetSavedWindowBounds(); |
727 if (browser_->type() == BrowserType::BROWSER) { | 739 if (browser_->type() == BrowserType::BROWSER || browser_->type() == BrowserTyp
e::EMBEDDED) { |
728 // We are a popup window. The value passed in |bounds| represents two | 740 // We are a popup or embedded window. The value passed in |bounds| represent
s two |
729 // pieces of information: | 741 // pieces of information: |
730 // - the position of the window, in screen coordinates (outer position). | 742 // - the position of the window, in screen coordinates (outer position). |
731 // - the size of the content area (inner size). | 743 // - the size of the content area (inner size). |
732 // We need to use these values to determine the appropriate size and | 744 // We need to use these values to determine the appropriate size and |
733 // position of the resulting window. | 745 // position of the resulting window. |
734 if (SupportsWindowFeature(FEATURE_TOOLBAR) || | 746 if (SupportsWindowFeature(FEATURE_TOOLBAR) || |
735 SupportsWindowFeature(FEATURE_LOCATIONBAR)) { | 747 SupportsWindowFeature(FEATURE_LOCATIONBAR)) { |
736 // If we're showing the toolbar, we need to adjust |*bounds| to include | 748 // If we're showing the toolbar, we need to adjust |*bounds| to include |
737 // its desired height, since the toolbar is considered part of the | 749 // its desired height, since the toolbar is considered part of the |
738 // window's client area as far as GetWindowBoundsForClientBounds is | 750 // window's client area as far as GetWindowBoundsForClientBounds is |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
954 } | 966 } |
955 return DragDropTypes::DRAG_NONE; | 967 return DragDropTypes::DRAG_NONE; |
956 } | 968 } |
957 | 969 |
958 | 970 |
959 /////////////////////////////////////////////////////////////////////////////// | 971 /////////////////////////////////////////////////////////////////////////////// |
960 // BrowserView, private: | 972 // BrowserView, private: |
961 | 973 |
962 void BrowserView::InitSystemMenu() { | 974 void BrowserView::InitSystemMenu() { |
963 HMENU system_menu = GetSystemMenu(frame_->GetWindow()->GetHWND(), FALSE); | 975 HMENU system_menu = GetSystemMenu(frame_->GetWindow()->GetHWND(), FALSE); |
| 976 if(!system_menu) |
| 977 return; |
964 system_menu_.reset(new Menu(system_menu)); | 978 system_menu_.reset(new Menu(system_menu)); |
965 int insertion_index = std::max(0, system_menu_->ItemCount() - 1); | 979 int insertion_index = std::max(0, system_menu_->ItemCount() - 1); |
966 // We add the menu items in reverse order so that insertion_index never needs | 980 // We add the menu items in reverse order so that insertion_index never needs |
967 // to change. | 981 // to change. |
968 if (browser_->type() == BrowserType::TABBED_BROWSER) { | 982 if (browser_->type() == BrowserType::TABBED_BROWSER) { |
969 system_menu_->AddSeparator(insertion_index); | 983 system_menu_->AddSeparator(insertion_index); |
970 system_menu_->AddMenuItemWithLabel(insertion_index, IDC_TASKMANAGER, | 984 system_menu_->AddMenuItemWithLabel(insertion_index, IDC_TASKMANAGER, |
971 l10n_util::GetString(IDS_TASKMANAGER)); | 985 l10n_util::GetString(IDS_TASKMANAGER)); |
972 // If it's a regular browser window with tabs, we don't add any more items, | 986 // If it's a regular browser window with tabs, we don't add any more items, |
973 // since it already has menus (Page, Chrome). | 987 // since it already has menus (Page, Chrome). |
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1328 | 1342 |
1329 // static | 1343 // static |
1330 void BrowserView::InitClass() { | 1344 void BrowserView::InitClass() { |
1331 static bool initialized = false; | 1345 static bool initialized = false; |
1332 if (!initialized) { | 1346 if (!initialized) { |
1333 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 1347 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
1334 default_favicon_ = *rb.GetBitmapNamed(IDR_DEFAULT_FAVICON); | 1348 default_favicon_ = *rb.GetBitmapNamed(IDR_DEFAULT_FAVICON); |
1335 initialized = true; | 1349 initialized = true; |
1336 } | 1350 } |
1337 } | 1351 } |
OLD | NEW |