Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(333)

Side by Side Diff: Source/core/page/DragController.cpp

Issue 23467007: Have Range constructor take a Document reference in argument (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 { 142 {
143 return adoptPtr(new DragController(page, client)); 143 return adoptPtr(new DragController(page, client));
144 } 144 }
145 145
146 static PassRefPtr<DocumentFragment> documentFragmentFromDragData(DragData* dragD ata, Frame* frame, RefPtr<Range> context, 146 static PassRefPtr<DocumentFragment> documentFragmentFromDragData(DragData* dragD ata, Frame* frame, RefPtr<Range> context,
147 bool allowPlainText, bool& chosePlainT ext) 147 bool allowPlainText, bool& chosePlainT ext)
148 { 148 {
149 ASSERT(dragData); 149 ASSERT(dragData);
150 chosePlainText = false; 150 chosePlainText = false;
151 151
152 Document* document = context->ownerDocument(); 152 Document& document = context->ownerDocument();
153 ASSERT(document); 153 if (dragData->containsCompatibleContent()) {
154 if (document && dragData->containsCompatibleContent()) {
155 if (PassRefPtr<DocumentFragment> fragment = dragData->asFragment(frame, context, allowPlainText, chosePlainText)) 154 if (PassRefPtr<DocumentFragment> fragment = dragData->asFragment(frame, context, allowPlainText, chosePlainText))
156 return fragment; 155 return fragment;
157 156
158 if (dragData->containsURL(frame, DragData::DoNotConvertFilenames)) { 157 if (dragData->containsURL(frame, DragData::DoNotConvertFilenames)) {
159 String title; 158 String title;
160 String url = dragData->asURL(frame, DragData::DoNotConvertFilenames, &title); 159 String url = dragData->asURL(frame, DragData::DoNotConvertFilenames, &title);
161 if (!url.isEmpty()) { 160 if (!url.isEmpty()) {
162 RefPtr<HTMLAnchorElement> anchor = HTMLAnchorElement::create(*do cument); 161 RefPtr<HTMLAnchorElement> anchor = HTMLAnchorElement::create(doc ument);
163 anchor->setHref(url); 162 anchor->setHref(url);
164 if (title.isEmpty()) { 163 if (title.isEmpty()) {
165 // Try the plain text first because the url might be normali zed or escaped. 164 // Try the plain text first because the url might be normali zed or escaped.
166 if (dragData->containsPlainText()) 165 if (dragData->containsPlainText())
167 title = dragData->asPlainText(frame); 166 title = dragData->asPlainText(frame);
168 if (title.isEmpty()) 167 if (title.isEmpty())
169 title = url; 168 title = url;
170 } 169 }
171 RefPtr<Node> anchorText = document->createTextNode(title); 170 RefPtr<Node> anchorText = document.createTextNode(title);
172 anchor->appendChild(anchorText); 171 anchor->appendChild(anchorText);
173 RefPtr<DocumentFragment> fragment = document->createDocumentFrag ment(); 172 RefPtr<DocumentFragment> fragment = document.createDocumentFragm ent();
174 fragment->appendChild(anchor); 173 fragment->appendChild(anchor);
175 return fragment.release(); 174 return fragment.release();
176 } 175 }
177 } 176 }
178 } 177 }
179 if (allowPlainText && dragData->containsPlainText()) { 178 if (allowPlainText && dragData->containsPlainText()) {
180 chosePlainText = true; 179 chosePlainText = true;
181 return createFragmentFromText(context.get(), dragData->asPlainText(frame )).get(); 180 return createFragmentFromText(context.get(), dragData->asPlainText(frame )).get();
182 } 181 }
183 182
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 477
479 VisibleSelection dragCaret = m_page->dragCaretController().caretPosition(); 478 VisibleSelection dragCaret = m_page->dragCaretController().caretPosition();
480 m_page->dragCaretController().clear(); 479 m_page->dragCaretController().clear();
481 RefPtr<Range> range = dragCaret.toNormalizedRange(); 480 RefPtr<Range> range = dragCaret.toNormalizedRange();
482 RefPtr<Element> rootEditableElement = innerFrame->selection().rootEditableEl ement(); 481 RefPtr<Element> rootEditableElement = innerFrame->selection().rootEditableEl ement();
483 482
484 // For range to be null a WebKit client must have done something bad while 483 // For range to be null a WebKit client must have done something bad while
485 // manually controlling drag behaviour 484 // manually controlling drag behaviour
486 if (!range) 485 if (!range)
487 return false; 486 return false;
488 ResourceFetcher* fetcher = range->ownerDocument()->fetcher(); 487 ResourceFetcher* fetcher = range->ownerDocument().fetcher();
489 ResourceCacheValidationSuppressor validationSuppressor(fetcher); 488 ResourceCacheValidationSuppressor validationSuppressor(fetcher);
490 if (dragIsMove(innerFrame->selection(), dragData) || dragCaret.isContentRich lyEditable()) { 489 if (dragIsMove(innerFrame->selection(), dragData) || dragCaret.isContentRich lyEditable()) {
491 bool chosePlainText = false; 490 bool chosePlainText = false;
492 RefPtr<DocumentFragment> fragment = documentFragmentFromDragData(dragDat a, innerFrame.get(), range, true, chosePlainText); 491 RefPtr<DocumentFragment> fragment = documentFragmentFromDragData(dragDat a, innerFrame.get(), range, true, chosePlainText);
493 if (!fragment || !innerFrame->editor().shouldInsertFragment(fragment, ra nge, EditorInsertActionDropped)) { 492 if (!fragment || !innerFrame->editor().shouldInsertFragment(fragment, ra nge, EditorInsertActionDropped)) {
494 return false; 493 return false;
495 } 494 }
496 495
497 if (dragIsMove(innerFrame->selection(), dragData)) { 496 if (dragIsMove(innerFrame->selection(), dragData)) {
498 // NSTextView behavior is to always smart delete on moving a selecti on, 497 // NSTextView behavior is to always smart delete on moving a selecti on,
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after
923 return false; 922 return false;
924 #endif 923 #endif
925 } 924 }
926 925
927 void DragController::cleanupAfterSystemDrag() 926 void DragController::cleanupAfterSystemDrag()
928 { 927 {
929 } 928 }
930 929
931 } // namespace WebCore 930 } // namespace WebCore
932 931
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698