Implement find-in-page in MiniBrowser
authortimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 7 Jan 2017 21:09:41 +0000 (21:09 +0000)
committertimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 7 Jan 2017 21:09:41 +0000 (21:09 +0000)
https://bugs.webkit.org/show_bug.cgi?id=166799

Reviewed by Andy Estes.

* MiniBrowser/mac/BrowserWindow.xib:
* MiniBrowser/mac/BrowserWindowController.h:
* MiniBrowser/mac/BrowserWindowController.m:
(-[BrowserWindowController find:]): Deleted.
* MiniBrowser/mac/MainMenu.xib:
* MiniBrowser/mac/WK1BrowserWindowController.m:
(-[WK1BrowserWindowController toggleShrinkToFit:]):
(-[WK1BrowserWindowController find:]): Deleted.
* MiniBrowser/mac/WK2BrowserWindowController.m:
(-[WK2BrowserWindowController awakeFromNib]):
(-[WK2BrowserWindowController dealloc]):
(-[WK2BrowserWindowController validateMenuItem:]):
(-[WK2BrowserWindowController performTextFinderAction:]):
(-[WK2BrowserWindowController findBarView]):
(-[WK2BrowserWindowController setFindBarView:]):
(-[WK2BrowserWindowController isFindBarVisible]):
(-[WK2BrowserWindowController setFindBarVisible:]):
(-[WK2BrowserWindowController contentView]):
(-[WK2BrowserWindowController findBarViewDidChangeHeight]):
(-[WK2BrowserWindowController performFindPanelAction:]): Deleted.
(-[WK2BrowserWindowController find:]): Deleted.
Implement find-in-page using WKWebView's conformance to the NSTextFinderClient
protocol. At first glance, it's pretty broken, but vaguely works.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@210482 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Tools/ChangeLog
Tools/MiniBrowser/mac/BrowserWindow.xib
Tools/MiniBrowser/mac/BrowserWindowController.h
Tools/MiniBrowser/mac/BrowserWindowController.m
Tools/MiniBrowser/mac/MainMenu.xib
Tools/MiniBrowser/mac/WK1BrowserWindowController.m
Tools/MiniBrowser/mac/WK2BrowserWindowController.m

index 4710518..76ca17f 100644 (file)
@@ -1,5 +1,36 @@
 2017-01-07  Tim Horton  <timothy_horton@apple.com>
 
+        Implement find-in-page in MiniBrowser
+        https://bugs.webkit.org/show_bug.cgi?id=166799
+
+        Reviewed by Andy Estes.
+
+        * MiniBrowser/mac/BrowserWindow.xib:
+        * MiniBrowser/mac/BrowserWindowController.h:
+        * MiniBrowser/mac/BrowserWindowController.m:
+        (-[BrowserWindowController find:]): Deleted.
+        * MiniBrowser/mac/MainMenu.xib:
+        * MiniBrowser/mac/WK1BrowserWindowController.m:
+        (-[WK1BrowserWindowController toggleShrinkToFit:]):
+        (-[WK1BrowserWindowController find:]): Deleted.
+        * MiniBrowser/mac/WK2BrowserWindowController.m:
+        (-[WK2BrowserWindowController awakeFromNib]):
+        (-[WK2BrowserWindowController dealloc]):
+        (-[WK2BrowserWindowController validateMenuItem:]):
+        (-[WK2BrowserWindowController performTextFinderAction:]):
+        (-[WK2BrowserWindowController findBarView]):
+        (-[WK2BrowserWindowController setFindBarView:]):
+        (-[WK2BrowserWindowController isFindBarVisible]):
+        (-[WK2BrowserWindowController setFindBarVisible:]):
+        (-[WK2BrowserWindowController contentView]):
+        (-[WK2BrowserWindowController findBarViewDidChangeHeight]):
+        (-[WK2BrowserWindowController performFindPanelAction:]): Deleted.
+        (-[WK2BrowserWindowController find:]): Deleted.
+        Implement find-in-page using WKWebView's conformance to the NSTextFinderClient
+        protocol. At first glance, it's pretty broken, but vaguely works.
+
+2017-01-07  Tim Horton  <timothy_horton@apple.com>
+
         Share the implementation of MiniBrowser view hiding functionality
         https://bugs.webkit.org/show_bug.cgi?id=166800
 
index a462b90..5bdeede 100644 (file)
@@ -1,15 +1,14 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="11085" systemVersion="16A167" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none">
+<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="11191" systemVersion="16D17a" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none">
     <dependencies>
         <deployment identifier="macosx"/>
-        <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="11085"/>
+        <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="11191"/>
     </dependencies>
     <objects>
         <customObject id="-2" userLabel="File's Owner" customClass="BrowserWindowController">
             <connections>
                 <outlet property="backButton" destination="40" id="46"/>
                 <outlet property="containerView" destination="9" id="37"/>
-                <outlet property="findPanelWindow" destination="70" id="77"/>
                 <outlet property="forwardButton" destination="42" id="47"/>
                 <outlet property="progressIndicator" destination="21" id="33"/>
                 <outlet property="reloadButton" destination="23" id="34"/>
                 <outlet property="delegate" destination="-2" id="4"/>
             </connections>
         </window>
-        <window title="Find" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" hidesOnDeactivate="YES" oneShot="NO" releasedWhenClosed="NO" visibleAtLaunch="NO" animationBehavior="default" id="70" customClass="NSPanel">
-            <windowStyleMask key="styleMask" titled="YES" closable="YES" utility="YES" nonactivatingPanel="YES"/>
-            <windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
-            <rect key="contentRect" x="230" y="479" width="452" height="62"/>
-            <rect key="screenRect" x="0.0" y="0.0" width="1920" height="1177"/>
-            <view key="contentView" id="71">
-                <rect key="frame" x="0.0" y="0.0" width="452" height="62"/>
-                <autoresizingMask key="autoresizingMask"/>
-                <subviews>
-                    <searchField verticalHuggingPriority="750" id="74">
-                        <rect key="frame" x="20" y="20" width="412" height="22"/>
-                        <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
-                        <searchFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" borderStyle="bezel" usesSingleLineMode="YES" bezelStyle="round" id="75">
-                            <font key="font" metaFont="system"/>
-                            <color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
-                            <color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
-                        </searchFieldCell>
-                        <connections>
-                            <action selector="find:" target="-2" id="76"/>
-                        </connections>
-                    </searchField>
-                </subviews>
-            </view>
-        </window>
     </objects>
     <resources>
         <image name="NSEnterFullScreenTemplate" width="15" height="15"/>
index a9ceed7..5b85ce4 100644 (file)
@@ -35,8 +35,6 @@
     IBOutlet NSTextField *urlText;
     IBOutlet NSView *containerView;
     IBOutlet NSButton *toggleUseShrinkToFitButton;
-    
-    IBOutlet NSWindow *findPanelWindow;
 
     BOOL _zoomTextOnly;
 }
@@ -73,7 +71,6 @@
 - (IBAction)toggleShrinkToFit:(id)sender;
 
 - (IBAction)dumpSourceToConsole:(id)sender;
-- (IBAction)find:(id)sender;
 
 - (void)didChangeSettings;
 
index 92d8733..0c0f548 100644 (file)
     [self doesNotRecognizeSelector:_cmd];
 }
 
-- (IBAction)find:(id)sender
-{
-    [self doesNotRecognizeSelector:_cmd];
-}
-
 - (void)didChangeSettings
 {
     [self doesNotRecognizeSelector:_cmd];
index ec4e420..67a945f 100644 (file)
                                     <items>
                                         <menuItem title="Find…" tag="1" keyEquivalent="f" id="209">
                                             <connections>
-                                                <action selector="performFindPanelAction:" target="-1" id="241"/>
+                                                <action selector="performTextFinderAction:" target="-1" id="241"/>
                                             </connections>
                                         </menuItem>
                                         <menuItem title="Find Next" tag="2" keyEquivalent="g" id="208">
                                             <connections>
-                                                <action selector="performFindPanelAction:" target="-1" id="487"/>
+                                                <action selector="performTextFinderAction:" target="-1" id="487"/>
                                             </connections>
                                         </menuItem>
                                         <menuItem title="Find Previous" tag="3" keyEquivalent="G" id="213">
                                             <modifierMask key="keyEquivalentModifierMask" shift="YES" command="YES"/>
                                             <connections>
-                                                <action selector="performFindPanelAction:" target="-1" id="488"/>
+                                                <action selector="performTextFinderAction:" target="-1" id="488"/>
                                             </connections>
                                         </menuItem>
                                         <menuItem title="Use Selection for Find" tag="7" keyEquivalent="e" id="221">
                                             <connections>
-                                                <action selector="performFindPanelAction:" target="-1" id="489"/>
+                                                <action selector="performTextFinderAction:" target="-1" id="489"/>
                                             </connections>
                                         </menuItem>
                                         <menuItem title="Jump to Selection" keyEquivalent="j" id="210">
index 93c5ff7..bb428b5 100644 (file)
@@ -231,11 +231,6 @@ static BOOL areEssentiallyEqual(double a, double b)
 
 - (IBAction)toggleShrinkToFit:(id)sender
 {
-
-}
-
-- (IBAction)find:(id)sender
-{
 }
 
 - (IBAction)dumpSourceToConsole:(id)sender
index f2546da..1538463 100644 (file)
@@ -46,7 +46,7 @@ static void* keyValueObservingContext = &keyValueObservingContext;
 static const int testHeaderBannerHeight = 42;
 static const int testFooterBannerHeight = 58;
 
-@interface WK2BrowserWindowController () <WKNavigationDelegate, WKUIDelegate, _WKIconLoadingDelegate>
+@interface WK2BrowserWindowController () <NSTextFinderBarContainer, WKNavigationDelegate, WKUIDelegate, _WKIconLoadingDelegate>
 @end
 
 @implementation WK2BrowserWindowController {
@@ -56,6 +56,10 @@ static const int testFooterBannerHeight = 58;
     BOOL _isPrivateBrowsingWindow;
 
     BOOL _useShrinkToFit;
+
+    NSTextFinder *_textFinder;
+    NSView *_textFindBarView;
+    BOOL _findBarVisible;
 }
 
 - (void)awakeFromNib
@@ -90,6 +94,12 @@ static const int testFooterBannerHeight = 58;
         | _WKRenderingProgressEventFirstPaintAfterSuppressedIncrementalRendering;
 
     _zoomTextOnly = NO;
+
+    _textFinder = [[NSTextFinder alloc] init];
+    _textFinder.incrementalSearchingEnabled = YES;
+    _textFinder.incrementalSearchingShouldDimContentView = YES;
+    _textFinder.client = _webView;
+    _textFinder.findBarContainer = self;
 }
 
 - (instancetype)initWithConfiguration:(WKWebViewConfiguration *)configuration
@@ -111,6 +121,8 @@ static const int testFooterBannerHeight = 58;
     [progressIndicator unbind:NSHiddenBinding];
     [progressIndicator unbind:NSValueBinding];
 
+    [_textFinder release];
+
     [_webView release];
     [_configuration release];
 
@@ -169,7 +181,7 @@ static BOOL areEssentiallyEqual(double a, double b)
 
 - (BOOL)validateMenuItem:(NSMenuItem *)menuItem
 {
-    SEL action = [menuItem action];
+    SEL action = menuItem.action;
 
     if (action == @selector(zoomIn:))
         return [self canZoomIn];
@@ -180,7 +192,6 @@ static BOOL areEssentiallyEqual(double a, double b)
     
     // Disabled until missing WK2 functionality is exposed via API/SPI.
     if (action == @selector(dumpSourceToConsole:)
-        || action == @selector(find:)
         || action == @selector(forceRepaint:))
         return NO;
     
@@ -514,15 +525,6 @@ static BOOL areEssentiallyEqual(double a, double b)
     [self fetch:nil];
 }
 
-- (IBAction)performFindPanelAction:(id)sender
-{
-    [findPanelWindow makeKeyAndOrderFront:sender];
-}
-
-- (IBAction)find:(id)sender
-{
-}
-
 static NSSet *dataTypes()
 {
     return [WKWebsiteDataStore allWebsiteDataTypes];
@@ -657,6 +659,51 @@ static NSSet *dataTypes()
     });
 }
 
+#pragma mark Find in Page
+
+- (IBAction)performTextFinderAction:(id)sender
+{
+    [_textFinder performAction:[sender tag]];
+}
+
+- (NSView *)findBarView
+{
+    return _textFindBarView;
+}
+
+- (void)setFindBarView:(NSView *)findBarView
+{
+    if (_textFindBarView)
+        [_textFindBarView removeFromSuperview];
+    _textFindBarView = findBarView;
+    _findBarVisible = YES;
+    [containerView addSubview:_textFindBarView];
+    [_textFindBarView setFrame:NSMakeRect(0, 0, containerView.bounds.size.width, _textFindBarView.frame.size.height)];
+}
+
+- (BOOL)isFindBarVisible
+{
+    return _findBarVisible;
+}
+
+- (void)setFindBarVisible:(BOOL)findBarVisible
+{
+    _findBarVisible = findBarVisible;
+    if (findBarVisible)
+        [containerView addSubview:_textFindBarView];
+    else
+        [_textFindBarView removeFromSuperview];
+}
+
+- (NSView *)contentView
+{
+    return _webView;
+}
+
+- (void)findBarViewDidChangeHeight
+{
+}
+
 @end
 
 #endif // WK_API_ENABLED