<rdar://problem/5344848> IME is incorrectly used for key events when on non-editable regions

Adding a new EditorClient method so it is possible to inform WebKit of focus changes.
Also added new virtual method Node::shouldUseInputMethod to allow us to trivially check
whether an input method should be used when processing input for the currently focused
Node.

Fixed <rdar://problem/5420682> Mail crashes at WebCore::InsertLineBreakCommand::doApply() after dropping a selected image over container's close box

editing/DeleteButtonController.cpp:
(WebCore::DeleteButtonController::show):
Factored out the code in ::show() that created and styled the elements of the Deletion UI

(WebCore::DeleteButtonController::createDeletionUI):
Neglecting to move the append of the deletionUI elements into the same clause that handles the creation
of them ended up creating multiple elements at were repeatedly appended to the target, resulting in a
bloated table deletion UI which was slow to show and hide.

editing/DeleteButtonController.h:
(WebCore::DeleteButtonController::enabled):
Restore this function to how it used to be pre-r25305, sans asserts

If the plug-in or one of its children have focus, set it to NULL to prevent the web view window from getting the focus,
which can cause a layout to happen while in HTMLObjectElement::detach. (This is what we do on the Mac).

Fix for <rdar://problem/5450600> REGRESSION: can't paste in textfield if its in a body that has user-select:none set (affects widgets)

Test: editing/pasteboard/paste-plaintext-user-select-none.html

editing/ReplaceSelectionCommand.cpp: (WebCore::ReplacementFragment::insertFragmentForTestRendering):
Copy the user-select style from the current selection node and apply it so it is considered during the test rendering.
This is important since we recently changed user-select to be inherited. When we consider valid VisiblePositions for the test rendering,
we need to have the correct user-select value that will actually be used for the real insertion.

LayoutTests:

Reviewed by Justin.

Test for <rdar://problem/5450600> REGRESSION: can't paste in textfield if its in a body that has user-select:none set (affects widgets)

editing/htmlediting.cpp: (WebCore::avoidIntersectionWithNode):
Change assertion so that it only fires when actually modifying the selection.
This isn't nearly as helpful, because the old assertion could catch potential
problems in more cases, but it's not obvious how to do better.

editing/ReplaceSelectionCommand.cpp:
(WebCore::ReplaceSelectionCommand::doApply): Use a default block element when creating
new paragraphs, so that empty paragraphs don't contain the block style of the previous
one.
Don't expand collapsed brs at the end of inserted content, this was the root of the bug.
We'd copy <blockquote>hello<br></blockquote><br class="Apple-interchange-newline">
and get an extra paragraph. The removed code used to make sure that if the copied
selection ends with a paragraph break that is represented in the copied markup by a
regular br (not an interchange newline br), that that paragraph break appears in the
pasted content, but shouldMergeEnd, which was introduced after this code was written,
now takes care of that.
(WebCore::ReplaceSelectionCommand::shouldRemoveEndBR): Inserted content should always
displace placeholder brs, even if that inserted content ends with a br.

editing/markup.cpp:
(WebCore::needInterchangeNewlineAfter): This code failed to add an interchange newline
if the user copied <div>hello</div><br>, only don't add an interchange newline when
copying hello<br><br>, because then the copied paragraph break will already be
represented in the copied markup by a br.
(WebCore::createMarkup):

LayoutTests:

Reviewed by Darin.

<rdar://problem/5368833>
REGRESSION: Pasting a triple-clicked line of quoted text at the top of a message adds an extra, quoted line

<rdar://problem/5439953> REGRESSION: Cannot load feeds in widgets in Dashcode due to change in WebKit delegate methods

WebView/WebFrame.mm:
(-[WebFrame _attachScriptDebugger]): Don't create the debugger object if the frame has not yet
created its script interpreter, to avoid premature dispatch of windowScriptObjectAvailable/Cleared
delegate methods. The script debugger will be created in any case when the window object does appear.

rendering/RenderText.cpp: (WebCore::RenderText::checkConsistency):
Put the actual consistency check inside an ifdef. If you need it you can
turn it on. There's still some function call overhead in builds that don't
have NDEBUG defined, but that's worth it so we can turn this on and off
without recompiling the world.

small code style improvement to recently changed function

editing/TextIterator.cpp: (WebCore::plainTextToMallocAllocatedBuffer):
Use a typedef and make_pair to make the code dealing with the pair simpler to read.

Misc/WebNSPasteboardExtras.h: Got rid of the global data objects and replaced
them with global functions.

Misc/WebNSPasteboardExtras.mm:
(initializePasteboardTypes): Changed the initialize method to be this function.
(WebURLPasteboardType): Added, calls the initialize function and then returns
the value of the global.
(WebURLNamePasteboardType): Ditto.
(+[NSPasteboard _web_writableTypesForURL]): Changed to call the new function instead
of getting at the global directly.
(+[NSPasteboard _web_dragTypesForURL]): Ditto.
(-[NSPasteboard _web_writeURL:andTitle:types:]): Ditto.

WebView/WebView.mm:
(+[WebView initialize]): Added a call to one of the functions to take advantage
of the side effect that initializes the globals; this is to help out old versions
of Safari.
(+[WebView URLTitleFromPasteboard:]): Changed to call the new function instead
of getting at the global directly.

If new nodes have been added or style recalc has been done with style sheets still pending, some nodes
may not have had their real style calculated yet. Normally this state gets cleaned when style sheets arrive
but in updateLayoutIgnorePendingStylesheets() we need to do full style recalc to get up-to-date style immediatly.

Added a document flag to track if there are any nodes that did not have their real style calculated due to
pending stylesheets.

We disable the DeleteButton UI before applying any editing commands.
This patch simply moves those disable/enable calls to a more correct place, closer to the actual application of the editing command.

editing/DeleteButtonController.h:
(WebCore::DeleteButtonController::enabled):
General changes made to DeleteButtonController: when hiding, it's not necessary to clear out
the m_containerElement and m_target, especially since to fix this bug we need to keep
their values around. It's sufficient to just detach the container from target.

editing/EditCommand.cpp:
(WebCore::EditCommand::EditCommand):
Move the selection out of the deletion UI since we don't want to expose the deletion UI to any editing.

editing/Editor.cpp:
(WebCore::Editor::rangeForPoint):
Move the range out of the deletion UI since we don't want to expose the deletion UI to any editing.

editing/htmlediting.cpp:

editing/htmlediting.h:
(WebCore::avoidIntersectionWithNode):
Moved function that operates on Range from markup.cpp to here
Added new implementation for function that operates on Selection

editing/markup.cpp:
(WebCore::createMarkup):
Moved function out of this file to htmlediting.cpp, and renamed to avoidIntersectionWithNode

The method that was swizzled to fix 5441281 does not exist on Tiger.
Tiger has to do a double swizzle instead (of resetCursorRects and NSCursor's
set method) in order to roughly achieve the same effect.

Fix for 5441281, remove our dependency on cursor rects and drag margins
in AppKit for a large performance boost on the PLT and iBench.

Reviewed by darin

platform/mac/WidgetMac.mm:
(WebCore::safeRemoveFromSuperview):
(WebCore::Widget::addToSuperview):
Suppress the resetting of drag margins when views are added and removed.

(WebCore::Widget::setCursor):
Just use NSCursor's set method to immediately set the cursor. We no longer
rely on NSScrollView/NSClipView setDocumentCursor, since that is implemented
using cursor rects.

WebKit:

Fix for 5441281, remove our dependency on cursor rects and drag margins
in AppKit for a large performance boost on the PLT and iBench.

WebView/WebFrameView.mm:
(-[WebFrameView _setDocumentView:]):
Suppress the resetting of drag margins while the new document view is being
added to the view hierarchy.

WebView/WebHTMLView.mm:
(-[NSWindow _web_borderView]):
Expose the border view of the NSWindow so that it can be hit tested.

(setCursorForMouseLocation):
Apply a method swizzle to override the private AppKit method, _setCursorForMouseLocation.
We have to do this to suppress the cursor rect invalidation handling from resetting
the cursor for no reason.

The swizzle will do a hit test and allow the cursor set to occur if the mouse ends up
being over a plugin or over a view other than a WebHTMLView.

(+[WebHTMLViewPrivate initialize]):
The swizzle for setCursorForMouseLocation is set up here.

(-[WebHTMLView _frameOrBoundsChanged]):
Add a 100ms delay to the fake mouse moved event that fires when the view moves
under the mouse (without the mouse moving). This happens on iBench when the
pages get scrolled. By adding a delay we ensure that even with the mouse inside
the window, we don't experience cursor thrashing when pages are updating and
scrolling rapidly.

fix ​http://bugs.webkit.org/show_bug.cgi?id=15104
Don't double-compensate for sizeof(unsigned) when making a buffer
overflow check in the GIF decoder. Now interlaced GIFs don't
sometimes get nothing/garbage in some of the bottom rows.

Fix fallout from the fix for <rdar://problem/5437983> (Loading history containing 100,000 entries adds 20s to Safari's startup)
in r25275. The array of entries for each day was being maintained in the reverse of the order that was expected.

<rdar://problem/5415006> Command Left in a To Do causes caret to disappear

The selection was ending up inside non-editable content at the To Do Options
arrow image, rather then at the editable position just to the left of that image.
The problem was that startPositionForLine looked only at line boxes, and there
is no linebox for the editable position at the far left of a To Do, which is
a table. Addressed by having startPositionForLine use table offset 0 instead
of the first VisiblePosition inside the table.

Found and fixed the similar case with option-left (move by word position).

Move WebHistoryItemPrivate from using a sorted array of NSCalendarDate's that map to a sorted array of arrays
of WebHistoryItem's over to using a HashMap of NSTimeIntervals and arrays of WebHistoryItems. NSTimeInterval
uses less memory and is substantially cheaper during comparisons than NSCalendarDate. The use of the HashMap
avoids the needs to repeatedly search within an array to locate the array that corresponds to the given days
history items.

The result of these changes is that loading 100,000 history items drops from around 25s to 1.6s. Loading
100 items drops from 0.003s to 0.002s.

History/WebHistory.mm:
(-[WebHistoryPrivate init]):
(-[WebHistoryPrivate dealloc]):
(timeIntervalForBeginningOfDay): Return the NSTimeInterval representing the beginning of the specified day.
(-[WebHistoryPrivate findKey:forDay:]):
(-[WebHistoryPrivate insertItem:forDateKey:]): Perform a binary search within the day's history items rather than a linear search.
(-[WebHistoryPrivate _removeItemFromDateCaches:]):
(-[WebHistoryPrivate _addItemToDateCaches:]):
(-[WebHistoryPrivate removeAllItems]):
(-[WebHistoryPrivate orderedLastVisitedDays]): Generate and cache the sorted NSArray of NSCalendarDate's exposed in the API.
This cache is invalidated by _removeItemFromDateCaches: and _addItemToDateCaches: when needed.
(-[WebHistoryPrivate orderedItemsLastVisitedOnDay:]):
(-[WebHistoryPrivate arrayRepresentation]):
(-[WebHistoryPrivate _loadHistoryGutsFromURL:savedItemsCount:collectDiscardedItemsInto:error:]): Use an autorelease pool to keep the
number of live autoreleased objects generated to a reasonable level.

History/WebHistoryItem.mm:
(-[WebHistoryItem initWithURLString:title:displayTitle:lastVisitedTimeInterval:]):
(-[WebHistoryItem initFromDictionaryRepresentation:]): Use the new HistoryItem constructor that accepts the alternate title
rather than setting it after construction. This prevents a modification notification from being sent for each WebHistoryItem that is loaded.

History/WebHistoryItemInternal.h:

History/WebHistoryPrivate.h:

Misc/WebNSCalendarDateExtras.h: Removed as _webkit_compareDay: is no longer used.

Add a new constructor for HistoryItem that initializes the alternate title. This prevents WebHistoryItem
in WebKit from having explicitly set the display title, which triggers a history item changed notification
to be posted, for each history item loaded.

WebURLResponse.cpp:
(WebURLResponse::QueryInterface):
(WebURLResponse::sslPeerCertificate): gets peer certificate context from CFNetwork
(WebURLResponse::certificateDictionary): gets the dictionary that contains SSL certificate
info from CFNetwork. We retain the dictionary to ensure the certificate context is valid
throughout the lifetime of the WebURLResponse.