LayoutTests:
[WebKit-https.git] / WebCore / bridge / mac / FrameMac.mm
index 64a7a88..ff491ac 100644 (file)
 #import "config.h"
 #import "FrameMac.h"
 
+#import "AXObjectCache.h"
+#import "BeforeUnloadEvent.h"
+#import "BlockExceptions.h"
 #import "BrowserExtensionMac.h"
+#import "CSSComputedStyleDeclaration.h"
 #import "Cache.h"
+#import "ClipboardEvent.h"
 #import "Cursor.h"
 #import "DOMInternal.h"
+#import "DOMWindow.h"
+#import "Decoder.h"
+#import "Event.h"
 #import "EventNames.h"
 #import "FloatRect.h"
 #import "FoundationExtras.h"
 #import "FramePrivate.h"
-#import "FrameView.h"
 #import "GraphicsContext.h"
+#import "HTMLDocument.h"
 #import "HTMLFormElement.h"
+#import "HTMLFrameElement.h"
 #import "HTMLGenericFormElement.h"
-#import "InlineTextBox.h"
-#import "AccessibilityObjectCache.h"
-#import "ClipboardMac.h"
-#import "KWQEditCommand.h"
-#import "BlockExceptions.h"
-#import "KWQFormData.h"
-#import "TransferJob.h"
+#import "HTMLInputElement.h"
+#import "HTMLNames.h"
+#import "HTMLTableCellElement.h"
+#import "WebCoreEditCommand.h"
+#import "FormDataMac.h"
+#import "WebCorePageState.h"
 #import "Logging.h"
-#import "KWQPageState.h"
-#import "RegularExpression.h"
-#import "KWQScrollBar.h"
-#import "TextEncoding.h"
-#import "PlatformKeyboardEvent.h"
-#import "PlatformMouseEvent.h"
 #import "MouseEventWithHitTestResults.h"
+#import "PlatformKeyboardEvent.h"
+#import "PlatformWheelEvent.h"
 #import "Plugin.h"
+#import "RegularExpression.h"
+#import "RenderImage.h"
+#import "RenderListItem.h"
+#import "RenderPart.h"
 #import "RenderTableCell.h"
-#import "SelectionController.h"
-#import "VisiblePosition.h"
+#import "RenderTheme.h"
+#import "RenderView.h"
+#import "TextIterator.h"
+#import "ResourceLoader.h"
 #import "WebCoreFrameBridge.h"
-#import "WebCoreGraphicsBridge.h"
 #import "WebCoreViewFactory.h"
 #import "WebDashboardRegion.h"
-#import "PlatformWheelEvent.h"
-#import "CSSComputedStyleDeclaration.h"
+#import "WebScriptObjectPrivate.h"
 #import "csshelper.h"
-#import "dom2_eventsimpl.h"
-#import "Range.h"
-#import "Position.h"
-#import "HTMLDocument.h"
-#import "html_tableimpl.h"
-#import "kjs_binding.h"
+#import "htmlediting.h"
 #import "kjs_window.h"
-#import "RenderCanvas.h"
-#import "render_frames.h"
-#import "RenderImage.h"
-#import "render_list.h"
-#import "render_style.h"
-#import "RenderTheme.h"
-#import "TextIterator.h"
 #import "visible_units.h"
+#import "WebCoreSystemInterface.h"
+#import <Carbon/Carbon.h>
 #import <JavaScriptCore/NP_jsobject.h>
-#import <JavaScriptCore/WebScriptObjectPrivate.h>
-#import <JavaScriptCore/identifier.h>
-#import <JavaScriptCore/interpreter.h>
 #import <JavaScriptCore/npruntime_impl.h>
-#import <JavaScriptCore/property_map.h>
-#import <JavaScriptCore/runtime.h>
-#import <JavaScriptCore/runtime_root.h>
 
-#undef _KWQ_TIMING
+#undef _webcore_TIMING
 
 @interface NSObject (WebPlugIn)
 - (id)objectForWebScript;
-- (void *)pluginScriptableObject;
+- (NPObject *)createPluginScriptableObject;
 @end
 
-using namespace KJS;
-using namespace Bindings;
+using namespace std;
+using namespace KJS::Bindings;
 
-using namespace KIO;
+using KJS::JSLock;
+using KJS::PausedTimeouts;
+using KJS::SavedBuiltins;
+using KJS::SavedProperties;
 
 namespace WebCore {
 
 using namespace EventNames;
 using namespace HTMLNames;
 
-NSEvent *FrameMac::_currentEvent = nil;
+NSEvent* FrameMac::_currentEvent = nil;
+
+static NSMutableDictionary* createNSDictionary(const HashMap<String, String>& map)
+{
+    NSMutableDictionary* dict = [[NSMutableDictionary alloc] initWithCapacity:map.size()];
+    HashMap<String, String>::const_iterator end = map.end();
+    for (HashMap<String, String>::const_iterator it = map.begin(); it != end; ++it) {
+        NSString* key = it->first;
+        NSString* object = it->second;
+        [dict setObject:object forKey:key];
+    }
+    return dict;
+}
+
+static const unsigned int escChar = 27;
+static SEL selectorForKeyEvent(const PlatformKeyboardEvent* event)
+{
+    // FIXME: This helper function is for the autofill code so the bridge can pass a selector to the form delegate.  
+    // Eventually, we should move all of the autofill code down to WebKit and remove the need for this function by
+    // not relying on the selector in the new implementation.
+    String key = event->unmodifiedText();
+    if (key.length() != 1)
+        return 0;
+
+    SEL selector = NULL;
+    switch (key[0U]) {
+    case NSUpArrowFunctionKey:
+        selector = @selector(moveUp:); break;
+    case NSDownArrowFunctionKey:
+        selector = @selector(moveDown:); break;
+    case escChar:
+        selector = @selector(cancel:); break;
+    case NSTabCharacter:
+        selector = @selector(insertTab:); break;
+    case NSBackTabCharacter:
+        selector = @selector(insertBacktab:); break;
+    case NSNewlineCharacter:
+    case NSCarriageReturnCharacter:
+    case NSEnterCharacter:
+        selector = @selector(insertNewline:); break;
+        break;
+    }
+    return selector;
+}
+
 
 bool FrameView::isFrameView() const
 {
     return true;
 }
 
-FrameMac::FrameMac(Page* page, RenderPart* ownerRenderer)
-    : Frame(page, ownerRenderer)
+FrameMac::FrameMac(Page* page, Element* ownerElement)
+    : Frame(page, ownerElement)
     , _bridge(nil)
     , _mouseDownView(nil)
     , _sendingEventToSubview(false)
     , _mouseDownMayStartDrag(false)
     , _mouseDownMayStartSelect(false)
     , _activationEventNumber(0)
-    , _formValuesAboutToBeSubmitted(nil)
-    , _formAboutToBeSubmitted(nil)
     , _bindingRoot(0)
     , _windowScriptObject(0)
     , _windowScriptNPObject(0)
@@ -136,7 +173,7 @@ FrameMac::~FrameMac()
     clearRecordedFormValues();    
     
     [_bridge clearFrame];
-    KWQRelease(_bridge);
+    HardRelease(_bridge);
     _bridge = nil;
 }
 
@@ -209,7 +246,7 @@ RegularExpression *regExpForLabels(NSArray *labels)
     RegularExpression *result;
     if (!regExpLabels)
         regExpLabels = [[NSMutableArray alloc] initWithCapacity:regExpCacheSize];
-    unsigned int cacheHit = [regExpLabels indexOfObject:labels];
+    CFIndex cacheHit = [regExpLabels indexOfObject:labels];
     if (cacheHit != NSNotFound)
         result = regExps.at(cacheHit);
     else {
@@ -264,16 +301,16 @@ RegularExpression *regExpForLabels(NSArray *labels)
     return result;
 }
 
-NSString *FrameMac::searchForLabelsAboveCell(RegularExpression *regExp, HTMLTableCellElement *cell)
+NSString* FrameMac::searchForLabelsAboveCell(RegularExpression* regExp, HTMLTableCellElement* cell)
 {
-    RenderTableCell *cellRenderer = static_cast<RenderTableCell *>(cell->renderer());
+    RenderTableCell* cellRenderer = static_cast<RenderTableCell*>(cell->renderer());
 
     if (cellRenderer && cellRenderer->isTableCell()) {
-        RenderTableCell *cellAboveRenderer = cellRenderer->table()->cellAbove(cellRenderer);
+        RenderTableCellcellAboveRenderer = cellRenderer->table()->cellAbove(cellRenderer);
 
         if (cellAboveRenderer) {
             HTMLTableCellElement *aboveCell =
-                static_cast<HTMLTableCellElement *>(cellAboveRenderer->element());
+                static_cast<HTMLTableCellElement*>(cellAboveRenderer->element());
 
             if (aboveCell) {
                 // search within the above cell we found for a match
@@ -314,12 +351,12 @@ NSString *FrameMac::searchForLabelsBeforeElement(NSArray *labels, Element *eleme
     {
         if (n->hasTagName(formTag)
             || (n->isHTMLElement()
-                && static_cast<HTMLElement *>(n)->isGenericFormElement()))
+                && static_cast<HTMLElement*>(n)->isGenericFormElement()))
         {
             // We hit another form element or the start of the form - bail out
             break;
         } else if (n->hasTagName(tdTag) && !startingTableCell) {
-            startingTableCell = static_cast<HTMLTableCellElement *>(n);
+            startingTableCell = static_cast<HTMLTableCellElement*>(n);
         } else if (n->hasTagName(trTag) && startingTableCell) {
             NSString *result = searchForLabelsAboveCell(regExp, startingTableCell);
             if (result) {
@@ -380,53 +417,6 @@ NSString *FrameMac::matchLabelsAgainstElement(NSArray *labels, Element *element)
     return nil;
 }
 
-// Searches from the beginning of the document if nothing is selected.
-bool FrameMac::findString(NSString *string, bool forward, bool caseFlag, bool wrapFlag)
-{
-    String target = string;
-    if (target.isEmpty())
-        return false;
-    
-    // Initially search from the start (if forward) or end (if backward) of the selection, and search to edge of document.
-    RefPtr<Range> searchRange(rangeOfContents(document()));
-    if (selection().start().node()) {
-        if (forward)
-            setStart(searchRange.get(), VisiblePosition(selection().start(), selection().affinity()));
-        else
-            setEnd(searchRange.get(), VisiblePosition(selection().end(), selection().affinity()));
-    }
-    RefPtr<Range> resultRange(findPlainText(searchRange.get(), target, forward, caseFlag));
-    
-    // If we re-found the (non-empty) selected range, then search again starting just past the selected range.
-    if (selection().start().node() && *resultRange == *selection().toRange()) {
-        searchRange = rangeOfContents(document());
-        if (forward)
-            setStart(searchRange.get(), VisiblePosition(selection().end(), selection().affinity()));
-        else
-            setEnd(searchRange.get(), VisiblePosition(selection().start(), selection().affinity()));
-        resultRange = findPlainText(searchRange.get(), target, forward, caseFlag);
-    }
-    
-    int exception = 0;
-    
-    // if we didn't find anything and we're wrapping, search again in the entire document (this will
-    // redundantly re-search the area already searched in some cases).
-    if (resultRange->collapsed(exception) && wrapFlag) {
-        searchRange = rangeOfContents(document());
-        resultRange = findPlainText(searchRange.get(), target, forward, caseFlag);
-        // We used to return false here if we ended up with the same range that we started with
-        // (e.g., the selection was already the only instance of this text). But we decided that
-        // this should be a success case instead, so we'll just fall through in that case.
-    }
-
-    if (resultRange->collapsed(exception))
-        return false;
-
-    setSelection(SelectionController(resultRange.get(), DOWNSTREAM));
-    revealSelection();
-    return true;
-}
-
 void FrameMac::submitForm(const ResourceRequest& request)
 {
     BEGIN_BLOCK_OBJC_EXCEPTIONS;
@@ -456,6 +446,9 @@ void FrameMac::submitForm(const ResourceRequest& request)
         d->m_submittedFormURL = request.url();
     }
 
+    ObjCDOMElement* submitForm = [DOMElement _elementWith:d->m_formAboutToBeSubmitted.get()];
+    NSMutableDictionary* formValues = createNSDictionary(d->m_formValuesAboutToBeSubmitted);
+    
     if (!request.doPost()) {
         [_bridge loadURL:request.url().getNSURL()
                 referrer:[_bridge referrer] 
@@ -463,8 +456,8 @@ void FrameMac::submitForm(const ResourceRequest& request)
              userGesture:true
                   target:request.frameName
          triggeringEvent:_currentEvent
-                    form:_formAboutToBeSubmitted
-              formValues:_formValuesAboutToBeSubmitted];
+                    form:submitForm
+              formValues:formValues];
     } else {
         ASSERT(request.contentType().startsWith("Content-Type: "));
         [_bridge postWithURL:request.url().getNSURL()
@@ -473,9 +466,10 @@ void FrameMac::submitForm(const ResourceRequest& request)
                         data:arrayFromFormData(request.postData)
                  contentType:request.contentType().substring(14)
              triggeringEvent:_currentEvent
-                        form:_formAboutToBeSubmitted
-                  formValues:_formValuesAboutToBeSubmitted];
+                        form:submitForm
+                  formValues:formValues];
     }
+    [formValues release];
     clearRecordedFormValues();
 
     END_BLOCK_OBJC_EXCEPTIONS;
@@ -527,29 +521,36 @@ static NSArray* nsArray(const Vector<String>& vector)
     return array;
 }
 
-Plugin* FrameMac::createPlugin(const KURL& url, const Vector<String>& paramNames, const Vector<String>& paramValues, const String& mimeType)
+Plugin* FrameMac::createPlugin(Element* element, const KURL& url, const Vector<String>& paramNames, const Vector<String>& paramValues, const String& mimeType)
 {
     BEGIN_BLOCK_OBJC_EXCEPTIONS;
 
     return new Plugin(new Widget([_bridge viewForPluginWithURL:url.getNSURL()
                                   attributeNames:nsArray(paramNames)
                                   attributeValues:nsArray(paramValues)
-                                  MIMEType:mimeType]));
+                                  MIMEType:mimeType
+                                  DOMElement:(element ? [DOMElement _elementWith:element] : nil)
+                                loadManually:d->m_doc->isPluginDocument()]));
 
     END_BLOCK_OBJC_EXCEPTIONS;
     return 0;
 }
 
+void FrameMac::redirectDataToPlugin(Widget* pluginWidget)
+{
+    [_bridge redirectDataToPlugin:pluginWidget->getView()];
+}
+
 
-Frame* FrameMac::createFrame(const KURL& url, const String& name, RenderPart* renderer, const String& referrer)
+Frame* FrameMac::createFrame(const KURL& url, const String& name, Element* ownerElement, const String& referrer)
 {
     BEGIN_BLOCK_OBJC_EXCEPTIONS;
     
     BOOL allowsScrolling = YES;
     int marginWidth = -1;
     int marginHeight = -1;
-    if (renderer->element()->hasTagName(frameTag) || renderer->element()->hasTagName(iframeTag)) {
-        HTMLFrameElement *o = static_cast<HTMLFrameElement *>(renderer->element());
+    if (ownerElement->hasTagName(frameTag) || ownerElement->hasTagName(iframeTag)) {
+        HTMLFrameElement* o = static_cast<HTMLFrameElement*>(ownerElement);
         allowsScrolling = o->scrollingMode() != ScrollBarAlwaysOff;
         marginWidth = o->getMarginWidth();
         marginHeight = o->getMarginHeight();
@@ -558,7 +559,7 @@ Frame* FrameMac::createFrame(const KURL& url, const String& name, RenderPart* re
     WebCoreFrameBridge *childBridge = [_bridge createChildFrameNamed:name
                                                              withURL:url.getNSURL()
                                                             referrer:referrer 
-                                                          renderPart:renderer
+                                                          ownerElement:ownerElement
                                                      allowsScrolling:allowsScrolling
                                                          marginWidth:marginWidth
                                                         marginHeight:marginHeight];
@@ -581,7 +582,7 @@ void FrameMac::setView(FrameView *view)
     // Delete old PlugIn data structures
     cleanupPluginRootObjects();
     _bindingRoot = 0;
-    KWQRelease(_windowScriptObject);
+    HardRelease(_windowScriptObject);
     _windowScriptObject = 0;
 
     if (_windowScriptNPObject) {
@@ -601,7 +602,7 @@ void FrameMac::setView(FrameView *view)
 void FrameMac::setTitle(const String &title)
 {
     String text = title;
-    text.replace(QChar('\\'), backslashAsCurrencySymbol());
+    text.replace('\\', backslashAsCurrencySymbol());
 
     BEGIN_BLOCK_OBJC_EXCEPTIONS;
     [_bridge setTitle:text];
@@ -611,11 +612,17 @@ void FrameMac::setTitle(const String &title)
 void FrameMac::setStatusBarText(const String& status)
 {
     String text = status;
-    text.replace(QChar('\\'), backslashAsCurrencySymbol());
+    text.replace('\\', backslashAsCurrencySymbol());
     
+    // We want the temporaries allocated here to be released even before returning to the 
+    // event loop; see <http://bugzilla.opendarwin.org/show_bug.cgi?id=9880>.
+    NSAutoreleasePool* localPool = [[NSAutoreleasePool alloc] init];
+
     BEGIN_BLOCK_OBJC_EXCEPTIONS;
     [_bridge setStatusText:text];
     END_BLOCK_OBJC_EXCEPTIONS;
+
+    [localPool release];
 }
 
 void FrameMac::scheduleClose()
@@ -627,10 +634,45 @@ void FrameMac::scheduleClose()
     END_BLOCK_OBJC_EXCEPTIONS;
 }
 
+void FrameMac::focusWindow()
+{
+    BEGIN_BLOCK_OBJC_EXCEPTIONS;
+
+    // If we're a top level window, bring the window to the front.
+    if (!tree()->parent())
+        [_bridge activateWindow];
+
+    // Might not have a view yet: this could be a child frame that has not yet received its first byte of data.
+    // FIXME: Should remember that the frame needs focus.  See <rdar://problem/4645685>.
+    if (d->m_view) {
+        NSView *view = d->m_view->getDocumentView();
+        if ([_bridge firstResponder] != view)
+            [_bridge makeFirstResponder:view];
+    }
+
+    END_BLOCK_OBJC_EXCEPTIONS;
+}
+
 void FrameMac::unfocusWindow()
 {
+    // Might not have a view yet: this could be a child frame that has not yet received its first byte of data.
+    // FIXME: Should remember that the frame needs to unfocus.  See <rdar://problem/4645685>.
+    if (!d->m_view)
+        return;
+
     BEGIN_BLOCK_OBJC_EXCEPTIONS;
-    [_bridge unfocusWindow];
+    NSView *view = d->m_view->getDocumentView();
+    if ([_bridge firstResponder] == view) {
+        // If we're a top level window, deactivate the window.
+        if (!tree()->parent())
+            [_bridge deactivateWindow];
+        else {
+            // We want to shift focus to our parent.
+            FrameMac* parentFrame = static_cast<FrameMac*>(tree()->parent());
+            NSView* parentView = parentFrame->d->m_view->getDocumentView();
+            [parentFrame->bridge() makeFirstResponder:parentView];
+        }
+    }
     END_BLOCK_OBJC_EXCEPTIONS;
 }
 
@@ -643,17 +685,18 @@ String FrameMac::advanceToNextMisspelling(bool startBeforeSelection)
     
     // Start at the end of the selection, search to edge of document.  Starting at the selection end makes
     // repeated "check spelling" commands work.
+    Selection selection(selectionController()->selection());
     RefPtr<Range> searchRange(rangeOfContents(document()));
     bool startedWithSelection = false;
-    if (selection().start().node()) {
+    if (selection.start().node()) {
         startedWithSelection = true;
         if (startBeforeSelection) {
-            VisiblePosition start(selection().start(), selection().affinity());
+            VisiblePosition start(selection.visibleStart());
             // We match AppKit's rule: Start 1 character before the selection.
             VisiblePosition oneBeforeStart = start.previous();
             setStart(searchRange.get(), oneBeforeStart.isNotNull() ? oneBeforeStart : start);
         } else
-            setStart(searchRange.get(), VisiblePosition(selection().end(), selection().affinity()));
+            setStart(searchRange.get(), selection.visibleEnd());
     }
 
     // If we're not in an editable node, try to find one, make that our range to work in
@@ -669,7 +712,7 @@ String FrameMac::advanceToNextMisspelling(bool startBeforeSelection)
     
     // topNode defines the whole range we want to operate on 
     Node *topNode = editableNode->rootEditableElement();
-    searchRange->setEndAfter(topNode, exception);
+    searchRange->setEnd(topNode, maxDeepOffset(topNode), exception);
 
     // Make sure start of searchRange is not in the middle of a word.  Jumping back a char and then
     // forward by a word happens to do the trick.
@@ -699,10 +742,10 @@ String FrameMac::advanceToNextMisspelling(bool startBeforeSelection)
 
     while (1) {
         if (!it.atEnd()) {      // we may be starting at the end of the doc, and already by atEnd
-            const QChar *chars = it.characters();
+            const UChar* chars = it.characters();
             int len = it.length();
-            if (len > 1 || !chars[0].isSpace()) {
-                NSString *chunk = [[NSString alloc] initWithCharactersNoCopy:(unichar *)chars length:len freeWhenDone:NO];
+            if (len > 1 || !DeprecatedChar(chars[0]).isSpace()) {
+                NSString *chunk = [[NSString alloc] initWithCharactersNoCopy:const_cast<UChar*>(chars) length:len freeWhenDone:NO];
                 NSRange misspelling = [checker checkSpellingOfString:chunk startingAt:0 language:nil wrap:NO inSpellDocumentWithTag:[_bridge spellCheckerDocumentTag] wordCount:NULL];
                 [chunk release];
                 if (misspelling.length > 0) {
@@ -715,7 +758,7 @@ String FrameMac::advanceToNextMisspelling(bool startBeforeSelection)
                     DeprecatedString result = chars.string(misspelling.length);
                     misspellingRange->setEnd(chars.range()->startContainer(exception), chars.range()->startOffset(exception), exception);
 
-                    setSelection(SelectionController(misspellingRange.get(), DOWNSTREAM));
+                    selectionController()->setSelection(Selection(misspellingRange.get(), DOWNSTREAM));
                     revealSelection();
                     // Mark misspelling in document.
                     document()->addMarker(misspellingRange.get(), DocumentMarker::Spelling);
@@ -731,7 +774,7 @@ String FrameMac::advanceToNextMisspelling(bool startBeforeSelection)
             } else {
                 // we've gone from the selection to the end of doc, now wrap around
                 wrapped = YES;
-                searchRange->setStartBefore(topNode, exception);
+                searchRange->setStart(topNode, 0, exception);
                 // going until the end of the very first chunk we tested is far enough
                 searchRange->setEnd(searchEndAfterWrapNode, searchEndAfterWrapOffset, exception);
                 it = WordAwareIterator(searchRange.get());
@@ -748,13 +791,13 @@ bool FrameMac::wheelEvent(NSEvent *event)
 
     if (v) {
         NSEvent *oldCurrentEvent = _currentEvent;
-        _currentEvent = KWQRetain(event);
+        _currentEvent = HardRetain(event);
 
         PlatformWheelEvent qEvent(event);
         v->handleWheelEvent(qEvent);
 
         ASSERT(_currentEvent == event);
-        KWQRelease(event);
+        HardRelease(event);
         _currentEvent = oldCurrentEvent;
 
         if (qEvent.isAccepted())
@@ -764,21 +807,21 @@ bool FrameMac::wheelEvent(NSEvent *event)
     // FIXME: The scrolling done here should be done in the default handlers
     // of the elements rather than here in the part.
 
-    KWQScrollDirection direction;
+    ScrollDirection direction;
     float multiplier;
     float deltaX = [event deltaX];
     float deltaY = [event deltaY];
     if (deltaX < 0) {
-        direction = KWQScrollRight;
+        direction = ScrollRight;
         multiplier = -deltaX;
     } else if (deltaX > 0) {
-        direction = KWQScrollLeft;
+        direction = ScrollLeft;
         multiplier = deltaX;
     } else if (deltaY < 0) {
-        direction = KWQScrollDown;
+        direction = ScrollDown;
         multiplier = -deltaY;
     }  else if (deltaY > 0) {
-        direction = KWQScrollUp;
+        direction = ScrollUp;
         multiplier = deltaY;
     } else
         return false;
@@ -799,7 +842,7 @@ bool FrameMac::wheelEvent(NSEvent *event)
     if (!r)
         return false;
     
-    return r->scroll(direction, KWQScrollWheel, multiplier);
+    return r->scroll(direction, ScrollByWheel, multiplier);
 }
 
 void FrameMac::startRedirectionTimer()
@@ -850,56 +893,79 @@ String FrameMac::mimeTypeForFileName(const String& fileName) const
     return String();
 }
 
-NSView *FrameMac::nextKeyViewInFrame(Node *node, KWQSelectionDirection direction)
+NSView* FrameMac::nextKeyViewInFrame(Node* n, SelectionDirection direction, bool* focusCallResultedInViewBeingCreated)
 {
-    Document *doc = document();
+    Documentdoc = document();
     if (!doc)
         return nil;
     
+    RefPtr<Node> node = n;
     for (;;) {
-        node = direction == KWQSelectingNext
-            ? doc->nextFocusNode(node) : doc->previousFocusNode(node);
+        node = direction == SelectingNext
+            ? doc->nextFocusNode(node.get()) : doc->previousFocusNode(node.get());
         if (!node)
             return nil;
         
-        RenderObject *renderer = node->renderer();
-        if (renderer->isWidget()) {
-            RenderWidget *renderWidget = static_cast<RenderWidget *>(renderer);
-            Widget *widget = renderWidget->widget();
-            if (!widget)
+        RenderObject* renderer = node->renderer();
+        
+        if (!renderer->isWidget()) {
+            static_cast<Element*>(node.get())->focus(); 
+            // The call to focus might have triggered event handlers that causes the 
+            // current renderer to be destroyed.
+            if (!(renderer = node->renderer()))
                 continue;
-            
-            FrameView *childFrameWidget = widget->isFrameView() ? static_cast<FrameView *>(widget) : 0;
-            NSView *view = nil;
-            if (childFrameWidget)
-                view = Mac(childFrameWidget->frame())->nextKeyViewInFrame(0, direction);
+                
+            // FIXME: When all input elements are native, we should investigate if this extra check is needed
+            if (!renderer->isWidget()) {
+                [_bridge willMakeFirstResponderForNodeFocus];
+                return [_bridge documentView];
+            } else if (focusCallResultedInViewBeingCreated)
+                *focusCallResultedInViewBeingCreated = true;
+        }
+
+        if (Widget* widget = static_cast<RenderWidget*>(renderer)->widget()) {
+            NSView* view;
+            if (widget->isFrameView())
+                view = Mac(static_cast<FrameView*>(widget)->frame())->nextKeyViewInFrame(0, direction);
             else
                 view = widget->getView();
             if (view)
                 return view;
-        } else
-            static_cast<Element *>(node)->focus(); 
-        [_bridge makeFirstResponder:[_bridge documentView]];
-        return [_bridge documentView];
+        }
     }
 }
 
-NSView *FrameMac::nextKeyViewInFrameHierarchy(Node *node, KWQSelectionDirection direction)
+NSView *FrameMac::nextKeyViewInFrameHierarchy(Node *node, SelectionDirection direction)
 {
-    NSView *next = nextKeyViewInFrame(node, direction);
+    bool focusCallResultedInViewBeingCreated = false;
+    NSView *next = nextKeyViewInFrame(node, direction, &focusCallResultedInViewBeingCreated);
     if (!next)
         if (FrameMac *parent = Mac(tree()->parent()))
             next = parent->nextKeyViewInFrameHierarchy(ownerElement(), direction);
     
     // remove focus from currently focused node if we're giving focus to another view
-    if (next && (next != [_bridge documentView]))
+    // unless the other view was created as a result of calling focus in nextKeyViewWithFrame.
+    // FIXME: The focusCallResultedInViewBeingCreated calls can be removed when all input element types
+    // have been made native.
+    if (next && (next != [_bridge documentView] && !focusCallResultedInViewBeingCreated))
         if (Document *doc = document())
             doc->setFocusNode(0);
+
+    // The common case where a view was created is when an <input> element changed from native 
+    // to non-native. When this happens, HTMLGenericFormElement::attach() method will call setFocus()
+    // on the widget. For views with a field editor, setFocus() will set the active responder to be the field editor. 
+    // In this case, we want to return the field editor as the next key view. Otherwise, the focus will be lost
+    // and a blur message will be sent. 
+    // FIXME: This code can be removed when all input element types are native.
+    if (focusCallResultedInViewBeingCreated) {
+        if ([[next window] firstResponder] == [[next window] fieldEditor:NO forObject:next])
+            return [[next window] fieldEditor:NO forObject:next];
+    }
     
     return next;
 }
 
-NSView *FrameMac::nextKeyView(Node *node, KWQSelectionDirection direction)
+NSView *FrameMac::nextKeyView(Node *node, SelectionDirection direction)
 {
     NSView * next;
     BEGIN_BLOCK_OBJC_EXCEPTIONS;
@@ -910,7 +976,7 @@ NSView *FrameMac::nextKeyView(Node *node, KWQSelectionDirection direction)
 
     // Look at views from the top level part up, looking for a next key view that we can use.
 
-    next = direction == KWQSelectingNext
+    next = direction == SelectingNext
         ? [_bridge nextKeyViewOutsideWebFrameViews]
         : [_bridge previousKeyViewOutsideWebFrameViews];
 
@@ -923,7 +989,7 @@ NSView *FrameMac::nextKeyView(Node *node, KWQSelectionDirection direction)
     return nextKeyViewInFrameHierarchy(0, direction);
 }
 
-NSView *FrameMac::nextKeyViewForWidget(Widget *startingWidget, KWQSelectionDirection direction)
+NSView *FrameMac::nextKeyViewForWidget(Widget *startingWidget, SelectionDirection direction)
 {
     // Use the event filter object to figure out which RenderWidget owns this Widget and get to the DOM.
     // Then get the next key view in the order determined by the DOM.
@@ -1023,6 +1089,9 @@ bool FrameMac::tabsToAllControls() const
 
 KJS::Bindings::RootObject *FrameMac::executionContextForDOM()
 {
+    if (!jScriptEnabled())
+        return 0;
+
     return bindingRootObject();
 }
 
@@ -1048,7 +1117,7 @@ WebScriptObject *FrameMac::windowScriptObject()
     if (!_windowScriptObject) {
         KJS::JSLock lock;
         KJS::JSObject *win = KJS::Window::retrieveWindow(this);
-        _windowScriptObject = KWQRetainNSRelease([[WebScriptObject alloc] _initWithJSObject:win originExecutionContext:bindingRootObject() executionContext:bindingRootObject()]);
+        _windowScriptObject = HardRetainWithNSRelease([[WebScriptObject alloc] _initWithJSObject:win originExecutionContext:bindingRootObject() executionContext:bindingRootObject()]);
     }
 
     return _windowScriptObject;
@@ -1079,10 +1148,10 @@ void FrameMac::partClearedInBegin()
         [_bridge windowObjectCleared];
 }
 
-void FrameMac::openURLFromPageCache(KWQPageState *state)
+void FrameMac::openURLFromPageCache(WebCorePageState *state)
 {
-    // It's safe to assume none of the KWQPageState methods will raise
-    // exceptions, since KWQPageState is implemented by WebCore and
+    // It's safe to assume none of the WebCorePageState methods will raise
+    // exceptions, since WebCorePageState is implemented by WebCore and
     // does not throw
 
     Document *doc = [state document];
@@ -1198,7 +1267,7 @@ String FrameMac::incomingReferrer() const
 void FrameMac::runJavaScriptAlert(const String& message)
 {
     String text = message;
-    text.replace(QChar('\\'), backslashAsCurrencySymbol());
+    text.replace('\\', backslashAsCurrencySymbol());
     BEGIN_BLOCK_OBJC_EXCEPTIONS;
     [_bridge runJavaScriptAlertPanelWithMessage:text];
     END_BLOCK_OBJC_EXCEPTIONS;
@@ -1207,7 +1276,7 @@ void FrameMac::runJavaScriptAlert(const String& message)
 bool FrameMac::runJavaScriptConfirm(const String& message)
 {
     String text = message;
-    text.replace(QChar('\\'), backslashAsCurrencySymbol());
+    text.replace('\\', backslashAsCurrencySymbol());
 
     BEGIN_BLOCK_OBJC_EXCEPTIONS;
     return [_bridge runJavaScriptConfirmPanelWithMessage:text];
@@ -1219,9 +1288,9 @@ bool FrameMac::runJavaScriptConfirm(const String& message)
 bool FrameMac::runJavaScriptPrompt(const String& prompt, const String& defaultValue, String& result)
 {
     String promptText = prompt;
-    promptText.replace(QChar('\\'), backslashAsCurrencySymbol());
+    promptText.replace('\\', backslashAsCurrencySymbol());
     String defaultValueText = defaultValue;
-    defaultValueText.replace(QChar('\\'), backslashAsCurrencySymbol());
+    defaultValueText.replace('\\', backslashAsCurrencySymbol());
 
     bool ok;
     BEGIN_BLOCK_OBJC_EXCEPTIONS;
@@ -1232,7 +1301,7 @@ bool FrameMac::runJavaScriptPrompt(const String& prompt, const String& defaultVa
 
     if (ok) {
         result = String(returnedText);
-        result.replace(backslashAsCurrencySymbol(), QChar('\\'));
+        result.replace(backslashAsCurrencySymbol(), '\\');
     }
 
     return ok;
@@ -1241,6 +1310,15 @@ bool FrameMac::runJavaScriptPrompt(const String& prompt, const String& defaultVa
     return false;
 }
 
+bool FrameMac::shouldInterruptJavaScript()
+{
+    BEGIN_BLOCK_OBJC_EXCEPTIONS;
+    return [_bridge shouldInterruptJavaScript];
+    END_BLOCK_OBJC_EXCEPTIONS;
+    
+    return false;
+}
+
 bool FrameMac::locationbarVisible()
 {
     return [_bridge areToolbarsVisible];
@@ -1319,7 +1397,7 @@ bool FrameMac::keyEvent(NSEvent *event)
     }
 
     NSEvent *oldCurrentEvent = _currentEvent;
-    _currentEvent = KWQRetain(event);
+    _currentEvent = HardRetain(event);
 
     PlatformKeyboardEvent qEvent(event);
     result = !EventTargetNodeCast(node)->dispatchKeyEvent(qEvent);
@@ -1335,7 +1413,7 @@ bool FrameMac::keyEvent(NSEvent *event)
     }
 
     ASSERT(_currentEvent == event);
-    KWQRelease(event);
+    HardRelease(event);
     _currentEvent = oldCurrentEvent;
 
     return result;
@@ -1351,12 +1429,12 @@ void FrameMac::handleMousePressEvent(const MouseEventWithHitTestResults& event)
 
     // If we got the event back, that must mean it wasn't prevented,
     // so it's allowed to start a drag or selection.
-    _mouseDownMayStartSelect = canMouseDownStartSelect(event.innerNode());
+    _mouseDownMayStartSelect = canMouseDownStartSelect(event.targetNode());
     
     // Careful that the drag starting logic stays in sync with eventMayStartDrag()
     _mouseDownMayStartDrag = singleClick;
 
-    d->m_mousePressNode = event.innerNode();
+    d->m_mousePressNode = event.targetNode();
     
     if (!passWidgetMouseDownEventToWidget(event, false)) {
         // We don't do this at the start of mouse down handling (before calling into WebCore),
@@ -1399,13 +1477,17 @@ bool FrameMac::passMouseDownEventToWidget(Widget* widget)
         // In the case where we just became first responder, we should send the mouseDown:
         // to the NSTextField, not the NSTextField's editor. This code makes sure that happens.
         // If we don't do this, we see a flash of selected text when clicking in a text field.
-        if (![_bridge wasFirstResponderAtMouseDownTime:view] && [view isKindOfClass:[NSTextView class]]) {
+        // FIXME: This is the only caller of textViewWasFirstResponderAtMouseDownTime. When we
+        // eliminate all use of NSTextField/NSTextView in form fields we can eliminate this code,
+        // and textViewWasFirstResponderAtMouseDownTime:, and the instance variable WebHTMLView
+        // keeps solely to support textViewWasFirstResponderAtMouseDownTime:.
+        if ([view isKindOfClass:[NSTextView class]] && ![_bridge textViewWasFirstResponderAtMouseDownTime:(NSTextView *)view]) {
             NSView *superview = view;
             while (superview != nodeView) {
                 superview = [superview superview];
                 ASSERT(superview);
                 if ([superview isKindOfClass:[NSControl class]]) {
-                    NSControl *control = static_cast<NSControl *>(superview);
+                    NSControl *control = static_cast<NSControl*>(superview);
                     if ([control currentEditor] == view) {
                         view = superview;
                     }
@@ -1644,7 +1726,7 @@ void FrameMac::handleMouseMoveEvent(const MouseEventWithHitTestResults& event)
                         _dragClipboard->setDragImageElement(_dragSrc.get(), IntPoint() + delta);
                     } 
 
-                    _mouseDownMayStartDrag = dispatchDragSrcEvent(dragstartEvent, m_mouseDown);
+                    _mouseDownMayStartDrag = dispatchDragSrcEvent(dragstartEvent, m_mouseDown) && mayCopy();
                     // Invalidate clipboard here against anymore pasteboard writing for security.  The drag
                     // image can still be changed as we drag, but not the pasteboard data.
                     _dragClipboard->setAccessPolicy(ClipboardMac::ImageWritable);
@@ -1671,7 +1753,7 @@ void FrameMac::handleMouseMoveEvent(const MouseEventWithHitTestResults& event)
                     BOOL startedDrag = [_bridge startDraggingImage:dragImage at:dragLoc operation:srcOp event:_currentEvent sourceIsDHTML:_dragSrcIsDHTML DHTMLWroteData:wcWrotePasteboard];
                     if (!startedDrag && _dragSrcMayBeDHTML) {
                         // WebKit canned the drag at the last minute - we owe _dragSrc a DRAGEND event
-                        PlatformMouseEvent event;
+                        PlatformMouseEvent event(PlatformMouseEvent::currentEvent);
                         dispatchDragSrcEvent(dragendEvent, event);
                         _mouseDownMayStartDrag = false;
                     }
@@ -1695,7 +1777,7 @@ void FrameMac::handleMouseMoveEvent(const MouseEventWithHitTestResults& event)
         _mouseDownMayStartDrag = false;
         d->m_view->invalidateClick();
 
-        Node* node = event.innerNode();
+        Node* node = event.targetNode();
         RenderLayer* layer = 0;
         if (node && node->renderer())
             layer = node->renderer()->enclosingLayer();
@@ -1706,8 +1788,11 @@ void FrameMac::handleMouseMoveEvent(const MouseEventWithHitTestResults& event)
             layer = layer->parent();
         if (layer)
             handleAutoscroll(layer);
-        else
+        else {
+            if (!d->m_autoscrollTimer.isActive())
+                startAutoscrollTimer();
             [_bridge handleAutoscrollForMouseDragged:_currentEvent];
+        }
             
     } else {
         // If we allowed the other side of the bridge to handle a drag
@@ -1726,12 +1811,14 @@ void FrameMac::handleMouseMoveEvent(const MouseEventWithHitTestResults& event)
 // the event handler NOT setting the return value to false
 bool FrameMac::dispatchCPPEvent(const AtomicString &eventType, ClipboardMac::AccessPolicy policy)
 {
-    Node* target = d->m_selection.start().element();
+    Node* target = selectionController()->start().element();
     if (!target && document())
         target = document()->body();
     if (!target)
         return true;
-
+    if (target->isShadowNode())
+        target = target->shadowParentNode();
+    
     RefPtr<ClipboardMac> clipboard = new ClipboardMac(false, [NSPasteboard generalPasteboard], (ClipboardMac::AccessPolicy)policy);
 
     ExceptionCode ec = 0;
@@ -1750,23 +1837,26 @@ bool FrameMac::dispatchCPPEvent(const AtomicString &eventType, ClipboardMac::Acc
 // We need to use onbeforecopy as a real menu enabler because we allow elements that are not
 // normally selectable to implement copy/paste (like divs, or a document body).
 
-bool FrameMac::mayCut()
+bool FrameMac::mayDHTMLCut()
 {
-    return !dispatchCPPEvent(beforecutEvent, ClipboardMac::Numb);
+    return mayCopy() && !dispatchCPPEvent(beforecutEvent, ClipboardMac::Numb);
 }
 
-bool FrameMac::mayCopy()
+bool FrameMac::mayDHTMLCopy()
 {
-    return !dispatchCPPEvent(beforecopyEvent, ClipboardMac::Numb);
+    return mayCopy() && !dispatchCPPEvent(beforecopyEvent, ClipboardMac::Numb);
 }
 
-bool FrameMac::mayPaste()
+bool FrameMac::mayDHTMLPaste()
 {
     return !dispatchCPPEvent(beforepasteEvent, ClipboardMac::Numb);
 }
 
-bool FrameMac::tryCut()
+bool FrameMac::tryDHTMLCut()
 {
+    if (!mayCopy())
+        return false;
+
     // Must be done before oncut adds types and data to the pboard,
     // also done for security, as it erases data from the last copy/paste.
     [[NSPasteboard generalPasteboard] declareTypes:[NSArray array] owner:nil];
@@ -1774,8 +1864,11 @@ bool FrameMac::tryCut()
     return !dispatchCPPEvent(cutEvent, ClipboardMac::Writable);
 }
 
-bool FrameMac::tryCopy()
+bool FrameMac::tryDHTMLCopy()
 {
+    if (!mayCopy())
+        return false;
+
     // Must be done before oncopy adds types and data to the pboard,
     // also done for security, as it erases data from the last copy/paste.
     [[NSPasteboard generalPasteboard] declareTypes:[NSArray array] owner:nil];
@@ -1783,7 +1876,7 @@ bool FrameMac::tryCopy()
     return !dispatchCPPEvent(copyEvent, ClipboardMac::Writable);
 }
 
-bool FrameMac::tryPaste()
+bool FrameMac::tryDHTMLPaste()
 {
     return !dispatchCPPEvent(pasteEvent, ClipboardMac::Readable);
 }
@@ -1822,7 +1915,7 @@ bool FrameMac::passSubframeEventToSubframe(MouseEventWithHitTestResults& event,
         }
         
         case NSLeftMouseDown: {
-            Node *node = event.innerNode();
+            Node *node = event.targetNode();
             if (!node) {
                 return false;
             }
@@ -1830,10 +1923,10 @@ bool FrameMac::passSubframeEventToSubframe(MouseEventWithHitTestResults& event,
             if (!renderer || !renderer->isWidget()) {
                 return false;
             }
-            Widget *widget = static_cast<RenderWidget *>(renderer)->widget();
+            Widget *widget = static_cast<RenderWidget*>(renderer)->widget();
             if (!widget || !widget->isFrameView())
                 return false;
-            if (!passWidgetMouseDownEventToWidget(static_cast<RenderWidget *>(renderer))) {
+            if (!passWidgetMouseDownEventToWidget(static_cast<RenderWidget*>(renderer))) {
                 return false;
             }
             _mouseDownWasInSubframe = true;
@@ -1885,7 +1978,7 @@ bool FrameMac::passWheelEventToChildWidget(Node *node)
         RenderObject *renderer = node->renderer();
         if (!renderer || !renderer->isWidget())
             return false;
-        Widget *widget = static_cast<RenderWidget *>(renderer)->widget();
+        Widget *widget = static_cast<RenderWidget*>(renderer)->widget();
         if (!widget)
             return false;
             
@@ -1919,7 +2012,7 @@ void FrameMac::mouseDown(NSEvent *event)
     _dragSrc = 0;
     
     NSEvent *oldCurrentEvent = _currentEvent;
-    _currentEvent = KWQRetain(event);
+    _currentEvent = HardRetain(event);
     m_mouseDown = PlatformMouseEvent(event);
     NSPoint loc = [event locationInWindow];
     m_mouseDownPos = d->m_view->viewportToContents(IntPoint(loc));
@@ -1931,7 +2024,7 @@ void FrameMac::mouseDown(NSEvent *event)
     v->handleMousePressEvent(event);
     
     ASSERT(_currentEvent == event);
-    KWQRelease(event);
+    HardRelease(event);
     _currentEvent = oldCurrentEvent;
 
     END_BLOCK_OBJC_EXCEPTIONS;
@@ -1947,12 +2040,12 @@ void FrameMac::mouseDragged(NSEvent *event)
     BEGIN_BLOCK_OBJC_EXCEPTIONS;
 
     NSEvent *oldCurrentEvent = _currentEvent;
-    _currentEvent = KWQRetain(event);
+    _currentEvent = HardRetain(event);
 
     v->handleMouseMoveEvent(event);
     
     ASSERT(_currentEvent == event);
-    KWQRelease(event);
+    HardRelease(event);
     _currentEvent = oldCurrentEvent;
 
     END_BLOCK_OBJC_EXCEPTIONS;
@@ -1967,7 +2060,7 @@ void FrameMac::mouseUp(NSEvent *event)
     BEGIN_BLOCK_OBJC_EXCEPTIONS;
 
     NSEvent *oldCurrentEvent = _currentEvent;
-    _currentEvent = KWQRetain(event);
+    _currentEvent = HardRetain(event);
 
     // Our behavior here is a little different that Qt. Qt always sends
     // a mouse release event, even for a double click. To correct problems
@@ -1983,7 +2076,7 @@ void FrameMac::mouseUp(NSEvent *event)
         v->handleMouseReleaseEvent(event);
     
     ASSERT(_currentEvent == event);
-    KWQRelease(event);
+    HardRelease(event);
     _currentEvent = oldCurrentEvent;
     
     _mouseDownView = nil;
@@ -2063,18 +2156,18 @@ void FrameMac::mouseMoved(NSEvent *event)
     BEGIN_BLOCK_OBJC_EXCEPTIONS;
 
     NSEvent *oldCurrentEvent = _currentEvent;
-    _currentEvent = KWQRetain(event);
+    _currentEvent = HardRetain(event);
     
     v->handleMouseMoveEvent(event);
     
     ASSERT(_currentEvent == event);
-    KWQRelease(event);
+    HardRelease(event);
     _currentEvent = oldCurrentEvent;
 
     END_BLOCK_OBJC_EXCEPTIONS;
 }
 
-// Called as we walk up the element chain for nodes with CSS property -khtml-user-drag == auto
+// Called as we walk up the element chain for nodes with CSS property -webkit-user-drag == auto
 bool FrameMac::shouldDragAutoNode(Node* node, const IntPoint& point) const
 {
     // We assume that WebKit only cares about dragging things that can be leaf nodes (text, images, urls).
@@ -2099,22 +2192,23 @@ bool FrameMac::sendContextMenuEvent(NSEvent *event)
     BEGIN_BLOCK_OBJC_EXCEPTIONS;
 
     NSEvent *oldCurrentEvent = _currentEvent;
-    _currentEvent = KWQRetain(event);
+    _currentEvent = HardRetain(event);
     
     PlatformMouseEvent mouseEvent(event);
 
     IntPoint viewportPos = v->viewportToContents(mouseEvent.pos());
     MouseEventWithHitTestResults mev = doc->prepareMouseEvent(false, true, false, viewportPos, mouseEvent);
 
-    swallowEvent = v->dispatchMouseEvent(contextmenuEvent, mev.innerNode(), true, 0, mouseEvent, true);
+    swallowEvent = v->dispatchMouseEvent(contextmenuEvent, mev.targetNode(), true, 0, mouseEvent, true);
     if (!swallowEvent && !isPointInsideSelection(viewportPos) &&
-        ([_bridge selectWordBeforeMenuEvent] || [_bridge isEditable] || mev.innerNode()->isContentEditable())) {
+            ([_bridge selectWordBeforeMenuEvent] || [_bridge isEditable]
+                || (mev.targetNode() && mev.targetNode()->isContentEditable()))) {
         _mouseDownMayStartSelect = true; // context menu events are always allowed to perform a selection
-        selectClosestWordFromMouseEvent(mouseEvent, mev.innerNode());
+        selectClosestWordFromMouseEvent(mouseEvent, mev.targetNode());
     }
 
     ASSERT(_currentEvent == event);
-    KWQRelease(event);
+    HardRelease(event);
     _currentEvent = oldCurrentEvent;
 
     return swallowEvent;
@@ -2140,7 +2234,7 @@ NSFileWrapper *FrameMac::fileWrapperForElement(Element *e)
         wrapper = [_bridge fileWrapperForURL:URL];
     }    
     if (!wrapper) {
-        RenderImage *renderer = static_cast<RenderImage *>(e->renderer());
+        RenderImage *renderer = static_cast<RenderImage*>(e->renderer());
         if (renderer->cachedImage() && !renderer->cachedImage()->isErrorImage()) {
             wrapper = [[NSFileWrapper alloc] initRegularFileWithContents:(NSData*)(renderer->cachedImage()->image()->getTIFFRepresentation())];
             [wrapper setPreferredFilename:@"image.tiff"];
@@ -2158,7 +2252,7 @@ NSFileWrapper *FrameMac::fileWrapperForElement(Element *e)
 static Element *listParent(Element *item)
 {
     while (!item->hasTagName(ulTag) && !item->hasTagName(olTag)) {
-        item = static_cast<Element *>(item->parentNode());
+        item = static_cast<Element*>(item->parentNode());
         if (!item)
             break;
     }
@@ -2252,7 +2346,7 @@ NSAttributedString *FrameMac::attributedString(Node *_start, int startOffset, No
                         text += str.mid(runStart, runEnd-runStart);
                         [pendingStyledSpace release];
                         pendingStyledSpace = nil;
-                        addedSpace = str[runEnd-1].direction() == QChar::DirWS;
+                        addedSpace = u_charDirection(str[runEnd - 1].unicode()) == U_WHITE_SPACE_NEUTRAL;
                     }
                     else {
                         RenderText* textObj = static_cast<RenderText*>(renderer);
@@ -2267,7 +2361,7 @@ NSAttributedString *FrameMac::attributedString(Node *_start, int startOffset, No
                             for (InlineTextBox* box = textObj->firstTextBox(); box; box = box->nextTextBox()) {
                                 int runStart = (start == -1) ? box->m_start : start;
                                 int runEnd = (end == -1) ? box->m_start + box->m_len : end;
-                                runEnd = kMin(runEnd, box->m_start + box->m_len);
+                                runEnd = min(runEnd, box->m_start + box->m_len);
                                 if (runStart >= box->m_start &&
                                     runStart < box->m_start + box->m_len) {
                                     if (box == textObj->firstTextBox() && box->m_start == runStart && runStart > 0)
@@ -2287,7 +2381,7 @@ NSAttributedString *FrameMac::attributedString(Node *_start, int startOffset, No
                                     needSpace = nextRunStart > runEnd;
                                     [pendingStyledSpace release];
                                     pendingStyledSpace = nil;
-                                    addedSpace = str[runEnd-1].direction() == QChar::DirWS;
+                                    addedSpace = u_charDirection(str[runEnd - 1].unicode()) == U_WHITE_SPACE_NEUTRAL;
                                     start = -1;
                                 }
                                 if (end != -1 && runEnd >= end)
@@ -2297,7 +2391,7 @@ NSAttributedString *FrameMac::attributedString(Node *_start, int startOffset, No
                     }
                 }
                 
-                text.replace(QChar('\\'), renderer->backslashAsCurrencySymbol());
+                text.replace('\\', renderer->backslashAsCurrencySymbol());
     
                 if (text.length() > 0 || needSpace) {
                     NSMutableDictionary *attrs = [[NSMutableDictionary alloc] init];
@@ -2335,7 +2429,7 @@ NSAttributedString *FrameMac::attributedString(Node *_start, int startOffset, No
                     hasNewLine = true;
                 } else if (n->hasTagName(liTag)) {
                     DeprecatedString listText;
-                    Element *itemParent = listParent(static_cast<Element *>(n));
+                    Element *itemParent = listParent(static_cast<Element*>(n));
                     
                     if (!hasNewLine)
                         listText += '\n';
@@ -2348,18 +2442,18 @@ NSAttributedString *FrameMac::attributedString(Node *_start, int startOffset, No
                     
                     listText += '\t';
                     if (itemParent && renderer->isListItem()) {
-                        RenderListItem *listRenderer = static_cast<RenderListItem*>(renderer);
+                        RenderListItemlistRenderer = static_cast<RenderListItem*>(renderer);
 
                         maxMarkerWidth = MAX([font pointSize], maxMarkerWidth);
                         switch(style->listStyleType()) {
                             case DISC:
-                                listText += ((QChar)BULLET_CHAR);
+                                listText += ((DeprecatedChar)BULLET_CHAR);
                                 break;
                             case CIRCLE:
-                                listText += ((QChar)CIRCLE_CHAR);
+                                listText += ((DeprecatedChar)CIRCLE_CHAR);
                                 break;
                             case SQUARE:
-                                listText += ((QChar)SQUARE_CHAR);
+                                listText += ((DeprecatedChar)SQUARE_CHAR);
                                 break;
                             case LNONE:
                                 break;
@@ -2434,7 +2528,7 @@ NSAttributedString *FrameMac::attributedString(Node *_start, int startOffset, No
                         [pendingStyledSpace release];
                         pendingStyledSpace = nil;
                     }
-                    NSFileWrapper *fileWrapper = fileWrapperForElement(static_cast<Element *>(n));
+                    NSFileWrapper *fileWrapper = fileWrapperForElement(static_cast<Element*>(n));
                     NSTextAttachment *attachment = [[NSTextAttachment alloc] initWithFileWrapper:fileWrapper];
                     NSAttributedString *iString = [NSAttributedString attributedStringWithAttachment:attachment];
                     [result appendAttributedString: iString];
@@ -2612,6 +2706,13 @@ NSImage *FrameMac::imageFromRect(NSRect rect) const
     BEGIN_BLOCK_OBJC_EXCEPTIONS;
     
     NSRect bounds = [view bounds];
+    
+    // Round image rect size in window coordinate space to avoid pixel cracks at HiDPI (4622794)
+    rect = [view convertRect:rect toView:nil];
+    rect.size.height = roundf(rect.size.height);
+    rect.size.width = roundf(rect.size.width);
+    rect = [view convertRect:rect fromView:nil];
+    
     resultImage = [[[NSImage alloc] initWithSize:rect.size] autorelease];
 
     if (rect.size.width != 0 && rect.size.height != 0) {
@@ -2636,11 +2737,11 @@ NSImage *FrameMac::imageFromRect(NSRect rect) const
     return nil;
 }
 
-NSImage *FrameMac::selectionImage() const
+NSImage* FrameMac::selectionImage(bool forceWhiteText) const
 {
-    d->m_drawSelectionOnly = true;  // invoke special drawing mode
+    d->m_paintRestriction = forceWhiteText ? PaintRestrictionSelectionOnlyWhiteText : PaintRestrictionSelectionOnly;
     NSImage *result = imageFromRect(visibleSelectionRect());
-    d->m_drawSelectionOnly = false;
+    d->m_paintRestriction = PaintRestrictionNone;
     return result;
 }
 
@@ -2674,7 +2775,7 @@ NSFont *FrameMac::fontForSelection(bool *hasMultipleFonts) const
     if (hasMultipleFonts)
         *hasMultipleFonts = false;
 
-    if (!d->m_selection.isRange()) {
+    if (!selectionController()->isRange()) {
         Node *nodeToRemove;
         RenderStyle *style = styleForSelectionStart(nodeToRemove); // sets nodeToRemove
 
@@ -2693,7 +2794,7 @@ NSFont *FrameMac::fontForSelection(bool *hasMultipleFonts) const
 
     NSFont *font = nil;
 
-    RefPtr<Range> range = d->m_selection.toRange();
+    RefPtr<Range> range = selectionController()->toRange();
     Node *startNode = range->editingStartPosition().node();
     if (startNode != nil) {
         Node *pastEnd = range->pastEndNode();
@@ -2787,7 +2888,7 @@ NSWritingDirection FrameMac::baseWritingDirectionForSelectionStart() const
 {
     NSWritingDirection result = NSWritingDirectionLeftToRight;
 
-    Position pos = VisiblePosition(d->m_selection.start(), d->m_selection.affinity()).deepEquivalent();
+    Position pos = selectionController()->selection().visibleStart().deepEquivalent();
     Node *node = pos.node();
     if (!node || !node->renderer() || !node->renderer()->containingBlock())
         return result;
@@ -2819,8 +2920,8 @@ void FrameMac::setBridge(WebCoreFrameBridge *bridge)
     if (_bridge == bridge)
         return;
 
-    KWQRetain(bridge);
-    KWQRelease(_bridge);
+    HardRetain(bridge);
+    HardRelease(_bridge);
     _bridge = bridge;
 }
 
@@ -2832,24 +2933,6 @@ String FrameMac::overrideMediaType() const
     return String();
 }
 
-void FrameMac::setDisplaysWithFocusAttributes(bool flag)
-{
-    if (d->m_isFocused == flag)
-        return;
-    
-    Frame::setDisplaysWithFocusAttributes(flag);
-    Document *doc = document();
-    // Mac Specific: Changing the tint of controls from clear to aqua/graphite and vice versa.  We
-    // do a "fake" paint.  When the theme gets a paint call, it can then do an invalidate.
-    if (doc && d->m_view && d->m_view->getDocumentView() && theme()->supportsControlTints() && renderer()) {
-        doc->updateLayout(); // Ensure layout is up to date.
-        IntRect visibleRect(enclosingIntRect(d->m_view->visibleContentRect()));
-        GraphicsContext p;
-        p.setUpdatingControlTints(true);
-        paint(&p, visibleRect);
-    }
-}
-
 NSColor *FrameMac::bodyBackgroundColor() const
 {
     if (document() && document()->body() && document()->body()->renderer()) {
@@ -2924,11 +3007,16 @@ static KJS::Bindings::Instance *getInstanceForView(NSView *aView)
             return KJS::Bindings::Instance::createBindingForLanguageInstance (KJS::Bindings::Instance::ObjectiveCLanguage, object, executionContext);
         }
     }
-    else if ([aView respondsToSelector:@selector(pluginScriptableObject)]){
-        void *object = [aView pluginScriptableObject];
+    else if ([aView respondsToSelector:@selector(createPluginScriptableObject)]) {
+        NPObject *object = [aView createPluginScriptableObject];
         if (object) {
-            KJS::Bindings::RootObject *executionContext = KJS::Bindings::RootObject::findRootObjectForNativeHandleFunction ()(aView);
-            return KJS::Bindings::Instance::createBindingForLanguageInstance (KJS::Bindings::Instance::CLanguage, object, executionContext);
+            KJS::Bindings::RootObject *executionContext = KJS::Bindings::RootObject::findRootObjectForNativeHandleFunction()(aView);
+            KJS::Bindings::Instance *instance = KJS::Bindings::Instance::createBindingForLanguageInstance(KJS::Bindings::Instance::CLanguage, object, executionContext);
+            
+            // -createPluginScriptableObject returns a retained NPObject.  The caller is expected to release it.
+            _NPN_ReleaseObject(object);
+            
+            return instance;
         }
     }
     return 0;
@@ -2959,32 +3047,45 @@ void FrameMac::cleanupPluginRootObjects()
     m_rootObjects.clear();
 }
 
-void FrameMac::registerCommandForUndoOrRedo(const EditCommandPtr &cmd, bool isRedo)
+void FrameMac::registerCommandForUndoOrRedo(PassRefPtr<EditCommand> cmd, bool isRedo)
 {
-    ASSERT(cmd.get());
-    KWQEditCommand *kwq = [KWQEditCommand commandWithEditCommand:cmd.get()];
-    NSUndoManager *undoManager = [_bridge undoManager];
-    [undoManager registerUndoWithTarget:_bridge selector:(isRedo ? @selector(redoEditing:) : @selector(undoEditing:)) object:kwq];
-    NSString *actionName = [_bridge nameForUndoAction:static_cast<WebUndoAction>(cmd.editingAction())];
+    ASSERT(cmd);
+    WebUndoAction action = static_cast<WebUndoAction>(cmd->editingAction());
+    NSUndoManager* undoManager = [_bridge undoManager];
+    WebCoreEditCommand* command = [WebCoreEditCommand commandWithEditCommand:cmd];
+    NSString* actionName = [_bridge nameForUndoAction:action];
+    [undoManager registerUndoWithTarget:_bridge selector:(isRedo ? @selector(redoEditing:) : @selector(undoEditing:)) object:command];
     if (actionName)
         [undoManager setActionName:actionName];
     _haveUndoRedoOperations = YES;
 }
 
-void FrameMac::registerCommandForUndo(const EditCommandPtr &cmd)
+void FrameMac::registerCommandForUndo(PassRefPtr<EditCommand> cmd)
 {
-    registerCommandForUndoOrRedo(cmd, NO);
+    registerCommandForUndoOrRedo(cmd, false);
 }
 
-void FrameMac::registerCommandForRedo(const EditCommandPtr &cmd)
+void FrameMac::registerCommandForRedo(PassRefPtr<EditCommand> cmd)
 {
-    registerCommandForUndoOrRedo(cmd, YES);
+    registerCommandForUndoOrRedo(cmd, true);
 }
 
 void FrameMac::clearUndoRedoOperations()
 {
     if (_haveUndoRedoOperations) {
-        [[_bridge undoManager] removeAllActionsWithTarget:_bridge];
+        // workaround for <rdar://problem/4645507> NSUndoManager dies
+        // with uncaught exception when undo items cleared while
+        // groups are open
+        NSUndoManager *undoManager = [_bridge undoManager];
+        int groupingLevel = [undoManager groupingLevel];
+        for (int i = 0; i < groupingLevel; ++i)
+            [undoManager endUndoGrouping];
+        
+        [undoManager removeAllActionsWithTarget:_bridge];
+
+        for (int i = 0; i < groupingLevel; ++i)
+            [undoManager beginUndoGrouping];
+
         _haveUndoRedoOperations = NO;
     }
 }
@@ -3045,10 +3146,10 @@ void FrameMac::markMisspellingsInAdjacentWords(const VisiblePosition &p)
 {
     if (![_bridge isContinuousSpellCheckingEnabled])
         return;
-    markMisspellings(SelectionController(startOfWord(p, LeftWordIfOnBoundary), endOfWord(p, RightWordIfOnBoundary)));
+    markMisspellings(Selection(startOfWord(p, LeftWordIfOnBoundary), endOfWord(p, RightWordIfOnBoundary)));
 }
 
-void FrameMac::markMisspellings(const SelectionController &selection)
+void FrameMac::markMisspellings(const Selectionselection)
 {
     // This function is called with a selection already expanded to word boundaries.
     // Might be nice to assert that here.
@@ -3074,10 +3175,10 @@ void FrameMac::markMisspellings(const SelectionController &selection)
     WordAwareIterator it(searchRange.get());
     
     while (!it.atEnd()) {      // we may be starting at the end of the doc, and already by atEnd
-        const QChar *chars = it.characters();
+        const UChar* chars = it.characters();
         int len = it.length();
-        if (len > 1 || !chars[0].isSpace()) {
-            NSString *chunk = [[NSString alloc] initWithCharactersNoCopy:(unichar *)chars length:len freeWhenDone:NO];
+        if (len > 1 || !DeprecatedChar(chars[0]).isSpace()) {
+            NSString *chunk = [[NSString alloc] initWithCharactersNoCopy:const_cast<UChar*>(chars) length:len freeWhenDone:NO];
             int startIndex = 0;
             // Loop over the chunk to find each misspelling in it.
             while (startIndex < len) {
@@ -3105,38 +3206,29 @@ void FrameMac::markMisspellings(const SelectionController &selection)
     }
 }
 
-void FrameMac::respondToChangedSelection(const SelectionController &oldSelection, bool closeTyping)
+void FrameMac::respondToChangedSelection(const Selection &oldSelection, bool closeTyping)
 {
     if (document()) {
         if ([_bridge isContinuousSpellCheckingEnabled]) {
-            SelectionController oldAdjacentWords = SelectionController();
+            Selection oldAdjacentWords;
             
             // If this is a change in selection resulting from a delete operation, oldSelection may no longer
             // be in the document.
             if (oldSelection.start().node() && oldSelection.start().node()->inDocument()) {
-                VisiblePosition oldStart(oldSelection.start(), oldSelection.affinity());
-                oldAdjacentWords = SelectionController(startOfWord(oldStart, LeftWordIfOnBoundary), endOfWord(oldStart, RightWordIfOnBoundary));   
+                VisiblePosition oldStart(oldSelection.visibleStart());
+                oldAdjacentWords = Selection(startOfWord(oldStart, LeftWordIfOnBoundary), endOfWord(oldStart, RightWordIfOnBoundary));   
             }
 
-            VisiblePosition newStart(selection().start(), selection().affinity());
-            SelectionController newAdjacentWords(startOfWord(newStart, LeftWordIfOnBoundary), endOfWord(newStart, RightWordIfOnBoundary));
+            VisiblePosition newStart(selectionController()->selection().visibleStart());
+            Selection newAdjacentWords(startOfWord(newStart, LeftWordIfOnBoundary), endOfWord(newStart, RightWordIfOnBoundary));
 
-            if (oldAdjacentWords != newAdjacentWords) {
-                // Mark misspellings in the portion that was previously unmarked because of
-                // the proximity of the start of the selection. We only spell check words in
-                // the vicinity of the start of the old selection because the spelling checker
-                // is not fast enough to do a lot of spelling checking implicitly. This matches
-                // AppKit. This function is really the only code that knows that rule. The
-                // markMisspellings function is prepared to handler larger ranges.
+            // When typing we check spelling elsewhere, so don't redo it here.
+            if (closeTyping && oldAdjacentWords != newAdjacentWords)
+                markMisspellings(oldAdjacentWords);
 
-                // When typing we check spelling elsewhere, so don't redo it here.
-                if (closeTyping)
-                    markMisspellings(oldAdjacentWords);
-
-                // This only erases a marker in the first word of the selection.
-                // Perhaps peculiar, but it matches AppKit.
-                document()->removeMarkers(newAdjacentWords.toRange().get(), DocumentMarker::Spelling);
-            }
+            // This only erases a marker in the first word of the selection.
+            // Perhaps peculiar, but it matches AppKit.
+            document()->removeMarkers(newAdjacentWords.toRange().get(), DocumentMarker::Spelling);
         } else
             // When continuous spell checking is off, no markers appear after the selection changes.
             document()->removeMarkers(DocumentMarker::Spelling);
@@ -3145,7 +3237,7 @@ void FrameMac::respondToChangedSelection(const SelectionController &oldSelection
     [_bridge respondToChangedSelection];
 }
 
-bool FrameMac::shouldChangeSelection(const SelectionController &oldSelection, const SelectionController &newSelection, EAffinity affinity, bool stillSelecting) const
+bool FrameMac::shouldChangeSelection(const Selection& oldSelection, const Selection& newSelection, EAffinity affinity, bool stillSelecting) const
 {
     return [_bridge shouldChangeSelectedDOMRange:[DOMRange _rangeWith:oldSelection.toRange().get()]
                                       toDOMRange:[DOMRange _rangeWith:newSelection.toRange().get()]
@@ -3153,10 +3245,18 @@ bool FrameMac::shouldChangeSelection(const SelectionController &oldSelection, co
                                   stillSelecting:stillSelecting];
 }
 
-void FrameMac::respondToChangedContents()
+bool FrameMac::shouldDeleteSelection(const Selection& selection) const
+{
+    return [_bridge shouldDeleteSelectedDOMRange:[DOMRange _rangeWith:selection.toRange().get()]];
+}
+
+void FrameMac::respondToChangedContents(const Selection& selection)
 {
-    if (AccessibilityObjectCache::accessibilityEnabled())
-        renderer()->document()->getAccObjectCache()->postNotificationToTopWebArea(renderer(), "AXValueChanged");
+    if (AXObjectCache::accessibilityEnabled()) {
+        Node* node = selection.start().node();
+        if (node)
+            renderer()->document()->axObjectCache()->postNotification(node->renderer(), "AXValueChanged");
+    }
     [_bridge respondToChangedContents];
 }
 
@@ -3168,13 +3268,13 @@ bool FrameMac::isContentEditable() const
 bool FrameMac::shouldBeginEditing(const Range *range) const
 {
     ASSERT(range);
-    return [_bridge shouldBeginEditing:[DOMRange _rangeWith:const_cast<Range *>(range)]];
+    return [_bridge shouldBeginEditing:[DOMRange _rangeWith:const_cast<Range*>(range)]];
 }
 
 bool FrameMac::shouldEndEditing(const Range *range) const
 {
     ASSERT(range);
-    return [_bridge shouldEndEditing:[DOMRange _rangeWith:const_cast<Range *>(range)]];
+    return [_bridge shouldEndEditing:[DOMRange _rangeWith:const_cast<Range*>(range)]];
 }
 
 void FrameMac::didBeginEditing() const
@@ -3187,6 +3287,80 @@ void FrameMac::didEndEditing() const
     [_bridge didEndEditing];
 }
 
+void FrameMac::textFieldDidBeginEditing(Element* input)
+{
+    BEGIN_BLOCK_OBJC_EXCEPTIONS;
+    [_bridge textFieldDidBeginEditing:(DOMHTMLInputElement *)[DOMElement _elementWith:input]];
+    END_BLOCK_OBJC_EXCEPTIONS;
+}
+
+void FrameMac::textFieldDidEndEditing(Element* input)
+{
+    BEGIN_BLOCK_OBJC_EXCEPTIONS;
+    [_bridge textFieldDidEndEditing:(DOMHTMLInputElement *)[DOMElement _elementWith:input]];
+    END_BLOCK_OBJC_EXCEPTIONS;
+}
+
+void FrameMac::textDidChangeInTextField(Element* input)
+{
+    BEGIN_BLOCK_OBJC_EXCEPTIONS;
+    [_bridge textDidChangeInTextField:(DOMHTMLInputElement *)[DOMElement _elementWith:input]];
+    END_BLOCK_OBJC_EXCEPTIONS;
+}
+
+void FrameMac::textDidChangeInTextArea(Element* textarea)
+{
+    BEGIN_BLOCK_OBJC_EXCEPTIONS;
+    [_bridge textDidChangeInTextArea:(DOMHTMLTextAreaElement *)[DOMElement _elementWith:textarea]];
+    END_BLOCK_OBJC_EXCEPTIONS;
+}
+
+bool FrameMac::doTextFieldCommandFromEvent(Element* input, const PlatformKeyboardEvent* event)
+{
+    // FIXME: We might eventually need to make sure key bindings for editing work even with
+    // events created with the DOM API. Those don't have a PlatformKeyboardEvent.
+    if (!event)
+        return false;
+
+    BEGIN_BLOCK_OBJC_EXCEPTIONS;
+    return [_bridge textField:(DOMHTMLInputElement *)[DOMElement _elementWith:input] doCommandBySelector:selectorForKeyEvent(event)];
+    END_BLOCK_OBJC_EXCEPTIONS;
+    return false;
+}
+
+void FrameMac::textWillBeDeletedInTextField(Element* input)
+{
+    // We're using the deleteBackward selector for all deletion operations since the autofill code treats all deletions the same way.
+    BEGIN_BLOCK_OBJC_EXCEPTIONS;
+    [_bridge textField:(DOMHTMLInputElement *)[DOMElement _elementWith:input] doCommandBySelector:@selector(deleteBackward:)];
+    END_BLOCK_OBJC_EXCEPTIONS;
+}
+
+bool FrameMac::inputManagerHasMarkedText() const
+{
+    BEGIN_BLOCK_OBJC_EXCEPTIONS;
+    return [[NSInputManager currentInputManager] hasMarkedText];
+    END_BLOCK_OBJC_EXCEPTIONS
+    return false;
+}
+
+const short enableRomanKeyboardsOnly = -23;
+void FrameMac::setSecureKeyboardEntry(bool enable)
+{
+    if (enable) {
+        EnableSecureEventInput();
+        KeyScript(enableRomanKeyboardsOnly);
+    } else {
+        DisableSecureEventInput();
+        KeyScript(smKeyEnableKybds);
+    }
+}
+
+bool FrameMac::isSecureKeyboardEntry()
+{
+    return IsSecureEventInputEnabled();
+}
+
 static DeprecatedValueList<MarkedTextUnderline> convertAttributesToUnderlines(const Range *markedTextRange, NSArray *attributes, NSArray *ranges)
 {
     DeprecatedValueList<MarkedTextUnderline> result;
@@ -3242,7 +3416,7 @@ void FrameMac::setMarkedTextRange(const Range *range, NSArray *attributes, NSArr
     if (range && range->collapsed(exception))
         m_markedTextRange = 0;
     else
-        m_markedTextRange = const_cast<Range *>(range);
+        m_markedTextRange = const_cast<Range*>(range);
 
     if (m_markedTextRange.get() && document() && m_markedTextRange->startContainer(exception)->renderer())
         m_markedTextRange->startContainer(exception)->renderer()->repaint();
@@ -3300,7 +3474,7 @@ void FrameMac::dashboardRegionsChanged()
     [_bridge dashboardRegionsChanged:webRegions];
 }
 
-bool FrameMac::isCharacterSmartReplaceExempt(const QChar &c, bool isPreviousChar)
+bool FrameMac::isCharacterSmartReplaceExempt(const DeprecatedChar &c, bool isPreviousChar)
 {
     return [_bridge isCharacterSmartReplaceExempt:c.unicode() isPreviousCharacter:isPreviousChar];
 }
@@ -3334,7 +3508,7 @@ bool FrameMac::shouldClose()
         return true;
 
     String text = event->result();
-    text.replace(QChar('\\'), backslashAsCurrencySymbol());
+    text.replace('\\', backslashAsCurrencySymbol());
 
     return [_bridge runBeforeUnloadConfirmPanelWithMessage:text];
 
@@ -3373,4 +3547,14 @@ void Frame::setNeedsReapplyStyles()
     [Mac(this)->bridge() setNeedsReapplyStyles];
 }
 
+FloatRect FrameMac::customHighlightLineRect(const AtomicString& type, const FloatRect& lineRect)
+{
+    return [bridge() customHighlightRect:type forLine:lineRect];
+}
+
+void FrameMac::paintCustomHighlight(const AtomicString& type, const FloatRect& boxRect, const FloatRect& lineRect, bool text, bool line)
+{
+    [bridge() paintCustomHighlight:type forBox:boxRect onLine:lineRect behindText:text entireLine:line];
+}
+
 }