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" |
11 #include "chrome/app/chrome_dll_resource.h" | 11 #include "chrome/app/chrome_dll_resource.h" |
12 #include "chrome/app/theme/theme_resources.h" | 12 #include "chrome/app/theme/theme_resources.h" |
13 #include "chrome/browser/app_modal_dialog_queue.h" | 13 #include "chrome/browser/app_modal_dialog_queue.h" |
14 #include "chrome/browser/browser.h" | 14 #include "chrome/browser/browser.h" |
15 #include "chrome/browser/browser_list.h" | 15 #include "chrome/browser/browser_list.h" |
16 #include "chrome/browser/encoding_menu_controller_delegate.h" | 16 #include "chrome/browser/encoding_menu_controller_delegate.h" |
17 #include "chrome/browser/navigation_entry.h" | 17 #include "chrome/browser/navigation_entry.h" |
18 #include "chrome/browser/view_ids.h" | 18 #include "chrome/browser/view_ids.h" |
19 #include "chrome/browser/views/about_chrome_view.h" | 19 #include "chrome/browser/views/about_chrome_view.h" |
20 #include "chrome/browser/views/bookmark_bar_view.h" | 20 #include "chrome/browser/views/bookmark_bar_view.h" |
21 #include "chrome/browser/views/bookmark_manager_view.h" | 21 #include "chrome/browser/views/bookmark_manager_view.h" |
22 #include "chrome/browser/views/bug_report_view.h" | 22 #include "chrome/browser/views/bug_report_view.h" |
23 #include "chrome/browser/views/clear_browsing_data.h" | 23 #include "chrome/browser/views/clear_browsing_data.h" |
24 #include "chrome/browser/views/download_shelf_view.h" | 24 #include "chrome/browser/views/download_shelf_view.h" |
25 #include "chrome/browser/views/frame/browser_frame.h" | 25 #include "chrome/browser/views/frame/browser_frame.h" |
26 #include "chrome/browser/views/html_dialog_view.h" | 26 #include "chrome/browser/views/html_dialog_view.h" |
27 #include "chrome/browser/views/importer_view.h" | 27 #include "chrome/browser/views/importer_view.h" |
| 28 #include "chrome/browser/views/infobars/infobar_container.h" |
28 #include "chrome/browser/views/keyword_editor_view.h" | 29 #include "chrome/browser/views/keyword_editor_view.h" |
29 #include "chrome/browser/views/password_manager_view.h" | 30 #include "chrome/browser/views/password_manager_view.h" |
30 #include "chrome/browser/views/status_bubble.h" | 31 #include "chrome/browser/views/status_bubble.h" |
31 #include "chrome/browser/views/tab_contents_container_view.h" | 32 #include "chrome/browser/views/tab_contents_container_view.h" |
32 #include "chrome/browser/views/tabs/tab_strip.h" | 33 #include "chrome/browser/views/tabs/tab_strip.h" |
33 #include "chrome/browser/views/toolbar_view.h" | 34 #include "chrome/browser/views/toolbar_view.h" |
34 #include "chrome/browser/web_contents.h" | 35 #include "chrome/browser/web_contents.h" |
35 #include "chrome/browser/web_contents_view.h" | 36 #include "chrome/browser/web_contents_view.h" |
36 #include "chrome/common/chrome_switches.h" | 37 #include "chrome/common/chrome_switches.h" |
37 #include "chrome/common/drag_drop_types.h" | 38 #include "chrome/common/drag_drop_types.h" |
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 tabstrip_ = new TabStrip(browser_->tabstrip_model()); | 332 tabstrip_ = new TabStrip(browser_->tabstrip_model()); |
332 tabstrip_->SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_TABSTRIP)); | 333 tabstrip_->SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_TABSTRIP)); |
333 AddChildView(tabstrip_); | 334 AddChildView(tabstrip_); |
334 | 335 |
335 toolbar_ = new BrowserToolbarView(browser_->controller(), browser_.get()); | 336 toolbar_ = new BrowserToolbarView(browser_->controller(), browser_.get()); |
336 AddChildView(toolbar_); | 337 AddChildView(toolbar_); |
337 toolbar_->SetID(VIEW_ID_TOOLBAR); | 338 toolbar_->SetID(VIEW_ID_TOOLBAR); |
338 toolbar_->Init(browser_->profile()); | 339 toolbar_->Init(browser_->profile()); |
339 toolbar_->SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_TOOLBAR)); | 340 toolbar_->SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_TOOLBAR)); |
340 | 341 |
| 342 infobar_container_ = new InfoBarContainer(this); |
| 343 AddChildView(infobar_container_); |
| 344 |
341 contents_container_ = new TabContentsContainerView; | 345 contents_container_ = new TabContentsContainerView; |
342 set_contents_view(contents_container_); | 346 set_contents_view(contents_container_); |
343 AddChildView(contents_container_); | 347 AddChildView(contents_container_); |
344 | 348 |
345 status_bubble_.reset(new StatusBubble(GetContainer())); | 349 status_bubble_.reset(new StatusBubble(GetContainer())); |
346 | 350 |
347 #ifdef CHROME_PERSONALIZATION | 351 #ifdef CHROME_PERSONALIZATION |
348 EnablePersonalization(CommandLine().HasSwitch(switches::kEnableP13n)); | 352 EnablePersonalization(CommandLine().HasSwitch(switches::kEnableP13n)); |
349 if (IsPersonalizationEnabled()) { | 353 if (IsPersonalizationEnabled()) { |
350 personalization_ = Personalization::CreateFramePersonalization( | 354 personalization_ = Personalization::CreateFramePersonalization( |
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
638 | 642 |
639 void BrowserView::TabSelectedAt(TabContents* old_contents, | 643 void BrowserView::TabSelectedAt(TabContents* old_contents, |
640 TabContents* new_contents, | 644 TabContents* new_contents, |
641 int index, | 645 int index, |
642 bool user_gesture) { | 646 bool user_gesture) { |
643 DCHECK(old_contents != new_contents); | 647 DCHECK(old_contents != new_contents); |
644 | 648 |
645 if (old_contents) | 649 if (old_contents) |
646 old_contents->StoreFocus(); | 650 old_contents->StoreFocus(); |
647 | 651 |
648 // Tell the frame what happened so that the TabContents gets resized, etc. | 652 // Update various elements that are interested in knowing the current |
| 653 // TabContents. |
| 654 infobar_container_->ChangeTabContents(new_contents); |
649 contents_container_->SetTabContents(new_contents); | 655 contents_container_->SetTabContents(new_contents); |
650 // TODO(beng): This should be called automatically by SetTabContents, but I | 656 // TODO(beng): This should be called automatically by SetTabContents, but I |
651 // am striving for parity now rather than cleanliness. This is | 657 // am striving for parity now rather than cleanliness. This is |
652 // required to make features like Duplicate Tab, Undo Close Tab, | 658 // required to make features like Duplicate Tab, Undo Close Tab, |
653 // etc not result in sad tab. | 659 // etc not result in sad tab. |
654 new_contents->DidBecomeSelected(); | 660 new_contents->DidBecomeSelected(); |
655 if (BrowserList::GetLastActive() == browser_) | 661 if (BrowserList::GetLastActive() == browser_) |
656 new_contents->RestoreFocus(); | 662 new_contents->RestoreFocus(); |
657 | 663 |
658 // Update all the UI bits. | 664 // Update all the UI bits. |
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1048 toolbar_->SetVisible(false); | 1054 toolbar_->SetVisible(false); |
1049 return top; | 1055 return top; |
1050 } | 1056 } |
1051 | 1057 |
1052 int BrowserView::LayoutBookmarkAndInfoBars(int top) { | 1058 int BrowserView::LayoutBookmarkAndInfoBars(int top) { |
1053 if (SupportsWindowFeature(FEATURE_BOOKMARKBAR)) { | 1059 if (SupportsWindowFeature(FEATURE_BOOKMARKBAR)) { |
1054 // If we have an Info-bar showing, and we're showing the New Tab Page, and | 1060 // If we have an Info-bar showing, and we're showing the New Tab Page, and |
1055 // the Bookmark bar isn't visible on all tabs, then we need to show the | 1061 // the Bookmark bar isn't visible on all tabs, then we need to show the |
1056 // Info bar _above_ the Bookmark bar, since the Bookmark bar is styled to | 1062 // Info bar _above_ the Bookmark bar, since the Bookmark bar is styled to |
1057 // look like it's part of the New Tab Page... | 1063 // look like it's part of the New Tab Page... |
1058 if (active_info_bar_ && active_bookmark_bar_ && | 1064 if (active_bookmark_bar_ && |
1059 bookmark_bar_view_->IsNewTabPage() && | 1065 bookmark_bar_view_->IsNewTabPage() && |
1060 !bookmark_bar_view_->IsAlwaysShown()) { | 1066 !bookmark_bar_view_->IsAlwaysShown()) { |
1061 top = LayoutInfoBar(top); | 1067 top = LayoutInfoBar(top); |
1062 return LayoutBookmarkBar(top); | 1068 return LayoutBookmarkBar(top); |
1063 } | 1069 } |
1064 // Otherwise, Bookmark bar first, Info bar second. | 1070 // Otherwise, Bookmark bar first, Info bar second. |
1065 top = LayoutBookmarkBar(top); | 1071 top = LayoutBookmarkBar(top); |
1066 } | 1072 } |
1067 return LayoutInfoBar(top); | 1073 return LayoutInfoBar(top); |
1068 } | 1074 } |
1069 | 1075 |
1070 int BrowserView::LayoutBookmarkBar(int top) { | 1076 int BrowserView::LayoutBookmarkBar(int top) { |
1071 if (SupportsWindowFeature(FEATURE_BOOKMARKBAR) && active_bookmark_bar_) { | 1077 if (SupportsWindowFeature(FEATURE_BOOKMARKBAR) && active_bookmark_bar_) { |
1072 gfx::Size ps = active_bookmark_bar_->GetPreferredSize(); | 1078 gfx::Size ps = active_bookmark_bar_->GetPreferredSize(); |
1073 if (!active_info_bar_ || show_bookmark_bar_pref_.GetValue()) | 1079 if (!active_info_bar_ || show_bookmark_bar_pref_.GetValue()) |
1074 top -= kSeparationLineHeight; | 1080 top -= kSeparationLineHeight; |
1075 active_bookmark_bar_->SetBounds(0, top, width(), ps.height()); | 1081 active_bookmark_bar_->SetBounds(0, top, width(), ps.height()); |
1076 top += ps.height(); | 1082 top += ps.height(); |
1077 } | 1083 } |
1078 return top; | 1084 return top; |
1079 } | 1085 } |
1080 int BrowserView::LayoutInfoBar(int top) { | 1086 int BrowserView::LayoutInfoBar(int top) { |
1081 if (SupportsWindowFeature(FEATURE_INFOBAR) && active_info_bar_) { | 1087 if (SupportsWindowFeature(FEATURE_INFOBAR)) { |
1082 gfx::Size ps = active_info_bar_->GetPreferredSize(); | 1088 // Layout the new infobar. |
1083 active_info_bar_->SetBounds(0, top, width(), ps.height()); | 1089 gfx::Size ps = infobar_container_->GetPreferredSize(); |
| 1090 infobar_container_->SetBounds(0, top, width(), ps.height()); |
1084 top += ps.height(); | 1091 top += ps.height(); |
1085 if (SupportsWindowFeature(FEATURE_BOOKMARKBAR) && active_bookmark_bar_ && | 1092 |
1086 !show_bookmark_bar_pref_.GetValue()) { | 1093 if (active_info_bar_) { |
1087 top -= kSeparationLineHeight; | 1094 // Layout the old infobar. |
| 1095 ps = active_info_bar_->GetPreferredSize(); |
| 1096 active_info_bar_->SetBounds(0, top, width(), ps.height()); |
| 1097 top += ps.height(); |
| 1098 if (SupportsWindowFeature(FEATURE_BOOKMARKBAR) && active_bookmark_bar_ && |
| 1099 !show_bookmark_bar_pref_.GetValue()) { |
| 1100 top -= kSeparationLineHeight; |
| 1101 } |
1088 } | 1102 } |
1089 } | 1103 } |
1090 return top; | 1104 return top; |
1091 } | 1105 } |
1092 | 1106 |
1093 void BrowserView::LayoutTabContents(int top, int bottom) { | 1107 void BrowserView::LayoutTabContents(int top, int bottom) { |
1094 contents_container_->SetBounds(0, top, width(), bottom - top); | 1108 contents_container_->SetBounds(0, top, width(), bottom - top); |
1095 } | 1109 } |
1096 | 1110 |
1097 int BrowserView::LayoutDownloadShelf() { | 1111 int BrowserView::LayoutDownloadShelf() { |
(...skipping 26 matching lines...) Expand all Loading... |
1124 } | 1138 } |
1125 return UpdateChildViewAndLayout(new_bookmark_bar_view, | 1139 return UpdateChildViewAndLayout(new_bookmark_bar_view, |
1126 &active_bookmark_bar_); | 1140 &active_bookmark_bar_); |
1127 } | 1141 } |
1128 | 1142 |
1129 bool BrowserView::MaybeShowInfoBar(TabContents* contents) { | 1143 bool BrowserView::MaybeShowInfoBar(TabContents* contents) { |
1130 views::View* new_info_bar = NULL; | 1144 views::View* new_info_bar = NULL; |
1131 if (contents && contents->AsWebContents() && | 1145 if (contents && contents->AsWebContents() && |
1132 contents->AsWebContents()->view()->IsInfoBarVisible()) | 1146 contents->AsWebContents()->view()->IsInfoBarVisible()) |
1133 new_info_bar = contents->AsWebContents()->view()->GetInfoBarView(); | 1147 new_info_bar = contents->AsWebContents()->view()->GetInfoBarView(); |
1134 return UpdateChildViewAndLayout(new_info_bar, &active_info_bar_); | 1148 UpdateChildViewAndLayout(new_info_bar, &active_info_bar_); |
| 1149 |
| 1150 // TODO(beng): remove this function once the InfoBar rejiggering is complete. |
| 1151 return true; |
1135 } | 1152 } |
1136 | 1153 |
1137 bool BrowserView::MaybeShowDownloadShelf(TabContents* contents) { | 1154 bool BrowserView::MaybeShowDownloadShelf(TabContents* contents) { |
1138 views::View* new_shelf = NULL; | 1155 views::View* new_shelf = NULL; |
1139 if (contents && contents->IsDownloadShelfVisible()) | 1156 if (contents && contents->IsDownloadShelfVisible()) |
1140 new_shelf = contents->GetDownloadShelfView(); | 1157 new_shelf = contents->GetDownloadShelfView(); |
1141 return UpdateChildViewAndLayout(new_shelf, &active_download_shelf_); | 1158 return UpdateChildViewAndLayout(new_shelf, &active_download_shelf_); |
1142 } | 1159 } |
1143 | 1160 |
1144 void BrowserView::UpdateUIForContents(TabContents* contents) { | 1161 void BrowserView::UpdateUIForContents(TabContents* contents) { |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1340 | 1357 |
1341 // static | 1358 // static |
1342 void BrowserView::InitClass() { | 1359 void BrowserView::InitClass() { |
1343 static bool initialized = false; | 1360 static bool initialized = false; |
1344 if (!initialized) { | 1361 if (!initialized) { |
1345 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 1362 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
1346 default_favicon_ = *rb.GetBitmapNamed(IDR_DEFAULT_FAVICON); | 1363 default_favicon_ = *rb.GetBitmapNamed(IDR_DEFAULT_FAVICON); |
1347 initialized = true; | 1364 initialized = true; |
1348 } | 1365 } |
1349 } | 1366 } |
OLD | NEW |