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

Side by Side Diff: Source/core/editing/EditorCommand.cpp

Issue 426433002: Use tighter typing in editing: Editor / EditorCommand (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 5 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) 2006, 2007, 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
3 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) 3 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
4 * Copyright (C) 2009 Igalia S.L. 4 * Copyright (C) 2009 Igalia S.L.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 return false; 193 return false;
194 } 194 }
195 195
196 static bool executeInsertFragment(LocalFrame& frame, PassRefPtrWillBeRawPtr<Docu mentFragment> fragment) 196 static bool executeInsertFragment(LocalFrame& frame, PassRefPtrWillBeRawPtr<Docu mentFragment> fragment)
197 { 197 {
198 ASSERT(frame.document()); 198 ASSERT(frame.document());
199 ReplaceSelectionCommand::create(*frame.document(), fragment, ReplaceSelectio nCommand::PreventNesting, EditActionUnspecified)->apply(); 199 ReplaceSelectionCommand::create(*frame.document(), fragment, ReplaceSelectio nCommand::PreventNesting, EditActionUnspecified)->apply();
200 return true; 200 return true;
201 } 201 }
202 202
203 static bool executeInsertNode(LocalFrame& frame, PassRefPtrWillBeRawPtr<Node> co ntent) 203 static bool executeInsertElement(LocalFrame& frame, PassRefPtrWillBeRawPtr<HTMLE lement> content)
204 { 204 {
205 ASSERT(frame.document()); 205 ASSERT(frame.document());
206 RefPtrWillBeRawPtr<DocumentFragment> fragment = DocumentFragment::create(*fr ame.document()); 206 RefPtrWillBeRawPtr<DocumentFragment> fragment = DocumentFragment::create(*fr ame.document());
207 TrackExceptionState exceptionState; 207 TrackExceptionState exceptionState;
208 fragment->appendChild(content, exceptionState); 208 fragment->appendChild(content, exceptionState);
209 if (exceptionState.hadException()) 209 if (exceptionState.hadException())
210 return false; 210 return false;
211 return executeInsertFragment(frame, fragment.release()); 211 return executeInsertFragment(frame, fragment.release());
212 } 212 }
213 213
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 } 264 }
265 265
266 static unsigned verticalScrollDistance(LocalFrame& frame) 266 static unsigned verticalScrollDistance(LocalFrame& frame)
267 { 267 {
268 Element* focusedElement = frame.document()->focusedElement(); 268 Element* focusedElement = frame.document()->focusedElement();
269 if (!focusedElement) 269 if (!focusedElement)
270 return 0; 270 return 0;
271 RenderObject* renderer = focusedElement->renderer(); 271 RenderObject* renderer = focusedElement->renderer();
272 if (!renderer || !renderer->isBox()) 272 if (!renderer || !renderer->isBox())
273 return 0; 273 return 0;
274 RenderStyle* style = renderer->style(); 274 RenderBox& renderBox = toRenderBox(*renderer);
275 RenderStyle* style = renderBox.style();
275 if (!style) 276 if (!style)
276 return 0; 277 return 0;
277 if (!(style->overflowY() == OSCROLL || style->overflowY() == OAUTO || focuse dElement->hasEditableStyle())) 278 if (!(style->overflowY() == OSCROLL || style->overflowY() == OAUTO || focuse dElement->hasEditableStyle()))
278 return 0; 279 return 0;
279 int height = std::min<int>(toRenderBox(renderer)->clientHeight(), frame.view ()->visibleHeight()); 280 int height = std::min<int>(renderBox.clientHeight(), frame.view()->visibleHe ight());
280 return static_cast<unsigned>(max(max<int>(height * ScrollableArea::minFracti onToStepWhenPaging(), height - ScrollableArea::maxOverlapBetweenPages()), 1)); 281 return static_cast<unsigned>(max(max<int>(height * ScrollableArea::minFracti onToStepWhenPaging(), height - ScrollableArea::maxOverlapBetweenPages()), 1));
281 } 282 }
282 283
283 static PassRefPtrWillBeRawPtr<Range> unionDOMRanges(Range* a, Range* b) 284 static PassRefPtrWillBeRawPtr<Range> unionDOMRanges(Range* a, Range* b)
284 { 285 {
285 Range* start = a->compareBoundaryPoints(Range::START_TO_START, b, ASSERT_NO_ EXCEPTION) <= 0 ? a : b; 286 Range* start = a->compareBoundaryPoints(Range::START_TO_START, b, ASSERT_NO_ EXCEPTION) <= 0 ? a : b;
286 Range* end = a->compareBoundaryPoints(Range::END_TO_END, b, ASSERT_NO_EXCEPT ION) <= 0 ? b : a; 287 Range* end = a->compareBoundaryPoints(Range::END_TO_END, b, ASSERT_NO_EXCEPT ION) <= 0 ? b : a;
287 288
288 return Range::create(a->ownerDocument(), start->startContainer(), start->sta rtOffset(), end->endContainer(), end->endOffset()); 289 return Range::create(a->ownerDocument(), start->startContainer(), start->sta rtOffset(), end->endContainer(), end->endOffset());
289 } 290 }
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
501 { 502 {
502 return targetFrame(frame, event)->eventHandler().handleTextInputEvent("\t", event, TextEventInputBackTab); 503 return targetFrame(frame, event)->eventHandler().handleTextInputEvent("\t", event, TextEventInputBackTab);
503 } 504 }
504 505
505 static bool executeInsertHorizontalRule(LocalFrame& frame, Event*, EditorCommand Source, const String& value) 506 static bool executeInsertHorizontalRule(LocalFrame& frame, Event*, EditorCommand Source, const String& value)
506 { 507 {
507 ASSERT(frame.document()); 508 ASSERT(frame.document());
508 RefPtrWillBeRawPtr<HTMLHRElement> rule = HTMLHRElement::create(*frame.docume nt()); 509 RefPtrWillBeRawPtr<HTMLHRElement> rule = HTMLHRElement::create(*frame.docume nt());
509 if (!value.isEmpty()) 510 if (!value.isEmpty())
510 rule->setIdAttribute(AtomicString(value)); 511 rule->setIdAttribute(AtomicString(value));
511 return executeInsertNode(frame, rule.release()); 512 return executeInsertElement(frame, rule.release());
512 } 513 }
513 514
514 static bool executeInsertHTML(LocalFrame& frame, Event*, EditorCommandSource, co nst String& value) 515 static bool executeInsertHTML(LocalFrame& frame, Event*, EditorCommandSource, co nst String& value)
515 { 516 {
516 ASSERT(frame.document()); 517 ASSERT(frame.document());
517 return executeInsertFragment(frame, createFragmentFromMarkup(*frame.document (), value, "")); 518 return executeInsertFragment(frame, createFragmentFromMarkup(*frame.document (), value, ""));
518 } 519 }
519 520
520 static bool executeInsertImage(LocalFrame& frame, Event*, EditorCommandSource, c onst String& value) 521 static bool executeInsertImage(LocalFrame& frame, Event*, EditorCommandSource, c onst String& value)
521 { 522 {
522 // FIXME: If userInterface is true, we should display a dialog box and let t he user choose a local image. 523 // FIXME: If userInterface is true, we should display a dialog box and let t he user choose a local image.
523 ASSERT(frame.document()); 524 ASSERT(frame.document());
524 RefPtrWillBeRawPtr<HTMLImageElement> image = HTMLImageElement::create(*frame .document()); 525 RefPtrWillBeRawPtr<HTMLImageElement> image = HTMLImageElement::create(*frame .document());
525 image->setSrc(value); 526 image->setSrc(value);
526 return executeInsertNode(frame, image.release()); 527 return executeInsertElement(frame, image.release());
527 } 528 }
528 529
529 static bool executeInsertLineBreak(LocalFrame& frame, Event* event, EditorComman dSource source, const String&) 530 static bool executeInsertLineBreak(LocalFrame& frame, Event* event, EditorComman dSource source, const String&)
530 { 531 {
531 switch (source) { 532 switch (source) {
532 case CommandFromMenuOrKeyBinding: 533 case CommandFromMenuOrKeyBinding:
533 return targetFrame(frame, event)->eventHandler().handleTextInputEvent("\ n", event, TextEventInputLineBreak); 534 return targetFrame(frame, event)->eventHandler().handleTextInputEvent("\ n", event, TextEventInputLineBreak);
534 case CommandFromDOM: 535 case CommandFromDOM:
535 case CommandFromDOMWithUserInterface: 536 case CommandFromDOMWithUserInterface:
536 // Doesn't scroll to make the selection visible, or modify the kill ring . 537 // Doesn't scroll to make the selection visible, or modify the kill ring .
(...skipping 1256 matching lines...) Expand 10 before | Expand all | Expand 10 after
1793 { 1794 {
1794 return m_command && m_command->isTextInsertion; 1795 return m_command && m_command->isTextInsertion;
1795 } 1796 }
1796 1797
1797 int Editor::Command::idForHistogram() const 1798 int Editor::Command::idForHistogram() const
1798 { 1799 {
1799 return isSupported() ? m_command->idForUserMetrics : 0; 1800 return isSupported() ? m_command->idForUserMetrics : 0;
1800 } 1801 }
1801 1802
1802 } // namespace blink 1803 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698