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

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

Issue 923023002: Refactoring code so as to avoid possible crash due to null pointer (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 10 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2006, 2007, 2008, 2011 Apple Inc. All rights reserved. 2 * Copyright (C) 2006, 2007, 2008, 2011 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 * 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 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 frame().selection().setSelectedRange(selectedRange.get(), DOWNSTREAM , FrameSelection::NonDirectional, NotUserTriggered); 311 frame().selection().setSelectedRange(selectedRange.get(), DOWNSTREAM , FrameSelection::NonDirectional, NotUserTriggered);
312 } 312 }
313 } 313 }
314 } 314 }
315 315
316 void InputMethodController::setCompositionFromExistingText(const Vector<Composit ionUnderline>& underlines, unsigned compositionStart, unsigned compositionEnd) 316 void InputMethodController::setCompositionFromExistingText(const Vector<Composit ionUnderline>& underlines, unsigned compositionStart, unsigned compositionEnd)
317 { 317 {
318 Element* editable = frame().selection().rootEditableElement(); 318 Element* editable = frame().selection().rootEditableElement();
319 Position base = frame().selection().base().downstream(); 319 Position base = frame().selection().base().downstream();
320 Node* baseNode = base.anchorNode(); 320 Node* baseNode = base.anchorNode();
321 if (editable->firstChild() == baseNode && editable->lastChild() == baseNode && baseNode->isTextNode()) { 321 if (baseNode && editable->firstChild() == baseNode && editable->lastChild() == baseNode && baseNode->isTextNode()) {
322 m_compositionNode = nullptr; 322 m_compositionNode = nullptr;
323 m_customCompositionUnderlines.clear(); 323 m_customCompositionUnderlines.clear();
324 324
325 if (base.anchorType() != Position::PositionIsOffsetInAnchor) 325 if (base.anchorType() != Position::PositionIsOffsetInAnchor)
326 return; 326 return;
327 if (!baseNode || baseNode != frame().selection().extent().anchorNode()) 327 if (baseNode != frame().selection().extent().anchorNode())
328 return; 328 return;
329 329
330 m_compositionNode = toText(baseNode); 330 m_compositionNode = toText(baseNode);
331 RefPtrWillBeRawPtr<Range> range = PlainTextRange(compositionStart, compo sitionEnd).createRange(*editable); 331 RefPtrWillBeRawPtr<Range> range = PlainTextRange(compositionStart, compo sitionEnd).createRange(*editable);
332 if (!range) 332 if (!range)
333 return; 333 return;
334 334
335 m_compositionStart = range->startOffset(); 335 m_compositionStart = range->startOffset();
336 m_compositionEnd = range->endOffset(); 336 m_compositionEnd = range->endOffset();
337 m_customCompositionUnderlines = underlines; 337 m_customCompositionUnderlines = underlines;
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 TypingCommand::deleteSelection(*frame().document()); 425 TypingCommand::deleteSelection(*frame().document());
426 } 426 }
427 427
428 void InputMethodController::trace(Visitor* visitor) 428 void InputMethodController::trace(Visitor* visitor)
429 { 429 {
430 visitor->trace(m_frame); 430 visitor->trace(m_frame);
431 visitor->trace(m_compositionNode); 431 visitor->trace(m_compositionNode);
432 } 432 }
433 433
434 } // namespace blink 434 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698