Reviewed by thatcher
authorjusting <justing@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 27 Sep 2006 22:54:05 +0000 (22:54 +0000)
committerjusting <justing@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 27 Sep 2006 22:54:05 +0000 (22:54 +0000)
        <rdar://problem/4044271>
        Writing Direction menu doesn't reflect the current writing direction (9773)

        * English.lproj/Localizable.strings: Added "Right to Left" and "Left to Right"
        * WebView/WebHTMLView.m:
        (-[NSArray validateUserInterfaceItem:]): Validate menu items that perform
        toggleBaseWritingDirection and changeBaseWritingDirection.
        Disable the menu item that changes the writing direction to NSWritingDirectionNautral
        because NSWritingDirectionNatural's behavior can't be implemented with CSS.
        Take control of the title of the menu item that performs toggleBaseWritingDirection:
        instead of checking/unchecking it, otherwise we wouldn't know what a check means.
        (-[NSArray changeBaseWritingDirection:]): ASSERT that the requested writing
        direction is not NSWritingDirectionNatural, since we've disabled the
        menu item that performs it.

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

WebKit/ChangeLog
WebKit/English.lproj/Localizable.strings
WebKit/WebView/WebHTMLView.m

index 98fa35a6798a4594ea0f8052db435daef888de88..da08b949e2ec1ae337bdc5ce1029d79a8204e358 100644 (file)
@@ -1,3 +1,22 @@
+2006-09-27  Justin Garcia  <justin.garcia@apple.com>
+
+        Reviewed by thatcher
+        
+        <rdar://problem/4044271>
+        Writing Direction menu doesn't reflect the current writing direction (9773)
+
+        * English.lproj/Localizable.strings: Added "Right to Left" and "Left to Right"
+        * WebView/WebHTMLView.m:
+        (-[NSArray validateUserInterfaceItem:]): Validate menu items that perform
+        toggleBaseWritingDirection and changeBaseWritingDirection.  
+        Disable the menu item that changes the writing direction to NSWritingDirectionNautral
+        because NSWritingDirectionNatural's behavior can't be implemented with CSS.
+        Take control of the title of the menu item that performs toggleBaseWritingDirection:
+        instead of checking/unchecking it, otherwise we wouldn't know what a check means.
+        (-[NSArray changeBaseWritingDirection:]): ASSERT that the requested writing
+        direction is not NSWritingDirectionNatural, since we've disabled the
+        menu item that performs it.
+
 2006-09-27  MorganL  <morganl.webkit@yahoo.com>
 
         Reviewed by Maciej, landed by Brady
index 254d133559e99b91b60809f91dad4681ebae6472..9745a2a57b021fc1a0c593e983b42031422c96c8 100644 (file)
Binary files a/WebKit/English.lproj/Localizable.strings and b/WebKit/English.lproj/Localizable.strings differ
index 6f1a6dc4f9b26b6c3f1069b3e1fe0d964aee3d62..566feaf0ea24479cbaa4b73c9124a221a14ab6a6 100644 (file)
@@ -51,6 +51,7 @@
 #import <WebKit/WebHTMLRepresentationPrivate.h>
 #import <WebKit/WebKitLogging.h>
 #import <WebKit/WebKitNSStringExtras.h>
+#import <WebKit/WebLocalizableStrings.h>
 #import <WebKit/WebNetscapePluginEmbeddedView.h>
 #import <WebKit/WebNSAttributedStringExtras.h>
 #import <WebKit/WebNSEventExtras.h>
@@ -2089,8 +2090,7 @@ static WebHTMLView *lastHitView = nil;
     SEL action = [item action];
     WebFrameBridge *bridge = [self _bridge];
 
-    if (action == @selector(changeBaseWritingDirection:) // FIXME: check menu item based on writing direction
-            || action == @selector(changeSpelling:)
+    if (action == @selector(changeSpelling:)
             || action == @selector(_changeSpellingFromMenu:)
             || action == @selector(checkSpelling:)
             || action == @selector(complete:)
@@ -2155,11 +2155,33 @@ static WebHTMLView *lastHitView = nil;
             || 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(changeBaseWritingDirection:)) {
+        NSMenuItem *menuItem = (NSMenuItem *)item;
+        if ([menuItem isKindOfClass:[NSMenuItem class]]) {
+            NSWritingDirection writingDirection = [item tag];
+            if (writingDirection == NSWritingDirectionNatural) {
+                [menuItem setState:NO];
+                return NO;
+            }
+            DOMCSSStyleDeclaration* style = [self _emptyStyle];
+            [style setDirection:writingDirection == NSWritingDirectionLeftToRight ? @"LTR" : @"RTL"];
+            [menuItem setState:[[self _bridge] selectionHasStyle:style]];
+        }
+        return [self _canEdit];
+    } else if (action == @selector(toggleBaseWritingDirection:)) {
+        NSMenuItem *menuItem = (NSMenuItem *)item;
+        if ([menuItem isKindOfClass:[NSMenuItem class]]) {
+            DOMCSSStyleDeclaration* rtl = [self _emptyStyle];
+            [rtl setDirection:@"RTL"];
+            // Take control of the title of the menu item, instead of just checking/unchecking it because otherwise
+            // we don't know what the check would mean.
+            [menuItem setTitle:[[self _bridge] selectionHasStyle:rtl] ? UI_STRING("Left to Right", "Left to Right context menu item") : UI_STRING("Right to Left", "Right to Left context menu item")];
+        }
+        return [self _canEdit];
     } else if (action == @selector(alignCenter:)
             || action == @selector(alignLeft:)
             || action == @selector(alignJustified:)
@@ -4718,19 +4740,13 @@ static DOMRange *unionDOMRanges(DOMRange *a, DOMRange *b)
         return;
     
     NSWritingDirection writingDirection = [sender tag];
-
-    NSString *direction = @"LTR";
-    switch (writingDirection) {
-        case NSWritingDirectionLeftToRight:
-        case NSWritingDirectionNatural:
-            break;
-        case NSWritingDirectionRightToLeft:
-            direction = @"RTL";
-            break;
-    }
+    
+    // We disable the menu item that performs this action because we can't implement
+    // NSWritingDirectionNatural's behavior using CSS.
+    ASSERT(writingDirection != NSWritingDirectionNatural);
 
     DOMCSSStyleDeclaration *style = [self _emptyStyle];
-    [style setDirection:direction];
+    [style setDirection:writingDirection == NSWritingDirectionLeftToRight ? @"LTR" : @"RTL"];
     [self _applyParagraphStyleToSelection:style withUndoAction:WebUndoActionSetWritingDirection];
 }