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

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

Issue 2316053002: Audit the use of updateStyleAndLayoutIgnorePendingStylesheets in InputMethodController::setSelectio… (Closed)
Patch Set: Created 4 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
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/editing/InputMethodControllerTest.cpp » ('j') | 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 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 248
249 if (text.length()) { 249 if (text.length()) {
250 confirmComposition(text); 250 confirmComposition(text);
251 return true; 251 return true;
252 } 252 }
253 253
254 if (confirmBehavior == DoNotKeepSelection) 254 if (confirmBehavior == DoNotKeepSelection)
255 return confirmComposition(composingText(), DoNotKeepSelection); 255 return confirmComposition(composingText(), DoNotKeepSelection);
256 256
257 SelectionOffsetsScope selectionOffsetsScope(this); 257 SelectionOffsetsScope selectionOffsetsScope(this);
258 return confirmComposition(); 258 bool result = confirmComposition();
259
260 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets
261 // needs to be audited. see http://crbug.com/590369 for more details.
262 frame().document()->updateStyleAndLayoutIgnorePendingStylesheets();
yosin_UTC9 2016/09/08 04:04:41 This is the first pattern which updates layout aft
Xiaocheng 2016/09/08 06:39:09 It is in fact the dtor of the SelectionOffsetsScop
263
264 return result;
259 } 265 }
260 266
261 void InputMethodController::cancelComposition() 267 void InputMethodController::cancelComposition()
262 { 268 {
263 if (!hasComposition()) 269 if (!hasComposition())
264 return; 270 return;
265 271
266 Editor::RevealSelectionScope revealSelectionScope(&editor()); 272 Editor::RevealSelectionScope revealSelectionScope(&editor());
267 273
268 if (frame().selection().isNone()) 274 if (frame().selection().isNone())
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 // !hasComposition() && test.isEmpty(). 353 // !hasComposition() && test.isEmpty().
348 if (text.isEmpty()) { 354 if (text.isEmpty()) {
349 if (hasComposition()) { 355 if (hasComposition()) {
350 confirmComposition(emptyString()); 356 confirmComposition(emptyString());
351 } else { 357 } else {
352 // It's weird to call |setComposition()| with empty text outside com position, however some IME 358 // It's weird to call |setComposition()| with empty text outside com position, however some IME
353 // (e.g. Japanese IBus-Anthy) did this, so we simply delete selectio n without sending extra events. 359 // (e.g. Japanese IBus-Anthy) did this, so we simply delete selectio n without sending extra events.
354 TypingCommand::deleteSelection(*frame().document(), TypingCommand::P reventSpellChecking); 360 TypingCommand::deleteSelection(*frame().document(), TypingCommand::P reventSpellChecking);
355 } 361 }
356 362
363 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesh eets
364 // needs to be audited. see http://crbug.com/590369 for more details.
365 frame().document()->updateStyleAndLayoutIgnorePendingStylesheets();
366
357 setEditableSelectionOffsets(selectedRange); 367 setEditableSelectionOffsets(selectedRange);
358 return; 368 return;
359 } 369 }
360 370
361 // We should send a 'compositionstart' event only when the given text is not empty because this 371 // We should send a 'compositionstart' event only when the given text is not empty because this
362 // function doesn't create a composition node when the text is empty. 372 // function doesn't create a composition node when the text is empty.
363 if (!hasComposition()) { 373 if (!hasComposition()) {
364 target->dispatchEvent(CompositionEvent::create(EventTypeNames::compositi onstart, frame().domWindow(), frame().selectedText())); 374 target->dispatchEvent(CompositionEvent::create(EventTypeNames::compositi onstart, frame().domWindow(), frame().selectedText()));
365 if (!frame().document()) 375 if (!frame().document())
366 return; 376 return;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 m_isDirty = true; 408 m_isDirty = true;
399 m_hasComposition = true; 409 m_hasComposition = true;
400 if (!m_compositionRange) 410 if (!m_compositionRange)
401 m_compositionRange = Range::create(baseNode->document()); 411 m_compositionRange = Range::create(baseNode->document());
402 m_compositionRange->setStart(baseNode, baseOffset); 412 m_compositionRange->setStart(baseNode, baseOffset);
403 m_compositionRange->setEnd(baseNode, extentOffset); 413 m_compositionRange->setEnd(baseNode, extentOffset);
404 414
405 if (baseNode->layoutObject()) 415 if (baseNode->layoutObject())
406 baseNode->layoutObject()->setShouldDoFullPaintInvalidation(); 416 baseNode->layoutObject()->setShouldDoFullPaintInvalidation();
407 417
418 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets
419 // needs to be audited. see http://crbug.com/590369 for more details.
420 frame().document()->updateStyleAndLayoutIgnorePendingStylesheets();
421
408 // We shouldn't close typing in the middle of setComposition. 422 // We shouldn't close typing in the middle of setComposition.
409 setEditableSelectionOffsets(selectedRange, NotUserTriggered); 423 setEditableSelectionOffsets(selectedRange, NotUserTriggered);
410 424
411 if (underlines.isEmpty()) { 425 if (underlines.isEmpty()) {
412 frame().document()->markers().addCompositionMarker(m_compositionRange->s tartPosition(), m_compositionRange->endPosition(), Color::black, false, LayoutTh eme::theme().platformDefaultCompositionBackgroundColor()); 426 frame().document()->markers().addCompositionMarker(m_compositionRange->s tartPosition(), m_compositionRange->endPosition(), Color::black, false, LayoutTh eme::theme().platformDefaultCompositionBackgroundColor());
413 return; 427 return;
414 } 428 }
415 for (const auto& underline : underlines) { 429 for (const auto& underline : underlines) {
416 unsigned underlineStart = baseOffset + underline.startOffset; 430 unsigned underlineStart = baseOffset + underline.startOffset;
417 unsigned underlineEnd = baseOffset + underline.endOffset; 431 unsigned underlineEnd = baseOffset + underline.endOffset;
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 } 505 }
492 506
493 bool InputMethodController::setSelectionOffsets(const PlainTextRange& selectionO ffsets, FrameSelection::SetSelectionOptions options) 507 bool InputMethodController::setSelectionOffsets(const PlainTextRange& selectionO ffsets, FrameSelection::SetSelectionOptions options)
494 { 508 {
495 if (selectionOffsets.isNull()) 509 if (selectionOffsets.isNull())
496 return false; 510 return false;
497 Element* rootEditableElement = frame().selection().rootEditableElement(); 511 Element* rootEditableElement = frame().selection().rootEditableElement();
498 if (!rootEditableElement) 512 if (!rootEditableElement)
499 return false; 513 return false;
500 514
501 // TODO(dglazkov): The use of updateStyleAndLayoutIgnorePendingStylesheets n eeds to be audited. 515 DCHECK(!rootEditableElement->document().needsLayoutTreeUpdate());
502 // see http://crbug.com/590369 for more details.
503 rootEditableElement->document().updateStyleAndLayoutIgnorePendingStylesheets ();
504 516
505 const EphemeralRange range = selectionOffsets.createRange(*rootEditableEleme nt); 517 const EphemeralRange range = selectionOffsets.createRange(*rootEditableEleme nt);
506 if (range.isNull()) 518 if (range.isNull())
507 return false; 519 return false;
508 520
509 return frame().selection().setSelectedRange(range, VP_DEFAULT_AFFINITY, Sele ctionDirectionalMode::NonDirectional, options); 521 return frame().selection().setSelectedRange(range, VP_DEFAULT_AFFINITY, Sele ctionDirectionalMode::NonDirectional, options);
510 } 522 }
511 523
512 bool InputMethodController::setEditableSelectionOffsets(const PlainTextRange& se lectionOffsets, FrameSelection::SetSelectionOptions options) 524 bool InputMethodController::setEditableSelectionOffsets(const PlainTextRange& se lectionOffsets, FrameSelection::SetSelectionOptions options)
513 { 525 {
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
580 TypingCommand::deleteSelection(*frame().document()); 592 TypingCommand::deleteSelection(*frame().document());
581 } 593 }
582 594
583 DEFINE_TRACE(InputMethodController) 595 DEFINE_TRACE(InputMethodController)
584 { 596 {
585 visitor->trace(m_frame); 597 visitor->trace(m_frame);
586 visitor->trace(m_compositionRange); 598 visitor->trace(m_compositionRange);
587 } 599 }
588 600
589 } // namespace blink 601 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/editing/InputMethodControllerTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698