diff options
author | rohitrao@chromium.org <rohitrao@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-22 22:54:03 +0000 |
---|---|---|
committer | rohitrao@chromium.org <rohitrao@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-22 22:54:03 +0000 |
commit | 2e39f625a1e09e2a1b29bb90e3a4aa1fee5829b1 (patch) | |
tree | 01c5246ff1483905cb1667a28ac116fe4559ab4b | |
parent | 7403d38f1a07efda20d3e6408a2edaf371da0007 (diff) | |
download | chromium_src-2e39f625a1e09e2a1b29bb90e3a4aa1fee5829b1.zip chromium_src-2e39f625a1e09e2a1b29bb90e3a4aa1fee5829b1.tar.gz chromium_src-2e39f625a1e09e2a1b29bb90e3a4aa1fee5829b1.tar.bz2 |
[Mac] Makes ctrl-return follow links when finding in page.
Enables the FindInPageControllerTest browser test on Mac.
BUG=38365,37808
TEST=Do a find in page for text in a link. Pressing ctrl-return while the findbar has focus should follow the link.
Review URL: http://codereview.chromium.org/1061003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@42276 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/cocoa/find_bar_bridge.h | 35 | ||||
-rw-r--r-- | chrome/browser/cocoa/find_bar_bridge.mm | 30 | ||||
-rw-r--r-- | chrome/browser/cocoa/find_bar_cocoa_controller.h | 1 | ||||
-rw-r--r-- | chrome/browser/cocoa/find_bar_cocoa_controller.mm | 12 | ||||
-rw-r--r-- | chrome/browser/find_bar_host_browsertest.cc | 24 | ||||
-rw-r--r-- | chrome/chrome_tests.gypi | 4 |
6 files changed, 80 insertions, 26 deletions
diff --git a/chrome/browser/cocoa/find_bar_bridge.h b/chrome/browser/cocoa/find_bar_bridge.h index ca9e27f..855886a 100644 --- a/chrome/browser/cocoa/find_bar_bridge.h +++ b/chrome/browser/cocoa/find_bar_bridge.h @@ -1,19 +1,23 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef CHROME_BROWSER_COCOA_FIND_BAR_BRIDGE_H_ #define CHROME_BROWSER_COCOA_FIND_BAR_BRIDGE_H_ -#import <Cocoa/Cocoa.h> - -#import "base/logging.h" -#import "base/scoped_nsobject.h" -#import "chrome/browser/find_bar.h" +#include "base/logging.h" +#include "chrome/browser/find_bar.h" class BrowserWindowCocoa; class FindBarController; + +// This class is included by find_bar_host_browsertest.cc, so it has to be +// objc-free. +#ifdef __OBJC__ @class FindBarCocoaController; +#else +class FindBarCocoaController; +#endif // Implementation of FindBar for the Mac. This class simply passes // each message along to |cocoa_controller_|. @@ -30,13 +34,14 @@ class FindBarController; // object is owned by the Browser. FindBarCocoaController is retained // by bother FindBarBridge and BrowserWindowController, since both use it. -class FindBarBridge : public FindBar { +class FindBarBridge : public FindBar, + public FindBarTesting { public: FindBarBridge(); virtual ~FindBarBridge(); FindBarCocoaController* find_bar_cocoa_controller() { - return cocoa_controller_.get(); + return cocoa_controller_; } virtual void SetFindBarController(FindBarController* find_bar_controller) { @@ -49,8 +54,7 @@ class FindBarBridge : public FindBar { } virtual FindBarTesting* GetFindBarTesting() { - NOTIMPLEMENTED(); - return NULL; + return this; } // Methods from FindBar. @@ -68,10 +72,17 @@ class FindBarBridge : public FindBar { virtual void MoveWindowIfNecessary(const gfx::Rect& selection_rect, bool no_redraw); + // Methods from FindBarTesting. + virtual bool GetFindBarWindowInfo(gfx::Point* position, + bool* fully_visible); + + // Used to disable find bar animations when testing. + static bool disable_animations_during_testing_; + private: // Pointer to the cocoa controller which manages the cocoa view. Is - // never null. - scoped_nsobject<FindBarCocoaController> cocoa_controller_; + // never nil. + FindBarCocoaController* cocoa_controller_; // Pointer back to the owning controller. FindBarController* find_bar_controller_; // weak, owns us diff --git a/chrome/browser/cocoa/find_bar_bridge.mm b/chrome/browser/cocoa/find_bar_bridge.mm index 26a6f3d..7b46fd2 100644 --- a/chrome/browser/cocoa/find_bar_bridge.mm +++ b/chrome/browser/cocoa/find_bar_bridge.mm @@ -1,27 +1,33 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#import "chrome/browser/cocoa/find_bar_bridge.h" +#include "chrome/browser/cocoa/find_bar_bridge.h" #include "base/sys_string_conversions.h" #import "chrome/browser/cocoa/find_bar_cocoa_controller.h" +// static +bool FindBarBridge::disable_animations_during_testing_ = false; + FindBarBridge::FindBarBridge() : find_bar_controller_(NULL) { - cocoa_controller_.reset([[FindBarCocoaController alloc] init]); + cocoa_controller_ = [[FindBarCocoaController alloc] init]; [cocoa_controller_ setFindBarBridge:this]; } FindBarBridge::~FindBarBridge() { + [cocoa_controller_ release]; } void FindBarBridge::Show(bool animate) { - [cocoa_controller_ showFindBar:(animate ? YES : NO)]; + bool really_animate = animate && !disable_animations_during_testing_; + [cocoa_controller_ showFindBar:(really_animate ? YES : NO)]; } void FindBarBridge::Hide(bool animate) { - [cocoa_controller_ hideFindBar:(animate ? YES : NO)]; + bool really_animate = animate && !disable_animations_during_testing_; + [cocoa_controller_ hideFindBar:(really_animate ? YES : NO)]; } void FindBarBridge::SetFocusAndSelection() { @@ -63,3 +69,17 @@ void FindBarBridge::StopAnimation() { void FindBarBridge::RestoreSavedFocus() { [cocoa_controller_ restoreSavedFocus]; } + +bool FindBarBridge::GetFindBarWindowInfo(gfx::Point* position, + bool* fully_visible) { + // TODO(rohitrao): Return the proper position. http://crbug.com/22036 + *position = gfx::Point(0, 0); + + NSWindow* window = [[cocoa_controller_ view] window]; + bool window_visible = [window isVisible] ? true : false; + *fully_visible = window_visible && + [cocoa_controller_ isFindBarVisible] && + ![cocoa_controller_ isFindBarAnimating]; + + return window_visible; +} diff --git a/chrome/browser/cocoa/find_bar_cocoa_controller.h b/chrome/browser/cocoa/find_bar_cocoa_controller.h index 6b3cf55..b6e66db 100644 --- a/chrome/browser/cocoa/find_bar_cocoa_controller.h +++ b/chrome/browser/cocoa/find_bar_cocoa_controller.h @@ -73,5 +73,6 @@ class FindNotificationDetails; - (void)updateUIForFindResult:(const FindNotificationDetails&)results withText:(const string16&)findText; - (BOOL)isFindBarVisible; +- (BOOL)isFindBarAnimating; @end diff --git a/chrome/browser/cocoa/find_bar_cocoa_controller.mm b/chrome/browser/cocoa/find_bar_cocoa_controller.mm index 569455f..a0eb5f3 100644 --- a/chrome/browser/cocoa/find_bar_cocoa_controller.mm +++ b/chrome/browser/cocoa/find_bar_cocoa_controller.mm @@ -147,6 +147,7 @@ const float kFindBarCloseDuration = 0.15; textView:(NSTextView*)textView doCommandBySelector:(SEL)command { if (command == @selector(insertNewline:)) { + // Pressing Return NSEvent* event = [NSApp currentEvent]; if ([event modifierFlags] & NSShiftKeyMask) @@ -155,6 +156,13 @@ const float kFindBarCloseDuration = 0.15; [nextButton_ performClick:nil]; return YES; + } else if (command == @selector(insertLineBreak:)) { + // Pressing Ctrl-Return + if (findBarBridge_) { + findBarBridge_->GetFindBarController()->EndFindSession( + FindBarController::kActivateSelection); + } + return YES; } else if (command == @selector(pageUp:) || command == @selector(pageUpAndModifySelection:) || command == @selector(scrollPageUp:) || @@ -291,6 +299,10 @@ const float kFindBarCloseDuration = 0.15; return NSIntersectsRect([[self view] bounds], [findBarView_ frame]); } +- (BOOL)isFindBarAnimating { + return (currentAnimation_.get() != nil); +} + // NSAnimation delegate methods. - (void)animationDidEnd:(NSAnimation*)animation { // Autorelease the animation (cannot use release because the animation object diff --git a/chrome/browser/find_bar_host_browsertest.cc b/chrome/browser/find_bar_host_browsertest.cc index 508e5c8..c6ff0d7 100644 --- a/chrome/browser/find_bar_host_browsertest.cc +++ b/chrome/browser/find_bar_host_browsertest.cc @@ -6,20 +6,23 @@ #include "base/message_loop.h" #include "chrome/browser/browser.h" #include "chrome/browser/browser_window.h" +#include "chrome/browser/find_bar.h" #include "chrome/browser/find_bar_controller.h" #include "chrome/browser/find_notification_details.h" #include "chrome/browser/renderer_host/render_view_host.h" #include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/browser/tab_contents/tab_contents_view.h" -#include "chrome/browser/views/find_bar_host.h" #include "chrome/common/notification_service.h" #include "chrome/test/in_process_browser_test.h" #include "chrome/test/ui_test_utils.h" #if defined(TOOLKIT_VIEWS) +#include "chrome/browser/views/find_bar_host.h" #include "views/focus/focus_manager.h" #elif defined(TOOLKIT_GTK) #include "chrome/browser/gtk/slide_animator_gtk.h" +#elif defined(OS_MACOSX) +#include "chrome/browser/cocoa/find_bar_bridge.h" #endif const std::wstring kSimplePage = L"404_is_enough_for_us.html"; @@ -54,6 +57,8 @@ class FindInPageControllerTest : public InProcessBrowserTest { DropdownBarHost::disable_animations_during_testing_ = true; #elif defined(TOOLKIT_GTK) SlideAnimatorGtk::SetAnimationsForTesting(false); +#elif defined(OS_MACOSX) + FindBarBridge::disable_animations_during_testing_ = true; #endif } @@ -495,23 +500,24 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindDisappearOnNavigate) { browser()->ShowFindBar(); + gfx::Point position; bool fully_visible = false; // Make sure it is open. - EXPECT_TRUE(GetFindBarWindowInfo(NULL, &fully_visible)); + EXPECT_TRUE(GetFindBarWindowInfo(&position, &fully_visible)); EXPECT_TRUE(fully_visible); // Reload the tab and make sure Find window doesn't go away. browser()->Reload(); ui_test_utils::WaitForNavigationInCurrentTab(browser()); - EXPECT_TRUE(GetFindBarWindowInfo(NULL, &fully_visible)); + EXPECT_TRUE(GetFindBarWindowInfo(&position, &fully_visible)); EXPECT_TRUE(fully_visible); // Navigate and make sure the Find window goes away. ui_test_utils::NavigateToURL(browser(), url2); - EXPECT_TRUE(GetFindBarWindowInfo(NULL, &fully_visible)); + EXPECT_TRUE(GetFindBarWindowInfo(&position, &fully_visible)); EXPECT_FALSE(fully_visible); } @@ -556,8 +562,16 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, EXPECT_FALSE(fully_visible); } +// TODO(rohitrao): The FindMovesWhenObscuring test does not pass on mac. +// http://crbug.com/22036 +#if defined(OS_MACOSX) +#define MAYBE_FindMovesWhenObscuring DISABLED_FindMovesWhenObscuring +#else +#define MAYBE_FindMovesWhenObscuring FindMovesWhenObscuring +#endif + // Make sure Find box moves out of the way if it is obscuring the active match. -IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindMovesWhenObscuring) { +IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, MAYBE_FindMovesWhenObscuring) { HTTPTestServer* server = StartHTTPServer(); GURL url = server->TestServerPageW(kMoveIfOver); diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index c8855b4..9e7cd02 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -1323,10 +1323,6 @@ 'sources': [ 'browser/extensions/browser_action_test_util_mac.mm', ], - 'sources!': [ - # TODO(estade): need to port. http://crbug.com/37808 - 'browser/find_bar_host_browsertest.cc', - ], 'include_dirs': [ '../third_party/GTM', ], |