diff options
author | brettw@google.com <brettw@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-09-26 19:30:34 +0000 |
---|---|---|
committer | brettw@google.com <brettw@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-09-26 19:30:34 +0000 |
commit | d5f942bab2af72892413a3080fb7468b0bbef713 (patch) | |
tree | ec5e97ea265fba45bb1f6102bc1aed4001f9898b /chrome/browser/tab_contents.cc | |
parent | e711c4dded8a24f780c039e545d7378937e1388b (diff) | |
download | chromium_src-d5f942bab2af72892413a3080fb7468b0bbef713.zip chromium_src-d5f942bab2af72892413a3080fb7468b0bbef713.tar.gz chromium_src-d5f942bab2af72892413a3080fb7468b0bbef713.tar.bz2 |
Reorganize the declarations to have some grouping and logical ordering in tab contents and web contents. Reorder the derived classes overrides to match, and reorder the definitions of the functions to match the order in the header file.
This doesn't actually change any code. I removed a few functions that were declared but never implemented (!) as well as some that were marked vitual but were never overridden. I renamed some things to make them more consistent.
Review URL: http://codereview.chromium.org/5005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@2634 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/tab_contents.cc')
-rw-r--r-- | chrome/browser/tab_contents.cc | 499 |
1 files changed, 242 insertions, 257 deletions
diff --git a/chrome/browser/tab_contents.cc b/chrome/browser/tab_contents.cc index 17fd07c..7794b32 100644 --- a/chrome/browser/tab_contents.cc +++ b/chrome/browser/tab_contents.cc @@ -19,17 +19,29 @@ #include "generated_resources.h" +namespace { + +BOOL CALLBACK InvalidateWindow(HWND hwnd, LPARAM lparam) { + // Note: erase is required to properly paint some widgets borders. This can be + // seen with textfields. + InvalidateRect(hwnd, NULL, TRUE); + return TRUE; +} + +} // namespace + TabContents::TabContents(TabContentsType type) - : is_loading_(false), - response_started_(false), - is_active_(true), - type_(type), + : type_(type), delegate_(NULL), controller_(NULL), - max_page_id_(-1), - saved_location_bar_state_(NULL), + is_loading_(false), + is_active_(true), is_crashed_(false), - shelf_visible_(false) { + waiting_for_response_(false), + saved_location_bar_state_(NULL), + shelf_visible_(false), + max_page_id_(-1), + capturing_contents_(false) { last_focused_view_storage_id_ = ChromeViews::ViewStorage::GetSharedInstance()->CreateStorageID(); } @@ -45,42 +57,49 @@ TabContents::~TabContents() { view_storage->RemoveView(last_focused_view_storage_id_); } -void TabContents::HideContents() { - // Hide the contents before adjusting its parent to avoid a full desktop - // flicker. - ShowWindow(GetContainerHWND(), SW_HIDE); - - // Reset the parent to NULL to ensure hidden tabs don't receive messages. - SetParent(GetContainerHWND(), NULL); +// static +void TabContents::RegisterUserPrefs(PrefService* prefs) { + prefs->RegisterBooleanPref(prefs::kBlockPopups, false); +} - // Remove any focus manager related information. - ChromeViews::FocusManager::UninstallFocusSubclass(GetContainerHWND()); - WasHidden(); +void TabContents::CloseContents() { + // Destroy our NavigationController, which will Destroy all tabs it owns. + controller_->Destroy(); + // Note that the controller may have deleted us at this point, + // so don't touch any member variables here. } -int32 TabContents::GetMaxPageID() { - if (GetSiteInstance()) - return GetSiteInstance()->max_page_id(); - else - return max_page_id_; -} +void TabContents::Destroy() { + // First cleanly close all child windows. + // TODO(mpcomplete): handle case if MaybeCloseChildWindows() already asked + // some of these to close. CloseWindows is async, so it might get called + // twice before it runs. + int size = static_cast<int>(child_windows_.size()); + for (int i = size - 1; i >= 0; --i) { + ConstrainedWindow* window = child_windows_[i]; + if (window) + window->CloseConstrainedWindow(); + } -void TabContents::UpdateMaxPageID(int32 page_id) { - // Ensure both the SiteInstance and RenderProcessHost update their max page - // IDs in sync. Only WebContents will also have site instances, except during - // testing. - if (GetSiteInstance()) - GetSiteInstance()->UpdateMaxPageID(page_id); + // Notify any observer that have a reference on this tab contents. + NotificationService::current()->Notify(NOTIFY_TAB_CONTENTS_DESTROYED, + Source<TabContents>(this), + NotificationService::NoDetails()); - if (AsWebContents()) - AsWebContents()->process()->UpdateMaxPageID(page_id); - else - max_page_id_ = std::max(max_page_id_, page_id); -} + // If we still have a window handle, destroy it. GetContainerHWND can return + // NULL if this contents was part of a window that closed. + if (GetContainerHWND()) + ::DestroyWindow(GetContainerHWND()); -const std::wstring TabContents::GetDefaultTitle() const { - return l10n_util::GetString(IDS_DEFAULT_TAB_TITLE); + // Notify our NavigationController. Make sure we are deleted first, so + // that the controller is the last to die. + NavigationController* controller = controller_; + TabContentsType type = this->type(); + + delete this; + + controller->TabContentsWasDestroyed(type); } void TabContents::SetupController(Profile* profile) { @@ -88,19 +107,22 @@ void TabContents::SetupController(Profile* profile) { controller_ = new NavigationController(this, profile); } -const GURL& TabContents::GetURL() const { - DCHECK(controller_); - - static const GURL kEmptyURL; +bool TabContents::SupportsURL(GURL* url) { + GURL u(*url); + if (TabContents::TypeForURL(&u) == type()) { + *url = u; + return true; + } + return false; +} +const GURL& TabContents::GetURL() const { // We may not have a navigation entry yet NavigationEntry* entry = controller_->GetActiveEntry(); - return entry ? entry->display_url() : kEmptyURL; + return entry ? entry->display_url() : GURL::EmptyGURL(); } const std::wstring& TabContents::GetTitle() const { - DCHECK(controller_); - // We always want to use the title for the last committed entry rather than // a pending navigation entry. For example, when the user types in a URL, we // want to keep the old page's title until the new load has committed and we @@ -113,9 +135,31 @@ const std::wstring& TabContents::GetTitle() const { return EmptyWString(); } -SkBitmap TabContents::GetFavIcon() const { - DCHECK(controller_); +int32 TabContents::GetMaxPageID() { + if (GetSiteInstance()) + return GetSiteInstance()->max_page_id(); + else + return max_page_id_; +} +void TabContents::UpdateMaxPageID(int32 page_id) { + // Ensure both the SiteInstance and RenderProcessHost update their max page + // IDs in sync. Only WebContents will also have site instances, except during + // testing. + if (GetSiteInstance()) + GetSiteInstance()->UpdateMaxPageID(page_id); + + if (AsWebContents()) + AsWebContents()->process()->UpdateMaxPageID(page_id); + else + max_page_id_ = std::max(max_page_id_, page_id); +} + +const std::wstring TabContents::GetDefaultTitle() const { + return l10n_util::GetString(IDS_DEFAULT_TAB_TITLE); +} + +SkBitmap TabContents::GetFavIcon() const { // Like GetTitle(), we also want to use the favicon for the last committed // entry rather than a pending navigation entry. NavigationEntry* entry = controller_->GetLastCommittedEntry(); @@ -154,43 +198,51 @@ bool TabContents::GetSSLEVText(std::wstring* ev_text, return SSLManager::GetEVCertNames(*cert, ev_text, ev_tooltip_text); } -void TabContents::CloseContents() { - // Destroy our NavigationController, which will Destroy all tabs it owns. - controller_->Destroy(); - // Note that the controller may have deleted us at this point, - // so don't touch any member variables here. +void TabContents::SetIsCrashed(bool state) { + if (state == is_crashed_) + return; + + is_crashed_ = state; + if (delegate_) + delegate_->ContentsStateChanged(this); } -void TabContents::Destroy() { - // First cleanly close all child windows. - // TODO(mpcomplete): handle case if MaybeCloseChildWindows() already asked - // some of these to close. CloseWindows is async, so it might get called - // twice before it runs. - int size = static_cast<int>(child_windows_.size()); - for (int i = size - 1; i >= 0; --i) { - ConstrainedWindow* window = child_windows_[i]; - if (window) - window->CloseConstrainedWindow(); - } +void TabContents::NotifyNavigationStateChanged(unsigned changed_flags) { + if (delegate_) + delegate_->NavigationStateChanged(this, changed_flags); +} - // Notify any observer that have a reference on this tab contents. - NotificationService::current()->Notify(NOTIFY_TAB_CONTENTS_DESTROYED, +void TabContents::DidBecomeSelected() { + if (controller_) + controller_->SetActive(true); + + // Invalidate all descendants. (take care to exclude invalidating ourselves!) + EnumChildWindows(GetContainerHWND(), InvalidateWindow, 0); +} + +void TabContents::WasHidden() { + NotificationService::current()->Notify(NOTIFY_TAB_CONTENTS_HIDDEN, Source<TabContents>(this), NotificationService::NoDetails()); +} - // If we still have a window handle, destroy it. GetContainerHWND can return - // NULL if this contents was part of a window that closed. - if (GetContainerHWND()) - ::DestroyWindow(GetContainerHWND()); - - // Notify our NavigationController. Make sure we are deleted first, so - // that the controller is the last to die. - NavigationController* controller = controller_; - TabContentsType type = this->type(); +void TabContents::Activate() { + if (delegate_) + delegate_->ActivateContents(this); +} - delete this; +void TabContents::OpenURL(const GURL& url, + WindowOpenDisposition disposition, + PageTransition::Type transition) { + if (delegate_) + delegate_->OpenURLFromTab(this, url, disposition, transition); +} - controller->TabContentsWasDestroyed(type); +bool TabContents::NavigateToPendingEntry(bool reload) { + // Our benavior is just to report that the entry was committed. + controller()->GetPendingEntry()->set_title(GetDefaultTitle()); + controller()->CommitPendingEntry(); + return true; } ConstrainedWindow* TabContents::CreateConstrainedDialog( @@ -236,66 +288,6 @@ void TabContents::AddConstrainedPopup(TabContents* new_contents, RepositionSupressedPopupsToFit(new_size); } -void TabContents::SetIsLoading(bool is_loading, - LoadNotificationDetails* details) { - if (is_loading == is_loading_) - return; - - is_loading_ = is_loading; - response_started_ = is_loading; - - // Suppress notifications for this TabContents if we are not active. - if (!is_active_) - return; - - if (delegate_) - delegate_->LoadingStateChanged(this); - - NotificationService::current()-> - Notify((is_loading ? NOTIFY_LOAD_START : NOTIFY_LOAD_STOP), - Source<NavigationController>(this->controller()), - details ? Details<LoadNotificationDetails>(details) : - NotificationService::NoDetails()); -} - -bool TabContents::NavigateToPendingEntry(bool reload) { - // Our benavior is just to report that the entry was committed. - controller()->GetPendingEntry()->set_title(GetDefaultTitle()); - controller()->CommitPendingEntry(); - return true; -} - -void TabContents::NotifyNavigationStateChanged(unsigned changed_flags) { - if (delegate_) - delegate_->NavigationStateChanged(this, changed_flags); -} - -static BOOL CALLBACK InvalidateWindow(HWND hwnd, LPARAM lparam) { - // Note: erase is required to properly paint some widgets borders. This can be - // seen with textfields. - InvalidateRect(hwnd, NULL, TRUE); - return TRUE; -} - -void TabContents::DidBecomeSelected() { - if (controller_) - controller_->SetActive(true); - - // Invalidate all descendants. (take care to exclude invalidating ourselves!) - EnumChildWindows(GetContainerHWND(), InvalidateWindow, 0); -} - -void TabContents::WasHidden() { - NotificationService::current()->Notify(NOTIFY_TAB_CONTENTS_HIDDEN, - Source<TabContents>(this), - NotificationService::NoDetails()); -} - -void TabContents::Activate() { - if (delegate_) - delegate_->ActivateContents(this); -} - void TabContents::CloseAllSuppressedPopups() { // Close all auto positioned child windows to "clean up" the workspace. int count = static_cast<int>(child_windows_.size()); @@ -306,88 +298,20 @@ void TabContents::CloseAllSuppressedPopups() { } } -void TabContents::OnStartDownload(DownloadItem* download) { - DCHECK(download); - TabContents* tab_contents = this; - - // Download in a constrained popup is shown in the tab that opened it. - TabContents* constraining_tab = delegate()->GetConstrainingContents(this); - if (constraining_tab) - tab_contents = constraining_tab; - - // GetDownloadShelfView creates the download shelf if it was not yet created. - tab_contents->GetDownloadShelfView()->AddDownload(download); - tab_contents->SetDownloadShelfVisible(true); - - // This animation will delete itself when it finishes, or if we become hidden - // or destroyed. - if (IsWindowVisible(GetContainerHWND())) { // For minimized windows, unit - // tests, etc. - new DownloadStartedAnimation(tab_contents); - } -} - - -/////////////////////////////////////////////////////////////////////////////// -// TabContents, ConstrainedTabContentsDelegate implementation: - -void TabContents::AddNewContents(ConstrainedWindow* window, - TabContents* new_contents, - WindowOpenDisposition disposition, - const gfx::Rect& initial_pos, - bool user_gesture) { - AddNewContents(new_contents, disposition, initial_pos, user_gesture); -} - -void TabContents::OpenURL(ConstrainedWindow* window, - const GURL& url, - WindowOpenDisposition disposition, - PageTransition::Type transition) { - OpenURL(url, disposition, transition); -} - -void TabContents::WillClose(ConstrainedWindow* window) { - ConstrainedWindowList::iterator it = - find(child_windows_.begin(), child_windows_.end(), window); - if (it != child_windows_.end()) - child_windows_.erase(it); - - if (::IsWindow(GetContainerHWND())) { - CRect client_rect; - GetClientRect(GetContainerHWND(), &client_rect); - RepositionSupressedPopupsToFit( - gfx::Size(client_rect.Width(), client_rect.Height())); - } -} - -void TabContents::DetachContents(ConstrainedWindow* window, - TabContents* contents, - const gfx::Rect& contents_bounds, - const gfx::Point& mouse_pt, - int frame_component) { - WillClose(window); - if (delegate_) { - delegate_->StartDraggingDetachedContents( - this, contents, contents_bounds, mouse_pt, frame_component); - } -} +void TabContents::HideContents() { + // Hide the contents before adjusting its parent to avoid a full desktop + // flicker. + ShowWindow(GetContainerHWND(), SW_HIDE); -void TabContents::DidMoveOrResize(ConstrainedWindow* window) { - UpdateWindow(GetContainerHWND()); -} + // Reset the parent to NULL to ensure hidden tabs don't receive messages. + SetParent(GetContainerHWND(), NULL); -/////////////////////////////////////////////////////////////////////////////// -// PageNavigator methods + // Remove any focus manager related information. + ChromeViews::FocusManager::UninstallFocusSubclass(GetContainerHWND()); -void TabContents::OpenURL(const GURL& url, - WindowOpenDisposition disposition, - PageTransition::Type transition) { - if (delegate_) - delegate_->OpenURLFromTab(this, url, disposition, transition); + WasHidden(); } -/////////////////////////////////////////////////////////////////////////////// - void TabContents::Focus() { ChromeViews::FocusManager* focus_manager = ChromeViews::FocusManager::GetFocusManager(GetContainerHWND()); @@ -456,21 +380,8 @@ void TabContents::RestoreFocus() { } } -void TabContents::RepositionSupressedPopupsToFit(const gfx::Size& new_size) { - // TODO(erg): There's no way to detect whether scroll bars are - // visible, so for beta, we're just going to assume that the - // vertical scroll bar is visible, and not care about covering up - // the horizontal scroll bar. Fixing this is half of - // http://b/1118139. - gfx::Point anchor_position( - new_size.width() - ChromeViews::NativeScrollBar::GetVerticalScrollBarWidth(), - new_size.height()); - int window_count = static_cast<int>(child_windows_.size()); - for (int i = window_count - 1; i >= 0; --i) { - ConstrainedWindow* window = child_windows_.at(i); - if (window->IsSuppressedConstrainedWindow()) - window->RepositionConstrainedWindowTo(anchor_position); - } +void TabContents::SetInitialFocus() { + ::SetFocus(GetContainerHWND()); } void TabContents::SetDownloadShelfVisible(bool visible) { @@ -491,40 +402,31 @@ void TabContents::SetDownloadShelfVisible(bool visible) { ToolbarSizeChanged(false); } -void TabContents::ReleaseDownloadShelfView() { - download_shelf_view_.release(); -} - -void TabContents::SetInitialFocus() { - ::SetFocus(GetContainerHWND()); +void TabContents::ToolbarSizeChanged(bool is_animating) { + TabContentsDelegate* d = delegate(); + if (d) + d->ToolbarSizeChanged(this, is_animating); } -void TabContents::SetIsCrashed(bool state) { - if (state == is_crashed_) - return; +void TabContents::OnStartDownload(DownloadItem* download) { + DCHECK(download); + TabContents* tab_contents = this; - is_crashed_ = state; - if (delegate_) - delegate_->ContentsStateChanged(this); -} + // Download in a constrained popup is shown in the tab that opened it. + TabContents* constraining_tab = delegate()->GetConstrainingContents(this); + if (constraining_tab) + tab_contents = constraining_tab; -bool TabContents::IsCrashed() const { - return is_crashed_; -} + // GetDownloadShelfView creates the download shelf if it was not yet created. + tab_contents->GetDownloadShelfView()->AddDownload(download); + tab_contents->SetDownloadShelfVisible(true); -bool TabContents::SupportsURL(GURL* url) { - GURL u(*url); - if (TabContents::TypeForURL(&u) == type()) { - *url = u; - return true; + // This animation will delete itself when it finishes, or if we become hidden + // or destroyed. + if (IsWindowVisible(GetContainerHWND())) { // For minimized windows, unit + // tests, etc. + new DownloadStartedAnimation(tab_contents); } - return false; -} - -void TabContents::ToolbarSizeChanged(bool is_animating) { - TabContentsDelegate* d = delegate(); - if (d) - d->ToolbarSizeChanged(this, is_animating); } DownloadShelfView* TabContents::GetDownloadShelfView() { @@ -542,6 +444,51 @@ void TabContents::MigrateShelfViewFrom(TabContents* tab_contents) { tab_contents->ReleaseDownloadShelfView(); } +void TabContents::AddNewContents(ConstrainedWindow* window, + TabContents* new_contents, + WindowOpenDisposition disposition, + const gfx::Rect& initial_pos, + bool user_gesture) { + AddNewContents(new_contents, disposition, initial_pos, user_gesture); +} + +void TabContents::OpenURL(ConstrainedWindow* window, + const GURL& url, + WindowOpenDisposition disposition, + PageTransition::Type transition) { + OpenURL(url, disposition, transition); +} + +void TabContents::WillClose(ConstrainedWindow* window) { + ConstrainedWindowList::iterator it = + find(child_windows_.begin(), child_windows_.end(), window); + if (it != child_windows_.end()) + child_windows_.erase(it); + + if (::IsWindow(GetContainerHWND())) { + CRect client_rect; + GetClientRect(GetContainerHWND(), &client_rect); + RepositionSupressedPopupsToFit( + gfx::Size(client_rect.Width(), client_rect.Height())); + } +} + +void TabContents::DetachContents(ConstrainedWindow* window, + TabContents* contents, + const gfx::Rect& contents_bounds, + const gfx::Point& mouse_pt, + int frame_component) { + WillClose(window); + if (delegate_) { + delegate_->StartDraggingDetachedContents( + this, contents, contents_bounds, mouse_pt, frame_component); + } +} + +void TabContents::DidMoveOrResize(ConstrainedWindow* window) { + UpdateWindow(GetContainerHWND()); +} + // static void TabContents::MigrateShelfView(TabContents* from, TabContents* to) { bool was_shelf_visible = from->IsDownloadShelfVisible(); @@ -550,8 +497,46 @@ void TabContents::MigrateShelfView(TabContents* from, TabContents* to) { to->SetDownloadShelfVisible(was_shelf_visible); } -// static -void TabContents::RegisterUserPrefs(PrefService* prefs) { - prefs->RegisterBooleanPref(prefs::kBlockPopups, false); +void TabContents::SetIsLoading(bool is_loading, + LoadNotificationDetails* details) { + if (is_loading == is_loading_) + return; + + is_loading_ = is_loading; + waiting_for_response_ = is_loading; + + // Suppress notifications for this TabContents if we are not active. + if (!is_active_) + return; + + if (delegate_) + delegate_->LoadingStateChanged(this); + + NotificationService::current()-> + Notify((is_loading ? NOTIFY_LOAD_START : NOTIFY_LOAD_STOP), + Source<NavigationController>(this->controller()), + details ? Details<LoadNotificationDetails>(details) : + NotificationService::NoDetails()); } +void TabContents::RepositionSupressedPopupsToFit(const gfx::Size& new_size) { + // TODO(erg): There's no way to detect whether scroll bars are + // visible, so for beta, we're just going to assume that the + // vertical scroll bar is visible, and not care about covering up + // the horizontal scroll bar. Fixing this is half of + // http://b/1118139. + gfx::Point anchor_position( + new_size.width() - + ChromeViews::NativeScrollBar::GetVerticalScrollBarWidth(), + new_size.height()); + int window_count = static_cast<int>(child_windows_.size()); + for (int i = window_count - 1; i >= 0; --i) { + ConstrainedWindow* window = child_windows_.at(i); + if (window->IsSuppressedConstrainedWindow()) + window->RepositionConstrainedWindowTo(anchor_position); + } +} + +void TabContents::ReleaseDownloadShelfView() { + download_shelf_view_.release(); +} |