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 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 | 174 |
175 BrowserView::BrowserView(Browser* browser) | 175 BrowserView::BrowserView(Browser* browser) |
176 : views::ClientView(NULL, NULL), | 176 : views::ClientView(NULL, NULL), |
177 frame_(NULL), | 177 frame_(NULL), |
178 browser_(browser), | 178 browser_(browser), |
179 active_bookmark_bar_(NULL), | 179 active_bookmark_bar_(NULL), |
180 active_download_shelf_(NULL), | 180 active_download_shelf_(NULL), |
181 toolbar_(NULL), | 181 toolbar_(NULL), |
182 contents_container_(NULL), | 182 contents_container_(NULL), |
183 initialized_(false), | 183 initialized_(false), |
| 184 fullscreen_(false), |
184 can_drop_(false), | 185 can_drop_(false), |
185 hung_window_detector_(&hung_plugin_action_), | 186 hung_window_detector_(&hung_plugin_action_), |
186 ticker_(0), | 187 ticker_(0), |
187 #ifdef CHROME_PERSONALIZATION | 188 #ifdef CHROME_PERSONALIZATION |
188 personalization_enabled_(false), | 189 personalization_enabled_(false), |
189 personalization_(NULL), | 190 personalization_(NULL), |
190 #endif | 191 #endif |
191 forwarding_to_tab_strip_(false) { | 192 forwarding_to_tab_strip_(false) { |
192 InitClass(); | 193 InitClass(); |
193 browser_->tabstrip_model()->AddObserver(this); | 194 browser_->tabstrip_model()->AddObserver(this); |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
359 command, | 360 command, |
360 browser_->command_updater()->IsCommandEnabled(command)); | 361 browser_->command_updater()->IsCommandEnabled(command)); |
361 } | 362 } |
362 } | 363 } |
363 } | 364 } |
364 | 365 |
365 bool BrowserView::SupportsWindowFeature(WindowFeature feature) const { | 366 bool BrowserView::SupportsWindowFeature(WindowFeature feature) const { |
366 const Browser::Type type = browser_->type(); | 367 const Browser::Type type = browser_->type(); |
367 unsigned int features = FEATURE_INFOBAR | FEATURE_DOWNLOADSHELF; | 368 unsigned int features = FEATURE_INFOBAR | FEATURE_DOWNLOADSHELF; |
368 if (type == Browser::TYPE_NORMAL) | 369 if (type == Browser::TYPE_NORMAL) |
369 features |= FEATURE_TABSTRIP | FEATURE_TOOLBAR | FEATURE_BOOKMARKBAR; | 370 features |= FEATURE_BOOKMARKBAR; |
370 else | 371 if (!fullscreen_) { |
371 features |= FEATURE_TITLEBAR; | 372 if (type == Browser::TYPE_NORMAL) |
372 if (type != Browser::TYPE_APP) | 373 features |= FEATURE_TABSTRIP | FEATURE_TOOLBAR; |
373 features |= FEATURE_LOCATIONBAR; | 374 else |
| 375 features |= FEATURE_TITLEBAR; |
| 376 if (type != Browser::TYPE_APP) |
| 377 features |= FEATURE_LOCATIONBAR; |
| 378 } |
374 return !!(features & feature); | 379 return !!(features & feature); |
375 } | 380 } |
376 | 381 |
377 // static | 382 // static |
378 void BrowserView::RegisterBrowserViewPrefs(PrefService* prefs) { | 383 void BrowserView::RegisterBrowserViewPrefs(PrefService* prefs) { |
379 prefs->RegisterIntegerPref(prefs::kPluginMessageResponseTimeout, | 384 prefs->RegisterIntegerPref(prefs::kPluginMessageResponseTimeout, |
380 kDefaultPluginMessageResponseTimeout); | 385 kDefaultPluginMessageResponseTimeout); |
381 prefs->RegisterIntegerPref(prefs::kHungPluginDetectFrequency, | 386 prefs->RegisterIntegerPref(prefs::kHungPluginDetectFrequency, |
382 kDefaultHungPluginDetectFrequency); | 387 kDefaultHungPluginDetectFrequency); |
383 } | 388 } |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
524 LoadingAnimationCallback(); | 529 LoadingAnimationCallback(); |
525 } | 530 } |
526 } | 531 } |
527 } | 532 } |
528 | 533 |
529 void BrowserView::SetStarredState(bool is_starred) { | 534 void BrowserView::SetStarredState(bool is_starred) { |
530 toolbar_->star_button()->SetToggled(is_starred); | 535 toolbar_->star_button()->SetToggled(is_starred); |
531 } | 536 } |
532 | 537 |
533 gfx::Rect BrowserView::GetNormalBounds() const { | 538 gfx::Rect BrowserView::GetNormalBounds() const { |
| 539 // If we're in fullscreen mode, we've changed the rect associated with the |
| 540 // current window style to the monitor rect. If we weren't maximized, that |
| 541 // means it's the rcNormalPosition which has been changed, so we need to |
| 542 // return the saved rect here instead of the current one. |
| 543 if (fullscreen_ && !IsMaximized()) |
| 544 return gfx::Rect(saved_window_info_.window_rect); |
| 545 |
534 WINDOWPLACEMENT wp; | 546 WINDOWPLACEMENT wp; |
535 wp.length = sizeof(wp); | 547 wp.length = sizeof(wp); |
536 const bool ret = !!GetWindowPlacement(frame_->GetWindow()->GetHWND(), &wp); | 548 const bool ret = !!GetWindowPlacement(frame_->GetWindow()->GetHWND(), &wp); |
537 DCHECK(ret); | 549 DCHECK(ret); |
538 return gfx::Rect(wp.rcNormalPosition); | 550 return gfx::Rect(wp.rcNormalPosition); |
539 } | 551 } |
540 | 552 |
541 bool BrowserView::IsMaximized() const { | 553 bool BrowserView::IsMaximized() const { |
542 return frame_->GetWindow()->IsMaximized(); | 554 return frame_->GetWindow()->IsMaximized(); |
543 } | 555 } |
544 | 556 |
| 557 void BrowserView::SetFullscreen(bool fullscreen) { |
| 558 if (fullscreen_ == fullscreen) |
| 559 return; // Nothing to do. |
| 560 |
| 561 // Move focus out of the location bar if necessary, and make it unfocusable. |
| 562 LocationBarView* location_bar = toolbar_->GetLocationBarView(); |
| 563 if (!fullscreen_) { |
| 564 views::FocusManager* focus_manager = GetFocusManager(); |
| 565 DCHECK(focus_manager); |
| 566 if (focus_manager->GetFocusedView() == location_bar) |
| 567 focus_manager->ClearFocus(); |
| 568 } |
| 569 location_bar->SetFocusable(fullscreen_); |
| 570 |
| 571 // Toggle fullscreen mode. |
| 572 fullscreen_ = fullscreen; |
| 573 |
| 574 // Notify bookmark bar, so it can set itself to the appropriate drawing state. |
| 575 if (bookmark_bar_view_.get()) |
| 576 bookmark_bar_view_->OnFullscreenToggled(fullscreen_); |
| 577 |
| 578 HWND hwnd = GetWidget()->GetHWND(); |
| 579 gfx::Rect new_rect; |
| 580 if (fullscreen_) { |
| 581 // Save current window information. |
| 582 saved_window_info_.style = GetWindowLong(hwnd, GWL_STYLE); |
| 583 saved_window_info_.ex_style = GetWindowLong(hwnd, GWL_EXSTYLE); |
| 584 GetWindowRect(hwnd, &saved_window_info_.window_rect); |
| 585 |
| 586 // Set new window style and size. |
| 587 SetWindowLong(hwnd, GWL_STYLE, |
| 588 saved_window_info_.style & ~(WS_CAPTION | WS_THICKFRAME)); |
| 589 SetWindowLong(hwnd, GWL_EXSTYLE, |
| 590 saved_window_info_.ex_style & ~(WS_EX_DLGMODALFRAME | |
| 591 WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE | WS_EX_STATICEDGE)); |
| 592 MONITORINFO monitor_info; |
| 593 monitor_info.cbSize = sizeof(monitor_info); |
| 594 GetMonitorInfo(MonitorFromWindow(hwnd, MONITOR_DEFAULTTOPRIMARY), |
| 595 &monitor_info); |
| 596 new_rect = monitor_info.rcMonitor; |
| 597 } else { |
| 598 // Reset original window style and size. |
| 599 SetWindowLong(hwnd, GWL_STYLE, saved_window_info_.style); |
| 600 SetWindowLong(hwnd, GWL_EXSTYLE, saved_window_info_.ex_style); |
| 601 new_rect = saved_window_info_.window_rect; |
| 602 } |
| 603 // This will cause the window to re-layout. |
| 604 SetWindowPos(hwnd, NULL, new_rect.x(), new_rect.y(), new_rect.width(), |
| 605 new_rect.height(), SWP_NOZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED); |
| 606 } |
| 607 |
| 608 bool BrowserView::IsFullscreen() const { |
| 609 return fullscreen_; |
| 610 } |
| 611 |
545 LocationBar* BrowserView::GetLocationBar() const { | 612 LocationBar* BrowserView::GetLocationBar() const { |
546 return toolbar_->GetLocationBarView(); | 613 return toolbar_->GetLocationBarView(); |
547 } | 614 } |
548 | 615 |
549 void BrowserView::SetFocusToLocationBar() { | 616 void BrowserView::SetFocusToLocationBar() { |
550 LocationBarView* location_bar = toolbar_->GetLocationBarView(); | 617 LocationBarView* location_bar = toolbar_->GetLocationBarView(); |
551 if (location_bar->IsFocusable()) { | 618 if (location_bar->IsFocusable()) { |
552 location_bar->FocusLocation(); | 619 location_bar->FocusLocation(); |
553 } else { | 620 } else { |
554 views::FocusManager* focus_manager = GetFocusManager(); | 621 views::FocusManager* focus_manager = GetFocusManager(); |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
851 return false; | 918 return false; |
852 } | 919 } |
853 | 920 |
854 std::wstring BrowserView::GetWindowName() const { | 921 std::wstring BrowserView::GetWindowName() const { |
855 return browser_->GetWindowPlacementKey(); | 922 return browser_->GetWindowPlacementKey(); |
856 } | 923 } |
857 | 924 |
858 void BrowserView::SaveWindowPlacement(const gfx::Rect& bounds, | 925 void BrowserView::SaveWindowPlacement(const gfx::Rect& bounds, |
859 bool maximized, | 926 bool maximized, |
860 bool always_on_top) { | 927 bool always_on_top) { |
861 if (browser_->ShouldSaveWindowPlacement()) { | 928 // If fullscreen_ is true, we've just changed into fullscreen mode, and we're |
| 929 // catching the going-into-fullscreen sizing and positioning calls, which we |
| 930 // want to ignore. |
| 931 if (!fullscreen_ && browser_->ShouldSaveWindowPlacement()) { |
862 WindowDelegate::SaveWindowPlacement(bounds, maximized, always_on_top); | 932 WindowDelegate::SaveWindowPlacement(bounds, maximized, always_on_top); |
863 browser_->SaveWindowPlacement(bounds, maximized); | 933 browser_->SaveWindowPlacement(bounds, maximized); |
864 } | 934 } |
865 } | 935 } |
866 | 936 |
867 bool BrowserView::GetSavedWindowBounds(gfx::Rect* bounds) const { | 937 bool BrowserView::GetSavedWindowBounds(gfx::Rect* bounds) const { |
868 *bounds = browser_->GetSavedWindowBounds(); | 938 *bounds = browser_->GetSavedWindowBounds(); |
869 if (browser_->type() == Browser::TYPE_POPUP) { | 939 if (browser_->type() == Browser::TYPE_POPUP) { |
870 // We are a popup window. The value passed in |bounds| represents two | 940 // We are a popup window. The value passed in |bounds| represents two |
871 // pieces of information: | 941 // pieces of information: |
(...skipping 615 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1487 | 1557 |
1488 // static | 1558 // static |
1489 void BrowserView::InitClass() { | 1559 void BrowserView::InitClass() { |
1490 static bool initialized = false; | 1560 static bool initialized = false; |
1491 if (!initialized) { | 1561 if (!initialized) { |
1492 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 1562 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
1493 default_favicon_ = *rb.GetBitmapNamed(IDR_DEFAULT_FAVICON); | 1563 default_favicon_ = *rb.GetBitmapNamed(IDR_DEFAULT_FAVICON); |
1494 initialized = true; | 1564 initialized = true; |
1495 } | 1565 } |
1496 } | 1566 } |
OLD | NEW |