Title: [191757] trunk/Source/WebKit2
Revision
191757
Author
[email protected]
Date
2015-10-29 15:07:42 -0700 (Thu, 29 Oct 2015)

Log Message

WKView being inside WKWebView leads to weird API issues
https://bugs.webkit.org/show_bug.cgi?id=150174

Reviewed by Darin Adler.

* UIProcess/API/mac/WKView.mm:
(-[WKView browsingContextController]):
(-[WKView validateUserInterfaceItem:]):
(-[WKView saveBackForwardSnapshotForCurrentItem]):
(-[WKView saveBackForwardSnapshotForItem:]):
(-[WKView updateLayer]):
(-[WKView minimumSizeForAutoLayout]):
(-[WKView setMinimumSizeForAutoLayout:]):
(-[WKView shouldExpandToViewHeightForAutoLayout]):
(-[WKView setShouldExpandToViewHeightForAutoLayout:]):
(-[WKView underlayColor]):
(-[WKView setUnderlayColor:]):
(-[WKView _setOverlayScrollbarStyle:]):
(-[WKView _overlayScrollbarStyle]):
(-[WKView _pageExtendedBackgroundColor]):
(-[WKView forceAsyncDrawingAreaSizeUpdate:]):
(-[WKView waitForAsyncDrawingAreaSizeUpdate]):
(-[WKView isUsingUISideCompositing]):
(createSelectorExceptionMap): Deleted.
(commandNameForSelector): Deleted.
(menuItem): Deleted.
(toolbarItem): Deleted.
(-[WKView _setUserInterfaceItemState:enabled:state:]): Deleted.
* UIProcess/Cocoa/WebViewImpl.h:
* UIProcess/Cocoa/WebViewImpl.mm:
(WebKit::WebViewImpl::createDrawingAreaProxy):
(WebKit::WebViewImpl::isUsingUISideCompositing):
(WebKit::WebViewImpl::forceAsyncDrawingAreaSizeUpdate):
(WebKit::WebViewImpl::waitForAsyncDrawingAreaSizeUpdate):
(WebKit::WebViewImpl::updateLayer):
(WebKit::WebViewImpl::setMinimumSizeForAutoLayout):
(WebKit::WebViewImpl::minimumSizeForAutoLayout):
(WebKit::WebViewImpl::setShouldExpandToViewHeightForAutoLayout):
(WebKit::WebViewImpl::shouldExpandToViewHeightForAutoLayout):
(WebKit::WebViewImpl::setUnderlayColor):
(WebKit::WebViewImpl::underlayColor):
(WebKit::WebViewImpl::pageExtendedBackgroundColor):
(WebKit::WebViewImpl::setOverlayScrollbarStyle):
(WebKit::WebViewImpl::overlayScrollbarStyle):
(WebKit::createSelectorExceptionMap):
(WebKit::commandNameForSelector):
(WebKit::WebViewImpl::executeSavedCommandBySelector):
(WebKit::WebViewImpl::executeEditCommandForSelector):
(WebKit::menuItem):
(WebKit::toolbarItem):
(WebKit::WebViewImpl::validateUserInterfaceItem):
(WebKit::WebViewImpl::setUserInterfaceItemState):
(WebKit::WebViewImpl::browsingContextController):
(WebKit::WebViewImpl::saveBackForwardSnapshotForCurrentItem):
(WebKit::WebViewImpl::saveBackForwardSnapshotForItem):
(WebKit::WebViewImpl::executeEditCommand): Deleted.
Move UI validation and a grab-bag of other things.

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (191756 => 191757)


--- trunk/Source/WebKit2/ChangeLog	2015-10-29 21:54:24 UTC (rev 191756)
+++ trunk/Source/WebKit2/ChangeLog	2015-10-29 22:07:42 UTC (rev 191757)
@@ -1,3 +1,63 @@
+2015-10-29  Tim Horton  <[email protected]>
+
+        WKView being inside WKWebView leads to weird API issues
+        https://bugs.webkit.org/show_bug.cgi?id=150174
+
+        Reviewed by Darin Adler.
+
+        * UIProcess/API/mac/WKView.mm:
+        (-[WKView browsingContextController]):
+        (-[WKView validateUserInterfaceItem:]):
+        (-[WKView saveBackForwardSnapshotForCurrentItem]):
+        (-[WKView saveBackForwardSnapshotForItem:]):
+        (-[WKView updateLayer]):
+        (-[WKView minimumSizeForAutoLayout]):
+        (-[WKView setMinimumSizeForAutoLayout:]):
+        (-[WKView shouldExpandToViewHeightForAutoLayout]):
+        (-[WKView setShouldExpandToViewHeightForAutoLayout:]):
+        (-[WKView underlayColor]):
+        (-[WKView setUnderlayColor:]):
+        (-[WKView _setOverlayScrollbarStyle:]):
+        (-[WKView _overlayScrollbarStyle]):
+        (-[WKView _pageExtendedBackgroundColor]):
+        (-[WKView forceAsyncDrawingAreaSizeUpdate:]):
+        (-[WKView waitForAsyncDrawingAreaSizeUpdate]):
+        (-[WKView isUsingUISideCompositing]):
+        (createSelectorExceptionMap): Deleted.
+        (commandNameForSelector): Deleted.
+        (menuItem): Deleted.
+        (toolbarItem): Deleted.
+        (-[WKView _setUserInterfaceItemState:enabled:state:]): Deleted.
+        * UIProcess/Cocoa/WebViewImpl.h:
+        * UIProcess/Cocoa/WebViewImpl.mm:
+        (WebKit::WebViewImpl::createDrawingAreaProxy):
+        (WebKit::WebViewImpl::isUsingUISideCompositing):
+        (WebKit::WebViewImpl::forceAsyncDrawingAreaSizeUpdate):
+        (WebKit::WebViewImpl::waitForAsyncDrawingAreaSizeUpdate):
+        (WebKit::WebViewImpl::updateLayer):
+        (WebKit::WebViewImpl::setMinimumSizeForAutoLayout):
+        (WebKit::WebViewImpl::minimumSizeForAutoLayout):
+        (WebKit::WebViewImpl::setShouldExpandToViewHeightForAutoLayout):
+        (WebKit::WebViewImpl::shouldExpandToViewHeightForAutoLayout):
+        (WebKit::WebViewImpl::setUnderlayColor):
+        (WebKit::WebViewImpl::underlayColor):
+        (WebKit::WebViewImpl::pageExtendedBackgroundColor):
+        (WebKit::WebViewImpl::setOverlayScrollbarStyle):
+        (WebKit::WebViewImpl::overlayScrollbarStyle):
+        (WebKit::createSelectorExceptionMap):
+        (WebKit::commandNameForSelector):
+        (WebKit::WebViewImpl::executeSavedCommandBySelector):
+        (WebKit::WebViewImpl::executeEditCommandForSelector):
+        (WebKit::menuItem):
+        (WebKit::toolbarItem):
+        (WebKit::WebViewImpl::validateUserInterfaceItem):
+        (WebKit::WebViewImpl::setUserInterfaceItemState):
+        (WebKit::WebViewImpl::browsingContextController):
+        (WebKit::WebViewImpl::saveBackForwardSnapshotForCurrentItem):
+        (WebKit::WebViewImpl::saveBackForwardSnapshotForItem):
+        (WebKit::WebViewImpl::executeEditCommand): Deleted.
+        Move UI validation and a grab-bag of other things.
+
 2015-10-29  Alex Christensen  <[email protected]>
 
         Fix Mac CMake build

Modified: trunk/Source/WebKit2/UIProcess/API/mac/WKView.mm (191756 => 191757)


--- trunk/Source/WebKit2/UIProcess/API/mac/WKView.mm	2015-10-29 21:54:24 UTC (rev 191756)
+++ trunk/Source/WebKit2/UIProcess/API/mac/WKView.mm	2015-10-29 22:07:42 UTC (rev 191757)
@@ -106,7 +106,6 @@
 #import <wtf/RunLoop.h>
 
 /* API internals. */
-#import "WKBrowsingContextControllerInternal.h"
 #import "WKBrowsingContextGroupPrivate.h"
 #import "WKProcessGroupPrivate.h"
 
@@ -126,14 +125,6 @@
 using namespace WebKit;
 using namespace WebCore;
 
-namespace WebKit {
-
-typedef id <NSValidatedUserInterfaceItem> ValidationItem;
-typedef Vector<RetainPtr<ValidationItem>> ValidationVector;
-typedef HashMap<String, ValidationVector> ValidationMap;
-
-}
-
 #if !USE(ASYNC_NSTEXTINPUTCLIENT)
 struct WKViewInterpretKeyEventsParameters {
     bool eventInterpretationHadSideEffects;
@@ -149,13 +140,6 @@
     RefPtr<WebPageProxy> _page;
     std::unique_ptr<WebViewImpl> _impl;
 
-#if WK_API_ENABLED
-    RetainPtr<WKBrowsingContextController> _browsingContextController;
-#endif
-
-    // For asynchronous validation.
-    ValidationMap _validationMap;
-
     // We keep here the event when resending it to
     // the application to distinguish the case of a new event from one 
     // that has been already sent to WebCore.
@@ -213,15 +197,10 @@
 }
 
 #if WK_API_ENABLED
-
 - (WKBrowsingContextController *)browsingContextController
 {
-    if (!_data->_browsingContextController)
-        _data->_browsingContextController = adoptNS([[WKBrowsingContextController alloc] _initWithPageRef:toAPI(_data->_page.get())]);
-
-    return _data->_browsingContextController.get();
+    return _data->_impl->browsingContextController();
 }
-
 #endif // WK_API_ENABLED
 
 - (void)setDrawsBackground:(BOOL)drawsBackground
@@ -297,49 +276,8 @@
     [super renewGState];
 }
 
-typedef HashMap<SEL, String> SelectorNameMap;
+#define WEBCORE_COMMAND(command) - (void)command:(id)sender { _data->_impl->executeEditCommandForSelector(_cmd); }
 
-// Map selectors into Editor command names.
-// This is not needed for any selectors that have the same name as the Editor command.
-static const SelectorNameMap* createSelectorExceptionMap()
-{
-    SelectorNameMap* map = new HashMap<SEL, String>;
-    
-    map->add(@selector(insertNewlineIgnoringFieldEditor:), "InsertNewline");
-    map->add(@selector(insertParagraphSeparator:), "InsertNewline");
-    map->add(@selector(insertTabIgnoringFieldEditor:), "InsertTab");
-    map->add(@selector(pageDown:), "MovePageDown");
-    map->add(@selector(pageDownAndModifySelection:), "MovePageDownAndModifySelection");
-    map->add(@selector(pageUp:), "MovePageUp");
-    map->add(@selector(pageUpAndModifySelection:), "MovePageUpAndModifySelection");
-    map->add(@selector(scrollPageDown:), "ScrollPageForward");
-    map->add(@selector(scrollPageUp:), "ScrollPageBackward");
-    
-    return map;
-}
-
-static String commandNameForSelector(SEL selector)
-{
-    // Check the exception map first.
-    static const SelectorNameMap* exceptionMap = createSelectorExceptionMap();
-    SelectorNameMap::const_iterator it = exceptionMap->find(selector);
-    if (it != exceptionMap->end())
-        return it->value;
-    
-    // Remove the trailing colon.
-    // No need to capitalize the command name since Editor command names are
-    // not case sensitive.
-    const char* selectorName = sel_getName(selector);
-    size_t selectorNameLength = strlen(selectorName);
-    if (selectorNameLength < 2 || selectorName[selectorNameLength - 1] != ':')
-        return String();
-    return String(selectorName, selectorNameLength - 1);
-}
-
-// Editing commands
-
-#define WEBCORE_COMMAND(command) - (void)command:(id)sender { _data->_impl->executeEditCommand(commandNameForSelector(_cmd)); }
-
 WEBCORE_COMMAND(alignCenter)
 WEBCORE_COMMAND(alignJustified)
 WEBCORE_COMMAND(alignLeft)
@@ -530,126 +468,9 @@
 
 */
 
-// Menu items validation
-
-static NSMenuItem *menuItem(id <NSValidatedUserInterfaceItem> item)
-{
-    if (![(NSObject *)item isKindOfClass:[NSMenuItem class]])
-        return nil;
-    return (NSMenuItem *)item;
-}
-
-static NSToolbarItem *toolbarItem(id <NSValidatedUserInterfaceItem> item)
-{
-    if (![(NSObject *)item isKindOfClass:[NSToolbarItem class]])
-        return nil;
-    return (NSToolbarItem *)item;
-}
-
 - (BOOL)validateUserInterfaceItem:(id <NSValidatedUserInterfaceItem>)item
 {
-    SEL action = "" action];
-
-    if (action == @selector(showGuessPanel:)) {
-        if (NSMenuItem *menuItem = ::menuItem(item))
-            [menuItem setTitle:contextMenuItemTagShowSpellingPanel(![[[NSSpellChecker sharedSpellChecker] spellingPanel] isVisible])];
-        return _data->_page->editorState().isContentEditable;
-    }
-
-    if (action == @selector(checkSpelling:) || action == @selector(changeSpelling:))
-        return _data->_page->editorState().isContentEditable;
-
-    if (action == @selector(toggleContinuousSpellChecking:)) {
-        bool enabled = TextChecker::isContinuousSpellCheckingAllowed();
-        bool checked = enabled && TextChecker::state().isContinuousSpellCheckingEnabled;
-        [menuItem(item) setState:checked ? NSOnState : NSOffState];
-        return enabled;
-    }
-
-    if (action == @selector(toggleGrammarChecking:)) {
-        bool checked = TextChecker::state().isGrammarCheckingEnabled;
-        [menuItem(item) setState:checked ? NSOnState : NSOffState];
-        return YES;
-    }
-
-    if (action == @selector(toggleAutomaticSpellingCorrection:)) {
-        bool checked = TextChecker::state().isAutomaticSpellingCorrectionEnabled;
-        [menuItem(item) setState:checked ? NSOnState : NSOffState];
-        return _data->_page->editorState().isContentEditable;
-    }
-
-    if (action == @selector(orderFrontSubstitutionsPanel:)) {
-        if (NSMenuItem *menuItem = ::menuItem(item))
-            [menuItem setTitle:contextMenuItemTagShowSubstitutions(![[[NSSpellChecker sharedSpellChecker] substitutionsPanel] isVisible])];
-        return _data->_page->editorState().isContentEditable;
-    }
-
-    if (action == @selector(toggleSmartInsertDelete:)) {
-        bool checked = _data->_page->isSmartInsertDeleteEnabled();
-        [menuItem(item) setState:checked ? NSOnState : NSOffState];
-        return _data->_page->editorState().isContentEditable;
-    }
-
-    if (action == @selector(toggleAutomaticQuoteSubstitution:)) {
-        bool checked = TextChecker::state().isAutomaticQuoteSubstitutionEnabled;
-        [menuItem(item) setState:checked ? NSOnState : NSOffState];
-        return _data->_page->editorState().isContentEditable;
-    }
-
-    if (action == @selector(toggleAutomaticDashSubstitution:)) {
-        bool checked = TextChecker::state().isAutomaticDashSubstitutionEnabled;
-        [menuItem(item) setState:checked ? NSOnState : NSOffState];
-        return _data->_page->editorState().isContentEditable;
-    }
-
-    if (action == @selector(toggleAutomaticLinkDetection:)) {
-        bool checked = TextChecker::state().isAutomaticLinkDetectionEnabled;
-        [menuItem(item) setState:checked ? NSOnState : NSOffState];
-        return _data->_page->editorState().isContentEditable;
-    }
-
-    if (action == @selector(toggleAutomaticTextReplacement:)) {
-        bool checked = TextChecker::state().isAutomaticTextReplacementEnabled;
-        [menuItem(item) setState:checked ? NSOnState : NSOffState];
-        return _data->_page->editorState().isContentEditable;
-    }
-
-    if (action == @selector(uppercaseWord:) || action == @selector(lowercaseWord:) || action == @selector(capitalizeWord:))
-        return _data->_page->editorState().selectionIsRange && _data->_page->editorState().isContentEditable;
-    
-    if (action == @selector(stopSpeaking:))
-        return [NSApp isSpeaking];
-    
-    // The centerSelectionInVisibleArea: selector is enabled if there's a selection range or if there's an insertion point in an editable area.
-    if (action == @selector(centerSelectionInVisibleArea:))
-        return _data->_page->editorState().selectionIsRange || (_data->_page->editorState().isContentEditable && !_data->_page->editorState().selectionIsNone);
-
-    // Next, handle editor commands. Start by returning YES for anything that is not an editor command.
-    // Returning YES is the default thing to do in an AppKit validate method for any selector that is not recognized.
-    String commandName = commandNameForSelector([item action]);
-    if (!Editor::commandIsSupportedFromMenuOrKeyBinding(commandName))
-        return YES;
-
-    // Add this item to the vector of items for a given command that are awaiting validation.
-    ValidationMap::AddResult addResult = _data->_validationMap.add(commandName, ValidationVector());
-    addResult.iterator->value.append(item);
-    if (addResult.isNewEntry) {
-        // If we are not already awaiting validation for this command, start the asynchronous validation process.
-        // FIXME: Theoretically, there is a race here; when we get the answer it might be old, from a previous time
-        // we asked for the same command; there is no guarantee the answer is still valid.
-        _data->_page->validateCommand(commandName, [self](const String& commandName, bool isEnabled, int32_t state, WebKit::CallbackBase::Error error) {
-            // If the process exits before the command can be validated, we'll be called back with an error.
-            if (error != WebKit::CallbackBase::Error::None)
-                return;
-            
-            [self _setUserInterfaceItemState:commandName enabled:isEnabled state:state];
-        });
-    }
-
-    // Treat as enabled until we get the result back from the web process and _setUserInterfaceItemState is called.
-    // FIXME <rdar://problem/8803459>: This means disabled items will flash enabled at first for a moment.
-    // But returning NO here would be worse; that would make keyboard commands such as command-C fail.
-    return YES;
+    return _data->_impl->validateUserInterfaceItem(item);
 }
 
 - (IBAction)startSpeaking:(id)sender
@@ -2171,19 +1992,6 @@
     _data->_impl->quickLookWithEvent(event);
 }
 
-- (void)_setUserInterfaceItemState:(NSString *)commandName enabled:(BOOL)isEnabled state:(int)newState
-{
-    ValidationVector items = _data->_validationMap.take(commandName);
-    size_t size = items.size();
-    for (size_t i = 0; i < size; ++i) {
-        ValidationItem item = items[i].get();
-        [menuItem(item) setState:newState];
-        [menuItem(item) setEnabled:isEnabled];
-        [toolbarItem(item) setEnabled:isEnabled];
-        // FIXME <rdar://problem/8803392>: If the item is neither a menu nor toolbar item, it will be left enabled.
-    }
-}
-
 - (void)_doneWithKeyEvent:(NSEvent *)event eventWasHandled:(BOOL)eventWasHandled
 {
     if ([event type] != NSKeyDown)
@@ -2325,12 +2133,12 @@
 
 - (void)saveBackForwardSnapshotForCurrentItem
 {
-    _data->_page->recordNavigationSnapshot();
+    _data->_impl->saveBackForwardSnapshotForCurrentItem();
 }
 
 - (void)saveBackForwardSnapshotForItem:(WKBackForwardListItemRef)item
 {
-    _data->_page->recordNavigationSnapshot(*toImpl(item));
+    _data->_impl->saveBackForwardSnapshotForItem(*toImpl(item));
 }
 
 - (id)initWithFrame:(NSRect)frame contextRef:(WKContextRef)contextRef pageGroupRef:(WKPageGroupRef)pageGroupRef
@@ -2363,19 +2171,7 @@
 
 - (void)updateLayer
 {
-    if ([self drawsBackground] && ![self drawsTransparentBackground])
-        self.layer.backgroundColor = CGColorGetConstantColor(kCGColorWhite);
-    else
-        self.layer.backgroundColor = CGColorGetConstantColor(kCGColorClear);
-
-    // If asynchronous geometry updates have been sent by forceAsyncDrawingAreaSizeUpdate,
-    // then subsequent calls to setFrameSize should not result in us waiting for the did
-    // udpate response if setFrameSize is called.
-    if ([self frameSizeUpdatesDisabled])
-        return;
-
-    if (DrawingAreaProxy* drawingArea = _data->_page->drawingArea())
-        drawingArea->waitForPossibleGeometryUpdate();
+    _data->_impl->updateLayer();
 }
 
 - (WKPageRef)pageRef
@@ -2431,27 +2227,22 @@
 
 - (NSSize)minimumSizeForAutoLayout
 {
-    return _data->_page->minimumLayoutSize();
+    return NSSizeFromCGSize(_data->_impl->minimumSizeForAutoLayout());
 }
 
 - (void)setMinimumSizeForAutoLayout:(NSSize)minimumSizeForAutoLayout
 {
-    BOOL expandsToFit = minimumSizeForAutoLayout.width > 0;
-
-    _data->_page->setMinimumLayoutSize(IntSize(minimumSizeForAutoLayout.width, minimumSizeForAutoLayout.height));
-    _data->_page->setMainFrameIsScrollable(!expandsToFit);
-
-    [self setShouldClipToVisibleRect:expandsToFit];
+    _data->_impl->setMinimumSizeForAutoLayout(NSSizeToCGSize(minimumSizeForAutoLayout));
 }
 
 - (BOOL)shouldExpandToViewHeightForAutoLayout
 {
-    return _data->_page->autoSizingShouldExpandToViewHeight();
+    return _data->_impl->shouldExpandToViewHeightForAutoLayout();
 }
 
 - (void)setShouldExpandToViewHeightForAutoLayout:(BOOL)shouldExpand
 {
-    return _data->_page->setAutoSizingShouldExpandToViewHeight(shouldExpand);
+    return _data->_impl->setShouldExpandToViewHeightForAutoLayout(shouldExpand);
 }
 
 - (BOOL)shouldClipToVisibleRect
@@ -2466,16 +2257,12 @@
 
 - (NSColor *)underlayColor
 {
-    Color webColor = _data->_page->underlayColor();
-    if (!webColor.isValid())
-        return nil;
-
-    return nsColor(webColor);
+    return _data->_impl->underlayColor();
 }
 
 - (void)setUnderlayColor:(NSColor *)underlayColor
 {
-    _data->_page->setUnderlayColor(colorFromNSColor(underlayColor));
+    _data->_impl->setUnderlayColor(underlayColor);
 }
 
 #if WK_API_ENABLED
@@ -2642,103 +2429,68 @@
     return _data->_impl->totalHeightOfBanners();
 }
 
-- (void)_setOverlayScrollbarStyle:(_WKOverlayScrollbarStyle)scrollbarStyle
+static WTF::Optional<WebCore::ScrollbarOverlayStyle> toCoreScrollbarStyle(_WKOverlayScrollbarStyle scrollbarStyle)
 {
-    WTF::Optional<WebCore::ScrollbarOverlayStyle> coreScrollbarStyle;
-
     switch (scrollbarStyle) {
     case _WKOverlayScrollbarStyleDark:
-        coreScrollbarStyle = ScrollbarOverlayStyleDark;
-        break;
+        return WebCore::ScrollbarOverlayStyleDark;
     case _WKOverlayScrollbarStyleLight:
-        coreScrollbarStyle = ScrollbarOverlayStyleLight;
-        break;
+        return WebCore::ScrollbarOverlayStyleLight;
     case _WKOverlayScrollbarStyleDefault:
-        coreScrollbarStyle = ScrollbarOverlayStyleDefault;
-        break;
+        return WebCore::ScrollbarOverlayStyleDefault;
     case _WKOverlayScrollbarStyleAutomatic:
     default:
         break;
     }
 
-    _data->_page->setOverlayScrollbarStyle(coreScrollbarStyle);
+    return Nullopt;
 }
 
-- (_WKOverlayScrollbarStyle)_overlayScrollbarStyle
+static _WKOverlayScrollbarStyle toAPIScrollbarStyle(WTF::Optional<WebCore::ScrollbarOverlayStyle> coreScrollbarStyle)
 {
-    WTF::Optional<WebCore::ScrollbarOverlayStyle> coreScrollbarStyle = _data->_page->overlayScrollbarStyle();
-
     if (!coreScrollbarStyle)
         return _WKOverlayScrollbarStyleAutomatic;
 
     switch (coreScrollbarStyle.value()) {
-    case ScrollbarOverlayStyleDark:
+    case WebCore::ScrollbarOverlayStyleDark:
         return _WKOverlayScrollbarStyleDark;
-    case ScrollbarOverlayStyleLight:
+    case WebCore::ScrollbarOverlayStyleLight:
         return _WKOverlayScrollbarStyleLight;
-    case ScrollbarOverlayStyleDefault:
+    case WebCore::ScrollbarOverlayStyleDefault:
         return _WKOverlayScrollbarStyleDefault;
     default:
         return _WKOverlayScrollbarStyleAutomatic;
     }
 }
 
-- (NSColor *)_pageExtendedBackgroundColor
+- (void)_setOverlayScrollbarStyle:(_WKOverlayScrollbarStyle)scrollbarStyle
 {
-    WebCore::Color color = _data->_page->pageExtendedBackgroundColor();
-    if (!color.isValid())
-        return nil;
+    _data->_impl->setOverlayScrollbarStyle(toCoreScrollbarStyle(scrollbarStyle));
+}
 
-    return nsColor(color);
+- (_WKOverlayScrollbarStyle)_overlayScrollbarStyle
+{
+    return toAPIScrollbarStyle(_data->_impl->overlayScrollbarStyle());
 }
 
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wmissing-noreturn"
-// This method forces a drawing area geometry update, even if frame size updates are disabled.
-// The updated is performed asynchronously; we don't wait for the geometry update before returning.
-// The area drawn need not match the current frame size - if it differs it will be anchored to the
-// frame according to the current contentAnchor.
-- (void)forceAsyncDrawingAreaSizeUpdate:(NSSize)size
+- (NSColor *)_pageExtendedBackgroundColor
 {
-    // This SPI is only used on 10.9 and below, and is incompatible with the fence-based drawing area size synchronization in 10.10+.
-#if __MAC_OS_X_VERSION_MIN_REQUIRED <= 1090
-    if (_data->_impl->clipsToVisibleRect())
-        _data->_impl->updateViewExposedRect();
-    _data->_impl->setDrawingAreaSize(NSSizeToCGSize(size));
+    return _data->_impl->pageExtendedBackgroundColor();
+}
 
-    // If a geometry update is pending the new update won't be sent. Poll without waiting for any
-    // pending did-update message now, such that the new update can be sent. We do so after setting
-    // the drawing area size such that the latest update is sent.
-    if (DrawingAreaProxy* drawingArea = _data->_page->drawingArea())
-        drawingArea->waitForPossibleGeometryUpdate(std::chrono::milliseconds::zero());
-#else
-    ASSERT_NOT_REACHED();
-#endif
+- (void)forceAsyncDrawingAreaSizeUpdate:(NSSize)size
+{
+    _data->_impl->forceAsyncDrawingAreaSizeUpdate(NSSizeToCGSize(size));
 }
 
 - (void)waitForAsyncDrawingAreaSizeUpdate
 {
-    // This SPI is only used on 10.9 and below, and is incompatible with the fence-based drawing area size synchronization in 10.10+.
-#if __MAC_OS_X_VERSION_MIN_REQUIRED <= 1090
-    if (DrawingAreaProxy* drawingArea = _data->_page->drawingArea()) {
-        // If a geometry update is still pending then the action of receiving the
-        // first geometry update may result in another update being scheduled -
-        // we should wait for this to complete too.
-        drawingArea->waitForPossibleGeometryUpdate(DrawingAreaProxy::didUpdateBackingStoreStateTimeout() / 2);
-        drawingArea->waitForPossibleGeometryUpdate(DrawingAreaProxy::didUpdateBackingStoreStateTimeout() / 2);
-    }
-#else
-    ASSERT_NOT_REACHED();
-#endif
+    _data->_impl->waitForAsyncDrawingAreaSizeUpdate();
 }
-#pragma clang diagnostic pop
 
 - (BOOL)isUsingUISideCompositing
 {
-    if (DrawingAreaProxy* drawingArea = _data->_page->drawingArea())
-        return drawingArea->type() == DrawingAreaTypeRemoteLayerTree;
-
-    return NO;
+    return _data->_impl->isUsingUISideCompositing();
 }
 
 - (void)setAllowsMagnification:(BOOL)allowsMagnification

Modified: trunk/Source/WebKit2/UIProcess/Cocoa/WebViewImpl.h (191756 => 191757)


--- trunk/Source/WebKit2/UIProcess/Cocoa/WebViewImpl.h	2015-10-29 21:54:24 UTC (rev 191756)
+++ trunk/Source/WebKit2/UIProcess/Cocoa/WebViewImpl.h	2015-10-29 22:07:42 UTC (rev 191757)
@@ -31,6 +31,7 @@
 #include "PluginComplexTextInputState.h"
 #include "WKLayoutMode.h"
 #include "WebPageProxy.h"
+#include "_WKOverlayScrollbarStyle.h"
 #include <WebCore/TextIndicatorWindow.h>
 #include <functional>
 #include <wtf/RetainPtr.h>
@@ -40,6 +41,7 @@
 OBJC_CLASS NSImmediateActionGestureRecognizer;
 OBJC_CLASS NSTextInputContext;
 OBJC_CLASS NSView;
+OBJC_CLASS WKBrowsingContextController;
 OBJC_CLASS WKEditorUndoTargetObjC;
 OBJC_CLASS WKFullScreenWindowController;
 OBJC_CLASS WKImmediateActionController;
@@ -80,6 +82,10 @@
 class WebPageProxy;
 struct ColorSpaceData;
 
+typedef id <NSValidatedUserInterfaceItem> ValidationItem;
+typedef Vector<RetainPtr<ValidationItem>> ValidationVector;
+typedef HashMap<String, ValidationVector> ValidationMap;
+
 class WebViewImpl {
     WTF_MAKE_FAST_ALLOCATED;
     WTF_MAKE_NONCOPYABLE(WebViewImpl);
@@ -119,7 +125,11 @@
     CGSize fixedLayoutSize() const;
 
     std::unique_ptr<DrawingAreaProxy> createDrawingAreaProxy();
+    bool isUsingUISideCompositing() const;
     void setDrawingAreaSize(CGSize);
+    void forceAsyncDrawingAreaSizeUpdate(CGSize);
+    void waitForAsyncDrawingAreaSizeUpdate();
+    void updateLayer();
 
     void setAutomaticallyAdjustsContentInsets(bool);
     bool automaticallyAdjustsContentInsets() const { return m_automaticallyAdjustsContentInsets; }
@@ -132,6 +142,10 @@
     void setClipsToVisibleRect(bool);
     bool clipsToVisibleRect() const { return m_clipsToVisibleRect; }
 
+    void setMinimumSizeForAutoLayout(CGSize);
+    CGSize minimumSizeForAutoLayout() const;
+    void setShouldExpandToViewHeightForAutoLayout(bool);
+    bool shouldExpandToViewHeightForAutoLayout() const;
     void setIntrinsicContentSize(CGSize);
     CGSize intrinsicContentSize() const;
 
@@ -164,6 +178,13 @@
 
     ColorSpaceData colorSpace();
 
+    void setUnderlayColor(NSColor *);
+    NSColor *underlayColor() const;
+    NSColor *pageExtendedBackgroundColor() const;
+
+    void setOverlayScrollbarStyle(WTF::Optional<WebCore::ScrollbarOverlayStyle> scrollbarStyle);
+    WTF::Optional<WebCore::ScrollbarOverlayStyle> overlayScrollbarStyle() const;
+
     void beginDeferringViewInWindowChanges();
     // FIXME: Merge these two?
     void endDeferringViewInWindowChanges();
@@ -204,7 +225,8 @@
     NSWindow *createFullScreenWindow();
 
     bool isEditable() const;
-    void executeEditCommand(const String& commandName, const String& argument = String());
+    bool executeSavedCommandBySelector(SEL);
+    void executeEditCommandForSelector(SEL, const String& argument = String());
     void registerEditCommand(RefPtr<WebEditCommandProxy>, WebPageProxy::UndoOrRedo);
     void clearAllEditCommands();
     bool writeSelectionToPasteboard(NSPasteboard *, NSArray *types);
@@ -212,6 +234,7 @@
     void selectionDidChange();
     void startObservingFontPanel();
     void updateFontPanelIfNeeded();
+    bool validateUserInterfaceItem(id <NSValidatedUserInterfaceItem>);
 
     void preferencesDidChange();
 
@@ -274,6 +297,8 @@
 
     _WKRemoteObjectRegistry *remoteObjectRegistry();
     void destroyRemoteObjectRegistry(); // FIXME: Temporary. Can fold in after we move ownership of WebPageProxy here.
+
+    WKBrowsingContextController *browsingContextController();
 #endif // WK_API_ENABLED
 
 #if ENABLE(DRAG_SUPPORT)
@@ -302,6 +327,8 @@
     NSArray *namesOfPromisedFilesDroppedAtDestination(NSURL *dropDestination);
 
     RefPtr<ViewSnapshot> takeViewSnapshot();
+    void saveBackForwardSnapshotForCurrentItem();
+    void saveBackForwardSnapshotForItem(WebBackForwardListItem&);
 
     ViewGestureController* gestureController() { return m_gestureController.get(); }
     ViewGestureController& ensureGestureController();
@@ -329,8 +356,6 @@
     void gestureEventWasNotHandledByWebCore(NSEvent *);
     void gestureEventWasNotHandledByWebCoreFromViewOnly(NSEvent *);
 
-    bool executeSavedCommandBySelector(SEL);
-
     void setTotalHeightOfBanners(CGFloat totalHeightOfBanners) { m_totalHeightOfBanners = totalHeightOfBanners; }
     CGFloat totalHeightOfBanners() const { return m_totalHeightOfBanners; }
 
@@ -351,6 +376,8 @@
     void reparentLayerTreeInThumbnailView();
     void updateThumbnailViewLayer();
 
+    void setUserInterfaceItemState(NSString *commandName, bool enabled, int state);
+
     NSView <WebViewImplDelegate> *m_view;
     WebPageProxy& m_page;
     PageClient& m_pageClient;
@@ -385,6 +412,8 @@
     bool m_inSecureInputState { false };
     RetainPtr<WKEditorUndoTargetObjC> m_undoTarget;
 
+    ValidationMap m_validationMap;
+
     // The identifier of the plug-in we want to send complex text input to, or 0 if there is none.
     uint64_t m_pluginComplexTextInputIdentifier { 0 };
 
@@ -435,6 +464,8 @@
     _WKThumbnailView *m_thumbnailView { nullptr };
 
     RetainPtr<_WKRemoteObjectRegistry> m_remoteObjectRegistry;
+
+    RetainPtr<WKBrowsingContextController> m_browsingContextController;
 #endif
 
     std::unique_ptr<ViewGestureController> m_gestureController;

Modified: trunk/Source/WebKit2/UIProcess/Cocoa/WebViewImpl.mm (191756 => 191757)


--- trunk/Source/WebKit2/UIProcess/Cocoa/WebViewImpl.mm	2015-10-29 21:54:24 UTC (rev 191756)
+++ trunk/Source/WebKit2/UIProcess/Cocoa/WebViewImpl.mm	2015-10-29 22:07:42 UTC (rev 191757)
@@ -41,8 +41,11 @@
 #import "RemoteObjectRegistry.h"
 #import "RemoteObjectRegistryMessages.h"
 #import "StringUtilities.h"
+#import "TextChecker.h"
+#import "TextCheckerState.h"
 #import "TiledCoreAnimationDrawingAreaProxy.h"
 #import "ViewGestureController.h"
+#import "WKBrowsingContextControllerInternal.h"
 #import "WKFullScreenWindowController.h"
 #import "WKImmediateActionController.h"
 #import "WKTextInputWindowController.h"
@@ -57,11 +60,14 @@
 #import "_WKThumbnailViewInternal.h"
 #import <HIToolbox/CarbonEventsCore.h>
 #import <WebCore/AXObjectCache.h>
+#import <WebCore/ColorMac.h>
 #import <WebCore/CoreGraphicsSPI.h>
 #import <WebCore/DataDetectorsSPI.h>
 #import <WebCore/DictionaryLookup.h>
 #import <WebCore/DragData.h>
+#import <WebCore/Editor.h>
 #import <WebCore/KeypressCommand.h>
+#import <WebCore/LocalizedStrings.h>
 #import <WebCore/LookupSPI.h>
 #import <WebCore/NSImmediateActionGestureRecognizerSPI.h>
 #import <WebCore/NSWindowSPI.h>
@@ -453,14 +459,6 @@
     return m_view.window;
 }
 
-std::unique_ptr<WebKit::DrawingAreaProxy> WebViewImpl::createDrawingAreaProxy()
-{
-    if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"WebKit2UseRemoteLayerTreeDrawingArea"] boolValue])
-        return std::make_unique<RemoteLayerTreeDrawingAreaProxy>(m_page);
-
-    return std::make_unique<TiledCoreAnimationDrawingAreaProxy>(m_page);
-}
-
 void WebViewImpl::processDidExit()
 {
     notifyInputContextAboutDiscardedComposition();
@@ -682,6 +680,20 @@
     return m_page.fixedLayoutSize();
 }
 
+std::unique_ptr<WebKit::DrawingAreaProxy> WebViewImpl::createDrawingAreaProxy()
+{
+    if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"WebKit2UseRemoteLayerTreeDrawingArea"] boolValue])
+        return std::make_unique<RemoteLayerTreeDrawingAreaProxy>(m_page);
+
+    return std::make_unique<TiledCoreAnimationDrawingAreaProxy>(m_page);
+}
+
+bool WebViewImpl::isUsingUISideCompositing() const
+{
+    auto* drawingArea = m_page.drawingArea();
+    return drawingArea && drawingArea->type() == DrawingAreaTypeRemoteLayerTree;
+}
+
 void WebViewImpl::setDrawingAreaSize(CGSize size)
 {
     if (!m_page.drawingArea())
@@ -691,6 +703,64 @@
     m_resizeScrollOffset = CGSizeZero;
 }
 
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wmissing-noreturn"
+// This method forces a drawing area geometry update, even if frame size updates are disabled.
+// The updated is performed asynchronously; we don't wait for the geometry update before returning.
+// The area drawn need not match the current frame size - if it differs it will be anchored to the
+// frame according to the current contentAnchor.
+void WebViewImpl::forceAsyncDrawingAreaSizeUpdate(CGSize size)
+{
+    // This SPI is only used on 10.9 and below, and is incompatible with the fence-based drawing area size synchronization in 10.10+.
+#if __MAC_OS_X_VERSION_MIN_REQUIRED <= 1090
+    if (m_clipsToVisibleRect)
+        updateViewExposedRect();
+    setDrawingAreaSize(size);
+
+    // If a geometry update is pending the new update won't be sent. Poll without waiting for any
+    // pending did-update message now, such that the new update can be sent. We do so after setting
+    // the drawing area size such that the latest update is sent.
+    if (DrawingAreaProxy* drawingArea = m_page.drawingArea())
+        drawingArea->waitForPossibleGeometryUpdate(std::chrono::milliseconds::zero());
+#else
+    ASSERT_NOT_REACHED();
+#endif
+}
+
+void WebViewImpl::waitForAsyncDrawingAreaSizeUpdate()
+{
+    // This SPI is only used on 10.9 and below, and is incompatible with the fence-based drawing area size synchronization in 10.10+.
+#if __MAC_OS_X_VERSION_MIN_REQUIRED <= 1090
+    if (DrawingAreaProxy* drawingArea = m_page.drawingArea()) {
+        // If a geometry update is still pending then the action of receiving the
+        // first geometry update may result in another update being scheduled -
+        // we should wait for this to complete too.
+        drawingArea->waitForPossibleGeometryUpdate(DrawingAreaProxy::didUpdateBackingStoreStateTimeout() / 2);
+        drawingArea->waitForPossibleGeometryUpdate(DrawingAreaProxy::didUpdateBackingStoreStateTimeout() / 2);
+    }
+#else
+    ASSERT_NOT_REACHED();
+#endif
+}
+#pragma clang diagnostic pop
+
+void WebViewImpl::updateLayer()
+{
+    if (drawsBackground() && !drawsTransparentBackground())
+        m_view.layer.backgroundColor = CGColorGetConstantColor(kCGColorWhite);
+    else
+        m_view.layer.backgroundColor = CGColorGetConstantColor(kCGColorClear);
+
+    // If asynchronous geometry updates have been sent by forceAsyncDrawingAreaSizeUpdate,
+    // then subsequent calls to setFrameSize should not result in us waiting for the did
+    // udpate response if setFrameSize is called.
+    if (frameSizeUpdatesDisabled())
+        return;
+
+    if (DrawingAreaProxy* drawingArea = m_page.drawingArea())
+        drawingArea->waitForPossibleGeometryUpdate();
+}
+
 void WebViewImpl::setAutomaticallyAdjustsContentInsets(bool automaticallyAdjustsContentInsets)
 {
     m_automaticallyAdjustsContentInsets = automaticallyAdjustsContentInsets;
@@ -763,6 +833,31 @@
     updateViewExposedRect();
 }
 
+void WebViewImpl::setMinimumSizeForAutoLayout(CGSize minimumSizeForAutoLayout)
+{
+    bool expandsToFit = minimumSizeForAutoLayout.width > 0;
+
+    m_page.setMinimumLayoutSize(WebCore::IntSize(minimumSizeForAutoLayout));
+    m_page.setMainFrameIsScrollable(!expandsToFit);
+
+    setClipsToVisibleRect(expandsToFit);
+}
+
+CGSize WebViewImpl::minimumSizeForAutoLayout() const
+{
+    return m_page.minimumLayoutSize();
+}
+
+void WebViewImpl::setShouldExpandToViewHeightForAutoLayout(bool shouldExpandToViewHeightForAutoLayout)
+{
+    m_page.setAutoSizingShouldExpandToViewHeight(shouldExpandToViewHeightForAutoLayout);
+}
+
+bool WebViewImpl::shouldExpandToViewHeightForAutoLayout() const
+{
+    return m_page.autoSizingShouldExpandToViewHeight();
+}
+
 void WebViewImpl::setIntrinsicContentSize(CGSize intrinsicContentSize)
 {
     // If the intrinsic content size is less than the minimum layout width, the content flowed to fit,
@@ -1052,6 +1147,39 @@
     return colorSpaceData;
 }
 
+void WebViewImpl::setUnderlayColor(NSColor *underlayColor)
+{
+    m_page.setUnderlayColor(WebCore::colorFromNSColor(underlayColor));
+}
+
+NSColor *WebViewImpl::underlayColor() const
+{
+    WebCore::Color webColor = m_page.underlayColor();
+    if (!webColor.isValid())
+        return nil;
+
+    return WebCore::nsColor(webColor);
+}
+
+NSColor *WebViewImpl::pageExtendedBackgroundColor() const
+{
+    WebCore::Color color = m_page.pageExtendedBackgroundColor();
+    if (!color.isValid())
+        return nil;
+
+    return WebCore::nsColor(color);
+}
+
+void WebViewImpl::setOverlayScrollbarStyle(WTF::Optional<WebCore::ScrollbarOverlayStyle> scrollbarStyle)
+{
+    m_page.setOverlayScrollbarStyle(scrollbarStyle);
+}
+
+WTF::Optional<WebCore::ScrollbarOverlayStyle> WebViewImpl::overlayScrollbarStyle() const
+{
+    return m_page.overlayScrollbarStyle();
+}
+
 void WebViewImpl::beginDeferringViewInWindowChanges()
 {
     if (m_shouldDeferViewInWindowChanges) {
@@ -1357,11 +1485,71 @@
     return m_page.isEditable();
 }
 
-void WebViewImpl::executeEditCommand(const String& commandName, const String& argument)
+typedef HashMap<SEL, String> SelectorNameMap;
+
+// Map selectors into Editor command names.
+// This is not needed for any selectors that have the same name as the Editor command.
+static const SelectorNameMap& selectorExceptionMap()
 {
-    m_page.executeEditCommand(commandName, argument);
+    static NeverDestroyed<SelectorNameMap> map;
+
+    struct SelectorAndCommandName {
+        SEL selector;
+        ASCIILiteral commandName;
+    };
+
+    static const SelectorAndCommandName names[] = {
+        { @selector(insertNewlineIgnoringFieldEditor:), ASCIILiteral("InsertNewline") },
+        { @selector(insertParagraphSeparator:), ASCIILiteral("InsertNewline") },
+        { @selector(insertTabIgnoringFieldEditor:), ASCIILiteral("InsertTab") },
+        { @selector(pageDown:), ASCIILiteral("MovePageDown") },
+        { @selector(pageDownAndModifySelection:), ASCIILiteral("MovePageDownAndModifySelection") },
+        { @selector(pageUp:), ASCIILiteral("MovePageUp") },
+        { @selector(pageUpAndModifySelection:), ASCIILiteral("MovePageUpAndModifySelection") },
+        { @selector(scrollPageDown:), ASCIILiteral("ScrollPageForward") },
+        { @selector(scrollPageUp:), ASCIILiteral("ScrollPageBackward") }
+    };
+
+    for (auto& name : names)
+        map.get().add(name.selector, name.commandName);
+
+    return map;
 }
 
+static String commandNameForSelector(SEL selector)
+{
+    // Check the exception map first.
+    static const SelectorNameMap& exceptionMap = selectorExceptionMap();
+    SelectorNameMap::const_iterator it = exceptionMap.find(selector);
+    if (it != exceptionMap.end())
+        return it->value;
+
+    // Remove the trailing colon.
+    // No need to capitalize the command name since Editor command names are
+    // not case sensitive.
+    const char* selectorName = sel_getName(selector);
+    size_t selectorNameLength = strlen(selectorName);
+    if (selectorNameLength < 2 || selectorName[selectorNameLength - 1] != ':')
+        return String();
+    return String(selectorName, selectorNameLength - 1);
+}
+
+bool WebViewImpl::executeSavedCommandBySelector(SEL selector)
+{
+    LOG(TextInput, "Executing previously saved command %s", sel_getName(selector));
+    // The sink does two things: 1) Tells us if the responder went unhandled, and
+    // 2) prevents any NSBeep; we don't ever want to beep here.
+    RetainPtr<WKResponderChainSink> sink = adoptNS([[WKResponderChainSink alloc] initWithResponderChain:m_view]);
+    [m_view _superDoCommandBySelector:selector];
+    [sink detach];
+    return ![sink didReceiveUnhandledCommand];
+}
+
+void WebViewImpl::executeEditCommandForSelector(SEL selector, const String& argument)
+{
+    m_page.executeEditCommand(commandNameForSelector(selector), argument);
+}
+
 void WebViewImpl::registerEditCommand(RefPtr<WebEditCommandProxy> prpCommand, WebPageProxy::UndoOrRedo undoOrRedo)
 {
     RefPtr<WebEditCommandProxy> command = prpCommand;
@@ -1424,6 +1612,141 @@
     }
 }
 
+static NSMenuItem *menuItem(id <NSValidatedUserInterfaceItem> item)
+{
+    if (![(NSObject *)item isKindOfClass:[NSMenuItem class]])
+        return nil;
+    return (NSMenuItem *)item;
+}
+
+static NSToolbarItem *toolbarItem(id <NSValidatedUserInterfaceItem> item)
+{
+    if (![(NSObject *)item isKindOfClass:[NSToolbarItem class]])
+        return nil;
+    return (NSToolbarItem *)item;
+}
+
+bool WebViewImpl::validateUserInterfaceItem(id <NSValidatedUserInterfaceItem> item)
+{
+    SEL action = "" action];
+
+    if (action == @selector(showGuessPanel:)) {
+        if (NSMenuItem *menuItem = WebKit::menuItem(item))
+            [menuItem setTitle:WebCore::contextMenuItemTagShowSpellingPanel(![[[NSSpellChecker sharedSpellChecker] spellingPanel] isVisible])];
+        return m_page.editorState().isContentEditable;
+    }
+
+    if (action == @selector(checkSpelling:) || action == @selector(changeSpelling:))
+        return m_page.editorState().isContentEditable;
+
+    if (action == @selector(toggleContinuousSpellChecking:)) {
+        bool enabled = TextChecker::isContinuousSpellCheckingAllowed();
+        bool checked = enabled && TextChecker::state().isContinuousSpellCheckingEnabled;
+        [menuItem(item) setState:checked ? NSOnState : NSOffState];
+        return enabled;
+    }
+
+    if (action == @selector(toggleGrammarChecking:)) {
+        bool checked = TextChecker::state().isGrammarCheckingEnabled;
+        [menuItem(item) setState:checked ? NSOnState : NSOffState];
+        return true;
+    }
+
+    if (action == @selector(toggleAutomaticSpellingCorrection:)) {
+        bool checked = TextChecker::state().isAutomaticSpellingCorrectionEnabled;
+        [menuItem(item) setState:checked ? NSOnState : NSOffState];
+        return m_page.editorState().isContentEditable;
+    }
+
+    if (action == @selector(orderFrontSubstitutionsPanel:)) {
+        if (NSMenuItem *menuItem = WebKit::menuItem(item))
+            [menuItem setTitle:WebCore::contextMenuItemTagShowSubstitutions(![[[NSSpellChecker sharedSpellChecker] substitutionsPanel] isVisible])];
+        return m_page.editorState().isContentEditable;
+    }
+
+    if (action == @selector(toggleSmartInsertDelete:)) {
+        bool checked = m_page.isSmartInsertDeleteEnabled();
+        [menuItem(item) setState:checked ? NSOnState : NSOffState];
+        return m_page.editorState().isContentEditable;
+    }
+
+    if (action == @selector(toggleAutomaticQuoteSubstitution:)) {
+        bool checked = TextChecker::state().isAutomaticQuoteSubstitutionEnabled;
+        [menuItem(item) setState:checked ? NSOnState : NSOffState];
+        return m_page.editorState().isContentEditable;
+    }
+
+    if (action == @selector(toggleAutomaticDashSubstitution:)) {
+        bool checked = TextChecker::state().isAutomaticDashSubstitutionEnabled;
+        [menuItem(item) setState:checked ? NSOnState : NSOffState];
+        return m_page.editorState().isContentEditable;
+    }
+
+    if (action == @selector(toggleAutomaticLinkDetection:)) {
+        bool checked = TextChecker::state().isAutomaticLinkDetectionEnabled;
+        [menuItem(item) setState:checked ? NSOnState : NSOffState];
+        return m_page.editorState().isContentEditable;
+    }
+
+    if (action == @selector(toggleAutomaticTextReplacement:)) {
+        bool checked = TextChecker::state().isAutomaticTextReplacementEnabled;
+        [menuItem(item) setState:checked ? NSOnState : NSOffState];
+        return m_page.editorState().isContentEditable;
+    }
+
+    if (action == @selector(uppercaseWord:) || action == @selector(lowercaseWord:) || action == @selector(capitalizeWord:))
+        return m_page.editorState().selectionIsRange && m_page.editorState().isContentEditable;
+
+    if (action == @selector(stopSpeaking:))
+        return [NSApp isSpeaking];
+
+    // The centerSelectionInVisibleArea: selector is enabled if there's a selection range or if there's an insertion point in an editable area.
+    if (action == @selector(centerSelectionInVisibleArea:))
+        return m_page.editorState().selectionIsRange || (m_page.editorState().isContentEditable && !m_page.editorState().selectionIsNone);
+
+    // Next, handle editor commands. Start by returning true for anything that is not an editor command.
+    // Returning true is the default thing to do in an AppKit validate method for any selector that is not recognized.
+    String commandName = commandNameForSelector([item action]);
+    if (!WebCore::Editor::commandIsSupportedFromMenuOrKeyBinding(commandName))
+        return true;
+
+    // Add this item to the vector of items for a given command that are awaiting validation.
+    ValidationMap::AddResult addResult = m_validationMap.add(commandName, ValidationVector());
+    addResult.iterator->value.append(item);
+    if (addResult.isNewEntry) {
+        // If we are not already awaiting validation for this command, start the asynchronous validation process.
+        // FIXME: Theoretically, there is a race here; when we get the answer it might be old, from a previous time
+        // we asked for the same command; there is no guarantee the answer is still valid.
+        auto weakThis = createWeakPtr();
+        m_page.validateCommand(commandName, [weakThis](const String& commandName, bool isEnabled, int32_t state, WebKit::CallbackBase::Error error) {
+            if (!weakThis)
+                return;
+
+            // If the process exits before the command can be validated, we'll be called back with an error.
+            if (error != WebKit::CallbackBase::Error::None)
+                return;
+
+            weakThis->setUserInterfaceItemState(commandName, isEnabled, state);
+        });
+    }
+
+    // Treat as enabled until we get the result back from the web process and _setUserInterfaceItemState is called.
+    // FIXME <rdar://problem/8803459>: This means disabled items will flash enabled at first for a moment.
+    // But returning NO here would be worse; that would make keyboard commands such as command-C fail.
+    return true;
+}
+
+void WebViewImpl::setUserInterfaceItemState(NSString *commandName, bool enabled, int state)
+{
+    ValidationVector items = m_validationMap.take(commandName);
+    for (auto& item : items) {
+        [menuItem(item.get()) setState:state];
+        [menuItem(item.get()) setEnabled:enabled];
+        [toolbarItem(item.get()) setEnabled:enabled];
+        // FIXME <rdar://problem/8803392>: If the item is neither a menu nor toolbar item, it will be left enabled.
+    }
+}
+
 void WebViewImpl::preferencesDidChange()
 {
     BOOL needsViewFrameInWindowCoordinates = m_page.preferences().pluginsEnabled();
@@ -1908,6 +2231,14 @@
     [m_remoteObjectRegistry _invalidate];
     m_remoteObjectRegistry = nil;
 }
+
+WKBrowsingContextController *WebViewImpl::browsingContextController()
+{
+    if (!m_browsingContextController)
+        m_browsingContextController = adoptNS([[WKBrowsingContextController alloc] _initWithPageRef:toAPI(&m_page)]);
+
+    return m_browsingContextController.get();
+}
 #endif // WK_API_ENABLED
 
 #if ENABLE(DRAG_SUPPORT)
@@ -2294,6 +2625,16 @@
     return ViewSnapshot::create(WTF::move(surface));
 }
 
+void WebViewImpl::saveBackForwardSnapshotForCurrentItem()
+{
+    m_page.recordNavigationSnapshot();
+}
+
+void WebViewImpl::saveBackForwardSnapshotForItem(WebBackForwardListItem& item)
+{
+    m_page.recordNavigationSnapshot(item);
+}
+
 ViewGestureController& WebViewImpl::ensureGestureController()
 {
     if (!m_gestureController)
@@ -2488,17 +2829,6 @@
 #endif
 }
 
-bool WebViewImpl::executeSavedCommandBySelector(SEL selector)
-{
-    LOG(TextInput, "Executing previously saved command %s", sel_getName(selector));
-    // The sink does two things: 1) Tells us if the responder went unhandled, and
-    // 2) prevents any NSBeep; we don't ever want to beep here.
-    RetainPtr<WKResponderChainSink> sink = adoptNS([[WKResponderChainSink alloc] initWithResponderChain:m_view]);
-    [m_view _superDoCommandBySelector:selector];
-    [sink detach];
-    return ![sink didReceiveUnhandledCommand];
-}
-
 } // namespace WebKit
 
 #endif // PLATFORM(MAC)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to