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

Side by Side Diff: third_party/WebKit/Source/web/WebViewImpl.cpp

Issue 2121313003: [Editing][DOM][CodeHealth] Make Node::isContentEditable and Node::isRichEditable global functions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * 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 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 2257 matching lines...) Expand 10 before | Expand all | Expand 10 after
2268 m_page->focusController().setActive(true); 2268 m_page->focusController().setActive(true);
2269 LocalFrame* focusedFrame = m_page->focusController().focusedFrame(); 2269 LocalFrame* focusedFrame = m_page->focusController().focusedFrame();
2270 if (focusedFrame) { 2270 if (focusedFrame) {
2271 Element* element = focusedFrame->document()->focusedElement(); 2271 Element* element = focusedFrame->document()->focusedElement();
2272 if (element && focusedFrame->selection().selection().isNone()) { 2272 if (element && focusedFrame->selection().selection().isNone()) {
2273 // If the selection was cleared while the WebView was not 2273 // If the selection was cleared while the WebView was not
2274 // focused, then the focus element shows with a focus ring but 2274 // focused, then the focus element shows with a focus ring but
2275 // no caret and does respond to keyboard inputs. 2275 // no caret and does respond to keyboard inputs.
2276 if (element->isTextFormControl()) { 2276 if (element->isTextFormControl()) {
2277 element->updateFocusAppearance(SelectionBehaviorOnFocus::Res tore); 2277 element->updateFocusAppearance(SelectionBehaviorOnFocus::Res tore);
2278 } else if (element->isContentEditable()) { 2278 } else if (isContentEditable(*element)) {
2279 // updateFocusAppearance() selects all the text of 2279 // updateFocusAppearance() selects all the text of
2280 // contentseditable DIVs. So we set the selection explicitly 2280 // contentseditable DIVs. So we set the selection explicitly
2281 // instead. Note that this has the side effect of moving the 2281 // instead. Note that this has the side effect of moving the
2282 // caret back to the beginning of the text. 2282 // caret back to the beginning of the text.
2283 Position position(element, 0); 2283 Position position(element, 0);
2284 focusedFrame->selection().setSelection(VisibleSelection(posi tion, SelDefaultAffinity)); 2284 focusedFrame->selection().setSelection(VisibleSelection(posi tion, SelDefaultAffinity));
2285 } 2285 }
2286 } 2286 }
2287 } 2287 }
2288 m_imeAcceptEvents = true; 2288 m_imeAcceptEvents = true;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
2337 if (!focused->editor().canEdit() && !inputMethodController.hasComposition()) 2337 if (!focused->editor().canEdit() && !inputMethodController.hasComposition())
2338 return false; 2338 return false;
2339 2339
2340 // We should verify the parent node of this IME composition node are 2340 // We should verify the parent node of this IME composition node are
2341 // editable because JavaScript may delete a parent node of the composition 2341 // editable because JavaScript may delete a parent node of the composition
2342 // node. In this case, WebKit crashes while deleting texts from the parent 2342 // node. In this case, WebKit crashes while deleting texts from the parent
2343 // node, which doesn't exist any longer. 2343 // node, which doesn't exist any longer.
2344 const EphemeralRange range = inputMethodController.compositionEphemeralRange (); 2344 const EphemeralRange range = inputMethodController.compositionEphemeralRange ();
2345 if (range.isNotNull()) { 2345 if (range.isNotNull()) {
2346 Node* node = range.startPosition().computeContainerNode(); 2346 Node* node = range.startPosition().computeContainerNode();
2347 if (!node || !node->isContentEditable()) 2347 if (!node || !isContentEditable(*node))
2348 return false; 2348 return false;
2349 } 2349 }
2350 2350
2351 // A keypress event is canceled. If an ongoing composition exists, then the 2351 // A keypress event is canceled. If an ongoing composition exists, then the
2352 // keydown event should have arisen from a handled key (e.g., backspace). 2352 // keydown event should have arisen from a handled key (e.g., backspace).
2353 // In this case we ignore the cancellation and continue; otherwise (no 2353 // In this case we ignore the cancellation and continue; otherwise (no
2354 // ongoing composition) we exit and signal success only for attempts to 2354 // ongoing composition) we exit and signal success only for attempts to
2355 // clear the composition. 2355 // clear the composition.
2356 if (m_suppressNextKeypressEvent && !inputMethodController.hasComposition()) 2356 if (m_suppressNextKeypressEvent && !inputMethodController.hasComposition())
2357 return text.isEmpty(); 2357 return text.isEmpty();
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
2535 if (toHTMLTextAreaElement(*element).isDisabledOrReadOnly()) 2535 if (toHTMLTextAreaElement(*element).isDisabledOrReadOnly())
2536 return WebTextInputTypeNone; 2536 return WebTextInputTypeNone;
2537 return WebTextInputTypeTextArea; 2537 return WebTextInputTypeTextArea;
2538 } 2538 }
2539 2539
2540 if (element->isHTMLElement()) { 2540 if (element->isHTMLElement()) {
2541 if (toHTMLElement(element)->isDateTimeFieldElement()) 2541 if (toHTMLElement(element)->isDateTimeFieldElement())
2542 return WebTextInputTypeDateTimeField; 2542 return WebTextInputTypeDateTimeField;
2543 } 2543 }
2544 2544
2545 if (element->isContentEditable()) 2545 if (isContentEditable(*element))
2546 return WebTextInputTypeContentEditable; 2546 return WebTextInputTypeContentEditable;
2547 2547
2548 return WebTextInputTypeNone; 2548 return WebTextInputTypeNone;
2549 } 2549 }
2550 2550
2551 int WebViewImpl::textInputFlags() 2551 int WebViewImpl::textInputFlags()
2552 { 2552 {
2553 Element* element = focusedElement(); 2553 Element* element = focusedElement();
2554 if (!element) 2554 if (!element)
2555 return WebTextInputFlagNone; 2555 return WebTextInputFlagNone;
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after
2990 2990
2991 Element* oldFocusedElement = document->focusedElement(); 2991 Element* oldFocusedElement = document->focusedElement();
2992 document->clearFocusedElement(); 2992 document->clearFocusedElement();
2993 if (!oldFocusedElement) 2993 if (!oldFocusedElement)
2994 return; 2994 return;
2995 2995
2996 // If a text field has focus, we need to make sure the selection controller 2996 // If a text field has focus, we need to make sure the selection controller
2997 // knows to remove selection from it. Otherwise, the text field is still 2997 // knows to remove selection from it. Otherwise, the text field is still
2998 // processing keyboard events even though focus has been moved to the page a nd 2998 // processing keyboard events even though focus has been moved to the page a nd
2999 // keystrokes get eaten as a result. 2999 // keystrokes get eaten as a result.
3000 if (oldFocusedElement->isContentEditable() || oldFocusedElement->isTextFormC ontrol()) 3000 if (isContentEditable(*oldFocusedElement) || oldFocusedElement->isTextFormCo ntrol())
3001 localFrame->selection().clear(); 3001 localFrame->selection().clear();
3002 } 3002 }
3003 3003
3004 // TODO(dglazkov): Remove and replace with Node:hasEditableStyle. 3004 // TODO(dglazkov): Remove and replace with Node:hasEditableStyle.
3005 // http://crbug.com/612560 3005 // http://crbug.com/612560
3006 static bool isElementEditable(const Element* element) 3006 static bool isElementEditable(const Element* element)
3007 { 3007 {
3008 if (element->isContentEditable()) 3008 if (isContentEditable(*element))
3009 return true; 3009 return true;
3010 3010
3011 if (element->isTextFormControl()) { 3011 if (element->isTextFormControl()) {
3012 const HTMLTextFormControlElement* input = toHTMLTextFormControlElement(e lement); 3012 const HTMLTextFormControlElement* input = toHTMLTextFormControlElement(e lement);
3013 if (!input->isDisabledOrReadOnly()) 3013 if (!input->isDisabledOrReadOnly())
3014 return true; 3014 return true;
3015 } 3015 }
3016 3016
3017 return equalIgnoringCase(element->getAttribute(HTMLNames::roleAttr), "textbo x"); 3017 return equalIgnoringCase(element->getAttribute(HTMLNames::roleAttr), "textbo x");
3018 } 3018 }
(...skipping 1597 matching lines...) Expand 10 before | Expand all | Expand 10 after
4616 return nullptr; 4616 return nullptr;
4617 return focusedFrame; 4617 return focusedFrame;
4618 } 4618 }
4619 4619
4620 LocalFrame* WebViewImpl::focusedLocalFrameAvailableForIme() const 4620 LocalFrame* WebViewImpl::focusedLocalFrameAvailableForIme() const
4621 { 4621 {
4622 return m_imeAcceptEvents ? focusedLocalFrameInWidget() : nullptr; 4622 return m_imeAcceptEvents ? focusedLocalFrameInWidget() : nullptr;
4623 } 4623 }
4624 4624
4625 } // namespace blink 4625 } // namespace blink
OLDNEW
« third_party/WebKit/Source/web/WebNode.cpp ('K') | « third_party/WebKit/Source/web/WebNode.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698