Commit 1f3e63cb authored by beidson@apple.com's avatar beidson@apple.com

WebCore:

2008-03-28  Brady Eidson  <beidson@apple.com>

        Reviewed by Darin Adler

        More Kit->Core WebArchive changes.

        Create an archive from the current selection in a frame

        * WebCore.base.exp:

        * loader/archive/cf/LegacyWebArchive.cpp:
        (WebCore::LegacyWebArchive::createFromSelection):
        * loader/archive/cf/LegacyWebArchive.h:

WebKit/mac:

2008-03-28  Brady Eidson  <beidson@apple.com>

        Reviewed by Darin Adler

        More Kit->Core WebArchive changes.

        Create an archive from the current selection in a frame

        * WebView/WebArchiver.mm: Remove one more *undeclared* method, the last method will drop off
          easily in a followup



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@31419 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent ed7c928d
2008-03-28 Brady Eidson <beidson@apple.com>
Reviewed by Darin Adler
More Kit->Core WebArchive changes.
Create an archive from the current selection in a frame
* WebCore.base.exp:
* loader/archive/cf/LegacyWebArchive.cpp:
(WebCore::LegacyWebArchive::createFromSelection):
* loader/archive/cf/LegacyWebArchive.h:
2008-03-28 Kevin McCullough <kmccullough@apple.com>
- Somehow managed to duplicate code :(
......@@ -338,6 +338,7 @@ __ZN7WebCore15StringTruncator5widthERKNS_6StringERKNS_4FontEb
__ZN7WebCore15VisiblePositionC1ERKNS_8PositionENS_9EAffinityE
__ZN7WebCore16FontPlatformDataC1EP6NSFontbb
__ZN7WebCore16FontPlatformDataD1Ev
__ZN7WebCore16LegacyWebArchive19createFromSelectionEPNS_5FrameE
__ZN7WebCore16LegacyWebArchive21rawDataRepresentationEv
__ZN7WebCore16LegacyWebArchive6createEN3WTF10PassRefPtrINS_15ArchiveResourceEEERNS1_6VectorIS4_Lm0EEERNS5_INS2_IS0_EELm0EEE
__ZN7WebCore16LegacyWebArchive6createEPNS_12SharedBufferE
......
......@@ -42,6 +42,7 @@
#include "markup.h"
#include "Node.h"
#include "Range.h"
#include "SelectionController.h"
#include "SharedBuffer.h"
#include <wtf/RetainPtr.h>
......@@ -525,4 +526,34 @@ PassRefPtr<LegacyWebArchive> LegacyWebArchive::create(const String& markupString
return create(mainResource, subresources, subframeArchives);
}
PassRefPtr<LegacyWebArchive> LegacyWebArchive::createFromSelection(Frame* frame)
{
if (!frame)
return 0;
RefPtr<Range> selectionRange = frame->selectionController()->toRange();
Vector<Node*> nodeList;
String markupString = frame->documentTypeString() + createMarkup(selectionRange.get(), &nodeList, AnnotateForInterchange);
RefPtr<LegacyWebArchive> archive = create(markupString, frame, nodeList);
if (!frame->isFrameSet())
return archive.release();
// Wrap the frameset document in an iframe so it can be pasted into
// another document (which will have a body or frameset of its own).
String iframeMarkup = String::format("<iframe frameborder=\"no\" marginwidth=\"0\" marginheight=\"0\" width=\"98%%\" height=\"98%%\" src=\"%s\"></iframe>",
frame->loader()->documentLoader()->response().url().string().utf8().data());
RefPtr<ArchiveResource> iframeResource = ArchiveResource::create(utf8Buffer(iframeMarkup), blankURL(), "text/html", "UTF-8", String());
Vector<PassRefPtr<ArchiveResource> > subresources;
Vector<PassRefPtr<LegacyWebArchive> > subframeArchives;
subframeArchives.append(archive);
archive = LegacyWebArchive::create(iframeResource.release(), subresources, subframeArchives);
return archive.release();
}
}
......@@ -46,6 +46,7 @@ public:
static PassRefPtr<LegacyWebArchive> create(PassRefPtr<ArchiveResource> mainResource, Vector<PassRefPtr<ArchiveResource> >& subresources, Vector<PassRefPtr<LegacyWebArchive> >& subframeArchives);
static PassRefPtr<LegacyWebArchive> create(Node*);
static PassRefPtr<LegacyWebArchive> create(Frame*);
static PassRefPtr<LegacyWebArchive> createFromSelection(Frame* frame);
static PassRefPtr<LegacyWebArchive> create(Range*);
static PassRefPtr<LegacyWebArchive> create(const String& markupString, Frame*, Vector<Node*>& nodes);
......
2008-03-28 Brady Eidson <beidson@apple.com>
Reviewed by Darin Adler
More Kit->Core WebArchive changes.
Create an archive from the current selection in a frame
* WebView/WebArchiver.mm: Remove one more *undeclared* method, the last method will drop off
easily in a followup
2008-03-28 Brady Eidson <beidson@apple.com>
Reviewed by Sam Weinig
......
......@@ -47,47 +47,9 @@ using namespace WebCore;
@implementation WebArchiver
+ (WebArchive *)_archiveWithMarkupString:(NSString *)markupString fromFrame:(WebFrame *)frame nodes:(NSArray *)nodes
{
Vector<Node*> coreNodes;
unsigned count = [nodes count];
coreNodes.reserveCapacity(count);
for (unsigned i = 0; i < count; ++i)
coreNodes.append([[nodes objectAtIndex:i] _node]);
return [[[WebArchive alloc] _initWithCoreLegacyWebArchive:LegacyWebArchive::create(markupString, core(frame), coreNodes)] autorelease];
}
+ (WebArchive *)archiveSelectionInFrame:(WebFrame *)frame
{
Frame* coreFrame = core(frame);
if (!coreFrame)
return nil;
NSArray *nodes;
NSString *markupString = [frame _markupStringFromRange:kit(coreFrame->selectionController()->toRange().get()) nodes:&nodes];
WebArchive *archive = [self _archiveWithMarkupString:markupString fromFrame:frame nodes:nodes];
if (coreFrame->isFrameSet()) {
// Wrap the frameset document in an iframe so it can be pasted into
// another document (which will have a body or frameset of its own).
NSString *iframeMarkup = [[NSString alloc] initWithFormat:@"<iframe frameborder=\"no\" marginwidth=\"0\" marginheight=\"0\" width=\"98%%\" height=\"98%%\" src=\"%@\"></iframe>", [[[frame _dataSource] response] URL]];
WebResource *iframeResource = [[WebResource alloc] initWithData:[iframeMarkup dataUsingEncoding:NSUTF8StringEncoding]
URL:blankURL()
MIMEType:@"text/html"
textEncodingName:@"UTF-8"
frameName:nil];
NSArray *subframeArchives = [NSArray arrayWithObject:archive];
archive = [[[WebArchive alloc] initWithMainResource:iframeResource subresources:nil subframeArchives:subframeArchives] autorelease];
[iframeResource release];
[iframeMarkup release];
}
return archive;
return [[[WebArchive alloc] _initWithCoreLegacyWebArchive:LegacyWebArchive::createFromSelection(core(frame))] autorelease];
}
@end
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment