Commit dd3845f1 authored by Nico Weber's avatar Nico Weber Committed by Commit Bot

mac: Remove unused cocoa find_bar code.

Bug: 832676
Change-Id: Ia5a1810b329d05e9357376cf00ac3f7d144ee96a
Reviewed-on: https://chromium-review.googlesource.com/1237454Reviewed-by: default avatarRobert Sesek <rsesek@chromium.org>
Reviewed-by: default avatarElly Fong-Jones <ellyjones@chromium.org>
Commit-Queue: Nico Weber <thakis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#593359}
parent cebf2f90
......@@ -15,10 +15,7 @@ translated_xibs = [
"Toolbar.xib",
]
untranslated_xibs = [
"FindBar.xib",
"InfoBar.xib",
]
untranslated_xibs = [ "InfoBar.xib" ]
mac_xib_bundle_data("chrome_xibs") {
sources = translated_xibs + untranslated_xibs
......
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="5056" systemVersion="13F1077" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none">
<dependencies>
<deployment version="1090" identifier="macosx"/>
<development version="5100" identifier="xcode"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="5056"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="FindBarCocoaController">
<connections>
<outlet property="closeButton_" destination="7" id="32"/>
<outlet property="findBarView_" destination="2" id="30"/>
<outlet property="findText_" destination="5" id="14"/>
<outlet property="nextButton_" destination="3" id="20"/>
<outlet property="previousButton_" destination="4" id="21"/>
<outlet property="view" destination="29" id="31"/>
</connections>
</customObject>
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
<customObject id="-3" userLabel="Application"/>
<customView id="29">
<rect key="frame" x="0.0" y="0.0" width="310" height="33"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMinY="YES"/>
<subviews>
<customView id="2" customClass="FindBarView">
<rect key="frame" x="0.0" y="0.0" width="310" height="33"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES"/>
<subviews>
<button id="7">
<rect key="frame" x="280" y="9" width="16" height="16"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxY="YES"/>
<buttonCell key="cell" type="square" bezelStyle="shadowlessSquare" imagePosition="overlaps" alignment="center" inset="2" id="8" customClass="ImageButtonCell">
<behavior key="behavior" lightByContents="YES"/>
<font key="font" metaFont="system"/>
<string key="keyEquivalent" base64-UTF8="YES">
Gw
</string>
</buttonCell>
<connections>
<action selector="close:" target="-2" id="15"/>
</connections>
</button>
<button id="3">
<rect key="frame" x="251" y="5" width="26" height="24"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxY="YES"/>
<buttonCell key="cell" type="square" bezelStyle="shadowlessSquare" imagePosition="overlaps" alignment="center" borderStyle="border" tag="1" imageScaling="proportionallyDown" inset="2" id="12" customClass="GradientButtonCell">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
<connections>
<action selector="nextResult:" target="-2" id="17"/>
</connections>
</button>
<button id="4">
<rect key="frame" x="228" y="5" width="24" height="24"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxY="YES"/>
<buttonCell key="cell" type="square" bezelStyle="shadowlessSquare" imagePosition="only" alignment="center" borderStyle="border" tag="2" imageScaling="proportionallyDown" inset="2" id="11" customClass="GradientButtonCell">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
<connections>
<action selector="previousResult:" target="-2" id="16"/>
</connections>
</button>
<textField verticalHuggingPriority="750" id="5" customClass="FindBarTextField">
<rect key="frame" x="13" y="5" width="216" height="24"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMaxY="YES"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" state="on" borderStyle="bezel" drawsBackground="YES" id="10" customClass="FindBarTextFieldCell">
<font key="font" metaFont="system"/>
<color key="textColor" name="textColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
<connections>
<outlet property="delegate" destination="-2" id="18"/>
</connections>
</textField>
</subviews>
</customView>
</subviews>
</customView>
</objects>
</document>
......@@ -169,16 +169,6 @@ jumbo_split_static_library("ui") {
"cocoa/extensions/toolbar_actions_bar_bubble_views_presenter.mm",
"cocoa/fast_resize_view.h",
"cocoa/fast_resize_view.mm",
"cocoa/find_bar/find_bar_bridge.h",
"cocoa/find_bar/find_bar_bridge.mm",
"cocoa/find_bar/find_bar_cocoa_controller.h",
"cocoa/find_bar/find_bar_cocoa_controller.mm",
"cocoa/find_bar/find_bar_text_field.h",
"cocoa/find_bar/find_bar_text_field.mm",
"cocoa/find_bar/find_bar_text_field_cell.h",
"cocoa/find_bar/find_bar_text_field_cell.mm",
"cocoa/find_bar/find_bar_view_cocoa.h",
"cocoa/find_bar/find_bar_view_cocoa.mm",
"cocoa/floating_bar_backing_view.h",
"cocoa/floating_bar_backing_view.mm",
"cocoa/framed_browser_window.h",
......@@ -3948,10 +3938,7 @@ static_library("test_support") {
"views/webauthn/authenticator_request_dialog_view_test_api.h",
]
if (is_mac) {
sources += [
"cocoa/extensions/browser_action_test_util_views_cocoa.mm",
"cocoa/find_bar/find_bar_host_unittest_util_cocoa.mm",
]
sources += [ "cocoa/extensions/browser_action_test_util_views_cocoa.mm" ]
}
if (use_aura) {
sources += [ "views/toolbar/browser_action_test_util_views_aura.cc" ]
......
......@@ -16,7 +16,6 @@
class Browser;
@class BrowserWindowController;
@class FindBarCocoaController;
@class NSEvent;
@class NSMenu;
@class NSWindow;
......@@ -157,9 +156,6 @@ class BrowserWindowCocoa
extensions::ActiveTabPermissionGranter* GetActiveTabPermissionGranter()
override;
// Adds the given FindBar cocoa controller to this browser window.
void AddFindBar(FindBarCocoaController* find_bar_cocoa_controller);
// Updates the window's alert state. If the new alert state is
// TabAlertState::AUDIO_PLAYING or TabAlertState::AUDIO_MUTING then sets
// the window's title to reflect that.
......
......@@ -37,7 +37,6 @@
#import "chrome/browser/ui/cocoa/chrome_event_processing_window.h"
#import "chrome/browser/ui/cocoa/constrained_window/constrained_window_sheet_controller.h"
#import "chrome/browser/ui/cocoa/extensions/browser_actions_controller.h"
#include "chrome/browser/ui/cocoa/find_bar/find_bar_bridge.h"
#import "chrome/browser/ui/cocoa/info_bubble_view.h"
#include "chrome/browser/ui/cocoa/key_equivalent_constants.h"
#import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h"
......@@ -489,11 +488,6 @@ bool BrowserWindowCocoa::IsToolbarVisible() const {
browser_->SupportsWindowFeature(Browser::FEATURE_LOCATIONBAR);
}
void BrowserWindowCocoa::AddFindBar(
FindBarCocoaController* find_bar_cocoa_controller) {
[controller_ addFindBar:find_bar_cocoa_controller];
}
void BrowserWindowCocoa::UpdateAlertState(TabAlertState alert_state) {
alert_state_ = alert_state;
UpdateTitleBar();
......@@ -640,13 +634,7 @@ void BrowserWindowCocoa::CutCopyPaste(int command_id) {
}
FindBar* BrowserWindowCocoa::CreateFindBar() {
// We could push the AddFindBar() call into the FindBarBridge
// constructor or the FindBarCocoaController init, but that makes
// unit testing difficult, since we would also require a
// BrowserWindow object.
FindBarBridge* bridge = new FindBarBridge(browser_);
AddFindBar(bridge->find_bar_cocoa_controller());
return bridge;
return nullptr;
}
web_modal::WebContentsModalDialogHost*
......
......@@ -41,7 +41,6 @@ class BrowserWindowCocoa;
class ExtensionKeybindingRegistryCocoa;
class ExclusiveAccessController;
class ExclusiveAccessContext;
@class FindBarCocoaController;
@class FullscreenModeController;
@class FullscreenToolbarControllerCocoa;
@class FullscreenToolbarVisibilityLockController;
......@@ -77,7 +76,6 @@ constexpr const gfx::Size kMinCocoaPopupWindowSize(100, 122);
std::unique_ptr<BrowserWindowCocoa> windowShim_;
base::scoped_nsobject<ToolbarController> toolbarController_;
base::scoped_nsobject<TabStripControllerCocoa> tabStripController_;
base::scoped_nsobject<FindBarCocoaController> findBarCocoaController_;
base::scoped_nsobject<InfoBarContainerController> infoBarContainerController_;
base::scoped_nsobject<DevToolsController> devToolsController_;
base::scoped_nsobject<OverlayableContentsController>
......@@ -217,9 +215,6 @@ constexpr const gfx::Size kMinCocoaPopupWindowSize(100, 122);
// Return a weak pointer to the tab strip controller.
- (TabStripControllerCocoa*)tabStripController;
// Return a weak pointer to the find bar controller.
- (FindBarCocoaController*)findBarCocoaController;
// Access the ObjC controller that contains the infobars.
- (InfoBarContainerController*)infoBarContainerController;
......@@ -305,11 +300,6 @@ constexpr const gfx::Size kMinCocoaPopupWindowSize(100, 122);
- (DevToolsController*)devToolsController;
// Retains the given FindBarCocoaController and adds its view to this
// browser window. Must only be called once per
// BrowserWindowController.
- (void)addFindBar:(FindBarCocoaController*)findBarCocoaController;
// The user changed the theme.
- (void)userChangedTheme;
......
......@@ -50,8 +50,6 @@
#import "chrome/browser/ui/cocoa/dev_tools_controller.h"
#include "chrome/browser/ui/cocoa/extensions/extension_keybinding_registry_cocoa.h"
#import "chrome/browser/ui/cocoa/fast_resize_view.h"
#import "chrome/browser/ui/cocoa/find_bar/find_bar_bridge.h"
#import "chrome/browser/ui/cocoa/find_bar/find_bar_cocoa_controller.h"
#import "chrome/browser/ui/cocoa/framed_browser_window.h"
#import "chrome/browser/ui/cocoa/fullscreen/fullscreen_toolbar_controller_cocoa.h"
#import "chrome/browser/ui/cocoa/fullscreen/fullscreen_toolbar_visibility_lock_controller.h"
......@@ -418,7 +416,6 @@ bool IsTabDetachingInFullscreenEnabled() {
// controllers.
[toolbarController_ browserWillBeDestroyed];
[tabStripController_ browserWillBeDestroyed];
[findBarCocoaController_ browserWillBeDestroyed];
[avatarButtonController_ browserWillBeDestroyed];
[super dealloc];
......@@ -468,10 +465,6 @@ bool IsTabDetachingInFullscreenEnabled() {
return tabStripController_.get();
}
- (FindBarCocoaController*)findBarCocoaController {
return findBarCocoaController_.get();
}
- (InfoBarContainerController*)infoBarContainerController {
return infoBarContainerController_.get();
}
......@@ -545,11 +538,8 @@ bool IsTabDetachingInFullscreenEnabled() {
}
- (void)updateDevToolsForContents:(WebContents*)contents {
BOOL layout_changed =
[devToolsController_ updateDevToolsForWebContents:contents
withProfile:browser_->profile()];
if (layout_changed && [findBarCocoaController_ isFindBarVisible])
[self layoutSubviews];
[devToolsController_ updateDevToolsForWebContents:contents
withProfile:browser_->profile()];
}
// Called when the user wants to close a window or from the shutdown process.
......@@ -1317,16 +1307,6 @@ bool IsTabDetachingInFullscreenEnabled() {
return devToolsController_;
}
- (void)addFindBar:(FindBarCocoaController*)findBarCocoaController {
// Shouldn't call addFindBar twice.
DCHECK(!findBarCocoaController_.get());
// Create a controller for the findbar.
findBarCocoaController_.reset([findBarCocoaController retain]);
[self layoutSubviews];
[self updateSubviewZOrder];
}
- (NSWindow*)createFullscreenWindow {
NSWindow* window = [[[FullscreenWindow alloc]
initForScreen:[[self window] screen]] autorelease];
......@@ -1536,14 +1516,6 @@ bool IsTabDetachingInFullscreenEnabled() {
}
[self updatePermissionBubbleAnchor];
// The FindBar needs to know its own position to properly detect overlaps
// with find results. The position changes whenever the window is resized,
// and |layoutSubviews| computes the FindBar's position.
// TODO: calling |layoutSubviews| here is a waste, find a better way to
// do this.
if ([findBarCocoaController_ isFindBarVisible])
[self layoutSubviews];
}
// Delegate method called when window did move. (See below for why we don't use
......
......@@ -83,7 +83,6 @@ void CreateProfileCallback(const base::Closure& quit_closure,
enum BrowserViewID {
BROWSER_VIEW_ID_TOOLBAR,
BROWSER_VIEW_ID_INFO_BAR,
BROWSER_VIEW_ID_FIND_BAR,
BROWSER_VIEW_ID_TAB_CONTENT_AREA,
BROWSER_VIEW_ID_FULLSCREEN_FLOATING_BAR,
BROWSER_VIEW_ID_COUNT,
......@@ -233,8 +232,6 @@ class BrowserWindowControllerTest : public InProcessBrowserTest {
return [[controller() toolbarController] view];
case BROWSER_VIEW_ID_INFO_BAR:
return [[controller() infoBarContainerController] view];
case BROWSER_VIEW_ID_FIND_BAR:
return [[controller() findBarCocoaController] view];
case BROWSER_VIEW_ID_TAB_CONTENT_AREA:
return [controller() tabContentArea];
default:
......@@ -409,13 +406,10 @@ IN_PROC_BROWSER_TEST_F(BrowserWindowControllerTest,
// Verify that in non-Instant normal mode that the find bar and download shelf
// are above the content area. Everything else should be below it.
IN_PROC_BROWSER_TEST_F(BrowserWindowControllerTest, ZOrderNormal) {
browser()->GetFindBarController(); // add find bar
std::vector<BrowserViewID> view_list;
view_list.push_back(BROWSER_VIEW_ID_TOOLBAR);
view_list.push_back(BROWSER_VIEW_ID_INFO_BAR);
view_list.push_back(BROWSER_VIEW_ID_TAB_CONTENT_AREA);
view_list.push_back(BROWSER_VIEW_ID_FIND_BAR);
VerifyZOrder(view_list);
[controller() showOverlay];
......@@ -433,14 +427,12 @@ IN_PROC_BROWSER_TEST_F(BrowserWindowControllerTest, ZOrderNormal) {
IN_PROC_BROWSER_TEST_F(BrowserWindowControllerTest,
DISABLED_ZOrderPresentationMode) {
chrome::ToggleFullscreenMode(browser());
browser()->GetFindBarController(); // add find bar
std::vector<BrowserViewID> view_list;
view_list.push_back(BROWSER_VIEW_ID_INFO_BAR);
view_list.push_back(BROWSER_VIEW_ID_TAB_CONTENT_AREA);
view_list.push_back(BROWSER_VIEW_ID_FULLSCREEN_FLOATING_BAR);
view_list.push_back(BROWSER_VIEW_ID_TOOLBAR);
view_list.push_back(BROWSER_VIEW_ID_FIND_BAR);
VerifyZOrder(view_list);
}
......
......@@ -27,7 +27,6 @@
#import "chrome/browser/ui/cocoa/constrained_window/constrained_window_sheet_controller.h"
#import "chrome/browser/ui/cocoa/dev_tools_controller.h"
#import "chrome/browser/ui/cocoa/fast_resize_view.h"
#import "chrome/browser/ui/cocoa/find_bar/find_bar_cocoa_controller.h"
#import "chrome/browser/ui/cocoa/floating_bar_backing_view.h"
#import "chrome/browser/ui/cocoa/framed_browser_window.h"
#import "chrome/browser/ui/cocoa/fullscreen/fullscreen_toolbar_controller_cocoa.h"
......@@ -887,10 +886,6 @@ willPositionSheet:(NSWindow*)sheet
[fullscreenToolbarController_
updateToolbarFrame:output.fullscreenBackingBarFrame];
}
[findBarCocoaController_
positionFindBarViewAtMaxY:output.findBarMaxY
maxWidth:NSWidth(output.contentAreaFrame)];
}
- (void)updateSubviewZOrder {
......@@ -908,8 +903,6 @@ willPositionSheet:(NSWindow*)sheet
[subviews addObject:[infoBarContainerController_ view]];
if ([self tabContentArea])
[subviews addObject:[self tabContentArea]];
if ([findBarCocoaController_ view])
[subviews addObject:[findBarCocoaController_ view]];
[self setContentViewSubviews:subviews];
}
......@@ -929,9 +922,6 @@ willPositionSheet:(NSWindow*)sheet
if ([infoBarContainerController_ view])
[subviews addObject:[infoBarContainerController_ view]];
if ([findBarCocoaController_ view])
[subviews addObject:[findBarCocoaController_ view]];
[self setContentViewSubviews:subviews];
}
......
......@@ -15,7 +15,6 @@
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/cocoa/browser_window_layout.h"
#import "chrome/browser/ui/cocoa/fast_resize_view.h"
#include "chrome/browser/ui/cocoa/find_bar/find_bar_bridge.h"
#include "chrome/browser/ui/cocoa/tabs/tab_strip_view.h"
#include "chrome/browser/ui/cocoa/test/cocoa_profile_test.h"
#include "chrome/browser/ui/cocoa/test/run_loop_testing.h"
......@@ -54,10 +53,6 @@ using ::testing::Return;
return [toolbarController_ view];
}
- (NSView*)findBarView {
return [findBarCocoaController_ view];
}
- (void)dontFocusLocationBar:(BOOL)selectAll {
}
@end
......@@ -477,22 +472,6 @@ TEST_F(BrowserWindowControllerTest, TestZoomFrame) {
EXPECT_EQ(screenFrame.origin.y, zoomFrame.origin.y);
}
TEST_F(BrowserWindowControllerTest, TestFindBarOnTop) {
FindBarBridge bridge(NULL);
[controller_ addFindBar:bridge.find_bar_cocoa_controller()];
// Test that the Z-order of the find bar is on top of everything.
NSArray* subviews = [controller_.chromeContentView subviews];
NSUInteger findBar_index =
[subviews indexOfObject:[controller_ findBarView]];
EXPECT_NE(static_cast<NSUInteger>(NSNotFound), findBar_index);
NSUInteger toolbar_index =
[subviews indexOfObject:[controller_ toolbarView]];
EXPECT_NE(static_cast<NSUInteger>(NSNotFound), toolbar_index);
EXPECT_GT(findBar_index, toolbar_index);
}
// Check that when the window becomes/resigns main, the tab strip's background
// view is redrawn.
TEST_F(BrowserWindowControllerTest, TabStripBackgroundViewRedrawTest) {
......
// Copyright (c) 2011 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_UI_COCOA_FIND_BAR_FIND_BAR_BRIDGE_H_
#define CHROME_BROWSER_UI_COCOA_FIND_BAR_FIND_BAR_BRIDGE_H_
#include "base/compiler_specific.h"
#include "base/logging.h"
#include "base/macros.h"
#include "chrome/browser/ui/find_bar/find_bar.h"
class Browser;
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_|.
//
// The initialization here is a bit complicated. FindBarBridge is
// created by a static method in BrowserWindow. The FindBarBridge
// constructor creates a FindBarCocoaController, which in turn loads a
// FindBarView from a nib file. All of this is happening outside of
// the main view hierarchy, so the static method also calls
// BrowserWindowCocoa::AddFindBar() in order to add its FindBarView to
// the cocoa views hierarchy.
//
// Memory ownership is relatively straightforward. The FindBarBridge
// object is owned by the Browser. FindBarCocoaController is retained
// by bother FindBarBridge and BrowserWindowController, since both use it.
class FindBarBridge : public FindBar,
public FindBarTesting {
public:
FindBarBridge(Browser* browser);
~FindBarBridge() override;
FindBarCocoaController* find_bar_cocoa_controller() {
return cocoa_controller_;
}
void SetFindBarController(FindBarController* find_bar_controller) override;
FindBarController* GetFindBarController() const override;
FindBarTesting* GetFindBarTesting() override;
// Methods from FindBar.
void Show(bool animate) override;
void Hide(bool animate) override;
void SetFocusAndSelection() override;
void ClearResults(const FindNotificationDetails& results) override;
void StopAnimation() override;
void SetFindTextAndSelectedRange(const base::string16& find_text,
const gfx::Range& selected_range) override;
base::string16 GetFindText() override;
gfx::Range GetSelectedRange() override;
void UpdateUIForFindResult(const FindNotificationDetails& result,
const base::string16& find_text) override;
void AudibleAlert() override;
bool IsFindBarVisible() override;
void RestoreSavedFocus() override;
bool HasGlobalFindPasteboard() override;
void UpdateFindBarForChangedWebContents() override;
void MoveWindowIfNecessary(const gfx::Rect& selection_rect) override;
// Methods from FindBarTesting.
bool GetFindBarWindowInfo(gfx::Point* position, bool* fully_visible) override;
base::string16 GetFindSelectedText() override;
base::string16 GetMatchCountText() override;
int GetWidth() override;
size_t GetAudibleAlertCount() override;
// 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 nil.
FindBarCocoaController* cocoa_controller_;
// Pointer back to the owning controller.
FindBarController* find_bar_controller_; // weak, owns us
// Number of audible alerts generated, for testing.
size_t audible_alerts_;
DISALLOW_COPY_AND_ASSIGN(FindBarBridge);
};
#endif // CHROME_BROWSER_UI_COCOA_FIND_BAR_FIND_BAR_BRIDGE_H_
// Copyright (c) 2011 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 <Cocoa/Cocoa.h>
#include "chrome/browser/ui/cocoa/find_bar/find_bar_bridge.h"
#include "base/strings/sys_string_conversions.h"
#import "chrome/browser/ui/cocoa/find_bar/find_bar_cocoa_controller.h"
#include "ui/gfx/range/range.h"
// static
bool FindBarBridge::disable_animations_during_testing_ = false;
FindBarBridge::FindBarBridge(Browser* browser)
: find_bar_controller_(NULL), audible_alerts_(0) {
cocoa_controller_ = [[FindBarCocoaController alloc] initWithBrowser:browser];
[cocoa_controller_ setFindBarBridge:this];
}
FindBarBridge::~FindBarBridge() {
[cocoa_controller_ release];
}
void FindBarBridge::SetFindBarController(
FindBarController* find_bar_controller) {
find_bar_controller_ = find_bar_controller;
}
FindBarController* FindBarBridge::GetFindBarController() const {
return find_bar_controller_;
}
FindBarTesting* FindBarBridge::GetFindBarTesting() {
return this;
}
void FindBarBridge::Show(bool animate) {
bool really_animate = animate && !disable_animations_during_testing_;
[cocoa_controller_ showFindBar:(really_animate ? YES : NO)];
}
void FindBarBridge::Hide(bool animate) {
bool really_animate = animate && !disable_animations_during_testing_;
[cocoa_controller_ hideFindBar:(really_animate ? YES : NO)];
}
void FindBarBridge::SetFocusAndSelection() {
[cocoa_controller_ setFocusAndSelection];
}
void FindBarBridge::ClearResults(const FindNotificationDetails& results) {
[cocoa_controller_ clearResults:results];
}
void FindBarBridge::SetFindTextAndSelectedRange(
const base::string16& find_text,
const gfx::Range& selected_range) {
[cocoa_controller_ setFindText:base::SysUTF16ToNSString(find_text)
selectedRange:selected_range.ToNSRange()];
}
base::string16 FindBarBridge::GetFindText() {
return base::SysNSStringToUTF16([cocoa_controller_ findText]);
}
gfx::Range FindBarBridge::GetSelectedRange() {
return gfx::Range([cocoa_controller_ selectedRange]);
}
void FindBarBridge::UpdateUIForFindResult(const FindNotificationDetails& result,
const base::string16& find_text) {
[cocoa_controller_ updateUIForFindResult:result withText:find_text];
}
void FindBarBridge::AudibleAlert() {
// Beep beep, beep beep, Yeah!
++audible_alerts_;
NSBeep();
}
bool FindBarBridge::IsFindBarVisible() {
return [cocoa_controller_ isFindBarVisible] ? true : false;
}
void FindBarBridge::MoveWindowIfNecessary(const gfx::Rect& selection_rect) {
// See FindBarCocoaController moveFindBarToAvoidRect.
}
void FindBarBridge::StopAnimation() {
[cocoa_controller_ stopAnimation];
}
void FindBarBridge::RestoreSavedFocus() {
[cocoa_controller_ restoreSavedFocus];
}
bool FindBarBridge::HasGlobalFindPasteboard() {
return true;
}
void FindBarBridge::UpdateFindBarForChangedWebContents() {
[cocoa_controller_ updateFindBarForChangedWebContents];
}
bool FindBarBridge::GetFindBarWindowInfo(gfx::Point* position,
bool* fully_visible) {
NSWindow* window = [[cocoa_controller_ view] window];
bool window_visible = [window isVisible] ? true : false;
if (position) {
if (window_visible)
*position = [cocoa_controller_ findBarWindowPosition];
else
*position = gfx::Point(0, 0);
}
if (fully_visible) {
*fully_visible = window_visible &&
[cocoa_controller_ isFindBarVisible] &&
![cocoa_controller_ isFindBarAnimating];
}
return window_visible;
}
base::string16 FindBarBridge::GetFindSelectedText() {
// This function is currently only used in Views.
NOTIMPLEMENTED();
return base::string16();
}
base::string16 FindBarBridge::GetMatchCountText() {
return base::SysNSStringToUTF16([cocoa_controller_ matchCountText]);
}
int FindBarBridge::GetWidth() {
return [cocoa_controller_ findBarWidth];
}
size_t FindBarBridge::GetAudibleAlertCount() {
return audible_alerts_;
}
// Copyright (c) 2009 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.
#include "chrome/browser/ui/cocoa/find_bar/find_bar_bridge.h"
#include "chrome/browser/ui/cocoa/test/cocoa_test_helper.h"
#include "chrome/browser/ui/find_bar/find_bar_controller.h"
namespace {
class FindBarBridgeTest : public CocoaTest {
};
TEST_F(FindBarBridgeTest, Creation) {
// Make sure the FindBarBridge constructor doesn't crash and
// properly initializes its FindBarCocoaController.
FindBarBridge bridge(NULL);
EXPECT_TRUE(bridge.find_bar_cocoa_controller() != NULL);
}
TEST_F(FindBarBridgeTest, Accessors) {
// Get/SetFindBarController are virtual methods implemented in
// FindBarBridge, so we test them here.
FindBarBridge* bridge = new FindBarBridge(NULL);
FindBarController controller(bridge, // takes ownership of |bridge|.
nullptr);
bridge->SetFindBarController(&controller);
EXPECT_EQ(&controller, bridge->GetFindBarController());
}
} // namespace
// Copyright (c) 2012 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.
#include "base/mac/foundation_util.h"
#include "base/run_loop.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_window.h"
#import "chrome/browser/ui/cocoa/browser_window_controller.h"
#include "chrome/browser/ui/cocoa/find_bar/find_bar_bridge.h"
#include "chrome/browser/ui/cocoa/find_bar/find_bar_cocoa_controller.h"
#include "chrome/browser/ui/cocoa/find_bar/find_bar_text_field.h"
#import "chrome/browser/ui/cocoa/test/run_loop_testing.h"
#include "chrome/browser/ui/exclusive_access/fullscreen_controller_test.h"
#include "chrome/browser/ui/find_bar/find_bar.h"
#include "chrome/browser/ui/find_bar/find_bar_controller.h"
#include "chrome/browser/ui/location_bar/location_bar.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "chrome/test/views/scoped_macviews_browser_mode.h"
#include "ui/base/test/ui_controls.h"
#import "ui/events/test/cocoa_test_event_utils.h"
// Expose private variables to make testing easier.
@implementation FindBarCocoaController (Testing)
- (NSButton*)nextButton {
return nextButton_;
}
- (NSButton*)previousButton {
return previousButton_;
}
@end
using content::WebContents;
using base::ASCIIToUTF16;
namespace {
const char kSimplePage[] = "simple.html";
bool FindBarHasFocus(Browser* browser) {
NSWindow* window = browser->window()->GetNativeWindow();
NSText* text_view = base::mac::ObjCCast<NSText>([window firstResponder]);
return [[text_view delegate] isKindOfClass:[FindBarTextField class]];
}
GURL GetTestURL(const std::string& filename) {
return ui_test_utils::GetTestUrl(base::FilePath().AppendASCII("find_in_page"),
base::FilePath().AppendASCII(filename));
}
FindBarCocoaController* GetFindBarCocoaController(Browser* browser) {
FindBarBridge* bridge =
static_cast<FindBarBridge*>(browser->GetFindBarController()->find_bar());
return bridge->find_bar_cocoa_controller();
}
NSButton* GetFindBarControllerNextButton(Browser* browser) {
FindBarCocoaController* cocoacontroller = GetFindBarCocoaController(browser);
return [cocoacontroller nextButton];
}
NSButton* GetFindBarControllerPreviousButton(Browser* browser) {
FindBarCocoaController* cocoacontroller = GetFindBarCocoaController(browser);
return [cocoacontroller previousButton];
}
int GetFindInContentsMatchCount(WebContents* contents,
const base::string16& search_string) {
return ui_test_utils::FindInPage(contents, search_string, true, false, NULL,
NULL);
}
void SimulateKeyPress(NSWindow* window, ui::KeyboardCode key) {
base::RunLoop run_loop;
ui_controls::EnableUIControls();
ui_controls::SendKeyPressNotifyWhenDone(window, key, false, false, false,
false, run_loop.QuitClosure());
run_loop.Run();
}
} // namespace
class FindBarBrowserTest : public InProcessBrowserTest {
private:
test::ScopedMacViewsBrowserMode cocoa_browser_mode_{false};
};
// Disabled. See https://crbug.com/845389 - this regressed somewhere between
// r545258 and r559030, but it may be obsolete soon.
IN_PROC_BROWSER_TEST_F(FindBarBrowserTest, DISABLED_FocusOnTabSwitch) {
AddTabAtIndex(1, GURL("about:blank"), ui::PAGE_TRANSITION_LINK);
browser()->GetFindBarController()->Show();
// Verify that if the find bar has focus then switching tabs and changing
// back sets focus back to the find bar.
browser()->GetFindBarController()->find_bar()->SetFocusAndSelection();
EXPECT_TRUE(FindBarHasFocus(browser()));
browser()->tab_strip_model()->ActivateTabAt(0, true);
EXPECT_FALSE(FindBarHasFocus(browser()));
browser()->tab_strip_model()->ActivateTabAt(1, true);
EXPECT_TRUE(FindBarHasFocus(browser()));
// Verify that if the find bar does not have focus then switching tabs and
// changing does not set focus to the find bar.
browser()->window()->GetLocationBar()->FocusLocation(true);
EXPECT_FALSE(FindBarHasFocus(browser()));
browser()->tab_strip_model()->ActivateTabAt(0, true);
EXPECT_FALSE(FindBarHasFocus(browser()));
browser()->tab_strip_model()->ActivateTabAt(1, true);
EXPECT_FALSE(FindBarHasFocus(browser()));
}
IN_PROC_BROWSER_TEST_F(FindBarBrowserTest,
NextPreviousButtonsDisabledAfterFocusChange) {
ui_test_utils::NavigateToURL(browser(), GetTestURL(kSimplePage));
browser()->GetFindBarController()->Show();
browser()->GetFindBarController()->find_bar()->SetFocusAndSelection();
EXPECT_TRUE(FindBarHasFocus(browser()));
// Simulate key press for character not in page contents.
SimulateKeyPress(browser()->window()->GetNativeWindow(), ui::VKEY_Z);
WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents();
EXPECT_EQ(GetFindInContentsMatchCount(contents, ASCIIToUTF16("Z")), 0);
// Buttons should be disabled as there were no results.
NSButton* nextButton = GetFindBarControllerNextButton(browser());
NSButton* previousButton = GetFindBarControllerPreviousButton(browser());
EXPECT_FALSE([nextButton isEnabled]);
EXPECT_FALSE([previousButton isEnabled]);
// Move focus to the location bar then back to the find bar.
browser()->window()->GetLocationBar()->FocusLocation(true);
EXPECT_FALSE(FindBarHasFocus(browser()));
browser()->GetFindBarController()->find_bar()->SetFocusAndSelection();
EXPECT_TRUE(FindBarHasFocus(browser()));
// Buttons should remain disabled.
EXPECT_FALSE([nextButton isEnabled]);
EXPECT_FALSE([previousButton isEnabled]);
}
IN_PROC_BROWSER_TEST_F(FindBarBrowserTest,
NextPreviousButtonsEnabledAfterFocusChange) {
ui_test_utils::NavigateToURL(browser(), GetTestURL(kSimplePage));
browser()->GetFindBarController()->Show();
browser()->GetFindBarController()->find_bar()->SetFocusAndSelection();
EXPECT_TRUE(FindBarHasFocus(browser()));
// Simulate key press for character in page contents.
SimulateKeyPress(browser()->window()->GetNativeWindow(), ui::VKEY_A);
WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents();
EXPECT_GT(GetFindInContentsMatchCount(contents, ASCIIToUTF16("A")), 0);
// Buttons should be enabled because we had results.
NSButton* nextButton = GetFindBarControllerNextButton(browser());
NSButton* previousButton = GetFindBarControllerPreviousButton(browser());
EXPECT_TRUE([nextButton isEnabled]);
EXPECT_TRUE([previousButton isEnabled]);
// Move focus to the location bar then back to the find bar.
browser()->window()->GetLocationBar()->FocusLocation(true);
EXPECT_FALSE(FindBarHasFocus(browser()));
browser()->GetFindBarController()->find_bar()->SetFocusAndSelection();
EXPECT_TRUE(FindBarHasFocus(browser()));
// Buttons should remain enabled.
EXPECT_TRUE([nextButton isEnabled]);
EXPECT_TRUE([previousButton isEnabled]);
}
IN_PROC_BROWSER_TEST_F(FindBarBrowserTest,
NextPreviousButtonsEnabledAfterCloseAndTabSwitch) {
AddTabAtIndex(1, GURL("about:blank"), ui::PAGE_TRANSITION_LINK);
ui_test_utils::NavigateToURL(browser(), GetTestURL(kSimplePage));
browser()->GetFindBarController()->Show();
browser()->GetFindBarController()->find_bar()->SetFocusAndSelection();
EXPECT_TRUE(FindBarHasFocus(browser()));
// Simulate key press for character in page contents.
SimulateKeyPress(browser()->window()->GetNativeWindow(), ui::VKEY_A);
WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents();
EXPECT_GT(GetFindInContentsMatchCount(contents, ASCIIToUTF16("A")), 0);
// Close find bar, switch to another tab then switch back and reopen find bar.
FindBarCocoaController* controller = GetFindBarCocoaController(browser());
[controller close:nil];
browser()->tab_strip_model()->ActivateTabAt(1, true);
browser()->tab_strip_model()->ActivateTabAt(0, true);
browser()->GetFindBarController()->Show();
browser()->GetFindBarController()->find_bar()->SetFocusAndSelection();
NSButton* nextButton = GetFindBarControllerNextButton(browser());
NSButton* previousButton = GetFindBarControllerPreviousButton(browser());
EXPECT_TRUE([nextButton isEnabled]);
EXPECT_TRUE([previousButton isEnabled]);
// Switch to another tab again and reopen find bar.
[controller close:nil];
browser()->tab_strip_model()->ActivateTabAt(1, true);
browser()->GetFindBarController()->Show();
browser()->GetFindBarController()->find_bar()->SetFocusAndSelection();
EXPECT_TRUE([nextButton isEnabled]);
EXPECT_TRUE([previousButton isEnabled]);
}
// Disabled. See https://crbug.com/845389 - this regressed somewhere between
// r545258 and r559030, but it may be obsolete soon.
IN_PROC_BROWSER_TEST_F(FindBarBrowserTest, DISABLED_EscapeKey) {
// Enter fullscreen.
std::unique_ptr<FullscreenNotificationObserver> waiter(
new FullscreenNotificationObserver());
browser()
->exclusive_access_manager()
->fullscreen_controller()
->ToggleBrowserFullscreenMode();
waiter->Wait();
NSWindow* window = browser()->window()->GetNativeWindow();
BrowserWindowController* bwc =
[BrowserWindowController browserWindowControllerForWindow:window];
EXPECT_TRUE([bwc isInAppKitFullscreen]);
// Show and focus on the find bar.
browser()->GetFindBarController()->Show();
browser()->GetFindBarController()->find_bar()->SetFocusAndSelection();
EXPECT_TRUE(FindBarHasFocus(browser()));
// Simulate a key press with the ESC key.
SimulateKeyPress(window, ui::VKEY_ESCAPE);
// Check that the browser is still in fullscreen and that the find bar has
// lost focus.
EXPECT_FALSE(FindBarHasFocus(browser()));
EXPECT_TRUE([bwc isInAppKitFullscreen]);
}
// Copyright (c) 2011 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_UI_COCOA_FIND_BAR_FIND_BAR_COCOA_CONTROLLER_H_
#define CHROME_BROWSER_UI_COCOA_FIND_BAR_FIND_BAR_COCOA_CONTROLLER_H_
#import <Cocoa/Cocoa.h>
#include "base/mac/scoped_nsobject.h"
#include "base/strings/string16.h"
#import "chrome/browser/ui/cocoa/has_weak_browser_pointer.h"
#include "ui/gfx/geometry/point.h"
class Browser;
class FindBarBridge;
@class FindBarTextField;
class FindNotificationDetails;
@class FocusTracker;
// A controller for the find bar in the browser window. Manages
// updating the state of the find bar and provides a target for the
// next/previous/close buttons. Certain operations require a pointer
// to the cross-platform FindBarController, so be sure to call
// setFindBarBridge: after creating this controller.
@interface FindBarCocoaController : NSViewController<HasWeakBrowserPointer> {
@private
IBOutlet NSView* findBarView_;
IBOutlet FindBarTextField* findText_;
IBOutlet NSButton* nextButton_;
IBOutlet NSButton* previousButton_;
IBOutlet NSButton* closeButton_;
// Needed to call methods on FindBarController.
FindBarBridge* findBarBridge_; // weak
Browser* browser_;
base::scoped_nsobject<FocusTracker> focusTracker_;
// The show/hide animation. This is defined to be non-nil if the
// animation is running, and is always nil otherwise. The
// FindBarCocoaController should not be deallocated while an animation is
// running (stopAnimation is currently called before the last tab in a
// window is removed).
base::scoped_nsobject<NSViewAnimation> showHideAnimation_;
// The horizontal-moving animation, to avoid occluding find results. This
// is nil when the animation is not running, and is also stopped by
// stopAnimation.
base::scoped_nsobject<NSViewAnimation> moveAnimation_;
// If YES, do nothing as a result of find pasteboard update notifications.
BOOL suppressPboardUpdateActions_;
// Vertical point of attachment of the FindBar.
CGFloat maxY_;
// Default width of FindBar.
CGFloat defaultWidth_;
};
@property (readonly, nonatomic) NSView* findBarView;
// Initializes a new FindBarCocoaController.
- (id)initWithBrowser:(Browser*)browser;
- (void)setFindBarBridge:(FindBarBridge*)findBar;
- (IBAction)close:(id)sender;
- (IBAction)nextResult:(id)sender;
- (IBAction)previousResult:(id)sender;
// Position the find bar at the given maximum y-coordinate (the min-y of the
// bar -- toolbar + possibly bookmark bar, but not including the infobars) with
// the given maximum width (i.e., the find bar should fit between 0 and
// |maxWidth|).
- (void)positionFindBarViewAtMaxY:(CGFloat)maxY maxWidth:(CGFloat)maxWidth;
// Methods called from FindBarBridge.
- (void)showFindBar:(BOOL)animate;
- (void)hideFindBar:(BOOL)animate;
- (void)stopAnimation;
- (void)setFocusAndSelection;
- (void)restoreSavedFocus;
- (void)setFindText:(NSString*)findText
selectedRange:(const NSRange&)selectedRange;
- (NSString*)findText;
- (NSRange)selectedRange;
- (NSString*)matchCountText;
- (void)updateFindBarForChangedWebContents;
- (void)clearResults:(const FindNotificationDetails&)results;
- (void)updateUIForFindResult:(const FindNotificationDetails&)results
withText:(const base::string16&)findText;
- (BOOL)isFindBarVisible;
- (BOOL)isFindBarAnimating;
// Returns the FindBar's position in the superview's coordinates, but with
// the Y coordinate growing down.
- (gfx::Point)findBarWindowPosition;
// Returns the width of the FindBar.
- (int)findBarWidth;
@end
#endif // CHROME_BROWSER_UI_COCOA_FIND_BAR_FIND_BAR_COCOA_CONTROLLER_H_
// Copyright (c) 2011 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.
#include "base/strings/string_util.h"
#include "base/strings/sys_string_conversions.h"
#include "chrome/browser/ui/browser_window.h"
#import "chrome/browser/ui/cocoa/find_bar/find_bar_cocoa_controller.h"
#import "chrome/browser/ui/cocoa/find_bar/find_bar_text_field.h"
#import "chrome/browser/ui/cocoa/test/cocoa_test_helper.h"
#include "chrome/browser/ui/find_bar/find_notification_details.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/platform_test.h"
#import "ui/base/cocoa/find_pasteboard.h"
// Expose private variables to make testing easier.
@interface FindBarCocoaController(Testing)
- (FindBarTextField*)findTextField;
@end
@implementation FindBarCocoaController(Testing)
- (FindBarTextField*)findTextField {
return findText_;
}
- (NSButton*)nextButton {
return nextButton_;
}
- (NSButton*)previousButton {
return previousButton_;
}
@end
namespace {
class FindBarCocoaControllerTest : public CocoaTest {
public:
void SetUp() override {
CocoaTest::SetUp();
controller_.reset([[FindBarCocoaController alloc] initWithBrowser:nil]);
[[test_window() contentView] addSubview:[controller_ view]];
}
void TearDown() override {
CocoaTest::TearDown();
[controller_ stopAnimation];
}
protected:
base::scoped_nsobject<FindBarCocoaController> controller_;
};
TEST_VIEW(FindBarCocoaControllerTest, [controller_ view])
TEST_F(FindBarCocoaControllerTest, ImagesLoadedProperly) {
EXPECT_TRUE([[[controller_ nextButton] image] isValid]);
EXPECT_TRUE([[[controller_ previousButton] image] isValid]);
}
TEST_F(FindBarCocoaControllerTest, ShowAndHide) {
NSView* findBarView = [controller_ findBarView];
ASSERT_GT([findBarView frame].origin.y, 0);
ASSERT_FALSE([controller_ isFindBarVisible]);
ASSERT_TRUE([[controller_ view] isHidden]);
[controller_ showFindBar:NO];
EXPECT_EQ([findBarView frame].origin.y, 0);
EXPECT_TRUE([controller_ isFindBarVisible]);
ASSERT_FALSE([[controller_ view] isHidden]);
[controller_ hideFindBar:NO];
EXPECT_GT([findBarView frame].origin.y, 0);
EXPECT_FALSE([controller_ isFindBarVisible]);
ASSERT_TRUE([[controller_ view] isHidden]);
}
TEST_F(FindBarCocoaControllerTest, SetFindText) {
NSTextField* findTextField = [controller_ findTextField];
// Start by making the find bar visible.
[controller_ showFindBar:NO];
EXPECT_TRUE([controller_ isFindBarVisible]);
// Set the find text.
NSString* const kFindText = @"Google";
[controller_ setFindText:kFindText selectedRange:NSMakeRange(NSNotFound, 0)];
EXPECT_EQ(
NSOrderedSame,
[[findTextField stringValue] compare:kFindText]);
// Call clearResults, which doesn't actually clear the find text but
// simply sets it back to what it was before. This is silly, but
// matches the behavior on other platforms. |details| isn't used by
// our implementation of clearResults, so it's ok to pass in an
// empty |details|.
FindNotificationDetails details;
[controller_ clearResults:details];
EXPECT_EQ(
NSOrderedSame,
[[findTextField stringValue] compare:kFindText]);
}
TEST_F(FindBarCocoaControllerTest, ResultLabelUpdatesCorrectly) {
// TODO(rohitrao): Test this. It may involve creating some dummy
// FindNotificationDetails objects.
}
TEST_F(FindBarCocoaControllerTest, FindTextIsGlobal) {
base::scoped_nsobject<FindBarCocoaController> otherController(
[[FindBarCocoaController alloc] initWithBrowser:nil]);
[[test_window() contentView] addSubview:[otherController view]];
// Setting the text in one controller should update the other controller's
// text as well.
NSString* const kFindText = @"Respect to the man in the ice cream van";
[controller_ setFindText:kFindText selectedRange:NSMakeRange(NSNotFound, 0)];
EXPECT_EQ(
NSOrderedSame,
[[controller_ findText] compare:kFindText]);
EXPECT_EQ(
NSOrderedSame,
[[otherController.get() findText] compare:kFindText]);
}
TEST_F(FindBarCocoaControllerTest, SettingFindTextUpdatesFindPboard) {
NSString* const kFindText =
@"It's not a bird, it's not a plane, it must be Dave who's on the train";
[controller_ setFindText:kFindText selectedRange:NSMakeRange(NSNotFound, 0)];
EXPECT_EQ(
NSOrderedSame,
[[[FindPasteboard sharedInstance] findText] compare:kFindText]);
}
} // namespace
// Copyright (c) 2012 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.
#include "chrome/browser/ui/find_bar/find_bar_host_unittest_util.h"
#include "build/buildflag.h"
#include "chrome/browser/ui/cocoa/find_bar/find_bar_bridge.h"
#include "ui/base/ui_features.h"
namespace chrome {
void DisableFindBarCocoaAnimationsDuringTesting(bool /* disable */) {
FindBarBridge::disable_animations_during_testing_ = true;
}
#if !BUILDFLAG(MAC_VIEWS_BROWSER)
void DisableFindBarAnimationsDuringTesting(bool disable) {
DisableFindBarCocoaAnimationsDuringTesting(disable);
}
#endif
} // namespace chrome
// Copyright (c) 2009 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_UI_COCOA_FIND_BAR_FIND_BAR_TEXT_FIELD_H_
#define CHROME_BROWSER_UI_COCOA_FIND_BAR_FIND_BAR_TEXT_FIELD_H_
#import <Cocoa/Cocoa.h>
#import "chrome/browser/ui/cocoa/styled_text_field.h"
@class FindBarTextFieldCell;
// TODO(rohitrao): This class may not need to exist, since it does not really
// add any functionality over StyledTextField. See if we can change the nib
// file to put a FindBarTextFieldCell into a StyledTextField.
// Extends StyledTextField to use a custom cell class (FindBarTextFieldCell).
@interface FindBarTextField : StyledTextField {
}
// Convenience method to return the cell, casted appropriately.
- (FindBarTextFieldCell*)findBarTextFieldCell;
@end
#endif // CHROME_BROWSER_UI_COCOA_FIND_BAR_FIND_BAR_TEXT_FIELD_H_
// 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/ui/cocoa/find_bar/find_bar_text_field.h"
#include "base/logging.h"
#include "base/mac/foundation_util.h"
#import "chrome/browser/ui/cocoa/find_bar/find_bar_text_field_cell.h"
#import "chrome/browser/ui/cocoa/view_id_util.h"
@implementation FindBarTextField
+ (Class)cellClass {
return [FindBarTextFieldCell class];
}
- (void)awakeFromNib {
DCHECK([[self cell] isKindOfClass:[FindBarTextFieldCell class]]);
[self registerForDraggedTypes:
[NSArray arrayWithObjects:NSStringPboardType, nil]];
}
- (FindBarTextFieldCell*)findBarTextFieldCell {
DCHECK([[self cell] isKindOfClass:[FindBarTextFieldCell class]]);
return static_cast<FindBarTextFieldCell*>([self cell]);
}
- (ViewID)viewID {
return VIEW_ID_FIND_IN_PAGE_TEXT_FIELD;
}
- (NSDragOperation)draggingEntered:(id<NSDraggingInfo>)info {
// When a drag enters the text field, focus the field. This will swap in the
// field editor, which will then handle the drag itself.
[[self window] makeFirstResponder:self];
return NSDragOperationNone;
}
// Disable default automated replacements, see <http://crbug.com/173405>.
- (void)textDidBeginEditing:(NSNotification*)aNotification {
// NSTextDidBeginEditingNotification is from NSText, but this only
// applies to NSTextView instances.
NSTextView* textView =
base::mac::ObjCCast<NSTextView>([aNotification object]);
NSTextCheckingTypes checkingTypes = [textView enabledTextCheckingTypes];
checkingTypes &= ~NSTextCheckingTypeReplacement;
checkingTypes &= ~NSTextCheckingTypeCorrection;
[textView setEnabledTextCheckingTypes:checkingTypes];
}
// Implemented to allow the findbar to respond to "Paste and Match Style" menu
// commands.
- (void)pasteAndMatchStyle:(id)sender {
[[self currentEditor] paste:sender];
}
@end
// Copyright (c) 2011 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_UI_COCOA_FIND_BAR_FIND_BAR_TEXT_FIELD_CELL_H_
#define CHROME_BROWSER_UI_COCOA_FIND_BAR_FIND_BAR_TEXT_FIELD_CELL_H_
#import <Cocoa/Cocoa.h>
#import "chrome/browser/ui/cocoa/styled_text_field_cell.h"
#include "base/mac/scoped_nsobject.h"
// FindBarTextFieldCell extends StyledTextFieldCell to provide support for a
// results label rooted at the right edge of the cell.
@interface FindBarTextFieldCell : StyledTextFieldCell {
@private
// Set if there is a results label to display on the right side of the cell.
base::scoped_nsobject<NSAttributedString> resultsString_;
}
// Sets the results label to the localized equivalent of "X of Y".
- (void)setActiveMatch:(NSInteger)current of:(NSInteger)total;
- (void)clearResults;
- (NSString*)resultsString;
@end
#endif // CHROME_BROWSER_UI_COCOA_FIND_BAR_FIND_BAR_TEXT_FIELD_CELL_H_
// Copyright (c) 2009 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/ui/cocoa/find_bar/find_bar_text_field_cell.h"
#include "base/logging.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/strings/sys_string_conversions.h"
#include "components/strings/grit/components_strings.h"
#include "ui/base/l10n/l10n_util.h"
namespace {
// How far to offset the keyword token into the field.
const NSInteger kResultsXOffset = 3;
// How much width (beyond text) to add to the keyword token on each
// side.
const NSInteger kResultsTokenInset = 3;
// How far to shift bounding box of hint down from top of field.
// Assumes -setFlipped:YES.
const NSInteger kResultsYOffset = 4;
// Conveniences to centralize width+offset calculations.
CGFloat WidthForResults(NSAttributedString* resultsString) {
return kResultsXOffset + ceil([resultsString size].width) +
2 * kResultsTokenInset;
}
} // namespace
@implementation FindBarTextFieldCell
- (CGFloat)topTextFrameOffset {
return 1.0;
}
- (CGFloat)bottomTextFrameOffset {
return 1.0;
}
- (CGFloat)cornerRadius {
return 4.0;
}
- (rect_path_utils::RoundedCornerFlags)roundedCornerFlags {
return rect_path_utils::RoundedCornerLeft;
}
// Convenience for the attributes used in the right-justified info
// cells. Sets the background color to red if |foundMatches| is YES.
- (NSDictionary*)resultsAttributes:(BOOL)foundMatches {
base::scoped_nsobject<NSMutableParagraphStyle> style(
[[NSMutableParagraphStyle alloc] init]);
[style setAlignment:NSRightTextAlignment];
return [NSDictionary dictionaryWithObjectsAndKeys:
[self font], NSFontAttributeName,
[NSColor lightGrayColor], NSForegroundColorAttributeName,
[NSColor whiteColor], NSBackgroundColorAttributeName,
style.get(), NSParagraphStyleAttributeName,
nil];
}
- (void)setActiveMatch:(NSInteger)current of:(NSInteger)total {
NSString* results =
base::SysUTF16ToNSString(l10n_util::GetStringFUTF16(
IDS_FIND_IN_PAGE_COUNT,
base::IntToString16(current),
base::IntToString16(total)));
resultsString_.reset([[NSAttributedString alloc]
initWithString:results
attributes:[self resultsAttributes:(total > 0)]]);
}
- (void)clearResults {
resultsString_.reset(nil);
}
- (NSString*)resultsString {
return [resultsString_ string];
}
- (NSRect)textFrameForFrame:(NSRect)cellFrame {
NSRect textFrame([super textFrameForFrame:cellFrame]);
if (resultsString_)
textFrame.size.width -= WidthForResults(resultsString_);
return textFrame;
}
// Do not show the I-beam cursor over the results label.
- (NSRect)textCursorFrameForFrame:(NSRect)cellFrame {
return [self textFrameForFrame:cellFrame];
}
- (void)drawResultsWithFrame:(NSRect)cellFrame inView:(NSView*)controlView {
DCHECK(resultsString_);
NSRect textFrame = [self textFrameForFrame:cellFrame];
NSRect infoFrame(NSMakeRect(NSMaxX(textFrame),
cellFrame.origin.y + kResultsYOffset,
ceil([resultsString_ size].width),
cellFrame.size.height - kResultsYOffset));
[resultsString_.get() drawInRect:infoFrame];
}
- (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView*)controlView {
if (resultsString_)
[self drawResultsWithFrame:cellFrame inView:controlView];
[super drawInteriorWithFrame:cellFrame inView:controlView];
}
@end
// Copyright (c) 2011 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 <Cocoa/Cocoa.h>
#include "base/mac/scoped_nsobject.h"
#import "chrome/browser/ui/cocoa/find_bar/find_bar_text_field_cell.h"
#import "chrome/browser/ui/cocoa/test/cocoa_test_helper.h"
#include "testing/gtest/include/gtest/gtest.h"
#import "testing/gtest_mac.h"
#include "testing/platform_test.h"
@interface FindBarTextFieldCell (ExposedForTesting)
- (NSAttributedString*)resultsAttributedString;
@end
@implementation FindBarTextFieldCell (ExposedForTesting)
- (NSAttributedString*)resultsAttributedString {
return resultsString_.get();
}
@end
namespace {
// Width of the field so that we don't have to ask |field_| for it all
// the time.
const CGFloat kWidth(300.0);
class FindBarTextFieldCellTest : public CocoaTest {
public:
FindBarTextFieldCellTest() {
// Make sure this is wide enough to play games with the cell
// decorations.
const NSRect frame = NSMakeRect(0, 0, kWidth, 30);
base::scoped_nsobject<FindBarTextFieldCell> cell(
[[FindBarTextFieldCell alloc] initTextCell:@"Testing"]);
cell_ = cell;
[cell_ setEditable:YES];
[cell_ setBordered:YES];
base::scoped_nsobject<NSTextField> view(
[[NSTextField alloc] initWithFrame:frame]);
view_ = view;
[view_ setCell:cell_];
[[test_window() contentView] addSubview:view_];
}
NSTextField* view_;
FindBarTextFieldCell* cell_;
};
// Basic view tests (AddRemove, Display).
TEST_VIEW(FindBarTextFieldCellTest, view_);
// Test drawing, mostly to ensure nothing leaks or crashes.
TEST_F(FindBarTextFieldCellTest, FocusedDisplay) {
[view_ display];
// Test focused drawing.
[test_window() makePretendKeyWindowAndSetFirstResponder:view_];
[view_ display];
[test_window() clearPretendKeyWindowAndFirstResponder];
// Test display of various cell configurations.
[cell_ setActiveMatch:4 of:30];
[view_ display];
[cell_ setActiveMatch:0 of:0];
[view_ display];
[cell_ clearResults];
[view_ display];
}
// Verify that setting and clearing the find results changes the results string
// appropriately.
TEST_F(FindBarTextFieldCellTest, SetAndClearFindResults) {
[cell_ setActiveMatch:10 of:30];
base::scoped_nsobject<NSAttributedString> tenString(
[[cell_ resultsAttributedString] copy]);
EXPECT_GT([tenString length], 0U);
[cell_ setActiveMatch:0 of:0];
base::scoped_nsobject<NSAttributedString> zeroString(
[[cell_ resultsAttributedString] copy]);
EXPECT_GT([zeroString length], 0U);
EXPECT_FALSE([tenString isEqualToAttributedString:zeroString]);
[cell_ clearResults];
EXPECT_EQ(0U, [[cell_ resultsAttributedString] length]);
}
TEST_F(FindBarTextFieldCellTest, TextFrame) {
const NSRect bounds = [view_ bounds];
NSRect textFrame = [cell_ textFrameForFrame:bounds];
NSRect cursorFrame = [cell_ textCursorFrameForFrame:bounds];
// At default settings, everything goes to the text area.
EXPECT_FALSE(NSIsEmptyRect(textFrame));
EXPECT_TRUE(NSContainsRect(bounds, textFrame));
EXPECT_EQ(NSMinX(bounds), NSMinX(textFrame));
EXPECT_EQ(NSMaxX(bounds), NSMaxX(textFrame));
EXPECT_NSEQ(cursorFrame, textFrame);
// Setting an active match leaves text frame to left.
[cell_ setActiveMatch:4 of:5];
textFrame = [cell_ textFrameForFrame:bounds];
cursorFrame = [cell_ textCursorFrameForFrame:bounds];
EXPECT_FALSE(NSIsEmptyRect(textFrame));
EXPECT_TRUE(NSContainsRect(bounds, textFrame));
EXPECT_LT(NSMaxX(textFrame), NSMaxX(bounds));
EXPECT_NSEQ(cursorFrame, textFrame);
}
// The editor frame should be slightly inset from the text frame.
TEST_F(FindBarTextFieldCellTest, DrawingRectForBounds) {
const NSRect bounds = [view_ bounds];
NSRect textFrame = [cell_ textFrameForFrame:bounds];
NSRect drawingRect = [cell_ drawingRectForBounds:bounds];
EXPECT_FALSE(NSIsEmptyRect(drawingRect));
EXPECT_TRUE(NSContainsRect(textFrame, NSInsetRect(drawingRect, 1, 1)));
[cell_ setActiveMatch:4 of:5];
textFrame = [cell_ textFrameForFrame:bounds];
drawingRect = [cell_ drawingRectForBounds:bounds];
EXPECT_FALSE(NSIsEmptyRect(drawingRect));
EXPECT_TRUE(NSContainsRect(textFrame, NSInsetRect(drawingRect, 1, 1)));
}
} // namespace
// Copyright (c) 2012 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 <Cocoa/Cocoa.h>
#include "base/mac/scoped_nsobject.h"
#import "chrome/browser/ui/cocoa/find_bar/find_bar_text_field.h"
#import "chrome/browser/ui/cocoa/find_bar/find_bar_text_field_cell.h"
#import "chrome/browser/ui/cocoa/test/cocoa_test_helper.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/platform_test.h"
namespace {
// Width of the field so that we don't have to ask |field_| for it all
// the time.
static const CGFloat kWidth(300.0);
class FindBarTextFieldTest : public CocoaTest {
public:
FindBarTextFieldTest() {
// Make sure this is wide enough to play games with the cell
// decorations.
NSRect frame = NSMakeRect(0, 0, kWidth, 30);
base::scoped_nsobject<FindBarTextField> field(
[[FindBarTextField alloc] initWithFrame:frame]);
field_ = field.get();
[field_ setStringValue:@"Test test"];
[[test_window() contentView] addSubview:field_];
}
FindBarTextField* field_;
};
// Basic view tests (AddRemove, Display).
TEST_VIEW(FindBarTextFieldTest, field_);
// Test that we have the right cell class.
TEST_F(FindBarTextFieldTest, CellClass) {
EXPECT_TRUE([[field_ cell] isKindOfClass:[FindBarTextFieldCell class]]);
}
// Test that we get the same cell from -cell and
// -findBarTextFieldCell.
TEST_F(FindBarTextFieldTest, Cell) {
FindBarTextFieldCell* cell = [field_ findBarTextFieldCell];
EXPECT_EQ(cell, [field_ cell]);
EXPECT_TRUE(cell != nil);
}
// Test that becoming first responder sets things up correctly.
TEST_F(FindBarTextFieldTest, FirstResponder) {
EXPECT_EQ(nil, [field_ currentEditor]);
EXPECT_EQ([[field_ subviews] count], 0U);
[test_window() makePretendKeyWindowAndSetFirstResponder:field_];
EXPECT_FALSE(nil == [field_ currentEditor]);
EXPECT_EQ([[field_ subviews] count], 1U);
EXPECT_TRUE([[field_ currentEditor] isDescendantOf:field_]);
}
// Test drawing, mostly to ensure nothing leaks or crashes.
TEST_F(FindBarTextFieldTest, Display) {
[field_ display];
// Test focussed drawing.
[test_window() makePretendKeyWindowAndSetFirstResponder:field_];
[field_ display];
[test_window() clearPretendKeyWindowAndFirstResponder];
// Test display of various cell configurations.
FindBarTextFieldCell* cell = [field_ findBarTextFieldCell];
[cell setActiveMatch:4 of:5];
[field_ display];
[cell clearResults];
[field_ display];
}
} // namespace
// Copyright (c) 2011 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_UI_COCOA_FIND_BAR_FIND_BAR_VIEW_COCOA_H_
#define CHROME_BROWSER_UI_COCOA_FIND_BAR_FIND_BAR_VIEW_COCOA_H_
#import <Cocoa/Cocoa.h>
#include "chrome/browser/ui/cocoa/background_gradient_view.h"
// A view that handles painting the border for the FindBar.
@interface FindBarView : BackgroundGradientView {
}
// Specifies that mouse events over this view should be ignored by the
// render host.
- (BOOL)nonWebContentView;
@end
#endif // CHROME_BROWSER_UI_COCOA_FIND_BAR_FIND_BAR_VIEW_COCOA_H_
// Copyright (c) 2011 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/ui/cocoa/find_bar/find_bar_view_cocoa.h"
#import "chrome/browser/ui/cocoa/url_drop_target.h"
#import "chrome/browser/ui/cocoa/view_id_util.h"
#import "ui/base/cocoa/nsview_additions.h"
#include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h"
namespace {
CGFloat kCurveSize = 8;
} // end namespace
@implementation FindBarView
- (id)initWithFrame:(NSRect)frame {
if ((self = [super initWithFrame:frame])) {
// Give this view its own layer so that it can appear over the web contents
// view's layer. Layer squashing is not helpful for this view because
// NSTextField will correctly anti-alias text on 10.8 and beyond.
[self setWantsLayer:YES];
}
return self;
}
- (void)awakeFromNib {
// Register for all the drag types handled by the RWHVCocoa.
[self registerForDraggedTypes:[URLDropTargetHandler handledDragTypes]];
}
- (void)drawRect:(NSRect)dirtyRect {
const CGFloat lineWidth = [self cr_lineWidth];
const CGFloat halfLineWidth = lineWidth / 2.0;
// TODO(rohitrao): Make this prettier.
NSRect rect = NSInsetRect([self bounds], halfLineWidth, halfLineWidth);
rect = NSOffsetRect(rect, 0, lineWidth);
NSPoint topLeft = NSMakePoint(NSMinX(rect), NSMaxY(rect));
NSPoint topRight = NSMakePoint(NSMaxX(rect), NSMaxY(rect));
NSPoint midLeft1 =
NSMakePoint(NSMinX(rect) + kCurveSize, NSMaxY(rect) - kCurveSize);
NSPoint midLeft2 =
NSMakePoint(NSMinX(rect) + kCurveSize, NSMinY(rect) + kCurveSize);
NSPoint midRight1 =
NSMakePoint(NSMaxX(rect) - kCurveSize, NSMinY(rect) + kCurveSize);
NSPoint midRight2 =
NSMakePoint(NSMaxX(rect) - kCurveSize, NSMaxY(rect) - kCurveSize);
NSPoint bottomLeft =
NSMakePoint(NSMinX(rect) + (2 * kCurveSize), NSMinY(rect));
NSPoint bottomRight =
NSMakePoint(NSMaxX(rect) - (2 * kCurveSize), NSMinY(rect));
NSBezierPath* path = [NSBezierPath bezierPath];
[path moveToPoint:topLeft];
[path curveToPoint:midLeft1
controlPoint1:NSMakePoint(midLeft1.x, topLeft.y)
controlPoint2:NSMakePoint(midLeft1.x, topLeft.y)];
[path lineToPoint:midLeft2];
[path curveToPoint:bottomLeft
controlPoint1:NSMakePoint(midLeft2.x, bottomLeft.y)
controlPoint2:NSMakePoint(midLeft2.x, bottomLeft.y)];
[path lineToPoint:bottomRight];
[path curveToPoint:midRight1
controlPoint1:NSMakePoint(midRight1.x, bottomLeft.y)
controlPoint2:NSMakePoint(midRight1.x, bottomLeft.y)];
[path lineToPoint:midRight2];
[path curveToPoint:topRight
controlPoint1:NSMakePoint(midRight2.x, topLeft.y)
controlPoint2:NSMakePoint(midRight2.x, topLeft.y)];
{
gfx::ScopedNSGraphicsContextSaveGState scopedGState;
[path addClip];
[self drawBackground:dirtyRect];
}
[[self strokeColor] set];
[path setLineWidth:lineWidth];
[path stroke];
}
// The findbar is mostly opaque, but has an 8px transparent border on the left
// and right sides (see |kCurveSize|). This is an artifact of the way it is
// drawn. We override hitTest to return nil for points in this transparent
// area.
- (NSView*)hitTest:(NSPoint)point {
NSView* hitView = [super hitTest:point];
if (hitView == self) {
// |rect| is approximately equivalent to the opaque area of the findbar.
NSRect rect = NSInsetRect([self bounds], kCurveSize, 0);
if (!NSMouseInRect(point, rect, [self isFlipped]))
return nil;
}
return hitView;
}
// Eat all mouse events, to prevent clicks from falling through to views below.
- (void)mouseDown:(NSEvent *)theEvent {
}
- (void)rightMouseDown:(NSEvent *)theEvent {
}
- (void)otherMouseDown:(NSEvent *)theEvent {
}
- (void)mouseUp:(NSEvent *)theEvent {
}
- (void)rightMouseUp:(NSEvent *)theEvent {
}
- (void)otherMouseUp:(NSEvent *)theEvent {
}
- (void)mouseMoved:(NSEvent *)theEvent {
}
- (void)mouseDragged:(NSEvent *)theEvent {
}
- (void)rightMouseDragged:(NSEvent *)theEvent {
}
- (void)otherMouseDragged:(NSEvent *)theEvent {
}
// Eat drag operations, to prevent drags from going through to the views below.
- (NSDragOperation)draggingEntered:(id<NSDraggingInfo>)info {
return NSDragOperationNone;
}
// Specifies that mouse events over this view should be ignored by the
// render host.
- (BOOL)nonWebContentView {
return YES;
}
@end
// Copyright (c) 2011 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 <Cocoa/Cocoa.h>
#include "base/mac/scoped_nsobject.h"
#import "chrome/browser/ui/cocoa/find_bar/find_bar_view_cocoa.h"
#import "chrome/browser/ui/cocoa/test/cocoa_test_helper.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/platform_test.h"
#include "ui/events/test/cocoa_test_event_utils.h"
@interface MouseDownViewPong : NSView {
BOOL pong_;
}
@property (nonatomic, assign) BOOL pong;
@end
@implementation MouseDownViewPong
@synthesize pong = pong_;
- (void)mouseDown:(NSEvent*)event {
pong_ = YES;
}
@end
namespace {
class FindBarViewTest : public CocoaTest {
public:
FindBarViewTest() {
NSRect frame = NSMakeRect(0, 0, 100, 30);
base::scoped_nsobject<FindBarView> view(
[[FindBarView alloc] initWithFrame:frame]);
view_ = view.get();
[[test_window() contentView] addSubview:view_];
}
FindBarView* view_;
};
TEST_VIEW(FindBarViewTest, view_)
TEST_F(FindBarViewTest, FindBarEatsMouseClicksInBackgroundArea) {
base::scoped_nsobject<MouseDownViewPong> pongView(
[[MouseDownViewPong alloc] initWithFrame:NSMakeRect(0, 0, 200, 200)]);
// Remove all of the subviews of the findbar, to make sure we don't
// accidentally hit a subview when trying to simulate a click in the
// background area.
[view_ setSubviews:[NSArray array]];
[view_ setFrame:NSMakeRect(0, 0, 200, 200)];
// Add the pong view as a sibling of the findbar.
[[test_window() contentView] addSubview:pongView.get()
positioned:NSWindowBelow
relativeTo:view_];
// Synthesize a mousedown event and send it to the window. The event is
// placed in the center of the find bar.
NSPoint pointInCenterOfFindBar = NSMakePoint(100, 100);
[pongView setPong:NO];
[test_window() sendEvent:
cocoa_test_event_utils::LeftMouseDownAtPoint(pointInCenterOfFindBar)];
// Click gets eaten by findbar, not passed through to underlying view.
EXPECT_FALSE([pongView pong]);
}
TEST_F(FindBarViewTest, FindBarPassesThroughClicksInTransparentArea) {
base::scoped_nsobject<MouseDownViewPong> pongView(
[[MouseDownViewPong alloc] initWithFrame:NSMakeRect(0, 0, 200, 200)]);
[view_ setFrame:NSMakeRect(0, 0, 200, 200)];
// Add the pong view as a sibling of the findbar.
[[test_window() contentView] addSubview:pongView.get()
positioned:NSWindowBelow
relativeTo:view_];
// Synthesize a mousedown event and send it to the window. The event is inset
// a few pixels from the lower left corner of the window, which places it in
// the transparent area surrounding the findbar.
NSPoint pointInTransparentArea = NSMakePoint(2, 2);
[pongView setPong:NO];
[test_window() sendEvent:
cocoa_test_event_utils::LeftMouseDownAtPoint(pointInTransparentArea)];
// Click is ignored by findbar, passed through to underlying view.
EXPECT_TRUE([pongView pong]);
}
} // namespace
......@@ -11,9 +11,6 @@ namespace chrome {
#if defined(TOOLKIT_VIEWS)
void DisableFindBarAnimationsDuringTesting(bool disable);
#if defined(OS_MACOSX)
void DisableFindBarCocoaAnimationsDuringTesting(bool disable);
#endif
#else
static inline void DisableFindBarAnimationsDuringTesting(bool disable) {}
#endif
......
......@@ -20,7 +20,6 @@
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/interactive_test_utils.h"
#include "chrome/test/base/ui_test_utils.h"
#include "chrome/test/views/scoped_macviews_browser_mode.h"
#include "testing/gtest/include/gtest/gtest.h"
#import "ui/base/cocoa/find_pasteboard.h"
#include "url/gurl.h"
......@@ -32,12 +31,9 @@ GURL GetURL(const std::string& filename) {
base::FilePath().AppendASCII(filename));
}
class FindBarPlatformHelperMacInteractiveUITest
: public InProcessBrowserTest,
public testing::WithParamInterface<bool> {
class FindBarPlatformHelperMacInteractiveUITest : public InProcessBrowserTest {
public:
FindBarPlatformHelperMacInteractiveUITest()
: scoped_macviews_browser_mode_(GetParam()) {}
FindBarPlatformHelperMacInteractiveUITest() {}
~FindBarPlatformHelperMacInteractiveUITest() override = default;
void SetUpOnMainThread() override {
......@@ -50,20 +46,14 @@ class FindBarPlatformHelperMacInteractiveUITest
InProcessBrowserTest::TearDownOnMainThread();
}
static std::string ParamInfoToString(
::testing::TestParamInfo<bool> param_info) {
return param_info.param ? "Views" : "Cocoa";
}
private:
test::ScopedMacViewsBrowserMode scoped_macviews_browser_mode_;
NSString* old_find_text_ = nullptr;
DISALLOW_COPY_AND_ASSIGN(FindBarPlatformHelperMacInteractiveUITest);
};
// Tests that the pasteboard is updated when the find bar is changed.
IN_PROC_BROWSER_TEST_P(FindBarPlatformHelperMacInteractiveUITest,
IN_PROC_BROWSER_TEST_F(FindBarPlatformHelperMacInteractiveUITest,
PasteboardUpdatedFromFindBar) {
FindBarController* find_bar_controller = browser()->GetFindBarController();
ASSERT_NE(nullptr, find_bar_controller);
......@@ -93,7 +83,7 @@ IN_PROC_BROWSER_TEST_P(FindBarPlatformHelperMacInteractiveUITest,
}
// Tests that the pasteboard is not updated from an incognito find bar.
IN_PROC_BROWSER_TEST_P(FindBarPlatformHelperMacInteractiveUITest,
IN_PROC_BROWSER_TEST_F(FindBarPlatformHelperMacInteractiveUITest,
IncognitoPasteboardNotUpdatedFromFindBar) {
Browser* browser_incognito = CreateIncognitoBrowser();
FindBarController* find_bar_controller =
......@@ -132,7 +122,7 @@ IN_PROC_BROWSER_TEST_P(FindBarPlatformHelperMacInteractiveUITest,
// FindInPageControllerTest.GlobalPasteBoardClearMatches.
// TODO(http://crbug.com/843878): Remove when referenced bug is fixed.
// Flaky. crbug.com/864585
IN_PROC_BROWSER_TEST_P(FindBarPlatformHelperMacInteractiveUITest,
IN_PROC_BROWSER_TEST_F(FindBarPlatformHelperMacInteractiveUITest,
DISABLED_GlobalPasteBoardClearMatches) {
FindBarController* find_bar_controller = browser()->GetFindBarController();
ASSERT_NE(nullptr, find_bar_controller);
......@@ -187,7 +177,7 @@ IN_PROC_BROWSER_TEST_P(FindBarPlatformHelperMacInteractiveUITest,
// Equivalent to browser_tests
// FindInPageControllerTest.IncognitoFindNextShared.
// TODO(http://crbug.com/843878): Remove when referenced bug is fixed.
IN_PROC_BROWSER_TEST_P(FindBarPlatformHelperMacInteractiveUITest,
IN_PROC_BROWSER_TEST_F(FindBarPlatformHelperMacInteractiveUITest,
IncognitoFindNextShared) {
chrome::Find(browser());
ASSERT_TRUE(
......@@ -220,7 +210,7 @@ IN_PROC_BROWSER_TEST_P(FindBarPlatformHelperMacInteractiveUITest,
// Equivalent to browser_tests
// FindInPageControllerTest.PreferPreviousSearch.
// TODO(http://crbug.com/843878): Remove when referenced bug is fixed.
IN_PROC_BROWSER_TEST_P(FindBarPlatformHelperMacInteractiveUITest,
IN_PROC_BROWSER_TEST_F(FindBarPlatformHelperMacInteractiveUITest,
PreferPreviousSearch) {
FindBarController* find_bar_controller = browser()->GetFindBarController();
ASSERT_NE(nullptr, find_bar_controller);
......@@ -275,9 +265,3 @@ IN_PROC_BROWSER_TEST_P(FindBarPlatformHelperMacInteractiveUITest,
base::ASCIIToUTF16("given"),
FindTabHelper::FromWebContents(first_active_web_contents)->find_text());
}
INSTANTIATE_TEST_CASE_P(
,
FindBarPlatformHelperMacInteractiveUITest,
::testing::Bool(),
FindBarPlatformHelperMacInteractiveUITest::ParamInfoToString);
......@@ -14,10 +14,6 @@ namespace chrome {
void DisableFindBarAnimationsDuringTesting(bool disable) {
DropdownBarHost::disable_animations_during_testing_ = disable;
#if defined(OS_MACOSX) && BUILDFLAG(MAC_VIEWS_BROWSER)
if (views_mode_controller::IsViewsBrowserCocoa())
DisableFindBarCocoaAnimationsDuringTesting(disable);
#endif
}
} // namespace chrome
......@@ -1973,7 +1973,6 @@ test("browser_tests") {
"../browser/ui/cocoa/apps/native_app_window_cocoa_browsertest.mm",
"../browser/ui/cocoa/dev_tools_controller_browsertest.mm",
"../browser/ui/cocoa/extensions/media_galleries_dialog_cocoa_browsertest.mm",
"../browser/ui/cocoa/find_bar/find_bar_browsertest.mm",
"../browser/ui/cocoa/location_bar/content_setting_decoration_browsertest.mm",
"../browser/ui/cocoa/location_bar/zoom_decoration_browsertest.mm",
"../browser/ui/cocoa/omnibox/omnibox_view_mac_browsertest.mm",
......@@ -4156,11 +4155,6 @@ test("unit_tests") {
"../browser/ui/cocoa/draggable_button_unittest.mm",
"../browser/ui/cocoa/extensions/browser_actions_container_view_unittest.mm",
"../browser/ui/cocoa/extensions/media_galleries_dialog_cocoa_unittest.mm",
"../browser/ui/cocoa/find_bar/find_bar_bridge_unittest.mm",
"../browser/ui/cocoa/find_bar/find_bar_cocoa_controller_unittest.mm",
"../browser/ui/cocoa/find_bar/find_bar_text_field_cell_unittest.mm",
"../browser/ui/cocoa/find_bar/find_bar_text_field_unittest.mm",
"../browser/ui/cocoa/find_bar/find_bar_view_unittest.mm",
"../browser/ui/cocoa/find_pasteboard_unittest.mm",
"../browser/ui/cocoa/first_run_dialog_controller_unittest.mm",
"../browser/ui/cocoa/floating_bar_backing_view_unittest.mm",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment