diff options
25 files changed, 488 insertions, 464 deletions
diff --git a/chrome/browser/automation/automation_provider.cc b/chrome/browser/automation/automation_provider.cc index 85443a9..56003de 100644 --- a/chrome/browser/automation/automation_provider.cc +++ b/chrome/browser/automation/automation_provider.cc @@ -5,7 +5,7 @@ #include "chrome/browser/automation/automation_provider.h" #include "base/path_service.h" -#include "chrome/app/chrome_dll_resource.h" +#include "chrome/app/chrome_dll_resource.h" #include "chrome/browser/automation/automation_provider_list.h" #include "chrome/browser/automation/ui_controls.h" #include "chrome/browser/automation/url_request_failed_dns_job.h" @@ -24,6 +24,7 @@ #include "chrome/browser/ssl_manager.h" #include "chrome/browser/ssl_blocking_page.h" #include "chrome/browser/web_contents.h" +#include "chrome/browser/web_contents_view.h" #include "chrome/browser/views/bookmark_bar_view.h" #include "chrome/browser/views/location_bar_view.h" #include "chrome/common/chrome_paths.h" @@ -1715,17 +1716,18 @@ void AutomationProvider::HandleFindRequest(const IPC::Message& message, FindInPageNotificationObserver(this, tab_contents, message.routing_id())); // The find in page dialog must be up for us to get the notification that the - // find was complete - if (tab_contents->AsWebContents()) { + // find was complete. + WebContents* web_contents = tab_contents->AsWebContents(); + if (web_contents) { NavigationController* tab = tab_tracker_->GetResource(handle); Browser* browser = Browser::GetBrowserForController(tab, NULL); - tab_contents->AsWebContents()->OpenFindInPageWindow(*browser); - } + web_contents->view()->FindInPage(*browser, true, request.forward); - tab_contents->StartFinding( - FindInPageNotificationObserver::kFindInPageRequestId, - request.search_string, request.forward, request.match_case, - request.find_next); + web_contents->render_view_host()->StartFinding( + FindInPageNotificationObserver::kFindInPageRequestId, + request.search_string, request.forward, request.match_case, + request.find_next); + } } void AutomationProvider::HandleOpenFindInPageRequest( @@ -1734,16 +1736,17 @@ void AutomationProvider::HandleOpenFindInPageRequest( WebContents* web_contents = GetWebContentsForHandle(handle, &tab); if (web_contents) { Browser* browser = Browser::GetBrowserForController(tab, NULL); - web_contents->OpenFindInPageWindow(*browser); + web_contents->view()->FindInPage(*browser, false, false); } } void AutomationProvider::GetFindWindowVisibility(const IPC::Message& message, int handle) { + gfx::Point position; bool visible = false; WebContents* web_contents = GetWebContentsForHandle(handle, NULL); if (web_contents) - visible = web_contents->IsFindWindowFullyVisible(); + visible = web_contents->view()->GetFindBarWindowInfo(&position, &visible); Send(new AutomationMsg_FindWindowVisibilityResponse(message.routing_id(), visible)); @@ -1751,13 +1754,15 @@ void AutomationProvider::GetFindWindowVisibility(const IPC::Message& message, void AutomationProvider::HandleFindWindowLocationRequest( const IPC::Message& message, int handle) { - int x = -1, y = -1; + gfx::Point position(0, 0); + bool visible = false; WebContents* web_contents = GetWebContentsForHandle(handle, NULL); if (web_contents) - web_contents->GetFindInPageWindowLocation(&x, &y); + visible = web_contents->view()->GetFindBarWindowInfo(&position, &visible); Send(new AutomationMsg_FindWindowLocationResponse(message.routing_id(), - x, y)); + position.x(), + position.y())); } void AutomationProvider::GetBookmarkBarVisitility(const IPC::Message& message, diff --git a/chrome/browser/browser.cc b/chrome/browser/browser.cc index cf88a6c..d7fd0fe 100644 --- a/chrome/browser/browser.cc +++ b/chrome/browser/browser.cc @@ -1312,7 +1312,10 @@ void Browser::CreateNewStripWithContents(TabContents* detached_contents, // When we detach a tab we need to make sure any associated Find window moves // along with it to its new home (basically we just make new_window the parent // of the Find window). - new_window->AdoptFindWindow(detached_contents); + // TODO(brettw) this could probably be improved, see + // WebContentsView::ReparentFindWindow for more. + if (detached_contents->AsWebContents()) + detached_contents->AsWebContents()->view()->ReparentFindWindow(new_window); } int Browser::GetDragActions() const { @@ -1383,7 +1386,10 @@ void Browser::TabInsertedAt(TabContents* contents, // associated Find window is moved along with it. We therefore change the // parent of the Find window (if the parent is already correctly set this // does nothing). - AdoptFindWindow(contents); + // TODO(brettw) this could probably be improved, see + // WebContentsView::ReparentFindWindow for more. + if (contents->AsWebContents()) + contents->AsWebContents()->view()->ReparentFindWindow(this); // If the tab crashes in the beforeunload or unload handler, it won't be // able to ack. But we know we can close it. diff --git a/chrome/browser/browser.h b/chrome/browser/browser.h index a57074f..e896b18 100644 --- a/chrome/browser/browser.h +++ b/chrome/browser/browser.h @@ -97,19 +97,13 @@ class Browser : public TabStripModelDelegate, // Opens the FindInPage window for the currently open tab. void OpenFindInPageWindow(); - // Becomes the parent window of the Find window of the specified tab. This is - // useful, for example, when tabs are dragged out of (or in to) the tab strip - // to make sure the Find window shows up in the right Browser window. - void AdoptFindWindow(TabContents* tab_contents); // debugger shell void OpenDebuggerWindow(); // Advance the find selection by one. Direction is either forward or backwards - // depending on parameter passed in. If selection cannot be advanced (for - // example because no search has been issued, then the function returns false - // and caller can call OpenFindInPageWindow to show the search window. - bool AdvanceFindSelection(bool forward_direction); + // depending on parameter passed in. + void AdvanceFindSelection(bool forward_direction); Profile* profile() const { return profile_; } diff --git a/chrome/browser/browser.vcproj b/chrome/browser/browser.vcproj index 2edc607..1fab9cc 100644 --- a/chrome/browser/browser.vcproj +++ b/chrome/browser/browser.vcproj @@ -970,22 +970,6 @@ > </File> <File - RelativePath=".\find_in_page_controller.cc" - > - </File> - <File - RelativePath=".\find_in_page_controller.h" - > - </File> - <File - RelativePath=".\find_in_page_view.cc" - > - </File> - <File - RelativePath=".\find_in_page_view.h" - > - </File> - <File RelativePath=".\find_notification_details.h" > </File> diff --git a/chrome/browser/browser_commands.cc b/chrome/browser/browser_commands.cc index e7f9230..b743984 100644 --- a/chrome/browser/browser_commands.cc +++ b/chrome/browser/browser_commands.cc @@ -33,6 +33,7 @@ #include "chrome/browser/views/toolbar_star_toggle.h" #include "chrome/browser/views/toolbar_view.h" #include "chrome/browser/web_contents.h" +#include "chrome/browser/web_contents_view.h" #include "chrome/common/pref_names.h" #include "chrome/common/pref_service.h" #include "chrome/common/win_util.h" @@ -394,14 +395,12 @@ void Browser::ExecuteCommand(int id) { case IDC_FIND_NEXT: UserMetrics::RecordAction(L"FindNext", profile_); - if (!AdvanceFindSelection(true)) - OpenFindInPageWindow(); + AdvanceFindSelection(true); break; case IDC_FIND_PREVIOUS: UserMetrics::RecordAction(L"FindPrevious", profile_); - if (!AdvanceFindSelection(false)) - OpenFindInPageWindow(); + AdvanceFindSelection(false); break; case IDS_COMMANDS_REPORTBUG: @@ -823,21 +822,15 @@ void Browser::StarCurrentTabContents() { void Browser::OpenFindInPageWindow() { TabContents* current_tab = GetSelectedTabContents(); if (current_tab && current_tab->AsWebContents()) - current_tab->AsWebContents()->OpenFindInPageWindow(*this); + current_tab->AsWebContents()->view()->FindInPage(*this, false, false); } -void Browser::AdoptFindWindow(TabContents* tab_contents) { - if (tab_contents->AsWebContents()) - tab_contents->AsWebContents()->ReparentFindWindow(GetTopLevelHWND()); -} - -bool Browser::AdvanceFindSelection(bool forward_direction) { +void Browser::AdvanceFindSelection(bool forward_direction) { TabContents* current_tab = GetSelectedTabContents(); if (current_tab && current_tab->AsWebContents()) { - current_tab->AsWebContents()->AdvanceFindSelection(forward_direction); + current_tab->AsWebContents()->view()->FindInPage(*this, true, + forward_direction); } - - return false; } void Browser::OpenDebuggerWindow() { diff --git a/chrome/browser/render_view_host.cc b/chrome/browser/render_view_host.cc index 577a695..c5db911 100644 --- a/chrome/browser/render_view_host.cc +++ b/chrome/browser/render_view_host.cc @@ -923,12 +923,11 @@ void RenderViewHost::OnMsgFindReply(int request_id, const gfx::Rect& selection_rect, int active_match_ordinal, bool final_update) { - RenderViewHostDelegate::FindInPage* delegate = - delegate_->GetFindInPageDelegate(); - if (!delegate) + RenderViewHostDelegate::View* view = delegate_->GetViewDelegate(); + if (!view) return; - delegate->FindReply(request_id, number_of_matches, selection_rect, - active_match_ordinal, final_update); + view->OnFindReply(request_id, number_of_matches, selection_rect, + active_match_ordinal, final_update); // Send a notification to the renderer that we are ready to receive more // results from the scoping effort of the Find operation. The FindInPage diff --git a/chrome/browser/render_view_host_delegate.h b/chrome/browser/render_view_host_delegate.h index d66ce34..3657005 100644 --- a/chrome/browser/render_view_host_delegate.h +++ b/chrome/browser/render_view_host_delegate.h @@ -99,16 +99,13 @@ class RenderViewHostDelegate { // specified events. This gives an opportunity to the browser to process the // event (used for keyboard shortcuts). virtual void HandleKeyboardEvent(const WebKeyboardEvent& event) = 0; - }; - class FindInPage { - public: // A find operation in the current page completed. - virtual void FindReply(int request_id, - int number_of_matches, - const gfx::Rect& selection_rect, - int active_match_ordinal, - bool final_update) = 0; + virtual void OnFindReply(int request_id, + int number_of_matches, + const gfx::Rect& selection_rect, + int active_match_ordinal, + bool final_update) = 0; }; // Interface for saving web pages. @@ -136,7 +133,6 @@ class RenderViewHostDelegate { // Returns the current delegate associated with a feature. May be NULL. virtual View* GetViewDelegate() const { return NULL; } - virtual FindInPage* GetFindInPageDelegate() const { return NULL; } virtual Save* GetSaveDelegate() const { return NULL; } // Retrieves the profile to be used. diff --git a/chrome/browser/tab_contents.cc b/chrome/browser/tab_contents.cc index 6234abb..f97c04c 100644 --- a/chrome/browser/tab_contents.cc +++ b/chrome/browser/tab_contents.cc @@ -311,20 +311,6 @@ void TabContents::CloseAllSuppressedPopups() { } } -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); - - // Remove any focus manager related information. - views::FocusManager::UninstallFocusSubclass(GetContainerHWND()); - - WasHidden(); -} - void TabContents::Focus() { views::FocusManager* focus_manager = views::FocusManager::GetFocusManager(GetContainerHWND()); @@ -534,6 +520,7 @@ void TabContents::SetIsLoading(bool is_loading, NotificationService::NoDetails()); } +// TODO(brettw) This should be on the WebContentsView. 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 diff --git a/chrome/browser/tab_contents.h b/chrome/browser/tab_contents.h index 3b38963..899a63e 100644 --- a/chrome/browser/tab_contents.h +++ b/chrome/browser/tab_contents.h @@ -289,20 +289,6 @@ class TabContents : public PageNavigator, // Stop any pending navigation. virtual void Stop() {} - // An asynchronous call to trigger the string search in the page. - // It sends an IPC message to the Renderer that handles the string - // search, selecting the matches and setting the caret positions. - // This function also starts the asynchronous scoping effort. - virtual void StartFinding(int request_id, - const std::wstring& string, - bool forward, bool match_case, - bool find_next) { } - - // An asynchronous call to stop the string search in the page. If - // |clear_selection| is true, it will also clear the selection on the - // focused frame. - virtual void StopFinding(bool clear_selection) { } - // TODO(erg): HACK ALERT! This was thrown together for beta and // needs to be completely removed after we ship it. Right now, the // cut/copy/paste menu items are always enabled and will send a @@ -350,15 +336,6 @@ class TabContents : public PageNavigator, // of unwanted popups. void CloseAllSuppressedPopups(); - // Show, Hide and Size the TabContents. - // TODO(beng): (Cleanup) Show/Size TabContents should be made to actually - // show and size the View. For simplicity sake, for now they're - // just empty. This is currently a bit of a mess and is just a - // band-aid. - virtual void ShowContents() {} - virtual void HideContents(); - virtual void SizeContents(const gfx::Size& size) {} - // Views and focus ----------------------------------------------------------- // Returns the actual window that is focused when this TabContents is shown. diff --git a/chrome/browser/views/browser_views.vcproj b/chrome/browser/views/browser_views.vcproj index e8a17da..cfce335 100644 --- a/chrome/browser/views/browser_views.vcproj +++ b/chrome/browser/views/browser_views.vcproj @@ -433,6 +433,26 @@ > </File> </Filter> + <Filter + Name="Find Bar" + > + <File + RelativePath=".\find_bar_view.cc" + > + </File> + <File + RelativePath=".\find_bar_view.h" + > + </File> + <File + RelativePath=".\find_bar_win.cc" + > + </File> + <File + RelativePath=".\find_bar_win.h" + > + </File> + </Filter> <File RelativePath=".\about_chrome_view.cc" > diff --git a/chrome/browser/views/constrained_window_impl.cc b/chrome/browser/views/constrained_window_impl.cc index dd948b7..e315e5a 100644 --- a/chrome/browser/views/constrained_window_impl.cc +++ b/chrome/browser/views/constrained_window_impl.cc @@ -15,6 +15,7 @@ #include "chrome/browser/toolbar_model.h" #include "chrome/browser/web_app.h" #include "chrome/browser/web_contents.h" +#include "chrome/browser/web_contents_view.h" #include "chrome/browser/window_sizer.h" #include "chrome/common/chrome_constants.h" #include "chrome/common/gfx/chrome_canvas.h" @@ -1132,9 +1133,16 @@ void ConstrainedWindowImpl::InitSizeForContents( CustomFrameWindow::Init(owner_->GetContainerHWND(), initial_bounds); contents_container_->Attach(constrained_contents_->GetContainerHWND()); - constrained_contents_->SizeContents( + // TODO(brettw) this should be done some other way, see + // WebContentsView::SizeContents. + if (constrained_contents_->AsWebContents()) { + // This should always be true, all constrained windows are WebContents. + constrained_contents_->AsWebContents()->view()->SizeContents( gfx::Size(contents_container_->width(), contents_container_->height())); + } else { + NOTREACHED(); + } current_bounds_ = initial_bounds; // Note that this is HWND_TOP, not HWND_TOPMOST... this is important diff --git a/chrome/browser/find_in_page_view.cc b/chrome/browser/views/find_bar_view.cc index 3868e0f..2307895 100644 --- a/chrome/browser/find_in_page_view.cc +++ b/chrome/browser/views/find_bar_view.cc @@ -2,13 +2,13 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/browser/find_in_page_view.h" +#include "chrome/browser/views/find_bar_view.h" #include <algorithm> #include "base/string_util.h" #include "chrome/app/theme/theme_resources.h" -#include "chrome/browser/find_in_page_controller.h" +#include "chrome/browser/views/find_bar_win.h" #include "chrome/common/l10n_util.h" #include "chrome/common/gfx/chrome_canvas.h" #include "chrome/common/resource_bundle.h" @@ -76,10 +76,10 @@ static const SkBitmap* kBackground_left = NULL; static const int kDefaultCharWidth = 43; //////////////////////////////////////////////////////////////////////////////// -// FindInPageView, public: +// FindBarView, public: -FindInPageView::FindInPageView(FindInPageController* controller) - : controller_(controller), +FindBarView::FindBarView(FindBarWin* container) + : container_(container), find_text_(NULL), match_count_text_(NULL), focus_forwarder_view_(NULL), @@ -166,22 +166,22 @@ FindInPageView::FindInPageView(FindInPageController* controller) } } -FindInPageView::~FindInPageView() { +FindBarView::~FindBarView() { } -void FindInPageView::ResetMatchCount() { +void FindBarView::ResetMatchCount() { match_count_text_->SetText(std::wstring()); ResetMatchCountBackground(); } -void FindInPageView::ResetMatchCountBackground() { +void FindBarView::ResetMatchCountBackground() { match_count_text_->SetBackground( views::Background::CreateSolidBackground(kBackgroundColorMatch)); match_count_text_->SetColor(kTextColorMatchCount); } -void FindInPageView::UpdateMatchCount(int number_of_matches, - bool final_update) { +void FindBarView::UpdateMatchCount(int number_of_matches, + bool final_update) { if (number_of_matches < 0) // We ignore -1 sent during FindNext operations. return; @@ -208,12 +208,12 @@ void FindInPageView::UpdateMatchCount(int number_of_matches, } } -void FindInPageView::UpdateActiveMatchOrdinal(int ordinal) { +void FindBarView::UpdateActiveMatchOrdinal(int ordinal) { if (ordinal >= 0) active_match_ordinal_ = ordinal; } -void FindInPageView::UpdateResultLabel() { +void FindBarView::UpdateResultLabel() { std::wstring search_string = find_text_->GetText(); if (search_string.length() > 0) { @@ -232,15 +232,15 @@ void FindInPageView::UpdateResultLabel() { Layout(); // The match_count label may have increased/decreased in size. } -void FindInPageView::OnShow() { +void FindBarView::OnShow() { find_text_->RequestFocus(); find_text_->SelectAll(); } /////////////////////////////////////////////////////////////////////////////// -// FindInPageView, views::View overrides: +// FindBarView, views::View overrides: -void FindInPageView::Paint(ChromeCanvas* canvas) { +void FindBarView::Paint(ChromeCanvas* canvas) { SkPaint paint; // Get the local bounds so that we now how much to stretch the background. @@ -250,7 +250,7 @@ void FindInPageView::Paint(ChromeCanvas* canvas) { // middle and right). Note, that the window region has been set by the // controller, so the whitespace in the left and right background images is // actually outside the window region and is therefore not drawn. See - // FindInPageController::CreateRoundedWindowEdges() for details. + // FindInPageContainerWin::CreateRoundedWindowEdges() for details. const SkBitmap *bg_left = toolbar_blend_ ? kDlgBackground_left : kDlgBackground_bb_left; const SkBitmap *bg_middle = @@ -333,7 +333,7 @@ void FindInPageView::Paint(ChromeCanvas* canvas) { } } -void FindInPageView::Layout() { +void FindBarView::Layout() { gfx::Size panel_size = GetPreferredSize(); // First we draw the close button on the far right. @@ -398,16 +398,16 @@ void FindInPageView::Layout() { find_previous_button_->height()); } -void FindInPageView::ViewHierarchyChanged(bool is_add, - View *parent, - View *child) { +void FindBarView::ViewHierarchyChanged(bool is_add, + View *parent, + View *child) { if (is_add && child == this) { find_text_->SetHorizontalMargins(3, 3); // Left and Right margins. find_text_->RemoveBorder(); // We draw our own border (a background image). } } -gfx::Size FindInPageView::GetPreferredSize() { +gfx::Size FindBarView::GetPreferredSize() { gfx::Size prefsize = find_text_->GetPreferredSize(); prefsize.set_height(kDlgBackground_middle->height()); @@ -422,19 +422,19 @@ gfx::Size FindInPageView::GetPreferredSize() { } //////////////////////////////////////////////////////////////////////////////// -// FindInPageView, views::BaseButton::ButtonListener implementation: +// FindBarView, views::BaseButton::ButtonListener implementation: -void FindInPageView::ButtonPressed(views::BaseButton* sender) { +void FindBarView::ButtonPressed(views::BaseButton* sender) { switch (sender->GetTag()) { case FIND_PREVIOUS_TAG: case FIND_NEXT_TAG: if (find_text_->GetText().length() > 0) { - controller_->set_find_string(find_text_->GetText()); - controller_->StartFinding(sender->GetTag() == FIND_NEXT_TAG); + container_->set_find_string(find_text_->GetText()); + container_->StartFinding(sender->GetTag() == FIND_NEXT_TAG); } break; case CLOSE_TAG: - controller_->EndFindSession(); + container_->EndFindSession(); break; default: NOTREACHED() << L"Unknown button"; @@ -443,30 +443,29 @@ void FindInPageView::ButtonPressed(views::BaseButton* sender) { } //////////////////////////////////////////////////////////////////////////////// -// FindInPageView, views::TextField::Controller implementation: +// FindBarView, views::TextField::Controller implementation: -void FindInPageView::ContentsChanged(views::TextField* sender, - const std::wstring& new_contents) { +void FindBarView::ContentsChanged(views::TextField* sender, + const std::wstring& new_contents) { // When the user changes something in the text box we check the contents and // if the textbox contains something we set it as the new search string and // initiate search (even though old searches might be in progress). if (new_contents.length() > 0) { - controller_->set_find_string(new_contents); - controller_->StartFinding(true); + container_->set_find_string(new_contents); + container_->StartFinding(true); } else { // The textbox is empty so we reset. UpdateMatchCount(0, true); // true = final update. UpdateResultLabel(); - controller_->StopFinding(true); // true = clear selection on page. - controller_->set_find_string(std::wstring()); + container_->StopFinding(true); // true = clear selection on page. + container_->set_find_string(std::wstring()); } } -void FindInPageView::HandleKeystroke(views::TextField* sender, - UINT message, TCHAR key, UINT repeat_count, - UINT flags) { +void FindBarView::HandleKeystroke(views::TextField* sender, UINT message, + TCHAR key, UINT repeat_count, UINT flags) { // If the dialog is not visible, there is no reason to process keyboard input. - if (!controller_->IsVisible()) + if (!container_->IsVisible()) return; switch (key) { @@ -474,16 +473,16 @@ void FindInPageView::HandleKeystroke(views::TextField* sender, // Pressing Return/Enter starts the search (unless text box is empty). std::wstring find_string = find_text_->GetText(); if (find_string.length() > 0) { - controller_->set_find_string(find_string); + container_->set_find_string(find_string); // Search forwards for enter, backwards for shift-enter. - controller_->StartFinding(GetKeyState(VK_SHIFT) >= 0); + container_->StartFinding(GetKeyState(VK_SHIFT) >= 0); } break; } } } -bool FindInPageView::FocusForwarderView::OnMousePressed( +bool FindBarView::FocusForwarderView::OnMousePressed( const views::MouseEvent& event) { if (view_to_focus_on_mousedown_) { view_to_focus_on_mousedown_->ClearSelection(); diff --git a/chrome/browser/find_in_page_view.h b/chrome/browser/views/find_bar_view.h index a6c957f..146f96b 100644 --- a/chrome/browser/find_in_page_view.h +++ b/chrome/browser/views/find_bar_view.h @@ -2,14 +2,14 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CHROME_BROWSER_FIND_IN_PAGE_VIEW_H__ -#define CHROME_BROWSER_FIND_IN_PAGE_VIEW_H__ +#ifndef CHROME_BROWSER_VIEWS_FIND_BAR_VIEW_H_ +#define CHROME_BROWSER_VIEWS_FIND_BAR_VIEW_H_ #include "base/gfx/size.h" #include "chrome/views/button.h" #include "chrome/views/text_field.h" -class FindInPageController; +class FindBarWin; namespace views { class Label; @@ -21,12 +21,12 @@ class View; // // The FindInPageView is responsible for drawing the UI controls of the // FindInPage window, the find text box, the 'Find' button and the 'Close' -// button. It communicates the user search words to the FindInPageController. +// button. It communicates the user search words to the FindBarWin. // //////////////////////////////////////////////////////////////////////////////// -class FindInPageView : public views::View, - public views::BaseButton::ButtonListener, - public views::TextField::Controller { +class FindBarView : public views::View, + public views::BaseButton::ButtonListener, + public views::TextField::Controller { public: // A tag denoting which button the user pressed. enum ButtonTag { @@ -35,8 +35,8 @@ class FindInPageView : public views::View, CLOSE_TAG, // The Close button (the 'X'). }; - FindInPageView(FindInPageController* controller); - virtual ~FindInPageView(); + FindBarView(FindBarWin* container); + virtual ~FindBarView(); // Updates the UI to show how many matches were found on the page/frames. // This function does nothing if |number_of_matches| is below 0, which can @@ -96,17 +96,17 @@ class FindInPageView : public views::View, views::TextField* view_to_focus_on_mousedown) : view_to_focus_on_mousedown_(view_to_focus_on_mousedown) {} - private: + private: virtual bool OnMousePressed(const views::MouseEvent& event); views::TextField* view_to_focus_on_mousedown_; - DISALLOW_EVIL_CONSTRUCTORS(FocusForwarderView); + DISALLOW_COPY_AND_ASSIGN(FocusForwarderView); }; - // The controller that maintains the selected model, and performs actions - // such as handling selected items. - FindInPageController* controller_; + // Manages the OS-specific view for the find bar and acts as an intermediary + // between us and the WebContentsView. + FindBarWin* container_; // The controls in the window. views::TextField* find_text_; @@ -132,8 +132,7 @@ class FindInPageView : public views::View, // The ordinal of the currently active match. int active_match_ordinal_; - DISALLOW_EVIL_CONSTRUCTORS(FindInPageView); + DISALLOW_COPY_AND_ASSIGN(FindBarView); }; -#endif // CHROME_BROWSER_FIND_IN_PAGE_VIEW_H__ - +#endif // CHROME_BROWSER_VIEWS_FIND_BAR_VIEW_H_ diff --git a/chrome/browser/find_in_page_controller.cc b/chrome/browser/views/find_bar_win.cc index df3b92d..1633981 100644 --- a/chrome/browser/find_in_page_controller.cc +++ b/chrome/browser/views/find_bar_win.cc @@ -2,22 +2,24 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/browser/find_in_page_controller.h" +#include "chrome/browser/views/find_bar_win.h" #include "chrome/browser/browser.h" #include "chrome/browser/browser_process.h" -#include "chrome/browser/find_in_page_view.h" #include "chrome/browser/find_notification_details.h" -#include "chrome/browser/tab_contents.h" +#include "chrome/browser/render_view_host.h" #include "chrome/browser/view_ids.h" #include "chrome/browser/views/bookmark_bar_view.h" +#include "chrome/browser/views/find_bar_view.h" +#include "chrome/browser/web_contents.h" +#include "chrome/browser/web_contents_view.h" #include "chrome/views/container_win.h" #include "chrome/views/external_focus_tracker.h" #include "chrome/views/native_scroll_bar.h" #include "chrome/views/root_view.h" #include "chrome/views/view_storage.h" -int FindInPageController::request_id_counter_ = 0; +int FindBarWin::request_id_counter_ = 0; // The minimum space between the FindInPage window and the search result. static const int kMinFindWndDistanceFromSelection = 5; @@ -26,17 +28,16 @@ static const int kMinFindWndDistanceFromSelection = 5; static const int kWindowBorderWidth = 3; //////////////////////////////////////////////////////////////////////////////// -// FindInPageController, public: - -FindInPageController::FindInPageController(TabContents* parent_tab, - HWND parent_hwnd) - : parent_tab_(parent_tab), - current_request_id_(request_id_counter_++), - parent_hwnd_(parent_hwnd), - find_dialog_animation_offset_(0), - show_on_tab_selection_(false), - focus_manager_(NULL), - old_accel_target_for_esc_(NULL) { +// FindBarWin, public: + +FindBarWin::FindBarWin(WebContentsView* parent_tab, HWND parent_hwnd) + : parent_tab_(parent_tab), + current_request_id_(request_id_counter_++), + parent_hwnd_(parent_hwnd), + find_dialog_animation_offset_(0), + show_on_tab_selection_(false), + focus_manager_(NULL), + old_accel_target_for_esc_(NULL) { // Start listening to focus changes, so we can register and unregister our // own handler for Escape. SetFocusChangeListener(parent_hwnd); @@ -45,7 +46,7 @@ FindInPageController::FindInPageController(TabContents* parent_tab, // coincide with WebContents. ContainerWin::set_delete_on_destroy(false); - view_ = new FindInPageView(this); + view_ = new FindBarView(this); views::FocusManager* focus_manager; focus_manager = views::FocusManager::GetFocusManager(parent_hwnd_); @@ -53,8 +54,7 @@ FindInPageController::FindInPageController(TabContents* parent_tab, // Stores the currently focused view, and tracks focus changes so that we can // restore focus when the find box is closed. - focus_tracker_.reset(new views::ExternalFocusTracker(view_, - focus_manager)); + focus_tracker_.reset(new views::ExternalFocusTracker(view_, focus_manager)); // Figure out where to place the dialog, initialize and set the position. gfx::Rect find_dlg_rect = GetDialogPosition(gfx::Rect()); @@ -68,14 +68,14 @@ FindInPageController::FindInPageController(TabContents* parent_tab, animation_->Show(); } -FindInPageController::~FindInPageController() { +FindBarWin::~FindBarWin() { Close(); } // TODO(brettw) this should not be so complicated. The view should really be in // charge of these regions. CustomFrameWindow will do this for us. It will also // let us set a path for the window region which will avoid some logic here. -void FindInPageController::UpdateWindowEdges(const gfx::Rect& new_pos) { +void FindBarWin::UpdateWindowEdges(const gfx::Rect& new_pos) { int w = new_pos.width(); int h = new_pos.height(); @@ -178,7 +178,7 @@ void FindInPageController::UpdateWindowEdges(const gfx::Rect& new_pos) { SetWindowRgn(region, TRUE); // TRUE = Redraw. } -void FindInPageController::Show() { +void FindBarWin::Show() { // Note: This function is called when the user presses Ctrl+F or switches back // to the parent tab of the Find window (assuming the Find window has been // opened at least once). If the Find window is already visible, we should @@ -201,11 +201,11 @@ void FindInPageController::Show() { view_->OnShow(); } -bool FindInPageController::IsAnimating() { +bool FindBarWin::IsAnimating() { return animation_->IsAnimating(); } -void FindInPageController::EndFindSession() { +void FindBarWin::EndFindSession() { if (IsVisible()) { show_on_tab_selection_ = false; animation_->Hide(); @@ -227,7 +227,7 @@ void FindInPageController::EndFindSession() { } } -void FindInPageController::Close() { +void FindBarWin::Close() { // We may already have been destroyed if the selection resulted in a tab // switch which will have reactivated the browser window and closed us, so // we need to check to see if we're still a window before trying to destroy @@ -236,14 +236,14 @@ void FindInPageController::Close() { DestroyWindow(); } -void FindInPageController::DidBecomeSelected() { +void FindBarWin::DidBecomeSelected() { if (!IsVisible() && show_on_tab_selection_) { Show(); show_on_tab_selection_ = false; } } -void FindInPageController::DidBecomeUnselected() { +void FindBarWin::DidBecomeUnselected() { if (::IsWindow(GetHWND()) && IsVisible()) { // Finish any existing animations. if (animation_->IsAnimating()) { @@ -257,7 +257,7 @@ void FindInPageController::DidBecomeUnselected() { } } -void FindInPageController::StartFinding(bool forward_direction) { +void FindBarWin::StartFinding(bool forward_direction) { if (find_string_.empty()) return; @@ -267,19 +267,19 @@ void FindInPageController::StartFinding(bool forward_direction) { last_find_string_ = find_string_; - parent_tab_->StartFinding(current_request_id_, - find_string_, - forward_direction, - false, // case sensitive - find_next); + GetRenderViewHost()->StartFinding(current_request_id_, + find_string_, + forward_direction, + false, // case sensitive + find_next); } -void FindInPageController::StopFinding(bool clear_selection) { +void FindBarWin::StopFinding(bool clear_selection) { last_find_string_.clear(); - parent_tab_->StopFinding(clear_selection); + GetRenderViewHost()->StopFinding(clear_selection); } -void FindInPageController::MoveWindowIfNecessary( +void FindBarWin::MoveWindowIfNecessary( const gfx::Rect& selection_rect) { gfx::Rect new_pos = GetDialogPosition(selection_rect); SetDialogPosition(new_pos); @@ -289,7 +289,7 @@ void FindInPageController::MoveWindowIfNecessary( view_->SchedulePaint(); } -void FindInPageController::RespondToResize(const gfx::Size& new_size) { +void FindBarWin::RespondToResize(const gfx::Size& new_size) { if (!IsVisible()) return; @@ -305,7 +305,7 @@ void FindInPageController::RespondToResize(const gfx::Size& new_size) { SetDialogPosition(new_pos); } -void FindInPageController::SetParent(HWND new_parent) { +void FindBarWin::SetParent(HWND new_parent) { DCHECK(new_parent); if (parent_hwnd_ != new_parent) { // Sync up the focus listener with the new focus manager. @@ -326,9 +326,9 @@ void FindInPageController::SetParent(HWND new_parent) { } //////////////////////////////////////////////////////////////////////////////// -// FindInPageController, views::ContainerWin implementation: +// FindBarWin, views::ContainerWin implementation: -void FindInPageController::OnFinalMessage(HWND window) { +void FindBarWin::OnFinalMessage(HWND window) { // We are exiting, so we no longer need to monitor focus changes. focus_manager_->RemoveFocusChangeListener(this); @@ -340,10 +340,10 @@ void FindInPageController::OnFinalMessage(HWND window) { }; //////////////////////////////////////////////////////////////////////////////// -// FindInPageController, views::FocusChangeListener implementation: +// FindBarWin, views::FocusChangeListener implementation: -void FindInPageController::FocusWillChange(views::View* focused_before, - views::View* focused_now) { +void FindBarWin::FocusWillChange(views::View* focused_before, + views::View* focused_now) { // First we need to determine if one or both of the views passed in are child // views of our view. bool our_view_before = focused_before && view_->IsParentOf(focused_before); @@ -366,10 +366,9 @@ void FindInPageController::FocusWillChange(views::View* focused_before, } //////////////////////////////////////////////////////////////////////////////// -// FindInPageController, views::AcceleratorTarget implementation: +// FindBarWin, views::AcceleratorTarget implementation: -bool FindInPageController::AcceleratorPressed( - const views::Accelerator& accelerator) { +bool FindBarWin::AcceleratorPressed(const views::Accelerator& accelerator) { DCHECK(accelerator.GetKeyCode() == VK_ESCAPE); // We only expect Escape key. // This will end the Find session and hide the window, causing it to loose // focus and in the process unregister us as the handler for the Escape @@ -380,10 +379,9 @@ bool FindInPageController::AcceleratorPressed( } //////////////////////////////////////////////////////////////////////////////// -// FindInPageController, AnimationDelegate implementation: +// FindBarWin, AnimationDelegate implementation: -void FindInPageController::AnimationProgressed( - const Animation* animation) { +void FindBarWin::AnimationProgressed(const Animation* animation) { // First, we calculate how many pixels to slide the window. find_dialog_animation_offset_ = static_cast<int>((1.0 - animation_->GetCurrentValue()) * @@ -400,8 +398,7 @@ void FindInPageController::AnimationProgressed( view_->SchedulePaint(); } -void FindInPageController::AnimationEnded( - const Animation* animation) { +void FindBarWin::AnimationEnded(const Animation* animation) { if (!animation_->IsShowing()) { // Animation has finished closing. find_dialog_animation_offset_ = 0; @@ -411,11 +408,11 @@ void FindInPageController::AnimationEnded( } } -void FindInPageController::FindReply(int request_id, - int number_of_matches, - const gfx::Rect& selection_rect, - int active_match_ordinal, - bool final_update) { +void FindBarWin::OnFindReply(int request_id, + int number_of_matches, + const gfx::Rect& selection_rect, + int active_match_ordinal, + bool final_update) { // Ignore responses for requests other than the one we have most recently // issued. That way we won't act on stale results when the user has // already typed in another query. @@ -441,12 +438,17 @@ void FindInPageController::FindReply(int request_id, selection_rect, active_match_ordinal, final_update); - NotificationService::current()-> - Notify(NOTIFY_FIND_RESULT_AVAILABLE, Source<TabContents>(parent_tab_), - Details<FindNotificationDetails>(&detail)); + NotificationService::current()->Notify( + NOTIFY_FIND_RESULT_AVAILABLE, + Source<TabContents>(parent_tab_->GetWebContents()), + Details<FindNotificationDetails>(&detail)); } -void FindInPageController::GetDialogBounds(gfx::Rect* bounds) { +RenderViewHost* FindBarWin::GetRenderViewHost() const { + return parent_tab_->GetWebContents()->render_view_host(); +} + +void FindBarWin::GetDialogBounds(gfx::Rect* bounds) { DCHECK(bounds); // We need to find the View for the toolbar because we want to visually @@ -551,8 +553,7 @@ void FindInPageController::GetDialogBounds(gfx::Rect* bounds) { bounds->set_width(bounds->width() - (2 * width)); } -gfx::Rect FindInPageController::GetDialogPosition( - gfx::Rect avoid_overlapping_rect) { +gfx::Rect FindBarWin::GetDialogPosition(gfx::Rect avoid_overlapping_rect) { // Find the area we have to work with (after accounting for scrollbars, etc). gfx::Rect dialog_bounds; GetDialogBounds(&dialog_bounds); @@ -625,7 +626,7 @@ gfx::Rect FindInPageController::GetDialogPosition( return new_pos; } -void FindInPageController::SetDialogPosition(const gfx::Rect& new_pos) { +void FindBarWin::SetDialogPosition(const gfx::Rect& new_pos) { if (new_pos.IsEmpty()) return; @@ -641,7 +642,7 @@ void FindInPageController::SetDialogPosition(const gfx::Rect& new_pos) { curr_pos_relative_ = new_pos; } -void FindInPageController::SetFocusChangeListener(HWND parent_hwnd) { +void FindBarWin::SetFocusChangeListener(HWND parent_hwnd) { // When tabs get torn off the tab-strip they get a new window with a new // FocusManager, which means we need to clean up old listener and start a new // one with the new FocusManager. @@ -657,14 +658,16 @@ void FindInPageController::SetFocusChangeListener(HWND parent_hwnd) { focus_manager_->AddFocusChangeListener(this); } -void FindInPageController::RestoreSavedFocus() { - if (focus_tracker_.get() == NULL) - parent_tab_->Focus(); - else +void FindBarWin::RestoreSavedFocus() { + if (focus_tracker_.get() == NULL) { + // TODO(brettw) Focus() should be on WebContentsView. + parent_tab_->GetWebContents()->Focus(); + } else { focus_tracker_->FocusLastFocusedExternalView(); + } } -void FindInPageController::RegisterEscAccelerator() { +void FindBarWin::RegisterEscAccelerator() { views::Accelerator escape(VK_ESCAPE, false, false, false); // TODO(finnur): Once we fix issue 1307173 we should not remember any old @@ -676,7 +679,7 @@ void FindInPageController::RegisterEscAccelerator() { old_accel_target_for_esc_ = old_target; } -void FindInPageController::UnregisterEscAccelerator() { +void FindBarWin::UnregisterEscAccelerator() { // TODO(finnur): Once we fix issue 1307173 we should not remember any old // accelerator targets and just Register and Unregister when needed. DCHECK(old_accel_target_for_esc_ != NULL); diff --git a/chrome/browser/find_in_page_controller.h b/chrome/browser/views/find_bar_win.h index 02399f9..bd3b06c 100644 --- a/chrome/browser/find_in_page_controller.h +++ b/chrome/browser/views/find_bar_win.h @@ -2,17 +2,18 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CHROME_BROWSER_FIND_IN_PAGE_CONTROLLER_H_ -#define CHROME_BROWSER_FIND_IN_PAGE_CONTROLLER_H_ +#ifndef CHROME_BROWSER_VIEWS_FIND_BAR_WIN_H_ +#define CHROME_BROWSER_VIEWS_FIND_BAR_WIN_H_ #include "base/gfx/rect.h" #include "chrome/browser/render_view_host_delegate.h" #include "chrome/common/animation.h" #include "chrome/views/container_win.h" -class FindInPageView; +class FindBarView; +class RenderViewHost; class SlideAnimation; -class TabContents; +class WebContentsView; namespace views { class ExternalFocusTracker; @@ -21,41 +22,38 @@ class View; //////////////////////////////////////////////////////////////////////////////// // -// The FindInPageController implements the container window for the FindInPage -// functionality. It uses the FindInPageView implementation to draw its content -// and is responsible for showing, hiding, closing, and moving the window if -// needed, for example if the window is obscuring the selection results. It also +// The FindBarWin implements the container window for the Windows find-in-page +// functionality. It uses the FindBarWin implementation to draw its content and +// is responsible for showing, hiding, closing, and moving the window if needed, +// for example if the window is obscuring the selection results. It also // communicates with the parent_tab to instruct it to start searching for what // the user selected and receives notifications about the search results and // communicates that to the view. // -// We create one controller per tab and remember each search query per tab. +// We create one container per tab and remember each search query per tab. // //////////////////////////////////////////////////////////////////////////////// -class FindInPageController : public RenderViewHostDelegate::FindInPage, - public views::FocusChangeListener, - public views::ContainerWin, - public AnimationDelegate { +class FindBarWin : public views::FocusChangeListener, + public views::ContainerWin, + public AnimationDelegate { public: - FindInPageController(TabContents* parent_tab, - HWND parent_hwnd); - virtual ~FindInPageController(); + FindBarWin(WebContentsView* parent_tab, HWND parent_hwnd); + virtual ~FindBarWin(); - // Shows the FindInPage window. The previous search string will again be - // visible. + // Shows the find bar. Any previous search string will again be visible. void Show(); - // Ends the current FindInPage session. + // Ends the current session. void EndFindSession(); - // Closes the FindInPage window (calls Close on the Window Container). + // Closes the find bar window (calls Close on the Window Container). void Close(); // This is triggered when the parent tab of the Find dialog becomes - // unselected, at which point the FindInPage dialog should become hidden. - // Otherwise, we leave artifacts on the chrome when other tabs are visible. - // However, we need to show the Find dialog again when the parent tab becomes - // selected again, so we set a flag for that and show the window if we get a + // unselected, at which point the find bar should become hidden. Otherwise, + // we leave artifacts on the chrome when other tabs are visible. However, we + // need to show the Find dialog again when the parent tab becomes selected + // again, so we set a flag for that and show the window if we get a // DidBecomeSelected call. void DidBecomeUnselected(); @@ -75,10 +73,10 @@ class FindInPageController : public RenderViewHostDelegate::FindInPage, // also clear the selection on the focused frame. void StopFinding(bool clear_selection); - // If the FindInPage window obscures the search results we need to move the - // window. To do that we need to know what is selected on the page. We simply - // calculate where it would be if we place it on the left of the selection and - // if it doesn't fit on the screen we try the right side. The parameter + // If the find bar obscures the search results we need to move the window. To + // do that we need to know what is selected on the page. We simply calculate + // where it would be if we place it on the left of the selection and if it + // doesn't fit on the screen we try the right side. The parameter // |selection_rect| is expected to have coordinates relative to the top of // the web page area. void MoveWindowIfNecessary(const gfx::Rect& selection_rect); @@ -89,9 +87,9 @@ class FindInPageController : public RenderViewHostDelegate::FindInPage, // Whether we are animating the position of the Find window. bool IsAnimating(); - // Changes the parent window for the FindInPage controller. If |new_parent| is - // already the parent of this window then no action is taken. |new_parent| can - // not be NULL. + // Changes the parent window for the find bar. If |new_parent| is already + // the parent of this window then no action is taken. + // |new_parent| can not be NULL. void SetParent(HWND new_parent); // We need to monitor focus changes so that we can register a handler for @@ -107,6 +105,14 @@ class FindInPageController : public RenderViewHostDelegate::FindInPage, find_string_ = find_string; } + // Updates the find bar with the latest results. This is called when the + // renderer (through the RenderViewHostDelegate::View) finds more stuff. + void OnFindReply(int request_id, + int number_of_matches, + const gfx::Rect& selection_rect, + int active_match_ordinal, + bool final_update); + // Overridden from views::ContainerWin: virtual void OnFinalMessage(HWND window); @@ -122,28 +128,24 @@ class FindInPageController : public RenderViewHostDelegate::FindInPage, virtual void AnimationEnded(const Animation* animation); private: - // RenderViewHostDelegate::FindInPage implementation. - virtual void FindReply(int request_id, - int number_of_matches, - const gfx::Rect& selection_rect, - int active_match_ordinal, - bool final_update); - - // Retrieves the boundaries that the FindInPage dialog has to work with within - // the Chrome frame window. The resulting rectangle will be a rectangle that + // Returns the RenderViewHost associated with the current tab. + RenderViewHost* GetRenderViewHost() const; + + // Retrieves the boundaries that the find bar has to work with within the + // Chrome frame window. The resulting rectangle will be a rectangle that // overlaps the bottom of the Chrome toolbar by one pixel (so we can create - // the illusion that the FindInPage window is part of the toolbar) and covers - // the page area, except that we deflate the rect width by subtracting (from - // both sides) the width of the toolbar and some extra pixels to account for - // the width of the Chrome window borders. |bounds| is relative to the browser + // the illusion that the find bar is part of the toolbar) and covers the page + // area, except that we deflate the rect width by subtracting (from both + // sides) the width of the toolbar and some extra pixels to account for the + // width of the Chrome window borders. |bounds| is relative to the browser // window. If the function fails to determine the browser window/client area // rectangle or the rectangle for the page area then |bounds| will // be an empty rectangle. void GetDialogBounds(gfx::Rect* bounds); - // Returns the rectangle representing where to position the FindInPage dialog. - // It uses GetDialogBounds and positions itself within that, either to the - // left (if an InfoBar is present) or to the right (no InfoBar). If + // Returns the rectangle representing where to position the find bar. It uses + // GetDialogBounds and positions itself within that, either to the left (if an + // InfoBar is present) or to the right (no InfoBar). If // |avoid_overlapping_rect| is specified, the return value will be a rectangle // located immediately to the left of |avoid_overlapping_rect|, as long as // there is enough room for the dialog to draw within the bounds. If not, the @@ -169,7 +171,7 @@ class FindInPageController : public RenderViewHostDelegate::FindInPage, void UpdateWindowEdges(const gfx::Rect& new_pos); // Upon dismissing the window, restore focus to the last focused view which is - // not FindInPageView or any of its children. + // not FindBarView or any of its children. void RestoreSavedFocus(); // Registers this class as the handler for when Escape is pressed. We will @@ -181,13 +183,13 @@ class FindInPageController : public RenderViewHostDelegate::FindInPage, void UnregisterEscAccelerator(); // The tab we are associated with. - TabContents* parent_tab_; + WebContentsView* parent_tab_; // The window handle of our parent window (the main Chrome window). HWND parent_hwnd_; // Our view, which is responsible for drawing the UI. - FindInPageView* view_; + FindBarView* view_; // Each time a search request comes in we assign it an id before passing it // over the IPC so that when the results come in we can evaluate whether we @@ -227,13 +229,12 @@ class FindInPageController : public RenderViewHostDelegate::FindInPage, // restore the state once we loose focus. views::AcceleratorTarget* old_accel_target_for_esc_; - // Tracks and stores the last focused view which is not the FindInPageView or - // any of its children. Used to restore focus once the FindInPageView is + // Tracks and stores the last focused view which is not the FindBarView + // or any of its children. Used to restore focus once the FindBarView is // closed. scoped_ptr<views::ExternalFocusTracker> focus_tracker_; - DISALLOW_COPY_AND_ASSIGN(FindInPageController); + DISALLOW_COPY_AND_ASSIGN(FindBarWin); }; -#endif // CHROME_BROWSER_FIND_IN_PAGE_CONTROLLER_H_ - +#endif // CHROME_BROWSER_VIEWS_FIND_BAR_WIN_H_ diff --git a/chrome/browser/find_in_page_controller_interactive_uitest.cc b/chrome/browser/views/find_bar_win_interactive_uitest.cc index 383a64a..383a64a 100644 --- a/chrome/browser/find_in_page_controller_interactive_uitest.cc +++ b/chrome/browser/views/find_bar_win_interactive_uitest.cc diff --git a/chrome/browser/find_in_page_controller_uitest.cc b/chrome/browser/views/find_bar_win_uitest.cc index af2ff6d..d1e036d2 100644 --- a/chrome/browser/find_in_page_controller_uitest.cc +++ b/chrome/browser/views/find_bar_win_uitest.cc @@ -3,7 +3,7 @@ // found in the LICENSE file. #include "chrome/app/chrome_dll_resource.h" -#include "chrome/browser/find_in_page_controller.h" +#include "chrome/browser/find_bar_win.h" #include "chrome/test/automation/browser_proxy.h" #include "chrome/test/automation/tab_proxy.h" #include "chrome/test/automation/window_proxy.h" diff --git a/chrome/browser/views/tab_contents_container_view.cc b/chrome/browser/views/tab_contents_container_view.cc index 7a506fc..c0c013b6 100644 --- a/chrome/browser/views/tab_contents_container_view.cc +++ b/chrome/browser/views/tab_contents_container_view.cc @@ -31,14 +31,21 @@ TabContentsContainerView::~TabContentsContainerView() { void TabContentsContainerView::SetTabContents(TabContents* tab_contents) { if (tab_contents_) { - // TODO(beng): (Cleanup) We want to call the _base_ class' version here. - // WebContents' WM_WINDOWPOSCHANGED handler will ensure its - // version is called. The correct thing to do here is to - // rationalize all TabContents Hide/Show/Size etc into a single - // API, but that's too complex for this first phase. - tab_contents_->TabContents::HideContents(); + // TODO(brettw) should this move to HWNDView::Detach which is called below? + // It needs cleanup regardless. + HWND container_hwnd = tab_contents_->GetContainerHWND(); + + // Hide the contents before adjusting its parent to avoid a full desktop + // flicker. + ::ShowWindow(container_hwnd, SW_HIDE); + + // Reset the parent to NULL to ensure hidden tabs don't receive messages. + ::SetParent(container_hwnd, NULL); + + tab_contents_->WasHidden(); // Unregister the tab contents window from the FocusManager. + views::FocusManager::UninstallFocusSubclass(container_hwnd); HWND hwnd = tab_contents_->GetContentHWND(); if (hwnd) { // We may not have an HWND anymore, if the renderer crashed and we are diff --git a/chrome/browser/web_contents.cc b/chrome/browser/web_contents.cc index 4ad5494..c0a048d 100644 --- a/chrome/browser/web_contents.cc +++ b/chrome/browser/web_contents.cc @@ -15,7 +15,6 @@ #include "chrome/browser/dom_operation_notification_details.h" #include "chrome/browser/download/download_manager.h" #include "chrome/browser/download/download_request_manager.h" -#include "chrome/browser/find_in_page_controller.h" #include "chrome/browser/find_notification_details.h" #include "chrome/browser/google_util.h" #include "chrome/browser/interstitial_page.h" @@ -300,13 +299,8 @@ void WebContents::Destroy() { cancelable_consumer_.CancelAllRequests(); - // Close the Find in page dialog. - if (find_in_page_controller_.get()) - find_in_page_controller_->Close(); - - // Detach plugin windows so that they are not destroyed automatically. - // They will be cleaned up properly in plugin process. - view_->DetachPluginWindows(); + // Clean up subwindows like plugins and the find in page bar. + view_->OnContentsDestroy(); NotifyDisconnected(); HungRendererWarning::HideForWebContents(this); @@ -388,19 +382,6 @@ void WebContents::Stop() { printing_.Stop(); } -void WebContents::StartFinding(int request_id, - const std::wstring& search_string, - bool forward, - bool match_case, - bool find_next) { - render_view_host()->StartFinding(request_id, search_string, forward, - match_case, find_next); -} - -void WebContents::StopFinding(bool clear_selection) { - render_view_host()->StopFinding(clear_selection); -} - void WebContents::Cut() { render_view_host()->Cut(); } @@ -444,10 +425,6 @@ void WebContents::WasHidden() { } } - // If we have a FindInPage dialog, notify it that its tab was hidden. - if (find_in_page_controller_.get()) - find_in_page_controller_->DidBecomeUnselected(); - TabContents::WasHidden(); } @@ -461,10 +438,6 @@ void WebContents::ShowContents() { ConstrainedWindow* window = child_windows_.at(i); window->DidBecomeSelected(); } - - // If we have a FindInPage dialog, notify it that its tab was selected. - if (find_in_page_controller_.get()) - find_in_page_controller_->DidBecomeSelected(); } void WebContents::HideContents() { @@ -477,14 +450,6 @@ void WebContents::HideContents() { WasHidden(); } -void WebContents::SizeContents(const gfx::Size& size) { - if (render_widget_host_view()) - render_widget_host_view()->SetSize(size); - if (find_in_page_controller_.get()) - find_in_page_controller_->RespondToResize(size); - RepositionSupressedPopupsToFit(size); -} - void WebContents::SetDownloadShelfVisible(bool visible) { TabContents::SetDownloadShelfVisible(visible); if (visible) { @@ -509,68 +474,6 @@ void WebContents::GetContainerBounds(gfx::Rect *out) const { view_->GetContainerBounds(out); } -void WebContents::OpenFindInPageWindow(const Browser& browser) { - if (!find_in_page_controller_.get()) { - // Get the Chrome top-level (Frame) window. - HWND hwnd = browser.GetTopLevelHWND(); - find_in_page_controller_.reset(new FindInPageController(this, hwnd)); - } else { - find_in_page_controller_->Show(); - } -} - -void WebContents::ReparentFindWindow(HWND new_parent) { - DCHECK(new_parent); - if (find_in_page_controller_.get()) { - find_in_page_controller_->SetParent(new_parent); - } -} - -bool WebContents::AdvanceFindSelection(bool forward_direction) { - // If no controller has been created or it doesn't know what to search for - // then just return false so that caller knows that it should create and - // show the window. - if (!find_in_page_controller_.get() || - find_in_page_controller_->find_string().empty()) - return false; - - // The dialog already exists, so show if hidden. - if (!find_in_page_controller_->IsVisible()) - find_in_page_controller_->Show(); - - find_in_page_controller_->StartFinding(forward_direction); - return true; -} - -bool WebContents::IsFindWindowFullyVisible() { - return find_in_page_controller_->IsVisible() && - !find_in_page_controller_->IsAnimating(); -} - -bool WebContents::GetFindInPageWindowLocation(int* x, int* y) { - DCHECK(x && y); - HWND find_wnd = find_in_page_controller_->GetHWND(); - CRect window_rect; - if (IsFindWindowFullyVisible() && - ::IsWindow(find_wnd) && - ::GetWindowRect(find_wnd, &window_rect)) { - *x = window_rect.TopLeft().x; - *y = window_rect.TopLeft().y; - return true; - } - - return false; -} - -void WebContents::SetFindInPageVisible(bool visible) { - if (find_in_page_controller_.get()) { - if (visible) - find_in_page_controller_->Show(); - else - find_in_page_controller_->EndFindSession(); - } -} - void WebContents::SetWebApp(WebApp* web_app) { if (web_app_.get()) { web_app_->RemoveObserver(this); @@ -660,9 +563,8 @@ void WebContents::PrintPreview() { if (render_manager_.showing_interstitial_page()) return; - // If we have a FindInPage dialog, notify it that its tab was hidden. - if (find_in_page_controller_.get()) - find_in_page_controller_->DidBecomeUnselected(); + // If we have a find bar it needs to hide as well. + view_->HideFindBar(false); // We don't show the print preview for the beta, only the print dialog. printing_.ShowPrintDialog(); @@ -673,9 +575,8 @@ bool WebContents::PrintNow() { if (render_manager_.showing_interstitial_page()) return false; - // If we have a FindInPage dialog, notify it that its tab was hidden. - if (find_in_page_controller_.get()) - find_in_page_controller_->DidBecomeUnselected(); + // If we have a find bar it needs to hide as well. + view_->HideFindBar(false); return printing_.PrintNow(); } @@ -708,12 +609,6 @@ RenderViewHostDelegate::View* WebContents::GetViewDelegate() const { return view_.get(); } -RenderViewHostDelegate::FindInPage* WebContents::GetFindInPageDelegate() const { - // The find in page controller implements this interface for us. Our return - // value can be NULL, so it's fine if the find in controller doesn't exist. - return find_in_page_controller_.get(); -} - RenderViewHostDelegate::Save* WebContents::GetSaveDelegate() const { return save_package_.get(); // May be NULL, but we can return NULL. } @@ -1436,8 +1331,8 @@ void WebContents::BeforeUnloadFiredFromRenderManager( } void WebContents::UpdateRenderViewSizeForRenderManager() { - // Using same technique as OnPaint, which sets size of SadTab. - SizeContents(view_->GetContainerSize()); + // TODO(brettw) this is a hack. See WebContentsView::SizeContents. + view_->SizeContents(view_->GetContainerSize()); } bool WebContents::CreateRenderViewForRenderManager( @@ -1548,13 +1443,13 @@ void WebContents::DidNavigateMainFramePostCommit( fav_icon_helper_.FetchFavIcon(details.entry->url()); // Close constrained popups if necessary. - MaybeCloseChildWindows(params); + MaybeCloseChildWindows(details.previous_url, details.entry->url()); // We hide the FindInPage window when the user navigates away, except on // reload. if (PageTransition::StripQualifier(params.transition) != PageTransition::RELOAD) - SetFindInPageVisible(false); + view_->HideFindBar(true); // Update the starred state. UpdateStarredStateForCurrentURL(); @@ -1586,12 +1481,11 @@ void WebContents::DidNavigateAnyFramePostCommit( GetPasswordManager()->ProvisionallySavePassword(params.password_form); } -void WebContents::MaybeCloseChildWindows( - const ViewHostMsg_FrameNavigate_Params& params) { +void WebContents::MaybeCloseChildWindows(const GURL& previous_url, + const GURL& current_url) { if (net::RegistryControlledDomainService::SameDomainOrHost( - last_url_, params.url)) + previous_url, current_url)) return; - last_url_ = params.url; // Clear out any child windows since we are leaving this page entirely. // We use indices instead of iterators in case CloseWindow does something diff --git a/chrome/browser/web_contents.h b/chrome/browser/web_contents.h index 7a6de26..b42c4ec 100644 --- a/chrome/browser/web_contents.h +++ b/chrome/browser/web_contents.h @@ -15,7 +15,6 @@ #include "chrome/browser/tab_contents.h" #include "chrome/browser/web_app.h" -class FindInPageController; class InterstitialPageDelegate; class PasswordManager; class PluginInstaller; @@ -82,12 +81,6 @@ class WebContents : public TabContents, virtual std::wstring GetStatusText() const; virtual bool NavigateToPendingEntry(bool reload); virtual void Stop(); - virtual void StartFinding(int request_id, - const std::wstring& search_string, - bool forward, - bool match_case, - bool find_next); - virtual void StopFinding(bool clear_selection); virtual void Cut(); virtual void Copy(); virtual void Paste(); @@ -96,7 +89,6 @@ class WebContents : public TabContents, virtual void WasHidden(); virtual void ShowContents(); virtual void HideContents(); - virtual void SizeContents(const gfx::Size& size); virtual void SetDownloadShelfVisible(bool visible); // Retarded pass-throughs to the view. @@ -107,16 +99,6 @@ class WebContents : public TabContents, virtual HWND GetContentHWND(); virtual void GetContainerBounds(gfx::Rect *out) const; - // Find in page -------------------------------------------------------------- - - // TODO(brettw) these should be commented. - void OpenFindInPageWindow(const Browser& browser); - void ReparentFindWindow(HWND new_parent); - bool AdvanceFindSelection(bool forward_direction); - bool IsFindWindowFullyVisible(); - bool GetFindInPageWindowLocation(int* x, int* y); - void SetFindInPageVisible(bool visible); - // Web apps ------------------------------------------------------------------ // Sets the WebApp for this WebContents. @@ -222,7 +204,6 @@ class WebContents : public TabContents, // RenderViewHostDelegate ---------------------------------------------------- virtual RenderViewHostDelegate::View* GetViewDelegate() const; - virtual RenderViewHostDelegate::FindInPage* GetFindInPageDelegate() const; virtual RenderViewHostDelegate::Save* GetSaveDelegate() const; virtual Profile* GetProfile() const; virtual void RendererReady(RenderViewHost* render_view_host); @@ -403,9 +384,11 @@ class WebContents : public TabContents, const NavigationController::LoadCommittedDetails& details, const ViewHostMsg_FrameNavigate_Params& params); - // Called when navigating the main frame to close all child windows if the - // domain is changing. - void MaybeCloseChildWindows(const ViewHostMsg_FrameNavigate_Params& params); + // Closes all child windows (constrained popups) when the domain changes. + // Supply the new and old URLs, and this function will figure out when the + // domain changing conditions are met. + void MaybeCloseChildWindows(const GURL& previous_url, + const GURL& current_url); // Updates the starred state from the bookmark bar model. If the state has // changed, the delegate is notified. @@ -486,10 +469,6 @@ class WebContents : public TabContents, // once. bool notify_disconnection_; - // When a navigation occurs (and is committed), we record its URL. This lets - // us see where we are navigating from. - GURL last_url_; - // Maps from handle to page_id. typedef std::map<HistoryService::Handle, int32> HistoryRequestMap; HistoryRequestMap history_requests_; @@ -506,9 +485,6 @@ class WebContents : public TabContents, // SavePackage, lazily created. scoped_refptr<SavePackage> save_package_; - // Handles communication with the FindInPage popup. - scoped_ptr<FindInPageController> find_in_page_controller_; - // Tracks our pending CancelableRequests. This maps pending requests to // page IDs so that we know whether a given callback still applies. The // page ID -1 means no page ID was set. diff --git a/chrome/browser/web_contents_view.h b/chrome/browser/web_contents_view.h index d358184..6ebf84c 100644 --- a/chrome/browser/web_contents_view.h +++ b/chrome/browser/web_contents_view.h @@ -15,6 +15,7 @@ #include "base/gfx/size.h" #include "chrome/browser/render_view_host_delegate.h" +class Browser; class InfoBarView; class RenderViewHost; class RenderWidgetHost; @@ -35,6 +36,8 @@ class WebContentsView : public RenderViewHostDelegate::View { public: virtual ~WebContentsView() {} + virtual WebContents* GetWebContents() = 0; + virtual void CreateView(HWND parent_hwnd, const gfx::Rect& initial_bounds) = 0; @@ -67,8 +70,13 @@ class WebContentsView : public RenderViewHostDelegate::View { return gfx::Size(rc.width(), rc.height()); } - // Enumerate and 'un-parent' any plugin windows that are children of us. - virtual void DetachPluginWindows() = 0; + // Called when the WebContents is being destroyed. This should clean up child + // windows that are part of the view. + // + // TODO(brettw) It seems like this might be able to be done internally as the + // window is being torn down without input from the WebContents. Try to + // implement functions that way rather than adding stuff here. + virtual void OnContentsDestroy() = 0; // Displays the given error in the info bar. A new info bar will be shown if // one is not shown already. The new error text will replace any existing @@ -101,6 +109,55 @@ class WebContentsView : public RenderViewHostDelegate::View { // renderer crashing. virtual void Invalidate() = 0; + // TODO(brettw) this is a hack. It's used in two places at the time of this + // writing: (1) when render view hosts switch, we need to size the replaced + // one to be correct, since it wouldn't have known about sizes that happened + // while it was hidden; (2) in constrained windows. + // + // (1) will be fixed once interstitials are cleaned up. (2) seems like it + // should be cleaned up or done some other way, since this works for normal + // TabContents without the special code. + virtual void SizeContents(const gfx::Size& size) = 0; + + // Find in page -------------------------------------------------------------- + + // Opens the find in page window if it isn't already open. It will advance to + // the next match if |find_next| is set and there is a search string, + // otherwise, the find window will merely be opened. |forward_direction| + // indicates the direction to search when find_next is set, otherwise it is + // ignored. + virtual void FindInPage(const Browser& browser, + bool find_next, bool forward_direction) = 0; + + // Hides the find bar if there is one shown. Does nothing otherwise. The find + // bar will not be deleted, merely hidden. This ensures that any search terms + // are preserved if the user subsequently opens the find bar. + // + // If |end_session| is true, then the find session will be ended, which + // indicates the user requested they no longer be in find mode for that tab. + // The find bar will not be restored when we switch back to the tab. + // Otherwise, we assume that the find bar is being hidden because the tab is + // being hidden, and all state like visibility and tickmarks will be restored + // when the tab comes back. + virtual void HideFindBar(bool end_session) = 0; + + // Called when the tab is reparented to a new browser window. On MS Windows, + // we have to change the parent of our find bar to go with the new window. + // + // TODO(brettw) this seems like it could be improved. Possibly all doohickies + // around the tab like this, the download bar etc. should be managed by the + // BrowserView2 object. + virtual void ReparentFindWindow(Browser* new_browser) const = 0; + + // Computes the location of the find bar and whether it is fully visible in + // its parent window. The return value indicates if the window is visible at + // all. Both out arguments are required. + // + // This is used for UI tests of the find bar. If the find bar is not currently + // shown (return value of false), the out params will be {(0, 0), false}. + virtual bool GetFindBarWindowInfo(gfx::Point* position, + bool* fully_visible) const = 0; + protected: WebContentsView() {} // Abstract interface. diff --git a/chrome/browser/web_contents_view_win.cc b/chrome/browser/web_contents_view_win.cc index a7f4365..9d2561b 100644 --- a/chrome/browser/web_contents_view_win.cc +++ b/chrome/browser/web_contents_view_win.cc @@ -6,14 +6,15 @@ #include <windows.h> +#include "chrome/browser/browser.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/download/download_request_manager.h" -#include "chrome/browser/find_in_page_controller.h" #include "chrome/browser/render_view_context_menu.h" #include "chrome/browser/render_view_context_menu_controller.h" #include "chrome/browser/render_view_host.h" #include "chrome/browser/render_widget_host_view_win.h" #include "chrome/browser/tab_contents_delegate.h" +#include "chrome/browser/views/find_bar_win.h" #include "chrome/browser/views/info_bar_message_view.h" #include "chrome/browser/views/info_bar_view.h" #include "chrome/browser/views/sad_tab_view.h" @@ -26,7 +27,7 @@ namespace { -// Windows callback for DetachPluginWindows. +// Windows callback for OnDestroy to detach the plugin windows. BOOL CALLBACK EnumPluginWindowsCallback(HWND window, LPARAM param) { if (WebPluginDelegateImpl::IsPluginDelegateWindow(window)) { ::ShowWindow(window, SW_HIDE); @@ -46,6 +47,10 @@ WebContentsViewWin::WebContentsViewWin(WebContents* web_contents) WebContentsViewWin::~WebContentsViewWin() { } +WebContents* WebContentsViewWin::GetWebContents() { + return web_contents_; +} + void WebContentsViewWin::CreateView(HWND parent_hwnd, const gfx::Rect& initial_bounds) { set_delete_on_destroy(false); @@ -117,8 +122,19 @@ void WebContentsViewWin::StartDragging(const WebDropData& drop_data) { web_contents_->render_view_host()->DragSourceSystemDragEnded(); } -void WebContentsViewWin::DetachPluginWindows() { +void WebContentsViewWin::OnContentsDestroy() { + // TODO(brettw) this seems like maybe it can be moved into OnDestroy and this + // function can be deleted? If you're adding more here, consider whether it + // can be moved into OnDestroy which is a Windows message handler as the + // window is being torn down. + + // First detach all plugin windows so that they are not destroyed + // automatically. They will be cleaned up properly in plugin process. EnumChildWindows(GetHWND(), EnumPluginWindowsCallback, NULL); + + // Close the find bar if any. + if (find_bar_.get()) + find_bar_->Close(); } void WebContentsViewWin::DisplayErrorInInfoBar(const std::wstring& text) { @@ -181,6 +197,55 @@ void WebContentsViewWin::Invalidate() { InvalidateRect(GetContainerHWND(), NULL, FALSE); } +void WebContentsViewWin::SizeContents(const gfx::Size& size) { + // TODO(brettw) this is a hack and should be removed. See web_contents_view.h. + WasSized(size); +} + +void WebContentsViewWin::FindInPage(const Browser& browser, + bool find_next, bool forward_direction) { + if (!find_bar_.get()) { + // We want the Chrome top-level (Frame) window. + HWND hwnd = browser.GetTopLevelHWND(); + find_bar_.reset(new FindBarWin(this, hwnd)); + } else if (!find_bar_->IsVisible()) { + find_bar_->Show(); + } + + if (find_next && !find_bar_->find_string().empty()) + find_bar_->StartFinding(forward_direction); +} + +void WebContentsViewWin::HideFindBar(bool end_session) { + if (find_bar_.get()) { + if (end_session) + find_bar_->EndFindSession(); + else + find_bar_->DidBecomeUnselected(); + } +} + +void WebContentsViewWin::ReparentFindWindow(Browser* new_browser) const { + if (find_bar_.get()) + find_bar_->SetParent(new_browser->GetTopLevelHWND()); +} + +bool WebContentsViewWin::GetFindBarWindowInfo(gfx::Point* position, + bool* fully_visible) const { + CRect window_rect; + if (!find_bar_.get() || + !::IsWindow(find_bar_->GetHWND()) || + !::GetWindowRect(find_bar_->GetHWND(), &window_rect)) { + *position = gfx::Point(0, 0); + *fully_visible = false; + return false; + } + + *position = gfx::Point(window_rect.TopLeft().x, window_rect.TopLeft().y); + *fully_visible = find_bar_->IsVisible() && !find_bar_->IsAnimating(); + return true; +} + void WebContentsViewWin::UpdateDragCursor(bool is_drop_target) { drop_target_->set_is_drop_target(is_drop_target); } @@ -224,6 +289,17 @@ void WebContentsViewWin::HandleKeyboardEvent(const WebKeyboardEvent& event) { event.actual_message.lParam); } +void WebContentsViewWin::OnFindReply(int request_id, + int number_of_matches, + const gfx::Rect& selection_rect, + int active_match_ordinal, + bool final_update) { + if (find_bar_.get()) { + find_bar_->OnFindReply(request_id, number_of_matches, selection_rect, + active_match_ordinal, final_update); + } +} + void WebContentsViewWin::ShowContextMenu( const ViewHostMsg_ContextMenu_Params& params) { RenderViewContextMenuController menu_controller(web_contents_, params); @@ -445,27 +521,23 @@ void WebContentsViewWin::OnVScroll(int scroll_type, short position, void WebContentsViewWin::OnWindowPosChanged(WINDOWPOS* window_pos) { if (window_pos->flags & SWP_HIDEWINDOW) { - web_contents_->HideContents(); + WasHidden(); } else { // The WebContents was shown by a means other than the user selecting a // Tab, e.g. the window was minimized then restored. if (window_pos->flags & SWP_SHOWWINDOW) - web_contents_->ShowContents(); + WasShown(); + // Unless we were specifically told not to size, cause the renderer to be // sized to the new bounds, which forces a repaint. Not required for the // simple minimize-restore case described above, for example, since the // size hasn't changed. - if (!(window_pos->flags & SWP_NOSIZE)) { - gfx::Size size(window_pos->cx, window_pos->cy); - web_contents_->SizeContents(size); // FIXME(brettw) should this be on this class? - } + if (!(window_pos->flags & SWP_NOSIZE)) + WasSized(gfx::Size(window_pos->cx, window_pos->cy)); // If we have a FindInPage dialog, notify it that the window changed. - if (web_contents_->find_in_page_controller_.get() && - web_contents_->find_in_page_controller_->IsVisible()) { - web_contents_->find_in_page_controller_->MoveWindowIfNecessary( - gfx::Rect()); - } + if (find_bar_.get() && find_bar_->IsVisible()) + find_bar_->MoveWindowIfNecessary(gfx::Rect()); } } @@ -511,6 +583,28 @@ void WebContentsViewWin::ScrollCommon(UINT message, int scroll_type, } } +void WebContentsViewWin::WasHidden() { + web_contents_->HideContents(); + if (find_bar_.get()) + find_bar_->DidBecomeUnselected(); +} + +void WebContentsViewWin::WasShown() { + web_contents_->ShowContents(); + if (find_bar_.get()) + find_bar_->DidBecomeSelected(); +} + +void WebContentsViewWin::WasSized(const gfx::Size& size) { + if (web_contents_->render_widget_host_view()) + web_contents_->render_widget_host_view()->SetSize(size); + if (find_bar_.get()) + find_bar_->RespondToResize(size); + + // TODO(brettw) this function can probably be moved to this class. + web_contents_->RepositionSupressedPopupsToFit(size); +} + bool WebContentsViewWin::ScrollZoom(int scroll_type) { // If ctrl is held, zoom the UI. There are three issues with this: // 1) Should the event be eaten or forwarded to content? We eat the event, diff --git a/chrome/browser/web_contents_view_win.h b/chrome/browser/web_contents_view_win.h index 13e2138..d1ea193 100644 --- a/chrome/browser/web_contents_view_win.h +++ b/chrome/browser/web_contents_view_win.h @@ -5,10 +5,12 @@ #ifndef CHROME_BROWSER_WEB_CONTENTS_VIEW_WIN_H_ #define CHROME_BROWSER_WEB_CONTENTS_VIEW_WIN_H_ +#include "base/gfx/size.h" #include "base/scoped_ptr.h" #include "chrome/browser/web_contents_view.h" #include "chrome/views/container_win.h" +class FindBarWin; class InfoBarView; class InfoBarMessageView; class SadTabView; @@ -28,8 +30,7 @@ class WebContentsViewWin : public WebContentsView, // WebContentsView implementation -------------------------------------------- - // TODO(brettw) what on earth is the difference between this and - // CreatePageView. Do we really need both? + virtual WebContents* GetWebContents(); virtual void CreateView(HWND parent_hwnd, const gfx::Rect& initial_bounds); virtual RenderWidgetHostViewWin* CreateViewForWidget( @@ -37,13 +38,20 @@ class WebContentsViewWin : public WebContentsView, virtual HWND GetContainerHWND() const; virtual HWND GetContentHWND() const; virtual void GetContainerBounds(gfx::Rect* out) const; - virtual void DetachPluginWindows(); + virtual void OnContentsDestroy(); virtual void DisplayErrorInInfoBar(const std::wstring& text); virtual void SetInfoBarVisible(bool visible); virtual bool IsInfoBarVisible() const; virtual InfoBarView* GetInfoBarView(); virtual void SetPageTitle(const std::wstring& title); virtual void Invalidate(); + virtual void SizeContents(const gfx::Size& size); + virtual void FindInPage(const Browser& browser, + bool find_next, bool forward_direction); + virtual void HideFindBar(bool end_session); + virtual void ReparentFindWindow(Browser* new_browser) const; + virtual bool GetFindBarWindowInfo(gfx::Point* position, + bool* fully_visible) const; // Backend implementation of RenderViewHostDelegate::View. virtual WebContents* CreateNewWindowInternal( @@ -61,6 +69,11 @@ class WebContentsViewWin : public WebContentsView, virtual void UpdateDragCursor(bool is_drop_target); virtual void TakeFocus(bool reverse); virtual void HandleKeyboardEvent(const WebKeyboardEvent& event); + virtual void OnFindReply(int request_id, + int number_of_matches, + const gfx::Rect& selection_rect, + int active_match_ordinal, + bool final_update); private: // Windows events ------------------------------------------------------------ @@ -84,15 +97,27 @@ class WebContentsViewWin : public WebContentsView, void ScrollCommon(UINT message, int scroll_type, short position, HWND scrollbar); + // Handles notifying the WebContents and other operations when the window was + // shown or hidden. + void WasHidden(); + void WasShown(); + + // Handles resizing of the contents. This will notify the RenderWidgetHostView + // of the change, reposition popups, and the find in page bar. + void WasSized(const gfx::Size& size); + // TODO(brettw) comment these. They're confusing. bool ScrollZoom(int scroll_type); void WheelZoom(int distance); // --------------------------------------------------------------------------- - // TODO(brettw) when this class is separated from WebContents, we should own WebContents* web_contents_; + // For find in page. This may be NULL if there is no find bar, and if it is + // non-NULL, it may or may not be visible. + scoped_ptr<FindBarWin> find_bar_; + // A drop target object that handles drags over this WebContents. scoped_refptr<WebDropTarget> drop_target_; diff --git a/chrome/test/interactive_ui/interactive_ui.vcproj b/chrome/test/interactive_ui/interactive_ui.vcproj index 3405e29..adb9663 100644 --- a/chrome/test/interactive_ui/interactive_ui.vcproj +++ b/chrome/test/interactive_ui/interactive_ui.vcproj @@ -207,7 +207,7 @@ Name="TestFindInPage" > <File - RelativePath="..\..\browser\find_in_page_controller_interactive_uitest.cc" + RelativePath="..\..\browser\views\find_bar_win_interactive_uitest.cc" > </File> </Filter> diff --git a/chrome/test/ui/ui_tests.vcproj b/chrome/test/ui/ui_tests.vcproj index 9cbe00b..f89d52d 100644 --- a/chrome/test/ui/ui_tests.vcproj +++ b/chrome/test/ui/ui_tests.vcproj @@ -358,7 +358,7 @@ Name="TestFindInPage" > <File - RelativePath="..\..\browser\find_in_page_controller_uitest.cc" + RelativePath="..\..\browser\views\find_bar_win_uitest.cc" > </File> </Filter> |