Support TouchBar in WebKit
authorbdakin@apple.com <bdakin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 9 Nov 2016 19:16:09 +0000 (19:16 +0000)
committerbdakin@apple.com <bdakin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 9 Nov 2016 19:16:09 +0000 (19:16 +0000)
https://bugs.webkit.org/show_bug.cgi?id=164437
-and corresponding-
rdar://problem/28876524

Reviewed by Darin Adler.

Source/WebCore:

* WebCore.xcodeproj/project.pbxproj:
* platform/spi/cocoa/AVKitSPI.h:
* platform/spi/cocoa/NSTouchBarSPI.h: Added.
* platform/spi/mac/NSSpellCheckerSPI.h:

Source/WebKit/mac:

* WebCoreSupport/WebEditorClient.mm:
(WebEditorClient::respondToChangedSelection):
(WebEditorClient::updateEditorStateAfterLayoutIfEditabilityChanged):
* WebView/WebHTMLView.mm:
(-[WebHTMLView candidateListTouchBarItem]):
* WebView/WebView.mm:
(-[_WebTextListTouchBarViewController initWithWebView:]):
(-[_WebTextListTouchBarViewController _selectList:]):
(-[_WebTextListTouchBarViewController setCurrentListType:]):
(-[WebTextTouchBarItemController initWithWebView:]):
(-[WebTextTouchBarItemController itemForIdentifier:]):
(-[WebTextTouchBarItemController webTextListTouchBarViewController]):
(-[WebTextTouchBarItemController setTextIsBold:]):
(-[WebTextTouchBarItemController setTextIsItalic:]):
(-[WebTextTouchBarItemController setTextIsUnderlined:]):
(-[WebTextTouchBarItemController _webChangeTextStyle:]):
(-[WebTextTouchBarItemController setCurrentTextAlignment:]):
(-[WebTextTouchBarItemController _webChangeTextAlignment:]):
(-[WebTextTouchBarItemController textColor]):
(-[WebTextTouchBarItemController setTextColor:]):
(-[WebTextTouchBarItemController _webChangeColor:]):
(-[WebTextTouchBarItemController textListViewController]):
(-[WebView _commonInitializationWithFrameName:groupName:]):
(-[WebView showCandidates:forString:inRect:forSelectedRange:view:completionHandler:]):
(-[WebView shouldRequestCandidates]):
(-[WebView forceRequestCandidatesForTesting]):
(-[WebView makeTouchBar]):
(-[WebView touchBar:makeItemForIdentifier:]):
(textCheckingResultFromNSTextCheckingResult):
(-[WebView candidateListTouchBarItem:endSelectingCandidateAtIndex:]):
(-[WebView candidateListTouchBarItem:changedCandidateListVisibility:]):
(-[WebView _setUpPlaybackControlsManagerForMediaElement:]):
(-[WebView _clearPlaybackControlsManager]):
(-[WebView _dismissTextTouchBarPopoverItemWithIdentifier:]):
(-[WebView _textTouchBarCustomizationAllowedIdentifiers]):
(-[WebView _plainTextTouchBarCustomizationDefaultItemIdentifiers]):
(-[WebView _richTextTouchBarCustomizationDefaultItemIdentifiers]):
(-[WebView touchBarDidExitCustomization:]):
(-[WebView touchBarWillEnterCustomization:]):
(-[WebView didChangeAutomaticTextCompletion:]):
(-[WebView setUpTextTouchBar:]):
(-[WebView _isRichlyEditable]):
(-[WebView textTouchBar]):
(-[WebView updateTextTouchBar]):
(-[WebView updateMediaTouchBar]):
(-[WebView updateTouchBar]):
(-[WebView prepareForMouseDown]):
(-[WebView prepareForMouseUp]):
(-[WebView webViewAdditionsWillDestroyView]):
(-[WebView candidateList]):
(-[WebView updateWebViewAdditions]): Deleted.
* WebView/WebViewData.h:
* WebView/WebViewInternal.h:
* WebView/WebViewPrivate.h:

Source/WebKit2:

* UIProcess/API/Cocoa/WKViewPrivate.h:
* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView makeTouchBar]):
(-[WKWebView candidateListTouchBarItem]):
(-[WKWebView _web_didAddMediaControlsManager:]):
(-[WKWebView _web_didRemoveMediaControlsManager]):
(-[WKWebView _interactWithMediaControlsForTesting]):
(-[WKWebView _wantsMediaPlaybackControlsView]):
(-[WKWebView _setWantsMediaPlaybackControlsView:]):
(-[WKWebView _mediaPlaybackControlsView]):
(-[WKWebView _addMediaPlaybackControlsView:]):
(-[WKWebView _removeMediaPlaybackControlsView]):
* UIProcess/API/Cocoa/WKWebViewPrivate.h:
* UIProcess/API/mac/WKView.mm:
(-[WKView makeTouchBar]):
(-[WKView candidateListTouchBarItem]):
(-[WKView _web_didAddMediaControlsManager:]):
(-[WKView _web_didRemoveMediaControlsManager]):
(-[WKView _wantsMediaPlaybackControlsView]):
(-[WKView _setWantsMediaPlaybackControlsView:]):
(-[WKView _mediaPlaybackControlsView]):
(-[WKView _addMediaPlaybackControlsView:]):
(-[WKView _removeMediaPlaybackControlsView]):
* UIProcess/Cocoa/WebViewImpl.h:
(WebKit::WebViewImpl::currentTouchBar):
(WebKit::WebViewImpl::clientWantsMediaPlaybackControlsView):
(WebKit::WebViewImpl::setClientWantsMediaPlaybackControlsView):
(WebKit::WebViewImpl::setIsCustomizingTouchBar):
* UIProcess/Cocoa/WebViewImpl.mm:
(-[WKTextListTouchBarViewController initWithWebViewImpl:]):
(-[WKTextListTouchBarViewController didDestroyView]):
(-[WKTextListTouchBarViewController _selectList:]):
(-[WKTextListTouchBarViewController setCurrentListType:]):
(-[WKTextTouchBarItemController initWithWebViewImpl:]):
(-[WKTextTouchBarItemController didDestroyView]):
(-[WKTextTouchBarItemController touchBar:makeItemForIdentifier:]):
(-[WKTextTouchBarItemController itemForIdentifier:]):
(-[WKTextTouchBarItemController candidateListTouchBarItem:endSelectingCandidateAtIndex:]):
(-[WKTextTouchBarItemController candidateListTouchBarItem:changedCandidateListVisibility:]):
(-[WKTextTouchBarItemController textListTouchBarViewController]):
(-[WKTextTouchBarItemController setTextIsBold:]):
(-[WKTextTouchBarItemController setTextIsItalic:]):
(-[WKTextTouchBarItemController setTextIsUnderlined:]):
(-[WKTextTouchBarItemController _wkChangeTextStyle:]):
(-[WKTextTouchBarItemController setCurrentTextAlignment:]):
(-[WKTextTouchBarItemController _wkChangeTextAlignment:]):
(-[WKTextTouchBarItemController textColor]):
(-[WKTextTouchBarItemController setTextColor:]):
(-[WKTextTouchBarItemController _wkChangeColor:]):
(-[WKTextTouchBarItemController textListViewController]):
(WebKit::WebViewImpl::makeTouchBar):
(WebKit::WebViewImpl::candidateListTouchBarItem):
(WebKit::WebViewImpl::mediaPlaybackControlsView):
(WebKit::WebViewImpl::useMediaPlaybackControlsView):
(WebKit::WebViewImpl::dismissTextTouchBarPopoverItemWithIdentifier):
(WebKit::textTouchBarCustomizationAllowedIdentifiers):
(WebKit::plainTextTouchBarCustomizationDefaultItemIdentifiers):
(WebKit::richTextTouchBarCustomizationDefaultItemIdentifiers):
(WebKit::touchBarDidExitCustomization):
(WebKit::touchBarWillEnterCustomization):
(WebKit::didChangeAutomaticTextCompletion):
(WebKit::WebViewImpl::updateTouchBarAndRefreshTextBarIdentifiers):
(WebKit::WebViewImpl::setUpTextTouchBar):
(WebKit::WebViewImpl::isRichlyEditable):
(WebKit::WebViewImpl::textTouchBar):
(WebKit::WebViewImpl::updateTextTouchBar):
(WebKit::WebViewImpl::updateMediaTouchBar):
(WebKit::WebViewImpl::forceRequestCandidatesForTesting):
(WebKit::WebViewImpl::updateTouchBar):
(WebKit::WebViewImpl::shouldRequestCandidates):
(WebKit::WebViewImpl::showCandidates):
(WebKit::WebViewImpl::webViewImplAdditionsWillDestroyView):
(WebKit::WebViewImpl::setEditableElementIsFocused):
(WebKit::WebViewImpl::becomeFirstResponder):
(WebKit::WebViewImpl::selectionDidChange):
(WebKit::WebViewImpl::videoControlsManagerDidChange):
(WebKit::WebViewImpl::updateWebViewImplAdditions): Deleted.

Tools:

This makes MiniBrowser support TouchBar customization.

* MiniBrowser/mac/AppDelegate.m:
(-[BrowserAppDelegate awakeFromNib]):

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

21 files changed:
Source/WebCore/ChangeLog
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/platform/spi/cocoa/AVKitSPI.h
Source/WebCore/platform/spi/cocoa/NSTouchBarSPI.h [new file with mode: 0644]
Source/WebCore/platform/spi/mac/NSSpellCheckerSPI.h
Source/WebKit/mac/ChangeLog
Source/WebKit/mac/WebCoreSupport/WebEditorClient.mm
Source/WebKit/mac/WebView/WebHTMLView.mm
Source/WebKit/mac/WebView/WebView.mm
Source/WebKit/mac/WebView/WebViewData.h
Source/WebKit/mac/WebView/WebViewInternal.h
Source/WebKit/mac/WebView/WebViewPrivate.h
Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/Cocoa/WKViewPrivate.h
Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm
Source/WebKit2/UIProcess/API/Cocoa/WKWebViewPrivate.h
Source/WebKit2/UIProcess/API/mac/WKView.mm
Source/WebKit2/UIProcess/Cocoa/WebViewImpl.h
Source/WebKit2/UIProcess/Cocoa/WebViewImpl.mm
Tools/ChangeLog
Tools/MiniBrowser/mac/AppDelegate.m

index 9696a2a..13e829f 100644 (file)
@@ -1,3 +1,17 @@
+2016-11-09  Beth Dakin  <bdakin@apple.com>
+
+        Support TouchBar in WebKit
+        https://bugs.webkit.org/show_bug.cgi?id=164437
+        -and corresponding-
+        rdar://problem/28876524
+
+        Reviewed by Darin Adler.
+
+        * WebCore.xcodeproj/project.pbxproj:
+        * platform/spi/cocoa/AVKitSPI.h:
+        * platform/spi/cocoa/NSTouchBarSPI.h: Added.
+        * platform/spi/mac/NSSpellCheckerSPI.h:
+
 2016-11-09  Chris Dumez  <cdumez@apple.com>
 
         Use Blob URL instead of webkit-fake-url when pasting an image
index 3c2509a..4766467 100644 (file)
                93309EA3099EB78C0056E581 /* SharedTimer.h in Headers */ = {isa = PBXBuildFile; fileRef = 93309EA0099EB78C0056E581 /* SharedTimer.h */; };
                93309EA4099EB78C0056E581 /* Timer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 93309EA1099EB78C0056E581 /* Timer.cpp */; };
                93354A3C0B24F8C9003F6DEA /* UIEventWithKeyState.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 93354A3B0B24F8C9003F6DEA /* UIEventWithKeyState.cpp */; };
+               9335B49D1DCBEF7C00ED468E /* NSTouchBarSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = 9335B49B1DCBEF7100ED468E /* NSTouchBarSPI.h */; settings = {ATTRIBUTES = (Private, ); }; };
                933A142E0B7D188600A53FFD /* TextEvent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 933A142B0B7D188600A53FFD /* TextEvent.cpp */; };
                933A14300B7D188600A53FFD /* TextEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = 933A142D0B7D188600A53FFD /* TextEvent.h */; settings = {ATTRIBUTES = (Private, ); }; };
                933A14B80B7D1D5200A53FFD /* JSTextEvent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 933A14B60B7D1D5200A53FFD /* JSTextEvent.cpp */; };
                9332AB8B1653A97900D827EC /* FELightingNEON.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FELightingNEON.h; sourceTree = "<group>"; };
                9332AB8C1653A97900D827EC /* NEONHelpers.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NEONHelpers.h; sourceTree = "<group>"; };
                93354A3B0B24F8C9003F6DEA /* UIEventWithKeyState.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UIEventWithKeyState.cpp; sourceTree = "<group>"; };
+               9335B49B1DCBEF7100ED468E /* NSTouchBarSPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NSTouchBarSPI.h; sourceTree = "<group>"; };
                933A142B0B7D188600A53FFD /* TextEvent.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TextEvent.cpp; sourceTree = "<group>"; };
                933A142C0B7D188600A53FFD /* TextEvent.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = TextEvent.idl; sourceTree = "<group>"; };
                933A142D0B7D188600A53FFD /* TextEvent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TextEvent.h; sourceTree = "<group>"; };
                                2DDB97F319F9AECA002025D8 /* NSExtensionSPI.h */,
                                CE12523A1A16711000864480 /* NSFileManagerSPI.h */,
                                CE1252521A1BEC0600864480 /* NSStringSPI.h */,
+                               9335B49B1DCBEF7100ED468E /* NSTouchBarSPI.h */,
                                31B313DA1B69871600F2AABC /* NSURLConnectionSPI.h */,
                                CE1252541A1BEC0E00864480 /* NSURLDownloadSPI.h */,
                                653EF83819A043AE0052202C /* NSURLFileTypeMappingsSPI.h */,
                                1CAF34810A6C405200ABE06E /* WebScriptObject.h in Headers */,
                                1CAF34830A6C405200ABE06E /* WebScriptObjectPrivate.h in Headers */,
                                1A569D1B0D7E2B82007C3983 /* WebScriptObjectProtocol.h in Headers */,
+                               9335B49D1DCBEF7C00ED468E /* NSTouchBarSPI.h in Headers */,
                                97AABD1B14FA09D5007457AE /* WebSocket.h in Headers */,
                                97AABD1E14FA09D5007457AE /* WebSocketChannel.h in Headers */,
                                97AABD1F14FA09D5007457AE /* WebSocketChannelClient.h in Headers */,
index bb889c5..f87fcf5 100644 (file)
@@ -61,6 +61,8 @@ typedef NS_ENUM(NSInteger, AVPlayerControllerExternalPlaybackType) {
 @property (NS_NONATOMIC_IOSONLY, readonly) AVPlayerControllerStatus status;
 @end
 
+NS_ASSUME_NONNULL_BEGIN
+
 @class AVPlayerLayer;
 
 @interface AVPictureInPicturePlayerLayerView : UIView
@@ -95,11 +97,13 @@ typedef NS_ENUM(NSInteger, AVPlayerViewControllerExitFullScreenReason) {
 - (void)startPictureInPicture;
 - (void)stopPictureInPicture;
 
-@property (nonatomic, strong) AVPlayerController *playerController;
+@property (nonatomic, strong, nullable) AVPlayerController *playerController;
 @property (nonatomic, readonly, getter=isPictureInPictureActive) BOOL pictureInPictureActive;
 @property (nonatomic, readonly) BOOL pictureInPictureWasStartedWhenEnteringBackground;
 @end
 
+NS_ASSUME_NONNULL_END
+
 #endif // USE(APPLE_INTERNAL_SDK)
 #endif // PLATFORM(IOS)
 
@@ -132,6 +136,8 @@ NS_CLASS_AVAILABLE_MAC(10_11)
 
 #endif // ENABLE(WIRELESS_PLAYBACK_TARGET) && !PLATFORM(IOS)
 
+NS_ASSUME_NONNULL_BEGIN
+
 @interface AVValueTiming : NSObject <NSCoding, NSCopying, NSMutableCopying> 
 @end
 
@@ -139,3 +145,32 @@ NS_CLASS_AVAILABLE_MAC(10_11)
 + (AVValueTiming *)valueTimingWithAnchorValue:(double)anchorValue anchorTimeStamp:(NSTimeInterval)timeStamp rate:(double)rate;
 @property (NS_NONATOMIC_IOSONLY, readonly) double currentValue;
 @end
+
+NS_ASSUME_NONNULL_END
+
+#if PLATFORM(MAC)
+#if ENABLE(WEB_PLAYBACK_CONTROLS_MANAGER)
+#import <AVKit/AVFunctionBarPlaybackControlsProvider.h>
+#import <AVKit/AVFunctionBarScrubber.h>
+#else
+
+NS_ASSUME_NONNULL_BEGIN
+
+@protocol AVFunctionBarPlaybackControlsControlling <NSObject>
+@property (readonly) NSTimeInterval contentDuration;
+@property (readonly, nullable) AVValueTiming *timing;
+@property (readonly, getter=isSeeking) BOOL seeking;
+@property (readonly) NSTimeInterval seekToTime;
+- (void)seekToTime:(NSTimeInterval)time toleranceBefore:(NSTimeInterval)toleranceBefore toleranceAfter:(NSTimeInterval)toleranceAfter;
+@property (readonly) BOOL hasEnabledAudio;
+@property (readonly) BOOL hasEnabledVideo;
+@end
+
+@interface AVFunctionBarScrubber : NSView
+@property (assign, nullable) id<AVFunctionBarPlaybackControlsControlling> playbackControlsController;
+@end
+
+NS_ASSUME_NONNULL_END
+
+#endif // ENABLE(WEB_PLAYBACK_CONTROLS_MANAGER)
+#endif // PLATFORM(MAC)
diff --git a/Source/WebCore/platform/spi/cocoa/NSTouchBarSPI.h b/Source/WebCore/platform/spi/cocoa/NSTouchBarSPI.h
new file mode 100644 (file)
index 0000000..a1dc6c2
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if PLATFORM(MAC) && HAVE(TOUCH_BAR)
+#if USE(APPLE_INTERNAL_SDK)
+
+#import <AppKit/NSFunctionBar_Private.h>
+#import <AppKit/NSTextTouchBarItemController_WebKitSPI.h>
+#import <AppKit/NSTouchBar_Private.h>
+
+#else
+
+NS_ASSUME_NONNULL_BEGIN
+
+@interface NSTouchBarItem : NSObject
+@end
+
+@interface NSColorPickerTouchBarItem : NSTouchBarItem
+@end
+
+@interface NSTouchBar : NSObject
+@property (readonly, copy, nullable) NSArray<NSTouchBarItem *> *items;
+@property (strong, nullable) NSTouchBarItem *escapeKeyReplacementItem;
+@end
+
+@interface NSTextTouchBarItemController : NSObject
+
+@property (readonly, strong, nullable) NSColorPickerTouchBarItem *colorPickerItem;
+@property (readonly, strong, nullable) NSSegmentedControl *textStyle;
+@property (readonly, strong, nullable) NSSegmentedControl *textAlignments;
+@property (nullable, strong) NSViewController *textListViewController;
+@property BOOL usesNarrowTextStyleItem;
+
+- (nullable NSTouchBarItem *)itemForIdentifier:(nullable NSString *)identifier;
+
+@end
+
+#define NSTouchBarWillEnterCustomization @"NSTouchBarWillEnterCustomization"
+#define NSTouchBarDidExitCustomization @"NSTouchBarDidExitCustomization"
+
+NS_ASSUME_NONNULL_END
+
+#endif // USE(APPLE_INTERNAL_SDK)
+#endif // PLATFORM(MAC) && HAVE(TOUCH_BAR)
index a78f1c1..b3cb229 100644 (file)
@@ -30,6 +30,7 @@
 // FIXME: This header should include system headers when possible.
 
 extern NSString *NSTextCheckingInsertionPointKey;
+extern NSNotificationName const NSSpellCheckerDidChangeAutomaticTextCompletionNotification;
 
 @interface NSSpellChecker ()
 - (NSInteger)requestCandidatesForSelectedRange:(NSRange)selectedRange inString:(NSString *)stringToCheck types:(NSTextCheckingTypes)checkingTypes options:(NSDictionary<NSString *, id> *)options inSpellDocumentWithTag:(NSInteger)tag completionHandler:(void (^)(NSInteger sequenceNumber, NSArray<NSTextCheckingResult *> *candidates))completionHandler;
index faf07c1..f370869 100644 (file)
@@ -1,3 +1,67 @@
+2016-11-09  Beth Dakin  <bdakin@apple.com>
+
+        Support TouchBar in WebKit
+        https://bugs.webkit.org/show_bug.cgi?id=164437
+        -and corresponding-
+        rdar://problem/28876524
+
+        Reviewed by Darin Adler.
+
+        * WebCoreSupport/WebEditorClient.mm:
+        (WebEditorClient::respondToChangedSelection):
+        (WebEditorClient::updateEditorStateAfterLayoutIfEditabilityChanged):
+        * WebView/WebHTMLView.mm:
+        (-[WebHTMLView candidateListTouchBarItem]):
+        * WebView/WebView.mm:
+        (-[_WebTextListTouchBarViewController initWithWebView:]):
+        (-[_WebTextListTouchBarViewController _selectList:]):
+        (-[_WebTextListTouchBarViewController setCurrentListType:]):
+        (-[WebTextTouchBarItemController initWithWebView:]):
+        (-[WebTextTouchBarItemController itemForIdentifier:]):
+        (-[WebTextTouchBarItemController webTextListTouchBarViewController]):
+        (-[WebTextTouchBarItemController setTextIsBold:]):
+        (-[WebTextTouchBarItemController setTextIsItalic:]):
+        (-[WebTextTouchBarItemController setTextIsUnderlined:]):
+        (-[WebTextTouchBarItemController _webChangeTextStyle:]):
+        (-[WebTextTouchBarItemController setCurrentTextAlignment:]):
+        (-[WebTextTouchBarItemController _webChangeTextAlignment:]):
+        (-[WebTextTouchBarItemController textColor]):
+        (-[WebTextTouchBarItemController setTextColor:]):
+        (-[WebTextTouchBarItemController _webChangeColor:]):
+        (-[WebTextTouchBarItemController textListViewController]):
+        (-[WebView _commonInitializationWithFrameName:groupName:]):
+        (-[WebView showCandidates:forString:inRect:forSelectedRange:view:completionHandler:]):
+        (-[WebView shouldRequestCandidates]):
+        (-[WebView forceRequestCandidatesForTesting]):
+        (-[WebView makeTouchBar]):
+        (-[WebView touchBar:makeItemForIdentifier:]):
+        (textCheckingResultFromNSTextCheckingResult):
+        (-[WebView candidateListTouchBarItem:endSelectingCandidateAtIndex:]):
+        (-[WebView candidateListTouchBarItem:changedCandidateListVisibility:]):
+        (-[WebView _setUpPlaybackControlsManagerForMediaElement:]):
+        (-[WebView _clearPlaybackControlsManager]):
+        (-[WebView _dismissTextTouchBarPopoverItemWithIdentifier:]):
+        (-[WebView _textTouchBarCustomizationAllowedIdentifiers]):
+        (-[WebView _plainTextTouchBarCustomizationDefaultItemIdentifiers]):
+        (-[WebView _richTextTouchBarCustomizationDefaultItemIdentifiers]):
+        (-[WebView touchBarDidExitCustomization:]):
+        (-[WebView touchBarWillEnterCustomization:]):
+        (-[WebView didChangeAutomaticTextCompletion:]):
+        (-[WebView setUpTextTouchBar:]):
+        (-[WebView _isRichlyEditable]):
+        (-[WebView textTouchBar]):
+        (-[WebView updateTextTouchBar]):
+        (-[WebView updateMediaTouchBar]):
+        (-[WebView updateTouchBar]):
+        (-[WebView prepareForMouseDown]):
+        (-[WebView prepareForMouseUp]):
+        (-[WebView webViewAdditionsWillDestroyView]):
+        (-[WebView candidateList]):
+        (-[WebView updateWebViewAdditions]): Deleted.
+        * WebView/WebViewData.h:
+        * WebView/WebViewInternal.h:
+        * WebView/WebViewPrivate.h:
+
 2016-11-04  Wenson Hsieh  <wenson_hsieh@apple.com>
 
         Safari does not emit composition end if blurred for dead key / Japanese IME
index ce48436..4252639 100644 (file)
@@ -347,7 +347,7 @@ void WebEditorClient::respondToChangedSelection(Frame* frame)
     NSView<WebDocumentView> *documentView = [[kit(frame) frameView] documentView];
     if ([documentView isKindOfClass:[WebHTMLView class]]) {
         [(WebHTMLView *)documentView _selectionChanged];
-        [m_webView updateWebViewAdditions];
+        [m_webView updateTouchBar];
         m_lastEditorStateWasContentEditable = [(WebHTMLView *)documentView _isEditable] ? EditorStateIsContentEditable::Yes : EditorStateIsContentEditable::No;
     }
 
@@ -674,7 +674,7 @@ void WebEditorClient::updateEditorStateAfterLayoutIfEditabilityChanged()
 
     EditorStateIsContentEditable editorStateIsContentEditable = [(WebHTMLView *)documentView _isEditable] ? EditorStateIsContentEditable::Yes : EditorStateIsContentEditable::No;
     if (m_lastEditorStateWasContentEditable != editorStateIsContentEditable)
-        [m_webView updateWebViewAdditions];
+        [m_webView updateTouchBar];
 }
 
 void WebEditorClient::registerUndoStep(PassRefPtr<UndoStep> cmd)
index 55f1ae2..a056fad 100644 (file)
@@ -7230,8 +7230,11 @@ static void extractUnderlines(NSAttributedString *string, Vector<CompositionUnde
 #endif // PLATFORM(IOS)
 }
 
-#if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101200 && USE(APPLE_INTERNAL_SDK)
-#import <WebKitAdditions/WebHTMLViewWebNSTextInputSupportAdditions.mm>
+#if HAVE(TOUCH_BAR)
+- (NSCandidateListTouchBarItem *)candidateListTouchBarItem
+{
+    return [[self _webView] candidateList];
+}
 #endif
 
 @end
index 7cfaa87..8ab02ac 100644 (file)
 #import <JavaScriptCore/APICast.h>
 #import <JavaScriptCore/Exception.h>
 #import <JavaScriptCore/JSValueRef.h>
+#import <WebCore/AVKitSPI.h>
 #import <WebCore/AlternativeTextUIController.h>
 #import <WebCore/AnimationController.h>
 #import <WebCore/ApplicationCacheStorage.h>
 #import <WebCore/GeolocationController.h>
 #import <WebCore/GeolocationError.h>
 #import <WebCore/HTMLNames.h>
+#import <WebCore/HTMLOListElement.h>
+#import <WebCore/HTMLUListElement.h>
 #import <WebCore/HTMLVideoElement.h>
 #import <WebCore/HistoryController.h>
 #import <WebCore/HistoryItem.h>
 #import <WebCore/JSElement.h>
 #import <WebCore/JSNodeList.h>
 #import <WebCore/JSNotification.h>
+#import <WebCore/LocalizedStrings.h>
 #import <WebCore/LogInitialization.h>
 #import <WebCore/MIMETypeRegistry.h>
 #import <WebCore/MainFrame.h>
 #import <WebCore/MemoryCache.h>
 #import <WebCore/MemoryPressureHandler.h>
+#import <WebCore/NSSpellCheckerSPI.h>
+#import <WebCore/NSTouchBarSPI.h>
 #import <WebCore/NSURLFileTypeMappingsSPI.h>
 #import <WebCore/NetworkStorageSession.h>
 #import <WebCore/NodeList.h>
 #import <WebCore/WebCoreObjCExtras.h>
 #import <WebCore/WebCoreView.h>
 #import <WebCore/Widget.h>
+#import <WebCore/htmlediting.h>
 #import <WebKitLegacy/DOM.h>
 #import <WebKitLegacy/DOMExtensions.h>
 #import <WebKitLegacy/DOMPrivate.h>
 #import <wtf/RefPtr.h>
 #import <wtf/RunLoop.h>
 #import <wtf/StdLibExtras.h>
+#import <wtf/TemporaryChange.h>
 #import <wtf/spi/darwin/dyldSPI.h>
 
 #if !PLATFORM(IOS)
 #import <WebCore/WebPlaybackSessionModelMediaElement.h>
 #endif
 
+#if HAVE(TOUCH_BAR) && ENABLE(WEB_PLAYBACK_CONTROLS_MANAGER)
+SOFT_LINK_FRAMEWORK(AVKit)
+SOFT_LINK_CLASS(AVKit, AVFunctionBarPlaybackControlsProvider)
+SOFT_LINK_CLASS(AVKit, AVFunctionBarScrubber)
+#endif // HAVE(TOUCH_BAR) && ENABLE(WEB_PLAYBACK_CONTROLS_MANAGER)
+
 #if PLATFORM(MAC)
 SOFT_LINK_CONSTANT_MAY_FAIL(Lookup, LUNotificationPopoverWillClose, NSString *)
 #endif
@@ -662,6 +676,279 @@ static BOOL automaticTextReplacementEnabled;
 static BOOL automaticSpellingCorrectionEnabled;
 #endif
 
+#if HAVE(TOUCH_BAR)
+
+enum class WebListType {
+    None = 0,
+    Ordered,
+    Unordered
+};
+
+@interface WebTextListTouchBarViewController : NSViewController {
+@private
+    WebView *_webView;
+}
+
+@property (nonatomic) WebListType currentListType;
+
+- (instancetype)initWithWebView:(WebView *)webView;
+
+@end
+
+@implementation WebTextListTouchBarViewController
+
+@synthesize currentListType=_currentListType;
+
+static const CGFloat listControlSegmentWidth = 67.0;
+
+static const NSUInteger noListSegment = 0;
+static const NSUInteger unorderedListSegment = 1;
+static const NSUInteger orderedListSegment = 2;
+
+- (instancetype)initWithWebView:(WebView *)webView
+{
+    if (!(self = [super init]))
+        return nil;
+
+    _webView = webView;
+
+    NSSegmentedControl *insertListControl = [NSSegmentedControl segmentedControlWithLabels:@[ WebCore::insertListTypeNone(), WebCore::insertListTypeBulleted(), WebCore::insertListTypeNumbered() ] trackingMode:NSSegmentSwitchTrackingSelectOne target:self action:@selector(_selectList:)];
+    [insertListControl setWidth:listControlSegmentWidth forSegment:noListSegment];
+    [insertListControl setWidth:listControlSegmentWidth forSegment:unorderedListSegment];
+    [insertListControl setWidth:listControlSegmentWidth forSegment:orderedListSegment];
+    insertListControl.font = [NSFont systemFontOfSize:15];
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+    id segmentElement = NSAccessibilityUnignoredDescendant(insertListControl);
+    NSArray *segments = [segmentElement accessibilityAttributeValue:NSAccessibilityChildrenAttribute];
+    ASSERT(segments.count == 3);
+    [segments[noListSegment] accessibilitySetOverrideValue:WebCore::insertListTypeNone() forAttribute:NSAccessibilityDescriptionAttribute];
+    [segments[unorderedListSegment] accessibilitySetOverrideValue:WebCore::insertListTypeBulletedAccessibilityTitle() forAttribute:NSAccessibilityDescriptionAttribute];
+    [segments[orderedListSegment] accessibilitySetOverrideValue:WebCore::insertListTypeNumberedAccessibilityTitle() forAttribute:NSAccessibilityDescriptionAttribute];
+#pragma clang diagnostic pop
+
+    self.view = insertListControl;
+
+    return self;
+}
+
+- (void)_selectList:(id)sender
+{
+    NSView *documentView = [[[_webView _selectedOrMainFrame] frameView] documentView];
+    if (![documentView isKindOfClass:[WebHTMLView class]])
+        return;
+
+    WebHTMLView *webHTMLView = (WebHTMLView *)documentView;
+    NSSegmentedControl *insertListControl = (NSSegmentedControl *)self.view;
+    switch (insertListControl.selectedSegment) {
+    case noListSegment:
+        // There is no "remove list" edit command, but _insertOrderedList and _insertUnorderedList both
+        // behave as toggles, so we can invoke the appropriate method depending on our _currentListType
+        // to remove an existing list. We don't have to do anything if _currentListType is WebListType::None.
+        if (_currentListType == WebListType::Ordered)
+            [webHTMLView _insertOrderedList];
+        else if (_currentListType == WebListType::Unordered)
+            [webHTMLView _insertUnorderedList];
+        break;
+    case unorderedListSegment:
+        [webHTMLView _insertUnorderedList];
+        break;
+    case orderedListSegment:
+        [webHTMLView _insertOrderedList];
+        break;
+    }
+
+    [_webView _dismissTextTouchBarPopoverItemWithIdentifier:NSTouchBarItemIdentifierTextList];
+}
+
+- (void)setCurrentListType:(WebListType)listType
+{
+    NSSegmentedControl *insertListControl = (NSSegmentedControl *)self.view;
+    switch (listType) {
+    case WebListType::None:
+        [insertListControl setSelected:YES forSegment:noListSegment];
+        break;
+    case WebListType::Ordered:
+        [insertListControl setSelected:YES forSegment:orderedListSegment];
+        break;
+    case WebListType::Unordered:
+        [insertListControl setSelected:YES forSegment:unorderedListSegment];
+        break;
+    }
+
+    _currentListType = listType;
+}
+
+@end
+
+@interface WebTextTouchBarItemController : NSTextTouchBarItemController {
+@private
+    BOOL _textIsBold;
+    BOOL _textIsItalic;
+    BOOL _textIsUnderlined;
+    NSTextAlignment _currentTextAlignment;
+    RetainPtr<NSColor> _textColor;
+    RetainPtr<WebTextListTouchBarViewController> _textListTouchBarViewController;
+    WebView *_webView;
+}
+
+@property (nonatomic) BOOL textIsBold;
+@property (nonatomic) BOOL textIsItalic;
+@property (nonatomic) BOOL textIsUnderlined;
+@property (nonatomic) NSTextAlignment currentTextAlignment;
+@property (nonatomic, retain, readwrite) NSColor *textColor;
+
+- (instancetype)initWithWebView:(WebView *)webView;
+@end
+
+@implementation WebTextTouchBarItemController
+
+@synthesize textIsBold=_textIsBold;
+@synthesize textIsItalic=_textIsItalic;
+@synthesize textIsUnderlined=_textIsUnderlined;
+@synthesize currentTextAlignment=_currentTextAlignment;
+
+- (instancetype)initWithWebView:(WebView *)webView
+{
+    if (!(self = [super init]))
+        return nil;
+
+    _webView = webView;
+
+    return self;
+}
+
+- (NSTouchBarItem *)itemForIdentifier:(NSString *)identifier
+{
+    NSTouchBarItem *item = [super itemForIdentifier:identifier];
+    BOOL isTextFormatItem = [identifier isEqualToString:NSTouchBarItemIdentifierTextFormat];
+
+    if (isTextFormatItem || [identifier isEqualToString:NSTouchBarItemIdentifierTextStyle])
+        self.textStyle.action = @selector(_webChangeTextStyle:);
+
+    if (isTextFormatItem || [identifier isEqualToString:NSTouchBarItemIdentifierTextAlignment])
+        self.textAlignments.action = @selector(_webChangeTextAlignment:);
+
+    NSColorPickerTouchBarItem *colorPickerItem = nil;
+    if ([identifier isEqualToString:NSTouchBarItemIdentifierTextColorPicker] && [item isKindOfClass:[NSColorPickerTouchBarItem class]])
+        colorPickerItem = (NSColorPickerTouchBarItem *)item;
+    if (isTextFormatItem)
+        colorPickerItem = self.colorPickerItem;
+    if (colorPickerItem) {
+        colorPickerItem.target = self;
+        colorPickerItem.action = @selector(_webChangeColor:);
+        colorPickerItem.showsAlpha = NO;
+    }
+
+    return item;
+}
+
+- (WebTextListTouchBarViewController *)webTextListTouchBarViewController
+{
+    return (WebTextListTouchBarViewController *)self.textListViewController;
+}
+
+- (void)setTextIsBold:(BOOL)bold
+{
+    _textIsBold = bold;
+    if ([self.textStyle isSelectedForSegment:0] != _textIsBold)
+        [self.textStyle setSelected:_textIsBold forSegment:0];
+}
+
+- (void)setTextIsItalic:(BOOL)italic
+{
+    _textIsItalic = italic;
+    if ([self.textStyle isSelectedForSegment:1] != _textIsItalic)
+        [self.textStyle setSelected:_textIsItalic forSegment:1];
+}
+
+- (void)setTextIsUnderlined:(BOOL)underlined
+{
+    _textIsUnderlined = underlined;
+    if ([self.textStyle isSelectedForSegment:2] != _textIsUnderlined)
+        [self.textStyle setSelected:_textIsUnderlined forSegment:2];
+}
+
+- (void)_webChangeTextStyle:(id)sender
+{
+    if ([self.textStyle isSelectedForSegment:0] != _textIsBold) {
+        _textIsBold = !_textIsBold;
+        [_webView _executeCoreCommandByName:@"ToggleBold" value:@""];
+    }
+
+    if ([self.textStyle isSelectedForSegment:1] != _textIsItalic) {
+        _textIsItalic = !_textIsItalic;
+        [_webView _executeCoreCommandByName:@"ToggleItalic" value:@""];
+    }
+
+    if ([self.textStyle isSelectedForSegment:2] != _textIsUnderlined) {
+        _textIsUnderlined = !_textIsUnderlined;
+        [_webView _executeCoreCommandByName:@"ToggleUnderline" value:@""];
+    }
+}
+
+- (void)setCurrentTextAlignment:(NSTextAlignment)alignment
+{
+    _currentTextAlignment = alignment;
+    [self.textAlignments selectSegmentWithTag:_currentTextAlignment];
+}
+
+- (void)_webChangeTextAlignment:(id)sender
+{
+    NSTextAlignment alignment = (NSTextAlignment)[self.textAlignments.cell tagForSegment:self.textAlignments.selectedSegment];
+    switch (alignment) {
+    case NSTextAlignmentLeft:
+        _currentTextAlignment = NSTextAlignmentLeft;
+        [_webView alignLeft:sender];
+        break;
+    case NSTextAlignmentRight:
+        _currentTextAlignment = NSTextAlignmentRight;
+        [_webView alignRight:sender];
+        break;
+    case NSTextAlignmentCenter:
+        _currentTextAlignment = NSTextAlignmentCenter;
+        [_webView alignCenter:sender];
+        break;
+    case NSTextAlignmentJustified:
+        _currentTextAlignment = NSTextAlignmentJustified;
+        [_webView alignJustified:sender];
+        break;
+    default:
+        break;
+    }
+
+    [_webView _dismissTextTouchBarPopoverItemWithIdentifier:NSTouchBarItemIdentifierTextAlignment];
+}
+
+- (NSColor *)textColor
+{
+    return _textColor.get();
+}
+
+- (void)setTextColor:(NSColor *)color
+{
+    _textColor = color;
+    self.colorPickerItem.color = _textColor.get();
+}
+
+- (void)_webChangeColor:(id)sender
+{
+    _textColor = self.colorPickerItem.color;
+    [_webView _executeCoreCommandByName:@"ForeColor" value: WebCore::colorFromNSColor(_textColor.get()).serialized()];
+}
+
+- (NSViewController *)textListViewController
+{
+    if (!_textListTouchBarViewController)
+        _textListTouchBarViewController = adoptNS([[WebTextListTouchBarViewController alloc] initWithWebView:_webView]);
+    return _textListTouchBarViewController.get();
+}
+
+@end
+
+#endif // HAVE(TOUCH_BAR)
+
 @implementation WebView (AllWebViews)
 
 static CFSetCallBacks NonRetainingSetCallbacks = {
@@ -970,7 +1257,7 @@ static void WebKitInitializeGamepadProviderIfNecessary()
     }
 #endif
 
-    [self updateWebViewAdditions];
+    [self updateTouchBar];
 
 #if !PLATFORM(IOS)
     static bool didOneTimeInitialization = false;
@@ -4692,6 +4979,45 @@ static Vector<String> toStringVector(NSArray* patterns)
         _private->page->settings().setFontFallbackPrefersPictographs(flag);
 }
 
+#if HAVE(TOUCH_BAR)
+
+- (void)showCandidates:(NSArray<NSTextCheckingResult *> *)candidates forString:(NSString *)string inRect:(NSRect)rectOfTypedString forSelectedRange:(NSRange)range view:(NSView *)view completionHandler:(void (^)(NSTextCheckingResult *acceptedCandidate))completionBlock
+{
+    [self.candidateList setCandidates:candidates forSelectedRange:range inString:string];
+}
+
+- (BOOL)shouldRequestCandidates
+{
+    Frame* coreFrame = core([self _selectedOrMainFrame]);
+    if (!coreFrame)
+        return NO;
+
+    return !coreFrame->selection().selection().isInPasswordField() && self.candidateList.candidateListVisible;
+}
+
+- (void)forceRequestCandidatesForTesting
+{
+    _private->_canCreateTouchBars = YES;
+    [self updateTouchBar];
+}
+
+#else
+
+- (void)showCandidates:(NSArray *)candidates forString:(NSString *)string inRect:(NSRect)rectOfTypedString forSelectedRange:(NSRange)range view:(NSView *)view completionHandler:(void (^)(NSTextCheckingResult *acceptedCandidate))completionBlock
+{
+}
+
+- (void)forceRequestCandidatesForTesting
+{
+}
+
+- (BOOL)shouldRequestCandidates
+{
+    return NO;
+}
+
+#endif // HAVE(TOUCH_BAR)
+
 @end
 
 @implementation _WebSafeForwarder
@@ -4804,6 +5130,11 @@ static Vector<String> toStringVector(NSArray* patterns)
 @end
 #endif
 
+#if HAVE(TOUCH_BAR)
+@interface WebView () <NSCandidateListTouchBarItemDelegate, NSTouchBarDelegate, NSTouchBarProvider>
+@end
+#endif
+
 @implementation WebView
 
 + (void)initialize
@@ -5257,7 +5588,7 @@ static bool needsWebViewInitThreadWorkaround()
             [_private->_geolocationProvider stopTrackingWebView:self];
 #endif
 
-        [self webViewAdditionsWillDestroyView];
+        [[NSNotificationCenter defaultCenter] removeObserver:self];
 
         // call close to ensure we tear-down completely
         // this maintains our old behavior for existing applications
@@ -6488,6 +6819,87 @@ static WebFrame *incrementFrame(WebFrame *frame, WebFindOptions options = 0)
     return [previousView previousValidKeyView];
 }
 
+#if HAVE(TOUCH_BAR)
+
+@dynamic touchBar;
+
+- (NSTouchBar *)makeTouchBar
+{
+    if (!_private->_canCreateTouchBars) {
+        _private->_canCreateTouchBars = YES;
+        [self updateTouchBar];
+    }
+    return _private->_currentTouchBar.get();
+}
+
+- (NSTouchBarItem *)touchBar:(NSTouchBar *)touchBar makeItemForIdentifier:(NSString *)identifier
+{
+    if (touchBar == _private->_richTextTouchBar || touchBar == _private->_plainTextTouchBar)
+        return [_private->_textTouchBarItemController itemForIdentifier:identifier];
+
+    return nil;
+}
+
+static TextCheckingResult textCheckingResultFromNSTextCheckingResult(NSTextCheckingResult *nsResult)
+{
+    WebCore::TextCheckingResult result;
+
+    switch ([nsResult resultType]) {
+    case NSTextCheckingTypeSpelling:
+        result.type = WebCore::TextCheckingTypeSpelling;
+        break;
+    case NSTextCheckingTypeReplacement:
+        result.type = WebCore::TextCheckingTypeReplacement;
+        break;
+    case NSTextCheckingTypeCorrection:
+        result.type = WebCore::TextCheckingTypeCorrection;
+        break;
+    default:
+        result.type = WebCore::TextCheckingTypeNone;
+    }
+
+    NSRange resultRange = nsResult.range;
+    result.location = resultRange.location;
+    result.length = resultRange.length;
+    result.replacement = nsResult.replacementString;
+
+    return result;
+}
+
+- (void)candidateListTouchBarItem:(NSCandidateListTouchBarItem *)anItem endSelectingCandidateAtIndex:(NSInteger)index
+{
+    if (index == NSNotFound)
+        return;
+
+    if (anItem != self.candidateList)
+        return;
+
+    NSArray *candidates = anItem.candidates;
+    if ((NSUInteger)index >= candidates.count)
+        return;
+
+    id candidate = candidates[index];
+    ASSERT([candidate isKindOfClass:[NSTextCheckingResult class]]);
+
+    if (Frame* coreFrame = core(self._selectedOrMainFrame))
+        coreFrame->editor().client()->handleAcceptedCandidateWithSoftSpaces(textCheckingResultFromNSTextCheckingResult((NSTextCheckingResult *)candidate));
+}
+
+- (void)candidateListTouchBarItem:(NSCandidateListTouchBarItem *)anItem changedCandidateListVisibility:(BOOL)isVisible
+{
+    if (anItem != self.candidateList)
+        return;
+
+    if (isVisible) {
+        if (Frame* coreFrame = core([self _selectedOrMainFrame]))
+            coreFrame->editor().client()->requestCandidatesForSelection(coreFrame->selection().selection());
+    }
+
+    [self updateTouchBar];
+}
+
+#endif // HAVE(TOUCH_BAR)
+
 @end
 
 @implementation WebView (WebIBActions)
@@ -6746,48 +7158,6 @@ static WebFrame *incrementFrame(WebFrame *frame, WebFindOptions options = 0)
 
 @end
 
-#if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101200 && USE(APPLE_INTERNAL_SDK)
-#import <WebKitAdditions/WebViewAdditions.mm>
-#else
-@implementation WebView (WebUpdateWebViewAdditions)
-
-- (void)updateWebViewAdditions
-{
-}
-
-- (void)prepareForMouseDown
-{
-}
-
-- (void)prepareForMouseUp
-{
-}
-
-- (void)showCandidates:(NSArray *)candidates forString:(NSString *)string inRect:(NSRect)rectOfTypedString forSelectedRange:(NSRange)range view:(NSView *)view completionHandler:(void (^)(NSTextCheckingResult *acceptedCandidate))completionBlock
-{
-}
-
-- (void)forceRequestCandidatesForTesting
-{
-}
-
-- (BOOL)shouldRequestCandidates
-{
-    return NO;
-}
-
-- (void)webViewAdditionsWillDestroyView
-{
-}
-
-- (id)candidateList
-{
-    return nil;
-}
-
-@end
-#endif // PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101200 && USE(APPLE_INTERNAL_SDK)
-
 @implementation WebView (WebPendingPublic)
 
 - (void)scheduleInRunLoop:(NSRunLoop *)runLoop forMode:(NSString *)mode
@@ -8656,7 +9026,7 @@ bool LayerFlushController::flushLayers()
     if (!_private->playbackSessionInterface)
         _private->playbackSessionInterface = WebPlaybackSessionInterfaceMac::create(*_private->playbackSessionModel);
 
-    [self updateWebViewAdditions];
+    [self updateTouchBar];
 }
 
 - (void)_clearPlaybackControlsManager
@@ -8669,7 +9039,7 @@ bool LayerFlushController::flushLayers()
 
     _private->playbackSessionModel = nullptr;
     _private->playbackSessionInterface = nullptr;
-    [self updateWebViewAdditions];
+    [self updateTouchBar];
 }
 #endif // PLATFORM(MAC) && ENABLE(VIDEO_PRESENTATION_MODE)
 #endif // ENABLE(VIDEO)
@@ -8898,6 +9268,341 @@ bool LayerFlushController::flushLayers()
 }
 #endif
 
+#if HAVE(TOUCH_BAR)
+- (void)_dismissTextTouchBarPopoverItemWithIdentifier:(NSString *)identifier
+{
+    NSTouchBarItem *foundItem = nil;
+    for (NSTouchBarItem *item in self.textTouchBar.items) {
+        if ([item.identifier isEqualToString:identifier]) {
+            foundItem = item;
+            break;
+        }
+
+        if ([item.identifier isEqualToString:NSTouchBarItemIdentifierTextFormat]) {
+            for (NSTouchBarItem *childItem in ((NSGroupTouchBarItem *)item).groupTouchBar.items) {
+                if ([childItem.identifier isEqualToString:identifier]) {
+                    foundItem = childItem;
+                    break;
+                }
+            }
+            break;
+        }
+    }
+
+    if ([foundItem isKindOfClass:[NSPopoverTouchBarItem class]])
+        [(NSPopoverTouchBarItem *)foundItem dismissPopover:nil];
+}
+
+- (NSArray<NSString *> *)_textTouchBarCustomizationAllowedIdentifiers
+{
+    return @[ NSTouchBarItemIdentifierCharacterPicker, NSTouchBarItemIdentifierTextColorPicker, NSTouchBarItemIdentifierTextStyle, NSTouchBarItemIdentifierTextAlignment, NSTouchBarItemIdentifierTextList, NSTouchBarItemIdentifierFlexibleSpace ];
+}
+
+- (NSArray<NSString *> *)_plainTextTouchBarCustomizationDefaultItemIdentifiers
+{
+    return @[ NSTouchBarItemIdentifierCharacterPicker, NSTouchBarItemIdentifierCandidateList ];
+}
+
+- (NSArray<NSString *> *)_richTextTouchBarCustomizationDefaultItemIdentifiers
+{
+    return @[ NSTouchBarItemIdentifierCharacterPicker, NSTouchBarItemIdentifierTextFormat, NSTouchBarItemIdentifierCandidateList ];
+}
+
+- (void)touchBarDidExitCustomization:(NSNotification *)notification
+{
+    _private->_isCustomizingTouchBar = NO;
+    [self updateTouchBar];
+}
+
+- (void)touchBarWillEnterCustomization:(NSNotification *)notification
+{
+    _private->_isCustomizingTouchBar = YES;
+}
+
+- (void)didChangeAutomaticTextCompletion:(NSNotification *)notification
+{
+    if (_private->_richTextTouchBar)
+        [self setUpTextTouchBar:_private->_richTextTouchBar.get()];
+
+    if (_private->_plainTextTouchBar)
+        [self setUpTextTouchBar:_private->_plainTextTouchBar.get()];
+
+    [self updateTouchBar];
+}
+
+- (void)setUpTextTouchBar:(NSTouchBar *)textTouchBar
+{
+    BOOL isRichTextTouchBar = textTouchBar == _private->_richTextTouchBar;
+    [textTouchBar setDelegate:self];
+    [textTouchBar setDefaultItems:[NSMutableSet setWithObject:isRichTextTouchBar ? _private->_richTextCandidateListTouchBarItem.get() : _private->_plainTextCandidateListTouchBarItem.get()]];
+    [textTouchBar setCustomizationAllowedItemIdentifiers:[self _textTouchBarCustomizationAllowedIdentifiers]];
+
+    NSArray<NSString *> *defaultIdentifiers = isRichTextTouchBar ? [self _richTextTouchBarCustomizationDefaultItemIdentifiers] : [self _plainTextTouchBarCustomizationDefaultItemIdentifiers];
+    [textTouchBar setCustomizationDefaultItemIdentifiers:defaultIdentifiers];
+
+    if (NSGroupTouchBarItem *textFormatItem = (NSGroupTouchBarItem *)[textTouchBar itemForIdentifier:NSTouchBarItemIdentifierTextFormat])
+        textFormatItem.groupTouchBar.customizationIdentifier = @"WebTextFormatTouchBar";
+}
+
+- (BOOL)_isRichlyEditable
+{
+    NSView *documentView = self._selectedOrMainFrame.frameView.documentView;
+    if (![documentView isKindOfClass:[WebHTMLView class]])
+        return NO;
+
+    WebHTMLView *webHTMLView = (WebHTMLView *)documentView;
+    return webHTMLView._isEditable && webHTMLView._canEditRichly;
+}
+
+- (NSTouchBar *)textTouchBar
+{
+    if (self._isRichlyEditable)
+        return _private->_richTextTouchBar.get();
+
+    return _private->_plainTextTouchBar.get();
+}
+
+static NSTextAlignment nsTextAlignmentFromRenderStyle(const RenderStyle* style)
+{
+    NSTextAlignment textAlignment;
+    switch (style->textAlign()) {
+    case RIGHT:
+    case WEBKIT_RIGHT:
+        textAlignment = NSTextAlignmentRight;
+        break;
+    case LEFT:
+    case WEBKIT_LEFT:
+        textAlignment = NSTextAlignmentLeft;
+        break;
+    case CENTER:
+    case WEBKIT_CENTER:
+        textAlignment = NSTextAlignmentCenter;
+        break;
+    case JUSTIFY:
+        textAlignment = NSTextAlignmentJustified;
+        break;
+    case TASTART:
+        textAlignment = style->isLeftToRightDirection() ? NSTextAlignmentLeft : NSTextAlignmentRight;
+        break;
+    case TAEND:
+        textAlignment = style->isLeftToRightDirection() ? NSTextAlignmentRight : NSTextAlignmentLeft;
+        break;
+    default:
+        ASSERT_NOT_REACHED();
+    }
+
+    return textAlignment;
+}
+
+- (void)updateTextTouchBar
+{
+    if (_private->_isDeferringTextTouchBarUpdates) {
+        _private->_needsDeferredTextTouchBarUpdate = YES;
+        return;
+    }
+
+    NSView *documentView = [[[self _selectedOrMainFrame] frameView] documentView];
+    if (![documentView isKindOfClass:[WebHTMLView class]])
+        return;
+    
+    WebHTMLView *webHTMLView = (WebHTMLView *)documentView;
+    if (![webHTMLView _isEditable])
+        return;
+
+    Frame* coreFrame = core([self _selectedOrMainFrame]);
+    if (!coreFrame)
+        return;
+
+    if (_private->_isUpdatingTextTouchBar)
+        return;
+
+    TemporaryChange<BOOL> isUpdatingTextTouchBar(_private->_isUpdatingTextTouchBar, YES);
+
+    if (!_private->_textTouchBarItemController)
+        _private->_textTouchBarItemController = adoptNS([[WebTextTouchBarItemController alloc] initWithWebView:self]);
+
+    if (!_private->_startedListeningToCustomizationEvents) {
+        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(touchBarDidExitCustomization:) name:NSTouchBarDidExitCustomization object:nil];
+        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(touchBarWillEnterCustomization:) name:NSTouchBarWillEnterCustomization object:nil];
+        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didChangeAutomaticTextCompletion:) name:NSSpellCheckerDidChangeAutomaticTextCompletionNotification object:nil];
+        _private->_startedListeningToCustomizationEvents = YES;
+    }
+
+    if (!_private->_plainTextCandidateListTouchBarItem || !_private->_richTextCandidateListTouchBarItem) {
+        _private->_plainTextCandidateListTouchBarItem = adoptNS([[NSCandidateListTouchBarItem alloc] initWithIdentifier:NSTouchBarItemIdentifierCandidateList]);
+        [_private->_plainTextCandidateListTouchBarItem setDelegate:self];
+        _private->_richTextCandidateListTouchBarItem = adoptNS([[NSCandidateListTouchBarItem alloc] initWithIdentifier:NSTouchBarItemIdentifierCandidateList]);
+        [_private->_richTextCandidateListTouchBarItem setDelegate:self];
+        coreFrame->editor().client()->requestCandidatesForSelection(coreFrame->selection().selection());
+    }
+
+    if (!_private->_richTextTouchBar) {
+        _private->_richTextTouchBar = adoptNS([[NSTouchBar alloc] init]);
+        [self setUpTextTouchBar:_private->_richTextTouchBar.get()];
+        [_private->_richTextTouchBar setCustomizationIdentifier:@"WebRichTextTouchBar"];
+    }
+
+    if (!_private->_plainTextTouchBar) {
+        _private->_plainTextTouchBar = adoptNS([[NSTouchBar alloc] init]);
+        [self setUpTextTouchBar:_private->_plainTextTouchBar.get()];
+        [_private->_plainTextTouchBar setCustomizationIdentifier:@"WebPlainTextTouchBar"];
+    }
+
+    if ([NSSpellChecker isAutomaticTextCompletionEnabled] && !_private->_isCustomizingTouchBar) {
+        BOOL shouldShowCandidateList = !coreFrame->selection().selection().isRange() || coreFrame->editor().ignoreCompositionSelectionChange();
+        [self.candidateList updateWithInsertionPointVisibility:shouldShowCandidateList];
+    }
+
+    if (coreFrame->selection().selection().isInPasswordField()) {
+        // We don't request candidates for password fields. If the user was previously in a non-password field, then the
+        // old candidates will still show by default, so we clear them here by setting an empty array of candidates.
+        if (!_private->_emptyCandidatesArray)
+            _private->_emptyCandidatesArray = adoptNS([[NSArray alloc] init]);
+        [self.candidateList setCandidates:_private->_emptyCandidatesArray.get() forSelectedRange:NSMakeRange(0, 0) inString:nil];
+    }
+
+    NSTouchBar *textTouchBar = self.textTouchBar;
+    NSArray<NSString *> *itemIdentifiers = textTouchBar.itemIdentifiers;
+    BOOL isShowingCombinedTextFormatItem = [itemIdentifiers containsObject:NSTouchBarItemIdentifierTextFormat];
+    [textTouchBar setPrincipalItemIdentifier:isShowingCombinedTextFormatItem ? NSTouchBarItemIdentifierTextFormat : nil];
+
+    // Set current typing attributes for rich text. This will ensure that the buttons reflect the state of
+    // the text when changing selection throughout the document.
+    if (webHTMLView._canEditRichly) {
+        const VisibleSelection& selection = coreFrame->selection().selection();
+        if (!selection.isNone()) {
+            Node* nodeToRemove;
+            if (auto* style = Editor::styleForSelectionStart(coreFrame, nodeToRemove)) {
+                [_private->_textTouchBarItemController setTextIsBold:(style->fontCascade().weight() >= FontWeightBold)];
+                [_private->_textTouchBarItemController setTextIsItalic:(style->fontCascade().italic() == FontItalicOn)];
+
+                RefPtr<EditingStyle> typingStyle = coreFrame->selection().typingStyle();
+                if (typingStyle && typingStyle->style()) {
+                    String value = typingStyle->style()->getPropertyValue(CSSPropertyWebkitTextDecorationsInEffect);
+                    [_private->_textTouchBarItemController setTextIsUnderlined:value.contains("underline")];
+                } else
+                    [_private->_textTouchBarItemController setTextIsUnderlined:(style->textDecorationsInEffect() & TextDecorationUnderline)];
+
+                if (style->visitedDependentColor(CSSPropertyColor).isValid())
+                    [_private->_textTouchBarItemController setTextColor:nsColor(style->visitedDependentColor(CSSPropertyColor))];
+
+                [_private->_textTouchBarItemController setCurrentTextAlignment:nsTextAlignmentFromRenderStyle(style)];
+
+                HTMLElement* enclosingListElement = enclosingList(selection.start().deprecatedNode());
+                if (enclosingListElement) {
+                    if (is<HTMLUListElement>(*enclosingListElement))
+                        [[_private->_textTouchBarItemController webTextListTouchBarViewController] setCurrentListType:WebListType::Unordered];
+                    else if (is<HTMLOListElement>(*enclosingListElement))
+                        [[_private->_textTouchBarItemController webTextListTouchBarViewController] setCurrentListType:WebListType::Ordered];
+                    else
+                        ASSERT_NOT_REACHED();
+                } else
+                    [[_private->_textTouchBarItemController webTextListTouchBarViewController] setCurrentListType:WebListType::None];
+
+                if (nodeToRemove)
+                    nodeToRemove->remove();
+            }
+        }
+        BOOL isShowingCandidateListItem = [itemIdentifiers containsObject:NSTouchBarItemIdentifierCandidateList] && [NSSpellChecker isAutomaticTextCompletionEnabled];
+        [_private->_textTouchBarItemController setUsesNarrowTextStyleItem:isShowingCombinedTextFormatItem && isShowingCandidateListItem];
+    }
+}
+
+- (void)updateMediaTouchBar
+{
+#if ENABLE(WEB_PLAYBACK_CONTROLS_MANAGER)
+    if (!_private->mediaTouchBarProvider)
+        _private->mediaTouchBarProvider = adoptNS([allocAVFunctionBarPlaybackControlsProviderInstance() init]);
+
+    if (![_private->mediaTouchBarProvider playbackControlsController]) {
+        ASSERT(_private->playbackSessionInterface);
+        WebPlaybackControlsManager *manager = _private->playbackSessionInterface->playBackControlsManager();
+        [_private->mediaTouchBarProvider setPlaybackControlsController:(id <AVFunctionBarPlaybackControlsControlling>)manager];
+        [_private->mediaPlaybackControlsView setPlaybackControlsController:(id <AVFunctionBarPlaybackControlsControlling>)manager];
+    }
+#endif
+}
+
+- (void)updateTouchBar
+{
+    if (!_private->_canCreateTouchBars)
+        return;
+
+    Frame* coreFrame = core([self _selectedOrMainFrame]);
+    if (!coreFrame)
+        return;
+
+    NSTouchBar *touchBar = nil;
+    NSView *documentView = [[[self _selectedOrMainFrame] frameView] documentView];
+    if ([documentView isKindOfClass:[WebHTMLView class]]) {
+        WebHTMLView *webHTMLView = (WebHTMLView *)documentView;
+        if ([webHTMLView _isEditable]) {
+            [self updateTextTouchBar];
+            touchBar = [self textTouchBar];
+        }
+#if ENABLE(WEB_PLAYBACK_CONTROLS_MANAGER)
+        else if ([self _hasActiveVideoForControlsInterface]) {
+            [self updateMediaTouchBar];
+            touchBar = [_private->mediaTouchBarProvider respondsToSelector:@selector(touchBar)] ? [(id)_private->mediaTouchBarProvider touchBar] : [(id)_private->mediaTouchBarProvider touchBar];
+        } else if ([_private->mediaTouchBarProvider playbackControlsController]) {
+            [_private->mediaTouchBarProvider setPlaybackControlsController:nil];
+            [_private->mediaPlaybackControlsView setPlaybackControlsController:nil];
+        }
+#endif
+    }
+
+    if (touchBar == _private->_currentTouchBar)
+        return;
+
+    _private->_currentTouchBar = touchBar;
+    [self willChangeValueForKey:@"touchBar"];
+    [self setTouchBar:_private->_currentTouchBar.get()];
+    [self didChangeValueForKey:@"touchBar"];
+}
+
+- (void)prepareForMouseDown
+{
+    _private->_needsDeferredTextTouchBarUpdate = NO;
+    _private->_isDeferringTextTouchBarUpdates = YES;
+}
+
+- (void)prepareForMouseUp
+{
+    if (!_private->_isDeferringTextTouchBarUpdates)
+        return;
+
+    _private->_isDeferringTextTouchBarUpdates = NO;
+    if (_private->_needsDeferredTextTouchBarUpdate) {
+        // Only trigger another update if we attempted and bailed from an update during the deferral.
+        [self updateTouchBar];
+    }
+}
+
+- (NSCandidateListTouchBarItem *)candidateList
+{
+    return self._isRichlyEditable ? _private->_richTextCandidateListTouchBarItem.get() : _private->_plainTextCandidateListTouchBarItem.get();
+}
+#else
+
+- (void)updateTouchBar
+{
+}
+
+- (void)prepareForMouseDown
+{
+}
+
+- (void)prepareForMouseUp
+{
+}
+
+- (id)candidateList
+{
+    return nil;
+}
+
+#endif
+
 @end
 
 @implementation WebView (WebViewDeviceOrientation)
index 3fd4fec..5369ac1 100644 (file)
@@ -101,8 +101,10 @@ class WebViewGroup;
 class WebSelectionServiceController;
 #endif
 
-#if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101200 && USE(APPLE_INTERNAL_SDK)
-#import <WebKitAdditions/WebViewDataAdditionsDeclarations.h>
+#if HAVE(TOUCH_BAR)
+@class WebTextTouchBarItemController;
+@class AVFunctionBarPlaybackControlsProvider;
+@class AVFunctionBarScrubber;
 #endif
 
 class WebViewLayerFlushScheduler : public WebCore::LayerFlushScheduler {
@@ -178,9 +180,24 @@ private:
 #if PLATFORM(MAC)
     WebImmediateActionController *immediateActionController;
 
-#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101200 && USE(APPLE_INTERNAL_SDK)
-#import <WebKitAdditions/WebViewDataAdditions.h>
-#endif
+#if HAVE(TOUCH_BAR)
+    RetainPtr<NSTouchBar> _currentTouchBar;
+    RetainPtr<NSTouchBar> _plainTextTouchBar;
+    RetainPtr<NSTouchBar> _richTextTouchBar;
+    RetainPtr<WebTextTouchBarItemController> _textTouchBarItemController;
+    RetainPtr<NSCandidateListTouchBarItem> _richTextCandidateListTouchBarItem;
+    RetainPtr<NSCandidateListTouchBarItem> _plainTextCandidateListTouchBarItem;
+    RetainPtr<NSArray> _emptyCandidatesArray;
+    RetainPtr<AVFunctionBarPlaybackControlsProvider> mediaTouchBarProvider;
+    RetainPtr<AVFunctionBarScrubber> mediaPlaybackControlsView;
+
+    BOOL _canCreateTouchBars;
+    BOOL _isUpdatingTextTouchBar;
+    BOOL _startedListeningToCustomizationEvents;
+    BOOL _isCustomizingTouchBar;
+    BOOL _isDeferringTextTouchBarUpdates;
+    BOOL _needsDeferredTextTouchBarUpdate;
+#endif // HAVE(TOUCH_BAR)
 
     std::unique_ptr<WebCore::TextIndicatorWindow> textIndicatorWindow;
     BOOL hasInitializedLookupObserver;
index ede1cb5..30dbf1b 100644 (file)
@@ -72,6 +72,7 @@ class WebSelectionServiceController;
 
 #endif
 
+@class NSCandidateListTouchBarItem;
 @class WebBasePluginPackage;
 @class WebDownload;
 @class WebImmediateActionController;
@@ -293,12 +294,10 @@ OBJC_CLASS NSTextAlternatives;
 - (void)_setMockMediaPlaybackTargetPickerName:(NSString *)name state:(WebCore::MediaPlaybackTargetContext::State)state;
 #endif
 
-@end
-
-@interface WebView (WebUpdateWebViewAdditions)
 - (void)prepareForMouseUp;
 - (void)prepareForMouseDown;
-- (void)updateWebViewAdditions;
-- (void)webViewAdditionsWillDestroyView;
-- (id)candidateList;
+- (void)updateTouchBar;
+- (void)_dismissTextTouchBarPopoverItemWithIdentifier:(NSString *)identifier;
+- (NSCandidateListTouchBarItem *)candidateList;
+
 @end
index 2f7e2b2..ca98b10 100644 (file)
@@ -889,6 +889,10 @@ Could be worth adding to the API.
 
 - (void)_setFontFallbackPrefersPictographs:(BOOL)flag;
 
+- (void)showCandidates:(NSArray *)candidates forString:(NSString *)string inRect:(NSRect)rectOfTypedString forSelectedRange:(NSRange)range view:(NSView *)view completionHandler:(void (^)(NSTextCheckingResult *acceptedCandidate))completionBlock;
+- (void)forceRequestCandidatesForTesting;
+- (BOOL)shouldRequestCandidates;
+
 @end
 
 #if !TARGET_OS_IPHONE
@@ -1061,12 +1065,6 @@ Could be worth adding to the API.
 - (NSCachedURLResponse *)webView:(WebView *)sender resource:(id)identifier willCacheResponse:(NSCachedURLResponse *)response fromDataSource:(WebDataSource *)dataSource;
 @end
 
-@interface WebView (WebShowCandidates)
-- (void)showCandidates:(NSArray *)candidates forString:(NSString *)string inRect:(NSRect)rectOfTypedString forSelectedRange:(NSRange)range view:(NSView *)view completionHandler:(void (^)(NSTextCheckingResult *acceptedCandidate))completionBlock;
-- (void)forceRequestCandidatesForTesting;
-- (BOOL)shouldRequestCandidates;
-@end
-
 #ifdef __cplusplus
 extern "C" {
 #endif
index c45fd40..ec35436 100644 (file)
@@ -1,3 +1,90 @@
+2016-11-09  Beth Dakin  <bdakin@apple.com>
+
+        Support TouchBar in WebKit
+        https://bugs.webkit.org/show_bug.cgi?id=164437
+        -and corresponding-
+        rdar://problem/28876524
+
+        Reviewed by Darin Adler.
+
+        * UIProcess/API/Cocoa/WKViewPrivate.h:
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView makeTouchBar]):
+        (-[WKWebView candidateListTouchBarItem]):
+        (-[WKWebView _web_didAddMediaControlsManager:]):
+        (-[WKWebView _web_didRemoveMediaControlsManager]):
+        (-[WKWebView _interactWithMediaControlsForTesting]):
+        (-[WKWebView _wantsMediaPlaybackControlsView]):
+        (-[WKWebView _setWantsMediaPlaybackControlsView:]):
+        (-[WKWebView _mediaPlaybackControlsView]):
+        (-[WKWebView _addMediaPlaybackControlsView:]):
+        (-[WKWebView _removeMediaPlaybackControlsView]):
+        * UIProcess/API/Cocoa/WKWebViewPrivate.h:
+        * UIProcess/API/mac/WKView.mm:
+        (-[WKView makeTouchBar]):
+        (-[WKView candidateListTouchBarItem]):
+        (-[WKView _web_didAddMediaControlsManager:]):
+        (-[WKView _web_didRemoveMediaControlsManager]):
+        (-[WKView _wantsMediaPlaybackControlsView]):
+        (-[WKView _setWantsMediaPlaybackControlsView:]):
+        (-[WKView _mediaPlaybackControlsView]):
+        (-[WKView _addMediaPlaybackControlsView:]):
+        (-[WKView _removeMediaPlaybackControlsView]):
+        * UIProcess/Cocoa/WebViewImpl.h:
+        (WebKit::WebViewImpl::currentTouchBar):
+        (WebKit::WebViewImpl::clientWantsMediaPlaybackControlsView):
+        (WebKit::WebViewImpl::setClientWantsMediaPlaybackControlsView):
+        (WebKit::WebViewImpl::setIsCustomizingTouchBar):
+        * UIProcess/Cocoa/WebViewImpl.mm:
+        (-[WKTextListTouchBarViewController initWithWebViewImpl:]):
+        (-[WKTextListTouchBarViewController didDestroyView]):
+        (-[WKTextListTouchBarViewController _selectList:]):
+        (-[WKTextListTouchBarViewController setCurrentListType:]):
+        (-[WKTextTouchBarItemController initWithWebViewImpl:]):
+        (-[WKTextTouchBarItemController didDestroyView]):
+        (-[WKTextTouchBarItemController touchBar:makeItemForIdentifier:]):
+        (-[WKTextTouchBarItemController itemForIdentifier:]):
+        (-[WKTextTouchBarItemController candidateListTouchBarItem:endSelectingCandidateAtIndex:]):
+        (-[WKTextTouchBarItemController candidateListTouchBarItem:changedCandidateListVisibility:]):
+        (-[WKTextTouchBarItemController textListTouchBarViewController]):
+        (-[WKTextTouchBarItemController setTextIsBold:]):
+        (-[WKTextTouchBarItemController setTextIsItalic:]):
+        (-[WKTextTouchBarItemController setTextIsUnderlined:]):
+        (-[WKTextTouchBarItemController _wkChangeTextStyle:]):
+        (-[WKTextTouchBarItemController setCurrentTextAlignment:]):
+        (-[WKTextTouchBarItemController _wkChangeTextAlignment:]):
+        (-[WKTextTouchBarItemController textColor]):
+        (-[WKTextTouchBarItemController setTextColor:]):
+        (-[WKTextTouchBarItemController _wkChangeColor:]):
+        (-[WKTextTouchBarItemController textListViewController]):
+        (WebKit::WebViewImpl::makeTouchBar):
+        (WebKit::WebViewImpl::candidateListTouchBarItem):
+        (WebKit::WebViewImpl::mediaPlaybackControlsView):
+        (WebKit::WebViewImpl::useMediaPlaybackControlsView):
+        (WebKit::WebViewImpl::dismissTextTouchBarPopoverItemWithIdentifier):
+        (WebKit::textTouchBarCustomizationAllowedIdentifiers):
+        (WebKit::plainTextTouchBarCustomizationDefaultItemIdentifiers):
+        (WebKit::richTextTouchBarCustomizationDefaultItemIdentifiers):
+        (WebKit::touchBarDidExitCustomization):
+        (WebKit::touchBarWillEnterCustomization):
+        (WebKit::didChangeAutomaticTextCompletion):
+        (WebKit::WebViewImpl::updateTouchBarAndRefreshTextBarIdentifiers):
+        (WebKit::WebViewImpl::setUpTextTouchBar):
+        (WebKit::WebViewImpl::isRichlyEditable):
+        (WebKit::WebViewImpl::textTouchBar):
+        (WebKit::WebViewImpl::updateTextTouchBar):
+        (WebKit::WebViewImpl::updateMediaTouchBar):
+        (WebKit::WebViewImpl::forceRequestCandidatesForTesting):
+        (WebKit::WebViewImpl::updateTouchBar):
+        (WebKit::WebViewImpl::shouldRequestCandidates):
+        (WebKit::WebViewImpl::showCandidates):
+        (WebKit::WebViewImpl::webViewImplAdditionsWillDestroyView):
+        (WebKit::WebViewImpl::setEditableElementIsFocused):
+        (WebKit::WebViewImpl::becomeFirstResponder):
+        (WebKit::WebViewImpl::selectionDidChange):
+        (WebKit::WebViewImpl::videoControlsManagerDidChange):
+        (WebKit::WebViewImpl::updateWebViewImplAdditions): Deleted.
+
 2016-11-09  Chris Dumez  <cdumez@apple.com>
 
         [WK2][NETWORK_SESSION] Add support for downloading file backed blobs
index 1f3ebec..7f6b139 100644 (file)
@@ -31,6 +31,8 @@
 #import <WebKit/WKView.h>
 #import <WebKit/_WKOverlayScrollbarStyle.h>
 
+@class AVFunctionBarScrubber;
+
 @interface WKView (Private)
 
 /* C SPI support. */
 
 - (void)_gestureEventWasNotHandledByWebCore:(NSEvent *)event;
 
+@property (nonatomic, readwrite, setter=_setWantsMediaPlaybackControlsView:) BOOL _wantsMediaPlaybackControlsView;
+@property (nonatomic, readonly) AVFunctionBarScrubber *_mediaPlaybackControlsView;
+- (void)_addMediaPlaybackControlsView:(AVFunctionBarScrubber *)mediaPlaybackControlsView;
+- (void)_removeMediaPlaybackControlsView;
+
 @end
 
 #endif // !TARGET_OS_IPHONE
index c500571..8ded988 100644 (file)
@@ -174,7 +174,12 @@ static const uint32_t firstSDKVersionWithLinkPreviewEnabledByDefault = 0xA0000;
 
 @interface WKWebView () <WebViewImplDelegate, NSTextInputClient>
 @end
-#endif
+
+#if HAVE(TOUCH_BAR)
+@interface WKWebView () <NSTouchBarProvider>
+@end
+#endif // HAVE(TOUCH_BAR)
+#endif // PLATFORM(MAC)
 
 static HashMap<WebKit::WebPageProxy*, WKWebView *>& pageToViewMap()
 {
@@ -3155,6 +3160,38 @@ WEBCORE_COMMAND(yankAndSelect)
 
 #endif // PLATFORM(MAC)
 
+#if HAVE(TOUCH_BAR)
+
+@dynamic touchBar;
+
+- (NSTouchBar *)makeTouchBar
+{
+    return _impl->makeTouchBar();
+}
+
+- (NSCandidateListTouchBarItem *)candidateListTouchBarItem
+{
+    return _impl->candidateListTouchBarItem();
+}
+
+- (void)_web_didAddMediaControlsManager:(id)controlsManager
+{
+    [self _addMediaPlaybackControlsView:controlsManager];
+}
+
+- (void)_web_didRemoveMediaControlsManager
+{
+    [self _removeMediaPlaybackControlsView];
+}
+
+- (void)_interactWithMediaControlsForTesting
+{
+    [self _setWantsMediaPlaybackControlsView:YES];
+    [self makeTouchBar];
+}
+
+#endif // HAVE(TOUCH_BAR)
+
 @end
 
 @implementation WKWebView (WKPrivate)
@@ -4529,6 +4566,41 @@ static WebCore::UserInterfaceLayoutDirection toUserInterfaceLayoutDirection(UISe
     _impl->setUserInterfaceLayoutDirection(userInterfaceLayoutDirection);
 }
 
+- (BOOL)_wantsMediaPlaybackControlsView
+{
+#if HAVE(TOUCH_BAR)
+    return _impl->clientWantsMediaPlaybackControlsView();
+#else
+    return NO;
+#endif
+}
+
+- (void)_setWantsMediaPlaybackControlsView:(BOOL)wantsMediaPlaybackControlsView
+{
+#if HAVE(TOUCH_BAR)
+    _impl->setClientWantsMediaPlaybackControlsView(wantsMediaPlaybackControlsView);
+#endif
+}
+
+- (AVFunctionBarScrubber *)_mediaPlaybackControlsView
+{
+#if HAVE(TOUCH_BAR)
+    return _impl->clientWantsMediaPlaybackControlsView() ? _impl->mediaPlaybackControlsView() : nil;
+#else
+    return nil;
+#endif
+}
+
+// This method is for subclasses to override.
+- (void)_addMediaPlaybackControlsView:(AVFunctionBarScrubber *)mediaPlaybackControlsView
+{
+}
+
+// This method is for subclasses to override.
+- (void)_removeMediaPlaybackControlsView
+{
+}
+
 #endif
 
 @end
index 76a9db3..03e84c2 100644 (file)
@@ -52,6 +52,7 @@ typedef NS_ENUM(NSInteger, _WKImmediateActionType) {
 
 #endif
 
+@class AVFunctionBarScrubber;
 @class WKBrowsingContextHandle;
 @class _WKFrameHandle;
 @class _WKHitTestResult;
@@ -202,6 +203,12 @@ typedef NS_ENUM(NSInteger, _WKImmediateActionType) {
 - (NSPrintOperation *)_printOperationWithPrintInfo:(NSPrintInfo *)printInfo;
 - (NSPrintOperation *)_printOperationWithPrintInfo:(NSPrintInfo *)printInfo forFrame:(_WKFrameHandle *)frameHandle WK_API_AVAILABLE(macosx(10.12), ios(10.0));
 
+// FIXME: This SPI should become a part of the WKUIDelegate. rdar://problem/26561537
+@property (nonatomic, readwrite, setter=_setWantsMediaPlaybackControlsView:) BOOL _wantsMediaPlaybackControlsView WK_API_AVAILABLE(macosx(WK_MAC_TBA));
+@property (nonatomic, readonly) AVFunctionBarScrubber *_mediaPlaybackControlsView WK_API_AVAILABLE(macosx(WK_MAC_TBA));
+- (void)_addMediaPlaybackControlsView:(AVFunctionBarScrubber *)mediaPlaybackControlsView WK_API_AVAILABLE(macosx(WK_MAC_TBA));
+- (void)_removeMediaPlaybackControlsView WK_API_AVAILABLE(macosx(WK_MAC_TBA));
+
 #endif
 
 - (WKNavigation *)_reloadWithoutContentBlockers WK_API_AVAILABLE(macosx(10.12), ios(10.0));
index 1f903ee..a63398a 100644 (file)
@@ -55,6 +55,11 @@ using namespace WebCore;
 @interface WKView () <WebViewImplDelegate>
 @end
 
+#if HAVE(TOUCH_BAR)
+@interface WKView () <NSTouchBarProvider>
+@end
+#endif
+
 @implementation WKView
 
 #if WK_API_ENABLED
@@ -977,6 +982,32 @@ Some other editing-related methods still unimplemented:
 {
 }
 
+#if HAVE(TOUCH_BAR)
+
+@dynamic touchBar;
+
+- (NSTouchBar *)makeTouchBar
+{
+    return _data->_impl->makeTouchBar();
+}
+
+- (NSCandidateListTouchBarItem *)candidateListTouchBarItem
+{
+    return _data->_impl->candidateListTouchBarItem();
+}
+
+- (void)_web_didAddMediaControlsManager:(id)controlsManager
+{
+    [self _addMediaPlaybackControlsView:controlsManager];
+}
+
+- (void)_web_didRemoveMediaControlsManager
+{
+    [self _removeMediaPlaybackControlsView];
+}
+
+#endif // HAVE(TOUCH_BAR)
+
 @end
 
 @implementation WKView (Private)
@@ -1467,10 +1498,41 @@ static _WKOverlayScrollbarStyle toAPIScrollbarStyle(WTF::Optional<WebCore::Scrol
     _data->_impl->setUserInterfaceLayoutDirection(userInterfaceLayoutDirection);
 }
 
-@end
+- (BOOL)_wantsMediaPlaybackControlsView
+{
+#if HAVE(TOUCH_BAR)
+    return _data->_impl->clientWantsMediaPlaybackControlsView();
+#else
+    return NO;
+#endif
+}
 
-#if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101200 && USE(APPLE_INTERNAL_SDK)
-#import <WebKitAdditions/WKViewAdditions.mm>
+- (void)_setWantsMediaPlaybackControlsView:(BOOL)wantsMediaPlaybackControlsView
+{
+#if HAVE(TOUCH_BAR)
+    _data->_impl->setClientWantsMediaPlaybackControlsView(wantsMediaPlaybackControlsView);
+#endif
+}
+
+- (AVFunctionBarScrubber *)_mediaPlaybackControlsView
+{
+#if HAVE(TOUCH_BAR)
+    return _data->_impl->clientWantsMediaPlaybackControlsView() ? _data->_impl->mediaPlaybackControlsView() : nil;
+#else
+    return nil;
 #endif
+}
+
+// This method is for subclasses to override.
+- (void)_addMediaPlaybackControlsView:(AVFunctionBarScrubber *)mediaPlaybackControlsView
+{
+}
+
+// This method is for subclasses to override.
+- (void)_removeMediaPlaybackControlsView
+{
+}
+
+@end
 
 #endif // PLATFORM(MAC)
index 73bf2bb..ba79936 100644 (file)
@@ -52,9 +52,17 @@ OBJC_CLASS WKWebView;
 OBJC_CLASS WKWindowVisibilityObserver;
 OBJC_CLASS _WKThumbnailView;
 
-#if USE(APPLE_INTERNAL_SDK) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101200
-#import <WebKitAdditions/WebViewImplAdditionsDeclarations.h>
-#endif
+#if HAVE(TOUCH_BAR)
+OBJC_CLASS AVFunctionBarPlaybackControlsProvider;
+OBJC_CLASS AVFunctionBarScrubber;
+OBJC_CLASS NSCandidateListTouchBarItem;
+OBJC_CLASS NSCustomTouchBarItem;
+OBJC_CLASS NSTouchBar;
+OBJC_CLASS NSTouchBarItem;
+OBJC_CLASS NSPopoverTouchBarItem;
+OBJC_CLASS WKTextTouchBarItemController;
+OBJC_CLASS WebPlaybackControlsManager;
+#endif // HAVE(TOUCH_BAR)
 
 @protocol WebViewImplDelegate
 
@@ -480,11 +488,9 @@ public:
     void rightMouseDragged(NSEvent *);
     void rightMouseUp(NSEvent *);
 
-    void updateWebViewImplAdditions();
     void forceRequestCandidatesForTesting();
     bool shouldRequestCandidates() const;
     void showCandidates(NSArray *candidates, NSString *, NSRect rectOfTypedString, NSRange selectedRange, NSView *, void (^completionHandler)(NSTextCheckingResult *acceptedCandidate));
-    void webViewImplAdditionsWillDestroyView();
 
     bool windowIsFrontWindowUnderMouse(NSEvent *);
 
@@ -496,12 +502,55 @@ public:
 
 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101200 
     void handleAcceptedCandidate(NSTextCheckingResult *acceptedCandidate);
-#if USE(APPLE_INTERNAL_SDK)
-#import <WebKitAdditions/WebViewImplAdditions.h>
-#endif
 #endif
 
+#if HAVE(TOUCH_BAR)
+    NSTouchBar *makeTouchBar();
+    void updateTouchBar();
+    NSTouchBar *currentTouchBar() const { return m_currentTouchBar.get(); }
+    NSCandidateListTouchBarItem *candidateListTouchBarItem() const;
+    AVFunctionBarScrubber *mediaPlaybackControlsView() const;
+    NSTouchBar *textTouchBar() const;
+    void dismissTextTouchBarPopoverItemWithIdentifier(NSString *);
+
+    bool clientWantsMediaPlaybackControlsView() const { return m_clientWantsMediaPlaybackControlsView; }
+    void setClientWantsMediaPlaybackControlsView(bool clientWantsMediaPlaybackControlsView) { m_clientWantsMediaPlaybackControlsView = clientWantsMediaPlaybackControlsView; }
+
+    void updateTouchBarAndRefreshTextBarIdentifiers();
+    void setIsCustomizingTouchBar(bool isCustomizingTouchBar) { m_isCustomizingTouchBar = isCustomizingTouchBar; };
+#endif // HAVE(TOUCH_BAR)
+
 private:
+#if HAVE(TOUCH_BAR)
+    void setUpTextTouchBar(NSTouchBar *);
+    void updateTextTouchBar();
+    void updateMediaTouchBar();
+
+    bool useMediaPlaybackControlsView() const;
+    bool isRichlyEditable() const;
+
+    bool m_clientWantsMediaPlaybackControlsView { false };
+    bool m_canCreateTouchBars { false };
+    bool m_startedListeningToCustomizationEvents { false };
+    bool m_isUpdatingTextTouchBar { false };
+    bool m_isCustomizingTouchBar { false };
+
+    RetainPtr<NSTouchBar> m_currentTouchBar;
+    RetainPtr<NSTouchBar> m_richTextTouchBar;
+    RetainPtr<NSTouchBar> m_plainTextTouchBar;
+    RetainPtr<WKTextTouchBarItemController> m_textTouchBarItemController;
+    RetainPtr<NSCandidateListTouchBarItem> m_richTextCandidateListTouchBarItem;
+    RetainPtr<NSCandidateListTouchBarItem> m_plainTextCandidateListTouchBarItem;
+    RetainPtr<NSArray> m_emptyCandidatesArray;
+    RetainPtr<WebPlaybackControlsManager> m_playbackControlsManager;
+    RetainPtr<NSCustomTouchBarItem> m_exitFullScreenButton;
+
+#if ENABLE(WEB_PLAYBACK_CONTROLS_MANAGER)
+    RetainPtr<AVFunctionBarPlaybackControlsProvider> m_mediaTouchBarProvider;
+    RetainPtr<AVFunctionBarScrubber> m_mediaPlaybackControlsView;
+#endif // ENABLE(WEB_PLAYBACK_CONTROLS_MANAGER)
+#endif // HAVE(TOUCH_BAR)
+
     WeakPtr<WebViewImpl> createWeakPtr() { return m_weakPtrFactory.createWeakPtr(); }
 
     bool supportsArbitraryLayoutModes() const;
index 32e639c..c28ca3c 100644 (file)
 #import "WebEventFactory.h"
 #import "WebInspectorProxy.h"
 #import "WebPageProxy.h"
+#import "WebPlaybackSessionManagerProxy.h"
 #import "WebProcessPool.h"
 #import "WebProcessProxy.h"
 #import "_WKRemoteObjectRegistryInternal.h"
 #import "_WKThumbnailViewInternal.h"
 #import <HIToolbox/CarbonEventsCore.h>
+#import <WebCore/AVKitSPI.h>
 #import <WebCore/AXObjectCache.h>
 #import <WebCore/ActivityState.h>
 #import <WebCore/ColorMac.h>
@@ -80,6 +82,7 @@
 #import <WebCore/NSImmediateActionGestureRecognizerSPI.h>
 #import <WebCore/NSSpellCheckerSPI.h>
 #import <WebCore/NSTextFinderSPI.h>
+#import <WebCore/NSTouchBarSPI.h>
 #import <WebCore/NSWindowSPI.h>
 #import <WebCore/PlatformEventFactoryMac.h>
 #import <WebCore/SoftLinking.h>
 #import <WebCore/WebCoreFullScreenPlaceholderView.h>
 #import <WebCore/WebCoreFullScreenWindow.h>
 #import <WebCore/WebCoreNSStringExtras.h>
+#import <WebCore/WebPlaybackControlsManager.h>
 #import <WebKitSystemInterface.h>
 #import <sys/stat.h>
 #import <wtf/NeverDestroyed.h>
+#import <wtf/TemporaryChange.h>
 
-#if USE(APPLE_INTERNAL_SDK)
-#import <WebKitAdditions/WebViewImplIncludes.h>
-#endif
+#if HAVE(TOUCH_BAR) && ENABLE(WEB_PLAYBACK_CONTROLS_MANAGER)
+SOFT_LINK_FRAMEWORK(AVKit)
+SOFT_LINK_CLASS(AVKit, AVFunctionBarPlaybackControlsProvider)
+SOFT_LINK_CLASS(AVKit, AVFunctionBarScrubber)
+
+static NSString * const WKMediaExitFullScreenItem = @"WKMediaExitFullScreenItem";
+#endif // HAVE(TOUCH_BAR) && ENABLE(WEB_PLAYBACK_CONTROLS_MANAGER)
 
 SOFT_LINK_CONSTANT_MAY_FAIL(Lookup, LUNotificationPopoverWillClose, NSString *)
 
@@ -433,29 +442,707 @@ static void* keyValueObservingContext = &keyValueObservingContext;
 
 @end
 
-#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101200 && USE(APPLE_INTERNAL_SDK)
-#import <WebKitAdditions/WebViewImplAdditions.mm>
-#else
+using namespace WebKit;
+
+#if HAVE(TOUCH_BAR)
+
+@interface WKTextListTouchBarViewController : NSViewController {
+@private
+    WebViewImpl* _webViewImpl;
+}
+
+@property (nonatomic) ListType currentListType;
+
+- (instancetype)initWithWebViewImpl:(WebViewImpl*)webViewImpl;
+
+@end
+
+@implementation WKTextListTouchBarViewController
+
+@synthesize currentListType=_currentListType;
+
+static const CGFloat listControlSegmentWidth = 67;
+static const CGFloat exitFullScreenButtonWidth = 64;
+
+static const NSUInteger noListSegment = 0;
+static const NSUInteger unorderedListSegment = 1;
+static const NSUInteger orderedListSegment = 2;
+
+- (instancetype)initWithWebViewImpl:(WebViewImpl*)webViewImpl
+{
+    if (!(self = [super init]))
+        return nil;
+
+    _webViewImpl = webViewImpl;
+
+    NSSegmentedControl *insertListControl = [NSSegmentedControl segmentedControlWithLabels:@[ WebCore::insertListTypeNone(), WebCore::insertListTypeBulleted(), WebCore::insertListTypeNumbered() ] trackingMode:NSSegmentSwitchTrackingSelectOne target:self action:@selector(_selectList:)];
+    [insertListControl setWidth:listControlSegmentWidth forSegment:noListSegment];
+    [insertListControl setWidth:listControlSegmentWidth forSegment:unorderedListSegment];
+    [insertListControl setWidth:listControlSegmentWidth forSegment:orderedListSegment];
+    insertListControl.font = [NSFont systemFontOfSize:15];
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+    id segmentElement = NSAccessibilityUnignoredDescendant(insertListControl);
+    NSArray *segments = [segmentElement accessibilityAttributeValue:NSAccessibilityChildrenAttribute];
+    ASSERT(segments.count == 3);
+    [segments[noListSegment] accessibilitySetOverrideValue:WebCore::insertListTypeNone() forAttribute:NSAccessibilityDescriptionAttribute];
+    [segments[unorderedListSegment] accessibilitySetOverrideValue:WebCore::insertListTypeBulletedAccessibilityTitle() forAttribute:NSAccessibilityDescriptionAttribute];
+    [segments[orderedListSegment] accessibilitySetOverrideValue:WebCore::insertListTypeNumberedAccessibilityTitle() forAttribute:NSAccessibilityDescriptionAttribute];
+#pragma clang diagnostic pop
+
+    self.view = insertListControl;
+
+    return self;
+}
+
+- (void)didDestroyView
+{
+    _webViewImpl = nullptr;
+}
+
+- (void)_selectList:(id)sender
+{
+    if (!_webViewImpl)
+        return;
+
+    NSSegmentedControl *insertListControl = (NSSegmentedControl *)self.view;
+    switch (insertListControl.selectedSegment) {
+    case noListSegment:
+        // There is no "remove list" edit command, but InsertOrderedList and InsertUnorderedList both
+        // behave as toggles, so we can invoke the appropriate edit command depending on our _currentListType
+        // to remove an existing list. We don't have to do anything if _currentListType is NoList.
+        if (_currentListType == OrderedList)
+            _webViewImpl->page().executeEditCommand(@"InsertOrderedList", @"");
+        else if (_currentListType == UnorderedList)
+            _webViewImpl->page().executeEditCommand(@"InsertUnorderedList", @"");
+        break;
+    case unorderedListSegment:
+        _webViewImpl->page().executeEditCommand(@"InsertUnorderedList", @"");
+        break;
+    case orderedListSegment:
+        _webViewImpl->page().executeEditCommand(@"InsertOrderedList", @"");
+        break;
+    }
+
+    _webViewImpl->dismissTextTouchBarPopoverItemWithIdentifier(NSTouchBarItemIdentifierTextList);
+}
+
+- (void)setCurrentListType:(ListType)listType
+{
+    NSSegmentedControl *insertListControl = (NSSegmentedControl *)self.view;
+    switch (listType) {
+    case NoList:
+        [insertListControl setSelected:YES forSegment:noListSegment];
+        break;
+    case OrderedList:
+        [insertListControl setSelected:YES forSegment:orderedListSegment];
+        break;
+    case UnorderedList:
+        [insertListControl setSelected:YES forSegment:unorderedListSegment];
+        break;
+    }
+
+    _currentListType = listType;
+}
+
+@end
+
+@interface WKTextTouchBarItemController : NSTextTouchBarItemController <NSCandidateListTouchBarItemDelegate, NSTouchBarDelegate> {
+@private
+    BOOL _textIsBold;
+    BOOL _textIsItalic;
+    BOOL _textIsUnderlined;
+    NSTextAlignment _currentTextAlignment;
+    RetainPtr<NSColor> _textColor;
+    RetainPtr<WKTextListTouchBarViewController> _textListTouchBarViewController;
+
+@private
+    WebViewImpl* _webViewImpl;
+}
+
+@property (nonatomic) BOOL textIsBold;
+@property (nonatomic) BOOL textIsItalic;
+@property (nonatomic) BOOL textIsUnderlined;
+@property (nonatomic) NSTextAlignment currentTextAlignment;
+@property (nonatomic, retain, readwrite) NSColor *textColor;
+
+- (instancetype)initWithWebViewImpl:(WebViewImpl*)webViewImpl;
+@end
+
+@implementation WKTextTouchBarItemController
+
+@synthesize textIsBold=_textIsBold;
+@synthesize textIsItalic=_textIsItalic;
+@synthesize textIsUnderlined=_textIsUnderlined;
+@synthesize currentTextAlignment=_currentTextAlignment;
+
+- (instancetype)initWithWebViewImpl:(WebViewImpl*)webViewImpl
+{
+    if (!(self = [super init]))
+        return nil;
+
+    _webViewImpl = webViewImpl;
+
+    return self;
+}
+
+- (void)didDestroyView
+{
+    [[NSNotificationCenter defaultCenter] removeObserver:self];
+    _webViewImpl = nullptr;
+    [_textListTouchBarViewController didDestroyView];
+}
+
+#pragma mark NSTouchBarDelegate
+
+- (NSTouchBarItem *)touchBar:(NSTouchBar *)touchBar makeItemForIdentifier:(NSString *)identifier
+{
+    return [self itemForIdentifier:identifier];
+}
+
+- (nullable NSTouchBarItem *)itemForIdentifier:(NSString *)identifier
+{
+    NSTouchBarItem *item = [super itemForIdentifier:identifier];
+    BOOL isTextFormatItem = [identifier isEqualToString:NSTouchBarItemIdentifierTextFormat];
+
+    if (isTextFormatItem || [identifier isEqualToString:NSTouchBarItemIdentifierTextStyle])
+        self.textStyle.action = @selector(_wkChangeTextStyle:);
+
+    if (isTextFormatItem || [identifier isEqualToString:NSTouchBarItemIdentifierTextAlignment])
+        self.textAlignments.action = @selector(_wkChangeTextAlignment:);
+
+    NSColorPickerTouchBarItem *colorPickerItem = nil;
+    if ([identifier isEqualToString:NSTouchBarItemIdentifierTextColorPicker] && [item isKindOfClass:[NSColorPickerTouchBarItem class]])
+        colorPickerItem = (NSColorPickerTouchBarItem *)item;
+    if (isTextFormatItem)
+        colorPickerItem = self.colorPickerItem;
+    if (colorPickerItem) {
+        colorPickerItem.target = self;
+        colorPickerItem.action = @selector(_wkChangeColor:);
+        colorPickerItem.showsAlpha = NO;
+    }
+
+    return item;
+}
+
+#pragma mark NSCandidateListTouchBarItemDelegate
+
+- (void)candidateListTouchBarItem:(NSCandidateListTouchBarItem *)anItem endSelectingCandidateAtIndex:(NSInteger)index
+{
+    if (index == NSNotFound)
+        return;
+
+    if (!_webViewImpl)
+        return;
+
+    NSArray *candidates = anItem.candidates;
+    if ((NSUInteger)index >= candidates.count)
+        return;
+
+    NSTextCheckingResult *candidate = candidates[index];
+    ASSERT([candidate isKindOfClass:[NSTextCheckingResult class]]);
+
+    _webViewImpl->handleAcceptedCandidate(candidate);
+}
+
+- (void)candidateListTouchBarItem:(NSCandidateListTouchBarItem *)anItem changedCandidateListVisibility:(BOOL)isVisible
+{
+    if (!_webViewImpl)
+        return;
+
+    if (isVisible)
+        _webViewImpl->requestCandidatesForSelectionIfNeeded();
+
+    _webViewImpl->updateTouchBar();
+}
+
+#pragma mark NSNotificationCenter observers
+
+- (void)touchBarDidExitCustomization:(NSNotification *)notification
+{
+    if (!_webViewImpl)
+        return;
+
+    _webViewImpl->setIsCustomizingTouchBar(false);
+    _webViewImpl->updateTouchBar();
+}
+
+- (void)touchBarWillEnterCustomization:(NSNotification *)notification
+{
+    if (!_webViewImpl)
+        return;
+
+    _webViewImpl->setIsCustomizingTouchBar(true);
+}
+
+- (void)didChangeAutomaticTextCompletion:(NSNotification *)notification
+{
+    if (!_webViewImpl)
+        return;
+
+    _webViewImpl->updateTouchBarAndRefreshTextBarIdentifiers();
+}
+
+
+#pragma mark NSTextTouchBarItemController
+
+- (WKTextListTouchBarViewController *)textListTouchBarViewController
+{
+    return (WKTextListTouchBarViewController *)self.textListViewController;
+}
+
+- (void)setTextIsBold:(BOOL)bold
+{
+    _textIsBold = bold;
+    if ([self.textStyle isSelectedForSegment:0] != _textIsBold)
+        [self.textStyle setSelected:_textIsBold forSegment:0];
+}
+
+- (void)setTextIsItalic:(BOOL)italic
+{
+    _textIsItalic = italic;
+    if ([self.textStyle isSelectedForSegment:1] != _textIsItalic)
+        [self.textStyle setSelected:_textIsItalic forSegment:1];
+}
+
+- (void)setTextIsUnderlined:(BOOL)underlined
+{
+    _textIsUnderlined = underlined;
+    if ([self.textStyle isSelectedForSegment:2] != _textIsUnderlined)
+        [self.textStyle setSelected:_textIsUnderlined forSegment:2];
+}
+
+- (void)_wkChangeTextStyle:(id)sender
+{
+    if (!_webViewImpl)
+        return;
+
+    if ([self.textStyle isSelectedForSegment:0] != _textIsBold) {
+        _textIsBold = !_textIsBold;
+        _webViewImpl->page().executeEditCommand(@"ToggleBold", @"");
+    }
+
+    if ([self.textStyle isSelectedForSegment:1] != _textIsItalic) {
+        _textIsItalic = !_textIsItalic;
+        _webViewImpl->page().executeEditCommand("ToggleItalic", @"");
+    }
+
+    if ([self.textStyle isSelectedForSegment:2] != _textIsUnderlined) {
+        _textIsUnderlined = !_textIsUnderlined;
+        _webViewImpl->page().executeEditCommand("ToggleUnderline", @"");
+    }
+}
+
+- (void)setCurrentTextAlignment:(NSTextAlignment)alignment
+{
+    _currentTextAlignment = alignment;
+    [self.textAlignments selectSegmentWithTag:_currentTextAlignment];
+}
+
+- (void)_wkChangeTextAlignment:(id)sender
+{
+    if (!_webViewImpl)
+        return;
+
+    NSTextAlignment alignment = (NSTextAlignment)[self.textAlignments.cell tagForSegment:self.textAlignments.selectedSegment];
+    switch (alignment) {
+    case NSTextAlignmentLeft:
+        _currentTextAlignment = NSTextAlignmentLeft;
+        _webViewImpl->page().executeEditCommand("AlignLeft", @"");
+        break;
+    case NSTextAlignmentRight:
+        _currentTextAlignment = NSTextAlignmentRight;
+        _webViewImpl->page().executeEditCommand("AlignRight", @"");
+        break;
+    case NSTextAlignmentCenter:
+        _currentTextAlignment = NSTextAlignmentCenter;
+        _webViewImpl->page().executeEditCommand("AlignCenter", @"");
+        break;
+    case NSTextAlignmentJustified:
+        _currentTextAlignment = NSTextAlignmentJustified;
+        _webViewImpl->page().executeEditCommand("AlignJustified", @"");
+        break;
+    default:
+        break;
+    }
+
+    _webViewImpl->dismissTextTouchBarPopoverItemWithIdentifier(NSTouchBarItemIdentifierTextAlignment);
+}
+
+- (NSColor *)textColor
+{
+    return _textColor.get();
+}
+
+- (void)setTextColor:(NSColor *)color
+{
+    _textColor = color;
+    self.colorPickerItem.color = _textColor.get();
+}
+
+- (void)_wkChangeColor:(id)sender
+{
+    if (!_webViewImpl)
+        return;
+
+    _textColor = self.colorPickerItem.color;
+    _webViewImpl->page().executeEditCommand("ForeColor", WebCore::colorFromNSColor(_textColor.get()).serialized());
+}
+
+- (NSViewController *)textListViewController
+{
+    if (!_textListTouchBarViewController)
+        _textListTouchBarViewController = adoptNS([[WKTextListTouchBarViewController alloc] initWithWebViewImpl:_webViewImpl]);
+    return _textListTouchBarViewController.get();
+}
+
+@end
+
 namespace WebKit {
 
-void WebViewImpl::updateWebViewImplAdditions()
+NSTouchBar *WebViewImpl::makeTouchBar()
+{
+    if (!m_canCreateTouchBars) {
+        m_canCreateTouchBars = true;
+        updateTouchBar();
+    }
+    return m_currentTouchBar.get();
+}
+
+void WebViewImpl::updateTouchBar()
+{
+    if (!m_canCreateTouchBars)
+        return;
+
+    NSTouchBar *touchBar = nil;
+    bool userActionRequirementsHaveBeenMet = m_requiresUserActionForEditingControlsManager ? m_page->hasHadSelectionChangesFromUserInteraction() : true;
+    if (m_page->editorState().isContentEditable && !m_page->needsHiddenContentEditableQuirk()) {
+        updateTextTouchBar();
+        if (userActionRequirementsHaveBeenMet)
+            touchBar = textTouchBar();
+    }
+#if ENABLE(WEB_PLAYBACK_CONTROLS_MANAGER)
+    else if (m_page->hasActiveVideoForControlsManager()) {
+        updateMediaTouchBar();
+        // If useMediaPlaybackControlsView() is true, then we are relying on the API client to display a popover version
+        // of the media timeline in their own function bar. If it is false, then we will display the media timeline in our
+        // function bar.
+        if (!useMediaPlaybackControlsView())
+            touchBar = [m_mediaTouchBarProvider respondsToSelector:@selector(touchBar)] ? [(id)m_mediaTouchBarProvider.get() touchBar] : [(id)m_mediaTouchBarProvider.get() touchBar];
+    } else if ([m_mediaTouchBarProvider playbackControlsController]) {
+        if (m_clientWantsMediaPlaybackControlsView) {
+            if ([m_view respondsToSelector:@selector(_web_didRemoveMediaControlsManager)] && m_view == m_view.window.firstResponder)
+                [m_view _web_didRemoveMediaControlsManager];
+        }
+        [m_mediaTouchBarProvider setPlaybackControlsController:nil];
+        [m_mediaPlaybackControlsView setPlaybackControlsController:nil];
+    }
+#endif
+
+    if (touchBar == m_currentTouchBar)
+        return;
+
+    // If m_editableElementIsFocused is true, then we may have a non-editable selection right now just because
+    // the user is clicking or tabbing between editable fields.
+    if (m_editableElementIsFocused && touchBar != textTouchBar())
+        return;
+
+    m_currentTouchBar = touchBar;
+    [m_view willChangeValueForKey:@"touchBar"];
+    [m_view setTouchBar:m_currentTouchBar.get()];
+    [m_view didChangeValueForKey:@"touchBar"];
+}
+
+NSCandidateListTouchBarItem *WebViewImpl::candidateListTouchBarItem() const
+{
+    return isRichlyEditable() ? m_richTextCandidateListTouchBarItem.get() : m_plainTextCandidateListTouchBarItem.get();
+}
+
+AVFunctionBarScrubber *WebViewImpl::mediaPlaybackControlsView() const
+{
+#if ENABLE(WEB_PLAYBACK_CONTROLS_MANAGER)
+    if (m_page->hasActiveVideoForControlsManager())
+        return m_mediaPlaybackControlsView.get();
+#endif
+    return nil;
+}
+
+bool WebViewImpl::useMediaPlaybackControlsView() const
+{
+#if ENABLE(FULLSCREEN_API)
+    if (hasFullScreenWindowController())
+        return ![m_fullScreenWindowController isFullScreen];
+#endif
+    return m_clientWantsMediaPlaybackControlsView;
+}
+
+void WebViewImpl::dismissTextTouchBarPopoverItemWithIdentifier(NSString *identifier)
+{
+    NSTouchBarItem *foundItem = nil;
+    for (NSTouchBarItem *item in textTouchBar().items) {
+        if ([item.identifier isEqualToString:identifier]) {
+            foundItem = item;
+            break;
+        }
+
+        if ([item.identifier isEqualToString:NSTouchBarItemIdentifierTextFormat]) {
+            for (NSTouchBarItem *childItem in ((NSGroupTouchBarItem *)item).groupTouchBar.items) {
+                if ([childItem.identifier isEqualToString:identifier]) {
+                    foundItem = childItem;
+                    break;
+                }
+            }
+            break;
+        }
+    }
+
+    if ([foundItem isKindOfClass:[NSPopoverTouchBarItem class]])
+        [(NSPopoverTouchBarItem *)foundItem dismissPopover:nil];
+}
+
+static NSArray<NSString *> *textTouchBarCustomizationAllowedIdentifiers()
 {
+    return @[ NSTouchBarItemIdentifierCharacterPicker, NSTouchBarItemIdentifierTextColorPicker, NSTouchBarItemIdentifierTextStyle, NSTouchBarItemIdentifierTextAlignment, NSTouchBarItemIdentifierTextList, NSTouchBarItemIdentifierFlexibleSpace ];
+}
+
+static NSArray<NSString *> *plainTextTouchBarCustomizationDefaultItemIdentifiers()
+{
+    return @[ NSTouchBarItemIdentifierCharacterPicker, NSTouchBarItemIdentifierCandidateList ];
+}
+
+static NSArray<NSString *> *richTextTouchBarCustomizationDefaultItemIdentifiers()
+{
+    return @[ NSTouchBarItemIdentifierCharacterPicker, NSTouchBarItemIdentifierTextFormat, NSTouchBarItemIdentifierCandidateList ];
+}
+
+void WebViewImpl::updateTouchBarAndRefreshTextBarIdentifiers()
+{
+    if (m_richTextTouchBar)
+        setUpTextTouchBar(m_richTextTouchBar.get());
+
+    if (m_plainTextTouchBar)
+        setUpTextTouchBar(m_plainTextTouchBar.get());
+
+    updateTouchBar();
+}
+
+void WebViewImpl::setUpTextTouchBar(NSTouchBar *touchBar)
+{
+    bool isRichTextTouchBar = touchBar == m_richTextTouchBar.get();
+    [touchBar setDelegate:m_textTouchBarItemController.get()];
+    [touchBar setDefaultItems:[NSMutableSet setWithObject:isRichTextTouchBar ? m_richTextCandidateListTouchBarItem.get() : m_plainTextCandidateListTouchBarItem.get()]];
+    [touchBar setCustomizationAllowedItemIdentifiers:textTouchBarCustomizationAllowedIdentifiers()];
+    [touchBar setCustomizationDefaultItemIdentifiers:isRichTextTouchBar ? richTextTouchBarCustomizationDefaultItemIdentifiers() : plainTextTouchBarCustomizationDefaultItemIdentifiers()];
+
+    if (NSGroupTouchBarItem *textFormatItem = (NSGroupTouchBarItem *)[touchBar itemForIdentifier:NSTouchBarItemIdentifierTextFormat])
+        textFormatItem.groupTouchBar.customizationIdentifier = @"WKTextFormatTouchBar";
+}
+
+bool WebViewImpl::isRichlyEditable() const
+{
+    return m_page->editorState().isContentRichlyEditable && !m_page->needsPlainTextQuirk();
+}
+
+NSTouchBar *WebViewImpl::textTouchBar() const
+{
+    return isRichlyEditable() ? m_richTextTouchBar.get() : m_plainTextTouchBar.get();
+}
+
+static NSTextAlignment nsTextAlignmentFromTextAlignment(TextAlignment textAlignment)
+{
+    NSTextAlignment nsTextAlignment;
+    switch (textAlignment) {
+    case NoAlignment:
+        nsTextAlignment = NSTextAlignmentNatural;
+        break;
+    case LeftAlignment:
+        nsTextAlignment = NSTextAlignmentLeft;
+        break;
+    case RightAlignment:
+        nsTextAlignment = NSTextAlignmentRight;
+        break;
+    case CenterAlignment:
+        nsTextAlignment = NSTextAlignmentCenter;
+        break;
+    case JustifiedAlignment:
+        nsTextAlignment = NSTextAlignmentJustified;
+        break;
+    default:
+        ASSERT_NOT_REACHED();
+    }
+    
+    return nsTextAlignment;
+}
+
+void WebViewImpl::updateTextTouchBar()
+{
+    if (!m_page->editorState().isContentEditable)
+        return;
+
+    if (m_isUpdatingTextTouchBar)
+        return;
+
+    TemporaryChange<bool> isUpdatingTextFunctionBar(m_isUpdatingTextTouchBar, true);
+
+    if (!m_textTouchBarItemController)
+        m_textTouchBarItemController = adoptNS([[WKTextTouchBarItemController alloc] initWithWebViewImpl:this]);
+
+    if (!m_startedListeningToCustomizationEvents) {
+        [[NSNotificationCenter defaultCenter] addObserver:m_textTouchBarItemController.get() selector:@selector(touchBarDidExitCustomization:) name:NSTouchBarDidExitCustomization object:nil];
+        [[NSNotificationCenter defaultCenter] addObserver:m_textTouchBarItemController.get() selector:@selector(touchBarWillEnterCustomization:) name:NSTouchBarWillEnterCustomization object:nil];
+        [[NSNotificationCenter defaultCenter] addObserver:m_textTouchBarItemController.get() selector:@selector(didChangeAutomaticTextCompletion:) name:NSSpellCheckerDidChangeAutomaticTextCompletionNotification object:nil];
+
+        m_startedListeningToCustomizationEvents = true;
+    }
+
+    if (!m_richTextCandidateListTouchBarItem || !m_plainTextCandidateListTouchBarItem) {
+        m_richTextCandidateListTouchBarItem = adoptNS([[NSCandidateListTouchBarItem alloc] initWithIdentifier:NSTouchBarItemIdentifierCandidateList]);
+        [m_richTextCandidateListTouchBarItem setDelegate:m_textTouchBarItemController.get()];
+        m_plainTextCandidateListTouchBarItem = adoptNS([[NSCandidateListTouchBarItem alloc] initWithIdentifier:NSTouchBarItemIdentifierCandidateList]);
+        [m_plainTextCandidateListTouchBarItem setDelegate:m_textTouchBarItemController.get()];
+        requestCandidatesForSelectionIfNeeded();
+    }
+
+    if (!m_richTextTouchBar) {
+        m_richTextTouchBar = adoptNS([[NSTouchBar alloc] init]);
+        setUpTextTouchBar(m_richTextTouchBar.get());
+        [m_richTextTouchBar setCustomizationIdentifier:@"WKRichTextTouchBar"];
+    }
+
+    if (!m_plainTextTouchBar) {
+        m_plainTextTouchBar = adoptNS([[NSTouchBar alloc] init]);
+        setUpTextTouchBar(m_plainTextTouchBar.get());
+        [m_plainTextTouchBar setCustomizationIdentifier:@"WKPlainTextTouchBar"];
+    }
+
+    if ([NSSpellChecker isAutomaticTextCompletionEnabled] && !m_isCustomizingTouchBar) {
+        BOOL showCandidatesList = !m_page->editorState().selectionIsRange || m_isHandlingAcceptedCandidate;
+        [candidateListTouchBarItem() updateWithInsertionPointVisibility:showCandidatesList];
+        [m_view _didUpdateCandidateListVisibility:showCandidatesList];
+    }
+
+    if (m_page->editorState().isInPasswordField) {
+        // We don't request candidates for password fields. If the user was previously in a non-password field, then the
+        // old candidates will still show by default, so we clear them here by setting an empty array of candidates.
+        if (!m_emptyCandidatesArray)
+            m_emptyCandidatesArray = adoptNS([[NSArray alloc] init]);
+        [candidateListTouchBarItem() setCandidates:m_emptyCandidatesArray.get() forSelectedRange:NSMakeRange(0, 0) inString:nil];
+    }
+
+    NSTouchBar *textTouchBar = this->textTouchBar();
+    BOOL isShowingCombinedTextFormatItem = [textTouchBar.itemIdentifiers containsObject:NSTouchBarItemIdentifierTextFormat];
+    [textTouchBar setPrincipalItemIdentifier:isShowingCombinedTextFormatItem ? NSTouchBarItemIdentifierTextFormat : nil];
+
+    // Set current typing attributes for rich text. This will ensure that the buttons reflect the state of
+    // the text when changing selection throughout the document.
+    if (isRichlyEditable()) {
+        const EditorState& editorState = m_page->editorState();
+        if (!editorState.isMissingPostLayoutData) {
+            [m_textTouchBarItemController setTextIsBold:(bool)(m_page->editorState().postLayoutData().typingAttributes & AttributeBold)];
+            [m_textTouchBarItemController setTextIsItalic:(bool)(m_page->editorState().postLayoutData().typingAttributes & AttributeItalics)];
+            [m_textTouchBarItemController setTextIsUnderlined:(bool)(m_page->editorState().postLayoutData().typingAttributes & AttributeUnderline)];
+            [m_textTouchBarItemController setTextColor:nsColor(editorState.postLayoutData().textColor)];
+            [[m_textTouchBarItemController textListTouchBarViewController] setCurrentListType:(ListType)m_page->editorState().postLayoutData().enclosingListType];
+            [m_textTouchBarItemController setCurrentTextAlignment:nsTextAlignmentFromTextAlignment((TextAlignment)editorState.postLayoutData().textAlignment)];
+        }
+        BOOL isShowingCandidateListItem = [textTouchBar.itemIdentifiers containsObject:NSTouchBarItemIdentifierCandidateList] && [NSSpellChecker isAutomaticTextReplacementEnabled];
+        [m_textTouchBarItemController setUsesNarrowTextStyleItem:isShowingCombinedTextFormatItem && isShowingCandidateListItem];
+    }
+}
+
+void WebViewImpl::updateMediaTouchBar()
+{
+#if ENABLE(WEB_PLAYBACK_CONTROLS_MANAGER)
+    if (!m_mediaTouchBarProvider)
+        m_mediaTouchBarProvider = adoptNS([allocAVFunctionBarPlaybackControlsProviderInstance() init]);
+
+    if (!m_mediaPlaybackControlsView)
+        m_mediaPlaybackControlsView = adoptNS([allocAVFunctionBarScrubberInstance() init]);
+
+    if (!m_playbackControlsManager)
+        m_playbackControlsManager = adoptNS([[WebPlaybackControlsManager alloc] init]);
+
+    if (PlatformWebPlaybackSessionInterface* interface = m_page->playbackSessionManager()->controlsManagerInterface())
+        [m_playbackControlsManager setWebPlaybackSessionInterfaceMac:interface];
+
+    [m_mediaTouchBarProvider setPlaybackControlsController:m_playbackControlsManager.get()];
+    [m_mediaPlaybackControlsView setPlaybackControlsController:m_playbackControlsManager.get()];
+
+    if (!useMediaPlaybackControlsView()) {
+#if ENABLE(FULLSCREEN_API)
+        // If we can't have a media popover function bar item, it might be because we are in full screen.
+        // If so, customize the escape key.
+        NSTouchBar *touchBar = [m_mediaTouchBarProvider respondsToSelector:@selector(touchBar)] ? [(id)m_mediaTouchBarProvider.get() touchBar] : [(id)m_mediaTouchBarProvider.get() touchBar];
+        if (hasFullScreenWindowController() && [m_fullScreenWindowController isFullScreen]) {
+            if (!m_exitFullScreenButton) {
+                m_exitFullScreenButton = adoptNS([[NSCustomTouchBarItem alloc] initWithIdentifier:WKMediaExitFullScreenItem]);
+
+                NSImage *image = [NSImage imageNamed:NSImageNameTouchBarExitFullScreenTemplate];
+                [image setTemplate:YES];
+
+                NSButton *exitFullScreenButton = [NSButton buttonWithTitle:image ? @"" : @"Exit" image:image target:m_fullScreenWindowController.get() action:@selector(requestExitFullScreen)];
+                [exitFullScreenButton setAccessibilityTitle:WebCore::exitFullScreenButtonAccessibilityTitle()];
+
+                [[exitFullScreenButton.widthAnchor constraintLessThanOrEqualToConstant:exitFullScreenButtonWidth] setActive:YES];
+                [m_exitFullScreenButton setView:exitFullScreenButton];
+            }
+            touchBar.escapeKeyReplacementItem = m_exitFullScreenButton.get();
+        } else
+            touchBar.escapeKeyReplacementItem = nil;
+#endif
+        // The rest of the work to update the media function bar only applies to the popover version, so return early.
+        return;
+    }
+
+    if (m_playbackControlsManager && m_view == m_view.window.firstResponder && [m_view respondsToSelector:@selector(_web_didAddMediaControlsManager:)])
+        [m_view _web_didAddMediaControlsManager:m_mediaPlaybackControlsView.get()];
+#endif
 }
 
 void WebViewImpl::forceRequestCandidatesForTesting()
 {
+    m_canCreateTouchBars = true;
+#if HAVE(TOUCH_BAR)
+    updateTouchBar();
+#endif
 }
 
 bool WebViewImpl::shouldRequestCandidates() const
 {
-    return false;
+    return !m_page->editorState().isInPasswordField && candidateListTouchBarItem().candidateListVisible;
 }
 
 void WebViewImpl::showCandidates(NSArray *candidates, NSString *string, NSRect rectOfTypedString, NSRange selectedRange, NSView *view, void (^completionHandler)(NSTextCheckingResult *acceptedCandidate))
 {
+    [candidateListTouchBarItem() setCandidates:candidates forSelectedRange:selectedRange inString:string];
+}
+
+void WebViewImpl::setEditableElementIsFocused(bool editableElementIsFocused)
+{
+    m_editableElementIsFocused = editableElementIsFocused;
+
+#if HAVE(TOUCH_BAR)
+    // If the editable elements have blurred, then we might need to get rid of the editing function bar.
+    if (!m_editableElementIsFocused)
+        updateTouchBar();
+#endif
+}
+
+} // namespace WebKit
+#else
+namespace WebKit {
+
+void WebViewImpl::forceRequestCandidatesForTesting()
+{
 }
 
-void WebViewImpl::webViewImplAdditionsWillDestroyView()
+bool WebViewImpl::shouldRequestCandidates() const
+{
+    return false;
+}
+
+void WebViewImpl::showCandidates(NSArray *candidates, NSString *string, NSRect rectOfTypedString, NSRange selectedRange, NSView *view, void (^completionHandler)(NSTextCheckingResult *acceptedCandidate))
 {
 }
 
@@ -465,7 +1152,7 @@ void WebViewImpl::setEditableElementIsFocused(bool editableElementIsFocused)
 }
 
 } // namespace WebKit
-#endif // __MAC_OS_X_VERSION_MIN_REQUIRED >= 101200 && USE(APPLE_INTERNAL_SDK)
+#endif // HAVE(TOUCH_BAR)
 
 namespace WebKit {
 
@@ -540,7 +1227,14 @@ WebViewImpl::~WebViewImpl()
     [m_layoutStrategy invalidate];
 
     [m_immediateActionController willDestroyView:m_view];
-    webViewImplAdditionsWillDestroyView();
+
+#if HAVE(DFR)
+    [m_textTouchBarItemController didDestroyView];
+#if ENABLE(WEB_PLAYBACK_CONTROLS_MANAGER)
+    [m_mediaTouchBarProvider setPlaybackControlsController:nil];
+    [m_mediaPlaybackControlsView setPlaybackControlsController:nil];
+#endif
+#endif
 
     m_page->close();
 
@@ -615,7 +1309,9 @@ bool WebViewImpl::becomeFirstResponder()
 
     m_inBecomeFirstResponder = false;
 
-    updateWebViewImplAdditions();
+#if HAVE(TOUCH_BAR)
+    updateTouchBar();
+#endif
 
     if (direction != NSDirectSelection) {
         NSEvent *event = [NSApp currentEvent];
@@ -1807,8 +2503,8 @@ void WebViewImpl::selectionDidChange()
     updateFontPanelIfNeeded();
     if (!m_isHandlingAcceptedCandidate)
         m_softSpaceRange = NSMakeRange(NSNotFound, 0);
-#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101200
-    updateWebViewImplAdditions();
+#if HAVE(TOUCH_BAR)
+    updateTouchBar();
     if (!m_page->editorState().isMissingPostLayoutData)
         requestCandidatesForSelectionIfNeeded();
 #endif
@@ -2447,8 +3143,8 @@ void WebViewImpl::didHandleAcceptedCandidate()
 
 void WebViewImpl::videoControlsManagerDidChange()
 {
-#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101200
-    updateWebViewImplAdditions();
+#if HAVE(TOUCH_BAR)
+    updateTouchBar();
 #endif
 }
 
index ed740ce..354272a 100644 (file)
@@ -1,3 +1,17 @@
+2016-11-09  Beth Dakin  <bdakin@apple.com>
+
+        Support TouchBar in WebKit
+        https://bugs.webkit.org/show_bug.cgi?id=164437
+        -and corresponding-
+        rdar://problem/28876524
+
+        Reviewed by Darin Adler.
+
+        This makes MiniBrowser support TouchBar customization. 
+
+        * MiniBrowser/mac/AppDelegate.m:
+        (-[BrowserAppDelegate awakeFromNib]):
+
 2016-11-09  Gyuyoung Kim  <gyuyoung.kim@webkit.org>
 
         [EFL] Use libgcrypt instead of GnuTLS for CryptoDigest
index c4fb8fa..7081df5 100644 (file)
@@ -47,6 +47,10 @@ enum {
     WebKit2NewWindowTag = 2
 };
 
+@interface NSApplication (TouchBar)
+@property (getter=isAutomaticCustomizeTouchBarMenuItemEnabled) BOOL automaticCustomizeTouchBarMenuItemEnabled;
+@end
+
 @implementation BrowserAppDelegate
 
 - (id)init
@@ -73,6 +77,9 @@ enum {
 #endif
 
     [[NSApp mainMenu] insertItem:[item autorelease] atIndex:[[NSApp mainMenu] indexOfItemWithTitle:@"Debug"]];
+
+    if ([NSApp respondsToSelector:@selector(setAutomaticCustomizeTouchBarMenuItemEnabled:)])
+        [NSApp setAutomaticCustomizeTouchBarMenuItemEnabled:YES];
 }
 
 #if WK_API_ENABLED