- add back "unused code" for plain text fields, still used by <isindex>!
authordarin <darin@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 10 Jul 2006 06:16:42 +0000 (06:16 +0000)
committerdarin <darin@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 10 Jul 2006 06:16:42 +0000 (06:16 +0000)
        * platform/TextField.h:
        * platform/mac/TextFieldMac.mm:
        * platform/mac/WebCoreTextField.h:
        * platform/mac/WebCoreTextField.mm:
        * rendering/RenderLineEdit.cpp:

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

WebCore/ChangeLog
WebCore/platform/TextField.h
WebCore/platform/mac/TextFieldMac.mm
WebCore/platform/mac/WebCoreTextField.h
WebCore/platform/mac/WebCoreTextField.mm
WebCore/rendering/RenderLineEdit.cpp

index 4b01e31071703123bbca1263a81efa75df94e71f..3054f67604723ade1b162598d9a7f8675e6b61aa 100644 (file)
@@ -1,3 +1,13 @@
+2006-07-09  Darin Adler  <darin@apple.com>
+
+        - add back "unused code" for plain text fields, still used by <isindex>!
+
+        * platform/TextField.h:
+        * platform/mac/TextFieldMac.mm:
+        * platform/mac/WebCoreTextField.h:
+        * platform/mac/WebCoreTextField.mm:
+        * rendering/RenderLineEdit.cpp:
+
 2006-07-09  Darin Adler  <darin@apple.com>
 
         Reviewed by Tim Hatcher.
index f02e97f3764268b0e658cfa9f3df661285a62e20..08a9591c9f7763d65b7ddcd7162ae977fe377058 100644 (file)
@@ -43,7 +43,7 @@ namespace WebCore {
 
 class TextField : public Widget {
 public:
-    enum Type { Password, Search };
+    enum Type { Normal, Password, Search };
 
     TextField(Type);
     ~TextField();
index 055fa5e028f5c8cd2dc8bfcfea89639c6eca9605..59aca0cf3b774089c94abcef318e4a83f7374500 100644 (file)
@@ -59,6 +59,9 @@ TextField::TextField(Type type)
     BEGIN_BLOCK_OBJC_EXCEPTIONS;
     id view = nil;
     switch (type) {
+        case Normal:
+            view = [WebCoreTextField alloc];
+            break;
         case Password:
             view = [WebCoreSecureTextField alloc];
             break;
@@ -67,7 +70,7 @@ TextField::TextField(Type type)
             break;
     }
     ASSERT(view);
-    [view initWithQLineEdit:this];
+    [view initWithWidget:this];
     m_controller = [view controller];
     setView((NSView *)view);
     [view release];
@@ -78,7 +81,7 @@ TextField::TextField(Type type)
 TextField::~TextField()
 {
     BEGIN_BLOCK_OBJC_EXCEPTIONS;
-    [m_controller detachQLineEdit];
+    [m_controller detachWidget];
     END_BLOCK_OBJC_EXCEPTIONS;
 }
 
index 9ce1f507f1e0da1609e56557aaeee42107600c0a..587251ad8b05fb87800747ac6b29edf3266dfe74 100644 (file)
@@ -28,7 +28,6 @@
 namespace WebCore {
     class TextField;
 }
-
 @class WebCoreTextFieldFormatter;
 @protocol WebCoreWidgetHolder;
 
@@ -46,7 +45,7 @@ namespace WebCore {
     NSWritingDirection baseWritingDirection;
 }
 
-- (void)detachQLineEdit;
+- (void)detachWidget;
 
 - (BOOL)hasSelection;
 
@@ -66,6 +65,18 @@ namespace WebCore {
 
 @end
 
+@interface WebCoreTextField : NSTextField <WebCoreWidgetHolder>
+{
+@private
+    WebCoreTextFieldController* controller;
+    BOOL inNextValidKeyView;
+}
+
+- (id)initWithWidget:(WebCore::TextField *)widget;
+- (WebCoreTextFieldController *)controller;
+
+@end
+
 @interface WebCoreSecureTextField : NSSecureTextField <WebCoreWidgetHolder>
 {
 @private
@@ -74,7 +85,7 @@ namespace WebCore {
     BOOL inSetFrameSize;
 }
 
-- (id)initWithQLineEdit:(WebCore::TextField *)widget;
+- (id)initWithWidget:(WebCore::TextField *)widget;
 - (WebCoreTextFieldController *)controller;
 
 @end
@@ -86,7 +97,8 @@ namespace WebCore {
     BOOL inNextValidKeyView;
 }
 
-- (id)initWithQLineEdit:(WebCore::TextField *)widget;
+- (id)initWithWidget:(WebCore::TextField *)widget;
 - (WebCoreTextFieldController *)controller;
 
 @end
+
index 74bce0dbb1a93570eb9f911b98e8d38258d24eaa..9a8cb720e96f28204207ff5e6b6d4a4cae658ce6 100644 (file)
@@ -60,8 +60,10 @@ using namespace HTMLNames;
 - (void)setWantsNotificationForMarkedText:(BOOL)wantsNotification;
 @end
 
-// The two cell subclasses allow us to tell when we get focus without an editor subclass,
+// The three cell subclasses allow us to tell when we get focus without an editor subclass,
 // and override the base writing direction.
+@interface KWQTextFieldCell : NSTextFieldCell
+@end
 @interface WebCoreSecureTextFieldCell : NSSecureTextFieldCell
 @end
 @interface WebCoreSearchFieldCell : NSSearchFieldCell
@@ -116,7 +118,7 @@ using namespace HTMLNames;
     return self;
 }
 
-- (void)detachQLineEdit
+- (void)detachWidget
 {
     widget = 0;
 }
@@ -496,6 +498,186 @@ static DOMHTMLInputElement* inputElement(TextField* widget)
 
 @end
 
+@implementation WebCoreTextField
+
++ (Class)cellClass
+{
+    return [KWQTextFieldCell class];
+}
+
+- (id)initWithWidget:(TextField *)w 
+{
+    self = [self init];
+    if (!self)
+        return nil;
+    controller = [[WebCoreTextFieldController alloc] initWithTextField:self TextField:w];
+    return self;
+}
+
+- (void)dealloc
+{
+    [controller release];
+    [super dealloc];
+}
+
+- (WebCoreTextFieldController *)controller
+{
+    return controller;
+}
+
+- (Widget *)widget
+{
+    return [controller widget];
+}
+
+- (void)selectText:(id)sender
+{
+    // Don't call the NSTextField's selectText if the field is already first responder.
+    // If we do, we'll end up deactivating and then reactivating, which will send
+    // unwanted onBlur events.
+    NSText *editor = [self currentEditor];
+    if (editor) {
+        [editor setSelectedRange:NSMakeRange(0, [[editor string] length])];
+        return;
+    }
+    
+    [super selectText:sender];
+}
+
+- (void)setStringValue:(NSString *)string
+{
+    [super setStringValue:[controller preprocessString:string]];
+    [controller textChanged];
+}
+
+- (NSView *)nextKeyView
+{
+    if (!inNextValidKeyView)
+        return [super nextKeyView];
+    Widget* widget = [controller widget];
+    if (!widget)
+        return [super nextKeyView];
+    return FrameMac::nextKeyViewForWidget(widget, SelectingNext);
+}
+
+- (NSView *)previousKeyView
+{
+    if (!inNextValidKeyView)
+        return [super previousKeyView];
+    Widget* widget = [controller widget];
+    if (!widget)
+        return [super previousKeyView];
+    return FrameMac::nextKeyViewForWidget(widget, SelectingPrevious);
+}
+
+- (NSView *)nextValidKeyView
+{
+    inNextValidKeyView = YES;
+    NSView *view = [super nextValidKeyView];
+    inNextValidKeyView = NO;
+    return view;
+}
+
+- (NSView *)previousValidKeyView
+{
+    inNextValidKeyView = YES;
+    NSView *view = [super previousValidKeyView];
+    inNextValidKeyView = NO;
+    return view;
+}
+
+- (BOOL)acceptsFirstResponder
+{
+    return [self isEnabled];
+}
+
+- (void)display
+{
+    // This is a workaround for Radar 2753974.
+    // Also, in the web page context, it's never OK to just display.
+    [self setNeedsDisplay:YES];
+}
+
+// This is the only one of the display family of calls that we use, and the way we do
+// displaying in WebCore means this is called on this NSView explicitly, so this catches
+// all cases where we are inside the normal display machinery. (Used only by the insertion
+// point method below.)
+- (void)displayRectIgnoringOpacity:(NSRect)rect
+{
+    [controller setInDrawingMachinery:YES];
+    [super displayRectIgnoringOpacity:rect];
+    [controller setInDrawingMachinery:NO];
+}
+
+- (BOOL)textView:(NSTextView *)view shouldDrawInsertionPointInRect:(NSRect)rect color:(NSColor *)color turnedOn:(BOOL)drawInsteadOfErase
+{
+    return [controller textView:view shouldDrawInsertionPointInRect:rect color:color turnedOn:drawInsteadOfErase];
+}
+
+- (BOOL)textView:(NSTextView *)view shouldHandleEvent:(NSEvent *)event
+{
+    return [controller textView:view shouldHandleEvent:event];
+}
+
+- (void)textView:(NSTextView *)view didHandleEvent:(NSEvent *)event
+{
+    [controller textView:view didHandleEvent:event];
+}
+
+- (BOOL)textView:(NSTextView *)view shouldChangeTextInRange:(NSRange)range replacementString:(NSString *)string
+{
+    return [controller textView:view shouldChangeTextInRange:range replacementString:string]
+        && [super textView:view shouldChangeTextInRange:range replacementString:string];
+}
+
+- (void)textViewDidChangeSelection:(NSNotification *)notification
+{
+    [super textViewDidChangeSelection:notification];
+    [controller textViewDidChangeSelection:notification];
+}
+
+- (void)textDidEndEditing:(NSNotification *)notification
+{
+    [controller setHasFocus:NO];
+    [super textDidEndEditing:notification];
+}
+
+@end
+
+@implementation KWQTextFieldCell
+
+- (void)editWithFrame:(NSRect)frame inView:(NSView *)view editor:(NSText *)editor delegate:(id)delegate event:(NSEvent *)event
+{
+    [super editWithFrame:frame inView:view editor:editor delegate:delegate event:event];
+    ASSERT([delegate isKindOfClass:[WebCoreTextField class]]);
+    [[(WebCoreTextField *)delegate controller] setHasFocus:YES];
+}
+
+- (void)selectWithFrame:(NSRect)frame inView:(NSView *)view editor:(NSText *)editor delegate:(id)delegate start:(int)start length:(int)length
+{
+    [super selectWithFrame:frame inView:view editor:editor delegate:delegate start:start length:length];
+    ASSERT([delegate isKindOfClass:[WebCoreTextField class]]);
+    [[(WebCoreTextField *)delegate controller] setHasFocus:YES];
+}
+
+- (NSMutableDictionary *)_textAttributes
+{
+    ASSERT([[self controlView] isKindOfClass:[WebCoreTextField class]]);
+    NSMutableDictionary* attributes = [super _textAttributes];
+    [[(WebCoreTextField*)[self controlView] controller] updateTextAttributes:attributes];
+    return attributes;
+}
+
+// Ignore the per-application typesetter setting and instead always use the latest behavior for
+// text fields in web pages. This fixes the "text fields too tall" problem.
+- (NSTypesetterBehavior)_typesetterBehavior
+{
+    return NSTypesetterLatestBehavior;
+}
+
+@end
+
+
 @implementation WebCoreSecureTextField
 
 + (Class)cellClass
@@ -503,7 +685,7 @@ static DOMHTMLInputElement* inputElement(TextField* widget)
     return [WebCoreSecureTextFieldCell class];
 }
 
-- (id)initWithQLineEdit:(TextField *)w 
+- (id)initWithWidget:(TextField *)w 
 {
     self = [self init];
     if (!self)
@@ -716,7 +898,7 @@ static DOMHTMLInputElement* inputElement(TextField* widget)
     return [WebCoreSearchFieldCell class];
 }
 
-- (id)initWithQLineEdit:(TextField *)w 
+- (id)initWithWidget:(TextField *)w 
 {
     self = [self init];
     if (!self)
index c483ea7e8503ba7d8a5bf28b69716b5233f017f2..86e5bd327a1f96de9e866cb42dfd5677f968599a 100644 (file)
@@ -49,9 +49,12 @@ RenderLineEdit::RenderLineEdit(HTMLInputElement* element)
         case HTMLInputElement::SEARCH:
             type = TextField::Search;
             break;
+        case HTMLInputElement::ISINDEX:
+            type = TextField::Normal;
+            break;
         default:
             ASSERT(false);
-            type = TextField::Search;
+            type = TextField::Normal;
     }
     TextField* edit = new TextField(type);
     if (type == TextField::Search)