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 PassRefPtrWillBeRawPtr<DocumentFragment> documentFragmentFromDragData(Dra
gData* dragData, LocalFrame* frame, RefPtrWillBeRawPtr<Range> context, bool allo
wPlainText, bool& chosePlainText) | 151 static PassRefPtr<DocumentFragment> documentFragmentFromDragData(DragData* dragD
ata, LocalFrame* frame, RefPtrWillBeRawPtr<Range> context, |
| 152 bool allowPlainText, bool& chosePlainT
ext) |
152 { | 153 { |
153 ASSERT(dragData); | 154 ASSERT(dragData); |
154 chosePlainText = false; | 155 chosePlainText = false; |
155 | 156 |
156 Document& document = context->ownerDocument(); | 157 Document& document = context->ownerDocument(); |
157 if (dragData->containsCompatibleContent()) { | 158 if (dragData->containsCompatibleContent()) { |
158 if (PassRefPtrWillBeRawPtr<DocumentFragment> fragment = dragData->asFrag
ment(frame, context, allowPlainText, chosePlainText)) | 159 if (PassRefPtr<DocumentFragment> fragment = dragData->asFragment(frame,
context, allowPlainText, chosePlainText)) |
159 return fragment; | 160 return fragment; |
160 | 161 |
161 if (dragData->containsURL(DragData::DoNotConvertFilenames)) { | 162 if (dragData->containsURL(DragData::DoNotConvertFilenames)) { |
162 String title; | 163 String title; |
163 String url = dragData->asURL(DragData::DoNotConvertFilenames, &title
); | 164 String url = dragData->asURL(DragData::DoNotConvertFilenames, &title
); |
164 if (!url.isEmpty()) { | 165 if (!url.isEmpty()) { |
165 RefPtrWillBeRawPtr<HTMLAnchorElement> anchor = HTMLAnchorElement
::create(document); | 166 RefPtrWillBeRawPtr<HTMLAnchorElement> anchor = HTMLAnchorElement
::create(document); |
166 anchor->setHref(AtomicString(url)); | 167 anchor->setHref(AtomicString(url)); |
167 if (title.isEmpty()) { | 168 if (title.isEmpty()) { |
168 // Try the plain text first because the url might be normali
zed or escaped. | 169 // Try the plain text first because the url might be normali
zed or escaped. |
169 if (dragData->containsPlainText()) | 170 if (dragData->containsPlainText()) |
170 title = dragData->asPlainText(); | 171 title = dragData->asPlainText(); |
171 if (title.isEmpty()) | 172 if (title.isEmpty()) |
172 title = url; | 173 title = url; |
173 } | 174 } |
174 RefPtr<Node> anchorText = document.createTextNode(title); | 175 RefPtr<Node> anchorText = document.createTextNode(title); |
175 anchor->appendChild(anchorText); | 176 anchor->appendChild(anchorText); |
176 RefPtrWillBeRawPtr<DocumentFragment> fragment = document.createD
ocumentFragment(); | 177 RefPtr<DocumentFragment> fragment = document.createDocumentFragm
ent(); |
177 fragment->appendChild(anchor); | 178 fragment->appendChild(anchor); |
178 return fragment.release(); | 179 return fragment.release(); |
179 } | 180 } |
180 } | 181 } |
181 } | 182 } |
182 if (allowPlainText && dragData->containsPlainText()) { | 183 if (allowPlainText && dragData->containsPlainText()) { |
183 chosePlainText = true; | 184 chosePlainText = true; |
184 return createFragmentFromText(context.get(), dragData->asPlainText()).ge
t(); | 185 return createFragmentFromText(context.get(), dragData->asPlainText()).ge
t(); |
185 } | 186 } |
186 | 187 |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
486 RefPtr<Element> rootEditableElement = innerFrame->selection().rootEditableEl
ement(); | 487 RefPtr<Element> rootEditableElement = innerFrame->selection().rootEditableEl
ement(); |
487 | 488 |
488 // For range to be null a WebKit client must have done something bad while | 489 // For range to be null a WebKit client must have done something bad while |
489 // manually controlling drag behaviour | 490 // manually controlling drag behaviour |
490 if (!range) | 491 if (!range) |
491 return false; | 492 return false; |
492 ResourceFetcher* fetcher = range->ownerDocument().fetcher(); | 493 ResourceFetcher* fetcher = range->ownerDocument().fetcher(); |
493 ResourceCacheValidationSuppressor validationSuppressor(fetcher); | 494 ResourceCacheValidationSuppressor validationSuppressor(fetcher); |
494 if (dragIsMove(innerFrame->selection(), dragData) || dragCaret.isContentRich
lyEditable()) { | 495 if (dragIsMove(innerFrame->selection(), dragData) || dragCaret.isContentRich
lyEditable()) { |
495 bool chosePlainText = false; | 496 bool chosePlainText = false; |
496 RefPtrWillBeRawPtr<DocumentFragment> fragment = documentFragmentFromDrag
Data(dragData, innerFrame.get(), range, true, chosePlainText); | 497 RefPtr<DocumentFragment> fragment = documentFragmentFromDragData(dragDat
a, innerFrame.get(), range, true, chosePlainText); |
497 if (!fragment) | 498 if (!fragment) |
498 return false; | 499 return false; |
499 | 500 |
500 if (dragIsMove(innerFrame->selection(), dragData)) { | 501 if (dragIsMove(innerFrame->selection(), dragData)) { |
501 // NSTextView behavior is to always smart delete on moving a selecti
on, | 502 // NSTextView behavior is to always smart delete on moving a selecti
on, |
502 // but only to smart insert if the selection granularity is word gra
nularity. | 503 // but only to smart insert if the selection granularity is word gra
nularity. |
503 bool smartDelete = innerFrame->editor().smartInsertDeleteEnabled(); | 504 bool smartDelete = innerFrame->editor().smartInsertDeleteEnabled(); |
504 bool smartInsert = smartDelete && innerFrame->selection().granularit
y() == WordGranularity && dragData->canSmartReplace(); | 505 bool smartInsert = smartDelete && innerFrame->selection().granularit
y() == WordGranularity && dragData->canSmartReplace(); |
505 MoveSelectionCommand::create(fragment, dragCaret.base(), smartInsert
, smartDelete)->apply(); | 506 MoveSelectionCommand::create(fragment, dragCaret.base(), smartInsert
, smartDelete)->apply(); |
506 } else { | 507 } else { |
(...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
957 #else | 958 #else |
958 return keyState & PlatformEvent::CtrlKey; | 959 return keyState & PlatformEvent::CtrlKey; |
959 #endif | 960 #endif |
960 } | 961 } |
961 | 962 |
962 void DragController::cleanupAfterSystemDrag() | 963 void DragController::cleanupAfterSystemDrag() |
963 { | 964 { |
964 } | 965 } |
965 | 966 |
966 } // namespace WebCore | 967 } // namespace WebCore |
OLD | NEW |