Reviewed by Harrison.
authordarin <darin@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 10 Feb 2005 23:48:08 +0000 (23:48 +0000)
committerdarin <darin@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 10 Feb 2005 23:48:08 +0000 (23:48 +0000)
        - fixed <rdar://problem/3991225> Format->Style->Underline menu item does not get checked when selected text is underlined

        * WebView.subproj/WebHTMLView.m:
        (-[WebHTMLView validateUserInterfaceItem:]): Added tons of additional cases in here for all the
        "action" style methods in this class that don't always want to be valid. For the ones where state
        makes sense, added the state-checking code too for the menu item case.
        (-[WebHTMLView ignoreSpelling:]): Removed unnecessary "editable text only" check since this command
        would work fine on a non-editable selection.
        (-[WebHTMLView swapWithMark:]): Ditto.
        (-[WebHTMLView changeBaseWritingDirection:]): Added. Like toggle, but based on the sender's tag.

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

WebKit/ChangeLog
WebKit/WebView.subproj/WebHTMLView.m

index 3e99432a4755ac97bd423080e23a834e40ea791a..fd78b64f175041f6e218bfb50ba4f3f6e9803d42 100644 (file)
@@ -1,3 +1,18 @@
+2005-02-10  Darin Adler  <darin@apple.com>
+
+        Reviewed by Harrison.
+
+        - fixed <rdar://problem/3991225> Format->Style->Underline menu item does not get checked when selected text is underlined
+
+        * WebView.subproj/WebHTMLView.m:
+        (-[WebHTMLView validateUserInterfaceItem:]): Added tons of additional cases in here for all the
+        "action" style methods in this class that don't always want to be valid. For the ones where state
+        makes sense, added the state-checking code too for the menu item case.
+        (-[WebHTMLView ignoreSpelling:]): Removed unnecessary "editable text only" check since this command
+        would work fine on a non-editable selection.
+        (-[WebHTMLView swapWithMark:]): Ditto.
+        (-[WebHTMLView changeBaseWritingDirection:]): Added. Like toggle, but based on the sender's tag.
+
 2005-02-08  Darin Adler  <darin@apple.com>
 
         "Reviewed" by Richard (he told me the file was obsolete).
index 3b6127a77f1ce4f4bef9067814c9ed5b1662a357..b6c9d5512c69eeea8eb53a61d54cb1b39b2342b0 100644 (file)
@@ -1753,7 +1753,7 @@ static WebHTMLView *lastHitView = nil;
     [self selectAll];
 }
 
-- (void)jumpToSelection: sender
+- (void)jumpToSelection:(id)sender
 {
     [[self _bridge] jumpToSelection];
 }
@@ -1763,23 +1763,141 @@ static WebHTMLView *lastHitView = nil;
     SEL action = [item action];
     WebBridge *bridge = [self _bridge];
 
-    if (action == @selector(cut:)) {
-        return [bridge mayDHTMLCut] || [self _canDelete];
+    if (action == @selector(alignCenter:)
+            || action == @selector(alignLeft:)
+            || action == @selector(alignJustified:)
+            || action == @selector(alignRight:)
+            || action == @selector(changeAttributes:)
+            || action == @selector(changeBaseWritingDirection:) // FIXME: check menu item based on writing direction
+            || action == @selector(changeColor:)
+            || action == @selector(changeFont:)
+            || action == @selector(changeSpelling:)
+            || action == @selector(_changeSpellingFromMenu:)
+            || action == @selector(checkSpelling:)
+            || action == @selector(complete:)
+            || action == @selector(deleteBackward:)
+            || action == @selector(deleteBackwardByDecomposingPreviousCharacter:)
+            || action == @selector(deleteForward:)
+            || action == @selector(deleteToBeginningOfLine:)
+            || action == @selector(deleteToBeginningOfParagraph:)
+            || action == @selector(deleteToEndOfLine:)
+            || action == @selector(deleteToEndOfParagraph:)
+            || action == @selector(deleteToMark:)
+            || action == @selector(deleteWordBackward:)
+            || action == @selector(deleteWordForward:)
+            || action == @selector(insertBacktab:)
+            || action == @selector(insertLineBreak:)
+            || action == @selector(insertNewline:)
+            || action == @selector(insertNewlineIgnoringFieldEditor:)
+            || action == @selector(insertParagraphSeparator:)
+            || action == @selector(insertTab:)
+            || action == @selector(insertTabIgnoringFieldEditor:)
+            || action == @selector(moveBackward:)
+            || action == @selector(moveBackwardAndModifySelection:)
+            || action == @selector(moveDown:)
+            || action == @selector(moveDownAndModifySelection:)
+            || action == @selector(moveForward:)
+            || action == @selector(moveForwardAndModifySelection:)
+            || action == @selector(moveLeft:)
+            || action == @selector(moveLeftAndModifySelection:)
+            || action == @selector(moveParagraphBackwardAndModifySelection:)
+            || action == @selector(moveParagraphForwardAndModifySelection:)
+            || action == @selector(moveRight:)
+            || action == @selector(moveRightAndModifySelection:)
+            || action == @selector(moveToBeginningOfDocument:)
+            || action == @selector(moveToBeginningOfDocumentAndModifySelection:)
+            || action == @selector(moveToBeginningOfLine:)
+            || action == @selector(moveToBeginningOfLineAndModifySelection:)
+            || action == @selector(moveToBeginningOfParagraph:)
+            || action == @selector(moveToBeginningOfParagraphAndModifySelection:)
+            || action == @selector(moveToEndOfDocument:)
+            || action == @selector(moveToEndOfDocumentAndModifySelection:)
+            || action == @selector(moveToEndOfLine:)
+            || action == @selector(moveToEndOfLineAndModifySelection:)
+            || action == @selector(moveToEndOfParagraph:)
+            || action == @selector(moveToEndOfParagraphAndModifySelection:)
+            || action == @selector(moveUp:)
+            || action == @selector(moveUpAndModifySelection:)
+            || action == @selector(moveWordBackward:)
+            || action == @selector(moveWordBackwardAndModifySelection:)
+            || action == @selector(moveWordForward:)
+            || action == @selector(moveWordForwardAndModifySelection:)
+            || action == @selector(moveWordLeft:)
+            || action == @selector(moveWordLeftAndModifySelection:)
+            || action == @selector(moveWordRight:)
+            || action == @selector(moveWordRightAndModifySelection:)
+            || action == @selector(pageDown:)
+            || action == @selector(pageDownAndModifySelection:)
+            || action == @selector(pageUp:)
+            || action == @selector(pageUpAndModifySelection:)
+            || action == @selector(pasteFont:)
+            || action == @selector(showGuessPanel:)
+            || action == @selector(toggleBaseWritingDirection:)
+            || action == @selector(transpose:)
+            || action == @selector(yank:)
+            || action == @selector(yankAndSelect:)) {
+        return [self _canEdit];
+    } else if (action == @selector(capitalizeWord:)
+               || action == @selector(lowercaseWord:)
+               || action == @selector(uppercaseWord:)) {
+        return [self _hasSelection] && [self _isEditable];
+    } else if (action == @selector(centerSelectionInVisibleArea:)
+            || action == @selector(copyFont:)
+            || action == @selector(setMark:)) {
+        return [self _hasSelectionOrInsertionPoint];
+    } else if (action == @selector(changeDocumentBackgroundColor:)) {
+        return [[self _webView] isEditable];
     } else if (action == @selector(copy:)) {
         return [bridge mayDHTMLCopy] || [self _canCopy];
+    } else if (action == @selector(cut:)) {
+        return [bridge mayDHTMLCut] || [self _canDelete];
     } else if (action == @selector(delete:)) {
         return [self _canDelete];
-    } else if (action == @selector(paste:)) {
-        return [bridge mayDHTMLPaste] || [self _canPaste];
-    } else if (action == @selector(takeFindStringFromSelection:)) {
+    } else if (action == @selector(_ignoreSpellingFromMenu:)
+            || action == @selector(jumpToSelection:)
+            || action == @selector(_learnSpellingFromMenu:)
+            || action == @selector(takeFindStringFromSelection:)) {
         return [self _hasSelection];
-    } else if (action == @selector(jumpToSelection:)) {
-        return [self _hasSelection];
-    } else if (action == @selector(checkSpelling:)
-               || action == @selector(showGuessPanel:)
-               || action == @selector(changeSpelling:)
-               || action == @selector(ignoreSpelling:)) {
-        return [[self _bridge] isSelectionEditable];
+    } else if (action == @selector(paste:) || action == @selector(pasteAsPlainText:) || action == @selector(pasteAsRichText:)) {
+        return [bridge mayDHTMLPaste] || [self _canPaste];
+    } else if (action == @selector(performFindPanelAction:)) {
+        // FIXME: Not yet implemented.
+        return NO;
+    } else if (action == @selector(selectToMark:)
+            || action == @selector(swapWithMark:)) {
+        return [self _hasSelectionOrInsertionPoint] && [[self _bridge] markDOMRange] != nil;
+    } else if (action == @selector(subscript:)) {
+        NSMenuItem *menuItem = (NSMenuItem *)item;
+        if ([menuItem isKindOfClass:[NSMenuItem class]]) {
+            DOMCSSStyleDeclaration *style = [self _emptyStyle];
+            [style setVerticalAlign:@"sub"];
+            [menuItem setState:[[self _bridge] selectionHasStyle:style]];
+        }
+        return [self _canEdit];
+    } else if (action == @selector(superscript:)) {
+        NSMenuItem *menuItem = (NSMenuItem *)item;
+        if ([menuItem isKindOfClass:[NSMenuItem class]]) {
+            DOMCSSStyleDeclaration *style = [self _emptyStyle];
+            [style setVerticalAlign:@"super"];
+            [menuItem setState:[[self _bridge] selectionHasStyle:style]];
+        }
+        return [self _canEdit];
+    } else if (action == @selector(underline:)) {
+        NSMenuItem *menuItem = (NSMenuItem *)item;
+        if ([menuItem isKindOfClass:[NSMenuItem class]]) {
+            DOMCSSStyleDeclaration *style = [self _emptyStyle];
+            [style setProperty:@"-khtml-text-decorations-in-effect" :@"underline" :@""];
+            [menuItem setState:[[self _bridge] selectionHasStyle:style]];
+        }
+        return [self _canEdit];
+    } else if (action == @selector(unscript:)) {
+        NSMenuItem *menuItem = (NSMenuItem *)item;
+        if ([menuItem isKindOfClass:[NSMenuItem class]]) {
+            DOMCSSStyleDeclaration *style = [self _emptyStyle];
+            [style setVerticalAlign:@"baseline"];
+            [menuItem setState:[[self _bridge] selectionHasStyle:style]];
+        }
+        return [self _canEdit];
 #ifndef OMIT_TIGER_FEATURES
     } else if (action == @selector(_searchWithSpotlightFromMenu:)
                || action == @selector(_searchWithGoogleFromMenu:)
@@ -3053,7 +3171,8 @@ static WebHTMLView *lastHitView = nil;
         return self;
 }
 
-- (id)_accessibilityParentForSubview:(NSView *)subview {
+- (id)_accessibilityParentForSubview:(NSView *)subview
+{
     id accTree = [[self _bridge] accessibilityTree];
     if (!accTree)
         return self;
@@ -4112,9 +4231,6 @@ NSStrokeColorAttributeName        /* NSColor, default nil: same as foreground co
 
 - (void)ignoreSpelling:(id)sender
 {
-    if (![self _canEdit])
-        return;
-    
     NSSpellChecker *checker = [NSSpellChecker sharedSpellChecker];
     if (!checker) {
         ERROR("No NSSpellChecker");
@@ -4267,9 +4383,6 @@ static DOMRange *unionDOMRanges(DOMRange *a, DOMRange *b)
 
 - (void)swapWithMark:(id)sender
 {
-    if (![self _canEdit])
-        return;
-
     WebBridge *bridge = [self _bridge];
     DOMRange *mark = [bridge markDOMRange];
     if (mark == nil) {
@@ -4337,6 +4450,28 @@ static DOMRange *unionDOMRanges(DOMRange *a, DOMRange *b)
     [self _applyParagraphStyleToSelection:style withUndoAction:WebUndoActionSetWritingDirection];
 }
 
+- (void)changeBaseWritingDirection:(id)sender
+{
+    if (![self _canEdit])
+        return;
+    
+    NSWritingDirection writingDirection = [sender tag];
+
+    NSString *direction = @"LTR";
+    switch (writingDirection) {
+        case NSWritingDirectionLeftToRight:
+        case NSWritingDirectionNatural:
+            break;
+        case NSWritingDirectionRightToLeft:
+            direction = @"RTL";
+            break;
+    }
+
+    DOMCSSStyleDeclaration *style = [self _emptyStyle];
+    [style setDirection:direction];
+    [self _applyParagraphStyleToSelection:style withUndoAction:WebUndoActionSetWritingDirection];
+}
+
 #if 0
 
 // CSS does not have a way to specify an outline font, which may make this difficult to implement.
@@ -4351,10 +4486,8 @@ static DOMRange *unionDOMRanges(DOMRange *a, DOMRange *b)
 
 // These could be important.
 - (void)toggleTraditionalCharacterShape:(id)sender;
-- (void)changeBaseWritingDirection:(id)sender;
 
-// I'm not sure what the equivalents of these in the web world are; we use <br> as a paragraph break.
-- (void)insertLineBreak:(id)sender;
+// I'm not sure what the equivalents of these in the web world are.
 - (void)insertLineSeparator:(id)sender;
 - (void)insertPageBreak:(id)sender;