OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2007, 2009, 2010 Apple Inc. All rights reserved. | 2 * Copyright (C) 2007, 2009, 2010 Apple Inc. All rights reserved. |
3 * Copyright (C) 2008 Google Inc. | 3 * Copyright (C) 2008 Google Inc. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 | 141 |
142 DragController::~DragController() | 142 DragController::~DragController() |
143 { | 143 { |
144 } | 144 } |
145 | 145 |
146 PassOwnPtr<DragController> DragController::create(Page* page, DragClient* client
) | 146 PassOwnPtr<DragController> DragController::create(Page* page, DragClient* client
) |
147 { | 147 { |
148 return adoptPtr(new DragController(page, client)); | 148 return adoptPtr(new DragController(page, client)); |
149 } | 149 } |
150 | 150 |
151 static PassRefPtr<DocumentFragment> documentFragmentFromDragData(DragData* dragD
ata, LocalFrame* frame, RefPtrWillBeRawPtr<Range> context, | 151 static PassRefPtrWillBeRawPtr<DocumentFragment> documentFragmentFromDragData(Dra
gData* dragData, LocalFrame* frame, RefPtrWillBeRawPtr<Range> context, bool allo
wPlainText, bool& chosePlainText) |
152 bool allowPlainText, bool& chosePlainT
ext) | |
153 { | 152 { |
154 ASSERT(dragData); | 153 ASSERT(dragData); |
155 chosePlainText = false; | 154 chosePlainText = false; |
156 | 155 |
157 Document& document = context->ownerDocument(); | 156 Document& document = context->ownerDocument(); |
158 if (dragData->containsCompatibleContent()) { | 157 if (dragData->containsCompatibleContent()) { |
159 if (PassRefPtr<DocumentFragment> fragment = dragData->asFragment(frame,
context, allowPlainText, chosePlainText)) | 158 if (PassRefPtrWillBeRawPtr<DocumentFragment> fragment = dragData->asFrag
ment(frame, context, allowPlainText, chosePlainText)) |
160 return fragment; | 159 return fragment; |
161 | 160 |
162 if (dragData->containsURL(DragData::DoNotConvertFilenames)) { | 161 if (dragData->containsURL(DragData::DoNotConvertFilenames)) { |
163 String title; | 162 String title; |
164 String url = dragData->asURL(DragData::DoNotConvertFilenames, &title
); | 163 String url = dragData->asURL(DragData::DoNotConvertFilenames, &title
); |
165 if (!url.isEmpty()) { | 164 if (!url.isEmpty()) { |
166 RefPtrWillBeRawPtr<HTMLAnchorElement> anchor = HTMLAnchorElement
::create(document); | 165 RefPtrWillBeRawPtr<HTMLAnchorElement> anchor = HTMLAnchorElement
::create(document); |
167 anchor->setHref(AtomicString(url)); | 166 anchor->setHref(AtomicString(url)); |
168 if (title.isEmpty()) { | 167 if (title.isEmpty()) { |
169 // Try the plain text first because the url might be normali
zed or escaped. | 168 // Try the plain text first because the url might be normali
zed or escaped. |
170 if (dragData->containsPlainText()) | 169 if (dragData->containsPlainText()) |
171 title = dragData->asPlainText(); | 170 title = dragData->asPlainText(); |
172 if (title.isEmpty()) | 171 if (title.isEmpty()) |
173 title = url; | 172 title = url; |
174 } | 173 } |
175 RefPtr<Node> anchorText = document.createTextNode(title); | 174 RefPtr<Node> anchorText = document.createTextNode(title); |
176 anchor->appendChild(anchorText); | 175 anchor->appendChild(anchorText); |
177 RefPtr<DocumentFragment> fragment = document.createDocumentFragm
ent(); | 176 RefPtrWillBeRawPtr<DocumentFragment> fragment = document.createD
ocumentFragment(); |
178 fragment->appendChild(anchor); | 177 fragment->appendChild(anchor); |
179 return fragment.release(); | 178 return fragment.release(); |
180 } | 179 } |
181 } | 180 } |
182 } | 181 } |
183 if (allowPlainText && dragData->containsPlainText()) { | 182 if (allowPlainText && dragData->containsPlainText()) { |
184 chosePlainText = true; | 183 chosePlainText = true; |
185 return createFragmentFromText(context.get(), dragData->asPlainText()).ge
t(); | 184 return createFragmentFromText(context.get(), dragData->asPlainText()).ge
t(); |
186 } | 185 } |
187 | 186 |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
487 RefPtr<Element> rootEditableElement = innerFrame->selection().rootEditableEl
ement(); | 486 RefPtr<Element> rootEditableElement = innerFrame->selection().rootEditableEl
ement(); |
488 | 487 |
489 // For range to be null a WebKit client must have done something bad while | 488 // For range to be null a WebKit client must have done something bad while |
490 // manually controlling drag behaviour | 489 // manually controlling drag behaviour |
491 if (!range) | 490 if (!range) |
492 return false; | 491 return false; |
493 ResourceFetcher* fetcher = range->ownerDocument().fetcher(); | 492 ResourceFetcher* fetcher = range->ownerDocument().fetcher(); |
494 ResourceCacheValidationSuppressor validationSuppressor(fetcher); | 493 ResourceCacheValidationSuppressor validationSuppressor(fetcher); |
495 if (dragIsMove(innerFrame->selection(), dragData) || dragCaret.isContentRich
lyEditable()) { | 494 if (dragIsMove(innerFrame->selection(), dragData) || dragCaret.isContentRich
lyEditable()) { |
496 bool chosePlainText = false; | 495 bool chosePlainText = false; |
497 RefPtr<DocumentFragment> fragment = documentFragmentFromDragData(dragDat
a, innerFrame.get(), range, true, chosePlainText); | 496 RefPtrWillBeRawPtr<DocumentFragment> fragment = documentFragmentFromDrag
Data(dragData, innerFrame.get(), range, true, chosePlainText); |
498 if (!fragment) | 497 if (!fragment) |
499 return false; | 498 return false; |
500 | 499 |
501 if (dragIsMove(innerFrame->selection(), dragData)) { | 500 if (dragIsMove(innerFrame->selection(), dragData)) { |
502 // NSTextView behavior is to always smart delete on moving a selecti
on, | 501 // NSTextView behavior is to always smart delete on moving a selecti
on, |
503 // but only to smart insert if the selection granularity is word gra
nularity. | 502 // but only to smart insert if the selection granularity is word gra
nularity. |
504 bool smartDelete = innerFrame->editor().smartInsertDeleteEnabled(); | 503 bool smartDelete = innerFrame->editor().smartInsertDeleteEnabled(); |
505 bool smartInsert = smartDelete && innerFrame->selection().granularit
y() == WordGranularity && dragData->canSmartReplace(); | 504 bool smartInsert = smartDelete && innerFrame->selection().granularit
y() == WordGranularity && dragData->canSmartReplace(); |
506 MoveSelectionCommand::create(fragment, dragCaret.base(), smartInsert
, smartDelete)->apply(); | 505 MoveSelectionCommand::create(fragment, dragCaret.base(), smartInsert
, smartDelete)->apply(); |
507 } else { | 506 } else { |
(...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
958 #else | 957 #else |
959 return keyState & PlatformEvent::CtrlKey; | 958 return keyState & PlatformEvent::CtrlKey; |
960 #endif | 959 #endif |
961 } | 960 } |
962 | 961 |
963 void DragController::cleanupAfterSystemDrag() | 962 void DragController::cleanupAfterSystemDrag() |
964 { | 963 { |
965 } | 964 } |
966 | 965 |
967 } // namespace WebCore | 966 } // namespace WebCore |
OLD | NEW |