diff options
Diffstat (limited to 'chrome/browser/ui/views')
-rw-r--r-- | chrome/browser/ui/views/dropdown_bar_host.h | 4 | ||||
-rw-r--r-- | chrome/browser/ui/views/find_bar_host.cc | 4 | ||||
-rw-r--r-- | chrome/browser/ui/views/find_bar_host.h | 1 | ||||
-rw-r--r-- | chrome/browser/ui/views/find_bar_host_interactive_uitest.cc | 71 | ||||
-rw-r--r-- | chrome/browser/ui/views/find_bar_view.cc | 17 | ||||
-rw-r--r-- | chrome/browser/ui/views/find_bar_view.h | 20 |
6 files changed, 112 insertions, 5 deletions
diff --git a/chrome/browser/ui/views/dropdown_bar_host.h b/chrome/browser/ui/views/dropdown_bar_host.h index f971ed0..71b0bf3 100644 --- a/chrome/browser/ui/views/dropdown_bar_host.h +++ b/chrome/browser/ui/views/dropdown_bar_host.h @@ -139,7 +139,7 @@ class DropdownBarHost : public views::AcceleratorTarget, // Allows implementation to tweak widget position. void SetWidgetPositionNative(const gfx::Rect& new_pos, bool no_redraw); - // Returns a keyboard event suitable for fowarding. + // Returns a keyboard event suitable for forwarding. NativeWebKeyboardEvent GetKeyboardEvent( const TabContents* contents, const views::Textfield::Keystroke& key_stroke); @@ -178,7 +178,7 @@ class DropdownBarHost : public views::AcceleratorTarget, // dropdown bar. It contains the DropdownBarView. scoped_ptr<views::Widget> host_; - // A flag to manually manage visibility. GTK/X11 is asynchrnous and + // A flag to manually manage visibility. GTK/X11 is asynchronous and // the state of the widget can be out of sync. bool is_visible_; diff --git a/chrome/browser/ui/views/find_bar_host.cc b/chrome/browser/ui/views/find_bar_host.cc index 09b513a..0eabaaf 100644 --- a/chrome/browser/ui/views/find_bar_host.cc +++ b/chrome/browser/ui/views/find_bar_host.cc @@ -214,6 +214,10 @@ string16 FindBarHost::GetFindText() { return find_bar_view()->GetFindText(); } +string16 FindBarHost::GetFindSelectedText() { + return find_bar_view()->GetFindSelectedText(); +} + string16 FindBarHost::GetMatchCountText() { return find_bar_view()->GetMatchCountText(); } diff --git a/chrome/browser/ui/views/find_bar_host.h b/chrome/browser/ui/views/find_bar_host.h index 496cef0..6ab11ca 100644 --- a/chrome/browser/ui/views/find_bar_host.h +++ b/chrome/browser/ui/views/find_bar_host.h @@ -72,6 +72,7 @@ class FindBarHost : public DropdownBarHost, virtual bool GetFindBarWindowInfo(gfx::Point* position, bool* fully_visible); virtual string16 GetFindText(); + virtual string16 GetFindSelectedText(); virtual string16 GetMatchCountText(); // Overridden from DropdownBarHost: diff --git a/chrome/browser/ui/views/find_bar_host_interactive_uitest.cc b/chrome/browser/ui/views/find_bar_host_interactive_uitest.cc index 92b5fbf..b26e5e4 100644 --- a/chrome/browser/ui/views/find_bar_host_interactive_uitest.cc +++ b/chrome/browser/ui/views/find_bar_host_interactive_uitest.cc @@ -174,6 +174,77 @@ IN_PROC_BROWSER_TEST_F(FindInPageTest, FocusRestore) { EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_LOCATION_BAR)); } +IN_PROC_BROWSER_TEST_F(FindInPageTest, FocusRestoreOnTabSwitch) { + base::TimeTicks start_time = base::TimeTicks::Now(); + Checkpoint("Starting test server", start_time); + + ASSERT_TRUE(test_server()->Start()); + + // First we navigate to our test page (tab A). + GURL url = test_server()->GetURL(kSimplePage); + ui_test_utils::NavigateToURL(browser(), url); + + Checkpoint("Calling Find", start_time); + + browser()->Find(); + EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), + VIEW_ID_FIND_IN_PAGE_TEXT_FIELD)); + + Checkpoint("GetFindBarTesting", start_time); + + FindBarTesting* find_bar = + browser()->GetFindBarController()->find_bar()->GetFindBarTesting(); + + Checkpoint("Search for 'a'", start_time); + + // Search for 'a'. + ui_test_utils::FindInPage(browser()->GetSelectedTabContents(), + ASCIIToUTF16("a"), true, false, NULL); + EXPECT_TRUE(ASCIIToUTF16("a") == find_bar->GetFindSelectedText()); + + Checkpoint("Open tab B", start_time); + + // Open another tab (tab B). + browser()->AddSelectedTabWithURL(url, PageTransition::TYPED); + ASSERT_TRUE(ui_test_utils::WaitForNavigationInCurrentTab(browser())); + + Checkpoint("Open find", start_time); + + // Make sure Find box is open. + browser()->Find(); + EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), + VIEW_ID_FIND_IN_PAGE_TEXT_FIELD)); + + Checkpoint("Search for 'b'", start_time); + + // Search for 'b'. + ui_test_utils::FindInPage(browser()->GetSelectedTabContents(), + ASCIIToUTF16("b"), true, false, NULL); + EXPECT_TRUE(ASCIIToUTF16("b") == find_bar->GetFindSelectedText()); + + Checkpoint("Focus location bar", start_time); + + // Set focus away from the Find bar (to the Location bar). + browser()->FocusLocationBar(); + EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_LOCATION_BAR)); + + Checkpoint("Select tab A", start_time); + + // Select tab A. Find bar should get focus. + browser()->SelectTabContentsAt(0, true); + EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), + VIEW_ID_FIND_IN_PAGE_TEXT_FIELD)); + EXPECT_TRUE(ASCIIToUTF16("a") == find_bar->GetFindSelectedText()); + + Checkpoint("Select tab B", start_time); + + // Select tab B. Location bar should get focus. + browser()->SelectTabContentsAt(1, true); + EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_LOCATION_BAR)); + + Checkpoint("Test done", start_time); +} + // This tests that whenever you clear values from the Find box and close it that // it respects that and doesn't show you the last search, as reported in bug: // http://crbug.com/40121. diff --git a/chrome/browser/ui/views/find_bar_view.cc b/chrome/browser/ui/views/find_bar_view.cc index 023ee57..72f722c 100644 --- a/chrome/browser/ui/views/find_bar_view.cc +++ b/chrome/browser/ui/views/find_bar_view.cc @@ -97,7 +97,7 @@ FindBarView::FindBarView(FindBarHost* host) SetID(VIEW_ID_FIND_IN_PAGE); ResourceBundle& rb = ResourceBundle::GetSharedInstance(); - find_text_ = new views::Textfield(); + find_text_ = new SearchTextfieldView(); find_text_->SetID(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD); find_text_->SetFont(rb.GetFont(ResourceBundle::BaseFont)); find_text_->set_default_width_in_chars(kDefaultCharWidth); @@ -187,6 +187,10 @@ string16 FindBarView::GetFindText() const { return find_text_->text(); } +string16 FindBarView::GetFindSelectedText() const { + return find_text_->GetSelectedText(); +} + string16 FindBarView::GetMatchCountText() const { return WideToUTF16Hack(match_count_text_->GetText()); } @@ -541,6 +545,17 @@ bool FindBarView::FocusForwarderView::OnMousePressed( return true; } +FindBarView::SearchTextfieldView::SearchTextfieldView() { +} + +FindBarView::SearchTextfieldView::~SearchTextfieldView() { +} + +void FindBarView::SearchTextfieldView::RequestFocus() { + views::View::RequestFocus(); + SelectAll(); +} + FindBarHost* FindBarView::find_bar_host() const { return static_cast<FindBarHost*>(host()); } diff --git a/chrome/browser/ui/views/find_bar_view.h b/chrome/browser/ui/views/find_bar_view.h index 92ab262..4047228 100644 --- a/chrome/browser/ui/views/find_bar_view.h +++ b/chrome/browser/ui/views/find_bar_view.h @@ -47,6 +47,9 @@ class FindBarView : public DropdownBarView, string16 GetFindText() const; void SetFindText(const string16& find_text); + // Gets the selected text in the text box. + string16 GetFindSelectedText() const; + // Gets the match count text displayed in the text box. string16 GetMatchCountText() const; @@ -105,12 +108,25 @@ class FindBarView : public DropdownBarView, DISALLOW_COPY_AND_ASSIGN(FocusForwarderView); }; + // A wrapper of views::TextField that allows us to select all text when we + // get focus. Represents the text field where the user enters a search term. + class SearchTextfieldView : public views::Textfield { + public: + SearchTextfieldView(); + virtual ~SearchTextfieldView(); + + virtual void RequestFocus(); + + private: + DISALLOW_COPY_AND_ASSIGN(SearchTextfieldView); + }; + // Returns the OS-specific view for the find bar that acts as an intermediary // between us and the TabContentsView. FindBarHost* find_bar_host() const; #if defined(OS_LINUX) - // In gtk we get changed signals if we programatically set the text. If we + // In GTK we get changed signals if we programmatically set the text. If we // don't ignore them we run into problems. For example, switching tabs back // to one with the find bar visible will cause a search to the next found // text. Also if the find bar had been visible and then hidden and the user @@ -119,7 +135,7 @@ class FindBarView : public DropdownBarView, #endif // The controls in the window. - views::Textfield* find_text_; + SearchTextfieldView* find_text_; views::Label* match_count_text_; FocusForwarderView* focus_forwarder_view_; views::ImageButton* find_previous_button_; |